r281: Revised nbd-client timeout support
authorsnitm <snitm>
Sat, 25 Aug 2007 22:43:44 +0000 (22:43 +0000)
committersnitm <snitm>
Sat, 25 Aug 2007 22:43:44 +0000 (22:43 +0000)
nbd-client.8.sgml
nbd-client.c

index 17a147a..7e18e8b 100644 (file)
@@ -56,6 +56,7 @@ manpage.1: manpage.sgml
     <cmdsynopsis>
       <command>&dhpackage;</command>
       <arg><option>bs=<replaceable>blocksize</replaceable></option></arg>
+      <arg><option>timeout=<replaceable>seconds</replaceable></option></arg>
       <arg choice=plain><option><replaceable>host</replaceable></option></arg>
       <arg choice=plain><option><replaceable>port</replaceable></option></arg>
       <arg choice=plain><option><replaceable>nbd-device</replaceable></option></arg>
index f4836c5..d03b568 100644 (file)
@@ -140,6 +140,16 @@ void setsizes(int nbd, u64 size64, int blocksize, u32 flags) {
                err("Unable to set read-only attribute for device");
 }
 
+void set_timeout(int nbd, int timeout) {
+#ifdef NBD_SET_TIMEOUT
+       if (timeout) {
+               if (ioctl(nbd, NBD_SET_TIMEOUT, (unsigned long)timeout) < 0)
+                       err("Ioctl NBD_SET_TIMEOUT failed: %m\n");
+               fprintf(stderr, "timeout=%d\n", timeout);
+       }
+#endif
+}
+
 void finish_sock(int sock, int nbd, int swap) {
        if (ioctl(nbd, NBD_SET_SOCK, sock) < 0)
                err("Ioctl NBD_SET_SOCK failed: %m\n");
@@ -160,6 +170,7 @@ int main(int argc, char *argv[]) {
        char *hostname, *nbddev;
        int swap=0;
        int cont=0;
+       int timeout=0;
        u64 size64;
        u32 flags;
 
@@ -168,7 +179,7 @@ int main(int argc, char *argv[]) {
        if (argc < 3) {
        errmsg:
                fprintf(stderr, "nbd-client version %s\n", PACKAGE_VERSION);
-               fprintf(stderr, "Usage: nbd-client [bs=blocksize] host port nbd_device [-swap] [-persist]\n");
+               fprintf(stderr, "Usage: nbd-client [bs=blocksize] [timeout=sec] host port nbd_device [-swap] [-persist]\n");
                fprintf(stderr, "Or   : nbd-client -d nbd_device\n");
                fprintf(stderr, "Default value for blocksize is 1024 (recommended for ethernet)\n");
                fprintf(stderr, "Allowed values for blocksize are 512,1024,2048,4096\n"); /* will be checked in kernel :) */
@@ -206,6 +217,11 @@ int main(int argc, char *argv[]) {
                ++argv; --argc; /* skip blocksize */
        }
 
+       if (strncmp(argv[0], "timeout=", 8)==0) {
+               timeout=atoi(argv[0]+8);
+               ++argv; --argc; /* skip timeout */
+       }
+       
        if (argc==0) goto errmsg;
        hostname=argv[0];
        ++argv; --argc; /* skip hostname */
@@ -239,6 +255,7 @@ int main(int argc, char *argv[]) {
 
        negotiate(sock, &size64, &flags);
        setsizes(nbd, size64, blocksize, flags);
+       set_timeout(nbd, timeout);
        finish_sock(sock, nbd, swap);
 
        /* Go daemon */
@@ -272,6 +289,7 @@ int main(int argc, char *argv[]) {
                                        setsizes(nbd, size64, blocksize,
                                                                new_flags);
 
+                                       set_timeout(nbd, timeout);
                                        finish_sock(sock,nbd,swap);
                                }
                        }