s3: Convert cli_get_fs_attr_info to the async API
authorVolker Lendecke <vl@samba.org>
Sat, 21 Nov 2009 12:46:52 +0000 (13:46 +0100)
committerVolker Lendecke <vl@samba.org>
Sat, 21 Nov 2009 13:01:56 +0000 (14:01 +0100)
source3/include/proto.h
source3/libsmb/clifsinfo.c
source3/libsmb/libsmb_server.c
source3/libsmb/libsmb_stat.c
source3/torture/torture.c
source3/utils/smbcquotas.c

index feeac59..92cb997 100644 (file)
@@ -2704,7 +2704,11 @@ NTSTATUS cli_set_unix_extensions_capabilities_recv(struct tevent_req *req);
 NTSTATUS cli_set_unix_extensions_capabilities(struct cli_state *cli,
                                              uint16 major, uint16 minor,
                                              uint32 caplow, uint32 caphigh);
-bool cli_get_fs_attr_info(struct cli_state *cli, uint32 *fs_attr);
+struct tevent_req *cli_get_fs_attr_info_send(TALLOC_CTX *mem_ctx,
+                                            struct tevent_context *ev,
+                                            struct cli_state *cli);
+NTSTATUS cli_get_fs_attr_info_recv(struct tevent_req *req, uint32_t *fs_attr);
+NTSTATUS cli_get_fs_attr_info(struct cli_state *cli, uint32_t *fs_attr);
 bool cli_get_fs_volume_info_old(struct cli_state *cli, fstring volume_name, uint32 *pserial_number);
 bool cli_get_fs_volume_info(struct cli_state *cli, fstring volume_name, uint32 *pserial_number, time_t *pdate);
 bool cli_get_fs_full_size_info(struct cli_state *cli,
index 3e9740d..ec690b4 100644 (file)
@@ -248,58 +248,103 @@ fail:
        return status;
 }
 
