UFSStrategy.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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 "base/IoManip.h"
14 #include "DiskIO/DiskIOStrategy.h"
15 #include "UFSStoreState.h"
16 #include "UFSStrategy.h"
17 #include "UFSSwapDir.h"
18 
19 bool
21 {
22  return io->shedLoad();
23 }
24 
25 int
27 {
28  return io->load();
29 }
30 
32 {}
33 
35 {
36  delete io;
37 }
38 
40 Fs::Ufs::UFSStrategy::createState(SwapDir *SD, StoreEntry *e, StoreIOState::STIOCB * aCallback, void *callback_data) const
41 {
42  return new Fs::Ufs::UFSStoreState (SD, e, aCallback, callback_data);
43 }
44 
47 {
48  return io->newFile(path);
49 }
50 
51 void
53 {
54  io->unlinkFile(path);
55 }
56 
59  StoreIOState::STIOCB * aCallback, void *callback_data)
60 {
61  assert (((UFSSwapDir *)SD)->IO == this);
62  debugs(79, 3, "fileno " << asHex(e->swap_filen).upperCase().minDigits(8));
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, nullptr);
74 
75  DiskFile::Pointer myFile = newFile (path);
76 
77  if (myFile.getRaw() == nullptr)
78  return nullptr;
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 nullptr;
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, "fileno " << asHex(filn).upperCase().minDigits(8));
100 
101  /* Shouldn't we handle a 'bitmap full' error here? */
102 
103  StoreIOState::Pointer sio = createState (SD, e, aCallback, callback_data);
104 
105  sio->mode |= O_WRONLY | O_CREAT | O_TRUNC;
106 
107  sio->swap_filen = filn;
108 
109  Fs::Ufs::UFSStoreState *state = dynamic_cast <Fs::Ufs::UFSStoreState *>(sio.getRaw());
110 
111  assert (state);
112 
113  char *path = ((UFSSwapDir *)SD)->fullPath(filn, nullptr);
114 
115  DiskFile::Pointer myFile = newFile (path);
116 
117  if (myFile.getRaw() == nullptr) {
118  ((UFSSwapDir *)SD)->mapBitReset (filn);
119  return nullptr;
120  }
121 
122  state->theFile = myFile;
123 
124  state->creating = true;
125 
126  myFile->create (state->mode, 0644, state);
127 
128  if (myFile->error()) {
129  ((UFSSwapDir *)SD)->mapBitReset (filn);
130  return nullptr;
131  }
132 
133  /* now insert into the replacement policy */
134  ((UFSSwapDir *)SD)->replacementAdd(e);
135 
136  return sio;
137 }
138 
139 int
141 {
142  return io->callback();
143 }
144 
145 void
147 {
148  io->init();
149 }
150 
151 void
153 {
154  io->sync();
155 }
156 
157 void
159 {
160  io->statfs(sentry);
161 }
162 
virtual void open(int flags, mode_t mode, RefCount< IORequestor > callback)=0
virtual bool shedLoad()=0
virtual void init()
Definition: UFSStrategy.cc:146
manages a single cache_dir
Definition: Disk.h:21
RefCount< DiskFile > theFile
Definition: UFSStoreState.h:36
virtual int load()
Definition: UFSStrategy.cc:26
virtual void unlinkFile(char const *)
Definition: UFSStrategy.cc:52
C * getRaw() const
Definition: RefCount.h:89
virtual int callback()
Definition: UFSStrategy.cc:140
virtual bool shedLoad()
Definition: UFSStrategy.cc:20
virtual RefCount< DiskFile > newFile(char const *path)
Definition: UFSStrategy.cc:46
StoreIOState::Pointer open(SwapDir *, StoreEntry *, StoreIOState::STIOCB *, void *)
Definition: UFSStrategy.cc:58
AsHex< Integer > asHex(const Integer n)
a helper to ease AsHex object creation
Definition: IoManip.h:169
StoreIOState::Pointer create(SwapDir *, StoreEntry *, StoreIOState::STIOCB *, void *)
Definition: UFSStrategy.cc:93
StoreIOState::Pointer createState(SwapDir *SD, StoreEntry *e, StoreIOState::STIOCB *callback, void *callback_data) const
Definition: UFSStrategy.cc:40
virtual bool error() const =0
#define assert(EX)
Definition: assert.h:17
signed_int32_t sfileno
Definition: forward.h:22
DiskIOStrategy * io
Definition: UFSStrategy.h:51
void STIOCB(void *their_data, int errflag, StoreIOState::Pointer self)
Definition: StoreIOState.h:39
virtual void sync()
Definition: UFSStrategy.cc:152
virtual void statfs(StoreEntry &sentry) const
Definition: UFSStrategy.cc:158
virtual ~UFSStrategy()
Definition: UFSStrategy.cc:34
sfileno swap_filen
Definition: StoreIOState.h:72
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192
virtual void create(int flags, mode_t mode, RefCount< IORequestor > callback)=0
sfileno swap_filen
unique ID inside a cache_dir for swapped out entries; -1 for others
Definition: Store.h:235

 

Introduction

Documentation

Support

Miscellaneous