Squid Web Cache master
Loading...
Searching...
No Matches
UFSStrategy.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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"
15#include "UFSStoreState.h"
16#include "UFSStrategy.h"
17#include "UFSSwapDir.h"
18
19bool
24
25int
27{
28 return io->load();
29}
30
33
35{
36 delete io;
37}
38
40Fs::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
51void
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
139int
141{
142 return io->callback();
143}
144
145void
147{
148 io->init();
149}
150
151void
153{
154 io->sync();
155}
156
157void
159{
160 io->statfs(sentry);
161}
162
AsHex< Integer > asHex(const Integer n)
a helper to ease AsHex object creation
Definition IoManip.h:169
#define assert(EX)
Definition assert.h:17
virtual void open(int flags, mode_t mode, RefCount< IORequestor > callback)=0
virtual void create(int flags, mode_t mode, RefCount< IORequestor > callback)=0
virtual bool error() const =0
virtual bool shedLoad()=0
RefCount< DiskFile > theFile
virtual int callback()
virtual int load()
StoreIOState::Pointer create(SwapDir *, StoreEntry *, StoreIOState::STIOCB *, void *)
virtual void statfs(StoreEntry &sentry) const
virtual void sync()
DiskIOStrategy * io
Definition UFSStrategy.h:51
virtual bool shedLoad()
virtual RefCount< DiskFile > newFile(char const *path)
StoreIOState::Pointer createState(SwapDir *SD, StoreEntry *e, StoreIOState::STIOCB *callback, void *callback_data) const
virtual void unlinkFile(char const *)
virtual void init()
StoreIOState::Pointer open(SwapDir *, StoreEntry *, StoreIOState::STIOCB *, void *)
C * getRaw() const
Definition RefCount.h:89
sfileno swap_filen
unique ID inside a cache_dir for swapped out entries; -1 for others
Definition Store.h:235
STIOCB * callback
sfileno swap_filen
void STIOCB(void *their_data, int errflag, StoreIOState::Pointer self)
manages a single cache_dir
Definition Disk.h:22
#define debugs(SECTION, LEVEL, CONTENT)
Definition Stream.h:192
signed_int32_t sfileno
Definition forward.h:22