提交 7762c5a2 编写于 作者: M Maxim Nestratov

vz: introduce new vzDriver lockable structure and use it

This patch introduces a new 'vzDriver' lockable object and provides
helper functions to allocate/destroy it and we pass it to prlsdkXxx
functions instead of virConnectPtr.
Now we store domain related objects such as domain list, capabitilies
etc. within a single vz_driver vzDriver structure, which is shared by
all driver connections. It is allocated during daemon initialization or
in a lazy manner when a new connection to 'vz' driver is established.
When a connection to vz daemon drops, vzDestroyConnection is called,
which in turn relays disconnect event to all connection to 'vz' driver.
Signed-off-by: NMaxim Nestratov <mnestratov@virtuozzo.com>
上级 30c61901
......@@ -63,19 +63,27 @@ VIR_LOG_INIT("parallels.parallels_driver");
#define PRLCTL "prlctl"
static int vzConnectClose(virConnectPtr conn);
static virClassPtr vzDriverClass;
void
vzDriverLock(vzConnPtr driver)
vzDriverLock(vzConnPtr privconn)
{
virMutexLock(&driver->lock);
virObjectLock(privconn->driver);
}
void
vzDriverUnlock(vzConnPtr driver)
vzDriverUnlock(vzConnPtr privconn)
{
virMutexUnlock(&driver->lock);
virObjectUnlock(privconn->driver);
}
static virMutex vz_driver_lock;
static vzDriverPtr vz_driver;
static vzConnPtr vz_conn_list;
static vzDriverPtr
vzDriverObjNew(void);
static int
vzCapsAddGuestDomain(virCapsPtr caps,
virDomainOSType ostype,
......@@ -158,6 +166,70 @@ vzBuildCapabilities(void)
goto cleanup;
}
static void vzDriverDispose(void * obj)
{
vzDriverPtr driver = obj;
if (driver->server) {
prlsdkUnsubscribeFromPCSEvents(driver);
prlsdkDisconnect(driver);
}
virObjectUnref(driver->domains);
virObjectUnref(driver->caps);
virObjectUnref(driver->xmlopt);
virObjectEventStateFree(driver->domainEventState);
}
static int vzDriverOnceInit(void)
{
if (!(vzDriverClass = virClassNew(virClassForObjectLockable(),
"vzDriver",
sizeof(vzDriver),
vzDriverDispose)))
return -1;
return 0;
}
VIR_ONCE_GLOBAL_INIT(vzDriver)
vzDriverPtr
vzGetDriverConnection(void)
{
virMutexLock(&vz_driver_lock);
if (!vz_driver)
vz_driver = vzDriverObjNew();
virObjectRef(vz_driver);
virMutexUnlock(&vz_driver_lock);
return vz_driver;
}
void
vzDestroyDriverConnection(void)
{
vzDriverPtr driver;
vzConnPtr privconn_list;
virMutexLock(&vz_driver_lock);
driver = vz_driver;
vz_driver = NULL;
privconn_list = vz_conn_list;
vz_conn_list = NULL;
virMutexUnlock(&vz_driver_lock);
while (privconn_list) {
vzConnPtr privconn = privconn_list;
privconn_list = privconn->next;
virConnectCloseCallbackDataCall(privconn->closeCallback,
VIR_CONNECT_CLOSE_REASON_EOF);
}
virObjectUnref(driver);
}
static char *
vzConnectGetCapabilities(virConnectPtr conn)
{
......@@ -165,7 +237,7 @@ vzConnectGetCapabilities(virConnectPtr conn)
char *xml;
vzDriverLock(privconn);
xml = virCapabilitiesFormatXML(privconn->caps);
xml = virCapabilitiesFormatXML(privconn->driver->caps);
vzDriverUnlock(privconn);
return xml;
}
......@@ -214,70 +286,34 @@ virDomainDefParserConfig vzDomainDefParserConfig = {
.domainPostParseCallback = vzDomainDefPostParse,
};
static int
vzOpenDefault(virConnectPtr conn)
static vzDriverPtr
vzDriverObjNew(void)
{
vzConnPtr privconn;
vzDriverPtr driver;
if (VIR_ALLOC(privconn) < 0)
return VIR_DRV_OPEN_ERROR;
if (virMutexInit(&privconn->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot initialize mutex"));
goto err_free;
}
if (prlsdkInit()) {
VIR_DEBUG("%s", _("Can't initialize Parallels SDK"));
goto err_free;
}
if (prlsdkConnect(privconn) < 0)
goto err_free;
if (vzInitVersion(privconn) < 0)
goto error;
if (!(privconn->caps = vzBuildCapabilities()))
goto error;
vzDomainDefParserConfig.priv = &privconn->vzCaps;
if (!(privconn->xmlopt = virDomainXMLOptionNew(&vzDomainDefParserConfig,
NULL, NULL)))
goto error;
if (!(privconn->domains = virDomainObjListNew()))
goto error;
if (!(privconn->domainEventState = virObjectEventStateNew()))
goto error;
if (prlsdkSubscribeToPCSEvents(privconn))
goto error;
if (!(privconn->closeCallback = virNewConnectCloseCallbackData()))
goto error;
conn->privateData = privconn;
if (vzDriverInitialize() < 0)
return NULL;
if (prlsdkLoadDomains(privconn))
goto error;
if (!(driver = virObjectLockableNew(vzDriverClass)))
return NULL;
return VIR_DRV_OPEN_SUCCESS;
vzDomainDefParserConfig.priv = &driver->vzCaps;
if (!(driver->caps = vzBuildCapabilities()) ||
!(driver->xmlopt = virDomainXMLOptionNew(&vzDomainDefParserConfig,
NULL, NULL)) ||
!(driver->domains = virDomainObjListNew()) ||
!(driver->domainEventState = virObjectEventStateNew()) ||
(vzInitVersion(driver) < 0) ||
(prlsdkConnect(driver) < 0) ||
(prlsdkSubscribeToPCSEvents(driver) < 0)
) {
virObjectUnref(driver);
return NULL;
}
error:
virObjectUnref(privconn->closeCallback);
privconn->closeCallback = NULL;
virObjectUnref(privconn->domains);
virObjectUnref(privconn->caps);
virObjectEventStateFree(privconn->domainEventState);
prlsdkDisconnect(privconn);
prlsdkDeinit();
err_free:
conn->privateData = NULL;
VIR_FREE(privconn);
return VIR_DRV_OPEN_ERROR;
ignore_value(prlsdkLoadDomains(driver));
return driver;
}
static virDrvOpenStatus
......@@ -285,7 +321,8 @@ vzConnectOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
unsigned int flags)
{
int ret;
vzDriverPtr driver = NULL;
vzConnPtr privconn = NULL;
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
......@@ -317,36 +354,56 @@ vzConnectOpen(virConnectPtr conn,
return VIR_DRV_OPEN_ERROR;
}
if ((ret = vzOpenDefault(conn)) != VIR_DRV_OPEN_SUCCESS)
return ret;
if (!(driver = vzGetDriverConnection()))
return VIR_DRV_OPEN_ERROR;
if (VIR_ALLOC(privconn) < 0)
goto error;
conn->privateData = privconn;
privconn->driver = driver;
if (!(privconn->closeCallback = virNewConnectCloseCallbackData()))
goto error;
virMutexLock(&vz_driver_lock);
privconn->next = vz_conn_list;
vz_conn_list = privconn;
virMutexUnlock(&vz_driver_lock);
return VIR_DRV_OPEN_SUCCESS;
error:
conn->privateData = NULL;
virObjectUnref(driver);
VIR_FREE(privconn);
return VIR_DRV_OPEN_ERROR;
}
static int
vzConnectClose(virConnectPtr conn)
{
vzConnPtr curr, *prev = &vz_conn_list;
vzConnPtr privconn = conn->privateData;
if (!privconn)
return 0;
vzDriverLock(privconn);
prlsdkUnsubscribeFromPCSEvents(privconn);
virObjectUnref(privconn->caps);
virObjectUnref(privconn->xmlopt);
virObjectUnref(privconn->domains);
virObjectUnref(privconn->closeCallback);
privconn->closeCallback = NULL;
virObjectEventStateFree(privconn->domainEventState);
prlsdkDisconnect(privconn);
conn->privateData = NULL;
prlsdkDeinit();
virMutexLock(&vz_driver_lock);
for (curr = vz_conn_list; curr; prev = &curr->next, curr = curr->next) {
if (curr == privconn) {
*prev = curr->next;
break;
}
}
vzDriverUnlock(privconn);
virMutexDestroy(&privconn->lock);
virMutexUnlock(&vz_driver_lock);
virObjectUnref(privconn->closeCallback);
virObjectUnref(privconn->driver);
VIR_FREE(privconn);
conn->privateData = NULL;
return 0;
}
......@@ -354,7 +411,7 @@ static int
vzConnectGetVersion(virConnectPtr conn, unsigned long *hvVer)
{
vzConnPtr privconn = conn->privateData;
*hvVer = privconn->vzVersion;
*hvVer = privconn->driver->vzVersion;
return 0;
}
......@@ -372,7 +429,7 @@ vzConnectListDomains(virConnectPtr conn, int *ids, int maxids)
int n;
vzDriverLock(privconn);
n = virDomainObjListGetActiveIDs(privconn->domains, ids, maxids,
n = virDomainObjListGetActiveIDs(privconn->driver->domains, ids, maxids,
NULL, NULL);
vzDriverUnlock(privconn);
......@@ -386,7 +443,7 @@ vzConnectNumOfDomains(virConnectPtr conn)
int count;
vzDriverLock(privconn);
count = virDomainObjListNumOfDomains(privconn->domains, true,
count = virDomainObjListNumOfDomains(privconn->driver->domains, true,
NULL, NULL);
vzDriverUnlock(privconn);
......@@ -401,7 +458,7 @@ vzConnectListDefinedDomains(virConnectPtr conn, char **const names, int maxnames
vzDriverLock(privconn);
memset(names, 0, sizeof(*names) * maxnames);
n = virDomainObjListGetInactiveNames(privconn->domains, names,
n = virDomainObjListGetInactiveNames(privconn->driver->domains, names,
maxnames, NULL, NULL);
vzDriverUnlock(privconn);
......@@ -415,7 +472,7 @@ vzConnectNumOfDefinedDomains(virConnectPtr conn)
int count;
vzDriverLock(privconn);
count = virDomainObjListNumOfDomains(privconn->domains, false,
count = virDomainObjListNumOfDomains(privconn->driver->domains, false,
NULL, NULL);
vzDriverUnlock(privconn);
......@@ -432,7 +489,7 @@ vzConnectListAllDomains(virConnectPtr conn,
virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1);
vzDriverLock(privconn);
ret = virDomainObjListExport(privconn->domains, conn, domains,
ret = virDomainObjListExport(privconn->driver->domains, conn, domains,
NULL, flags);
vzDriverUnlock(privconn);
......@@ -447,7 +504,7 @@ vzDomainLookupByID(virConnectPtr conn, int id)
virDomainObjPtr dom;
vzDriverLock(privconn);
dom = virDomainObjListFindByID(privconn->domains, id);
dom = virDomainObjListFindByID(privconn->driver->domains, id);
vzDriverUnlock(privconn);
if (dom == NULL) {
......@@ -473,7 +530,8 @@ vzDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
virDomainObjPtr dom;
vzDriverLock(privconn);
dom = virDomainObjListFindByUUID(privconn->domains, uuid);
dom = virDomainObjListFindByUUID(privconn->driver->domains, uuid);
vzDriverUnlock(privconn);
if (dom == NULL) {
......@@ -502,7 +560,7 @@ vzDomainLookupByName(virConnectPtr conn, const char *name)
virDomainObjPtr dom;
vzDriverLock(privconn);
dom = virDomainObjListFindByName(privconn->domains, name);
dom = virDomainObjListFindByName(privconn->driver->domains, name);
vzDriverUnlock(privconn);
if (dom == NULL) {
......@@ -626,7 +684,7 @@ vzDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
def = (flags & VIR_DOMAIN_XML_INACTIVE) &&
privdom->newDef ? privdom->newDef : privdom->def;
ret = virDomainDefFormat(def, privconn->caps, flags);
ret = virDomainDefFormat(def, privconn->driver->caps, flags);
cleanup:
if (privdom)
......@@ -661,28 +719,29 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
virDomainObjPtr olddom = NULL;
virDomainObjPtr newdom = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
vzDriverPtr driver = privconn->driver;
virCheckFlags(VIR_DOMAIN_DEFINE_VALIDATE, NULL);
if (flags & VIR_DOMAIN_DEFINE_VALIDATE)
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE;
vzDriverLock(privconn);
if ((def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt,
virObjectLock(driver);
if ((def = virDomainDefParseString(xml, driver->caps, driver->xmlopt,
parse_flags)) == NULL)
goto cleanup;
olddom = virDomainObjListFindByUUID(privconn->domains, def->uuid);
olddom = virDomainObjListFindByUUID(driver->domains, def->uuid);
if (olddom == NULL) {
virResetLastError();
newdom = vzNewDomain(privconn, def->name, def->uuid);
newdom = vzNewDomain(driver, def->name, def->uuid);
if (!newdom)
goto cleanup;
if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
if (prlsdkCreateVm(conn, def))
if (prlsdkCreateVm(driver, def))
goto cleanup;
} else if (def->os.type == VIR_DOMAIN_OSTYPE_EXE) {
if (prlsdkCreateCt(conn, def))
if (prlsdkCreateCt(driver, def))
goto cleanup;
} else {
virReportError(VIR_ERR_INVALID_ARG,
......@@ -691,7 +750,7 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
goto cleanup;
}
if (prlsdkLoadDomain(privconn, newdom))
if (prlsdkLoadDomain(driver, newdom))
goto cleanup;
} else {
int state, reason;
......@@ -717,10 +776,10 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
goto cleanup;
}
} else {
if (prlsdkApplyConfig(conn, olddom, def))
if (prlsdkApplyConfig(driver, olddom, def))
goto cleanup;
if (prlsdkUpdateDomain(privconn, olddom))
if (prlsdkUpdateDomain(driver, olddom))
goto cleanup;
}
}
......@@ -734,12 +793,12 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
virObjectUnlock(olddom);
if (newdom) {
if (!retdom)
virDomainObjListRemove(privconn->domains, newdom);
virDomainObjListRemove(driver->domains, newdom);
else
virObjectUnlock(newdom);
}
virDomainDefFree(def);
vzDriverUnlock(privconn);
virObjectUnlock(driver);
return retdom;
}
......@@ -855,7 +914,7 @@ vzConnectDomainEventRegisterAny(virConnectPtr conn,
int ret = -1;
vzConnPtr privconn = conn->privateData;
if (virDomainEventStateRegisterID(conn,
privconn->domainEventState,
privconn->driver->domainEventState,
domain, eventID,
callback, opaque, freecb, &ret) < 0)
ret = -1;
......@@ -870,7 +929,7 @@ vzConnectDomainEventDeregisterAny(virConnectPtr conn,
int ret = -1;
if (virObjectEventStateDeregisterID(conn,
privconn->domainEventState,
privconn->driver->domainEventState,
callbackID) < 0)
goto cleanup;
......@@ -949,7 +1008,7 @@ vzDomainUndefineFlags(virDomainPtr domain,
if (!(dom = vzDomObjFromDomain(domain)))
return -1;
ret = prlsdkUnregisterDomain(privconn, dom, flags);
ret = prlsdkUnregisterDomain(privconn->driver, dom, flags);
if (ret)
virObjectUnlock(dom);
......@@ -999,12 +1058,12 @@ vzDomainManagedSave(virDomainPtr domain, unsigned int flags)
state = virDomainObjGetState(dom, &reason);
if (state == VIR_DOMAIN_RUNNING && (flags & VIR_DOMAIN_SAVE_PAUSED)) {
ret = prlsdkDomainChangeStateLocked(privconn, dom, prlsdkPause);
ret = prlsdkDomainChangeStateLocked(privconn->driver, dom, prlsdkPause);
if (ret)
goto cleanup;
}
ret = prlsdkDomainChangeStateLocked(privconn, dom, prlsdkSuspend);
ret = prlsdkDomainChangeStateLocked(privconn->driver, dom, prlsdkSuspend);
cleanup:
virObjectUnlock(dom);
......@@ -1074,14 +1133,14 @@ static int vzDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
if (vzCheckConfigUpdateFlags(privdom, &flags) < 0)
goto cleanup;
dev = virDomainDeviceDefParse(xml, privdom->def, privconn->caps,
privconn->xmlopt, VIR_DOMAIN_XML_INACTIVE);
dev = virDomainDeviceDefParse(xml, privdom->def, privconn->driver->caps,
privconn->driver->xmlopt, VIR_DOMAIN_XML_INACTIVE);
if (dev == NULL)
goto cleanup;
switch (dev->type) {
case VIR_DOMAIN_DEVICE_DISK:
ret = prlsdkAttachVolume(privconn, privdom, dev->data.disk);
ret = prlsdkAttachVolume(privconn->driver, privdom, dev->data.disk);
if (ret) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("disk attach failed"));
......@@ -1089,7 +1148,7 @@ static int vzDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
}
break;
case VIR_DOMAIN_DEVICE_NET:
ret = prlsdkAttachNet(privconn, privdom, dev->data.net);
ret = prlsdkAttachNet(privconn->driver, privdom, dev->data.net);
if (ret) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("network attach failed"));
......@@ -1133,8 +1192,8 @@ static int vzDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
if (vzCheckConfigUpdateFlags(privdom, &flags) < 0)
goto cleanup;
dev = virDomainDeviceDefParse(xml, privdom->def, privconn->caps,
privconn->xmlopt, VIR_DOMAIN_XML_INACTIVE);
dev = virDomainDeviceDefParse(xml, privdom->def, privconn->driver->caps,
privconn->driver->xmlopt, VIR_DOMAIN_XML_INACTIVE);
if (dev == NULL)
goto cleanup;
......@@ -1148,7 +1207,7 @@ static int vzDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
}
break;
case VIR_DOMAIN_DEVICE_NET:
ret = prlsdkDetachNet(privconn, privdom, dev->data.net);
ret = prlsdkDetachNet(privconn->driver, privdom, dev->data.net);
if (ret) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("network detach failed"));
......@@ -1165,6 +1224,7 @@ static int vzDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
ret = 0;
cleanup:
virObjectUnlock(privdom);
return ret;
}
......@@ -1437,7 +1497,6 @@ vzConnectRegisterCloseCallback(virConnectPtr conn,
int ret = -1;
vzDriverLock(privconn);
if (virConnectCloseCallbackDataGetCallback(privconn->closeCallback) != NULL) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("A close callback is already registered"));
......@@ -1583,6 +1642,45 @@ static virConnectDriver vzConnectDriver = {
.hypervisorDriver = &vzHypervisorDriver,
};
static int
vzStateCleanup(void)
{
virObjectUnref(vz_driver);
vz_driver = NULL;
virMutexDestroy(&vz_driver_lock);
prlsdkDeinit();
return 0;
}
static int
vzStateInitialize(bool privileged ATTRIBUTE_UNUSED,
virStateInhibitCallback callback ATTRIBUTE_UNUSED,
void *opaque ATTRIBUTE_UNUSED)
{
if (prlsdkInit() < 0) {
VIR_DEBUG("%s", _("Can't initialize Parallels SDK"));
return -1;
}
if (virMutexInit(&vz_driver_lock) < 0)
goto error;
/* Failing to create driver here is not fatal and only means
* that next driver client will try once more when connecting */
vz_driver = vzDriverObjNew();
return 0;
error:
vzStateCleanup();
return -1;
}
static virStateDriver vzStateDriver = {
.name = "vz",
.stateInitialize = vzStateInitialize,
.stateCleanup = vzStateCleanup,
};
/* Parallels domain type backward compatibility*/
static virHypervisorDriver parallelsHypervisorDriver;
static virConnectDriver parallelsConnectDriver;
......@@ -1616,5 +1714,8 @@ vzRegister(void)
if (virRegisterConnectDriver(&vzConnectDriver, false) < 0)
return -1;
if (virRegisterStateDriver(&vzStateDriver) < 0)
return -1;
return 0;
}
此差异已折叠。
......@@ -26,16 +26,16 @@
int prlsdkInit(void);
void prlsdkDeinit(void);
int prlsdkConnect(vzConnPtr privconn);
void prlsdkDisconnect(vzConnPtr privconn);
int prlsdkConnect(vzDriverPtr driver);
void prlsdkDisconnect(vzDriverPtr driver);
int
prlsdkLoadDomains(vzConnPtr privconn);
int prlsdkUpdateDomain(vzConnPtr privconn, virDomainObjPtr dom);
prlsdkLoadDomains(vzDriverPtr driver);
int prlsdkUpdateDomain(vzDriverPtr driver, virDomainObjPtr dom);
int
prlsdkLoadDomain(vzConnPtr privconn,
prlsdkLoadDomain(vzDriverPtr driver,
virDomainObjPtr dom);
int prlsdkSubscribeToPCSEvents(vzConnPtr privconn);
void prlsdkUnsubscribeFromPCSEvents(vzConnPtr privconn);
int prlsdkSubscribeToPCSEvents(vzDriverPtr driver);
void prlsdkUnsubscribeFromPCSEvents(vzDriverPtr driver);
PRL_RESULT prlsdkStart(PRL_HANDLE sdkdom);
PRL_RESULT prlsdkKill(PRL_HANDLE sdkdom);
PRL_RESULT prlsdkStop(PRL_HANDLE sdkdom);
......@@ -49,29 +49,29 @@ int
prlsdkDomainChangeState(virDomainPtr domain,
prlsdkChangeStateFunc chstate);
int
prlsdkDomainChangeStateLocked(vzConnPtr privconn,
prlsdkDomainChangeStateLocked(vzDriverPtr driver,
virDomainObjPtr dom,
prlsdkChangeStateFunc chstate);
int
prlsdkApplyConfig(virConnectPtr conn,
prlsdkApplyConfig(vzDriverPtr driver,
virDomainObjPtr dom,
virDomainDefPtr new);
int prlsdkCreateVm(virConnectPtr conn, virDomainDefPtr def);
int prlsdkCreateCt(virConnectPtr conn, virDomainDefPtr def);
int prlsdkCreateVm(vzDriverPtr driver, virDomainDefPtr def);
int prlsdkCreateCt(vzDriverPtr driver, virDomainDefPtr def);
int
prlsdkUnregisterDomain(vzConnPtr privconn, virDomainObjPtr dom, unsigned int flags);
prlsdkUnregisterDomain(vzDriverPtr driver, virDomainObjPtr dom, unsigned int flags);
int
prlsdkDomainManagedSaveRemove(virDomainObjPtr dom);
int
prlsdkAttachVolume(vzConnPtr privconn, virDomainObjPtr dom, virDomainDiskDefPtr disk);
prlsdkAttachVolume(vzDriverPtr driver, virDomainObjPtr dom, virDomainDiskDefPtr disk);
int
prlsdkDetachVolume(virDomainObjPtr dom, virDomainDiskDefPtr disk);
int
prlsdkGetBlockStats(virDomainObjPtr dom, virDomainDiskDefPtr disk, virDomainBlockStatsPtr stats);
int
prlsdkAttachNet(vzConnPtr privconn, virDomainObjPtr dom, virDomainNetDefPtr net);
prlsdkAttachNet(vzDriverPtr driver, virDomainObjPtr dom, virDomainNetDefPtr net);
int
prlsdkDetachNet(vzConnPtr privconn, virDomainObjPtr dom, virDomainNetDefPtr net);
prlsdkDetachNet(vzDriverPtr driver, virDomainObjPtr dom, virDomainNetDefPtr net);
int
prlsdkGetNetStats(virDomainObjPtr dom, const char *path, virDomainInterfaceStatsPtr stats);
int
......
......@@ -73,8 +73,9 @@ vzDomObjFromDomain(virDomainPtr domain)
virDomainObjPtr vm;
vzConnPtr privconn = domain->conn->privateData;
char uuidstr[VIR_UUID_STRING_BUFLEN];
vzDriverPtr driver = privconn->driver;
vm = virDomainObjListFindByUUID(privconn->domains, domain->uuid);
vm = virDomainObjListFindByUUID(driver->domains, domain->uuid);
if (!vm) {
virUUIDFormat(domain->uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN,
......@@ -84,7 +85,6 @@ vzDomObjFromDomain(virDomainPtr domain)
}
return vm;
}
/**
......@@ -103,8 +103,9 @@ vzDomObjFromDomainRef(virDomainPtr domain)
virDomainObjPtr vm;
vzConnPtr privconn = domain->conn->privateData;
char uuidstr[VIR_UUID_STRING_BUFLEN];
vzDriverPtr driver = privconn->driver;
vm = virDomainObjListFindByUUIDRef(privconn->domains, domain->uuid);
vm = virDomainObjListFindByUUIDRef(driver->domains, domain->uuid);
if (!vm) {
virUUIDFormat(domain->uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN,
......@@ -159,7 +160,7 @@ vzGetOutput(const char *binary, ...)
}
virDomainObjPtr
vzNewDomain(vzConnPtr privconn, char *name, const unsigned char *uuid)
vzNewDomain(vzDriverPtr driver, char *name, const unsigned char *uuid)
{
virDomainDefPtr def = NULL;
virDomainObjPtr dom = NULL;
......@@ -180,8 +181,8 @@ vzNewDomain(vzConnPtr privconn, char *name, const unsigned char *uuid)
def->virtType = VIR_DOMAIN_VIRT_VZ;
if (!(dom = virDomainObjListAdd(privconn->domains, def,
privconn->xmlopt,
if (!(dom = virDomainObjListAdd(driver->domains, def,
driver->xmlopt,
0, NULL)))
goto error;
......@@ -199,7 +200,7 @@ vzNewDomain(vzConnPtr privconn, char *name, const unsigned char *uuid)
}
static void
vzInitCaps(unsigned long vzVersion, vzCapabilities *vzCaps)
vzInitCaps(unsigned long vzVersion, vzCapabilitiesPtr vzCaps)
{
if (vzVersion < VIRTUOZZO_VER_7) {
vzCaps->ctDiskFormat = VIR_STORAGE_FILE_PLOOP;
......@@ -217,7 +218,7 @@ vzInitCaps(unsigned long vzVersion, vzCapabilities *vzCaps)
}
int
vzInitVersion(vzConnPtr privconn)
vzInitVersion(vzDriverPtr driver)
{
char *output, *sVer, *tmp;
const char *searchStr = "prlsrvctl version ";
......@@ -250,12 +251,12 @@ vzInitVersion(vzConnPtr privconn)
}
tmp[0] = '\0';
if (virParseVersionString(sVer, &(privconn->vzVersion), true) < 0) {
if (virParseVersionString(sVer, &(driver->vzVersion), true) < 0) {
vzParseError();
goto cleanup;
}
vzInitCaps(privconn->vzVersion, &privconn->vzCaps);
vzInitCaps(driver->vzVersion, &driver->vzCaps);
ret = 0;
cleanup:
......@@ -474,10 +475,10 @@ vzCheckUnsupportedControllers(virDomainDefPtr def, vzCapabilitiesPtr vzCaps)
return 0;
}
int vzGetDefaultSCSIModel(vzConnPtr privconn,
int vzGetDefaultSCSIModel(vzDriverPtr driver,
PRL_CLUSTERED_DEVICE_SUBTYPE *scsiModel)
{
switch (privconn->vzCaps.scsiControllerModel) {
switch (driver->vzCaps.scsiControllerModel) {
case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VIRTIO_SCSI:
*scsiModel = PCD_VIRTIO_SCSI;
break;
......@@ -488,7 +489,7 @@ int vzGetDefaultSCSIModel(vzConnPtr privconn,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unknown SCSI controller model %s"),
virDomainControllerModelSCSITypeToString(
privconn->vzCaps.scsiControllerModel));
driver->vzCaps.scsiControllerModel));
return -1;
}
return 0;
......
......@@ -60,8 +60,8 @@ struct _vzCapabilities {
typedef struct _vzCapabilities vzCapabilities;
typedef struct _vzCapabilities *vzCapabilitiesPtr;
struct _vzConn {
virMutex lock;
struct _vzDriver {
virObjectLockable parent;
/* Immutable pointer, self-locking APIs */
virDomainObjListPtr domains;
......@@ -70,15 +70,25 @@ struct _vzConn {
virCapsPtr caps;
virDomainXMLOptionPtr xmlopt;
virObjectEventStatePtr domainEventState;
/* Immutable pointer, self-locking APIs */
virConnectCloseCallbackDataPtr closeCallback;
unsigned long vzVersion;
vzCapabilities vzCaps;
};
typedef struct _vzDriver vzDriver;
typedef struct _vzDriver *vzDriverPtr;
struct _vzConn {
struct _vzConn* next;
vzDriverPtr driver;
/* Immutable pointer, self-locking APIs */
virConnectCloseCallbackDataPtr closeCallback;
};
typedef struct _vzConn vzConn;
typedef struct _vzConn *vzConnPtr;
struct _vzCountersCache {
PRL_HANDLE stats;
virCond cond;
......@@ -105,12 +115,19 @@ char * vzGetOutput(const char *binary, ...)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_SENTINEL;
void vzDriverLock(vzConnPtr driver);
void vzDriverUnlock(vzConnPtr driver);
vzDriverPtr
vzGetDriverConnection(void);
void
vzDestroyDriverConnection(void);
virDomainObjPtr
vzNewDomain(vzConnPtr privconn,
vzNewDomain(vzDriverPtr driver,
char *name,
const unsigned char *uuid);
int
vzInitVersion(vzConnPtr privconn);
vzInitVersion(vzDriverPtr driver);
int
vzCheckUnsupportedDisks(virDomainDefPtr def,
vzCapabilitiesPtr vzCaps);
......@@ -118,7 +135,7 @@ int
vzCheckUnsupportedControllers(virDomainDefPtr def,
vzCapabilitiesPtr vzCaps);
int
vzGetDefaultSCSIModel(vzConnPtr privconn,
vzGetDefaultSCSIModel(vzDriverPtr driver,
PRL_CLUSTERED_DEVICE_SUBTYPE *scsiModel);
# define PARALLELS_BLOCK_STATS_FOREACH(OP) \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册