[PATCH 3/7] Re-arrange code setting up ifs/disk loop devices for LXC

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

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

The current code for setting up loop devices to LXC disks first
does a switch() based on the disk format, then looks at the
disk driver name. Reverse this so it first looks at the driver
name, and then the disk format. This is more useful since the
list of supported disk formats depends on what driver is used.

The code for setting loop devices for LXC fs entries also needs
to have the same logic added, now the XML schema supports this.

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 src/lxc/lxc_controller.c | 76 +++++++++++++++++++++++++++---------------------
 1 file changed, 43 insertions(+), 33 deletions(-)

diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 1508b9c..8f3ca6a 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -415,17 +415,31 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl)
         if (fs->type != VIR_DOMAIN_FS_TYPE_FILE)
             continue;
 
-        fd = virLXCControllerSetupLoopDeviceFS(fs);
-        if (fd < 0)
-            goto cleanup;
+        if (fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_LOOP) {
+            if (fs->format != VIR_STORAGE_FILE_RAW &&
+                fs->format != VIR_STORAGE_FILE_NONE) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("fs format %s is not supported"),
+                               virStorageFileFormatTypeToString(fs->format));
+                goto cleanup;
+            }
 
-        VIR_DEBUG("Saving loop fd %d", fd);
-        if (VIR_EXPAND_N(ctrl->loopDevFds, ctrl->nloopDevs, 1) < 0) {
-            VIR_FORCE_CLOSE(fd);
-            virReportOOMError();
-            goto cleanup;
+            fd = virLXCControllerSetupLoopDeviceFS(fs);
+            if (fd < 0)
+                goto cleanup;
+
+            VIR_DEBUG("Saving loop fd %d", fd);
+            if (VIR_EXPAND_N(ctrl->loopDevFds, ctrl->nloopDevs, 1) < 0) {
+                VIR_FORCE_CLOSE(fd);
+                virReportOOMError();
+                goto cleanup;
+            }
+            ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd;
+        } else {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("fs driver %s is not supported"),
+                           virDomainFSDriverTypeTypeToString(fs->fsdriver));
         }
-        ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd;
     }
 
     for (i = 0 ; i < ctrl->def->ndisks ; i++) {
@@ -435,40 +449,36 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl)
         if (disk->type != VIR_DOMAIN_DISK_TYPE_FILE)
             continue;
 
-        switch (disk->format) {
-            /* We treat 'none' as meaning 'raw' since we
-             * don't want to go into the auto-probing
-             * business for security reasons
-             */
-        case VIR_STORAGE_FILE_RAW:
-        case VIR_STORAGE_FILE_NONE:
-            if (disk->driverName &&
-                STRNEQ(disk->driverName, "loop")) {
+        if (!disk->driverName ||
+            STREQ(disk->driverName, "loop")) {
+            if (disk->format != VIR_STORAGE_FILE_RAW &&
+                disk->format != VIR_STORAGE_FILE_NONE) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                               _("disk driver %s is not supported"),
-                               disk->driverName);
+                               _("disk format %s is not supported"),
+                               virStorageFileFormatTypeToString(disk->format));
                 goto cleanup;
             }
 
+            /* We treat 'none' as meaning 'raw' since we
+             * don't want to go into the auto-probing
+             * business for security reasons
+             */
             fd = virLXCControllerSetupLoopDeviceDisk(disk);
             if (fd < 0)
                 goto cleanup;
-            break;
 
-        default:
+            VIR_DEBUG("Saving loop fd %d", fd);
+            if (VIR_EXPAND_N(ctrl->loopDevFds, ctrl->nloopDevs, 1) < 0) {
+                VIR_FORCE_CLOSE(fd);
+                virReportOOMError();
+                goto cleanup;
+            }
+            ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd;
+        } else {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("disk format %s is not supported"),
-                           virStorageFileFormatTypeToString(disk->format));
-            goto cleanup;
-        }
-
-        VIR_DEBUG("Saving loop fd %d", fd);
-        if (VIR_EXPAND_N(ctrl->loopDevFds, ctrl->nloopDevs, 1) < 0) {
-            VIR_FORCE_CLOSE(fd);
-            virReportOOMError();
-            goto cleanup;
+                           _("disk driver %s is not supported"),
+                           disk->driverName);
         }
-        ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd;
     }
 
     VIR_DEBUG("Setup all loop devices");
-- 
1.7.11.7

--
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]