]>
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
5 #include "DiskIO/DiskFile.h"
6 #include "DiskIO/IORequestor.h"
7 #include "fs/rock/RockDbCell.h"
8 #include "fs/rock/RockForward.h"
9 #include "ipc/StoreMap.h"
10 #include "ipc/mem/Page.h"
11 #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 disconnect(StoreEntry
&e
);
36 virtual uint64_t currentSize() const;
37 virtual uint64_t currentCount() const;
38 virtual bool doReportStat() const;
39 virtual void swappedOut(const StoreEntry
&e
);
40 virtual void create();
41 virtual void parse(int index
, char *path
);
43 // temporary path to the shared memory map of first slots of cached entries
44 const char *inodeMapPath() const;
45 // temporary path to the shared memory stack of free slots
46 const char *freeSlotsPath() const;
48 int64_t entryLimitHigh() const { return SwapFilenMax
; } ///< Core limit
49 int64_t entryLimitAllowed() const;
51 /// removes a slot from a list of free slots or returns false
52 bool useFreeSlot(Ipc::Mem::PageId
&pageId
);
53 /// whether the given slot ID may point to a slot in this db
54 bool validSlotId(const SlotId slotId
) const;
55 /// purges one or more entries to make full() false and free some slots
58 int64_t diskOffset(Ipc::Mem::PageId
&pageId
) const;
59 int64_t diskOffset(int filen
) const;
60 void writeError(const sfileno fileno
);
62 /* StoreMapCleaner API */
63 virtual void noteFreeMapSlice(const sfileno fileno
);
65 uint64_t slotSize
; ///< all db slots are of this size
68 /* protected ::SwapDir API */
69 virtual bool needsDiskStrand() const;
71 virtual ConfigOption
*getOptionTree() const;
72 virtual bool allowOptionReconfigure(const char *const option
) const;
73 virtual bool canStore(const StoreEntry
&e
, int64_t diskSpaceNeeded
, int &load
) const;
74 virtual StoreIOState::Pointer
createStoreIO(StoreEntry
&, StoreIOState::STFNCB
*, StoreIOState::STIOCB
*, void *);
75 virtual StoreIOState::Pointer
openStoreIO(StoreEntry
&, StoreIOState::STFNCB
*, StoreIOState::STIOCB
*, void *);
76 virtual void maintain();
77 virtual void diskFull();
78 virtual void reference(StoreEntry
&e
);
79 virtual bool dereference(StoreEntry
&e
, bool);
80 virtual bool unlinkdUseful() const;
81 virtual void unlink(StoreEntry
&e
);
82 virtual void statfs(StoreEntry
&e
) const;
85 virtual void ioCompletedNotification();
86 virtual void closeCompleted();
87 virtual void readCompleted(const char *buf
, int len
, int errflag
, RefCount
< ::ReadRequest
>);
88 virtual void writeCompleted(int errflag
, size_t len
, RefCount
< ::WriteRequest
>);
90 void parseSize(const bool reconfiguring
); ///< parses anonymous cache_dir size option
91 void validateOptions(); ///< warns of configuration problems; may quit
92 bool parseTimeOption(char const *option
, const char *value
, int reconfiguring
);
93 void dumpTimeOption(StoreEntry
* e
) const;
94 bool parseRateOption(char const *option
, const char *value
, int reconfiguring
);
95 void dumpRateOption(StoreEntry
* e
) const;
96 bool parseSizeOption(char const *option
, const char *value
, int reconfiguring
);
97 void dumpSizeOption(StoreEntry
* e
) const;
99 void rebuild(); ///< starts loading and validating stored entry metadata
101 bool full() const; ///< no more entries can be stored without purging
102 void trackReferences(StoreEntry
&e
); ///< add to replacement policy scope
103 void ignoreReferences(StoreEntry
&e
); ///< delete from repl policy scope
105 int64_t diskOffsetLimit() const;
106 int entryLimit() const { return map
->entryLimit(); }
107 int entryMaxPayloadSize() const;
108 int entriesNeeded(const int64_t objSize
) const;
110 friend class Rebuild
;
111 friend class IoState
;
112 const char *filePath
; ///< location of cache storage file inside path/
113 DirMap
*map
; ///< entry key/sfileno to MaxExtras/inode mapping
116 void createError(const char *const msg
);
119 RefCount
<DiskFile
> theFile
; ///< cache storage for this cache_dir
120 Ipc::Mem::Pointer
<Ipc::Mem::PageStack
> freeSlots
; ///< all unused slots
121 Ipc::Mem::PageId
*waitingForPage
; ///< one-page cache for a "hot" free slot
123 /* configurable options */
124 DiskFile::Config fileConfig
; ///< file-level configuration options
126 static const int64_t HeaderSize
; ///< on-disk db header size
129 /// initializes shared memory segments used by Rock::SwapDir
130 class SwapDirRr
: public Ipc::Mem::RegisteredRunner
133 /* ::RegisteredRunner API */
134 virtual ~SwapDirRr();
137 /* Ipc::Mem::RegisteredRunner API */
138 virtual void create(const RunnerRegistry
&);
141 Vector
<SwapDir::DirMap::Owner
*> mapOwners
;
142 Vector
< Ipc::Mem::Owner
<Ipc::Mem::PageStack
> *> freeSlotsOwners
;
147 #endif /* SQUID_FS_ROCK_SWAP_DIR_H */