qemu_conf: split out virQEMUDriverConfigLoadSWTPMEntry

Split out parts of the config parsing code to make
the parent function easier to read.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
Ján Tomko 2019-01-14 21:18:44 +01:00
parent d051e7f703
commit d447293893

View File

@ -423,6 +423,31 @@ virQEMUDriverConfigHugeTLBFSInit(virHugeTLBFSPtr hugetlbfs,
}
static int
virQEMUDriverConfigLoadSWTPMEntry(virQEMUDriverConfigPtr cfg,
virConfPtr conf)
{
char *swtpm_user = NULL, *swtpm_group = NULL;
int ret = -1;
if (virConfGetValueString(conf, "swtpm_user", &swtpm_user) < 0)
goto cleanup;
if (swtpm_user && virGetUserID(swtpm_user, &cfg->swtpm_user) < 0)
goto cleanup;
if (virConfGetValueString(conf, "swtpm_group", &swtpm_group) < 0)
goto cleanup;
if (swtpm_group && virGetGroupID(swtpm_group, &cfg->swtpm_group) < 0)
goto cleanup;
ret = 0;
cleanup:
VIR_FREE(swtpm_user);
VIR_FREE(swtpm_group);
return ret;
}
int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
const char *filename,
bool privileged)
@ -433,7 +458,6 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
size_t i, j;
char *stdioHandler = NULL;
char *user = NULL, *group = NULL;
char *swtpm_user = NULL, *swtpm_group = NULL;
char **controllers = NULL;
char **hugetlbfs = NULL;
char **nvram = NULL;
@ -871,14 +895,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
if (virConfGetValueString(conf, "memory_backing_dir", &cfg->memoryBackingDir) < 0)
goto cleanup;
if (virConfGetValueString(conf, "swtpm_user", &swtpm_user) < 0)
goto cleanup;
if (swtpm_user && virGetUserID(swtpm_user, &cfg->swtpm_user) < 0)
goto cleanup;
if (virConfGetValueString(conf, "swtpm_group", &swtpm_group) < 0)
goto cleanup;
if (swtpm_group && virGetGroupID(swtpm_group, &cfg->swtpm_group) < 0)
if (virQEMUDriverConfigLoadSWTPMEntry(cfg, conf) < 0)
goto cleanup;
ret = 0;
@ -891,8 +908,6 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
VIR_FREE(corestr);
VIR_FREE(user);
VIR_FREE(group);
VIR_FREE(swtpm_user);
VIR_FREE(swtpm_group);
virConfFree(conf);
return ret;
}