If there is a pool source hostname provided, let's make sure the name
can be resolved before trying to connect to it via a virCommand sequence.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/storage/storage_backend_sheepdog.c | 38 +++++++++++++++++++++-------------
1 file changed, 24 insertions(+), 14 deletions(-)
diff --git a/src/storage/storage_backend_sheepdog.c
b/src/storage/storage_backend_sheepdog.c
index af15c3b..b92c7a3 100644
--- a/src/storage/storage_backend_sheepdog.c
+++ b/src/storage/storage_backend_sheepdog.c
@@ -1,7 +1,7 @@
/*
* storage_backend_sheepdog.c: storage backend for Sheepdog handling
*
- * Copyright (C) 2013-2014 Red Hat, Inc.
+ * Copyright (C) 2013-2015 Red Hat, Inc.
* Copyright (C) 2012 Wido den Hollander
* Copyright (C) 2012 Frank Spijkerman
* Copyright (C) 2012 Sebastian Wiedenroth
@@ -40,9 +40,6 @@ static int virStorageBackendSheepdogRefreshVol(virConnectPtr conn,
virStoragePoolObjPtr pool,
virStorageVolDefPtr vol);
-void virStorageBackendSheepdogAddHostArg(virCommandPtr cmd,
- virStoragePoolObjPtr pool);
-
int
virStorageBackendSheepdogParseNodeInfo(virStoragePoolDefPtr pool,
char *output)
@@ -90,7 +87,7 @@ virStorageBackendSheepdogParseNodeInfo(virStoragePoolDefPtr pool,
return -1;
}
-void
+static int
virStorageBackendSheepdogAddHostArg(virCommandPtr cmd,
virStoragePoolObjPtr pool)
{
@@ -99,6 +96,8 @@ virStorageBackendSheepdogAddHostArg(virCommandPtr cmd,
if (pool->def->source.nhost > 0) {
if (pool->def->source.hosts[0].name != NULL)
address = pool->def->source.hosts[0].name;
+ if (virSocketAddrParseName(NULL, address, AF_UNSPEC, IPPROTO_TCP) < 0)
+ return -1;
if (pool->def->source.hosts[0].port)
port = pool->def->source.hosts[0].port;
}
@@ -106,6 +105,7 @@ virStorageBackendSheepdogAddHostArg(virCommandPtr cmd,
virCommandAddArgFormat(cmd, "%s", address);
virCommandAddArg(cmd, "-p");
virCommandAddArgFormat(cmd, "%d", port);
+ return 0;
}
static int
@@ -151,7 +151,8 @@ virStorageBackendSheepdogRefreshAllVol(virConnectPtr conn
ATTRIBUTE_UNUSED,
size_t i;
virCommandPtr cmd = virCommandNewArgList(COLLIE, "vdi", "list",
"-r", NULL);
- virStorageBackendSheepdogAddHostArg(cmd, pool);
+ if (virStorageBackendSheepdogAddHostArg(cmd, pool) < 0)
+ goto cleanup;
virCommandSetOutputBuffer(cmd, &output);
if (virCommandRun(cmd, NULL) < 0)
goto cleanup;
@@ -196,7 +197,8 @@ virStorageBackendSheepdogRefreshPool(virConnectPtr conn
ATTRIBUTE_UNUSED,
virCommandPtr cmd;
cmd = virCommandNewArgList(COLLIE, "node", "info",
"-r", NULL);
- virStorageBackendSheepdogAddHostArg(cmd, pool);
+ if (virStorageBackendSheepdogAddHostArg(cmd, pool) < 0)
+ goto cleanup;
virCommandSetOutputBuffer(cmd, &output);
if (virCommandRun(cmd, NULL) < 0)
goto cleanup;
@@ -218,13 +220,16 @@ virStorageBackendSheepdogDeleteVol(virConnectPtr conn
ATTRIBUTE_UNUSED,
virStorageVolDefPtr vol,
unsigned int flags)
{
+ int ret = -1;
virCheckFlags(0, -1);
virCommandPtr cmd = virCommandNewArgList(COLLIE, "vdi", "delete",
vol->name, NULL);
- virStorageBackendSheepdogAddHostArg(cmd, pool);
- int ret = virCommandRun(cmd, NULL);
+ if (virStorageBackendSheepdogAddHostArg(cmd, pool) < 0)
+ goto cleanup;
+ ret = virCommandRun(cmd, NULL);
+ cleanup:
virCommandFree(cmd);
return ret;
}
@@ -275,7 +280,8 @@ virStorageBackendSheepdogBuildVol(virConnectPtr conn,
cmd = virCommandNewArgList(COLLIE, "vdi", "create", vol->name,
NULL);
virCommandAddArgFormat(cmd, "%llu", vol->target.capacity);
- virStorageBackendSheepdogAddHostArg(cmd, pool);
+ if (virStorageBackendSheepdogAddHostArg(cmd, pool) < 0)
+ goto cleanup;
if (virCommandRun(cmd, NULL) < 0)
goto cleanup;
@@ -355,11 +361,12 @@ virStorageBackendSheepdogRefreshVol(virConnectPtr conn
ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool,
virStorageVolDefPtr vol)
{
- int ret;
+ int ret = -1;
char *output = NULL;
virCommandPtr cmd = virCommandNewArgList(COLLIE, "vdi", "list",
vol->name, "-r", NULL);
- virStorageBackendSheepdogAddHostArg(cmd, pool);
+ if (virStorageBackendSheepdogAddHostArg(cmd, pool) < 0)
+ goto cleanup;
virCommandSetOutputBuffer(cmd, &output);
ret = virCommandRun(cmd, NULL);
@@ -391,14 +398,17 @@ virStorageBackendSheepdogResizeVol(virConnectPtr conn
ATTRIBUTE_UNUSED,
unsigned long long capacity,
unsigned int flags)
{
+ int ret = -1;
virCheckFlags(0, -1);
virCommandPtr cmd = virCommandNewArgList(COLLIE, "vdi", "resize",
vol->name, NULL);
virCommandAddArgFormat(cmd, "%llu", capacity);
- virStorageBackendSheepdogAddHostArg(cmd, pool);
- int ret = virCommandRun(cmd, NULL);
+ if (virStorageBackendSheepdogAddHostArg(cmd, pool) < 0)
+ goto cleanup;
+ ret = virCommandRun(cmd, NULL);
+ cleanup:
virCommandFree(cmd);
return ret;
--
2.1.0