~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to src/fs/ufs/ufscommon.h

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2006-11-11 10:32:06 UTC
  • Revision ID: james.westby@ubuntu.com-20061111103206-f3p0r9g0vq44rp3r
Tags: upstream-3.0.PRE5
ImportĀ upstreamĀ versionĀ 3.0.PRE5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * $Id: ufscommon.h,v 1.9 2006/09/14 00:51:12 robertc Exp $
 
4
 *
 
5
 * SQUID Web Proxy Cache          http://www.squid-cache.org/
 
6
 * ----------------------------------------------------------
 
7
 *
 
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.
 
16
 *
 
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.
 
21
 *  
 
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.
 
26
 *  
 
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.
 
30
 *
 
31
 */
 
32
 
 
33
#ifndef SQUID_UFSCOMMON_H
 
34
#define SQUID_UFSCOMMON_H
 
35
 
 
36
#include "squid.h"
 
37
#include "event.h"
 
38
 
 
39
#define DefaultLevelOneDirs     16
 
40
#define DefaultLevelTwoDirs     256
 
41
#define STORE_META_BUFSZ 4096
 
42
 
 
43
/* Common UFS routines */
 
44
#include "SwapDir.h"
 
45
#include "StoreSearch.h"
 
46
 
 
47
class UFSStrategy;
 
48
 
 
49
class ConfigOptionVector;
 
50
 
 
51
class DiskIOModule;
 
52
 
 
53
class UFSSwapDir : public SwapDir
 
54
{
 
55
 
 
56
public:
 
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);
 
60
 
 
61
    UFSSwapDir(char const *aType, const char *aModuleType);
 
62
    virtual void init();
 
63
    virtual void create();
 
64
    virtual void dump(StoreEntry &) const;
 
65
    ~UFSSwapDir();
 
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();
 
84
    virtual void sync();
 
85
 
 
86
    void unlinkFile(sfileno f);
 
87
    // move down when unlink is a virtual method
 
88
    //protected:
 
89
    UFSStrategy *IO;
 
90
    char *fullPath(sfileno, char *) const;
 
91
    /* temp */
 
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,
 
99
                               sfileno file_number,
 
100
                               size_t swap_file_sz,
 
101
                               time_t expires,
 
102
                               time_t timestamp,
 
103
                               time_t lastref,
 
104
                               time_t lastmod,
 
105
                               u_int32_t refcount,
 
106
                               u_int16_t flags,
 
107
                               int clean);
 
108
    int validFileno(sfileno filn, int flag) const;
 
109
    int mapBitAllocate();
 
110
    virtual ConfigOption *getOptionTree() const;
 
111
 
 
112
    void *fsdata;
 
113
 
 
114
    bool validL2(int) const;
 
115
    bool validL1(int) const;
 
116
 
 
117
    void replacementAdd(StoreEntry *e);
 
118
    void replacementRemove(StoreEntry *e);
 
119
 
 
120
protected:
 
121
    fileMap *map;
 
122
    int suggest;
 
123
    int l1;
 
124
    int l2;
 
125
 
 
126
private:
 
127
    void parseSizeL1L2();
 
128
    static int NumberOfUFSDirs;
 
129
    static int * UFSDirToGlobalDirMapping;
 
130
    bool pathIsDirectory(const char *path)const;
 
131
    int swaplog_fd;
 
132
    static EVH CleanEvent;
 
133
    bool verifyCacheDirs();
 
134
    void rebuild();
 
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;
 
143
    char const *ioType;
 
144
 
 
145
};
 
146
 
 
147
#include "RefCount.h"
 
148
#include "DiskIO/IORequestor.h"
 
149
 
 
150
/* UFS dir specific IO calls 
 
151
 *
 
152
 * This should be whittled away - DiskIOModule should be providing the
 
153
 * entire needed api.
 
154
 */
 
155
 
 
156
class DiskIOStrategy;
 
157
 
 
158
class DiskFile;
 
159
 
 
160
class UFSStrategy
 
161
{
 
162
 
 
163
public:
 
164
    UFSStrategy (DiskIOStrategy *);
 
165
    virtual ~UFSStrategy ();
 
166
    /* Not implemented */
 
167
    UFSStrategy (UFSStrategy const &);
 
168
    UFSStrategy &operator=(UFSStrategy const &);
 
169
 
 
170
    virtual bool shedLoad();
 
171
 
 
172
    virtual int load();
 
173
 
 
174
    StoreIOState::Pointer createState(SwapDir *SD, StoreEntry *e, StoreIOState::STIOCB * callback, void *callback_data) const;
 
175
    /* UFS specific */
 
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 *);
 
181
 
 
182
    virtual void unlinkFile (char const *);
 
183
    virtual void sync();
 
184
 
 
185
    virtual int callback();
 
186
 
 
187
    /* Init per-instance logic */
 
188
    virtual void init();
 
189
 
 
190
    /* cachemgr output on the IO instance stats */
 
191
    virtual void statfs(StoreEntry & sentry)const;
 
192
 
 
193
    /* The io strategy in use */
 
194
    DiskIOStrategy *io;
 
195
protected:
 
196
 
 
197
    friend class UFSSwapDir;
 
198
};
 
199
 
 
200
/* Common ufs-store-dir logic */
 
201
 
 
202
class ReadRequest;
 
203
 
 
204
class UFSStoreState : public StoreIOState, public IORequestor
 
