]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/DiskIO/AIO/AIODiskFile.cc
2 * AUTHOR: Adrian Chadd <adrian@squid-cache.org>
3 * DEBUG: section 79 Disk IO Routines
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>
37 * These routines are simple plugin replacements for the file_* routines
38 * in disk.c . They back-end into the POSIX AIO routines to provide
39 * a nice and simple async IO framework for COSS.
42 * AIO is suitable for COSS - the only sync operations that the standard
43 * supports are read/write, and since COSS works on a single file
44 * per storedir it should work just fine.
48 #include "AIODiskFile.h"
49 #include "AIODiskIOStrategy.h"
51 #include "DiskIO/IORequestor.h"
52 #include "DiskIO/ReadRequest.h"
53 #include "DiskIO/WriteRequest.h"
60 CBDATA_CLASS_INIT(AIODiskFile
);
62 AIODiskFile::AIODiskFile(char const *aPath
, AIODiskIOStrategy
*aStrategy
) : fd(-1), closed(true), error_(false)
67 debugs(79, 3, "AIODiskFile::AIODiskFile: " << aPath
);
70 AIODiskFile::~AIODiskFile()
74 AIODiskFile::error(bool const &aBool
)
80 AIODiskFile::open(int flags
, mode_t mode
, RefCount
<IORequestor
> callback
)
82 /* Simulate async calls */
84 fd
= aio_open(path
.termedBuf(), flags
);
86 fd
= file_open(path
.termedBuf() , flags
);
89 ioRequestor
= callback
;
92 debugs(79, 3, HERE
<< ": got failure (" << errno
<< ")");
97 debugs(79, 3, HERE
<< ": opened FD " << fd
);
100 callback
->ioCompletedNotification();
104 AIODiskFile::create(int flags
, mode_t mode
, RefCount
<IORequestor
> callback
)
106 /* We use the same logic path for open */
107 open(flags
, mode
, callback
);
111 AIODiskFile::read(ReadRequest
*request
)
114 async_queue_entry_t
*qe
;
116 assert(strategy
->aq
.aq_state
== AQ_STATE_SETUP
);
118 /* Find a free slot */
119 slot
= strategy
->findSlot();
122 /* No free slot? Callback error, and return */
123 fatal("Aiee! out of aiocb slots! - FIXME and wrap file_read\n");
124 debugs(79, DBG_IMPORTANT
, "WARNING: out of aiocb slots!");
125 /* fall back to blocking method */
126 // file_read(fd, request->buf, request->len, request->offset, callback, data);
130 /* Mark slot as ours */
131 qe
= &strategy
->aq
.aq_queue
[slot
];
133 qe
->aq_e_state
= AQ_ENTRY_USED
;
135 qe
->aq_e_callback_data
= cbdataReference(request
);
137 qe
->theFile
= cbdataReference(this);
139 qe
->aq_e_type
= AQ_ENTRY_READ
;
141 qe
->aq_e_free
= NULL
;
143 qe
->aq_e_buf
= request
->buf
;
145 qe
->aq_e_fd
= getFD();
147 qe
->aq_e_aiocb
.aio_fildes
= getFD();
149 qe
->aq_e_aiocb
.aio_nbytes
= request
->len
;
151 qe
->aq_e_aiocb
.aio_offset
= request
->offset
;
153 qe
->aq_e_aiocb
.aio_buf
= request
->buf
;
156 ++ strategy
->aq
.aq_numpending
;
159 if (aio_read(&qe
->aq_e_aiocb
) < 0) {
160 fatalf("Aiee! aio_read() returned error (%d) FIXME and wrap file_read !\n", errno
);
161 debugs(79, DBG_IMPORTANT
, "WARNING: aio_read() returned error: " << xstrerror());
162 /* fall back to blocking method */
163 // file_read(fd, request->buf, request->len, request->offset, callback, data);
169 AIODiskFile::write(WriteRequest
*request
)
172 async_queue_entry_t
*qe
;
174 assert(strategy
->aq
.aq_state
== AQ_STATE_SETUP
);
176 /* Find a free slot */
177 slot
= strategy
->findSlot();
180 /* No free slot? Callback error, and return */
181 fatal("Aiee! out of aiocb slots FIXME and wrap file_write !\n");
182 debugs(79, DBG_IMPORTANT
, "WARNING: out of aiocb slots!");
183 /* fall back to blocking method */
184 // file_write(fd, offset, buf, len, callback, data, freefunc);
188 /* Mark slot as ours */
189 qe
= &strategy
->aq
.aq_queue
[slot
];
191 qe
->aq_e_state
= AQ_ENTRY_USED
;
193 qe
->aq_e_callback_data
= cbdataReference(request
);
195 qe
->theFile
= cbdataReference(this);
197 qe
->aq_e_type
= AQ_ENTRY_WRITE
;
199 qe
->aq_e_free
= request
->free_func
;
201 qe
->aq_e_buf
= (void *)request
->buf
;
205 qe
->aq_e_aiocb
.aio_fildes
= fd
;
207 qe
->aq_e_aiocb
.aio_nbytes
= request
->len
;
209 qe
->aq_e_aiocb
.aio_offset
= request
->offset
;
211 qe
->aq_e_aiocb
.aio_buf
= (void *)request
->buf
;
214 ++strategy
->aq
.aq_numpending
;
217 if (aio_write(&qe
->aq_e_aiocb
) < 0) {
218 fatalf("Aiee! aio_write() returned error (%d) FIXME and wrap file_write !\n", errno
);
219 debugs(79, DBG_IMPORTANT
, "WARNING: aio_write() returned error: " << xstrerror());
220 /* fall back to blocking method */
221 // file_write(fd, offset, buf, len, callback, data, freefunc);
226 AIODiskFile::close ()
237 assert (ioRequestor
!= NULL
);
238 ioRequestor
->closeCompleted();
242 AIODiskFile::canRead() const
248 AIODiskFile::canWrite() const
254 AIODiskFile::getFD() const
260 AIODiskFile::error() const
266 AIODiskFile::ioInProgress() const