From: Peter Krempa Date: Thu, 11 Dec 2025 18:47:16 +0000 (+0100) Subject: qemu: Implement support for persistent reservation migration control X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d3ef7cb71979172de2c531d865e4525a314f902;p=thirdparty%2Flibvirt.git qemu: Implement support for persistent reservation migration control The 'migration' attribute for the '' element allows to control the persistent reservation migration feature independently of the machine type default. Add the XML plumbing and qemu support. We consider it ABI for now since it influences qemu migration protocol. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index f9f8719f1c..d1352a8fb1 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -3186,6 +3186,9 @@ paravirtualized driver is specified via the ``disk`` element. the socket, and finally ``mode`` which accepts one value ``client`` specifying the role of hypervisor. It's recommended to allow libvirt manage the persistent reservations. + :since:`Since 12.1.0` the ``migration`` (values ``yes``, ``no``) controls + whether the hypervisor should attempt to migrate persistent reservations + during migration. ``initiator`` :since:`Since 4.7.0`, the ``initiator`` element is supported for a disk ``type`` "network" that is using a ``source`` element with the diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 00b6e1970c..93b1175d21 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -21040,6 +21040,27 @@ virDomainDiskDefCheckABIStability(virDomainDiskDef *src, return false; } + /* While not guest visible it influences the qemu migration stream so + * we need to keep it identical */ + if (src->src->pr || dst->src->pr) { + virTristateBool srcmig = VIR_TRISTATE_BOOL_ABSENT; + virTristateBool dstmig = VIR_TRISTATE_BOOL_ABSENT; + + if (src->src->pr) + srcmig = src->src->pr->migration; + + if (dst->src->pr) + dstmig = dst->src->pr->migration; + + if (srcmig != dstmig) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target disk reservations 'migration' property %1$s does not match source %2$s"), + virTristateBoolTypeToString(dstmig), + virTristateBoolTypeToString(srcmig)); + return false; + } + } + if (!virDomainVirtioOptionsCheckABIStability(src->virtio, dst->virtio)) return false; diff --git a/src/conf/schemas/storagecommon.rng b/src/conf/schemas/storagecommon.rng index 14704c737e..450d53131f 100644 --- a/src/conf/schemas/storagecommon.rng +++ b/src/conf/schemas/storagecommon.rng @@ -104,6 +104,11 @@ + + + + + diff --git a/src/conf/storage_source_conf.c b/src/conf/storage_source_conf.c index d7b9bdfecb..e5f20fba80 100644 --- a/src/conf/storage_source_conf.c +++ b/src/conf/storage_source_conf.c @@ -331,6 +331,11 @@ virStoragePRDefParseXML(xmlXPathContextPtr ctxt) &prd->managed) < 0) goto cleanup; + if (virXMLPropTristateBool(ctxt->node, "migration", + VIR_XML_PROP_NONZERO, + &prd->migration) < 0) + goto cleanup; + type = virXPathString("string(./source[1]/@type)", ctxt); path = virXPathString("string(./source[1]/@path)", ctxt); mode = virXPathString("string(./source[1]/@mode)", ctxt); @@ -385,6 +390,11 @@ virStoragePRDefFormat(virBuffer *buf, { virBufferAsprintf(buf, "managed)); + + if (prd->migration != VIR_TRISTATE_BOOL_ABSENT) + virBufferAsprintf(buf, " migration='%s'", + virTristateBoolTypeToString(prd->migration)); + if (prd->path && (prd->managed == VIR_TRISTATE_BOOL_NO || !migratable)) { virBufferAddLit(buf, ">\n"); diff --git a/src/conf/storage_source_conf.h b/src/conf/storage_source_conf.h index 22c35d420d..d3a9b0e7a2 100644 --- a/src/conf/storage_source_conf.h +++ b/src/conf/storage_source_conf.h @@ -236,6 +236,8 @@ struct _virStoragePRDef { virTristateBool managed; char *path; + virTristateBool migration; + /* manager object alias */ char *mgralias; }; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 069211e139..c09c883a28 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1692,6 +1692,7 @@ qemuBuildDiskDeviceProps(const virDomainDef *def, g_autofree char *usbdiskalias = NULL; const virDomainDeviceInfo *deviceinfo = &disk->info; g_autoptr(virJSONValue) statistics = NULL; + virTristateBool migrate_pr = VIR_TRISTATE_BOOL_ABSENT; virDomainDeviceInfo usbSCSIinfo = { .type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE, .addr.drive = { .diskbus = VIR_DOMAIN_DISK_BUS_USB }, @@ -1717,6 +1718,8 @@ qemuBuildDiskDeviceProps(const virDomainDef *def, case VIR_DOMAIN_DISK_BUS_SCSI: if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) { driver = "scsi-block"; + if (disk->src->pr) + migrate_pr = disk->src->pr->migration; } else { if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) { driver = "scsi-cd"; @@ -1938,6 +1941,7 @@ qemuBuildDiskDeviceProps(const virDomainDef *def, "S:rerror", rpolicy, "A:stats-intervals", &statistics, "T:dpofua", disk->dpofua, /* SCSI-only, ensured by validation */ + "T:migrate-pr", migrate_pr, /* 'scsi-block' only, ensured by validation */ NULL) < 0) return NULL; diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 0bad299996..2ca38db9f1 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -3226,6 +3226,22 @@ qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk, } } + if (disk->src->pr && + disk->src->pr->migration != VIR_TRISTATE_BOOL_ABSENT) { + if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN || + disk->bus != VIR_DOMAIN_DISK_BUS_SCSI) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("persistent reservation migration supported only with 'lun' disks on 'scsi' bus")); + return -1; + } + + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_SCSI_BLOCK_MIGRATE_PR)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("persistent reservation migration not supported by this qemu")); + return -1; + } + } + if (disk->rotation_rate) { if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI && disk->bus != VIR_DOMAIN_DISK_BUS_IDE && diff --git a/tests/qemuxmlconfdata/disk-virtio-scsi-reservations.x86_64-latest.args b/tests/qemuxmlconfdata/disk-virtio-scsi-reservations.x86_64-latest.args index cbc2a0f398..f1d7a450ee 100644 --- a/tests/qemuxmlconfdata/disk-virtio-scsi-reservations.x86_64-latest.args +++ b/tests/qemuxmlconfdata/disk-virtio-scsi-reservations.x86_64-latest.args @@ -33,7 +33,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ -device '{"driver":"scsi-block","bus":"scsi0.0","channel":0,"scsi-id":0,"lun":0,"drive":"libvirt-2-storage","id":"scsi0-0-0-0","bootindex":1}' \ -object '{"qom-type":"pr-manager-helper","id":"pr-helper-libvirt-1-storage","path":"/path/to/qemu-pr-helper.sock"}' \ -blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest2","pr-manager":"pr-helper-libvirt-1-storage","node-name":"libvirt-1-storage","read-only":false}' \ --device '{"driver":"scsi-block","bus":"scsi0.0","channel":0,"scsi-id":0,"lun":1,"drive":"libvirt-1-storage","id":"scsi0-0-0-1"}' \ +-device '{"driver":"scsi-block","bus":"scsi0.0","channel":0,"scsi-id":0,"lun":1,"drive":"libvirt-1-storage","id":"scsi0-0-0-1","migrate-pr":true}' \ -audiodev '{"id":"audio1","driver":"none"}' \ -device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x4"}' \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ diff --git a/tests/qemuxmlconfdata/disk-virtio-scsi-reservations.xml b/tests/qemuxmlconfdata/disk-virtio-scsi-reservations.xml index 9c55d6ec3e..7f9160ff3a 100644 --- a/tests/qemuxmlconfdata/disk-virtio-scsi-reservations.xml +++ b/tests/qemuxmlconfdata/disk-virtio-scsi-reservations.xml @@ -28,7 +28,7 @@ - +