From nobody Fri May 3 02:03:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1525405937046360.5310968861378; Thu, 3 May 2018 20:52:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7AC11883BD; Fri, 4 May 2018 03:52:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 487585C20D; Fri, 4 May 2018 03:52:15 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A19AA4CAA7; Fri, 4 May 2018 03:52:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w443lH5X019963 for ; Thu, 3 May 2018 23:47:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 01D5F5D6A8; Fri, 4 May 2018 03:47:17 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EDED25D6A5 for ; Fri, 4 May 2018 03:47:13 +0000 (UTC) Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8D9E630C8095 for ; Fri, 4 May 2018 03:47:02 +0000 (UTC) Received: by mail-wr0-f193.google.com with SMTP id v60-v6so19571156wrc.7 for ; Thu, 03 May 2018 20:47:02 -0700 (PDT) Received: from localhost.localdomain ([212.92.105.247]) by smtp.gmail.com with ESMTPSA id a14-v6sm19472541wra.84.2018.05.03.20.47.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 May 2018 20:47:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=28Qfo5o1u+vrEqSEzqB91au7p8GpBR9Tvk+d0b9P+wQ=; b=fsAin3prKAg5RS9nKcyXmKNrhOwST5FAvvp02Uuw1gfdEdnI75N10+oUXI5juFj0r6 g8F4hBHF/wrD0g84xr01MLjYT0XP+2vcTGhW/k8zXmjahWG6olWOWqOz+dGLShn7DXw/ KqflAMtoMpi2eLOjtki1wCj4DbmtcIEzGr0/Z4buRXkEvpHmyDIGBTvw0VtkoFRhfplS 0Wl6oJNxGn8LPNvLdReqwKyZhjQNXyYwmOHJS60WSLTtvoEPrnqbr6BgDBaiOboYxy0w 9Utf9W8RMc5uvBct5AhdVVpXJ3XxG02jsg/XAZyxNjTaYVkALfc62EgVK1PrufYn9ncV PxuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=28Qfo5o1u+vrEqSEzqB91au7p8GpBR9Tvk+d0b9P+wQ=; b=dKoXgACYUDljsG5YnIcftvI/o7Rr37cp+MCIPnmpLcGhX9XTR10mabdh/CEuL68NcO nMBm8uiWkYtzUUlwFK7H+tOLpPKqhQ+lrDAdX5O81HWFnVK1DVOIkTypRizmEaUdusQS e0lyOgU60QqTZjZDBbh4hmdeGiyIK3F3D7H4IKdkxg8qsXaA/QeWP060DAolpZb+Q5tZ A0yxSPipiTbwh10in9D7pIHWoZisf0SuSbv2ECU/LJaU9m1qDvzW21LVRtEXUuARnFdZ xQfA9TzluZAUuEHUCvnJTmj3o+jOq3HIY8LxmNpTt/JfjRRTXVsoEfbIoqY1mydt8I5x Hd3g== X-Gm-Message-State: ALQs6tDxp9TI4w54ps4EhpbIiYkf3yM+GzkZMb5V9H0FUDHsC732SvGI Yh6cKro48f63/aKRcLu7mchlnV3hcqI= X-Google-Smtp-Source: AB8JxZq2haVhfM7tmjZ9rkXO4UQYE/S7WDqJHplNtlnK/s/IoUrsjl0pb0zWcVScddV7zIMTVOeR7Q== X-Received: by 2002:adf:ba4a:: with SMTP id t10-v6mr19024771wrg.219.1525405621191; Thu, 03 May 2018 20:47:01 -0700 (PDT) From: ramyelkest To: libvir-list@redhat.com Date: Fri, 4 May 2018 04:46:47 +0100 Message-Id: <1525405608-29406-2-git-send-email-ramyelkest@gmail.com> In-Reply-To: <1525405608-29406-1-git-send-email-ramyelkest@gmail.com> References: <1525405608-29406-1-git-send-email-ramyelkest@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 04 May 2018 03:47:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 04 May 2018 03:47:02 +0000 (UTC) for IP:'209.85.128.193' DOMAIN:'mail-wr0-f193.google.com' HELO:'mail-wr0-f193.google.com' FROM:'ramyelkest@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.3 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.128.193 mail-wr0-f193.google.com 209.85.128.193 mail-wr0-f193.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: ramyelkest Subject: [libvirt] [PATCH 1/2] util: adding virHasLastError and virGetLastErrorCode/Domain X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 04 May 2018 03:52:16 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Many places in the code call virGetLastError() just to check the raised error code, or domain. However virGetLastError() can return NULL, so the code has to check for that as well. So Instead we create functions virGetLastErrorCode and virGetLastErrorDomain (in addition to the existing virGetLastErrorMessage) that always return a valid error code/domain/message, to simplify callers. Also created virHasLastErrorCode for completion My first commit, for: https://wiki.libvirt.org/page/BiteSizedTasks#Add_and_use_virGetLastErrorCod= e.28.29 Signed-off-by: Ramy Elkest --- include/libvirt/virterror.h | 3 +++ src/libvirt_public.syms | 7 +++++ src/util/virerror.c | 63 +++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 73 insertions(+) diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h index 3e7c7a0..8336258 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -344,6 +344,9 @@ void virResetLastError (void); void virResetError (virErrorPtr err); void virFreeError (virErrorPtr err); =20 +int virHasLastError (void); +int virGetLastErrorCode (void); +int virGetLastErrorDomain (void); const char * virGetLastErrorMessage (void); =20 virErrorPtr virConnGetLastError (virConnectPtr conn); diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 95df3a0..3a641a3 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -785,4 +785,11 @@ LIBVIRT_4.1.0 { virStoragePoolLookupByTargetPath; } LIBVIRT_3.9.0; =20 +LIBVIRT_4.4.0 { + global: + virHasLastError; + virGetLastErrorCode; + virGetLastErrorDomain; +} LIBVIRT_4.1.0; + # .... define new API here using predicted next version number .... diff --git a/src/util/virerror.c b/src/util/virerror.c index c000b00..818af2e 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -272,6 +272,69 @@ virGetLastError(void) =20 =20 /** + * virHasLastError: + * + * Check for a reported last error + * + * The error object is kept in thread local storage, so separate + * threads can safely access this concurrently. + * + * Returns 1 if there is an error and the error code is not VIR_ERR_OK, + otherwise returns 0 + */ +int +virHasLastError(void) +{ + virErrorPtr err =3D virLastErrorObject(); + if (!err || err->code =3D=3D VIR_ERR_OK) + return 0; + return 1; +} + + +/** + * virGetLastErrorCode: + * + * Get the most recent error code + * + * The error object is kept in thread local storage, so separate + * threads can safely access this concurrently. + * + * Returns the most recent error code in this thread, + * or VIR_ERR_OK if none is set + */ +int +virGetLastErrorCode(void) +{ + virErrorPtr err =3D virLastErrorObject(); + if (!err) + return VIR_ERR_OK; + return err->code; +} + + +/** + * virGetLastErrorDomain: + * + * Get the most recent error domain + * + * The error object is kept in thread local storage, so separate + * threads can safely access this concurrently. + * + * Returns the most recent error code in this thread, + * or VIR_FROM_NONE if none is set + */ +int +virGetLastErrorDomain(void) +{ + virErrorPtr err =3D virLastErrorObject(); + if (!err) + return VIR_FROM_NONE; + return err->domain; +} + + +/** * virGetLastErrorMessage: * * Get the most recent error message --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 02:03:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1525405942377550.5873506487729; Thu, 3 May 2018 20:52:22 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 141D8C036778; Fri, 4 May 2018 03:52:21 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B95E130012A8; Fri, 4 May 2018 03:52:20 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5DBA7180BADA; Fri, 4 May 2018 03:52:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w443lIgl019973 for ; Thu, 3 May 2018 23:47:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1FDC6271A9; Fri, 4 May 2018 03:47:18 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 15886271A7 for ; Fri, 4 May 2018 03:47:16 +0000 (UTC) Received: from mail-wr0-f180.google.com (mail-wr0-f180.google.com [209.85.128.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 04EC13004876 for ; Fri, 4 May 2018 03:47:04 +0000 (UTC) Received: by mail-wr0-f180.google.com with SMTP id q3-v6so19565811wrj.6 for ; Thu, 03 May 2018 20:47:03 -0700 (PDT) Received: from localhost.localdomain ([212.92.105.247]) by smtp.gmail.com with ESMTPSA id a14-v6sm19472541wra.84.2018.05.03.20.47.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 May 2018 20:47:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IkiTBy/CRqspsABW0kFQMTJN3qwmEoCwhDiTHKsFzao=; b=RlFBNs5pXWup1J0lxdFA2gOsG0XWKOGw48/2l+WEBwAvnLWrXth4+LzPTyMbWNh3Se 1W4r/xk7BP1UIvcf28syIYPUcFghX+WI2+7CzGgGQ3fHCURROmuCklpnQSmcH9zPguF2 ph9tem8YWoNEIYy/ugawbWupEtA/TnJHnvCr5DQpikAG8VmXoKVORU+OW3DuVZMBD5+0 rFzg7VEbF6Xzx41gxWmAsol/OwzYQqHb08j9tX4auGTm0v+oBfdhsgN3cY7xLyYnBF3S BYTL49iKe4C4a6L3x0msR/rOOCFSPM73QszfYic/gGvv6wxx96E1GkO5GRqTECV8pXaU w4qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IkiTBy/CRqspsABW0kFQMTJN3qwmEoCwhDiTHKsFzao=; b=qkPPS2LvvNEmO1yBFt/2s5oMF+4IuSPKHvo3ZDbWNnM4Fv0JpVxkGSlwPI2wAKbxrJ T2xh6T8kUbqRjbTxMGalB/hKcgXuI7piG6QUB+01okMpXM7Va6/di9nzWlhNmd/kOyjz R2V6s4u4ibUy2YUaGZN3LkDmrML5LAS+TBXffMaXwWhxerch5VFTcxdxIGArQGtWUWwj B27rGR94i0KbQIv2K9LexGDA57YUEeC3P9Xqx2K5yujKm8bMGbn11Ne5Ya6qwl5WIR2P NuiSgo6k2ZGtooT74bLWEsdJCdcoUn+RYZX63ZiYaPnH71KoqWS4Aly690uw09c61DC5 tTBQ== X-Gm-Message-State: ALQs6tDpDrMaBOn9MdQQcq1NdQacfUIEs28GT3fXWCcvoJNRSN8PHt8X XtwFBbTdwlm33FvrBt8tmcoZRG+nywY= X-Google-Smtp-Source: AB8JxZoTbX/El6vprNX/Mv9GQrg2NCnOVArUVlAbSBKIoPTy+g9JGldbecwVe1fNepW7FjHMiY40wQ== X-Received: by 2002:adf:b08e:: with SMTP id i14-v6mr21572747wra.9.1525405622292; Thu, 03 May 2018 20:47:02 -0700 (PDT) From: ramyelkest To: libvir-list@redhat.com Date: Fri, 4 May 2018 04:46:48 +0100 Message-Id: <1525405608-29406-3-git-send-email-ramyelkest@gmail.com> In-Reply-To: <1525405608-29406-1-git-send-email-ramyelkest@gmail.com> References: <1525405608-29406-1-git-send-email-ramyelkest@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 04 May 2018 03:47:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 04 May 2018 03:47:04 +0000 (UTC) for IP:'209.85.128.180' DOMAIN:'mail-wr0-f180.google.com' HELO:'mail-wr0-f180.google.com' FROM:'ramyelkest@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.3 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.128.180 mail-wr0-f180.google.com 209.85.128.180 mail-wr0-f180.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: ramyelkest Subject: [libvirt] [PATCH 2/2] all: replacing virGetLastError with virHas/GetLastErrorCode/Domain X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 04 May 2018 03:52:21 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Many places in the code call virGetLastError() just to check the raised error code, or domain. However virGetLastError() can return NULL, so the code has to check for that as well. So Instead we create functions virGetLastErrorCode and virGetLastErrorDomain (in addition to the existing virGetLastErrorMessage) that always return a valid error code/domain/message, to simplify callers. Also created virHasLastErrorCode for completion for: https://wiki.libvirt.org/page/BiteSizedTasks#Add_and_use_virGetLastErrorCod= e.28.29 Notes: * There are a few instances of virGetLastErrorCode() left where we use mult= iple fields from the error, which makes sense to keep it. * I didn't manage to use virGetLastErrorDomain() (due to the above) so I'm = inclined to remove it. Signed-off-by: Ramy Elkest --- src/locking/lock_driver_lockd.c | 3 +-- src/lxc/lxc_controller.c | 4 +--- src/qemu/qemu_agent.c | 3 +-- src/qemu/qemu_conf.c | 3 +-- src/qemu/qemu_domain.c | 2 +- src/qemu/qemu_driver.c | 12 ++++++------ src/qemu/qemu_hotplug.c | 2 +- src/qemu/qemu_migration.c | 4 ++-- src/qemu/qemu_monitor.c | 5 ++--- src/qemu/qemu_monitor_json.c | 2 +- src/qemu/qemu_process.c | 2 +- src/remote/remote_driver.c | 3 +-- src/rpc/virnetclient.c | 2 +- src/util/virfilecache.c | 3 +-- src/util/virxml.c | 4 ++-- tests/commandtest.c | 2 +- tests/testutils.c | 6 ++---- tests/virhostcputest.c | 2 +- tests/virstoragetest.c | 8 ++++---- tools/virsh-domain-monitor.c | 7 +++---- tools/virsh-domain.c | 4 +--- tools/virsh-util.c | 3 +-- tools/vsh.c | 2 +- 23 files changed, 37 insertions(+), 51 deletions(-) diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lock= d.c index c3fc18a..957a963 100644 --- a/src/locking/lock_driver_lockd.c +++ b/src/locking/lock_driver_lockd.c @@ -302,8 +302,7 @@ static int virLockManagerLockDaemonSetupLockspace(const= char *path) 0, NULL, NULL, NULL, (xdrproc_t)xdr_virLockSpaceProtocolCreateL= ockSpaceArgs, (char*)&args, (xdrproc_t)xdr_void, NULL) < 0) { - virErrorPtr err =3D virGetLastError(); - if (err && err->code =3D=3D VIR_ERR_OPERATION_INVALID) { + if (virGetLastErrorCode() =3D=3D VIR_ERR_OPERATION_INVALID) { /* The lockspace already exists */ virResetLastError(); rv =3D 0; diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index d5636b8..81709d5 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -1297,7 +1297,6 @@ static void virLXCControllerConsoleIO(int watch, int = fd, int events, void *opaqu */ static int virLXCControllerMain(virLXCControllerPtr ctrl) { - virErrorPtr err; int rc =3D -1; size_t i; =20 @@ -1349,8 +1348,7 @@ static int virLXCControllerMain(virLXCControllerPtr c= trl) =20 virNetDaemonRun(ctrl->daemon); =20 - err =3D virGetLastError(); - if (!err || err->code =3D=3D VIR_ERR_OK) + if (!virHasLastError()) rc =3D wantReboot ? 1 : 0; =20 cleanup: diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 4df1bde..0d7a484 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -686,8 +686,7 @@ qemuAgentIO(int watch, int fd, int events, void *opaque) /* Already have an error, so clear any new error */ virResetLastError(); } else { - virErrorPtr err =3D virGetLastError(); - if (!err) + if (!virHasLastError()) virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Error while processing monitor IO")); virCopyLastError(&mon->lastError); diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index bfbb572..a09532d 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -297,8 +297,7 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool priv= ileged) if (privileged && virFileFindHugeTLBFS(&cfg->hugetlbfs, &cfg->nhugetlbfs) < 0) { /* This however is not implemented on all platforms. */ - virErrorPtr err =3D virGetLastError(); - if (err && err->code !=3D VIR_ERR_NO_SUPPORT) + if (virGetLastErrorCode() !=3D VIR_ERR_NO_SUPPORT) goto error; } =20 diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 727ea33..7df1520 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -6063,7 +6063,7 @@ int qemuDomainObjExitMonitor(virQEMUDriverPtr driver, { qemuDomainObjExitMonitorInternal(driver, obj); if (!virDomainObjIsActive(obj)) { - if (!virGetLastError()) + if (!virHasLastError()) virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("domain is no longer running")); return -1; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 83fc191..7a313b5 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1929,7 +1929,7 @@ static int qemuDomainResume(virDomainPtr dom) if (qemuProcessStartCPUs(driver, vm, VIR_DOMAIN_RUNNING_UNPAUSED, QEMU_ASYNC_JOB_NONE) < 0) { - if (virGetLastError() =3D=3D NULL) + if (!virHasLastError()) virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("resume operation failed")); goto endjob; @@ -3209,7 +3209,7 @@ qemuFileWrapperFDClose(virDomainObjPtr vm, ret =3D virFileWrapperFdClose(fd); virObjectLock(vm); if (!virDomainObjIsActive(vm)) { - if (!virGetLastError()) + if (!virHasLastError()) virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("domain is no longer running")); ret =3D -1; @@ -3991,7 +3991,7 @@ qemuDomainCoreDumpWithFormat(virDomainPtr dom, event =3D virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT= _SUSPENDED, VIR_DOMAIN_EVENT= _SUSPENDED_API_ERROR); - if (virGetLastError() =3D=3D NULL) + if (!virHasLastError()) virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("resuming after dump failed")); } @@ -6638,7 +6638,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn, if (qemuProcessStartCPUs(driver, vm, VIR_DOMAIN_RUNNING_RESTORED, asyncJob) < 0) { - if (virGetLastError() =3D=3D NULL) + if (!virHasLastError()) virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("failed to resume domain")); goto cleanup; @@ -14084,7 +14084,7 @@ qemuDomainSnapshotCreateActiveInternal(virQEMUDrive= rPtr driver, event =3D virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_SUSPENDED, VIR_DOMAIN_EVENT_SUSPENDED_API_ER= ROR); - if (virGetLastError() =3D=3D NULL) { + if (!virHasLastError()) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("resuming after snapshot failed")); } @@ -15048,7 +15048,7 @@ qemuDomainSnapshotCreateActiveExternal(virQEMUDrive= rPtr driver, VIR_DOMAIN_EVENT_SUSPENDED, VIR_DOMAIN_EVENT_SUSPENDED_API_ER= ROR); qemuDomainEventQueue(driver, event); - if (virGetLastError() =3D=3D NULL) { + if (!virHasLastError()) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("resuming after snapshot failed")); } diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 9ca8e66..831582f 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -212,7 +212,7 @@ qemuHotplugWaitForTrayEject(virQEMUDriverPtr driver, if (rc > 0) { /* the caller called qemuMonitorEjectMedia which usually repor= ts an * error. Report the failure in an off-chance that it didn't. = */ - if (!virGetLastError()) { + if (!virHasLastError()) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("timed out waiting for disk tray status u= pdate")); } diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 7602a30..a4b3434 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -4944,7 +4944,7 @@ qemuMigrationDstFinish(virQEMUDriverPtr driver, inPostCopy ? VIR_DOMAIN_RUNNING_POSTCOPY : VIR_DOMAIN_RUNNING_MIGRATED, QEMU_ASYNC_JOB_MIGRATION_IN) < 0) { - if (virGetLastError() =3D=3D NULL) + if (!virHasLastError()) virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("resume operation failed")); /* Need to save the current error, in case shutting @@ -5082,7 +5082,7 @@ qemuMigrationDstFinish(virQEMUDriverPtr driver, /* Set a special error if Finish is expected to return NULL as a resul= t of * successful call with retcode !=3D 0 */ - if (retcode !=3D 0 && !dom && !virGetLastError()) + if (retcode !=3D 0 && !dom && !virHasLastError()) virReportError(VIR_ERR_MIGRATE_FINISH_OK, NULL); return dom; } diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 3918791..31b303d 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -752,8 +752,7 @@ qemuMonitorIO(int watch, int fd, int events, void *opaq= ue) /* Already have an error, so clear any new error */ virResetLastError(); } else { - virErrorPtr err =3D virGetLastError(); - if (!err) + if (!virHasLastError()) virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Error while processing monitor IO")); virCopyLastError(&mon->lastError); @@ -1032,7 +1031,7 @@ qemuMonitorClose(qemuMonitorPtr mon) /* Propagate existing monitor error in case the current thread has no * error set. */ - if (mon->lastError.code !=3D VIR_ERR_OK && !virGetLastError()) + if (mon->lastError.code !=3D VIR_ERR_OK && !virHasLastError()) virSetError(&mon->lastError); =20 virObjectUnlock(mon); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 8176175..6cc2db1 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -4338,7 +4338,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 && !virHasLastError()) virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to find backing name for device %s"), device); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 37876b8..58524d0 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -558,7 +558,7 @@ qemuProcessFakeReboot(void *opaque) if (qemuProcessStartCPUs(driver, vm, reason, QEMU_ASYNC_JOB_NONE) < 0) { - if (virGetLastError() =3D=3D NULL) + if (!virHasLastError()) virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("resume operation failed")); goto endjob; diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 95437b4..e670e16 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -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 =3D virGetLastError(); - if (verr && verr->code =3D=3D VIR_ERR_NO_SUPPORT) { + if (virGetLastErrorCode() =3D=3D VIR_ERR_NO_SUPPORT) { /* Missing RPC - old server - ignore */ virResetLastError(); return 0; diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index 6bbc984..365485a 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -1958,7 +1958,7 @@ static int virNetClientIO(virNetClientPtr client, virNetClientIOUpdateCallback(client, true); =20 if (rv =3D=3D 0 && - virGetLastError()) + virHasLastError()) rv =3D -1; =20 cleanup: diff --git a/src/util/virfilecache.c b/src/util/virfilecache.c index dab7216..96ae96d 100644 --- a/src/util/virfilecache.c +++ b/src/util/virfilecache.c @@ -157,9 +157,8 @@ virFileCacheLoad(virFileCachePtr cache, } =20 if (!(loadData =3D cache->handlers.loadFile(file, name, cache->priv)))= { - virErrorPtr err =3D virGetLastError(); VIR_WARN("Failed to load cached data from '%s' for '%s': %s", - file, name, err ? NULLSTR(err->message) : "unknown error"= ); + file, name, virGetLastErrorMessage()); virResetLastError(); ret =3D 0; goto cleanup; diff --git a/src/util/virxml.c b/src/util/virxml.c index 6e87605..3d3d08e 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -708,7 +708,7 @@ catchXMLError(void *ctx, const char *msg ATTRIBUTE_UNUS= ED, ...) =20 /* conditions for error printing */ if (!ctxt || - (virGetLastError() !=3D NULL) || + (virHasLastError()) || ctxt->input =3D=3D NULL || ctxt->lastError.level !=3D XML_ERR_FATAL || ctxt->lastError.message =3D=3D NULL) @@ -845,7 +845,7 @@ virXMLParseHelper(int domcode, xmlFreeDoc(xml); xml =3D NULL; =20 - if (virGetLastError() =3D=3D NULL) { + if (!virHasLastError()) { virGenericReportError(domcode, VIR_ERR_XML_ERROR, "%s", _("failed to parse xml document")); } diff --git a/tests/commandtest.c b/tests/commandtest.c index ad81c2a..06eecba 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -127,7 +127,7 @@ static int test0(const void *unused ATTRIBUTE_UNUSED) if (virCommandRun(cmd, NULL) =3D=3D 0) goto cleanup; =20 - if (virGetLastError() =3D=3D NULL) + if (!virHasLastError()) goto cleanup; =20 virResetLastError(); diff --git a/tests/testutils.c b/tests/testutils.c index 4b13d11..9bef446 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -178,8 +178,7 @@ virTestRun(const char *title, =20 virResetLastError(); ret =3D body(data); - virErrorPtr err =3D virGetLastError(); - if (err) { + if (virHasLastError()) { 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 =3D virGetLastError(); - if (!lerr) { + if (!virHasLastError()) { # if 0 fprintf(stderr, " alloc %zu failed but no error report= \n", i + 1); # endif diff --git a/tests/virhostcputest.c b/tests/virhostcputest.c index cb318df..34cf015 100644 --- a/tests/virhostcputest.c +++ b/tests/virhostcputest.c @@ -49,7 +49,7 @@ linuxTestCompareFiles(const char *cpuinfofile, &nodeinfo.nodes, &nodeinfo.sockets, &nodeinfo.cores, &nodeinfo.threads)= < 0) { if (virTestGetDebug()) { - if (virGetLastError()) + if (virHasLastError()) VIR_TEST_DEBUG("\n%s\n", virGetLastErrorMessage()); } VIR_FORCE_FCLOSE(cpuinfo); diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 0e11602..adc3ae7 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -333,7 +333,7 @@ testStorageChain(const void *args) goto cleanup; } if (data->flags & EXP_WARN) { - if (!virGetLastError()) { + if (!virHasLastError()) { fprintf(stderr, "call should have warned\n"); goto cleanup; } @@ -343,7 +343,7 @@ testStorageChain(const void *args) goto cleanup; } } else { - if (virGetLastError()) { + if (virHasLastError()) { fprintf(stderr, "call should not have warned\n"); goto cleanup; } @@ -449,13 +449,13 @@ testStorageLookup(const void *args) idx, NULL); =20 if (!data->expResult) { - if (!virGetLastError()) { + if (!virHasLastError()) { fprintf(stderr, "call should have failed\n"); ret =3D -1; } virResetLastError(); } else { - if (virGetLastError()) { + if (virHasLastError()) { fprintf(stderr, "call should not have warned\n"); ret =3D -1; } diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 8e07177..32099cb 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -63,7 +63,6 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr d= om, bool title, unsigned int flags) { char *desc =3D NULL; - virErrorPtr err =3D NULL; xmlDocPtr doc =3D NULL; xmlXPathContextPtr ctxt =3D NULL; int type; @@ -76,15 +75,15 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr= dom, bool title, if ((desc =3D virDomainGetMetadata(dom, type, NULL, flags))) { return desc; } else { - err =3D virGetLastError(); + int errCode =3D virGetLastErrorCode(); =20 - if (err && err->code =3D=3D VIR_ERR_NO_DOMAIN_METADATA) { + if (errCode =3D=3D VIR_ERR_NO_DOMAIN_METADATA) { desc =3D vshStrdup(ctl, ""); vshResetLibvirtError(); return desc; } =20 - if (err && err->code !=3D VIR_ERR_NO_SUPPORT) + if (errCode !=3D VIR_ERR_NO_SUPPORT) return desc; } =20 diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 2b775fc..54f00dc 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -94,9 +94,7 @@ virshDomainDefine(virConnectPtr conn, const char *xml, un= signed int flags) * try again. */ if (!dom) { - virErrorPtr err =3D virGetLastError(); - if (err && - (err->code =3D=3D VIR_ERR_NO_SUPPORT) && + if ((virGetLastErrorCode() =3D=3D VIR_ERR_NO_SUPPORT) && (flags =3D=3D VIR_DOMAIN_DEFINE_VALIDATE)) dom =3D virDomainDefineXML(conn, xml); } diff --git a/tools/virsh-util.c b/tools/virsh-util.c index 44be3ad..aa88397 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -123,8 +123,7 @@ virshDomainState(vshControl *ctl, if (!priv->useGetInfo) { int state; if (virDomainGetState(dom, &state, reason, 0) < 0) { - virErrorPtr err =3D virGetLastError(); - if (err && err->code =3D=3D VIR_ERR_NO_SUPPORT) + if (virGetLastErrorCode() =3D=3D VIR_ERR_NO_SUPPORT) priv->useGetInfo =3D true; else return -1; diff --git a/tools/vsh.c b/tools/vsh.c index 73ec007..8799cd2 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -266,7 +266,7 @@ vshSaveLibvirtHelperError(void) if (last_error) return; =20 - if (!virGetLastError()) + if (!virHasLastError()) return; =20 vshSaveLibvirtError(); --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list