render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 2098b067ec805170011979646c52c8dbbda943c3 Mon Sep 17 00:00:00 2001
Message-Id: <2098b067ec805170011979646c52c8dbbda943c3@dist-git>
From: John Ferlan <jferlan@redhat.com>
Date: Wed, 3 Apr 2019 09:12:13 -0400
Subject: [PATCH] storage: Extract out mount command creation for FS Backend
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

https://bugzilla.redhat.com/show_bug.cgi?id=1584663

Extract out the code that is used to create the MOUNT command
for starting the pool. We can use this for Storage Pool XML
to Argv testing to ensure code changes don't alter how a
storage pool is started.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit 1bebb904fe2f8f51b29efe28bbe91d708f142ade)
Message-Id: <20190403131219.16385-2-jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/storage/storage_backend_fs.c | 70 +++++++++++++++++++-------------
 1 file changed, 41 insertions(+), 29 deletions(-)

diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 8983738210..4015271419 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -333,19 +333,11 @@ virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr pool)
     return ret;
 }
 
-/**
- * @pool storage pool to mount
- *
- * Ensure that a FS storage pool is mounted on its target location.
- * If already mounted, this is a no-op
- *
- * Returns 0 if successfully mounted, -1 on error
- */
-static int
-virStorageBackendFileSystemMount(virStoragePoolObjPtr pool)
+
+static virCommandPtr
+virStorageBackendFileSystemMountCmd(virStoragePoolDefPtr def,
+                                    const char *src)
 {
-    virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
-    char *src = NULL;
     /* 'mount -t auto' doesn't seem to auto determine nfs (or cifs),
      *  while plain 'mount' does. We have to craft separate argvs to
      *  accommodate this */
@@ -356,23 +348,6 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr pool)
     bool cifsfs = (def->type == VIR_STORAGE_POOL_NETFS &&
                    def->source.format == VIR_STORAGE_POOL_NETFS_CIFS);
     virCommandPtr cmd = NULL;
-    int ret = -1;
-    int rc;
-
-    if (virStorageBackendFileSystemIsValid(pool) < 0)
-        return -1;
-
-    if ((rc = virStorageBackendFileSystemIsMounted(pool)) < 0)
-        return -1;
-
-    /* Short-circuit if already mounted */
-    if (rc == 1) {
-        VIR_INFO("Target '%s' is already mounted", def->target.path);
-        return 0;
-    }
-
-    if (!(src = virStorageBackendFileSystemGetPoolSource(pool)))
-        return -1;
 
     if (netauto)
         cmd = virCommandNewArgList(MOUNT,
@@ -407,6 +382,43 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr pool)
                                    def->target.path,
                                    NULL);
 
+    return cmd;
+}
+
+
+/**
+ * @pool storage pool to mount
+ *
+ * Ensure that a FS storage pool is mounted on its target location.
+ * If already mounted, this is a no-op
+ *
+ * Returns 0 if successfully mounted, -1 on error
+ */
+static int
+virStorageBackendFileSystemMount(virStoragePoolObjPtr pool)
+{
+    virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
+    char *src = NULL;
+    virCommandPtr cmd = NULL;
+    int ret = -1;
+    int rc;
+
+    if (virStorageBackendFileSystemIsValid(pool) < 0)
+        return -1;
+
+    if ((rc = virStorageBackendFileSystemIsMounted(pool)) < 0)
+        return -1;
+
+    /* Short-circuit if already mounted */
+    if (rc == 1) {
+        VIR_INFO("Target '%s' is already mounted", def->target.path);
+        return 0;
+    }
+
+    if (!(src = virStorageBackendFileSystemGetPoolSource(pool)))
+        return -1;
+
+    cmd = virStorageBackendFileSystemMountCmd(def, src);
     if (virCommandRun(cmd, NULL) < 0)
         goto cleanup;
 
-- 
2.21.0