]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/rock/RockSwapDir.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / fs / rock / RockSwapDir.h
1 #ifndef SQUID_FS_ROCK_SWAP_DIR_H
2 #define SQUID_FS_ROCK_SWAP_DIR_H
3
4 #include "DiskIO/DiskFile.h"
5 #include "DiskIO/IORequestor.h"
6 #include "fs/rock/RockDbCell.h"
7 #include "ipc/StoreMap.h"
8 #include "SwapDir.h"
9
10 class DiskIOStrategy;
11 class ReadRequest;
12 class WriteRequest;
13
14 namespace Rock
15 {
16
17 class Rebuild;
18
19 /// \ingroup Rock
20 class SwapDir: public ::SwapDir, public IORequestor
21 {
22 public:
23 SwapDir();
24 virtual ~SwapDir();
25
26 /* public ::SwapDir API */
27 virtual void reconfigure();
28 virtual StoreSearch *search(String const url, HttpRequest *);
29 virtual StoreEntry *get(const cache_key *key);
30 virtual void get(String const, STOREGETCLIENT, void * cbdata);
31 virtual void disconnect(StoreEntry &e);
32 virtual uint64_t currentSize() const;
33 virtual uint64_t currentCount() const;
34 virtual bool doReportStat() const;
35 virtual void swappedOut(const StoreEntry &e);
36 virtual void create();
37 virtual void parse(int index, char *path);
38
39 int64_t entryLimitHigh() const { return SwapFilenMax; } ///< Core limit
40 int64_t entryLimitAllowed() const;
41
42 typedef Ipc::StoreMapWithExtras<DbCellHeader> DirMap;
43
44 protected:
45 /* protected ::SwapDir API */
46 virtual bool needsDiskStrand() const;
47 virtual void init();
48 virtual ConfigOption *getOptionTree() const;
49 virtual bool allowOptionReconfigure(const char *const option) const;
50 virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const;
51 virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
52 virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
53 virtual void maintain();
54 virtual void diskFull();
55 virtual void reference(StoreEntry &e);
56 virtual bool dereference(StoreEntry &e, bool);
57 virtual bool unlinkdUseful() const;
58 virtual void unlink(StoreEntry &e);
59 virtual void statfs(StoreEntry &e) const;
60
61 /* IORequestor API */
62 virtual void ioCompletedNotification();
63 virtual void closeCompleted();
64 virtual void readCompleted(const char *buf, int len, int errflag, RefCount< ::ReadRequest>);
65 virtual void writeCompleted(int errflag, size_t len, RefCount< ::WriteRequest>);
66
67 void parseSize(const bool reconfiguring); ///< parses anonymous cache_dir size option
68 void validateOptions(); ///< warns of configuration problems; may quit
69 bool parseTimeOption(char const *option, const char *value, int reconfiguring);
70 void dumpTimeOption(StoreEntry * e) const;
71 bool parseRateOption(char const *option, const char *value, int reconfiguring);
72 void dumpRateOption(StoreEntry * e) const;
73
74 void rebuild(); ///< starts loading and validating stored entry metadata
75 ///< used to add entries successfully loaded during rebuild
76 bool addEntry(const int fileno, const DbCellHeader &header, const StoreEntry &from);
77
78 bool full() const; ///< no more entries can be stored without purging
79 void trackReferences(StoreEntry &e); ///< add to replacement policy scope
80 void ignoreReferences(StoreEntry &e); ///< delete from repl policy scope
81
82 int64_t diskOffset(int filen) const;
83 int64_t diskOffsetLimit() const;
84 int entryLimit() const { return map->entryLimit(); }
85
86 friend class Rebuild;
87 const char *filePath; ///< location of cache storage file inside path/
88
89 private:
90 DiskIOStrategy *io;
91 RefCount<DiskFile> theFile; ///< cache storage for this cache_dir
92 DirMap *map;
93
94 /* configurable options */
95 DiskFile::Config fileConfig; ///< file-level configuration options
96
97 static const int64_t HeaderSize; ///< on-disk db header size
98 };
99
100 /// initializes shared memory segments used by Rock::SwapDir
101 class SwapDirRr: public Ipc::Mem::RegisteredRunner
102 {
103 public:
104 /* ::RegisteredRunner API */
105 virtual ~SwapDirRr();
106
107 protected:
108 /* Ipc::Mem::RegisteredRunner API */
109 virtual void create(const RunnerRegistry &);
110
111 private:
112 Vector<SwapDir::DirMap::Owner *> owners;
113 };
114
115 } // namespace Rock
116
117 #endif /* SQUID_FS_ROCK_SWAP_DIR_H */