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
14#include "UFSStoreState.h"
15#include "UFSStrategy.h"
16#include "UFSSwapDir.h"
17
18bool
20{
21 return io->shedLoad();
22}
23
24int
26{
27 return io->load();
28}
29
31{}
32
34{
35 delete io;
36}
37
39Fs::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
50void
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, "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, 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 "<< 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, nullptr);
115
116 DiskFile::Pointer myFile = newFile (path);
117
118 if (myFile.getRaw() == nullptr) {
119 ((UFSSwapDir *)SD)->mapBitReset (filn);
120 return nullptr;
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 nullptr;
132 }
133
134 /* now insert into the replacement policy */
135 ((UFSSwapDir *)SD)->replacementAdd(e);
136
137 return sio;
138}
139
140int
142{
143 return io->callback();
144}
145
146void
148{
149 io->init();
150}
151
152void
154{
155 io->sync();
156}
157
158void
160{
161 io->statfs(sentry);
162}
163
#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
Definition: UFSStoreState.h:36
virtual int callback()
Definition: UFSStrategy.cc:141
virtual int load()
Definition: UFSStrategy.cc:25
StoreIOState::Pointer create(SwapDir *, StoreEntry *, StoreIOState::STIOCB *, void *)
Definition: UFSStrategy.cc:93
virtual void statfs(StoreEntry &sentry) const
Definition: UFSStrategy.cc:159
virtual void sync()
Definition: UFSStrategy.cc:153
DiskIOStrategy * io
Definition: UFSStrategy.h:51
virtual bool shedLoad()
Definition: UFSStrategy.cc:19
virtual RefCount< DiskFile > newFile(char const *path)
Definition: UFSStrategy.cc:45
StoreIOState::Pointer createState(SwapDir *SD, StoreEntry *e, StoreIOState::STIOCB *callback, void *callback_data) const
Definition: UFSStrategy.cc:39
virtual ~UFSStrategy()
Definition: UFSStrategy.cc:33
virtual void unlinkFile(char const *)
Definition: UFSStrategy.cc:51
virtual void init()
Definition: UFSStrategy.cc:147
StoreIOState::Pointer open(SwapDir *, StoreEntry *, StoreIOState::STIOCB *, void *)
Definition: UFSStrategy.cc:57
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:236
sfileno swap_filen
Definition: StoreIOState.h:72
void STIOCB(void *their_data, int errflag, StoreIOState::Pointer self)
Definition: StoreIOState.h:39
manages a single cache_dir
Definition: Disk.h:22
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
signed_int32_t sfileno
Definition: forward.h:22

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors