]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/DiskIO/DiskDaemon/DiskdFile.cc
2 * Copyright (C) 1996-2015 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
,
106 // IO->shm.put (shm_offset);
107 debugs(79, DBG_IMPORTANT
, "storeDiskdSend CREATE: " << xstrerror());
113 ++diskd_stats
.create
.ops
;
117 DiskdFile::read(ReadRequest
*aRead
)
119 assert (ioRequestor
.getRaw() != NULL
);
121 char *rbuf
= (char *)IO
->shm
.get(&shm_offset
);
124 int x
= IO
->send(_MQD_READ
,
135 // IO->shm.put (shm_offset);
136 debugs(79, DBG_IMPORTANT
, "storeDiskdSend READ: " << xstrerror());
142 ++diskd_stats
.read
.ops
;
148 debugs(79, 3, "DiskdFile::close: " << this << " closing for " << ioRequestor
.getRaw());
149 assert (ioRequestor
.getRaw());
151 int x
= IO
->send(_MQD_CLOSE
,
162 debugs(79, DBG_IMPORTANT
, "storeDiskdSend CLOSE: " << xstrerror());
168 ++diskd_stats
.close
.ops
;
172 DiskdFile::error() const
178 DiskdFile::canRead() const
184 DiskdFile::canNotifyClient() const
186 if (!ioRequestor
.getRaw()) {
187 debugs(79, 3, "DiskdFile::canNotifyClient: No ioRequestor to notify");
195 DiskdFile::notifyClient()
197 if (!canNotifyClient()) {
201 ioRequestor
->ioCompletedNotification();
205 DiskdFile::completed(diomsg
*M
)
207 assert (M
->newstyle
);
242 DiskdFile::openDone(diomsg
*M
)
244 ++statCounter
.syscalls
.disk
.opens
;
245 debugs(79, 3, "storeDiskdOpenDone: status " << M
->status
);
248 ++diskd_stats
.open
.fail
;
251 ++diskd_stats
.open
.success
;
259 DiskdFile::createDone(diomsg
*M
)
261 ++statCounter
.syscalls
.disk
.opens
;
262 debugs(79, 3, "storeDiskdCreateDone: status " << M
->status
);
265 ++diskd_stats
.create
.fail
;
268 ++diskd_stats
.create
.success
;
276 DiskdFile::write(WriteRequest
*aRequest
)
278 debugs(79, 3, "DiskdFile::write: this " << (void *)this << ", buf " << (void *)aRequest
->buf
<< ", off " << aRequest
->offset
<< ", len " << aRequest
->len
);
280 char *sbuf
= (char *)IO
->shm
.get(&shm_offset
);
281 memcpy(sbuf
, aRequest
->buf
, aRequest
->len
);
283 if (aRequest
->free_func
)
284 aRequest
->free_func(const_cast<char *>(aRequest
->buf
));
288 int x
= IO
->send(_MQD_WRITE
,
299 debugs(79, DBG_IMPORTANT
, "storeDiskdSend WRITE: " << xstrerror());
300 // IO->shm.put (shm_offset);
306 ++diskd_stats
.write
.ops
;
316 DiskdFile::ioCompleted()
322 DiskdFile::closeDone(diomsg
* M
)
324 ++statCounter
.syscalls
.disk
.closes
;
325 debugs(79, 3, "DiskdFile::closeDone: status " << M
->status
);
328 ++diskd_stats
.close
.fail
;
331 ++diskd_stats
.close
.success
;
336 if (canNotifyClient())
337 ioRequestor
->closeCompleted();
343 DiskdFile::readDone(diomsg
* M
)
345 ++statCounter
.syscalls
.disk
.reads
;
346 debugs(79, 3, "DiskdFile::readDone: status " << M
->status
);
347 assert (M
->requestor
);
348 ReadRequest::Pointer readRequest
= dynamic_cast<ReadRequest
*>(M
->requestor
);
350 /* remove the free protection */
351 if (readRequest
!= NULL
)
352 readRequest
->unlock();
355 ++diskd_stats
.read
.fail
;
358 ioRequestor
->readCompleted(NULL
, -1, DISK_ERROR
, readRequest
);
362 ++diskd_stats
.read
.success
;
365 ioRequestor
->readCompleted (IO
->shm
.buf
+ M
->shm_offset
, M
->status
, DISK_OK
, readRequest
);
369 DiskdFile::writeDone(diomsg
*M
)
371 ++statCounter
.syscalls
.disk
.writes
;
372 debugs(79, 3, "storeDiskdWriteDone: status " << M
->status
);
373 assert (M
->requestor
);
374 WriteRequest::Pointer writeRequest
= dynamic_cast<WriteRequest
*>(M
->requestor
);
375 /* remove the free protection */
376 if (writeRequest
!= NULL
)
377 writeRequest
->unlock();
381 ++diskd_stats
.write
.fail
;
383 ioRequestor
->writeCompleted (DISK_ERROR
,0, writeRequest
);
387 ++diskd_stats
.write
.success
;
389 ioRequestor
->writeCompleted (DISK_OK
,M
->status
, writeRequest
);
393 DiskdFile::ioInProgress()const
395 return inProgressIOs
!= 0;