]> git.ipfire.org Git - thirdparty/squid.git/blame - src/store_io.cc
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / store_io.cc
CommitLineData
bbc27441 1/*
b8ae064d 2 * Copyright (C) 1996-2023 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 16StoreIoStats 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 24StoreIOState::Pointer
4fcc8876 25storeCreate(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;
aee3523a 40 return nullptr;
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
aee3523a 46 if (sio == nullptr)
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 57StoreIOState::Pointer
4fcc8876 58storeOpen(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
64void
aa1a691e 65storeClose(StoreIOState::Pointer sio, int how)
2391a162 66{
bdf5b250 67 if (sio->flags.closing) {
bf95c10a 68 debugs(20,3, "storeClose: flags.closing already set, bailing");
62e76326 69 return;
bdf5b250 70 }
62e76326 71
3555cbff 72 sio->flags.closing = true;
62e76326 73
bf95c10a 74 debugs(20,3, "storeClose: calling sio->close(" << how << ")");
aa1a691e 75 sio->close(how);
2391a162 76}
77
78void
4fcc8876 79storeRead(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
84void
528b2c61 85storeIOWrite(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