mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
conf: Use virXMLPropEnum more when parsing TPM
When parsing a TPM device plenty of virXMLPropString() + enum2int() combos are used. These can be replaced with virXMLPropEnum(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
c8992f6d97
commit
e31fc5bb2a
@ -10364,9 +10364,6 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt,
|
||||
int nnodes;
|
||||
size_t i;
|
||||
g_autofree char *path = NULL;
|
||||
g_autofree char *model = NULL;
|
||||
g_autofree char *backend = NULL;
|
||||
g_autofree char *version = NULL;
|
||||
g_autofree char *secretuuid = NULL;
|
||||
g_autofree char *persistent_state = NULL;
|
||||
g_autofree xmlNodePtr *backends = NULL;
|
||||
@ -10375,13 +10372,11 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt,
|
||||
|
||||
def = g_new0(virDomainTPMDef, 1);
|
||||
|
||||
model = virXMLPropString(node, "model");
|
||||
if (model != NULL &&
|
||||
(def->model = virDomainTPMModelTypeFromString(model)) <= 0) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("Unknown TPM frontend model '%s'"), model);
|
||||
if (virXMLPropEnum(node, "model",
|
||||
virDomainTPMModelTypeFromString,
|
||||
VIR_XML_PROP_NONZERO,
|
||||
&def->model) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
ctxt->node = node;
|
||||
|
||||
@ -10400,18 +10395,11 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt,
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(backend = virXMLPropString(backends[0], "type"))) {
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("missing TPM device backend type"));
|
||||
if (virXMLPropEnum(backends[0], "type",
|
||||
virDomainTPMBackendTypeFromString,
|
||||
VIR_XML_PROP_REQUIRED,
|
||||
&def->type) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((def->type = virDomainTPMBackendTypeFromString(backend)) < 0) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("Unknown TPM backend type '%s'"),
|
||||
backend);
|
||||
goto error;
|
||||
}
|
||||
|
||||
switch (def->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
@ -10424,14 +10412,11 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt,
|
||||
def->data.passthrough.source->data.file.path = g_steal_pointer(&path);
|
||||
break;
|
||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||
version = virXMLPropString(backends[0], "version");
|
||||
if (version &&
|
||||
(def->data.emulator.version = virDomainTPMVersionTypeFromString(version)) <= 0) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("Unsupported TPM version '%s'"),
|
||||
version);
|
||||
if (virXMLPropEnum(backends[0], "version",
|
||||
virDomainTPMVersionTypeFromString,
|
||||
VIR_XML_PROP_NONZERO,
|
||||
&def->data.emulator.version) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(def->data.emulator.source = virDomainChrSourceDefNew(xmlopt)))
|
||||
goto error;
|
||||
|
@ -1436,15 +1436,15 @@ typedef enum {
|
||||
#define VIR_DOMAIN_TPM_DEFAULT_DEVICE "/dev/tpm0"
|
||||
|
||||
struct _virDomainTPMDef {
|
||||
int type; /* virDomainTPMBackendType */
|
||||
virDomainTPMModel model;
|
||||
virDomainTPMBackendType type;
|
||||
virDomainDeviceInfo info;
|
||||
int model; /* virDomainTPMModel */
|
||||
union {
|
||||
struct {
|
||||
virDomainChrSourceDef *source;
|
||||
} passthrough;
|
||||
struct {
|
||||
int version; /* virDomainTPMVersion */
|
||||
virDomainTPMVersion version;
|
||||
virDomainChrSourceDef *source;
|
||||
char *storagepath;
|
||||
char *logfile;
|
||||
|
@ -9860,7 +9860,7 @@ qemuBuildTPMCommandLine(virCommand *cmd,
|
||||
g_autoptr(qemuFDPass) passtpm = NULL;
|
||||
g_autoptr(qemuFDPass) passcancel = NULL;
|
||||
|
||||
switch ((virDomainTPMBackendType) tpm->type) {
|
||||
switch (tpm->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: {
|
||||
VIR_AUTOCLOSE fdtpm = -1;
|
||||
VIR_AUTOCLOSE fdcancel = -1;
|
||||
|
@ -11753,7 +11753,7 @@ qemuDomainDeviceBackendChardevForeachOne(virDomainDeviceDef *dev,
|
||||
return cb(dev, dev->data.rng->source.chardev, opaque);
|
||||
|
||||
case VIR_DOMAIN_DEVICE_TPM:
|
||||
switch ((virDomainTPMBackendType) dev->data.tpm->type) {
|
||||
switch (dev->data.tpm->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
return cb(dev, dev->data.tpm->data.passthrough.source, opaque);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user