]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
all: Replace virGetLastError with virGetLastErrorCode where we can
authorramyelkest <ramyelkest@gmail.com>
Sat, 5 May 2018 12:04:21 +0000 (13:04 +0100)
committerErik Skultety <eskultet@redhat.com>
Tue, 5 Jun 2018 16:44:05 +0000 (18:44 +0200)
Replace instances where we previously called virGetLastError just to
either get the code or to check if an error exists with
virGetLastErrorCode to avoid a validity pre-check.

Signed-off-by: Ramy Elkest <ramyelkest@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
24 files changed:
src/locking/lock_driver_lockd.c
src/lxc/lxc_controller.c
src/qemu/qemu_agent.c
src/qemu/qemu_conf.c
src/qemu/qemu_domain.c
src/qemu/qemu_driver.c
src/qemu/qemu_hotplug.c
src/qemu/qemu_migration.c
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor_json.c
src/qemu/qemu_process.c
src/remote/remote_driver.c
src/rpc/virnetclient.c
src/rpc/virnetlibsshsession.c
src/util/virmodule.c
src/util/virxml.c
tests/commandtest.c
tests/testutils.c
tests/virhostcputest.c
tests/virstoragetest.c
tools/virsh-domain-monitor.c
tools/virsh-domain.c
tools/virsh-util.c
tools/vsh.c

