]>
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 "ConfigOption.h"
37 #include "DiskdFile.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
);
56 DiskdFile::DiskdFile(char const *aPath
, DiskdIOStrategy
*anIO
) :
63 debugs(79, 3, "DiskdFile::DiskdFile: " << aPath
);
64 path_
= xstrdup(aPath
);
65 id
= diskd_stats
.sio_id
;
69 DiskdFile::~DiskdFile()
71 assert(inProgressIOs
== 0);
76 DiskdFile::open(int flags
, mode_t aMode
, RefCount
< IORequestor
> callback
)
78 debugs(79, 3, "DiskdFile::open: " << this << " opening for " << callback
.getRaw());
79 assert(ioRequestor
.getRaw() == NULL
);
80 ioRequestor
= callback
;
81 assert(callback
.getRaw());
84 char *buf
= (char *)IO
->shm
.get(&shm_offset
);
85 xstrncpy(buf
, path_
, SHMBUF_BLKSZ
);
87 int x
= IO
->send(_MQD_OPEN
,
98 // IO->shm.put (shm_offset);
99 ioRequestor
->ioCompletedNotification();
103 ++diskd_stats
.open
.ops
;
107 DiskdFile::create(int flags
, mode_t aMode
, RefCount
< IORequestor
> callback
)
109 debugs(79, 3, "DiskdFile::create: " << this << " creating for " << callback
.getRaw());
110 assert (ioRequestor
.getRaw() == NULL
);
111 ioRequestor
= callback
;
112 assert (callback
.getRaw());
115 char *buf
= (char *)IO
->shm
.get(&shm_offset
);
116 xstrncpy(buf
, path_
, SHMBUF_BLKSZ
);
118 int x
= IO
->send(_MQD_CREATE
,
129 // IO->shm.put (shm_offset);
130 debugs(79, DBG_IMPORTANT
, "storeDiskdSend CREATE: " << xstrerror());
136 ++diskd_stats
.create
.ops
;
140 DiskdFile::read(ReadRequest
*aRead
)
142 assert (ioRequestor
.getRaw() != NULL
);
144 char *rbuf
= (char *)IO
->shm
.get(&shm_offset
);
147 int x
= IO
->send(_MQD_READ
,
158 // IO->shm.put (shm_offset);
159 debugs(79, DBG_IMPORTANT
, "storeDiskdSend READ: " << xstrerror());
165 ++diskd_stats
.read
.ops
;
171 debugs(79, 3, "DiskdFile::close: " << this << " closing for " << ioRequestor
.getRaw());
172 assert (ioRequestor
.getRaw());
174 int x
= IO
->send(_MQD_CLOSE
,
185 debugs(79, DBG_IMPORTANT
, "storeDiskdSend CLOSE: " << xstrerror());
191 ++diskd_stats
.close
.ops
;
195 DiskdFile::error() const
201 DiskdFile::canRead() const
207 DiskdFile::canNotifyClient() const
209 if (!ioRequestor
.getRaw()) {
210 debugs(79, 3, "DiskdFile::canNotifyClient: No ioRequestor to notify");
218 DiskdFile::notifyClient()
220 if (!canNotifyClient()) {
224 ioRequestor
->ioCompletedNotification();
228 DiskdFile::completed(diomsg
*M
)
230 assert (M
->newstyle
);
265 DiskdFile::openDone(diomsg
*M
)
267 ++statCounter
.syscalls
.disk
.opens
;
268 debugs(79, 3, "storeDiskdOpenDone: status " << M
->status
);
271 ++diskd_stats
.open
.fail
;
274 ++diskd_stats
.open
.success
;
282 DiskdFile::createDone(diomsg
*M
)
284 ++statCounter
.syscalls
.disk
.opens
;
285 debugs(79, 3, "storeDiskdCreateDone: status " << M
->status
);
288 ++diskd_stats
.create
.fail
;
291 ++diskd_stats
.create
.success
;
299 DiskdFile::write(WriteRequest
*aRequest
)
301 debugs(79, 3, "DiskdFile::write: this " << (void *)this << ", buf " << (void *)aRequest
->buf
<< ", off " << aRequest
->offset
<< ", len " << aRequest
->len
);
303 char *sbuf
= (char *)IO
->shm
.get(&shm_offset
);
304 memcpy(sbuf
, aRequest
->buf
, aRequest
->len
);
306 if (aRequest
->free_func
)
307 aRequest
->free_func(const_cast<char *>(aRequest
->buf
));
311 int x
= IO
->send(_MQD_WRITE
,
322 debugs(79, DBG_IMPORTANT
, "storeDiskdSend WRITE: " << xstrerror());
323 // IO->shm.put (shm_offset);
329 ++diskd_stats
.write
.ops
;
339 DiskdFile::ioCompleted()
345 DiskdFile::closeDone(diomsg
* M
)
347 ++statCounter
.syscalls
.disk
.closes
;
348 debugs(79, 3, "DiskdFile::closeDone: status " << M
->status
);
351 ++diskd_stats
.close
.fail
;
354 ++diskd_stats
.close
.success
;
359 if (canNotifyClient())
360 ioRequestor
->closeCompleted();
366 DiskdFile::readDone(diomsg
* M
)
368 ++statCounter
.syscalls
.disk
.reads
;
369 debugs(79, 3, "DiskdFile::readDone: status " << M
->status
);
370 assert (M
->requestor
);
371 ReadRequest::Pointer readRequest
= dynamic_cast<ReadRequest
*>(M
->requestor
);
373 /* remove the free protection */
374 if (readRequest
!= NULL
)
375 readRequest
->unlock();
378 ++diskd_stats
.read
.fail
;
381 ioRequestor
->readCompleted(NULL
, -1, DISK_ERROR
, readRequest
);
385 ++diskd_stats
.read
.success
;
388 ioRequestor
->readCompleted (IO
->shm
.buf
+ M
->shm_offset
, M
->status
, DISK_OK
, readRequest
);
392 DiskdFile::writeDone(diomsg
*M
)
394 ++statCounter
.syscalls
.disk
.writes
;
395 debugs(79, 3, "storeDiskdWriteDone: status " << M
->status
);
396 assert (M
->requestor
);
397 WriteRequest::Pointer writeRequest
= dynamic_cast<WriteRequest
*>(M
->requestor
);
398 /* remove the free protection */
399 if (writeRequest
!= NULL
)
400 writeRequest
->unlock();
404 ++diskd_stats
.write
.fail
;
406 ioRequestor
->writeCompleted (DISK_ERROR
,0, writeRequest
);
410 ++diskd_stats
.write
.success
;
412 ioRequestor
->writeCompleted (DISK_OK
,M
->status
, writeRequest
);
416 DiskdFile::ioInProgress()const
418 return inProgressIOs
!= 0;