From nobody Thu Apr 25 06:07:15 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560254526; cv=none; d=zoho.com; s=zohoarc; b=OMuh42yJ2lL819mp1HDrx1wdcNtVlWGVdufY2qG8iv89pQTl3s6nYiKXAccgohdDdGz0DTPOcRu3M5WTqaD1/xoBvGFOhfeJt76nfL23rxBGT0daAOdcRntcjzCBDRSfkUXsziHVW27O4fTr4WtPrq8S5Rp+nbsnZnhE92WwTM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560254526; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=GG8UqA+t0ycEQSOoD1pfRCoTDLh0RrDZM7Ufsk/BFcg=; b=KjtZuGCOj5JIWcsjjWzziInOuG4jTh6uwgC6HDOZCY6j/Ce3rcDfw58wwxw23cwkY/CgTMHMGeBxny9CeW+OT3eRtzolPVKdSPpvm+naE17Q3cxjUXIEyWNzxFy/8fp7uwTfyoFRmhWSwBzsAxr5uKMxTcMX8uei19HwaJne7tM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1560254526570878.9401301558253; Tue, 11 Jun 2019 05:02:06 -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 EC0AA821CB; Tue, 11 Jun 2019 12:01:38 +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 AB9A061B6D; Tue, 11 Jun 2019 12:01:34 +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 242441833004; Tue, 11 Jun 2019 12:01:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5BC1TAN002778 for ; Tue, 11 Jun 2019 08:01:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9700B60C05; Tue, 11 Jun 2019 12:01:29 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20CB060BF1 for ; Tue, 11 Jun 2019 12:01:28 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Jun 2019 14:01:26 +0200 Message-Id: <79253c76bd4c178227a0a026136712526bfc20cd.1560254455.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/2] util: error: Add API for prefixing last set error with a string 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: , 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.28]); Tue, 11 Jun 2019 12:01:49 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In some cases we report a low level error message which does not have enough information to see what the problem is. To allow improving on this add an API which will prefix the error message with another error message string which can be used to describe where the error comes from. Signed-off-by: Peter Krempa --- cfg.mk | 1 + src/libvirt_private.syms | 1 + src/util/virerror.c | 38 ++++++++++++++++++++++++++++++++++++++ src/util/virerror.h | 3 +++ 4 files changed, 43 insertions(+) diff --git a/cfg.mk b/cfg.mk index 5074ef611a..f99b0d0b55 100644 --- a/cfg.mk +++ b/cfg.mk @@ -614,6 +614,7 @@ msg_gen_function +=3D virReportError msg_gen_function +=3D virReportErrorHelper msg_gen_function +=3D virReportSystemError msg_gen_function +=3D xenapiSessionErrorHandler +msg_gen_function +=3D virLastErrorPrefixMessage # Uncomment the following and run "make syntax-check" to see diagnostics # that are not yet marked for translation, but that need to be rewritten diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8ee76645cd..1ded794931 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1810,6 +1810,7 @@ virErrorPreserveLast; virErrorRestore; virErrorSetErrnoFromLastError; virLastErrorIsSystemErrno; +virLastErrorPrefixMessage; virRaiseErrorFull; virRaiseErrorObject; virReportErrorHelper; diff --git a/src/util/virerror.c b/src/util/virerror.c index 37b5b2f3f9..7c5f4da8e8 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -1452,3 +1452,41 @@ bool virLastErrorIsSystemErrno(int errnum) return false; return true; } + + +/** + * virLastErrorPrefixMessage: + * @fmt: printf-style formatting string + * @...: Arguments for @fmt + * + * Prefixes last error reported with message formatted from @fmt. This is = useful + * if the low level error message does not convey enough information to de= scribe + * the problem. + */ +void +virLastErrorPrefixMessage(const char *fmt, ...) +{ + int save_errno =3D errno; + virErrorPtr err =3D virGetLastError(); + VIR_AUTOFREE(char *) fmtmsg =3D NULL; + VIR_AUTOFREE(char *) newmsg =3D NULL; + va_list args; + + if (!err) + return; + + va_start(args, fmt); + + if (virVasprintfQuiet(&fmtmsg, fmt, args) < 0) + goto cleanup; + + if (virAsprintfQuiet(&newmsg, "%s: %s", fmtmsg, err->message) < 0) + goto cleanup; + + VIR_FREE(err->message); + VIR_STEAL_PTR(err->message, newmsg); + + cleanup: + va_end(args); + errno =3D save_errno; +} diff --git a/src/util/virerror.h b/src/util/virerror.h index 8f51510dc2..ca875fb8f4 100644 --- a/src/util/virerror.h +++ b/src/util/virerror.h @@ -206,6 +206,9 @@ bool virLastErrorIsSystemErrno(int errnum); void virErrorPreserveLast(virErrorPtr *saveerr); void virErrorRestore(virErrorPtr *savederr); +void virLastErrorPrefixMessage(const char *fmt, ...) + ATTRIBUTE_FMT_PRINTF(1, 2); + VIR_DEFINE_AUTOPTR_FUNC(virError, virFreeError); #endif /* LIBVIRT_VIRERROR_H */ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 06:07:15 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560254540; cv=none; d=zoho.com; s=zohoarc; b=h9Y/PlXCfOsr4WmSAIb1HBxgO71PkJ2u/R+RvCfEc/hgIg6P4euvxN8ly0ZZXQ489G/1bS2T8bXWp4er7A2sk/2j4kExoofLnJ07qGhfvcHeJn1wnmQtsP6h8EgrSCY8qKQMSI1WwjZzo4Sd8iqVlFGPdhqbi/P+hmSBQMc3yDs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560254540; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=5XICxwz8RZ+OWl89QBphET3TUQR/YZFpVQYpHSTeHpU=; b=C1y00LJhecALpyEx/ZnhdN1DGSvXGhZ7qDOYRlCitFZvz4VZfQImVpW3Oc+lChhky2RVhM5SyxiKXdrDsWUlVacyiKw9iIX+3RQvnUOzm9831zL2LokQW0DHT72U8Mkp4CKuu+V1aj84t8k/LYAJviZAUt7Mm9jZF83elWHztAk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1560254540408412.88809212407466; Tue, 11 Jun 2019 05:02:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1B5C3C0733C9; Tue, 11 Jun 2019 12:02:10 +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 D8B46611B2; Tue, 11 Jun 2019 12:02:08 +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 7E87A1833006; Tue, 11 Jun 2019 12:02:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5BC1U0g002785 for ; Tue, 11 Jun 2019 08:01:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 64B7360C18; Tue, 11 Jun 2019 12:01:30 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3C5160BF1 for ; Tue, 11 Jun 2019 12:01:29 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Jun 2019 14:01:27 +0200 Message-Id: <65855fb52f0d8d9da5e8c1a4d2396cec429e9007.1560254455.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/2] qemu: process: Report better error when virtlogd connection fails 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: , 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 11 Jun 2019 12:02:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" When connecting to virtlogd fails e.g. due to wrong libvirtd selinux process label we'd report an utterly useless error message: $ virsh start upstream error: Failed to start domain upstream error: Cannot recv data: Connection reset by peer Use virLastErrorPrefixMessage in the correct place to give a better sense of what's going on: $ virsh start upstream error: Failed to start domain upstream error: can't connect to virtlogd: Cannot recv data: Connection reset by peer Signed-off-by: Peter Krempa --- src/qemu/qemu_process.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 50a76aa0ed..0ac3e0727b 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6604,8 +6604,10 @@ qemuProcessLaunch(virConnectPtr conn, VIR_DEBUG("Creating domain log file"); if (!(logCtxt =3D qemuDomainLogContextNew(driver, vm, - QEMU_DOMAIN_LOG_CONTEXT_MODE_S= TART))) + QEMU_DOMAIN_LOG_CONTEXT_MODE_S= TART))) { + virLastErrorPrefixMessage("%s", _("can't connect to virtlogd")); goto cleanup; + } logfile =3D qemuDomainLogContextGetWriteFD(logCtxt); if (qemuProcessGenID(vm, flags) < 0) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list