提交 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"); ...@@ -63,19 +63,27 @@ VIR_LOG_INIT("parallels.parallels_driver");
#define PRLCTL "prlctl" #define PRLCTL "prlctl"
static int vzConnectClose(virConnectPtr conn); static int vzConnectClose(virConnectPtr conn);
static virClassPtr vzDriverClass;
void void
vzDriverLock(vzConnPtr driver) vzDriverLock(vzConnPtr privconn)
{ {
virMutexLock(&driver->lock); virObjectLock(privconn->driver);
} }
void 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 static int
vzCapsAddGuestDomain(virCapsPtr caps, vzCapsAddGuestDomain(virCapsPtr caps,
virDomainOSType ostype, virDomainOSType ostype,
...@@ -158,6 +166,70 @@ vzBuildCapabilities(void) ...@@ -158,6 +166,70 @@ vzBuildCapabilities(void)
goto cleanup; 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 * static char *
vzConnectGetCapabilities(virConnectPtr conn) vzConnectGetCapabilities(virConnectPtr conn)
{ {
...@@ -165,7 +237,7 @@ vzConnectGetCapabilities(virConnectPtr conn) ...@@ -165,7 +237,7 @@ vzConnectGetCapabilities(virConnectPtr conn)
char *xml; char *xml;
vzDriverLock(privconn); vzDriverLock(privconn);
xml = virCapabilitiesFormatXML(privconn->caps); xml = virCapabilitiesFormatXML(privconn->driver->caps);
vzDriverUnlock(privconn); vzDriverUnlock(privconn);
return xml; return xml;
} }
...@@ -214,70 +286,34 @@ virDomainDefParserConfig vzDomainDefParserConfig = { ...@@ -214,70 +286,34 @@ virDomainDefParserConfig vzDomainDefParserConfig = {
.domainPostParseCallback = vzDomainDefPostParse, .domainPostParseCallback = vzDomainDefPostParse,
}; };
static vzDriverPtr
static int vzDriverObjNew(void)
vzOpenDefault(virConnectPtr conn)
{ {
vzConnPtr privconn; vzDriverPtr driver;
if (VIR_ALLOC(privconn) < 0) if (vzDriverInitialize() < 0)
return VIR_DRV_OPEN_ERROR; return NULL;
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 (prlsdkLoadDomains(privconn)) if (!(driver = virObjectLockableNew(vzDriverClass)))
goto error; 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: ignore_value(prlsdkLoadDomains(driver));
virObjectUnref(privconn->closeCallback); return driver;
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;
} }
static virDrvOpenStatus static virDrvOpenStatus
...@@ -285,7 +321,8 @@ vzConnectOpen(virConnectPtr conn, ...@@ -285,7 +321,8 @@ vzConnectOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED, virConnectAuthPtr auth ATTRIBUTE_UNUSED,
unsigned int flags) unsigned int flags)
{ {
int ret; vzDriverPtr driver = NULL;
vzConnPtr privconn = NULL;
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
...@@ -317,36 +354,56 @@ vzConnectOpen(virConnectPtr conn, ...@@ -317,36 +354,56 @@ vzConnectOpen(virConnectPtr conn,
return VIR_DRV_OPEN_ERROR; return VIR_DRV_OPEN_ERROR;
} }
if ((ret = vzOpenDefault(conn)) != VIR_DRV_OPEN_SUCCESS) if (!(driver = vzGetDriverConnection()))
return ret; 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; return VIR_DRV_OPEN_SUCCESS;
error:
conn->privateData = NULL;
virObjectUnref(driver);
VIR_FREE(privconn);
return VIR_DRV_OPEN_ERROR;
} }
static int static int
vzConnectClose(virConnectPtr conn) vzConnectClose(virConnectPtr conn)
{ {
vzConnPtr curr, *prev = &vz_conn_list;
vzConnPtr privconn = conn->privateData; vzConnPtr privconn = conn->privateData;
if (!privconn) if (!privconn)
return 0; return 0;
vzDriverLock(privconn); virMutexLock(&vz_driver_lock);
prlsdkUnsubscribeFromPCSEvents(privconn); for (curr = vz_conn_list; curr; prev = &curr->next, curr = curr->next) {
virObjectUnref(privconn->caps); if (curr == privconn) {
virObjectUnref(privconn->xmlopt); *prev = curr->next;
virObjectUnref(privconn->domains); break;
virObjectUnref(privconn->closeCallback); }
privconn->closeCallback = NULL; }
virObjectEventStateFree(privconn->domainEventState);
prlsdkDisconnect(privconn);
conn->privateData = NULL;
prlsdkDeinit();
vzDriverUnlock(privconn); virMutexUnlock(&vz_driver_lock);
virMutexDestroy(&privconn->lock);
virObjectUnref(privconn->closeCallback);
virObjectUnref(privconn->driver);
VIR_FREE(privconn); VIR_FREE(privconn);
conn->privateData = NULL;
return 0; return 0;
} }
...@@ -354,7 +411,7 @@ static int ...@@ -354,7 +411,7 @@ static int
vzConnectGetVersion(virConnectPtr conn, unsigned long *hvVer) vzConnectGetVersion(virConnectPtr conn, unsigned long *hvVer)
{ {
vzConnPtr privconn = conn->privateData; vzConnPtr privconn = conn->privateData;
*hvVer = privconn->vzVersion; *hvVer = privconn->driver->vzVersion;
return 0; return 0;
} }
...@@ -372,7 +429,7 @@ vzConnectListDomains(virConnectPtr conn, int *ids, int maxids) ...@@ -372,7 +429,7 @@ vzConnectListDomains(virConnectPtr conn, int *ids, int maxids)
int n; int n;
vzDriverLock(privconn); vzDriverLock(privconn);
n = virDomainObjListGetActiveIDs(privconn->domains, ids, maxids, n = virDomainObjListGetActiveIDs(privconn->driver->domains, ids, maxids,
NULL, NULL); NULL, NULL);
vzDriverUnlock(privconn); vzDriverUnlock(privconn);
...@@ -386,7 +443,7 @@ vzConnectNumOfDomains(virConnectPtr conn) ...@@ -386,7 +443,7 @@ vzConnectNumOfDomains(virConnectPtr conn)
int count; int count;
vzDriverLock(privconn); vzDriverLock(privconn);
count = virDomainObjListNumOfDomains(privconn->domains, true, count = virDomainObjListNumOfDomains(privconn->driver->domains, true,
NULL, NULL); NULL, NULL);
vzDriverUnlock(privconn); vzDriverUnlock(privconn);
...@@ -401,7 +458,7 @@ vzConnectListDefinedDomains(virConnectPtr conn, char **const names, int maxnames ...@@ -401,7 +458,7 @@ vzConnectListDefinedDomains(virConnectPtr conn, char **const names, int maxnames
vzDriverLock(privconn); vzDriverLock(privconn);
memset(names, 0, sizeof(*names) * maxnames); memset(names, 0, sizeof(*names) * maxnames);
n = virDomainObjListGetInactiveNames(privconn->domains, names, n = virDomainObjListGetInactiveNames(privconn->driver->domains, names,
maxnames, NULL, NULL); maxnames, NULL, NULL);
vzDriverUnlock(privconn); vzDriverUnlock(privconn);
...@@ -415,7 +472,7 @@ vzConnectNumOfDefinedDomains(virConnectPtr conn) ...@@ -415,7 +472,7 @@ vzConnectNumOfDefinedDomains(virConnectPtr conn)
int count; int count;
vzDriverLock(privconn); vzDriverLock(privconn);
count = virDomainObjListNumOfDomains(privconn->domains, false, count = virDomainObjListNumOfDomains(privconn->driver->domains, false,
NULL, NULL); NULL, NULL);
vzDriverUnlock(privconn); vzDriverUnlock(privconn);
...@@ -432,7 +489,7 @@ vzConnectListAllDomains(virConnectPtr conn, ...@@ -432,7 +489,7 @@ vzConnectListAllDomains(virConnectPtr conn,
virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1); virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1);
vzDriverLock(privconn); vzDriverLock(privconn);
ret = virDomainObjListExport(privconn->domains, conn, domains, ret = virDomainObjListExport(privconn->driver->domains, conn, domains,
NULL, flags); NULL, flags);
vzDriverUnlock(privconn); vzDriverUnlock(privconn);
...@@ -447,7 +504,7 @@ vzDomainLookupByID(virConnectPtr conn, int id) ...@@ -447,7 +504,7 @@ vzDomainLookupByID(virConnectPtr conn, int id)
virDomainObjPtr dom; virDomainObjPtr dom;
vzDriverLock(privconn); vzDriverLock(privconn);
dom = virDomainObjListFindByID(privconn->domains, id); dom = virDomainObjListFindByID(privconn->driver->domains, id);
vzDriverUnlock(privconn); vzDriverUnlock(privconn);
if (dom == NULL) { if (dom == NULL) {
...@@ -473,7 +530,8 @@ vzDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) ...@@ -473,7 +530,8 @@ vzDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
virDomainObjPtr dom; virDomainObjPtr dom;
vzDriverLock(privconn); vzDriverLock(privconn);
dom = virDomainObjListFindByUUID(privconn->domains, uuid);
dom = virDomainObjListFindByUUID(privconn->driver->domains, uuid);
vzDriverUnlock(privconn); vzDriverUnlock(privconn);
if (dom == NULL) { if (dom == NULL) {
...@@ -502,7 +560,7 @@ vzDomainLookupByName(virConnectPtr conn, const char *name) ...@@ -502,7 +560,7 @@ vzDomainLookupByName(virConnectPtr conn, const char *name)
virDomainObjPtr dom; virDomainObjPtr dom;
vzDriverLock(privconn); vzDriverLock(privconn);
dom = virDomainObjListFindByName(privconn->domains, name); dom = virDomainObjListFindByName(privconn->driver->domains, name);
vzDriverUnlock(privconn); vzDriverUnlock(privconn);
if (dom == NULL) { if (dom == NULL) {
...@@ -626,7 +684,7 @@ vzDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) ...@@ -626,7 +684,7 @@ vzDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
def = (flags & VIR_DOMAIN_XML_INACTIVE) && def = (flags & VIR_DOMAIN_XML_INACTIVE) &&
privdom->newDef ? privdom->newDef : privdom->def; privdom->newDef ? privdom->newDef : privdom->def;
ret = virDomainDefFormat(def, privconn->caps, flags); ret = virDomainDefFormat(def, privconn->driver->caps, flags);
cleanup: cleanup:
if (privdom) if (privdom)
...@@ -661,28 +719,29 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) ...@@ -661,28 +719,29 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
virDomainObjPtr olddom = NULL; virDomainObjPtr olddom = NULL;
virDomainObjPtr newdom = NULL; virDomainObjPtr newdom = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE; unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
vzDriverPtr driver = privconn->driver;
virCheckFlags(VIR_DOMAIN_DEFINE_VALIDATE, NULL); virCheckFlags(VIR_DOMAIN_DEFINE_VALIDATE, NULL);
if (flags & VIR_DOMAIN_DEFINE_VALIDATE) if (flags & VIR_DOMAIN_DEFINE_VALIDATE)
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE; parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE;
vzDriverLock(privconn); virObjectLock(driver);
if ((def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt, if ((def = virDomainDefParseString(xml, driver->caps, driver->xmlopt,
parse_flags)) == NULL) parse_flags)) == NULL)
goto cleanup; goto cleanup;
olddom = virDomainObjListFindByUUID(privconn->domains, def->uuid); olddom = virDomainObjListFindByUUID(driver->domains, def->uuid);
if (olddom == NULL) { if (olddom == NULL) {
virResetLastError(); virResetLastError();
newdom = vzNewDomain(privconn, def->name, def->uuid); newdom = vzNewDomain(driver, def->name, def->uuid);
if (!newdom) if (!newdom)
goto cleanup; goto cleanup;
if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) { if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
if (prlsdkCreateVm(conn, def)) if (prlsdkCreateVm(driver, def))
goto cleanup; goto cleanup;
} else if (def->os.type == VIR_DOMAIN_OSTYPE_EXE) { } else if (def->os.type == VIR_DOMAIN_OSTYPE_EXE) {
if (prlsdkCreateCt(conn, def)) if (prlsdkCreateCt(driver, def))
goto cleanup; goto cleanup;
} else { } else {
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
...@@ -691,7 +750,7 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) ...@@ -691,7 +750,7 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
goto cleanup; goto cleanup;
} }
if (prlsdkLoadDomain(privconn, newdom)) if (prlsdkLoadDomain(driver, newdom))
goto cleanup; goto cleanup;
} else { } else {
int state, reason; int state, reason;
...@@ -717,10 +776,10 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) ...@@ -717,10 +776,10 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
goto cleanup; goto cleanup;
} }
} else { } else {
if (prlsdkApplyConfig(conn, olddom, def)) if (prlsdkApplyConfig(driver, olddom, def))
goto cleanup; goto cleanup;
if (prlsdkUpdateDomain(privconn, olddom)) if (prlsdkUpdateDomain(driver, olddom))
goto cleanup; goto cleanup;
} }
} }
...@@ -734,12 +793,12 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) ...@@ -734,12 +793,12 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
virObjectUnlock(olddom); virObjectUnlock(olddom);
if (newdom) { if (newdom) {
if (!retdom) if (!retdom)
virDomainObjListRemove(privconn->domains, newdom); virDomainObjListRemove(driver->domains, newdom);
else else
virObjectUnlock(newdom); virObjectUnlock(newdom);
} }
virDomainDefFree(def); virDomainDefFree(def);
vzDriverUnlock(privconn); virObjectUnlock(driver);
return retdom; return retdom;
} }
...@@ -855,7 +914,7 @@ vzConnectDomainEventRegisterAny(virConnectPtr conn, ...@@ -855,7 +914,7 @@ vzConnectDomainEventRegisterAny(virConnectPtr conn,
int ret = -1; int ret = -1;
vzConnPtr privconn = conn->privateData; vzConnPtr privconn = conn->privateData;
if (virDomainEventStateRegisterID(conn, if (virDomainEventStateRegisterID(conn,
privconn->domainEventState, privconn->driver->domainEventState,
domain, eventID, domain, eventID,
callback, opaque, freecb, &ret) < 0) callback, opaque, freecb, &ret) < 0)
ret = -1; ret = -1;
...@@ -870,7 +929,7 @@ vzConnectDomainEventDeregisterAny(virConnectPtr conn, ...@@ -870,7 +929,7 @@ vzConnectDomainEventDeregisterAny(virConnectPtr conn,
int ret = -1; int ret = -1;
if (virObjectEventStateDeregisterID(conn, if (virObjectEventStateDeregisterID(conn,
privconn->domainEventState, privconn->driver->domainEventState,
callbackID) < 0) callbackID) < 0)
goto cleanup; goto cleanup;
...@@ -949,7 +1008,7 @@ vzDomainUndefineFlags(virDomainPtr domain, ...@@ -949,7 +1008,7 @@ vzDomainUndefineFlags(virDomainPtr domain,
if (!(dom = vzDomObjFromDomain(domain))) if (!(dom = vzDomObjFromDomain(domain)))
return -1; return -1;
ret = prlsdkUnregisterDomain(privconn, dom, flags); ret = prlsdkUnregisterDomain(privconn->driver, dom, flags);
if (ret) if (ret)
virObjectUnlock(dom); virObjectUnlock(dom);
...@@ -999,12 +1058,12 @@ vzDomainManagedSave(virDomainPtr domain, unsigned int flags) ...@@ -999,12 +1058,12 @@ vzDomainManagedSave(virDomainPtr domain, unsigned int flags)
state = virDomainObjGetState(dom, &reason); state = virDomainObjGetState(dom, &reason);
if (state == VIR_DOMAIN_RUNNING && (flags & VIR_DOMAIN_SAVE_PAUSED)) { if (state == VIR_DOMAIN_RUNNING && (flags & VIR_DOMAIN_SAVE_PAUSED)) {
ret = prlsdkDomainChangeStateLocked(privconn, dom, prlsdkPause); ret = prlsdkDomainChangeStateLocked(privconn->driver, dom, prlsdkPause);
if (ret) if (ret)
goto cleanup; goto cleanup;
} }
ret = prlsdkDomainChangeStateLocked(privconn, dom, prlsdkSuspend); ret = prlsdkDomainChangeStateLocked(privconn->driver, dom, prlsdkSuspend);
cleanup: cleanup:
virObjectUnlock(dom); virObjectUnlock(dom);
...@@ -1074,14 +1133,14 @@ static int vzDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, ...@@ -1074,14 +1133,14 @@ static int vzDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
if (vzCheckConfigUpdateFlags(privdom, &flags) < 0) if (vzCheckConfigUpdateFlags(privdom, &flags) < 0)
goto cleanup; goto cleanup;
dev = virDomainDeviceDefParse(xml, privdom->def, privconn->caps, dev = virDomainDeviceDefParse(xml, privdom->def, privconn->driver->caps,
privconn->xmlopt, VIR_DOMAIN_XML_INACTIVE); privconn->driver->xmlopt, VIR_DOMAIN_XML_INACTIVE);
if (dev == NULL) if (dev == NULL)
goto cleanup; goto cleanup;
switch (dev->type) { switch (dev->type) {
case VIR_DOMAIN_DEVICE_DISK: case VIR_DOMAIN_DEVICE_DISK:
ret = prlsdkAttachVolume(privconn, privdom, dev->data.disk); ret = prlsdkAttachVolume(privconn->driver, privdom, dev->data.disk);
if (ret) { if (ret) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("disk attach failed")); _("disk attach failed"));
...@@ -1089,7 +1148,7 @@ static int vzDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, ...@@ -1089,7 +1148,7 @@ static int vzDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
} }
break; break;
case VIR_DOMAIN_DEVICE_NET: case VIR_DOMAIN_DEVICE_NET:
ret = prlsdkAttachNet(privconn, privdom, dev->data.net); ret = prlsdkAttachNet(privconn->driver, privdom, dev->data.net);
if (ret) { if (ret) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("network attach failed")); _("network attach failed"));
...@@ -1133,8 +1192,8 @@ static int vzDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, ...@@ -1133,8 +1192,8 @@ static int vzDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
if (vzCheckConfigUpdateFlags(privdom, &flags) < 0) if (vzCheckConfigUpdateFlags(privdom, &flags) < 0)
goto cleanup; goto cleanup;
dev = virDomainDeviceDefParse(xml, privdom->def, privconn->caps, dev = virDomainDeviceDefParse(xml, privdom->def, privconn->driver->caps,
privconn->xmlopt, VIR_DOMAIN_XML_INACTIVE); privconn->driver->xmlopt, VIR_DOMAIN_XML_INACTIVE);
if (dev == NULL) if (dev == NULL)
goto cleanup; goto cleanup;
...@@ -1148,7 +1207,7 @@ static int vzDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, ...@@ -1148,7 +1207,7 @@ static int vzDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
} }
break; break;
case VIR_DOMAIN_DEVICE_NET: case VIR_DOMAIN_DEVICE_NET:
ret = prlsdkDetachNet(privconn, privdom, dev->data.net); ret = prlsdkDetachNet(privconn->driver, privdom, dev->data.net);
if (ret) { if (ret) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("network detach failed")); _("network detach failed"));
...@@ -1165,6 +1224,7 @@ static int vzDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, ...@@ -1165,6 +1224,7 @@ static int vzDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
ret = 0; ret = 0;
cleanup: cleanup:
virObjectUnlock(privdom); virObjectUnlock(privdom);
return ret; return ret;
} }
...@@ -1437,7 +1497,6 @@ vzConnectRegisterCloseCallback(virConnectPtr conn, ...@@ -1437,7 +1497,6 @@ vzConnectRegisterCloseCallback(virConnectPtr conn,
int ret = -1; int ret = -1;
vzDriverLock(privconn); vzDriverLock(privconn);
if (virConnectCloseCallbackDataGetCallback(privconn->closeCallback) != NULL) { if (virConnectCloseCallbackDataGetCallback(privconn->closeCallback) != NULL) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("A close callback is already registered")); _("A close callback is already registered"));
...@@ -1583,6 +1642,45 @@ static virConnectDriver vzConnectDriver = { ...@@ -1583,6 +1642,45 @@ static virConnectDriver vzConnectDriver = {
.hypervisorDriver = &vzHypervisorDriver, .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*/ /* Parallels domain type backward compatibility*/
static virHypervisorDriver parallelsHypervisorDriver; static virHypervisorDriver parallelsHypervisorDriver;
static virConnectDriver parallelsConnectDriver; static virConnectDriver parallelsConnectDriver;
...@@ -1616,5 +1714,8 @@ vzRegister(void) ...@@ -1616,5 +1714,8 @@ vzRegister(void)
if (virRegisterConnectDriver(&vzConnectDriver, false) < 0) if (virRegisterConnectDriver(&vzConnectDriver, false) < 0)
return -1; return -1;
if (virRegisterStateDriver(&vzStateDriver) < 0)
return -1;
return 0; return 0;
} }
...@@ -234,22 +234,22 @@ prlsdkDeinit(void) ...@@ -234,22 +234,22 @@ prlsdkDeinit(void)
}; };
int int
prlsdkConnect(vzConnPtr privconn) prlsdkConnect(vzDriverPtr driver)
{ {
PRL_RESULT ret; PRL_RESULT ret;
PRL_HANDLE job = PRL_INVALID_HANDLE; PRL_HANDLE job = PRL_INVALID_HANDLE;
ret = PrlSrv_Create(&privconn->server); ret = PrlSrv_Create(&driver->server);
if (PRL_FAILED(ret)) { if (PRL_FAILED(ret)) {
logPrlError(ret); logPrlError(ret);
return -1; return -1;
} }
job = PrlSrv_LoginLocalEx(privconn->server, NULL, 0, job = PrlSrv_LoginLocalEx(driver->server, NULL, 0,
PSL_HIGH_SECURITY, PACF_NON_INTERACTIVE_MODE); PSL_HIGH_SECURITY, PACF_NON_INTERACTIVE_MODE);
if (waitJob(job)) { if (waitJob(job)) {
PrlHandle_Free(privconn->server); PrlHandle_Free(driver->server);
return -1; return -1;
} }
...@@ -257,18 +257,18 @@ prlsdkConnect(vzConnPtr privconn) ...@@ -257,18 +257,18 @@ prlsdkConnect(vzConnPtr privconn)
} }
void void
prlsdkDisconnect(vzConnPtr privconn) prlsdkDisconnect(vzDriverPtr driver)
{ {
PRL_HANDLE job; PRL_HANDLE job;
job = PrlSrv_Logoff(privconn->server); job = PrlSrv_Logoff(driver->server);
waitJob(job); waitJob(job);
PrlHandle_Free(privconn->server); PrlHandle_Free(driver->server);
} }
static int static int
prlsdkSdkDomainLookup(vzConnPtr privconn, prlsdkSdkDomainLookup(vzDriverPtr driver,
const char *id, const char *id,
unsigned int flags, unsigned int flags,
PRL_HANDLE *sdkdom) PRL_HANDLE *sdkdom)
...@@ -278,7 +278,7 @@ prlsdkSdkDomainLookup(vzConnPtr privconn, ...@@ -278,7 +278,7 @@ prlsdkSdkDomainLookup(vzConnPtr privconn,
PRL_RESULT pret = PRL_ERR_UNINITIALIZED; PRL_RESULT pret = PRL_ERR_UNINITIALIZED;
int ret = -1; int ret = -1;
job = PrlSrv_GetVmConfig(privconn->server, id, flags); job = PrlSrv_GetVmConfig(driver->server, id, flags);
if (PRL_FAILED(getJobResult(job, &result))) if (PRL_FAILED(getJobResult(job, &result)))
goto cleanup; goto cleanup;
...@@ -303,14 +303,14 @@ prlsdkUUIDFormat(const unsigned char *uuid, char *uuidstr) ...@@ -303,14 +303,14 @@ prlsdkUUIDFormat(const unsigned char *uuid, char *uuidstr)
} }
static PRL_HANDLE static PRL_HANDLE
prlsdkSdkDomainLookupByUUID(vzConnPtr privconn, const unsigned char *uuid) prlsdkSdkDomainLookupByUUID(vzDriverPtr driver, const unsigned char *uuid)
{ {
char uuidstr[VIR_UUID_STRING_BUFLEN + 2]; char uuidstr[VIR_UUID_STRING_BUFLEN + 2];
PRL_HANDLE sdkdom = PRL_INVALID_HANDLE; PRL_HANDLE sdkdom = PRL_INVALID_HANDLE;
prlsdkUUIDFormat(uuid, uuidstr); prlsdkUUIDFormat(uuid, uuidstr);
if (prlsdkSdkDomainLookup(privconn, uuidstr, if (prlsdkSdkDomainLookup(driver, uuidstr,
PGVC_SEARCH_BY_UUID, &sdkdom) < 0) { PGVC_SEARCH_BY_UUID, &sdkdom) < 0) {
virUUIDFormat(uuid, uuidstr); virUUIDFormat(uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN, virReportError(VIR_ERR_NO_DOMAIN,
...@@ -466,7 +466,7 @@ prlsdkAddDomainVideoInfo(PRL_HANDLE sdkdom, virDomainDefPtr def) ...@@ -466,7 +466,7 @@ prlsdkAddDomainVideoInfo(PRL_HANDLE sdkdom, virDomainDefPtr def)
} }
static int static int
prlsdkGetDiskInfo(vzConnPtr privconn, prlsdkGetDiskInfo(vzDriverPtr driver,
PRL_HANDLE prldisk, PRL_HANDLE prldisk,
virDomainDiskDefPtr disk, virDomainDiskDefPtr disk,
bool isCdrom, bool isCdrom,
...@@ -489,9 +489,9 @@ prlsdkGetDiskInfo(vzConnPtr privconn, ...@@ -489,9 +489,9 @@ prlsdkGetDiskInfo(vzConnPtr privconn,
virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW); virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW);
} else { } else {
if (isCt) if (isCt)
virDomainDiskSetFormat(disk, privconn->vzCaps.ctDiskFormat); virDomainDiskSetFormat(disk, driver->vzCaps.ctDiskFormat);
else else
virDomainDiskSetFormat(disk, privconn->vzCaps.vmDiskFormat); virDomainDiskSetFormat(disk, driver->vzCaps.vmDiskFormat);
} }
} else { } else {
virDomainDiskSetType(disk, VIR_STORAGE_TYPE_BLOCK); virDomainDiskSetType(disk, VIR_STORAGE_TYPE_BLOCK);
...@@ -620,7 +620,7 @@ prlsdkGetFSInfo(PRL_HANDLE prldisk, ...@@ -620,7 +620,7 @@ prlsdkGetFSInfo(PRL_HANDLE prldisk,
} }
static int static int
prlsdkAddDomainHardDisksInfo(vzConnPtr privconn, PRL_HANDLE sdkdom, virDomainDefPtr def) prlsdkAddDomainHardDisksInfo(vzDriverPtr driver, PRL_HANDLE sdkdom, virDomainDefPtr def)
{ {
PRL_RESULT pret; PRL_RESULT pret;
PRL_UINT32 hddCount; PRL_UINT32 hddCount;
...@@ -660,7 +660,7 @@ prlsdkAddDomainHardDisksInfo(vzConnPtr privconn, PRL_HANDLE sdkdom, virDomainDef ...@@ -660,7 +660,7 @@ prlsdkAddDomainHardDisksInfo(vzConnPtr privconn, PRL_HANDLE sdkdom, virDomainDef
if (!(disk = virDomainDiskDefNew(NULL))) if (!(disk = virDomainDiskDefNew(NULL)))
goto error; goto error;
if (prlsdkGetDiskInfo(privconn, hdd, disk, false, IS_CT(def)) < 0) if (prlsdkGetDiskInfo(driver, hdd, disk, false, IS_CT(def)) < 0)
goto error; goto error;
if (virDomainDiskInsert(def, disk) < 0) if (virDomainDiskInsert(def, disk) < 0)
...@@ -682,7 +682,7 @@ prlsdkAddDomainHardDisksInfo(vzConnPtr privconn, PRL_HANDLE sdkdom, virDomainDef ...@@ -682,7 +682,7 @@ prlsdkAddDomainHardDisksInfo(vzConnPtr privconn, PRL_HANDLE sdkdom, virDomainDef
} }
static int static int
prlsdkAddDomainOpticalDisksInfo(vzConnPtr privconn, PRL_HANDLE sdkdom, virDomainDefPtr def) prlsdkAddDomainOpticalDisksInfo(vzDriverPtr driver, PRL_HANDLE sdkdom, virDomainDefPtr def)
{ {
PRL_RESULT pret; PRL_RESULT pret;
PRL_UINT32 cdromsCount; PRL_UINT32 cdromsCount;
...@@ -700,7 +700,7 @@ prlsdkAddDomainOpticalDisksInfo(vzConnPtr privconn, PRL_HANDLE sdkdom, virDomain ...@@ -700,7 +700,7 @@ prlsdkAddDomainOpticalDisksInfo(vzConnPtr privconn, PRL_HANDLE sdkdom, virDomain
if (!(disk = virDomainDiskDefNew(NULL))) if (!(disk = virDomainDiskDefNew(NULL)))
goto error; goto error;
if (prlsdkGetDiskInfo(privconn, cdrom, disk, true, IS_CT(def)) < 0) if (prlsdkGetDiskInfo(driver, cdrom, disk, true, IS_CT(def)) < 0)
goto error; goto error;
PrlHandle_Free(cdrom); PrlHandle_Free(cdrom);
...@@ -961,16 +961,16 @@ prlsdkAddSerialInfo(PRL_HANDLE sdkdom, ...@@ -961,16 +961,16 @@ prlsdkAddSerialInfo(PRL_HANDLE sdkdom,
static int static int
prlsdkAddDomainHardware(vzConnPtr privconn, PRL_HANDLE sdkdom, virDomainDefPtr def) prlsdkAddDomainHardware(vzDriverPtr driver, PRL_HANDLE sdkdom, virDomainDefPtr def)
{ {
if (!IS_CT(def)) if (!IS_CT(def))
if (prlsdkAddDomainVideoInfo(sdkdom, def) < 0) if (prlsdkAddDomainVideoInfo(sdkdom, def) < 0)
goto error; goto error;
if (prlsdkAddDomainHardDisksInfo(privconn, sdkdom, def) < 0) if (prlsdkAddDomainHardDisksInfo(driver, sdkdom, def) < 0)
goto error; goto error;
if (prlsdkAddDomainOpticalDisksInfo(privconn, sdkdom, def) < 0) if (prlsdkAddDomainOpticalDisksInfo(driver, sdkdom, def) < 0)
goto error; goto error;
if (prlsdkAddDomainNetInfo(sdkdom, def) < 0) if (prlsdkAddDomainNetInfo(sdkdom, def) < 0)
...@@ -1248,7 +1248,7 @@ prlsdkConvertCpuMode(PRL_HANDLE sdkdom, virDomainDefPtr def) ...@@ -1248,7 +1248,7 @@ prlsdkConvertCpuMode(PRL_HANDLE sdkdom, virDomainDefPtr def)
} }
static virDomainObjPtr static virDomainObjPtr
prlsdkNewDomainByHandle(vzConnPtr privconn, PRL_HANDLE sdkdom) prlsdkNewDomainByHandle(vzDriverPtr driver, PRL_HANDLE sdkdom)
{ {
virDomainObjPtr dom = NULL; virDomainObjPtr dom = NULL;
unsigned char uuid[VIR_UUID_BUFLEN]; unsigned char uuid[VIR_UUID_BUFLEN];
...@@ -1257,11 +1257,11 @@ prlsdkNewDomainByHandle(vzConnPtr privconn, PRL_HANDLE sdkdom) ...@@ -1257,11 +1257,11 @@ prlsdkNewDomainByHandle(vzConnPtr privconn, PRL_HANDLE sdkdom)
if (prlsdkGetDomainIds(sdkdom, &name, uuid) < 0) if (prlsdkGetDomainIds(sdkdom, &name, uuid) < 0)
goto cleanup; goto cleanup;
if (!(dom = vzNewDomain(privconn, name, uuid))) if (!(dom = vzNewDomain(driver, name, uuid)))
goto cleanup; goto cleanup;
if (prlsdkLoadDomain(privconn, dom) < 0) { if (prlsdkLoadDomain(driver, dom) < 0) {
virDomainObjListRemove(privconn->domains, dom); virDomainObjListRemove(driver->domains, dom);
dom = NULL; dom = NULL;
goto cleanup; goto cleanup;
} }
...@@ -1507,7 +1507,7 @@ prlsdkConvertBootOrder(PRL_HANDLE sdkdom, virDomainDefPtr def) ...@@ -1507,7 +1507,7 @@ prlsdkConvertBootOrder(PRL_HANDLE sdkdom, virDomainDefPtr def)
} }
int int
prlsdkLoadDomain(vzConnPtr privconn, virDomainObjPtr dom) prlsdkLoadDomain(vzDriverPtr driver, virDomainObjPtr dom)
{ {
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
vzDomObjPtr pdom = NULL; vzDomObjPtr pdom = NULL;
...@@ -1521,11 +1521,10 @@ prlsdkLoadDomain(vzConnPtr privconn, virDomainObjPtr dom) ...@@ -1521,11 +1521,10 @@ prlsdkLoadDomain(vzConnPtr privconn, virDomainObjPtr dom)
PRL_VM_AUTOSTART_OPTION autostart; PRL_VM_AUTOSTART_OPTION autostart;
PRL_HANDLE sdkdom = PRL_INVALID_HANDLE; PRL_HANDLE sdkdom = PRL_INVALID_HANDLE;
virCheckNonNullArgGoto(privconn, error);
virCheckNonNullArgGoto(dom, error); virCheckNonNullArgGoto(dom, error);
pdom = dom->privateData; pdom = dom->privateData;
sdkdom = prlsdkSdkDomainLookupByUUID(privconn, dom->def->uuid); sdkdom = prlsdkSdkDomainLookupByUUID(driver, dom->def->uuid);
if (sdkdom == PRL_INVALID_HANDLE) if (sdkdom == PRL_INVALID_HANDLE)
return -1; return -1;
...@@ -1558,7 +1557,7 @@ prlsdkLoadDomain(vzConnPtr privconn, virDomainObjPtr dom) ...@@ -1558,7 +1557,7 @@ prlsdkLoadDomain(vzConnPtr privconn, virDomainObjPtr dom)
if (prlsdkConvertDomainType(sdkdom, def) < 0) if (prlsdkConvertDomainType(sdkdom, def) < 0)
goto error; goto error;
if (prlsdkAddDomainHardware(privconn, sdkdom, def) < 0) if (prlsdkAddDomainHardware(driver, sdkdom, def) < 0)
goto error; goto error;
/* depends on prlsdkAddDomainHardware */ /* depends on prlsdkAddDomainHardware */
...@@ -1650,7 +1649,7 @@ prlsdkLoadDomain(vzConnPtr privconn, virDomainObjPtr dom) ...@@ -1650,7 +1649,7 @@ prlsdkLoadDomain(vzConnPtr privconn, virDomainObjPtr dom)
} }
int int
prlsdkLoadDomains(vzConnPtr privconn) prlsdkLoadDomains(vzDriverPtr driver)
{ {
PRL_HANDLE job = PRL_INVALID_HANDLE; PRL_HANDLE job = PRL_INVALID_HANDLE;
PRL_HANDLE result; PRL_HANDLE result;
...@@ -1660,7 +1659,7 @@ prlsdkLoadDomains(vzConnPtr privconn) ...@@ -1660,7 +1659,7 @@ prlsdkLoadDomains(vzConnPtr privconn)
size_t i = 0; size_t i = 0;
virDomainObjPtr dom; virDomainObjPtr dom;
job = PrlSrv_GetVmListEx(privconn->server, PVTF_VM | PVTF_CT); job = PrlSrv_GetVmListEx(driver->server, PVTF_VM | PVTF_CT);
if (PRL_FAILED(getJobResult(job, &result))) if (PRL_FAILED(getJobResult(job, &result)))
return -1; return -1;
...@@ -1672,8 +1671,8 @@ prlsdkLoadDomains(vzConnPtr privconn) ...@@ -1672,8 +1671,8 @@ prlsdkLoadDomains(vzConnPtr privconn)
pret = PrlResult_GetParamByIndex(result, i, &sdkdom); pret = PrlResult_GetParamByIndex(result, i, &sdkdom);
prlsdkCheckRetGoto(pret, error); prlsdkCheckRetGoto(pret, error);
if (!(dom = prlsdkNewDomainByHandle(privconn, sdkdom))) if (!(dom = prlsdkNewDomainByHandle(driver, sdkdom)))
goto error; continue;
virObjectUnlock(dom); virObjectUnlock(dom);
PrlHandle_Free(sdkdom); PrlHandle_Free(sdkdom);
...@@ -1690,7 +1689,7 @@ prlsdkLoadDomains(vzConnPtr privconn) ...@@ -1690,7 +1689,7 @@ prlsdkLoadDomains(vzConnPtr privconn)
} }
int int
prlsdkUpdateDomain(vzConnPtr privconn, virDomainObjPtr dom) prlsdkUpdateDomain(vzDriverPtr driver, virDomainObjPtr dom)
{ {
PRL_HANDLE job; PRL_HANDLE job;
vzDomObjPtr pdom = dom->privateData; vzDomObjPtr pdom = dom->privateData;
...@@ -1699,10 +1698,10 @@ prlsdkUpdateDomain(vzConnPtr privconn, virDomainObjPtr dom) ...@@ -1699,10 +1698,10 @@ prlsdkUpdateDomain(vzConnPtr privconn, virDomainObjPtr dom)
if (waitJob(job)) if (waitJob(job))
return -1; return -1;
return prlsdkLoadDomain(privconn, dom); return prlsdkLoadDomain(driver, dom);
} }
static int prlsdkSendEvent(vzConnPtr privconn, static int prlsdkSendEvent(vzDriverPtr driver,
virDomainObjPtr dom, virDomainObjPtr dom,
virDomainEventType lvEventType, virDomainEventType lvEventType,
int lvEventTypeDetails) int lvEventTypeDetails)
...@@ -1715,7 +1714,7 @@ static int prlsdkSendEvent(vzConnPtr privconn, ...@@ -1715,7 +1714,7 @@ static int prlsdkSendEvent(vzConnPtr privconn,
if (!event) if (!event)
return -1; return -1;
virObjectEventStateQueue(privconn->domainEventState, event); virObjectEventStateQueue(driver->domainEventState, event);
return 0; return 0;
} }
...@@ -1753,7 +1752,7 @@ prlsdkNewStateToEvent(VIRTUAL_MACHINE_STATE domainState, ...@@ -1753,7 +1752,7 @@ prlsdkNewStateToEvent(VIRTUAL_MACHINE_STATE domainState,
} }
static void static void
prlsdkHandleVmStateEvent(vzConnPtr privconn, prlsdkHandleVmStateEvent(vzDriverPtr driver,
PRL_HANDLE prlEvent, PRL_HANDLE prlEvent,
unsigned char *uuid) unsigned char *uuid)
{ {
...@@ -1765,7 +1764,7 @@ prlsdkHandleVmStateEvent(vzConnPtr privconn, ...@@ -1765,7 +1764,7 @@ prlsdkHandleVmStateEvent(vzConnPtr privconn,
virDomainEventType lvEventType = 0; virDomainEventType lvEventType = 0;
int lvEventTypeDetails = 0; int lvEventTypeDetails = 0;
dom = virDomainObjListFindByUUID(privconn->domains, uuid); dom = virDomainObjListFindByUUID(driver->domains, uuid);
if (dom == NULL) if (dom == NULL)
return; return;
...@@ -1783,7 +1782,7 @@ prlsdkHandleVmStateEvent(vzConnPtr privconn, ...@@ -1783,7 +1782,7 @@ prlsdkHandleVmStateEvent(vzConnPtr privconn,
&lvEventType, &lvEventType,
&lvEventTypeDetails); &lvEventTypeDetails);
prlsdkSendEvent(privconn, dom, lvEventType, lvEventTypeDetails); prlsdkSendEvent(driver, dom, lvEventType, lvEventTypeDetails);
cleanup: cleanup:
virObjectUnlock(dom); virObjectUnlock(dom);
...@@ -1791,19 +1790,19 @@ prlsdkHandleVmStateEvent(vzConnPtr privconn, ...@@ -1791,19 +1790,19 @@ prlsdkHandleVmStateEvent(vzConnPtr privconn,
} }
static void static void
prlsdkHandleVmConfigEvent(vzConnPtr privconn, prlsdkHandleVmConfigEvent(vzDriverPtr driver,
unsigned char *uuid) unsigned char *uuid)
{ {
virDomainObjPtr dom = NULL; virDomainObjPtr dom = NULL;
dom = virDomainObjListFindByUUID(privconn->domains, uuid); dom = virDomainObjListFindByUUID(driver->domains, uuid);
if (dom == NULL) if (dom == NULL)
return; return;
if (prlsdkUpdateDomain(privconn, dom) < 0) if (prlsdkUpdateDomain(driver, dom) < 0)
goto cleanup; goto cleanup;
prlsdkSendEvent(privconn, dom, VIR_DOMAIN_EVENT_DEFINED, prlsdkSendEvent(driver, dom, VIR_DOMAIN_EVENT_DEFINED,
VIR_DOMAIN_EVENT_DEFINED_UPDATED); VIR_DOMAIN_EVENT_DEFINED_UPDATED);
cleanup: cleanup:
...@@ -1812,23 +1811,23 @@ prlsdkHandleVmConfigEvent(vzConnPtr privconn, ...@@ -1812,23 +1811,23 @@ prlsdkHandleVmConfigEvent(vzConnPtr privconn,
} }
static void static void
prlsdkHandleVmAddedEvent(vzConnPtr privconn, prlsdkHandleVmAddedEvent(vzDriverPtr driver,
unsigned char *uuid) unsigned char *uuid)
{ {
virDomainObjPtr dom = NULL; virDomainObjPtr dom = NULL;
PRL_HANDLE sdkdom = PRL_INVALID_HANDLE; PRL_HANDLE sdkdom = PRL_INVALID_HANDLE;
dom = virDomainObjListFindByUUID(privconn->domains, uuid); dom = virDomainObjListFindByUUID(driver->domains, uuid);
if (!dom) { if (!dom) {
sdkdom = prlsdkSdkDomainLookupByUUID(privconn, uuid); sdkdom = prlsdkSdkDomainLookupByUUID(driver, uuid);
if (sdkdom == PRL_INVALID_HANDLE) if (sdkdom == PRL_INVALID_HANDLE)
goto cleanup; goto cleanup;
if (!(dom = prlsdkNewDomainByHandle(privconn, sdkdom))) if (!(dom = prlsdkNewDomainByHandle(driver, sdkdom)))
goto cleanup; goto cleanup;
} }
prlsdkSendEvent(privconn, dom, VIR_DOMAIN_EVENT_DEFINED, prlsdkSendEvent(driver, dom, VIR_DOMAIN_EVENT_DEFINED,
VIR_DOMAIN_EVENT_DEFINED_ADDED); VIR_DOMAIN_EVENT_DEFINED_ADDED);
cleanup: cleanup:
...@@ -1839,28 +1838,28 @@ prlsdkHandleVmAddedEvent(vzConnPtr privconn, ...@@ -1839,28 +1838,28 @@ prlsdkHandleVmAddedEvent(vzConnPtr privconn,
} }
static void static void
prlsdkHandleVmRemovedEvent(vzConnPtr privconn, prlsdkHandleVmRemovedEvent(vzDriverPtr driver,
unsigned char *uuid) unsigned char *uuid)
{ {
virDomainObjPtr dom = NULL; virDomainObjPtr dom = NULL;
dom = virDomainObjListFindByUUID(privconn->domains, uuid); dom = virDomainObjListFindByUUID(driver->domains, uuid);
/* domain was removed from the list from the libvirt /* domain was removed from the list from the libvirt
* API function in current connection */ * API function in current connection */
if (dom == NULL) if (dom == NULL)
return; return;
prlsdkSendEvent(privconn, dom, VIR_DOMAIN_EVENT_UNDEFINED, prlsdkSendEvent(driver, dom, VIR_DOMAIN_EVENT_UNDEFINED,
VIR_DOMAIN_EVENT_UNDEFINED_REMOVED); VIR_DOMAIN_EVENT_UNDEFINED_REMOVED);
virDomainObjListRemove(privconn->domains, dom); virDomainObjListRemove(driver->domains, dom);
return; return;
} }
#define PARALLELS_STATISTICS_DROP_COUNT 3 #define PARALLELS_STATISTICS_DROP_COUNT 3
static PRL_RESULT static PRL_RESULT
prlsdkHandlePerfEvent(vzConnPtr privconn, prlsdkHandlePerfEvent(vzDriverPtr driver,
PRL_HANDLE event, PRL_HANDLE event,
unsigned char *uuid) unsigned char *uuid)
{ {
...@@ -1868,7 +1867,7 @@ prlsdkHandlePerfEvent(vzConnPtr privconn, ...@@ -1868,7 +1867,7 @@ prlsdkHandlePerfEvent(vzConnPtr privconn,
vzDomObjPtr privdom = NULL; vzDomObjPtr privdom = NULL;
PRL_HANDLE job = PRL_INVALID_HANDLE; PRL_HANDLE job = PRL_INVALID_HANDLE;
dom = virDomainObjListFindByUUID(privconn->domains, uuid); dom = virDomainObjListFindByUUID(driver->domains, uuid);
if (dom == NULL) if (dom == NULL)
goto cleanup; goto cleanup;
privdom = dom->privateData; privdom = dom->privateData;
...@@ -1905,7 +1904,7 @@ prlsdkHandlePerfEvent(vzConnPtr privconn, ...@@ -1905,7 +1904,7 @@ prlsdkHandlePerfEvent(vzConnPtr privconn,
static PRL_RESULT static PRL_RESULT
prlsdkEventsHandler(PRL_HANDLE prlEvent, PRL_VOID_PTR opaque) prlsdkEventsHandler(PRL_HANDLE prlEvent, PRL_VOID_PTR opaque)
{ {
vzConnPtr privconn = opaque; vzDriverPtr driver = opaque;
PRL_RESULT pret = PRL_ERR_FAILURE; PRL_RESULT pret = PRL_ERR_FAILURE;
PRL_HANDLE_TYPE handleType; PRL_HANDLE_TYPE handleType;
char uuidstr[VIR_UUID_STRING_BUFLEN + 2]; char uuidstr[VIR_UUID_STRING_BUFLEN + 2];
...@@ -1920,7 +1919,7 @@ prlsdkEventsHandler(PRL_HANDLE prlEvent, PRL_VOID_PTR opaque) ...@@ -1920,7 +1919,7 @@ prlsdkEventsHandler(PRL_HANDLE prlEvent, PRL_VOID_PTR opaque)
if (handleType != PHT_EVENT) if (handleType != PHT_EVENT)
goto cleanup; goto cleanup;
if (privconn == NULL) if (driver == NULL)
goto cleanup; goto cleanup;
pret = PrlEvent_GetIssuerId(prlEvent, uuidstr, &bufsize); pret = PrlEvent_GetIssuerId(prlEvent, uuidstr, &bufsize);
...@@ -1936,27 +1935,26 @@ prlsdkEventsHandler(PRL_HANDLE prlEvent, PRL_VOID_PTR opaque) ...@@ -1936,27 +1935,26 @@ prlsdkEventsHandler(PRL_HANDLE prlEvent, PRL_VOID_PTR opaque)
switch (prlEventType) { switch (prlEventType) {
case PET_DSP_EVT_VM_STATE_CHANGED: case PET_DSP_EVT_VM_STATE_CHANGED:
prlsdkHandleVmStateEvent(privconn, prlEvent, uuid); prlsdkHandleVmStateEvent(driver, prlEvent, uuid);
break; break;
case PET_DSP_EVT_VM_CONFIG_CHANGED: case PET_DSP_EVT_VM_CONFIG_CHANGED:
prlsdkHandleVmConfigEvent(privconn, uuid); prlsdkHandleVmConfigEvent(driver, uuid);
break; break;
case PET_DSP_EVT_VM_CREATED: case PET_DSP_EVT_VM_CREATED:
case PET_DSP_EVT_VM_ADDED: case PET_DSP_EVT_VM_ADDED:
prlsdkHandleVmAddedEvent(privconn, uuid); prlsdkHandleVmAddedEvent(driver, uuid);
break; break;
case PET_DSP_EVT_VM_DELETED: case PET_DSP_EVT_VM_DELETED:
case PET_DSP_EVT_VM_UNREGISTERED: case PET_DSP_EVT_VM_UNREGISTERED:
prlsdkHandleVmRemovedEvent(privconn, uuid); prlsdkHandleVmRemovedEvent(driver, uuid);
break; break;
case PET_DSP_EVT_VM_PERFSTATS: case PET_DSP_EVT_VM_PERFSTATS:
prlsdkHandlePerfEvent(privconn, prlEvent, uuid); prlsdkHandlePerfEvent(driver, prlEvent, uuid);
/* above function takes own of event */ /* above function takes own of event */
prlEvent = PRL_INVALID_HANDLE; prlEvent = PRL_INVALID_HANDLE;
break; break;
case PET_DSP_EVT_DISP_CONNECTION_CLOSED: case PET_DSP_EVT_DISP_CONNECTION_CLOSED:
virConnectCloseCallbackDataCall(privconn->closeCallback, vzDestroyDriverConnection();
VIR_CONNECT_CLOSE_REASON_EOF);
break; break;
default: default:
VIR_DEBUG("Skipping event of type %d", prlEventType); VIR_DEBUG("Skipping event of type %d", prlEventType);
...@@ -1967,13 +1965,13 @@ prlsdkEventsHandler(PRL_HANDLE prlEvent, PRL_VOID_PTR opaque) ...@@ -1967,13 +1965,13 @@ prlsdkEventsHandler(PRL_HANDLE prlEvent, PRL_VOID_PTR opaque)
return PRL_ERR_SUCCESS; return PRL_ERR_SUCCESS;
} }
int prlsdkSubscribeToPCSEvents(vzConnPtr privconn) int prlsdkSubscribeToPCSEvents(vzDriverPtr driver)
{ {
PRL_RESULT pret = PRL_ERR_UNINITIALIZED; PRL_RESULT pret = PRL_ERR_UNINITIALIZED;
pret = PrlSrv_RegEventHandler(privconn->server, pret = PrlSrv_RegEventHandler(driver->server,
prlsdkEventsHandler, prlsdkEventsHandler,
privconn); driver);
prlsdkCheckRetGoto(pret, error); prlsdkCheckRetGoto(pret, error);
return 0; return 0;
...@@ -1981,12 +1979,12 @@ int prlsdkSubscribeToPCSEvents(vzConnPtr privconn) ...@@ -1981,12 +1979,12 @@ int prlsdkSubscribeToPCSEvents(vzConnPtr privconn)
return -1; return -1;
} }
void prlsdkUnsubscribeFromPCSEvents(vzConnPtr privconn) void prlsdkUnsubscribeFromPCSEvents(vzDriverPtr driver)
{ {
PRL_RESULT ret = PRL_ERR_UNINITIALIZED; PRL_RESULT ret = PRL_ERR_UNINITIALIZED;
ret = PrlSrv_UnregEventHandler(privconn->server, ret = PrlSrv_UnregEventHandler(driver->server,
prlsdkEventsHandler, prlsdkEventsHandler,
privconn); driver);
if (PRL_FAILED(ret)) if (PRL_FAILED(ret))
logPrlError(ret); logPrlError(ret);
} }
...@@ -2050,7 +2048,7 @@ PRL_RESULT prlsdkRestart(PRL_HANDLE sdkdom) ...@@ -2050,7 +2048,7 @@ PRL_RESULT prlsdkRestart(PRL_HANDLE sdkdom)
} }
int int
prlsdkDomainChangeStateLocked(vzConnPtr privconn, prlsdkDomainChangeStateLocked(vzDriverPtr driver,
virDomainObjPtr dom, virDomainObjPtr dom,
prlsdkChangeStateFunc chstate) prlsdkChangeStateFunc chstate)
{ {
...@@ -2076,7 +2074,7 @@ prlsdkDomainChangeStateLocked(vzConnPtr privconn, ...@@ -2076,7 +2074,7 @@ prlsdkDomainChangeStateLocked(vzConnPtr privconn,
return -1; return -1;
} }
return prlsdkUpdateDomain(privconn, dom); return prlsdkUpdateDomain(driver, dom);
} }
int int
...@@ -2090,7 +2088,7 @@ prlsdkDomainChangeState(virDomainPtr domain, ...@@ -2090,7 +2088,7 @@ prlsdkDomainChangeState(virDomainPtr domain,
if (!(dom = vzDomObjFromDomain(domain))) if (!(dom = vzDomObjFromDomain(domain)))
return -1; return -1;
ret = prlsdkDomainChangeStateLocked(privconn, dom, chstate); ret = prlsdkDomainChangeStateLocked(privconn->driver, dom, chstate);
virObjectUnlock(dom); virObjectUnlock(dom);
return ret; return ret;
} }
...@@ -2847,7 +2845,7 @@ static const char * prlsdkFormatMac(virMacAddrPtr mac, char *macstr) ...@@ -2847,7 +2845,7 @@ static const char * prlsdkFormatMac(virMacAddrPtr mac, char *macstr)
return macstr; return macstr;
} }
static int prlsdkAddNet(vzConnPtr privconn, static int prlsdkAddNet(vzDriverPtr driver,
PRL_HANDLE sdkdom, PRL_HANDLE sdkdom,
virDomainNetDefPtr net, virDomainNetDefPtr net,
bool isCt) bool isCt)
...@@ -3052,7 +3050,7 @@ static int prlsdkAddNet(vzConnPtr privconn, ...@@ -3052,7 +3050,7 @@ static int prlsdkAddNet(vzConnPtr privconn,
pret = PrlVirtNet_SetNetworkType(vnet, PVN_BRIDGED_ETHERNET); pret = PrlVirtNet_SetNetworkType(vnet, PVN_BRIDGED_ETHERNET);
prlsdkCheckRetGoto(pret, cleanup); prlsdkCheckRetGoto(pret, cleanup);
job = PrlSrv_AddVirtualNetwork(privconn->server, job = PrlSrv_AddVirtualNetwork(driver->server,
vnet, vnet,
PRL_USE_VNET_NAME_FOR_BRIDGE_NAME); PRL_USE_VNET_NAME_FOR_BRIDGE_NAME);
if (PRL_FAILED(pret = waitJob(job))) if (PRL_FAILED(pret = waitJob(job)))
...@@ -3081,7 +3079,7 @@ static int prlsdkAddNet(vzConnPtr privconn, ...@@ -3081,7 +3079,7 @@ static int prlsdkAddNet(vzConnPtr privconn,
} }
static void static void
prlsdkCleanupBridgedNet(vzConnPtr privconn, virDomainNetDefPtr net) prlsdkCleanupBridgedNet(vzDriverPtr driver, virDomainNetDefPtr net)
{ {
PRL_RESULT pret; PRL_RESULT pret;
PRL_HANDLE vnet = PRL_INVALID_HANDLE; PRL_HANDLE vnet = PRL_INVALID_HANDLE;
...@@ -3096,7 +3094,7 @@ prlsdkCleanupBridgedNet(vzConnPtr privconn, virDomainNetDefPtr net) ...@@ -3096,7 +3094,7 @@ prlsdkCleanupBridgedNet(vzConnPtr privconn, virDomainNetDefPtr net)
pret = PrlVirtNet_SetNetworkId(vnet, net->data.network.name); pret = PrlVirtNet_SetNetworkId(vnet, net->data.network.name);
prlsdkCheckRetGoto(pret, cleanup); prlsdkCheckRetGoto(pret, cleanup);
job = PrlSrv_DeleteVirtualNetwork(privconn->server, vnet, 0); job = PrlSrv_DeleteVirtualNetwork(driver->server, vnet, 0);
if (PRL_FAILED(pret = waitJob(job))) if (PRL_FAILED(pret = waitJob(job)))
goto cleanup; goto cleanup;
...@@ -3104,7 +3102,7 @@ prlsdkCleanupBridgedNet(vzConnPtr privconn, virDomainNetDefPtr net) ...@@ -3104,7 +3102,7 @@ prlsdkCleanupBridgedNet(vzConnPtr privconn, virDomainNetDefPtr net)
PrlHandle_Free(vnet); PrlHandle_Free(vnet);
} }
int prlsdkAttachNet(vzConnPtr privconn, int prlsdkAttachNet(vzDriverPtr driver,
virDomainObjPtr dom, virDomainObjPtr dom,
virDomainNetDefPtr net) virDomainNetDefPtr net)
{ {
...@@ -3122,7 +3120,7 @@ int prlsdkAttachNet(vzConnPtr privconn, ...@@ -3122,7 +3120,7 @@ int prlsdkAttachNet(vzConnPtr privconn,
if (PRL_FAILED(waitJob(job))) if (PRL_FAILED(waitJob(job)))
return ret; return ret;
ret = prlsdkAddNet(privconn, privdom->sdkdom, net, IS_CT(dom->def)); ret = prlsdkAddNet(driver, privdom->sdkdom, net, IS_CT(dom->def));
if (ret == 0) { if (ret == 0) {
job = PrlVm_CommitEx(privdom->sdkdom, PVCF_DETACH_HDD_BUNDLE); job = PrlVm_CommitEx(privdom->sdkdom, PVCF_DETACH_HDD_BUNDLE);
if (PRL_FAILED(waitJob(job))) if (PRL_FAILED(waitJob(job)))
...@@ -3169,7 +3167,7 @@ prlsdkFindNetByMAC(PRL_HANDLE sdkdom, virMacAddrPtr mac) ...@@ -3169,7 +3167,7 @@ prlsdkFindNetByMAC(PRL_HANDLE sdkdom, virMacAddrPtr mac)
return adapter; return adapter;
} }
int prlsdkDetachNet(vzConnPtr privconn, int prlsdkDetachNet(vzDriverPtr driver,
virDomainObjPtr dom, virDomainObjPtr dom,
virDomainNetDefPtr net) virDomainNetDefPtr net)
{ {
...@@ -3193,7 +3191,7 @@ int prlsdkDetachNet(vzConnPtr privconn, ...@@ -3193,7 +3191,7 @@ int prlsdkDetachNet(vzConnPtr privconn,
if (sdknet == PRL_INVALID_HANDLE) if (sdknet == PRL_INVALID_HANDLE)
goto cleanup; goto cleanup;
prlsdkCleanupBridgedNet(privconn, net); prlsdkCleanupBridgedNet(driver, net);
pret = PrlVmDev_Remove(sdknet); pret = PrlVmDev_Remove(sdknet);
prlsdkCheckRetGoto(pret, cleanup); prlsdkCheckRetGoto(pret, cleanup);
...@@ -3228,7 +3226,7 @@ static int prlsdkDelDisk(PRL_HANDLE sdkdom, int idx) ...@@ -3228,7 +3226,7 @@ static int prlsdkDelDisk(PRL_HANDLE sdkdom, int idx)
return ret; return ret;
} }
static int prlsdkAddDisk(vzConnPtr privconn, static int prlsdkAddDisk(vzDriverPtr driver,
PRL_HANDLE sdkdom, PRL_HANDLE sdkdom,
virDomainDiskDefPtr disk) virDomainDiskDefPtr disk)
{ {
...@@ -3339,7 +3337,7 @@ static int prlsdkAddDisk(vzConnPtr privconn, ...@@ -3339,7 +3337,7 @@ static int prlsdkAddDisk(vzConnPtr privconn,
} }
if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) { if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
if (vzGetDefaultSCSIModel(privconn, &scsiModel) < 0) if (vzGetDefaultSCSIModel(driver, &scsiModel) < 0)
goto cleanup; goto cleanup;
pret = PrlVmDev_SetSubType(sdkdisk, scsiModel); pret = PrlVmDev_SetSubType(sdkdisk, scsiModel);
prlsdkCheckRetGoto(pret, cleanup); prlsdkCheckRetGoto(pret, cleanup);
...@@ -3377,7 +3375,7 @@ static int prlsdkAddDisk(vzConnPtr privconn, ...@@ -3377,7 +3375,7 @@ static int prlsdkAddDisk(vzConnPtr privconn,
} }
int int
prlsdkAttachVolume(vzConnPtr privconn, prlsdkAttachVolume(vzDriverPtr driver,
virDomainObjPtr dom, virDomainObjPtr dom,
virDomainDiskDefPtr disk) virDomainDiskDefPtr disk)
{ {
...@@ -3389,7 +3387,7 @@ prlsdkAttachVolume(vzConnPtr privconn, ...@@ -3389,7 +3387,7 @@ prlsdkAttachVolume(vzConnPtr privconn,
if (PRL_FAILED(waitJob(job))) if (PRL_FAILED(waitJob(job)))
goto cleanup; goto cleanup;
ret = prlsdkAddDisk(privconn, privdom->sdkdom, disk); ret = prlsdkAddDisk(driver, privdom->sdkdom, disk);
if (ret == 0) { if (ret == 0) {
job = PrlVm_CommitEx(privdom->sdkdom, PVCF_DETACH_HDD_BUNDLE); job = PrlVm_CommitEx(privdom->sdkdom, PVCF_DETACH_HDD_BUNDLE);
if (PRL_FAILED(waitJob(job))) { if (PRL_FAILED(waitJob(job))) {
...@@ -3591,7 +3589,7 @@ prlsdkSetBootOrderVm(PRL_HANDLE sdkdom, virDomainDefPtr def) ...@@ -3591,7 +3589,7 @@ prlsdkSetBootOrderVm(PRL_HANDLE sdkdom, virDomainDefPtr def)
} }
static int static int
prlsdkDoApplyConfig(virConnectPtr conn, prlsdkDoApplyConfig(vzDriverPtr driver,
PRL_HANDLE sdkdom, PRL_HANDLE sdkdom,
virDomainDefPtr def, virDomainDefPtr def,
virDomainDefPtr olddef) virDomainDefPtr olddef)
...@@ -3657,11 +3655,11 @@ prlsdkDoApplyConfig(virConnectPtr conn, ...@@ -3657,11 +3655,11 @@ prlsdkDoApplyConfig(virConnectPtr conn,
if (olddef) { if (olddef) {
for (i = 0; i < olddef->nnets; i++) for (i = 0; i < olddef->nnets; i++)
prlsdkCleanupBridgedNet(conn->privateData, olddef->nets[i]); prlsdkCleanupBridgedNet(driver, olddef->nets[i]);
} }
for (i = 0; i < def->nnets; i++) { for (i = 0; i < def->nnets; i++) {
if (prlsdkAddNet(conn->privateData, sdkdom, def->nets[i], IS_CT(def)) < 0) if (prlsdkAddNet(driver, sdkdom, def->nets[i], IS_CT(def)) < 0)
goto error; goto error;
} }
...@@ -3682,7 +3680,7 @@ prlsdkDoApplyConfig(virConnectPtr conn, ...@@ -3682,7 +3680,7 @@ prlsdkDoApplyConfig(virConnectPtr conn,
} }
for (i = 0; i < def->ndisks; i++) { for (i = 0; i < def->ndisks; i++) {
if (prlsdkAddDisk(conn->privateData, sdkdom, def->disks[i]) < 0) if (prlsdkAddDisk(driver, sdkdom, def->disks[i]) < 0)
goto error; goto error;
} }
...@@ -3700,22 +3698,21 @@ prlsdkDoApplyConfig(virConnectPtr conn, ...@@ -3700,22 +3698,21 @@ prlsdkDoApplyConfig(virConnectPtr conn,
VIR_FREE(mask); VIR_FREE(mask);
for (i = 0; i < def->nnets; i++) for (i = 0; i < def->nnets; i++)
prlsdkCleanupBridgedNet(conn->privateData, def->nets[i]); prlsdkCleanupBridgedNet(driver, def->nets[i]);
return -1; return -1;
} }
int int
prlsdkApplyConfig(virConnectPtr conn, prlsdkApplyConfig(vzDriverPtr driver,
virDomainObjPtr dom, virDomainObjPtr dom,
virDomainDefPtr new) virDomainDefPtr new)
{ {
vzConnPtr privconn = conn->privateData;
PRL_HANDLE sdkdom = PRL_INVALID_HANDLE; PRL_HANDLE sdkdom = PRL_INVALID_HANDLE;
PRL_HANDLE job = PRL_INVALID_HANDLE; PRL_HANDLE job = PRL_INVALID_HANDLE;
int ret; int ret;
sdkdom = prlsdkSdkDomainLookupByUUID(privconn, dom->def->uuid); sdkdom = prlsdkSdkDomainLookupByUUID(driver, dom->def->uuid);
if (sdkdom == PRL_INVALID_HANDLE) if (sdkdom == PRL_INVALID_HANDLE)
return -1; return -1;
...@@ -3723,7 +3720,7 @@ prlsdkApplyConfig(virConnectPtr conn, ...@@ -3723,7 +3720,7 @@ prlsdkApplyConfig(virConnectPtr conn,
if (PRL_FAILED(waitJob(job))) if (PRL_FAILED(waitJob(job)))
return -1; return -1;
ret = prlsdkDoApplyConfig(conn, sdkdom, new, dom->def); ret = prlsdkDoApplyConfig(driver, sdkdom, new, dom->def);
if (ret == 0) { if (ret == 0) {
job = PrlVm_CommitEx(sdkdom, PVCF_DETACH_HDD_BUNDLE); job = PrlVm_CommitEx(sdkdom, PVCF_DETACH_HDD_BUNDLE);
...@@ -3737,9 +3734,8 @@ prlsdkApplyConfig(virConnectPtr conn, ...@@ -3737,9 +3734,8 @@ prlsdkApplyConfig(virConnectPtr conn,
} }
int int
prlsdkCreateVm(virConnectPtr conn, virDomainDefPtr def) prlsdkCreateVm(vzDriverPtr driver, virDomainDefPtr def)
{ {
vzConnPtr privconn = conn->privateData;
PRL_HANDLE sdkdom = PRL_INVALID_HANDLE; PRL_HANDLE sdkdom = PRL_INVALID_HANDLE;
PRL_HANDLE job = PRL_INVALID_HANDLE; PRL_HANDLE job = PRL_INVALID_HANDLE;
PRL_HANDLE result = PRL_INVALID_HANDLE; PRL_HANDLE result = PRL_INVALID_HANDLE;
...@@ -3747,10 +3743,10 @@ prlsdkCreateVm(virConnectPtr conn, virDomainDefPtr def) ...@@ -3747,10 +3743,10 @@ prlsdkCreateVm(virConnectPtr conn, virDomainDefPtr def)
PRL_RESULT pret; PRL_RESULT pret;
int ret = -1; int ret = -1;
pret = PrlSrv_CreateVm(privconn->server, &sdkdom); pret = PrlSrv_CreateVm(driver->server, &sdkdom);
prlsdkCheckRetGoto(pret, cleanup); prlsdkCheckRetGoto(pret, cleanup);
job = PrlSrv_GetSrvConfig(privconn->server); job = PrlSrv_GetSrvConfig(driver->server);
if (PRL_FAILED(getJobResult(job, &result))) if (PRL_FAILED(getJobResult(job, &result)))
goto cleanup; goto cleanup;
...@@ -3763,7 +3759,7 @@ prlsdkCreateVm(virConnectPtr conn, virDomainDefPtr def) ...@@ -3763,7 +3759,7 @@ prlsdkCreateVm(virConnectPtr conn, virDomainDefPtr def)
pret = PrlVmCfg_SetOfflineManagementEnabled(sdkdom, 0); pret = PrlVmCfg_SetOfflineManagementEnabled(sdkdom, 0);
prlsdkCheckRetGoto(pret, cleanup); prlsdkCheckRetGoto(pret, cleanup);
ret = prlsdkDoApplyConfig(conn, sdkdom, def, NULL); ret = prlsdkDoApplyConfig(driver, sdkdom, def, NULL);
if (ret) if (ret)
goto cleanup; goto cleanup;
...@@ -3777,9 +3773,8 @@ prlsdkCreateVm(virConnectPtr conn, virDomainDefPtr def) ...@@ -3777,9 +3773,8 @@ prlsdkCreateVm(virConnectPtr conn, virDomainDefPtr def)
} }
int int
prlsdkCreateCt(virConnectPtr conn, virDomainDefPtr def) prlsdkCreateCt(vzDriverPtr driver, virDomainDefPtr def)
{ {
vzConnPtr privconn = conn->privateData;
PRL_HANDLE sdkdom = PRL_INVALID_HANDLE; PRL_HANDLE sdkdom = PRL_INVALID_HANDLE;
PRL_GET_VM_CONFIG_PARAM_DATA confParam; PRL_GET_VM_CONFIG_PARAM_DATA confParam;
PRL_HANDLE job = PRL_INVALID_HANDLE; PRL_HANDLE job = PRL_INVALID_HANDLE;
...@@ -3812,7 +3807,7 @@ prlsdkCreateCt(virConnectPtr conn, virDomainDefPtr def) ...@@ -3812,7 +3807,7 @@ prlsdkCreateCt(virConnectPtr conn, virDomainDefPtr def)
confParam.sConfigSample = "vswap.1024MB"; confParam.sConfigSample = "vswap.1024MB";
confParam.nOsVersion = 0; confParam.nOsVersion = 0;
job = PrlSrv_GetDefaultVmConfig(privconn->server, &confParam, 0); job = PrlSrv_GetDefaultVmConfig(driver->server, &confParam, 0);
if (PRL_FAILED(getJobResult(job, &result))) if (PRL_FAILED(getJobResult(job, &result)))
goto cleanup; goto cleanup;
...@@ -3825,7 +3820,7 @@ prlsdkCreateCt(virConnectPtr conn, virDomainDefPtr def) ...@@ -3825,7 +3820,7 @@ prlsdkCreateCt(virConnectPtr conn, virDomainDefPtr def)
} }
ret = prlsdkDoApplyConfig(conn, sdkdom, def, NULL); ret = prlsdkDoApplyConfig(driver, sdkdom, def, NULL);
if (ret) if (ret)
goto cleanup; goto cleanup;
...@@ -3944,7 +3939,7 @@ prlsdkDomainHasSnapshots(PRL_HANDLE sdkdom, int* found) ...@@ -3944,7 +3939,7 @@ prlsdkDomainHasSnapshots(PRL_HANDLE sdkdom, int* found)
} }
int int
prlsdkUnregisterDomain(vzConnPtr privconn, virDomainObjPtr dom, unsigned int flags) prlsdkUnregisterDomain(vzDriverPtr driver, virDomainObjPtr dom, unsigned int flags)
{ {
vzDomObjPtr privdom = dom->privateData; vzDomObjPtr privdom = dom->privateData;
PRL_HANDLE job; PRL_HANDLE job;
...@@ -3981,13 +3976,13 @@ prlsdkUnregisterDomain(vzConnPtr privconn, virDomainObjPtr dom, unsigned int fla ...@@ -3981,13 +3976,13 @@ prlsdkUnregisterDomain(vzConnPtr privconn, virDomainObjPtr dom, unsigned int fla
return -1; return -1;
for (i = 0; i < dom->def->nnets; i++) for (i = 0; i < dom->def->nnets; i++)
prlsdkCleanupBridgedNet(privconn, dom->def->nets[i]); prlsdkCleanupBridgedNet(driver, dom->def->nets[i]);
if (prlsdkSendEvent(privconn, dom, VIR_DOMAIN_EVENT_UNDEFINED, if (prlsdkSendEvent(driver, dom, VIR_DOMAIN_EVENT_UNDEFINED,
VIR_DOMAIN_EVENT_UNDEFINED_REMOVED) < 0) VIR_DOMAIN_EVENT_UNDEFINED_REMOVED) < 0)
return -1; return -1;
virDomainObjListRemove(privconn->domains, dom); virDomainObjListRemove(driver->domains, dom);
return 0; return 0;
} }
......
...@@ -26,16 +26,16 @@ ...@@ -26,16 +26,16 @@
int prlsdkInit(void); int prlsdkInit(void);
void prlsdkDeinit(void); void prlsdkDeinit(void);
int prlsdkConnect(vzConnPtr privconn); int prlsdkConnect(vzDriverPtr driver);
void prlsdkDisconnect(vzConnPtr privconn); void prlsdkDisconnect(vzDriverPtr driver);
int int
prlsdkLoadDomains(vzConnPtr privconn); prlsdkLoadDomains(vzDriverPtr driver);
int prlsdkUpdateDomain(vzConnPtr privconn, virDomainObjPtr dom); int prlsdkUpdateDomain(vzDriverPtr driver, virDomainObjPtr dom);
int int
prlsdkLoadDomain(vzConnPtr privconn, prlsdkLoadDomain(vzDriverPtr driver,
virDomainObjPtr dom); virDomainObjPtr dom);
int prlsdkSubscribeToPCSEvents(vzConnPtr privconn); int prlsdkSubscribeToPCSEvents(vzDriverPtr driver);
void prlsdkUnsubscribeFromPCSEvents(vzConnPtr privconn); void prlsdkUnsubscribeFromPCSEvents(vzDriverPtr driver);
PRL_RESULT prlsdkStart(PRL_HANDLE sdkdom); PRL_RESULT prlsdkStart(PRL_HANDLE sdkdom);
PRL_RESULT prlsdkKill(PRL_HANDLE sdkdom); PRL_RESULT prlsdkKill(PRL_HANDLE sdkdom);
PRL_RESULT prlsdkStop(PRL_HANDLE sdkdom); PRL_RESULT prlsdkStop(PRL_HANDLE sdkdom);
...@@ -49,29 +49,29 @@ int ...@@ -49,29 +49,29 @@ int
prlsdkDomainChangeState(virDomainPtr domain, prlsdkDomainChangeState(virDomainPtr domain,
prlsdkChangeStateFunc chstate); prlsdkChangeStateFunc chstate);
int int
prlsdkDomainChangeStateLocked(vzConnPtr privconn, prlsdkDomainChangeStateLocked(vzDriverPtr driver,
virDomainObjPtr dom, virDomainObjPtr dom,
prlsdkChangeStateFunc chstate); prlsdkChangeStateFunc chstate);
int int
prlsdkApplyConfig(virConnectPtr conn, prlsdkApplyConfig(vzDriverPtr driver,
virDomainObjPtr dom, virDomainObjPtr dom,
virDomainDefPtr new); virDomainDefPtr new);
int prlsdkCreateVm(virConnectPtr conn, virDomainDefPtr def); int prlsdkCreateVm(vzDriverPtr driver, virDomainDefPtr def);
int prlsdkCreateCt(virConnectPtr conn, virDomainDefPtr def); int prlsdkCreateCt(vzDriverPtr driver, virDomainDefPtr def);
int int
prlsdkUnregisterDomain(vzConnPtr privconn, virDomainObjPtr dom, unsigned int flags); prlsdkUnregisterDomain(vzDriverPtr driver, virDomainObjPtr dom, unsigned int flags);
int int
prlsdkDomainManagedSaveRemove(virDomainObjPtr dom); prlsdkDomainManagedSaveRemove(virDomainObjPtr dom);
int int
prlsdkAttachVolume(vzConnPtr privconn, virDomainObjPtr dom, virDomainDiskDefPtr disk); prlsdkAttachVolume(vzDriverPtr driver, virDomainObjPtr dom, virDomainDiskDefPtr disk);
int int
prlsdkDetachVolume(virDomainObjPtr dom, virDomainDiskDefPtr disk); prlsdkDetachVolume(virDomainObjPtr dom, virDomainDiskDefPtr disk);
int int
prlsdkGetBlockStats(virDomainObjPtr dom, virDomainDiskDefPtr disk, virDomainBlockStatsPtr stats); prlsdkGetBlockStats(virDomainObjPtr dom, virDomainDiskDefPtr disk, virDomainBlockStatsPtr stats);
int int
prlsdkAttachNet(vzConnPtr privconn, virDomainObjPtr dom, virDomainNetDefPtr net); prlsdkAttachNet(vzDriverPtr driver, virDomainObjPtr dom, virDomainNetDefPtr net);
int int
prlsdkDetachNet(vzConnPtr privconn, virDomainObjPtr dom, virDomainNetDefPtr net); prlsdkDetachNet(vzDriverPtr driver, virDomainObjPtr dom, virDomainNetDefPtr net);
int int
prlsdkGetNetStats(virDomainObjPtr dom, const char *path, virDomainInterfaceStatsPtr stats); prlsdkGetNetStats(virDomainObjPtr dom, const char *path, virDomainInterfaceStatsPtr stats);
int int
......
...@@ -73,8 +73,9 @@ vzDomObjFromDomain(virDomainPtr domain) ...@@ -73,8 +73,9 @@ vzDomObjFromDomain(virDomainPtr domain)
virDomainObjPtr vm; virDomainObjPtr vm;
vzConnPtr privconn = domain->conn->privateData; vzConnPtr privconn = domain->conn->privateData;
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
vzDriverPtr driver = privconn->driver;
vm = virDomainObjListFindByUUID(privconn->domains, domain->uuid); vm = virDomainObjListFindByUUID(driver->domains, domain->uuid);
if (!vm) { if (!vm) {
virUUIDFormat(domain->uuid, uuidstr); virUUIDFormat(domain->uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN, virReportError(VIR_ERR_NO_DOMAIN,
...@@ -84,7 +85,6 @@ vzDomObjFromDomain(virDomainPtr domain) ...@@ -84,7 +85,6 @@ vzDomObjFromDomain(virDomainPtr domain)
} }
return vm; return vm;
} }
/** /**
...@@ -103,8 +103,9 @@ vzDomObjFromDomainRef(virDomainPtr domain) ...@@ -103,8 +103,9 @@ vzDomObjFromDomainRef(virDomainPtr domain)
virDomainObjPtr vm; virDomainObjPtr vm;
vzConnPtr privconn = domain->conn->privateData; vzConnPtr privconn = domain->conn->privateData;
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
vzDriverPtr driver = privconn->driver;
vm = virDomainObjListFindByUUIDRef(privconn->domains, domain->uuid); vm = virDomainObjListFindByUUIDRef(driver->domains, domain->uuid);
if (!vm) { if (!vm) {
virUUIDFormat(domain->uuid, uuidstr); virUUIDFormat(domain->uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN, virReportError(VIR_ERR_NO_DOMAIN,
...@@ -159,7 +160,7 @@ vzGetOutput(const char *binary, ...) ...@@ -159,7 +160,7 @@ vzGetOutput(const char *binary, ...)
} }
virDomainObjPtr virDomainObjPtr
vzNewDomain(vzConnPtr privconn, char *name, const unsigned char *uuid) vzNewDomain(vzDriverPtr driver, char *name, const unsigned char *uuid)
{ {
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
virDomainObjPtr dom = NULL; virDomainObjPtr dom = NULL;
...@@ -180,8 +181,8 @@ vzNewDomain(vzConnPtr privconn, char *name, const unsigned char *uuid) ...@@ -180,8 +181,8 @@ vzNewDomain(vzConnPtr privconn, char *name, const unsigned char *uuid)
def->virtType = VIR_DOMAIN_VIRT_VZ; def->virtType = VIR_DOMAIN_VIRT_VZ;
if (!(dom = virDomainObjListAdd(privconn->domains, def, if (!(dom = virDomainObjListAdd(driver->domains, def,
privconn->xmlopt, driver->xmlopt,
0, NULL))) 0, NULL)))
goto error; goto error;
...@@ -199,7 +200,7 @@ vzNewDomain(vzConnPtr privconn, char *name, const unsigned char *uuid) ...@@ -199,7 +200,7 @@ vzNewDomain(vzConnPtr privconn, char *name, const unsigned char *uuid)
} }
static void static void
vzInitCaps(unsigned long vzVersion, vzCapabilities *vzCaps) vzInitCaps(unsigned long vzVersion, vzCapabilitiesPtr vzCaps)
{ {
if (vzVersion < VIRTUOZZO_VER_7) { if (vzVersion < VIRTUOZZO_VER_7) {
vzCaps->ctDiskFormat = VIR_STORAGE_FILE_PLOOP; vzCaps->ctDiskFormat = VIR_STORAGE_FILE_PLOOP;
...@@ -217,7 +218,7 @@ vzInitCaps(unsigned long vzVersion, vzCapabilities *vzCaps) ...@@ -217,7 +218,7 @@ vzInitCaps(unsigned long vzVersion, vzCapabilities *vzCaps)
} }
int int
vzInitVersion(vzConnPtr privconn) vzInitVersion(vzDriverPtr driver)
{ {
char *output, *sVer, *tmp; char *output, *sVer, *tmp;
const char *searchStr = "prlsrvctl version "; const char *searchStr = "prlsrvctl version ";
...@@ -250,12 +251,12 @@ vzInitVersion(vzConnPtr privconn) ...@@ -250,12 +251,12 @@ vzInitVersion(vzConnPtr privconn)
} }
tmp[0] = '\0'; tmp[0] = '\0';
if (virParseVersionString(sVer, &(privconn->vzVersion), true) < 0) { if (virParseVersionString(sVer, &(driver->vzVersion), true) < 0) {
vzParseError(); vzParseError();
goto cleanup; goto cleanup;
} }
vzInitCaps(privconn->vzVersion, &privconn->vzCaps); vzInitCaps(driver->vzVersion, &driver->vzCaps);
ret = 0; ret = 0;
cleanup: cleanup:
...@@ -474,10 +475,10 @@ vzCheckUnsupportedControllers(virDomainDefPtr def, vzCapabilitiesPtr vzCaps) ...@@ -474,10 +475,10 @@ vzCheckUnsupportedControllers(virDomainDefPtr def, vzCapabilitiesPtr vzCaps)
return 0; return 0;
} }
int vzGetDefaultSCSIModel(vzConnPtr privconn, int vzGetDefaultSCSIModel(vzDriverPtr driver,
PRL_CLUSTERED_DEVICE_SUBTYPE *scsiModel) PRL_CLUSTERED_DEVICE_SUBTYPE *scsiModel)
{ {
switch (privconn->vzCaps.scsiControllerModel) { switch (driver->vzCaps.scsiControllerModel) {
case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VIRTIO_SCSI: case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VIRTIO_SCSI:
*scsiModel = PCD_VIRTIO_SCSI; *scsiModel = PCD_VIRTIO_SCSI;
break; break;
...@@ -488,7 +489,7 @@ int vzGetDefaultSCSIModel(vzConnPtr privconn, ...@@ -488,7 +489,7 @@ int vzGetDefaultSCSIModel(vzConnPtr privconn,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unknown SCSI controller model %s"), _("Unknown SCSI controller model %s"),
virDomainControllerModelSCSITypeToString( virDomainControllerModelSCSITypeToString(
privconn->vzCaps.scsiControllerModel)); driver->vzCaps.scsiControllerModel));
return -1; return -1;
} }
return 0; return 0;
......
...@@ -60,8 +60,8 @@ struct _vzCapabilities { ...@@ -60,8 +60,8 @@ struct _vzCapabilities {
typedef struct _vzCapabilities vzCapabilities; typedef struct _vzCapabilities vzCapabilities;
typedef struct _vzCapabilities *vzCapabilitiesPtr; typedef struct _vzCapabilities *vzCapabilitiesPtr;
struct _vzConn { struct _vzDriver {
virMutex lock; virObjectLockable parent;
/* Immutable pointer, self-locking APIs */ /* Immutable pointer, self-locking APIs */
virDomainObjListPtr domains; virDomainObjListPtr domains;
...@@ -70,15 +70,25 @@ struct _vzConn { ...@@ -70,15 +70,25 @@ struct _vzConn {
virCapsPtr caps; virCapsPtr caps;
virDomainXMLOptionPtr xmlopt; virDomainXMLOptionPtr xmlopt;
virObjectEventStatePtr domainEventState; virObjectEventStatePtr domainEventState;
/* Immutable pointer, self-locking APIs */
virConnectCloseCallbackDataPtr closeCallback;
unsigned long vzVersion; unsigned long vzVersion;
vzCapabilities vzCaps; 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 vzConn;
typedef struct _vzConn *vzConnPtr; typedef struct _vzConn *vzConnPtr;
struct _vzCountersCache { struct _vzCountersCache {
PRL_HANDLE stats; PRL_HANDLE stats;
virCond cond; virCond cond;
...@@ -105,12 +115,19 @@ char * vzGetOutput(const char *binary, ...) ...@@ -105,12 +115,19 @@ char * vzGetOutput(const char *binary, ...)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_SENTINEL; ATTRIBUTE_NONNULL(1) ATTRIBUTE_SENTINEL;
void vzDriverLock(vzConnPtr driver); void vzDriverLock(vzConnPtr driver);
void vzDriverUnlock(vzConnPtr driver); void vzDriverUnlock(vzConnPtr driver);
vzDriverPtr
vzGetDriverConnection(void);
void
vzDestroyDriverConnection(void);
virDomainObjPtr virDomainObjPtr
vzNewDomain(vzConnPtr privconn, vzNewDomain(vzDriverPtr driver,
char *name, char *name,
const unsigned char *uuid); const unsigned char *uuid);
int int
vzInitVersion(vzConnPtr privconn); vzInitVersion(vzDriverPtr driver);
int int
vzCheckUnsupportedDisks(virDomainDefPtr def, vzCheckUnsupportedDisks(virDomainDefPtr def,
vzCapabilitiesPtr vzCaps); vzCapabilitiesPtr vzCaps);
...@@ -118,7 +135,7 @@ int ...@@ -118,7 +135,7 @@ int
vzCheckUnsupportedControllers(virDomainDefPtr def, vzCheckUnsupportedControllers(virDomainDefPtr def,
vzCapabilitiesPtr vzCaps); vzCapabilitiesPtr vzCaps);
int int
vzGetDefaultSCSIModel(vzConnPtr privconn, vzGetDefaultSCSIModel(vzDriverPtr driver,
PRL_CLUSTERED_DEVICE_SUBTYPE *scsiModel); PRL_CLUSTERED_DEVICE_SUBTYPE *scsiModel);
# define PARALLELS_BLOCK_STATS_FOREACH(OP) \ # define PARALLELS_BLOCK_STATS_FOREACH(OP) \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册