]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/coss/CossSwapDir.h
Merged from parent (trunk r11728, v3.2.0.11+).
[thirdparty/squid.git] / src / fs / coss / CossSwapDir.h
1 #ifndef __COSSSWAPDIR_H__
2 #define __COSSSWAPDIR_H__
3
4 class StoreEntry;
5 class CossSwapDir;
6 class CossMemBuf;
7 class DiskIOStrategy;
8 class DiskIOModule;
9 class ConfigOptionVector;
10 class DiskFile;
11
12 #include "SwapDir.h"
13 #include "DiskIO/IORequestor.h"
14
15
16 #ifndef COSS_MEMBUF_SZ
17 #define COSS_MEMBUF_SZ 1048576
18 #endif
19
20 /* Note that swap_filen in sio/e are actually disk offsets too! */
21
22 /* What we're doing in storeCossAllocate() */
23 #define COSS_ALLOC_ALLOCATE 1
24 #define COSS_ALLOC_REALLOC 2
25
26
27 /// \ingroup COSS
28 class CossSwapDir : public SwapDir, public IORequestor
29 {
30
31 public:
32 CossSwapDir();
33 virtual void init();
34 virtual void create();
35 virtual void dump(StoreEntry &)const;
36 ~CossSwapDir();
37 virtual StoreSearch *search(String const url, HttpRequest *);
38 virtual void unlink (StoreEntry &);
39 virtual void statfs (StoreEntry &)const;
40 virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const;
41 virtual int callback();
42 virtual void sync();
43 virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
44 virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
45 virtual void openLog();
46 virtual void closeLog();
47 virtual int writeCleanStart();
48 virtual void writeCleanDone();
49 virtual void logEntry(const StoreEntry & e, int op) const;
50 virtual void parse (int index, char *path);
51 virtual void reconfigure (int, char *);
52 virtual void swappedOut(const StoreEntry &e);
53 virtual uint64_t currentSize() const { return cur_size; }
54 virtual uint64_t currentCount() const { return n_disk_objects; }
55 /* internals */
56 virtual off_t storeCossFilenoToDiskOffset(sfileno);
57 virtual sfileno storeCossDiskOffsetToFileno(off_t);
58 virtual CossMemBuf *storeCossFilenoToMembuf(sfileno f);
59 /* IORequestor routines */
60 virtual void ioCompletedNotification();
61 virtual void closeCompleted();
62 virtual void readCompleted(const char *buf, int len, int errflag, RefCount<ReadRequest>);
63 virtual void writeCompleted(int errflag, size_t len, RefCount<WriteRequest>);
64 //private:
65 int swaplog_fd;
66 int count;
67 dlink_list membufs;
68
69 CossMemBuf *current_membuf;
70 off_t current_offset; /* in Blocks */
71 int numcollisions;
72 dlink_list cossindex;
73 unsigned int blksz_bits;
74 unsigned int blksz_mask; /* just 1<<blksz_bits - 1*/
75 DiskIOStrategy *io;
76 RefCount<DiskFile> theFile;
77 char *storeCossMemPointerFromDiskOffset(off_t offset, CossMemBuf ** mb);
78 void storeCossMemBufUnlock(StoreIOState::Pointer);
79 CossMemBuf *createMemBuf(off_t start, sfileno curfn, int *collision);
80 sfileno allocate(const StoreEntry * e, int which);
81 void startMembuf();
82 StoreEntry *addDiskRestore(const cache_key *const key,
83 int file_number,
84 uint64_t swap_file_sz,
85 time_t expires,
86 time_t timestamp,
87 time_t lastref,
88 time_t lastmod,
89 uint32_t refcount,
90 uint16_t flags,
91 int clean);
92
93 private:
94 void changeIO(DiskIOModule *module);
95 bool optionIOParse(char const *option, const char *value, int reconfiguring);
96 void optionIODump(StoreEntry * e) const;
97 void optionBlockSizeDump(StoreEntry *) const;
98 bool optionBlockSizeParse(const char *, const char *, int);
99 char const *stripePath() const;
100 ConfigOption * getOptionTree() const;
101 const char *ioModule;
102 mutable ConfigOptionVector *currentIOOptions;
103 const char *stripe_path;
104 uint64_t cur_size; ///< currently used space in the storage area
105 uint64_t n_disk_objects; ///< total number of objects stored
106 };
107
108 /// \ingroup COSS
109 extern void storeCossAdd(CossSwapDir *, StoreEntry *);
110 /// \ingroup COSS
111 extern void storeCossRemove(CossSwapDir *, StoreEntry *);
112 /// \ingroup COSS
113 extern void storeCossStartMembuf(CossSwapDir * SD);
114
115
116 #include "StoreSearch.h"
117
118 /// \ingroup COSS
119 class StoreSearchCoss : public StoreSearch
120 {
121
122 public:
123 StoreSearchCoss(RefCount<CossSwapDir> sd);
124 StoreSearchCoss(StoreSearchCoss const &);
125 ~StoreSearchCoss();
126 /* Iterator API - garh, wrong place */
127 /* callback the client when a new StoreEntry is available
128 * or an error occurs
129 */
130 virtual void next(void (callback)(void *cbdata), void *cbdata);
131 /* return true if a new StoreEntry is immediately available */
132 virtual bool next();
133 virtual bool error() const;
134 virtual bool isDone() const;
135 virtual StoreEntry *currentItem();
136
137 private:
138 CBDATA_CLASS2(StoreSearchCoss);
139 RefCount<CossSwapDir> sd;
140 void (*callback)(void *cbdata);
141 void *cbdata;
142 bool _done;
143 dlink_node * current;
144 dlink_node * next_;
145 };
146
147 #endif