Make rmdir async.
authorJeremy Allison <jra@samba.org>
Tue, 21 Apr 2009 13:52:54 +0000 (06:52 -0700)
committerJeremy Allison <jra@samba.org>
Tue, 21 Apr 2009 13:52:54 +0000 (06:52 -0700)
Jeremy.

source3/client/client.c
source3/include/proto.h
source3/libsmb/clifile.c
source3/libsmb/libsmb_dir.c
source3/torture/mangle_test.c
source3/torture/nbio.c
source3/torture/torture.c

index d74de35bc5ad80315a33e7b8034e2ca3971288dd..54ff755ed32b5eb054c560a7e18f20db7a65ef2b 100644 (file)
@@ -2675,7 +2675,7 @@ static int cmd_rmdir(void)
                return 1;
        }
 
-       if (!cli_rmdir(targetcli, targetname)) {
+       if (!NT_STATUS_IS_OK(cli_rmdir(targetcli, targetname))) {
                d_printf("%s removing remote directory file %s\n",
                         cli_errstr(targetcli),mask);
        }
index 3ddbf6f3b9d2722cb758e09b869f2fe2ca9590fc..3a706e4725e75647c842e81050af13b09c1743bc 100644 (file)
@@ -2339,7 +2339,7 @@ bool cli_nt_hardlink(struct cli_state *cli, const char *fname_src, const char *f
 bool cli_unlink_full(struct cli_state *cli, const char *fname, uint16 attrs);
 bool cli_unlink(struct cli_state *cli, const char *fname);
 NTSTATUS cli_mkdir(struct cli_state *cli, const char *dname);
-bool cli_rmdir(struct cli_state *cli, const char *dname);
+NTSTATUS cli_rmdir(struct cli_state *cli, const char *dname);
 int cli_nt_delete_on_close(struct cli_state *cli, int fnum, bool flag);
 int cli_nt_create_full(struct cli_state *cli, const char *fname,
                 uint32 CreatFlags, uint32 DesiredAccess,
index 5be18366b9d5464921ed207d64ef2740f3211cd4..f5d5ad0fdae3d17f789a1dde3cfafd9857a9055a 100644 (file)
@@ -596,44 +596,6 @@ bool cli_unlink(struct cli_state *cli, const char *fname)
        return cli_unlink_full(cli, fname, aSYSTEM | aHIDDEN);
 }
 
-#if 0
-/****************************************************************************
- Create a directory.
-****************************************************************************/
-
-bool cli_mkdir(struct cli_state *cli, const char *dname)
-{
-       char *p;
-
-       memset(cli->outbuf,'\0',smb_size);
-       memset(cli->inbuf,'\0',smb_size);
-
-       cli_set_message(cli->outbuf,0, 0, true);
-
-       SCVAL(cli->outbuf,smb_com,SMBmkdir);
-       SSVAL(cli->outbuf,smb_tid,cli->cnum);
-       cli_setup_packet(cli);
-
-       p = smb_buf(cli->outbuf);
-       *p++ = 4;
-       p += clistr_push(cli, p, dname,
-                       cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE);
-
-       cli_setup_bcc(cli, p);
-
-       cli_send_smb(cli);
-       if (!cli_receive_smb(cli)) {
-               return False;
-       }
-
-       if (cli_is_error(cli)) {
-               return False;
-       }
-
-       return True;
-}
-#endif
-
 /****************************************************************************
  Create a directory.
 ****************************************************************************/
@@ -746,36 +708,108 @@ NTSTATUS cli_mkdir(struct cli_state *cli, const char *dname)
  Remove a directory.
 ****************************************************************************/
 
-bool cli_rmdir(struct cli_state *cli, const char *dname)
+static void cli_rmdir_done(struct tevent_req *subreq);
+
+struct cli_rmdir_state {
+       int dummy;
+};
+
+struct tevent_req *cli_rmdir_send(TALLOC_CTX *mem_ctx,
+                                 struct event_context *ev,
+                                 struct cli_state *cli,
+                                 const char *dname)
 {
-       char *p;
+       struct tevent_req *req = NULL, *subreq = NULL;
+       struct cli_rmdir_state *state = NULL;
+       uint8_t additional_flags = 0;
+       uint8_t *bytes = NULL;
 
-       memset(cli->outbuf,'\0',smb_size);
-       memset(cli->inbuf,'\0',smb_size);
+       req = tevent_req_create(mem_ctx, &state, struct cli_rmdir_state);
+       if (req == NULL) {
+               return NULL;
+       }
 
-       cli_set_message(cli->outbuf,0, 0, true);
+       bytes = talloc_array(state, uint8_t, 1);
+       if (!bytes) {
+               return NULL;
+       }
+       bytes[0] = 4;
+       bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), dname,
+                                  strlen(dname)+1, NULL);
 
-       SCVAL(cli->outbuf,smb_com,SMBrmdir);
-       SSVAL(cli->outbuf,smb_tid,cli->cnum);
-       cli_setup_packet(cli);
+       if (tevent_req_nomem(bytes, req)) {
+               return tevent_req_post(req, ev);
+       }
 
-       p = smb_buf(cli->outbuf);
-       *p++ = 4;
-       p += clistr_push(cli, p, dname,
-                       cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE);
+       subreq = cli_smb_send(state, ev, cli, SMBrmdir, additional_flags,
+                                   0, NULL, talloc_get_size(bytes), bytes);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, cli_rmdir_done, req);
+       return req;
+}
 
