summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2009-04-22 08:04:53 -0700
committerJeremy Allison <jra@samba.org>2009-04-22 08:04:53 -0700
commit455f2a4c65b679a996a8d6e7548dc2f4a6f28fae (patch)
tree95aab64d6f8927d5f7be56a363add62b0159c916 /source3
parent740c2c4366badc62d017881c9484ee5153b62f94 (diff)
downloadsamba-455f2a4c65b679a996a8d6e7548dc2f4a6f28fae.tar.gz
samba-455f2a4c65b679a996a8d6e7548dc2f4a6f28fae.tar.bz2
samba-455f2a4c65b679a996a8d6e7548dc2f4a6f28fae.zip
Make dskattr async.
Jeremy.
Diffstat (limited to 'source3')
-rw-r--r--source3/client/client.c2
-rw-r--r--source3/include/proto.h2
-rw-r--r--source3/libsmb/clifile.c140
3 files changed, 104 insertions, 40 deletions
diff --git a/source3/client/client.c b/source3/client/client.c
index 151f7460fc..68d96a9dcc 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 1435f4f405..518c3a7e93 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 c98346e3b3..3d1da5f412 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.