5 * DEBUG: section 32 Asynchronous Disk I/O
6 * AUTHOR: Pete Bentley <pete@demon.net>
7 * AUTHOR: Stewart Forster <slf@connect.com.au>
9 * SQUID Web Proxy Cache http://www.squid-cache.org/
10 * ----------------------------------------------------------
12 * Squid is the result of efforts by numerous individuals from
13 * the Internet community; see the CONTRIBUTORS file for full
14 * details. Many organizations have provided support for Squid's
15 * development; see the SPONSORS file for full details. Squid is
16 * Copyrighted (C) 2001 by the Regents of the University of
17 * California; see the COPYRIGHT file for full details. Squid
18 * incorporates software developed and/or copyrighted by other
19 * sources; see the CREDITS file for full details.
21 * This program is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 2 of the License, or
24 * (at your option) any later version.
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
38 #include "DiskThreads.h"
41 #include "DiskThreadsIOStrategy.h"
44 AIOCounts squidaio_counts
;
46 typedef struct squidaio_unlinkq_t
{
49 struct squidaio_unlinkq_t
*next
;
55 aioOpen(const char *path
, int oflag
, mode_t mode
, AIOCB
* callback
, void *callback_data
)
57 squidaio_ctrl_t
*ctrlp
;
59 assert(DiskThreadsIOStrategy::Instance
.initialised
);
60 ++squidaio_counts
.open_start
;
61 ctrlp
= (squidaio_ctrl_t
*)DiskThreadsIOStrategy::Instance
.squidaio_ctrl_pool
->alloc();
63 ctrlp
->done_handler
= callback
;
64 ctrlp
->done_handler_data
= cbdataReference(callback_data
);
65 ctrlp
->operation
= _AIO_OPEN
;
66 ctrlp
->result
.data
= ctrlp
;
67 squidaio_open(path
, oflag
, mode
, &ctrlp
->result
);
68 dlinkAdd(ctrlp
, &ctrlp
->node
, &used_list
);
75 squidaio_ctrl_t
*ctrlp
;
77 assert(DiskThreadsIOStrategy::Instance
.initialised
);
78 ++squidaio_counts
.close_start
;
80 ctrlp
= (squidaio_ctrl_t
*)DiskThreadsIOStrategy::Instance
.squidaio_ctrl_pool
->alloc();
82 ctrlp
->done_handler
= NULL
;
83 ctrlp
->done_handler_data
= NULL
;
84 ctrlp
->operation
= _AIO_CLOSE
;
85 ctrlp
->result
.data
= ctrlp
;
86 squidaio_close(fd
, &ctrlp
->result
);
87 dlinkAdd(ctrlp
, &ctrlp
->node
, &used_list
);
94 squidaio_ctrl_t
*ctrlp
;
97 assert(DiskThreadsIOStrategy::Instance
.initialised
);
98 ++squidaio_counts
.cancel
;
100 for (m
= used_list
.head
; m
; m
= next
) {
102 ctrlp
= (squidaio_ctrl_t
*)m
->data
;
107 squidaio_cancel(&ctrlp
->result
);
109 if (ctrlp
->done_handler
) {
110 AIOCB
*callback
= ctrlp
->done_handler
;
112 ctrlp
->done_handler
= NULL
;
113 debugs(32, DBG_IMPORTANT
, "this be aioCancel. Danger ahead!");
115 if (cbdataReferenceValidDone(ctrlp
->done_handler_data
, &cbdata
))
116 callback(fd
, cbdata
, NULL
, -2, -2);
118 /* free data if requested to aioWrite() */
119 if (ctrlp
->free_func
)
120 ctrlp
->free_func(ctrlp
->bufp
);
122 /* free temporary read buffer */
123 if (ctrlp
->operation
== _AIO_READ
)
124 squidaio_xfree(ctrlp
->bufp
, ctrlp
->len
);
127 dlinkDelete(m
, &used_list
);
128 DiskThreadsIOStrategy::Instance
.squidaio_ctrl_pool
->freeOne(ctrlp
);
133 aioWrite(int fd
, off_t offset
, char *bufp
, size_t len
, AIOCB
* callback
, void *callback_data
, FREE
* free_func
)
135 squidaio_ctrl_t
*ctrlp
;
138 assert(DiskThreadsIOStrategy::Instance
.initialised
);
139 ++squidaio_counts
.write_start
;
140 ctrlp
= (squidaio_ctrl_t
*)DiskThreadsIOStrategy::Instance
.squidaio_ctrl_pool
->alloc();
142 ctrlp
->done_handler
= callback
;
143 ctrlp
->done_handler_data
= cbdataReference(callback_data
);
144 ctrlp
->operation
= _AIO_WRITE
;
146 ctrlp
->free_func
= free_func
;
155 ctrlp
->result
.data
= ctrlp
;
156 squidaio_write(fd
, bufp
, len
, offset
, seekmode
, &ctrlp
->result
);
157 dlinkAdd(ctrlp
, &ctrlp
->node
, &used_list
);
161 aioRead(int fd
, off_t offset
, size_t len
, AIOCB
* callback
, void *callback_data
)
163 squidaio_ctrl_t
*ctrlp
;
166 assert(DiskThreadsIOStrategy::Instance
.initialised
);
167 ++squidaio_counts
.read_start
;
168 ctrlp
= (squidaio_ctrl_t
*)DiskThreadsIOStrategy::Instance
.squidaio_ctrl_pool
->alloc();
170 ctrlp
->done_handler
= callback
;
171 ctrlp
->done_handler_data
= cbdataReference(callback_data
);
172 ctrlp
->operation
= _AIO_READ
;
174 ctrlp
->bufp
= (char *)squidaio_xmalloc(len
);
183 ctrlp
->result
.data
= ctrlp
;
184 squidaio_read(fd
, ctrlp
->bufp
, len
, offset
, seekmode
, &ctrlp
->result
);
185 dlinkAdd(ctrlp
, &ctrlp
->node
, &used_list
);
191 aioStat(char *path
, struct stat
*sb
, AIOCB
* callback
, void *callback_data
)
193 squidaio_ctrl_t
*ctrlp
;
195 assert(DiskThreadsIOStrategy::Instance
.initialised
);
196 ++squidaio_counts
.stat_start
;
197 ctrlp
= (squidaio_ctrl_t
*)DiskThreadsIOStrategy::Instance
.squidaio_ctrl_pool
->alloc();
199 ctrlp
->done_handler
= callback
;
200 ctrlp
->done_handler_data
= cbdataReference(callback_data
);
201 ctrlp
->operation
= _AIO_STAT
;
202 ctrlp
->result
.data
= ctrlp
;
203 squidaio_stat(path
, sb
, &ctrlp
->result
);
204 dlinkAdd(ctrlp
, &ctrlp
->node
, &used_list
);
209 aioUnlink(const char *path
, AIOCB
* callback
, void *callback_data
)
211 squidaio_ctrl_t
*ctrlp
;
212 assert(DiskThreadsIOStrategy::Instance
.initialised
);
213 ++squidaio_counts
.unlink_start
;
214 ctrlp
= (squidaio_ctrl_t
*)DiskThreadsIOStrategy::Instance
.squidaio_ctrl_pool
->alloc();
216 ctrlp
->done_handler
= callback
;
217 ctrlp
->done_handler_data
= cbdataReference(callback_data
);
218 ctrlp
->operation
= _AIO_UNLINK
;
219 ctrlp
->result
.data
= ctrlp
;
220 squidaio_unlink(path
, &ctrlp
->result
);
221 dlinkAdd(ctrlp
, &ctrlp
->node
, &used_list
);
227 return DiskThreadsIOStrategy::Instance
.squidaio_ctrl_pool
->inUseCount();