IpcIoFile.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2020 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 
23 namespace Ipc
24 {
25 class FewToFewBiQueue;
26 } // Ipc
27 
28 // TODO: expand to all classes
29 namespace IpcIo
30 {
31 
33 typedef enum { cmdNone, cmdOpen, cmdRead, cmdWrite } Command;
34 
35 } // namespace IpcIo
36 
37 std::ostream &operator <<(std::ostream &, IpcIo::Command);
38 
40 class IpcIoMsg
41 {
42 public:
43  IpcIoMsg();
44 
46  void stat(std::ostream &);
47 
48 public:
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 
66 class IpcIoFile: public DiskFile
67 {
69 
70 public:
72 
73  IpcIoFile(char const *aDb);
74  virtual ~IpcIoFile();
75 
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;
88 
90  static void HandleOpenResponse(const Ipc::StrandSearchResponse &response);
91 
93  static void HandleNotification(const Ipc::TypedMsgHdr &msg);
94 
96  static void StatQueue(std::ostream &);
97 
99 
100 protected:
101  friend class IpcIoPendingRequest;
102  void openCompleted(const Ipc::StrandSearchResponse *const response);
103  void readCompleted(ReadRequest *readRequest, IpcIoMsg *const response);
104  void writeCompleted(WriteRequest *writeRequest, const IpcIoMsg *const response);
105  bool canWait() const;
106 
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);
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();
121  void scheduleTimeoutCheck();
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 private:
132  const String dbName;
133  const pid_t myPid;
134  int diskId;
136 
137  bool error_;
138 
139  unsigned int lastRequestId;
140 
142  typedef std::map<unsigned int, IpcIoPendingRequest*> RequestMap;
148 
149  static const double Timeout;
150 
151  typedef std::list<Pointer> IpcIoFileList;
153 
155  typedef std::map<int, IpcIoFile*> IpcIoFilesMap;
157 
159  static std::unique_ptr<Queue> queue;
160 
163 };
164 
167 {
168 public:
170 
172  void completeIo(IpcIoMsg *const response);
173 
174 public:
178 
180 
181 private:
182  IpcIoPendingRequest(const IpcIoPendingRequest &d); // not implemented
184 };
185 
186 #endif /* SQUID_IPC_IOFILE_H */
187 
bool timeoutCheckScheduled
we expect a CheckTimeouts() call
Definition: IpcIoFile.h:147
size_t pendingRequests() const
Definition: IpcIoFile.h:114
asynchronous strand search response
Definition: StrandSearch.h:33
ReadRequest * readRequest
set if this is a read requests
Definition: IpcIoFile.h:176
virtual bool canRead() const
Definition: IpcIoFile.cc:220
Command
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:693
RefCount< IORequestor > ioRequestor
Definition: IpcIoFile.h:135
RequestMap * olderRequests
older requests (map1 or map2)
Definition: IpcIoFile.h:145
Shared memory page identifier, address, or handler.
Definition: Page.h:23
off_t offset
Definition: IpcIoFile.h:51
void readCompleted(ReadRequest *readRequest, IpcIoMsg *const response)
Definition: IpcIoFile.cc:256
virtual bool ioInProgress() const
Definition: IpcIoFile.cc:340
IpcIoPendingRequest * dequeueRequest(const unsigned int requestId)
returns and forgets the right IpcIoFile pending request
Definition: IpcIoFile.cc:631
virtual ~IpcIoFile()
Definition: IpcIoFile.cc:106
std::map< unsigned int, IpcIoPendingRequest * > RequestMap
maps requestId to the handleResponse callback
Definition: IpcIoFile.h:142
void trackPendingRequest(const unsigned int id, IpcIoPendingRequest *const pending)
track a new pending request
Definition: IpcIoFile.cc:347
CodeContext::Pointer codeContext
requestor's context
Definition: IpcIoFile.h:179
void checkTimeouts()
Definition: IpcIoFile.cc:574
std::list< Pointer > IpcIoFileList
Definition: IpcIoFile.h:151
RefCount< IpcIoFile > Pointer
Definition: IpcIoFile.h:71
static void Notify(const int peerId)
Definition: IpcIoFile.cc:511
static IpcIoFileList WaitingForOpen
pending open requests
Definition: IpcIoFile.h:152
@ cmdWrite
Definition: IpcIoFile.h:33
virtual void open(int flags, mode_t mode, RefCount< IORequestor > callback)
Definition: IpcIoFile.cc:126
Ipc::Mem::PageId page
Definition: IpcIoFile.h:53
void writeCompleted(WriteRequest *writeRequest, const IpcIoMsg *const response)
Definition: IpcIoFile.cc:305
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:137
static std::unique_ptr< Queue > queue
IPC queue.
Definition: IpcIoFile.h:159
int xerrno
I/O error code or zero.
Definition: IpcIoFile.h:59
virtual bool canWrite() const
Definition: IpcIoFile.cc:226
void push(IpcIoPendingRequest *const pending)
push an I/O request to disker
Definition: IpcIoFile.cc:358
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:545
static void HandleResponses(const char *const when)
Definition: IpcIoFile.cc:476
static bool DiskerHandleMoreRequestsScheduled
whether we are waiting for an event to handle still queued I/O requests
Definition: IpcIoFile.h:162
virtual bool error() const
Definition: IpcIoFile.cc:232
static void DiskerHandleRequest(const int workerId, IpcIoMsg &ipcIo)
called when disker receives an I/O request
Definition: IpcIoFile.cc:926
Ipc::FewToFewBiQueue Queue
Definition: IpcIoFile.h:158
unsigned int requestId
unique for requestor; matches request w/ response
Definition: IpcIoFile.h:49
virtual int getFD() const
Definition: IpcIoFile.cc:655
void handleResponse(IpcIoMsg &ipcIo)
Definition: IpcIoFile.cc:490
virtual void create(int flags, mode_t mode, RefCount< IORequestor > callback)
Definition: IpcIoFile.cc:200
virtual void close()
Definition: IpcIoFile.cc:208
void stat(std::ostream &)
prints message parameters; suitable for cache manager reports
Definition: IpcIoFile.cc:676
WriteRequest * writeRequest
set if this is a write request
Definition: IpcIoFile.h:177
std::ostream & operator<<(std::ostream &, IpcIo::Command)
Definition: IpcIoFile.cc:76
void scheduleTimeoutCheck()
prepare to check for timeouts in a little while
Definition: IpcIoFile.cc:617
RequestMap requestMap1
older (or newer) pending requests
Definition: IpcIoFile.h:143
IpcIo::Command command
what disker is supposed to do or did
Definition: IpcIoFile.h:56
IpcIoFile(char const *aDb)
Definition: IpcIoFile.cc:94
static void HandleNotification(const Ipc::TypedMsgHdr &msg)
handle queue push notifications from worker or disker
Definition: IpcIoFile.cc:523
std::map< int, IpcIoFile * > IpcIoFilesMap
Definition: IpcIoFile.h:155
virtual void write(WriteRequest *)
Definition: IpcIoFile.cc:286
@ cmdRead
Definition: IpcIoFile.h:33
const pid_t myPid
optimization: cached process ID of our process
Definition: IpcIoFile.h:133
virtual void configure(const Config &cfg)
notes supported configuration options; kids must call this first
Definition: IpcIoFile.cc:119
static const double Timeout
timeout value in seconds
Definition: IpcIoFile.h:149
pid_t workerPid
the process ID of the I/O requestor
Definition: IpcIoFile.h:54
CBDATA_CLASS(IpcIoFile)
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:166
generally useful configuration options supported by some children
Definition: DiskFile.h:27
RequestMap requestMap2
newer (or older) pending requests
Definition: IpcIoFile.h:144
void openCompleted(const Ipc::StrandSearchResponse *const response)
Definition: IpcIoFile.cc:171
static bool WaitBeforePop()
Definition: IpcIoFile.cc:822
static void DiskerHandleMoreRequests(void *)
Definition: IpcIoFile.cc:813
unsigned short mode_t
Definition: types.h:150
void const char HLPCB * callback
Definition: stub_helper.cc:16
struct msghdr with a known type, fixed-size I/O and control buffers
Definition: TypedMsgHdr.h:31
static void StatQueue(std::ostream &)
prints IPC message queue state; suitable for cache manager reports
Definition: IpcIoFile.cc:535
virtual void read(ReadRequest *)
Definition: IpcIoFile.cc:238
void completeIo(IpcIoMsg *const response)
called when response is received and, with a nil response, on timeouts
Definition: IpcIoFile.cc:702
const IpcIoFile::Pointer file
the file object waiting for the response
Definition: IpcIoFile.h:175
size_t len
Definition: IpcIoFile.h:52
RequestMap * newerRequests
newer requests (map2 or map1)
Definition: IpcIoFile.h:146
static IpcIoFilesMap IpcIoFiles
Definition: IpcIoFile.h:156
converts DiskIO requests to IPC queue messages
Definition: IpcIoFile.h:40
static void HandleOpenResponse(const Ipc::StrandSearchResponse &response)
handle open response from coordinator
Definition: IpcIoFile.cc:458
int diskId
the kid ID of the disker we talk to
Definition: IpcIoFile.h:134
@ cmdNone
Definition: IpcIoFile.h:33
bool canWait() const
whether we think there is enough time to complete the I/O
Definition: IpcIoFile.cc:423
static void CheckTimeouts(void *const param)
IpcIoFile::checkTimeouts wrapper.
Definition: IpcIoFile.cc:563
unsigned int lastRequestId
last requestId used
Definition: IpcIoFile.h:139
Definition: IpcIoFile.h:23
static void DiskerHandleRequests()
Definition: IpcIoFile.cc:883
const String dbName
the name of the file we are managing
Definition: IpcIoFile.h:132

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors