nbd-proxy: Specify nbd socket timeout
For non-local connections, we need a longer timeout than the kernel
default.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
diff --git a/nbd-proxy.c b/nbd-proxy.c
index 738b0d2..13a1366 100644
--- a/nbd-proxy.c
+++ b/nbd-proxy.c
@@ -49,6 +49,7 @@
static const char *sockpath_tmpl = RUNSTATEDIR "/nbd.%d.sock";
static const char *dev_path = "/dev/nbd0";
static const size_t bufsize = 0x20000;
+static const int nbd_timeout = 30;
static int open_nbd_socket(struct ctx *ctx)
{
@@ -112,8 +113,11 @@
/* child process: run nbd-client in non-fork mode */
if (pid == 0) {
+ char timeout_str[10];
int fd;
+ snprintf(timeout_str, sizeof(timeout_str), "%d", nbd_timeout);
+
fd = open("/dev/null", O_RDWR);
if (fd < 0)
err(EXIT_FAILURE, "can't open /dev/null");
@@ -127,6 +131,7 @@
execlp("nbd-client", "nbd-client",
"-u", ctx->sock_path,
"-n",
+ "-t", timeout_str,
dev_path,
NULL);
err(EXIT_FAILURE, "can't start ndb client");