]> git.ipfire.org Git - thirdparty/squid.git/blame - src/DiskIO/AIO/AIODiskIOStrategy.cc
Cleanup: zap CVS Id tags
[thirdparty/squid.git] / src / DiskIO / AIO / AIODiskIOStrategy.cc
CommitLineData
b9ae18aa 1
2/*
262a0e14 3 * $Id$
b9ae18aa 4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
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.
16 *
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.
26ac0430 21 *
b9ae18aa 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.
26ac0430 26 *
b9ae18aa 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.
30 *
31 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
32 */
33/*
34 * Author: Adrian Chadd <adrian@squid-cache.org>
35 *
36 * These routines are simple plugin replacements for the file_* routines
37 * in disk.c . They back-end into the POSIX AIO routines to provide
38 * a nice and simple async IO framework for COSS.
39 *
40 * AIO is suitable for COSS - the only sync operations that the standard
41 * supports are read/write, and since COSS works on a single file
42 * per storedir it should work just fine.
43 */
44
45#include "squid.h"
46#include "AIODiskIOStrategy.h"
47#include "AIODiskFile.h"
48#include "DiskIO/IORequestor.h"
49#include "DiskIO/ReadRequest.h"
50#include "DiskIO/WriteRequest.h"
51
52AIODiskIOStrategy::AIODiskIOStrategy()
53{
54 aq.aq_numpending = 0;
55}
56
57AIODiskIOStrategy::~AIODiskIOStrategy()
58{
59 assert(aq.aq_state == AQ_STATE_SETUP ||
60 aq.aq_numpending == 0);
61
62 sync();
63 aq.aq_state = AQ_STATE_NONE;
64}
65
66bool
67AIODiskIOStrategy::shedLoad()
68{
69 return false;
70}
71
72int
73AIODiskIOStrategy::load()
74{
75 return aq.aq_numpending * 1000 / MAX_ASYNCOP;
76}
77
78RefCount<DiskFile>
79AIODiskIOStrategy::newFile (char const *path)
80{
81 if (shedLoad()) {
82 return NULL;
83 }
84
85 return new AIODiskFile (path, this);
86}
87
88void
89AIODiskIOStrategy::sync()
90{
91 assert(aq.aq_state == AQ_STATE_SETUP);
92
93 /*
94 * Keep calling callback to complete ops until the queue is empty
95 * We can't quit when callback returns 0 - some calls may not
96 * return any completed pending events, but they're still pending!
97 */
98
99 while (aq.aq_numpending)
100 callback();
101}
102
103void
104AIODiskIOStrategy::unlinkFile (char const *)
105{}
106
107/*
108 * Note: we grab the state and free the state before calling the callback
109 * because this allows us to cut down the amount of time it'll take
110 * to find a free slot (since if we call the callback first, we're going
111 * to probably be allocated the slot _after_ this one..)
112 *
113 * I'll make it much more optimal later.
114 */
115int
116AIODiskIOStrategy::callback()
117{
118 return 0;
119 int i;
120 int completed = 0;
121 int retval, reterr;
122 FREE *freefunc;
123 void *cbdata;
124 int callback_valid;
125 void *buf;
126 int fd;
127 async_queue_entry_t *aqe;
128 async_queue_entry_type_t type;
129
130 assert(aq.aq_state == AQ_STATE_SETUP);
131
132 /* Loop through all slots */
133
134 for (i = 0; i < MAX_ASYNCOP; i++) {
135 if (aq.aq_queue[i].aq_e_state == AQ_ENTRY_USED) {
136 aqe = &aq.aq_queue[i];
137 /* Active, get status */
138 reterr = aio_error(&aqe->aq_e_aiocb);
139
140 if (reterr < 0) {
141 fatal("aio_error returned an error!\n");
142 }
143
144 if (reterr != EINPROGRESS) {
145 /* Get the return code */
146 retval = aio_return(&aqe->aq_e_aiocb);
147
148 /* Get the callback parameters */
149 freefunc = aqe->aq_e_free;
150 buf = aqe->aq_e_buf;
151 fd = aqe->aq_e_fd;
152 type = aqe->aq_e_type;
153 callback_valid = cbdataReferenceValidDone(aqe->aq_e_callback_data, &cbdata);
154 AIODiskFile * theFile = NULL;
155 void *theFileVoid = NULL;
8abf232c 156 void *theTmpFile = aqe->theFile;
157 bool fileOk = cbdataReferenceValidDone(theTmpFile, &theFileVoid);
b9ae18aa 158
159 if (fileOk) {
160 theFile = static_cast<AIODiskFile *>(theFileVoid);
161 }
162
163 /* Free slot */
04830959 164 memset(aqe, 0, sizeof(async_queue_entry_t));
b9ae18aa 165
166 aqe->aq_e_state = AQ_ENTRY_FREE;
167
168 --aq.aq_numpending;
169
170 /* Callback */
171
172 if (callback_valid) {
173 assert (fileOk);
174
175 if (type == AQ_ENTRY_READ)
176 theFile->ioRequestor->readCompleted((const char *)buf, retval, reterr, static_cast<ReadRequest *>(cbdata));
177
178 if (type == AQ_ENTRY_WRITE)
179 theFile->ioRequestor->writeCompleted(reterr,retval, static_cast<WriteRequest *>(cbdata));
180 }
181
182 if (type == AQ_ENTRY_WRITE && freefunc)
183 freefunc(buf);
184 }
185 }
186 }
187
188 return completed;
189}
190
191void
192AIODiskIOStrategy::init()
193{
194 /* Make sure the queue isn't setup */
195 assert(aq.aq_state == AQ_STATE_NONE);
196
197 /* Loop through, blanking the queue entries */
198
199 /* Done */
200 aq.aq_state = AQ_STATE_SETUP;
201}
202
203void
204AIODiskIOStrategy::statfs(StoreEntry & sentry)const
26ac0430 205{}
b9ae18aa 206
207ConfigOption *
208AIODiskIOStrategy::getOptionTree() const
209{
210 return NULL;
211}
212
213/*
214 * find a free aio slot.
215 * Return the index, or -1 if we can't find one.
216 */
217int
218AIODiskIOStrategy::findSlot()
219{
220 /* Later we should use something a little more .. efficient :) */
221
222 for (int i = 0; i < MAX_ASYNCOP; i++) {
223 if (aq.aq_queue[i].aq_e_state == AQ_ENTRY_FREE)
224 /* Found! */
225 return i;
226 }
227
228 /* found nothing */
229 return -1;
230}