-bool cli_get_fs_attr_info(struct cli_state *cli, uint32 *fs_attr)
-{
-       bool ret = False;
-       uint16 setup;
-       char param[2];
-       char *rparam=NULL, *rdata=NULL;
-       unsigned int rparam_count=0, rdata_count=0;
-
-       if (!cli||!fs_attr)
-               smb_panic("cli_get_fs_attr_info() called with NULL Pionter!");
+struct cli_get_fs_attr_info_state {
+       uint16_t setup[1];
+       uint8_t param[2];
+       uint32_t fs_attr;
+};
 
-       setup = TRANSACT2_QFSINFO;
+static void cli_get_fs_attr_info_done(struct tevent_req *subreq);
 
-       SSVAL(param,0,SMB_QUERY_FS_ATTRIBUTE_INFO);
+struct tevent_req *cli_get_fs_attr_info_send(TALLOC_CTX *mem_ctx,
+                                            struct tevent_context *ev,
+                                            struct cli_state *cli)
+{
+       struct tevent_req *subreq, *req;
+       struct cli_get_fs_attr_info_state *state;
 
-       if (!cli_send_trans(cli, SMBtrans2,
-                   NULL,
-                   0, 0,
-                   &setup, 1, 0,
-                   param, 2, 0,
-                   NULL, 0, 560)) {
-               goto cleanup;
+       req = tevent_req_create(mem_ctx, &state,
+                               struct cli_get_fs_attr_info_state);
+       if (req == NULL) {
+               return NULL;
        }
+       SSVAL(state->setup+0, 0, TRANSACT2_QFSINFO);
+       SSVAL(state->param+0, 0, SMB_QUERY_FS_ATTRIBUTE_INFO);
 
-       if (!cli_receive_trans(cli, SMBtrans2,
-                              &rparam, &rparam_count,
-                              &rdata, &rdata_count)) {
-               goto cleanup;
+       subreq = cli_trans_send(state, ev, cli, SMBtrans2,
+                               NULL, 0, 0, 0,
+                               state->setup, 1, 0,
+                               state->param, 2, 0,
+                               NULL, 0, 560);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
        }
+       tevent_req_set_callback(subreq, cli_get_fs_attr_info_done, req);
+       return req;
+}
 
-       if (cli_is_error(cli)) {
-               ret = False;
-               goto cleanup;
-       } else {
-               ret = True;
-       }
+static void cli_get_fs_attr_info_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct cli_get_fs_attr_info_state *state = tevent_req_data(
+               req, struct cli_get_fs_attr_info_state);
+       uint8_t *data;
+       uint32_t num_data;
+       NTSTATUS status;
 
-       if (rdata_count < 12) {
-               goto cleanup;
+       status = cli_trans_recv(subreq, talloc_tos(), NULL, 0, NULL,
+                               NULL, 0, NULL, &data, 12, &num_data);
+       TALLOC_FREE(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return;
        }
+       state->fs_attr = IVAL(data, 0);
+       TALLOC_FREE(data);
+       tevent_req_done(req);
+}
 
-       *fs_attr = IVAL(rdata,0);
+NTSTATUS cli_get_fs_attr_info_recv(struct tevent_req *req, uint32_t *fs_attr)
+{
+       struct cli_get_fs_attr_info_state *state = tevent_req_data(
+               req, struct cli_get_fs_attr_info_state);
+       NTSTATUS status;
 
-       /* todo: but not yet needed
-        *       return the other stuff
-        */
+       if (tevent_req_is_nterror(req, &status)) {
+               return status;
+       }
+       *fs_attr = state->fs_attr;
+       return NT_STATUS_OK;
+}
 
-cleanup:
-       SAFE_FREE(rparam);
-       SAFE_FREE(rdata);
+NTSTATUS cli_get_fs_attr_info(struct cli_state *cli, uint32_t *fs_attr)
+{
+       struct tevent_context *ev;
+       struct tevent_req *req;
+       NTSTATUS status = NT_STATUS_NO_MEMORY;
 
-       return ret;
+       if (cli_has_async_calls(cli)) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+       ev = tevent_context_init(talloc_tos());
+       if (ev == NULL) {
+               goto fail;
+       }
+       req = cli_get_fs_attr_info_send(ev, ev, cli);
+       if (req == NULL) {
+               goto fail;
+       }
+       if (!tevent_req_poll_ntstatus(req, ev, &status)) {
+               goto fail;
+       }
+       status = cli_get_fs_attr_info_recv(req, fs_attr);
+fail:
+       TALLOC_FREE(ev);
+       if (!NT_STATUS_IS_OK(status)) {
+               cli_set_error(cli, status);
+       }
+       return status;
 }
 
 bool cli_get_fs_volume_info_old(struct cli_state *cli, fstring volume_name, uint32 *pserial_number)
index a572acd..71cb67c 100644 (file)
@@ -330,7 +330,7 @@ SMBC_server_internal(TALLOC_CTX *ctx,
                         if (is_ipc) {
                                 DEBUG(4,
                                       ("IPC$ so ignore case sensitivity\n"));
-                        } else if (!cli_get_fs_attr_info(c, &fs_attrs)) {
+                        } else if (!NT_STATUS_IS_OK(cli_get_fs_attr_info(c, &fs_attrs))) {
                                 DEBUG(4, ("Could not retrieve "
                                           "case sensitivity flag: %s.\n",
                                           cli_errstr(c)));
@@ -563,7 +563,7 @@ again:
         /* Determine if this share supports case sensitivity */
        if (is_ipc) {
                 DEBUG(4, ("IPC$ so ignore case sensitivity\n"));
-        } else if (!cli_get_fs_attr_info(c, &fs_attrs)) {
+        } else if (!NT_STATUS_IS_OK(cli_get_fs_attr_info(c, &fs_attrs))) {
                 DEBUG(4, ("Could not retrieve case sensitivity flag: %s.\n",
                           cli_errstr(c)));
 
index 4349b0a..95c5c52 100644 (file)
@@ -454,7 +454,7 @@ SMBC_fstatvfs_ctx(SMBCCTX *context,
         }
 
         /* See if the share is case sensitive */
-        if (!cli_get_fs_attr_info(cli, &fs_attrs)) {
+        if (!NT_STATUS_IS_OK(cli_get_fs_attr_info(cli, &fs_attrs))) {
                 /*
                  * We can't determine the case sensitivity of
                  * the share. We have no choice but to use the
index 840dc94..bf89ca3 100644 (file)
@@ -2827,6 +2827,8 @@ static bool run_trans2test(int dummy)
        const char *fname2 = "\\trans2\\trans2.tst";
        char pname[1024];
        bool correct = True;
+       NTSTATUS status;
+       uint32_t fs_attr;
 
        printf("starting trans2 test\n");
 
@@ -2834,6 +2836,13 @@ static bool run_trans2test(int dummy)
                return False;
        }
 
+       status = cli_get_fs_attr_info(cli, &fs_attr);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ERROR: cli_get_fs_attr_info returned %s\n",
+                      nt_errstr(status));
+               correct = false;
+       }
+
        cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
        cli_open(cli, fname, 
                        O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
index a0eed65..ef67ad7 100644 (file)
@@ -235,7 +235,7 @@ static int do_quota(struct cli_state *cli,
        SMB_NTQUOTA_STRUCT qt;
        ZERO_STRUCT(qt);
 
-       if (!cli_get_fs_attr_info(cli, &fs_attrs)) {
+       if (!NT_STATUS_IS_OK(cli_get_fs_attr_info(cli, &fs_attrs))) {
                d_printf("Failed to get the filesystem attributes %s.\n",
                        cli_errstr(cli));
                return -1;