]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/store/Disk.h
2 * Copyright (C) 1996-2016 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_STORE_DISK_H
10 #define SQUID_STORE_DISK_H
12 #include "store/Controlled.h"
13 #include "StoreIOState.h"
20 /// manages a single cache_dir
21 class Disk
: public Controlled
25 typedef RefCount
<Disk
> Pointer
;
27 explicit Disk(char const *aType
);
29 virtual void reconfigure() = 0;
30 char const *type() const;
32 virtual bool needsDiskStrand() const; ///< needs a dedicated kid process
33 virtual bool active() const; ///< may be used in this strand
34 /// whether stat should be reported by this SwapDir
35 virtual bool doReportStat() const { return active(); }
36 /// whether SwapDir may benefit from unlinkd
37 virtual bool unlinkdUseful() const = 0;
40 * Notify this disk that it is full.
41 \todo XXX move into a protected api call between store files and their stores, rather than a top level api call
43 virtual void diskFull();
46 virtual void create() override
;
47 virtual StoreEntry
*get(const cache_key
*) override
;
48 virtual uint64_t maxSize() const override
{ return max_size
; }
49 virtual uint64_t minSize() const override
;
50 virtual int64_t maxObjectSize() const override
;
51 virtual void getStats(StoreInfoStats
&stats
) const override
;
52 virtual void stat(StoreEntry
&) const override
;
53 virtual void reference(StoreEntry
&e
) override
;
54 virtual bool dereference(StoreEntry
&e
) override
;
55 virtual void maintain() override
;
56 virtual bool smpAware() const override
{ return false; }
58 /// the size of the smallest entry this cache_dir can store
59 int64_t minObjectSize() const;
61 /// configure the maximum object size for this storage area.
62 /// May be any size up to the total storage area.
63 void maxObjectSize(int64_t newMax
);
65 /// whether we can store an object of the given size
66 /// negative objSize means the object size is currently unknown
67 bool objectSizeIsAcceptable(int64_t objSize
) const;
69 /// called when the entry is about to forget its association with cache_dir
70 virtual void disconnect(StoreEntry
&) {}
72 /// called when entry swap out is complete
73 virtual void swappedOut(const StoreEntry
&e
) = 0;
76 void parseOptions(int reconfiguring
);
77 void dumpOptions(StoreEntry
* e
) const;
78 virtual ConfigOption
*getOptionTree() const;
79 virtual bool allowOptionReconfigure(const char *const) const { return true; }
81 int64_t sizeInBlocks(const int64_t size
) const { return (size
+ fs
.blksize
- 1) / fs
.blksize
; }
84 bool optionReadOnlyParse(char const *option
, const char *value
, int reconfiguring
);
85 void optionReadOnlyDump(StoreEntry
* e
) const;
86 bool optionObjectSizeParse(char const *option
, const char *value
, int reconfiguring
);
87 void optionObjectSizeDump(StoreEntry
* e
) const;
91 uint64_t max_size
; ///< maximum allocatable size of the storage area
92 int64_t min_objsize
; ///< minimum size of any object stored here (-1 for no limit)
93 int64_t max_objsize
; ///< maximum size of any object stored here (-1 for no limit)
97 int index
; /* This entry's index into the swapDirs array */
98 int disker
; ///< disker kid id dedicated to this SwapDir or -1
104 Flags() : selected(false), read_only(false) {}
109 virtual void dump(StoreEntry
&)const; /* Dump fs config snippet */
110 virtual bool doubleCheck(StoreEntry
&); /* Double check the obj integrity */
111 virtual void statfs(StoreEntry
&) const; /* Dump fs statistics */
113 /// check whether we can store the entry; if we can, report current load
114 virtual bool canStore(const StoreEntry
&e
, int64_t diskSpaceNeeded
, int &load
) const = 0;
116 virtual StoreIOState::Pointer
createStoreIO(StoreEntry
&, StoreIOState::STFNCB
*, StoreIOState::STIOCB
*, void *) = 0;
117 virtual StoreIOState::Pointer
openStoreIO(StoreEntry
&, StoreIOState::STFNCB
*, StoreIOState::STIOCB
*, void *) = 0;
119 bool canLog(StoreEntry
const &e
)const;
120 virtual void openLog();
121 virtual void closeLog();
122 virtual void logEntry(const StoreEntry
& e
, int op
) const;
128 virtual ~CleanLog() {}
130 virtual const StoreEntry
*nextEntry() = 0;
131 virtual void write(StoreEntry
const &) = 0;
135 virtual int writeCleanStart();
136 virtual void writeCleanDone();
137 virtual void parse(int index
, char *path
) = 0;
146 #endif /* SQUID_STORE_DISK_H */