[libvirt] [PATCH] (qemuTeardownDiskCgroup): avoid dead code

Jim Meyering jim at meyering.net
Mon May 17 20:55:38 UTC 2010


Jim Meyering wrote:

> It's a good thing the latter while loop condition
> could never be true -- otherwise it'd be an infloop.
>
>>From 319fd4536555d68316a2cb7967f1093be8de3945 Mon Sep 17 00:00:00 2001
> From: Jim Meyering <meyering at redhat.com>
> Date: Mon, 17 May 2010 22:50:21 +0200
> Subject: [PATCH] (qemuTeardownDiskCgroup): avoid dead code
>
> * src/qemu/qemu_driver.c (qemuTeardownDiskCgroup): Convert
> bogus while...while loop to the intended do...while loop.

Wait a minute...
There's another, just like that:

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 3e44407..3a93418 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2962,7 +2962,7 @@ static int qemuSetupDiskCgroup(virCgroupPtr cgroup,
     char *path = disk->src;
     int ret = -1;

-    while (path != NULL) {
+    do {
         virStorageFileMetadata meta;
         int rc;

Here's the combined patch:

>From 8c53e149c499e0f10d2950b77dd459bd9f85b239 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Mon, 17 May 2010 22:50:21 +0200
Subject: [PATCH] (qemu*DiskCgroup): avoid dead code

* src/qemu/qemu_driver.c (qemuTeardownDiskCgroup): Convert
bogus while...while loop to the intended do...while loop.
(qemuSetupDiskCgroup): Likewise.
---
 src/qemu/qemu_driver.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 16a9646..3a93418 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2933,113 +2933,113 @@ qemuDomainReAttachHostDevices(struct qemud_driver *driver,
             virErrorPtr err = virGetLastError();
             VIR_ERROR(_("Failed to reset PCI device: %s"),
                       err ? err->message : "");
             virResetError(err);
         }
     }

     for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
         pciDevice *dev = pciDeviceListGet(pcidevs, i);
         qemudReattachManagedDevice(dev);
     }

     pciDeviceListFree(pcidevs);
 }

 static const char *const defaultDeviceACL[] = {
     "/dev/null", "/dev/full", "/dev/zero",
     "/dev/random", "/dev/urandom",
     "/dev/ptmx", "/dev/kvm", "/dev/kqemu",
     "/dev/rtc", "/dev/hpet", "/dev/net/tun",
     NULL,
 };
 #define DEVICE_PTY_MAJOR 136
 #define DEVICE_SND_MAJOR 116

 static int qemuSetupDiskCgroup(virCgroupPtr cgroup,
                                virDomainObjPtr vm,
                                virDomainDiskDefPtr disk)
 {
     char *path = disk->src;
     int ret = -1;

-    while (path != NULL) {
+    do {
         virStorageFileMetadata meta;
         int rc;

         VIR_DEBUG("Process path %s for disk", path);
         rc = virCgroupAllowDevicePath(cgroup, path);
         if (rc != 0) {
             /* Get this for non-block devices */
             if (rc == -EINVAL) {
                 VIR_DEBUG("Ignoring EINVAL for %s", path);
             } else {
                 virReportSystemError(-rc,
                                      _("Unable to allow device %s for %s"),
                                      path, vm->def->name);
                 if (path != disk->src)
                     VIR_FREE(path);
                 goto cleanup;
             }
         }

         memset(&meta, 0, sizeof(meta));

         rc = virStorageFileGetMetadata(path, &meta);

         if (path != disk->src)
             VIR_FREE(path);
         path = NULL;

         if (rc < 0)
             goto cleanup;

         path = meta.backingStore;
     } while (path != NULL);

     ret = 0;

 cleanup:
     return ret;
 }


 static int qemuTeardownDiskCgroup(virCgroupPtr cgroup,
                                   virDomainObjPtr vm,
                                   virDomainDiskDefPtr disk)
 {
     char *path = disk->src;
     int ret = -1;

-    while (path != NULL) {
+    do {
         virStorageFileMetadata meta;
         int rc;

         VIR_DEBUG("Process path %s for disk", path);
         rc = virCgroupDenyDevicePath(cgroup, path);
         if (rc != 0) {
             /* Get this for non-block devices */
             if (rc == -EINVAL) {
                 VIR_DEBUG("Ignoring EINVAL for %s", path);
             } else {
                 virReportSystemError(-rc,
                                      _("Unable to deny device %s for %s"),
                                      path, vm->def->name);
                 if (path != disk->src)
                     VIR_FREE(path);
                 goto cleanup;
             }
         }

         memset(&meta, 0, sizeof(meta));

         rc = virStorageFileGetMetadata(path, &meta);

         if (path != disk->src)
             VIR_FREE(path);
         path = NULL;

         if (rc < 0)
             goto cleanup;

         path = meta.backingStore;
     } while (path != NULL);
--
1.7.1.250.g7d1e8




More information about the libvir-list mailing list