From nobody Mon Feb 9 11:05:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692867473; cv=none; d=zohomail.com; s=zohoarc; b=jMTKwuKB9R9pKM7maWYEAy/Z6K5slRFBu3CWiDQ4bxLETIwp+7Ep6spp8zqnaZPDfHWQc5wBW6F2vRPh5ewhJjvoljiYe9YigVe9AqxNWWoY10nKcQRa26Enn0zqClyfOQqc/dAKve74B47pcCcilo/b2KLRvj+MoHT8dnz/9X8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692867473; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=r8kpM9GQan1L/4Y0hN64JKNopZcNLQMA9cUXdi/AS94=; b=jSCvPraqOUPPhSPsCxo8/5z2inkqiCkZ88TRlLaJlB8mv4ZxMk4+faAWr+9oPx2HNTHygUlXaCuALxph5u9Re8G2Hn8cZfzXktwgWoTscBWV2B0VEdnOXq+4S8okCiSthYDQNMiJCxzT4fkas2vkCXqKyB1oeZ8Pu6eelc2BpNo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1692867473795414.57010822138227; Thu, 24 Aug 2023 01:57:53 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-154-VhZnC3vNPpu-4CbG9OG2JQ-1; Thu, 24 Aug 2023 04:57:51 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E1D218D40A1; Thu, 24 Aug 2023 08:57:47 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id C8FE82026D2C; Thu, 24 Aug 2023 08:57:47 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 874CF194658C; Thu, 24 Aug 2023 08:57:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E924A1946589 for ; Thu, 24 Aug 2023 08:57:44 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D65771121315; Thu, 24 Aug 2023 08:57:44 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DD501121314 for ; Thu, 24 Aug 2023 08:57:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692867472; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=r8kpM9GQan1L/4Y0hN64JKNopZcNLQMA9cUXdi/AS94=; b=WXK5iJ5RyPffrx9x794/IhqbAMoHq/cIwMPKd8M0ObZggtc3wKZqI/iSSfpfYLFHf5s28A qP6T45FFrqhfDrVWUONg6zTgzuNJky9p3ucIGmf+rwjjJozXbgHq2/+T6Y4728XUZINLig a1mbBwmT0olKbk1IyIRGCr5kbiq3/M4= X-MC-Unique: VhZnC3vNPpu-4CbG9OG2JQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/6] node_device_driver: Deduplicate mediated devices listing Date: Thu, 24 Aug 2023 10:57:38 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692867475480100004 Content-Type: text/plain; charset="utf-8"; x-default="true" We have virMdevctlListDefined() to list defined mdevs, and virMdevctlListActive() to list active mdevs. Both have the same body except for one boolean argument passed to nodeDeviceGetMdevctlListCommand(). Join the two functions under virMdevctlList() name and introduce @defined argument that is then just passed to the cmd line builder function. Signed-off-by: Michal Privoznik --- src/node_device/node_device_driver.c | 30 ++++++---------------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 593bc64e25..ac50c96837 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1636,32 +1636,14 @@ nodeDeviceGenerateName(virNodeDeviceDef *def, =20 =20 static int -virMdevctlListDefined(virNodeDeviceDef ***devs, char **errmsg) +virMdevctlList(bool defined, + virNodeDeviceDef ***devs, + char **errmsg) { int status; g_autofree char *output =3D NULL; g_autofree char *errbuf =3D NULL; - g_autoptr(virCommand) cmd =3D nodeDeviceGetMdevctlListCommand(true, &o= utput, &errbuf); - - if (virCommandRun(cmd, &status) < 0 || status !=3D 0) { - *errmsg =3D g_steal_pointer(&errbuf); - return -1; - } - - if (!output) - return -1; - - return nodeDeviceParseMdevctlJSON(output, devs); -} - - -static int -virMdevctlListActive(virNodeDeviceDef ***devs, char **errmsg) -{ - int status; - g_autofree char *output =3D NULL; - g_autofree char *errbuf =3D NULL; - g_autoptr(virCommand) cmd =3D nodeDeviceGetMdevctlListCommand(false, &= output, &errbuf); + g_autoptr(virCommand) cmd =3D nodeDeviceGetMdevctlListCommand(defined,= &output, &errbuf); =20 if (virCommandRun(cmd, &status) < 0 || status !=3D 0) { *errmsg =3D g_steal_pointer(&errbuf); @@ -1750,7 +1732,7 @@ nodeDeviceUpdateMediatedDevices(void) return 0; } =20 - if ((data.ndefs =3D virMdevctlListDefined(&defs, &errmsg)) < 0) { + if ((data.ndefs =3D virMdevctlList(true, &defs, &errmsg)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to query mdevs from mdevctl: %1$s"), errm= sg); return -1; @@ -1767,7 +1749,7 @@ nodeDeviceUpdateMediatedDevices(void) return -1; =20 /* Update active/transient mdev devices */ - if ((act_ndefs =3D virMdevctlListActive(&act_defs, &errmsg)) < 0) { + if ((act_ndefs =3D virMdevctlList(false, &act_defs, &errmsg)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to query mdevs from mdevctl: %1$s"), errm= sg); return -1; --=20 2.41.0