提交 3505790b 编写于 作者: D Daniel P. Berrange

Allow for a driver specific private data blob in virDomainObjPtr

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
上级 530d4463
......@@ -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 *);
};
......
......@@ -594,12 +594,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;
......@@ -608,9 +612,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;
}
......@@ -624,6 +638,7 @@ static virDomainObjPtr virDomainObjNew(virConnectPtr conn)
}
virDomainObjPtr virDomainAssignDef(virConnectPtr conn,
virCapsPtr caps,
virDomainObjListPtr doms,
const virDomainDefPtr def)
{
......@@ -643,7 +658,7 @@ virDomainObjPtr virDomainAssignDef(virConnectPtr conn,
return domain;
}
if (!(domain = virDomainObjNew(conn)))
if (!(domain = virDomainObjNew(conn, caps)))
return NULL;
domain->def = def;
......@@ -3187,7 +3202,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))) {
......@@ -4768,7 +4783,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;
......
......@@ -636,6 +636,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;
......@@ -678,6 +681,7 @@ void virDomainDefFree(virDomainDefPtr vm);
void virDomainObjFree(virDomainObjPtr vm);
virDomainObjPtr virDomainAssignDef(virConnectPtr conn,
virCapsPtr caps,
virDomainObjListPtr doms,
const virDomainDefPtr def);
void virDomainRemoveInactive(virDomainObjListPtr doms,
......
......@@ -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;
......@@ -1312,7 +1313,8 @@ lxcDomainCreateAndStart(virConnectPtr conn,
}
if (!(vm = virDomainAssignDef(conn, &driver->domains, def)))
if (!(vm = virDomainAssignDef(conn, driver->caps,
&driver->domains, def)))
goto cleanup;
def = NULL;
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -2697,6 +2697,7 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
}
if (!(vm = virDomainAssignDef(conn,
driver->caps,
&driver->domains,
def)))
goto cleanup;
......@@ -3757,6 +3758,7 @@ static int qemudDomainRestore(virConnectPtr conn,
}
if (!(vm = virDomainAssignDef(conn,
driver->caps,
&driver->domains,
def))) {
qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
......@@ -4243,6 +4245,7 @@ static virDomainPtr qemudDomainDefine(virConnectPtr conn, const char *xml) {
goto cleanup;
if (!(vm = virDomainAssignDef(conn,
driver->caps,
&driver->domains,
def))) {
goto cleanup;
......@@ -6101,6 +6104,7 @@ qemudDomainMigratePrepareTunnel(virConnectPtr dconn,
}
if (!(vm = virDomainAssignDef(dconn,
driver->caps,
&driver->domains,
def))) {
qemudReportError(dconn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
......@@ -6339,6 +6343,7 @@ qemudDomainMigratePrepare2 (virConnectPtr dconn,
}
if (!(vm = virDomainAssignDef(dconn,
driver->caps,
&driver->domains,
def))) {
qemudReportError (dconn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
......
......@@ -387,7 +387,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++;
......@@ -739,7 +740,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;
}
......@@ -1091,7 +1093,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;
......@@ -1639,7 +1642,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;
......@@ -1913,7 +1917,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;
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册