[PATCH 05/14] virDomainSmartcardDef: Declare 'type' as virDomainSmartcardType

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

 



Use 'virXMLPropEnum' to parse it and fix all switch statements which
didn't include the VIR_DOMAIN_SMARTCARD_TYPE_LAST case.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/conf/domain_conf.c          | 23 +++++++----------------
 src/conf/domain_conf.h          |  2 +-
 src/qemu/qemu_command.c         |  1 +
 src/qemu/qemu_validate.c        |  1 +
 src/security/security_selinux.c | 10 ++++------
 5 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4799070bc4..aeb64c9c83 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2884,6 +2884,7 @@ void virDomainSmartcardDefFree(virDomainSmartcardDef *def)
         virObjectUnref(def->data.passthru);
         break;

+    case VIR_DOMAIN_SMARTCARD_TYPE_LAST:
     default:
         break;
     }
@@ -11602,7 +11603,6 @@ virDomainSmartcardDefParseXML(virDomainXMLOption *xmlopt,
                               unsigned int flags)
 {
     g_autoptr(virDomainSmartcardDef) def = NULL;
-    g_autofree char *mode = NULL;
     g_autofree char *type = NULL;
     g_autofree xmlNodePtr *certificates = NULL;
     int n = 0;
@@ -11611,18 +11611,9 @@ virDomainSmartcardDefParseXML(virDomainXMLOption *xmlopt,
     ctxt->node = node;
     def = g_new0(virDomainSmartcardDef, 1);

-    mode = virXMLPropString(node, "mode");
-    if (mode == NULL) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("missing smartcard device mode"));
-        return NULL;
-    }
-    if ((def->type = virDomainSmartcardTypeFromString(mode)) < 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("unknown smartcard device mode: %s"),
-                       mode);
+    if (virXMLPropEnum(node, "mode", virDomainSmartcardTypeFromString,
+                       VIR_XML_PROP_REQUIRED, &def->type) < 0)
         return NULL;
-    }

     switch (def->type) {
     case VIR_DOMAIN_SMARTCARD_TYPE_HOST:
@@ -11687,9 +11678,9 @@ virDomainSmartcardDefParseXML(virDomainXMLOption *xmlopt,

         break;

+    case VIR_DOMAIN_SMARTCARD_TYPE_LAST:
     default:
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("unknown smartcard mode"));
+        virReportEnumRangeError(virDomainSmartcardType, def->type);
         return NULL;
     }

@@ -25406,9 +25397,9 @@ virDomainSmartcardDefFormat(virBuffer *buf,
         virDomainChrSourceDefFormat(&childBuf, def->data.passthru, flags);
         break;

+    case VIR_DOMAIN_SMARTCARD_TYPE_LAST:
     default:
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("unexpected smartcard type %d"), def->type);
+        virReportEnumRangeError(virDomainSmartcardType, def->type);
         return -1;
     }
     virDomainDeviceInfoFormat(&childBuf, &def->info, flags);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index c1871b1757..55be01bbcf 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1320,7 +1320,7 @@ typedef enum {
 #define VIR_DOMAIN_SMARTCARD_DEFAULT_DATABASE "/etc/pki/nssdb"

 struct _virDomainSmartcardDef {
-    int type; /* virDomainSmartcardType */
+    virDomainSmartcardType type;
     union {
         /* no extra data for 'host' */
         struct {
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index fae2d1569c..2d7a6ebde7 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -9146,6 +9146,7 @@ qemuBuildSmartcardCommandLine(virLogManager *logManager,
                           smartcard->info.alias);
         break;

+    case VIR_DOMAIN_SMARTCARD_TYPE_LAST:
     default:
         virReportEnumRangeError(virDomainSmartcardType, smartcard->type);
         return -1;
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 9865e29637..48d5c172c5 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -2117,6 +2117,7 @@ qemuValidateDomainSmartcardDef(const virDomainSmartcardDef *def,
             return -1;
         break;

+    case VIR_DOMAIN_SMARTCARD_TYPE_LAST:
     default:
         virReportEnumRangeError(virDomainSmartcardType, def->type);
         return -1;
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index cc72453329..622a8f4c02 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -2696,10 +2696,9 @@ virSecuritySELinuxRestoreSecuritySmartcardCallback(virDomainDef *def,
         return virSecuritySELinuxRestoreChardevLabel(mgr, def,
                                                      dev->data.passthru, false);

+    case VIR_DOMAIN_SMARTCARD_TYPE_LAST:
     default:
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("unknown smartcard type %d"),
-                       dev->type);
+        virReportEnumRangeError(virDomainSmartcardType, dev->type);
         return -1;
     }

@@ -3103,10 +3102,9 @@ virSecuritySELinuxSetSecuritySmartcardCallback(virDomainDef *def,
         return virSecuritySELinuxSetChardevLabel(mgr, def,
                                                  dev->data.passthru, false);

+    case VIR_DOMAIN_SMARTCARD_TYPE_LAST:
     default:
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("unknown smartcard type %d"),
-                       dev->type);
+        virReportEnumRangeError(virDomainSmartcardType, dev->type);
         return -1;
     }

-- 
2.31.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