[PATCH 07/18] conf: use disk source accessors in lxc/

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

 



Part of a series of cleanups to use new accessor methods.

* src/lxc/lxc_cgroup.c (virLXCCgroupSetupDeviceACL): Use
accessors.
* src/lxc/lxc_controller.c (virLXCControllerSetupLoopDeviceDisk)
(virLXCControllerSetupNBDDeviceDisk)
(virLXCControllerSetupLoopDevices, virLXCControllerSetupDisk):
Likewise.
* src/lxc/lxc_driver.c (lxcDomainAttachDeviceDiskLive)
(lxcDomainDetachDeviceDiskLive): Likewise.

Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
---
 src/lxc/lxc_cgroup.c     |  6 ++---
 src/lxc/lxc_controller.c | 69 +++++++++++++++++++++++++++---------------------
 src/lxc/lxc_driver.c     | 27 +++++++++++--------
 3 files changed, 58 insertions(+), 44 deletions(-)

diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index 5a1718d..da5ccf5 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2012 Red Hat, Inc.
+ * Copyright (C) 2010-2014 Red Hat, Inc.
  * Copyright IBM Corp. 2008
  *
  * lxc_cgroup.c: LXC cgroup helpers
@@ -372,11 +372,11 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,

     VIR_DEBUG("Allowing any disk block devs");
     for (i = 0; i < def->ndisks; i++) {
-        if (def->disks[i]->type != VIR_DOMAIN_DISK_TYPE_BLOCK)
+        if (!virDomainDiskSourceIsBlockType(def->disks[i]))
             continue;

         if (virCgroupAllowDevicePath(cgroup,
-                                     def->disks[i]->src,
+                                     virDomainDiskGetSource(def->disks[i]),
                                      (def->disks[i]->readonly ?
                                       VIR_CGROUP_DEVICE_READ :
                                       VIR_CGROUP_DEVICE_RW) |
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 874e196..6ed13fb 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2013 Red Hat, Inc.
+ * Copyright (C) 2010-2014 Red Hat, Inc.
  * Copyright IBM Corp. 2008
  *
  * lxc_controller.c: linux container process controller
@@ -382,21 +382,24 @@ static int virLXCControllerSetupLoopDeviceDisk(virDomainDiskDefPtr disk)
 {
     int lofd;
     char *loname = NULL;
+    const char *src = virDomainDiskGetSource(disk);

-    if ((lofd = virFileLoopDeviceAssociate(disk->src, &loname)) < 0)
+    if ((lofd = virFileLoopDeviceAssociate(src, &loname)) < 0)
         return -1;

     VIR_DEBUG("Changing disk %s to use type=block for dev %s",
-              disk->src, loname);
+              src, loname);

     /*
      * We now change it into a block device type, so that
      * the rest of container setup 'just works'
      */
-    disk->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
-    VIR_FREE(disk->src);
-    disk->src = loname;
-    loname = NULL;
+    virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_BLOCK);
+    if (virDomainDiskSetSource(disk, loname) < 0) {
+        VIR_FREE(loname);
+        return -1;
+    }
+    VIR_FREE(loname);

     return lofd;
 }
@@ -435,28 +438,33 @@ static int virLXCControllerSetupNBDDeviceFS(virDomainFSDefPtr fs)
 static int virLXCControllerSetupNBDDeviceDisk(virDomainDiskDefPtr disk)
 {
     char *dev;
+    const char *src = virDomainDiskGetSource(disk);
+    int format = virDomainDiskGetFormat(disk);

-    if (disk->format <= VIR_STORAGE_FILE_NONE) {
+    if (format <= VIR_STORAGE_FILE_NONE) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("An explicit disk format must be specified"));
         return -1;
     }

-    if (virFileNBDDeviceAssociate(disk->src,
-                                  disk->format,
+    if (virFileNBDDeviceAssociate(src,
+                                  format,
                                   disk->readonly,
                                   &dev) < 0)
         return -1;

     VIR_DEBUG("Changing disk %s to use type=block for dev %s",
-              disk->src, dev);
+              src, dev);
     /*
      * We now change it into a block device type, so that
      * the rest of container setup 'just works'
      */
-    disk->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
-    VIR_FREE(disk->src);
-    disk->src = dev;
+    virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_BLOCK);
+    if (virDomainDiskSetSource(disk, dev) < 0) {
+        VIR_FREE(dev);
+        return -1;
+    }
+    VIR_FREE(dev);

     return 0;
 }
