projects
/
nbd.git
/ commitdiff
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
d37e788
)
r281: Revised nbd-client timeout support
author
snitm <snitm>
Sat, 25 Aug 2007 22:43:44 +0000
(22:43 +0000)
committer
snitm <snitm>
Sat, 25 Aug 2007 22:43:44 +0000
(22:43 +0000)
nbd-client.8.sgml
patch
|
blob
|
history
nbd-client.c
patch
|
blob
|
history
diff --git
a/nbd-client.8.sgml
b/nbd-client.8.sgml
index
17a147a
..
7e18e8b
100644
(file)
--- a/
nbd-client.8.sgml
+++ b/
nbd-client.8.sgml
@@
-56,6
+56,7
@@
manpage.1: manpage.sgml
<cmdsynopsis>
<command>&dhpackage;</command>
<arg><option>bs=<replaceable>blocksize</replaceable></option></arg>
<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>
<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>
diff --git
a/nbd-client.c
b/nbd-client.c
index
f4836c5
..
d03b568
100644
(file)
--- a/
nbd-client.c
+++ b/
nbd-client.c
@@
-140,6
+140,16
@@
void setsizes(int nbd, u64 size64, int blocksize, u32 flags) {
err("Unable to set read-only attribute for device");
}
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");
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;
char *hostname, *nbddev;
int swap=0;
int cont=0;
+ int timeout=0;
u64 size64;
u32 flags;
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);
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 :) */
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 */
}
++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 */
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);
negotiate(sock, &size64, &flags);
setsizes(nbd, size64, blocksize, flags);
+ set_timeout(nbd, timeout);
finish_sock(sock, nbd, swap);
/* Go daemon */
finish_sock(sock, nbd, swap);
/* Go daemon */
@@
-272,6
+289,7
@@
int main(int argc, char *argv[]) {
setsizes(nbd, size64, blocksize,
new_flags);
setsizes(nbd, size64, blocksize,
new_flags);
+ set_timeout(nbd, timeout);
finish_sock(sock,nbd,swap);
}
}
finish_sock(sock,nbd,swap);
}
}