UFSStrategy.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 /* DEBUG: section 47 Store Directory Routines */
10 
11 #include "squid.h"
12 
13 #include "DiskIO/DiskIOStrategy.h"
14 #include "UFSStoreState.h"
15 #include "UFSStrategy.h"
16 #include "UFSSwapDir.h"
17 
18 bool
20 {
21  return io->shedLoad();
22 }
23 
24 int
26 {
27  return io->load();
28 }
29 
31 {}
32 
34 {
35  delete io;
36 }
37 
39 Fs::Ufs::UFSStrategy::createState(SwapDir *SD, StoreEntry *e, StoreIOState::STIOCB * aCallback, void *callback_data) const
40 {
41  return new Fs::Ufs::UFSStoreState (SD, e, aCallback, callback_data);
42 }
43 
46 {
47  return io->newFile(path);
48 }
49 
50 void
52 {
53  io->unlinkFile(path);
54 }
55 
58  StoreIOState::STIOCB * aCallback, void *callback_data)
59 {
60  assert (((UFSSwapDir *)SD)->IO == this);
61  debugs(79, 3, HERE << "fileno "<< std::setfill('0') << std::hex
62  << std::uppercase << std::setw(8) << e->swap_filen);
63 
64  /* to consider: make createstate a private UFSStrategy call */
65  StoreIOState::Pointer sio = createState (SD, e, aCallback, callback_data);
66 
67  sio->mode |= O_RDONLY;
68 
69  Fs::Ufs::UFSStoreState *state = dynamic_cast <Fs::Ufs::UFSStoreState *>(sio.getRaw());
70 
71  assert (state);
72 
73  char *path = ((UFSSwapDir *)SD)->fullPath(e->swap_filen, NULL);
74 
75  DiskFile::Pointer myFile = newFile (path);
76 
77  if (myFile.getRaw() == NULL)
78  return NULL;
79 
80  state->theFile = myFile;
81 
82  state->opening = true;
83 
84  myFile->open (sio->mode, 0644, state);
85 
86  if (myFile->error())
87  return NULL;
88 
89  return sio;
90 }
91 
94  StoreIOState::STIOCB * aCallback, void *callback_data)
95 {
96  assert (((UFSSwapDir *)SD)->IO == this);
97  /* Allocate a number */
98  sfileno filn = ((UFSSwapDir *)SD)->mapBitAllocate();
99  debugs(79, 3, HERE << "fileno "<< std::setfill('0') <<
100  std::hex << std::uppercase << std::setw(8) << filn);
101 
102  /* Shouldn't we handle a 'bitmap full' error here? */
103 
104  StoreIOState::Pointer sio = createState (SD, e, aCallback, callback_data);
105 
106  sio->mode |= O_WRONLY | O_CREAT | O_TRUNC;
107 
108  sio->swap_filen = filn;
109 
110  Fs::Ufs::UFSStoreState *state = dynamic_cast <Fs::Ufs::UFSStoreState *>(sio.getRaw());
111 
112  assert (state);
113 
114  char *path = ((UFSSwapDir *)SD)->fullPath(filn, NULL);
115 
116  DiskFile::Pointer myFile = newFile (path);
117 
118  if (myFile.getRaw() == NULL) {
119  ((UFSSwapDir *)SD)->mapBitReset (filn);
120  return NULL;
121  }
122 
123  state->theFile = myFile;
124 
125  state->creating = true;
126 
127  myFile->create (state->mode, 0644, state);
128 
129  if (myFile->error()) {
130  ((UFSSwapDir *)SD)->mapBitReset (filn);
131  return NULL;
132  }
133 
134  /* now insert into the replacement policy */
135  ((UFSSwapDir *)SD)->replacementAdd(e);
136 
137  return sio;
138 }
139 
140 int
142 {
143  return io->callback();
144 }
145 
146 void
148 {
149  io->init();
150 }
151 
152 void
154 {
155  io->sync();
156 }
157 
158 void
160 {
161  io->statfs(sentry);
162 }
163 
virtual void init()
Definition: UFSStrategy.cc:147
#define assert(EX)
Definition: assert.h:17
virtual void create(int flags, mode_t mode, RefCount< IORequestor > callback)=0
virtual void unlinkFile(char const *)
Definition: UFSStrategy.cc:51
sfileno swap_filen
unique ID inside a cache_dir for swapped out entries; -1 for others
Definition: Store.h:177
virtual int load()
Definition: UFSStrategy.cc:25
virtual RefCount< DiskFile > newFile(char const *path)
Definition: UFSStrategy.cc:45
virtual int callback()
Definition: UFSStrategy.cc:141
StoreIOState::Pointer open(SwapDir *, StoreEntry *, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *)
Definition: UFSStrategy.cc:57
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
virtual bool error() const =0
StoreIOState::Pointer createState(SwapDir *SD, StoreEntry *e, StoreIOState::STIOCB *callback, void *callback_data) const
Definition: UFSStrategy.cc:39
void STFNCB(void *their_data, int errflag, StoreIOState::Pointer self)
Definition: StoreIOState.h:41
StoreIOState::Pointer create(SwapDir *, StoreEntry *, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *)
Definition: UFSStrategy.cc:93
virtual bool shedLoad()=0
virtual bool shedLoad()
Definition: UFSStrategy.cc:19
signed_int32_t sfileno
Definition: forward.h:22
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:147
void STIOCB(void *their_data, int errflag, StoreIOState::Pointer self)
Definition: StoreIOState.h:51
DiskIOStrategy * io
Definition: UFSStrategy.h:53
virtual ~UFSStrategy()
Definition: UFSStrategy.cc:33
virtual void statfs(StoreEntry &sentry) const
Definition: UFSStrategy.cc:159
virtual void sync()
Definition: UFSStrategy.cc:153
RefCount< DiskFile > theFile
Definition: UFSStoreState.h:35
virtual void open(int flags, mode_t mode, RefCount< IORequestor > callback)=0
C * getRaw() const
Definition: RefCount.h:74
#define NULL
Definition: types.h:166
sfileno swap_filen
Definition: StoreIOState.h:84
manages a single cache_dir
Definition: Disk.h:21

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors