]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/DiskIO/DiskDaemon/DiskdFile.cc
4 * DEBUG: section 79 Squid-side DISKD I/O functions.
5 * AUTHOR: Duane Wessels
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 * CopyRight (c) 2003, Robert Collins <robertc@squid-cache.org>
36 #include "squid-old.h"
42 #include "DiskdFile.h"
43 #include "ConfigOption.h"
46 #include "DiskdIOStrategy.h"
47 #include "DiskIO/IORequestor.h"
48 #include "DiskIO/ReadRequest.h"
49 #include "DiskIO/WriteRequest.h"
50 #include "StatCounters.h"
51 CBDATA_CLASS_INIT(DiskdFile
);
54 DiskdFile::operator new(size_t unused
)
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 debugs(79, 3, "diskdFile with base " << result
<< " allocating");
65 DiskdFile::operator delete(void *address
)
67 DiskdFile
*t
= static_cast<DiskdFile
*>(address
);
68 debugs(79, 3, "diskdFile with base " << t
<< " deleting");
72 DiskdFile::DiskdFile(char const *aPath
, DiskdIOStrategy
*anIO
) : errorOccured (false), IO(anIO
),
76 debugs(79, 3, "DiskdFile::DiskdFile: " << 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
, RefCount
< IORequestor
> callback
)
90 debugs(79, 3, "DiskdFile::open: " << this << " opening for " << 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
, RefCount
< IORequestor
> callback
)
121 debugs(79, 3, "DiskdFile::create: " << this << " creating for " << 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 debugs(79, 1, "storeDiskdSend CREATE: " << 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 debugs(79, 1, "storeDiskdSend READ: " << xstrerror());
177 ++diskd_stats
.read
.ops
;
183 debugs(79, 3, "DiskdFile::close: " << this << " closing for " << ioRequestor
.getRaw());
184 assert (ioRequestor
.getRaw());
186 int x
= IO
->send(_MQD_CLOSE
,
197 debugs(79, 1, "storeDiskdSend CLOSE: " << xstrerror());
203 ++diskd_stats
.close
.ops
;
207 DiskdFile::error() const
213 DiskdFile::canRead() const
219 DiskdFile::canNotifyClient() const
221 if (!ioRequestor
.getRaw()) {
222 debugs(79, 3, "DiskdFile::canNotifyClient: No ioRequestor to notify");
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 debugs(79, 3, "storeDiskdOpenDone: status " << M
->status
);
283 ++diskd_stats
.open
.fail
;
286 ++diskd_stats
.open
.success
;
294 DiskdFile::createDone(diomsg
*M
)
296 ++statCounter
.syscalls
.disk
.opens
;
297 debugs(79, 3, "storeDiskdCreateDone: status " << 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 memcpy(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
,
334 debugs(79, 1, "storeDiskdSend WRITE: " << xstrerror());
335 // IO->shm.put (shm_offset);
341 ++diskd_stats
.write
.ops
;
351 DiskdFile::ioCompleted()
357 DiskdFile::closeDone(diomsg
* M
)
359 ++statCounter
.syscalls
.disk
.closes
;
360 debugs(79, 3, "DiskdFile::closeDone: status " << M
->status
);
363 ++diskd_stats
.close
.fail
;
366 ++diskd_stats
.close
.success
;
371 if (canNotifyClient())
372 ioRequestor
->closeCompleted();
378 DiskdFile::readDone(diomsg
* M
)
380 ++statCounter
.syscalls
.disk
.reads
;
381 debugs(79, 3, "DiskdFile::readDone: status " << M
->status
);
382 assert (M
->requestor
);
383 ReadRequest::Pointer readRequest
= dynamic_cast<ReadRequest
*>(M
->requestor
);
384 /* remove the free protection */
385 readRequest
->RefCountDereference();
388 ++diskd_stats
.read
.fail
;
391 ioRequestor
->readCompleted(NULL
, -1, DISK_ERROR
, readRequest
);
395 ++diskd_stats
.read
.success
;
398 ioRequestor
->readCompleted (IO
->shm
.buf
+ M
->shm_offset
, M
->status
, DISK_OK
, readRequest
);
402 DiskdFile::writeDone(diomsg
*M
)
404 ++statCounter
.syscalls
.disk
.writes
;
405 debugs(79, 3, "storeDiskdWriteDone: status " << M
->status
);
406 assert (M
->requestor
);
407 WriteRequest::Pointer writeRequest
= dynamic_cast<WriteRequest
*>(M
->requestor
);
408 /* remove the free protection */
409 writeRequest
->RefCountDereference();
413 ++diskd_stats
.write
.fail
;
415 ioRequestor
->writeCompleted (DISK_ERROR
,0, writeRequest
);
419 ++diskd_stats
.write
.success
;
421 ioRequestor
->writeCompleted (DISK_OK
,M
->status
, writeRequest
);
425 DiskdFile::ioInProgress()const
427 return inProgressIOs
!= 0;