3
* $Id: DiskdFile.cc,v 1.2 2004/12/21 17:28:29 robertc Exp $
5
* DEBUG: section 79 Squid-side DISKD I/O functions.
6
* AUTHOR: Duane Wessels
8
* SQUID Web Proxy Cache http://www.squid-cache.org/
9
* ----------------------------------------------------------
11
* Squid is the result of efforts by numerous individuals from
12
* the Internet community; see the CONTRIBUTORS file for full
13
* details. Many organizations have provided support for Squid's
14
* development; see the SPONSORS file for full details. Squid is
15
* Copyrighted (C) 2001 by the Regents of the University of
16
* California; see the COPYRIGHT file for full details. Squid
17
* incorporates software developed and/or copyrighted by other
18
* sources; see the CREDITS file for full details.
20
* This program is free software; you can redistribute it and/or modify
21
* it under the terms of the GNU General Public License as published by
22
* the Free Software Foundation; either version 2 of the License, or
23
* (at your option) any later version.
25
* This program is distributed in the hope that it will be useful,
26
* but WITHOUT ANY WARRANTY; without even the implied warranty of
27
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28
* GNU General Public License for more details.
30
* You should have received a copy of the GNU General Public License
31
* along with this program; if not, write to the Free Software
32
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
34
* CopyRight (c) 2003, Robert Collins <robertc@squid-cache.org>
43
#include "DiskdFile.h"
44
#include "ConfigOption.h"
47
#include "DiskdIOStrategy.h"
48
#include "DiskIO/IORequestor.h"
49
#include "DiskIO/ReadRequest.h"
50
#include "DiskIO/WriteRequest.h"
51
CBDATA_CLASS_INIT(DiskdFile);
54
DiskdFile::operator new (size_t)
56
CBDATA_INIT_TYPE(DiskdFile);
57
DiskdFile *result = cbdataAlloc(DiskdFile);
58
/* Mark result as being owned - we want the refcounter to do the delete
60
debug (79,3)("diskdFile with base %p allocating\n", result);
65
DiskdFile::operator delete (void *address)
67
DiskdFile *t = static_cast<DiskdFile *>(address);
68
debug (79,3)("diskdFile with base %p deleting\n",t);
72
DiskdFile::DiskdFile (char const *aPath, DiskdIOStrategy *anIO) : errorOccured (false), IO(anIO),
76
debug (79,3)("DiskdFile::DiskdFile: %s\n", aPath);
77
path_ = xstrdup (aPath);
78
id = diskd_stats.sio_id++;
81
DiskdFile::~DiskdFile()
83
assert (inProgressIOs == 0);
88
DiskdFile::open (int flags, mode_t aMode, IORequestor::Pointer callback)
90
debug (79,3)("DiskdFile::open: %p opening for %p\n", this, callback.getRaw());
91
assert (ioRequestor.getRaw() == NULL);
92
ioRequestor = callback;
93
assert (callback.getRaw());
96
char *buf = (char *)IO->shm.get(&shm_offset);
97
xstrncpy(buf, path_, SHMBUF_BLKSZ);
99
int x = IO->send(_MQD_OPEN,
110
// IO->shm.put (shm_offset);
111
ioRequestor->ioCompletedNotification();
115
diskd_stats.open.ops++;
119
DiskdFile::create (int flags, mode_t aMode, IORequestor::Pointer callback)
121
debug (79,3)("DiskdFile::create: %p creating for %p\n", this, callback.getRaw());
122
assert (ioRequestor.getRaw() == NULL);
123
ioRequestor = callback;
124
assert (callback.getRaw());
127
char *buf = (char *)IO->shm.get(&shm_offset);
128
xstrncpy(buf, path_, SHMBUF_BLKSZ);
130
int x = IO->send(_MQD_CREATE,
141
// IO->shm.put (shm_offset);
142
debug(79, 1) ("storeDiskdSend CREATE: %s\n", xstrerror());
148
diskd_stats.create.ops++;
152
DiskdFile::read(ReadRequest *aRead)
154
assert (ioRequestor.getRaw() != NULL);
156
char *rbuf = (char *)IO->shm.get(&shm_offset);
159
int x = IO->send(_MQD_READ,
170
// IO->shm.put (shm_offset);
171
debug(79, 1) ("storeDiskdSend READ: %s\n", xstrerror());
177
diskd_stats.read.ops++;
183
debug (79,3)("DiskdFile::close: %p closing for %p\n", this, ioRequestor.getRaw());
184
assert (ioRequestor.getRaw());
186
int x = IO->send(_MQD_CLOSE,
197
debug(79, 1) ("storeDiskdSend CLOSE: %s\n", xstrerror());
203
diskd_stats.close.ops++;
207
DiskdFile::error() const
213
DiskdFile::canRead() const
219
DiskdFile::canNotifyClient() const
221
if (!ioRequestor.getRaw()) {
222
debug (79,3)("DiskdFile::canNotifyClient: No ioRequestor to notify\n");
230
DiskdFile::notifyClient()
232
if (!canNotifyClient()) {
236
ioRequestor->ioCompletedNotification();
240
DiskdFile::completed(diomsg *M)
242
assert (M->newstyle);
277
DiskdFile::openDone(diomsg *M)
279
statCounter.syscalls.disk.opens++;
280
debug(79, 3) ("storeDiskdOpenDone: status %d\n", M->status);
283
diskd_stats.open.fail++;
286
diskd_stats.open.success++;
294
DiskdFile::createDone(diomsg *M)
296
statCounter.syscalls.disk.opens++;
297
debug(79, 3) ("storeDiskdCreateDone: status %d\n", M->status);
300
diskd_stats.create.fail++;
303
diskd_stats.create.success++;
311
DiskdFile::write(WriteRequest *aRequest)
313
debugs(79, 3, "DiskdFile::write: this " << (void *)this << ", buf " << (void *)aRequest->buf << ", off " << aRequest->offset << ", len " << aRequest->len);
315
char *sbuf = (char *)IO->shm.get(&shm_offset);
316
xmemcpy(sbuf, aRequest->buf, aRequest->len);
318
if (aRequest->free_func)
319
aRequest->free_func(const_cast<char *>(aRequest->buf));
323
int x = IO->send(_MQD_WRITE,
327
(int) aRequest->offset,
335
debug(79, 1) ("storeDiskdSend WRITE: %s\n", xstrerror());
336
// IO->shm.put (shm_offset);
342
diskd_stats.write.ops++;
352
DiskdFile::ioCompleted()
358
DiskdFile::closeDone(diomsg * M)
360
statCounter.syscalls.disk.closes++;
361
debug(79, 3) ("DiskdFile::closeDone: status %d\n", M->status);
364
diskd_stats.close.fail++;
367
diskd_stats.close.success++;
372
if (canNotifyClient())
373
ioRequestor->closeCompleted();
379
DiskdFile::readDone(diomsg * M)
381
statCounter.syscalls.disk.reads++;
382
debug(79, 3) ("DiskdFile::readDone: status %d\n", M->status);
383
assert (M->requestor);
384
ReadRequest::Pointer readRequest = dynamic_cast<ReadRequest *>(M->requestor);
385
/* remove the free protection */
386
readRequest->RefCountDereference();
389
diskd_stats.read.fail++;
392
ioRequestor->readCompleted(NULL, -1, DISK_ERROR, readRequest);
396
diskd_stats.read.success++;
399
ioRequestor->readCompleted (IO->shm.buf + M->shm_offset, M->status, DISK_OK, readRequest);
403
DiskdFile::writeDone(diomsg *M)
405
statCounter.syscalls.disk.writes++;
406
debug(79, 3) ("storeDiskdWriteDone: status %d\n", M->status);
407
assert (M->requestor);
408
WriteRequest::Pointer writeRequest = dynamic_cast<WriteRequest *>(M->requestor);
409
/* remove the free protection */
410
writeRequest->RefCountDereference();
414
diskd_stats.write.fail++;
416
ioRequestor->writeCompleted (DISK_ERROR,0, writeRequest);
420
diskd_stats.write.success++;
422
ioRequestor->writeCompleted (DISK_OK,M->status, writeRequest);
426
DiskdFile::ioInProgress()const
428
return inProgressIOs != 0;