]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/ufs/UFSStoreState.h
Maintenance: automate header guards 2/3 (#1655)
[thirdparty/squid.git] / src / fs / ufs / UFSStoreState.h
1 /*
2 * Copyright (C) 1996-2023 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_SRC_FS_UFS_UFSSTORESTATE_H
10 #define SQUID_SRC_FS_UFS_UFSSTORESTATE_H
11
12 #include "DiskIO/DiskFile.h"
13 #include "DiskIO/IORequestor.h"
14 #include "StoreIOState.h"
15
16 #include <queue>
17
18 namespace Fs
19 {
20 namespace Ufs
21 {
22
23 class UFSStoreState : public StoreIOState, public IORequestor
24 {
25 CBDATA_CLASS(UFSStoreState);
26
27 public:
28 UFSStoreState(SwapDir * SD, StoreEntry * anEntry, STIOCB * callback_, void *callback_data_);
29 ~UFSStoreState() override;
30 void close(int how) override;
31 void closeCompleted() override;
32 // protected:
33 void ioCompletedNotification() override;
34 void readCompleted(const char *buf, int len, int errflag, RefCount<ReadRequest>) override;
35 void writeCompleted(int errflag, size_t len, RefCount<WriteRequest>) override;
36 RefCount<DiskFile> theFile;
37 bool opening;
38 bool creating;
39 bool closing;
40 bool reading;
41 bool writing;
42 /* StoreIOState API */
43 void read_(char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data) override;
44 bool write(char const *buf, size_t size, off_t offset, FREE * free_func) override;
45
46 protected:
47 virtual void doCloseCallback (int errflag);
48
49 class _queued_read
50 {
51 MEMPROXY_CLASS(UFSStoreState::_queued_read);
52 public:
53 _queued_read(char *b, size_t s, off_t o, STRCB *cb, void *data) :
54 buf(b),
55 size(s),
56 offset(o),
57 callback(cb),
58 callback_data(cbdataReference(data))
59 {}
60 ~_queued_read() {
61 cbdataReferenceDone(callback_data);
62 }
63 _queued_read(const _queued_read &qr) = delete;
64 _queued_read &operator =(const _queued_read &qr) = delete;
65
66 char *buf;
67 size_t size;
68 off_t offset;
69 STRCB *callback;
70 void *callback_data;
71 };
72 std::queue<Ufs::UFSStoreState::_queued_read> pending_reads;
73
74 class _queued_write
75 {
76 MEMPROXY_CLASS(UFSStoreState::_queued_write);
77 public:
78 _queued_write(const char *b, size_t s, off_t o, FREE *f) :
79 buf(b),
80 size(s),
81 offset(o),
82 free_func(f)
83 {}
84 ~_queued_write() {
85 /*
86 * DPW 2006-05-24
87 * Note "free_func" is memNodeWriteComplete(), which doesn't
88 * really free the memory. Instead it clears the node's
89 * write_pending flag.
90 */
91 if (free_func && buf)
92 free_func(const_cast<char *>(buf));
93 }
94 _queued_write(const _queued_write &qr) = delete;
95 _queued_write &operator =(const _queued_write &qr) = delete;
96
97 char const *buf;
98 size_t size;
99 off_t offset;
100 FREE *free_func;
101 };
102 std::queue<Ufs::UFSStoreState::_queued_write> pending_writes;
103
104 // TODO: These should be in the IO strategy
105
106 struct {
107 /**
108 * DPW 2006-05-24
109 * the write_draining flag is used to avoid recursion inside
110 * the UFSStoreState::drainWriteQueue() method.
111 */
112 bool write_draining;
113 /**
114 * DPW 2006-05-24
115 * The try_closing flag is set by UFSStoreState::tryClosing()
116 * when UFSStoreState wants to close the file, but cannot
117 * because of pending I/Os. If set, UFSStoreState will
118 * try to close again in the I/O callbacks.
119 */
120 bool try_closing;
121 } flags;
122
123 bool kickReadQueue();
124 void drainWriteQueue();
125 void tryClosing();
126 char *read_buf;
127
128 private:
129 void openDone();
130 void freePending();
131 void doWrite();
132 };
133
134 } //namespace Ufs
135 } //namespace Fs
136
137 #endif /* SQUID_SRC_FS_UFS_UFSSTORESTATE_H */
138