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 ef6f4b5ba8..a2affd5c02 100644 --- a/src/ch/ch_conf.c +++ b/src/ch/ch_conf.c @@ -115,7 +115,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 d6f69b3ace..44f1428f80 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1564,7 +1564,8 @@ virDomainXMLOptionNew(virDomainDefParserConfig *config, virDomainXMLPrivateDataCallbacks *priv, virXMLNamespace *xmlns, virDomainABIStability *abi, - virSaveCookieCallbacks *saveCookie) + virSaveCookieCallbacks *saveCookie, + virDomainDeviceDefOperationsCallbacks *deviceOps) { virDomainXMLOption *xmlopt; @@ -1589,6 +1590,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 e4259bf890..1b092b2ee5 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3173,7 +3173,8 @@ virDomainXMLOption *virDomainXMLOptionNew(virDomainDefParserConfig *config, virDomainXMLPrivateDataCallbacks *priv, virXMLNamespace *xmlns, virDomainABIStability *abi, - virSaveCookieCallbacks *saveCookie); + virSaveCookieCallbacks *saveCookie, + virDomainDeviceDefOperationsCallbacks *deviceOps); virSaveCookieCallbacks * virDomainXMLOptionGetSaveCookie(virDomainXMLOption *xmlopt); @@ -3191,6 +3192,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 { @@ -3213,6 +3226,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 bafec27a88..57d2eb9ec6 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -1784,7 +1784,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 f37c228139..a586454f23 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -2505,5 +2505,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 73156f15a3..c1d695e97b 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -194,7 +194,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 e2fbc28abc..b9522acd59 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -1087,5 +1087,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 7eb04e66a0..ec85b6f5a6 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1290,7 +1290,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 6b83a571b9..a2e4066158 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -9238,7 +9238,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 b7ffb5e2c3..afb884e5d8 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 b6bca884f0..7febb4f5a6 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -466,7 +466,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 72f1b9c466..5d6f5e77c2 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 e6843ee745..700bb41232 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 d3540acd84..9de20d8024 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 23b7795035..01671c6cf4 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -334,7 +334,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 e460c9ecc5..3215dc981b 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -986,7 +986,7 @@ static virDomainDefParserConfig virTestGenericDomainDefParserConfig = { virDomainXMLOption *virTestGenericDomainXMLConfInit(void) { return virDomainXMLOptionNew(&virTestGenericDomainDefParserConfig, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL); } -- 2.34.1