From nobody Wed May 14 13:20:41 2025 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 1523372946041194.87451294865298; Tue, 10 Apr 2018 08:09:06 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2263B10790F; Tue, 10 Apr 2018 15:09:04 +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 22BE799DE0; Tue, 10 Apr 2018 15:07:43 +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 B32C118033EB; Tue, 10 Apr 2018 15:00:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3AEwNoO013427 for ; Tue, 10 Apr 2018 10:58:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 863CB2024CA4; Tue, 10 Apr 2018 14:58:23 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DFF02024CA7 for ; Tue, 10 Apr 2018 14:58:23 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 10 Apr 2018 16:58:10 +0200 Message-Id: <2763a150bc3939cb13412f6170e7a6fc53a0bbdc.1523372187.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 08/14] qemu: Generate cmd line at startup 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.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 10 Apr 2018 15:09:04 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This is the easier part. All we need to do here is put -object pr-manager-helper,id=3D$alias,path=3D$socketPath and then just reference the object in -drive file.pr-manager=3D$alias. Signed-off-by: Michal Privoznik --- src/qemu/qemu_command.c | 94 ++++++++++++++++++= ++++ src/qemu/qemu_command.h | 3 + .../disk-virtio-scsi-reservations.args | 35 ++++++++ tests/qemuxml2argvtest.c | 4 + 4 files changed, 136 insertions(+) create mode 100644 tests/qemuxml2argvdata/disk-virtio-scsi-reservations.ar= gs diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 514c3ab2ef..81f6025207 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1514,6 +1514,20 @@ qemuDiskSourceGetProps(virStorageSourcePtr src) } =20 =20 +static void +qemuBuildDriveSourcePR(virBufferPtr buf, + virStorageSourcePtr src) +{ + qemuDomainStorageSourcePrivatePtr srcPriv =3D QEMU_DOMAIN_STORAGE_SOUR= CE_PRIVATE(src); + qemuDomainDiskPRDPtr prd =3D srcPriv->prd; + + if (!prd || !prd->alias) + return; + + virBufferAsprintf(buf, ",file.pr-manager=3D%s", prd->alias); +} + + static int qemuBuildDriveSourceStr(virDomainDiskDefPtr disk, virQEMUCapsPtr qemuCaps, @@ -1591,6 +1605,8 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk, =20 if (disk->src->debug) virBufferAsprintf(buf, ",file.debug=3D%d", disk->src->debugLev= el); + + qemuBuildDriveSourcePR(buf, disk->src); } else { if (!(source =3D virQEMUBuildDriveCommandlineFromJSON(srcprops))) goto cleanup; @@ -9872,6 +9888,81 @@ qemuBuildPanicCommandLine(virCommandPtr cmd, } =20 =20 +/** + * qemuBuildPRManagerInfoProps: + * @prd: disk PR runtime info + * @propsret: JSON properties to return + * + * Build the JSON properties for the pr-manager object. + * + * Returns: 0 on success (@propsret is NULL if no properties are needed), + * -1 on failure (with error message set). + */ +int +qemuBuildPRManagerInfoProps(qemuDomainDiskPRDPtr prd, + virJSONValuePtr *propsret) +{ + *propsret =3D NULL; + + if (!prd || !prd->alias) + return 0; + + if (virJSONValueObjectCreate(propsret, + "s:path", prd->path, + NULL) < 0) + return -1; + + return 0; +} + + +static int +qemuBuildMasterPRCommandLine(virCommandPtr cmd, + const virDomainDef *def) +{ + size_t i; + bool managedAdded =3D false; + virJSONValuePtr props =3D NULL; + char *tmp =3D NULL; + int ret =3D -1; + + for (i =3D 0; i < def->ndisks; i++) { + const virDomainDiskDef *disk =3D def->disks[i]; + qemuDomainStorageSourcePrivatePtr srcPriv =3D QEMU_DOMAIN_STORAGE_= SOURCE_PRIVATE(disk->src); + qemuDomainDiskPRDPtr prd =3D srcPriv->prd; + + + if (virStoragePRDefIsManaged(disk->src->pr)) { + if (managedAdded) + continue; + + managedAdded =3D true; + } + + if (qemuBuildPRManagerInfoProps(prd, &props) < 0) + goto cleanup; + + if (!props) + continue; + + if (!(tmp =3D virQEMUBuildObjectCommandlineFromJSON("pr-manager-he= lper", + prd->alias, + props))) + goto cleanup; + virJSONValueFree(props); + props =3D NULL; + + virCommandAddArgList(cmd, "-object", tmp, NULL); + VIR_FREE(tmp); + } + + ret =3D 0; + cleanup: + virJSONValueFree(props); + return ret; +} + + /** * qemuBuildCommandLineValidate: * @@ -10024,6 +10115,9 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, if (qemuBuildMasterKeyCommandLine(cmd, priv) < 0) goto error; =20 + if (qemuBuildMasterPRCommandLine(cmd, def) < 0) + goto error; + if (enableFips) virCommandAddArg(cmd, "-enable-fips"); =20 diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 31c9da673c..32f3697181 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -54,6 +54,9 @@ virCommandPtr qemuBuildCommandLine(virQEMUDriverPtr drive= r, size_t *nnicindexes, int **nicindexes); =20 +/* Generate the object properties for pr-manager */ +int qemuBuildPRManagerInfoProps(qemuDomainDiskPRDPtr prd, + virJSONValuePtr *propsret); =20 /* Generate the object properties for a secret */ int qemuBuildSecretInfoProps(qemuDomainSecretInfoPtr secinfo, diff --git a/tests/qemuxml2argvdata/disk-virtio-scsi-reservations.args b/te= sts/qemuxml2argvdata/disk-virtio-scsi-reservations.args new file mode 100644 index 0000000000..195e83a048 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-virtio-scsi-reservations.args @@ -0,0 +1,35 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/home/test \ +USER=3Dtest \ +LOGNAME=3Dtest \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-i686 \ +-name QEMUGuest1 \ +-S \ +-object pr-manager-helper,id=3Dpr-helper0,\ +path=3D/tmp/lib/domain--1-QEMUGuest1/pr-helper0.sock \ +-object pr-manager-helper,id=3Dpr-helper-scsi0-0-0-1,\ +path=3D/path/to/qemu-pr-helper.sock \ +-M pc \ +-m 214 \ +-smp 8,sockets=3D8,cores=3D1,threads=3D1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-nographic \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,path=3D/tmp/lib/domain--1-QEMUGuest1/moni= tor.sock,\ +server,nowait \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dreadline \ +-no-acpi \ +-boot c \ +-device virtio-scsi-pci,id=3Dscsi0,num_queues=3D8,bus=3Dpci.0,addr=3D0x3 \ +-usb \ +-drive file=3D/dev/HostVG/QEMUGuest1,file.pr-manager=3Dpr-helper0,format= =3Draw,\ +if=3Dnone,id=3Ddrive-scsi0-0-0-0,boot=3Don \ +-device scsi-block,bus=3Dscsi0.0,channel=3D0,scsi-id=3D0,lun=3D0,\ +drive=3Ddrive-scsi0-0-0-0,id=3Dscsi0-0-0-0 \ +-drive file=3D/dev/HostVG/QEMUGuest2,file.pr-manager=3Dpr-helper-scsi0-0-0= -1,\ +format=3Draw,if=3Dnone,id=3Ddrive-scsi0-0-0-1 \ +-device scsi-block,bus=3Dscsi0.0,channel=3D0,scsi-id=3D0,lun=3D1,\ +drive=3Ddrive-scsi0-0-0-1,id=3Dscsi0-0-0-1 \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x4 diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 165137e93c..fdaeb473d0 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -3055,6 +3055,10 @@ mymain(void) QEMU_CAPS_PIIX_DISABLE_S3, QEMU_CAPS_PIIX_DISABLE_S4, QEMU_CAPS_ICH9_USB_EHCI1, QEMU_CAPS_PCI_MULTIFUNCTION); =20 + DO_TEST("disk-virtio-scsi-reservations", + QEMU_CAPS_DRIVE_BOOT, QEMU_CAPS_VIRTIO_SCSI, + QEMU_CAPS_SCSI_BLOCK, QEMU_CAPS_PR_MANAGER_HELPER); + /* Test disks with format probing enabled for legacy reasons. * New tests should not go in this section. */ driver.config->allowDiskFormatProbing =3D true; --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list