From nobody Wed May 1 23:59:00 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=1624391699; cv=none; d=zohomail.com; s=zohoarc; b=b3y+AO1JC533wqk9qXoEFFJ4H+dyHlZdxd6PMbUeLf90yyFiUi9IBvi9UQpSqJJAuMWkeGi+zTHfBRPnNxwmtv+UHqL8d5Yoh/PMiQdEsC7nhOm0VUK6OlTZTogP242t8hedrddy4yX9wxN6JBGpnaRej/m0mV4h6G3vqp5ZPoM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624391699; h=Content-Type:Content-Transfer-Encoding:Cc: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=gUO8f6UHI2td1x2ZLUMBSuzHkMMbVFg17JyfrlYAePk=; b=Iac0WHzcNbgTDVv13XBXzAAv3a9OHAZWyiO4EhV4VGP5Bv7lytwx2Vk/XCbEN6QpyiWW+Tldw2gHs8fvW5ISBRRpF/FY0FszpgGBBaBA2TDOxhfAYeh9Pf32VMwIxTgOC7Z4cvZ9//9o9x9AvV3+/InhflJAN2OW9/PmmFHFZdU= 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 1624391699667384.26375628288645; Tue, 22 Jun 2021 12:54:59 -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-44-jg8CmWxPMg2Vp7Td_BflGw-1; Tue, 22 Jun 2021 15:54:56 -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 CFEF0362F9; Tue, 22 Jun 2021 19:54: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 C1B9A17C5F; Tue, 22 Jun 2021 19:54:47 +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 1A9294E9F4; Tue, 22 Jun 2021 19:54:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15MJrf1f016868 for ; Tue, 22 Jun 2021 15:53:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 833A65D9F0; Tue, 22 Jun 2021 19:53:41 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-18.phx2.redhat.com [10.3.112.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4699D5D9DE; Tue, 22 Jun 2021 19:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624391698; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=gUO8f6UHI2td1x2ZLUMBSuzHkMMbVFg17JyfrlYAePk=; b=Rs04K0TcD/+6QRr/CbWNkUnXKqr/AnE3adQFMVsk42f1+n/plkwTFfs/bpW53UnM9PXqoK cLHsniUMI7D1Ivi/5mNBbct10JCpXIzwfm/q66vEsjNb/Xksha6vnZInw0pLCwWpWND7+/ Y8riQOSyFFbngBS4eQVRewStWG11ius= X-MC-Unique: jg8CmWxPMg2Vp7Td_BflGw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 1/5] nodedev: Remove useless device name from error message Date: Tue, 22 Jun 2021 14:53:32 -0500 Message-Id: <20210622195336.814205-2-jjongsma@redhat.com> In-Reply-To: <20210622195336.814205-1-jjongsma@redhat.com> References: <20210622195336.814205-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Peter Krempa 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" 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 Reviewed-by: Boris Fiuczynski --- 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 Wed May 1 23:59:00 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=1624391715; cv=none; d=zohomail.com; s=zohoarc; b=m2lNtQto2Bx2gQhDV+RsGDrw1nSpq8E9b9zTdOXC+yDcq+xIklbwmZE8unxoVog1ddgDLrkQPdFj7UJCkiM927HMqi0XG9By9hDOMk0eV+ySeoqx+J2fnfijWHQ+dB/jRi2HE/5m3ybN0A+tqC6VZCTTNmemhAILt0wHoxedL/Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624391715; 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=7K9kjMENdK4r5IWemUVS0+mVkSwvm5v3JakSBXdWoPA=; b=kcixST1ArTeoeS3CJ0nQkKQrywu06NSCooGjCndyGfIz5wy1/3ikZhDsZY2Wp+J3Zh05FU83COCQGzfVZ8Coyy26LeiQAB32xSSVhUpsj0DbV2Ks9l3om5w1LOhPbmWiGs8iDindOvykFLpgJ2I2DsRAtq9+FYmNXbRYHOfocvs= 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 1624391715656466.4753626224174; Tue, 22 Jun 2021 12:55:15 -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-62-PrY6LBJfPGeQ8CA9H4wLzg-1; Tue, 22 Jun 2021 15:55:12 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B570A800685; Tue, 22 Jun 2021 19:55:07 +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 6013C19C66; Tue, 22 Jun 2021 19:55:07 +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 1E1164EA3C; Tue, 22 Jun 2021 19:55:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15MJrfLe016873 for ; Tue, 22 Jun 2021 15:53:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id CCFB85D9F0; Tue, 22 Jun 2021 19:53:41 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-18.phx2.redhat.com [10.3.112.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9F5EA5D9DE for ; Tue, 22 Jun 2021 19:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624391714; 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=7K9kjMENdK4r5IWemUVS0+mVkSwvm5v3JakSBXdWoPA=; b=CHZxXn7HydrgpiCsk4W+F2uTZ9wgtF1GcqonB5YX77DfcIwwVd12SQQgNGDQ80WdEjsgFL l/JUt1cWjbnAJF+dJF3Yrt4d50gWGIKJdRK5S8vMXGlrA701Ngo/0p6IFtfblh6AS43+fb obhHz4QEtTh5iQi7beYIO4/AtDda1Z8= X-MC-Unique: PrY6LBJfPGeQ8CA9H4wLzg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 2/5] nodedev: Handle NULL command variable Date: Tue, 22 Jun 2021 14:53:33 -0500 Message-Id: <20210622195336.814205-3-jjongsma@redhat.com> In-Reply-To: <20210622195336.814205-1-jjongsma@redhat.com> References: <20210622195336.814205-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.23 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 Reviewed-by: Boris Fiuczynski --- src/node_device/node_device_driver.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 0f13cb4849..43a8c1bf60 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -799,6 +799,10 @@ virMdevctlCreate(virNodeDeviceDef *def, char **uuid, c= har **errmsg) MDEVCTL_CMD_CR= EATE, uuid, errmsg); + + if (!cmd) + return -1; + /* 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) @@ -819,6 +823,9 @@ virMdevctlDefine(virNodeDeviceDef *def, char **uuid, ch= ar **errmsg) MDEVCTL_CMD_DE= FINE, uuid, errmsg); =20 + if (!cmd) + return -1; + /* 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) @@ -925,6 +932,9 @@ virMdevctlStop(virNodeDeviceDef *def, char **errmsg) =20 cmd =3D nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_STOP, NULL, errms= g); =20 + if (!cmd) + return -1; + if (virCommandRun(cmd, &status) < 0 || status !=3D 0) return -1; =20 @@ -940,6 +950,9 @@ virMdevctlUndefine(virNodeDeviceDef *def, char **errmsg) =20 cmd =3D nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_UNDEFINE, NULL, e= rrmsg); =20 + if (!cmd) + return -1; + if (virCommandRun(cmd, &status) < 0 || status !=3D 0) return -1; =20 @@ -955,6 +968,9 @@ virMdevctlStart(virNodeDeviceDef *def, char **errmsg) =20 cmd =3D nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_START, NULL, errm= sg); =20 + if (!cmd) + return -1; + if (virCommandRun(cmd, &status) < 0 || status !=3D 0) return -1; =20 --=20 2.31.1 From nobody Wed May 1 23:59:00 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=1624391773; cv=none; d=zohomail.com; s=zohoarc; b=PmMF0hqYxQ0H4TtzNZ3pZIYHbv7DKfKI5r2MBm+f2P/YeB+lW22V5Edt8BDLpOV5oPGKUkBtCKKiFpbPbY/sZBcHAuhyEF8cRLyNkXu1GLIL70GE2+VXCJbFCFXtU13yChLpgMYiOqLxRggY+b7n9vaKxg7UeL/PqnQtgFv8idU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624391773; 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=7tGOrMU2JyIf7Ndw/i06dY+r3DDNuW2nybjp4QBc7vY=; b=LFmE4Rl/ejU1HW0aB9JMMYdI1lusvZ8gDVRG06HnpQjhPrQYZ6pMJQUwMQRAdYPrufz/KZdB+pXiYGM8xyrdNPfs8rwN+rJ3/GP85j2y1d8vQIauwb8MhX3eOgH7l44tduF1RG8CUMg/f9bF5rY9hraNf+vw+NKe8rrOWNRUkM4= 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 1624391773125206.2241540820994; Tue, 22 Jun 2021 12:56:13 -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-169-xnbVW32mPNKcsGV40tvF8w-1; Tue, 22 Jun 2021 15:55:02 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 316228042A8; Tue, 22 Jun 2021 19:54:57 +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 105FC5D9F0; Tue, 22 Jun 2021 19:54:57 +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 B9F0C4EA38; Tue, 22 Jun 2021 19:54:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15MJrgqG016878 for ; Tue, 22 Jun 2021 15:53:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 220375D9F0; Tue, 22 Jun 2021 19:53:42 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-18.phx2.redhat.com [10.3.112.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E8AAD5D9DE for ; Tue, 22 Jun 2021 19:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624391772; 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=7tGOrMU2JyIf7Ndw/i06dY+r3DDNuW2nybjp4QBc7vY=; b=jVOan37faz7QJu7t80ATWwizjPOP+T8/Y7/Pt6Asne8Nkn3spCTmFYRg2IIIj+tnnL5JVq dzYIrnczE1s1N4PdphxRiiPX+M227GqCMBfaCNQyp7f+qKKcUabbGWKFxcsleR67u+66rF yIt2P3p7xvoBWjSIwYNkkX7nywIGuwo= X-MC-Unique: xnbVW32mPNKcsGV40tvF8w-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 3/5] nodedev: add macro to handle command errors Date: Tue, 22 Jun 2021 14:53:34 -0500 Message-Id: <20210622195336.814205-4-jjongsma@redhat.com> In-Reply-To: <20210622195336.814205-1-jjongsma@redhat.com> References: <20210622195336.814205-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.14 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" This macro will be utilized in the following patch. Since mdevctl commands can fail with or without an error message, this macro makes it easy to print a fallback error in the case that the error message is not set. Signed-off-by: Jonathon Jongsma Reviewed-by: Boris Fiuczynski --- src/node_device/node_device_driver.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 43a8c1bf60..eb85cc0439 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -57,6 +57,9 @@ VIR_ENUM_IMPL(virMdevctlCommand, ); =20 =20 +#define MDEVCTL_ERROR(msg) (msg && msg[0] !=3D '\0' ? msg : _("Unknown err= or")) + + virDrvOpenStatus nodeConnectOpen(virConnectPtr conn, virConnectAuthPtr auth G_GNUC_UNUSED, @@ -1387,7 +1390,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; @@ -1434,7 +1437,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 From nobody Wed May 1 23:59:00 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=1624391716; cv=none; d=zohomail.com; s=zohoarc; b=gtH3kQuRRi1EFqKGbpsXPDIApU4+Gksg5wjZM+pDbqWvCckmrKIAynqo/YyIAqL5o5no6TkWMkKbOhDbS8AAM6TkdbUzWvHG++I7AoUztnIiPs1efngWjrLzw753ZLkR/1geZq8Yiy5p/tYMv+aNNrGbuxLcHJWoNUxvYLOxEr4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624391716; 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=SuyMJrQznKgiALczAUR7Ic+FV9D7QF4NGhkuTY3s3PU=; b=hfKvf0rWhUvac5QkREMDwPeu1m7xNIiblSZMWwBu/jhUQKbTebqDAgVbWg7NpueAOL6GSp3u8dHVvk9syoZiVO8mgyUzB2lGaaUss2JkPWGaJw/AuTHFKGcT89qGuy8C0ibE/MTPenwIwjvCuuadsJx1QNZ74cDrZUauw+fzCJE= 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 1624391716254688.7086033562869; Tue, 22 Jun 2021 12:55:16 -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-21-Esx1olO3OZ-Jr6wJooiceA-1; Tue, 22 Jun 2021 15:55:13 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C524D801596; Tue, 22 Jun 2021 19:55:07 +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 9B77F5D705; Tue, 22 Jun 2021 19:55:07 +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 263001809C99; Tue, 22 Jun 2021 19:55:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15MJrgqU016883 for ; Tue, 22 Jun 2021 15:53:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7AB935D9F0; Tue, 22 Jun 2021 19:53:42 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-18.phx2.redhat.com [10.3.112.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E9245D9DE for ; Tue, 22 Jun 2021 19:53:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624391715; 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=SuyMJrQznKgiALczAUR7Ic+FV9D7QF4NGhkuTY3s3PU=; b=OHBaiwHUNcB7dp7Ips4NHBxWYgBugIamjhIVZ9wKMiZ5YK+JWZ/IyvcdGd45TV2HWIQH6t uShmZZ0xr46cm2mLq7IvqhBAq7ZvRwRAlMZySpD3a9UwNgsJB1BtJAyxeP7+wqFBO/UwG3 NKcbmZ3gLdQY7NQdS0M8vOpckLMIctM= X-MC-Unique: Esx1olO3OZ-Jr6wJooiceA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 4/5] nodedev: handle mdevctl errors consistently Date: Tue, 22 Jun 2021 14:53:35 -0500 Message-Id: <20210622195336.814205-5-jjongsma@redhat.com> In-Reply-To: <20210622195336.814205-1-jjongsma@redhat.com> References: <20210622195336.814205-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.15 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 three different types of mdevctl errors: 1. the command cannot be constructed ecause of unsatisfied preconditions 2. the command cannot be executed due to some error 3. the command is executed, but returns an error status These different failures are handled differently. Some cases set an error and return and error status, and some return a error message but do not set an error. 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 ensuring that virReportError() is called for all error conditions rather than returning an error message back to the calling function. Signed-off-by: Jonathon Jongsma Reviewed-by: Boris Fiuczynski --- src/node_device/node_device_driver.c | 114 +++++++++++++++------------ 1 file changed, 65 insertions(+), 49 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index eb85cc0439..497db0006a 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -746,6 +746,8 @@ nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def, case MDEVCTL_CMD_LAST: default: /* SHOULD NEVER HAPPEN */ + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unknown Command '%i'"), cmd_type); return NULL; } =20 @@ -795,48 +797,62 @@ nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def, =20 =20 static int -virMdevctlCreate(virNodeDeviceDef *def, char **uuid, char **errmsg) +virMdevctlCreate(virNodeDeviceDef *def, char **uuid) { int status; + g_autofree char *errmsg =3D NULL; g_autoptr(virCommand) cmd =3D nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_CR= EATE, uuid, - errmsg); + &errmsg); =20 if (!cmd) return -1; =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 (virCommandRun(cmd, &status) < 0) + return -1; + + if (status !=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to start mediated device: %s"), + MDEVCTL_ERROR(errmsg)); return -1; + } =20 /* remove newline */ *uuid =3D g_strstrip(*uuid); - return 0; } =20 =20 static int -virMdevctlDefine(virNodeDeviceDef *def, char **uuid, char **errmsg) +virMdevctlDefine(virNodeDeviceDef *def, char **uuid) { int status; + g_autofree char *errmsg =3D NULL; g_autoptr(virCommand) cmd =3D nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_DE= FINE, - uuid, errmsg); + uuid, &errmsg); =20 if (!cmd) return -1; =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 (virCommandRun(cmd, &status) < 0) return -1; =20 + if (status !=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to define mediated device: %s"), + MDEVCTL_ERROR(errmsg)); + return -1; + } + /* remove newline */ *uuid =3D g_strstrip(*uuid); - return 0; } =20 @@ -846,7 +862,6 @@ nodeDeviceCreateXMLMdev(virConnectPtr conn, virNodeDeviceDef *def) { g_autofree char *uuid =3D NULL; - g_autofree char *errmsg =3D NULL; =20 if (!def->parent) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -854,11 +869,7 @@ nodeDeviceCreateXMLMdev(virConnectPtr conn, return NULL; } =20 - if (virMdevctlCreate(def, &uuid, &errmsg) < 0) { - if (errmsg) - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to start mediated device: %s"), - errmsg); + if (virMdevctlCreate(def, &uuid) < 0) { return NULL; } =20 @@ -928,55 +939,79 @@ nodeDeviceCreateXML(virConnectPtr conn, =20 =20 static int -virMdevctlStop(virNodeDeviceDef *def, char **errmsg) +virMdevctlStop(virNodeDeviceDef *def) { int status; g_autoptr(virCommand) cmd =3D NULL; + g_autofree char *errmsg =3D NULL; =20 - cmd =3D nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_STOP, NULL, errms= g); + cmd =3D nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_STOP, NULL, &errm= sg); =20 if (!cmd) return -1; =20 - if (virCommandRun(cmd, &status) < 0 || status !=3D 0) + if (virCommandRun(cmd, &status) < 0) return -1; =20 + if (status !=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to destroy '%s': %s"), def->name, + MDEVCTL_ERROR(errmsg)); + return -1; + } + return 0; } =20 =20 static int -virMdevctlUndefine(virNodeDeviceDef *def, char **errmsg) +virMdevctlUndefine(virNodeDeviceDef *def) { int status; g_autoptr(virCommand) cmd =3D NULL; + g_autofree char *errmsg =3D NULL; =20 - cmd =3D nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_UNDEFINE, NULL, e= rrmsg); + cmd =3D nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_UNDEFINE, NULL, &= errmsg); =20 if (!cmd) return -1; =20 - if (virCommandRun(cmd, &status) < 0 || status !=3D 0) + if (virCommandRun(cmd, &status) < 0) return -1; =20 + if (status !=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to undefine mediated device: %s"), + MDEVCTL_ERROR(errmsg)); + return -1; + } + return 0; } =20 =20 static int -virMdevctlStart(virNodeDeviceDef *def, char **errmsg) +virMdevctlStart(virNodeDeviceDef *def) { int status; g_autoptr(virCommand) cmd =3D NULL; + g_autofree char *errmsg =3D NULL; =20 - cmd =3D nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_START, NULL, errm= sg); + cmd =3D nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_START, NULL, &err= msg); =20 if (!cmd) return -1; =20 - if (virCommandRun(cmd, &status) < 0 || status !=3D 0) + if (virCommandRun(cmd, &status) < 0) return -1; =20 + if (status !=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to create mediated device: %s"), + MDEVCTL_ERROR(errmsg)); + return -1; + } + return 0; } =20 @@ -1204,7 +1239,6 @@ nodeDeviceDestroy(virNodeDevicePtr device) g_autofree char *vfiogroup =3D virMediatedDeviceGetIOMMUGroupDev(def->caps->data.mdev.uuid); VIR_AUTOCLOSE fd =3D -1; - g_autofree char *errmsg =3D NULL; =20 if (!vfiogroup) goto cleanup; @@ -1218,13 +1252,9 @@ nodeDeviceDestroy(virNodeDevicePtr device) goto cleanup; } =20 - if (virMdevctlStop(def, &errmsg) < 0) { - if (errmsg) - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to destroy '%s': %s"), def->name, - errmsg); + if (virMdevctlStop(def) < 0) goto cleanup; - } + ret =3D 0; } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -1299,7 +1329,6 @@ nodeDeviceDefineXML(virConnect *conn, g_autoptr(virNodeDeviceDef) def =3D NULL; const char *virt_type =3D NULL; g_autofree char *uuid =3D NULL; - g_autofree char *errmsg =3D NULL; g_autofree char *name =3D NULL; =20 virCheckFlags(0, NULL); @@ -1327,10 +1356,7 @@ nodeDeviceDefineXML(virConnect *conn, return NULL; } =20 - if (virMdevctlDefine(def, &uuid, &errmsg) < 0) { - if (errmsg) - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to define mediated device: %s"), errm= sg); + if (virMdevctlDefine(def, &uuid) < 0) { return NULL; } =20 @@ -1385,14 +1411,9 @@ nodeDeviceUndefine(virNodeDevice *device, } =20 if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) { - g_autofree char *errmsg =3D NULL; - - if (virMdevctlUndefine(def, &errmsg) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to undefine mediated device: %s"), - MDEVCTL_ERROR(errmsg)); + if (virMdevctlUndefine(def) < 0) goto cleanup; - } + ret =3D 0; } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -1432,14 +1453,9 @@ nodeDeviceCreate(virNodeDevice *device, goto cleanup; =20 if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) { - g_autofree char *errmsg =3D NULL; - - if (virMdevctlStart(def, &errmsg) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to create mediated device: %s"), - MDEVCTL_ERROR(errmsg)); + if (virMdevctlStart(def) < 0) goto cleanup; - } + ret =3D 0; } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", --=20 2.31.1 From nobody Wed May 1 23:59:00 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=1624391720; cv=none; d=zohomail.com; s=zohoarc; b=EBYPia00vMGJwCO+3E6VA3nZDPFSVmf1W+OEkVDXUnGt0t3/P+whoIzRFjUQAm1igvIyCEi1FPVXVH4gtSyNtc3UsRSG4QpBjH94D28ZnvQOjjg8s67u3EWBCUcWmQp8OKz5XybAOFPBGOz7+/wLaKJHGUbCMq3OjDaXtOX4CSQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624391720; 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=h68KlSe0hlwxcrl+JkYDAO/PqqE5evM3R+Fqoueck7c=; b=CYx/F5G4jzQ0CBiw+Dl1rPlyr91zLyO/2P3SbbyOfZJE6Wmjugi3pE3Ow2lLrQK4T2n98EjcNbtUOkeDKZkWQ6VSBEm2jQEuhuIdICrySJaOkVahDljup9VPNZQ46xrg/0jttNpUAOmsyWjqhehDqsRoMebvufhk22UW1S5P/aw= 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 1624391720418129.1531196314794; Tue, 22 Jun 2021 12:55:20 -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-499-GM8BBXIsMJiNLK7YBbmFXA-1; Tue, 22 Jun 2021 15:55:16 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E71BF100B3B7; Tue, 22 Jun 2021 19:55: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 BBE465D6D1; Tue, 22 Jun 2021 19:55:10 +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 80CE51809CB2; Tue, 22 Jun 2021 19:55:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15MJrgum016888 for ; Tue, 22 Jun 2021 15:53:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id C46015D9F0; Tue, 22 Jun 2021 19:53:42 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-18.phx2.redhat.com [10.3.112.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 967665D9DE for ; Tue, 22 Jun 2021 19:53:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624391719; 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=h68KlSe0hlwxcrl+JkYDAO/PqqE5evM3R+Fqoueck7c=; b=VzMK6C5sfCGTX6i/9yW3vdHw4MbzvpPf/A3KUXjVCggqwj02zKrQgtT01B6VhHsc4xSlBP uzS4IUxZucAXK+W0gxHNe+z+oFlu0XJTdLm3g/47j4jiINexOep5YHABay5xk29RLxNEY+ 2dpw8ey+kkooYoAYINRzNucFm3boPdU= X-MC-Unique: GM8BBXIsMJiNLK7YBbmFXA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v2 5/5] nodedev: improve error message when destroying an inactive device Date: Tue, 22 Jun 2021 14:53:36 -0500 Message-Id: <20210622195336.814205-6-jjongsma@redhat.com> In-Reply-To: <20210622195336.814205-1-jjongsma@redhat.com> References: <20210622195336.814205-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.15 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" When trying to destroy a node device that is not active, we end up with a confusing error message: # nodedev-destroy mdev_88a6b868_46bd_4015_8e5b_26107f82da38 error: Failed to destroy node device 'mdev_88a6b868_46bd_4015_8e5b_26107f= 82da38' error: failed to access '/sys/bus/mdev/devices/88a6b868-46bd-4015-8e5b-26= 107f82da38/iommu_group': No such file or directory With this patch, the error is more clear: # nodedev-destroy mdev_88a6b868_46bd_4015_8e5b_26107f82da38 error: Failed to destroy node device 'mdev_88a6b868_46bd_4015_8e5b_26107f= 82da38' error: Requested operation is not valid: Device 'mdev_88a6b868_46bd_4015_= 8e5b_26107f82da38' is not active Signed-off-by: Jonathon Jongsma Reviewed-by: Boris Fiuczynski --- src/node_device/node_device_driver.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 497db0006a..721ba96203 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1227,6 +1227,15 @@ nodeDeviceDestroy(virNodeDevicePtr device) =20 ret =3D 0; } else if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) { + g_autofree char *vfiogroup =3D NULL; + VIR_AUTOCLOSE fd =3D -1; + + if (!virNodeDeviceObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("Device '%s' is not active"), def->name); + goto cleanup; + } + /* If this mediated device is in use by a vm, attempting to stop it * will block until the vm closes the device. The nodedev driver * cannot query the hypervisor driver to determine whether the dev= ice @@ -1236,10 +1245,7 @@ nodeDeviceDestroy(virNodeDevicePtr device) * to be opened by one user at a time. So if we get EBUSY when ope= ning * the group, we infer that the device is in use and therefore we * shouldn't try to remove the device. */ - g_autofree char *vfiogroup =3D - virMediatedDeviceGetIOMMUGroupDev(def->caps->data.mdev.uuid); - VIR_AUTOCLOSE fd =3D -1; - + vfiogroup =3D virMediatedDeviceGetIOMMUGroupDev(def->caps->data.md= ev.uuid); if (!vfiogroup) goto cleanup; =20 --=20 2.31.1