From nobody Mon Feb 9 03:29:20 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=1633620780; cv=none; d=zohomail.com; s=zohoarc; b=lzFyRO9ZdzE+X4D0/M4xASssegxIYtnkP29sln35l4D/Q+9ifXpWyVZzW/rd8bK577BqrVWBiMaL7R+xbuKbbaQ0YZQ3VpcwXp+0XWgHrhttQosF9R5nJHCB7oMhRv8IpGAUjmIqpUpMUwz51Ojib8e4b/9Mh55obM9C/GbemC4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633620780; 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=bm2GCx3NFTknpodQ50qLBloKjW6n4pLXOyciA/A2aV0=; b=neJsOqe8ROnYLbDTHojqZQzhrM//ZRVttv04RsG4GLdNHlozF+9efP5kIqYzudC2zG0qy75OkCRAZgduRQJwGb9XY6K3Nd9fpsNUcwOmVFwom31+TOnfFxO4Uvm+DEDweQKjMDDYei6wD1c7UFUojaM6sjTCF+irUOTgG0iI2CU= 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 1633620780837595.384494854323; Thu, 7 Oct 2021 08:33: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-580-6EpHAwqaOGifxZLcmm2WlQ-1; Thu, 07 Oct 2021 11:32:57 -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 50B2A10B6B91; Thu, 7 Oct 2021 15:26:15 +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 87C2610843AE; Thu, 7 Oct 2021 15:26:13 +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 47F971803B30; Thu, 7 Oct 2021 15:26:13 +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 197FJ9pJ023830 for ; Thu, 7 Oct 2021 11:19:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 00C225D6D5; Thu, 7 Oct 2021 15:19:09 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 627505D6BA for ; Thu, 7 Oct 2021 15:19:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633620779; 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=bm2GCx3NFTknpodQ50qLBloKjW6n4pLXOyciA/A2aV0=; b=ZHfQK739F9WswElpCkFxHryVDK1inzb+hi3pw/qHOGv4/hwRep9JJT7Ser6EMFExmWfJFK o06Wk2roxEYhfPIjslexv1lGLzRAvx8rf2Ykx8bCAamQiziC8jk2RyCDHAIKAy7zovl+rb RlSSHIqYuOD4urB3+cY41fojk31CG/k= X-MC-Unique: 6EpHAwqaOGifxZLcmm2WlQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 033/103] qemu: command: Introduce JSON equivalent of qemuBuildDeviceAddressStr Date: Thu, 7 Oct 2021 17:17:21 +0200 Message-Id: <7a68fa85ea7b7d3cbbc833266bbd225532189499.1633619630.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.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) X-ZM-MESSAGEID: 1633620782510100043 Content-Type: text/plain; charset="utf-8" Upcoming patches will start converting the formatting of arguments for -device from a string to JSON so that we can keep proper types around when using it via QMP. This means we will need an equivalet for the device address builder function. 'qemuBuildDeviceAddressProps' provides equal functionality, but the output differs for fields where a number is expected, where we've previously formatted a hex value but now end up with a decimal value per JSON standard. For given address types I've selected an example device and used '-device $DEV,help' to obtain the current types recognized by qemu: Note that 'bus' is not shown below, but it's already a string so we can keep using it as a string. VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI (virtio-balloon-pci) acpi-index=3D - (default: 0) addr=3D - Slot and optional function number, example: 06= .0 or 06 (default: -1) multifunction=3D - on/off (default: false) Note that 'addr' is here defined as 'int32' but in fact internally in qemu is an alternate type between a number and a string so we can keep using strings here. VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB (usb-tablet) port=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO (spapr-vty) reg=3D - (default: 4294967295) VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW (virtio-blk-cww) devno=3D - Identifier of an I/O device in the channel sub= system, example: fe.1.23ab VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA (isa-serial) iobase=3D - (default: 4294967295) irq=3D - (default: 4294967295) VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM (pc-dimm) slot=3D - (default: -1) addr=3D - (default: 0) Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_command.c | 101 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 56acd9a109..565b1970dc 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -416,7 +416,7 @@ qemuBuildDeviceAddressPCIStr(virBuffer *buf, } -static int +static int G_GNUC_UNUSED qemuBuildDeviceAddressStr(virBuffer *buf, const virDomainDef *domainDef, virDomainDeviceInfo *info) @@ -484,6 +484,105 @@ qemuBuildDeviceAddressStr(virBuffer *buf, } +static int G_GNUC_UNUSED +qemuBuildDeviceAddressProps(virJSONValue *props, + const virDomainDef *domainDef, + virDomainDeviceInfo *info) +{ + switch ((virDomainDeviceAddressType) info->type) { + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: { + g_autofree char *pciaddr =3D NULL; + + if (info->addr.pci.function !=3D 0) + pciaddr =3D g_strdup_printf("0x%x.0x%x", info->addr.pci.slot, = info->addr.pci.function); + else + pciaddr =3D g_strdup_printf("0x%x", info->addr.pci.slot); + + if (virJSONValueObjectAdd(props, + "F:bus", qemuBuildDeviceAddressPCIGetBus= (domainDef, info), + "T:multifunction", info->addr.pci.multi, + "s:addr", pciaddr, + "p:acpi-index", info->acpiIndex, + NULL) < 0) + return -1; + + return 0; + } + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB: { + const char *contAlias =3D NULL; + g_auto(virBuffer) port =3D VIR_BUFFER_INITIALIZER; + + if (!(contAlias =3D virDomainControllerAliasFind(domainDef, + VIR_DOMAIN_CONTROLL= ER_TYPE_USB, + info->addr.usb.bus)= )) + return -1; + + virDomainUSBAddressPortFormatBuf(&port, info->addr.usb.port); + + if (virJSONValueObjectAdd(props, + "f:bus", g_strdup_printf("%s.0", contAli= as), + "S:port", virBufferCurrentContent(&port), + NULL) < 0) + return -1; + + return 0; + } + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO: + if (info->addr.spaprvio.has_reg) { + if (virJSONValueObjectAdd(props, + "P:reg", info->addr.spaprvio.reg, + NULL) < 0) + return -1; + } + return 0; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW: { + g_autofree char *devno =3D g_strdup_printf("%x.%x.%04x", + info->addr.ccw.cssid, + info->addr.ccw.ssid, + info->addr.ccw.devno); + + if (virJSONValueObjectAdd(props, "s:devno", devno, NULL) < 0) + return -1; + + return 0; + } + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA: + if (virJSONValueObjectAdd(props, + "u:iobase", info->addr.isa.iobase, + "p:irq", info->addr.isa.irq, + NULL) < 0) + return -1; + + return 0; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM: + if (virJSONValueObjectAdd(props, + "u:slot", info->addr.dimm.slot, + "P:addr", info->addr.dimm.base, + NULL) < 0) + return -1; + + return 0; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE: + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE: + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL: + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID: + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390: + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO: + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED: + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST: + default: + return 0; + } +} + + /** * qemuBuildVirtioDevStr * @buf: virBuffer * to append the built string --=20 2.31.1