]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/DiskIO/DiskDaemon/DiskdFile.cc
2 * DEBUG: section 79 Squid-side DISKD I/O functions.
3 * AUTHOR: Duane Wessels
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
31 * CopyRight (c) 2003, Robert Collins <robertc@squid-cache.org>
35 #include "DiskdFile.h"
36 #include "ConfigOption.h"
38 #include "DiskdIOStrategy.h"
39 #include "DiskIO/IORequestor.h"
40 #include "DiskIO/ReadRequest.h"
41 #include "DiskIO/WriteRequest.h"
42 #include "StatCounters.h"
48 CBDATA_CLASS_INIT(DiskdFile
);
51 DiskdFile::operator new(size_t unused
)
53 CBDATA_INIT_TYPE(DiskdFile
);
54 DiskdFile
*result
= cbdataAlloc(DiskdFile
);
55 /* Mark result as being owned - we want the refcounter to do the delete
57 debugs(79, 3, "diskdFile with base " << result
<< " allocating");
62 DiskdFile::operator delete(void *address
)
64 DiskdFile
*t
= static_cast<DiskdFile
*>(address
);
65 debugs(79, 3, "diskdFile with base " << t
<< " deleting");
69 DiskdFile::DiskdFile(char const *aPath
, DiskdIOStrategy
*anIO
) : errorOccured (false), IO(anIO
),
73 debugs(79, 3, "DiskdFile::DiskdFile: " << aPath
);
74 path_
= xstrdup (aPath
);
75 id
= diskd_stats
.sio_id
;
79 DiskdFile::~DiskdFile()
81 assert (inProgressIOs
== 0);
86 DiskdFile::open(int flags
, mode_t aMode
, RefCount
< IORequestor
> callback
)
88 debugs(79, 3, "DiskdFile::open: " << this << " opening for " << callback
.getRaw());
89 assert (ioRequestor
.getRaw() == NULL
);
90 ioRequestor
= callback
;
91 assert (callback
.getRaw());
94 char *buf
= (char *)IO
->shm
.get(&shm_offset
);
95 xstrncpy(buf
, path_
, SHMBUF_BLKSZ
);
97 int x
= IO
->send(_MQD_OPEN
,
108 // IO->shm.put (shm_offset);
109 ioRequestor
->ioCompletedNotification();
113 ++diskd_stats
.open
.ops
;
117 DiskdFile::create(int flags
, mode_t aMode
, RefCount
< IORequestor
> callback
)
119 debugs(79, 3, "DiskdFile::create: " << this << " creating for " << callback
.getRaw());
120 assert (ioRequestor
.getRaw() == NULL
);
121 ioRequestor
= callback
;
122 assert (callback
.getRaw());
125 char *buf
= (char *)IO
->shm
.get(&shm_offset
);
126 xstrncpy(buf
, path_
, SHMBUF_BLKSZ
);
128 int x
= IO
->send(_MQD_CREATE
,
139 // IO->shm.put (shm_offset);
140 debugs(79, DBG_IMPORTANT
, "storeDiskdSend CREATE: " << xstrerror());
146 ++diskd_stats
.create
.ops
;
150 DiskdFile::read(ReadRequest
*aRead
)
152 assert (ioRequestor
.getRaw() != NULL
);
154 char *rbuf
= (char *)IO
->shm
.get(&shm_offset
);
157 int x
= IO
->send(_MQD_READ
,
168 // IO->shm.put (shm_offset);
169 debugs(79, DBG_IMPORTANT
, "storeDiskdSend READ: " << xstrerror());
175 ++diskd_stats
.read
.ops
;
181 debugs(79, 3, "DiskdFile::close: " << this << " closing for " << ioRequestor
.getRaw());
182 assert (ioRequestor
.getRaw());
184 int x
= IO
->send(_MQD_CLOSE
,
195 debugs(79, DBG_IMPORTANT
, "storeDiskdSend CLOSE: " << xstrerror());
201 ++diskd_stats
.close
.ops
;
205 DiskdFile::error() const
211 DiskdFile::canRead() const
217 DiskdFile::canNotifyClient() const
219 if (!ioRequestor
.getRaw()) {
220 debugs(79, 3, "DiskdFile::canNotifyClient: No ioRequestor to notify");
228 DiskdFile::notifyClient()
230 if (!canNotifyClient()) {
234 ioRequestor
->ioCompletedNotification();
238 DiskdFile::completed(diomsg
*M
)
240 assert (M
->newstyle
);
275 DiskdFile::openDone(diomsg
*M
)
277 ++statCounter
.syscalls
.disk
.opens
;
278 debugs(79, 3, "storeDiskdOpenDone: status " << M
->status
);
281 ++diskd_stats
.open
.fail
;
284 ++diskd_stats
.open
.success
;
292 DiskdFile::createDone(diomsg
*M
)
294 ++statCounter
.syscalls
.disk
.opens
;
295 debugs(79, 3, "storeDiskdCreateDone: status " << M
->status
);
298 ++diskd_stats
.create
.fail
;
301 ++diskd_stats
.create
.success
;
309 DiskdFile::write(WriteRequest
*aRequest
)
311 debugs(79, 3, "DiskdFile::write: this " << (void *)this << ", buf " << (void *)aRequest
->buf
<< ", off " << aRequest
->offset
<< ", len " << aRequest
->len
);
313 char *sbuf
= (char *)IO
->shm
.get(&shm_offset
);
314 memcpy(sbuf
, aRequest
->buf
, aRequest
->len
);
316 if (aRequest
->free_func
)
317 aRequest
->free_func(const_cast<char *>(aRequest
->buf
));
321 int x
= IO
->send(_MQD_WRITE
,
332 debugs(79, DBG_IMPORTANT
, "storeDiskdSend WRITE: " << xstrerror());
333 // IO->shm.put (shm_offset);
339 ++diskd_stats
.write
.ops
;
349 DiskdFile::ioCompleted()
355 DiskdFile::closeDone(diomsg
* M
)
357 ++statCounter
.syscalls
.disk
.closes
;
358 debugs(79, 3, "DiskdFile::closeDone: status " << M
->status
);
361 ++diskd_stats
.close
.fail
;
364 ++diskd_stats
.close
.success
;
369 if (canNotifyClient())
370 ioRequestor
->closeCompleted();
376 DiskdFile::readDone(diomsg
* M
)
378 ++statCounter
.syscalls
.disk
.reads
;
379 debugs(79, 3, "DiskdFile::readDone: status " << M
->status
);
380 assert (M
->requestor
);
381 ReadRequest::Pointer readRequest
= dynamic_cast<ReadRequest
*>(M
->requestor
);
382 /* remove the free protection */
383 readRequest
->RefCountDereference();
386 ++diskd_stats
.read
.fail
;
389 ioRequestor
->readCompleted(NULL
, -1, DISK_ERROR
, readRequest
);
393 ++diskd_stats
.read
.success
;
396 ioRequestor
->readCompleted (IO
->shm
.buf
+ M
->shm_offset
, M
->status
, DISK_OK
, readRequest
);
400 DiskdFile::writeDone(diomsg
*M
)
402 ++statCounter
.syscalls
.disk
.writes
;
403 debugs(79, 3, "storeDiskdWriteDone: status " << M
->status
);
404 assert (M
->requestor
);
405 WriteRequest::Pointer writeRequest
= dynamic_cast<WriteRequest
*>(M
->requestor
);
406 /* remove the free protection */
407 writeRequest
->RefCountDereference();
411 ++diskd_stats
.write
.fail
;
413 ioRequestor
->writeCompleted (DISK_ERROR
,0, writeRequest
);
417 ++diskd_stats
.write
.success
;
419 ioRequestor
->writeCompleted (DISK_OK
,M
->status
, writeRequest
);
423 DiskdFile::ioInProgress()const
425 return inProgressIOs
!= 0;