2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_FS_ROCK_IO_STATE_H
10 #define SQUID_FS_ROCK_IO_STATE_H
12 #include "fs/rock/forward.h"
13 #include "fs/rock/RockSwapDir.h"
14 #include "sbuf/MemBlob.h"
25 class IoState
: public ::StoreIOState
27 MEMPROXY_CLASS(IoState
);
30 typedef RefCount
<IoState
> Pointer
;
32 IoState(Rock::SwapDir::Pointer
&aDir
, StoreEntry
*e
, StoreIOState::STFNCB
*cbFile
, StoreIOState::STIOCB
*cbIo
, void *data
);
35 void file(const RefCount
<DiskFile
> &aFile
);
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
);
42 /// whether we are still waiting for the I/O results (i.e., not closed)
43 bool stillWaiting() const { return theFile
!= NULL
; }
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
);
48 /// called by SwapDir::writeCompleted() after the last write and on error
49 void finishedWriting(const int errFlag
);
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
);
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
59 /// the last db slot successfully read or written
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
;
66 const Ipc::StoreMapAnchor
&readAnchor() const;
67 Ipc::StoreMapAnchor
&writeAnchor();
68 const Ipc::StoreMapSlice
¤tReadableSlice() const;
70 void tryWrite(char const *buf
, size_t size
, off_t offset
);
71 size_t writeToBuffer(char const *buf
, size_t size
);
74 void callReaderBack(const char *buf
, int rlen
);
75 void callBack(int errflag
);
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
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.
85 /// Unused by readers.
86 /// For writers, the slot pointing (via .next) to sidCurrent.
89 /// For readers, the db slot currently being read from disk.
90 /// For writers, the reserved db slot currently being filled (to be written).
93 /// Unused by readers.
94 /// For writers, the reserved db slot that sidCurrent.next will point to.
97 /// the number of read or write requests we sent to theFile
98 uint64_t requestsSent
;
100 /// the number of successful responses we received from theFile
101 uint64_t repliesReceived
;
103 RefCount
<DiskFile
> theFile
; // "file" responsible for this I/O
104 MemBlob theBuf
; // use for write content accumulation only
109 #endif /* SQUID_FS_ROCK_IO_STATE_H */