UFSSwapDir.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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_FS_UFS_UFSSWAPDIR_H
10 #define SQUID_FS_UFS_UFSSWAPDIR_H
11 
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"
19 
20 class HttpRequest;
21 class ConfigOptionVector;
22 class FileMap;
23 class DiskIOModule;
24 
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);
42 
43  UFSSwapDir(char const *aType, const char *aModuleType);
44  virtual ~UFSSwapDir();
45 
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 unlink(StoreEntry &) override;
53  virtual void statfs(StoreEntry &) const override;
54  virtual void maintain() override;
55  virtual void markForUnlink(StoreEntry &) 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 swappedOut(const StoreEntry &e) override;
71  virtual uint64_t currentSize() const override { return cur_size; }
72  virtual uint64_t currentCount() const override { return n_disk_objects; }
73  virtual ConfigOption *getOptionTree() const override;
74  virtual bool smpAware() const override { return false; }
75 
76  void unlinkFile(sfileno f);
77  // move down when unlink is a virtual method
78  //protected:
80  char *fullPath(sfileno, char *) const;
81  /* temp */
82  void closeTmpSwapLog();
83  FILE *openTmpSwapLog(int *clean_flag, int *zero_flag);
84  char *swapSubDir(int subdirn) const;
85  int mapBitTest(sfileno filn);
86  void mapBitReset(sfileno filn);
87  void mapBitSet(sfileno filn);
93  sfileno file_number,
94  uint64_t swap_file_sz,
95  time_t expires,
96  time_t timestamp,
97  time_t lastref,
98  time_t lastmod,
99  uint32_t refcount,
100  uint16_t flags,
101  int clean);
104  int validFileno(sfileno filn, int flag) const;
105  int mapBitAllocate();
106 
107  void *fsdata;
108 
109  bool validL2(int) const;
110  bool validL1(int) const;
111 
113  void replacementAdd(StoreEntry *e);
114  void replacementRemove(StoreEntry *e);
115 
116 protected:
118  int suggest;
119  int l1;
120  int l2;
121 
122 private:
123  void parseSizeL1L2();
124  static int NumberOfUFSDirs;
126  bool pathIsDirectory(const char *path)const;
128  static EVH CleanEvent;
129  static int HandleCleanEvent();
136  bool verifyCacheDirs();
137  void rebuild();
138  int createDirectory(const char *path, int);
139  void createSwapSubDirs();
140  void dumpEntry(StoreEntry &) const;
141  char *logFile(char const *ext = NULL)const;
142  void changeIO(DiskIOModule *);
143  bool optionIOParse(char const *option, const char *value, int reconfiguring);
144  void optionIODump(StoreEntry * e) const;
146  char const *ioType;
147  uint64_t cur_size;
148  uint64_t n_disk_objects;
149  bool rebuilding_;
150 };
151 
152 } //namespace Ufs
153 } //namespace Fs
154 #endif /* SQUID_FS_UFS_UFSSWAPDIR_H */
155 
bool rebuilding_
whether RebuildState is writing the new swap.state
Definition: UFSSwapDir.h:149
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:1011
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:147
int createDirectory(const char *path, int)
Definition: UFSSwapDir.cc:609
virtual bool unlinkdUseful() const override
whether SwapDir may benefit from unlinkd
Definition: UFSSwapDir.cc:1212
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:72
struct Store::Disk::Flags flags
uint64_t n_disk_objects
total number of objects stored
Definition: UFSSwapDir.h:148
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:967
void replacementAdd(StoreEntry *e)
Definition: UFSSwapDir.cc:1236
char * path
Definition: Disk.h:96
ConfigOptionVector * currentIOOptions
Definition: UFSSwapDir.h:145
void EVH(void *)
Definition: event.h:19
char const * ioType
Definition: UFSSwapDir.h:146
virtual bool dereference(StoreEntry &) override
Definition: UFSSwapDir.cc:539
static int HandleCleanEvent()
safely cleans a few unused files if possible
Definition: UFSSwapDir.cc:1079
void optionIODump(StoreEntry *e) const
Definition: UFSSwapDir.cc:249
virtual void dump(StoreEntry &) const override
Definition: UFSSwapDir.cc:1258
void STFNCB(void *their_data, int errflag, StoreIOState::Pointer self)
Definition: StoreIOState.h:41
static bool IsUFSDir(SwapDir *sd)
Definition: UFSSwapDir.cc:1143
void unlinkFile(sfileno f)
Definition: UFSSwapDir.cc:1202
virtual void sync() override
prepare for shutdown
Definition: UFSSwapDir.cc:1292
virtual void swappedOut(const StoreEntry &e) override
called when entry swap out is complete
Definition: UFSSwapDir.cc:1298
char * swapSubDir(int subdirn) const
Definition: UFSSwapDir.cc:600
static int NumberOfUFSDirs
Definition: UFSSwapDir.h:124
void replacementRemove(StoreEntry *e)
Definition: UFSSwapDir.cc:1243
bool pathIsDirectory(const char *path) const
Definition: UFSSwapDir.cc:634
signed_int32_t sfileno
Definition: forward.h:22
void mapBitSet(sfileno filn)
Definition: UFSSwapDir.cc:569
int index
Definition: Disk.h:97
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:1185
char * fullPath(sfileno, char *) const
Definition: UFSSwapDir.cc:1265
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:1155
static int * UFSDirToGlobalDirMapping
Definition: UFSSwapDir.h:125
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
void const cache_key * key
static EVH CleanEvent
Definition: UFSSwapDir.h:128
virtual void logEntry(const StoreEntry &e, int op) const override
Definition: UFSSwapDir.cc:1305
virtual bool smpAware() const override
Definition: UFSSwapDir.h:74
void undoAddDiskRestore(StoreEntry *e)
Undo the effects of UFSSwapDir::addDiskRestore().
Definition: UFSSwapDir.cc:831
static int DirClean(int swap_index)
Definition: UFSSwapDir.cc:1334
Fs::Ufs::UFSStrategy * IO
Definition: UFSSwapDir.h:79
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:1286
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:71
virtual void unlink(StoreEntry &) override
remove the entry from the store
Definition: UFSSwapDir.cc:1219
int reconfiguring
virtual void create() override
create system resources needed for this store to operate in the future
Definition: UFSSwapDir.cc:305
virtual void markForUnlink(StoreEntry &) override
expect an unlink() call after the entry becomes idle
Definition: UFSSwapDir.h:55
manages a single cache_dir
Definition: Disk.h:21
FILE * openTmpSwapLog(int *clean_flag, int *zero_flag)
Definition: UFSSwapDir.cc:880

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors