summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2018-07-27 16:29:38 +0800
committerJeremy Kerr <jk@ozlabs.org>2018-07-27 16:29:38 +0800
commit09295f2e0b0b07468e0f45f51889cb066d1e537f (patch)
treedf33eb582bb1b3eb79fa0105892d26660e6f9646
parent0668cd4a07f53b37d17ad6329a985a0bbf74cef0 (diff)
downloadjsnbd-09295f2e0b0b07468e0f45f51889cb066d1e537f.tar.gz
jsnbd-09295f2e0b0b07468e0f45f51889cb066d1e537f.zip
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>
-rw-r--r--nbd-proxy.c5
1 files changed, 5 insertions, 0 deletions
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 @@ struct ctx {
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 @@ static int start_nbd_client(struct ctx *ctx)
/* 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 @@ static int start_nbd_client(struct ctx *ctx)
execlp("nbd-client", "nbd-client",
"-u", ctx->sock_path,
"-n",
+ "-t", timeout_str,
dev_path,
NULL);
err(EXIT_FAILURE, "can't start ndb client");
OpenPOWER on IntegriCloud