]>
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"
54 CBDATA_CLASS_INIT(DiskdFile
);
57 DiskdFile::operator new(size_t unused
)
59 CBDATA_INIT_TYPE(DiskdFile
);
60 DiskdFile
*result
= cbdataAlloc(DiskdFile
);
61 /* Mark result as being owned - we want the refcounter to do the delete
63 debugs(79, 3, "diskdFile with base " << result
<< " allocating");
68 DiskdFile::operator delete(void *address
)
70 DiskdFile
*t
= static_cast<DiskdFile
*>(address
);
71 debugs(79, 3, "diskdFile with base " << t
<< " deleting");
75 DiskdFile::DiskdFile(char const *aPath
, DiskdIOStrategy
*anIO
) :
82 debugs(79, 3, "DiskdFile::DiskdFile: " << aPath
);
83 path_
= xstrdup (aPath
);
84 id
= diskd_stats
.sio_id
;
88 DiskdFile::~DiskdFile()
90 assert (inProgressIOs
== 0);
95 DiskdFile::open(int flags
, mode_t aMode
, RefCount
< IORequestor
> callback
)
97 debugs(79, 3, "DiskdFile::open: " << this << " opening for " << callback
.getRaw());
98 assert (ioRequestor
.getRaw() == NULL
);
99 ioRequestor
= callback
;
100 assert (callback
.getRaw());
103 char *buf
= (char *)IO
->shm
.get(&shm_offset
);
104 xstrncpy(buf
, path_
, SHMBUF_BLKSZ
);
106 int x
= IO
->send(_MQD_OPEN
,
117 // IO->shm.put (shm_offset);
118 ioRequestor
->ioCompletedNotification();
122 ++diskd_stats
.open
.ops
;
126 DiskdFile::create(int flags
, mode_t aMode
, RefCount
< IORequestor
> callback
)
128 debugs(79, 3, "DiskdFile::create: " << this << " creating for " << callback
.getRaw());
129 assert (ioRequestor
.getRaw() == NULL
);
130 ioRequestor
= callback
;
131 assert (callback
.getRaw());
134 char *buf
= (char *)IO
->shm
.get(&shm_offset
);
135 xstrncpy(buf
, path_
, SHMBUF_BLKSZ
);
137 int x
= IO
->send(_MQD_CREATE
,
148 // IO->shm.put (shm_offset);
149 debugs(79, DBG_IMPORTANT
, "storeDiskdSend CREATE: " << xstrerror());
155 ++diskd_stats
.create
.ops
;
159 DiskdFile::read(ReadRequest
*aRead
)
161 assert (ioRequestor
.getRaw() != NULL
);
163 char *rbuf
= (char *)IO
->shm
.get(&shm_offset
);
166 int x
= IO
->send(_MQD_READ
,
177 // IO->shm.put (shm_offset);
178 debugs(79, DBG_IMPORTANT
, "storeDiskdSend READ: " << xstrerror());
184 ++diskd_stats
.read
.ops
;
190 debugs(79, 3, "DiskdFile::close: " << this << " closing for " << ioRequestor
.getRaw());
191 assert (ioRequestor
.getRaw());
193 int x
= IO
->send(_MQD_CLOSE
,
204 debugs(79, DBG_IMPORTANT
, "storeDiskdSend CLOSE: " << xstrerror());
210 ++diskd_stats
.close
.ops
;
214 DiskdFile::error() const
220 DiskdFile::canRead() const
226 DiskdFile::canNotifyClient() const
228 if (!ioRequestor
.getRaw()) {
229 debugs(79, 3, "DiskdFile::canNotifyClient: No ioRequestor to notify");
237 DiskdFile::notifyClient()
239 if (!canNotifyClient()) {
243 ioRequestor
->ioCompletedNotification();
247 DiskdFile::completed(diomsg
*M
)
249 assert (M
->newstyle
);
284 DiskdFile::openDone(diomsg
*M
)
286 ++statCounter
.syscalls
.disk
.opens
;
287 debugs(79, 3, "storeDiskdOpenDone: status " << M
->status
);
290 ++diskd_stats
.open
.fail
;
293 ++diskd_stats
.open
.success
;
301 DiskdFile::createDone(diomsg
*M
)
303 ++statCounter
.syscalls
.disk
.opens
;
304 debugs(79, 3, "storeDiskdCreateDone: status " << M
->status
);
307 ++diskd_stats
.create
.fail
;
310 ++diskd_stats
.create
.success
;
318 DiskdFile::write(WriteRequest
*aRequest
)
320 debugs(79, 3, "DiskdFile::write: this " << (void *)this << ", buf " << (void *)aRequest
->buf
<< ", off " << aRequest
->offset
<< ", len " << aRequest
->len
);
322 char *sbuf
= (char *)IO
->shm
.get(&shm_offset
);
323 memcpy(sbuf
, aRequest
->buf
, aRequest
->len
);
325 if (aRequest
->free_func
)
326 aRequest
->free_func(const_cast<char *>(aRequest
->buf
));
330 int x
= IO
->send(_MQD_WRITE
,
341 debugs(79, DBG_IMPORTANT
, "storeDiskdSend WRITE: " << xstrerror());
342 // IO->shm.put (shm_offset);
348 ++diskd_stats
.write
.ops
;
358 DiskdFile::ioCompleted()
364 DiskdFile::closeDone(diomsg
* M
)
366 ++statCounter
.syscalls
.disk
.closes
;
367 debugs(79, 3, "DiskdFile::closeDone: status " << M
->status
);
370 ++diskd_stats
.close
.fail
;
373 ++diskd_stats
.close
.success
;
378 if (canNotifyClient())
379 ioRequestor
->closeCompleted();
385 DiskdFile::readDone(diomsg
* M
)
387 ++statCounter
.syscalls
.disk
.reads
;
388 debugs(79, 3, "DiskdFile::readDone: status " << M
->status
);
389 assert (M
->requestor
);
390 ReadRequest::Pointer readRequest
= dynamic_cast<ReadRequest
*>(M
->requestor
);
392 /* remove the free protection */
393 if (readRequest
!= NULL
)
394 readRequest
->unlock();
397 ++diskd_stats
.read
.fail
;
400 ioRequestor
->readCompleted(NULL
, -1, DISK_ERROR
, readRequest
);
404 ++diskd_stats
.read
.success
;
407 ioRequestor
->readCompleted (IO
->shm
.buf
+ M
->shm_offset
, M
->status
, DISK_OK
, readRequest
);
411 DiskdFile::writeDone(diomsg
*M
)
413 ++statCounter
.syscalls
.disk
.writes
;
414 debugs(79, 3, "storeDiskdWriteDone: status " << M
->status
);
415 assert (M
->requestor
);
416 WriteRequest::Pointer writeRequest
= dynamic_cast<WriteRequest
*>(M
->requestor
);
417 /* remove the free protection */
418 if (writeRequest
!= NULL
)
419 writeRequest
->unlock();
423 ++diskd_stats
.write
.fail
;
425 ioRequestor
->writeCompleted (DISK_ERROR
,0, writeRequest
);
429 ++diskd_stats
.write
.success
;
431 ioRequestor
->writeCompleted (DISK_OK
,M
->status
, writeRequest
);
435 DiskdFile::ioInProgress()const
437 return inProgressIOs
!= 0;