]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/rock/RockSwapDir.h
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_FS_ROCK_SWAP_DIR_H
10 #define SQUID_FS_ROCK_SWAP_DIR_H
12 #include "DiskIO/DiskFile.h"
13 #include "DiskIO/IORequestor.h"
14 #include "fs/rock/RockDbCell.h"
15 #include "fs/rock/RockForward.h"
16 #include "ipc/mem/Page.h"
17 #include "ipc/mem/PageStack.h"
18 #include "ipc/StoreMap.h"
29 class SwapDir
: public ::SwapDir
, public IORequestor
, public Ipc::StoreMapCleaner
32 typedef RefCount
<SwapDir
> Pointer
;
33 typedef Ipc::StoreMap DirMap
;
38 /* public ::SwapDir API */
39 virtual void reconfigure();
40 virtual StoreSearch
*search(String
const url
, HttpRequest
*);
41 virtual StoreEntry
*get(const cache_key
*key
);
42 virtual void get(String
const, STOREGETCLIENT
, void * cbdata
);
43 virtual void markForUnlink(StoreEntry
&e
);
44 virtual void disconnect(StoreEntry
&e
);
45 virtual uint64_t currentSize() const;
46 virtual uint64_t currentCount() const;
47 virtual bool doReportStat() const;
48 virtual void swappedOut(const StoreEntry
&e
);
49 virtual void create();
50 virtual void parse(int index
, char *path
);
52 // temporary path to the shared memory map of first slots of cached entries
53 SBuf
inodeMapPath() const;
54 // temporary path to the shared memory stack of free slots
55 const char *freeSlotsPath() const;
57 int64_t entryLimitAbsolute() const { return SwapFilenMax
+1; } ///< Core limit
58 int64_t entryLimitActual() const; ///< max number of possible entries in db
59 int64_t slotLimitAbsolute() const; ///< Rock store implementation limit
60 int64_t slotLimitActual() const; ///< total number of slots in this db
62 /// removes a slot from a list of free slots or returns false
63 bool useFreeSlot(Ipc::Mem::PageId
&pageId
);
64 /// whether the given slot ID may point to a slot in this db
65 bool validSlotId(const SlotId slotId
) const;
66 /// purges one or more entries to make full() false and free some slots
69 int64_t diskOffset(Ipc::Mem::PageId
&pageId
) const;
70 int64_t diskOffset(int filen
) const;
71 void writeError(StoreEntry
&e
);
73 /* StoreMapCleaner API */
74 virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId fileno
);
76 uint64_t slotSize
; ///< all db slots are of this size
80 virtual bool anchorCollapsed(StoreEntry
&collapsed
, bool &inSync
);
81 virtual bool updateCollapsed(StoreEntry
&collapsed
);
83 /* protected ::SwapDir API */
84 virtual bool needsDiskStrand() const;
86 virtual ConfigOption
*getOptionTree() const;
87 virtual bool allowOptionReconfigure(const char *const option
) const;
88 virtual bool canStore(const StoreEntry
&e
, int64_t diskSpaceNeeded
, int &load
) const;
89 virtual StoreIOState::Pointer
createStoreIO(StoreEntry
&, StoreIOState::STFNCB
*, StoreIOState::STIOCB
*, void *);
90 virtual StoreIOState::Pointer
openStoreIO(StoreEntry
&, StoreIOState::STFNCB
*, StoreIOState::STIOCB
*, void *);
91 virtual void maintain();
92 virtual void diskFull();
93 virtual void reference(StoreEntry
&e
);
94 virtual bool dereference(StoreEntry
&e
, bool);
95 virtual bool unlinkdUseful() const;
96 virtual void unlink(StoreEntry
&e
);
97 virtual void statfs(StoreEntry
&e
) const;
100 virtual void ioCompletedNotification();
101 virtual void closeCompleted();
102 virtual void readCompleted(const char *buf
, int len
, int errflag
, RefCount
< ::ReadRequest
>);
103 virtual void writeCompleted(int errflag
, size_t len
, RefCount
< ::WriteRequest
>);
105 void parseSize(const bool reconfiguring
); ///< parses anonymous cache_dir size option
106 void validateOptions(); ///< warns of configuration problems; may quit
107 bool parseTimeOption(char const *option
, const char *value
, int reconfiguring
);
108 void dumpTimeOption(StoreEntry
* e
) const;
109 bool parseRateOption(char const *option
, const char *value
, int reconfiguring
);
110 void dumpRateOption(StoreEntry
* e
) const;
111 bool parseSizeOption(char const *option
, const char *value
, int reconfiguring
);
112 void dumpSizeOption(StoreEntry
* e
) const;
114 void rebuild(); ///< starts loading and validating stored entry metadata
116 bool full() const; ///< no more entries can be stored without purging
117 void trackReferences(StoreEntry
&e
); ///< add to replacement policy scope
118 void ignoreReferences(StoreEntry
&e
); ///< delete from repl policy scope
120 int64_t diskOffsetLimit() const;
122 void anchorEntry(StoreEntry
&e
, const sfileno filen
, const Ipc::StoreMapAnchor
&anchor
);
123 bool updateCollapsedWith(StoreEntry
&collapsed
, const Ipc::StoreMapAnchor
&anchor
);
125 friend class Rebuild
;
126 friend class IoState
;
127 const char *filePath
; ///< location of cache storage file inside path/
128 DirMap
*map
; ///< entry key/sfileno to MaxExtras/inode mapping
131 void createError(const char *const msg
);
134 RefCount
<DiskFile
> theFile
; ///< cache storage for this cache_dir
135 Ipc::Mem::Pointer
<Ipc::Mem::PageStack
> freeSlots
; ///< all unused slots
136 Ipc::Mem::PageId
*waitingForPage
; ///< one-page cache for a "hot" free slot
138 /* configurable options */
139 DiskFile::Config fileConfig
; ///< file-level configuration options
141 static const int64_t HeaderSize
; ///< on-disk db header size
144 /// initializes shared memory segments used by Rock::SwapDir
145 class SwapDirRr
: public Ipc::Mem::RegisteredRunner
148 /* ::RegisteredRunner API */
149 virtual ~SwapDirRr();
152 /* Ipc::Mem::RegisteredRunner API */
153 virtual void create();
156 std::vector
<SwapDir::DirMap::Owner
*> mapOwners
;
157 std::vector
< Ipc::Mem::Owner
<Ipc::Mem::PageStack
> *> freeSlotsOwners
;
162 #endif /* SQUID_FS_ROCK_SWAP_DIR_H */