Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2018 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  */
12 #include "SquidString.h"
13 #include "Store.h"
14 #include "store/Disk.h"
15 #include "StoreIOState.h"
16 #include "StoreSearch.h"
17 #include "swap_log_op.h"
18 #include "UFSStrategy.h"
20 class HttpRequest;
21 class ConfigOptionVector;
22 class FileMap;
23 class DiskIOModule;
25 namespace Fs
26 {
27 namespace Ufs
28 {
30 class UFSSwapDir : public SwapDir
31 {
32 public:
33  static bool IsUFSDir(SwapDir* sd);
34  static int DirClean(int swap_index);
41  static bool FilenoBelongsHere(int fn, int cachedir, int level1dir, int level2dir);
43  UFSSwapDir(char const *aType, const char *aModuleType);
44  virtual ~UFSSwapDir();
46  /* Store::Disk API */
47  virtual void create() override;
48  virtual void init() override;
49  virtual void dump(StoreEntry &) const override;
50  virtual bool doubleCheck(StoreEntry &) override;
51  virtual bool unlinkdUseful() const override;
52  virtual void statfs(StoreEntry &) const override;
53  virtual void maintain() override;
54  virtual void evictCached(StoreEntry &) override;
55  virtual void evictIfFound(const cache_key *) override;
56  virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const override;
57  virtual void reference(StoreEntry &) override;
58  virtual bool dereference(StoreEntry &) override;
61  virtual void openLog() override;
62  virtual void closeLog() override;
63  virtual int writeCleanStart() override;
64  virtual void writeCleanDone() override;
65  virtual void logEntry(const StoreEntry & e, int op) const override;
66  virtual void parse(int index, char *path) override;
67  virtual void reconfigure() override;
68  virtual int callback() override;
69  virtual void sync() override;
70  virtual void finalizeSwapoutSuccess(const StoreEntry &) override;
71  virtual void finalizeSwapoutFailure(StoreEntry &) override;
72  virtual uint64_t currentSize() const override { return cur_size; }
73  virtual uint64_t currentCount() const override { return n_disk_objects; }
74  virtual ConfigOption *getOptionTree() const override;
75  virtual bool smpAware() const override { return false; }
78  virtual bool hasReadableEntry(const StoreEntry &) const override { return false; }
80  void unlinkFile(sfileno f);
81  // move down when unlink is a virtual method
82  //protected:
84  char *fullPath(sfileno, char *) const;
85  /* temp */
86  void closeTmpSwapLog();
87  FILE *openTmpSwapLog(int *clean_flag, int *zero_flag);
88  char *swapSubDir(int subdirn) const;
89  int mapBitTest(sfileno filn);
90  void mapBitReset(sfileno filn);
91  void mapBitSet(sfileno filn);
96  StoreEntry *addDiskRestore(const cache_key * key,
97  sfileno file_number,
98  uint64_t swap_file_sz,
99  time_t expires,
100  time_t timestamp,
101  time_t lastref,
102  time_t lastmod,
103  uint32_t refcount,
104  uint16_t flags,
105  int clean);
106  int validFileno(sfileno filn, int flag) const;
107  int mapBitAllocate();
109  void *fsdata;
111  bool validL2(int) const;
112  bool validL1(int) const;
115  void replacementAdd(StoreEntry *e);
116  void replacementRemove(StoreEntry *e);
118 protected:
120  int suggest;
121  int l1;
122  int l2;
124 private:
125  void parseSizeL1L2();
126  static int NumberOfUFSDirs;
128  bool pathIsDirectory(const char *path)const;
130  static EVH CleanEvent;
131  static int HandleCleanEvent();
138  bool verifyCacheDirs();
139  void rebuild();
140  int createDirectory(const char *path, int);
141  void createSwapSubDirs();
142  void dumpEntry(StoreEntry &) const;
143  char *logFile(char const *ext = NULL)const;
144  void changeIO(DiskIOModule *);
145  bool optionIOParse(char const *option, const char *value, int reconfiguring);
146  void optionIODump(StoreEntry * e) const;
148  char const *ioType;
149  uint64_t cur_size;
150  uint64_t n_disk_objects;
151  bool rebuilding_;
152 };
154 } //namespace Ufs
155 } //namespace Fs
156 #endif /* SQUID_FS_UFS_UFSSWAPDIR_H */
bool rebuilding_
whether RebuildState is writing the new swap.state
Definition: UFSSwapDir.h:151
char * logFile(char const *ext=NULL) const
Definition: UFSSwapDir.cc:694
virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const override
check whether we can store the entry; if we can, report current load
Definition: UFSSwapDir.cc:120
virtual ConfigOption * getOptionTree() const override
Definition: UFSSwapDir.cc:255
virtual void writeCleanDone() override
Definition: UFSSwapDir.cc:994
virtual void evictIfFound(const cache_key *) override
Definition: UFSSwapDir.cc:1222
virtual void maintain() override
perform regular periodic maintenance; TODO: move to UFSSwapDir::Maintain
Definition: UFSSwapDir.cc:419
uint64_t cur_size
currently used space in the storage area
Definition: UFSSwapDir.h:149
int createDirectory(const char *path, int)
Definition: UFSSwapDir.cc:609
virtual bool unlinkdUseful() const override
whether SwapDir may benefit from unlinkd
Definition: UFSSwapDir.cc:1195
unsigned char cache_key
Store key.
Definition: forward.h:29
virtual void reference(StoreEntry &) override
somebody needs this entry (many cache replacement policies need to know)
Definition: UFSSwapDir.cc:529
virtual bool doubleCheck(StoreEntry &) override
Definition: UFSSwapDir.cc:354
char * fn
Definition: membanger.c:36
virtual void closeLog() override
Definition: UFSSwapDir.cc:756
UFSSwapDir(char const *aType, const char *aModuleType)
Definition: UFSSwapDir.cc:312
virtual uint64_t currentCount() const override
the total number of objects stored right now
Definition: UFSSwapDir.h:73
struct Store::Disk::Flags flags
uint64_t n_disk_objects
total number of objects stored
Definition: UFSSwapDir.h:150
virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *) override
Definition: UFSSwapDir.cc:557
StoreEntry * addDiskRestore(const cache_key *key, sfileno file_number, uint64_t swap_file_sz, time_t expires, time_t timestamp, time_t lastref, time_t lastmod, uint32_t refcount, uint16_t flags, int clean)
Definition: UFSSwapDir.cc:789
bool validL1(int) const
Definition: UFSSwapDir.cc:777
virtual int writeCleanStart() override
Definition: UFSSwapDir.cc:950
void replacementAdd(StoreEntry *e)
Definition: UFSSwapDir.cc:1229
char * path
Definition: Disk.h:101
ConfigOptionVector * currentIOOptions
Definition: UFSSwapDir.h:147
void EVH(void *)
Definition: event.h:19
char const * ioType
Definition: UFSSwapDir.h:148
virtual bool dereference(StoreEntry &) override
Definition: UFSSwapDir.cc:539
static int HandleCleanEvent()
safely cleans a few unused files if possible
Definition: UFSSwapDir.cc:1062
void optionIODump(StoreEntry *e) const
Definition: UFSSwapDir.cc:249
virtual void dump(StoreEntry &) const override
Definition: UFSSwapDir.cc:1250
void STFNCB(void *their_data, int errflag, StoreIOState::Pointer self)
Definition: StoreIOState.h:41
static bool IsUFSDir(SwapDir *sd)
Definition: UFSSwapDir.cc:1126
void unlinkFile(sfileno f)
Definition: UFSSwapDir.cc:1185
virtual void sync() override
prepare for shutdown
Definition: UFSSwapDir.cc:1284
virtual void finalizeSwapoutFailure(StoreEntry &) override
abort the failed swapout that has been already noticed by Store
Definition: UFSSwapDir.cc:1297
char * swapSubDir(int subdirn) const
Definition: UFSSwapDir.cc:600
static int NumberOfUFSDirs
Definition: UFSSwapDir.h:126
void replacementRemove(StoreEntry *e)
Definition: UFSSwapDir.cc:1236
bool pathIsDirectory(const char *path) const
Definition: UFSSwapDir.cc:634
signed_int32_t sfileno
Definition: forward.h:22
virtual void evictCached(StoreEntry &) override
Definition: UFSSwapDir.cc:1202
void mapBitSet(sfileno filn)
Definition: UFSSwapDir.cc:569
int index
Definition: Disk.h:102
bool validL2(int) const
Definition: UFSSwapDir.cc:783
void STIOCB(void *their_data, int errflag, StoreIOState::Pointer self)
Definition: StoreIOState.h:51
int validFileno(sfileno filn, int flag) const
Definition: UFSSwapDir.cc:1168
char * fullPath(sfileno, char *) const
Definition: UFSSwapDir.cc:1257
void dumpEntry(StoreEntry &) const
Definition: UFSSwapDir.cc:346
int mapBitTest(sfileno filn)
Definition: UFSSwapDir.cc:563
static bool FilenoBelongsHere(int fn, int cachedir, int level1dir, int level2dir)
Definition: UFSSwapDir.cc:1138
static int * UFSDirToGlobalDirMapping
Definition: UFSSwapDir.h:127
virtual void statfs(StoreEntry &) const override
Definition: UFSSwapDir.cc:376
virtual void reconfigure() override
Definition: UFSSwapDir.cc:178
void mapBitReset(sfileno filn)
Definition: UFSSwapDir.cc:575
virtual void parse(int index, char *path) override
Definition: UFSSwapDir.cc:185
virtual ~UFSSwapDir()
Definition: UFSSwapDir.cc:333
static EVH CleanEvent
Definition: UFSSwapDir.h:130
virtual void logEntry(const StoreEntry &e, int op) const override
Definition: UFSSwapDir.cc:1305
virtual bool smpAware() const override
Definition: UFSSwapDir.h:75
static int DirClean(int swap_index)
Definition: UFSSwapDir.cc:1334
Fs::Ufs::UFSStrategy * IO
Definition: UFSSwapDir.h:83
virtual void openLog() override
Definition: UFSSwapDir.cc:731
virtual void init() override
Definition: UFSSwapDir.cc:277
void changeIO(DiskIOModule *)
Definition: UFSSwapDir.cc:199
virtual int callback() override
called once every main loop iteration; TODO: Move to UFS code.
Definition: UFSSwapDir.cc:1278
virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *) override
Definition: UFSSwapDir.cc:551
#define NULL
Definition: types.h:166
bool optionIOParse(char const *option, const char *value, int reconfiguring)
Definition: UFSSwapDir.cc:222
virtual uint64_t currentSize() const override
current size
Definition: UFSSwapDir.h:72
virtual bool hasReadableEntry(const StoreEntry &) const override
Definition: UFSSwapDir.h:78
int reconfiguring
virtual void create() override
create system resources needed for this store to operate in the future
Definition: UFSSwapDir.cc:305
virtual void finalizeSwapoutSuccess(const StoreEntry &) override
finalize the successful swapout that has been already noticed by Store
Definition: UFSSwapDir.cc:1290
manages a single cache_dir
Definition: Disk.h:21
FILE * openTmpSwapLog(int *clean_flag, int *zero_flag)
Definition: UFSSwapDir.cc:863






Web Site Translations