3
* $Id: ufscommon.h,v 1.9 2006/09/14 00:51:12 robertc Exp $
5
* SQUID Web Proxy Cache http://www.squid-cache.org/
6
* ----------------------------------------------------------
8
* Squid is the result of efforts by numerous individuals from
9
* the Internet community; see the CONTRIBUTORS file for full
10
* details. Many organizations have provided support for Squid's
11
* development; see the SPONSORS file for full details. Squid is
12
* Copyrighted (C) 2001 by the Regents of the University of
13
* California; see the COPYRIGHT file for full details. Squid
14
* incorporates software developed and/or copyrighted by other
15
* sources; see the CREDITS file for full details.
17
* This program is free software; you can redistribute it and/or modify
18
* it under the terms of the GNU General Public License as published by
19
* the Free Software Foundation; either version 2 of the License, or
20
* (at your option) any later version.
22
* This program is distributed in the hope that it will be useful,
23
* but WITHOUT ANY WARRANTY; without even the implied warranty of
24
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
* GNU General Public License for more details.
27
* You should have received a copy of the GNU General Public License
28
* along with this program; if not, write to the Free Software
29
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33
#ifndef SQUID_UFSCOMMON_H
34
#define SQUID_UFSCOMMON_H
39
#define DefaultLevelOneDirs 16
40
#define DefaultLevelTwoDirs 256
41
#define STORE_META_BUFSZ 4096
43
/* Common UFS routines */
45
#include "StoreSearch.h"
49
class ConfigOptionVector;
53
class UFSSwapDir : public SwapDir
57
static int IsUFSDir(SwapDir* sd);
58
static int DirClean(int swap_index);
59
static int FilenoBelongsHere(int fn, int F0, int F1, int F2);
61
UFSSwapDir(char const *aType, const char *aModuleType);
63
virtual void create();
64
virtual void dump(StoreEntry &) const;
66
virtual StoreSearch *search(String const url, HttpRequest *);
67
virtual bool doubleCheck(StoreEntry &);
68
virtual void unlink(StoreEntry &);
69
virtual void statfs(StoreEntry &)const;
70
virtual void maintain();
71
virtual int canStore(StoreEntry const &)const;
72
virtual void reference(StoreEntry &);
73
virtual void dereference(StoreEntry &);
74
virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
75
virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
76
virtual void openLog();
77
virtual void closeLog();
78
virtual int writeCleanStart();
79
virtual void writeCleanDone();
80
virtual void logEntry(const StoreEntry & e, int op) const;
81
virtual void parse(int index, char *path);
82
virtual void reconfigure(int, char *);
83
virtual int callback();
86
void unlinkFile(sfileno f);
87
// move down when unlink is a virtual method
90
char *fullPath(sfileno, char *) const;
92
void closeTmpSwapLog();
93
FILE *openTmpSwapLog(int *clean_flag, int *zero_flag);
94
char *swapSubDir(int subdirn) const;
95
int mapBitTest(sfileno filn);
96
void mapBitReset(sfileno filn);
97
void mapBitSet(sfileno filn);
98
StoreEntry *addDiskRestore(const cache_key * key,
108
int validFileno(sfileno filn, int flag) const;
109
int mapBitAllocate();
110
virtual ConfigOption *getOptionTree() const;
114
bool validL2(int) const;
115
bool validL1(int) const;
117
void replacementAdd(StoreEntry *e);
118
void replacementRemove(StoreEntry *e);
127
void parseSizeL1L2();
128
static int NumberOfUFSDirs;
129
static int * UFSDirToGlobalDirMapping;
130
bool pathIsDirectory(const char *path)const;
132
static EVH CleanEvent;
133
bool verifyCacheDirs();
135
int createDirectory(const char *path, int);
136
void createSwapSubDirs();
137
void dumpEntry(StoreEntry &) const;
138
char *logFile(char const *ext = NULL)const;
139
void changeIO(DiskIOModule *);
140
bool optionIOParse(char const *option, const char *value, int reconfiguring);
141
void optionIODump(StoreEntry * e) const;
142
mutable ConfigOptionVector *currentIOOptions;
147
#include "RefCount.h"
148
#include "DiskIO/IORequestor.h"
150
/* UFS dir specific IO calls
152
* This should be whittled away - DiskIOModule should be providing the
156
class DiskIOStrategy;
164
UFSStrategy (DiskIOStrategy *);
165
virtual ~UFSStrategy ();
166
/* Not implemented */
167
UFSStrategy (UFSStrategy const &);
168
UFSStrategy &operator=(UFSStrategy const &);
170
virtual bool shedLoad();
174
StoreIOState::Pointer createState(SwapDir *SD, StoreEntry *e, StoreIOState::STIOCB * callback, void *callback_data) const;
176
virtual RefCount<DiskFile> newFile (char const *path);
177
StoreIOState::Pointer open(SwapDir *, StoreEntry *, StoreIOState::STFNCB *,
178
StoreIOState::STIOCB *, void *);
179
StoreIOState::Pointer create(SwapDir *, StoreEntry *, StoreIOState::STFNCB *,
180
StoreIOState::STIOCB *, void *);
182
virtual void unlinkFile (char const *);
185
virtual int callback();
187
/* Init per-instance logic */
190
/* cachemgr output on the IO instance stats */
191
virtual void statfs(StoreEntry & sentry)const;
193
/* The io strategy in use */
197
friend class UFSSwapDir;
200
/* Common ufs-store-dir logic */
204
class UFSStoreState : public StoreIOState, public IORequestor
208
void * operator new (size_t);
209
void operator delete (void *);
210
UFSStoreState(SwapDir * SD, StoreEntry * anEntry, STIOCB * callback_, void *callback_data_);
212
virtual void close();
213
virtual void closeCompleted();
215
virtual void ioCompletedNotification();
216
virtual void readCompleted(const char *buf, int len, int errflag, RefCount<ReadRequest>);
217
virtual void writeCompleted(int errflag, size_t len, RefCount<WriteRequest>);
218
RefCount<DiskFile> theFile;
224
void read_(char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data);
225
void write(char const *buf, size_t size, off_t offset, FREE * free_func);
228
virtual void doCloseCallback (int errflag);
234
MEMPROXY_CLASS(UFSStoreState::_queued_read);
247
MEMPROXY_CLASS(UFSStoreState::_queued_write);
255
/* These should be in the IO strategy */
261
* the write_draining flag is used to avoid recursion inside
262
* the UFSStoreState::drainWriteQueue() method.
267
* The try_closing flag is set by UFSStoreState::tryClosing()
268
* when UFSStoreState wants to close the file, but cannot
269
* because of pending I/Os. If set, UFSStoreState will
270
* try to close again in the I/O callbacks.
276
link_list *pending_reads;
277
link_list *pending_writes;
278
void queueRead(char *, size_t, off_t, STRCB *, void *);
279
void queueWrite(char const *, size_t, off_t, FREE *);
280
bool kickReadQueue();
281
void drainWriteQueue();
286
CBDATA_CLASS(UFSStoreState);
292
MEMPROXY_CLASS_INLINE(UFSStoreState::_queued_read)
293
MEMPROXY_CLASS_INLINE(UFSStoreState::_queued_write)
295
class StoreSearchUFS : public StoreSearch
299
StoreSearchUFS(RefCount<UFSSwapDir> sd);
300
StoreSearchUFS(StoreSearchUFS const &);
301
virtual ~StoreSearchUFS();
302
/* Iterator API - garh, wrong place */
303
/* callback the client when a new StoreEntry is available
306
virtual void next(void (callback)(void *cbdata), void *cbdata);
307
/* return true if a new StoreEntry is immediately available */
309
virtual bool error() const;
310
virtual bool isDone() const;
311
virtual StoreEntry *currentItem();
313
RefCount<UFSSwapDir> sd;
314
RemovalPolicyWalker *walker;
317
CBDATA_CLASS2(StoreSearchUFS);
318
void (callback)(void *cbdata);
320
StoreEntry * current;
324
class RebuildState : public RefCountable
328
static EVH RebuildStep;
330
RebuildState(RefCount<UFSSwapDir> sd);
333
/* Iterator API - garh, wrong place */
334
/* callback the client when a new StoreEntry is available
337
virtual void next(void (callback)(void *cbdata), void *cbdata);
338
/* return true if a new StoreEntry is immediately available */
340
virtual bool error() const;
341
virtual bool isDone() const;
342
virtual StoreEntry *currentItem();
344
RefCount<UFSSwapDir> sd;
354
unsigned int need_to_validate:
369
struct dirent *entry;
371
char fullpath[SQUID_MAXPATHLEN];
372
char fullfilename[SQUID_MAXPATHLEN];
374
struct _store_rebuild_data counts;
377
CBDATA_CLASS2(RebuildState);
378
void rebuildFromDirectory();
379
void rebuildFromSwapLog();
381
int getNextFile(sfileno *, int *size);
382
StoreEntry *currentEntry() const;
383
void currentEntry(StoreEntry *);
387
void (callback)(void *cbdata);
392
#include "ufscommon.cci"
395
#endif /* SQUID_UFSCOMMON_H */