]>
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>
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 CBDATA_CLASS_INIT(DiskdFile
);
53 DiskdFile::operator new(size_t unused
)
55 CBDATA_INIT_TYPE(DiskdFile
);
56 DiskdFile
*result
= cbdataAlloc(DiskdFile
);
57 /* Mark result as being owned - we want the refcounter to do the delete
59 debugs(79, 3, "diskdFile with base " << result
<< " allocating");
64 DiskdFile::operator delete(void *address
)
66 DiskdFile
*t
= static_cast<DiskdFile
*>(address
);
67 debugs(79, 3, "diskdFile with base " << t
<< " deleting");
71 DiskdFile::DiskdFile(char const *aPath
, DiskdIOStrategy
*anIO
) : errorOccured (false), IO(anIO
),
75 debugs(79, 3, "DiskdFile::DiskdFile: " << aPath
);
76 path_
= xstrdup (aPath
);
77 id
= diskd_stats
.sio_id
++;
80 DiskdFile::~DiskdFile()
82 assert (inProgressIOs
== 0);
87 DiskdFile::open(int flags
, mode_t aMode
, RefCount
< IORequestor
> callback
)
89 debugs(79, 3, "DiskdFile::open: " << this << " opening for " << callback
.getRaw());
90 assert (ioRequestor
.getRaw() == NULL
);
91 ioRequestor
= callback
;
92 assert (callback
.getRaw());
95 char *buf
= (char *)IO
->shm
.get(&shm_offset
);
96 xstrncpy(buf
, path_
, SHMBUF_BLKSZ
);
98 int x
= IO
->send(_MQD_OPEN
,
109 // IO->shm.put (shm_offset);
110 ioRequestor
->ioCompletedNotification();
114 diskd_stats
.open
.ops
++;
118 DiskdFile::create(int flags
, mode_t aMode
, RefCount
< IORequestor
> callback
)
120 debugs(79, 3, "DiskdFile::create: " << this << " creating for " << callback
.getRaw());
121 assert (ioRequestor
.getRaw() == NULL
);
122 ioRequestor
= callback
;
123 assert (callback
.getRaw());
126 char *buf
= (char *)IO
->shm
.get(&shm_offset
);
127 xstrncpy(buf
, path_
, SHMBUF_BLKSZ
);
129 int x
= IO
->send(_MQD_CREATE
,
140 // IO->shm.put (shm_offset);
141 debugs(79, 1, "storeDiskdSend CREATE: " << xstrerror());
147 diskd_stats
.create
.ops
++;
151 DiskdFile::read(ReadRequest
*aRead
)
153 assert (ioRequestor
.getRaw() != NULL
);
155 char *rbuf
= (char *)IO
->shm
.get(&shm_offset
);
158 int x
= IO
->send(_MQD_READ
,
169 // IO->shm.put (shm_offset);
170 debugs(79, 1, "storeDiskdSend READ: " << xstrerror());
176 diskd_stats
.read
.ops
++;
182 debugs(79, 3, "DiskdFile::close: " << this << " closing for " << ioRequestor
.getRaw());
183 assert (ioRequestor
.getRaw());
185 int x
= IO
->send(_MQD_CLOSE
,
196 debugs(79, 1, "storeDiskdSend CLOSE: " << xstrerror());
202 diskd_stats
.close
.ops
++;
206 DiskdFile::error() const
212 DiskdFile::canRead() const
218 DiskdFile::canNotifyClient() const
220 if (!ioRequestor
.getRaw()) {
221 debugs(79, 3, "DiskdFile::canNotifyClient: No ioRequestor to notify");
229 DiskdFile::notifyClient()
231 if (!canNotifyClient()) {
235 ioRequestor
->ioCompletedNotification();
239 DiskdFile::completed(diomsg
*M
)
241 assert (M
->newstyle
);
276 DiskdFile::openDone(diomsg
*M
)
278 statCounter
.syscalls
.disk
.opens
++;
279 debugs(79, 3, "storeDiskdOpenDone: status " << M
->status
);
282 diskd_stats
.open
.fail
++;
285 diskd_stats
.open
.success
++;
293 DiskdFile::createDone(diomsg
*M
)
295 statCounter
.syscalls
.disk
.opens
++;
296 debugs(79, 3, "storeDiskdCreateDone: status " << M
->status
);
299 diskd_stats
.create
.fail
++;
302 diskd_stats
.create
.success
++;
310 DiskdFile::write(WriteRequest
*aRequest
)
312 debugs(79, 3, "DiskdFile::write: this " << (void *)this << ", buf " << (void *)aRequest
->buf
<< ", off " << aRequest
->offset
<< ", len " << aRequest
->len
);
314 char *sbuf
= (char *)IO
->shm
.get(&shm_offset
);
315 memcpy(sbuf
, aRequest
->buf
, aRequest
->len
);
317 if (aRequest
->free_func
)
318 aRequest
->free_func(const_cast<char *>(aRequest
->buf
));
322 int x
= IO
->send(_MQD_WRITE
,
333 debugs(79, 1, "storeDiskdSend WRITE: " << xstrerror());
334 // IO->shm.put (shm_offset);
340 diskd_stats
.write
.ops
++;
350 DiskdFile::ioCompleted()
356 DiskdFile::closeDone(diomsg
* M
)
358 statCounter
.syscalls
.disk
.closes
++;
359 debugs(79, 3, "DiskdFile::closeDone: status " << M
->status
);
362 diskd_stats
.close
.fail
++;
365 diskd_stats
.close
.success
++;
370 if (canNotifyClient())
371 ioRequestor
->closeCompleted();
377 DiskdFile::readDone(diomsg
* M
)
379 statCounter
.syscalls
.disk
.reads
++;
380 debugs(79, 3, "DiskdFile::readDone: status " << M
->status
);
381 assert (M
->requestor
);
382 ReadRequest::Pointer readRequest
= dynamic_cast<ReadRequest
*>(M
->requestor
);
383 /* remove the free protection */
384 readRequest
->RefCountDereference();
387 diskd_stats
.read
.fail
++;
390 ioRequestor
->readCompleted(NULL
, -1, DISK_ERROR
, readRequest
);
394 diskd_stats
.read
.success
++;
397 ioRequestor
->readCompleted (IO
->shm
.buf
+ M
->shm_offset
, M
->status
, DISK_OK
, readRequest
);
401 DiskdFile::writeDone(diomsg
*M
)
403 statCounter
.syscalls
.disk
.writes
++;
404 debugs(79, 3, "storeDiskdWriteDone: status " << M
->status
);
405 assert (M
->requestor
);
406 WriteRequest::Pointer writeRequest
= dynamic_cast<WriteRequest
*>(M
->requestor
);
407 /* remove the free protection */
408 writeRequest
->RefCountDereference();
412 diskd_stats
.write
.fail
++;
414 ioRequestor
->writeCompleted (DISK_ERROR
,0, writeRequest
);
418 diskd_stats
.write
.success
++;
420 ioRequestor
->writeCompleted (DISK_OK
,M
->status
, writeRequest
);
424 DiskdFile::ioInProgress()const
426 return inProgressIOs
!= 0;