From: Jeremy Allison Date: Wed, 22 Apr 2009 15:04:53 +0000 (-0700) Subject: Make dskattr async. X-Git-Url: http://git.samba.org/samba.git/?p=jra%2Fsamba%2F.git;a=commitdiff_plain;h=455f2a4c65b679a996a8d6e7548dc2f4a6f28fae Make dskattr async. Jeremy. --- diff --git a/source3/client/client.c b/source3/client/client.c index 151f7460fcc..68d96a9dcc8 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -307,7 +307,7 @@ static int do_dskattr(void) return 1; } - if (!cli_dskattr(targetcli, &bsize, &total, &avail)) { + if (!NT_STATUS_IS_OK(cli_dskattr(targetcli, &bsize, &total, &avail))) { d_printf("Error in dskattr: %s\n",cli_errstr(targetcli)); return 1; } diff --git a/source3/include/proto.h b/source3/include/proto.h index 1435f4f4051..518c3a7e931 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -2417,7 +2417,7 @@ bool cli_setattrE(struct cli_state *cli, int fd, time_t write_time); bool cli_setatr(struct cli_state *cli, const char *fname, uint16 attr, time_t t); NTSTATUS cli_chkpath(struct cli_state *cli, const char *path); -bool cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail); +NTSTATUS cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail); int cli_ctemp(struct cli_state *cli, const char *path, char **tmp_path); NTSTATUS cli_raw_ioctl(struct cli_state *cli, int fnum, uint32 code, DATA_BLOB *blob); bool cli_set_ea_path(struct cli_state *cli, const char *path, const char *ea_name, const char *ea_val, size_t ea_len); diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c index c98346e3b30..3d1da5f412d 100644 --- a/source3/libsmb/clifile.c +++ b/source3/libsmb/clifile.c @@ -2163,57 +2163,120 @@ NTSTATUS cli_chkpath(struct cli_state *cli, const char *path) return status; } -#if 0 -bool cli_chkpath(struct cli_state *cli, const char *path) +/**************************************************************************** + Query disk space. +****************************************************************************/ + +static void cli_dskattr_done(struct tevent_req *subreq); + +struct cli_dskattr_state { + int bsize; + int total; + int avail; +}; + +struct tevent_req *cli_dskattr_send(TALLOC_CTX *mem_ctx, + struct event_context *ev, + struct cli_state *cli) { - char *path2 = NULL; - char *p; - TALLOC_CTX *frame = talloc_stackframe(); + struct tevent_req *req = NULL, *subreq = NULL; + struct cli_dskattr_state *state = NULL; + uint8_t additional_flags = 0; - path2 = talloc_strdup(frame, path); - if (!path2) { - TALLOC_FREE(frame); - return false; + req = tevent_req_create(mem_ctx, &state, struct cli_dskattr_state); + if (req == NULL) { + return NULL; } - trim_char(path2,'\0','\\'); - if (!*path2) { - path2 = talloc_strdup(frame, "\\"); - if (!path2) { - TALLOC_FREE(frame); - return false; - } + + subreq = cli_smb_send(state, ev, cli, SMBdskattr, additional_flags, + 0, NULL, 0, NULL); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); } + tevent_req_set_callback(subreq, cli_dskattr_done, req); + return req; +} - memset(cli->outbuf,'\0',smb_size); - cli_set_message(cli->outbuf,0,0,True); - SCVAL(cli->outbuf,smb_com,SMBcheckpath); - SSVAL(cli->outbuf,smb_tid,cli->cnum); - cli_setup_packet(cli); - p = smb_buf(cli->outbuf); - *p++ = 4; - p += clistr_push(cli, p, path2, - cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); +static void cli_dskattr_done(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct cli_dskattr_state *state = tevent_req_data( + req, struct cli_dskattr_state); + uint8_t wct; + uint16_t *vwv = NULL; + NTSTATUS status; - cli_setup_bcc(cli, p); + status = cli_smb_recv(subreq, 4, &wct, &vwv, NULL, NULL); + if (!NT_STATUS_IS_OK(status)) { + tevent_req_nterror(req, status); + return; + } + state->bsize = SVAL(vwv+1, 0)*SVAL(vwv+2,0); + state->total = SVAL(vwv+0, 0); + state->avail = SVAL(vwv+3, 0); + TALLOC_FREE(subreq); + tevent_req_done(req); +} - cli_send_smb(cli); - if (!cli_receive_smb(cli)) { - TALLOC_FREE(frame); - return False; +NTSTATUS cli_dskattr_recv(struct tevent_req *req, int *bsize, int *total, int *avail) +{ + struct cli_dskattr_state *state = tevent_req_data( + req, struct cli_dskattr_state); + NTSTATUS status; + + if (tevent_req_is_nterror(req, &status)) { + return status; } + *bsize = state->bsize; + *total = state->total; + *avail = state->avail; + return NT_STATUS_OK; +} - TALLOC_FREE(frame); +NTSTATUS cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail) +{ + TALLOC_CTX *frame = talloc_stackframe(); + struct event_context *ev = NULL; + struct tevent_req *req = NULL; + NTSTATUS status = NT_STATUS_OK; - if (cli_is_error(cli)) return False; + 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; -} -#endif + ev = event_context_init(frame); + if (ev == NULL) { + status = NT_STATUS_NO_MEMORY; + goto fail; + } -/**************************************************************************** - Query disk space. -****************************************************************************/ + req = cli_dskattr_send(frame, ev, cli); + 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_dskattr_recv(req, bsize, total, avail); + + fail: + TALLOC_FREE(frame); + if (!NT_STATUS_IS_OK(status)) { + cli_set_error(cli, status); + } + return status; +} + +#if 0 bool cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail) { memset(cli->outbuf,'\0',smb_size); @@ -2233,6 +2296,7 @@ bool cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail) return True; } +#endif /**************************************************************************** Create and open a temporary file.