205
{
 
206
 
 
207
public:
 
208
    void * operator new (size_t);
 
209
    void operator delete (void *);
 
210
    UFSStoreState(SwapDir * SD, StoreEntry * anEntry, STIOCB * callback_, void *callback_data_);
 
211
    ~UFSStoreState();
 
212
    virtual void close();
 
213
    virtual void closeCompleted();
 
214
    // protected:
 
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;
 
219
    bool opening;
 
220
    bool creating;
 
221
    bool closing;
 
222
    bool reading;
 
223
    bool writing;
 
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);
 
226
 
 
227
protected:
 
228
    virtual void doCloseCallback (int errflag);
 
229
 
 
230
    class _queued_read
 
231
    {
 
232
 
 
233
    public:
 
234
        MEMPROXY_CLASS(UFSStoreState::_queued_read);
 
235
        char *buf;
 
236
        size_t size;
 
237
        off_t offset;
 
238
        STRCB *callback;
 
239
        void *callback_data;
 
240
 
 
241
    };
 
242
 
 
243
    class _queued_write
 
244
    {
 
245
 
 
246
    public:
 
247
        MEMPROXY_CLASS(UFSStoreState::_queued_write);
 
248
        char const *buf;
 
249
        size_t size;
 
250
        off_t offset;
 
251
        FREE *free_func;
 
252
 
 
253
    };
 
254
 
 
255
    /* These should be in the IO strategy */
 
256
 
 
257
    struct
 
258
    {
 
259
        /*
 
260
         * DPW 2006-05-24
 
261
         * the write_draining flag is used to avoid recursion inside
 
262
         * the UFSStoreState::drainWriteQueue() method.
 
263
         */
 
264
        bool write_draining;
 
265
        /*
 
266
         * DPW 2006-05-24
 
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.
 
271
         */
 
272
        bool try_closing;
 
273
    }
 
274
 
 
275
    flags;
 
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();
 
282
    void tryClosing();
 
283
    char *read_buf;
 
284
 
 
285
private:
 
286
    CBDATA_CLASS(UFSStoreState);
 
287
    void openDone();
 
288
    void freePending();
 
289
    void doWrite();
 
290
};
 
291
 
 
292
MEMPROXY_CLASS_INLINE(UFSStoreState::_queued_read)
 
293
MEMPROXY_CLASS_INLINE(UFSStoreState::_queued_write)
 
294
 
 
295
class StoreSearchUFS : public StoreSearch
 
296
{
 
297
 
 
298
public:
 
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
 
304
     * or an error occurs 
 
305
     */
 
306
    virtual void next(void (callback)(void *cbdata), void *cbdata);
 
307
    /* return true if a new StoreEntry is immediately available */
 
308
    virtual bool next();
 
309
    virtual bool error() const;
 
310
    virtual bool isDone() const;
 
311
    virtual StoreEntry *currentItem();
 
312
 
 
313
    RefCount<UFSSwapDir> sd;
 
314
    RemovalPolicyWalker *walker;
 
315
 
 
316
private:
 
317
    CBDATA_CLASS2(StoreSearchUFS);
 
318
    void (callback)(void *cbdata);
 
319
    void *cbdata;
 
320
    StoreEntry * current;
 
321
    bool _done;
 
322
};
 
323
 
 
324
class RebuildState : public RefCountable
 
325
{
 
326
 
 
327
public:
 
328
    static EVH RebuildStep;
 
329
 
 
330
    RebuildState(RefCount<UFSSwapDir> sd);
 
331
    ~RebuildState();
 
332
 
 
333
    /* Iterator API - garh, wrong place */
 
334
    /* callback the client when a new StoreEntry is available
 
335
     * or an error occurs 
 
336
     */
 
337
    virtual void next(void (callback)(void *cbdata), void *cbdata);
 
338
    /* return true if a new StoreEntry is immediately available */
 
339
    virtual bool next();
 
340
    virtual bool error() const;
 
341
    virtual bool isDone() const;
 
342
    virtual StoreEntry *currentItem();
 
343
 
 
344
    RefCount<UFSSwapDir> sd;
 
345
    int n_read;
 
346
    FILE *log;
 
347
    int speed;
 
348
    int curlvl1;
 
349
    int curlvl2;
 
350
 
 
351
    struct
 
352
    {
 
353
 
 
354
unsigned int need_to_validate:
 
355
        1;
 
356
 
 
357
unsigned int clean:
 
358
        1;
 
359
 
 
360
unsigned int init:
 
361
        1;
 
362
    }
 
363
 
 
364
    flags;
 
365
    int in_dir;
 
366
    int done;
 
367
    int fn;
 
368
 
 
369
    struct dirent *entry;
 
370
    DIR *td;
 
371
    char fullpath[SQUID_MAXPATHLEN];
 
372
    char fullfilename[SQUID_MAXPATHLEN];
 
373
 
 
374
    struct _store_rebuild_data counts;
 
375
 
 
376
private:
 
377
    CBDATA_CLASS2(RebuildState);
 
378
    void rebuildFromDirectory();
 
379
    void rebuildFromSwapLog();
 
380
    void rebuildStep();
 
381
    int getNextFile(sfileno *, int *size);
 
382
    StoreEntry *currentEntry() const;
 
383
    void currentEntry(StoreEntry *);
 
384
    StoreEntry *e;
 
385
    bool fromLog;
 
386
    bool _done;
 
387
    void (callback)(void *cbdata);
 
388
    void *cbdata;
 
389
};
 
390
 
 
391
#ifdef _USE_INLINE_
 
392
#include "ufscommon.cci"
 
393
#endif
 
394
 
 
395
#endif /* SQUID_UFSCOMMON_H */