IpcIoFile.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9#ifndef SQUID_IPC_IOFILE_H
10#define SQUID_IPC_IOFILE_H
11
12#include "base/AsyncCall.h"
13#include "cbdata.h"
14#include "DiskIO/DiskFile.h"
15#include "DiskIO/IORequestor.h"
16#include "ipc/forward.h"
17#include "ipc/mem/Page.h"
18#include "SquidString.h"
19#include <list>
20#include <map>
21#include <memory>
22
23namespace Ipc
24{
25class FewToFewBiQueue;
26} // Ipc
27
28// TODO: expand to all classes
29namespace IpcIo
30{
31
34
35std::ostream &operator <<(std::ostream &, Command);
36
37} // namespace IpcIo
38
41{
42public:
43 IpcIoMsg();
44
46 void stat(std::ostream &);
47
48public:
49 unsigned int requestId;
50
51 off_t offset;
52 size_t len;
54 pid_t workerPid;
55
57 struct timeval start;
58
59 int xerrno;
60};
61
63
66class IpcIoFile: public DiskFile
67{
69
70public:
72
73 IpcIoFile(char const *aDb);
74 ~IpcIoFile() override;
75
76 /* DiskFile API */
77 void configure(const Config &cfg) override;
78 void open(int flags, mode_t mode, RefCount<IORequestor> callback) override;
79 void create(int flags, mode_t mode, RefCount<IORequestor> callback) override;
80 void read(ReadRequest *) override;
81 void write(WriteRequest *) override;
82 void close() override;
83 bool error() const override;
84 int getFD() const override;
85 bool canRead() const override;
86 bool canWrite() const override;
87 bool ioInProgress() const override;
88
90 static void HandleOpenResponse(const Ipc::StrandMessage &);
91
93 static void HandleNotification(const Ipc::TypedMsgHdr &msg);
94
96 static void StatQueue(std::ostream &);
97
99
100protected:
102 void openCompleted(const Ipc::StrandMessage *);
103 void readCompleted(ReadRequest *readRequest, IpcIoMsg *const response);
104 void writeCompleted(WriteRequest *writeRequest, const IpcIoMsg *const response);
105 bool canWait() const;
106
107private:
108 void trackPendingRequest(const unsigned int id, IpcIoPendingRequest *const pending);
109 void push(IpcIoPendingRequest *const pending);
110 IpcIoPendingRequest *dequeueRequest(const unsigned int requestId);
111
114 size_t pendingRequests() const { return olderRequests->size() + newerRequests->size(); }
115
116 static void Notify(const int peerId);
117
118 static void OpenTimeout(void *const param);
119 static void CheckTimeouts(void *const param);
120 void checkTimeouts();
122
123 static void HandleResponses(const char *const when);
124 void handleResponse(IpcIoMsg &ipcIo);
125
126 static void DiskerHandleMoreRequests(void*);
127 static void DiskerHandleRequests();
128 static void DiskerHandleRequest(const int workerId, IpcIoMsg &ipcIo);
129 static bool WaitBeforePop();
130
131 static void HandleMessagesAtStart();
132
133private:
135 const pid_t myPid;
136 int diskId;
138
139 bool error_;
140
141 unsigned int lastRequestId;
142
144 typedef std::map<unsigned int, IpcIoPendingRequest*> RequestMap;
150
151 static const double Timeout;
152
153 typedef std::list<Pointer> IpcIoFileList;
155
157 typedef std::map<int, IpcIoFile*> IpcIoFilesMap;
159
161 static std::unique_ptr<Queue> queue;
162
165};
166
169{
170public:
172
174 void completeIo(IpcIoMsg *const response);
175
176public:
180
182
183private:
184 IpcIoPendingRequest(const IpcIoPendingRequest &d); // not implemented
186};
187
188#endif /* SQUID_IPC_IOFILE_H */
189
generally useful configuration options supported by some children
Definition: DiskFile.h:28
RequestMap * newerRequests
newer requests (map2 or map1)
Definition: IpcIoFile.h:148
RequestMap requestMap1
older (or newer) pending requests
Definition: IpcIoFile.h:145
static void DiskerHandleMoreRequests(void *)
Definition: IpcIoFile.cc:826
void create(int flags, mode_t mode, RefCount< IORequestor > callback) override
Definition: IpcIoFile.cc:198
void scheduleTimeoutCheck()
prepare to check for timeouts in a little while
Definition: IpcIoFile.cc:630
RefCount< IpcIoFile > Pointer
Definition: IpcIoFile.h:71
static bool DiskerHandleMoreRequestsScheduled
whether we are waiting for an event to handle still queued I/O requests
Definition: IpcIoFile.h:164
bool canWait() const
whether we think there is enough time to complete the I/O
Definition: IpcIoFile.cc:421
static IpcIoFileList WaitingForOpen
pending open requests
Definition: IpcIoFile.h:154
void read(ReadRequest *) override
Definition: IpcIoFile.cc:236
static const double Timeout
timeout value in seconds
Definition: IpcIoFile.h:151
~IpcIoFile() override
Definition: IpcIoFile.cc:107
bool canRead() const override
Definition: IpcIoFile.cc:218
static void CheckTimeouts(void *const param)
IpcIoFile::checkTimeouts wrapper.
Definition: IpcIoFile.cc:576
static IpcIoFilesMap IpcIoFiles
Definition: IpcIoFile.h:158
RequestMap * olderRequests
older requests (map1 or map2)
Definition: IpcIoFile.h:147
void trackPendingRequest(const unsigned int id, IpcIoPendingRequest *const pending)
track a new pending request
Definition: IpcIoFile.cc:345
void checkTimeouts()
Definition: IpcIoFile.cc:587
static void DiskerHandleRequests()
Definition: IpcIoFile.cc:896
void open(int flags, mode_t mode, RefCount< IORequestor > callback) override
Definition: IpcIoFile.cc:127
static void Notify(const int peerId)
Definition: IpcIoFile.cc:512
static void HandleOpenResponse(const Ipc::StrandMessage &)
handle open response from coordinator
Definition: IpcIoFile.cc:456
void writeCompleted(WriteRequest *writeRequest, const IpcIoMsg *const response)
Definition: IpcIoFile.cc:303
RefCount< IORequestor > ioRequestor
Definition: IpcIoFile.h:137
bool ioInProgress() const override
Definition: IpcIoFile.cc:338
int getFD() const override
Definition: IpcIoFile.cc:668
void configure(const Config &cfg) override
notes supported configuration options; kids must call this first
Definition: IpcIoFile.cc:120
CBDATA_CLASS(IpcIoFile)
static void OpenTimeout(void *const param)
handles open request timeout
Definition: IpcIoFile.cc:558
void handleResponse(IpcIoMsg &ipcIo)
Definition: IpcIoFile.cc:491
bool error() const override
Definition: IpcIoFile.cc:230
void close() override
Definition: IpcIoFile.cc:206
static void DiskerHandleRequest(const int workerId, IpcIoMsg &ipcIo)
called when disker receives an I/O request
Definition: IpcIoFile.cc:939
void openCompleted(const Ipc::StrandMessage *)
Definition: IpcIoFile.cc:169
IpcIoFile(char const *aDb)
Definition: IpcIoFile.cc:95
int diskId
the kid ID of the disker we talk to
Definition: IpcIoFile.h:136
void readCompleted(ReadRequest *readRequest, IpcIoMsg *const response)
Definition: IpcIoFile.cc:254
size_t pendingRequests() const
Definition: IpcIoFile.h:114
std::map< int, IpcIoFile * > IpcIoFilesMap
Definition: IpcIoFile.h:157
DiskFile::Config config
supported configuration options
Definition: IpcIoFile.h:98
void push(IpcIoPendingRequest *const pending)
push an I/O request to disker
Definition: IpcIoFile.cc:356
static void StatQueue(std::ostream &)
prints IPC message queue state; suitable for cache manager reports
Definition: IpcIoFile.cc:548
void write(WriteRequest *) override
Definition: IpcIoFile.cc:284
bool timeoutCheckScheduled
we expect a CheckTimeouts() call
Definition: IpcIoFile.h:149
unsigned int lastRequestId
last requestId used
Definition: IpcIoFile.h:141
Ipc::FewToFewBiQueue Queue
Definition: IpcIoFile.h:160
RequestMap requestMap2
newer (or older) pending requests
Definition: IpcIoFile.h:146
static std::unique_ptr< Queue > queue
IPC queue.
Definition: IpcIoFile.h:161
IpcIoPendingRequest * dequeueRequest(const unsigned int requestId)
returns and forgets the right IpcIoFile pending request
Definition: IpcIoFile.cc:644
const pid_t myPid
optimization: cached process ID of our process
Definition: IpcIoFile.h:135
bool error_
whether we have seen at least one I/O error (XXX)
Definition: IpcIoFile.h:139
bool canWrite() const override
Definition: IpcIoFile.cc:224
static void HandleMessagesAtStart()
Definition: IpcIoFile.cc:537
static void HandleResponses(const char *const when)
Definition: IpcIoFile.cc:474
const String dbName
the name of the file we are managing
Definition: IpcIoFile.h:134
std::map< unsigned int, IpcIoPendingRequest * > RequestMap
maps requestId to the handleResponse callback
Definition: IpcIoFile.h:144
static bool WaitBeforePop()
Definition: IpcIoFile.cc:835
static void HandleNotification(const Ipc::TypedMsgHdr &msg)
handle queue push notifications from worker or disker
Definition: IpcIoFile.cc:524
std::list< Pointer > IpcIoFileList
Definition: IpcIoFile.h:153
converts DiskIO requests to IPC queue messages
Definition: IpcIoFile.h:41
size_t len
Definition: IpcIoFile.h:52
pid_t workerPid
the process ID of the I/O requestor
Definition: IpcIoFile.h:54
IpcIo::Command command
what disker is supposed to do or did
Definition: IpcIoFile.h:56
unsigned int requestId
unique for requestor; matches request w/ response
Definition: IpcIoFile.h:49
void stat(std::ostream &)
prints message parameters; suitable for cache manager reports
Definition: IpcIoFile.cc:689
struct timeval start
when the I/O request was converted to IpcIoMsg
Definition: IpcIoFile.h:57
int xerrno
I/O error code or zero.
Definition: IpcIoFile.h:59
Ipc::Mem::PageId page
Definition: IpcIoFile.h:53
off_t offset
Definition: IpcIoFile.h:51
keeps original I/O request parameters while disker is handling the request
Definition: IpcIoFile.h:169
IpcIoPendingRequest & operator=(const IpcIoPendingRequest &d)
CodeContext::Pointer codeContext
requestor's context
Definition: IpcIoFile.h:181
const IpcIoFile::Pointer file
the file object waiting for the response
Definition: IpcIoFile.h:177
WriteRequest * writeRequest
set if this is a write request
Definition: IpcIoFile.h:179
IpcIoPendingRequest(const IpcIoPendingRequest &d)
IpcIoPendingRequest(const IpcIoFile::Pointer &aFile)
Definition: IpcIoFile.cc:706
void completeIo(IpcIoMsg *const response)
called when response is received and, with a nil response, on timeouts
Definition: IpcIoFile.cc:715
ReadRequest * readRequest
set if this is a read requests
Definition: IpcIoFile.h:178
Shared memory page identifier, address, or handler.
Definition: Page.h:24
an IPC message carrying StrandCoord
Definition: StrandCoord.h:39
struct msghdr with a known type, fixed-size I/O and control buffers
Definition: TypedMsgHdr.h:35
Command
what kind of I/O the disker needs to do or have done
Definition: IpcIoFile.h:33
@ cmdNone
Definition: IpcIoFile.h:33
@ cmdRead
Definition: IpcIoFile.h:33
@ cmdWrite
Definition: IpcIoFile.h:33
@ cmdOpen
Definition: IpcIoFile.h:33
std::ostream & operator<<(std::ostream &, Command)
Definition: IpcIoFile.cc:77
Definition: IpcIoFile.h:24
unsigned short mode_t
Definition: types.h:129

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors