]> git.ipfire.org Git - thirdparty/squid.git/blame - src/store_io.cc
Changed increment operators from postfix to prefix form.
[thirdparty/squid.git] / src / store_io.cc
CommitLineData
f7f3304a 1#include "squid-old.h"
e6ccf245 2#include "Store.h"
528b2c61 3#include "MemObject.h"
d3b3ab85 4#include "SwapDir.h"
2391a162 5
8822ebee 6StoreIoStats store_io_stats;
2391a162 7
cd748f27 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 */
d3b3ab85 14StoreIOState::Pointer
4fcc8876 15storeCreate(StoreEntry * e, StoreIOState::STFNCB * file_callback, StoreIOState::STIOCB * close_callback, void *callback_data)
cd748f27 16{
d3b3ab85 17 assert (e);
cd748f27 18
65a53c8e 19 store_io_stats.create.calls++;
cd748f27 20
21 /*
22 * Pick the swapdir
23 * We assume that the header has been packed by now ..
24 */
aa1a691e 25 const sdirno dirn = storeDirSelectSwapDir(e);
62e76326 26
cd748f27 27 if (dirn == -1) {
aa1a691e 28 debugs(20, 2, "storeCreate: no swapdirs for " << *e);
62e76326 29 store_io_stats.create.select_fail++;
30 return NULL;
cd748f27 31 }
62e76326 32
aa1a691e
AR
33 debugs(20, 2, "storeCreate: Selected dir " << dirn << " for " << *e);
34 SwapDir *SD = dynamic_cast<SwapDir *>(INDEXSD(dirn));
cd748f27 35
36 /* Now that we have a fs to use, call its storeCreate function */
d3b3ab85 37 StoreIOState::Pointer sio = SD->createStoreIO(*e, file_callback, close_callback, callback_data);
62e76326 38
d3b3ab85 39 if (sio == NULL)
62e76326 40 store_io_stats.create.create_fail++;
65a53c8e 41 else
62e76326 42 store_io_stats.create.success++;
43
65a53c8e 44 return sio;
cd748f27 45}
46
cd748f27 47/*
48 * storeOpen() is purely for reading ..
49 */
d3b3ab85 50StoreIOState::Pointer
4fcc8876 51storeOpen(StoreEntry * e, StoreIOState::STFNCB * file_callback, StoreIOState::STIOCB * callback,
62e76326 52 void *callback_data)
2391a162 53{
c8f4eac4 54 return dynamic_cast<SwapDir *>(e->store().getRaw())->openStoreIO(*e, file_callback, callback, callback_data);
2391a162 55}
56
57void
aa1a691e 58storeClose(StoreIOState::Pointer sio, int how)
2391a162 59{
bdf5b250 60 if (sio->flags.closing) {
26ac0430 61 debugs(20,3,HERE << "storeClose: flags.closing already set, bailing");
62e76326 62 return;
bdf5b250 63 }
62e76326 64
2391a162 65 sio->flags.closing = 1;
62e76326 66
aa1a691e
AR
67 debugs(20,3,HERE << "storeClose: calling sio->close(" << how << ")");
68 sio->close(how);
2391a162 69}
70
71void
4fcc8876 72storeRead(StoreIOState::Pointer sio, char *buf, size_t size, off_t offset, StoreIOState::STRCB * callback, void *callback_data)
2391a162 73{
d3b3ab85 74 sio->read_(buf, size, offset, callback, callback_data);
2391a162 75}
76
77void
528b2c61 78storeIOWrite(StoreIOState::Pointer sio, char const *buf, size_t size, off_t offset, FREE * free_func)
2391a162 79{
d3b3ab85 80 sio->write(buf,size,offset,free_func);
2391a162 81}