]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/rock/RockIoState.h
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / fs / rock / RockIoState.h
1 /*
2 * Copyright (C) 1996-2021 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_FS_ROCK_IO_STATE_H
10 #define SQUID_FS_ROCK_IO_STATE_H
11
12 #include "fs/rock/forward.h"
13 #include "fs/rock/RockSwapDir.h"
14 #include "sbuf/MemBlob.h"
15
16 class DiskFile;
17
18 namespace Rock
19 {
20
21 class DbCellHeader;
22 class SwapDir;
23
24 /// \ingroup Rock
25 class IoState: public ::StoreIOState
26 {
27 MEMPROXY_CLASS(IoState);
28
29 public:
30 typedef RefCount<IoState> Pointer;
31
32 IoState(Rock::SwapDir::Pointer &aDir, StoreEntry *e, StoreIOState::STFNCB *cbFile, StoreIOState::STIOCB *cbIo, void *data);
33 virtual ~IoState();
34
35 void file(const RefCount<DiskFile> &aFile);
36
37 // ::StoreIOState API
38 virtual void read_(char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data);
39 virtual bool write(char const *buf, size_t size, off_t offset, FREE * free_func);
40 virtual void close(int how);
41
42 /// whether we are still waiting for the I/O results (i.e., not closed)
43 bool stillWaiting() const { return theFile != NULL; }
44
45 /// forwards read data (or an error) to the reader that initiated this I/O
46 void handleReadCompletion(Rock::ReadRequest &request, const int rlen, const int errFlag);
47
48 /// called by SwapDir::writeCompleted() after the last write and on error
49 void finishedWriting(const int errFlag);
50
51 /// notes that the disker has satisfied the given I/O request
52 /// \returns whether all earlier I/O requests have been satisfied already
53 bool expectedReply(const IoXactionId receivedId);
54
55 /* one and only one of these will be set and locked; access via *Anchor() */
56 const Ipc::StoreMapAnchor *readableAnchor_; ///< starting point for reading
57 Ipc::StoreMapAnchor *writeableAnchor_; ///< starting point for writing
58
59 /// the last db slot successfully read or written
60 SlotId splicingPoint;
61 /// when reading, this is the next slot we are going to read (if asked)
62 /// when writing, this is the next slot to use after the last fresh slot
63 SlotId staleSplicingPointNext;
64
65 private:
66 const Ipc::StoreMapAnchor &readAnchor() const;
67 Ipc::StoreMapAnchor &writeAnchor();
68 const Ipc::StoreMapSlice &currentReadableSlice() const;
69
70 void tryWrite(char const *buf, size_t size, off_t offset);
71 size_t writeToBuffer(char const *buf, size_t size);
72 void writeToDisk();
73
74 void callReaderBack(const char *buf, int rlen);
75 void callBack(int errflag);
76
77 Rock::SwapDir::Pointer dir; ///< swap dir that initiated I/O
78 const size_t slotSize; ///< db cell size
79 int64_t objOffset; ///< object offset for current db slot
80
81 /// The very first entry slot. Usually the same as anchor.first,
82 /// but writers set anchor.first only after the first write is done.
83 SlotId sidFirst;
84
85 /// Unused by readers.
86 /// For writers, the slot pointing (via .next) to sidCurrent.
87 SlotId sidPrevious;
88
89 /// For readers, the db slot currently being read from disk.
90 /// For writers, the reserved db slot currently being filled (to be written).
91 SlotId sidCurrent;
92
93 /// Unused by readers.
94 /// For writers, the reserved db slot that sidCurrent.next will point to.
95 SlotId sidNext;
96
97 /// the number of read or write requests we sent to theFile
98 uint64_t requestsSent;
99
100 /// the number of successful responses we received from theFile
101 uint64_t repliesReceived;
102
103 RefCount<DiskFile> theFile; // "file" responsible for this I/O
104 MemBlob theBuf; // use for write content accumulation only
105 };
106
107 } // namespace Rock
108
109 #endif /* SQUID_FS_ROCK_IO_STATE_H */
110