r10458: Patches from Jiri Sasek <Jiri.Sasek@Sun.COM> to help
[Samba/nascimento.git] / source3 / smbd / aio.c
blobaf1f172b9244d76788051c0c147aa0ae3c0508a3
1 /*
2 Unix SMB/Netbios implementation.
3 Version 3.0
4 async_io read handling using POSIX async io.
5 Copyright (C) Jeremy Allison 2005.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
24 #if defined(WITH_AIO)
26 /* The signal we'll use to signify aio done. */
27 #ifndef RT_SIGNAL_AIO
28 #define RT_SIGNAL_AIO (SIGRTMIN+3)
29 #endif
31 /****************************************************************************
32 The buffer we keep around whilst an aio request is in process.
33 *****************************************************************************/
35 struct aio_extra {
36 struct aio_extra *next, *prev;
37 SMB_STRUCT_AIOCB acb;
38 files_struct *fsp;
39 BOOL read_req;
40 uint16 mid;
41 char *inbuf;
42 char *outbuf;
45 static struct aio_extra *aio_list_head;
47 /****************************************************************************
48 Create the extended aio struct we must keep around for the lifetime
49 of the aio_read call.
50 *****************************************************************************/
52 static struct aio_extra *create_aio_ex_read(files_struct *fsp, size_t buflen, uint16 mid)
54 struct aio_extra *aio_ex = SMB_MALLOC_P(struct aio_extra);
56 if (!aio_ex) {
57 return NULL;
59 ZERO_STRUCTP(aio_ex);
60 /* The output buffer stored in the aio_ex is the start of
61 the smb return buffer. The buffer used in the acb
62 is the start of the reply data portion of that buffer. */
63 aio_ex->outbuf = SMB_MALLOC_ARRAY(char, buflen);
64 if (!aio_ex->outbuf) {
65 SAFE_FREE(aio_ex);
66 return NULL;
68 DLIST_ADD(aio_list_head, aio_ex);
69 aio_ex->fsp = fsp;
70 aio_ex->read_req = True;
71 aio_ex->mid = mid;
72 return aio_ex;
75 /****************************************************************************
76 Create the extended aio struct we must keep around for the lifetime
77 of the aio_write call.
78 *****************************************************************************/
80 static struct aio_extra *create_aio_ex_write(files_struct *fsp, size_t outbuflen, uint16 mid)
82 struct aio_extra *aio_ex = SMB_MALLOC_P(struct aio_extra);
84 if (!aio_ex) {
85 return NULL;
87 ZERO_STRUCTP(aio_ex);
89 /* We need space for an output reply of outbuflen bytes. */
90 aio_ex->outbuf = SMB_MALLOC_ARRAY(char, outbuflen);
91 if (!aio_ex->outbuf) {
92 SAFE_FREE(aio_ex);
93 return NULL;
95 /* Steal the input buffer containing the write data from the main SMB call. */
96 /* We must re-allocate a new one here. */
97 if (NewInBuffer(&aio_ex->inbuf) == NULL) {
98 SAFE_FREE(aio_ex->outbuf);
99 SAFE_FREE(aio_ex);
100 return NULL;
103 /* aio_ex->inbuf now contains the stolen old InBuf containing the data to write. */
105 DLIST_ADD(aio_list_head, aio_ex);
106 aio_ex->fsp = fsp;
107 aio_ex->read_req = False;
108 aio_ex->mid = mid;
109 return aio_ex;
112 /****************************************************************************
113 Delete the extended aio struct.
114 *****************************************************************************/
116 static void delete_aio_ex(struct aio_extra *aio_ex)
118 DLIST_REMOVE(aio_list_head, aio_ex);
119 /* Safe to do as we've removed ourselves from the in use list first. */
120 free_InBuffer(aio_ex->inbuf);
122 SAFE_FREE(aio_ex->outbuf);
123 SAFE_FREE(aio_ex);
126 /****************************************************************************
127 Given the aiocb struct find the extended aio struct containing it.
128 *****************************************************************************/
130 static struct aio_extra *find_aio_ex(uint16 mid)
132 struct aio_extra *p;
134 for( p = aio_list_head; p; p = p->next) {
135 if (mid == p->mid) {
136 return p;
139 return NULL;
142 /****************************************************************************
143 We can have these many aio buffers in flight.
144 *****************************************************************************/
146 #define AIO_PENDING_SIZE 10
147 static sig_atomic_t signals_received;
148 static int outstanding_aio_calls;
149 static uint16 aio_pending_array[AIO_PENDING_SIZE];
151 /****************************************************************************
152 Signal handler when an aio request completes.
153 *****************************************************************************/
155 static void signal_handler(int sig, siginfo_t *info, void *unused)
157 if (signals_received < AIO_PENDING_SIZE - 1) {
158 aio_pending_array[signals_received] = *(uint16 *)(info->si_value.sival_ptr);
159 signals_received++;
160 } /* Else signal is lost. */
161 sys_select_signal(RT_SIGNAL_AIO);
164 /****************************************************************************
165 Is there a signal waiting ?
166 *****************************************************************************/
168 BOOL aio_finished(void)
170 return (signals_received != 0);
173 /****************************************************************************
174 Initialize the signal handler for aio read/write.
175 *****************************************************************************/
177 void initialize_async_io_handler(void)
179 struct sigaction act;
181 ZERO_STRUCT(act);
182 act.sa_sigaction = signal_handler;
183 act.sa_flags = SA_SIGINFO;
184 sigemptyset( &act.sa_mask );
185 if (sigaction(RT_SIGNAL_AIO, &act, NULL) != 0) {
186 DEBUG(0,("Failed to setup RT_SIGNAL_AIO handler\n"));
189 /* the signal can start off blocked due to a bug in bash */
190 BlockSignals(False, RT_SIGNAL_AIO);
193 /****************************************************************************
194 Set up an aio request from a SMBreadX call.
195 *****************************************************************************/
197 BOOL schedule_aio_read_and_X(connection_struct *conn,
198 char *inbuf, char *outbuf,
199 int length, int len_outbuf,
200 files_struct *fsp, SMB_OFF_T startpos,
201 size_t smb_maxcnt)
203 struct aio_extra *aio_ex;
204 SMB_STRUCT_AIOCB *a;
205 size_t bufsize;
206 size_t min_aio_read_size = lp_aio_read_size(SNUM(conn));
208 if (!min_aio_read_size || (smb_maxcnt < min_aio_read_size)) {
209 /* Too small a read for aio request. */
210 DEBUG(10,("schedule_aio_read_and_X: read size (%u) too small "
211 "for minimum aio_read of %u\n",
212 (unsigned int)smb_maxcnt,
213 (unsigned int)min_aio_read_size ));
214 return False;
217 /* Only do this on non-chained and non-chaining reads not using the write cache. */
218 if (chain_size !=0 || (CVAL(inbuf,smb_vwv0) != 0xFF) || (lp_write_cache_size(SNUM(conn)) != 0) ) {
219 return False;
222 if (outstanding_aio_calls >= AIO_PENDING_SIZE) {
223 DEBUG(10,("schedule_aio_read_and_X: Already have %d aio activities outstanding.\n",
224 outstanding_aio_calls ));
225 return False;
228 /* The following is safe from integer wrap as we've already
229 checked smb_maxcnt is 128k or less. */
230 bufsize = PTR_DIFF(smb_buf(outbuf),outbuf) + smb_maxcnt;
232 if ((aio_ex = create_aio_ex_read(fsp, bufsize, SVAL(inbuf,smb_mid))) == NULL) {
233 DEBUG(10,("schedule_aio_read_and_X: malloc fail.\n"));
234 return False;
237 /* Copy the SMB header already setup in outbuf. */
238 memcpy(aio_ex->outbuf, outbuf, smb_buf(outbuf) - outbuf);
239 SCVAL(aio_ex->outbuf,smb_vwv0,0xFF); /* Never a chained reply. */
241 a = &aio_ex->acb;
243 /* Now set up the aio record for the read call. */
245 a->aio_fildes = fsp->fh->fd;
246 a->aio_buf = smb_buf(aio_ex->outbuf);
247 a->aio_nbytes = smb_maxcnt;
248 a->aio_offset = startpos;
249 a->aio_sigevent.sigev_notify = SIGEV_SIGNAL;
250 a->aio_sigevent.sigev_signo = RT_SIGNAL_AIO;
251 a->aio_sigevent.sigev_value.sival_ptr = (void *)&aio_ex->mid;
253 if (SMB_VFS_AIO_READ(fsp,a) == -1) {
254 DEBUG(0,("schedule_aio_read_and_X: aio_read failed. Error %s\n",
255 strerror(errno) ));
256 delete_aio_ex(aio_ex);
257 return False;
260 DEBUG(10,("schedule_aio_read_and_X: scheduled aio_read for file %s, offset %.0f, len = %u (mid = %u)\n",
261 fsp->fsp_name, (double)startpos, (unsigned int)smb_maxcnt, (unsigned int)aio_ex->mid ));
263 srv_defer_sign_response(aio_ex->mid);
264 outstanding_aio_calls++;
265 return True;
268 /****************************************************************************
269 Set up an aio request from a SMBwriteX call.
270 *****************************************************************************/
272 BOOL schedule_aio_write_and_X(connection_struct *conn,
273 char *inbuf, char *outbuf,
274 int length, int len_outbuf,
275 files_struct *fsp, char *data,
276 SMB_OFF_T startpos,
277 size_t numtowrite)
279 struct aio_extra *aio_ex;
280 SMB_STRUCT_AIOCB *a;
281 size_t outbufsize;
282 BOOL write_through = BITSETW(inbuf+smb_vwv7,0);
283 size_t min_aio_write_size = lp_aio_write_size(SNUM(conn));
285 if (!min_aio_write_size || (numtowrite < min_aio_write_size)) {
286 /* Too small a write for aio request. */
287 DEBUG(10,("schedule_aio_write_and_X: write size (%u) too small "
288 "for minimum aio_write of %u\n",
289 (unsigned int)numtowrite,
290 (unsigned int)min_aio_write_size ));
291 return False;
294 /* Only do this on non-chained and non-chaining reads not using the write cache. */
295 if (chain_size !=0 || (CVAL(inbuf,smb_vwv0) != 0xFF) || (lp_write_cache_size(SNUM(conn)) != 0) ) {
296 return False;
299 if (outstanding_aio_calls >= AIO_PENDING_SIZE) {
300 DEBUG(3,("schedule_aio_write_and_X: Already have %d aio activities outstanding.\n",
301 outstanding_aio_calls ));
302 DEBUG(10,("schedule_aio_write_and_X: failed to schedule aio_write for file %s, offset %.0f, len = %u (mid = %u)\n",
303 fsp->fsp_name, (double)startpos, (unsigned int)numtowrite, (unsigned int)SVAL(inbuf,smb_mid) ));
304 return False;
307 outbufsize = smb_len(outbuf) + 4;
308 if ((aio_ex = create_aio_ex_write(fsp, outbufsize, SVAL(inbuf,smb_mid))) == NULL) {
309 DEBUG(0,("schedule_aio_write_and_X: malloc fail.\n"));
310 return False;
313 /* Paranioa.... */
314 SMB_ASSERT(aio_ex->inbuf == inbuf);
316 /* Copy the SMB header already setup in outbuf. */
317 memcpy(aio_ex->outbuf, outbuf, outbufsize);
318 SCVAL(aio_ex->outbuf,smb_vwv0,0xFF); /* Never a chained reply. */
320 a = &aio_ex->acb;
322 /* Now set up the aio record for the write call. */
324 a->aio_fildes = fsp->fh->fd;
325 a->aio_buf = data; /* As we've stolen inbuf this points within inbuf. */
326 a->aio_nbytes = numtowrite;
327 a->aio_offset = startpos;
328 a->aio_sigevent.sigev_notify = SIGEV_SIGNAL;
329 a->aio_sigevent.sigev_signo = RT_SIGNAL_AIO;
330 a->aio_sigevent.sigev_value.sival_ptr = (void *)&aio_ex->mid;
332 if (SMB_VFS_AIO_WRITE(fsp,a) == -1) {
333 DEBUG(3,("schedule_aio_wrote_and_X: aio_write failed. Error %s\n",
334 strerror(errno) ));
335 /* Replace global InBuf as we're going to do a normal write. */
336 set_InBuffer(aio_ex->inbuf);
337 aio_ex->inbuf = NULL;
338 delete_aio_ex(aio_ex);
339 return False;
342 if (!write_through && !lp_syncalways(SNUM(fsp->conn)) && fsp->aio_write_behind) {
343 /* Lie to the client and immediately claim we finished the write. */
344 SSVAL(aio_ex->outbuf,smb_vwv2,numtowrite);
345 SSVAL(aio_ex->outbuf,smb_vwv4,(numtowrite>>16)&1);
346 show_msg(aio_ex->outbuf);
347 if (!send_smb(smbd_server_fd(),aio_ex->outbuf)) {
348 exit_server("handle_aio_write: send_smb failed.");
350 DEBUG(10,("schedule_aio_write_and_X: scheduled aio_write behind for file %s\n",
351 fsp->fsp_name ));
352 } else {
353 srv_defer_sign_response(aio_ex->mid);
355 outstanding_aio_calls++;
357 DEBUG(10,("schedule_aio_write_and_X: scheduled aio_write for file %s, \
358 offset %.0f, len = %u (mid = %u) outstanding_aio_calls = %d\n",
359 fsp->fsp_name, (double)startpos, (unsigned int)numtowrite, (unsigned int)aio_ex->mid, outstanding_aio_calls ));
361 return True;
365 /****************************************************************************
366 Complete the read and return the data or error back to the client.
367 Returns errno or zero if all ok.
368 *****************************************************************************/
370 static int handle_aio_read_complete(struct aio_extra *aio_ex)
372 int ret = 0;
373 int outsize;
374 char *outbuf = aio_ex->outbuf;
375 char *data = smb_buf(outbuf);
376 ssize_t nread = SMB_VFS_AIO_RETURN(aio_ex->fsp,&aio_ex->acb);
378 if (nread < 0) {
379 /* We're relying here on the fact that if the fd is
380 closed then the aio will complete and aio_return
381 will return an error. Hopefully this is
382 true.... JRA. */
384 /* If errno is ECANCELED then don't return anything to the client. */
385 if (errno == ECANCELED) {
386 srv_cancel_sign_response(aio_ex->mid);
387 return 0;
390 DEBUG( 3,( "handle_aio_read_complete: file %s nread == -1. Error = %s\n",
391 aio_ex->fsp->fsp_name, strerror(errno) ));
393 outsize = (UNIXERROR(ERRDOS,ERRnoaccess));
394 ret = errno;
395 } else {
396 outsize = set_message(outbuf,12,nread,False);
397 SSVAL(outbuf,smb_vwv2,0xFFFF); /* Remaining - must be * -1. */
398 SSVAL(outbuf,smb_vwv5,nread);
399 SSVAL(outbuf,smb_vwv6,smb_offset(data,outbuf));
400 SSVAL(outbuf,smb_vwv7,((nread >> 16) & 1));
401 SSVAL(smb_buf(outbuf),-2,nread);
403 DEBUG( 3, ( "handle_aio_read_complete file %s max=%d nread=%d\n",
404 aio_ex->fsp->fsp_name,
405 aio_ex->acb.aio_nbytes, (int)nread ) );
408 smb_setlen(outbuf,outsize - 4);
409 show_msg(outbuf);
410 if (!send_smb(smbd_server_fd(),outbuf)) {
411 exit_server("handle_aio_read_complete: send_smb failed.");
414 DEBUG(10,("handle_aio_read_complete: scheduled aio_read completed for file %s, offset %.0f, len = %u\n",
415 aio_ex->fsp->fsp_name, (double)aio_ex->acb.aio_offset, (unsigned int)nread ));
417 return ret;
420 /****************************************************************************
421 Complete the write and return the data or error back to the client.
422 Returns errno or zero if all ok.
423 *****************************************************************************/
425 static int handle_aio_write_complete(struct aio_extra *aio_ex)
427 int ret = 0;
428 files_struct *fsp = aio_ex->fsp;
429 char *outbuf = aio_ex->outbuf;
430 ssize_t numtowrite = aio_ex->acb.aio_nbytes;
431 ssize_t nwritten = SMB_VFS_AIO_RETURN(fsp,&aio_ex->acb);
433 if (fsp->aio_write_behind) {
434 if (nwritten != numtowrite) {
435 if (nwritten == -1) {
436 DEBUG(5,("handle_aio_write_complete: aio_write_behind failed ! File %s is corrupt ! Error %s\n",
437 fsp->fsp_name, strerror(errno) ));
438 ret = errno;
439 } else {
440 DEBUG(0,("handle_aio_write_complete: aio_write_behind failed ! File %s is corrupt ! \
441 Wanted %u bytes but only wrote %d\n", fsp->fsp_name, (unsigned int)numtowrite, (int)nwritten ));
442 ret = EIO;
444 } else {
445 DEBUG(10,("handle_aio_write_complete: aio_write_behind completed for file %s\n",
446 fsp->fsp_name ));
448 return 0;
451 /* We don't need outsize or set_message here as we've already set the
452 fixed size length when we set up the aio call. */
454 if(nwritten == -1) {
455 DEBUG( 3,( "handle_aio_write: file %s wanted %u bytes. nwritten == %d. Error = %s\n",
456 fsp->fsp_name, (unsigned int)numtowrite,
457 (int)nwritten, strerror(errno) ));
459 /* If errno is ECANCELED then don't return anything to the client. */
460 if (errno == ECANCELED) {
461 srv_cancel_sign_response(aio_ex->mid);
462 return 0;
465 UNIXERROR(ERRHRD,ERRdiskfull);
466 ret = errno;
467 } else {
468 BOOL write_through = BITSETW(aio_ex->inbuf+smb_vwv7,0);
470 SSVAL(outbuf,smb_vwv2,nwritten);
471 SSVAL(outbuf,smb_vwv4,(nwritten>>16)&1);
472 if (nwritten < (ssize_t)numtowrite) {
473 SCVAL(outbuf,smb_rcls,ERRHRD);
474 SSVAL(outbuf,smb_err,ERRdiskfull);
477 DEBUG(3,("handle_aio_write: fnum=%d num=%d wrote=%d\n", fsp->fnum, (int)numtowrite, (int)nwritten));
478 sync_file(fsp->conn,fsp, write_through);
481 show_msg(outbuf);
482 if (!send_smb(smbd_server_fd(),outbuf)) {
483 exit_server("handle_aio_write: send_smb failed.");
486 DEBUG(10,("handle_aio_write_complete: scheduled aio_write completed for file %s, offset %.0f, requested %u, written = %u\n",
487 fsp->fsp_name, (double)aio_ex->acb.aio_offset, (unsigned int)numtowrite, (unsigned int)nwritten ));
489 return ret;
492 /****************************************************************************
493 Handle any aio completion. Returns True if finished (and sets *perr if err was non-zero),
494 False if not.
495 *****************************************************************************/
497 static BOOL handle_aio_completed(struct aio_extra *aio_ex, int *perr)
499 int err;
501 /* Ensure the operation has really completed. */
502 if (SMB_VFS_AIO_ERROR(aio_ex->fsp, &aio_ex->acb) == EINPROGRESS) {
503 DEBUG(10,( "handle_aio_completed: operation mid %u still in process for file %s\n",
504 aio_ex->mid, aio_ex->fsp->fsp_name ));
505 return False;
508 if (aio_ex->read_req) {
509 err = handle_aio_read_complete(aio_ex);
510 } else {
511 err = handle_aio_write_complete(aio_ex);
514 if (err) {
515 *perr = err; /* Only save non-zero errors. */
518 return True;
521 /****************************************************************************
522 Handle any aio completion inline.
523 Returns non-zero errno if fail or zero if all ok.
524 *****************************************************************************/
526 int process_aio_queue(void)
528 int i;
529 int ret = 0;
531 BlockSignals(True, RT_SIGNAL_AIO);
533 DEBUG(10,("process_aio_queue: signals_received = %d\n", (int)signals_received));
534 DEBUG(10,("process_aio_queue: outstanding_aio_calls = %d\n", outstanding_aio_calls));
536 if (!signals_received) {
537 BlockSignals(False, RT_SIGNAL_AIO);
538 return 0;
541 /* Drain all the complete aio_reads. */
542 for (i = 0; i < signals_received; i++) {
543 uint16 mid = aio_pending_array[i];
544 files_struct *fsp = NULL;
545 struct aio_extra *aio_ex = find_aio_ex(mid);
547 if (!aio_ex) {
548 DEBUG(3,("process_aio_queue: Can't find record to match mid %u.\n",
549 (unsigned int)mid));
550 srv_cancel_sign_response(mid);
551 continue;
554 fsp = aio_ex->fsp;
555 if (fsp == NULL) {
556 /* file was closed whilst I/O was outstanding. Just ignore. */
557 DEBUG( 3,( "process_aio_queue: file closed whilst aio outstanding.\n"));
558 srv_cancel_sign_response(mid);
559 continue;
562 if (!handle_aio_completed(aio_ex, &ret)) {
563 continue;
566 delete_aio_ex(aio_ex);
569 outstanding_aio_calls -= signals_received;
570 signals_received = 0;
571 BlockSignals(False, RT_SIGNAL_AIO);
572 return ret;
575 /****************************************************************************
576 We're doing write behind and the client closed the file. Wait up to 30 seconds
577 (my arbitrary choice) for the aio to complete. Return 0 if all writes completed,
578 errno to return if not.
579 *****************************************************************************/
581 #define SMB_TIME_FOR_AIO_COMPLETE_WAIT 29
583 BOOL wait_for_aio_completion(files_struct *fsp)
585 struct aio_extra *aio_ex;
586 const SMB_STRUCT_AIOCB **aiocb_list;
587 int aio_completion_count = 0;
588 time_t start_time = time(NULL);
589 int seconds_left;
590 int ret = 0;
592 for (seconds_left = SMB_TIME_FOR_AIO_COMPLETE_WAIT; seconds_left >= 0;) {
593 int err = 0;
594 int i;
595 struct timespec ts;
597 aio_completion_count = 0;
598 for( aio_ex = aio_list_head; aio_ex; aio_ex = aio_ex->next) {
599 if (aio_ex->fsp == fsp) {
600 aio_completion_count++;
604 if (!aio_completion_count) {
605 return ret;
608 DEBUG(3,("wait_for_aio_completion: waiting for %d aio events to complete.\n",
609 aio_completion_count ));
611 aiocb_list = SMB_MALLOC_ARRAY(const SMB_STRUCT_AIOCB *, aio_completion_count);
612 if (!aiocb_list) {
613 return False;
616 for( i = 0, aio_ex = aio_list_head; aio_ex; aio_ex = aio_ex->next) {
617 if (aio_ex->fsp == fsp) {
618 aiocb_list[i++] = &aio_ex->acb;
622 /* Now wait up to seconds_left for completion. */
623 ts.tv_sec = seconds_left;
624 ts.tv_nsec = 0;
626 DEBUG(10,("wait_for_aio_completion: %d events, doing a wait of %d seconds.\n",
627 aio_completion_count, seconds_left ));
629 err = SMB_VFS_AIO_SUSPEND(fsp, aiocb_list, aio_completion_count, &ts);
631 DEBUG(10,("wait_for_aio_completion: returned err = %d, errno = %s\n",
632 err, strerror(errno) ));
634 if (err == -1 && errno == EAGAIN) {
635 DEBUG(0,("wait_for_aio_completion: aio_suspend timed out waiting for %d events after a wait of %d seconds\n",
636 aio_completion_count, seconds_left));
637 /* Timeout. */
638 cancel_aio_by_fsp(fsp);
639 SAFE_FREE(aiocb_list);
640 return ret ? ret : EIO;
643 /* One or more events might have completed - process them if so. */
644 for( i = 0; i < aio_completion_count; i++) {
645 uint16 mid = *(uint16 *)aiocb_list[i]->aio_sigevent.sigev_value.sival_ptr;
647 aio_ex = find_aio_ex(mid);
649 if (!handle_aio_completed(aio_ex, &err)) {
650 continue;
652 delete_aio_ex(aio_ex);
655 SAFE_FREE(aiocb_list);
656 seconds_left = SMB_TIME_FOR_AIO_COMPLETE_WAIT - (time(NULL) - start_time);
659 /* We timed out - we don't know why. Return ret if already an error, else EIO. */
660 DEBUG(10,("wait_for_aio_completion: aio_suspend timed out waiting for %d events\n",
661 aio_completion_count));
663 return ret ? ret : EIO;
666 /****************************************************************************
667 Cancel any outstanding aio requests. The client doesn't care about the reply.
668 *****************************************************************************/
670 void cancel_aio_by_fsp(files_struct *fsp)
672 struct aio_extra *aio_ex;
674 for( aio_ex = aio_list_head; aio_ex; aio_ex = aio_ex->next) {
675 if (aio_ex->fsp == fsp) {
676 /* Don't delete the aio_extra record as we may have completed
677 and don't yet know it. Just do the aio_cancel call and return. */
678 SMB_VFS_AIO_CANCEL(fsp,fsp->fh->fd, &aio_ex->acb);
679 aio_ex->fsp = NULL; /* fsp will be closed when we return. */
684 /****************************************************************************
685 Check if a buffer was stolen for aio use.
686 *****************************************************************************/
688 BOOL aio_inbuffer_in_use(char *inbuf)
690 struct aio_extra *aio_ex;
692 for( aio_ex = aio_list_head; aio_ex; aio_ex = aio_ex->next) {
693 if (aio_ex->inbuf == inbuf) {
694 return True;
697 return False;
699 #else
700 BOOL aio_finished(void)
702 return False;
705 void initialize_async_io_handler(void)
709 int process_aio_queue(void)
711 return False;
714 BOOL schedule_aio_read_and_X(connection_struct *conn,
715 char *inbuf, char *outbuf,
716 int length, int len_outbuf,
717 files_struct *fsp, SMB_OFF_T startpos,
718 size_t smb_maxcnt)
720 return False;
723 BOOL schedule_aio_write_and_X(connection_struct *conn,
724 char *inbuf, char *outbuf,
725 int length, int len_outbuf,
726 files_struct *fsp, char *data,
727 SMB_OFF_T startpos,
728 size_t numtowrite)
730 return False;
733 void cancel_aio_by_fsp(files_struct *fsp)
737 BOOL wait_for_aio_completion(files_struct *fsp)
739 return True;
742 BOOL aio_inbuffer_in_use(char *ptr)
744 return False;
746 #endif