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