]>
Commit | Line | Data |
---|---|---|
2391a162 | 1 | #include "squid.h" |
e6ccf245 | 2 | #include "Store.h" |
3 | ||
2391a162 | 4 | |
65a53c8e | 5 | static struct { |
6 | struct { | |
7 | int calls; | |
8 | int select_fail; | |
9 | int create_fail; | |
10 | int success; | |
11 | } create; | |
12 | } store_io_stats; | |
13 | ||
14 | OBJH storeIOStats; | |
2391a162 | 15 | |
cd748f27 | 16 | /* |
17 | * submit a request to create a cache object for writing. | |
18 | * The StoreEntry structure is sent as a hint to the filesystem | |
19 | * to what will be stored in this object, to allow the filesystem | |
20 | * to select different polices depending on object size or type. | |
21 | */ | |
22 | storeIOState * | |
a4b8110e | 23 | storeCreate(StoreEntry * e, STIOCB * file_callback, STIOCB * close_callback, void *callback_data) |
cd748f27 | 24 | { |
e6ccf245 | 25 | ssize_t objsize; |
cd748f27 | 26 | sdirno dirn; |
27 | SwapDir *SD; | |
65a53c8e | 28 | storeIOState *sio; |
cd748f27 | 29 | |
65a53c8e | 30 | store_io_stats.create.calls++; |
cd748f27 | 31 | /* This is just done for logging purposes */ |
32 | objsize = objectLen(e); | |
33 | if (objsize != -1) | |
a4b8110e | 34 | objsize += e->mem_obj->swap_hdr_sz; |
cd748f27 | 35 | |
36 | /* | |
37 | * Pick the swapdir | |
38 | * We assume that the header has been packed by now .. | |
39 | */ | |
40 | dirn = storeDirSelectSwapDir(e); | |
41 | if (dirn == -1) { | |
a4b8110e | 42 | debug(20, 2) ("storeCreate: no valid swapdirs for this object\n"); |
65a53c8e | 43 | store_io_stats.create.select_fail++; |
a4b8110e | 44 | return NULL; |
cd748f27 | 45 | } |
ed19251a | 46 | debug(20, 2) ("storeCreate: Selected dir '%d' for obj size '%ld'\n", dirn, (long int) objsize); |
cd748f27 | 47 | SD = &Config.cacheSwap.swapDirs[dirn]; |
48 | ||
49 | /* Now that we have a fs to use, call its storeCreate function */ | |
65a53c8e | 50 | sio = SD->obj.create(SD, e, file_callback, close_callback, callback_data); |
51 | if (NULL == sio) | |
52 | store_io_stats.create.create_fail++; | |
53 | else | |
54 | store_io_stats.create.success++; | |
55 | return sio; | |
cd748f27 | 56 | } |
57 | ||
2391a162 | 58 | |
cd748f27 | 59 | /* |
60 | * storeOpen() is purely for reading .. | |
61 | */ | |
2391a162 | 62 | storeIOState * |
a4b8110e | 63 | storeOpen(StoreEntry * e, STFNCB * file_callback, STIOCB * callback, |
64 | void *callback_data) | |
2391a162 | 65 | { |
cd748f27 | 66 | SwapDir *SD = &Config.cacheSwap.swapDirs[e->swap_dirn]; |
67 | return SD->obj.open(SD, e, file_callback, callback, callback_data); | |
2391a162 | 68 | } |
69 | ||
70 | void | |
60df005c | 71 | storeClose(storeIOState * sio) |
2391a162 | 72 | { |
cd748f27 | 73 | SwapDir *SD = &Config.cacheSwap.swapDirs[sio->swap_dirn]; |
5bd1abac | 74 | if (sio->flags.closing) |
75 | return; | |
2391a162 | 76 | sio->flags.closing = 1; |
cd748f27 | 77 | SD->obj.close(SD, sio); |
2391a162 | 78 | } |
79 | ||
80 | void | |
60df005c | 81 | storeRead(storeIOState * sio, char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data) |
2391a162 | 82 | { |
cd748f27 | 83 | SwapDir *SD = &Config.cacheSwap.swapDirs[sio->swap_dirn]; |
84 | SD->obj.read(SD, sio, buf, size, offset, callback, callback_data); | |
2391a162 | 85 | } |
86 | ||
87 | void | |
50f4d6ae | 88 | storeWrite(storeIOState * sio, char *buf, size_t size, off_t offset, FREE * free_func) |
2391a162 | 89 | { |
cd748f27 | 90 | SwapDir *SD = &Config.cacheSwap.swapDirs[sio->swap_dirn]; |
91 | SD->obj.write(SD, sio, buf, size, offset, free_func); | |
2391a162 | 92 | } |
93 | ||
94 | void | |
a4b8110e | 95 | storeUnlink(StoreEntry * e) |
2391a162 | 96 | { |
cd748f27 | 97 | SwapDir *SD = INDEXSD(e->swap_dirn); |
98 | SD->obj.unlink(SD, e); | |
2391a162 | 99 | } |
100 | ||
101 | off_t | |
60df005c | 102 | storeOffset(storeIOState * sio) |
2391a162 | 103 | { |
60df005c | 104 | return sio->offset; |
2391a162 | 105 | } |
65a53c8e | 106 | |
107 | /* | |
108 | * Make this non-static so we can register | |
109 | * it from storeInit(); | |
110 | */ | |
111 | void | |
112 | storeIOStats(StoreEntry * sentry) | |
113 | { | |
114 | storeAppendPrintf(sentry, "Store IO Interface Stats\n"); | |
115 | storeAppendPrintf(sentry, "create.calls %d\n", store_io_stats.create.calls); | |
116 | storeAppendPrintf(sentry, "create.select_fail %d\n", store_io_stats.create.select_fail); | |
117 | storeAppendPrintf(sentry, "create.create_fail %d\n", store_io_stats.create.create_fail); | |
118 | storeAppendPrintf(sentry, "create.success %d\n", store_io_stats.create.success); | |
119 | } |