Disk.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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_SRC_STORE_DISK_H
10 #define SQUID_SRC_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 
21 class Disk: public Controlled
22 {
23 
24 public:
26 
27  explicit Disk(char const *aType);
28  ~Disk() override;
29  virtual void reconfigure() = 0;
30  char const *type() const;
31 
32  virtual bool needsDiskStrand() const;
33  virtual bool active() const;
34  virtual bool doReportStat() const { return active(); }
37  virtual bool unlinkdUseful() const = 0;
38 
43  virtual void diskFull();
44 
45  /* Controlled API */
46  void create() override;
47  StoreEntry *get(const cache_key *) override;
48  uint64_t maxSize() const override { return max_size; }
49  uint64_t minSize() const override;
50  int64_t maxObjectSize() const override;
51  void getStats(StoreInfoStats &stats) const override;
52  void stat(StoreEntry &) const override;
53  void reference(StoreEntry &e) override;
54  bool dereference(StoreEntry &e) override;
55  void maintain() override;
57  virtual bool smpAware() const = 0;
58 
60  int64_t minObjectSize() const;
61 
64  void maxObjectSize(int64_t newMax);
65 
68  bool objectSizeIsAcceptable(int64_t objSize) const;
69 
71  virtual void disconnect(StoreEntry &) {}
72 
74  virtual void finalizeSwapoutSuccess(const StoreEntry &) = 0;
76  virtual void finalizeSwapoutFailure(StoreEntry &) = 0;
77 
79  virtual bool hasReadableEntry(const StoreEntry &e) const = 0;
80 
81 protected:
82  void parseOptions(int reconfiguring);
83  void dumpOptions(StoreEntry * e) const;
84  virtual ConfigOption *getOptionTree() const;
85  virtual bool allowOptionReconfigure(const char *const) const { return true; }
86 
87  int64_t sizeInBlocks(const int64_t size) const { return (size + fs.blksize - 1) / fs.blksize; }
88 
89 private:
90  bool optionReadOnlyParse(char const *option, const char *value, int reconfiguring);
91  void optionReadOnlyDump(StoreEntry * e) const;
92  bool optionObjectSizeParse(char const *option, const char *value, int reconfiguring);
93  void optionObjectSizeDump(StoreEntry * e) const;
94  char const *theType;
95 
96 protected:
97  uint64_t max_size;
98  int64_t min_objsize;
99  int64_t max_objsize;
100 
101 public:
102  char *path;
103  int index; /* This entry's index into the swapDirs array */
104  int disker;
106  int removals;
107  int scanned;
108 
109  struct Flags {
110  Flags() : selected(false), read_only(false) {}
111  bool selected;
112  bool read_only;
113  } flags;
114 
115  virtual void dump(StoreEntry &)const; /* Dump fs config snippet */
116  virtual bool doubleCheck(StoreEntry &); /* Double check the obj integrity */
117  virtual void statfs(StoreEntry &) const; /* Dump fs statistics */
118 
120  virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const = 0;
121 
124 
125  bool canLog(StoreEntry const &e)const;
126  virtual void openLog();
127  virtual void closeLog();
128  virtual void logEntry(const StoreEntry & e, int op) const;
129 
130  class CleanLog
131  {
132 
133  public:
134  virtual ~CleanLog() {}
135 
136  virtual const StoreEntry *nextEntry() = 0;
137  virtual void write(StoreEntry const &) = 0;
138  };
139 
141  virtual int writeCleanStart();
142  virtual void writeCleanDone();
143  virtual void parse(int index, char *path) = 0;
144 
145  struct {
146  int blksize;
147  } fs;
148 };
149 
150 } // namespace Store
151 
152 #endif /* SQUID_SRC_STORE_DISK_H */
153 
virtual void dump(StoreEntry &) const
Definition: Disk.cc:43
virtual bool doubleCheck(StoreEntry &)
Definition: Disk.cc:46
virtual bool smpAware() const =0
whether this disk storage is capable of serving multiple workers
bool read_only
Definition: Disk.h:112
virtual bool active() const
Definition: Disk.cc:236
void stat(StoreEntry &) const override
Definition: Disk.cc:63
virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const =0
check whether we can store the entry; if we can, report current load
Definition: Disk.cc:164
virtual void finalizeSwapoutFailure(StoreEntry &)=0
abort the failed swapout that has been already noticed by Store
void reference(StoreEntry &e) override
somebody needs this entry (many cache replacement policies need to know)
Definition: Disk.cc:136
virtual void logEntry(const StoreEntry &e, int op) const
Definition: Disk.cc:227
manages a single cache_dir
Definition: Disk.h:21
unsigned char cache_key
Store key.
Definition: forward.h:29
virtual bool allowOptionReconfigure(const char *const) const
Definition: Disk.h:85
int removals
Definition: Disk.h:106
int64_t max_objsize
maximum size of any object stored here (-1 for no limit)
Definition: Disk.h:99
StoreEntry * get(const cache_key *) override
Definition: Disk.cc:393
virtual void closeLog()
Definition: Disk.cc:215
int64_t maxObjectSize() const override
the maximum size of a storable object; -1 if unlimited
Definition: Disk.cc:103
virtual bool hasReadableEntry(const StoreEntry &e) const =0
whether this cache dir has an entry with e.key
virtual void statfs(StoreEntry &) const
Definition: Disk.cc:83
int64_t minObjectSize() const
the size of the smallest entry this cache_dir can store
Definition: Disk.cc:96
RemovalPolicy * repl
Definition: Disk.h:105
virtual void openLog()
Definition: Disk.cc:212
struct Store::Disk::Flags flags
virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STIOCB *, void *)=0
virtual void disconnect(StoreEntry &)
called when the entry is about to forget its association with cache_dir
Definition: Disk.h:71
int size
Definition: ModDevPoll.cc:69
int scanned
Definition: Disk.h:107
const char * theType
Definition: Disk.h:94
virtual ~CleanLog()
Definition: Disk.h:134
bool dereference(StoreEntry &e) override
Definition: Disk.cc:139
uint64_t maxSize() const override
Definition: Disk.h:48
int64_t min_objsize
minimum size of any object stored here (-1 for no limit)
Definition: Disk.h:98
char * path
Definition: Disk.h:102
const char * type() const
Definition: Disk.cc:230
virtual void diskFull()
Definition: Disk.cc:145
virtual bool needsDiskStrand() const
needs a dedicated kid process
Definition: Disk.cc:249
uint64_t max_size
maximum allocatable size of the storage area
Definition: Disk.h:97
int reconfiguring
Disk(char const *aType)
Definition: Disk.cc:24
bool objectSizeIsAcceptable(int64_t objSize) const
Definition: Disk.cc:156
int64_t sizeInBlocks(const int64_t size) const
Definition: Disk.h:87
bool canLog(StoreEntry const &e) const
Definition: Disk.cc:188
void optionReadOnlyDump(StoreEntry *e) const
Definition: Disk.cc:340
~Disk() override
Definition: Disk.cc:33
virtual ConfigOption * getOptionTree() const
Definition: Disk.cc:258
int disker
disker kid id dedicated to this SwapDir or -1
Definition: Disk.h:104
void optionObjectSizeDump(StoreEntry *e) const
Definition: Disk.cc:382
void parseOptions(int reconfiguring)
Definition: Disk.cc:267
virtual void finalizeSwapoutSuccess(const StoreEntry &)=0
finalize the successful swapout that has been already noticed by Store
void dumpOptions(StoreEntry *e) const
Definition: Disk.cc:307
virtual int writeCleanStart()
Definition: Disk.cc:218
void maintain() override
perform regular periodic maintenance; TODO: move to UFSSwapDir::Maintain
Definition: Disk.cc:86
virtual void reconfigure()=0
virtual bool unlinkdUseful() const =0
whether SwapDir may benefit from unlinkd
virtual void writeCleanDone()
Definition: Disk.cc:224
void STIOCB(void *their_data, int errflag, StoreIOState::Pointer self)
Definition: StoreIOState.h:39
virtual void parse(int index, char *path)=0
bool optionObjectSizeParse(char const *option, const char *value, int reconfiguring)
Definition: Disk.cc:347
struct Store::Disk::@125 fs
uint64_t minSize() const override
the minimum size the store will shrink to via normal housekeeping
Definition: Disk.cc:89
CleanLog * cleanLog
Definition: Disk.h:140
int index
Definition: Disk.h:103
virtual void write(StoreEntry const &)=0
void getStats(StoreInfoStats &stats) const override
collect statistics
Definition: Disk.cc:52
virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STIOCB *, void *)=0
virtual bool doReportStat() const
whether stat should be reported by this SwapDir
Definition: Disk.h:35
virtual const StoreEntry * nextEntry()=0
void create() override
create system resources needed for this store to operate in the future
Definition: Disk.cc:40
High-level store statistics used by mgr:info action. Used inside PODs!
Definition: StoreStats.h:13
bool optionReadOnlyParse(char const *option, const char *value, int reconfiguring)
Definition: Disk.cc:318
RefCount< Disk > Pointer
Definition: Disk.h:25
int blksize
Definition: Disk.h:146

 

Introduction

Documentation

Support

Miscellaneous