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