From nobody Mon Feb 9 06:50:22 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532534352066693.2192013931328; Wed, 25 Jul 2018 08:59:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C120C308FB9C; Wed, 25 Jul 2018 15:59: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 8AEF0308BDB1; Wed, 25 Jul 2018 15:59: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 391BB14B09; Wed, 25 Jul 2018 15:59:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6PFwcwN025792 for ; Wed, 25 Jul 2018 11:58:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id BBE0B7C56; Wed, 25 Jul 2018 15:58:38 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E0067C4B; Wed, 25 Jul 2018 15:58:38 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 25 Jul 2018 17:57:55 +0200 Message-Id: <1f630ef395c868e56efe9acf61f196891667551f.1532533587.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH RFC 24/39] qemu: command: format disk source commandline for -blockdev 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 25 Jul 2018 15:59:11 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Format the backing chain onto the commandline using the 'json' syntax with -blockdev. The command line formatter needs only minor tweaks to add the new entries but we now need to initialize the strucutres that are used for every layer of the backing chain. Signed-off-by: Peter Krempa --- src/qemu/qemu_command.c | 84 ++++++++++++++++++++++++++++++++++++++++++++-= ---- 1 file changed, 76 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index ae45c45b7f..7fa366cd3f 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2237,6 +2237,8 @@ static int qemuBuildBlockStorageSourceAttachDataCommandline(virCommandPtr cmd, qemuBlockStorageSourceAtt= achDataPtr data) { + char *tmp; + if (qemuBuildObjectCommandline(cmd, data->prmgrProps) < 0 || qemuBuildObjectCommandline(cmd, data->authsecretProps) < 0 || qemuBuildObjectCommandline(cmd, data->encryptsecretProps) < 0 || @@ -2246,6 +2248,22 @@ qemuBuildBlockStorageSourceAttachDataCommandline(vir= CommandPtr cmd, if (data->driveCmd) virCommandAddArgList(cmd, "-drive", data->driveCmd, NULL); + if (data->storageProps) { + if (!(tmp =3D virJSONValueToString(data->storageProps, false))) + return -1; + + virCommandAddArgList(cmd, "-blockdev", tmp, NULL); + VIR_FREE(tmp); + } + + if (data->formatProps) { + if (!(tmp =3D virJSONValueToString(data->formatProps, false))) + return -1; + + virCommandAddArgList(cmd, "-blockdev", tmp, NULL); + VIR_FREE(tmp); + } + return 0; } @@ -2256,21 +2274,71 @@ qemuBuildDiskSourceCommandLine(virCommandPtr cmd, virQEMUCapsPtr qemuCaps, bool driveBoot) { - qemuBlockStorageSourceAttachDataPtr data =3D NULL; + qemuBlockStorageSourceAttachDataPtr *data =3D NULL; + size_t ndata =3D 0; + qemuBlockStorageSourceAttachDataPtr tmp =3D NULL; + virJSONValuePtr copyOnReadProps =3D NULL; + virStorageSourcePtr n; + char *str =3D NULL; + size_t i; int ret =3D -1; - if (!(data =3D qemuBuildStorageSourceAttachPrepareDrive(disk, qemuCaps, - driveBoot))) - return -1; + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) { + if (virStorageSourceIsEmpty(disk->src)) { + ret =3D 0; + goto cleanup; + } - if (qemuBuildStorageSourceAttachPrepareCommon(disk->src, data, qemuCap= s) < 0 || - qemuBuildBlockStorageSourceAttachDataCommandline(cmd, data) < 0) - goto cleanup; + for (n =3D disk->src; virStorageSourceIsBacking(n); n =3D n->backi= ngStore) { + if (!(tmp =3D qemuBlockStorageSourceAttachPrepareBlockdev(n))) + goto cleanup; + + if (qemuBuildStorageSourceAttachPrepareCommon(n, tmp, qemuCaps= ) < 0) + goto cleanup; + + if (VIR_APPEND_ELEMENT(data, ndata, tmp) < 0) + goto cleanup; + } + + if (disk->copy_on_read =3D=3D VIR_TRISTATE_SWITCH_ON && + !(copyOnReadProps =3D qemuBlockStorageGetCopyOnReadProps(disk)= )) + goto cleanup; + } else { + if (!(tmp =3D qemuBuildStorageSourceAttachPrepareDrive(disk, qemuC= aps, + driveBoot))) + goto cleanup; + + if (qemuBuildStorageSourceAttachPrepareCommon(disk->src, tmp, + qemuCaps) < 0) + goto cleanup; + + if (VIR_APPEND_ELEMENT(data, ndata, tmp) < 0) + goto cleanup; + } + + for (i =3D ndata; i > 0; i--) { + if (qemuBuildBlockStorageSourceAttachDataCommandline(cmd, + data[i - 1]) = < 0) + goto cleanup; + } + + if (copyOnReadProps) { + if (!(str =3D virJSONValueToString(copyOnReadProps, false))) + goto cleanup; + + virCommandAddArgList(cmd, "-blockdev", str, NULL); + VIR_FREE(str); + } ret =3D 0; cleanup: - qemuBlockStorageSourceAttachDataFree(data); + for (i =3D 0; i < ndata; i++) + qemuBlockStorageSourceAttachDataFree(data[i]); + VIR_FREE(data); + qemuBlockStorageSourceAttachDataFree(tmp); + virJSONValueFree(copyOnReadProps); + VIR_FREE(str); return ret; } --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list