The virDomainObjPtr object stores state about a running domain. This object is shared across all drivers so it is not appropriate to include driver specific state here. This patch adds the ability to request a blob of private data per domain object instance. The driver must provide a allocator & deallocator for this purpose THis patch abuses the virCapabilitiesPtr structure for storing the allocator/deallocator callbacks, since it is already being abused for other internal things relating to parsing. This should be moved out into a separate object at some point. * src/conf/capabilities.h: Add privateDataAllocFunc and privateDataFreeFunc fields * src/conf/domain_conf.c: Invoke the driver allocators / deallocators when creating/freeing virDomainObjPtr instances. * src/conf/domain_conf.h: Pass virCapsPtr into virDomainAssignDef to allow access to the driver specific allocator function * src/lxc/lxc_driver.c, src/opennebula/one_driver.c, src/openvz/openvz_driver.c, src/qemu/qemu_driver.c, src/test/test_driver.c, src/uml/uml_driver.c: Update for change in virDomainAssignDef contract --- src/conf/capabilities.h | 2 ++ src/conf/domain_conf.c | 23 +++++++++++++++++++---- src/conf/domain_conf.h | 4 ++++ src/lxc/lxc_driver.c | 6 ++++-- src/opennebula/one_driver.c | 6 ++++-- src/openvz/openvz_driver.c | 6 ++++-- src/qemu/qemu_driver.c | 5 +++++ src/test/test_driver.c | 15 ++++++++++----- src/uml/uml_driver.c | 2 ++ 9 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index 2f24605..7234cf4 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -115,6 +115,8 @@ struct _virCaps { virCapsGuestPtr *guests; unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN]; unsigned int emulatorRequired : 1; + void *(*privateDataAllocFunc)(void); + void (*privateDataFreeFunc)(void *); }; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7700d6a..b168c83 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -569,12 +569,16 @@ void virDomainObjFree(virDomainObjPtr dom) VIR_FREE(dom->vcpupids); + if (dom->privateDataFreeFunc) + (dom->privateDataFreeFunc)(dom->privateData); + virMutexDestroy(&dom->lock); VIR_FREE(dom); } -static virDomainObjPtr virDomainObjNew(virConnectPtr conn) +static virDomainObjPtr virDomainObjNew(virConnectPtr conn, + virCapsPtr caps) { virDomainObjPtr domain; @@ -583,9 +587,19 @@ static virDomainObjPtr virDomainObjNew(virConnectPtr conn) return NULL; } + if (caps->privateDataAllocFunc && + !(domain->privateData = (caps->privateDataAllocFunc)())) { + virReportOOMError(conn); + VIR_FREE(domain); + return NULL; + } + domain->privateDataFreeFunc = caps->privateDataFreeFunc; + if (virMutexInit(&domain->lock) < 0) { virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", _("cannot initialize mutex")); + if (domain->privateDataFreeFunc) + (domain->privateDataFreeFunc)(domain->privateData); VIR_FREE(domain); return NULL; } @@ -599,6 +613,7 @@ static virDomainObjPtr virDomainObjNew(virConnectPtr conn) } virDomainObjPtr virDomainAssignDef(virConnectPtr conn, + virCapsPtr caps, virDomainObjListPtr doms, const virDomainDefPtr def) { @@ -618,7 +633,7 @@ virDomainObjPtr virDomainAssignDef(virConnectPtr conn, return domain; } - if (!(domain = virDomainObjNew(conn))) + if (!(domain = virDomainObjNew(conn, caps))) return NULL; domain->def = def; @@ -3083,7 +3098,7 @@ static virDomainObjPtr virDomainObjParseXML(virConnectPtr conn, xmlNodePtr *nodes = NULL; int n, i; - if (!(obj = virDomainObjNew(conn))) + if (!(obj = virDomainObjNew(conn, caps))) return NULL; if (!(config = virXPathNode(conn, "./domain", ctxt))) { @@ -4634,7 +4649,7 @@ virDomainObjPtr virDomainLoadConfig(virConnectPtr conn, newVM = 0; } - if (!(dom = virDomainAssignDef(conn, doms, def))) + if (!(dom = virDomainAssignDef(conn, caps, doms, def))) goto error; dom->autostart = autostart; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 11f059c..1e53385 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -609,6 +609,9 @@ struct _virDomainObj { virDomainDefPtr def; /* The current definition */ virDomainDefPtr newDef; /* New definition to activate at shutdown */ + + void *privateData; + void (*privateDataFreeFunc)(void *); }; typedef struct _virDomainObjList virDomainObjList; @@ -650,6 +653,7 @@ void virDomainDefFree(virDomainDefPtr vm); void virDomainObjFree(virDomainObjPtr vm); virDomainObjPtr virDomainAssignDef(virConnectPtr conn, + virCapsPtr caps, virDomainObjListPtr doms, const virDomainDefPtr def); void virDomainRemoveInactive(virDomainObjListPtr doms, diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 077e970..3e0d24d 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -315,7 +315,8 @@ static virDomainPtr lxcDomainDefine(virConnectPtr conn, const char *xml) goto cleanup; } - if (!(vm = virDomainAssignDef(conn, &driver->domains, def))) + if (!(vm = virDomainAssignDef(conn, driver->caps, + &driver->domains, def))) goto cleanup; def = NULL; vm->persistent = 1; @@ -1285,7 +1286,8 @@ lxcDomainCreateAndStart(virConnectPtr conn, } - if (!(vm = virDomainAssignDef(conn, &driver->domains, def))) + if (!(vm = virDomainAssignDef(conn, driver->caps, + &driver->domains, def))) goto cleanup; def = NULL; diff --git a/src/opennebula/one_driver.c b/src/opennebula/one_driver.c index 0b807ad..beb48ce 100644 --- a/src/opennebula/one_driver.c +++ b/src/opennebula/one_driver.c @@ -235,7 +235,8 @@ static virDomainPtr oneDomainDefine(virConnectPtr conn, const char *xml) VIR_DOMAIN_XML_INACTIVE))) goto return_point; - if (!(vm = virDomainAssignDef(conn, &driver->domains, def))) { + if (!(vm = virDomainAssignDef(conn, driver->caps, + &driver->domains, def))) { virDomainDefFree(def); goto return_point; } @@ -439,7 +440,8 @@ oneDomainCreateAndStart(virConnectPtr conn, goto return_point; } - if (!(vm = virDomainAssignDef(conn, &driver->domains, def))) { + if (!(vm = virDomainAssignDef(conn, driver->caps, + &driver->domains, def))) { virDomainDefFree(def); goto return_point; } diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index b0092cd..d334235 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -774,7 +774,8 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml) vmdef->name); goto cleanup; } - if (!(vm = virDomainAssignDef(conn, &driver->domains, vmdef))) + if (!(vm = virDomainAssignDef(conn, driver->caps, + &driver->domains, vmdef))) goto cleanup; vmdef = NULL; @@ -841,7 +842,8 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml, vmdef->name); goto cleanup; } - if (!(vm = virDomainAssignDef(conn, &driver->domains, vmdef))) + if (!(vm = virDomainAssignDef(conn, driver->caps, + &driver->domains, vmdef))) goto cleanup; vmdef = NULL; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 19187ac..1fe789a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2700,6 +2700,7 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml, } if (!(vm = virDomainAssignDef(conn, + driver->caps, &driver->domains, def))) goto cleanup; @@ -3763,6 +3764,7 @@ static int qemudDomainRestore(virConnectPtr conn, } if (!(vm = virDomainAssignDef(conn, + driver->caps, &driver->domains, def))) { qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED, @@ -4251,6 +4253,7 @@ static virDomainPtr qemudDomainDefine(virConnectPtr conn, const char *xml) { goto cleanup; if (!(vm = virDomainAssignDef(conn, + driver->caps, &driver->domains, def))) { goto cleanup; @@ -6109,6 +6112,7 @@ qemudDomainMigratePrepareTunnel(virConnectPtr dconn, } if (!(vm = virDomainAssignDef(dconn, + driver->caps, &driver->domains, def))) { qemudReportError(dconn, NULL, NULL, VIR_ERR_OPERATION_FAILED, @@ -6330,6 +6334,7 @@ qemudDomainMigratePrepare2 (virConnectPtr dconn, } if (!(vm = virDomainAssignDef(dconn, + driver->caps, &driver->domains, def))) { qemudReportError (dconn, NULL, NULL, VIR_ERR_OPERATION_FAILED, diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 919a2f6..f08fe74 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -364,7 +364,8 @@ static int testOpenDefault(virConnectPtr conn) { goto error; if (testDomainGenerateIfnames(conn, domdef) < 0) goto error; - if (!(domobj = virDomainAssignDef(conn, &privconn->domains, domdef))) + if (!(domobj = virDomainAssignDef(conn, privconn->caps, + &privconn->domains, domdef))) goto error; domdef = NULL; domobj->def->id = privconn->nextDomID++; @@ -716,7 +717,8 @@ static int testOpenFromFile(virConnectPtr conn, } if (testDomainGenerateIfnames(conn, def) < 0 || - !(dom = virDomainAssignDef(conn, &privconn->domains, def))) { + !(dom = virDomainAssignDef(conn, privconn->caps, + &privconn->domains, def))) { virDomainDefFree(def); goto error; } @@ -1068,7 +1070,8 @@ testDomainCreateXML(virConnectPtr conn, const char *xml, if (testDomainGenerateIfnames(conn, def) < 0) goto cleanup; - if (!(dom = virDomainAssignDef(conn, &privconn->domains, def))) + if (!(dom = virDomainAssignDef(conn, privconn->caps, + &privconn->domains, def))) goto cleanup; def = NULL; dom->state = VIR_DOMAIN_RUNNING; @@ -1616,7 +1619,8 @@ static int testDomainRestore(virConnectPtr conn, if (testDomainGenerateIfnames(conn, def) < 0) goto cleanup; - if (!(dom = virDomainAssignDef(conn, &privconn->domains, def))) + if (!(dom = virDomainAssignDef(conn, privconn->caps, + &privconn->domains, def))) goto cleanup; def = NULL; @@ -1890,7 +1894,8 @@ static virDomainPtr testDomainDefineXML(virConnectPtr conn, if (testDomainGenerateIfnames(conn, def) < 0) goto cleanup; - if (!(dom = virDomainAssignDef(conn, &privconn->domains, def))) + if (!(dom = virDomainAssignDef(conn, privconn->caps, + &privconn->domains, def))) goto cleanup; def = NULL; dom->persistent = 1; diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 80cf477..4fb04d9 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -1212,6 +1212,7 @@ static virDomainPtr umlDomainCreate(virConnectPtr conn, const char *xml, } if (!(vm = virDomainAssignDef(conn, + driver->caps, &driver->domains, def))) goto cleanup; @@ -1546,6 +1547,7 @@ static virDomainPtr umlDomainDefine(virConnectPtr conn, const char *xml) { goto cleanup; if (!(vm = virDomainAssignDef(conn, + driver->caps, &driver->domains, def))) goto cleanup; -- 1.6.2.5 -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list