-       cli_setup_bcc(cli, p);
+static void cli_rmdir_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       NTSTATUS status;
 
-       cli_send_smb(cli);
-       if (!cli_receive_smb(cli)) {
-               return false;
+       status = cli_smb_recv(subreq, 0, NULL, NULL, NULL, NULL);
+       TALLOC_FREE(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return;
        }
+       tevent_req_done(req);
+}
 
-       if (cli_is_error(cli)) {
-               return false;
+NTSTATUS cli_rmdir_recv(struct tevent_req *req)
+{
+       return tevent_req_simple_recv_ntstatus(req);
+}
+
+NTSTATUS cli_rmdir(struct cli_state *cli, const char *dname)
+{
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct event_context *ev;
+       struct tevent_req *req;
+       NTSTATUS status = NT_STATUS_OK;
+
+       if (cli_has_async_calls(cli)) {
+               /*
+                * Can't use sync call while an async call is in flight
+                */
+               status = NT_STATUS_INVALID_PARAMETER;
+               goto fail;
        }
 
-       return true;
+       ev = event_context_init(frame);
+       if (ev == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto fail;
+       }
+
+       req = cli_rmdir_send(frame, ev, cli, dname);
+       if (req == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto fail;
+       }
+
+       if (!tevent_req_poll(req, ev)) {
+               status = map_nt_error_from_unix(errno);
+               goto fail;
+       }
+
+       status = cli_rmdir_recv(req);
+
+ fail:
+       TALLOC_FREE(frame);
+       if (!NT_STATUS_IS_OK(status)) {
+               cli_set_error(cli, status);
+       }
+       return status;
 }
 
 /****************************************************************************
index 5afc8e48b6249703496b84a53bea4b3c58bcab19..508810538f8a67d2021682c2fa17921ccde8864a 100644 (file)
@@ -1284,8 +1284,7 @@ SMBC_rmdir_ctx(SMBCCTX *context,
        }
        /*d_printf(">>>rmdir: resolved path as %s\n", targetpath);*/
 
-
-       if (!cli_rmdir(targetcli, targetpath)) {
+       if (!NT_STATUS_IS_OK(cli_rmdir(targetcli, targetpath))) {
 
                errno = SMBC_errno(context, targetcli);
 
index 525a1eb3c379074e108b8c8fb786a73df2a3ce40..81bdbce04d39ca606322f439e5253c687be22bac 100644 (file)
@@ -202,7 +202,7 @@ bool torture_mangle(int dummy)
        }
 
        cli_unlink(cli, "\\mangle_test\\*");
-       if (!cli_rmdir(cli, "\\mangle_test")) {
+       if (!NT_STATUS_IS_OK(cli_rmdir(cli, "\\mangle_test"))) {
                printf("ERROR: Failed to remove directory\n");
                return False;
        }
index a010c80985e6d9ec3abe839c29a4c15a1242f135..998adac4e0a4b27e23fbad01d88aa2d2822340be 100644 (file)
@@ -220,7 +220,7 @@ void nb_close(int handle)
 
 void nb_rmdir(const char *fname)
 {
-       if (!cli_rmdir(c, fname)) {
+       if (!NT_STATUS_IS_OK(cli_rmdir(c, fname))) {
                printf("ERROR: rmdir %s failed (%s)\n", 
                       fname, cli_errstr(c));
                exit(1);
index 0328cfe545ac90d8d3901fda540b5bf7ea868ead..7e2b3a56e5f40d086968170f7ed5685ec5c4f1de 100644 (file)
@@ -4500,7 +4500,7 @@ static void del_fn(const char *mnt, file_info *finfo, const char *mask, void *st
                return;
 
        if (finfo->mode & aDIR) {
-               if (!cli_rmdir(pcli, fname))
+               if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
                        printf("del_fn: failed to rmdir %s\n,", fname );
        } else {
                if (!cli_unlink(pcli, fname))