libvirt/vdpa-support-vdpa-device-hot-plug-unplug.patch
Jiabo Feng 52e9a4d1d4 libvirt update to version 6.2.0-60
- vdpa: support vdpa device migrate
- vdpa: support vdpa device hot plug/unplug
- vdpa: Introduce the new device type vdpa to hostdev
- node_device: fix leak of DIR*
- Include vdpa devices in node device list
- lxc: fix lxcContainerMountAllFS() DEREF_BEFORE_CHECK
- qemu: Return perf status that affect next boot  for shutoff domains While we set up perf events for a shutoff domain and check the settings, All of perf events are reported as 'disabled', unless we add --config, This is redundant for a shutoff domain.
- tests: upstream Fixing compiler warning in cputest
- qemu_migration_cookie: Rename ret in qemuDomainExtractTLSSubject
- virrandom: Fix printf format string in virRandomGenerateWWN()
- fix the issue of errors when saving after 'virsh edit'
- Use (un)signed printf specifiers correctly
- admin: fix leak of typed parameters on error
- esx: call freeaddrinfo earlier in esxUtil_ResolveHostname Call freeaddrinfo() as soon as @result is not needed anymore, i.e. right after getnameinfo(); this avoids calling freeaddrinfo() in two branches.
- qemu: Fix incorrect command name in error messages

Signed-off-by: Jiabo Feng <fengjiabo1@huawei.com>
2023-12-05 21:06:20 +08:00

151 lines
5.1 KiB
Diff

From 9033b938d402c3eb2cbc13b3dc2a87b191b03aed Mon Sep 17 00:00:00 2001
From: AlexChen <alex.chen@huawei.com>
Date: Sat, 25 Nov 2023 09:51:46 +0800
Subject: [PATCH] vdpa: support vdpa device hot plug/unplug
support vdpa device hot plug/unplug
Signed-off-by: jiangdongxu <jiangdongxu1@huawei.com>
Signed-off-by: AlexChen <alex.chen@huawei.com>
---
src/qemu/qemu_hotplug.c | 95 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 95 insertions(+)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index e13879cde3..3c5540291b 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2907,6 +2907,89 @@ qemuDomainAttachMediatedDevice(virQEMUDriverPtr driver,
}
+static int
+qemuDomainAttachVDPADevice(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virDomainHostdevDefPtr hostdev)
+{
+ int ret = -1;
+ g_autofree char *devstr = NULL;
+ bool teardowncgroup = false;
+ bool teardownlabel = false;
+ bool teardowndevice = false;
+ bool teardownmemlock = false;
+ bool releaseaddr = false;
+ qemuDomainObjPrivatePtr priv = vm->privateData;
+ virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_HOSTDEV,
+ { .hostdev = hostdev } };
+
+ if (qemuDomainNamespaceSetupHostdev(vm, hostdev) < 0)
+ goto error;
+ teardowndevice = true;
+
+ if (qemuSetupHostdevCgroup(vm, hostdev) < 0)
+ goto error;
+ teardowncgroup = true;
+
+ if (qemuSecuritySetHostdevLabel(driver, vm, hostdev) < 0)
+ goto error;
+ teardownlabel = true;
+
+ if (qemuDomainEnsurePCIAddress(vm, &dev, driver) < 0)
+ goto error;
+ releaseaddr = true;
+
+ if (qemuAssignDeviceHostdevAlias(vm->def, &hostdev->info->alias, -1) < 0)
+ goto error;
+
+ if (!virDomainObjIsActive(vm)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("guest unexpectedly quit during hotplug"));
+ goto error;
+ }
+
+ if (!(devstr = qemuBuildHostdevVDPAStr(vm->def, hostdev, priv->qemuCaps)))
+ goto error;
+
+ if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
+ goto error;
+
+ if (qemuDomainAdjustMaxMemLockHostdev(vm, hostdev) < 0)
+ goto error;
+ teardownmemlock = true;
+
+ qemuDomainObjEnterMonitor(driver, vm);
+ ret = qemuMonitorAddDevice(priv->mon, devstr);
+ if (qemuDomainObjExitMonitor(driver, vm) < 0) {
+ goto error;
+ }
+
+ virDomainAuditHostdev(vm, hostdev, "attach", ret == 0);
+ if (ret < 0)
+ goto error;
+
+ vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
+
+ return 0;
+
+ error:
+ if (teardowncgroup && qemuTeardownHostdevCgroup(vm, hostdev) < 0)
+ VIR_WARN("Unable to remove host device cgroup ACL on hotplug fail");
+ if (teardownlabel &&
+ qemuSecurityRestoreHostdevLabel(driver, vm, hostdev) < 0)
+ VIR_WARN("Unable to restore host device labelling on hotplug fail");
+ if (teardowndevice &&
+ qemuDomainNamespaceTeardownHostdev(vm, hostdev) < 0)
+ VIR_WARN("Unable to remove host device from /dev");
+ if (teardownmemlock && qemuDomainAdjustMaxMemLock(vm, false) < 0)
+ VIR_WARN("Unable to reset maximum locked memory on hotplug fail");
+ if (releaseaddr)
+ qemuDomainReleaseDeviceAddress(vm, hostdev->info);
+
+ return -1;
+}
+
+
int
qemuDomainAttachHostDevice(virQEMUDriverPtr driver,
virDomainObjPtr vm,
@@ -2947,6 +3030,11 @@ qemuDomainAttachHostDevice(virQEMUDriverPtr driver,
return -1;
break;
+ case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_VDPA:
+ if (qemuDomainAttachVDPADevice(driver, vm, hostdev) < 0)
+ return -1;
+ break;
+
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("hotplug is not supported for hostdev subsys type '%s'"),
@@ -4564,6 +4652,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
qemuDomainRemoveMediatedDevice(driver, vm, hostdev);
break;
+ case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_VDPA:
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
break;
}
@@ -5397,6 +5486,7 @@ qemuDomainDetachPrepHostdev(virDomainObjPtr vm,
virDomainHostdevSubsysPCIPtr pcisrc = &subsys->u.pci;
virDomainHostdevSubsysSCSIPtr scsisrc = &subsys->u.scsi;
virDomainHostdevSubsysMediatedDevPtr mdevsrc = &subsys->u.mdev;
+ virDomainHostdevSubsysVDPAPtr vdpasrc = &subsys->u.vdpa;
virDomainHostdevDefPtr hostdev = NULL;
int idx;
@@ -5454,6 +5544,11 @@ qemuDomainDetachPrepHostdev(virDomainObjPtr vm,
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
break;
+ case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_VDPA:
+ virReportError(VIR_ERR_DEVICE_MISSING,
+ _("vdpa device '%s' not found"),
+ vdpasrc->devpath);
+ break;
default:
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected hostdev type %d"), subsys->type);
--
2.27.0