From nobody Fri May 3 19:29:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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=1623774538; cv=none; d=zohomail.com; s=zohoarc; b=cuh/aTqJQXEFV+QSFL+LMnxscOyqRZEkqZMP9BrtrN5HOve/gWLSLutWzy5/fCzxKkBzq+LUtvVclP4W9W7pCkqajPYyv2xsVgvCcStDFPsCSmcsG89MsDlanAPalyXRL+2VlCVIoWrbEpzb2bMusHG8z4D6xLTbT1Tr0rEpi+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623774538; 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; bh=wk+cgFeFSIGl8bhuIjpQEMQrAyox/eLgOx021JBL+C8=; b=QeYQPAhtzc1K05//7dQzSscCh0uZgTlTqBj4M6P33CM9FM7ZoAtQ/NialcknJFm2g51UbNQvjf5wIh4xbeDBbiJC+dKl6lH7kkiFo2j5ERkcfoFBLTeC4n8o3FzR9zxEbiDBDY4IuM+3ANSl0lSpRlPTqWZ2B3oQhdIK/MP7Mcw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1623774538711743.5422591849409; Tue, 15 Jun 2021 09:28:58 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-546-nEmvVKh8PRqCbCarrOo-tg-1; Tue, 15 Jun 2021 12:28:55 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 53251801B37; Tue, 15 Jun 2021 16:28:50 +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 3F89360E3A; Tue, 15 Jun 2021 16:28:49 +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 C32EB4EA6C; Tue, 15 Jun 2021 16:28:46 +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 15FGSj9s023665 for ; Tue, 15 Jun 2021 12:28:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 099BA60E3A; Tue, 15 Jun 2021 16:28:45 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-10.phx2.redhat.com [10.3.114.10]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CFB1460C4A for ; Tue, 15 Jun 2021 16:28:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623774537; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=wk+cgFeFSIGl8bhuIjpQEMQrAyox/eLgOx021JBL+C8=; b=WqaibxHNFNJc2t4Ql5EE+VBtzuUCeIUFFUojKqSi7qYXO/55PnOziZWaRIuqXJGbFgsxqD aS9ar2DjZJLqxjJ69WNCz083cHvCNzHzcIdN4L0geM14TiAM0fk79YdmFiJhCPxbkLe1iK bcvDQSINnFUltH/XpY+W5xw0trXlmR8= X-MC-Unique: nEmvVKh8PRqCbCarrOo-tg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 1/3] nodedev: Remove useless device name from error message Date: Tue, 15 Jun 2021 11:28:38 -0500 Message-Id: <20210615162840.269488-2-jjongsma@redhat.com> In-Reply-To: <20210615162840.269488-1-jjongsma@redhat.com> References: <20210615162840.269488-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" At the point where the error message is emitted, the field def->name is still set to "new device", so the error message becomes: Unable to start mediated device 'new device': ... Since the name doesn't contain anything useful, just omit it from the error message altogether. Signed-off-by: Jonathon Jongsma Reviewed-by: Peter Krempa --- src/node_device/node_device_driver.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 8a0a2c3847..0f13cb4849 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -847,8 +847,8 @@ nodeDeviceCreateXMLMdev(virConnectPtr conn, if (virMdevctlCreate(def, &uuid, &errmsg) < 0) { if (errmsg) virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to start mediated device '%s': %s"), - def->name, errmsg); + _("Unable to start mediated device: %s"), + errmsg); return NULL; } =20 --=20 2.31.1 From nobody Fri May 3 19:29:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1623774549; cv=none; d=zohomail.com; s=zohoarc; b=Efnl/Zw17TyPecnsCu6KDGRCtdpnUU0v63nNuS70QFhgpCwHEKWX8gztWPdSUNJx4O/YA6LAo2kYXFbsOUM4uEqX3iPqsyHDmGVOP+gjfPBlyTDF36pok19GeZ49blqaiKKihkFnjC9BpEB0O842Jd67eg9/mkEhlp1puL9rhL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623774549; 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; bh=CNqvf/+zHex+BeTUfKPHsQF30wZWe2oDTRkOonB/ir4=; b=LBUk0HU66oXWwsVuQN5+DCvl9Ep4LFI/DjLVqcbGwDDffZE4fPx981fknK5ULRH7YpWIUOEovfurVzBMR1s4A4SpTElYXXk5IDTwODXCQEpRby7Y9IUTsLaBQuLTTktb8UfX8H01bsxiBX+tpDX+hReudW5AqR3BhAeAet48jAA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 162377454998451.47466120023455; Tue, 15 Jun 2021 09:29:09 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-307-nL407zrOPE-dg5E8ViGCzA-1; Tue, 15 Jun 2021 12:29:07 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D253A8015D0; Tue, 15 Jun 2021 16:29:01 +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 B5B5F18F0A; Tue, 15 Jun 2021 16:29:01 +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 7EAAE1809CBB; Tue, 15 Jun 2021 16:29:01 +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 15FGSjC6023670 for ; Tue, 15 Jun 2021 12:28:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5468860E3A; Tue, 15 Jun 2021 16:28:45 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-10.phx2.redhat.com [10.3.114.10]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2651860C4A for ; Tue, 15 Jun 2021 16:28:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623774548; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=CNqvf/+zHex+BeTUfKPHsQF30wZWe2oDTRkOonB/ir4=; b=bosDohmX4fK5qynNnEfJtXsRZyv3K3lks4me2PQ+ZpLC0dcFFcgcixuATAr5E1R27MmmQv AEi8denVl3cFu2i7O6FZPk8XFb5E8HqehUlQp6QeTWUrH+Bdw27YkZ3jpyp1vtN4Hj6w72 xqBrul/Sjb+mUW9VXWL1NWeRw70RKGc= X-MC-Unique: nL407zrOPE-dg5E8ViGCzA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 2/3] nodedev: Handle NULL command variable Date: Tue, 15 Jun 2021 11:28:39 -0500 Message-Id: <20210615162840.269488-3-jjongsma@redhat.com> In-Reply-To: <20210615162840.269488-1-jjongsma@redhat.com> References: <20210615162840.269488-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In commit 68580a51, I removed the checks for NULL cmd variables because virCommandRun() already handles the case where it is called with a NULL cmd. Unfortunately, it handles this case by raising a generic error which is both unhelpful and overwrites our existing error message. So for example, when I attempt to create a mediated device with an invalid parent, I get the following output: virsh # nodedev-create mdev-test.xml error: Failed to create node device from mdev-test.xml error: internal error: invalid use of command API With this patch, I now get a useful error message again: virsh # nodedev-create mdev-test.xml error: Failed to create node device from mdev-test.xml error: internal error: unable to find parent device 'pci_0000_00_03_0' Signed-off-by: Jonathon Jongsma --- src/node_device/node_device_driver.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 0f13cb4849..e6d4e6ccb1 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -799,9 +799,10 @@ virMdevctlCreate(virNodeDeviceDef *def, char **uuid, c= har **errmsg) MDEVCTL_CMD_CR= EATE, uuid, errmsg); + /* an auto-generated uuid is returned via stdout if no uuid is specifi= ed in * the mdevctl args */ - if (virCommandRun(cmd, &status) < 0 || status !=3D 0) + if (!cmd || virCommandRun(cmd, &status) < 0 || status !=3D 0) return -1; =20 /* remove newline */ @@ -821,7 +822,7 @@ virMdevctlDefine(virNodeDeviceDef *def, char **uuid, ch= ar **errmsg) =20 /* an auto-generated uuid is returned via stdout if no uuid is specifi= ed in * the mdevctl args */ - if (virCommandRun(cmd, &status) < 0 || status !=3D 0) + if (!cmd || virCommandRun(cmd, &status) < 0 || status !=3D 0) return -1; =20 /* remove newline */ @@ -925,7 +926,7 @@ virMdevctlStop(virNodeDeviceDef *def, char **errmsg) =20 cmd =3D nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_STOP, NULL, errms= g); =20 - if (virCommandRun(cmd, &status) < 0 || status !=3D 0) + if (!cmd || virCommandRun(cmd, &status) < 0 || status !=3D 0) return -1; =20 return 0; @@ -940,7 +941,7 @@ virMdevctlUndefine(virNodeDeviceDef *def, char **errmsg) =20 cmd =3D nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_UNDEFINE, NULL, e= rrmsg); =20 - if (virCommandRun(cmd, &status) < 0 || status !=3D 0) + if (!cmd || virCommandRun(cmd, &status) < 0 || status !=3D 0) return -1; =20 return 0; @@ -955,7 +956,7 @@ virMdevctlStart(virNodeDeviceDef *def, char **errmsg) =20 cmd =3D nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_START, NULL, errm= sg); =20 - if (virCommandRun(cmd, &status) < 0 || status !=3D 0) + if (!cmd || virCommandRun(cmd, &status) < 0 || status !=3D 0) return -1; =20 return 0; --=20 2.31.1 From nobody Fri May 3 19:29:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1623774565; cv=none; d=zohomail.com; s=zohoarc; b=Y2MOPd/CX9lS3lIf/GOoF6tokNMhMHutUX38L2u2lQX8uMTsp8q97N+p8iqTd/OwiZ9nDJXQGEZWU9tJZOsN222yTcKn3ybxn8vUZNnsrpiDeDzwQBJxNsKa8Ae/Tb+/PSRFkVWUmJOX5JzusS58JBpy0j7rBO2dbw575d3XfzY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623774565; 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; bh=yzn/B2M57yZ5YlEZ+Qwd6aNWHi/GEnOOBM3z/IO7oII=; b=ZI6jZU8SQ7/xQwxm58V8chOKupxP8d5SQbT+Q/qEmaW1Iz1Xq7jyeGYkCeW/4646FxZlH0eNkoYQQzUfR+8GP738ZnlrIPKNH5l+zSDIFPwc0+bnhspDkQX7/z6DaWc5Uc+doJmd2Mu18YoWek9ympIUwpRDZ/1BVJgFfxXVrTM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1623774565519849.9139847080421; Tue, 15 Jun 2021 09:29:25 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-335-GQ_isu9NPnywCtKI8cEO_w-1; Tue, 15 Jun 2021 12:29:10 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B80F0100C612; Tue, 15 Jun 2021 16:29:04 +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 8A0811000358; Tue, 15 Jun 2021 16:29:04 +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 43D661809CBD; Tue, 15 Jun 2021 16:29:04 +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 15FGSjCU023678 for ; Tue, 15 Jun 2021 12:28:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9EE3060C4A; Tue, 15 Jun 2021 16:28:45 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-10.phx2.redhat.com [10.3.114.10]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7103060E3A for ; Tue, 15 Jun 2021 16:28:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623774564; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=yzn/B2M57yZ5YlEZ+Qwd6aNWHi/GEnOOBM3z/IO7oII=; b=bBoj4ADmAj0PzlBIZbt1WVVQ+QKhnucOPHuHaugvwyrspvzUxtxmalHMvyvNYuNvuJakP0 9wWBz2F0bD6m1mn/XHbEGHX+E/QrjVLjwghgR7hbc4VxB6l+dEFaojFo3yDjyDx2AXDGnE +lQSymxTsspUkCMc/a5n3O/QZCM7cZY= X-MC-Unique: GQ_isu9NPnywCtKI8cEO_w-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 3/3] nodedev: handle mdevctl errors consistently Date: Tue, 15 Jun 2021 11:28:40 -0500 Message-Id: <20210615162840.269488-4-jjongsma@redhat.com> In-Reply-To: <20210615162840.269488-1-jjongsma@redhat.com> References: <20210615162840.269488-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Currently, we have two different types of mdevctl errors: 1. the command cannot be executed due to some error 2. the command is executed, but returns an error status These two different failures are handled differently. Scenario 1 calls virReportError() from within nodeDeviceGetMdevctlCommand() and returns an error status (-1). Scenario 2 also returns -1, but does not call virReportError() and instead passes the error message back in the errmsg argument. This means that the caller has to check both whether the return value is negative and whether the errmsg parameter is non-NULL before deciding whether to report the error or not. The situation is further complicated by the fact that there are occasional instances where mdevctl exits with an error status but does not print an error message. This results in errmsg being an empty string "" (i.e. non-NULL). Simplify the situation by not calling virReportError() at all from within nodeDeviceGetMdevctlCommand() and instead returning an error message for those that previously called virReportError(). The caller is now always responsible for reporting the error. Also introduce a simple macro that converts NULL or empty errmsg to "Unknown Error". Signed-off-by: Jonathon Jongsma --- src/node_device/node_device_driver.c | 34 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index e6d4e6ccb1..3cf9fc129f 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -752,14 +752,13 @@ nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def, parent_addr =3D nodeDeviceFindAddressByName(def->parent); =20 if (!parent_addr) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unable to find parent device '%s'"), def->pa= rent); + *errbuf =3D g_strdup_printf(_("unable to find parent device '%= s'"), + def->parent); return NULL; } =20 if (nodeDeviceDefToMdevctlConfig(def, &inbuf) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("couldn't convert node device def to mdevctl = JSON")); + *errbuf =3D g_strdup(_("couldn't convert node device def to md= evctl JSON")); return NULL; } =20 @@ -832,6 +831,9 @@ virMdevctlDefine(virNodeDeviceDef *def, char **uuid, ch= ar **errmsg) } =20 =20 +#define MDEVCTL_ERROR(msg) msg && msg[0] !=3D '\0' ? msg : _("Unknown erro= r") + + static virNodeDevicePtr nodeDeviceCreateXMLMdev(virConnectPtr conn, virNodeDeviceDef *def) @@ -846,10 +848,9 @@ nodeDeviceCreateXMLMdev(virConnectPtr conn, } =20 if (virMdevctlCreate(def, &uuid, &errmsg) < 0) { - if (errmsg) - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to start mediated device: %s"), - errmsg); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to start mediated device: %s"), + MDEVCTL_ERROR(errmsg)); return NULL; } =20 @@ -1201,10 +1202,9 @@ nodeDeviceDestroy(virNodeDevicePtr device) } =20 if (virMdevctlStop(def, &errmsg) < 0) { - if (errmsg) - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to destroy '%s': %s"), def->name, - errmsg); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to destroy '%s': %s"), def->name, + MDEVCTL_ERROR(errmsg)); goto cleanup; } ret =3D 0; @@ -1310,9 +1310,9 @@ nodeDeviceDefineXML(virConnect *conn, } =20 if (virMdevctlDefine(def, &uuid, &errmsg) < 0) { - if (errmsg) - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to define mediated device: %s"), errm= sg); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to define mediated device: %s"), + MDEVCTL_ERROR(errmsg)); return NULL; } =20 @@ -1372,7 +1372,7 @@ nodeDeviceUndefine(virNodeDevice *device, if (virMdevctlUndefine(def, &errmsg) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to undefine mediated device: %s"), - errmsg && errmsg[0] ? errmsg : "Unknown Error"); + MDEVCTL_ERROR(errmsg)); goto cleanup; } ret =3D 0; @@ -1419,7 +1419,7 @@ nodeDeviceCreate(virNodeDevice *device, if (virMdevctlStart(def, &errmsg) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to create mediated device: %s"), - errmsg && errmsg[0] ? errmsg : "Unknown Error"); + MDEVCTL_ERROR(errmsg)); goto cleanup; } ret =3D 0; --=20 2.31.1