From nobody Mon Feb 9 20:59:36 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1616777361; cv=none; d=zohomail.com; s=zohoarc; b=Jwc0wRi2NcsDZpS+o9LPAbA+XGosPu6Bu1wCi0ky0b8eNG/JGgKhg5dlPQ6b81Nn14bpWhlI0Gm8ue98Qo1MGoEE7srXU37wD82Zxe6xFY85xPR7tP3h/dH9XmL1cSSL//laJmivYvNyk6rCx3xxYW51+4YDMHLgCCFoAUQUwdI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777361; 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=4ilIUJQNkOsNBOG3uN8J0UTCN1JhG9U2cQwOfSUDxbw=; b=YkoUhooM9ubV3IkyzOt1HD3U6KBpOlTZST38Fq0a50hSrEbuid5yGBNm38Kr1V4Hq2cmugjhBThJPN1UY5HbUS4ydf8HtEyplgn7wOvurjoO6t08ysAwy+a6EueY+CitKFOq838/XeDpHsgAY5HoYgG+8zPndPSdpiuqDfdgZzk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1616777361763849.2266024302575; Fri, 26 Mar 2021 09:49:21 -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-518-EaoO53FWNuOVkTPnvBRLKg-1; Fri, 26 Mar 2021 12:48:41 -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 205AC1034B5C; Fri, 26 Mar 2021 16:48:37 +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 E4C075DAA5; Fri, 26 Mar 2021 16:48:36 +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 847D34A7C9; Fri, 26 Mar 2021 16:48:36 +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 12QGmXFF002912 for ; Fri, 26 Mar 2021 12:48:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id CBDC85D756; Fri, 26 Mar 2021 16:48:33 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-51.phx2.redhat.com [10.3.113.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 92EB15D755; Fri, 26 Mar 2021 16:48:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777323; 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=4ilIUJQNkOsNBOG3uN8J0UTCN1JhG9U2cQwOfSUDxbw=; b=OAzOmv6rlRQTIBweRqYeXhndme+Ibs18PVct/Vqe93aHG/bpqe2qhqv7OTNHpG25fZQf0R gfn2D5YovRQJw2UavV0d7BX2NdV4X3Y35bjKCVXp6WE5sIeNmzD4Eav53Ew4m/JPK4rOsv YloJl+BoLD8MJ39akKOPrajkZ1eswf4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777361; 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=4ilIUJQNkOsNBOG3uN8J0UTCN1JhG9U2cQwOfSUDxbw=; b=NAak1Ea6btEU64uI0tWiDcu2l5kG2V/4bG06acUKk8wi+W+1NCkFK8D+BR1FIr7fBY9TdD ya8Am6HkU2iytR5Do6vwtTMWetNg2Ksw0C9jZGvs3rH/bSa8d2Va4OxT+K4J8AVNXWpPBc MWVIQULSm0fRDy0fQ/ztmpH/cF16fcQ= X-MC-Unique: EaoO53FWNuOVkTPnvBRLKg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 01/30] nodedev: capture and report stderror from mdevctl Date: Fri, 26 Mar 2021 11:47:57 -0500 Message-Id: <20210326164826.1720062-2-jjongsma@redhat.com> In-Reply-To: <20210326164826.1720062-1-jjongsma@redhat.com> References: <20210326164826.1720062-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: eskultet@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) (identity @redhat.com) Content-Type: text/plain; charset="utf-8" When an mdevctl command fails, there is not much information available to the user about why it failed. This is partly because we were not making use of the error message that mdevctl itself prints upon failure. Signed-off-by: Jonathon Jongsma --- src/node_device/node_device_driver.c | 46 +++++++++++++++++----------- src/node_device/node_device_driver.h | 6 ++-- tests/nodedevmdevctltest.c | 6 ++-- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 543e5bb90a..3851a3568f 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -700,7 +700,8 @@ nodeDeviceFindAddressByName(const char *name) =20 virCommandPtr nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr def, - char **uuid_out) + char **uuid_out, + char **errmsg) { virCommandPtr cmd; g_autofree char *json =3D NULL; @@ -725,15 +726,17 @@ nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr = def, =20 virCommandSetInputBuffer(cmd, json); virCommandSetOutputBuffer(cmd, uuid_out); + virCommandSetErrorBuffer(cmd, errmsg); =20 return cmd; } =20 static int -virMdevctlStart(virNodeDeviceDefPtr def, char **uuid) +virMdevctlStart(virNodeDeviceDefPtr def, char **uuid, char **errmsg) { int status; - g_autoptr(virCommand) cmd =3D nodeDeviceGetMdevctlStartCommand(def, uu= id); + g_autoptr(virCommand) cmd =3D nodeDeviceGetMdevctlStartCommand(def, uu= id, + errmsg); if (!cmd) return -1; =20 @@ -754,6 +757,7 @@ nodeDeviceCreateXMLMdev(virConnectPtr conn, virNodeDeviceDefPtr def) { g_autofree char *uuid =3D NULL; + g_autofree char *errmsg =3D NULL; =20 if (!def->parent) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -761,9 +765,10 @@ nodeDeviceCreateXMLMdev(virConnectPtr conn, return NULL; } =20 - if (virMdevctlStart(def, &uuid) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to start mediated device")); + if (virMdevctlStart(def, &uuid, &errmsg) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to start mediated device '%s': %s"), def-= >name, + errmsg && errmsg[0] ? errmsg : "Unknown Error"); return NULL; } =20 @@ -828,23 +833,25 @@ nodeDeviceCreateXML(virConnectPtr conn, =20 =20 virCommandPtr -nodeDeviceGetMdevctlStopCommand(const char *uuid) -{ - return virCommandNewArgList(MDEVCTL, - "stop", - "-u", - uuid, - NULL); +nodeDeviceGetMdevctlStopCommand(const char *uuid, char **errmsg) +{ + virCommandPtr cmd =3D virCommandNewArgList(MDEVCTL, + "stop", + "-u", + uuid, + NULL); + virCommandSetErrorBuffer(cmd, errmsg); + return cmd; =20 } =20 static int -virMdevctlStop(virNodeDeviceDefPtr def) +virMdevctlStop(virNodeDeviceDefPtr def, char **errmsg) { int status; g_autoptr(virCommand) cmd =3D NULL; =20 - cmd =3D nodeDeviceGetMdevctlStopCommand(def->caps->data.mdev.uuid); + cmd =3D nodeDeviceGetMdevctlStopCommand(def->caps->data.mdev.uuid, err= msg); =20 if (virCommandRun(cmd, &status) < 0 || status !=3D 0) return -1; @@ -901,9 +908,12 @@ nodeDeviceDestroy(virNodeDevicePtr device) =20 ret =3D 0; } else if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) { - if (virMdevctlStop(def) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to stop mediated device")); + g_autofree char *errmsg =3D NULL; + + if (virMdevctlStop(def, &errmsg) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to destroy '%s': %s"), def->name, + errmsg && errmsg[0] ? errmsg : "Unknown error"); goto cleanup; } ret =3D 0; diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index 2113d2b0a5..4a40aa51f6 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -115,6 +115,8 @@ nodeConnectNodeDeviceEventDeregisterAny(virConnectPtr c= onn, =20 virCommandPtr nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr def, - char **uuid_out); + char **uuid_out, + char **errmsg); virCommandPtr -nodeDeviceGetMdevctlStopCommand(const char *uuid); +nodeDeviceGetMdevctlStopCommand(const char *uuid, + char **errmsg); diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 1bad65549b..c12feaac55 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -58,6 +58,7 @@ testMdevctlStart(const char *virt_type, const char *actualCmdline =3D NULL; int ret =3D -1; g_autofree char *uuid =3D NULL; + g_autofree char *errmsg =3D NULL; g_autofree char *stdinbuf =3D NULL; g_autoptr(virCommand) cmd =3D NULL; =20 @@ -66,7 +67,7 @@ testMdevctlStart(const char *virt_type, =20 /* this function will set a stdin buffer containing the json configura= tion * of the device. The json value is captured in the callback above */ - cmd =3D nodeDeviceGetMdevctlStartCommand(def, &uuid); + cmd =3D nodeDeviceGetMdevctlStartCommand(def, &uuid, &errmsg); =20 if (!cmd) goto cleanup; @@ -117,11 +118,12 @@ testMdevctlStop(const void *data) const char *actualCmdline =3D NULL; int ret =3D -1; g_autoptr(virCommand) cmd =3D NULL; + g_autofree char *errmsg =3D NULL; g_autofree char *cmdlinefile =3D g_strdup_printf("%s/nodedevmdevctldata/mdevctl-stop.argv", abs_srcdir); =20 - cmd =3D nodeDeviceGetMdevctlStopCommand(uuid); + cmd =3D nodeDeviceGetMdevctlStopCommand(uuid, &errmsg); =20 if (!cmd) goto cleanup; --=20 2.26.3