[libvirt] [PATCH] fix virsh dominfo returns error when virNodeGetSecurityModel() is not supported.

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

 



Hi all

I try virsh dominfo in upstream libvirt on xen machine,
the commands returns -1 as follows:

[root@vmi20 ~]# virsh dominfo rhel53rc2_pv_sdb3
Id:             1
Name:           rhel53rc2_pv_sdb3
UUID:           05ba9be8-f4e9-e208-11c7-fc936655cd8e
OS Type:        linux
State:          idle
CPU(s):         2
CPU time:       8.8s
Max memory:     1048576 kB
Used memory:    716800 kB
Autostart:      disable
error: this function is not supported by the hypervisor:
virNodeGetSecurityModel

[root@vmi20 ~]# echo $?
1

The explanation of virNodeGetSecurityModel() and
virNodeGetSecurityModel() in libvirt.c is return -2
when hypervisor drivers don't support these operations.
But these functions return -1 in this case, and so
cmdDominfo() in virsh.c returns FALSE.

I make a patch.
  - virNodeGetSecurityModel() and virNodeGetSecurityModel()
    return -2 when drivers don't supprted these operations.
  - In CmdDominfo(), it is no operation when virNodeGetSecurityModel()
    and virNodeGetSecurityModel() return -2.

Signed-off-by: Tatsuro Enokura <fj2026af@xxxxxxxxxxxxxxxxx>

Thanks
Tatsuro Enokura
Index: src/libvirt.c
===================================================================
RCS file: /data/cvs/libvirt/src/libvirt.c,v
retrieving revision 1.214
diff -u -r1.214 libvirt.c
--- src/libvirt.c	12 Jun 2009 13:20:13 -0000	1.214
+++ src/libvirt.c	18 Jun 2009 02:51:23 -0000
@@ -4412,8 +4412,9 @@
     if (conn->driver->domainGetSecurityLabel)
         return conn->driver->domainGetSecurityLabel(domain, seclabel);
 
+    /* the operation is not supported */
     virLibConnWarning(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
-    return -1;
+    return -2;
 }
 
 /**
@@ -4442,8 +4443,9 @@
     if (conn->driver->nodeGetSecurityModel)
         return conn->driver->nodeGetSecurityModel(conn, secmodel);
 
+    /* the operation is not supported */
     virLibConnWarning(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
-    return -1;
+    return -2;
 }
 
 /**
Index: src/virsh.c
===================================================================
RCS file: /data/cvs/libvirt/src/virsh.c,v
retrieving revision 1.210
diff -u -r1.210 virsh.c
--- src/virsh.c	3 Jun 2009 12:13:52 -0000	1.210
+++ src/virsh.c	18 Jun 2009 02:51:25 -0000
@@ -1582,7 +1582,7 @@
     virDomainPtr dom;
     virSecurityModel secmodel;
     virSecurityLabel seclabel;
-    int ret = TRUE, autostart;
+    int ret = TRUE, ret_code, autostart;
     unsigned int id;
     char *str, uuid[VIR_UUID_STRING_BUFLEN];
 
@@ -1642,9 +1642,13 @@
 
     /* Security model and label information */
     memset(&secmodel, 0, sizeof secmodel);
-    if (virNodeGetSecurityModel(ctl->conn, &secmodel) == -1) {
+    ret_code = virNodeGetSecurityModel(ctl->conn, &secmodel);
+    if (ret_code == -1) {
+        /* operation failure */
         virDomainFree(dom);
         return FALSE;
+    } else if (ret_code == -2) {
+        /* operation is not supported. noop */
     } else {
         /* Only print something if a security model is active */
         if (secmodel.model[0] != '\0') {
@@ -1653,9 +1657,13 @@
 
             /* Security labels are only valid for active domains */
             memset(&seclabel, 0, sizeof seclabel);
-            if (virDomainGetSecurityLabel(dom, &seclabel) == -1) {
+            ret_code = virDomainGetSecurityLabel(dom, &seclabel);
+            if (ret == -1) {
+                /* operation failure */
                 virDomainFree(dom);
                 return FALSE;
+            } else if (ret == -2) {
+                /* operation is not supported. noop */
             } else {
                 if (seclabel.label[0] != '\0')
                     vshPrint(ctl, "%-15s %s (%s)\n", _("Security label:"),
--
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]