30 debugs(79, 3,
"UFSStoreState::ioCompletedNotification: dirno " <<
31 swap_dirn <<
", fileno "<< std::setfill(
'0') << std::hex <<
32 std::setw(8) <<
swap_filen <<
" status "<< std::setfill(
' ') <<
43 debugs(79, 3,
"UFSStoreState::ioCompletedNotification: dirno " <<
44 swap_dirn <<
", fileno "<< std::setfill(
'0') << std::hex <<
45 std::setw(8) <<
swap_filen <<
" status "<< std::setfill(
' ') <<
54 debugs(79, 3,
"diskd::ioCompleted: dirno " <<
swap_dirn <<
", fileno "<<
55 std::setfill(
'0') << std::hex << std::setw(8) <<
swap_filen <<
56 " status "<< std::setfill(
' ') << std::dec <<
theFile->
error());
69 if (theFile->error()) {
77 }
else if ((
FILE_MODE(mode) == O_RDONLY) && !closing) {
82 if (flags.try_closing)
85 debugs(79, 3,
"UFSStoreState::openDone: exiting");
92 debugs(79, 3,
"UFSStoreState::closeCompleted: dirno " << swap_dirn <<
93 ", fileno "<< std::setfill(
'0') << std::hex << std::setw(8) <<
94 swap_filen <<
" status "<< std::setfill(
' ') << std::dec <<
97 if (theFile->error()) {
98 debugs(79,3,
"theFile->error() ret " << theFile->error());
119 debugs(79, 3,
"UFSStoreState::close: dirno " << swap_dirn <<
", fileno "<<
120 std::setfill(
'0') << std::hex << std::uppercase << std::setw(8) << swap_filen);
127 assert(read.callback ==
nullptr);
128 assert(read.callback_data ==
nullptr);
133 if (!theFile->canRead()) {
134 debugs(79, 3,
"queueing read because theFile can't read");
136 pending_reads.emplace(buf,
size, aOffset, aCallback, aCallbackData);
140 read.callback = aCallback;
142 debugs(79, 3,
"UFSStoreState::read_: dirno " << swap_dirn <<
", fileno "<<
143 std::setfill(
'0') << std::hex << std::uppercase << std::setw(8) << swap_filen);
161 debugs(79, 3,
"UFSStoreState::write: dirn " << swap_dirn <<
", fileno "<<
162 std::setfill(
'0') << std::hex << std::uppercase << std::setw(8) << swap_filen);
164 if (theFile->error()) {
167 free_func((
void*)buf);
172 if (
static_cast<uint64_t
>(offset_ +
size) >
static_cast<uint64_t
>(dir.
maxObjectSize())) {
173 debugs(79, 2,
"accepted unknown-size entry grew too big: " <<
175 free_func((
void*)buf);
180 debugs(79, 3, (
void*)
this <<
" queueing write of size " <<
size);
181 pending_writes.emplace(buf,
size, aOffset, free_func);
195 debugs(79, 3, (
void*)
this);
197 assert(theFile->canWrite());
199 if (pending_writes.empty()) {
200 debugs(79, 3, (
void*)
this <<
" write queue is empty");
204 auto &q = pending_writes.front();
206 if (theFile->error()) {
208 pending_writes.pop();
222 debugs(79, 3, (
void*)
this <<
" calling theFile->write(" << q.size <<
")");
224 theFile->write(
new WriteRequest(q.buf, q.offset, q.size, q.free_func));
226 pending_writes.pop();
234 debugs(79, 3,
"UFSStoreState::readCompleted: dirno " << swap_dirn <<
235 ", fileno "<< std::setfill(
'0') << std::hex << std::setw(8) <<
236 swap_filen <<
" len "<< std::setfill(
' ') << std::dec << len);
241 STRCB *callback_ = read.callback;
245 read.callback =
nullptr;
262 if (len > 0 && read_buf != buf)
263 memcpy(read_buf, buf, len);
265 callback_(
cbdata, read_buf, len,
this);
268 if (flags.try_closing || (theFile !=
nullptr && theFile->error()) )
275 debugs(79, 3,
"dirno " << swap_dirn <<
", fileno " <<
276 std::setfill(
'0') << std::hex << std::uppercase << std::setw(8) << swap_filen <<
286 if (theFile->error()) {
287 debugs(79,2,
" detected an error, will try to close");
301 debugs(79, 3,
"storeUfsIOCallback: errflag=" << errflag);
310 STIOCB *theCallback = callback;
316 theCallback(
cbdata, errflag,
this);
343 flags.write_draining =
false;
344 flags.try_closing =
false;
349 assert(pending_reads.empty());
350 assert(pending_writes.empty());
356 while (!pending_reads.empty())
358 debugs(79, 3,
"freed pending reads");
360 while (!pending_writes.empty())
361 pending_writes.pop();
362 debugs(79, 3,
"freed pending writes");
368 if (pending_reads.empty())
371 auto &q = pending_reads.front();
373 debugs(79, 3,
"reading queued request of " << q.size <<
" bytes");
378 read_(q.buf, q.size, q.offset, q.callback,
cbdata);
380 debugs(79, 2,
"this=" << (
void*)
this <<
" cbdataReferenceValidDone returned false." <<
381 " closing: " << closing <<
" flags.try_closing: " << flags.try_closing);
405 if (flags.write_draining)
408 if (!theFile || !theFile->canWrite())
411 flags.write_draining =
true;
413 while (!pending_writes.empty())
416 flags.write_draining =
false;
418 if (flags.try_closing)
432 debugs(79,3,
this <<
" tryClosing()" <<
433 " closing = " << closing <<
434 " flags.try_closing = " << flags.try_closing <<
435 " ioInProgress = " << theFile->ioInProgress());
437 if (theFile->ioInProgress()) {
439 " won't close since ioInProgress is true, bailing");
440 flags.try_closing =
true;
445 flags.try_closing =
false;
CBDATA_NAMESPACED_CLASS_INIT(Fs::Ufs, UFSStoreState)
#define cbdataReference(var)
#define cbdataReferenceValidDone(var, ptr)
virtual bool error() const =0
~UFSStoreState() override
virtual void doCloseCallback(int errflag)
void closeCompleted() override
void read_(char *buf, size_t size, off_t offset, STRCB *callback, void *callback_data) override
void writeCompleted(int errflag, size_t len, RefCount< WriteRequest >) override
bool write(char const *buf, size_t size, off_t offset, FREE *free_func) override
UFSStoreState(SwapDir *SD, StoreEntry *anEntry, STIOCB *callback_, void *callback_data_)
void close(int how) override
finish or abort swapping per CloseHow
void readCompleted(const char *buf, int len, int errflag, RefCount< ReadRequest >) override
struct Fs::Ufs::UFSStoreState::@66 flags
RefCount< DiskFile > theFile
void ioCompletedNotification() override
sfileno swap_filen
unique ID inside a cache_dir for swapped out entries; -1 for others
manages a single cache_dir
int64_t maxObjectSize() const override
the maximum size of a storable object; -1 if unlimited
#define debugs(SECTION, LEVEL, CONTENT)