From nobody Mon Feb 9 07:39:21 2026 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