Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2018 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
38 class IpcIoMsg
39 {
40 public:
41  IpcIoMsg();
43 public:
44  unsigned int requestId;
46  off_t offset;
47  size_t len;
51  struct timeval start;
53  int xerrno;
54 };
58 class IpcIoFile: public DiskFile
59 {
62 public:
65  IpcIoFile(char const *aDb);
66  virtual ~IpcIoFile();
68  /* DiskFile API */
69  virtual void configure(const Config &cfg);
70  virtual void open(int flags, mode_t mode, RefCount<IORequestor> callback);
71  virtual void create(int flags, mode_t mode, RefCount<IORequestor> callback);
72  virtual void read(ReadRequest *);
73  virtual void write(WriteRequest *);
74  virtual void close();
75  virtual bool error() const;
76  virtual int getFD() const;
77  virtual bool canRead() const;
78  virtual bool canWrite() const;
79  virtual bool ioInProgress() const;
82  static void HandleOpenResponse(const Ipc::StrandSearchResponse &response);
85  static void HandleNotification(const Ipc::TypedMsgHdr &msg);
89 protected:
90  friend class IpcIoPendingRequest;
91  void openCompleted(const Ipc::StrandSearchResponse *const response);
92  void readCompleted(ReadRequest *readRequest, IpcIoMsg *const response);
93  void writeCompleted(WriteRequest *writeRequest, const IpcIoMsg *const response);
94  bool canWait() const;
96 private:
97  void trackPendingRequest(const unsigned int id, IpcIoPendingRequest *const pending);
98  void push(IpcIoPendingRequest *const pending);
99  IpcIoPendingRequest *dequeueRequest(const unsigned int requestId);
101  static void Notify(const int peerId);
103  static void OpenTimeout(void *const param);
104  static void CheckTimeouts(void *const param);
105  void checkTimeouts();
106  void scheduleTimeoutCheck();
108  static void HandleResponses(const char *const when);
109  void handleResponse(IpcIoMsg &ipcIo);
111  static void DiskerHandleMoreRequests(void*);
112  static void DiskerHandleRequests();
113  static void DiskerHandleRequest(const int workerId, IpcIoMsg &ipcIo);
114  static bool WaitBeforePop();
116 private:
117  const String dbName;
118  int diskId;
121  bool error_;
123  unsigned int lastRequestId;
126  typedef std::map<unsigned int, IpcIoPendingRequest*> RequestMap;
133  static const double Timeout;
135  typedef std::list<Pointer> IpcIoFileList;
139  typedef std::map<int, IpcIoFile*> IpcIoFilesMap;
143  static std::unique_ptr<Queue> queue;
147 };
151 {
152 public:
156  void completeIo(IpcIoMsg *const response);
158 public:
163 private:
164  IpcIoPendingRequest(const IpcIoPendingRequest &d); // not implemented
166 };
168 #endif /* SQUID_IPC_IOFILE_H */
virtual bool canWrite() const
Definition: IpcIoFile.cc:199
int diskId
the process ID of the disker we talk to
Definition: IpcIoFile.h:118
generally useful configuration options supported by some children
Definition: DiskFile.h:27
bool canWait() const
whether we think there is enough time to complete the I/O
Definition: IpcIoFile.cc:389
RequestMap * olderRequests
older requests (map1 or map2)
Definition: IpcIoFile.h:129
static void HandleOpenResponse(const Ipc::StrandSearchResponse &response)
handle open response from coordinator
Definition: IpcIoFile.cc:424
void const char HLPCB * callback
Definition: stub_helper.cc:16
virtual void open(int flags, mode_t mode, RefCount< IORequestor > callback)
Definition: IpcIoFile.cc:99
keeps original I/O request parameters while disker is handling the request
Definition: IpcIoFile.h:150
IpcIoPendingRequest(const IpcIoFile::Pointer &aFile)
Definition: IpcIoFile.cc:627
bool error_
whether we have seen at least one I/O error (XXX)
Definition: IpcIoFile.h:121
std::list< Pointer > IpcIoFileList
Definition: IpcIoFile.h:135
virtual void create(int flags, mode_t mode, RefCount< IORequestor > callback)
Definition: IpcIoFile.cc:173
IpcIo::Command command
what disker is supposed to do or did
Definition: IpcIoFile.h:50
IpcIoPendingRequest & operator=(const IpcIoPendingRequest &d)
RefCount< IORequestor > ioRequestor
Definition: IpcIoFile.h:119
static void CheckTimeouts(void *const param)
IpcIoFile::checkTimeouts wrapper.
Definition: IpcIoFile.cc:517
static void Notify(const int peerId)
Definition: IpcIoFile.cc:474
virtual void write(WriteRequest *)
Definition: IpcIoFile.cc:259
static void HandleResponses(const char *const when)
Definition: IpcIoFile.cc:442
void scheduleTimeoutCheck()
prepare to check for timeouts in a little while
Definition: IpcIoFile.cc:572
static void DiskerHandleRequest(const int workerId, IpcIoMsg &ipcIo)
called when disker receives an I/O request
Definition: IpcIoFile.cc:857
IpcIoFile(char const *aDb)
Definition: IpcIoFile.cc:72
virtual int getFD() const
Definition: IpcIoFile.cc:606
virtual void configure(const Config &cfg)
notes supported configuration options; kids must call this first
Definition: IpcIoFile.cc:92
std::map< unsigned int, IpcIoPendingRequest * > RequestMap
maps requestId to the handleResponse callback
Definition: IpcIoFile.h:126
void writeCompleted(WriteRequest *writeRequest, const IpcIoMsg *const response)
Definition: IpcIoFile.cc:278
what kind of I/O the disker needs to do or have done
Definition: IpcIoFile.h:33
bool timeoutCheckScheduled
we expect a CheckTimeouts() call
Definition: IpcIoFile.h:131
virtual bool canRead() const
Definition: IpcIoFile.cc:193
static IpcIoFilesMap IpcIoFiles
Definition: IpcIoFile.h:140
RefCount< IpcIoFile > Pointer
Definition: IpcIoFile.h:63
DiskFile::Config config
supported configuration options
Definition: IpcIoFile.h:87
void readCompleted(ReadRequest *readRequest, IpcIoMsg *const response)
Definition: IpcIoFile.cc:229
static bool DiskerHandleMoreRequestsScheduled
whether we are waiting for an event to handle still queued I/O requests
Definition: IpcIoFile.h:146
WriteRequest * writeRequest
set if this is a write request
Definition: IpcIoFile.h:161
unsigned int lastRequestId
last requestId used
Definition: IpcIoFile.h:123
std::map< int, IpcIoFile * > IpcIoFilesMap
Definition: IpcIoFile.h:139
virtual bool ioInProgress() const
Definition: IpcIoFile.cc:313
static void DiskerHandleRequests()
Definition: IpcIoFile.cc:814
void checkTimeouts()
Definition: IpcIoFile.cc:528
static std::unique_ptr< Queue > queue
IPC queue.
Definition: IpcIoFile.h:143
RequestMap requestMap1
older (or newer) pending requests
Definition: IpcIoFile.h:127
static void HandleNotification(const Ipc::TypedMsgHdr &msg)
handle queue push notifications from worker or disker
Definition: IpcIoFile.cc:486
int xerrno
I/O error code or zero.
Definition: IpcIoFile.h:53
void trackPendingRequest(const unsigned int id, IpcIoPendingRequest *const pending)
track a new pending request
Definition: IpcIoFile.cc:320
virtual void read(ReadRequest *)
Definition: IpcIoFile.cc:211
asynchronous strand search response
Definition: StrandSearch.h:33
static bool WaitBeforePop()
Definition: IpcIoFile.cc:753
static void DiskerHandleMoreRequests(void *)
Definition: IpcIoFile.cc:744
ReadRequest * readRequest
set if this is a read requests
Definition: IpcIoFile.h:160
unsigned short mode_t
Definition: types.h:150
Ipc::Mem::PageId page
Definition: IpcIoFile.h:48
const IpcIoFile::Pointer file
the file object waiting for the response
Definition: IpcIoFile.h:159
virtual bool error() const
Definition: IpcIoFile.cc:205
virtual ~IpcIoFile()
Definition: IpcIoFile.cc:79
void completeIo(IpcIoMsg *const response)
called when response is received and, with a nil response, on timeouts
Definition: IpcIoFile.cc:633
RequestMap requestMap2
newer (or older) pending requests
Definition: IpcIoFile.h:128
struct msghdr with a known type, fixed-size I/O and control buffers
Definition: TypedMsgHdr.h:31
RequestMap * newerRequests
newer requests (map2 or map1)
Definition: IpcIoFile.h:130
void push(IpcIoPendingRequest *const pending)
push an I/O request to disker
Definition: IpcIoFile.cc:331
size_t len
Definition: IpcIoFile.h:47
Shared memory page identifier, address, or handler.
Definition: Page.h:21
Ipc::FewToFewBiQueue Queue
Definition: IpcIoFile.h:142
void handleResponse(IpcIoMsg &ipcIo)
Definition: IpcIoFile.cc:456
static const double Timeout
timeout value in seconds
Definition: IpcIoFile.h:133
const String dbName
the name of the file we are managing
Definition: IpcIoFile.h:117
unsigned int requestId
unique for requestor; matches request w/ response
Definition: IpcIoFile.h:44
void openCompleted(const Ipc::StrandSearchResponse *const response)
Definition: IpcIoFile.cc:144
static IpcIoFileList WaitingForOpen
pending open requests
Definition: IpcIoFile.h:136
off_t offset
Definition: IpcIoFile.h:46
IpcIoPendingRequest * dequeueRequest(const unsigned int requestId)
returns and forgets the right IpcIoFile pending request
Definition: IpcIoFile.cc:582
static void OpenTimeout(void *const param)
handles open request timeout
Definition: IpcIoFile.cc:499
virtual void close()
Definition: IpcIoFile.cc:181
converts DiskIO requests to IPC queue messages
Definition: IpcIoFile.h:38
struct timeval start
when the I/O request was converted to IpcIoMsg
Definition: IpcIoFile.h:51






Web Site Translations