[PATCH 5/7] sheepdog: Check for validity of pool source hostname

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/storage/storage_backend_sheepdog.c | 36 ++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_backend_sheepdog.c
index af15c3b..78caae5 100644
--- a/src/storage/storage_backend_sheepdog.c
+++ b/src/storage/storage_backend_sheepdog.c
@@ -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 (!virIsValidHostname(address))
+            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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]