]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/rock/RockSwapDir.h
1 #ifndef SQUID_FS_ROCK_SWAP_DIR_H
2 #define SQUID_FS_ROCK_SWAP_DIR_H
4 #include "DiskIO/DiskFile.h"
5 #include "DiskIO/IORequestor.h"
6 #include "fs/rock/RockDbCell.h"
7 #include "fs/rock/RockForward.h"
8 #include "ipc/StoreMap.h"
9 #include "ipc/mem/Page.h"
10 #include "ipc/mem/PageStack.h"
21 class SwapDir
: public ::SwapDir
, public IORequestor
, public Ipc::StoreMapCleaner
24 typedef RefCount
<SwapDir
> Pointer
;
25 typedef Ipc::StoreMap DirMap
;
30 /* public ::SwapDir API */
31 virtual void reconfigure();
32 virtual StoreSearch
*search(String
const url
, HttpRequest
*);
33 virtual StoreEntry
*get(const cache_key
*key
);
34 virtual void get(String
const, STOREGETCLIENT
, void * cbdata
);
35 virtual void markForUnlink(StoreEntry
&e
);
36 virtual void disconnect(StoreEntry
&e
);
37 virtual uint64_t currentSize() const;
38 virtual uint64_t currentCount() const;
39 virtual bool doReportStat() const;
40 virtual void swappedOut(const StoreEntry
&e
);
41 virtual void create();
42 virtual void parse(int index
, char *path
);
44 // temporary path to the shared memory map of first slots of cached entries
45 const char *inodeMapPath() const;
46 // temporary path to the shared memory stack of free slots
47 const char *freeSlotsPath() const;
49 int64_t entryLimitHigh() const { return SwapFilenMax
; } ///< Core limit
50 int64_t entryLimitAllowed() const;
52 /// removes a slot from a list of free slots or returns false
53 bool useFreeSlot(Ipc::Mem::PageId
&pageId
);
54 /// whether the given slot ID may point to a slot in this db
55 bool validSlotId(const SlotId slotId
) const;
56 /// purges one or more entries to make full() false and free some slots
59 int64_t diskOffset(Ipc::Mem::PageId
&pageId
) const;
60 int64_t diskOffset(int filen
) const;
61 void writeError(StoreEntry
&e
);
63 /* StoreMapCleaner API */
64 virtual void noteFreeMapSlice(const sfileno fileno
);
66 uint64_t slotSize
; ///< all db slots are of this size
70 virtual bool anchorCollapsed(StoreEntry
&collapsed
, bool &inSync
);
71 virtual bool updateCollapsed(StoreEntry
&collapsed
);
73 /* protected ::SwapDir API */
74 virtual bool needsDiskStrand() const;
76 virtual ConfigOption
*getOptionTree() const;
77 virtual bool allowOptionReconfigure(const char *const option
) const;
78 virtual bool canStore(const StoreEntry
&e
, int64_t diskSpaceNeeded
, int &load
) const;
79 virtual StoreIOState::Pointer
createStoreIO(StoreEntry
&, StoreIOState::STFNCB
*, StoreIOState::STIOCB
*, void *);
80 virtual StoreIOState::Pointer
openStoreIO(StoreEntry
&, StoreIOState::STFNCB
*, StoreIOState::STIOCB
*, void *);
81 virtual void maintain();
82 virtual void diskFull();
83 virtual void reference(StoreEntry
&e
);
84 virtual bool dereference(StoreEntry
&e
, bool);
85 virtual bool unlinkdUseful() const;
86 virtual void unlink(StoreEntry
&e
);
87 virtual void statfs(StoreEntry
&e
) const;
90 virtual void ioCompletedNotification();
91 virtual void closeCompleted();
92 virtual void readCompleted(const char *buf
, int len
, int errflag
, RefCount
< ::ReadRequest
>);
93 virtual void writeCompleted(int errflag
, size_t len
, RefCount
< ::WriteRequest
>);
95 void parseSize(const bool reconfiguring
); ///< parses anonymous cache_dir size option
96 void validateOptions(); ///< warns of configuration problems; may quit
97 bool parseTimeOption(char const *option
, const char *value
, int reconfiguring
);
98 void dumpTimeOption(StoreEntry
* e
) const;
99 bool parseRateOption(char const *option
, const char *value
, int reconfiguring
);
100 void dumpRateOption(StoreEntry
* e
) const;
101 bool parseSizeOption(char const *option
, const char *value
, int reconfiguring
);
102 void dumpSizeOption(StoreEntry
* e
) const;
104 void rebuild(); ///< starts loading and validating stored entry metadata
106 bool full() const; ///< no more entries can be stored without purging
107 void trackReferences(StoreEntry
&e
); ///< add to replacement policy scope
108 void ignoreReferences(StoreEntry
&e
); ///< delete from repl policy scope
110 int64_t diskOffsetLimit() const;
111 int entryLimit() const { return map
->entryLimit(); }
112 int entryMaxPayloadSize() const;
113 int entriesNeeded(const int64_t objSize
) const;
115 void anchorEntry(StoreEntry
&e
, const sfileno filen
, const Ipc::StoreMapAnchor
&anchor
);
116 bool updateCollapsedWith(StoreEntry
&collapsed
, const Ipc::StoreMapAnchor
&anchor
);
118 friend class Rebuild
;
119 friend class IoState
;
120 const char *filePath
; ///< location of cache storage file inside path/
121 DirMap
*map
; ///< entry key/sfileno to MaxExtras/inode mapping
124 void createError(const char *const msg
);
127 RefCount
<DiskFile
> theFile
; ///< cache storage for this cache_dir
128 Ipc::Mem::Pointer
<Ipc::Mem::PageStack
> freeSlots
; ///< all unused slots
129 Ipc::Mem::PageId
*waitingForPage
; ///< one-page cache for a "hot" free slot
131 /* configurable options */
132 DiskFile::Config fileConfig
; ///< file-level configuration options
134 static const int64_t HeaderSize
; ///< on-disk db header size
137 /// initializes shared memory segments used by Rock::SwapDir
138 class SwapDirRr
: public Ipc::Mem::RegisteredRunner
141 /* ::RegisteredRunner API */
142 virtual ~SwapDirRr();
145 /* Ipc::Mem::RegisteredRunner API */
146 virtual void create(const RunnerRegistry
&);
149 Vector
<SwapDir::DirMap::Owner
*> mapOwners
;
150 Vector
< Ipc::Mem::Owner
<Ipc::Mem::PageStack
> *> freeSlotsOwners
;
155 #endif /* SQUID_FS_ROCK_SWAP_DIR_H */