]> git.ipfire.org Git - thirdparty/squid.git/blob - src/store/Disk.h
be8c3ee082f3ceac7922381c3863356feafec473
[thirdparty/squid.git] / src / store / Disk.h
1 /*
2 * Copyright (C) 1996-2016 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 class ConfigOption;
16 class RemovalPolicy;
17
18 namespace Store {
19
20 /// manages a single cache_dir
21 class Disk: public Controlled
22 {
23
24 public:
25 typedef RefCount<Disk> Pointer;
26
27 explicit Disk(char const *aType);
28 virtual ~Disk();
29 virtual void reconfigure() = 0;
30 char const *type() const;
31
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;
38
39 /**
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
42 */
43 virtual void diskFull();
44
45 /* Controlled API */
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; }
57
58 /// the size of the smallest entry this cache_dir can store
59 int64_t minObjectSize() const;
60
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);
64
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;
68
69 /// called when the entry is about to forget its association with cache_dir
70 virtual void disconnect(StoreEntry &) {}
71
72 /// called when entry swap out is complete
73 virtual void swappedOut(const StoreEntry &e) = 0;
74
75 protected:
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; }
80
81 int64_t sizeInBlocks(const int64_t size) const { return (size + fs.blksize - 1) / fs.blksize; }
82
83 private:
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;
88 char const *theType;
89
90 protected:
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)
94
95 public:
96 char *path;
97 int index; /* This entry's index into the swapDirs array */
98 int disker; ///< disker kid id dedicated to this SwapDir or -1
99 RemovalPolicy *repl;
100 int removals;
101 int scanned;
102
103 struct Flags {
104 Flags() : selected(false), read_only(false) {}
105 bool selected;
106 bool read_only;
107 } flags;
108
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 */
112
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;
115
116 virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *) = 0;
117 virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *) = 0;
118
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;
123
124 class CleanLog
125 {
126
127 public:
128 virtual ~CleanLog() {}
129
130 virtual const StoreEntry *nextEntry() = 0;
131 virtual void write(StoreEntry const &) = 0;
132 };
133
134 CleanLog *cleanLog;
135 virtual int writeCleanStart();
136 virtual void writeCleanDone();
137 virtual void parse(int index, char *path) = 0;
138
139 struct {
140 int blksize;
141 } fs;
142 };
143
144 } // namespace Store
145
146 #endif /* SQUID_STORE_DISK_H */
147