index c3fc18a8a7686ca12251f7fe48d2a916c888e038..957a963a7b19ba172f94ef81f8f3777565b6481f 100644 (file)
@@ -302,8 +302,7 @@ static int virLockManagerLockDaemonSetupLockspace(const char *path)
                                 0, NULL, NULL, NULL,
                                 (xdrproc_t)xdr_virLockSpaceProtocolCreateLockSpaceArgs, (char*)&args,
                                 (xdrproc_t)xdr_void, NULL) < 0) {
-        virErrorPtr err = virGetLastError();
-        if (err && err->code == VIR_ERR_OPERATION_INVALID) {
+        if (virGetLastErrorCode() == VIR_ERR_OPERATION_INVALID) {
             /* The lockspace already exists */
             virResetLastError();
             rv = 0;
index 03077af1ec765c72de7d3fa5f124a3ca75b7148d..4e84391bf5cf931230b5e28ff7bf054b203bfec9 100644 (file)
@@ -1295,7 +1295,6 @@ static void virLXCControllerConsoleIO(int watch, int fd, int events, void *opaqu
  */
 static int virLXCControllerMain(virLXCControllerPtr ctrl)
 {
-    virErrorPtr err;
     int rc = -1;
     size_t i;
 
@@ -1347,8 +1346,7 @@ static int virLXCControllerMain(virLXCControllerPtr ctrl)
 
     virNetDaemonRun(ctrl->daemon);
 
-    err = virGetLastError();
-    if (!err || err->code == VIR_ERR_OK)
+    if (virGetLastErrorCode() == VIR_ERR_OK)
         rc = wantReboot ? 1 : 0;
 
  cleanup:
index e508abcc24777fbb757c9cd68c7ec12b5965da62..10c6ef09fa379dce07ccd5f030a9eaa726b8af97 100644 (file)
@@ -620,8 +620,7 @@ qemuAgentIO(int watch, int fd, int events, void *opaque)
             /* Already have an error, so clear any new error */
             virResetLastError();
         } else {
-            virErrorPtr err = virGetLastError();
-            if (!err)
+            if (virGetLastErrorCode() == VIR_ERR_OK)
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("Error while processing monitor IO"));
             virCopyLastError(&mon->lastError);
index 5f35a49e91812d58530a17e60b92070378f1175b..33c0e26c034264bb0fdb51e7ef77348ac89095fc 100644 (file)
@@ -298,8 +298,7 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
     if (privileged &&
         virFileFindHugeTLBFS(&cfg->hugetlbfs, &cfg->nhugetlbfs) < 0) {
         /* This however is not implemented on all platforms. */
-        virErrorPtr err = virGetLastError();
-        if (err && err->code != VIR_ERR_NO_SUPPORT)
+        if (virGetLastErrorCode() != VIR_ERR_NO_SUPPORT)
             goto error;
     }
 
index 2dd4e5ef5f86dd297c3ea4e4f5c3423638235b1d..f135117a959126c60271ace27b22fcc8084d3c24 100644 (file)
@@ -6662,7 +6662,7 @@ int qemuDomainObjExitMonitor(virQEMUDriverPtr driver,
 {
     qemuDomainObjExitMonitorInternal(driver, obj);
     if (!virDomainObjIsActive(obj)) {
-        if (!virGetLastError())
+        if (virGetLastErrorCode() == VIR_ERR_OK)
             virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                            _("domain is no longer running"));
         return -1;
index b7b318896fe22b5604e7ebfbfdeb4f65d3abb18f..38ea865ce33a61ec7cdcdbb071bb6f1cbe0d2f50 100644 (file)
@@ -1923,7 +1923,7 @@ static int qemuDomainResume(virDomainPtr dom)
         if (qemuProcessStartCPUs(driver, vm,
                                  VIR_DOMAIN_RUNNING_UNPAUSED,
                                  QEMU_ASYNC_JOB_NONE) < 0) {
-            if (virGetLastError() == NULL)
+            if (virGetLastErrorCode() == VIR_ERR_OK)
                 virReportError(VIR_ERR_OPERATION_FAILED,
                                "%s", _("resume operation failed"));
             goto endjob;
@@ -3185,7 +3185,7 @@ qemuFileWrapperFDClose(virDomainObjPtr vm,
     ret = virFileWrapperFdClose(fd);
     virObjectLock(vm);
     if (!virDomainObjIsActive(vm)) {
-        if (!virGetLastError())
+        if (virGetLastErrorCode() == VIR_ERR_OK)
             virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                            _("domain is no longer running"));
         ret = -1;
@@ -3959,7 +3959,7 @@ qemuDomainCoreDumpWithFormat(virDomainPtr dom,
                 event = virDomainEventLifecycleNewFromObj(vm,
                                                           VIR_DOMAIN_EVENT_SUSPENDED,
                                                           VIR_DOMAIN_EVENT_SUSPENDED_API_ERROR);
-                if (virGetLastError() == NULL)
+                if (virGetLastErrorCode() == VIR_ERR_OK)
                     virReportError(VIR_ERR_OPERATION_FAILED,
                                    "%s", _("resuming after dump failed"));
             }
@@ -6629,7 +6629,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
         if (qemuProcessStartCPUs(driver, vm,
                                  VIR_DOMAIN_RUNNING_RESTORED,
                                  asyncJob) < 0) {
-            if (virGetLastError() == NULL)
+            if (virGetLastErrorCode() == VIR_ERR_OK)
                 virReportError(VIR_ERR_OPERATION_FAILED,
                                "%s", _("failed to resume domain"));
             goto cleanup;
@@ -14326,7 +14326,7 @@ qemuDomainSnapshotCreateActiveInternal(virQEMUDriverPtr driver,
         event = virDomainEventLifecycleNewFromObj(vm,
                                          VIR_DOMAIN_EVENT_SUSPENDED,
                                          VIR_DOMAIN_EVENT_SUSPENDED_API_ERROR);
-        if (virGetLastError() == NULL) {
+        if (virGetLastErrorCode() == VIR_ERR_OK) {
             virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                            _("resuming after snapshot failed"));
         }
@@ -15290,7 +15290,7 @@ qemuDomainSnapshotCreateActiveExternal(virQEMUDriverPtr driver,
                                          VIR_DOMAIN_EVENT_SUSPENDED,
                                          VIR_DOMAIN_EVENT_SUSPENDED_API_ERROR);
         qemuDomainEventQueue(driver, event);
-        if (virGetLastError() == NULL) {
+        if (virGetLastErrorCode() == VIR_ERR_OK) {
             virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                            _("resuming after snapshot failed"));
         }
index 8abe02adc6793876b7a9b4932f37db8d8e861fe2..822e38ae08cd6010848c171261a16d2038e0e005 100644 (file)
@@ -173,7 +173,7 @@ qemuHotplugWaitForTrayEject(virQEMUDriverPtr driver,
         if (rc > 0) {
             /* the caller called qemuMonitorEjectMedia which usually reports an
              * error. Report the failure in an off-chance that it didn't. */
-            if (!virGetLastError()) {
+            if (virGetLastErrorCode() == VIR_ERR_OK) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("timed out waiting for disk tray status update"));
             }
index ef0de0ac7e2f0519f033b97dcb6516b255870081..ee482475f5ce2f0d57bbfdc757055c26445dc4a6 100644 (file)
@@ -5057,7 +5057,7 @@ qemuMigrationDstFinish(virQEMUDriverPtr driver,
                                  inPostCopy ? VIR_DOMAIN_RUNNING_POSTCOPY
                                             : VIR_DOMAIN_RUNNING_MIGRATED,
                                  QEMU_ASYNC_JOB_MIGRATION_IN) < 0) {
-            if (virGetLastError() == NULL)
+            if (virGetLastErrorCode() == VIR_ERR_OK)
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                "%s", _("resume operation failed"));
             /* Need to save the current error, in case shutting
@@ -5196,7 +5196,7 @@ qemuMigrationDstFinish(virQEMUDriverPtr driver,
     /* Set a special error if Finish is expected to return NULL as a result of
      * successful call with retcode != 0
      */
-    if (retcode != 0 && !dom && !virGetLastError())
+    if (retcode != 0 && !dom && virGetLastErrorCode() == VIR_ERR_OK)
         virReportError(VIR_ERR_MIGRATE_FINISH_OK, NULL);
     return dom;
 }
index 69aea6a850bb5da30ec0edf43a525cfc2ee72208..215135aa3e2eb8596a67063270c9b7cb1b0161a5 100644 (file)
@@ -748,8 +748,7 @@ qemuMonitorIO(int watch, int fd, int events, void *opaque)
             /* Already have an error, so clear any new error */
             virResetLastError();
         } else {
-            virErrorPtr err = virGetLastError();
-            if (!err)
+            if (virGetLastErrorCode() == VIR_ERR_OK)
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("Error while processing monitor IO"));
             virCopyLastError(&mon->lastError);
@@ -1029,7 +1028,7 @@ qemuMonitorClose(qemuMonitorPtr mon)
     /* Propagate existing monitor error in case the current thread has no
      * error set.
      */
-    if (mon->lastError.code != VIR_ERR_OK && !virGetLastError())
+    if (mon->lastError.code != VIR_ERR_OK && virGetLastErrorCode() == VIR_ERR_OK)
         virSetError(&mon->lastError);
 
     virObjectUnlock(mon);
index 42d7b9c5e96fcaf6447481707ce17f43b73b6eef..e8a46d2ec346eaeae2b1edd34ee5b797289d10ba 100644 (file)
@@ -4352,7 +4352,7 @@ qemuMonitorJSONDiskNameLookup(qemuMonitorPtr mon,
     }
     /* Guarantee an error when returning NULL, but don't override a
      * more specific error if one was already generated.  */
-    if (!ret && !virGetLastError())
+    if (!ret && virGetLastErrorCode() == VIR_ERR_OK)
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unable to find backing name for device %s"),
                        device);
index d53d6b04fa226de8f0d960d2850fe9fc1216ae3f..9eb3ea08e5a1bca7bbf5d757270ea2937ad7910f 100644 (file)
@@ -466,7 +466,7 @@ qemuProcessFakeReboot(void *opaque)
     if (qemuProcessStartCPUs(driver, vm,
                              reason,
                              QEMU_ASYNC_JOB_NONE) < 0) {
-        if (virGetLastError() == NULL)
+        if (virGetLastErrorCode() == VIR_ERR_OK)
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            "%s", _("resume operation failed"));
         goto endjob;
@@ -6411,7 +6411,7 @@ qemuProcessFinishStartup(virQEMUDriverPtr driver,
         if (qemuProcessStartCPUs(driver, vm,
                                  VIR_DOMAIN_RUNNING_BOOTED,
                                  asyncJob) < 0) {
-            if (!virGetLastError())
+            if (virGetLastErrorCode() == VIR_ERR_OK)
                 virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                                _("resume operation failed"));
             goto cleanup;
index 3be30bd79a887d47cc7d8dcf63fa40b90534364a..c22993ce9ed168f5cbe67836b811d364119470dd 100644 (file)
@@ -3672,8 +3672,7 @@ remoteAuthenticate(virConnectPtr conn, struct private_data *priv,
                (xdrproc_t) xdr_void, (char *) NULL,
                (xdrproc_t) xdr_remote_auth_list_ret, (char *) &ret);
     if (err < 0) {
-        virErrorPtr verr = virGetLastError();
-        if (verr && verr->code == VIR_ERR_NO_SUPPORT) {
+        if (virGetLastErrorCode() == VIR_ERR_NO_SUPPORT) {
             /* Missing RPC - old server - ignore */
             virResetLastError();
             return 0;
index 6bbc984e484cb767bf24c77292e8b1d6af7bc9d7..b4d8fb2187fff1ab184fd2422661ada924532068 100644 (file)
@@ -1958,7 +1958,7 @@ static int virNetClientIO(virNetClientPtr client,
         virNetClientIOUpdateCallback(client, true);
 
     if (rv == 0 &&
-        virGetLastError())
+        virGetLastErrorCode())
         rv = -1;
 
  cleanup:
index 6d78d2569e051a17d8fbba98faff8b9273153fdc..df819f616983db2383fa4dbf5e54b22ac5e8da4f 100644 (file)
@@ -499,9 +499,7 @@ virNetLibsshImportPrivkey(virNetLibsshSessionPtr sess,
         err = SSH_AUTH_ERROR;
         goto error;
     } else if (ret == SSH_ERROR) {
-        virErrorPtr vir_err = virGetLastError();
-
-        if (!vir_err || !vir_err->code) {
+        if (virGetLastErrorCode() == VIR_ERR_OK) {
             virReportError(VIR_ERR_AUTH_FAILED,
                            _("error while opening private key '%s', wrong "
                              "passphrase?"),
index ff8c22752e2c622035cd07712f9247b32060889b..b19a787e4f639231b6b7b13c0227f6d6a3604957 100644 (file)
@@ -123,8 +123,7 @@ virModuleLoad(const char *path,
     if ((*regsym)() < 0) {
         /* regsym() should report an error itself, but lets
          * just make sure */
-        virErrorPtr err = virGetLastError();
-        if (err == NULL) {
+        if (virGetLastErrorCode() == VIR_ERR_OK) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Failed to execute symbol '%s' in module '%s'"),
                            regfunc, path);
index 6e87605ea5e478bf05282b6414f5a01c480f2bfb..a03a747e603cee33da3832939f9af3219fefa3a6 100644 (file)
@@ -708,7 +708,7 @@ catchXMLError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
 
     /* conditions for error printing */
     if (!ctxt ||
-        (virGetLastError() != NULL) ||
+        (virGetLastErrorCode()) ||
         ctxt->input == NULL ||
         ctxt->lastError.level != XML_ERR_FATAL ||
         ctxt->lastError.message == NULL)
@@ -845,7 +845,7 @@ virXMLParseHelper(int domcode,
     xmlFreeDoc(xml);
     xml = NULL;
 
-    if (virGetLastError() == NULL) {
+    if (virGetLastErrorCode() == VIR_ERR_OK) {
         virGenericReportError(domcode, VIR_ERR_XML_ERROR,
                               "%s", _("failed to parse xml document"));
     }
index ad81c2a71219f50bb44734a8d9f02e6900d3ca2d..744a387aa0c4c4ecc7a6b93766a231e15d80f23d 100644 (file)
@@ -127,7 +127,7 @@ static int test0(const void *unused ATTRIBUTE_UNUSED)
     if (virCommandRun(cmd, NULL) == 0)
         goto cleanup;
 
-    if (virGetLastError() == NULL)
+    if (virGetLastErrorCode() == VIR_ERR_OK)
         goto cleanup;
 
     virResetLastError();
index 4b13d112788a7c2e173c0ac9653ddca9371a84f4..423f4bfdff1603dacacf1ef5759d6b8b7454e405 100644 (file)
@@ -178,8 +178,7 @@ virTestRun(const char *title,
 
     virResetLastError();
     ret = body(data);
-    virErrorPtr err = virGetLastError();
-    if (err) {
+    if (virGetLastErrorCode()) {
         if (virTestGetVerbose() || virTestGetDebug())
             virDispatchError(NULL);
     }
@@ -258,8 +257,7 @@ virTestRun(const char *title,
                 fprintf(stderr, " alloc %zu failed but no err status\n", i + 1);
 # endif
             } else {
-                virErrorPtr lerr = virGetLastError();
-                if (!lerr) {
+                if (virGetLastErrorCode() == VIR_ERR_OK) {
 # if 0
                     fprintf(stderr, " alloc %zu failed but no error report\n", i + 1);
 # endif
index cb318df6e1bb0b0f6f0521e1eace76ab56ef8b5d..091dd59b83e6d8dc3e12fd056c1be8e8b29a87f8 100644 (file)
@@ -49,7 +49,7 @@ linuxTestCompareFiles(const char *cpuinfofile,
                                        &nodeinfo.nodes, &nodeinfo.sockets,
                                        &nodeinfo.cores, &nodeinfo.threads) < 0) {
         if (virTestGetDebug()) {
-            if (virGetLastError())
+            if (virGetLastErrorCode())
                 VIR_TEST_DEBUG("\n%s\n", virGetLastErrorMessage());
         }
         VIR_FORCE_FCLOSE(cpuinfo);
index 0e11602e84d7fdf28deaf45586e706aff677ee06..5221e82ad28d94b82657ad48756e5558c333626a 100644 (file)
@@ -333,7 +333,7 @@ testStorageChain(const void *args)
         goto cleanup;
     }
     if (data->flags & EXP_WARN) {
-        if (!virGetLastError()) {
+        if (virGetLastErrorCode() == VIR_ERR_OK) {
             fprintf(stderr, "call should have warned\n");
             goto cleanup;
         }
@@ -343,7 +343,7 @@ testStorageChain(const void *args)
             goto cleanup;
         }
     } else {
-        if (virGetLastError()) {
+        if (virGetLastErrorCode()) {
             fprintf(stderr, "call should not have warned\n");
             goto cleanup;
         }
@@ -449,13 +449,13 @@ testStorageLookup(const void *args)
                                        idx, NULL);
 
     if (!data->expResult) {
-        if (!virGetLastError()) {
+        if (virGetLastErrorCode() == VIR_ERR_OK) {
             fprintf(stderr, "call should have failed\n");
             ret = -1;
         }
         virResetLastError();
     } else {
-        if (virGetLastError()) {
+        if (virGetLastErrorCode()) {
             fprintf(stderr, "call should not have warned\n");
             ret = -1;
         }
index 39cb2ce7f01d5f099564c0541523433cccd63a52..8cbb3db37ccffae71d857a7b2c64ec214ee120c7 100644 (file)
@@ -60,7 +60,6 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title,
                           unsigned int flags)
 {
     char *desc = NULL;
-    virErrorPtr err = NULL;
     xmlDocPtr doc = NULL;
     xmlXPathContextPtr ctxt = NULL;
     int type;
@@ -73,15 +72,15 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title,
     if ((desc = virDomainGetMetadata(dom, type, NULL, flags))) {
         return desc;
     } else {
-        err = virGetLastError();
+        int errCode = virGetLastErrorCode();
 
-        if (err && err->code == VIR_ERR_NO_DOMAIN_METADATA) {
+        if (errCode == VIR_ERR_NO_DOMAIN_METADATA) {
             desc = vshStrdup(ctl, "");
             vshResetLibvirtError();
             return desc;
         }
 
-        if (err && err->code != VIR_ERR_NO_SUPPORT)
+        if (errCode != VIR_ERR_NO_SUPPORT)
             return desc;
     }
 
index 4f655bf0e597d8ad085e668f6f9e88da4e017ead..b555d746c5ee96622c0612a686e22dcb2aa2905e 100644 (file)
@@ -91,9 +91,7 @@ virshDomainDefine(virConnectPtr conn, const char *xml, unsigned int flags)
          * try again.
          */
         if (!dom) {
-            virErrorPtr err = virGetLastError();
-            if (err &&
-                (err->code == VIR_ERR_NO_SUPPORT) &&
+            if ((virGetLastErrorCode() == VIR_ERR_NO_SUPPORT) &&
                 (flags == VIR_DOMAIN_DEFINE_VALIDATE))
                 dom = virDomainDefineXML(conn, xml);
         }
index 44be3ad64b1f60f7d801b9ae18af07d797e4da63..aa88397d6123f1fb60f88b9df822101800dc5a95 100644 (file)
@@ -123,8 +123,7 @@ virshDomainState(vshControl *ctl,
     if (!priv->useGetInfo) {
         int state;
         if (virDomainGetState(dom, &state, reason, 0) < 0) {
-            virErrorPtr err = virGetLastError();
-            if (err && err->code == VIR_ERR_NO_SUPPORT)
+            if (virGetLastErrorCode() == VIR_ERR_NO_SUPPORT)
                 priv->useGetInfo = true;
             else
                 return -1;
index 1516e578d987955010ec05afd471baa2f7cbff3a..10497290652c65edbe57ade8b09ee83f6aa03584 100644 (file)
@@ -266,7 +266,7 @@ vshSaveLibvirtHelperError(void)
     if (last_error)
         return;
 
-    if (!virGetLastError())
+    if (virGetLastErrorCode() == VIR_ERR_OK)
         return;
 
     vshSaveLibvirtError();