virDomainDeviceDefOperationsCallbacks would enable virDomainXMLOption to gain driver specific callback for attaching / detaching / updating devices, also it can store flags for attachable / detachable / updatable devices that driver supported (currently only add flags for detachable devices). This would be useful when de-duplicate related functions. Signed-off-by: Luke Yue <lukedyue@xxxxxxxxx> --- I am not pretty sure whether these functions could be put into virDomainXMLPrivateDataCallbacks or not, so I just create a new one to store them. --- src/bhyve/bhyve_domain.c | 2 +- src/ch/ch_conf.c | 2 +- src/conf/domain_conf.c | 6 +++++- src/conf/domain_conf.h | 18 +++++++++++++++++- src/conf/virconftypes.h | 2 ++ src/hyperv/hyperv_driver.c | 3 ++- src/libxl/libxl_conf.c | 2 +- src/lxc/lxc_conf.c | 2 +- src/openvz/openvz_conf.c | 2 +- src/qemu/qemu_conf.c | 3 ++- src/qemu/qemu_process.c | 2 +- src/security/virt-aa-helper.c | 2 +- src/test/test_driver.c | 3 ++- src/vbox/vbox_common.c | 2 +- src/vmware/vmware_driver.c | 2 +- src/vmx/vmx.c | 2 +- src/vz/vz_driver.c | 2 +- tests/bhyveargv2xmltest.c | 2 +- tests/testutils.c | 2 +- 19 files changed, 43 insertions(+), 18 deletions(-) diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index b526235a4e..1b7986ffff 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -217,7 +217,7 @@ virBhyveDriverCreateXMLConf(struct _bhyveConn *driver) return virDomainXMLOptionNew(&virBhyveDriverDomainDefParserConfig, &virBhyveDriverPrivateDataCallbacks, &virBhyveDriverDomainXMLNamespace, - NULL, NULL); + NULL, NULL, NULL); } diff --git a/src/ch/ch_conf.c b/src/ch/ch_conf.c index 88a23a59cd..fc1313584b 100644 --- a/src/ch/ch_conf.c +++ b/src/ch/ch_conf.c @@ -111,7 +111,7 @@ chDomainXMLConfInit(virCHDriver *driver) virCHDriverDomainDefParserConfig.priv = driver; return virDomainXMLOptionNew(&virCHDriverDomainDefParserConfig, &virCHDriverPrivateDataCallbacks, - NULL, NULL, NULL); + NULL, NULL, NULL, NULL); } virCHDriverConfig * diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c8c2f13f8b..e19e3deb17 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1579,7 +1579,8 @@ virDomainXMLOptionNew(virDomainDefParserConfig *config, virDomainXMLPrivateDataCallbacks *priv, virXMLNamespace *xmlns, virDomainABIStability *abi, - virSaveCookieCallbacks *saveCookie) + virSaveCookieCallbacks *saveCookie, + virDomainDeviceDefOperationsCallbacks *deviceOps) { virDomainXMLOption *xmlopt; @@ -1604,6 +1605,9 @@ virDomainXMLOptionNew(virDomainDefParserConfig *config, if (saveCookie) xmlopt->saveCookie = *saveCookie; + if (deviceOps) + xmlopt->deviceOps = *deviceOps; + /* Technically this forbids to use one of Xerox's MAC address prefixes in * our hypervisor drivers. This shouldn't ever be a problem. * diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c0167eee85..14fb9777de 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3208,7 +3208,8 @@ virDomainXMLOption *virDomainXMLOptionNew(virDomainDefParserConfig *config, virDomainXMLPrivateDataCallbacks *priv, virXMLNamespace *xmlns, virDomainABIStability *abi, - virSaveCookieCallbacks *saveCookie); + virSaveCookieCallbacks *saveCookie, + virDomainDeviceDefOperationsCallbacks *deviceOps); virSaveCookieCallbacks * virDomainXMLOptionGetSaveCookie(virDomainXMLOption *xmlopt); @@ -3226,6 +3227,18 @@ virXMLNamespace * virDomainXMLOptionGetNamespace(virDomainXMLOption *xmlopt) ATTRIBUTE_NONNULL(1); +typedef int (*virDomainDeviceDetachFunc)(virDomainDef *vmdef, + virDomainDeviceDef *dev, + unsigned int flags); + +struct _virDomainDeviceDefOperationsCallbacks { + virDomainDeviceDetachFunc detachChr; + virDomainDeviceDetachFunc detachMemballoon; + + /* Flags for detachable devices that driver supported */ + unsigned int detachFlags; +}; + /* This structure holds various callbacks and data needed * while parsing and creating domain XMLs */ struct _virDomainXMLOption { @@ -3248,6 +3261,9 @@ struct _virDomainXMLOption { /* Snapshot postparse callbacks */ virDomainMomentPostParseCallback momentPostParse; + + /* domain specific device operation callbacks */ + virDomainDeviceDefOperationsCallbacks deviceOps; }; G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainXMLOption, virObjectUnref); diff --git a/src/conf/virconftypes.h b/src/conf/virconftypes.h index 21420ba8ea..d3bb720c52 100644 --- a/src/conf/virconftypes.h +++ b/src/conf/virconftypes.h @@ -251,3 +251,5 @@ typedef struct _virDomainXMLOption virDomainXMLOption; typedef struct _virDomainXMLPrivateDataCallbacks virDomainXMLPrivateDataCallbacks; typedef struct _virDomainXenbusControllerOpts virDomainXenbusControllerOpts; + +typedef struct _virDomainDeviceDefOperationsCallbacks virDomainDeviceDefOperationsCallbacks; diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 288c01ad14..732cf4a163 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -1766,7 +1766,8 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, goto cleanup; /* init xmlopt for domain XML */ - priv->xmlopt = virDomainXMLOptionNew(&hypervDomainDefParserConfig, NULL, NULL, NULL, NULL); + priv->xmlopt = virDomainXMLOptionNew(&hypervDomainDefParserConfig, + NULL, NULL, NULL, NULL, NULL); if (hypervGetOperatingSystem(priv, &os) < 0) goto cleanup; diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index f062f8e958..032f7196c2 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -2486,5 +2486,5 @@ libxlCreateXMLConf(libxlDriverPrivate *driver) return virDomainXMLOptionNew(&libxlDomainDefParserConfig, &libxlDomainXMLPrivateDataCallbacks, &libxlDriverDomainXMLNamespace, - NULL, NULL); + NULL, NULL, NULL); } diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index 8955578d54..01a159438e 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -190,7 +190,7 @@ lxcDomainXMLConfInit(virLXCDriver *driver, const char *defsecmodel) return virDomainXMLOptionNew(&virLXCDriverDomainDefParserConfig, &virLXCDriverPrivateDataCallbacks, &virLXCDriverDomainXMLNamespace, - NULL, NULL); + NULL, NULL, NULL); } diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 191c79e1e2..5bcb9c584b 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -1063,5 +1063,5 @@ virDomainXMLOption *openvzXMLOption(struct openvz_driver *driver) { openvzDomainDefParserConfig.priv = driver; return virDomainXMLOptionNew(&openvzDomainDefParserConfig, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL); } diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 81449b8b77..8b2926f766 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1296,7 +1296,8 @@ virQEMUDriverCreateXMLConf(virQEMUDriver *driver, &virQEMUDriverPrivateDataCallbacks, &virQEMUDriverDomainXMLNamespace, &virQEMUDriverDomainABIStability, - &virQEMUDriverDomainSaveCookie); + &virQEMUDriverDomainSaveCookie, + NULL); } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index ea586e54c1..42a3062cb9 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -9342,7 +9342,7 @@ qemuProcessQMPConnectMonitor(qemuProcessQMP *proc) monConfig.data.nix.path = proc->monpath; monConfig.data.nix.listen = false; - if (!(xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL)) || + if (!(xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL, NULL)) || !(proc->vm = virDomainObjNew(xmlopt)) || !(proc->vm->def = virDomainDefNew(xmlopt))) return -1; diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 1f1cce8b3d..ead785ee57 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -632,7 +632,7 @@ get_definition(vahControl * ctl, const char *xmlStr) } if (!(ctl->xmlopt = virDomainXMLOptionNew(&virAAHelperDomainDefParserConfig, - NULL, NULL, NULL, NULL))) { + NULL, NULL, NULL, NULL, NULL))) { vah_error(ctl, 0, _("Failed to create XML config object")); return -1; } diff --git a/src/test/test_driver.c b/src/test/test_driver.c index f900123941..e4eb0e87d2 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -462,7 +462,8 @@ testDriverNew(void) if (!(ret = virObjectLockableNew(testDriverClass))) return NULL; - if (!(ret->xmlopt = virDomainXMLOptionNew(&config, &privatecb, &ns, NULL, NULL)) || + if (!(ret->xmlopt = virDomainXMLOptionNew(&config, &privatecb, &ns, + NULL, NULL, NULL)) || !(ret->eventState = virObjectEventStateNew()) || !(ret->ifaces = virInterfaceObjListNew()) || !(ret->domains = virDomainObjListNew()) || diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index eec47a02fc..ce8e7203b1 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -143,7 +143,7 @@ vboxDriverObjNew(void) if (!(driver->caps = vboxCapsInit()) || !(driver->xmlopt = virDomainXMLOptionNew(&vboxDomainDefParserConfig, - NULL, NULL, NULL, NULL))) + NULL, NULL, NULL, NULL, NULL))) goto cleanup; return driver; diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 998ecdb546..4943049df5 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -156,7 +156,7 @@ vmwareDomainXMLConfigInit(struct vmware_driver *driver) .free = vmwareDataFreeFunc }; vmwareDomainDefParserConfig.priv = driver; return virDomainXMLOptionNew(&vmwareDomainDefParserConfig, &priv, - NULL, NULL, NULL); + NULL, NULL, NULL, NULL); } static virDrvOpenStatus diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index ca65caa9a1..6500ed518e 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -695,7 +695,7 @@ virVMXDomainXMLConfInit(virCaps *caps) { virVMXDomainDefParserConfig.priv = caps; return virDomainXMLOptionNew(&virVMXDomainDefParserConfig, NULL, - &virVMXDomainXMLNamespace, NULL, NULL); + &virVMXDomainXMLNamespace, NULL, NULL, NULL); } char * diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index c16cc2be00..c7224a9cbe 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -330,7 +330,7 @@ vzDriverObjNew(void) if (!(driver->caps = vzBuildCapabilities()) || !(driver->xmlopt = virDomainXMLOptionNew(&vzDomainDefParserConfig, &vzDomainXMLPrivateDataCallbacksPtr, - NULL, NULL, NULL)) || + NULL, NULL, NULL, NULL)) || !(driver->domains = virDomainObjListNew()) || !(driver->domainEventState = virObjectEventStateNew()) || (vzInitVersion(driver) < 0) || diff --git a/tests/bhyveargv2xmltest.c b/tests/bhyveargv2xmltest.c index 2ccc1379b9..92189a2e58 100644 --- a/tests/bhyveargv2xmltest.c +++ b/tests/bhyveargv2xmltest.c @@ -113,7 +113,7 @@ mymain(void) if ((driver.caps = virBhyveCapsBuild()) == NULL) return EXIT_FAILURE; - if ((driver.xmlopt = virDomainXMLOptionNew(NULL, NULL, + if ((driver.xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL, NULL)) == NULL) return EXIT_FAILURE; diff --git a/tests/testutils.c b/tests/testutils.c index 2b37c1965d..949a3cae36 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -988,7 +988,7 @@ static virDomainDefParserConfig virTestGenericDomainDefParserConfig = { virDomainXMLOption *virTestGenericDomainXMLConfInit(void) { return virDomainXMLOptionNew(&virTestGenericDomainDefParserConfig, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL); } -- 2.35.1