On 9/4/25 14:10, Stefan Kober wrote:
> On-behalf-of: SAP [email protected]
> Signed-off-by: Stefan Kober <[email protected]>
> ---
> src/ch/ch_driver.c | 44 +++++++++++++++++++++++++++++++++++++++++
> src/ch/ch_hotplug.c | 48 ++++++++++++++++++++++++++++++++++++++++-----
> 2 files changed, 87 insertions(+), 5 deletions(-)
>
> diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c
> index cf6874f22e..4f4783efb1 100644
> --- a/src/ch/ch_driver.c
> +++ b/src/ch/ch_driver.c
> @@ -25,6 +25,7 @@
> #include "ch_conf.h"
> #include "ch_domain.h"
> #include "ch_driver.h"
> +#include "ch_hotplug.h"
> #include "ch_monitor.h"
> #include "ch_process.h"
> #include "domain_cgroup.h"
> @@ -2344,6 +2345,47 @@ chDomainInterfaceAddresses(virDomain *dom,
> return ret;
> }
>
> +static int
> +chDomainAttachDeviceFlags(virDomainPtr dom,
> + const char *xml,
> + unsigned int flags)
> +{
> + virCHDriver *driver = dom->conn->privateData;
> + virDomainObj *vm = NULL;
> + int ret = -1;
> +
> + if (!(vm = virCHDomainObjFromDomain(dom)))
> + goto cleanup;
> +
> + if (virDomainAttachDeviceFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
> + goto cleanup;
> +
> + if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
> + goto cleanup;
> +
> + if (virDomainObjUpdateModificationImpact(vm, &flags) < 0)
> + goto endjob;
> +
> + if (chDomainAttachDeviceLiveAndUpdateConfig(vm, driver, xml, flags) < 0)
> {
> + goto endjob;
> + }
> +
> + ret = 0;
> +
> + endjob:
> + virDomainObjEndJob(vm);
> +
> + cleanup:
> + virDomainObjEndAPI(&vm);
> + return ret;
> +}
> +
> +static int
> +chDomainAttachDevice(virDomainPtr dom,
> + const char *xml)
> +{
> + return chDomainAttachDeviceFlags(dom, xml, VIR_DOMAIN_AFFECT_LIVE);
> +}
>
> /* Function Tables */
> static virHypervisorDriver chHypervisorDriver = {
> @@ -2406,6 +2448,8 @@ static virHypervisorDriver chHypervisorDriver = {
> .connectDomainEventRegisterAny = chConnectDomainEventRegisterAny,
> /* 10.10.0 */
> .connectDomainEventDeregisterAny = chConnectDomainEventDeregisterAny,
> /* 10.10.0 */
> .domainInterfaceAddresses = chDomainInterfaceAddresses, /* 11.0.0 */
> + .domainAttachDevice = chDomainAttachDevice, /* 11.8.0 */
> + .domainAttachDeviceFlags = chDomainAttachDeviceFlags, /* 11.8.0 */
> };
>
> static virConnectDriver chConnectDriver = {
Until here the change makes sense. But what's below should be part of
previous patch.
> diff --git a/src/ch/ch_hotplug.c b/src/ch/ch_hotplug.c
> index 7de688dc44..524355b93c 100644
> --- a/src/ch/ch_hotplug.c
> +++ b/src/ch/ch_hotplug.c
> @@ -50,7 +50,6 @@ chDomainAddDisk(virCHMonitor *mon, virDomainObj *vm,
> virDomainDiskDef *disk)
> return 0;
> }
>
> -G_GNUC_UNUSED
> static int
> chDomainAttachDeviceLive(virDomainObj *vm,
> virDomainDeviceDef *dev)
> @@ -108,13 +107,52 @@ chDomainAttachDeviceLive(virDomainObj *vm,
> }
>
> int
> -chDomainAttachDeviceLiveAndUpdateConfig(virDomainObj *vm G_GNUC_UNUSED,
> - virCHDriver *driver G_GNUC_UNUSED,
> - const char *xml G_GNUC_UNUSED,
> +chDomainAttachDeviceLiveAndUpdateConfig(virDomainObj *vm,
> + virCHDriver *driver,
> + const char *xml,
> unsigned int flags)
> {
> + unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE |
> + VIR_DOMAIN_DEF_PARSE_ABI_UPDATE;
> + g_autoptr(virDomainDeviceDef) devLive = NULL;
> + g_autoptr(virDomainDef) vmdef = NULL;
> + g_autoptr(virCHDriverConfig) cfg = NULL;
> + g_autoptr(virDomainDeviceDef) devConf = NULL;
> +
> virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
> VIR_DOMAIN_AFFECT_CONFIG, -1);
>
> - return -1;
> + cfg = virCHDriverGetConfig(driver);
> +
> + if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
> + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
> + _("Persistent domain state changes are not
> supported"));
At first I was a bit puzzled why have this at all. I mean,
virCheckFlags() could have just contained _AFFECT_LIVE but then it hit
me: this produces much more descriptive error message. So let's keep it
then.
> + return -1;
> + }
> +
> + if (flags & VIR_DOMAIN_AFFECT_LIVE) {
> + if (!(devLive = virDomainDeviceDefParse(xml, vm->def,
> + driver->xmlopt, NULL,
> + parse_flags))) {
> + return -1;
> + }
> +
> + if (virDomainDeviceValidateAliasForHotplug(vm, devLive,
> + VIR_DOMAIN_AFFECT_LIVE) <
> 0)
> + return -1;
> +
> + if (virDomainDefCompatibleDevice(vm->def, devLive, NULL,
> + VIR_DOMAIN_DEVICE_ACTION_ATTACH,
> + true) < 0) {
> + return -1;
> + }
> +
> + if (chDomainAttachDeviceLive(vm, devLive) < 0) {
> + virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> + _("Failed to add device"));
> + return -1;
> + }
> + }
> +
> + return 0;
> }
Michal