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






Web Site Translations