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
"
14
#include "
DiskIO/DiskIOStrategy.h
"
15
#include "
UFSStoreState.h
"
16
#include "
UFSStrategy.h
"
17
#include "
UFSSwapDir.h
"
18
19
bool
20
Fs::Ufs::UFSStrategy::shedLoad
()
21
{
22
return
io
->
shedLoad
();
23
}
24
25
int
26
Fs::Ufs::UFSStrategy::load
()
27
{
28
return
io->load();
29
}
30
31
Fs::Ufs::UFSStrategy::UFSStrategy
(
DiskIOStrategy
*anIO) : io(anIO)
32
{}
33
34
Fs::Ufs::UFSStrategy::~UFSStrategy
()
35
{
36
delete
io;
37
}
38
39
StoreIOState::Pointer
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
45
DiskFile::Pointer
46
Fs::Ufs::UFSStrategy::newFile
(
char
const
*path)
47
{
48
return
io->newFile(path);
49
}
50
51
void
52
Fs::Ufs::UFSStrategy::unlinkFile
(
char
const
*path)
53
{
54
io->unlinkFile(path);
55
}
56
57
StoreIOState::Pointer
58
Fs::Ufs::UFSStrategy::open
(
SwapDir
*
const
SD,
StoreEntry
*
const
e,
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
92
StoreIOState::Pointer
93
Fs::Ufs::UFSStrategy::create
(
SwapDir
*
const
SD,
StoreEntry
*
const
e,
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
140
Fs::Ufs::UFSStrategy::callback
()
141
{
142
return
io->
callback
();
143
}
144
145
void
146
Fs::Ufs::UFSStrategy::init
()
147
{
148
io->init();
149
}
150
151
void
152
Fs::Ufs::UFSStrategy::sync
()
153
{
154
io->sync();
155
}
156
157
void
158
Fs::Ufs::UFSStrategy::statfs
(
StoreEntry
& sentry)
const
159
{
160
io->statfs(sentry);
161
}
162
DiskIOStrategy.h
IoManip.h
asHex
AsHex< Integer > asHex(const Integer n)
a helper to ease AsHex object creation
Definition
IoManip.h:169
UFSStoreState.h
UFSStrategy.h
UFSSwapDir.h
assert
#define assert(EX)
Definition
assert.h:17
DiskFile::open
virtual void open(int flags, mode_t mode, RefCount< IORequestor > callback)=0
DiskFile::create
virtual void create(int flags, mode_t mode, RefCount< IORequestor > callback)=0
DiskFile::error
virtual bool error() const =0
DiskIOStrategy
Definition
DiskIOStrategy.h:20
DiskIOStrategy::shedLoad
virtual bool shedLoad()=0
Fs::Ufs::UFSStoreState
Definition
UFSStoreState.h:24
Fs::Ufs::UFSStoreState::opening
bool opening
Definition
UFSStoreState.h:37
Fs::Ufs::UFSStoreState::creating
bool creating
Definition
UFSStoreState.h:38
Fs::Ufs::UFSStoreState::theFile
RefCount< DiskFile > theFile
Definition
UFSStoreState.h:36
Fs::Ufs::UFSStrategy::callback
virtual int callback()
Definition
UFSStrategy.cc:140
Fs::Ufs::UFSStrategy::load
virtual int load()
Definition
UFSStrategy.cc:26
Fs::Ufs::UFSStrategy::create
StoreIOState::Pointer create(SwapDir *, StoreEntry *, StoreIOState::STIOCB *, void *)
Definition
UFSStrategy.cc:93
Fs::Ufs::UFSStrategy::statfs
virtual void statfs(StoreEntry &sentry) const
Definition
UFSStrategy.cc:158
Fs::Ufs::UFSStrategy::sync
virtual void sync()
Definition
UFSStrategy.cc:152
Fs::Ufs::UFSStrategy::io
DiskIOStrategy * io
Definition
UFSStrategy.h:51
Fs::Ufs::UFSStrategy::shedLoad
virtual bool shedLoad()
Definition
UFSStrategy.cc:20
Fs::Ufs::UFSStrategy::newFile
virtual RefCount< DiskFile > newFile(char const *path)
Definition
UFSStrategy.cc:46
Fs::Ufs::UFSStrategy::createState
StoreIOState::Pointer createState(SwapDir *SD, StoreEntry *e, StoreIOState::STIOCB *callback, void *callback_data) const
Definition
UFSStrategy.cc:40
Fs::Ufs::UFSStrategy::UFSStrategy
UFSStrategy()
Fs::Ufs::UFSStrategy::~UFSStrategy
virtual ~UFSStrategy()
Definition
UFSStrategy.cc:34
Fs::Ufs::UFSStrategy::unlinkFile
virtual void unlinkFile(char const *)
Definition
UFSStrategy.cc:52
Fs::Ufs::UFSStrategy::init
virtual void init()
Definition
UFSStrategy.cc:146
Fs::Ufs::UFSStrategy::open
StoreIOState::Pointer open(SwapDir *, StoreEntry *, StoreIOState::STIOCB *, void *)
Definition
UFSStrategy.cc:58
Fs::Ufs::UFSSwapDir
Definition
UFSSwapDir.h:31
RefCount< StoreIOState >
RefCount::getRaw
C * getRaw() const
Definition
RefCount.h:89
StoreEntry
Definition
Store.h:38
StoreEntry::swap_filen
sfileno swap_filen
unique ID inside a cache_dir for swapped out entries; -1 for others
Definition
Store.h:235
StoreIOState::mode
mode_t mode
Definition
StoreIOState.h:74
StoreIOState::callback
STIOCB * callback
Definition
StoreIOState.h:76
StoreIOState::swap_filen
sfileno swap_filen
Definition
StoreIOState.h:72
StoreIOState::STIOCB
void STIOCB(void *their_data, int errflag, StoreIOState::Pointer self)
Definition
StoreIOState.h:39
Store::Disk
manages a single cache_dir
Definition
Disk.h:22
debugs
#define debugs(SECTION, LEVEL, CONTENT)
Definition
Stream.h:192
squid.h
sfileno
signed_int32_t sfileno
Definition
forward.h:22
squid
src
fs
ufs
UFSStrategy.cc
Generated by
1.9.8