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 
56  struct timeval start;
57 
58  int xerrno;
59 };
60 
62 
65 class IpcIoFile: public DiskFile
66 {
68 
69 public:
71 
72  IpcIoFile(char const *aDb);
73  virtual ~IpcIoFile();
74 
75  /* DiskFile API */
76  virtual void configure(const Config &cfg);
77  virtual void open(int flags, mode_t mode, RefCount<IORequestor> callback);
78  virtual void create(int flags, mode_t mode, RefCount<IORequestor> callback);
79  virtual void read(ReadRequest *);
80  virtual void write(WriteRequest *);
81  virtual void close();
82  virtual bool error() const;
83  virtual int getFD() const;
84  virtual bool canRead() const;
85  virtual bool canWrite() const;
86  virtual bool ioInProgress() const;
87 
89  static void HandleOpenResponse(const Ipc::StrandSearchResponse &response);
90 
92  static void HandleNotification(const Ipc::TypedMsgHdr &msg);
93 
95  static void StatQueue(std::ostream &);
96 
98 
99 protected:
100  friend class IpcIoPendingRequest;
101  void openCompleted(const Ipc::StrandSearchResponse *const response);
102  void readCompleted(ReadRequest *readRequest, IpcIoMsg *const response);
103  void writeCompleted(WriteRequest *writeRequest, const IpcIoMsg *const response);
104  bool canWait() const;
105 
106 private:
107  void trackPendingRequest(const unsigned int id, IpcIoPendingRequest *const pending);
108  void push(IpcIoPendingRequest *const pending);
109  IpcIoPendingRequest *dequeueRequest(const unsigned int requestId);
110 
113  size_t pendingRequests() const { return olderRequests->size() + newerRequests->size(); }
114 
115  static void Notify(const int peerId);
116 
117  static void OpenTimeout(void *const param);
118  static void CheckTimeouts(void *const param);
119  void checkTimeouts();
120  void scheduleTimeoutCheck();
121 
122  static void HandleResponses(const char *const when);
123  void handleResponse(IpcIoMsg &ipcIo);
124 
125  static void DiskerHandleMoreRequests(void*);
126  static void DiskerHandleRequests();
127  static void DiskerHandleRequest(const int workerId, IpcIoMsg &ipcIo);
128  static bool WaitBeforePop();
129 
130 private:
131  const String dbName;
132  int diskId;
134 
135  bool error_;
136 
137  unsigned int lastRequestId;
138 
140  typedef std::map<unsigned int, IpcIoPendingRequest*> RequestMap;
146 
147  static const double Timeout;
148 
149  typedef std::list<Pointer> IpcIoFileList;
151 
153  typedef std::map<int, IpcIoFile*> IpcIoFilesMap;
155 
157  static std::unique_ptr<Queue> queue;
158 
161 };
162 
165 {
166 public:
168 
170  void completeIo(IpcIoMsg *const response);
171 
172 public:
176 
178 
179 private:
180  IpcIoPendingRequest(const IpcIoPendingRequest &d); // not implemented
182 };
183 
184 #endif /* SQUID_IPC_IOFILE_H */
185 
bool timeoutCheckScheduled
we expect a CheckTimeouts() call
Definition: IpcIoFile.h:145
size_t pendingRequests() const
Definition: IpcIoFile.h:113
asynchronous strand search response
Definition: StrandSearch.h:33
ReadRequest * readRequest
set if this is a read requests
Definition: IpcIoFile.h:174
virtual bool canRead() const
Definition: IpcIoFile.cc:215
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:682
RefCount< IORequestor > ioRequestor
Definition: IpcIoFile.h:133
RequestMap * olderRequests
older requests (map1 or map2)
Definition: IpcIoFile.h:143
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:251
virtual bool ioInProgress() const
Definition: IpcIoFile.cc:335
IpcIoPendingRequest * dequeueRequest(const unsigned int requestId)
returns and forgets the right IpcIoFile pending request
Definition: IpcIoFile.cc:622
virtual ~IpcIoFile()
Definition: IpcIoFile.cc:101
std::map< unsigned int, IpcIoPendingRequest * > RequestMap
maps requestId to the handleResponse callback
Definition: IpcIoFile.h:140
void trackPendingRequest(const unsigned int id, IpcIoPendingRequest *const pending)
track a new pending request
Definition: IpcIoFile.cc:342
CodeContext::Pointer codeContext
requestor's context
Definition: IpcIoFile.h:177
void checkTimeouts()
Definition: IpcIoFile.cc:565
std::list< Pointer > IpcIoFileList
Definition: IpcIoFile.h:149
RefCount< IpcIoFile > Pointer
Definition: IpcIoFile.h:70
static void Notify(const int peerId)
Definition: IpcIoFile.cc:502
static IpcIoFileList WaitingForOpen
pending open requests
Definition: IpcIoFile.h:150
@ cmdWrite
Definition: IpcIoFile.h:33
virtual void open(int flags, mode_t mode, RefCount< IORequestor > callback)
Definition: IpcIoFile.cc:121
Ipc::Mem::PageId page
Definition: IpcIoFile.h:53
void writeCompleted(WriteRequest *writeRequest, const IpcIoMsg *const response)
Definition: IpcIoFile.cc:300
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:135
static std::unique_ptr< Queue > queue
IPC queue.
Definition: IpcIoFile.h:157
int xerrno
I/O error code or zero.
Definition: IpcIoFile.h:58
virtual bool canWrite() const
Definition: IpcIoFile.cc:221
void push(IpcIoPendingRequest *const pending)
push an I/O request to disker
Definition: IpcIoFile.cc:353
struct timeval start
when the I/O request was converted to IpcIoMsg
Definition: IpcIoFile.h:56
static void OpenTimeout(void *const param)
handles open request timeout
Definition: IpcIoFile.cc:536
static void HandleResponses(const char *const when)
Definition: IpcIoFile.cc:470
static bool DiskerHandleMoreRequestsScheduled
whether we are waiting for an event to handle still queued I/O requests
Definition: IpcIoFile.h:160
virtual bool error() const
Definition: IpcIoFile.cc:227
static void DiskerHandleRequest(const int workerId, IpcIoMsg &ipcIo)
called when disker receives an I/O request
Definition: IpcIoFile.cc:915
Ipc::FewToFewBiQueue Queue
Definition: IpcIoFile.h:156
unsigned int requestId
unique for requestor; matches request w/ response
Definition: IpcIoFile.h:49
virtual int getFD() const
Definition: IpcIoFile.cc:646
void handleResponse(IpcIoMsg &ipcIo)
Definition: IpcIoFile.cc:484
virtual void create(int flags, mode_t mode, RefCount< IORequestor > callback)
Definition: IpcIoFile.cc:195
virtual void close()
Definition: IpcIoFile.cc:203
void stat(std::ostream &)
prints message parameters; suitable for cache manager reports
Definition: IpcIoFile.cc:666
WriteRequest * writeRequest
set if this is a write request
Definition: IpcIoFile.h:175
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:608
RequestMap requestMap1
older (or newer) pending requests
Definition: IpcIoFile.h:141
IpcIo::Command command
what disker is supposed to do or did
Definition: IpcIoFile.h:55
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:514
std::map< int, IpcIoFile * > IpcIoFilesMap
Definition: IpcIoFile.h:153
virtual void write(WriteRequest *)
Definition: IpcIoFile.cc:281
@ cmdRead
Definition: IpcIoFile.h:33
virtual void configure(const Config &cfg)
notes supported configuration options; kids must call this first
Definition: IpcIoFile.cc:114
static const double Timeout
timeout value in seconds
Definition: IpcIoFile.h:147
CBDATA_CLASS(IpcIoFile)
DiskFile::Config config
supported configuration options
Definition: IpcIoFile.h:97
keeps original I/O request parameters while disker is handling the request
Definition: IpcIoFile.h:164
generally useful configuration options supported by some children
Definition: DiskFile.h:27
RequestMap requestMap2
newer (or older) pending requests
Definition: IpcIoFile.h:142
void openCompleted(const Ipc::StrandSearchResponse *const response)
Definition: IpcIoFile.cc:166
static bool WaitBeforePop()
Definition: IpcIoFile.cc:811
static void DiskerHandleMoreRequests(void *)
Definition: IpcIoFile.cc:802
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:526
virtual void read(ReadRequest *)
Definition: IpcIoFile.cc:233
void completeIo(IpcIoMsg *const response)
called when response is received and, with a nil response, on timeouts
Definition: IpcIoFile.cc:691
const IpcIoFile::Pointer file
the file object waiting for the response
Definition: IpcIoFile.h:173
size_t len
Definition: IpcIoFile.h:52
RequestMap * newerRequests
newer requests (map2 or map1)
Definition: IpcIoFile.h:144
static IpcIoFilesMap IpcIoFiles
Definition: IpcIoFile.h:154
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:452
int diskId
the process ID of the disker we talk to
Definition: IpcIoFile.h:132
@ cmdNone
Definition: IpcIoFile.h:33
bool canWait() const
whether we think there is enough time to complete the I/O
Definition: IpcIoFile.cc:417
static void CheckTimeouts(void *const param)
IpcIoFile::checkTimeouts wrapper.
Definition: IpcIoFile.cc:554
unsigned int lastRequestId
last requestId used
Definition: IpcIoFile.h:137
Definition: IpcIoFile.h:23
static void DiskerHandleRequests()
Definition: IpcIoFile.cc:872
const String dbName
the name of the file we are managing
Definition: IpcIoFile.h:131

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors