[PATCH 03/22] qemu: driver: Use 'qemuDomainSaveStatus' for saving status XML

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

 



We've got multiple random open-coded versions. Switch to the helper
function which doesn't report errors as they'd be mostly wrong as the
operation was indeed successful.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c | 96 ++++++++++++------------------------------
 1 file changed, 26 insertions(+), 70 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 2de17aaa4e..39347f84c7 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1869,8 +1869,7 @@ static int qemuDomainSuspend(virDomainPtr dom)
         if (qemuProcessStopCPUs(driver, vm, reason, QEMU_ASYNC_JOB_NONE) < 0)
             goto endjob;
     }
-    if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
-        goto endjob;
+    qemuDomainSaveStatus(vm);
     ret = 0;

  endjob:
@@ -1927,8 +1926,7 @@ static int qemuDomainResume(virDomainPtr dom)
             goto endjob;
         }
     }
-    if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
-        goto endjob;
+    qemuDomainSaveStatus(vm);
     ret = 0;

  endjob:
@@ -2522,8 +2520,7 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPtr dom, int period,
         }

         def->memballoon->period = period;
-        if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
-            goto endjob;
+        qemuDomainSaveStatus(vm);
     }

     if (persistentDef) {
@@ -3623,7 +3620,6 @@ processGuestPanicEvent(virQEMUDriver *driver,
 {
     qemuDomainObjPrivate *priv = vm->privateData;
     virObjectEvent *event = NULL;
-    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
     bool removeInactive = false;
     unsigned long flags = VIR_DUMP_MEMORY_ONLY;

@@ -3648,10 +3644,7 @@ processGuestPanicEvent(virQEMUDriver *driver,

     virObjectEventStateQueue(driver->domainEventState, event);

-    if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) {
-        VIR_WARN("Unable to save status on vm %s after state change",
-                 vm->def->name);
-    }
+    qemuDomainSaveStatus(vm);

     if (virDomainLockProcessPause(driver->lockManager, vm, &priv->lockState) < 0)
         VIR_WARN("Unable to release lease on %s", vm->def->name);
@@ -3704,7 +3697,6 @@ processDeviceDeletedEvent(virQEMUDriver *driver,
                           virDomainObj *vm,
                           const char *devAlias)
 {
-    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
     virDomainDeviceDef dev;

     VIR_DEBUG("Removing device %s from domain %p %s",
@@ -3728,9 +3720,7 @@ processDeviceDeletedEvent(virQEMUDriver *driver,
             goto endjob;
     }

-    if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
-        VIR_WARN("unable to save domain status after removing device %s",
-                 devAlias);
+    qemuDomainSaveStatus(vm);

  endjob:
     qemuDomainObjEndJob(driver, vm);
@@ -4045,7 +4035,6 @@ processSerialChangedEvent(virQEMUDriver *driver,
                           const char *devAlias,
                           bool connected)
 {
-    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
     virDomainChrDeviceState newstate;
     virObjectEvent *event = NULL;
     virDomainDeviceDef dev;
@@ -4096,9 +4085,7 @@ processSerialChangedEvent(virQEMUDriver *driver,

     dev.data.chr->state = newstate;

-    if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
-        VIR_WARN("unable to save status of domain %s after updating state of "
-                 "channel %s", vm->def->name, devAlias);
+    qemuDomainSaveStatus(vm);

     if (STREQ_NULLABLE(dev.data.chr->target.name, "org.qemu.guest_agent.0")) {
         if (newstate == VIR_DOMAIN_CHR_DEVICE_STATE_CONNECTED) {
@@ -4520,7 +4507,6 @@ qemuDomainPinVcpuLive(virDomainObj *vm,
                       virDomainDef *def,
                       int vcpu,
                       virQEMUDriver *driver,
-                      virQEMUDriverConfig *cfg,
                       virBitmap *cpumap)
 {
     virBitmap *tmpmap = NULL;
@@ -4572,8 +4558,7 @@ qemuDomainPinVcpuLive(virDomainObj *vm,
     vcpuinfo->cpumask = tmpmap;
     tmpmap = NULL;

-    if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
-        goto cleanup;
+    qemuDomainSaveStatus(vm);

     if (g_snprintf(paramField, VIR_TYPED_PARAM_FIELD_LENGTH,
                    VIR_DOMAIN_TUNABLE_CPU_VCPUPIN, vcpu) < 0) {
@@ -4646,7 +4631,7 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
     }

     if (def &&
-        qemuDomainPinVcpuLive(vm, def, vcpu, driver, cfg, pcpumap) < 0)
+        qemuDomainPinVcpuLive(vm, def, vcpu, driver, pcpumap) < 0)
         goto endjob;

     if (persistentDef) {
@@ -4787,8 +4772,7 @@ qemuDomainPinEmulator(virDomainPtr dom,
         virBitmapFree(def->cputune.emulatorpin);
         def->cputune.emulatorpin = virBitmapNewCopy(pcpumap);

-        if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
-            goto endjob;
+        qemuDomainSaveStatus(vm);

         str = virBitmapFormat(pcpumap);
         if (virTypedParamsAddString(&eventParams, &eventNparams,
@@ -5247,8 +5231,7 @@ qemuDomainPinIOThread(virDomainPtr dom,
         if (virProcessSetAffinity(iothrid->thread_id, pcpumap, false) < 0)
             goto endjob;

-        if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
-            goto endjob;
+        qemuDomainSaveStatus(vm);

         if (g_snprintf(paramField, VIR_TYPED_PARAM_FIELD_LENGTH,
                        VIR_DOMAIN_TUNABLE_CPU_IOTHREADSPIN, iothread_id) < 0) {
@@ -5694,8 +5677,7 @@ qemuDomainChgIOThread(virQEMUDriver *driver,

         }

-        if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
-            goto endjob;
+        qemuDomainSaveStatus(vm);
     }

     if (persistentDef) {
@@ -7825,8 +7807,7 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObj *vm,
          * changed even if we failed to attach the device. For example,
          * a new controller may be created.
          */
-        if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
-            return -1;
+        qemuDomainSaveStatus(vm);
     }

     /* Finally, if no error until here, we can save config. */
@@ -7964,15 +7945,8 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom,
          * device we're going to update. */
         if ((ret = qemuDomainUpdateDeviceLive(vm, dev_copy, dom, force)) < 0)
             goto endjob;
-        /*
-         * update domain status forcibly because the domain status may be
-         * changed even if we failed to attach the device. For example,
-         * a new controller may be created.
-         */
-        if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) {
-            ret = -1;
-            goto endjob;
-        }
+
+        qemuDomainSaveStatus(vm);
     }

     /* Finally, if no error until here, we can save config. */
@@ -8057,13 +8031,7 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriver *driver,
         if (rc == 0 && qemuDomainUpdateDeviceList(driver, vm, QEMU_ASYNC_JOB_NONE) < 0)
             goto cleanup;

-        /*
-         * update domain status forcibly because the domain status may be
-         * changed even if we failed to attach the device. For example,
-         * a new controller may be created.
-         */
-        if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
-            goto cleanup;
+        qemuDomainSaveStatus(vm);
     }

     /* Finally, if no error until here, we can save config. */
@@ -8436,9 +8404,7 @@ qemuDomainSetBlkioParameters(virDomainPtr dom,
     if (def) {
         ret = virDomainCgroupSetupDomainBlkioParameters(priv->cgroup, def,
                                                         params, nparams);
-
-        if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
-            goto endjob;
+        qemuDomainSaveStatus(vm);
     }
     if (ret < 0)
         goto endjob;
@@ -8613,9 +8579,8 @@ qemuDomainSetMemoryParameters(virDomainPtr dom,
                                                 params, nparams) < 0)
         goto endjob;

-    if (def &&
-        virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
-        goto endjob;
+    if (def)
+        qemuDomainSaveStatus(vm);

     if (persistentDef &&
         virDomainDefSave(persistentDef, driver->xmlopt, cfg->configDir) < 0)
@@ -8876,8 +8841,7 @@ qemuDomainSetNumaParameters(virDomainPtr dom,
                                  -1, mode, nodeset) < 0)
             goto endjob;

-        if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
-            goto endjob;
+        qemuDomainSaveStatus(vm);
     }

     if (persistentDef) {
@@ -9068,8 +9032,7 @@ qemuDomainSetPerfEvents(virDomainPtr dom,
                 VIR_TRISTATE_BOOL_YES : VIR_TRISTATE_BOOL_NO;
         }

-        if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
-            goto endjob;
+        qemuDomainSaveStatus(vm);
     }

     if (persistentDef) {
@@ -9520,8 +9483,7 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
         }
     }

-    if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
-        goto endjob;
+    qemuDomainSaveStatus(vm);

     if (eventNparams) {
         event = virDomainEventTunableNewFromDom(dom, eventParams, eventNparams);
@@ -10418,8 +10380,7 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
                 goto endjob;
         }

-        if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
-            goto endjob;
+        qemuDomainSaveStatus(vm);
     }

     if (persistentNet) {
@@ -14444,7 +14405,6 @@ qemuDomainBlockJobAbort(virDomainPtr dom,
 {
     virQEMUDriver *driver = dom->conn->privateData;
     virDomainDiskDef *disk = NULL;
-    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
     bool pivot = !!(flags & VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT);
     bool async = !!(flags & VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC);
     g_autoptr(qemuBlockJobData) job = NULL;
@@ -14508,7 +14468,7 @@ qemuDomainBlockJobAbort(virDomainPtr dom,
         job->state = QEMU_BLOCKJOB_STATE_ABORTING;
     }

-    ignore_value(virDomainObjSave(vm, driver->xmlopt, cfg->stateDir));
+    qemuDomainSaveStatus(vm);

     if (!async) {
         qemuBlockJobUpdate(vm, job, QEMU_ASYNC_JOB_NONE);
@@ -16191,8 +16151,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,

         qemuDomainSetGroupBlockIoTune(def, &info);

-        if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
-            goto endjob;
+        qemuDomainSaveStatus(vm);

         if (eventNparams) {
             event = virDomainEventTunableNewFromDom(dom, eventParams, eventNparams);
@@ -19686,8 +19645,7 @@ qemuDomainSetLifecycleAction(virDomainPtr dom,

         qemuDomainModifyLifecycleAction(def, type, action);

-        if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
-            goto endjob;
+        qemuDomainSaveStatus(vm);
     }

     if (persistentDef) {
@@ -20225,9 +20183,7 @@ qemuDomainAgentSetResponseTimeout(virDomainPtr dom,

     QEMU_DOMAIN_PRIVATE(vm)->agentTimeout = timeout;

-    if (virDomainObjIsActive(vm) &&
-        virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
-        goto cleanup;
+    qemuDomainSaveStatus(vm);

     ret = 0;

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