@@ -519,23 +527,25 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl)
     for (i = 0; i < ctrl->def->ndisks; i++) {
         virDomainDiskDefPtr disk = ctrl->def->disks[i];
         int fd;
+        const char *driver = virDomainDiskGetDriver(disk);
+        int format = virDomainDiskGetFormat(disk);

-        if (disk->type != VIR_DOMAIN_DISK_TYPE_FILE)
+        if (virDomainDiskGetType(disk) != VIR_DOMAIN_DISK_TYPE_FILE)
             continue;

         /* If no driverName is set, we prefer 'loop' for
          * dealing with raw or undefined formats, otherwise
          * we use 'nbd'.
          */
-        if (STREQ_NULLABLE(disk->driverName, "loop") ||
-            (!disk->driverName &&
-             (disk->format == VIR_STORAGE_FILE_RAW ||
-              disk->format == VIR_STORAGE_FILE_NONE))) {
-            if (disk->format != VIR_STORAGE_FILE_RAW &&
-                disk->format != VIR_STORAGE_FILE_NONE) {
+        if (STREQ_NULLABLE(driver, "loop") ||
+            (!driver &&
+             (format == VIR_STORAGE_FILE_RAW ||
+              format == VIR_STORAGE_FILE_NONE))) {
+            if (format != VIR_STORAGE_FILE_RAW &&
+                format != VIR_STORAGE_FILE_NONE) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                                _("disk format %s is not supported"),
-                               virStorageFileFormatTypeToString(disk->format));
+                               virStorageFileFormatTypeToString(format));
                 goto cleanup;
             }

@@ -553,8 +563,7 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl)
                 goto cleanup;
             }
             ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd;
-        } else if (STREQ_NULLABLE(disk->driverName, "nbd") ||
-                   !disk->driverName) {
+        } else if (!driver || STREQ(driver, "nbd")) {
             if (disk->cachemode != VIR_DOMAIN_DISK_CACHE_DEFAULT &&
                 disk->cachemode != VIR_DOMAIN_DISK_CACHE_DISABLE) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -567,7 +576,7 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl)
         } else {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("disk driver %s is not supported"),
-                           disk->driverName);
+                           driver);
             goto cleanup;
         }
     }
@@ -1662,12 +1671,12 @@ static int virLXCControllerSetupDisk(virLXCControllerPtr ctrl,
     mode_t mode;
     char *tmpsrc = def->src;

-    if (def->type != VIR_DOMAIN_DISK_TYPE_BLOCK) {
+    if (virDomainDiskGetType(def) != VIR_DOMAIN_DISK_TYPE_BLOCK) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Can't setup disk for non-block device"));
         goto cleanup;
     }
-    if (def->src == NULL) {
+    if (!tmpsrc) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Can't setup disk without media"));
         goto cleanup;
@@ -1679,14 +1688,14 @@ static int virLXCControllerSetupDisk(virLXCControllerPtr ctrl,

     if (stat(def->src, &sb) < 0) {
         virReportSystemError(errno,
-                             _("Unable to access %s"), def->src);
+                             _("Unable to access %s"), tmpsrc);
         goto cleanup;
     }

     if (!S_ISCHR(sb.st_mode) && !S_ISBLK(sb.st_mode)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("Disk source %s must be a character/block device"),
-                       def->src);
+                       tmpsrc);
         goto cleanup;
     }

