]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
f70aedc4 | 2 | * Copyright (C) 1996-2021 The Squid Software Foundation and contributors |
bbc27441 AJ |
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 | ||
582c2af2 | 9 | #include "squid.h" |
528b2c61 | 10 | #include "MemObject.h" |
4d5904f7 | 11 | #include "SquidConfig.h" |
602d9612 | 12 | #include "Store.h" |
2745fea5 AR |
13 | #include "store/Disk.h" |
14 | #include "store/Disks.h" | |
2391a162 | 15 | |
8822ebee | 16 | StoreIoStats store_io_stats; |
2391a162 | 17 | |
cd748f27 | 18 | /* |
19 | * submit a request to create a cache object for writing. | |
20 | * The StoreEntry structure is sent as a hint to the filesystem | |
21 | * to what will be stored in this object, to allow the filesystem | |
22 | * to select different polices depending on object size or type. | |
23 | */ | |
d3b3ab85 | 24 | StoreIOState::Pointer |
4fcc8876 | 25 | storeCreate(StoreEntry * e, StoreIOState::STFNCB * file_callback, StoreIOState::STIOCB * close_callback, void *callback_data) |
cd748f27 | 26 | { |
d3b3ab85 | 27 | assert (e); |
cd748f27 | 28 | |
5db6bf73 | 29 | ++store_io_stats.create.calls; |
cd748f27 | 30 | |
31 | /* | |
32 | * Pick the swapdir | |
33 | * We assume that the header has been packed by now .. | |
34 | */ | |
5d84beb5 | 35 | const auto sd = Store::Disks::SelectSwapDir(e); |
62e76326 | 36 | |
5d84beb5 | 37 | if (!sd) { |
aa1a691e | 38 | debugs(20, 2, "storeCreate: no swapdirs for " << *e); |
5db6bf73 | 39 | ++store_io_stats.create.select_fail; |
62e76326 | 40 | return NULL; |
cd748f27 | 41 | } |
62e76326 | 42 | |
cd748f27 | 43 | /* Now that we have a fs to use, call its storeCreate function */ |
5d84beb5 | 44 | StoreIOState::Pointer sio = sd->createStoreIO(*e, file_callback, close_callback, callback_data); |
62e76326 | 45 | |
d3b3ab85 | 46 | if (sio == NULL) |
5db6bf73 | 47 | ++store_io_stats.create.create_fail; |
65a53c8e | 48 | else |
5db6bf73 | 49 | ++store_io_stats.create.success; |
62e76326 | 50 | |
65a53c8e | 51 | return sio; |
cd748f27 | 52 | } |
53 | ||
cd748f27 | 54 | /* |
55 | * storeOpen() is purely for reading .. | |
56 | */ | |
d3b3ab85 | 57 | StoreIOState::Pointer |
4fcc8876 | 58 | storeOpen(StoreEntry * e, StoreIOState::STFNCB * file_callback, StoreIOState::STIOCB * callback, |
62e76326 | 59 | void *callback_data) |
2391a162 | 60 | { |
2745fea5 | 61 | return e->disk().openStoreIO(*e, file_callback, callback, callback_data); |
2391a162 | 62 | } |
63 | ||
64 | void | |
aa1a691e | 65 | storeClose(StoreIOState::Pointer sio, int how) |
2391a162 | 66 | { |
bdf5b250 | 67 | if (sio->flags.closing) { |
26ac0430 | 68 | debugs(20,3,HERE << "storeClose: flags.closing already set, bailing"); |
62e76326 | 69 | return; |
bdf5b250 | 70 | } |
62e76326 | 71 | |
3555cbff | 72 | sio->flags.closing = true; |
62e76326 | 73 | |
aa1a691e AR |
74 | debugs(20,3,HERE << "storeClose: calling sio->close(" << how << ")"); |
75 | sio->close(how); | |
2391a162 | 76 | } |
77 | ||
78 | void | |
4fcc8876 | 79 | storeRead(StoreIOState::Pointer sio, char *buf, size_t size, off_t offset, StoreIOState::STRCB * callback, void *callback_data) |
2391a162 | 80 | { |
d3b3ab85 | 81 | sio->read_(buf, size, offset, callback, callback_data); |
2391a162 | 82 | } |
83 | ||
84 | void | |
528b2c61 | 85 | storeIOWrite(StoreIOState::Pointer sio, char const *buf, size_t size, off_t offset, FREE * free_func) |
2391a162 | 86 | { |
d3b3ab85 | 87 | sio->write(buf,size,offset,free_func); |
2391a162 | 88 | } |
f53969cc | 89 |