]> git.ipfire.org Git - thirdparty/squid.git/blob - src/store_io.cc
Renamed squid.h to squid-old.h and config.h to squid.h
[thirdparty/squid.git] / src / store_io.cc
1 #include "squid-old.h"
2 #include "Store.h"
3 #include "MemObject.h"
4 #include "SwapDir.h"
5
6 StoreIoStats store_io_stats;
7
8 /*
9 * submit a request to create a cache object for writing.
10 * The StoreEntry structure is sent as a hint to the filesystem
11 * to what will be stored in this object, to allow the filesystem
12 * to select different polices depending on object size or type.
13 */
14 StoreIOState::Pointer
15 storeCreate(StoreEntry * e, StoreIOState::STFNCB * file_callback, StoreIOState::STIOCB * close_callback, void *callback_data)
16 {
17 assert (e);
18
19 store_io_stats.create.calls++;
20
21 /*
22 * Pick the swapdir
23 * We assume that the header has been packed by now ..
24 */
25 const sdirno dirn = storeDirSelectSwapDir(e);
26
27 if (dirn == -1) {
28 debugs(20, 2, "storeCreate: no swapdirs for " << *e);
29 store_io_stats.create.select_fail++;
30 return NULL;
31 }
32
33 debugs(20, 2, "storeCreate: Selected dir " << dirn << " for " << *e);
34 SwapDir *SD = dynamic_cast<SwapDir *>(INDEXSD(dirn));
35
36 /* Now that we have a fs to use, call its storeCreate function */
37 StoreIOState::Pointer sio = SD->createStoreIO(*e, file_callback, close_callback, callback_data);
38
39 if (sio == NULL)
40 store_io_stats.create.create_fail++;
41 else
42 store_io_stats.create.success++;
43
44 return sio;
45 }
46
47 /*
48 * storeOpen() is purely for reading ..
49 */
50 StoreIOState::Pointer
51 storeOpen(StoreEntry * e, StoreIOState::STFNCB * file_callback, StoreIOState::STIOCB * callback,
52 void *callback_data)
53 {
54 return dynamic_cast<SwapDir *>(e->store().getRaw())->openStoreIO(*e, file_callback, callback, callback_data);
55 }
56
57 void
58 storeClose(StoreIOState::Pointer sio, int how)
59 {
60 if (sio->flags.closing) {
61 debugs(20,3,HERE << "storeClose: flags.closing already set, bailing");
62 return;
63 }
64
65 sio->flags.closing = 1;
66
67 debugs(20,3,HERE << "storeClose: calling sio->close(" << how << ")");
68 sio->close(how);
69 }
70
71 void
72 storeRead(StoreIOState::Pointer sio, char *buf, size_t size, off_t offset, StoreIOState::STRCB * callback, void *callback_data)
73 {
74 sio->read_(buf, size, offset, callback, callback_data);
75 }
76
77 void
78 storeIOWrite(StoreIOState::Pointer sio, char const *buf, size_t size, off_t offset, FREE * free_func)
79 {
80 sio->write(buf,size,offset,free_func);
81 }