]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Introduce virFileMoveMount
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 11 Jan 2017 10:29:00 +0000 (11:29 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 11 Jan 2017 17:06:30 +0000 (18:06 +0100)
This is a simple wrapper over mount(). However, not every system
out there is capable of moving a mount point. Therefore, instead
of having to deal with this fact in all the places of our code we
can have a simple wrapper and deal with this fact at just one
place.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/libvirt_private.syms
src/qemu/qemu_domain.c
src/util/virfile.c
src/util/virfile.h

index d02d23b3595c5e500c64ab503451b33f6ea71267..70ed87b9537b3b071452b54a12ca82e55b43ceb3 100644 (file)
@@ -1605,6 +1605,7 @@ virFileMakeParentPath;
 virFileMakePath;
 virFileMakePathWithMode;
 virFileMatchesNameSuffix;
+virFileMoveMount;
 virFileNBDDeviceAssociate;
 virFileOpenAs;
 virFileOpenTty;
index 473d0c1a2c047c5acb02638e5aa64e92eaf794b0..8602f01c77eb4c23f6d671785915d9b9dad49d50 100644 (file)
@@ -7332,7 +7332,6 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver,
                          virDomainObjPtr vm)
 {
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
-    const unsigned long mount_flags = MS_MOVE;
     char *devPath = NULL;
     char **devMountsPath = NULL, **devMountsSavePath = NULL;
     size_t ndevMountsPath = 0, i;
@@ -7376,13 +7375,8 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver,
             goto cleanup;
         }
 
-        if (mount(devMountsPath[i], devMountsSavePath[i],
-                  NULL, mount_flags, NULL) < 0) {
-            virReportSystemError(errno,
-                                 _("Unable to move %s mount"),
-                                 devMountsPath[i]);
+        if (virFileMoveMount(devMountsPath[i], devMountsSavePath[i]) < 0)
             goto cleanup;
-        }
     }
 
     if (qemuDomainSetupAllDisks(driver, vm, devPath) < 0)
@@ -7403,12 +7397,8 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver,
     if (qemuDomainSetupAllRNGs(driver, vm, devPath) < 0)
         goto cleanup;
 
-    if (mount(devPath, "/dev", NULL, mount_flags, NULL) < 0) {
-        virReportSystemError(errno,
-                             _("Failed to mount %s on /dev"),
-                             devPath);
+    if (virFileMoveMount(devPath, "/dev") < 0)
         goto cleanup;
-    }
 
     for (i = 0; i < ndevMountsPath; i++) {
         if (devMountsSavePath[i] == devPath)
@@ -7420,14 +7410,8 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver,
             goto cleanup;
         }
 
-        if (mount(devMountsSavePath[i], devMountsPath[i],
-                  NULL, mount_flags, NULL) < 0) {
-            virReportSystemError(errno,
-                                 _("Failed to mount %s on %s"),
-                                 devMountsSavePath[i],
-                                 devMountsPath[i]);
+        if (virFileMoveMount(devMountsSavePath[i], devMountsPath[i]) < 0)
             goto cleanup;
-        }
     }
 
     ret = 0;
index 99157be162b4e5d80d4062b0ee2dfbfa55c91171..bf8099e3427626f195f0e4d3619970468a411537 100644 (file)
@@ -3610,6 +3610,24 @@ virFileBindMountDevice(const char *src,
     return 0;
 }
 
+
+int
+virFileMoveMount(const char *src,
+                 const char *dst)
+{
+    const unsigned long mount_flags = MS_MOVE;
+
+    if (mount(src, dst, NULL, mount_flags, NULL) < 0) {
+        virReportSystemError(errno,
+                             _("Unable to move %s mount to %s"),
+                             src, dst);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 #else /* !defined(__linux__) || !defined(HAVE_SYS_MOUNT_H) */
 
 int
@@ -3630,6 +3648,16 @@ virFileBindMountDevice(const char *src ATTRIBUTE_UNUSED,
                          _("mount is not supported on this platform."));
     return -1;
 }
+
+
+int
+virFileMoveMount(const char *src ATTRIBUTE_UNUSED,
+                 const char *dst ATTRIBUTE_UNUSED)
+{
+    virReportSystemError(ENOSYS, "%s",
+                         _("mount move is not supported on this platform."));
+    return -1;
+}
 #endif /* !defined(__linux__) || !defined(HAVE_SYS_MOUNT_H) */
 
 
index 571e5bdc86c1672f7ad5b81927850620dd8f96be..0343acd5b8460bac73c837f5f9724b4fb52ebc08 100644 (file)
@@ -318,6 +318,9 @@ int virFileSetupDev(const char *path,
 int virFileBindMountDevice(const char *src,
                            const char *dst);
 
+int virFileMoveMount(const char *src,
+                     const char *dst);
+
 int virFileGetACLs(const char *file,
                    void **acl);