]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/ufs/UFSStoreState.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / fs / ufs / UFSStoreState.h
1 /*
2 * Copyright (C) 1996-2016 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_UFS_UFSSTORESTATE_H
10 #define SQUID_FS_UFS_UFSSTORESTATE_H
11
12 #include "DiskIO/IORequestor.h"
13 #include "SquidList.h"
14 #include "StoreIOState.h"
15
16 namespace Fs
17 {
18 namespace Ufs
19 {
20
21 class UFSStoreState : public StoreIOState, public IORequestor
22 {
23 CBDATA_CLASS(UFSStoreState);
24
25 public:
26 UFSStoreState(SwapDir * SD, StoreEntry * anEntry, STIOCB * callback_, void *callback_data_);
27 ~UFSStoreState();
28 virtual void close(int how);
29 virtual void closeCompleted();
30 // protected:
31 virtual void ioCompletedNotification();
32 virtual void readCompleted(const char *buf, int len, int errflag, RefCount<ReadRequest>);
33 virtual void writeCompleted(int errflag, size_t len, RefCount<WriteRequest>);
34 RefCount<DiskFile> theFile;
35 bool opening;
36 bool creating;
37 bool closing;
38 bool reading;
39 bool writing;
40 /* StoreIOState API */
41 void read_(char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data);
42 virtual bool write(char const *buf, size_t size, off_t offset, FREE * free_func);
43
44 protected:
45 virtual void doCloseCallback (int errflag);
46
47 class _queued_read
48 {
49 MEMPROXY_CLASS(UFSStoreState::_queued_read);
50 public:
51 _queued_read() :
52 buf(nullptr),
53 size(0),
54 offset(0),
55 callback(nullptr),
56 callback_data(nullptr)
57 {}
58
59 char *buf;
60 size_t size;
61 off_t offset;
62 STRCB *callback;
63 void *callback_data;
64 };
65
66 class _queued_write
67 {
68 MEMPROXY_CLASS(UFSStoreState::_queued_write);
69 public:
70 _queued_write() :
71 buf(nullptr),
72 size(0),
73 offset(0),
74 free_func(nullptr)
75 {}
76
77 char const *buf;
78 size_t size;
79 off_t offset;
80 FREE *free_func;
81 };
82
83 /** \todo These should be in the IO strategy */
84
85 struct {
86 /**
87 * DPW 2006-05-24
88 * the write_draining flag is used to avoid recursion inside
89 * the UFSStoreState::drainWriteQueue() method.
90 */
91 bool write_draining;
92 /**
93 * DPW 2006-05-24
94 * The try_closing flag is set by UFSStoreState::tryClosing()
95 * when UFSStoreState wants to close the file, but cannot
96 * because of pending I/Os. If set, UFSStoreState will
97 * try to close again in the I/O callbacks.
98 */
99 bool try_closing;
100 } flags;
101 link_list *pending_reads;
102 link_list *pending_writes;
103 void queueRead(char *, size_t, off_t, STRCB *, void *);
104 void queueWrite(char const *, size_t, off_t, FREE *);
105 bool kickReadQueue();
106 void drainWriteQueue();
107 void tryClosing();
108 char *read_buf;
109
110 private:
111 void openDone();
112 void freePending();
113 void doWrite();
114 };
115
116 } //namespace Ufs
117 } //namespace Fs
118
119 #endif /* SQUID_FS_UFS_UFSSTORESTATE_H */
120