store_io.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 "store/Disk.h"
14 #include "store/Disks.h"
15 
17 
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  */
25 storeCreate(StoreEntry * e, StoreIOState::STFNCB * file_callback, StoreIOState::STIOCB * close_callback, void *callback_data)
26 {
27  assert (e);
28 
29  ++store_io_stats.create.calls;
30 
31  /*
32  * Pick the swapdir
33  * We assume that the header has been packed by now ..
34  */
35  const sdirno dirn = storeDirSelectSwapDir(e);
36 
37  if (dirn == -1) {
38  debugs(20, 2, "storeCreate: no swapdirs for " << *e);
39  ++store_io_stats.create.select_fail;
40  return NULL;
41  }
42 
43  debugs(20, 2, "storeCreate: Selected dir " << dirn << " for " << *e);
44  SwapDir *SD = dynamic_cast<SwapDir *>(INDEXSD(dirn));
45 
46  /* Now that we have a fs to use, call its storeCreate function */
47  StoreIOState::Pointer sio = SD->createStoreIO(*e, file_callback, close_callback, callback_data);
48 
49  if (sio == NULL)
50  ++store_io_stats.create.create_fail;
51  else
52  ++store_io_stats.create.success;
53 
54  return sio;
55 }
56 
57 /*
58  * storeOpen() is purely for reading ..
59  */
62  void *callback_data)
63 {
64  return e->disk().openStoreIO(*e, file_callback, callback, callback_data);
65 }
66 
67 void
69 {
70  if (sio->flags.closing) {
71  debugs(20,3,HERE << "storeClose: flags.closing already set, bailing");
72  return;
73  }
74 
75  sio->flags.closing = true;
76 
77  debugs(20,3,HERE << "storeClose: calling sio->close(" << how << ")");
78  sio->close(how);
79 }
80 
81 void
82 storeRead(StoreIOState::Pointer sio, char *buf, size_t size, off_t offset, StoreIOState::STRCB * callback, void *callback_data)
83 {
84  sio->read_(buf, size, offset, callback, callback_data);
85 }
86 
87 void
88 storeIOWrite(StoreIOState::Pointer sio, char const *buf, size_t size, off_t offset, FREE * free_func)
89 {
90  sio->write(buf,size,offset,free_func);
91 }
92 
#define assert(EX)
Definition: assert.h:17
void const char HLPCB * callback
Definition: stub_helper.cc:16
void STRCB(void *their_data, const char *buf, ssize_t len, StoreIOState::Pointer self)
Definition: StoreIOState.h:29
void storeClose(StoreIOState::Pointer sio, int how)
Definition: store_io.cc:68
struct StoreIoStats::@150 create
cache_dir selection and disk entry creation stats
void FREE(void *)
Definition: forward.h:36
void storeIOWrite(StoreIOState::Pointer sio, char const *buf, size_t size, off_t offset, FREE *free_func)
Definition: store_io.cc:88
StoreIoStats store_io_stats
Definition: store_io.cc:16
virtual void read_(char *buf, size_t size, off_t offset, STRCB *callback, void *callback_data)=0
virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *)=0
STDIRSELECT * storeDirSelectSwapDir
Definition: Disks.cc:28
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
virtual void close(int how)=0
finish or abort swapping per CloseHow
void STFNCB(void *their_data, int errflag, StoreIOState::Pointer self)
Definition: StoreIOState.h:41
Store statistics related to low-level I/O.
Definition: StoreStats.h:58
struct StoreIOState::@148 flags
#define INDEXSD(i)
Definition: SquidConfig.h:64
void const char * buf
Definition: stub_helper.cc:16
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:147
signed int sdirno
Definition: forward.h:23
void STIOCB(void *their_data, int errflag, StoreIOState::Pointer self)
Definition: StoreIOState.h:51
int select_fail
Definition: StoreStats.h:65
StoreIOState::Pointer storeOpen(StoreEntry *e, StoreIOState::STFNCB *file_callback, StoreIOState::STIOCB *callback, void *callback_data)
Definition: store_io.cc:61
Store::Disk & disk() const
the disk this entry is [being] cached on; asserts for entries w/o a disk
Definition: store.cc:2055
virtual bool write(char const *buf, size_t size, off_t offset, FREE *free_func)=0
virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *)=0
int create_fail
Definition: StoreStats.h:66
StoreIOState::Pointer storeCreate(StoreEntry *e, StoreIOState::STFNCB *file_callback, StoreIOState::STIOCB *close_callback, void *callback_data)
Definition: store_io.cc:25
#define NULL
Definition: types.h:166
int size
Definition: ModDevPoll.cc:77
void storeRead(StoreIOState::Pointer sio, char *buf, size_t size, off_t offset, StoreIOState::STRCB *callback, void *callback_data)
Definition: store_io.cc:82
manages a single cache_dir
Definition: Disk.h:21

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors