]>
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
;
82 DiskdFile::~DiskdFile()
84 assert (inProgressIOs
== 0);
89 DiskdFile::open(int flags
, mode_t aMode
, RefCount
< IORequestor
> callback
)
91 debugs(79, 3, "DiskdFile::open: " << this << " opening for " << callback
.getRaw());
92 assert (ioRequestor
.getRaw() == NULL
);
93 ioRequestor
= callback
;
94 assert (callback
.getRaw());
97 char *buf
= (char *)IO
->shm
.get(&shm_offset
);
98 xstrncpy(buf
, path_
, SHMBUF_BLKSZ
);
100 int x
= IO
->send(_MQD_OPEN
,
111 // IO->shm.put (shm_offset);
112 ioRequestor
->ioCompletedNotification();
116 ++diskd_stats
.open
.ops
;
120 DiskdFile::create(int flags
, mode_t aMode
, RefCount
< IORequestor
> callback
)
122 debugs(79, 3, "DiskdFile::create: " << this << " creating for " << callback
.getRaw());
123 assert (ioRequestor
.getRaw() == NULL
);
124 ioRequestor
= callback
;
125 assert (callback
.getRaw());
128 char *buf
= (char *)IO
->shm
.get(&shm_offset
);
129 xstrncpy(buf
, path_
, SHMBUF_BLKSZ
);
131 int x
= IO
->send(_MQD_CREATE
,
142 // IO->shm.put (shm_offset);
143 debugs(79, 1, "storeDiskdSend CREATE: " << xstrerror());
149 ++diskd_stats
.create
.ops
;
153 DiskdFile::read(ReadRequest
*aRead
)
155 assert (ioRequestor
.getRaw() != NULL
);
157 char *rbuf
= (char *)IO
->shm
.get(&shm_offset
);
160 int x
= IO
->send(_MQD_READ
,
171 // IO->shm.put (shm_offset);
172 debugs(79, 1, "storeDiskdSend READ: " << xstrerror());
178 ++diskd_stats
.read
.ops
;
184 debugs(79, 3, "DiskdFile::close: " << this << " closing for " << ioRequestor
.getRaw());
185 assert (ioRequestor
.getRaw());
187 int x
= IO
->send(_MQD_CLOSE
,
198 debugs(79, 1, "storeDiskdSend CLOSE: " << xstrerror());
204 ++diskd_stats
.close
.ops
;
208 DiskdFile::error() const
214 DiskdFile::canRead() const
220 DiskdFile::canNotifyClient() const
222 if (!ioRequestor
.getRaw()) {
223 debugs(79, 3, "DiskdFile::canNotifyClient: No ioRequestor to notify");
231 DiskdFile::notifyClient()
233 if (!canNotifyClient()) {
237 ioRequestor
->ioCompletedNotification();
241 DiskdFile::completed(diomsg
*M
)
243 assert (M
->newstyle
);
278 DiskdFile::openDone(diomsg
*M
)
280 ++statCounter
.syscalls
.disk
.opens
;
281 debugs(79, 3, "storeDiskdOpenDone: status " << M
->status
);
284 ++diskd_stats
.open
.fail
;
287 ++diskd_stats
.open
.success
;
295 DiskdFile::createDone(diomsg
*M
)
297 ++statCounter
.syscalls
.disk
.opens
;
298 debugs(79, 3, "storeDiskdCreateDone: status " << M
->status
);
301 ++diskd_stats
.create
.fail
;
304 ++diskd_stats
.create
.success
;
312 DiskdFile::write(WriteRequest
*aRequest
)
314 debugs(79, 3, "DiskdFile::write: this " << (void *)this << ", buf " << (void *)aRequest
->buf
<< ", off " << aRequest
->offset
<< ", len " << aRequest
->len
);
316 char *sbuf
= (char *)IO
->shm
.get(&shm_offset
);
317 memcpy(sbuf
, aRequest
->buf
, aRequest
->len
);
319 if (aRequest
->free_func
)
320 aRequest
->free_func(const_cast<char *>(aRequest
->buf
));
324 int x
= IO
->send(_MQD_WRITE
,
335 debugs(79, 1, "storeDiskdSend WRITE: " << 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 debugs(79, 3, "DiskdFile::closeDone: status " << 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 debugs(79, 3, "DiskdFile::readDone: status " << 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 debugs(79, 3, "storeDiskdWriteDone: status " << 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;