@@ -1704,7 +1713,7 @@ static int virLXCControllerSetupDisk(virLXCControllerPtr ctrl,
      * to that normally implied by the device name
      */
     VIR_DEBUG("Creating dev %s (%d,%d) from %s",
-              dst, major(sb.st_rdev), minor(sb.st_rdev), def->src);
+              dst, major(sb.st_rdev), minor(sb.st_rdev), tmpsrc);
     if (mknod(dst, mode, sb.st_rdev) < 0) {
         virReportSystemError(errno,
                              _("Unable to create device %s"),
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 1ae04c5..5546861 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -4013,6 +4013,7 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver,
     struct stat sb;
     char *file = NULL;
     int perms;
+    const char *src = NULL;

     if (!priv->initpid) {
         virReportError(VIR_ERR_OPERATION_INVALID, "%s",
@@ -4026,12 +4027,13 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver,
         goto cleanup;
     }

-    if (def->type != VIR_DOMAIN_DISK_TYPE_BLOCK) {
+    if (!virDomainDiskSourceIsBlockType(def)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Can't setup disk for non-block device"));
         goto cleanup;
     }
-    if (def->src == NULL) {
+    src = virDomainDiskGetSource(def);
+    if (src == NULL) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Can't setup disk without media"));
         goto cleanup;
@@ -4043,16 +4045,16 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver,
         goto cleanup;
     }

-    if (stat(def->src, &sb) < 0) {
+    if (stat(src, &sb) < 0) {
         virReportSystemError(errno,
-                             _("Unable to access %s"), def->src);
+                             _("Unable to access %s"), src);
         goto cleanup;
     }

     if (!S_ISBLK(sb.st_mode)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("Disk source %s must be a block device"),
-                       def->src);
+                       src);
         goto cleanup;
     }

@@ -4093,7 +4095,7 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver,
                                 minor(sb.st_rdev),
                                 perms) < 0)
             VIR_WARN("cannot deny device %s for domain %s",
-                     def->src, vm->def->name);
+                     src, vm->def->name);
         goto cleanup;
     }

@@ -4102,7 +4104,8 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver,
     ret = 0;

 cleanup:
-    virDomainAuditDisk(vm, NULL, def->src, "attach", ret == 0);
+    if (src)
+        virDomainAuditDisk(vm, NULL, src, "attach", ret == 0);
     VIR_FREE(file);
     return ret;
 }
@@ -4576,6 +4579,7 @@ lxcDomainDetachDeviceDiskLive(virDomainObjPtr vm,
     virDomainDiskDefPtr def = NULL;
     int idx, ret = -1;
     char *dst = NULL;
+    const char *src;

     if (!priv->initpid) {
         virReportError(VIR_ERR_OPERATION_INVALID, "%s",
@@ -4592,6 +4596,7 @@ lxcDomainDetachDeviceDiskLive(virDomainObjPtr vm,
     }

     def = vm->def->disks[idx];
+    src = virDomainDiskGetSource(def);

     if (virAsprintf(&dst, "/dev/%s", def->dst) < 0)
         goto cleanup;
@@ -4603,14 +4608,14 @@ lxcDomainDetachDeviceDiskLive(virDomainObjPtr vm,
     }

     if (lxcDomainAttachDeviceUnlink(vm, dst) < 0) {
-        virDomainAuditDisk(vm, def->src, NULL, "detach", false);
+        virDomainAuditDisk(vm, src, NULL, "detach", false);
         goto cleanup;
     }
-    virDomainAuditDisk(vm, def->src, NULL, "detach", true);
+    virDomainAuditDisk(vm, src, NULL, "detach", true);

-    if (virCgroupDenyDevicePath(priv->cgroup, def->src, VIR_CGROUP_DEVICE_RWM) != 0)
+    if (virCgroupDenyDevicePath(priv->cgroup, src, VIR_CGROUP_DEVICE_RWM) != 0)
         VIR_WARN("cannot deny device %s for domain %s",
-                 def->src, vm->def->name);
+                 src, vm->def->name);

     virDomainDiskRemove(vm->def, idx);
     virDomainDiskDefFree(def);
-- 
1.8.5.3

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