Move initialize_async_io_handler() inside of smbd/aio.c.
authorJeremy Allison <jra@samba.org>
Thu, 1 Apr 2010 23:47:59 +0000 (16:47 -0700)
committerJeremy Allison <jra@samba.org>
Thu, 1 Apr 2010 23:47:59 +0000 (16:47 -0700)
Call from actual aio read or write. No reason to call this globally on startup.

Jeremy.

source3/include/proto.h
source3/smbd/aio.c
source3/smbd/process.c

index 2ebc75ce12360b21c8f1d4d61b4e01c67521fcd5..c9fe61014a867846105890a72f5cf7ec71c6808c 100644 (file)
@@ -6047,7 +6047,6 @@ struct regval_ctr *svcctl_fetch_regvalues( const char *name, NT_USER_TOKEN *toke
 
 /* The following definitions come from smbd/aio.c  */
 
-void initialize_async_io_handler(void);
 bool schedule_aio_read_and_X(connection_struct *conn,
                             struct smb_request *req,
                             files_struct *fsp, SMB_OFF_T startpos,
index 751fed168f2967cd246d60f14c045338a5b77430..a04f3d55d7621fe35584617cf46d7a8b98297cb9 100644 (file)
 #endif
 #endif
 
+/****************************************************************************
+ Initialize the signal handler for aio read/write.
+*****************************************************************************/
+
+static void smbd_aio_signal_handler(struct tevent_context *ev_ctx,
+                                   struct tevent_signal *se,
+                                   int signum, int count,
+                                   void *_info, void *private_data)
+{
+       siginfo_t *info = (siginfo_t *)_info;
+       unsigned int mid = (unsigned int)info->si_value.sival_int;
+
+       smbd_aio_complete_mid(mid);
+}
+
+
+static void initialize_async_io_handler(void)
+{
+       if (aio_signal_event) {
+               return;
+       }
+
+       aio_signal_event = tevent_add_signal(smbd_event_context(),
+                                            smbd_event_context(),
+                                            RT_SIGNAL_AIO, SA_SIGINFO,
+                                            smbd_aio_signal_handler,
+                                            NULL);
+       if (!aio_signal_event) {
+               exit_server("Failed to setup RT_SIGNAL_AIO handler");
+       }
+
+       /* tevent supports 100 signal with SA_SIGINFO */
+       aio_pending_size = 100;
+}
+
+
 /****************************************************************************
  The buffer we keep around whilst an aio request is in process.
 *****************************************************************************/
@@ -154,6 +190,9 @@ bool schedule_aio_read_and_X(connection_struct *conn,
 
        bufsize = smb_size + 12 * 2 + smb_maxcnt;
 
+       /* Ensure aio is initialized. */
+       initialize_async_io_handler();
+
        if ((aio_ex = create_aio_extra(fsp, bufsize)) == NULL) {
                DEBUG(10,("schedule_aio_read_and_X: malloc fail.\n"));
                return False;
@@ -247,6 +286,9 @@ bool schedule_aio_write_and_X(connection_struct *conn,
                return False;
        }
 
+       /* Ensure aio is initialized. */
+       initialize_async_io_handler();
+
        bufsize = smb_size + 6*2;
 
        if (!(aio_ex = create_aio_extra(fsp, bufsize))) {
@@ -535,17 +577,6 @@ void smbd_aio_complete_mid(unsigned int mid)
        TALLOC_FREE(aio_ex);
 }
 
-static void smbd_aio_signal_handler(struct tevent_context *ev_ctx,
-                                   struct tevent_signal *se,
-                                   int signum, int count,
-                                   void *_info, void *private_data)
-{
-       siginfo_t *info = (siginfo_t *)_info;
-       unsigned int mid = (unsigned int)info->si_value.sival_int;
-
-       smbd_aio_complete_mid(mid);
-}
-
 /****************************************************************************
  We're doing write behind and the client closed the file. Wait up to 30
  seconds (my arbitrary choice) for the aio to complete. Return 0 if all writes
@@ -675,30 +706,7 @@ void cancel_aio_by_fsp(files_struct *fsp)
        }
 }
 
-/****************************************************************************
- Initialize the signal handler for aio read/write.
-*****************************************************************************/
-
-void initialize_async_io_handler(void)
-{
-       aio_signal_event = tevent_add_signal(smbd_event_context(),
-                                            smbd_event_context(),
-                                            RT_SIGNAL_AIO, SA_SIGINFO,
-                                            smbd_aio_signal_handler,
-                                            NULL);
-       if (!aio_signal_event) {
-               exit_server("Failed to setup RT_SIGNAL_AIO handler");
-       }
-
-       /* tevent supports 100 signal with SA_SIGINFO */
-       aio_pending_size = 100;
-}
-
 #else
-void initialize_async_io_handler(void)
-{
-}
-
 bool schedule_aio_read_and_X(connection_struct *conn,
                             struct smb_request *req,
                             files_struct *fsp, SMB_OFF_T startpos,
index 40c85d4a621cd9e8d5eece7cf12232e20127d15e..485439a089648f76bccda6b43d3a0dcb439b6176 100644 (file)
@@ -2852,9 +2852,6 @@ void smbd_process(void)
        if (!init_oplocks(smbd_messaging_context()))
                exit_server("Failed to init oplocks");
 
-       /* Setup aio signal handler. */
-       initialize_async_io_handler();
-
        /* register our message handlers */
        messaging_register(smbd_messaging_context(), NULL,
                           MSG_SMB_FORCE_TDIS, msg_force_tdis);