[PATCH 11/13] virshFindDisk: Sanitize removable media check

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

 



The XPath lookup guarantees that the top level element is always 'disk'
so there's no need to check that it actually is. We can also remove the
two unnecessary temporary variables.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 tools/virsh-domain.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 1beaacd5e9..8bd058a33a 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -12658,22 +12658,13 @@ virshFindDisk(const char *doc,

     /* search disk using @path */
     for (i = 0; i < nnodes; i++) {
-        bool is_supported = true;
-
         if (type == VIRSH_FIND_DISK_CHANGEABLE) {
-            xmlNodePtr n = nodes[i];
-            is_supported = false;
+            g_autofree char *device = virXMLPropString(nodes[i], "device");

             /* Check if the disk is CDROM or floppy disk */
-            if (virXMLNodeNameEqual(n, "disk")) {
-                g_autofree char *device_value = virXMLPropString(n, "device");
-
-                if (STREQ(device_value, "cdrom") ||
-                    STREQ(device_value, "floppy"))
-                    is_supported = true;
-            }
-
-            if (!is_supported)
+            if (device &&
+                STRNEQ(device, "cdrom") &&
+                STRNEQ(device, "floppy"))
                 continue;
         }

-- 
2.38.1




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

  Powered by Linux