Add new "timeout" command and -t option to smbclient to set the per-operation timeout.
authorJeremy Allison <jra@samba.org>
Fri, 16 Aug 2013 20:49:39 +0000 (13:49 -0700)
committerMichael Adam <obnox@samba.org>
Wed, 21 Aug 2013 15:28:55 +0000 (17:28 +0200)
This is needed as once SMB3 encryption is selected the server
response time can be very slow when requesting large numbers
(256) of large encrypted packets (1MB) from a Windows 2012
virtual machine. This allows clients to tune their allowable
wait time.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
source3/client/client.c

index ad4a87547e206e64697e1aa20fd46922bc3ec71e..581b9c6115b04d3c6abf9801d911bb93b91ea7d4 100644 (file)
@@ -56,6 +56,7 @@ static char *cmdstr = NULL;
 const char *cmd_ptr = NULL;
 
 static int io_bufsize = 0; /* we use the default size */
+static int io_timeout = (CLIENT_TIMEOUT/1000); /* Per operation timeout (in seconds). */
 
 static int name_type = 0x20;
 static int max_protocol = -1;
@@ -4564,6 +4565,31 @@ int cmd_iosize(void)
        return 0;
 }
 
+/****************************************************************************
+ timeout command
+***************************************************************************/
+
+static int cmd_timeout(void)
+{
+       TALLOC_CTX *ctx = talloc_tos();
+       char *buf;
+
+       if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
+               unsigned int old_timeout = cli_set_timeout(cli, 0);
+               cli_set_timeout(cli, old_timeout);
+               d_printf("timeout <n> (per-operation timeout "
+                       "in seconds - currently %u).\n",
+                       old_timeout/1000);
+               return 1;
+       }
+
+       io_timeout = strtol(buf,NULL,0);
+       cli_set_timeout(cli, io_timeout*1000);
+       d_printf("io_timeout per operation is now %d\n", io_timeout);
+       return 0;
+}
+
+
 /****************************************************************************
 history
 ****************************************************************************/
@@ -4672,6 +4698,7 @@ static struct {
   {"symlink",cmd_symlink,"<oldname> <newname> create a UNIX symlink",{COMPL_REMOTE,COMPL_REMOTE}},
   {"tar",cmd_tar,"tar <c|x>[IXFqbgNan] current directory to/from <file name>",{COMPL_NONE,COMPL_NONE}},
   {"tarmode",cmd_tarmode,"<full|inc|reset|noreset> tar's behaviour towards archive bits",{COMPL_NONE,COMPL_NONE}},
+  {"timeout",cmd_timeout,"timeout <number> - set the per-operation timeout in seconds (default 20)",{COMPL_NONE,COMPL_NONE}},
   {"translate",cmd_translate,"toggle text translation for printing",{COMPL_NONE,COMPL_NONE}},
   {"unlock",cmd_unlock,"unlock <fnum> <hex-start> <hex-len> : remove a POSIX lock",{COMPL_REMOTE,COMPL_REMOTE}},
   {"volume",cmd_volume,"print the volume name",{COMPL_NONE,COMPL_NONE}},
@@ -4775,6 +4802,7 @@ static int process_command_string(const char *cmd_in)
                if (!NT_STATUS_IS_OK(status)) {
                        return 1;
                }
+               cli_set_timeout(cli, io_timeout*1000);
        }
 
        while (cmd[0] != '\0')    {
@@ -5202,6 +5230,8 @@ static int process(const char *base_directory)
                return 1;
        }
 
+       cli_set_timeout(cli, io_timeout*1000);
+
        if (base_directory && *base_directory) {
                rc = do_cd(base_directory);
                if (rc) {
@@ -5236,6 +5266,7 @@ static int do_host_query(const char *query_host)
                return 1;
        }
 
+       cli_set_timeout(cli, io_timeout*1000);
        browse_host(true);
 
        /* Ensure that the host can do IPv4 */
@@ -5271,6 +5302,7 @@ static int do_host_query(const char *query_host)
                return 1;
        }
 
+       cli_set_timeout(cli, io_timeout*1000);
        list_servers(lp_workgroup());
 
        cli_shutdown(cli);
@@ -5297,6 +5329,7 @@ static int do_tar_op(const char *base_directory)
                if (!NT_STATUS_IS_OK(status)) {
                        return 1;
                }
+               cli_set_timeout(cli, io_timeout*1000);
        }
 
        recurse=true;
@@ -5332,6 +5365,7 @@ static int do_message_op(struct user_auth_info *a_info)
                return 1;
        }
 
+       cli_set_timeout(cli, io_timeout*1000);
        send_message(get_cmdline_auth_info_username(a_info));
        cli_shutdown(cli);
 
@@ -5368,6 +5402,7 @@ static int do_message_op(struct user_auth_info *a_info)
                { "directory", 'D', POPT_ARG_STRING, NULL, 'D', "Start from directory", "DIR" },
                { "command", 'c', POPT_ARG_STRING, &cmdstr, 'c', "Execute semicolon separated commands" }, 
                { "send-buffer", 'b', POPT_ARG_INT, &io_bufsize, 'b', "Changes the transmit/send buffer", "BYTES" },
+               { "timeout", 't', POPT_ARG_INT, &io_timeout, 'b', "Changes the per-operation timeout", "SECONDS" },
                { "port", 'p', POPT_ARG_INT, &port, 'p', "Port to connect to", "PORT" },
                { "grepable", 'g', POPT_ARG_NONE, NULL, 'g', "Produce grepable output" },
                 { "browse", 'B', POPT_ARG_NONE, NULL, 'B', "Browse SMB servers using DNS" },