]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/DiskIO/DiskDaemon/DiskdFile.cc
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 79 Squid-side DISKD I/O functions. */
12 #include "ConfigOption.h"
14 #include "DiskdFile.h"
15 #include "DiskdIOStrategy.h"
16 #include "DiskIO/IORequestor.h"
17 #include "DiskIO/ReadRequest.h"
18 #include "DiskIO/WriteRequest.h"
19 #include "StatCounters.h"
31 CBDATA_CLASS_INIT(DiskdFile
);
33 DiskdFile::DiskdFile(char const *aPath
, DiskdIOStrategy
*anIO
) :
40 debugs(79, 3, "DiskdFile::DiskdFile: " << aPath
);
41 path_
= xstrdup(aPath
);
42 id
= diskd_stats
.sio_id
;
46 DiskdFile::~DiskdFile()
48 assert(inProgressIOs
== 0);
53 DiskdFile::open(int flags
, mode_t
, RefCount
<IORequestor
> callback
)
55 debugs(79, 3, "DiskdFile::open: " << this << " opening for " << callback
.getRaw());
56 assert(ioRequestor
.getRaw() == NULL
);
57 ioRequestor
= callback
;
58 assert(callback
.getRaw());
61 char *buf
= (char *)IO
->shm
.get(&shm_offset
);
62 xstrncpy(buf
, path_
, SHMBUF_BLKSZ
);
64 int x
= IO
->send(_MQD_OPEN
,
75 // IO->shm.put (shm_offset);
76 ioRequestor
->ioCompletedNotification();
80 ++diskd_stats
.open
.ops
;
84 DiskdFile::create(int flags
, mode_t
, RefCount
<IORequestor
> callback
)
86 debugs(79, 3, "DiskdFile::create: " << this << " creating for " << callback
.getRaw());
87 assert (ioRequestor
.getRaw() == NULL
);
88 ioRequestor
= callback
;
89 assert (callback
.getRaw());
92 char *buf
= (char *)IO
->shm
.get(&shm_offset
);
93 xstrncpy(buf
, path_
, SHMBUF_BLKSZ
);
95 int x
= IO
->send(_MQD_CREATE
,
107 // IO->shm.put (shm_offset);
108 debugs(79, DBG_IMPORTANT
, "storeDiskdSend CREATE: " << xstrerr(xerrno
));
114 ++diskd_stats
.create
.ops
;
118 DiskdFile::read(ReadRequest
*aRead
)
120 assert (ioRequestor
.getRaw() != NULL
);
122 char *rbuf
= (char *)IO
->shm
.get(&shm_offset
);
125 int x
= IO
->send(_MQD_READ
,
137 // IO->shm.put (shm_offset);
138 debugs(79, DBG_IMPORTANT
, "storeDiskdSend READ: " << xstrerr(xerrno
));
144 ++diskd_stats
.read
.ops
;
150 debugs(79, 3, "DiskdFile::close: " << this << " closing for " << ioRequestor
.getRaw());
151 assert (ioRequestor
.getRaw());
153 int x
= IO
->send(_MQD_CLOSE
,
165 debugs(79, DBG_IMPORTANT
, "storeDiskdSend CLOSE: " << xstrerr(xerrno
));
171 ++diskd_stats
.close
.ops
;
175 DiskdFile::error() const
181 DiskdFile::canRead() const
187 DiskdFile::canNotifyClient() const
189 if (!ioRequestor
.getRaw()) {
190 debugs(79, 3, "DiskdFile::canNotifyClient: No ioRequestor to notify");
198 DiskdFile::notifyClient()
200 if (!canNotifyClient()) {
204 ioRequestor
->ioCompletedNotification();
208 DiskdFile::completed(diomsg
*M
)
210 assert (M
->newstyle
);
245 DiskdFile::openDone(diomsg
*M
)
247 ++statCounter
.syscalls
.disk
.opens
;
248 debugs(79, 3, "storeDiskdOpenDone: status " << M
->status
);
251 ++diskd_stats
.open
.fail
;
254 ++diskd_stats
.open
.success
;
262 DiskdFile::createDone(diomsg
*M
)
264 ++statCounter
.syscalls
.disk
.opens
;
265 debugs(79, 3, "storeDiskdCreateDone: status " << M
->status
);
268 ++diskd_stats
.create
.fail
;
271 ++diskd_stats
.create
.success
;
279 DiskdFile::write(WriteRequest
*aRequest
)
281 debugs(79, 3, "DiskdFile::write: this " << (void *)this << ", buf " << (void *)aRequest
->buf
<< ", off " << aRequest
->offset
<< ", len " << aRequest
->len
);
283 char *sbuf
= (char *)IO
->shm
.get(&shm_offset
);
284 memcpy(sbuf
, aRequest
->buf
, aRequest
->len
);
286 if (aRequest
->free_func
)
287 aRequest
->free_func(const_cast<char *>(aRequest
->buf
));
291 int x
= IO
->send(_MQD_WRITE
,
303 debugs(79, DBG_IMPORTANT
, "storeDiskdSend WRITE: " << xstrerr(xerrno
));
304 // IO->shm.put (shm_offset);
310 ++diskd_stats
.write
.ops
;
320 DiskdFile::ioCompleted()
326 DiskdFile::closeDone(diomsg
* M
)
328 ++statCounter
.syscalls
.disk
.closes
;
329 debugs(79, 3, "DiskdFile::closeDone: status " << M
->status
);
332 ++diskd_stats
.close
.fail
;
335 ++diskd_stats
.close
.success
;
340 if (canNotifyClient())
341 ioRequestor
->closeCompleted();
347 DiskdFile::readDone(diomsg
* M
)
349 ++statCounter
.syscalls
.disk
.reads
;
350 debugs(79, 3, "DiskdFile::readDone: status " << M
->status
);
351 assert (M
->requestor
);
352 ReadRequest::Pointer readRequest
= dynamic_cast<ReadRequest
*>(M
->requestor
);
354 /* remove the free protection */
355 if (readRequest
!= NULL
) {
356 const uint32_t lcount
= readRequest
->unlock();
358 debugs(79, DBG_IMPORTANT
, "invariant check failed: readRequest reference count is 0");
362 ++diskd_stats
.read
.fail
;
365 ioRequestor
->readCompleted(NULL
, -1, DISK_ERROR
, readRequest
);
369 ++diskd_stats
.read
.success
;
372 ioRequestor
->readCompleted (IO
->shm
.buf
+ M
->shm_offset
, M
->status
, DISK_OK
, readRequest
);
376 DiskdFile::writeDone(diomsg
*M
)
378 ++statCounter
.syscalls
.disk
.writes
;
379 debugs(79, 3, "storeDiskdWriteDone: status " << M
->status
);
380 assert (M
->requestor
);
381 WriteRequest::Pointer writeRequest
= dynamic_cast<WriteRequest
*>(M
->requestor
);
383 /* remove the free protection */
384 if (writeRequest
!= NULL
) {
385 const uint32_t lcount
= writeRequest
->unlock();
387 debugs(79, DBG_IMPORTANT
, "invariant check failed: writeRequest reference count is 0");
392 ++diskd_stats
.write
.fail
;
394 ioRequestor
->writeCompleted (DISK_ERROR
,0, writeRequest
);
398 ++diskd_stats
.write
.success
;
400 ioRequestor
->writeCompleted (DISK_OK
,M
->status
, writeRequest
);
404 DiskdFile::ioInProgress()const
406 return inProgressIOs
!= 0;