[PATCH 05/23] qemu_conf: split out virQEMUDriverConfigLoadSWTPMEntry

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

 



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

Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 src/qemu/qemu_conf.c | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 837bff6b30..325e5ccfd5 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -423,6 +423,30 @@ 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 +457,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 +894,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 +907,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;
 }
-- 
2.20.1

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

  Powered by Linux