s4-smbtorture: rename test_EnumDomain{Users,Groups,Aliases} in RPC-SAMR.
[Samba/gbeck.git] / source3 / smbd / aio.c
blobfbfec46d705067fb422b7f9ae6a856c988fdfad8
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 3 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, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "smbd/globals.h"
24 #if defined(WITH_AIO)
26 /* The signal we'll use to signify aio done. */
27 #ifndef RT_SIGNAL_AIO
28 #ifndef SIGRTMIN
29 #define SIGRTMIN NSIG
30 #endif
31 #define RT_SIGNAL_AIO (SIGRTMIN+3)
32 #endif
34 #ifndef HAVE_STRUCT_SIGEVENT_SIGEV_VALUE_SIVAL_PTR
35 #ifdef HAVE_STRUCT_SIGEVENT_SIGEV_VALUE_SIGVAL_PTR
36 #define sival_int sigval_int
37 #define sival_ptr sigval_ptr
38 #endif
39 #endif
41 /****************************************************************************
42 The buffer we keep around whilst an aio request is in process.
43 *****************************************************************************/
45 struct aio_extra {
46 struct aio_extra *next, *prev;
47 SMB_STRUCT_AIOCB acb;
48 files_struct *fsp;
49 struct smb_request *req;
50 char *outbuf;
51 int (*handle_completion)(struct aio_extra *ex);
54 static int handle_aio_read_complete(struct aio_extra *aio_ex);
55 static int handle_aio_write_complete(struct aio_extra *aio_ex);
57 static int aio_extra_destructor(struct aio_extra *aio_ex)
59 DLIST_REMOVE(aio_list_head, aio_ex);
60 return 0;
63 /****************************************************************************
64 Create the extended aio struct we must keep around for the lifetime
65 of the aio call.
66 *****************************************************************************/
68 static struct aio_extra *create_aio_extra(files_struct *fsp, size_t buflen)
70 struct aio_extra *aio_ex = TALLOC_ZERO_P(NULL, struct aio_extra);
72 if (!aio_ex) {
73 return NULL;
76 /* The output buffer stored in the aio_ex is the start of
77 the smb return buffer. The buffer used in the acb
78 is the start of the reply data portion of that buffer. */
80 aio_ex->outbuf = TALLOC_ARRAY(aio_ex, char, buflen);
81 if (!aio_ex->outbuf) {
82 TALLOC_FREE(aio_ex);
83 return NULL;
85 DLIST_ADD(aio_list_head, aio_ex);
86 talloc_set_destructor(aio_ex, aio_extra_destructor);
87 aio_ex->fsp = fsp;
88 return aio_ex;
91 /****************************************************************************
92 Given the mid find the extended aio struct containing it.
93 *****************************************************************************/
95 static struct aio_extra *find_aio_ex(uint16 mid)
97 struct aio_extra *p;
99 for( p = aio_list_head; p; p = p->next) {
100 if (mid == p->req->mid) {
101 return p;
104 return NULL;
107 /****************************************************************************
108 We can have these many aio buffers in flight.
109 *****************************************************************************/
111 /****************************************************************************
112 Set up an aio request from a SMBreadX call.
113 *****************************************************************************/
115 bool schedule_aio_read_and_X(connection_struct *conn,
116 struct smb_request *req,
117 files_struct *fsp, SMB_OFF_T startpos,
118 size_t smb_maxcnt)
120 struct aio_extra *aio_ex;
121 SMB_STRUCT_AIOCB *a;
122 size_t bufsize;
123 size_t min_aio_read_size = lp_aio_read_size(SNUM(conn));
124 int ret;
126 if (fsp->base_fsp != NULL) {
127 /* No AIO on streams yet */
128 DEBUG(10, ("AIO on streams not yet supported\n"));
129 return false;
132 if ((!min_aio_read_size || (smb_maxcnt < min_aio_read_size))
133 && !SMB_VFS_AIO_FORCE(fsp)) {
134 /* Too small a read for aio request. */
135 DEBUG(10,("schedule_aio_read_and_X: read size (%u) too small "
136 "for minimum aio_read of %u\n",
137 (unsigned int)smb_maxcnt,
138 (unsigned int)min_aio_read_size ));
139 return False;
142 /* Only do this on non-chained and non-chaining reads not using the
143 * write cache. */
144 if (req_is_in_chain(req) || (lp_write_cache_size(SNUM(conn)) != 0)) {
145 return False;
148 if (outstanding_aio_calls >= aio_pending_size) {
149 DEBUG(10,("schedule_aio_read_and_X: Already have %d aio "
150 "activities outstanding.\n",
151 outstanding_aio_calls ));
152 return False;
155 /* The following is safe from integer wrap as we've already checked
156 smb_maxcnt is 128k or less. Wct is 12 for read replies */
158 bufsize = smb_size + 12 * 2 + smb_maxcnt;
160 if ((aio_ex = create_aio_extra(fsp, bufsize)) == NULL) {
161 DEBUG(10,("schedule_aio_read_and_X: malloc fail.\n"));
162 return False;
164 aio_ex->handle_completion = handle_aio_read_complete;
166 construct_reply_common_req(req, aio_ex->outbuf);
167 srv_set_message(aio_ex->outbuf, 12, 0, True);
168 SCVAL(aio_ex->outbuf,smb_vwv0,0xFF); /* Never a chained reply. */
170 a = &aio_ex->acb;
172 /* Now set up the aio record for the read call. */
174 a->aio_fildes = fsp->fh->fd;
175 a->aio_buf = smb_buf(aio_ex->outbuf);
176 a->aio_nbytes = smb_maxcnt;
177 a->aio_offset = startpos;
178 a->aio_sigevent.sigev_notify = SIGEV_SIGNAL;
179 a->aio_sigevent.sigev_signo = RT_SIGNAL_AIO;
180 a->aio_sigevent.sigev_value.sival_int = req->mid;
182 ret = SMB_VFS_AIO_READ(fsp, a);
183 if (ret == -1) {
184 DEBUG(0,("schedule_aio_read_and_X: aio_read failed. "
185 "Error %s\n", strerror(errno) ));
186 TALLOC_FREE(aio_ex);
187 return False;
190 aio_ex->req = talloc_move(aio_ex, &req);
192 DEBUG(10,("schedule_aio_read_and_X: scheduled aio_read for file %s, "
193 "offset %.0f, len = %u (mid = %u)\n",
194 fsp->fsp_name, (double)startpos, (unsigned int)smb_maxcnt,
195 (unsigned int)aio_ex->req->mid ));
197 srv_defer_sign_response(aio_ex->req->mid);
198 outstanding_aio_calls++;
199 return True;
202 /****************************************************************************
203 Set up an aio request from a SMBwriteX call.
204 *****************************************************************************/
206 bool schedule_aio_write_and_X(connection_struct *conn,
207 struct smb_request *req,
208 files_struct *fsp, char *data,
209 SMB_OFF_T startpos,
210 size_t numtowrite)
212 struct aio_extra *aio_ex;
213 SMB_STRUCT_AIOCB *a;
214 size_t bufsize;
215 bool write_through = BITSETW(req->vwv+7,0);
216 size_t min_aio_write_size = lp_aio_write_size(SNUM(conn));
217 int ret;
219 if (fsp->base_fsp != NULL) {
220 /* No AIO on streams yet */
221 DEBUG(10, ("AIO on streams not yet supported\n"));
222 return false;
225 if ((!min_aio_write_size || (numtowrite < min_aio_write_size))
226 && !SMB_VFS_AIO_FORCE(fsp)) {
227 /* Too small a write for aio request. */
228 DEBUG(10,("schedule_aio_write_and_X: write size (%u) too "
229 "small for minimum aio_write of %u\n",
230 (unsigned int)numtowrite,
231 (unsigned int)min_aio_write_size ));
232 return False;
235 /* Only do this on non-chained and non-chaining reads not using the
236 * write cache. */
237 if (req_is_in_chain(req) || (lp_write_cache_size(SNUM(conn)) != 0)) {
238 return False;
241 if (outstanding_aio_calls >= aio_pending_size) {
242 DEBUG(3,("schedule_aio_write_and_X: Already have %d aio "
243 "activities outstanding.\n",
244 outstanding_aio_calls ));
245 DEBUG(10,("schedule_aio_write_and_X: failed to schedule "
246 "aio_write for file %s, offset %.0f, len = %u "
247 "(mid = %u)\n",
248 fsp->fsp_name, (double)startpos,
249 (unsigned int)numtowrite,
250 (unsigned int)req->mid ));
251 return False;
254 bufsize = smb_size + 6*2;
256 if (!(aio_ex = create_aio_extra(fsp, bufsize))) {
257 DEBUG(0,("schedule_aio_write_and_X: malloc fail.\n"));
258 return False;
260 aio_ex->handle_completion = handle_aio_write_complete;
262 construct_reply_common_req(req, aio_ex->outbuf);
263 srv_set_message(aio_ex->outbuf, 6, 0, True);
264 SCVAL(aio_ex->outbuf,smb_vwv0,0xFF); /* Never a chained reply. */
266 a = &aio_ex->acb;
268 /* Now set up the aio record for the write call. */
270 a->aio_fildes = fsp->fh->fd;
271 a->aio_buf = data;
272 a->aio_nbytes = numtowrite;
273 a->aio_offset = startpos;
274 a->aio_sigevent.sigev_notify = SIGEV_SIGNAL;
275 a->aio_sigevent.sigev_signo = RT_SIGNAL_AIO;
276 a->aio_sigevent.sigev_value.sival_int = req->mid;
278 ret = SMB_VFS_AIO_WRITE(fsp, a);
279 if (ret == -1) {
280 DEBUG(3,("schedule_aio_wrote_and_X: aio_write failed. "
281 "Error %s\n", strerror(errno) ));
282 TALLOC_FREE(aio_ex);
283 return False;
286 aio_ex->req = talloc_move(aio_ex, &req);
288 /* This should actually be improved to span the write. */
289 contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_WRITE);
290 contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_WRITE);
292 if (!write_through && !lp_syncalways(SNUM(fsp->conn))
293 && fsp->aio_write_behind) {
294 /* Lie to the client and immediately claim we finished the
295 * write. */
296 SSVAL(aio_ex->outbuf,smb_vwv2,numtowrite);
297 SSVAL(aio_ex->outbuf,smb_vwv4,(numtowrite>>16)&1);
298 show_msg(aio_ex->outbuf);
299 if (!srv_send_smb(smbd_server_fd(),aio_ex->outbuf,
300 IS_CONN_ENCRYPTED(fsp->conn),
301 &req->pcd)) {
302 exit_server_cleanly("handle_aio_write: srv_send_smb "
303 "failed.");
305 DEBUG(10,("schedule_aio_write_and_X: scheduled aio_write "
306 "behind for file %s\n", fsp->fsp_name ));
307 } else {
308 srv_defer_sign_response(aio_ex->req->mid);
310 outstanding_aio_calls++;
312 DEBUG(10,("schedule_aio_write_and_X: scheduled aio_write for file "
313 "%s, offset %.0f, len = %u (mid = %u) "
314 "outstanding_aio_calls = %d\n",
315 fsp->fsp_name, (double)startpos, (unsigned int)numtowrite,
316 (unsigned int)aio_ex->req->mid, outstanding_aio_calls ));
318 return True;
322 /****************************************************************************
323 Complete the read and return the data or error back to the client.
324 Returns errno or zero if all ok.
325 *****************************************************************************/
327 static int handle_aio_read_complete(struct aio_extra *aio_ex)
329 int ret = 0;
330 int outsize;
331 char *outbuf = aio_ex->outbuf;
332 char *data = smb_buf(outbuf);
333 ssize_t nread = SMB_VFS_AIO_RETURN(aio_ex->fsp,&aio_ex->acb);
335 if (nread < 0) {
336 /* We're relying here on the fact that if the fd is
337 closed then the aio will complete and aio_return
338 will return an error. Hopefully this is
339 true.... JRA. */
341 /* If errno is ECANCELED then don't return anything to the
342 * client. */
343 if (errno == ECANCELED) {
344 srv_cancel_sign_response(aio_ex->req->mid, false);
345 return 0;
348 DEBUG( 3,( "handle_aio_read_complete: file %s nread == -1. "
349 "Error = %s\n",
350 aio_ex->fsp->fsp_name, strerror(errno) ));
352 ret = errno;
353 ERROR_NT(map_nt_error_from_unix(ret));
354 outsize = srv_set_message(outbuf,0,0,true);
355 } else {
356 outsize = srv_set_message(outbuf,12,nread,False);
357 SSVAL(outbuf,smb_vwv2,0xFFFF); /* Remaining - must be * -1. */
358 SSVAL(outbuf,smb_vwv5,nread);
359 SSVAL(outbuf,smb_vwv6,smb_offset(data,outbuf));
360 SSVAL(outbuf,smb_vwv7,((nread >> 16) & 1));
361 SSVAL(smb_buf(outbuf),-2,nread);
363 aio_ex->fsp->fh->pos = aio_ex->acb.aio_offset + nread;
364 aio_ex->fsp->fh->position_information = aio_ex->fsp->fh->pos;
366 DEBUG( 3, ( "handle_aio_read_complete file %s max=%d "
367 "nread=%d\n",
368 aio_ex->fsp->fsp_name,
369 (int)aio_ex->acb.aio_nbytes, (int)nread ) );
372 smb_setlen(outbuf,outsize - 4);
373 show_msg(outbuf);
374 if (!srv_send_smb(smbd_server_fd(),outbuf,
375 IS_CONN_ENCRYPTED(aio_ex->fsp->conn), NULL)) {
376 exit_server_cleanly("handle_aio_read_complete: srv_send_smb "
377 "failed.");
380 DEBUG(10,("handle_aio_read_complete: scheduled aio_read completed "
381 "for file %s, offset %.0f, len = %u\n",
382 aio_ex->fsp->fsp_name, (double)aio_ex->acb.aio_offset,
383 (unsigned int)nread ));
385 return ret;
388 /****************************************************************************
389 Complete the write and return the data or error back to the client.
390 Returns errno or zero if all ok.
391 *****************************************************************************/
393 static int handle_aio_write_complete(struct aio_extra *aio_ex)
395 int ret = 0;
396 files_struct *fsp = aio_ex->fsp;
397 char *outbuf = aio_ex->outbuf;
398 ssize_t numtowrite = aio_ex->acb.aio_nbytes;
399 ssize_t nwritten = SMB_VFS_AIO_RETURN(fsp,&aio_ex->acb);
401 if (fsp->aio_write_behind) {
402 if (nwritten != numtowrite) {
403 if (nwritten == -1) {
404 DEBUG(5,("handle_aio_write_complete: "
405 "aio_write_behind failed ! File %s "
406 "is corrupt ! Error %s\n",
407 fsp->fsp_name, strerror(errno) ));
408 ret = errno;
409 } else {
410 DEBUG(0,("handle_aio_write_complete: "
411 "aio_write_behind failed ! File %s "
412 "is corrupt ! Wanted %u bytes but "
413 "only wrote %d\n", fsp->fsp_name,
414 (unsigned int)numtowrite,
415 (int)nwritten ));
416 ret = EIO;
418 } else {
419 DEBUG(10,("handle_aio_write_complete: "
420 "aio_write_behind completed for file %s\n",
421 fsp->fsp_name ));
423 return 0;
426 /* We don't need outsize or set_message here as we've already set the
427 fixed size length when we set up the aio call. */
429 if(nwritten == -1) {
430 DEBUG( 3,( "handle_aio_write: file %s wanted %u bytes. "
431 "nwritten == %d. Error = %s\n",
432 fsp->fsp_name, (unsigned int)numtowrite,
433 (int)nwritten, strerror(errno) ));
435 /* If errno is ECANCELED then don't return anything to the
436 * client. */
437 if (errno == ECANCELED) {
438 srv_cancel_sign_response(aio_ex->req->mid, false);
439 return 0;
442 ret = errno;
443 ERROR_BOTH(map_nt_error_from_unix(ret), ERRHRD, ERRdiskfull);
444 srv_set_message(outbuf,0,0,true);
445 } else {
446 bool write_through = BITSETW(aio_ex->req->vwv+7,0);
447 NTSTATUS status;
449 SSVAL(outbuf,smb_vwv2,nwritten);
450 SSVAL(outbuf,smb_vwv4,(nwritten>>16)&1);
451 if (nwritten < (ssize_t)numtowrite) {
452 SCVAL(outbuf,smb_rcls,ERRHRD);
453 SSVAL(outbuf,smb_err,ERRdiskfull);
456 DEBUG(3,("handle_aio_write: fnum=%d num=%d wrote=%d\n",
457 fsp->fnum, (int)numtowrite, (int)nwritten));
458 status = sync_file(fsp->conn,fsp, write_through);
459 if (!NT_STATUS_IS_OK(status)) {
460 ret = errno;
461 ERROR_BOTH(map_nt_error_from_unix(ret),
462 ERRHRD, ERRdiskfull);
463 srv_set_message(outbuf,0,0,true);
464 DEBUG(5,("handle_aio_write: sync_file for %s returned %s\n",
465 fsp->fsp_name, nt_errstr(status) ));
468 aio_ex->fsp->fh->pos = aio_ex->acb.aio_offset + nwritten;
471 show_msg(outbuf);
472 if (!srv_send_smb(smbd_server_fd(),outbuf,IS_CONN_ENCRYPTED(fsp->conn),
473 NULL)) {
474 exit_server_cleanly("handle_aio_write: srv_send_smb failed.");
477 DEBUG(10,("handle_aio_write_complete: scheduled aio_write completed "
478 "for file %s, offset %.0f, requested %u, written = %u\n",
479 fsp->fsp_name, (double)aio_ex->acb.aio_offset,
480 (unsigned int)numtowrite, (unsigned int)nwritten ));
482 return ret;
485 /****************************************************************************
486 Handle any aio completion. Returns True if finished (and sets *perr if err
487 was non-zero), False if not.
488 *****************************************************************************/
490 static bool handle_aio_completed(struct aio_extra *aio_ex, int *perr)
492 int err;
494 if(!aio_ex) {
495 DEBUG(3, ("handle_aio_completed: Non-existing aio_ex passed\n"));
496 return false;
499 /* Ensure the operation has really completed. */
500 if (SMB_VFS_AIO_ERROR(aio_ex->fsp, &aio_ex->acb) == EINPROGRESS) {
501 DEBUG(10,( "handle_aio_completed: operation mid %u still in "
502 "process for file %s\n",
503 aio_ex->req->mid, aio_ex->fsp->fsp_name ));
504 return False;
507 err = aio_ex->handle_completion(aio_ex);
508 if (err) {
509 *perr = err; /* Only save non-zero errors. */
512 return True;
515 /****************************************************************************
516 Handle any aio completion inline.
517 Returns non-zero errno if fail or zero if all ok.
518 *****************************************************************************/
520 void smbd_aio_complete_mid(unsigned int mid)
522 files_struct *fsp = NULL;
523 struct aio_extra *aio_ex = find_aio_ex(mid);
524 int ret = 0;
526 DEBUG(10,("smbd_aio_complete_mid: mid[%u]\n", mid));
528 if (!aio_ex) {
529 DEBUG(3,("smbd_aio_complete_mid: Can't find record to "
530 "match mid %u.\n", mid));
531 srv_cancel_sign_response(mid, false);
532 return;
535 fsp = aio_ex->fsp;
536 if (fsp == NULL) {
537 /* file was closed whilst I/O was outstanding. Just
538 * ignore. */
539 DEBUG( 3,( "smbd_aio_complete_mid: file closed whilst "
540 "aio outstanding (mid[%u]).\n", mid));
541 srv_cancel_sign_response(mid, false);
542 return;
545 if (!handle_aio_completed(aio_ex, &ret)) {
546 return;
549 TALLOC_FREE(aio_ex);
552 static void smbd_aio_signal_handler(struct tevent_context *ev_ctx,
553 struct tevent_signal *se,
554 int signum, int count,
555 void *_info, void *private_data)
557 siginfo_t *info = (siginfo_t *)_info;
558 unsigned int mid = (unsigned int)info->si_value.sival_int;
560 smbd_aio_complete_mid(mid);
563 /****************************************************************************
564 We're doing write behind and the client closed the file. Wait up to 30
565 seconds (my arbitrary choice) for the aio to complete. Return 0 if all writes
566 completed, errno to return if not.
567 *****************************************************************************/
569 #define SMB_TIME_FOR_AIO_COMPLETE_WAIT 29
571 int wait_for_aio_completion(files_struct *fsp)
573 struct aio_extra *aio_ex;
574 const SMB_STRUCT_AIOCB **aiocb_list;
575 int aio_completion_count = 0;
576 time_t start_time = time(NULL);
577 int seconds_left;
579 for (seconds_left = SMB_TIME_FOR_AIO_COMPLETE_WAIT;
580 seconds_left >= 0;) {
581 int err = 0;
582 int i;
583 struct timespec ts;
585 aio_completion_count = 0;
586 for( aio_ex = aio_list_head; aio_ex; aio_ex = aio_ex->next) {
587 if (aio_ex->fsp == fsp) {
588 aio_completion_count++;
592 if (!aio_completion_count) {
593 return 0;
596 DEBUG(3,("wait_for_aio_completion: waiting for %d aio events "
597 "to complete.\n", aio_completion_count ));
599 aiocb_list = SMB_MALLOC_ARRAY(const SMB_STRUCT_AIOCB *,
600 aio_completion_count);
601 if (!aiocb_list) {
602 return ENOMEM;
605 for( i = 0, aio_ex = aio_list_head;
606 aio_ex;
607 aio_ex = aio_ex->next) {
608 if (aio_ex->fsp == fsp) {
609 aiocb_list[i++] = &aio_ex->acb;
613 /* Now wait up to seconds_left for completion. */
614 ts.tv_sec = seconds_left;
615 ts.tv_nsec = 0;
617 DEBUG(10,("wait_for_aio_completion: %d events, doing a wait "
618 "of %d seconds.\n",
619 aio_completion_count, seconds_left ));
621 err = SMB_VFS_AIO_SUSPEND(fsp, aiocb_list,
622 aio_completion_count, &ts);
624 DEBUG(10,("wait_for_aio_completion: returned err = %d, "
625 "errno = %s\n", err, strerror(errno) ));
627 if (err == -1 && errno == EAGAIN) {
628 DEBUG(0,("wait_for_aio_completion: aio_suspend timed "
629 "out waiting for %d events after a wait of "
630 "%d seconds\n", aio_completion_count,
631 seconds_left));
632 /* Timeout. */
633 cancel_aio_by_fsp(fsp);
634 SAFE_FREE(aiocb_list);
635 return EIO;
638 /* One or more events might have completed - process them if
639 * so. */
640 for( i = 0; i < aio_completion_count; i++) {
641 uint16 mid = aiocb_list[i]->aio_sigevent.sigev_value.sival_int;
643 aio_ex = find_aio_ex(mid);
645 if (!aio_ex) {
646 DEBUG(0, ("wait_for_aio_completion: mid %u "
647 "doesn't match an aio record\n",
648 (unsigned int)mid ));
649 continue;
652 if (!handle_aio_completed(aio_ex, &err)) {
653 continue;
655 TALLOC_FREE(aio_ex);
658 SAFE_FREE(aiocb_list);
659 seconds_left = SMB_TIME_FOR_AIO_COMPLETE_WAIT
660 - (time(NULL) - start_time);
663 /* We timed out - we don't know why. Return ret if already an error,
664 * else EIO. */
665 DEBUG(10,("wait_for_aio_completion: aio_suspend timed out waiting "
666 "for %d events\n",
667 aio_completion_count));
669 return EIO;
672 /****************************************************************************
673 Cancel any outstanding aio requests. The client doesn't care about the reply.
674 *****************************************************************************/
676 void cancel_aio_by_fsp(files_struct *fsp)
678 struct aio_extra *aio_ex;
680 for( aio_ex = aio_list_head; aio_ex; aio_ex = aio_ex->next) {
681 if (aio_ex->fsp == fsp) {
682 /* Don't delete the aio_extra record as we may have
683 completed and don't yet know it. Just do the
684 aio_cancel call and return. */
685 SMB_VFS_AIO_CANCEL(fsp, &aio_ex->acb);
686 aio_ex->fsp = NULL; /* fsp will be closed when we
687 * return. */
692 /****************************************************************************
693 Initialize the signal handler for aio read/write.
694 *****************************************************************************/
696 void initialize_async_io_handler(void)
698 aio_signal_event = tevent_add_signal(smbd_event_context(),
699 smbd_event_context(),
700 RT_SIGNAL_AIO, SA_SIGINFO,
701 smbd_aio_signal_handler,
702 NULL);
703 if (!aio_signal_event) {
704 exit_server("Failed to setup RT_SIGNAL_AIO handler");
707 /* tevent supports 100 signal with SA_SIGINFO */
708 aio_pending_size = 100;
711 #else
712 void initialize_async_io_handler(void)
716 bool schedule_aio_read_and_X(connection_struct *conn,
717 struct smb_request *req,
718 files_struct *fsp, SMB_OFF_T startpos,
719 size_t smb_maxcnt)
721 return False;
724 bool schedule_aio_write_and_X(connection_struct *conn,
725 struct smb_request *req,
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 int wait_for_aio_completion(files_struct *fsp)
739 return ENOSYS;
742 void smbd_aio_complete_mid(unsigned int mid);
744 #endif