From nobody Wed Apr 24 21:05:09 2024 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 From nobody Wed Apr 24 21:05:09 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=1616777328; cv=none; d=zohomail.com; s=zohoarc; b=mZYn9qNfEY5zURjlkFswlSFR5LWUrDrK9nGm25RXPHiPYEWSPMDi7rIMyVtupjVP0pyCPP/uRnVpsySWYu1GFzL4qCtLJ8RUfMW1M5tp8rHDl1HRF4HgGJWOknI2ustEFZE+iGqSknSOcQtRYkg+7z9uvE2vD70sAX3dujRe/70= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777328; 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=uDTrHy49Vyx0imqdNquzCgDjMV95iw0jyyjz4R8BYD4=; b=C67wOR8dNcznGzF/7+p7MLrLEnBionr9i08bWdjrHfsrADB+zOfedCJm/wTnT0Sd1ftnhHgGw0q6Tk+DdCwtDXts8SZv0S+k5moR+65JAy2iWYYKDFBzLWBeoZlkMp0pURy/wohy/Hw17pmqvpzzErvReCdQG1sf02xwuOMspHo= 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) header.from= 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 1616777328671592.723167946204; Fri, 26 Mar 2021 09:48:48 -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-295-bZZVAbbYOEifnwwKNxKmlg-1; Fri, 26 Mar 2021 12:48:45 -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 70CD1E49FE; Fri, 26 Mar 2021 16:48: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 2981E891AE; Fri, 26 Mar 2021 16:48:38 +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 D97F71800215; Fri, 26 Mar 2021 16:48:37 +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 12QGmYRs002920 for ; Fri, 26 Mar 2021 12:48:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 29DF95D762; Fri, 26 Mar 2021 16:48:34 +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 E69FC5D755; 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=1616777327; 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=uDTrHy49Vyx0imqdNquzCgDjMV95iw0jyyjz4R8BYD4=; b=H2UibowR38vIHBhyvbHSKxv9GALbj0xDLwzO9yYLz6xT9kmBCTg//H//pwDhZmyzsFc+NX RDyRWTN4l6+Jyu06VnYJ/NehlAU+p3fSZodyehYLc7VnqvxguhJk7IZk/SeymjXJcZboWv 4T4Gj4Evlh72bMsW3onHr8+ek09iv6g= X-MC-Unique: bZZVAbbYOEifnwwKNxKmlg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 02/30] tests: remove extra trailing semicolon Date: Fri, 26 Mar 2021 11:47:58 -0500 Message-Id: <20210326164826.1720062-3-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.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" The macro should not have a trailing semicolon so that when the macro is used, the user can add a semicolon themselves. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- tests/nodedevmdevctltest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index c12feaac55..650e46a29f 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -273,7 +273,7 @@ mymain(void) struct startTestInfo info =3D { virt_type, create, filename }; \ DO_TEST_FULL("mdevctl start " filename, testMdevctlStartHelper, in= fo); \ } \ - while (0); + while (0) =20 #define DO_TEST_START(filename) \ DO_TEST_START_FULL("QEMU", CREATE_DEVICE, filename) --=20 2.26.3 From nobody Wed Apr 24 21:05:09 2024 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=1616777342; cv=none; d=zohomail.com; s=zohoarc; b=YnQT4j9Psv3tXewK5QDs+lxyly/LBqXRlusrVBfSrcPGCRPcaCtG6whuNo3oUls7QHGOJSdn8WaMAshIflOhzEodvfQMSN7y14OEwTC4VmH0VMGPgm05NutkXQnWwK1BbpIiG6WBvX3gnH7XYqcs1WigOH/LrRV/mD7ll3wQbJQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777342; 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=EetFSFuw1NHO6k6odHK6/nKmKScBboIKjQB1f4TZ77M=; b=ApRJYuUYlnF0dhtYRtYuImrKlSjLkgA2eAwYNgzxlkcn0rYPAWXX/w1R5iTj6K0onFiX7NYwpIvpyy30uYuY8xGqeYDR9MaYpYGpQVD8nZ6LPbBX3bZkb9/GIY3jytZobVyls6CvCX6m1jboebiTN/QowmLAwtJ8Slw463Sxdj8= 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 1616777342487384.0659880634023; Fri, 26 Mar 2021 09:49:02 -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-426-whyqADcBOZ2iOlowPLogew-1; Fri, 26 Mar 2021 12:48:49 -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 8FEA7107ACCA; Fri, 26 Mar 2021 16:48:44 +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 65A105D6DC; Fri, 26 Mar 2021 16:48:44 +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 137C2180B451; Fri, 26 Mar 2021 16:48:44 +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 12QGmYqu002926 for ; Fri, 26 Mar 2021 12:48:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7F1F15D756; Fri, 26 Mar 2021 16:48:34 +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 439EC5D755; Fri, 26 Mar 2021 16:48:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777332; 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=EetFSFuw1NHO6k6odHK6/nKmKScBboIKjQB1f4TZ77M=; b=QAQZ4JmSar+Rj77ZfiTArZOoA91klAzLwh9BQ3Xf4Zy4v5exWFAEfkuLywpNfjI1YFElcn /Iq1AkJ6nukC7jbhQNa+n7H5fk+lFKlOrTHV8tWTbYzHxiG1rEJLBqhT649zRz6jW7hhAF n7IDVIgl7LMFQc8dWLNzG4lfZqTWS2s= X-MC-Unique: whyqADcBOZ2iOlowPLogew-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 03/30] nodedev: introduce concept of 'active' node devices Date: Fri, 26 Mar 2021 11:47:59 -0500 Message-Id: <20210326164826.1720062-4-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.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" we will be able to define mediated devices that can be started or stopped, so we need to be able to indicate whether the device is active or not, similar to other resources (storage pools, domains, etc.) Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- src/conf/virnodedeviceobj.c | 16 ++++++++++++++++ src/conf/virnodedeviceobj.h | 7 +++++++ src/libvirt_private.syms | 2 ++ src/node_device/node_device_udev.c | 3 +++ 4 files changed, 28 insertions(+) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index ecae3d0479..f0ceb61a19 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -39,6 +39,7 @@ struct _virNodeDeviceObj { virNodeDeviceDefPtr def; /* device definition */ bool skipUpdateCaps; /* whether to skip checking host c= aps, used by testdriver */ + bool active; }; =20 struct _virNodeDeviceObjList { @@ -976,3 +977,18 @@ virNodeDeviceObjSetSkipUpdateCaps(virNodeDeviceObjPtr = obj, { obj->skipUpdateCaps =3D skipUpdateCaps; } + + +bool +virNodeDeviceObjIsActive(virNodeDeviceObj *obj) +{ + return obj->active; +} + + +void +virNodeDeviceObjSetActive(virNodeDeviceObj *obj, + bool active) +{ + obj->active =3D active; +} diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 6efdb23d36..e786a70f51 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -121,3 +121,10 @@ virNodeDeviceObjSetSkipUpdateCaps(virNodeDeviceObjPtr = obj, virNodeDeviceObjPtr virNodeDeviceObjListFindMediatedDeviceByUUID(virNodeDeviceObjListPtr devs, const char *uuid); + +bool +virNodeDeviceObjIsActive(virNodeDeviceObj *obj); + +void +virNodeDeviceObjSetActive(virNodeDeviceObj *obj, + bool active); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index cb9fe7c80a..09957c943b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1272,6 +1272,7 @@ virNetworkPortDefSaveStatus; # conf/virnodedeviceobj.h virNodeDeviceObjEndAPI; virNodeDeviceObjGetDef; +virNodeDeviceObjIsActive; virNodeDeviceObjListAssignDef; virNodeDeviceObjListExport; virNodeDeviceObjListFindByName; @@ -1284,6 +1285,7 @@ virNodeDeviceObjListGetParentHost; virNodeDeviceObjListNew; virNodeDeviceObjListNumOfDevices; virNodeDeviceObjListRemove; +virNodeDeviceObjSetActive; =20 =20 # conf/virnwfilterbindingdef.h diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 3daa5c90ad..373f36c41f 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1544,6 +1544,7 @@ udevAddOneDevice(struct udev_device *device) else event =3D virNodeDeviceEventUpdateNew(objdef->name); =20 + virNodeDeviceObjSetActive(obj, true); virNodeDeviceObjEndAPI(&obj); =20 ret =3D 0; @@ -1930,6 +1931,8 @@ udevSetupSystemDev(void) if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, def))) goto cleanup; =20 + virNodeDeviceObjSetActive(obj, true); + virNodeDeviceObjEndAPI(&obj); =20 ret =3D 0; --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777333; cv=none; d=zohomail.com; s=zohoarc; b=a5HpHCSP7AEZFTmyAGb0sD8VTDfzGOqSXJ7ZdKB9MCN/jGe5G5uYMZayU5ArVEUfP+wLwiOxtTUcP5mBPOhOsiPDxYlZCpnTWz9NLQ+GPzjF8GgeAjDZJsrsuGNoRN/5iuEwFQNtQr3IPaWRe7gU98x0uR3TMXyjNFaJhBTF/wg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777333; 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=BG3M4zyKYvEhDDiTeA7Vm6uL6v7VzJbfAz1qud8OR8g=; b=CCkrAwUsc3ZRCYqczkAxIfBckICqKxdv/aVr0fDUb7GwF9mLVniiUHNvx1FlGp0c6R1YLmNiFhAz5Fub+beU1sgCfKVCHJmto80AoaL8CJ7K6Au08JR+eTEVVlOlBhCL+SNN0LSRMoqSTSpUEjp+tvOvemp/ZzNqF0Ms5iB4710= 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) header.from= 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 1616777333866151.2868654521942; Fri, 26 Mar 2021 09:48:53 -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-156-sfM-jAMaM7-Vjg_y8l6kOw-1; Fri, 26 Mar 2021 12:48:50 -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 541411853034; Fri, 26 Mar 2021 16:48:45 +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 1C0F31007606; Fri, 26 Mar 2021 16:48:45 +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 BFDFA180C5A5; Fri, 26 Mar 2021 16:48:44 +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 12QGmZr4002935 for ; Fri, 26 Mar 2021 12:48:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id D9E8D5B6A2; Fri, 26 Mar 2021 16:48:34 +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 99C095D755; Fri, 26 Mar 2021 16:48:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777332; 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=BG3M4zyKYvEhDDiTeA7Vm6uL6v7VzJbfAz1qud8OR8g=; b=P7+r5kwtROwM9HODkAqtT6nt7+8L+synqiawo9c2Yl1dOyCQJzENX3YHmVH8BtcZ8qejPy USVYUXdc0gRMRBxy8wfbSK6BivMvGl0UuqIw6Yf8i6R7PHBSBrGwZnl+HeYNdbzvRjmcJE tk2sNIl15CGd55LMj6jAVYv6lQY4Xto= X-MC-Unique: sfM-jAMaM7-Vjg_y8l6kOw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 04/30] nodedev: Add ability to filter by active state Date: Fri, 26 Mar 2021 11:48:00 -0500 Message-Id: <20210326164826.1720062-5-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.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" Add two flag values for virConnectListAllNodeDevices() so that we can list only node devices that are active or inactive. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- include/libvirt/libvirt-nodedev.h | 9 +++-- src/conf/node_device_conf.h | 8 ++++ src/conf/virnodedeviceobj.c | 57 +++++++++++++++++----------- src/libvirt-nodedev.c | 2 + src/node_device/node_device_driver.c | 2 +- 5 files changed, 51 insertions(+), 27 deletions(-) diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index eab8abf6ab..1a0e60b81f 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -61,10 +61,9 @@ int virNodeListDevices (virConn= ectPtr conn, * virConnectListAllNodeDevices: * * Flags used to filter the returned node devices. Flags in each group - * are exclusive. Currently only one group to filter the devices by cap - * type. - */ + * are exclusive. */ typedef enum { + /* filter the devices by cap type */ VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM =3D 1 << 0, /* System= capability */ VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV =3D 1 << 1, /* PCI de= vice */ VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV =3D 1 << 2, /* USB de= vice */ @@ -86,6 +85,10 @@ typedef enum { VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_CARD =3D 1 << 18, /* s390 A= P Card device */ VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_QUEUE =3D 1 << 19, /* s390 A= P Queue */ VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_MATRIX =3D 1 << 20, /* s390 A= P Matrix */ + + /* filter the devices by active state */ + VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE =3D 1 << 30, /* Inacti= ve devices */ + VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE =3D 1U << 31, /* Activ= e devices */ } virConnectListAllNodeDeviceFlags; =20 int virConnectListAllNodeDevices (virConnectPtr conn, diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index c67b8e2aeb..3d7872fd6e 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -422,6 +422,14 @@ virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps); VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_QUEUE | \ VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_MATRIX) =20 +#define VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_ACTIVE \ + VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE |\ + VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE + +#define VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_ALL \ + VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP | \ + VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_ACTIVE + int virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host); =20 diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index f0ceb61a19..ab663fd5a0 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -848,8 +848,10 @@ virNodeDeviceObjListGetNames(virNodeDeviceObjListPtr d= evs, } =20 =20 -#define MATCH(FLAG) ((flags & (VIR_CONNECT_LIST_NODE_DEVICES_CAP_ ## FLAG)= ) && \ - virNodeDeviceObjHasCap(obj, VIR_NODE_DEV_CAP_ ## FLAG= )) +#define MATCH_CAP(FLAG) ((flags & (VIR_CONNECT_LIST_NODE_DEVICES_CAP_ ## F= LAG)) && \ + virNodeDeviceObjHasCap(obj, VIR_NODE_DEV_CAP_ ## = FLAG)) +#define MATCH(FLAG) (flags & (FLAG)) + static bool virNodeDeviceObjMatch(virNodeDeviceObjPtr obj, unsigned int flags) @@ -861,33 +863,42 @@ virNodeDeviceObjMatch(virNodeDeviceObjPtr obj, =20 /* filter by cap type */ if (flags & VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP) { - if (!(MATCH(SYSTEM) || - MATCH(PCI_DEV) || - MATCH(USB_DEV) || - MATCH(USB_INTERFACE) || - MATCH(NET) || - MATCH(SCSI_HOST) || - MATCH(SCSI_TARGET) || - MATCH(SCSI) || - MATCH(STORAGE) || - MATCH(FC_HOST) || - MATCH(VPORTS) || - MATCH(SCSI_GENERIC) || - MATCH(DRM) || - MATCH(MDEV_TYPES) || - MATCH(MDEV) || - MATCH(CCW_DEV) || - MATCH(CSS_DEV) || - MATCH(VDPA) || - MATCH(AP_CARD) || - MATCH(AP_QUEUE) || - MATCH(AP_MATRIX))) + if (!(MATCH_CAP(SYSTEM) || + MATCH_CAP(PCI_DEV) || + MATCH_CAP(USB_DEV) || + MATCH_CAP(USB_INTERFACE) || + MATCH_CAP(NET) || + MATCH_CAP(SCSI_HOST) || + MATCH_CAP(SCSI_TARGET) || + MATCH_CAP(SCSI) || + MATCH_CAP(STORAGE) || + MATCH_CAP(FC_HOST) || + MATCH_CAP(VPORTS) || + MATCH_CAP(SCSI_GENERIC) || + MATCH_CAP(DRM) || + MATCH_CAP(MDEV_TYPES) || + MATCH_CAP(MDEV) || + MATCH_CAP(CCW_DEV) || + MATCH_CAP(CSS_DEV) || + MATCH_CAP(VDPA) || + MATCH_CAP(AP_CARD) || + MATCH_CAP(AP_QUEUE) || + MATCH_CAP(AP_MATRIX))) + return false; + } + + if (flags & (VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_ACTIVE)) { + if (!((MATCH(VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE) && + virNodeDeviceObjIsActive(obj)) || + (MATCH(VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE) && + !virNodeDeviceObjIsActive(obj)))) return false; } =20 return true; } #undef MATCH +#undef MATCH_CAP =20 =20 typedef struct _virNodeDeviceObjListExportData virNodeDeviceObjListExportD= ata; diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index eb8c735a8c..375b907852 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -105,6 +105,8 @@ virNodeNumOfDevices(virConnectPtr conn, const char *cap= , unsigned int flags) * VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_CARD * VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_QUEUE * VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_MATRIX + * VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE + * VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE * * Returns the number of node devices found or -1 and sets @devices to NUL= L in * case of error. On success, the array stored into @devices is guarantee= d to diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 3851a3568f..920fd815f2 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -217,7 +217,7 @@ nodeConnectListAllNodeDevices(virConnectPtr conn, virNodeDevicePtr **devices, unsigned int flags) { - virCheckFlags(VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP, -1); + virCheckFlags(VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_ALL, -1); =20 if (virConnectListAllNodeDevicesEnsureACL(conn) < 0) return -1; --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777386; cv=none; d=zohomail.com; s=zohoarc; b=YckbdbtT4jGXSwu8rT3i61KVOGhTZAbfU7QnXUBsQ5gQIaqpBLTdo47hU4RpHs6d2BOKfOMWjdY0j16dZff5YQKT6zsg2z//ufjixmiwLxAvNqsn51T9XyqGDakttpnxujmYqFQyPmzyaHRIbsI2GpdN9G3jF6RRe57khWRcVLQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777386; 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=FMu8+gQSyMUO1LnSfuMd+rJt2rbLSVRiRUpro6HpykE=; b=A/iWHlZoOAYKQsGSSz7HuJ+xjTks07DTtVMz9I2COVAqSvltXL/MWOCEDKVZpWlLhq/3ZG1ElwZqaUJPyarLx0fKU2v9xe8d6dEK9LY+pTFI6S7ZcLKSqytmXxU+MfDRcIKOjIRdm9Sc469DlyAcsYfvE4o6Bx9lzRZ2Z0WIHQA= 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) header.from= 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 1616777386187247.65905616432053; Fri, 26 Mar 2021 09:49:46 -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-423-npgNYWmGPwC_oe8qoDtIBQ-1; Fri, 26 Mar 2021 12:48:55 -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 7E07010866D2; Fri, 26 Mar 2021 16:48:48 +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 57BD65D72E; Fri, 26 Mar 2021 16:48:48 +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 EAE6918045CA; Fri, 26 Mar 2021 16:48:47 +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 12QGmZ8F002940 for ; Fri, 26 Mar 2021 12:48:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3E1B65D72E; Fri, 26 Mar 2021 16:48:35 +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 0317D78C09; Fri, 26 Mar 2021 16:48:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777385; 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=FMu8+gQSyMUO1LnSfuMd+rJt2rbLSVRiRUpro6HpykE=; b=gU5lcpFmjV+IF04d5kLz8SMYbeU0fP9J8Bx3hLehn/n27aehbt4OA60z8kSh4ie46CtP8K h3w/nqIc3nP1Nsl3T0EJkTFgqX6DHqZQuSKBmj4S4Is3rJxx+eQ/FI5uyLfInp9VAMewxX XsEdDKyKpp8TEZB+2VUhY0T5CS67c+E= X-MC-Unique: npgNYWmGPwC_oe8qoDtIBQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 05/30] nodedev: fix docs for virConnectListAllNodeDevices() Date: Fri, 26 Mar 2021 11:48:01 -0500 Message-Id: <20210326164826.1720062-6-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.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" It doesn't make sense to list all of the flag values in the function documentation. This is unnecessary duplication, we already refer to the enum type. Also, remove reference to exclusive groups of flags, since that does not apply to this API. Signed-off-by: Jonathon Jongsma --- include/libvirt/libvirt-nodedev.h | 3 +-- src/libvirt-nodedev.c | 30 +----------------------------- 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index 1a0e60b81f..2deead0791 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -60,8 +60,7 @@ int virNodeListDevices (virConne= ctPtr conn, /* * virConnectListAllNodeDevices: * - * Flags used to filter the returned node devices. Flags in each group - * are exclusive. */ + * Flags used to filter the returned node devices. */ typedef enum { /* filter the devices by cap type */ VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM =3D 1 << 0, /* System= capability */ diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index 375b907852..fb707b570f 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -78,35 +78,7 @@ virNodeNumOfDevices(virConnectPtr conn, const char *cap,= unsigned int flags) * objects. * * Normally, all node devices are returned; however, @flags can be used to - * filter the results for a smaller list of targeted node devices. The va= lid - * flags are divided into groups, where each group contains bits that - * describe mutually exclusive attributes of a node device, and where all = bits - * within a group describe all possible node devices. - * - * Only one group of the @flags is provided to filter the node devices by - * capability type, flags include: - * VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM - * VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV - * VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV - * VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_INTERFACE - * VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET - * VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_HOST - * VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET - * VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI - * VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE - * VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST - * VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS - * VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_GENERIC - * VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM - * VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES - * VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV - * VIR_CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV - * VIR_CONNECT_LIST_NODE_DEVICES_CAP_CSS_DEV - * VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_CARD - * VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_QUEUE - * VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_MATRIX - * VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE - * VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE + * filter the results for a smaller list of targeted node devices. * * Returns the number of node devices found or -1 and sets @devices to NUL= L in * case of error. On success, the array stored into @devices is guarantee= d to --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777342; cv=none; d=zohomail.com; s=zohoarc; b=Ljcz5u/OCW4FcvJQFDcRuWDNCb/Cyic5qqOw0+Nw5OPNCK3eDMSDdDu5MRwpJ1u6077PrPbZJ/6mr9yd6LE4BW36z//yXFl6ysraQlgiCaHmQlVdJjtekJjS5ATDLK5f0/ZXeMMszHFegVq2HcYcNyoaDYuRl/HoP8j5LG8+zfo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777342; 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=GU/L9q497qHERTdfR2670srKRKEDww4l3NTie2h49wI=; b=A/45lmky2raqlhGkYbhjXuwOgK6ixkSOQCFuPKjmyYA6zxeaEWDXXAykXKMegRFYURfwkFVGwFU0QAzV25pGG8waDxrjRA98C52APFLYK2q+V3Xb2g1BTPloa5JG/142fJmuQTQXwjfcWXctoJ33uXHgMhBgrm+HhsWC7eorhMU= 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) header.from= 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 161677734285426.724995262888456; Fri, 26 Mar 2021 09:49:02 -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-365-QZ-I8BAsM3-BzeX_l4D0BA-1; Fri, 26 Mar 2021 12:48:58 -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 AB132107B7C9; Fri, 26 Mar 2021 16:48:51 +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 8790B5D6DC; Fri, 26 Mar 2021 16:48:51 +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 48594180213C; Fri, 26 Mar 2021 16:48:51 +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 12QGmZ9h002945 for ; Fri, 26 Mar 2021 12:48:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8E0785D72E; Fri, 26 Mar 2021 16:48:35 +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 56C0E5D6DC; Fri, 26 Mar 2021 16:48:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777341; 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=GU/L9q497qHERTdfR2670srKRKEDww4l3NTie2h49wI=; b=SwJwqssO9w+QB8ISLfoTOglGlS25TqoGd+tnKomc9+qKmbbhf6zjc7KJUXAsAlHQb/eosn vVF5/7gd1O7M7lD9RfITFI+IfD+fvGABJcgc6vdHVi0FbM7A+tRBsNyldgi4uyvs8BTKvJ UxtxJtLSYnUqhU9TV03jeQjLDzrvbkw= X-MC-Unique: QZ-I8BAsM3-BzeX_l4D0BA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 06/30] nodedev: expose internal helper for naming devices Date: Fri, 26 Mar 2021 11:48:02 -0500 Message-Id: <20210326164826.1720062-7-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.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" Expose a helper function that can be used by udev and mdevctl to generate device names for node devices. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- src/node_device/node_device_driver.c | 25 +++++++++++++++++++++++++ src/node_device/node_device_driver.h | 6 ++++++ src/node_device/node_device_udev.c | 19 +++---------------- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 920fd815f2..bada5bbf00 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -978,3 +978,28 @@ nodedevRegister(void) return udevNodeRegister(); #endif } + + +void +nodeDeviceGenerateName(virNodeDeviceDef *def, + const char *subsystem, + const char *sysname, + const char *s) +{ + size_t i; + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, "%s_%s", + subsystem, + sysname); + + if (s !=3D NULL) + virBufferAsprintf(&buf, "_%s", s); + + def->name =3D virBufferContentAndReset(&buf); + + for (i =3D 0; i < strlen(def->name); i++) { + if (!(g_ascii_isalnum(*(def->name + i)))) + *(def->name + i) =3D '_'; + } +} diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index 4a40aa51f6..76a40c05ad 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -120,3 +120,9 @@ nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr de= f, virCommandPtr nodeDeviceGetMdevctlStopCommand(const char *uuid, char **errmsg); + +void +nodeDeviceGenerateName(virNodeDeviceDef *def, + const char *subsystem, + const char *sysname, + const char *s); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 373f36c41f..eae301cc95 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -311,22 +311,9 @@ udevGenerateDeviceName(struct udev_device *device, virNodeDeviceDefPtr def, const char *s) { - size_t i; - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, "%s_%s", - udev_device_get_subsystem(device), - udev_device_get_sysname(device)); - - if (s !=3D NULL) - virBufferAsprintf(&buf, "_%s", s); - - def->name =3D virBufferContentAndReset(&buf); - - for (i =3D 0; i < strlen(def->name); i++) { - if (!(g_ascii_isalnum(*(def->name + i)))) - *(def->name + i) =3D '_'; - } + nodeDeviceGenerateName(def, + udev_device_get_subsystem(device), + udev_device_get_sysname(device), s); =20 return 0; } --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777347; cv=none; d=zohomail.com; s=zohoarc; b=F9OB0xgfanTkO9MLZgqtoJfWkI4q+XQpSA8p8At/OI5iQguKK6wtMw2dutKlY9nDt2gyzImhPZ3UfvBAfRK8q54ioRnErrp2y1Z6cxBZZoD9R6DKQI/I7gB9I6Z3FNkKLlaefDOH4/CnPY/wrVcGR+VjbjPk2vKj+hpfvT0cLs4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777347; 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=2XjAi9URCqodQ1MfsvzZStc2c4EfdNzFFHm5B/TrX9E=; b=lHgu/4UhCO9OcobCXOtpoGVn2gwr+TSCidNiGr/GGurYROPuoEPx/pYqSXpzNEW3qNrr7oLDUBNo/8SZYWHgLDv4AqAE3NEgbyf1dCQ4oZIhiQ7eObW1e+rb9iK2E4y4m8NmblLkDrSSb8De/UmZSX5GlbFOyPScc6fHhUDIuok= 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) header.from= 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 1616777347507884.7524342354124; Fri, 26 Mar 2021 09:49:07 -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-51-VI1tCZSgM9uOkiXme-_rmA-1; Fri, 26 Mar 2021 12:49:02 -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 15EA01853041; Fri, 26 Mar 2021 16:48:55 +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 E3838690EF; Fri, 26 Mar 2021 16:48:54 +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 92CE74A70C; Fri, 26 Mar 2021 16:48:54 +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 12QGmZKO002952 for ; Fri, 26 Mar 2021 12:48:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id EEDDF5D72E; Fri, 26 Mar 2021 16:48:35 +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 AB2A15D6DC; Fri, 26 Mar 2021 16:48:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777345; 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=2XjAi9URCqodQ1MfsvzZStc2c4EfdNzFFHm5B/TrX9E=; b=DeA3n9n7yMRVbqqTfvuux2kSfKCBKBufCYQU0soqWi68wNZIM+29WS4lG0BV+jjS8ohQza C14wYa33QfI6upWSPNCOzNvqNgvpmDEejB0f6jQYbxaqoSFh7Fu1JbEK2951rCQh7oAOko rU3fVb3Xi3+sTdSWYO7tedcUQ9HEt6Y= X-MC-Unique: VI1tCZSgM9uOkiXme-_rmA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 07/30] nodedev: add ability to parse mdevs from mdevctl Date: Fri, 26 Mar 2021 11:48:03 -0500 Message-Id: <20210326164826.1720062-8-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.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" This function will parse the list of mediated devices that are returned by mdevctl and convert it into our internal node device representation. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- src/node_device/node_device_driver.c | 143 ++++++++++++++++++ src/node_device/node_device_driver.h | 4 + .../mdevctl-list-multiple.json | 59 ++++++++ .../mdevctl-list-multiple.out.xml | 39 +++++ tests/nodedevmdevctltest.c | 56 ++++++- 5 files changed, 299 insertions(+), 2 deletions(-) create mode 100644 tests/nodedevmdevctldata/mdevctl-list-multiple.json create mode 100644 tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index bada5bbf00..a646692870 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -860,6 +860,149 @@ virMdevctlStop(virNodeDeviceDefPtr def, char **errmsg) } =20 =20 +static void mdevGenerateDeviceName(virNodeDeviceDef *dev) +{ + nodeDeviceGenerateName(dev, "mdev", dev->caps->data.mdev.uuid, NULL); +} + + +static virNodeDeviceDef* +nodeDeviceParseMdevctlChildDevice(const char *parent, + virJSONValue *json) +{ + virNodeDevCapMdev *mdev; + const char *uuid; + virJSONValue *props; + virJSONValue *attrs; + g_autoptr(virNodeDeviceDef) child =3D g_new0(virNodeDeviceDef, 1); + + /* the child object should have a single key equal to its uuid. + * The value is an object describing the properties of the mdev */ + if (virJSONValueObjectKeysNumber(json) !=3D 1) + return NULL; + + uuid =3D virJSONValueObjectGetKey(json, 0); + props =3D virJSONValueObjectGetValue(json, 0); + + child->parent =3D g_strdup(parent); + child->caps =3D g_new0(virNodeDevCapsDef, 1); + child->caps->data.type =3D VIR_NODE_DEV_CAP_MDEV; + + mdev =3D &child->caps->data.mdev; + mdev->uuid =3D g_strdup(uuid); + mdev->type =3D + g_strdup(virJSONValueObjectGetString(props, "mdev_type")); + + attrs =3D virJSONValueObjectGet(props, "attrs"); + + if (attrs && virJSONValueIsArray(attrs)) { + size_t i; + int nattrs =3D virJSONValueArraySize(attrs); + + mdev->attributes =3D g_new0(virMediatedDeviceAttr*, nattrs); + mdev->nattributes =3D nattrs; + + for (i =3D 0; i < nattrs; i++) { + virJSONValue *attr =3D virJSONValueArrayGet(attrs, i); + virMediatedDeviceAttr *attribute; + virJSONValue *value; + + if (!virJSONValueIsObject(attr) || + virJSONValueObjectKeysNumber(attr) !=3D 1) + return NULL; + + attribute =3D g_new0(virMediatedDeviceAttr, 1); + attribute->name =3D g_strdup(virJSONValueObjectGetKey(attr, 0)= ); + value =3D virJSONValueObjectGetValue(attr, 0); + attribute->value =3D g_strdup(virJSONValueGetString(value)); + mdev->attributes[i] =3D attribute; + } + } + mdevGenerateDeviceName(child); + + return g_steal_pointer(&child); +} + + +int +nodeDeviceParseMdevctlJSON(const char *jsonstring, + virNodeDeviceDef ***devs) +{ + int n; + g_autoptr(virJSONValue) json_devicelist =3D NULL; + virNodeDeviceDef **outdevs =3D NULL; + size_t noutdevs =3D 0; + size_t i; + size_t j; + + json_devicelist =3D virJSONValueFromString(jsonstring); + + if (!json_devicelist || !virJSONValueIsArray(json_devicelist)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("mdevctl JSON response contains no devices")); + goto error; + } + + n =3D virJSONValueArraySize(json_devicelist); + + for (i =3D 0; i < n; i++) { + virJSONValue *obj =3D virJSONValueArrayGet(json_devicelist, i); + const char *parent; + virJSONValue *child_array; + int nchildren; + + if (!virJSONValueIsObject(obj)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Parent device is not an object")); + goto error; + } + + /* mdevctl returns an array of objects. Each object is a parent d= evice + * object containing a single key-value pair which maps from the n= ame + * of the parent device to an array of child devices */ + if (virJSONValueObjectKeysNumber(obj) !=3D 1) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unexpected format for parent device object")= ); + goto error; + } + + parent =3D virJSONValueObjectGetKey(obj, 0); + child_array =3D virJSONValueObjectGetValue(obj, 0); + + if (!virJSONValueIsArray(child_array)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Parent device's JSON object data is not an a= rray")); + goto error; + } + + nchildren =3D virJSONValueArraySize(child_array); + + for (j =3D 0; j < nchildren; j++) { + g_autoptr(virNodeDeviceDef) child =3D NULL; + virJSONValue *child_obj =3D virJSONValueArrayGet(child_array, = j); + + if (!(child =3D nodeDeviceParseMdevctlChildDevice(parent, chil= d_obj))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to parse child device")); + goto error; + } + + if (VIR_APPEND_ELEMENT(outdevs, noutdevs, child) < 0) + goto error; + } + } + + *devs =3D outdevs; + return noutdevs; + + error: + for (i =3D 0; i < noutdevs; i++) + virNodeDeviceDefFree(outdevs[i]); + VIR_FREE(outdevs); + return -1; +} + + int nodeDeviceDestroy(virNodeDevicePtr device) { diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index 76a40c05ad..f1c93f4b21 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -121,6 +121,10 @@ virCommandPtr nodeDeviceGetMdevctlStopCommand(const char *uuid, char **errmsg); =20 +int +nodeDeviceParseMdevctlJSON(const char *jsonstring, + virNodeDeviceDef ***devs); + void nodeDeviceGenerateName(virNodeDeviceDef *def, const char *subsystem, diff --git a/tests/nodedevmdevctldata/mdevctl-list-multiple.json b/tests/no= dedevmdevctldata/mdevctl-list-multiple.json new file mode 100644 index 0000000000..eefcd90c62 --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-list-multiple.json @@ -0,0 +1,59 @@ +[ + { + "0000:00:02.0": [ + { + "200f228a-c80a-4d50-bfb7-f5a0e4e34045": { + "mdev_type": "i915-GVTg_V5_4", + "start": "manual" + } + }, + { + "de807ffc-1923-4d5f-b6c9-b20ecebc6d4b": { + "mdev_type": "i915-GVTg_V5_4", + "start": "auto" + } + }, + { + "435722ea-5f43-468a-874f-da34f1217f13": { + "mdev_type": "i915-GVTg_V5_8", + "start": "manual", + "attrs": [ + { + "testattr": "42" + } + ] + } + } + ] + }, + { + "matrix": [ + { "783e6dbb-ea0e-411f-94e2-717eaad438bf": { + "mdev_type": "vfio_ap-passthrough", + "start": "manual", + "attrs": [ + { + "assign_adapter": "5" + }, + { + "assign_adapter": "6" + }, + { + "assign_domain": "0xab" + }, + { + "assign_control_domain": "0xab" + }, + { + "assign_domain": "4" + }, + { + "assign_control_domain": "4" + } + ] + } + } + ] + } +] + diff --git a/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml b/tests= /nodedevmdevctldata/mdevctl-list-multiple.out.xml new file mode 100644 index 0000000000..543ad916b7 --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml @@ -0,0 +1,39 @@ + + mdev_200f228a_c80a_4d50_bfb7_f5a0e4e34045 + 0000:00:02.0 + + + + + + + mdev_de807ffc_1923_4d5f_b6c9_b20ecebc6d4b + 0000:00:02.0 + + + + + + + mdev_435722ea_5f43_468a_874f_da34f1217f13 + 0000:00:02.0 + + + + + + + + mdev_783e6dbb_ea0e_411f_94e2_717eaad438bf + matrix + + + + + + + + + + + diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 650e46a29f..6c92d839d1 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -145,6 +145,53 @@ testMdevctlStop(const void *data) return ret; } =20 + +static int +testMdevctlParse(const void *data) +{ + g_autofree char *buf =3D NULL; + const char *filename =3D data; + g_autofree char *jsonfile =3D g_strdup_printf("%s/nodedevmdevctldata/%= s.json", + abs_srcdir, filename); + g_autofree char *xmloutfile =3D g_strdup_printf("%s/nodedevmdevctldata= /%s.out.xml", + abs_srcdir, filename); + int ret =3D -1; + int nmdevs =3D 0; + virNodeDeviceDef **mdevs =3D NULL; + virBuffer xmloutbuf =3D VIR_BUFFER_INITIALIZER; + size_t i; + + if (virFileReadAll(jsonfile, 1024*1024, &buf) < 0) { + VIR_TEST_DEBUG("Unable to read file %s", jsonfile); + return -1; + } + + if ((nmdevs =3D nodeDeviceParseMdevctlJSON(buf, &mdevs)) < 0) { + VIR_TEST_DEBUG("Unable to parse json for %s", filename); + return -1; + } + + for (i =3D 0; i < nmdevs; i++) { + g_autofree char *devxml =3D virNodeDeviceDefFormat(mdevs[i]); + if (!devxml) + goto cleanup; + virBufferAddStr(&xmloutbuf, devxml); + } + + if (nodedevCompareToFile(virBufferCurrentContent(&xmloutbuf), xmloutfi= le) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virBufferFreeAndReset(&xmloutbuf); + for (i =3D 0; i < nmdevs; i++) + virNodeDeviceDefFree(mdevs[i]); + g_free(mdevs); + + return ret; +} + static void nodedevTestDriverFree(virNodeDeviceDriverStatePtr drv) { @@ -265,13 +312,13 @@ mymain(void) } =20 #define DO_TEST_FULL(desc, func, info) \ - if (virTestRun(desc, func, &info) < 0) \ + if (virTestRun(desc, func, info) < 0) \ ret =3D -1; =20 #define DO_TEST_START_FULL(virt_type, create, filename) \ do { \ struct startTestInfo info =3D { virt_type, create, filename }; \ - DO_TEST_FULL("mdevctl start " filename, testMdevctlStartHelper, in= fo); \ + DO_TEST_FULL("mdevctl start " filename, testMdevctlStartHelper, &i= nfo); \ } \ while (0) =20 @@ -281,6 +328,9 @@ mymain(void) #define DO_TEST_STOP(uuid) \ DO_TEST_FULL("mdevctl stop " uuid, testMdevctlStop, uuid) =20 +#define DO_TEST_PARSE_JSON(filename) \ + DO_TEST_FULL("parse mdevctl json " filename, testMdevctlParse, filenam= e) + /* Test mdevctl start commands */ DO_TEST_START("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); DO_TEST_START("mdev_fedc4916_1ca8_49ac_b176_871d16c13076"); @@ -289,6 +339,8 @@ mymain(void) /* Test mdevctl stop command, pass an arbitrary uuid */ DO_TEST_STOP("e2451f73-c95b-4124-b900-e008af37c576"); =20 + DO_TEST_PARSE_JSON("mdevctl-list-multiple"); + done: nodedevTestDriverFree(driver); =20 --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777444; cv=none; d=zohomail.com; s=zohoarc; b=lIS7v3u3VayffFD24Sq6ekUO7GJKNwWLWkC86VO4eRo7nZsEewcSGBJ+wzskftBJ8Skdrmqr0xUwO/V7yOYXeWTdlqySNC6Z003J214Vyh/aDOMYVfVUjUz68T/Z+fBaBL46DfzkiA4Lt8DbpO4bBoL8YV/i5oQtE8LZmGRwqCc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777444; 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=7KgfspYIsBVfroKGeSvtdlSFfZNyvcrH92CTvvn0HXE=; b=m1G1y2lsl3giY/LV0z0StFY3WwNWaKITFgjShiGus29WjMTcLAQqOtcXii+q8GVgVYOK7beQF/F7F3N//gJUPk9Ix4kaRlC39MYvmV6kOt6ohGQliZAjvVSEVzjOfB/GIUBaLgMsscuPuE/TKlt+SBlgj8q5jexWVp2sOu25ugY= 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) header.from= 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 1616777444926744.8915053218242; Fri, 26 Mar 2021 09:50:44 -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-387-795tNIr_OX27kK8nHJMZrQ-1; Fri, 26 Mar 2021 12:49:05 -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 57D7F1853022; Fri, 26 Mar 2021 16:48:58 +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 34E0C60C21; Fri, 26 Mar 2021 16:48:58 +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 E38721802142; Fri, 26 Mar 2021 16:48:57 +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 12QGma5T002958 for ; Fri, 26 Mar 2021 12:48:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4D58E5D72E; Fri, 26 Mar 2021 16:48:36 +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 159565D6DC; Fri, 26 Mar 2021 16:48:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777443; 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=7KgfspYIsBVfroKGeSvtdlSFfZNyvcrH92CTvvn0HXE=; b=OHLeHmM8nL3xzVL1brcmfyFPey2AkWl/Jf4k9YWgkx+1roSJmZzZTSTYUu7O9ZxzbEEdcN Pdu/HiZaxsGu4Q3+cbmtX/0dkY39esOWGcRqauxPRwv5s0UbqJ8gs8JIhwXcdq1lTVYrRL FamEf/84sqXokQ8T7wpXcGlDJsn+bdo= X-MC-Unique: 795tNIr_OX27kK8nHJMZrQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 08/30] nodedev: add ability to list defined mdevs Date: Fri, 26 Mar 2021 11:48:04 -0500 Message-Id: <20210326164826.1720062-9-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) Content-Type: text/plain; charset="utf-8" This adds an internal API to query for persistent mediated devices that are defined by mdevctl. Upcoming commits will make use of this information. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- src/node_device/node_device_driver.c | 18 +++++++++ src/node_device/node_device_driver.h | 3 ++ .../mdevctl-list-defined.argv | 1 + tests/nodedevmdevctltest.c | 39 +++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 tests/nodedevmdevctldata/mdevctl-list-defined.argv diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index a646692870..6911fa36da 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -860,6 +860,24 @@ virMdevctlStop(virNodeDeviceDefPtr def, char **errmsg) } =20 =20 +virCommand* +nodeDeviceGetMdevctlListCommand(bool defined, + char **output) +{ + virCommand *cmd =3D virCommandNewArgList(MDEVCTL, + "list", + "--dumpjson", + NULL); + + if (defined) + virCommandAddArg(cmd, "--defined"); + + virCommandSetOutputBuffer(cmd, output); + + return cmd; +} + + static void mdevGenerateDeviceName(virNodeDeviceDef *dev) { nodeDeviceGenerateName(dev, "mdev", dev->caps->data.mdev.uuid, NULL); diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index f1c93f4b21..705d83f827 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -121,6 +121,9 @@ virCommandPtr nodeDeviceGetMdevctlStopCommand(const char *uuid, char **errmsg); =20 +virCommandPtr +nodeDeviceGetMdevctlListCommand(bool defined, char **output); + int nodeDeviceParseMdevctlJSON(const char *jsonstring, virNodeDeviceDef ***devs); diff --git a/tests/nodedevmdevctldata/mdevctl-list-defined.argv b/tests/nod= edevmdevctldata/mdevctl-list-defined.argv new file mode 100644 index 0000000000..72b5906e9e --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-list-defined.argv @@ -0,0 +1 @@ +$MDEVCTL_BINARY$ list --dumpjson --defined diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 6c92d839d1..1ab4776a23 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -145,6 +145,40 @@ testMdevctlStop(const void *data) return ret; } =20 +static int +testMdevctlListDefined(const void *data G_GNUC_UNUSED) +{ + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + const char *actualCmdline =3D NULL; + int ret =3D -1; + g_autoptr(virCommand) cmd =3D NULL; + g_autofree char *output =3D NULL; + g_autofree char *cmdlinefile =3D + g_strdup_printf("%s/nodedevmdevctldata/mdevctl-list-defined.argv", + abs_srcdir); + + cmd =3D nodeDeviceGetMdevctlListCommand(true, &output); + + if (!cmd) + goto cleanup; + + virCommandSetDryRun(&buf, NULL, NULL); + if (virCommandRun(cmd, NULL) < 0) + goto cleanup; + + if (!(actualCmdline =3D virBufferCurrentContent(&buf))) + goto cleanup; + + if (nodedevCompareToFile(actualCmdline, cmdlinefile) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virBufferFreeAndReset(&buf); + virCommandSetDryRun(NULL, NULL, NULL); + return ret; +} =20 static int testMdevctlParse(const void *data) @@ -328,6 +362,9 @@ mymain(void) #define DO_TEST_STOP(uuid) \ DO_TEST_FULL("mdevctl stop " uuid, testMdevctlStop, uuid) =20 +#define DO_TEST_LIST_DEFINED() \ + DO_TEST_FULL("mdevctl list --defined", testMdevctlListDefined, NULL) + #define DO_TEST_PARSE_JSON(filename) \ DO_TEST_FULL("parse mdevctl json " filename, testMdevctlParse, filenam= e) =20 @@ -339,6 +376,8 @@ mymain(void) /* Test mdevctl stop command, pass an arbitrary uuid */ DO_TEST_STOP("e2451f73-c95b-4124-b900-e008af37c576"); =20 + DO_TEST_LIST_DEFINED(); + DO_TEST_PARSE_JSON("mdevctl-list-multiple"); =20 done: --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777343; cv=none; d=zohomail.com; s=zohoarc; b=YAHH9GsdSMhb1H+AhiYtaQDw6QGFsKHmKzTgB+Jc3wWc51Itzj0yP8OJGDvZ7Z6gb3AU9yUg5JxBincuryLWZ7fGoXNAzHow/0q0SOREUExb64jhrPce6eaGuyFsKgPJ7JmkmuGRlHcIlm50RSTELOUSQFh96SpS+P5XIqUqNQw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777343; 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=DtRClMRHWFyDk37bunhLojMW1CzKjZDOCVO0vgaXAVo=; b=Jw2q5orbLWxYYiBKEUx5ThmerTv1DXgs0prXInJXhycr+eETMzNusK2J0W4fzfXLI2+Obd42A4QvHvxnv1JfrW7R5otQQsAVxFwctakJEEEIrS3mOlYbvx4XR4cpL67LrYstULbCYCdQxvdp5Vg4l5f7Ylu/qA0yAA5EVSjvrSw= 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) header.from= 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 1616777343239225.31473971353216; Fri, 26 Mar 2021 09:49:03 -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-453-fPWFKj-kMiqFTN-rlY81-w-1; Fri, 26 Mar 2021 12:48: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 A54161853021; Fri, 26 Mar 2021 16:48:46 +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 7B4FB89D02; Fri, 26 Mar 2021 16:48:46 +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 081D44A7CA; Fri, 26 Mar 2021 16:48:46 +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 12QGmavt002963 for ; Fri, 26 Mar 2021 12:48:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id A499C5D72E; Fri, 26 Mar 2021 16:48:36 +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 6B9305D6DC; Fri, 26 Mar 2021 16:48:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777337; 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=DtRClMRHWFyDk37bunhLojMW1CzKjZDOCVO0vgaXAVo=; b=DYV1uKGu9onAt/LKR9LJZ73ME4mJ8gPpK6V8Zpk5jumkdqrM961R9tzS50Js5FeOyDAbwA U0EtpjK1eGna5IY1fB89294WjGoG7O4y3XHA0iCJsMqUpywWg8b+4+IREUgXLnVwoGek5w zyEuMDRlOps23WZ8uc0AmWMAM801IRY= X-MC-Unique: fPWFKj-kMiqFTN-rlY81-w-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 09/30] nodedev: add persistence to virNodeDeviceObj Date: Fri, 26 Mar 2021 11:48:05 -0500 Message-Id: <20210326164826.1720062-10-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.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" Consistent with other objects (e.g. virDomainObj), add a field to indicate whether the node device is persistent or transient. Signed-off-by: Jonathon Jongsma --- src/conf/virnodedeviceobj.c | 16 ++++++++++++++++ src/conf/virnodedeviceobj.h | 6 ++++++ src/libvirt_private.syms | 2 ++ 3 files changed, 24 insertions(+) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index ab663fd5a0..ce84e4d8c1 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -40,6 +40,7 @@ struct _virNodeDeviceObj { bool skipUpdateCaps; /* whether to skip checking host c= aps, used by testdriver */ bool active; + bool persistent; }; =20 struct _virNodeDeviceObjList { @@ -1003,3 +1004,18 @@ virNodeDeviceObjSetActive(virNodeDeviceObj *obj, { obj->active =3D active; } + + +bool +virNodeDeviceObjIsPersistent(virNodeDeviceObj *obj) +{ + return obj->persistent; +} + + +void +virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj, + bool persistent) +{ + obj->persistent =3D persistent; +} diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index e786a70f51..7f682b9dca 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -128,3 +128,9 @@ virNodeDeviceObjIsActive(virNodeDeviceObj *obj); void virNodeDeviceObjSetActive(virNodeDeviceObj *obj, bool active); +bool +virNodeDeviceObjIsPersistent(virNodeDeviceObj *obj); + +void +virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj, + bool persistent); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 09957c943b..047314ec19 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1273,6 +1273,7 @@ virNetworkPortDefSaveStatus; virNodeDeviceObjEndAPI; virNodeDeviceObjGetDef; virNodeDeviceObjIsActive; +virNodeDeviceObjIsPersistent; virNodeDeviceObjListAssignDef; virNodeDeviceObjListExport; virNodeDeviceObjListFindByName; @@ -1286,6 +1287,7 @@ virNodeDeviceObjListNew; virNodeDeviceObjListNumOfDevices; virNodeDeviceObjListRemove; virNodeDeviceObjSetActive; +virNodeDeviceObjSetPersistent; =20 =20 # conf/virnwfilterbindingdef.h --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777340; cv=none; d=zohomail.com; s=zohoarc; b=fze99Np/+N2VA7fPMKN9PuF7lky0k7T+2UksA2ABcxIjKO/ZW65TTeSTactl7vTa+ZoQYoBt9AUGZPEeVHR1+Q90lVGeDjYVCLgJyJ3KDEH91+hHbBrJwjuV5JA7RZWZ48F1OLhFn+/imUhaK/WxcPBKvqJgFEROFM1JiMc5B/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777340; 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=pM/wLnH4u7q9ms91nAdYPOGOuQByBX+lW0Frb1Y/eCw=; b=Q5ykRmGh9LsSIiewLLFP5vu7f+ccpHhjULPDgq5/R2xPBdFTEh6uByDBeSUHOuQP5ah8iIQAxljWI8jmY82RB0/hdjBNTQusIl2lL5ieo6UxmKIrh5JwsRWmVLumhQnEY/uYZH/Tn6Jvt+yRwf0+jpAQL7VONkTUQTsoI0Re1D4= 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) header.from= 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 1616777340824527.8973268487558; Fri, 26 Mar 2021 09:49:00 -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-273-s6JCrj1fP9WC7aTFXB-obQ-1; Fri, 26 Mar 2021 12:48:56 -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 EB69410866AB; Fri, 26 Mar 2021 16:48:49 +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 C9D7E5D6DC; Fri, 26 Mar 2021 16:48: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 8CDA21802137; Fri, 26 Mar 2021 16:48:49 +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 12QGmbq8002972 for ; Fri, 26 Mar 2021 12:48:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 063125D755; Fri, 26 Mar 2021 16:48:37 +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 C2DFE5D6DC; Fri, 26 Mar 2021 16:48:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777339; 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=pM/wLnH4u7q9ms91nAdYPOGOuQByBX+lW0Frb1Y/eCw=; b=XEZ8NfyR55kknNjUtvnCs2Rpa/j6J4xCwPxgqQKafTuGgkJ+jrDHVCJdr0yer28wZ8vKso faFjCdZvuDAFYcjHk6ji9NLZaKnQryUOwwNbx8o4w8OM+6Jek7EsYO6e6bJgOsn3miCLk1 8IsJfQoTuBqOlW+nhpZAoMeucE6eXvc= X-MC-Unique: s6JCrj1fP9WC7aTFXB-obQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 10/30] nodedev: add DEFINED/UNDEFINED lifecycle events Date: Fri, 26 Mar 2021 11:48:06 -0500 Message-Id: <20210326164826.1720062-11-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.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" Since a mediated device can be persistently defined by the mdevctl backend, we need additional lifecycle events beyond CREATED/DELETED to indicate that e.g. the device has been stopped but the device definition still exists. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- examples/c/misc/event-test.c | 4 ++++ include/libvirt/libvirt-nodedev.h | 2 ++ tools/virsh-nodedev.c | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/c/misc/event-test.c b/examples/c/misc/event-test.c index 76d4f3f6e8..10c707e66b 100644 --- a/examples/c/misc/event-test.c +++ b/examples/c/misc/event-test.c @@ -381,6 +381,10 @@ nodeDeviceEventToString(int event) return "Created"; case VIR_NODE_DEVICE_EVENT_DELETED: return "Deleted"; + case VIR_NODE_DEVICE_EVENT_DEFINED: + return "Defined"; + case VIR_NODE_DEVICE_EVENT_UNDEFINED: + return "Undefined"; case VIR_NODE_DEVICE_EVENT_LAST: break; } diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index 2deead0791..77d814935e 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -196,6 +196,8 @@ int virConnectNodeDeviceEventDeregisterAny(virConnectPt= r conn, typedef enum { VIR_NODE_DEVICE_EVENT_CREATED =3D 0, VIR_NODE_DEVICE_EVENT_DELETED =3D 1, + VIR_NODE_DEVICE_EVENT_DEFINED =3D 2, + VIR_NODE_DEVICE_EVENT_UNDEFINED =3D 3, =20 # ifdef VIR_ENUM_SENTINELS VIR_NODE_DEVICE_EVENT_LAST diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index fedc8497f8..b9fe9b8be1 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -775,7 +775,9 @@ VIR_ENUM_DECL(virshNodeDeviceEvent); VIR_ENUM_IMPL(virshNodeDeviceEvent, VIR_NODE_DEVICE_EVENT_LAST, N_("Created"), - N_("Deleted")); + N_("Deleted"), + N_("Defined"), + N_("Undefined")); =20 static const char * virshNodeDeviceEventToString(int event) --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777354; cv=none; d=zohomail.com; s=zohoarc; b=TxGlJ6av0RqQt51+MPH4pdadnYhQb5vojKApTWEwpUWGHKdZC2OPX90+syYsMB88VGnOLsbEiEvr1TGOzhKH1cnwNlSgRLILmdWTGMXGyl03adArQAJGeRPaMY0NNGq+HUfvaU/qTIBoC45Hklu7f28fzYWwmELK94s+nQFyuIY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777354; 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=jlK8NSyrEUJdMvEDoCLI2lkLMALIfE12DVeQU05zBWs=; b=TuuaFWPAE/7yHmpRiYm7SSjq1AqriJuTpdB/ZDbKkzl2SGlEa0bVySmjgdhOu0HvPDbroxTDwFhTdbVoWz9O1PwQRvpnOyPOSmAnfHXw2t03YQhu9V+mt58bnGSNo/CBSb0AGCRgNHEyQNe+HLxOhIi/c2+bJiyrKaf94u1O9Ow= 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) header.from= 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 1616777354467704.1402129710261; Fri, 26 Mar 2021 09:49:14 -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-68-DlkkhnG1NvKwbnaIpycEug-1; Fri, 26 Mar 2021 12:49:08 -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 A4CDF10866AA; Fri, 26 Mar 2021 16:49:01 +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 7B297100AE43; Fri, 26 Mar 2021 16:49: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 3E1EB4A71A; Fri, 26 Mar 2021 16:49:01 +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 12QGmbg0002977 for ; Fri, 26 Mar 2021 12:48:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5C3755D755; Fri, 26 Mar 2021 16:48:37 +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 228215D6DC; Fri, 26 Mar 2021 16:48:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777353; 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=jlK8NSyrEUJdMvEDoCLI2lkLMALIfE12DVeQU05zBWs=; b=PsOjGxgRUdJHPsDnb/1a2EwsjnLhtPkWbHpB8ZBQvugLcZes6mA7hBVP3gt5wg835qyFEi 6ivkepfgHaoWKmuCe0MUyN61mGjEn4txZr+LYB2Oqb4sh+tnUyGZmkTsHFgDH2ckKYEXxt 6KJTf7k3KL+3kpGGaIbfGzSbFiSWmj8= X-MC-Unique: DlkkhnG1NvKwbnaIpycEug-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 11/30] nodedev: add mdevctl devices to node device list Date: Fri, 26 Mar 2021 11:48:07 -0500 Message-Id: <20210326164826.1720062-12-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.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" At startup, query devices that are defined by 'mdevctl' and add them to the node device list. This adds a complication: we now have two potential sources of information for a node device: - udev for all devices and for activated mediated devices - mdevctl for persistent mediated devices Unfortunately, neither backend returns full information for a mediated device. For example, if a persistent mediated device in the list (with information provided from mdevctl) is 'started', that same device will now be detected by udev. If we simply overwrite the existing device definition with the new one provided by the udev backend, we will lose extra information that was provided by mdevctl (e.g. attributes, etc). To avoid this, make sure to copy the extra information into the new device definition. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- src/node_device/node_device_driver.c | 153 +++++++++++++++++++++++++++ src/node_device/node_device_driver.h | 6 ++ src/node_device/node_device_udev.c | 31 +++++- 3 files changed, 185 insertions(+), 5 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 6911fa36da..efa524f317 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1164,3 +1164,156 @@ nodeDeviceGenerateName(virNodeDeviceDef *def, *(def->name + i) =3D '_'; } } + + +static int +virMdevctlListDefined(virNodeDeviceDef ***devs) +{ + int status; + g_autofree char *output =3D NULL; + g_autoptr(virCommand) cmd =3D nodeDeviceGetMdevctlListCommand(true, &o= utput); + + if (virCommandRun(cmd, &status) < 0 || status !=3D 0) + return -1; + + if (!output) + return -1; + + return nodeDeviceParseMdevctlJSON(output, devs); +} + + +int +nodeDeviceUpdateMediatedDevices(void) +{ + g_autofree virNodeDeviceDef **defs =3D NULL; + int ndefs; + size_t i; + + if ((ndefs =3D virMdevctlListDefined(&defs)) < 0) { + virReportSystemError(errno, "%s", + _("failed to query mdevs from mdevctl")); + return -1; + } + + for (i =3D 0; i < ndefs; i++) { + virNodeDeviceObj *obj; + virObjectEvent *event; + g_autoptr(virNodeDeviceDef) def =3D defs[i]; + g_autofree char *name =3D g_strdup(def->name); + bool defined =3D false; + + def->driver =3D g_strdup("vfio_mdev"); + + if (!(obj =3D virNodeDeviceObjListFindByName(driver->devs, def->na= me))) { + virNodeDeviceDef *d =3D g_steal_pointer(&def); + if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, d)))= { + virNodeDeviceDefFree(d); + return -1; + } + } else { + bool changed; + virNodeDeviceDef *olddef =3D virNodeDeviceObjGetDef(obj); + + defined =3D virNodeDeviceObjIsPersistent(obj); + /* Active devices contain some additional information (e.g. sy= sfs + * path) that is not provided by mdevctl, so re-use the existi= ng + * definition and copy over new mdev data */ + changed =3D nodeDeviceDefCopyFromMdevctl(olddef, def); + + if (defined && !changed) { + /* if this device was already defined and the definition + * hasn't changed, there's nothing to do for this device */ + virNodeDeviceObjEndAPI(&obj); + continue; + } + } + + /* all devices returned by virMdevctlListDefined() are persistent = */ + virNodeDeviceObjSetPersistent(obj, true); + + if (!defined) + event =3D virNodeDeviceEventLifecycleNew(name, + VIR_NODE_DEVICE_EVENT_D= EFINED, + 0); + else + event =3D virNodeDeviceEventUpdateNew(name); + + virNodeDeviceObjEndAPI(&obj); + virObjectEventStateQueue(driver->nodeDeviceEventState, event); + } + + return 0; +} + + +/* returns true if any attributes were copied, else returns false */ +static bool +virMediatedDeviceAttrsCopy(virNodeDevCapMdev *dst, + virNodeDevCapMdev *src) +{ + bool ret =3D false; + size_t i; + + if (src->nattributes !=3D dst->nattributes) { + ret =3D true; + for (i =3D 0; i < dst->nattributes; i++) + virMediatedDeviceAttrFree(dst->attributes[i]); + g_free(dst->attributes); + + dst->nattributes =3D src->nattributes; + dst->attributes =3D g_new0(virMediatedDeviceAttr*, + src->nattributes); + for (i =3D 0; i < dst->nattributes; i++) + dst->attributes[i] =3D virMediatedDeviceAttrNew(); + } + + for (i =3D 0; i < src->nattributes; i++) { + if (STRNEQ_NULLABLE(src->attributes[i]->name, + dst->attributes[i]->name)) { + ret =3D true; + g_free(dst->attributes[i]->name); + dst->attributes[i]->name =3D + g_strdup(src->attributes[i]->name); + } + if (STRNEQ_NULLABLE(src->attributes[i]->value, + dst->attributes[i]->value)) { + ret =3D true; + g_free(dst->attributes[i]->value); + dst->attributes[i]->value =3D + g_strdup(src->attributes[i]->value); + } + } + + return ret; +} + + +/* A mediated device definitions from mdevctl contains additional info tha= t is + * not available from udev. Transfer this data to the new definition. + * Returns true if anything was copied, else returns false */ +bool +nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, + virNodeDeviceDef *src) +{ + bool ret =3D false; + virNodeDevCapMdev *srcmdev =3D &src->caps->data.mdev; + virNodeDevCapMdev *dstmdev =3D &dst->caps->data.mdev; + + if (STRNEQ_NULLABLE(dstmdev->type, srcmdev->type)) { + ret =3D true; + g_free(dstmdev->type); + dstmdev->type =3D g_strdup(srcmdev->type); + } + + if (STRNEQ_NULLABLE(dstmdev->uuid, srcmdev->uuid)) { + ret =3D true; + g_free(dstmdev->uuid); + dstmdev->uuid =3D g_strdup(srcmdev->uuid); + } + + if (virMediatedDeviceAttrsCopy(dstmdev, srcmdev)) + ret =3D true; + + return ret; +} diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index 705d83f827..9b54efe4e3 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -128,8 +128,14 @@ int nodeDeviceParseMdevctlJSON(const char *jsonstring, virNodeDeviceDef ***devs); =20 +int +nodeDeviceUpdateMediatedDevices(void); + void nodeDeviceGenerateName(virNodeDeviceDef *def, const char *subsystem, const char *sysname, const char *s); + +bool nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, + virNodeDeviceDef *src); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index eae301cc95..38ebe7b5c5 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1421,9 +1421,17 @@ udevRemoveOneDeviceSysPath(const char *path) VIR_NODE_DEVICE_EVENT_DELETED, 0); =20 - VIR_DEBUG("Removing device '%s' with sysfs path '%s'", - def->name, path); - virNodeDeviceObjListRemove(driver->devs, obj); + /* If the device is a mediated device that has been 'stopped', it may = still + * be defined by mdevctl and can therefore be started again. Don't dro= p it + * from the list of node devices */ + if (virNodeDeviceObjIsPersistent(obj)) { + VIR_FREE(def->sysfs_path); + virNodeDeviceObjSetActive(obj, false); + } else { + VIR_DEBUG("Removing device '%s' with sysfs path '%s'", + def->name, path); + virNodeDeviceObjListRemove(driver->devs, obj); + } virNodeDeviceObjEndAPI(&obj); =20 virObjectEventStateQueue(driver->nodeDeviceEventState, event); @@ -1481,7 +1489,6 @@ udevSetParent(struct udev_device *device, return 0; } =20 - static int udevAddOneDevice(struct udev_device *device) { @@ -1491,6 +1498,7 @@ udevAddOneDevice(struct udev_device *device) virObjectEventPtr event =3D NULL; bool new_device =3D true; int ret =3D -1; + bool was_persistent =3D false; =20 def =3D g_new0(virNodeDeviceDef, 1); =20 @@ -1514,14 +1522,23 @@ udevAddOneDevice(struct udev_device *device) goto cleanup; =20 if ((obj =3D virNodeDeviceObjListFindByName(driver->devs, def->name)))= { + objdef =3D virNodeDeviceObjGetDef(obj); + + if (def->caps->data.type =3D=3D VIR_NODE_DEV_CAP_MDEV) + nodeDeviceDefCopyFromMdevctl(def, objdef); + was_persistent =3D virNodeDeviceObjIsPersistent(obj); + /* If the device was defined by mdevctl and was never instantiated= , it + * won't have a sysfs path. We need to emit a CREATED event... */ + new_device =3D (objdef->sysfs_path =3D=3D NULL); + virNodeDeviceObjEndAPI(&obj); - new_device =3D false; } =20 /* If this is a device change, the old definition will be freed * and the current definition will take its place. */ if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, def))) goto cleanup; + virNodeDeviceObjSetPersistent(obj, was_persistent); objdef =3D virNodeDeviceObjGetDef(obj); =20 if (new_device) @@ -1941,6 +1958,10 @@ nodeStateInitializeEnumerate(void *opaque) /* Populate with known devices */ if (udevEnumerateDevices(udev) !=3D 0) goto error; + /* Load persistent mdevs (which might not be activated yet) and additi= onal + * information about active mediated devices from mdevctl */ + if (nodeDeviceUpdateMediatedDevices() !=3D 0) + goto error; =20 nodeDeviceLock(); driver->initialized =3D true; --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777464; cv=none; d=zohomail.com; s=zohoarc; b=HusBZ8qbx480sNJ7s9ruBv+MzefliwEMOWlM4SMdCPOUQ2RQBg4YjmZAs/w7EtZeSS6KJ+cgBlL64hy8tw8VDfDk8FtyTxCVPuIvSPcpidoXjOWHW1XjJga+PI7ACF7MJS1wd/1whrbjKQ7o9Kvgsi/FTLM4994PHbKGFtI7p1o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777464; 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=DeAA7cjFkWOEFxc6xBy8T747EyOv+4mOVis5ORbXpyQ=; b=OOBELL0oPIc5RSHhmxXQe9zNbof8W+ww1zXWo/vSAocYoXpWywdjbxR8zcK0YeYATB+A5Wv6stMQCG09DITGYf7aeD3cmu6xLS/NAKZ9VEPGSLnSbpi+wq9nCK12k2LnrdmbC111J4wfNs57H4Rwum8fp2PjLzjUInuehEJW0b4= 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) header.from= 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 1616777464305849.3400030870741; Fri, 26 Mar 2021 09:51:04 -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-175-n4eef9zyNPae7qY1g8bIOw-1; Fri, 26 Mar 2021 12:49:11 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id E85DD10866BC; Fri, 26 Mar 2021 16:49:04 +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 C11A3679E7; Fri, 26 Mar 2021 16:49: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 80C884A71E; Fri, 26 Mar 2021 16:49:04 +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 12QGmbgt002989 for ; Fri, 26 Mar 2021 12:48:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id B0BBB5D755; Fri, 26 Mar 2021 16:48:37 +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 76F605D6DC; Fri, 26 Mar 2021 16:48:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777463; 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=DeAA7cjFkWOEFxc6xBy8T747EyOv+4mOVis5ORbXpyQ=; b=EXK6aKOm6L7z6nrLx2SQG8f6DehKpNXRXI0B5w96pCeswFfFVaczCxTh+T/jRHX8NqN13f S1uc2xKJ/LYXd3AWrcOubCAZ1ceMlZYIJ1jqTRXDF0erUkVcTtNVK5+Y04t1bSPBG6+twd Q0ueqnu3bj4nn1LMbqdSUNY4/sP5R3g= X-MC-Unique: n4eef9zyNPae7qY1g8bIOw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 12/30] nodedev: add helper functions to remove node devices Date: Fri, 26 Mar 2021 11:48:08 -0500 Message-Id: <20210326164826.1720062-13-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.16 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 a mediated device is stopped or undefined by an application outside of libvirt, we need to remove it from our list of node devices within libvirt. This patch introduces virNodeDeviceObjListRemoveLocked() and virNodeDeviceObjListForEachRemove() (which are analogous to other types of object lists in libvirt) to facilitate that. They will be used in coming commits. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- src/conf/virnodedeviceobj.c | 58 ++++++++++++++++++++++++++++++++++--- src/conf/virnodedeviceobj.h | 11 +++++++ src/libvirt_private.syms | 2 ++ 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index ce84e4d8c1..97e7d7ab11 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -507,23 +507,29 @@ void virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs, virNodeDeviceObjPtr obj) { - virNodeDeviceDefPtr def; - if (!obj) return; - def =3D obj->def; =20 virObjectRef(obj); virObjectUnlock(obj); virObjectRWLockWrite(devs); virObjectLock(obj); - virHashRemoveEntry(devs->objs, def->name); + virNodeDeviceObjListRemoveLocked(devs, obj); virObjectUnlock(obj); virObjectUnref(obj); virObjectRWUnlock(devs); } =20 =20 +/* The caller must hold lock on 'devs' */ +void +virNodeDeviceObjListRemoveLocked(virNodeDeviceObjList *devs, + virNodeDeviceObj *dev) +{ + virHashRemoveEntry(devs->objs, dev->def->name); +} + + /* * Return the NPIV dev's parent device name */ @@ -1019,3 +1025,47 @@ virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj, { obj->persistent =3D persistent; } + + +struct virNodeDeviceObjListRemoveData +{ + virNodeDeviceObjListRemoveIter iter; + void *opaque; +}; + +static int virNodeDeviceObjListRemoveCb(void *key G_GNUC_UNUSED, + void *value, + void *opaque) +{ + struct virNodeDeviceObjListRemoveData *data =3D opaque; + + return data->iter(value, data->opaque); +} + + +/** + * virNodeDeviceObjListForEachRemove + * @devs: Pointer to object list + * @iter: function to call for each device object + * @opaque: Opaque data to use as argument to helper + * + * For each object in @devs, call the @iter helper using @opaque as + * an argument. If @iter returns true, that item will be removed from the + * object list. + */ +void +virNodeDeviceObjListForEachRemove(virNodeDeviceObjList *devs, + virNodeDeviceObjListRemoveIter iter, + void *opaque) +{ + struct virNodeDeviceObjListRemoveData data =3D { + .iter =3D iter, + .opaque =3D opaque + }; + + virObjectRWLockWrite(devs); + g_hash_table_foreach_remove(devs->objs, + virNodeDeviceObjListRemoveCb, + &data); + virObjectRWUnlock(devs); +} diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 7f682b9dca..249115cf68 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -80,6 +80,10 @@ void virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs, virNodeDeviceObjPtr dev); =20 +void +virNodeDeviceObjListRemoveLocked(virNodeDeviceObjList *devs, + virNodeDeviceObj *dev); + int virNodeDeviceObjListGetParentHost(virNodeDeviceObjListPtr devs, virNodeDeviceDefPtr def); @@ -134,3 +138,10 @@ virNodeDeviceObjIsPersistent(virNodeDeviceObj *obj); void virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj, bool persistent); + +typedef bool (*virNodeDeviceObjListRemoveIter)(virNodeDeviceObj *obj, + const void *opaque); + +void virNodeDeviceObjListForEachRemove(virNodeDeviceObjList *devs, + virNodeDeviceObjListRemoveIter iter, + void *opaque); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 047314ec19..f36400b5f6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1280,12 +1280,14 @@ virNodeDeviceObjListFindByName; virNodeDeviceObjListFindBySysfsPath; virNodeDeviceObjListFindMediatedDeviceByUUID; virNodeDeviceObjListFindSCSIHostByWWNs; +virNodeDeviceObjListForEachRemove; virNodeDeviceObjListFree; virNodeDeviceObjListGetNames; virNodeDeviceObjListGetParentHost; virNodeDeviceObjListNew; virNodeDeviceObjListNumOfDevices; virNodeDeviceObjListRemove; +virNodeDeviceObjListRemoveLocked; virNodeDeviceObjSetActive; virNodeDeviceObjSetPersistent; =20 --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777337; cv=none; d=zohomail.com; s=zohoarc; b=OZJEZNbbhqMjc4/Bz6pE7wzW7gEgPK+dAP1aX9i4xfdp7UqYHYNF/VVX/t260IGmF0Unhkg+2V6EYqG50OSbnYmouh3Rw3MPcltkI97j+duo19F8GpSCgxLj5Y+IyKGdTbdt+gcJ7EvPURAWHcyXSH1vQjlkEHwfF2voMszGL3g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777337; 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=36vwbNHMdmI1tBoPwTIYhdJXDZ30LFbvEX7k6WTFyio=; b=W+Mrq4LWnVL377BttDs2GR/p9NpqWWROnAbT10v2/apBYcguU6CW9OkZEW7y2/1V1eM81qfqMCpeUXtaQHb7SF7K5TVj7k9p8+I3oV3fuZr51wRFiIDthHrf4jabU8/R6Ora4WSOh/7HLY1XmBK+CZtMJMTWdbt+H5Xta8A4l3g= 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) header.from= 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 1616777337898356.1684740042506; Fri, 26 Mar 2021 09:48:57 -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-322-NUqgFlgKOe63-1e3L_08dw-1; Fri, 26 Mar 2021 12:48:54 -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 AA56C80006E; Fri, 26 Mar 2021 16:48:49 +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 874575D6DC; Fri, 26 Mar 2021 16:48: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 1F0D54A700; Fri, 26 Mar 2021 16:48:49 +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 12QGmcC7002996 for ; Fri, 26 Mar 2021 12:48:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0EAB35D755; Fri, 26 Mar 2021 16:48:38 +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 C9C605D72E; Fri, 26 Mar 2021 16:48:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777336; 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=36vwbNHMdmI1tBoPwTIYhdJXDZ30LFbvEX7k6WTFyio=; b=DBgfYRvhm8GrQAl5jQibppSkpCu81kTQ122W6eETttIaMruBvSEtNTTDOmVQUcggErlojd wMhASipyo52/BP2BDOP9BiTfMS4CRyHZQEzeNWw7rFbjK7A2nOVUYY9ci7cEcwWgHgeV8G yoaI0yPBzYQYS4L6M0/yRDbRTuIL/y0= X-MC-Unique: NUqgFlgKOe63-1e3L_08dw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 13/30] nodedev: handle mdevs that disappear from mdevctl Date: Fri, 26 Mar 2021 11:48:09 -0500 Message-Id: <20210326164826.1720062-14-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.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" mdevctl does not currently provide any events when the list of defined devices changes, so we will need to poll mdevctl for the list of defined devices periodically. When a mediated device no longer exists from one iteration to the next, we need to treat it as an "undefine" event. When we get such an event, we remove the device from the list if it's not active. Otherwise, we simply mark it as non-persistent. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- src/node_device/node_device_driver.c | 67 ++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index efa524f317..4be650ddef 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1183,20 +1183,81 @@ virMdevctlListDefined(virNodeDeviceDef ***devs) } =20 =20 +typedef struct _virMdevctlForEachData virMdevctlForEachData; +struct _virMdevctlForEachData { + int ndefs; + virNodeDeviceDef **defs; +}; + + +/* This function keeps the list of persistent mediated devices consistent + * between the nodedev driver and mdevctl. + * @obj is a device that is currently known by the nodedev driver, and @op= aque + * contains the most recent list of devices defined by mdevctl. If @obj is= no + * longer defined in mdevctl, mark it as undefined and possibly remove it = from + * the driver as well. Returning 'true' from this function indicates that = the + * device should be removed from the nodedev driver list. */ +static bool +removeMissingPersistentMdevs(virNodeDeviceObj *obj, + const void *opaque) +{ + bool remove =3D false; + const virMdevctlForEachData *data =3D opaque; + size_t i; + virNodeDeviceDef *def =3D virNodeDeviceObjGetDef(obj); + virObjectEvent *event; + + if (def->caps->data.type !=3D VIR_NODE_DEV_CAP_MDEV) + return false; + + /* transient mdevs are populated via udev, so don't remove them from t= he + * nodedev driver just because they are not reported by by mdevctl */ + if (!virNodeDeviceObjIsPersistent(obj)) + return false; + + for (i =3D 0; i < data->ndefs; i++) { + /* OK, this mdev is still defined by mdevctl */ + if (STREQ(data->defs[i]->name, def->name)) + return false; + } + + event =3D virNodeDeviceEventLifecycleNew(def->name, + VIR_NODE_DEVICE_EVENT_UNDEFINED, + 0); + + /* The device is active, but no longer defined by mdevctl. Keep the de= vice + * in the list, but mark it as non-persistent */ + if (virNodeDeviceObjIsActive(obj)) + virNodeDeviceObjSetPersistent(obj, false); + else + remove =3D true; + + virObjectEventStateQueue(driver->nodeDeviceEventState, event); + + return remove; +} + + int nodeDeviceUpdateMediatedDevices(void) { g_autofree virNodeDeviceDef **defs =3D NULL; - int ndefs; + virMdevctlForEachData data =3D { 0, }; size_t i; =20 - if ((ndefs =3D virMdevctlListDefined(&defs)) < 0) { + if ((data.ndefs =3D virMdevctlListDefined(&defs)) < 0) { virReportSystemError(errno, "%s", _("failed to query mdevs from mdevctl")); return -1; } =20 - for (i =3D 0; i < ndefs; i++) { + /* Any mdevs that were previously defined but were not returned in the + * latest mdevctl query should be removed from the device list */ + data.defs =3D defs; + virNodeDeviceObjListForEachRemove(driver->devs, + removeMissingPersistentMdevs, &data); + + for (i =3D 0; i < data.ndefs; i++) { virNodeDeviceObj *obj; virObjectEvent *event; g_autoptr(virNodeDeviceDef) def =3D defs[i]; --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777347; cv=none; d=zohomail.com; s=zohoarc; b=Tq3UNFW0Gu9V6KyPu3XlSnxcF5NDtjqeKoMysiy7CuOQUCIFymmBNldnA63gfULIJFt8YdPvBPhFEf2TFfNqUhiFqKbRd6ZQplA+/K3dMeXTtvKa5KgYZzcRzkLIrESBhLy7V+UOz+hPlLKMpOq6mmAL9u1LRcQKd0wF1mImZo8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777347; 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=AOmXMAiWb4eQCnqAiDygLwAwpYlRi1Xfoqh45DnHU6I=; b=fwwaN7HiRbfQNhZP5Jb/xw4auN2zm29gco1hYqdF0/SdtttxKCDSR1ax3PJjpxN4bRIHq8xojFf5ldomFtsxOG2t5v9XRo+w0Re5Te1RdLHXFiuouXDUvJjfOvy0wD5fPCLmBFCkiHgcKgRJ1rXvHOIlj3FcD4aXIvZvUES5VcM= 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) header.from= 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 1616777347512788.8122048202154; Fri, 26 Mar 2021 09:49:07 -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-55-vtjHxNKMPtSn6RhAKZPUrQ-1; Fri, 26 Mar 2021 12:49:01 -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 27E24107ACCA; Fri, 26 Mar 2021 16:48:53 +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 0366D5D6DC; Fri, 26 Mar 2021 16:48:53 +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 B45AB4A708; Fri, 26 Mar 2021 16:48:52 +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 12QGmcsP003002 for ; Fri, 26 Mar 2021 12:48:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 689115D756; Fri, 26 Mar 2021 16:48:38 +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 2B1585D755; Fri, 26 Mar 2021 16:48:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777346; 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=AOmXMAiWb4eQCnqAiDygLwAwpYlRi1Xfoqh45DnHU6I=; b=ZDtx8IjZGtZd71CmIYXKy8DDWZ29q/AP/kXaBdCTwQDqzo1pczaZU4dk9rggBB5BJNqLZq zkVJwARzNUJA8lv3tjBzVYUnCZ4tIF6mCT22lapmGlLahWIHrvo5jrPT8lrEtSZe4tfCUh oDa3I7GbLX6dg/2kPoM7Ms7cv+SXTfE= X-MC-Unique: vtjHxNKMPtSn6RhAKZPUrQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 14/30] nodedev: Refresh mdev devices when changes are detected Date: Fri, 26 Mar 2021 11:48:10 -0500 Message-Id: <20210326164826.1720062-15-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.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" We need to query mdevctl for changes to device definitions since an administrator can define new devices by executing mdevctl outside of libvirt. In the future, mdevctl may add a way to signal device add/remove via events, but for now we resort to a bit of a workaround: monitoring the mdevctl config directory for changes to files. When a change is detected, we query mdevctl and update our device list. The mdevctl querying is handled in a throwaway thread, and these threads are synchronized with a mutex. Signed-off-by: Jonathon Jongsma --- src/node_device/node_device_udev.c | 161 +++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 38ebe7b5c5..78144b7762 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -19,6 +19,7 @@ */ =20 #include +#include #include #include #include @@ -69,6 +70,10 @@ struct _udevEventData { =20 /* init thread */ virThread initThread; + + GList *mdevctlMonitors; + virMutex mdevctlLock; + int mdevctlTimeout; }; =20 static virClassPtr udevEventDataClass; @@ -89,6 +94,11 @@ udevEventDataDispose(void *obj) udev_monitor_unref(priv->udev_monitor); udev_unref(udev); =20 + virMutexLock(&priv->mdevctlLock); + g_list_free_full(priv->mdevctlMonitors, g_object_unref); + virMutexUnlock(&priv->mdevctlLock); + virMutexDestroy(&priv->mdevctlLock); + virCondDestroy(&priv->threadCond); } =20 @@ -120,6 +130,11 @@ udevEventDataNew(void) return NULL; } =20 + if (virMutexInit(&ret->mdevctlLock) < 0) { + virObjectUnref(ret); + return NULL; + } + ret->watch =3D -1; return ret; } @@ -2004,6 +2019,137 @@ udevPCITranslateInit(bool privileged G_GNUC_UNUSED) } =20 =20 +static void +mdevctlHandlerThread(void *opaque G_GNUC_UNUSED) +{ + udevEventData *priv =3D driver->privateData; + + /* ensure only a single thread can query mdevctl at a time */ + virMutexLock(&priv->mdevctlLock); + if (nodeDeviceUpdateMediatedDevices() < 0) + VIR_WARN("mdevctl failed to updated mediated devices"); + virMutexUnlock(&priv->mdevctlLock); +} + + +static void +scheduleMdevctlHandler(int timer G_GNUC_UNUSED, void *opaque) +{ + udevEventData *priv =3D opaque; + virThread thread; + + if (priv->mdevctlTimeout > 0) { + virEventRemoveTimeout(priv->mdevctlTimeout); + priv->mdevctlTimeout =3D -1; + } + + if (virThreadCreateFull(&thread, false, mdevctlHandlerThread, + "mdevctl-thread", false, NULL) < 0) { + virReportSystemError(errno, "%s", + _("failed to create mdevctl thread")); + } +} + + +static void +mdevctlEventHandleCallback(GFileMonitor *monitor G_GNUC_UNUSED, + GFile *file, + GFile *other_file G_GNUC_UNUSED, + GFileMonitorEvent event_type, + gpointer user_data); + + +/* Recursively monitors a directory and its subdirectories for file change= s and + * returns a GList of GFileMonitor objects */ +static GList* +monitorFileRecursively(udevEventData *udev, + GFile *file) +{ + GList *monitors =3D NULL; + g_autoptr(GError) error =3D NULL; + g_autoptr(GFileEnumerator) children =3D NULL; + GFileMonitor *mon; + + if (!(children =3D g_file_enumerate_children(file, "standard::*", + G_FILE_QUERY_INFO_NONE, NUL= L, &error))) + goto error; + + if (!(mon =3D g_file_monitor(file, G_FILE_MONITOR_NONE, NULL, &error))) + goto error; + + g_signal_connect(mon, "changed", + G_CALLBACK(mdevctlEventHandleCallback), udev); + + monitors =3D g_list_append(monitors, mon); + + while (true) { + GFileInfo *info =3D NULL; + GFile *child =3D NULL; + GList *child_monitors =3D NULL; + + if (!g_file_enumerator_iterate(children, &info, &child, NULL, &err= or)) + goto error; + + if (!info) + break; + + if (g_file_query_file_type(child, G_FILE_QUERY_INFO_NONE, NULL) = =3D=3D + G_FILE_TYPE_DIRECTORY) { + + child_monitors =3D monitorFileRecursively(udev, child); + if (child_monitors) + monitors =3D g_list_concat(monitors, child_monitors); + } + } + + return monitors; + + error: + g_list_free_full(monitors, g_object_unref); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to monitor directory: %s"), error->message); + g_clear_error(&error); + return NULL; +} + + +static void +mdevctlEventHandleCallback(GFileMonitor *monitor G_GNUC_UNUSED, + GFile *file, + GFile *other_file G_GNUC_UNUSED, + GFileMonitorEvent event_type, + gpointer user_data) +{ + udevEventData *priv =3D user_data; + /* if a new directory appears, monitor that directory for changes */ + if (event_type =3D=3D G_FILE_MONITOR_EVENT_CREATED && + g_file_query_file_type(file, G_FILE_QUERY_INFO_NONE, NULL) =3D=3D + G_FILE_TYPE_DIRECTORY) { + GList *newmonitors =3D monitorFileRecursively(priv, file); + virMutexLock(&priv->mdevctlLock); + priv->mdevctlMonitors =3D g_list_concat(priv->mdevctlMonitors, new= monitors); + virMutexUnlock(&priv->mdevctlLock); + } + + /* When mdevctl creates a device, it can result in multiple notify eve= nts + * emitted for a single logical change (e.g. several CHANGED events, o= r a + * CREATED and CHANGED event followed by CHANGES_DONE_HINT). To avoid + * spawning a mdevctl thread multiple times for a single logical + * configuration change, try to coalesce these changes by waiting for = the + * CHANGES_DONE_HINT event. As a fallback, add a timeout to trigger t= he + * signal if that event never comes */ + if (event_type !=3D G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT) { + if (priv->mdevctlTimeout > 0) + virEventRemoveTimeout(priv->mdevctlTimeout); + priv->mdevctlTimeout =3D virEventAddTimeout(100, scheduleMdevctlHa= ndler, + priv, NULL); + return; + } + + scheduleMdevctlHandler(-1, priv); +} + + static int nodeStateInitialize(bool privileged, const char *root, @@ -2012,6 +2158,7 @@ nodeStateInitialize(bool privileged, { udevEventDataPtr priv =3D NULL; struct udev *udev =3D NULL; + g_autoptr(GFile) mdevctlConfigDir =3D g_file_new_for_path("/etc/mdevct= l.d"); =20 if (root !=3D NULL) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -2113,6 +2260,20 @@ nodeStateInitialize(bool privileged, if (priv->watch =3D=3D -1) goto unlock; =20 + /* mdevctl may add notification events in the future: + * https://github.com/mdevctl/mdevctl/issues/27. For now, fall back to + * monitoring the mdevctl configuration directory for changes. + * mdevctl configuration is stored in a directory tree within + * /etc/mdevctl.d/. There is a directory for each parent device, which + * contains a file defining each mediated device */ + virMutexLock(&priv->mdevctlLock); + if (!(priv->mdevctlMonitors =3D monitorFileRecursively(priv, + mdevctlConfigDir)= )) { + virMutexUnlock(&priv->mdevctlLock); + goto cleanup; + } + virMutexUnlock(&priv->mdevctlLock); + virObjectUnlock(priv); =20 /* Create a fictional 'computer' device to root the device tree. */ --=20 2.26.3 From nobody Wed Apr 24 21:05:09 2024 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=1616777346; cv=none; d=zohomail.com; s=zohoarc; b=iXzkfp/q91OXTMovaAvE09zj7cJbnApYXmaB2pQVb0C4TaukS7L7e1tD7NCxm/ArggSSjGWtthlsYhtcP7UBKbqygrckdy/GY2xdWL2x3lv4hvPxkTCpNy5I7Pb8KOpx3cj1SLwK5M0aOOTh+gd3vhEmuf9awbzSyJn3H1CHzyc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777346; 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=8CnzyJ7B82y/mcEbEbQ2bCdao6m18kuWPtIijECSLeY=; b=MXr1JfuFkooRm5jkA45oKhdNVQ+gTeX378Rubr+IcflAEFHUU3yY70MAqGRZmmj0U2msvXRM7Vqtd5MLEWf1697CO/T7qJ+LS6aeVjojrRgWo9mRIcxn7LQled84zTVkPfvXX4g0BQtImeJt6rQOLFuPXtKKEQVSNWfGsZ508YE= 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 1616777346478817.0380252956667; Fri, 26 Mar 2021 09:49:06 -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-512-uvaukci2P_S6MPOXfQfanw-1; Fri, 26 Mar 2021 12:49:01 -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 9D7FD107B7ED; Fri, 26 Mar 2021 16:48:56 +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 704FB19705; Fri, 26 Mar 2021 16:48:56 +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 EDF6B180213F; Fri, 26 Mar 2021 16:48:55 +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 12QGmcit003013 for ; Fri, 26 Mar 2021 12:48:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id BB4585D755; Fri, 26 Mar 2021 16:48:38 +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 80FEF5D6DC; Fri, 26 Mar 2021 16:48:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777344; 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=8CnzyJ7B82y/mcEbEbQ2bCdao6m18kuWPtIijECSLeY=; b=GYa83hkn9rVXr08zDI67cZV3JmRTOCwXSKOb41EQ2tST106ykl4eguPrFxShHncIv6CBI3 2gSJYx7DS+xQbwqsSUfMhqwN983/A4ViEgoqnEZ4hvq5h0p/zkox5GX2f/A34CMZvej4AW LeNRW7dFnHaHA7lpJ6Sdpa7dSzMHpNE= X-MC-Unique: uvaukci2P_S6MPOXfQfanw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 15/30] nodedev: add function to generate mdevctl define command Date: Fri, 26 Mar 2021 11:48:11 -0500 Message-Id: <20210326164826.1720062-16-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.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" Abstract out the function used to generate the commandline for 'mdevctl start' since they take the same arguments. Add tests to ensure that we're generating the command properly. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- src/node_device/node_device_driver.c | 34 +++++++-- src/node_device/node_device_driver.h | 6 ++ ...19_36ea_4111_8f0a_8c9a70e21366-define.argv | 1 + ...19_36ea_4111_8f0a_8c9a70e21366-define.json | 1 + ...39_495e_4243_ad9f_beb3f14c23d9-define.argv | 1 + ...39_495e_4243_ad9f_beb3f14c23d9-define.json | 1 + ...16_1ca8_49ac_b176_871d16c13076-define.argv | 1 + ...16_1ca8_49ac_b176_871d16c13076-define.json | 1 + tests/nodedevmdevctltest.c | 76 +++++++++++++------ 9 files changed, 95 insertions(+), 27 deletions(-) create mode 100644 tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8= c9a70e21366-define.argv create mode 100644 tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8= c9a70e21366-define.json create mode 100644 tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_b= eb3f14c23d9-define.argv create mode 100644 tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_b= eb3f14c23d9-define.json create mode 100644 tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_8= 71d16c13076-define.argv create mode 100644 tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_8= 71d16c13076-define.json diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 4be650ddef..abd45a6eab 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -698,10 +698,14 @@ nodeDeviceFindAddressByName(const char *name) } =20 =20 -virCommandPtr -nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr def, - char **uuid_out, - char **errmsg) +/* the mdevctl 'start' and 'define' commands accept almost the exact same + * arguments, so provide a common implementation that can be wrapped by a = more + * specific function */ +static virCommand* +nodeDeviceGetMdevctlDefineStartCommand(virNodeDeviceDef *def, + const char *subcommand, + char **uuid_out, + char **errmsg) { virCommandPtr cmd; g_autofree char *json =3D NULL; @@ -719,7 +723,7 @@ nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr de= f, return NULL; } =20 - cmd =3D virCommandNewArgList(MDEVCTL, "start", + cmd =3D virCommandNewArgList(MDEVCTL, subcommand, "-p", parent_addr, "--jsonfile", "/dev/stdin", NULL); @@ -731,6 +735,26 @@ nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr d= ef, return cmd; } =20 +virCommand* +nodeDeviceGetMdevctlStartCommand(virNodeDeviceDef *def, + char **uuid_out, + char **errmsg) +{ + return nodeDeviceGetMdevctlDefineStartCommand(def, "start", uuid_out, + errmsg); +} + +virCommand* +nodeDeviceGetMdevctlDefineCommand(virNodeDeviceDef *def, + char **uuid_out, + char **errmsg) +{ + return nodeDeviceGetMdevctlDefineStartCommand(def, "define", uuid_out, + errmsg); +} + + + static int virMdevctlStart(virNodeDeviceDefPtr def, char **uuid, char **errmsg) { diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index 9b54efe4e3..b319990f0f 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -117,6 +117,12 @@ virCommandPtr nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr def, char **uuid_out, char **errmsg); + +virCommand* +nodeDeviceGetMdevctlDefineCommand(virNodeDeviceDef *def, + char **uuid_out, + char **errmsg); + virCommandPtr nodeDeviceGetMdevctlStopCommand(const char *uuid, char **errmsg); diff --git a/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e2= 1366-define.argv b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c= 9a70e21366-define.argv new file mode 100644 index 0000000000..773e98b963 --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-de= fine.argv @@ -0,0 +1 @@ +$MDEVCTL_BINARY$ define -p 0000:00:02.0 --jsonfile /dev/stdin diff --git a/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e2= 1366-define.json b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c= 9a70e21366-define.json new file mode 100644 index 0000000000..bfc6dcace3 --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-de= fine.json @@ -0,0 +1 @@ +{"mdev_type":"i915-GVTg_V5_8","start":"manual"} \ No newline at end of file diff --git a/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c= 23d9-define.argv b/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_be= b3f14c23d9-define.argv new file mode 100644 index 0000000000..773e98b963 --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-de= fine.argv @@ -0,0 +1 @@ +$MDEVCTL_BINARY$ define -p 0000:00:02.0 --jsonfile /dev/stdin diff --git a/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c= 23d9-define.json b/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_be= b3f14c23d9-define.json new file mode 100644 index 0000000000..e5b22b2c44 --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-de= fine.json @@ -0,0 +1 @@ +{"mdev_type":"i915-GVTg_V5_8","start":"manual","attrs":[{"example-attribut= e-1":"attribute-value-1"},{"example-attribute-2":"attribute-value-2"}]} \ No newline at end of file diff --git a/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c1= 3076-define.argv b/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_87= 1d16c13076-define.argv new file mode 100644 index 0000000000..773e98b963 --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-de= fine.argv @@ -0,0 +1 @@ +$MDEVCTL_BINARY$ define -p 0000:00:02.0 --jsonfile /dev/stdin diff --git a/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c1= 3076-define.json b/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_87= 1d16c13076-define.json new file mode 100644 index 0000000000..2e03d0bd8e --- /dev/null +++ b/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-de= fine.json @@ -0,0 +1 @@ +{"mdev_type":"i915-GVTg_V5_8","start":"manual","attrs":[{"example-attribut= e":"attribute-value"}]} \ No newline at end of file diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 1ab4776a23..99fa328d24 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -10,10 +10,16 @@ =20 #define VIR_FROM_THIS VIR_FROM_NODEDEV =20 +typedef enum { + MDEVCTL_CMD_START, + MDEVCTL_CMD_DEFINE, +} MdevctlCmd; + struct startTestInfo { const char *virt_type; int create; const char *filename; + MdevctlCmd command; }; =20 /* capture stdin passed to command */ @@ -45,12 +51,17 @@ nodedevCompareToFile(const char *actual, return virTestCompareToFile(replacedCmdline, filename); } =20 + +typedef virCommand* (*MdevctlCmdFunc)(virNodeDeviceDef *, char **, char **= ); + + static int -testMdevctlStart(const char *virt_type, - int create, - const char *mdevxml, - const char *startcmdfile, - const char *startjsonfile) +testMdevctlStartOrDefine(const char *virt_type, + int create, + MdevctlCmdFunc mdevctl_cmd_func, + const char *mdevxml, + const char *cmdfile, + const char *jsonfile) { g_autoptr(virNodeDeviceDef) def =3D NULL; virNodeDeviceObjPtr obj =3D NULL; @@ -67,7 +78,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, &errmsg); + cmd =3D mdevctl_cmd_func(def, &uuid, &errmsg); =20 if (!cmd) goto cleanup; @@ -79,10 +90,10 @@ testMdevctlStart(const char *virt_type, if (!(actualCmdline =3D virBufferCurrentContent(&buf))) goto cleanup; =20 - if (nodedevCompareToFile(actualCmdline, startcmdfile) < 0) + if (nodedevCompareToFile(actualCmdline, cmdfile) < 0) goto cleanup; =20 - if (virTestCompareToFile(stdinbuf, startjsonfile) < 0) + if (virTestCompareToFile(stdinbuf, jsonfile) < 0) goto cleanup; =20 ret =3D 0; @@ -94,20 +105,34 @@ testMdevctlStart(const char *virt_type, } =20 static int -testMdevctlStartHelper(const void *data) +testMdevctlStartOrDefineHelper(const void *data) { const struct startTestInfo *info =3D data; + const char *cmd; + MdevctlCmdFunc func; + g_autofree char *mdevxml =3D NULL; + g_autofree char *cmdlinefile =3D NULL; + g_autofree char *jsonfile =3D NULL; + + if (info->command =3D=3D MDEVCTL_CMD_START) { + cmd =3D "start"; + func =3D nodeDeviceGetMdevctlStartCommand; + } else if (info->command =3D=3D MDEVCTL_CMD_DEFINE) { + cmd =3D "define"; + func =3D nodeDeviceGetMdevctlDefineCommand; + } else { + return -1; + } =20 - g_autofree char *mdevxml =3D g_strdup_printf("%s/nodedevschemadata/%s.= xml", - abs_srcdir, info->filename); - g_autofree char *cmdlinefile =3D g_strdup_printf("%s/nodedevmdevctldat= a/%s-start.argv", - abs_srcdir, info->filen= ame); - g_autofree char *jsonfile =3D g_strdup_printf("%s/nodedevmdevctldata/%= s-start.json", - abs_srcdir, info->filen= ame); + mdevxml =3D g_strdup_printf("%s/nodedevschemadata/%s.xml", abs_srcdir, + info->filename); + cmdlinefile =3D g_strdup_printf("%s/nodedevmdevctldata/%s-%s.argv", + abs_srcdir, info->filename, cmd); + jsonfile =3D g_strdup_printf("%s/nodedevmdevctldata/%s-%s.json", abs_s= rcdir, + info->filename, cmd); =20 - return testMdevctlStart(info->virt_type, - info->create, mdevxml, cmdlinefile, - jsonfile); + return testMdevctlStartOrDefine(info->virt_type, info->create, func, + mdevxml, cmdlinefile, jsonfile); } =20 static int @@ -349,15 +374,18 @@ mymain(void) if (virTestRun(desc, func, info) < 0) \ ret =3D -1; =20 -#define DO_TEST_START_FULL(virt_type, create, filename) \ +#define DO_TEST_CMD(desc, virt_type, create, filename, command) \ do { \ - struct startTestInfo info =3D { virt_type, create, filename }; \ - DO_TEST_FULL("mdevctl start " filename, testMdevctlStartHelper, &i= nfo); \ + struct startTestInfo info =3D { virt_type, create, filename, comma= nd }; \ + DO_TEST_FULL(desc, testMdevctlStartOrDefineHelper, &info); \ } \ while (0) =20 #define DO_TEST_START(filename) \ - DO_TEST_START_FULL("QEMU", CREATE_DEVICE, filename) + DO_TEST_CMD("mdevctl start " filename, "QEMU", CREATE_DEVICE, filename= , MDEVCTL_CMD_START) + +#define DO_TEST_DEFINE(filename) \ + DO_TEST_CMD("mdevctl define " filename, "QEMU", CREATE_DEVICE, filenam= e, MDEVCTL_CMD_DEFINE) =20 #define DO_TEST_STOP(uuid) \ DO_TEST_FULL("mdevctl stop " uuid, testMdevctlStop, uuid) @@ -380,6 +408,10 @@ mymain(void) =20 DO_TEST_PARSE_JSON("mdevctl-list-multiple"); =20 + DO_TEST_DEFINE("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); + DO_TEST_DEFINE("mdev_fedc4916_1ca8_49ac_b176_871d16c13076"); + DO_TEST_DEFINE("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9"); + done: nodedevTestDriverFree(driver); =20 --=20 2.26.3 From nobody Wed Apr 24 21:05:09 2024 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=1616777349; cv=none; d=zohomail.com; s=zohoarc; b=EY5+lN0n9SLAJtw3RHKw5eLC8cFDEjxGOi34ICzM10ZoQ+PYbCY8qZI3k9AOZrWsfTquvUdHkGElimm6sC+XX736EUXCjwYp4oHiU1bY3qZDYEUldKs5qPcy8ZRBDQTOpB0fabMwb+mkjaJlXyh7F7hdsp+5HPv7JQBaIbcXvrQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777349; 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=tksBCiu3OMihoD8zlYN0AJQH4AoN97Chj1xIiV+2z7g=; b=XjqVoDVClC4Que31+nKlEF0P5VV764v3FnutNd0cLmaugsc5bI1BhadHrCannQNRc7eTMtMEb12D2MTtB8rKfJAhBoSXmWvH8AF05iTyNaaSNPCzu3eKhWt7n1nv07+oVF2+cv4j55BsmWQpxwNTR9xfGvPFE1eedA4nctY6F9M= 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 1616777349587550.02502941771; Fri, 26 Mar 2021 09:49: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-580-p3to5hMaPaOFf2_DeJElFQ-1; Fri, 26 Mar 2021 12:49:05 -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 C3966107B830; Fri, 26 Mar 2021 16:48:59 +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 9E70089D05; Fri, 26 Mar 2021 16:48:59 +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 35BB84A715; Fri, 26 Mar 2021 16:48:59 +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 12QGmdk0003023 for ; Fri, 26 Mar 2021 12:48:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1F33F5D6DC; Fri, 26 Mar 2021 16:48:39 +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 D5DDB5D755; Fri, 26 Mar 2021 16:48:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777348; 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=tksBCiu3OMihoD8zlYN0AJQH4AoN97Chj1xIiV+2z7g=; b=SB4VWyLJ5afA1LIRXmoHWIo3JjDW3/09ir5ySxclD6EEzt7Jf/Xd3tbRFXU90gRE1OtmwY wbNxtLLS8leI9cOzvseeCXSmKgxZKj5JMA9lIFnp/eBFLI8TeCka0xFhDKzBKjk2tJtWvu aVqYwpJ9LGhfK9pUxLLRy473h1d22+s= X-MC-Unique: p3to5hMaPaOFf2_DeJElFQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 16/30] api: add virNodeDeviceDefineXML() Date: Fri, 26 Mar 2021 11:48:12 -0500 Message-Id: <20210326164826.1720062-17-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.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" With mediated devices, we can now define persistent node devices that can be started and stopped. In order to take advantage of this, we need an API to define new node devices. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- include/libvirt/libvirt-nodedev.h | 4 ++ src/driver-nodedev.h | 6 +++ src/libvirt-nodedev.c | 42 ++++++++++++++++ src/libvirt_public.syms | 1 + src/node_device/node_device_driver.c | 71 ++++++++++++++++++++++++++++ src/node_device/node_device_driver.h | 5 ++ src/node_device/node_device_udev.c | 1 + src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 17 ++++++- src/remote_protocol-structs | 8 ++++ src/rpc/gendispatch.pl | 1 + 11 files changed, 156 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index 77d814935e..33eb46b3cd 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -131,6 +131,10 @@ virNodeDevicePtr virNodeDeviceCreateXML (virCo= nnectPtr conn, =20 int virNodeDeviceDestroy (virNodeDevicePtr dev); =20 +virNodeDevicePtr virNodeDeviceDefineXML(virConnectPtr conn, + const char *xmlDesc, + unsigned int flags); + /** * VIR_NODE_DEVICE_EVENT_CALLBACK: * diff --git a/src/driver-nodedev.h b/src/driver-nodedev.h index d0fc7f19cf..64a0a7c473 100644 --- a/src/driver-nodedev.h +++ b/src/driver-nodedev.h @@ -74,6 +74,11 @@ typedef virNodeDevicePtr typedef int (*virDrvNodeDeviceDestroy)(virNodeDevicePtr dev); =20 +typedef virNodeDevice* +(*virDrvNodeDeviceDefineXML)(virConnect *conn, + const char *xmlDesc, + unsigned int flags); + typedef int (*virDrvConnectNodeDeviceEventRegisterAny)(virConnectPtr conn, virNodeDevicePtr dev, @@ -113,4 +118,5 @@ struct _virNodeDeviceDriver { virDrvNodeDeviceListCaps nodeDeviceListCaps; virDrvNodeDeviceCreateXML nodeDeviceCreateXML; virDrvNodeDeviceDestroy nodeDeviceDestroy; + virDrvNodeDeviceDefineXML nodeDeviceDefineXML; }; diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index fb707b570f..cfc0c9de5b 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -737,6 +737,48 @@ virNodeDeviceDestroy(virNodeDevicePtr dev) } =20 =20 +/** + * virNodeDeviceDefineXML: + * @conn: pointer to the hypervisor connection + * @xmlDesc: string containing an XML description of the device to be defi= ned + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Define a new device on the VM host machine, for example, a mediated dev= ice + * + * virNodeDeviceFree should be used to free the resources after the + * node device object is no longer needed. + * + * Returns a node device object if successful, NULL in case of failure + */ +virNodeDevice* +virNodeDeviceDefineXML(virConnect *conn, + const char *xmlDesc, + unsigned int flags) +{ + VIR_DEBUG("conn=3D%p, xmlDesc=3D%s, flags=3D0x%x", conn, NULLSTR(xmlDe= sc), flags); + + virResetLastError(); + + virCheckConnectReturn(conn, NULL); + virCheckReadOnlyGoto(conn->flags, error); + virCheckNonNullArgGoto(xmlDesc, error); + + if (conn->nodeDeviceDriver && + conn->nodeDeviceDriver->nodeDeviceDefineXML) { + virNodeDevice *dev =3D conn->nodeDeviceDriver->nodeDeviceDefineXML= (conn, xmlDesc, flags); + if (dev =3D=3D NULL) + goto error; + return dev; + } + + virReportUnsupportedError(); + + error: + virDispatchError(conn); + return NULL; +} + + /** * virConnectNodeDeviceEventRegisterAny: * @conn: pointer to the connection diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 51a3d7265a..3d8176351c 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -887,6 +887,7 @@ LIBVIRT_7.1.0 { LIBVIRT_7.2.0 { global: virDomainStartDirtyRateCalc; + virNodeDeviceDefineXML; } LIBVIRT_7.1.0; =20 # .... define new API here using predicted next version number .... diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index abd45a6eab..418faa9fb9 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -776,6 +776,26 @@ virMdevctlStart(virNodeDeviceDefPtr def, char **uuid, = char **errmsg) } =20 =20 +static int +virMdevctlDefine(virNodeDeviceDefPtr def, char **uuid, char **errmsg) +{ + int status; + g_autoptr(virCommand) cmd =3D nodeDeviceGetMdevctlDefineCommand(def, u= uid, 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) + return -1; + + /* remove newline */ + *uuid =3D g_strstrip(*uuid); + + return 0; +} + + static virNodeDevicePtr nodeDeviceCreateXMLMdev(virConnectPtr conn, virNodeDeviceDefPtr def) @@ -1112,6 +1132,57 @@ nodeDeviceDestroy(virNodeDevicePtr device) return ret; } =20 +virNodeDevice* +nodeDeviceDefineXML(virConnect *conn, + const char *xmlDesc, + unsigned int flags) +{ + g_autoptr(virNodeDeviceDef) def =3D NULL; + virNodeDevice *device =3D NULL; + const char *virt_type =3D NULL; + g_autofree char *uuid =3D NULL; + g_autofree char *errmsg =3D NULL; + + virCheckFlags(0, NULL); + + if (nodeDeviceWaitInit() < 0) + return NULL; + + virt_type =3D virConnectGetType(conn); + + if (!(def =3D virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, virt= _type))) + return NULL; + + if (virNodeDeviceDefineXMLEnsureACL(conn, def) < 0) + return NULL; + + if (!nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Unsupported device type")); + return NULL; + } + + if (!def->parent) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("cannot define a mediated device without a parent= ")); + return NULL; + } + + if (virMdevctlDefine(def, &uuid, &errmsg) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to define mediated device: %s"), + errmsg && errmsg[0] ? errmsg : "Unknown Error"); + return NULL; + } + + def->caps->data.mdev.uuid =3D g_strdup(uuid); + mdevGenerateDeviceName(def); + device =3D nodeDeviceFindNewMediatedDevice(conn, uuid); + + return device; +} + + =20 int nodeConnectNodeDeviceEventRegisterAny(virConnectPtr conn, diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index b319990f0f..f626e9ac8a 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -102,6 +102,11 @@ nodeDeviceCreateXML(virConnectPtr conn, int nodeDeviceDestroy(virNodeDevicePtr dev); =20 +virNodeDevice* +nodeDeviceDefineXML(virConnect *conn, + const char *xmlDesc, + unsigned int flags); + int nodeConnectNodeDeviceEventRegisterAny(virConnectPtr conn, virNodeDevicePtr dev, diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 78144b7762..9de658cab5 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2321,6 +2321,7 @@ static virNodeDeviceDriver udevNodeDeviceDriver =3D { .nodeDeviceListCaps =3D nodeDeviceListCaps, /* 0.7.3 */ .nodeDeviceCreateXML =3D nodeDeviceCreateXML, /* 0.7.3 */ .nodeDeviceDestroy =3D nodeDeviceDestroy, /* 0.7.3 */ + .nodeDeviceDefineXML =3D nodeDeviceDefineXML, /* 7.2.0 */ }; =20 =20 diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 62ada08344..15c592b5b5 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8696,6 +8696,7 @@ static virNodeDeviceDriver node_device_driver =3D { .nodeDeviceNumOfCaps =3D remoteNodeDeviceNumOfCaps, /* 0.5.0 */ .nodeDeviceListCaps =3D remoteNodeDeviceListCaps, /* 0.5.0 */ .nodeDeviceCreateXML =3D remoteNodeDeviceCreateXML, /* 0.6.3 */ + .nodeDeviceDefineXML =3D remoteNodeDeviceDefineXML, /* 7.2.0 */ .nodeDeviceDestroy =3D remoteNodeDeviceDestroy /* 0.6.3 */ }; =20 diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 7fdc65f029..a95ed65f12 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -2145,6 +2145,15 @@ struct remote_node_device_destroy_args { remote_nonnull_string name; }; =20 +struct remote_node_device_define_xml_args { + remote_nonnull_string xml_desc; + unsigned int flags; +}; + +struct remote_node_device_define_xml_ret { + remote_nonnull_node_device dev; +}; + =20 /* * Events Register/Deregister: @@ -6745,5 +6754,11 @@ enum remote_procedure { * @generate: both * @acl: domain:read */ - REMOTE_PROC_DOMAIN_START_DIRTY_RATE_CALC =3D 427 + REMOTE_PROC_DOMAIN_START_DIRTY_RATE_CALC =3D 427, + + /** + * @generate: both + * @acl: node_device:write + */ + REMOTE_PROC_NODE_DEVICE_DEFINE_XML =3D 428 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index d13dc81a82..3488659da1 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -1600,6 +1600,13 @@ struct remote_node_device_create_xml_ret { struct remote_node_device_destroy_args { remote_nonnull_string name; }; +struct remote_node_device_define_xml_args { + remote_nonnull_string xml_desc; + u_int flags; +}; +struct remote_node_device_define_xml_ret { + remote_nonnull_node_device dev; +}; struct remote_connect_domain_event_register_ret { int cb_registered; }; @@ -3605,4 +3612,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_AUTHORIZED_SSH_KEYS_SET =3D 425, REMOTE_PROC_DOMAIN_GET_MESSAGES =3D 426, REMOTE_PROC_DOMAIN_START_DIRTY_RATE_CALC =3D 427, + REMOTE_PROC_NODE_DEVICE_DEFINE_XML =3D 428, }; diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index 9dcd8c3e89..9f5bf0e316 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -567,6 +567,7 @@ elsif ($mode eq "server") { if ($argtype =3D~ m/^remote_node_device_/ and !($argtype =3D~ m/^remote_node_device_lookup_by_name_/) and !($argtype =3D~ m/^remote_node_device_create_xml_/) and + !($argtype =3D~ m/^remote_node_device_define_xml_/) and !($argtype =3D~ m/^remote_node_device_lookup_scsi_host_by_= wwn_/)) { $has_node_device =3D 1; push(@vars_list, "virNodeDevicePtr dev =3D NULL"); --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777408; cv=none; d=zohomail.com; s=zohoarc; b=YvRcBRnHhvQWmT4MYfPIfcCdPeAzmHY8DXDNBfd4MA0y6PweThx6dlGp1mYYCCDS4VMRfzp1xyL/MvmAWFFJfnsSkQww0I/HDEk8XaXuQbRenSUeGF1LudqfV6NTYblrrnSsocySQVZLYxPP+F6GLkqZ4eXZKo8KNP83H8iP1s8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777408; 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=YL6Yf2SCY3Cz6zotMmoF/QxCMykZfjTj3vurqqYoWWU=; b=DEZQzjzHDwEx0qtwPiQysbEDmq0eM2n8iwAB4Qb47/ZVgwTW9dTHvmVA9Zl/WKvWeHatMlJycTY2S9gs9SDK1d7LVjZhH1m0XVW4mT1kHFVzIe/N/nO5bzidJ9hOe+20sySCM9PuiV8VHNRfsamAyoTezawKVMxP9KUeJABtl6o= 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) header.from= 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 1616777408535415.4029861826525; Fri, 26 Mar 2021 09:50:08 -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-602-75oZlVZ-Oh2woQwGpsG4QA-1; Fri, 26 Mar 2021 12:49: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 15FD784B9A0; Fri, 26 Mar 2021 16:49:08 +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 E87D85D756; Fri, 26 Mar 2021 16:49: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 AC3FB5003B; Fri, 26 Mar 2021 16:49:07 +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 12QGmd6I003028 for ; Fri, 26 Mar 2021 12:48:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6E8745D72E; Fri, 26 Mar 2021 16:48:39 +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 378195D6DC; Fri, 26 Mar 2021 16:48:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777407; 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=YL6Yf2SCY3Cz6zotMmoF/QxCMykZfjTj3vurqqYoWWU=; b=UiPGFTO6yIzxWLfMzma94zTM9Y5p3db1mQj8x0DGwQZMLooWS9Jp1alRmXFAfAMFcMVWg4 dagHRwWllT9SlJGIsdVl+5GEG5SW9IhP1rx5JzyI2c0UxzKmvQNYHcGvRa6OgciMznxSM2 Jr3SkBM6XH+8gd5DzmHDwFk8mvWcv2k= X-MC-Unique: 75oZlVZ-Oh2woQwGpsG4QA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 17/30] virsh: Add --inactive, --all to nodedev-list Date: Fri, 26 Mar 2021 11:48:13 -0500 Message-Id: <20210326164826.1720062-18-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.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" Now that we can filter active and inactive node devices in virConnectListAllNodeDevices(), add these switches to the virsh command. Eventual output (once everything is hooked up): virsh # nodedev-list --cap mdev mdev_bd2ea955_3402_4252_8c17_7468083a0f26 virsh # nodedev-list --inactive --cap mdev mdev_07d8b8b0_7e04_4c0f_97ed_9214ce12723c mdev_927c040f_ae7d_4a35_966e_286ba6ebbe1c virsh # nodedev-list --all --cap mdev mdev_07d8b8b0_7e04_4c0f_97ed_9214ce12723c mdev_927c040f_ae7d_4a35_966e_286ba6ebbe1c mdev_bd2ea955_3402_4252_8c17_7468083a0f26 Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- tools/virsh-nodedev.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index b9fe9b8be1..7ab5b264fc 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -378,6 +378,14 @@ static const vshCmdOptDef opts_node_list_devices[] =3D= { .completer =3D virshNodeDeviceCapabilityNameCompleter, .help =3D N_("capability names, separated by comma") }, + {.name =3D "inactive", + .type =3D VSH_OT_BOOL, + .help =3D N_("list inactive devices") + }, + {.name =3D "all", + .type =3D VSH_OT_BOOL, + .help =3D N_("list inactive & active devices") + }, {.name =3D NULL} }; =20 @@ -393,18 +401,26 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd= G_GNUC_UNUSED) int ncaps =3D 0; virshNodeDeviceListPtr list =3D NULL; int cap_type =3D -1; + bool inactive =3D vshCommandOptBool(cmd, "inactive"); + bool all =3D vshCommandOptBool(cmd, "all"); =20 ignore_value(vshCommandOptStringQuiet(ctl, cmd, "cap", &cap_str)); =20 if (cap_str) { - if (tree) { - vshError(ctl, "%s", _("Options --tree and --cap are incompatib= le")); - return false; - } if ((ncaps =3D vshStringToArray(cap_str, &caps)) < 0) return false; } =20 + if (all && inactive) { + vshError(ctl, "%s", _("Option --all is incompatible with --inactiv= e")); + return false; + } + + if (tree && (cap_str || inactive || all)) { + vshError(ctl, "%s", _("Option --tree is incompatible with other op= tions")); + return false; + } + for (i =3D 0; i < ncaps; i++) { if ((cap_type =3D virNodeDevCapTypeFromString(caps[i])) < 0) { vshError(ctl, "%s", _("Invalid capability type")); @@ -481,6 +497,11 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd = G_GNUC_UNUSED) } } =20 + if (inactive || all) + flags |=3D VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE; + if (!inactive) + flags |=3D VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE; + if (!(list =3D virshNodeDeviceListCollect(ctl, caps, ncaps, flags))) { ret =3D false; goto cleanup; --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777342; cv=none; d=zohomail.com; s=zohoarc; b=FTkZA4YEGaHZodVLDf0ofPMunzXuYHYdhJBa0Bx1GwKlNLF9mbbzEWeBQW5s2kIFblE+cPgxC3CI4kj3f8bQH3btWdhyM37eTfvnNk+miSJYq0+mGjLPjL4r8THVF3A0yGotn4Q78Rx3guSejC44ZiauyKDobJSLFfukU1h97LY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777342; 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=yfGLAM/L98gEsJYvSo5Zw+FQ4vaAi79fEs7+DpzHF88=; b=d/kvQNj2ECHVH9A5EzUkA30OP+ryQw+VEpyEt3RlvKyqQCSv78vqXVcDKK9IRfHyaMDXv5HZ7x5R6HnJTnpBAC0uRaaxA7vPXT0RQeeubJexWNhK3PJ8Yb2Wz2s/0PuXsTkE4sdFkcE+Ndfi5r6458nsxO38aBN4XFvoAmtMP70= 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) header.from= 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 161677734295297.75136274162787; Fri, 26 Mar 2021 09:49:02 -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-565-VC_J0llEPMGJFv_vcesCQg-1; Fri, 26 Mar 2021 12:48:59 -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 BE1E9814339; Fri, 26 Mar 2021 16:48:52 +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 9AD5C5D756; Fri, 26 Mar 2021 16:48:52 +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 59F0C4A707; Fri, 26 Mar 2021 16:48:52 +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 12QGmd18003041 for ; Fri, 26 Mar 2021 12:48:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id C50A05D72E; Fri, 26 Mar 2021 16:48:39 +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 8D4365D6DC; Fri, 26 Mar 2021 16:48:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777342; 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=yfGLAM/L98gEsJYvSo5Zw+FQ4vaAi79fEs7+DpzHF88=; b=Q/b61h4Ug481diDh4uP1D2pVB7hCjcRM5PohFOkTQRcje1V0QlPmoE20HFF8yBOGhfq0fK TGwBBO9cfRHT3mvigBvDZiYbCKiyUBcCIe/ODU4Ue5/6qB2AeFmpJsDnVwcDP8YPXmILb4 DeWrjTYK0Ll+XHNZi2+u105a3gVl5zE= X-MC-Unique: VC_J0llEPMGJFv_vcesCQg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 18/30] virsh: add nodedev-define command Date: Fri, 26 Mar 2021 11:48:14 -0500 Message-Id: <20210326164826.1720062-19-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.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" Add a virsh command that maps to virNodeDeviceDefineXML(). Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- tools/virsh-nodedev.c | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 7ab5b264fc..1cbf2e082b 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -1013,6 +1013,58 @@ cmdNodeDeviceEvent(vshControl *ctl, const vshCmd *cm= d) } =20 =20 +/* + * "nodedev-define" command + */ +static const vshCmdInfo info_node_device_define[] =3D { + {.name =3D "help", + .data =3D N_("Define a device by an xml file on a node") + }, + {.name =3D "desc", + .data =3D N_("Defines a persistent device on the node that can be " + "assigned to a domain. The device must be started before " + "it can be assigned to a domain.") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_node_device_define[] =3D { + VIRSH_COMMON_OPT_FILE(N_("file containing an XML description " + "of the device")), + {.name =3D NULL} +}; + +static bool +cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) +{ + virNodeDevice *dev =3D NULL; + const char *from =3D NULL; + bool ret =3D true; + char *buffer; + virshControl *priv =3D ctl->privData; + + if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) + return false; + + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) + return false; + + dev =3D virNodeDeviceDefineXML(priv->conn, buffer, 0); + VIR_FREE(buffer); + + if (dev !=3D NULL) { + vshPrintExtra(ctl, _("Node device '%s' defined from '%s'\n"), + virNodeDeviceGetName(dev), from); + virNodeDeviceFree(dev); + } else { + vshError(ctl, _("Failed to define node device from '%s'"), from); + ret =3D false; + } + + return ret; +} + + const vshCmdDef nodedevCmds[] =3D { {.name =3D "nodedev-create", .handler =3D cmdNodeDeviceCreate, @@ -1066,5 +1118,11 @@ const vshCmdDef nodedevCmds[] =3D { .info =3D info_node_device_event, .flags =3D 0 }, + {.name =3D "nodedev-define", + .handler =3D cmdNodeDeviceDefine, + .opts =3D opts_node_device_define, + .info =3D info_node_device_define, + .flags =3D 0 + }, {.name =3D NULL} }; --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777348; cv=none; d=zohomail.com; s=zohoarc; b=htPLPECNxc8MJOorH017uIov6IAj9woaA28KHFllaUosGMSuYygPIbXb30QQAxv1+b/5v6Pl0omitJg5Y4PURyqH4/ZZ5BAcFbU8sC1FItYit33up24kpjoYyO1YySYNayqvlAZxVmWfstNQ4wmYUpxictfsK+noQp+4k+zoFY4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777348; 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=iuYGfVEpj0uyorSHSrJ9eR24uad4qjgzsT1ai+xWt1Y=; b=J9LuxpRH6qzM9c9Pm88jGQwNNJ938hSZL9ZuUt73sosNjkCQhPFQb71Uy9qF9oZxUF7Kky9hufu+ExS39yMbYX79OiMJ2Jyt4Y9rqXiUSvvlWdxEcjMtZM88NHwnM5/MNmRd4AvuIRa4rDHADDLCm7+HcncqoobWy3JbPx2MZac= 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) header.from= 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 1616777348032357.07804319905813; Fri, 26 Mar 2021 09:49:08 -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-583-RaZtZtn9O4CK2Lr0kf0BzQ-1; Fri, 26 Mar 2021 12:49:03 -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 0F36B107ACCD; Fri, 26 Mar 2021 16:48:56 +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 D624419705; Fri, 26 Mar 2021 16:48:55 +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 96F944A711; Fri, 26 Mar 2021 16:48:55 +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 12QGmeLm003048 for ; Fri, 26 Mar 2021 12:48:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 286685D72E; Fri, 26 Mar 2021 16:48:40 +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 E476E5D6DC; Fri, 26 Mar 2021 16:48:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777346; 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=iuYGfVEpj0uyorSHSrJ9eR24uad4qjgzsT1ai+xWt1Y=; b=cNJ7UOuWQJC2OSqokQFXtPnd5bkfCcy/QMEuPFarCl39Z4HkRbqd+7XHatYtf7OsmMPjGK AlDGzL9Ujev+YuuJLfD4elT6NDs2UkrPB3Up61TDw7DVy/C2dL25QOFnnK8Zj0cJcGg++r tJFUKwNIB03dK3D77a3ElubN/0xqOpE= X-MC-Unique: RaZtZtn9O4CK2Lr0kf0BzQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 19/30] nodedev: refactor tests to support mdev undefine Date: Fri, 26 Mar 2021 11:48:15 -0500 Message-Id: <20210326164826.1720062-20-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.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" mdevctl 'stop' and 'undefine' commands take the same uuid parameter, so refactor the test infrastructure to share common implementation for both of these commands. The 'undefine' command will be introduced in a following patch. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- tests/nodedevmdevctltest.c | 48 +++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 99fa328d24..7cf9fa7c67 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -12,7 +12,9 @@ =20 typedef enum { MDEVCTL_CMD_START, + MDEVCTL_CMD_STOP, MDEVCTL_CMD_DEFINE, + MDEVCTL_CMD_UNDEFINE } MdevctlCmd; =20 struct startTestInfo { @@ -135,20 +137,22 @@ testMdevctlStartOrDefineHelper(const void *data) mdevxml, cmdlinefile, jsonfile); } =20 +typedef virCommand* (*GetStopUndefineCmdFunc)(const char *uuid, char **err= buf); +struct UuidCommandTestInfo { + const char *uuid; + MdevctlCmd command; +}; + static int -testMdevctlStop(const void *data) +testMdevctlUuidCommand(const char *uuid, GetStopUndefineCmdFunc func, cons= t char *outfile) { - const char *uuid =3D data; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; 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, &errmsg); + cmd =3D func(uuid, &errmsg); =20 if (!cmd) goto cleanup; @@ -160,7 +164,7 @@ testMdevctlStop(const void *data) if (!(actualCmdline =3D virBufferCurrentContent(&buf))) goto cleanup; =20 - if (nodedevCompareToFile(actualCmdline, cmdlinefile) < 0) + if (nodedevCompareToFile(actualCmdline, outfile) < 0) goto cleanup; =20 ret =3D 0; @@ -170,6 +174,27 @@ testMdevctlStop(const void *data) return ret; } =20 +static int +testMdevctlUuidCommandHelper(const void *data) +{ + const struct UuidCommandTestInfo *info =3D data; + GetStopUndefineCmdFunc func; + const char *cmd; + g_autofree char *cmdlinefile =3D NULL; + + if (info->command =3D=3D MDEVCTL_CMD_STOP) { + cmd =3D "stop"; + func =3D nodeDeviceGetMdevctlStopCommand; + } else { + return -1; + } + + cmdlinefile =3D g_strdup_printf("%s/nodedevmdevctldata/mdevctl-%s.argv= ", + abs_srcdir, cmd); + + return testMdevctlUuidCommand(info->uuid, func, cmdlinefile); +} + static int testMdevctlListDefined(const void *data G_GNUC_UNUSED) { @@ -387,8 +412,15 @@ mymain(void) #define DO_TEST_DEFINE(filename) \ DO_TEST_CMD("mdevctl define " filename, "QEMU", CREATE_DEVICE, filenam= e, MDEVCTL_CMD_DEFINE) =20 +#define DO_TEST_UUID_COMMAND_FULL(desc, uuid, command) \ + do { \ + struct UuidCommandTestInfo info =3D { uuid, command }; \ + DO_TEST_FULL(desc, testMdevctlUuidCommandHelper, &info); \ + } \ + while (0) + #define DO_TEST_STOP(uuid) \ - DO_TEST_FULL("mdevctl stop " uuid, testMdevctlStop, uuid) + DO_TEST_UUID_COMMAND_FULL("mdevctl stop " uuid, uuid, MDEVCTL_CMD_STOP) =20 #define DO_TEST_LIST_DEFINED() \ DO_TEST_FULL("mdevctl list --defined", testMdevctlListDefined, NULL) --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777351; cv=none; d=zohomail.com; s=zohoarc; b=FrKIugFcaZQd8jCQK64ejGSrdfbh9eyZz8AErLquR14p/zQPuzZUhhmzXBnK6jp5ZPZmM2g15Qm2/Zqj0/eBFrewu8Sg8QQcHDWEQd7eRBSsejgX7wvc+Bi6y8uYmcd3cRit9KrZyzUOsVu3X1NfiFAK/r/8FWzt3zXwf0cSyGU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777351; 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=OE72jQCxr/CIJtheekriXdSlBUJpZgnwAA2Esn+/RJE=; b=HQfn6YE8pKMOhLi8D/vlViz5LmsuoSueASESRfF6LPVa+Ihgbw6DM7BOeEVXGTkJynaixbdSF1kyqTng0/WYf9Hw18fxB3emTOZd0qdkaz5A7oVs5GqDtcMKFRm620jzwuwcmJul3fBotDKiiRMBxMs8Is+i+9Ico3HC+NaQANE= 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) header.from= 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 1616777351658875.2761324323573; Fri, 26 Mar 2021 09:49:11 -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-170-2pkUdvyeM3ajJv4TzDCshw-1; Fri, 26 Mar 2021 12:49:08 -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 046E5107B83B; Fri, 26 Mar 2021 16:49:03 +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 CD691100763D; Fri, 26 Mar 2021 16:49:02 +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 807BF180C5A5; Fri, 26 Mar 2021 16:49:02 +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 12QGmeol003057 for ; Fri, 26 Mar 2021 12:48:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7EB7B5D72E; Fri, 26 Mar 2021 16:48:40 +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 461A25D6DC; Fri, 26 Mar 2021 16:48:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777350; 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=OE72jQCxr/CIJtheekriXdSlBUJpZgnwAA2Esn+/RJE=; b=cMojf9JTu60TZXEXZH91QJHSynE19VhyjWjmCB8S8eG+qsO1WT+aKXMNuxq5J+T2VY6Ztl cUPX8Zmi+uSRfKA280qsyJaVTk9l7v+9n+WEPcFE3iBG+vavHsoF7axbAfBkxrzs6yw2An ykCLvv0bQYP+8W7l/dPYRTh3fcy5zNc= X-MC-Unique: 2pkUdvyeM3ajJv4TzDCshw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 20/30] api: add virNodeDeviceUndefine() Date: Fri, 26 Mar 2021 11:48:16 -0500 Message-Id: <20210326164826.1720062-21-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.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" This interface allows you to undefine a persistently defined (but inactive) mediated devices. It is implemented via 'mdevctl' Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- include/libvirt/libvirt-nodedev.h | 2 + src/access/viraccessperm.c | 2 +- src/access/viraccessperm.h | 6 ++ src/driver-nodedev.h | 4 + src/libvirt-nodedev.c | 36 +++++++++ src/libvirt_public.syms | 1 + src/node_device/node_device_driver.c | 73 +++++++++++++++++++ src/node_device/node_device_driver.h | 7 ++ src/node_device/node_device_udev.c | 1 + src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 14 +++- src/remote_protocol-structs | 4 + .../nodedevmdevctldata/mdevctl-undefine.argv | 1 + tests/nodedevmdevctltest.c | 8 ++ 14 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 tests/nodedevmdevctldata/mdevctl-undefine.argv diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index 33eb46b3cd..623017f1fd 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -135,6 +135,8 @@ virNodeDevicePtr virNodeDeviceDefineXML(virConnectPtr c= onn, const char *xmlDesc, unsigned int flags); =20 +int virNodeDeviceUndefine(virNodeDevicePtr dev); + /** * VIR_NODE_DEVICE_EVENT_CALLBACK: * diff --git a/src/access/viraccessperm.c b/src/access/viraccessperm.c index 33db7752b6..d4a0c98b9b 100644 --- a/src/access/viraccessperm.c +++ b/src/access/viraccessperm.c @@ -70,7 +70,7 @@ VIR_ENUM_IMPL(virAccessPermNodeDevice, VIR_ACCESS_PERM_NODE_DEVICE_LAST, "getattr", "read", "write", "start", "stop", - "detach", + "detach", "delete", ); =20 VIR_ENUM_IMPL(virAccessPermNWFilter, diff --git a/src/access/viraccessperm.h b/src/access/viraccessperm.h index 42996b9741..051246a7b6 100644 --- a/src/access/viraccessperm.h +++ b/src/access/viraccessperm.h @@ -500,6 +500,12 @@ typedef enum { */ VIR_ACCESS_PERM_NODE_DEVICE_DETACH, =20 + /** + * @desc: Delete node device + * @message: Deleting node device driver requires authorization + */ + VIR_ACCESS_PERM_NODE_DEVICE_DELETE, + VIR_ACCESS_PERM_NODE_DEVICE_LAST } virAccessPermNodeDevice; =20 diff --git a/src/driver-nodedev.h b/src/driver-nodedev.h index 64a0a7c473..c352462dda 100644 --- a/src/driver-nodedev.h +++ b/src/driver-nodedev.h @@ -79,6 +79,9 @@ typedef virNodeDevice* const char *xmlDesc, unsigned int flags); =20 +typedef int +(*virDrvNodeDeviceUndefine)(virNodeDevice *dev); + typedef int (*virDrvConnectNodeDeviceEventRegisterAny)(virConnectPtr conn, virNodeDevicePtr dev, @@ -119,4 +122,5 @@ struct _virNodeDeviceDriver { virDrvNodeDeviceCreateXML nodeDeviceCreateXML; virDrvNodeDeviceDestroy nodeDeviceDestroy; virDrvNodeDeviceDefineXML nodeDeviceDefineXML; + virDrvNodeDeviceUndefine nodeDeviceUndefine; }; diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index cfc0c9de5b..1d397c6610 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -779,6 +779,42 @@ virNodeDeviceDefineXML(virConnect *conn, } =20 =20 +/** + * virNodeDeviceUndefine: + * @dev: a device object + * + * Undefine the device object. The virtual device is removed from the host + * operating system. This function may require privileged access. + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virNodeDeviceUndefine(virNodeDevice *dev) +{ + VIR_DEBUG("dev=3D%p", dev); + + virResetLastError(); + + virCheckNodeDeviceReturn(dev, -1); + virCheckReadOnlyGoto(dev->conn->flags, error); + + if (dev->conn->nodeDeviceDriver && + dev->conn->nodeDeviceDriver->nodeDeviceUndefine) { + int retval =3D dev->conn->nodeDeviceDriver->nodeDeviceUndefine(dev= ); + if (retval < 0) + goto error; + + return 0; + } + + virReportUnsupportedError(); + + error: + virDispatchError(dev->conn); + return -1; +} + + /** * virConnectNodeDeviceEventRegisterAny: * @conn: pointer to the connection diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 3d8176351c..99b46587b9 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -888,6 +888,7 @@ LIBVIRT_7.2.0 { global: virDomainStartDirtyRateCalc; virNodeDeviceDefineXML; + virNodeDeviceUndefine; } LIBVIRT_7.1.0; =20 # .... define new API here using predicted next version number .... diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 418faa9fb9..48b4b1f438 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -889,6 +889,18 @@ nodeDeviceGetMdevctlStopCommand(const char *uuid, char= **errmsg) =20 } =20 +virCommand* +nodeDeviceGetMdevctlUndefineCommand(const char *uuid, char **errmsg) +{ + virCommand *cmd =3D virCommandNewArgList(MDEVCTL, + "undefine", + "-u", + uuid, + NULL); + virCommandSetErrorBuffer(cmd, errmsg); + return cmd; +} + static int virMdevctlStop(virNodeDeviceDefPtr def, char **errmsg) { @@ -904,6 +916,22 @@ virMdevctlStop(virNodeDeviceDefPtr def, char **errmsg) } =20 =20 +static int +virMdevctlUndefine(virNodeDeviceDef *def, char **errmsg) +{ + int status; + g_autoptr(virCommand) cmd =3D NULL; + + cmd =3D nodeDeviceGetMdevctlUndefineCommand(def->caps->data.mdev.uuid, + errmsg); + + if (virCommandRun(cmd, &status) < 0 || status !=3D 0) + return -1; + + return 0; +} + + virCommand* nodeDeviceGetMdevctlListCommand(bool defined, char **output) @@ -1183,6 +1211,51 @@ nodeDeviceDefineXML(virConnect *conn, } =20 =20 +int +nodeDeviceUndefine(virNodeDevice *device) +{ + int ret =3D -1; + virNodeDeviceObj *obj =3D NULL; + virNodeDeviceDef *def; + + if (nodeDeviceWaitInit() < 0) + return -1; + + if (!(obj =3D nodeDeviceObjFindByName(device->name))) + return -1; + + def =3D virNodeDeviceObjGetDef(obj); + + if (virNodeDeviceUndefineEnsureACL(device->conn, def) < 0) + goto cleanup; + + if (!virNodeDeviceObjIsPersistent(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("Node device '%s' is not defined"), + def->name); + goto cleanup; + } + + 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"), + errmsg && errmsg[0] ? errmsg : "Unknown Error"); + goto cleanup; + } + ret =3D 0; + } else { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Unsupported device type")); + } + + cleanup: + virNodeDeviceObjEndAPI(&obj); + return ret; +} + =20 int nodeConnectNodeDeviceEventRegisterAny(virConnectPtr conn, diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index f626e9ac8a..92bb72ee5d 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -107,6 +107,9 @@ nodeDeviceDefineXML(virConnect *conn, const char *xmlDesc, unsigned int flags); =20 +int +nodeDeviceUndefine(virNodeDevice *dev); + int nodeConnectNodeDeviceEventRegisterAny(virConnectPtr conn, virNodeDevicePtr dev, @@ -132,6 +135,10 @@ virCommandPtr nodeDeviceGetMdevctlStopCommand(const char *uuid, char **errmsg); =20 +virCommand* +nodeDeviceGetMdevctlUndefineCommand(const char *uuid, + char **errmsg); + virCommandPtr nodeDeviceGetMdevctlListCommand(bool defined, char **output); =20 diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 9de658cab5..b870446c55 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2322,6 +2322,7 @@ static virNodeDeviceDriver udevNodeDeviceDriver =3D { .nodeDeviceCreateXML =3D nodeDeviceCreateXML, /* 0.7.3 */ .nodeDeviceDestroy =3D nodeDeviceDestroy, /* 0.7.3 */ .nodeDeviceDefineXML =3D nodeDeviceDefineXML, /* 7.2.0 */ + .nodeDeviceUndefine =3D nodeDeviceUndefine, /* 7.2.0 */ }; =20 =20 diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 15c592b5b5..d3e21ea797 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8697,6 +8697,7 @@ static virNodeDeviceDriver node_device_driver =3D { .nodeDeviceListCaps =3D remoteNodeDeviceListCaps, /* 0.5.0 */ .nodeDeviceCreateXML =3D remoteNodeDeviceCreateXML, /* 0.6.3 */ .nodeDeviceDefineXML =3D remoteNodeDeviceDefineXML, /* 7.2.0 */ + .nodeDeviceUndefine =3D remoteNodeDeviceUndefine, /* 7.2.0 */ .nodeDeviceDestroy =3D remoteNodeDeviceDestroy /* 0.6.3 */ }; =20 diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index a95ed65f12..10d4233d69 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -2154,6 +2154,10 @@ struct remote_node_device_define_xml_ret { remote_nonnull_node_device dev; }; =20 +struct remote_node_device_undefine_args { + remote_nonnull_string name; +}; + =20 /* * Events Register/Deregister: @@ -6760,5 +6764,13 @@ enum remote_procedure { * @generate: both * @acl: node_device:write */ - REMOTE_PROC_NODE_DEVICE_DEFINE_XML =3D 428 + REMOTE_PROC_NODE_DEVICE_DEFINE_XML =3D 428, + + /** + * @generate: both + * @priority: high + * @acl: node_device:delete + */ + REMOTE_PROC_NODE_DEVICE_UNDEFINE =3D 429 + }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 3488659da1..792e858770 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -1607,6 +1607,9 @@ struct remote_node_device_define_xml_args { struct remote_node_device_define_xml_ret { remote_nonnull_node_device dev; }; +struct remote_node_device_undefine_args { + remote_nonnull_string name; +}; struct remote_connect_domain_event_register_ret { int cb_registered; }; @@ -3613,4 +3616,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_GET_MESSAGES =3D 426, REMOTE_PROC_DOMAIN_START_DIRTY_RATE_CALC =3D 427, REMOTE_PROC_NODE_DEVICE_DEFINE_XML =3D 428, + REMOTE_PROC_NODE_DEVICE_UNDEFINE =3D 429, }; diff --git a/tests/nodedevmdevctldata/mdevctl-undefine.argv b/tests/nodedev= mdevctldata/mdevctl-undefine.argv new file mode 100644 index 0000000000..54717455f7 --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-undefine.argv @@ -0,0 +1 @@ +$MDEVCTL_BINARY$ undefine -u d76a6b78-45ed-4149-a325-005f9abc5281 diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 7cf9fa7c67..e471e2e6eb 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -185,6 +185,9 @@ testMdevctlUuidCommandHelper(const void *data) if (info->command =3D=3D MDEVCTL_CMD_STOP) { cmd =3D "stop"; func =3D nodeDeviceGetMdevctlStopCommand; + } else if (info->command =3D=3D MDEVCTL_CMD_UNDEFINE) { + cmd =3D "undefine"; + func =3D nodeDeviceGetMdevctlUndefineCommand; } else { return -1; } @@ -422,6 +425,9 @@ mymain(void) #define DO_TEST_STOP(uuid) \ DO_TEST_UUID_COMMAND_FULL("mdevctl stop " uuid, uuid, MDEVCTL_CMD_STOP) =20 +#define DO_TEST_UNDEFINE(uuid) \ + DO_TEST_UUID_COMMAND_FULL("mdevctl undefine " uuid, uuid, MDEVCTL_CMD_= UNDEFINE) + #define DO_TEST_LIST_DEFINED() \ DO_TEST_FULL("mdevctl list --defined", testMdevctlListDefined, NULL) =20 @@ -444,6 +450,8 @@ mymain(void) DO_TEST_DEFINE("mdev_fedc4916_1ca8_49ac_b176_871d16c13076"); DO_TEST_DEFINE("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9"); =20 + DO_TEST_UNDEFINE("d76a6b78-45ed-4149-a325-005f9abc5281"); + done: nodedevTestDriverFree(driver); =20 --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777409; cv=none; d=zohomail.com; s=zohoarc; b=ny9nHp1HZDtfmMpB+BSFKJKIby4YdNUfPJTn/SShKFLynEbJT2wh/Xz/Ij7UymHO0LMcpZEi5L5RwYiShILsOp/dvvZUJD+rn2PAr9pFuUOansN/6vd1Y39QlsgqZ5HMQ14PGTHVZH2x5iV1HBaoTXtiT1vJ/I3fKrGAE47SQ7g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777409; 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=V/2slfBZjKB5JjNmiC38naYHtKeyPOPL2P0fLTeOtcc=; b=IuWo3k1vGyLQX/okQiA24yltn10cNq53bG++5xqa3EdZ1ssRZwT22GlaMZd1laNdiqOi+ga0HoFpaob1edW8eQnY9rQZmUA/MWLCb9LAS0KIvgor8jjnbnCazvJNbIrFvgm77Jl6Utxm1MhcapTN0AAnaJZOCdzz3Vmzb6sw7Go= 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) header.from= 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 1616777409946610.080440081714; Fri, 26 Mar 2021 09:50: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-265-xQ7E9KEDMXy7AuG7PRfRzg-1; Fri, 26 Mar 2021 12:49:07 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 371E91853021; Fri, 26 Mar 2021 16:48:59 +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 1174D6A044; Fri, 26 Mar 2021 16:48:59 +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 C74DB4A714; Fri, 26 Mar 2021 16:48:58 +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 12QGmeqv003064 for ; Fri, 26 Mar 2021 12:48:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id D1F075D72E; Fri, 26 Mar 2021 16:48:40 +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 9AA945D6DC; Fri, 26 Mar 2021 16:48:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777408; 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=V/2slfBZjKB5JjNmiC38naYHtKeyPOPL2P0fLTeOtcc=; b=TvuAVLcyOT2RzzMAGTdivzJDd1hq/cnUh6W/c7+Gle2oF0QkQUuY7O1J3XXJEnpG2pta7O N2KL8tUYjRKZ7LHtygSD4n5W+ya/C0jgmYyCsLpiCy9S2HreqIurby3Gx6PSAUxgsszo/u KX5eK0mq+OywxH0ZzrQuPqwSuheHwxQ= X-MC-Unique: xQ7E9KEDMXy7AuG7PRfRzg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 21/30] virsh: Factor out function to find node device Date: Fri, 26 Mar 2021 11:48:17 -0500 Message-Id: <20210326164826.1720062-22-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.13 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" Several functions accept providing a node device by name or by wwnn,wwpn pair. Extract the logic to do this into a function that can be used by both callers. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- tools/virsh-nodedev.c | 62 +++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 1cbf2e082b..5589a5862d 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -111,23 +111,18 @@ static const vshCmdOptDef opts_node_device_destroy[] = =3D { {.name =3D NULL} }; =20 -static bool -cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd) +static virNodeDevice* +vshFindNodeDevice(vshControl *ctl, const char *value) { virNodeDevicePtr dev =3D NULL; - bool ret =3D false; - const char *device_value =3D NULL; char **arr =3D NULL; int narr; virshControlPtr priv =3D ctl->privData; =20 - if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0) - return false; - - if (strchr(device_value, ',')) { - narr =3D vshStringToArray(device_value, &arr); + if (strchr(value, ',')) { + narr =3D vshStringToArray(value, &arr); if (narr !=3D 2) { - vshError(ctl, _("Malformed device value '%s'"), device_value); + vshError(ctl, _("Malformed device value '%s'"), value); goto cleanup; } =20 @@ -136,14 +131,33 @@ cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *c= md) =20 dev =3D virNodeDeviceLookupSCSIHostByWWN(priv->conn, arr[0], arr[1= ], 0); } else { - dev =3D virNodeDeviceLookupByName(priv->conn, device_value); + dev =3D virNodeDeviceLookupByName(priv->conn, value); } =20 if (!dev) { - vshError(ctl, "%s '%s'", _("Could not find matching device"), devi= ce_value); + vshError(ctl, "%s '%s'", _("Could not find matching device"), valu= e); goto cleanup; } =20 + cleanup: + g_strfreev(arr); + return dev; +} + +static bool +cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd) +{ + virNodeDevice *dev =3D NULL; + bool ret =3D false; + const char *device_value =3D NULL; + + if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0) + return false; + + dev =3D vshFindNodeDevice(ctl, device_value); + if (!dev) + goto cleanup; + if (virNodeDeviceDestroy(dev) =3D=3D 0) { vshPrintExtra(ctl, _("Destroyed node device '%s'\n"), device_value= ); } else { @@ -153,7 +167,6 @@ cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd) =20 ret =3D true; cleanup: - g_strfreev(arr); if (dev) virNodeDeviceFree(dev); return ret; @@ -578,33 +591,15 @@ cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *c= md) virNodeDevicePtr device =3D NULL; char *xml =3D NULL; const char *device_value =3D NULL; - char **arr =3D NULL; - int narr; bool ret =3D false; - virshControlPtr priv =3D ctl->privData; =20 if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0) return false; =20 - if (strchr(device_value, ',')) { - narr =3D vshStringToArray(device_value, &arr); - if (narr !=3D 2) { - vshError(ctl, _("Malformed device value '%s'"), device_value); - goto cleanup; - } + device =3D vshFindNodeDevice(ctl, device_value); =20 - if (!virValidateWWN(arr[0]) || !virValidateWWN(arr[1])) - goto cleanup; - - device =3D virNodeDeviceLookupSCSIHostByWWN(priv->conn, arr[0], ar= r[1], 0); - } else { - device =3D virNodeDeviceLookupByName(priv->conn, device_value); - } - - if (!device) { - vshError(ctl, "%s '%s'", _("Could not find matching device"), devi= ce_value); + if (!device) goto cleanup; - } =20 if (!(xml =3D virNodeDeviceGetXMLDesc(device, 0))) goto cleanup; @@ -613,7 +608,6 @@ cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd) =20 ret =3D true; cleanup: - g_strfreev(arr); VIR_FREE(xml); if (device) virNodeDeviceFree(device); --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777353; cv=none; d=zohomail.com; s=zohoarc; b=NOa865S61MsITt49vAiE6ZGQD7IudY9AuLBvW0OJwBFFXbD1yW7bN0ImKD2cTgLRG7HrA2UwulxlvdQ8rN0mLZ2PlU4rljk/KjEvDJsvPAGwwXl9NwTQ49Fc8pfkaV82QGMjILK/pjqbN8M4E0mAHur+6yOn2FIyUwXQBiBoo1g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777353; 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=9tVlKLLquiyn4u3EXUt+aME4U2rd7IiFkk3bseyO/So=; b=bwnvTv+HJf0RGsFC9TUC2edZA5P07cV0GI4aLRaRggbneR0ERtsoZUI394z8UlYLON7WKRNLN+ok24XrjAGrYA3dWqiXVf3AjHMf+5jzTURpgagwk+IutA/d9NU/6vqx+YJK6gx8RKxqFbVIo6la8pJkIMUam1A3pJ15dJGkahQ= 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) header.from= 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 161677735301191.30965578673943; Fri, 26 Mar 2021 09:49: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-361-AX1FJU48P-y4W9-vmEZ0-g-1; Fri, 26 Mar 2021 12:49:09 -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 7FD56107B832; Fri, 26 Mar 2021 16:49:02 +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 594496A857; Fri, 26 Mar 2021 16:49:02 +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 191361800232; Fri, 26 Mar 2021 16:49:02 +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 12QGmfbd003070 for ; Fri, 26 Mar 2021 12:48:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 33E605D72E; Fri, 26 Mar 2021 16:48:41 +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 EEF005D6DC; Fri, 26 Mar 2021 16:48:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777352; 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=9tVlKLLquiyn4u3EXUt+aME4U2rd7IiFkk3bseyO/So=; b=h7VcW+a4Rj6IMcbtWgTBS4WEkzcxaqFpV0RPgHzsTpzABdirWueLvBCVYVea2rJnUWPx0K TpuqXNUamljPO+VBrcPFZHXzW9+t4r+IWB1Gd1Wm6/yHmB7bmytT2GUc+4WXYkC6ZRnRfu 7u9UMfx8yIuRbmiYOSAcPIedTanGUcs= X-MC-Unique: AX1FJU48P-y4W9-vmEZ0-g-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 22/30] virsh: add nodedev-undefine command Date: Fri, 26 Mar 2021 11:48:18 -0500 Message-Id: <20210326164826.1720062-23-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.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" Add a virsh command that maps to virNodeDeviceUndefine(). Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- tools/virsh-nodedev.c | 59 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 5589a5862d..d5b82ba285 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -1007,6 +1007,59 @@ cmdNodeDeviceEvent(vshControl *ctl, const vshCmd *cm= d) } =20 =20 +/* + * "nodedev-undefine" command + */ +static const vshCmdInfo info_node_device_undefine[] =3D { + {.name =3D "help", + .data =3D N_("Undefine an inactive node device") + }, + {.name =3D "desc", + .data =3D N_("Undefines the configuration for an inactive node device= ") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_node_device_undefine[] =3D { + {.name =3D "device", + .type =3D VSH_OT_DATA, + .flags =3D VSH_OFLAG_REQ, + .help =3D N_("device name or wwn pair in 'wwnn,wwpn' format"), + .completer =3D virshNodeDeviceNameCompleter, + }, + {.name =3D NULL} +}; + +static bool +cmdNodeDeviceUndefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) +{ + virNodeDevice *dev =3D NULL; + bool ret =3D false; + const char *device_value =3D NULL; + + if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0) + return false; + + dev =3D vshFindNodeDevice(ctl, device_value); + + if (!dev) + goto cleanup; + + if (virNodeDeviceUndefine(dev) =3D=3D 0) { + vshPrintExtra(ctl, _("Undefined node device '%s'\n"), device_value= ); + } else { + vshError(ctl, _("Failed to undefine node device '%s'"), device_val= ue); + goto cleanup; + } + + ret =3D true; + cleanup: + if (dev) + virNodeDeviceFree(dev); + return ret; +} + + /* * "nodedev-define" command */ @@ -1118,5 +1171,11 @@ const vshCmdDef nodedevCmds[] =3D { .info =3D info_node_device_define, .flags =3D 0 }, + {.name =3D "nodedev-undefine", + .handler =3D cmdNodeDeviceUndefine, + .opts =3D opts_node_device_undefine, + .info =3D info_node_device_undefine, + .flags =3D 0 + }, {.name =3D NULL} }; --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777413; cv=none; d=zohomail.com; s=zohoarc; b=E9ROfL+Eqqil5BVl/lglbW2nQcR2pvFnqcm/c5ws0Bn9kOekFhWaeODhinrGh52kbBHRmwoAzPhoeisFL3N6s3WLd5fras5c87P2Qi/PeqKPyQFGaRM/zXQosf3YTmAvvVQEW76iqyQRBReW3E8hhfcPWrIV6pi9XVOuk9EjAhQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777413; 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=5cImxyf+4G/8DtRPL4PP6rjB0pAtpP14L6xVGP6kI9M=; b=gHHLnu8JXYSGgByOB87NhMd2QE+OtUl8qeETZkJ0RtXk3Rt/ZiD05me9xj1P0sxJc9XEZxmXw0OB+WuSe2cB0OWptQi8d0TcfYMqnm1Mi4iAiwUWxY2E0ELGknLHS5d01fc0/5sLepS1G3OFvtvfQzGsMexhLqPMapTLh+VbIog= 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) header.from= 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 1616777413366211.57061259797933; Fri, 26 Mar 2021 09:50: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-247-M0r_kl6SOjWsGQlbg3fmXg-1; Fri, 26 Mar 2021 12:49:14 -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 F26A51853036; Fri, 26 Mar 2021 16:49:05 +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 C4EED19716; Fri, 26 Mar 2021 16:49:05 +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 68B0A1802143; Fri, 26 Mar 2021 16:49:05 +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 12QGmfhV003080 for ; Fri, 26 Mar 2021 12:48:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8B7235D755; Fri, 26 Mar 2021 16:48:41 +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 50A2B5D72E; Fri, 26 Mar 2021 16:48:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777412; 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=5cImxyf+4G/8DtRPL4PP6rjB0pAtpP14L6xVGP6kI9M=; b=ZdTVVGOG+6pUQV/oo48wvZL5GpemGuP0xEDw8pXAPzRgjc8tiDkNgf7S+i/oOXp0iSlNr/ yOXQ7RskMuyUxtZf/3QdhJLv2unhYf/wki6eB232g9GrPytOrEvqewmtGDU4k6WZCO4hTQ y6hL5yF3QLrypWhip1o7DmU1GuhgNpI= X-MC-Unique: M0r_kl6SOjWsGQlbg3fmXg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 23/30] api: add virNodeDeviceCreate() Date: Fri, 26 Mar 2021 11:48:19 -0500 Message-Id: <20210326164826.1720062-24-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.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" This new API function provides a way to start a persistently-defined mediate device that was defined by virNodeDeviceDefineXML() (or one that was defined externally via mdevctl) Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- include/libvirt/libvirt-nodedev.h | 2 + src/driver-nodedev.h | 4 ++ src/libvirt-nodedev.c | 35 ++++++++++ src/libvirt_public.syms | 1 + src/node_device/node_device_driver.c | 68 ++++++++++++++++++++ src/node_device/node_device_driver.h | 7 ++ src/node_device/node_device_udev.c | 1 + src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 13 +++- src/remote_protocol-structs | 4 ++ tests/nodedevmdevctldata/mdevctl-create.argv | 1 + tests/nodedevmdevctltest.c | 11 +++- 12 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 tests/nodedevmdevctldata/mdevctl-create.argv diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index 623017f1fd..cf51c3d085 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -137,6 +137,8 @@ virNodeDevicePtr virNodeDeviceDefineXML(virConnectPtr c= onn, =20 int virNodeDeviceUndefine(virNodeDevicePtr dev); =20 +int virNodeDeviceCreate(virNodeDevicePtr dev); + /** * VIR_NODE_DEVICE_EVENT_CALLBACK: * diff --git a/src/driver-nodedev.h b/src/driver-nodedev.h index c352462dda..22fe53bfc0 100644 --- a/src/driver-nodedev.h +++ b/src/driver-nodedev.h @@ -82,6 +82,9 @@ typedef virNodeDevice* typedef int (*virDrvNodeDeviceUndefine)(virNodeDevice *dev); =20 +typedef int +(*virDrvNodeDeviceCreate)(virNodeDevice *def); + typedef int (*virDrvConnectNodeDeviceEventRegisterAny)(virConnectPtr conn, virNodeDevicePtr dev, @@ -123,4 +126,5 @@ struct _virNodeDeviceDriver { virDrvNodeDeviceDestroy nodeDeviceDestroy; virDrvNodeDeviceDefineXML nodeDeviceDefineXML; virDrvNodeDeviceUndefine nodeDeviceUndefine; + virDrvNodeDeviceCreate nodeDeviceCreate; }; diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index 1d397c6610..a1b9e44ab3 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -815,6 +815,41 @@ virNodeDeviceUndefine(virNodeDevice *dev) } =20 =20 +/** + * virNodeDeviceCreate: + * @dev: a device object + * + * Start a defined node device: + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virNodeDeviceCreate(virNodeDevice *dev) +{ + VIR_DEBUG("dev=3D%p", dev); + + virResetLastError(); + + virCheckNodeDeviceReturn(dev, -1); + virCheckReadOnlyGoto(dev->conn->flags, error); + + if (dev->conn->nodeDeviceDriver && + dev->conn->nodeDeviceDriver->nodeDeviceCreate) { + int retval =3D dev->conn->nodeDeviceDriver->nodeDeviceCreate(dev); + if (retval < 0) + goto error; + + return 0; + } + + virReportUnsupportedError(); + + error: + virDispatchError(dev->conn); + return -1; +} + + /** * virConnectNodeDeviceEventRegisterAny: * @conn: pointer to the connection diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 99b46587b9..3a8f5d8fc6 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -889,6 +889,7 @@ LIBVIRT_7.2.0 { virDomainStartDirtyRateCalc; virNodeDeviceDefineXML; virNodeDeviceUndefine; + virNodeDeviceCreate; } LIBVIRT_7.1.0; =20 # .... define new API here using predicted next version number .... diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 48b4b1f438..cd7677633a 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -901,6 +901,18 @@ nodeDeviceGetMdevctlUndefineCommand(const char *uuid, = char **errmsg) return cmd; } =20 +virCommand* +nodeDeviceGetMdevctlCreateCommand(const char *uuid, char **errmsg) +{ + virCommand *cmd =3D virCommandNewArgList(MDEVCTL, + "start", + "-u", + uuid, + NULL); + virCommandSetErrorBuffer(cmd, errmsg); + return cmd; +} + static int virMdevctlStop(virNodeDeviceDefPtr def, char **errmsg) { @@ -932,6 +944,21 @@ virMdevctlUndefine(virNodeDeviceDef *def, char **errms= g) } =20 =20 +static int +virMdevctlCreate(virNodeDeviceDef *def, char **errmsg) +{ + int status; + g_autoptr(virCommand) cmd =3D NULL; + + cmd =3D nodeDeviceGetMdevctlCreateCommand(def->caps->data.mdev.uuid, e= rrmsg); + + if (virCommandRun(cmd, &status) < 0 || status !=3D 0) + return -1; + + return 0; +} + + virCommand* nodeDeviceGetMdevctlListCommand(bool defined, char **output) @@ -1257,6 +1284,47 @@ nodeDeviceUndefine(virNodeDevice *device) } =20 =20 +int +nodeDeviceCreate(virNodeDevice *device) +{ + int ret =3D -1; + virNodeDeviceObj *obj =3D NULL; + virNodeDeviceDef *def =3D NULL; + + if (!(obj =3D nodeDeviceObjFindByName(device->name))) + return -1; + + if (virNodeDeviceObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("Device is already active")); + goto cleanup; + } + def =3D virNodeDeviceObjGetDef(obj); + + if (virNodeDeviceCreateEnsureACL(device->conn, def) < 0) + goto cleanup; + + if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) { + g_autofree char *errmsg =3D NULL; + + if (virMdevctlCreate(def, &errmsg) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to create mediated device: %s"), + errmsg && errmsg[0] ? errmsg : "Unknown Error"); + goto cleanup; + } + ret =3D 0; + } else { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Unsupported device type")); + } + + cleanup: + virNodeDeviceObjEndAPI(&obj); + return ret; +} + + int nodeConnectNodeDeviceEventRegisterAny(virConnectPtr conn, virNodeDevicePtr device, diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index 92bb72ee5d..27e4095299 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -157,3 +157,10 @@ nodeDeviceGenerateName(virNodeDeviceDef *def, =20 bool nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, virNodeDeviceDef *src); + +virCommand* +nodeDeviceGetMdevctlCreateCommand(const char *uuid, + char **errmsg); + +int +nodeDeviceCreate(virNodeDevice *dev); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index b870446c55..d80e81a5a9 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2323,6 +2323,7 @@ static virNodeDeviceDriver udevNodeDeviceDriver =3D { .nodeDeviceDestroy =3D nodeDeviceDestroy, /* 0.7.3 */ .nodeDeviceDefineXML =3D nodeDeviceDefineXML, /* 7.2.0 */ .nodeDeviceUndefine =3D nodeDeviceUndefine, /* 7.2.0 */ + .nodeDeviceCreate =3D nodeDeviceCreate, /* 7.2.0 */ }; =20 =20 diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index d3e21ea797..31b293ac4a 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8696,6 +8696,7 @@ static virNodeDeviceDriver node_device_driver =3D { .nodeDeviceNumOfCaps =3D remoteNodeDeviceNumOfCaps, /* 0.5.0 */ .nodeDeviceListCaps =3D remoteNodeDeviceListCaps, /* 0.5.0 */ .nodeDeviceCreateXML =3D remoteNodeDeviceCreateXML, /* 0.6.3 */ + .nodeDeviceCreate =3D remoteNodeDeviceCreate, /* 7.2.0 */ .nodeDeviceDefineXML =3D remoteNodeDeviceDefineXML, /* 7.2.0 */ .nodeDeviceUndefine =3D remoteNodeDeviceUndefine, /* 7.2.0 */ .nodeDeviceDestroy =3D remoteNodeDeviceDestroy /* 0.6.3 */ diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 10d4233d69..273ae7531e 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -2158,6 +2158,10 @@ struct remote_node_device_undefine_args { remote_nonnull_string name; }; =20 +struct remote_node_device_create_args { + remote_nonnull_string name; +}; + =20 /* * Events Register/Deregister: @@ -6771,6 +6775,13 @@ enum remote_procedure { * @priority: high * @acl: node_device:delete */ - REMOTE_PROC_NODE_DEVICE_UNDEFINE =3D 429 + REMOTE_PROC_NODE_DEVICE_UNDEFINE =3D 429, + + /** + * @generate: both + * @priority: high + * @acl: node_device:start + */ + REMOTE_PROC_NODE_DEVICE_CREATE =3D 430 =20 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 792e858770..15bd7ae8f0 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -1610,6 +1610,9 @@ struct remote_node_device_define_xml_ret { struct remote_node_device_undefine_args { remote_nonnull_string name; }; +struct remote_node_device_create_args { + remote_nonnull_string name; +}; struct remote_connect_domain_event_register_ret { int cb_registered; }; @@ -3617,4 +3620,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_START_DIRTY_RATE_CALC =3D 427, REMOTE_PROC_NODE_DEVICE_DEFINE_XML =3D 428, REMOTE_PROC_NODE_DEVICE_UNDEFINE =3D 429, + REMOTE_PROC_NODE_DEVICE_CREATE =3D 430, }; diff --git a/tests/nodedevmdevctldata/mdevctl-create.argv b/tests/nodedevmd= evctldata/mdevctl-create.argv new file mode 100644 index 0000000000..802109340c --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-create.argv @@ -0,0 +1 @@ +$MDEVCTL_BINARY$ start -u 8a05ad83-3472-497d-8631-8142f31460e8 diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index e471e2e6eb..af5e073e8b 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -14,7 +14,8 @@ typedef enum { MDEVCTL_CMD_START, MDEVCTL_CMD_STOP, MDEVCTL_CMD_DEFINE, - MDEVCTL_CMD_UNDEFINE + MDEVCTL_CMD_UNDEFINE, + MDEVCTL_CMD_CREATE, } MdevctlCmd; =20 struct startTestInfo { @@ -188,6 +189,9 @@ testMdevctlUuidCommandHelper(const void *data) } else if (info->command =3D=3D MDEVCTL_CMD_UNDEFINE) { cmd =3D "undefine"; func =3D nodeDeviceGetMdevctlUndefineCommand; + }else if (info->command =3D=3D MDEVCTL_CMD_CREATE) { + cmd =3D "create"; + func =3D nodeDeviceGetMdevctlCreateCommand; } else { return -1; } @@ -428,6 +432,9 @@ mymain(void) #define DO_TEST_UNDEFINE(uuid) \ DO_TEST_UUID_COMMAND_FULL("mdevctl undefine " uuid, uuid, MDEVCTL_CMD_= UNDEFINE) =20 +#define DO_TEST_CREATE(uuid) \ + DO_TEST_UUID_COMMAND_FULL("mdevctl create " uuid, uuid, MDEVCTL_CMD_CR= EATE) + #define DO_TEST_LIST_DEFINED() \ DO_TEST_FULL("mdevctl list --defined", testMdevctlListDefined, NULL) =20 @@ -452,6 +459,8 @@ mymain(void) =20 DO_TEST_UNDEFINE("d76a6b78-45ed-4149-a325-005f9abc5281"); =20 + DO_TEST_CREATE("8a05ad83-3472-497d-8631-8142f31460e8"); + done: nodedevTestDriverFree(driver); =20 --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777425; cv=none; d=zohomail.com; s=zohoarc; b=I9RuYlJ75r/1D+usHNf9OMm/VIdn6z0/e0XBf2c/G+ZM4ZLS3X+DloHyye+1uN7kv6Hx9K/f6YF/57sbiftIuP94G/qSca72iJH0uHRTB7WQWM6Mey5CeDC5+flKClq7a215EWwDmatmBaUg6ZrnyU2bykgPdLq9zbJPLAPpYXA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777425; 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=qqVkpyGobcVcALZ6pobWXZJNyr5wc98G8vTB8wg6H9s=; b=D/EfQOxSF16+35zxAlv0SFV7NmTcdR4cw0LV5U3KzElW1lerh3h/dkkiwEQyukPEof9VWae2+xJO+iLiw2ffZQYOZBxO7iP3KHF7yuH4kVexaN0jbMHoa+wCW7YIWj13tvEWk5oLEgj5WJSsHi3XmNFsb7fp7Uc8JMcS39ELNhE= 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) header.from= 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 1616777425165168.06975000834552; Fri, 26 Mar 2021 09:50: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-475-RENnFr0YNJC3Bpp45EiygA-1; Fri, 26 Mar 2021 12:49:16 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 20D1310866C3; Fri, 26 Mar 2021 16:49:09 +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 E76E66EF42; Fri, 26 Mar 2021 16:49: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 A69555003E; Fri, 26 Mar 2021 16:49:08 +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 12QGmfiY003086 for ; Fri, 26 Mar 2021 12:48:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id DC3405D72E; Fri, 26 Mar 2021 16:48:41 +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 A4BA75D6DC; Fri, 26 Mar 2021 16:48:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777424; 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=qqVkpyGobcVcALZ6pobWXZJNyr5wc98G8vTB8wg6H9s=; b=dzcdoPyeKdqNoMeXDP8Gs1NcQBFL3QBEPU4ZyhqDhf2kgPem2LYFyQClg8E6HO/hKk6Gm4 Am58Wzq01l/ugwiv4mudjzrIO0RwQ4kWUpfrmy8ffAFl5Nk+wnilPhmG9LnJ5+Ixo6oq6U wozgJIBhSVyZShUV9HLD7YMYxeIJhfs= X-MC-Unique: RENnFr0YNJC3Bpp45EiygA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 24/30] virsh: add "nodedev-start" command Date: Fri, 26 Mar 2021 11:48:20 -0500 Message-Id: <20210326164826.1720062-25-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.13 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 virsh command maps to virNodeDeviceCreate(), which starts a node device that has been previously defined by virNodeDeviceDefineXML(). This is only supported for mediated devices. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- tools/virsh-nodedev.c | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index d5b82ba285..e13c15b4b0 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -1112,6 +1112,57 @@ cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *c= md G_GNUC_UNUSED) } =20 =20 +/* + * "nodedev-start" command + */ +static const vshCmdInfo info_node_device_start[] =3D { + {.name =3D "help", + .data =3D N_("Start an inactive node device") + }, + {.name =3D "desc", + .data =3D N_("Starts an inactive node device that was previously defi= ned") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_node_device_start[] =3D { + {.name =3D "device", + .type =3D VSH_OT_DATA, + .flags =3D VSH_OFLAG_REQ, + .help =3D N_("device name"), + .completer =3D virshNodeDeviceNameCompleter, + }, + {.name =3D NULL} +}; + +static bool +cmdNodeDeviceStart(vshControl *ctl, const vshCmd *cmd) +{ + const char *name =3D NULL; + virNodeDevice *device; + bool ret =3D true; + virshControl *priv =3D ctl->privData; + + if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0) + return false; + + if (!(device =3D virNodeDeviceLookupByName(priv->conn, name))) { + vshError(ctl, _("Could not find matching device '%s'"), name); + return false; + } + + if (virNodeDeviceCreate(device) =3D=3D 0) { + vshPrintExtra(ctl, _("Device %s started\n"), name); + } else { + vshError(ctl, _("Failed to start device %s"), name); + ret =3D false; + } + + virNodeDeviceFree(device); + return ret; +} + + const vshCmdDef nodedevCmds[] =3D { {.name =3D "nodedev-create", .handler =3D cmdNodeDeviceCreate, @@ -1177,5 +1228,11 @@ const vshCmdDef nodedevCmds[] =3D { .info =3D info_node_device_undefine, .flags =3D 0 }, + {.name =3D "nodedev-start", + .handler =3D cmdNodeDeviceStart, + .opts =3D opts_node_device_start, + .info =3D info_node_device_start, + .flags =3D 0 + }, {.name =3D NULL} }; --=20 2.26.3 From nobody Wed Apr 24 21:05:09 2024 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=1616777467; cv=none; d=zohomail.com; s=zohoarc; b=RLdjjW0wtdIiCJjZsR5SdKk8HVM0SCg1h0wszBAnJ95M/ff8TCWvjF8Ad7iNYNlHulYqrLLAyPwN3DvHqU0QtcgytnqPEQ5OhxBlXUeNhP64o52JnxCi4Wpnporw9ZDgyh1zuf8mjqudHTDe/fJWyblFGaIcH2l5Trq8MPxStr8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777467; 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=xWGaTHvGUXR6qcfJjb5jjYIOFSknL9umRWV7ko2g6m0=; b=MRWS2z1iQ/RrhGKJ4ArrZnVfTXp9pXFP6UNvJjhzpjokuoUzGErZnOsEc2IrTBhPosLMXnY5HZMWH5m8uGMXzlVnLy4dMrbJ3+BLT5fPEm8/vN3u+EH61d46VF6xXMYeNOSwcMOCVf6YMWZmdOtzAwLNGj/ilqk+FauxGCF44PY= 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 1616777467228637.2765656085758; Fri, 26 Mar 2021 09:51:07 -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-231-nFpiBCPNOuihBAb4YjedAQ-1; Fri, 26 Mar 2021 12:49:19 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C62B107BEFA; Fri, 26 Mar 2021 16:49:11 +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 43C47226FC; Fri, 26 Mar 2021 16:49:11 +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 ED37A180214A; Fri, 26 Mar 2021 16:49:10 +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 12QGmgQ9003092 for ; Fri, 26 Mar 2021 12:48:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3AEED5D755; Fri, 26 Mar 2021 16:48:42 +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 0337E5D72E; Fri, 26 Mar 2021 16:48:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777466; 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=xWGaTHvGUXR6qcfJjb5jjYIOFSknL9umRWV7ko2g6m0=; b=NcYikw4rvMYyPGRCchLgHeZ/GcTPpMK81eXP5veH5iUfYbHfFJjof06RPYBkTKOqhJtwAE 8COUcM0RiilUSIowLWpeTM4RjvulV+xyQrjJXhuNL/xiZnCY+Z2kYp37g3FPWDpXtvUo7/ 0Wq91AesrqgCky0UbIJSBTHU1v6rOfA= X-MC-Unique: nFpiBCPNOuihBAb4YjedAQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 25/30] nodedev: add element to mdev caps Date: Fri, 26 Mar 2021 11:48:21 -0500 Message-Id: <20210326164826.1720062-26-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.13 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" It will be useful to be able to specify a particular UUID for a mediated device when defining the node device. To accomodate that, allow this to be specified in the xml schema. This patch also parses and formats that value to the xml, but does not yet use it. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- docs/schemas/nodedev.rng | 43 +++++++++++-------- src/conf/node_device_conf.c | 14 ++++++ .../mdevctl-list-multiple.out.xml | 4 ++ 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng index 5840dc9f0d..777227c38a 100644 --- a/docs/schemas/nodedev.rng +++ b/docs/schemas/nodedev.rng @@ -606,27 +606,34 @@ =20 - - mdev - - - - + + + mdev - - - - - + + + - - - - - - - + + + + + + + + + + + + + + + + + + + =20 diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index b1739ceb01..d167da6171 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -527,6 +527,7 @@ virNodeDeviceCapMdevDefFormat(virBufferPtr buf, size_t i; =20 virBufferEscapeString(buf, "\n", data->mdev.type); + virBufferEscapeString(buf, "%s\n", data->mdev.uuid); virBufferAsprintf(buf, "\n", data->mdev.iommuGroupNumber); =20 @@ -1948,6 +1949,7 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, int nattrs =3D 0; g_autofree xmlNodePtr *attrs =3D NULL; size_t i; + g_autofree char *uuidstr =3D NULL; =20 ctxt->node =3D node; =20 @@ -1957,6 +1959,18 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, return -1; } =20 + if ((uuidstr =3D virXPathString("string(./uuid[1])", ctxt))) { + unsigned char uuidbuf[VIR_UUID_BUFLEN]; + /* make sure that the provided uuid is valid */ + if (virUUIDParse(uuidstr, uuidbuf) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid uuid '%s' for new mdev device"), uui= dstr); + return -1; + } + mdev->uuid =3D g_new0(char, VIR_UUID_STRING_BUFLEN); + virUUIDFormat(uuidbuf, mdev->uuid); + } + /* 'iommuGroup' is optional, only report an error if the supplied valu= e is * invalid (-2), not if it's missing (-1) */ if (virXPathUInt("number(./iommuGroup[1]/@number)", diff --git a/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml b/tests= /nodedevmdevctldata/mdevctl-list-multiple.out.xml index 543ad916b7..cf7e966256 100644 --- a/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml +++ b/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml @@ -3,6 +3,7 @@ 0000:00:02.0 + 200f228a-c80a-4d50-bfb7-f5a0e4e34045 @@ -11,6 +12,7 @@ 0000:00:02.0 + de807ffc-1923-4d5f-b6c9-b20ecebc6d4b @@ -19,6 +21,7 @@ 0000:00:02.0 + 435722ea-5f43-468a-874f-da34f1217f13 @@ -28,6 +31,7 @@ matrix + 783e6dbb-ea0e-411f-94e2-717eaad438bf --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777437; cv=none; d=zohomail.com; s=zohoarc; b=Bz4gNbbvh/IVJmXzIN/KuAlMk3IufreS5LzJM73ReK1F6huQOTg5uXQ5tn4BSEW6Z9Kuz2oBAfc5n9pZkrVQfLCnpGGpvHEeipolpL9ssEaQsXEExXOrR2vh8VVzSQP0pJ1kTR6KMhVow0xG289BlIYfXZ5Tl2BH4hp/sE5fc+4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777437; 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=wK3J2wyBuGFcrGYWiro4eWIf4SzFjIKzCJUQleianPs=; b=G6U47X5LmZKIT/E3SzV3FFgtft32dnjNjCKAsZxXeAQpGBVy9NX5SEuDAXmfMdhj22xddIe8wRLX9kTerR6TTezm6MNQXM/13zjrwH0WUQ35guC4U+Z01FxrozpudwP+OvrPhlU92iKhx4V5MQsfHgh8MVVqrn7sM1RE+ioisSg= 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) header.from= 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 1616777437027226.31649290992095; Fri, 26 Mar 2021 09:50:37 -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-290-79f8hj7-MKCwECDtZF_MBA-1; Fri, 26 Mar 2021 12:49:12 -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 7F50D107BEF6; Fri, 26 Mar 2021 16:49:06 +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 5A2796A857; Fri, 26 Mar 2021 16:49:06 +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 E6F9D1802148; Fri, 26 Mar 2021 16:49:05 +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 12QGmgmh003102 for ; Fri, 26 Mar 2021 12:48:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8ECA25D755; Fri, 26 Mar 2021 16:48:42 +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 55A845D6DC; Fri, 26 Mar 2021 16:48:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777436; 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=wK3J2wyBuGFcrGYWiro4eWIf4SzFjIKzCJUQleianPs=; b=gjZz/EhVtroazIknQJwQoR9yKxvzQr5seRUSGCA0vLitiRMQ8BO+H7EN2Z3b2Dcx+OgGr1 k8HKlELgut4ejp4s2WK6+TpTVF4EKV8DVGWOi0jK+NLVCRhb92CaOVFODIL7KuztNCGYt5 gubbt0Jz1bLDRuDiG7bAye5FGbOEtqc= X-MC-Unique: 79f8hj7-MKCwECDtZF_MBA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 26/30] nodedev: add ability to specify UUID for new mdevs Date: Fri, 26 Mar 2021 11:48:22 -0500 Message-Id: <20210326164826.1720062-27-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.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" Use the new element in the mdev caps to define and start devices with a specific UUID. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- src/node_device/node_device_driver.c | 19 ++++++++++++++++--- ...19_36ea_4111_8f0a_8c9a70e21366-define.argv | 3 ++- ...019_36ea_4111_8f0a_8c9a70e21366-start.argv | 3 ++- ...v_d069d019_36ea_4111_8f0a_8c9a70e21366.xml | 1 + 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index cd7677633a..b1b3217afb 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -729,6 +729,10 @@ nodeDeviceGetMdevctlDefineStartCommand(virNodeDeviceDe= f *def, NULL); =20 virCommandSetInputBuffer(cmd, json); + + if (def->caps->data.mdev.uuid) + virCommandAddArgPair(cmd, "--uuid", def->caps->data.mdev.uuid); + virCommandSetOutputBuffer(cmd, uuid_out); virCommandSetErrorBuffer(cmd, errmsg); =20 @@ -816,7 +820,12 @@ nodeDeviceCreateXMLMdev(virConnectPtr conn, return NULL; } =20 - return nodeDeviceFindNewMediatedDevice(conn, uuid); + if (uuid && uuid[0]) { + g_free(def->caps->data.mdev.uuid); + def->caps->data.mdev.uuid =3D g_steal_pointer(&uuid); + } + + return nodeDeviceFindNewMediatedDevice(conn, def->caps->data.mdev.uuid= ); } =20 =20 @@ -1230,9 +1239,13 @@ nodeDeviceDefineXML(virConnect *conn, return NULL; } =20 - def->caps->data.mdev.uuid =3D g_strdup(uuid); + if (uuid && uuid[0]) { + g_free(def->caps->data.mdev.uuid); + def->caps->data.mdev.uuid =3D g_steal_pointer(&uuid); + } + mdevGenerateDeviceName(def); - device =3D nodeDeviceFindNewMediatedDevice(conn, uuid); + device =3D nodeDeviceFindNewMediatedDevice(conn, def->caps->data.mdev.= uuid); =20 return device; } diff --git a/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e2= 1366-define.argv b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c= 9a70e21366-define.argv index 773e98b963..118ec7a8da 100644 --- a/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-de= fine.argv +++ b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-de= fine.argv @@ -1 +1,2 @@ -$MDEVCTL_BINARY$ define -p 0000:00:02.0 --jsonfile /dev/stdin +$MDEVCTL_BINARY$ define -p 0000:00:02.0 --jsonfile /dev/stdin \ +--uuid=3Dd069d019-36ea-4111-8f0a-8c9a70e21366 diff --git a/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e2= 1366-start.argv b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9= a70e21366-start.argv index eb7262035e..129f438e4a 100644 --- a/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-st= art.argv +++ b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-st= art.argv @@ -1 +1,2 @@ -$MDEVCTL_BINARY$ start -p 0000:00:02.0 --jsonfile /dev/stdin +$MDEVCTL_BINARY$ start -p 0000:00:02.0 --jsonfile /dev/stdin \ +--uuid=3Dd069d019-36ea-4111-8f0a-8c9a70e21366 diff --git a/tests/nodedevschemadata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21= 366.xml b/tests/nodedevschemadata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366= .xml index d6a2e99edc..605d8f63a1 100644 --- a/tests/nodedevschemadata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366.xml +++ b/tests/nodedevschemadata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366.xml @@ -3,5 +3,6 @@ pci_0000_00_02_0 + d069d019-36ea-4111-8f0a-8c9a70e21366 --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777365; cv=none; d=zohomail.com; s=zohoarc; b=i6Gu9al1co7YQ70FNZq64g5xOrl1LutwN3zvM5AukJHQl90hhF69C4pttBxtrq+FlmwFPTPyWL800wpUxkTMgiFt2mGTG8DiryoeD4L67ueGJfAnX1ypbAtT+5AGMX4NNijgD/daPWf3JnxA2D8TOY/fujg+uYVnBNrCxJeHtiw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777365; 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=oC09Eskm6srJv6p9/XzJ/xmFQWTWEvVrrEJVEgedaRM=; b=mQpUVjCakyrI1dipWEhoqPG5w/vaKQTUCtZeoSZ0QNgu7ZR6RVdyTWKcFFXiVH+qjt//XJzlV/NNYldEry7CViv9vkDMkQ69fOedQRZ6VJz+1HK/qGRWC5JkwMXRBmdR6ZuDugoJhxZTFK/0g5WIJZuuD+QLvo1eFqRZSZjuXa8= 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) header.from= 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 161677736544340.21759542135783; Fri, 26 Mar 2021 09:49: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-435-ML8G23hLOVKGzU_Cp51gVA-1; Fri, 26 Mar 2021 12:49:21 -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 B3C5484B9BC; Fri, 26 Mar 2021 16:49:14 +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 8CA5A607D5; Fri, 26 Mar 2021 16:49:14 +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 4B1CF180214F; Fri, 26 Mar 2021 16:49:14 +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 12QGmgOQ003109 for ; Fri, 26 Mar 2021 12:48:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id DF3DC5D72E; Fri, 26 Mar 2021 16:48:42 +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 A80455D6DC; Fri, 26 Mar 2021 16:48:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777364; 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=oC09Eskm6srJv6p9/XzJ/xmFQWTWEvVrrEJVEgedaRM=; b=Y1VZEF915zSW7N6urJkI1Y2w3LSoAkzybENQ9mMPKoGaUQ/o6PNr61UFxEZQxJMJMeygz5 FUM1QwZHSMxBoeHQkPQdRRMviYU20VPZD6W+tz8evEglDABgfLXJ6dFNrScy3cF37gd2uP KKN9YyhqIKsr3xY/hYfSQGFHS+N37CE= X-MC-Unique: ML8G23hLOVKGzU_Cp51gVA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 27/30] nodedev: fix hang when destroying an mdev in use Date: Fri, 26 Mar 2021 11:48:23 -0500 Message-Id: <20210326164826.1720062-28-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) Content-Type: text/plain; charset="utf-8" Calling `mdevctl stop` for a mediated device that is in use by an active domain will block until that vm exits (or the vm closes the device). Since the nodedev driver cannot query the hypervisor driver to see whether any active domains are using the device, we resort to a workaround that relies on the fact that a vfio group can only be opened by one user at a time. If we get an EBUSY error when attempting to open the group file, we assume the device is in use and refuse to try to destroy that device. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- src/node_device/node_device_driver.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index b1b3217afb..31322e3afb 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1177,8 +1177,27 @@ nodeDeviceDestroy(virNodeDevicePtr device) =20 ret =3D 0; } else if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) { + /* 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 + * is in use by any active domains, since that would introduce cir= cular + * dependencies between daemons and add a risk of deadlocks. So we= need + * to resort to a workaround. vfio only allows the group for a de= vice + * 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 open(vfiogroup, O_RDONLY); g_autofree char *errmsg =3D NULL; =20 + if (fd < 0 && errno =3D=3D EBUSY) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to destroy '%s': device in use"), + def->name); + goto cleanup; + } + if (virMdevctlStop(def, &errmsg) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to destroy '%s': %s"), def->name, --=20 2.26.3 From nobody Wed Apr 24 21:05:09 2024 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=1616777368; cv=none; d=zohomail.com; s=zohoarc; b=m1SbCWi6bI8FCced4nZYh2oy6fs2Qv+zl1q3/n7agYFbn3/Rg4EE3DaihcxdWLqPpwRLOCQjscvyvp2xuryrQJrhL1/tWUms629iC+bIjCUpWBzrSByh5KF5++EhRsIFUyPHPJPo7EGAp5q8QpYapptkJHzdRWO+l4DwvTFHGZs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777368; 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=EpDNqWSA5zQtvBHyxdnHVxXW9Cjk/16iZObO2Olw5AM=; b=g8GKZ4L2TuzwCJs/41nhxB/PHDtOZ+CMn7Ai018u87unRDu2lrsvCzIpafgFs2TGQRk1oh+LVkR25u1XrA1tjHIDvWijgLppvI63+z+UiQ8txSw+RUWxbB2bHDk6X+NksTUzLKZRMO40XQ3DnaMkyaOt5tJHiS6APVm9IBoq86s= 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 1616777368218846.6366912605215; Fri, 26 Mar 2021 09:49:28 -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-578-u5watMe3P6iOxGpu3dp1Tw-1; Fri, 26 Mar 2021 12:49:23 -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 E2864107BEF9; Fri, 26 Mar 2021 16:49:17 +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 C1E4A89D0E; Fri, 26 Mar 2021 16:49:17 +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 835D3180448E; Fri, 26 Mar 2021 16:49:17 +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 12QGmhSi003117 for ; Fri, 26 Mar 2021 12:48:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3E91F5D755; Fri, 26 Mar 2021 16:48:43 +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 056A05D6DC; Fri, 26 Mar 2021 16:48:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777366; 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=EpDNqWSA5zQtvBHyxdnHVxXW9Cjk/16iZObO2Olw5AM=; b=HLGT4QEX9rmFt4sh/XA1/sNj5NnOOddY/6jnHeEUhwpP4JxW9FB23mrjub8deBmOnHRpoF fuVOHDeIgwLt2XxhWcJ7XzAb9MciO6KR86+4h7Jo7nabf7kUOF2cYPt080se35gL3mGXbx DqEuB6Bagy7pBOvSAyJgEcEwA6gkLNg= X-MC-Unique: u5watMe3P6iOxGpu3dp1Tw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 28/30] nodedev: add docs about mdev attribute order Date: Fri, 26 Mar 2021 11:48:24 -0500 Message-Id: <20210326164826.1720062-29-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.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" Mention that mdev attribute order is significant. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- docs/formatnode.html.in | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/formatnode.html.in b/docs/formatnode.html.in index 5c7286df8a..c58cd01395 100644 --- a/docs/formatnode.html.in +++ b/docs/formatnode.html.in @@ -379,7 +379,10 @@ This optional element can occur multiple times. It represe= nts a vendor-specific attribute that is used to configure this mediated device. It has two required attributes: - name and value. + name and value. Note that the or= der + in which attributes are set may be important for some devi= ces. + The order that they appear in the xml definition determine= s the + order that they will be written to the device. --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777372; cv=none; d=zohomail.com; s=zohoarc; b=UZj5zQuiIOuykNSpd62L6M0+LVq3RwY4drIOL0BZvv3OtjEOmiXB4jx7a9FzgZjBVrFieit3LRBgd7B9kFWelWHYG35RI8tBHZCU5scsOVYOdLSBLX8q6x03XqM9DDRN+sc5ZykuecfH/K0OrPlWZp6m0eyyuNvxtUykr3ffRUM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777372; 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=jlqzlXra53IPYqcZgvZpR8dqB3gbxdXlVjsGplez1f8=; b=P3xJ8ClzI4v6XCToDrPuuhkJAQm5HZzhBiozeL20s1tt7PtrJ6rASKT55YEVvQtTGNLoD78d+LPSk+aHAbPfC79biDgKK8+vPesmF2Lp3RgOmFHiakmC7RfQwzMkDTAWNsFcfE9ruhykAP4XMYdgstX3WqQLuO3zpiZciTRwI0M= 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) header.from= 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 1616777372576486.4947014564708; Fri, 26 Mar 2021 09:49:32 -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-457-A2NmavK6MFS4aSjXUeeAPA-1; Fri, 26 Mar 2021 12:49:27 -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 320CAE49E2; Fri, 26 Mar 2021 16:49:21 +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 102895D756; Fri, 26 Mar 2021 16:49:21 +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 C6AD31818467; Fri, 26 Mar 2021 16:49:20 +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 12QGmhOM003127 for ; Fri, 26 Mar 2021 12:48:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 905BE5D72E; Fri, 26 Mar 2021 16:48:43 +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 585365D6DC; Fri, 26 Mar 2021 16:48:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777369; 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=jlqzlXra53IPYqcZgvZpR8dqB3gbxdXlVjsGplez1f8=; b=e7g3nzvBKdiG6ZtiT+rGiC8Z8aXm4e+GoPQNyRT3FfYgKyMe4+NsuGRF4WhlahLNYxpYcI 8F3t0NrJTcLEmQCsdFj597cbPb/VZK7rrm+OZ9H94+4R66P64WxCMp8kQLUO4jbJsVL0tG v2/dH2/W08lOpaPw8+SCpj2eDKAbj3E= X-MC-Unique: A2NmavK6MFS4aSjXUeeAPA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 29/30] nodedev: factor out function to add mediated devices Date: Fri, 26 Mar 2021 11:48:25 -0500 Message-Id: <20210326164826.1720062-30-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.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" To accomodate re-use of this functionality in a following patch, split out the processing of an individual mdev definition into a separate function. --- src/node_device/node_device_driver.c | 103 +++++++++++++++------------ 1 file changed, 57 insertions(+), 46 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 31322e3afb..35db24817a 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1506,6 +1506,60 @@ removeMissingPersistentMdevs(virNodeDeviceObj *obj, } =20 =20 +/* takes ownership of @def and potentially frees it. @def should not be us= ed + * after returning from this function */ +static int +nodeDeviceUpdateMediatedDevice(virNodeDeviceDef *def) +{ + virNodeDeviceObj *obj; + virObjectEvent *event; + bool defined =3D false; + g_autoptr(virNodeDeviceDef) owned =3D def; + g_autofree char *name =3D g_strdup(owned->name); + + owned->driver =3D g_strdup("vfio_mdev"); + + if (!(obj =3D virNodeDeviceObjListFindByName(driver->devs, owned->name= ))) { + virNodeDeviceDef *d =3D g_steal_pointer(&owned); + if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, d))) { + virNodeDeviceDefFree(d); + return -1; + } + } else { + bool changed; + virNodeDeviceDef *olddef =3D virNodeDeviceObjGetDef(obj); + + defined =3D virNodeDeviceObjIsPersistent(obj); + /* Active devices contain some additional information (e.g. sysfs + * path) that is not provided by mdevctl, so re-use the existing + * definition and copy over new mdev data */ + changed =3D nodeDeviceDefCopyFromMdevctl(olddef, owned); + + if (defined && !changed) { + /* if this device was already defined and the definition + * hasn't changed, there's nothing to do for this device */ + virNodeDeviceObjEndAPI(&obj); + return 0; + } + } + + /* all devices returned by virMdevctlListDefined() are persistent */ + virNodeDeviceObjSetPersistent(obj, true); + + if (!defined) + event =3D virNodeDeviceEventLifecycleNew(name, + VIR_NODE_DEVICE_EVENT_DEFIN= ED, + 0); + else + event =3D virNodeDeviceEventUpdateNew(name); + + virNodeDeviceObjEndAPI(&obj); + virObjectEventStateQueue(driver->nodeDeviceEventState, event); + + return 0; +} + + int nodeDeviceUpdateMediatedDevices(void) { @@ -1525,52 +1579,9 @@ nodeDeviceUpdateMediatedDevices(void) virNodeDeviceObjListForEachRemove(driver->devs, removeMissingPersistentMdevs, &data); =20 - for (i =3D 0; i < data.ndefs; i++) { - virNodeDeviceObj *obj; - virObjectEvent *event; - g_autoptr(virNodeDeviceDef) def =3D defs[i]; - g_autofree char *name =3D g_strdup(def->name); - bool defined =3D false; - - def->driver =3D g_strdup("vfio_mdev"); - - if (!(obj =3D virNodeDeviceObjListFindByName(driver->devs, def->na= me))) { - virNodeDeviceDef *d =3D g_steal_pointer(&def); - if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, d)))= { - virNodeDeviceDefFree(d); - return -1; - } - } else { - bool changed; - virNodeDeviceDef *olddef =3D virNodeDeviceObjGetDef(obj); - - defined =3D virNodeDeviceObjIsPersistent(obj); - /* Active devices contain some additional information (e.g. sy= sfs - * path) that is not provided by mdevctl, so re-use the existi= ng - * definition and copy over new mdev data */ - changed =3D nodeDeviceDefCopyFromMdevctl(olddef, def); - - if (defined && !changed) { - /* if this device was already defined and the definition - * hasn't changed, there's nothing to do for this device */ - virNodeDeviceObjEndAPI(&obj); - continue; - } - } - - /* all devices returned by virMdevctlListDefined() are persistent = */ - virNodeDeviceObjSetPersistent(obj, true); - - if (!defined) - event =3D virNodeDeviceEventLifecycleNew(name, - VIR_NODE_DEVICE_EVENT_D= EFINED, - 0); - else - event =3D virNodeDeviceEventUpdateNew(name); - - virNodeDeviceObjEndAPI(&obj); - virObjectEventStateQueue(driver->nodeDeviceEventState, event); - } + for (i =3D 0; i < data.ndefs; i++) + if (nodeDeviceUpdateMediatedDevice(defs[i]) < 0) + return -1; =20 return 0; } --=20 2.26.3 From nobody Wed Apr 24 21:05:09 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=1616777360; cv=none; d=zohomail.com; s=zohoarc; b=cS0DMsVINKLYByKWKm3DxJKum+U9v71I22aajslvsAhp5/a+HM3gI5MyZXnfqw/BQkFGaFWL+oDxPrjV7919fwRe6io0nWGJLyOUz13PKoh3OusjcUDxIXKvyFWmAsv69J0HtSbEb7Bhj7+4TWG5pfaG11i8dT6gOrhJQg1xYJY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777360; 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=18ksDzgq6i6+T//WgMCbvYwlNC6cT+AMNADxy1WKhVw=; b=BSPj+OeQc/ODxeOlT6QMdR0WEWh8vFgdgNNq7v1RtFgkxG0DzByQBqNRQbfntNWlGLhNTti+h+3UnMyaqSgUA3nRun7C5KIRJFco0kV6bV7ywn4dROQEp9VM7UKMB1R5C6asJVKUoYxs+zPjIAgd2jQq0n0iy0ZXZwIX5z7Pt9c= 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) header.from= 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 1616777360248384.2793102795357; Fri, 26 Mar 2021 09:49: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-325-BK9KxfoQOua6I_1svi9yig-1; Fri, 26 Mar 2021 12:49:16 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id BB78D107BF14; Fri, 26 Mar 2021 16:49:09 +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 95E346A03B; Fri, 26 Mar 2021 16:49:09 +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 2E60350041; Fri, 26 Mar 2021 16:49:09 +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 12QGmhGb003132 for ; Fri, 26 Mar 2021 12:48:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id E2BD65D72E; Fri, 26 Mar 2021 16:48:43 +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 AA6965D6DC; Fri, 26 Mar 2021 16:48:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777359; 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=18ksDzgq6i6+T//WgMCbvYwlNC6cT+AMNADxy1WKhVw=; b=GeXETG4DL+tT68/b3FUSwihBnIlilsw/z0hhyXd0f7oP2batKfOsKvlaD2nwelQcflR2M4 Vq8e4sz3UjsqUC6OqskXgQqzA4fJ5xSNLynvb8Z+0yuCkmzf+9dv7vVwrf5qA5wjLQ8EAL diPyI+1TgTITkwL4qKBNJJ/u1hYZiUU= X-MC-Unique: BK9KxfoQOua6I_1svi9yig-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 30/30] nodedev: avoid delay when defining a new mdev Date: Fri, 26 Mar 2021 11:48:26 -0500 Message-Id: <20210326164826.1720062-31-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.13 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 calling virNodeDeviceDefineXML() to define a new mediated device, we call virMdevctlDefine() and then wait for the new device to appear in the driver's device list before returning. This caused long delays due to the behavior of nodeDeviceFindNewMediatedDevice(). This function checks to see if the device is in the list and then waits for 5s before checking again. Because mdevctl is relatively slow to query the list of defined devices[0], the newly-defined device was generally not in the device list when we first checked. This results in libvirt almost always taking at least 5s to complete this API call for mediated devices, which is unacceptable. In order to avoid this long delay, we resort to a workaround. If the call to virMdevctlDefine() was successful, we can assume that this new device will exist the next time we query mdevctl for new devices. So we simply add this provisional device definition directly to the nodedev driver's device list and return from the function. At some point in the future, the mdevctl handler will run and the "official" device will be processed, which will update the provisional device if any new details need to be added. The reason that this is not necessary for virNodeDeviceCreateXML() is because detecting newly-created (not defined) mdevs happens through udev instead of mdevctl. And nodeDeviceFindNewMediatedDevice() always calls 'udevadm settle' before checking to see whether the device is in the list. This allows us to wait just long enough for all udev events to be processed, so the device is almost always in the list the first time we check and so we almost never end up hitting the 5s sleep. [0] on my machine, 'mdevctl list --defined' took around 0.8s to complete for only 3 defined mdevs. Reviewed-by: Erik Skultety --- src/node_device/node_device_driver.c | 126 +++++++++++++++------------ 1 file changed, 68 insertions(+), 58 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 35db24817a..a1b79d93f7 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1215,16 +1215,70 @@ nodeDeviceDestroy(virNodeDevicePtr device) return ret; } =20 + +/* takes ownership of @def and potentially frees it. @def should not be us= ed + * after returning from this function */ +static int +nodeDeviceUpdateMediatedDevice(virNodeDeviceDef *def) +{ + virNodeDeviceObj *obj; + virObjectEvent *event; + bool defined =3D false; + g_autoptr(virNodeDeviceDef) owned =3D def; + g_autofree char *name =3D g_strdup(owned->name); + + owned->driver =3D g_strdup("vfio_mdev"); + + if (!(obj =3D virNodeDeviceObjListFindByName(driver->devs, owned->name= ))) { + virNodeDeviceDef *d =3D g_steal_pointer(&owned); + if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, d))) { + virNodeDeviceDefFree(d); + return -1; + } + } else { + bool changed; + virNodeDeviceDef *olddef =3D virNodeDeviceObjGetDef(obj); + + defined =3D virNodeDeviceObjIsPersistent(obj); + /* Active devices contain some additional information (e.g. sysfs + * path) that is not provided by mdevctl, so re-use the existing + * definition and copy over new mdev data */ + changed =3D nodeDeviceDefCopyFromMdevctl(olddef, owned); + + if (defined && !changed) { + /* if this device was already defined and the definition + * hasn't changed, there's nothing to do for this device */ + virNodeDeviceObjEndAPI(&obj); + return 0; + } + } + + /* all devices returned by virMdevctlListDefined() are persistent */ + virNodeDeviceObjSetPersistent(obj, true); + + if (!defined) + event =3D virNodeDeviceEventLifecycleNew(name, + VIR_NODE_DEVICE_EVENT_DEFIN= ED, + 0); + else + event =3D virNodeDeviceEventUpdateNew(name); + + virNodeDeviceObjEndAPI(&obj); + virObjectEventStateQueue(driver->nodeDeviceEventState, event); + + return 0; +} + virNodeDevice* -nodeDeviceDefineXML(virConnect *conn, +nodeDeviceDefineXML(virConnectPtr conn, const char *xmlDesc, unsigned int flags) { g_autoptr(virNodeDeviceDef) def =3D NULL; - virNodeDevice *device =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); =20 @@ -1264,9 +1318,19 @@ nodeDeviceDefineXML(virConnect *conn, } =20 mdevGenerateDeviceName(def); - device =3D nodeDeviceFindNewMediatedDevice(conn, def->caps->data.mdev.= uuid); + name =3D g_strdup(def->name); + + /* Normally we would call nodeDeviceFindNewMediatedDevice() here to wa= it + * for the new device to appear. But mdevctl can take a while to query + * devices, and if nodeDeviceFindNewMediatedDevice() doesn't find the = new + * device immediately it will wait at 5s before checking again. Since = we + * have already received the uuid from virMdevctlDefine(), we can simp= ly + * add the provisional device to the list and return it immediately and + * avoid this long delay. */ + if (nodeDeviceUpdateMediatedDevice(g_steal_pointer(&def)) < 0) + return NULL; =20 - return device; + return virGetNodeDevice(conn, name); } =20 =20 @@ -1506,60 +1570,6 @@ removeMissingPersistentMdevs(virNodeDeviceObj *obj, } =20 =20 -/* takes ownership of @def and potentially frees it. @def should not be us= ed - * after returning from this function */ -static int -nodeDeviceUpdateMediatedDevice(virNodeDeviceDef *def) -{ - virNodeDeviceObj *obj; - virObjectEvent *event; - bool defined =3D false; - g_autoptr(virNodeDeviceDef) owned =3D def; - g_autofree char *name =3D g_strdup(owned->name); - - owned->driver =3D g_strdup("vfio_mdev"); - - if (!(obj =3D virNodeDeviceObjListFindByName(driver->devs, owned->name= ))) { - virNodeDeviceDef *d =3D g_steal_pointer(&owned); - if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, d))) { - virNodeDeviceDefFree(d); - return -1; - } - } else { - bool changed; - virNodeDeviceDef *olddef =3D virNodeDeviceObjGetDef(obj); - - defined =3D virNodeDeviceObjIsPersistent(obj); - /* Active devices contain some additional information (e.g. sysfs - * path) that is not provided by mdevctl, so re-use the existing - * definition and copy over new mdev data */ - changed =3D nodeDeviceDefCopyFromMdevctl(olddef, owned); - - if (defined && !changed) { - /* if this device was already defined and the definition - * hasn't changed, there's nothing to do for this device */ - virNodeDeviceObjEndAPI(&obj); - return 0; - } - } - - /* all devices returned by virMdevctlListDefined() are persistent */ - virNodeDeviceObjSetPersistent(obj, true); - - if (!defined) - event =3D virNodeDeviceEventLifecycleNew(name, - VIR_NODE_DEVICE_EVENT_DEFIN= ED, - 0); - else - event =3D virNodeDeviceEventUpdateNew(name); - - virNodeDeviceObjEndAPI(&obj); - virObjectEventStateQueue(driver->nodeDeviceEventState, event); - - return 0; -} - - int nodeDeviceUpdateMediatedDevices(void) { --=20 2.26.3