From nobody Sun May 5 18:43:10 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=1623349021; cv=none; d=zohomail.com; s=zohoarc; b=I0g1JkQgm8k/RDok7AIVw0sKGyLzU67NX4tJtYd4PAHGLWAdi54CO3iZT+/lYTGfhfXEXWVASA3qWjvtT/TrnBzdxPumrb3bm/vnAmtkQi59BqY5X6bmoNS2LYf7FoHjCaiEuIIRt+Id6DYI4gQWhd6LGDdHoJ9qDkijnSFAzu4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623349021; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=9stXWpvU6jJZbWMMcsWsIx05K9xhclNeyqINayV0gLc=; b=CHeqaBjaeB5ms+pqVdozs4ySWBcMgVDFxxf+oX81QpPT5c4WbLtDsUgASyI+DLEyvT9CASdurSlm/1mGjydS3r4dOaTDD5kym6+o0207u0njiSnqFOAmcwPu/jXukhl2K/x11fbGzQm5o36Gdhmnybiq8dImlVGMnkk3KHtP7wI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1623349021193745.3361871979909; Thu, 10 Jun 2021 11:17:01 -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-201-CyrG8Eg5N0y2O5axMlzJXw-1; Thu, 10 Jun 2021 14:16:58 -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 4BCC091278; Thu, 10 Jun 2021 18:16: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 3D90F60C04; Thu, 10 Jun 2021 18:16: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 7C4B11809CAD; Thu, 10 Jun 2021 18:16:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15AIFifo028864 for ; Thu, 10 Jun 2021 14:15:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id D62CE5C1CF; Thu, 10 Jun 2021 18:15:44 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-229.phx2.redhat.com [10.3.113.229]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A7FAE5C1C5 for ; Thu, 10 Jun 2021 18:15:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623349020; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=9stXWpvU6jJZbWMMcsWsIx05K9xhclNeyqINayV0gLc=; b=NhW56bEBujMfWRJsWb1zQiol8b/+C6+8pT5xXsfQPjcFVmvc5W9DLY6a3EBuS+vGQL77dZ dEDeAy6EubF8EBcHwhT965114Kka5hw/XBcawPJcMPGkVF5JLynfB43XMQhOEEL0+blvJA ywytm7wD7B0cTtylBOMPeYmpL2fGrEc= X-MC-Unique: CyrG8Eg5N0y2O5axMlzJXw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH] nodedev: handle mdevs from multiple parents Date: Thu, 10 Jun 2021 13:15:37 -0500 Message-Id: <20210610181537.4178380-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.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" Due to a rather unfortunate misunderstanding, we were parsing the list of defined devices from mdevctl incorrectly. Since my primary development machine only has a single device capable of mdevs, I apparently neglected to test multiple parent devices and made some assumptions based on reading the mdevctl code. These assumptions turned out to be incorrect, so the parsing failed when devices from more than one parent device were returned. The details: mdevctl returns an array of objects representing the defined devices. But instead of an array of multiple objects (with each object representing a parent device), the array always contains only a single object. That object has a separate property for each parent device. Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- src/node_device/node_device_driver.c | 41 ++++++++++--------- .../mdevctl-list-multiple.json | 4 +- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 8a0a2c3847..cb2c3ceaa4 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1056,6 +1056,7 @@ nodeDeviceParseMdevctlJSON(const char *jsonstring, size_t noutdevs =3D 0; size_t i; size_t j; + virJSONValue *obj; =20 json_devicelist =3D virJSONValueFromString(jsonstring); =20 @@ -1065,31 +1066,33 @@ nodeDeviceParseMdevctlJSON(const char *jsonstring, goto error; } =20 - n =3D virJSONValueArraySize(json_devicelist); + /* mdevctl list --dumpjson produces an output that is an array that + * contains only a single object which contains a property for each pa= rent + * device */ + if (virJSONValueArraySize(json_devicelist) !=3D 1) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unexpected format for mdevctl response")); + goto error; + } + + obj =3D virJSONValueArrayGet(json_devicelist, 0); + + if (!virJSONValueIsObject(obj)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("device list is not an object")); + goto error; + } =20 + n =3D virJSONValueObjectKeysNumber(obj); for (i =3D 0; i < n; i++) { - virJSONValue *obj =3D virJSONValueArrayGet(json_devicelist, i); const char *parent; virJSONValue *child_array; int nchildren; =20 - 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); + /* The key of each object property is the name of a parent device + * which maps to an array of child devices */ + parent =3D virJSONValueObjectGetKey(obj, i); + child_array =3D virJSONValueObjectGetValue(obj, i); =20 if (!virJSONValueIsArray(child_array)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/tests/nodedevmdevctldata/mdevctl-list-multiple.json b/tests/no= dedevmdevctldata/mdevctl-list-multiple.json index eefcd90c62..ca1918d00a 100644 --- a/tests/nodedevmdevctldata/mdevctl-list-multiple.json +++ b/tests/nodedevmdevctldata/mdevctl-list-multiple.json @@ -24,9 +24,7 @@ ] } } - ] - }, - { + ], "matrix": [ { "783e6dbb-ea0e-411f-94e2-717eaad438bf": { "mdev_type": "vfio_ap-passthrough", --=20 2.31.1