From nobody Thu May 2 06:54:18 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; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.ibm.com 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 1625838059381205.85491130095147; Fri, 9 Jul 2021 06:40:59 -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-407-cXSQKJLSO4yDqkliMoL1ZQ-1; Fri, 09 Jul 2021 09:40:56 -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 151F81835919; Fri, 9 Jul 2021 13:40:51 +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 AA6825C1CF; Fri, 9 Jul 2021 13:40:50 +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 C0D814EA2F; Fri, 9 Jul 2021 13:40:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 169De2QU031422 for ; Fri, 9 Jul 2021 09:40:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id C312A1043DFF; Fri, 9 Jul 2021 13:40:02 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BEA931043DEC for ; Fri, 9 Jul 2021 13:39:59 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2807F18A6532 for ; Fri, 9 Jul 2021 13:39:59 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-196-mgY22e-NO8mAk-SuvmdZOw-1; Fri, 09 Jul 2021 09:39:56 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 169DWrkr180887; Fri, 9 Jul 2021 09:39:55 -0400 Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0a-001b2d01.pphosted.com with ESMTP id 39phqksx4p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Jul 2021 09:39:55 -0400 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 169DapPN009726; Fri, 9 Jul 2021 13:39:52 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma02fra.de.ibm.com with ESMTP id 39jfh89ewx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Jul 2021 13:39:52 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 169DdnlO35783050 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 9 Jul 2021 13:39:49 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A6B20A4060; Fri, 9 Jul 2021 13:39:49 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 80F3CA405F; Fri, 9 Jul 2021 13:39:49 +0000 (GMT) Received: from localhost.localdomain (unknown [9.145.86.105]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 9 Jul 2021 13:39:49 +0000 (GMT) X-MC-Unique: cXSQKJLSO4yDqkliMoL1ZQ-1 X-MC-Unique: mgY22e-NO8mAk-SuvmdZOw-1 From: Boris Fiuczynski To: libvir-list@redhat.com Subject: [PATCH] nodedev: fix error when no defined mdev exist Date: Fri, 9 Jul 2021 15:39:47 +0200 Message-Id: <20210709133947.17484-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: dknWdjHrEcTDR7rGLgN96O0HaxAo7sYB X-Proofpoint-GUID: dknWdjHrEcTDR7rGLgN96O0HaxAo7sYB X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-09_06:2021-07-09, 2021-07-09 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 spamscore=0 lowpriorityscore=0 adultscore=0 suspectscore=0 priorityscore=1501 mlxscore=0 malwarescore=0 phishscore=0 mlxlogscore=965 clxscore=1015 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107090067 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: jjongsma@redhat.com, shalini@linux.ibm.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-ZM-MESSAGEID: 1625838060679100001 Content-Type: text/plain; charset="utf-8" Commit e9b534905f4 introduced an error when parsing an empty list returned from mdevctl. This occurs e.g. if nodedev-undefine is used to undefine the last defined mdev which cuases the following error messages libvirtd[33143]: internal error: Unexpected format for mdevctl response libvirtd[33143]: internal error: failed to query mdevs from mdevctl: libvirtd[33143]: mdevctl failed to updated mediated devices Signed-off-by: Boris Fiuczynski --- src/node_device/node_device_driver.c | 68 ++++++++++--------- .../mdevctl-list-empty.json | 1 + .../mdevctl-list-empty.out.xml | 0 tests/nodedevmdevctltest.c | 1 + 4 files changed, 37 insertions(+), 33 deletions(-) create mode 100644 tests/nodedevmdevctldata/mdevctl-list-empty.json create mode 100644 tests/nodedevmdevctldata/mdevctl-list-empty.out.xml diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index b4dd57e5f4..31525f2312 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1123,51 +1123,53 @@ nodeDeviceParseMdevctlJSON(const char *jsonstring, /* 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; - } - - n =3D virJSONValueObjectKeysNumber(obj); - for (i =3D 0; i < n; i++) { - const char *parent; - virJSONValue *child_array; - int nchildren; + if (virJSONValueArraySize(json_devicelist) > 0) { + if (virJSONValueArraySize(json_devicelist) !=3D 1) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unexpected format for mdevctl response")); + goto error; + } =20 - /* 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); + obj =3D virJSONValueArrayGet(json_devicelist, 0); =20 - if (!virJSONValueIsArray(child_array)) { + if (!virJSONValueIsObject(obj)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Parent device's JSON object data is not an a= rray")); + _("device list is not an object")); goto error; } =20 - nchildren =3D virJSONValueArraySize(child_array); + n =3D virJSONValueObjectKeysNumber(obj); + for (i =3D 0; i < n; i++) { + const char *parent; + virJSONValue *child_array; + int nchildren; =20 - for (j =3D 0; j < nchildren; j++) { - g_autoptr(virNodeDeviceDef) child =3D NULL; - virJSONValue *child_obj =3D virJSONValueArrayGet(child_array, = j); + /* The key of each object property is the name of a parent dev= ice + * which maps to an array of child devices */ + parent =3D virJSONValueObjectGetKey(obj, i); + child_array =3D virJSONValueObjectGetValue(obj, i); =20 - if (!(child =3D nodeDeviceParseMdevctlChildDevice(parent, chil= d_obj))) { + if (!virJSONValueIsArray(child_array)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to parse child device")); + _("Parent device's JSON object data is not = an array")); goto error; } =20 - if (VIR_APPEND_ELEMENT(outdevs, noutdevs, child) < 0) - 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_arr= ay, j); + + if (!(child =3D nodeDeviceParseMdevctlChildDevice(parent, = child_obj))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to parse child device")); + goto error; + } + + if (VIR_APPEND_ELEMENT(outdevs, noutdevs, child) < 0) + goto error; + } } } =20 diff --git a/tests/nodedevmdevctldata/mdevctl-list-empty.json b/tests/noded= evmdevctldata/mdevctl-list-empty.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/tests/nodedevmdevctldata/mdevctl-list-empty.json @@ -0,0 +1 @@ +[] diff --git a/tests/nodedevmdevctldata/mdevctl-list-empty.out.xml b/tests/no= dedevmdevctldata/mdevctl-list-empty.out.xml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 8ba1d2da70..e246de4d87 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -360,6 +360,7 @@ mymain(void) =20 DO_TEST_LIST_DEFINED(); =20 + DO_TEST_PARSE_JSON("mdevctl-list-empty"); DO_TEST_PARSE_JSON("mdevctl-list-multiple"); =20 DO_TEST_DEFINE("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); --=20 2.31.1