1 | /* |
---|
2 | * Copyright (C) 1996-2015 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_DISKIOSTRATEGY_H |
---|
10 | #define SQUID_DISKIOSTRATEGY_H |
---|
11 | |
---|
12 | #include "base/RefCount.h" |
---|
13 | #include "Store.h" |
---|
14 | |
---|
15 | class DiskFile; |
---|
16 | |
---|
17 | class ConfigOption; |
---|
18 | |
---|
19 | class DiskIOStrategy |
---|
20 | { |
---|
21 | |
---|
22 | public: |
---|
23 | virtual ~DiskIOStrategy() {} |
---|
24 | |
---|
25 | /** Can the IO Strategy handle more requests ? */ |
---|
26 | virtual bool shedLoad() = 0; |
---|
27 | |
---|
28 | /** What is the current load? 999 = 99.9% */ |
---|
29 | virtual int load() = 0; |
---|
30 | |
---|
31 | /** Return a handle for performing IO operations */ |
---|
32 | virtual RefCount<DiskFile> newFile(char const *path) = 0; |
---|
33 | |
---|
34 | /** flush all IO operations */ |
---|
35 | virtual void sync() {} |
---|
36 | |
---|
37 | /** whether the IO Strategy can use unlinkd */ |
---|
38 | virtual bool unlinkdUseful() const = 0; |
---|
39 | |
---|
40 | /** unlink a file by path */ |
---|
41 | virtual void unlinkFile(char const *) = 0; |
---|
42 | |
---|
43 | /** perform any pending callbacks */ |
---|
44 | virtual int callback() { return 0; } |
---|
45 | |
---|
46 | /** Init per-instance logic */ |
---|
47 | virtual void init() {} |
---|
48 | |
---|
49 | /** cachemgr output on the IO instance stats */ |
---|
50 | virtual void statfs(StoreEntry & sentry)const {} |
---|
51 | |
---|
52 | /** module specific options */ |
---|
53 | virtual ConfigOption *getOptionTree() const { return NULL;} |
---|
54 | }; |
---|
55 | |
---|
56 | /* Because we need the DiskFile definition for newFile. */ |
---|
57 | #include "DiskFile.h" |
---|
58 | |
---|
59 | class SingletonIOStrategy : public DiskIOStrategy |
---|
60 | { |
---|
61 | |
---|
62 | public: |
---|
63 | SingletonIOStrategy(DiskIOStrategy *anIO) : io(anIO) {} |
---|
64 | |
---|
65 | virtual bool shedLoad() { return io->shedLoad(); } |
---|
66 | |
---|
67 | virtual int load() { return io->load(); } |
---|
68 | |
---|
69 | virtual RefCount<DiskFile> newFile (char const *path) {return io->newFile(path); } |
---|
70 | |
---|
71 | virtual void sync() { io->sync(); } |
---|
72 | |
---|
73 | virtual bool unlinkdUseful() const { return io->unlinkdUseful(); } |
---|
74 | |
---|
75 | virtual void unlinkFile (char const *path) { io->unlinkFile(path); } |
---|
76 | |
---|
77 | virtual int callback() { return io->callback(); } |
---|
78 | |
---|
79 | virtual void init() { io->init(); } |
---|
80 | |
---|
81 | virtual void statfs(StoreEntry & sentry)const { io->statfs(sentry); } |
---|
82 | |
---|
83 | virtual ConfigOption *getOptionTree() const { return io->getOptionTree(); } |
---|
84 | |
---|
85 | private: |
---|
86 | DiskIOStrategy *io; |
---|
87 | }; |
---|
88 | |
---|
89 | #endif /* SQUID_DISKIOSTRATEGY_H */ |
---|
90 | |
---|