From nobody Wed May 14 09:23:19 2025 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