]> git.ipfire.org Git - thirdparty/squid.git/blob - src/store/Disk.h
Store API and layout polishing. No functionality changes intended.
[thirdparty/squid.git] / src / store / Disk.h
1 /*
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 #ifndef SQUID_STORE_DISK_H
10 #define SQUID_STORE_DISK_H
11
12 #include "store/Controlled.h"
13 #include "StoreIOState.h"
14
15
16 class ConfigOption;
17 class RemovalPolicy;
18
19 namespace Store {
20
21 /// manages a single cache_dir
22 class Disk: public Controlled
23 {
24
25 public:
26 typedef RefCount<Disk> Pointer;
27
28 explicit Disk(char const *aType);
29 virtual ~Disk();
30 virtual void reconfigure() = 0;
31 char const *type() const;
32
33 virtual bool needsDiskStrand() const; ///< needs a dedicated kid process
34 virtual bool active() const; ///< may be used in this strand
35 /// whether stat should be reported by this SwapDir
36 virtual bool doReportStat() const { return active(); }
37 /// whether SwapDir may benefit from unlinkd
38 virtual bool unlinkdUseful() const = 0;
39
40 /**
41 * Notify this disk that it is full.
42 \todo XXX move into a protected api call between store files and their stores, rather than a top level api call
43 */
44 virtual void diskFull();
45
46 /* Controlled API */
47 virtual void create() override;
48 virtual StoreEntry *get(const cache_key *) override;
49 virtual uint64_t maxSize() const override { return max_size; }
50 virtual uint64_t minSize() const override;
51 virtual int64_t maxObjectSize() const override;
52 virtual void getStats(StoreInfoStats &stats) const override;
53 virtual void stat(StoreEntry &) const override;
54 virtual void reference(StoreEntry &e) override;
55 virtual bool dereference(StoreEntry &e) override;
56 virtual void maintain() override;
57
58 /// configure the maximum object size for this storage area.
59 /// May be any size up to the total storage area.
60 void maxObjectSize(int64_t newMax);
61
62 /// whether we can store an object of the given size
63 /// negative objSize means the object size is currently unknown
64 bool objectSizeIsAcceptable(int64_t objSize) const;
65
66 /// called when the entry is about to forget its association with cache_dir
67 virtual void disconnect(StoreEntry &) {}
68
69 /// called when entry swap out is complete
70 virtual void swappedOut(const StoreEntry &e) = 0;
71
72 protected:
73 void parseOptions(int reconfiguring);
74 void dumpOptions(StoreEntry * e) const;
75 virtual ConfigOption *getOptionTree() const;
76 virtual bool allowOptionReconfigure(const char *const) const { return true; }
77
78 int64_t sizeInBlocks(const int64_t size) const { return (size + fs.blksize - 1) / fs.blksize; }
79
80 private:
81 bool optionReadOnlyParse(char const *option, const char *value, int reconfiguring);
82 void optionReadOnlyDump(StoreEntry * e) const;
83 bool optionObjectSizeParse(char const *option, const char *value, int reconfiguring);
84 void optionObjectSizeDump(StoreEntry * e) const;
85 char const *theType;
86
87 protected:
88 uint64_t max_size; ///< maximum allocatable size of the storage area
89 int64_t min_objsize; ///< minimum size of any object stored here (-1 for no limit)
90 int64_t max_objsize; ///< maximum size of any object stored here (-1 for no limit)
91
92 public:
93 char *path;
94 int index; /* This entry's index into the swapDirs array */
95 int disker; ///< disker kid id dedicated to this SwapDir or -1
96 RemovalPolicy *repl;
97 int removals;
98 int scanned;
99
100 struct Flags {
101 Flags() : selected(false), read_only(false) {}
102 bool selected;
103 bool read_only;
104 } flags;
105
106 virtual void dump(StoreEntry &)const; /* Dump fs config snippet */
107 virtual bool doubleCheck(StoreEntry &); /* Double check the obj integrity */
108 virtual void statfs(StoreEntry &) const; /* Dump fs statistics */
109
110 /// check whether we can store the entry; if we can, report current load
111 virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const = 0;
112
113 virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *) = 0;
114 virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *) = 0;
115
116 bool canLog(StoreEntry const &e)const;
117 virtual void openLog();
118 virtual void closeLog();
119 virtual void logEntry(const StoreEntry & e, int op) const;
120
121 class CleanLog
122 {
123
124 public:
125 virtual ~CleanLog() {}
126
127 virtual const StoreEntry *nextEntry() = 0;
128 virtual void write(StoreEntry const &) = 0;
129 };
130
131 CleanLog *cleanLog;
132 virtual int writeCleanStart();
133 virtual void writeCleanDone();
134 virtual void parse(int index, char *path) = 0;
135
136 struct {
137 int blksize;
138 } fs;
139 };
140
141 } // namespace Store
142
143 #endif /* SQUID_STORE_DISK_H */
144