[PATCH 0/2] qemu: Fix hotplug of VDPA disks

Peter Krempa (2): qemu: process: Extract host setup of disk device into a helper qemu: hotplug: Setup host side of VDPA device for disk hotplug src/qemu/qemu_hotplug.c | 3 +++ src/qemu/qemu_process.c | 42 ++++++++++++++++++++++++++++++++--------- src/qemu/qemu_process.h | 3 +++ 3 files changed, 39 insertions(+), 9 deletions(-) -- 2.41.0

Currently the code sets up only VDPA backends but will be used later in hotplug code too. This patch also uses normal forward iteration in the loop in qemuProcessPrepareHostStorage as we don't need to remove disks from the disk list at that point. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_process.c | 42 ++++++++++++++++++++++++++++++++--------- src/qemu/qemu_process.h | 3 +++ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 63c0c62a46..b420ec283d 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6777,6 +6777,35 @@ qemuProcessPrepareHostStorageSourceVDPA(virStorageSource *src, } +/** + * qemuProcessPrepareHostStorageDisk: + * + * @vm: domain object + * @disk: disk definition object + * + * Prepare the host side of a disk for use with the VM. Note that this function + * accesses host resources. + * + * Note that this function does not call qemuDomainDetermineDiskChain as that is + * needed in qemuProcessPrepareHostStorage to remove disks based on the startup + * policy, thus other callers need to call it explicitly. + */ +int +qemuProcessPrepareHostStorageDisk(virDomainObj *vm, + virDomainDiskDef *disk) +{ + virStorageSource *n; + + for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) { + /* connect to any necessary vdpa block devices */ + if (qemuProcessPrepareHostStorageSourceVDPA(n, vm->privateData) < 0) + return -1; + } + + return 0; +} + + static int qemuProcessPrepareHostStorage(virQEMUDriver *driver, virDomainObj *vm, @@ -6813,16 +6842,11 @@ qemuProcessPrepareHostStorage(virQEMUDriver *driver, return -1; } - /* connect to any necessary vdpa block devices */ - for (i = vm->def->ndisks; i > 0; i--) { - size_t idx = i - 1; - virDomainDiskDef *disk = vm->def->disks[idx]; - virStorageSource *src; + for (i = 0; i < vm->def->ndisks; i++) { + virDomainDiskDef *disk = vm->def->disks[i]; - for (src = disk->src; virStorageSourceIsBacking(src); src = src->backingStore) { - if (qemuProcessPrepareHostStorageSourceVDPA(src, vm->privateData) < 0) - return -1; - } + if (qemuProcessPrepareHostStorageDisk(vm, disk) < 0) + return -1; } return 0; diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index ef05b46892..7b974259d3 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -133,6 +133,9 @@ int qemuProcessPrepareHost(virQEMUDriver *driver, virDomainObj *vm, unsigned int flags); +int qemuProcessPrepareHostStorageDisk(virDomainObj *vm, + virDomainDiskDef *disk); + int qemuProcessDeleteThreadContext(virDomainObj *vm); int qemuProcessLaunch(virConnectPtr conn, -- 2.41.0

The code which opens the VDPA device and prepares it for FD passing was not called in the hotplug code path, preventing hotplug of VDPA disks with: error: internal error: argument key 'path' must not have null value Use the new helper qemuProcessPrepareHostStorageDisk to setup the VDPA definition. Closes: https://gitlab.com/libvirt/libvirt/-/issues/539 Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_hotplug.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 1f7f5bdd26..fec7c4be4e 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1007,6 +1007,9 @@ qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriver *driver, if (qemuDomainDetermineDiskChain(driver, vm, disk, NULL) < 0) goto cleanup; + if (qemuProcessPrepareHostStorageDisk(vm, disk) < 0) + goto cleanup; + if (qemuHotplugAttachManagedPR(vm, disk->src, VIR_ASYNC_JOB_NONE) < 0) goto cleanup; -- 2.41.0

On Thu, Oct 26, 2023 at 15:15:15 +0200, Peter Krempa wrote:
Peter Krempa (2): qemu: process: Extract host setup of disk device into a helper qemu: hotplug: Setup host side of VDPA device for disk hotplug
src/qemu/qemu_hotplug.c | 3 +++ src/qemu/qemu_process.c | 42 ++++++++++++++++++++++++++++++++--------- src/qemu/qemu_process.h | 3 +++ 3 files changed, 39 insertions(+), 9 deletions(-)
I'll be posting a v2 to properly address also block copy.
participants (1)
-
Peter Krempa