Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy(a)virtuozzo.com>
---
src/vz/vz_sdk.c | 68 ++++++++++++++++++++++++++++++-------------------------
src/vz/vz_utils.h | 2 +-
2 files changed, 38 insertions(+), 32 deletions(-)
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index a5474dc..51730be 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -44,6 +44,8 @@ static vzCountersCachePtr
vzCountersCacheNew(PRL_HANDLE sdkdom);
static void
vzCountersCacheFree(vzCountersCachePtr cache);
+static void
+vzCountersCacheEvent(vzCountersCachePtr cache, PRL_HANDLE event);
VIR_LOG_INIT("parallels.sdk");
@@ -1874,8 +1876,6 @@ prlsdkHandleVmRemovedEvent(vzDriverPtr driver,
return;
}
-#define PARALLELS_STATISTICS_DROP_COUNT 3
-
static void
prlsdkHandlePerfEvent(vzDriverPtr driver,
PRL_HANDLE event,
@@ -1883,8 +1883,6 @@ prlsdkHandlePerfEvent(vzDriverPtr driver,
{
virDomainObjPtr dom;
vzDomObjPtr privdom = NULL;
- PRL_HANDLE job = PRL_INVALID_HANDLE;
- vzCountersCachePtr cache;
dom = virDomainObjListFindByUUIDRef(driver->domains, uuid);
if (dom == NULL) {
@@ -1894,33 +1892,7 @@ prlsdkHandlePerfEvent(vzDriverPtr driver,
virObjectUnlock(dom);
privdom = dom->privateData;
- cache = privdom->cache;
- virMutexLock(&cache->lock);
-
- /* delayed event after unsubscribe */
- if (cache->count == -1)
- goto cleanup;
-
- PrlHandle_Free(cache->stats);
- cache->stats = PRL_INVALID_HANDLE;
-
- if (cache->count > PARALLELS_STATISTICS_DROP_COUNT) {
- job = PrlVm_UnsubscribeFromPerfStats(cache->sdkdom);
- if (PRL_FAILED(waitJob(job)))
- goto cleanup;
- /* change state to unsubscribed */
- cache->count = -1;
- } else {
- ++cache->count;
- cache->stats = event;
- /* thus we get own of event handle */
- event = PRL_INVALID_HANDLE;
- virCondSignal(&cache->cond);
- }
-
- cleanup:
- PrlHandle_Free(event);
- virMutexUnlock(&cache->lock);
+ vzCountersCacheEvent(privdom->cache, event);
virObjectUnref(dom);
}
@@ -4137,6 +4109,40 @@ vzCountersCacheNew(PRL_HANDLE sdkdom)
return NULL;
}
+#define PARALLELS_STATISTICS_DROP_COUNT 3
+
+static void
+vzCountersCacheEvent(vzCountersCachePtr cache, PRL_HANDLE event)
+{
+ PRL_HANDLE job = PRL_INVALID_HANDLE;
+ virMutexLock(&cache->lock);
+
+ /* delayed event after unsubscribe */
+ if (cache->count == -1)
+ goto cleanup;
+
+ PrlHandle_Free(cache->stats);
+ cache->stats = PRL_INVALID_HANDLE;
+
+ if (cache->count > PARALLELS_STATISTICS_DROP_COUNT) {
+ job = PrlVm_UnsubscribeFromPerfStats(cache->sdkdom);
+ if (PRL_FAILED(waitJob(job)))
+ goto cleanup;
+ /* change state to unsubscribed */
+ cache->count = -1;
+ } else {
+ ++cache->count;
+ cache->stats = event;
+ /* thus we get own of event handle */
+ event = PRL_INVALID_HANDLE;
+ virCondSignal(&cache->cond);
+ }
+
+ cleanup:
+ PrlHandle_Free(event);
+ virMutexUnlock(&cache->lock);
+}
+
char* prlsdkGetDiskStatName(virDomainDiskDefPtr disk)
{
virDomainDeviceDriveAddressPtr address;
diff --git a/src/vz/vz_utils.h b/src/vz/vz_utils.h
index a3ff152..d4ee88d 100644
--- a/src/vz/vz_utils.h
+++ b/src/vz/vz_utils.h
@@ -110,7 +110,7 @@ typedef vzCountersCache *vzCountersCachePtr;
struct vzDomObj {
int id;
PRL_HANDLE sdkdom;
- /* immutable */
+ /* immutable self-locking*/
vzCountersCachePtr cache;
};
--
1.8.3.1