/* esxVI_Context_Free */
ESX_VI__TEMPLATE__FREE(Context,
{
+ if (item->sessionLock != NULL) {
+ virMutexDestroy(item->sessionLock);
+ }
+
esxVI_CURL_Free(&item->curl);
VIR_FREE(item->url);
VIR_FREE(item->ipAddress);
VIR_FREE(item->password);
esxVI_ServiceContent_Free(&item->service);
esxVI_UserSession_Free(&item->session);
+ VIR_FREE(item->sessionLock);
esxVI_Datacenter_Free(&item->datacenter);
esxVI_ComputeResource_Free(&item->computeResource);
esxVI_HostSystem_Free(&item->hostSystem);
return -1;
}
+ if (VIR_ALLOC(ctx->sessionLock) < 0) {
+ virReportOOMError();
+ return -1;
+ }
+
+ if (virMutexInit(ctx->sessionLock) < 0) {
+ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Could not initialize session mutex"));
+ return -1;
+ }
+
if (esxVI_RetrieveServiceContent(ctx, &ctx->service) < 0) {
return -1;
}
esxVI_DynamicProperty *dynamicProperty = NULL;
esxVI_UserSession *currentSession = NULL;
- if (ctx->session == NULL) {
- ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid call"));
+ if (ctx->sessionLock == NULL) {
+ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid call, no mutex"));
return -1;
}
+ virMutexLock(ctx->sessionLock);
+
+ if (ctx->session == NULL) {
+ ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid call, no session"));
+ goto cleanup;
+ }
+
if (ctx->hasSessionIsActive) {
/*
* Use SessionIsActive to check if there is an active session for this
*/
if (esxVI_SessionIsActive(ctx, ctx->session->key,
ctx->session->userName, &active) < 0) {
- return -1;
+ goto cleanup;
}
if (active != esxVI_Boolean_True) {
if (esxVI_Login(ctx, ctx->username, ctx->password, NULL,
&ctx->session) < 0) {
- return -1;
+ goto cleanup;
}
}
-
- return 0;
} else {
/*
* Query the session manager for the current session of this connection
"last login"));
goto cleanup;
}
+ }
- result = 0;
+ result = 0;
cleanup:
- esxVI_String_Free(&propertyNameList);
- esxVI_ObjectContent_Free(&sessionManager);
- esxVI_UserSession_Free(¤tSession);
+ virMutexUnlock(ctx->sessionLock);
- return result;
- }
+ esxVI_String_Free(&propertyNameList);
+ esxVI_ObjectContent_Free(&sessionManager);
+ esxVI_UserSession_Free(¤tSession);
+
+ return result;
}
*/
struct _esxVI_Context {
+ /* All members are used read-only after esxVI_Context_Connect ... */
esxVI_CURL *curl;
char *url;
char *ipAddress;
esxVI_ServiceContent *service;
esxVI_APIVersion apiVersion;
esxVI_ProductVersion productVersion;
- esxVI_UserSession *session;
+ esxVI_UserSession *session; /* ... except the session ... */
+ virMutexPtr sessionLock; /* ... that is protected by this mutex */
esxVI_Datacenter *datacenter;
esxVI_ComputeResource *computeResource;
esxVI_HostSystem *hostSystem;