s3:vfs_default: optimize vfswrap_asys_finished() and read as much as we can
authorStefan Metzmacher <metze@samba.org>
Fri, 2 Nov 2012 11:52:51 +0000 (12:52 +0100)
committerVolker Lendecke <vl@samba.org>
Mon, 5 Nov 2012 18:01:13 +0000 (19:01 +0100)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Mon Nov  5 19:01:13 CET 2012 on sn-devel-104

source3/modules/vfs_default.c

index 8e980e0cbc6eb8840d39ecd10cabe85630811555..0f651dca51119879c184cc5485455f472b1fa271 100644 (file)
@@ -637,6 +637,7 @@ static void vfswrap_asys_finished(struct tevent_context *ev,
 static bool vfswrap_init_asys_ctx(struct smbXsrv_connection *conn)
 {
        int ret;
+       int fd;
 
        if (conn->asys_ctx != NULL) {
                return true;
@@ -646,8 +647,12 @@ static bool vfswrap_init_asys_ctx(struct smbXsrv_connection *conn)
                DEBUG(1, ("asys_context_init failed: %s\n", strerror(ret)));
                return false;
        }
-       conn->asys_fde = tevent_add_fd(conn->ev_ctx, conn,
-                                      asys_signalfd(conn->asys_ctx),
+
+       fd = asys_signalfd(conn->asys_ctx);
+
+       set_blocking(fd, false);
+
+       conn->asys_fde = tevent_add_fd(conn->ev_ctx, conn, fd,
                                       TEVENT_FD_READ,
                                       vfswrap_asys_finished,
                                       conn->asys_ctx);
@@ -783,24 +788,36 @@ static void vfswrap_asys_finished(struct tevent_context *ev,
                return;
        }
 
-       res = asys_result(asys_ctx, &ret, &err, &private_data);
-       if (res == ECANCELED) {
-               return;
-       }
+       while (true) {
+               res = asys_result(asys_ctx, &ret, &err, &private_data);
+               if (res == EINTR || res == EAGAIN) {
+                       return;
+               }
+#ifdef EWOULDBLOCK
+               if (res == EWOULDBLOCK) {
+                       return;
+               }
+#endif
 
-       if (res != 0) {
-               DEBUG(1, ("asys_result returned %s\n", strerror(res)));
-               return;
-       }
+               if (res == ECANCELED) {
+                       return;
+               }
 
-       req = talloc_get_type_abort(private_data, struct tevent_req);
-       state = tevent_req_data(req, struct vfswrap_asys_state);
+               if (res != 0) {
+                       DEBUG(1, ("asys_result returned %s\n", strerror(res)));
+                       return;
+               }
+
+               req = talloc_get_type_abort(private_data, struct tevent_req);
+               state = tevent_req_data(req, struct vfswrap_asys_state);
 
-       talloc_set_destructor(state, NULL);
+               talloc_set_destructor(state, NULL);
 
-       state->ret = ret;
-       state->err = err;
-       tevent_req_done(req);
+               state->ret = ret;
+               state->err = err;
+               tevent_req_defer_callback(req, ev);
+               tevent_req_done(req);
+       }
 }
 
 static ssize_t vfswrap_asys_ssize_t_recv(struct tevent_req *req, int *err)