[SCM] Samba Shared Repository - branch v3-2-test updated -
release-3-2-0pre2-120-g1bcfef6
Volker Lendecke
vl at samba.org
Thu Mar 6 12:31:08 GMT 2008
The branch, v3-2-test has been updated
via 1bcfef6a9093aa873550a263dc142c8a3f5edffd (commit)
via e602f06cbba852a7eacd15b2511ef2571a95cc80 (commit)
via d69b20111a849152a7d9108763207c813bf9068b (commit)
via 76f9b360ee1d973630d82d401eeddce858189301 (commit)
via e2153301351559f30f2714345f4c1ca6c5f1a45f (commit)
via 9f8b2a87ee8bba930b776dcfda608a5639f6d55a (commit)
from 6761fed30821b30246a0f25874566f8a6019abde (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test
- Log -----------------------------------------------------------------
commit 1bcfef6a9093aa873550a263dc142c8a3f5edffd
Author: Volker Lendecke <vl at samba.org>
Date: Sat Mar 1 12:11:22 2008 +0100
Change default bufsize to 512k
I did not do any scientific tests, but the dummy test on my laptop against a
w2k3 vmware shows that in this specific situation going beyond 512k seems not
to gain anything anymore.
smb: \> iosize 64512
iosize is now 64512
smb: \> lcd /dev
smb: \> get random null
getting file \random of size 104857600 as null (33453,1 kb/s) (average 19718,5 kb/s)
smb: \> get random null
getting file \random of size 104857600 as null (34236,0 kb/s) (average 20509,1 kb/s)
smb: \> iosize 524288
iosize is now 524288
smb: \> get random null
getting file \random of size 104857600 as null (49042,1 kb/s) (average 22521,9 kb/s)
smb: \> get random null
getting file \random of size 104857600 as null (49420,8 kb/s) (average 23432,9 kb/s)
smb: \> iosize 1048576
iosize is now 1048576
smb: \> get random null
getting file \random of size 104857600 as null (49420,8 kb/s) (average 24284,2 kb/s)
smb: \> get random null
getting file \random of size 104857600 as null (49136,3 kb/s) (average 25076,9 kb/s)
commit e602f06cbba852a7eacd15b2511ef2571a95cc80
Author: Volker Lendecke <vl at samba.org>
Date: Sat Mar 1 12:05:09 2008 +0100
Use io_bufsize as window size in smbclient get command
commit d69b20111a849152a7d9108763207c813bf9068b
Author: Volker Lendecke <vl at samba.org>
Date: Thu Feb 28 15:26:01 2008 +0100
Convert cli_read to use cli_pull
commit 76f9b360ee1d973630d82d401eeddce858189301
Author: Volker Lendecke <vl at samba.org>
Date: Thu Feb 28 15:21:33 2008 +0100
Add async cli_pull support
This is the big (and potentially controversial) one. It took a phone call to
explain to metze what is going on inside cli_pull_read_done, but I would really
like everybody to understand this function. It is a very good and reasonably
complex example of async programming. If we want more asynchronism in s3, this
is what we will have to deal with :-)
Make use of it in the smbclient "get" command.
Volker
commit e2153301351559f30f2714345f4c1ca6c5f1a45f
Author: Volker Lendecke <vl at samba.org>
Date: Thu Feb 28 14:41:25 2008 +0100
Add infrastructure to support async SMB requests
commit 9f8b2a87ee8bba930b776dcfda608a5639f6d55a
Author: Volker Lendecke <vl at samba.org>
Date: Thu Feb 28 13:55:53 2008 +0100
Add basic infrastructure for general async requests
-----------------------------------------------------------------------
Summary of changes:
source/Makefile.in | 4 +-
source/client/client.c | 47 ++---
source/include/async_req.h | 89 +++++++
source/include/async_smb.h | 62 +++++
source/include/client.h | 30 +++
source/include/includes.h | 2 +
source/lib/async_req.c | 68 ++++++
source/libsmb/async_smb.c | 483 +++++++++++++++++++++++++++++++++++++++
source/libsmb/clireadwrite.c | 519 ++++++++++++++++++++++++++++++++----------
9 files changed, 1151 insertions(+), 153 deletions(-)
create mode 100644 source/include/async_req.h
create mode 100644 source/include/async_smb.h
create mode 100644 source/lib/async_req.c
create mode 100644 source/libsmb/async_smb.c
Changeset truncated at 500 lines:
diff --git a/source/Makefile.in b/source/Makefile.in
index acd39d7..7dfa312 100644
--- a/source/Makefile.in
+++ b/source/Makefile.in
@@ -327,7 +327,7 @@ LIB_WITHOUT_PROTO_OBJ = $(LIBSAMBAUTIL_OBJ) \
lib/messages.o librpc/gen_ndr/ndr_messaging.o lib/messages_local.o \
lib/messages_ctdbd.o lib/packet.o lib/ctdbd_conn.o lib/talloc_stack.o \
lib/interfaces.o lib/rbtree.o lib/memcache.o \
- lib/util_transfer_file.o
+ lib/util_transfer_file.o lib/async_req.o
LIB_WITH_PROTO_OBJ = $(VERSION_OBJ) lib/charcnv.o lib/debug.o lib/fault.o \
lib/interface.o lib/md4.o \
@@ -418,7 +418,7 @@ LIBSMB_OBJ = libsmb/clientgen.o libsmb/cliconnect.o libsmb/clifile.o \
libsmb/clistr.o libsmb/cliquota.o libsmb/clifsinfo.o libsmb/clidfs.o \
libsmb/smberr.o libsmb/credentials.o libsmb/pwd_cache.o \
libsmb/clioplock.o $(ERRORMAP_OBJ) libsmb/clirap2.o \
- libsmb/smb_seal.o $(DOSERR_OBJ) \
+ libsmb/smb_seal.o $(DOSERR_OBJ) libsmb/async_smb.o \
$(RPC_PARSE_OBJ1) $(LIBSAMBA_OBJ) $(LIBNMB_OBJ)
RPC_CLIENT_OBJ1 = rpc_client/cli_netlogon.o rpc_client/cli_srvsvc.o
diff --git a/source/client/client.c b/source/client/client.c
index f7ed33a..79b7dfe 100644
--- a/source/client/client.c
+++ b/source/client/client.c
@@ -43,7 +43,7 @@ static bool grepable = false;
static char *cmdstr = NULL;
static const char *cmd_ptr = NULL;
-static int io_bufsize = 64512;
+static int io_bufsize = 524288;
static int name_type = 0x20;
extern int max_protocol;
@@ -964,22 +964,30 @@ static int cmd_echo(void)
Get a file from rname to lname
****************************************************************************/
+static NTSTATUS writefile_sink(char *buf, size_t n, void *priv)
+{
+ int *pfd = (int *)priv;
+ if (writefile(*pfd, buf, n) == -1) {
+ return map_nt_error_from_unix(errno);
+ }
+ return NT_STATUS_OK;
+}
+
static int do_get(const char *rname, const char *lname_in, bool reget)
{
TALLOC_CTX *ctx = talloc_tos();
int handle = 0, fnum;
bool newhandle = false;
- char *data = NULL;
struct timeval tp_start;
- int read_size = io_bufsize;
uint16 attr;
SMB_OFF_T size;
off_t start = 0;
- off_t nread = 0;
+ ssize_t nread = 0;
int rc = 0;
struct cli_state *targetcli = NULL;
char *targetname = NULL;
char *lname = NULL;
+ NTSTATUS status;
lname = talloc_strdup(ctx, lname_in);
if (!lname) {
@@ -1038,36 +1046,15 @@ static int do_get(const char *rname, const char *lname_in, bool reget)
DEBUG(1,("getting file %s of size %.0f as %s ",
rname, (double)size, lname));
- if(!(data = (char *)SMB_MALLOC(read_size))) {
- d_printf("malloc fail for size %d\n", read_size);
+ status = cli_pull(targetcli, fnum, start, size, io_bufsize,
+ writefile_sink, (void *)&handle, &nread);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr, "parallel_read returned %s\n",
+ nt_errstr(status));
cli_close(targetcli, fnum);
return 1;
}
- while (1) {
- int n = cli_read(targetcli, fnum, data, nread + start, read_size);
-
- if (n <= 0)
- break;
-
- if (writefile(handle,data, n) != n) {
- d_printf("Error writing local file\n");
- rc = 1;
- break;
- }
-
- nread += n;
- }
-
- if (nread + start < size) {
- DEBUG (0, ("Short read when getting file %s. Only got %ld bytes.\n",
- rname, (long)nread));
-
- rc = 1;
- }
-
- SAFE_FREE(data);
-
if (!cli_close(targetcli, fnum)) {
d_printf("Error %s closing remote file\n",cli_errstr(cli));
rc = 1;
diff --git a/source/include/async_req.h b/source/include/async_req.h
new file mode 100644
index 0000000..6df5360
--- /dev/null
+++ b/source/include/async_req.h
@@ -0,0 +1,89 @@
+/*
+ Unix SMB/CIFS implementation.
+ Infrastructure for async requests
+ Copyright (C) Volker Lendecke 2008
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __ASYNC_REQ_H__
+#define __ASYNC_REQ_H__
+
+#include "includes.h"
+
+/*
+ * An async request moves between the following 4 states.
+ */
+enum async_req_state {
+ ASYNC_REQ_INIT, /* we are creating the request */
+ ASYNC_REQ_IN_PROGRESS, /* we are waiting the request to complete */
+ ASYNC_REQ_DONE, /* the request is finished */
+ ASYNC_REQ_ERROR }; /* an error has occured */
+
+struct async_req {
+ /* the external state - will be queried by the caller */
+ enum async_req_state state;
+
+ /* a private pointer for use by the async function implementation */
+ void *private_data;
+
+ /* print yourself, for debugging purposes */
+ char *(*print)(TALLOC_CTX *mem_ctx, struct async_req *);
+
+ /* status code when finished */
+ NTSTATUS status;
+
+ /* the event context we are using */
+ struct event_context *event_ctx;
+
+ /* information on what to do on completion */
+ struct {
+ void (*fn)(struct async_req *);
+ void *priv;
+ } async;
+};
+
+/*
+ * Print an async_req structure for debugging purposes
+ */
+char *async_req_print(TALLOC_CTX *mem_ctx, struct async_req *req);
+
+/*
+ * Create an async request
+ */
+struct async_req *async_req_new(TALLOC_CTX *mem_ctx, struct event_context *ev);
+
+/*
+ * An async request has successfully finished, invoke the callback
+ */
+void async_req_done(struct async_req *req);
+
+/*
+ * An async request has seen an error, invoke the callback
+ */
+void async_req_error(struct async_req *req, NTSTATUS status);
+
+/*
+ * Convenience helper to easily check alloc failure within a callback.
+ *
+ * Call pattern would be
+ * p = talloc(mem_ctx, bla);
+ * if (async_req_nomem(p, req)) {
+ * return;
+ * }
+ *
+ */
+bool async_req_nomem(const void *p, struct async_req *req);
+
+#endif
diff --git a/source/include/async_smb.h b/source/include/async_smb.h
new file mode 100644
index 0000000..19408be
--- /dev/null
+++ b/source/include/async_smb.h
@@ -0,0 +1,62 @@
+/*
+ Unix SMB/CIFS implementation.
+ Infrastructure for async SMB client requests
+ Copyright (C) Volker Lendecke 2008
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+
+/*
+ * Create a fresh async smb request
+ */
+
+struct async_req *cli_request_new(TALLOC_CTX *mem_ctx,
+ struct event_context *ev,
+ struct cli_state *cli,
+ uint8_t num_words, size_t num_bytes,
+ struct cli_request **preq);
+
+/*
+ * Convenience function to get the SMB part out of an async_req
+ */
+
+struct cli_request *cli_request_get(struct async_req *req);
+
+/*
+ * Fetch an error out of a NBT packet
+ */
+
+NTSTATUS cli_pull_error(char *buf);
+
+/*
+ * Compatibility helper for the sync APIs: Fake NTSTATUS in cli->inbuf
+ */
+
+void cli_set_error(struct cli_state *cli, NTSTATUS status);
+
+/*
+ * Create a temporary event context for use in the sync helper functions
+ */
+
+struct cli_tmp_event *cli_tmp_event_ctx(TALLOC_CTX *mem_ctx,
+ struct cli_state *cli);
+
+/*
+ * Attach an event context permanently to a cli_struct
+ */
+
+NTSTATUS cli_add_event_ctx(struct cli_state *cli,
+ struct event_context *event_ctx);
diff --git a/source/include/client.h b/source/include/client.h
index d29a2e7..52dc513 100644
--- a/source/include/client.h
+++ b/source/include/client.h
@@ -192,6 +192,36 @@ struct cli_state {
bool force_dos_errors;
bool case_sensitive; /* False by default. */
+
+ struct event_context *event_ctx;
+ struct fd_event *fd_event;
+ char *evt_inbuf;
+
+ struct cli_request *outstanding_requests;
+};
+
+struct cli_request {
+ struct cli_request *prev, *next;
+ struct async_req *async;
+
+ struct cli_state *cli;
+
+ struct smb_trans_enc_state *enc_state;
+
+ uint16_t mid;
+
+ char *outbuf;
+ size_t sent;
+ char *inbuf;
+
+ union {
+ struct {
+ off_t ofs;
+ size_t size;
+ ssize_t received;
+ uint8_t *rcvbuf;
+ } read;
+ } data;
};
typedef struct file_info {
diff --git a/source/include/includes.h b/source/include/includes.h
index c54afd8..36c71d7 100644
--- a/source/include/includes.h
+++ b/source/include/includes.h
@@ -723,6 +723,8 @@ typedef char fstring[FSTRING_LEN];
#include "ctdbd_conn.h"
#include "talloc_stack.h"
#include "memcache.h"
+#include "async_req.h"
+#include "async_smb.h"
/* used in net.c */
struct functable {
diff --git a/source/lib/async_req.c b/source/lib/async_req.c
new file mode 100644
index 0000000..01154ca
--- /dev/null
+++ b/source/lib/async_req.c
@@ -0,0 +1,68 @@
+/*
+ Unix SMB/CIFS implementation.
+ Infrastructure for async requests
+ Copyright (C) Volker Lendecke 2008
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+
+char *async_req_print(TALLOC_CTX *mem_ctx, struct async_req *req)
+{
+ return talloc_asprintf(mem_ctx, "async_req: state=%d, status=%s, "
+ "priv=%s", req->state, nt_errstr(req->status),
+ talloc_get_name(req->private_data));
+}
+
+struct async_req *async_req_new(TALLOC_CTX *mem_ctx, struct event_context *ev)
+{
+ struct async_req *result;
+
+ result = TALLOC_ZERO_P(mem_ctx, struct async_req);
+ if (result == NULL) {
+ return NULL;
+ }
+ result->state = ASYNC_REQ_IN_PROGRESS;
+ result->event_ctx = ev;
+ result->print = async_req_print;
+ return result;
+}
+
+void async_req_done(struct async_req *req)
+{
+ req->status = NT_STATUS_OK;
+ req->state = ASYNC_REQ_DONE;
+ if (req->async.fn != NULL) {
+ req->async.fn(req);
+ }
+}
+
+void async_req_error(struct async_req *req, NTSTATUS status)
+{
+ req->status = status;
+ req->state = ASYNC_REQ_ERROR;
+ if (req->async.fn != NULL) {
+ req->async.fn(req);
+ }
+}
+
+bool async_req_nomem(const void *p, struct async_req *req)
+{
+ if (p != NULL) {
+ return false;
+ }
+ async_req_error(req, NT_STATUS_NO_MEMORY);
+ return true;
+}
diff --git a/source/libsmb/async_smb.c b/source/libsmb/async_smb.c
new file mode 100644
index 0000000..21bcd5b
--- /dev/null
+++ b/source/libsmb/async_smb.c
@@ -0,0 +1,483 @@
+/*
+ Unix SMB/CIFS implementation.
+ Infrastructure for async SMB client requests
+ Copyright (C) Volker Lendecke 2008
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+
+/*
+ * Fetch an error out of a NBT packet
+ */
+
+NTSTATUS cli_pull_error(char *buf)
+{
+ uint32_t flags2 = SVAL(buf, smb_flg2);
+
+ if (flags2 & FLAGS2_32_BIT_ERROR_CODES) {
+ return NT_STATUS(IVAL(buf, smb_rcls));
+ }
+
+ return NT_STATUS_DOS(CVAL(buf, smb_rcls), SVAL(buf,smb_err));
+}
+
+/*
+ * Compatibility helper for the sync APIs: Fake NTSTATUS in cli->inbuf
+ */
+
+void cli_set_error(struct cli_state *cli, NTSTATUS status)
+{
+ uint32_t flags2 = SVAL(cli->inbuf, smb_flg2);
+
+ if (NT_STATUS_IS_DOS(status)) {
+ SSVAL(cli->inbuf, smb_flg2,
+ flags2 & ~FLAGS2_32_BIT_ERROR_CODES);
+ SCVAL(cli->inbuf, smb_rcls, NT_STATUS_DOS_CLASS(status));
+ SSVAL(cli->inbuf, smb_err, NT_STATUS_DOS_CODE(status));
+ return;
+ }
+
+ SSVAL(cli->inbuf, smb_flg2, flags2 | FLAGS2_32_BIT_ERROR_CODES);
+ SIVAL(cli->inbuf, smb_rcls, NT_STATUS_V(status));
+ return;
+}
+
+/*
+ * Allocate a new mid
+ */
+
+static uint16_t cli_new_mid(struct cli_state *cli)
+{
+ uint16_t result;
+ struct cli_request *req;
+
+ while (true) {
+ result = cli->mid++;
+ if (result == 0) {
+ continue;
+ }
+
+ for (req = cli->outstanding_requests; req; req = req->next) {
+ if (result == req->mid) {
+ break;
+ }
+ }
+
+ if (req == NULL) {
+ return result;
+ }
+ }
+}
+
+static char *cli_request_print(TALLOC_CTX *mem_ctx, struct async_req *req)
+{
+ char *result = async_req_print(mem_ctx, req);
+ struct cli_request *cli_req = cli_request_get(req);
+
+ if (result == NULL) {
+ return NULL;
+ }
--
Samba Shared Repository
More information about the samba-cvs
mailing list