提交 65a0b334 编写于 作者: N Nikolay Shirokovskiy 提交者: Dmitry Guryanov

parallels: return only success from PCS event handler

2 reasons to to this.
1. PCS SDK really don't care of handler return value.
2. It hard to imagine how notifier can handle
subscriber failures. Even if there are some situations
we probably will use some special error codes and
not just throw error codes we get from SDK itself.
Signed-off-by: NNikolay Shirokovskiy <nshirokovskiy@parallels.com>
上级 c71f5f8c
...@@ -1534,7 +1534,7 @@ prlsdkNewStateToEvent(VIRTUAL_MACHINE_STATE domainState, ...@@ -1534,7 +1534,7 @@ prlsdkNewStateToEvent(VIRTUAL_MACHINE_STATE domainState,
} }
} }
static PRL_RESULT static void
prlsdkHandleVmStateEvent(parallelsConnPtr privconn, prlsdkHandleVmStateEvent(parallelsConnPtr privconn,
PRL_HANDLE prlEvent, PRL_HANDLE prlEvent,
unsigned char *uuid) unsigned char *uuid)
...@@ -1547,18 +1547,16 @@ prlsdkHandleVmStateEvent(parallelsConnPtr privconn, ...@@ -1547,18 +1547,16 @@ prlsdkHandleVmStateEvent(parallelsConnPtr privconn,
virDomainEventType lvEventType = 0; virDomainEventType lvEventType = 0;
int lvEventTypeDetails = 0; int lvEventTypeDetails = 0;
dom = virDomainObjListFindByUUID(privconn->domains, uuid);
if (dom == NULL)
return;
pret = PrlEvent_GetParamByName(prlEvent, "vminfo_vm_state", &eventParam); pret = PrlEvent_GetParamByName(prlEvent, "vminfo_vm_state", &eventParam);
prlsdkCheckRetGoto(pret, cleanup); prlsdkCheckRetGoto(pret, cleanup);
pret = PrlEvtPrm_ToInt32(eventParam, &domainState); pret = PrlEvtPrm_ToInt32(eventParam, &domainState);
prlsdkCheckRetGoto(pret, cleanup); prlsdkCheckRetGoto(pret, cleanup);
dom = virDomainObjListFindByUUID(privconn->domains, uuid);
if (dom == NULL) {
pret = PRL_ERR_VM_UUID_NOT_FOUND;
goto cleanup;
}
pdom = dom->privateData; pdom = dom->privateData;
if (prlsdkConvertDomainState(domainState, pdom->id, dom) < 0) if (prlsdkConvertDomainState(domainState, pdom->id, dom) < 0)
goto cleanup; goto cleanup;
...@@ -1567,96 +1565,74 @@ prlsdkHandleVmStateEvent(parallelsConnPtr privconn, ...@@ -1567,96 +1565,74 @@ prlsdkHandleVmStateEvent(parallelsConnPtr privconn,
&lvEventType, &lvEventType,
&lvEventTypeDetails); &lvEventTypeDetails);
if (prlsdkSendEvent(privconn, dom, lvEventType, lvEventTypeDetails) < 0) { prlsdkSendEvent(privconn, dom, lvEventType, lvEventTypeDetails);
pret = PRL_ERR_OUT_OF_MEMORY;
goto cleanup;
}
cleanup: cleanup:
if (dom)
virObjectUnlock(dom); virObjectUnlock(dom);
return pret; return;
} }
static PRL_RESULT static void
prlsdkHandleVmConfigEvent(parallelsConnPtr privconn, prlsdkHandleVmConfigEvent(parallelsConnPtr privconn,
unsigned char *uuid) unsigned char *uuid)
{ {
PRL_RESULT pret = PRL_ERR_FAILURE;
virDomainObjPtr dom = NULL; virDomainObjPtr dom = NULL;
dom = virDomainObjListFindByUUID(privconn->domains, uuid); dom = virDomainObjListFindByUUID(privconn->domains, uuid);
if (dom == NULL) { if (dom == NULL)
pret = PRL_ERR_VM_UUID_NOT_FOUND; return;
goto cleanup;
}
if (prlsdkUpdateDomain(privconn, dom) < 0) if (prlsdkUpdateDomain(privconn, dom) < 0)
goto cleanup; goto cleanup;
if (prlsdkSendEvent(privconn, dom, VIR_DOMAIN_EVENT_DEFINED, prlsdkSendEvent(privconn, dom, VIR_DOMAIN_EVENT_DEFINED,
VIR_DOMAIN_EVENT_DEFINED_UPDATED) < 0) { VIR_DOMAIN_EVENT_DEFINED_UPDATED);
pret = PRL_ERR_OUT_OF_MEMORY;
goto cleanup;
}
pret = PRL_ERR_SUCCESS;
cleanup: cleanup:
if (dom)
virObjectUnlock(dom); virObjectUnlock(dom);
return pret; return;
} }
static PRL_RESULT static void
prlsdkHandleVmAddedEvent(parallelsConnPtr privconn, prlsdkHandleVmAddedEvent(parallelsConnPtr privconn,
unsigned char *uuid) unsigned char *uuid)
{ {
PRL_RESULT pret;
virDomainObjPtr dom = NULL; virDomainObjPtr dom = NULL;
dom = prlsdkAddDomain(privconn, uuid); dom = prlsdkAddDomain(privconn, uuid);
if (!dom) if (dom == NULL)
return PRL_ERR_FAILURE; return;
if (prlsdkSendEvent(privconn, dom, VIR_DOMAIN_EVENT_DEFINED, prlsdkSendEvent(privconn, dom, VIR_DOMAIN_EVENT_DEFINED,
VIR_DOMAIN_EVENT_DEFINED_ADDED) < 0) { VIR_DOMAIN_EVENT_DEFINED_ADDED);
pret = PRL_ERR_OUT_OF_MEMORY;
goto cleanup;
}
pret = PRL_ERR_SUCCESS;
cleanup:
if (dom)
virObjectUnlock(dom); virObjectUnlock(dom);
return pret; return;
} }
static PRL_RESULT static void
prlsdkHandleVmRemovedEvent(parallelsConnPtr privconn, prlsdkHandleVmRemovedEvent(parallelsConnPtr privconn,
unsigned char *uuid) unsigned char *uuid)
{ {
virDomainObjPtr dom = NULL; virDomainObjPtr dom = NULL;
PRL_RESULT pret = PRL_ERR_SUCCESS;
dom = virDomainObjListFindByUUID(privconn->domains, uuid); dom = virDomainObjListFindByUUID(privconn->domains, uuid);
if (dom == NULL) {
/* 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 */
return PRL_ERR_SUCCESS; if (dom == NULL)
} return;
if (prlsdkSendEvent(privconn, dom, VIR_DOMAIN_EVENT_UNDEFINED, prlsdkSendEvent(privconn, dom, VIR_DOMAIN_EVENT_UNDEFINED,
VIR_DOMAIN_EVENT_UNDEFINED_REMOVED) < 0) VIR_DOMAIN_EVENT_UNDEFINED_REMOVED);
pret = PRL_ERR_OUT_OF_MEMORY;
virDomainObjListRemove(privconn->domains, dom); virDomainObjListRemove(privconn->domains, dom);
return pret; return;
} }
static PRL_RESULT static void
prlsdkHandleVmEvent(parallelsConnPtr privconn, PRL_HANDLE prlEvent) prlsdkHandleVmEvent(parallelsConnPtr privconn, PRL_HANDLE prlEvent)
{ {
PRL_RESULT pret; PRL_RESULT pret = PRL_ERR_FAILURE;
char uuidstr[VIR_UUID_STRING_BUFLEN + 2]; char uuidstr[VIR_UUID_STRING_BUFLEN + 2];
unsigned char uuid[VIR_UUID_BUFLEN]; unsigned char uuid[VIR_UUID_BUFLEN];
PRL_UINT32 bufsize = ARRAY_CARDINALITY(uuidstr); PRL_UINT32 bufsize = ARRAY_CARDINALITY(uuidstr);
...@@ -1669,67 +1645,64 @@ prlsdkHandleVmEvent(parallelsConnPtr privconn, PRL_HANDLE prlEvent) ...@@ -1669,67 +1645,64 @@ prlsdkHandleVmEvent(parallelsConnPtr privconn, PRL_HANDLE prlEvent)
prlsdkCheckRetGoto(pret, error); prlsdkCheckRetGoto(pret, error);
if (prlsdkUUIDParse(uuidstr, uuid) < 0) if (prlsdkUUIDParse(uuidstr, uuid) < 0)
return PRL_ERR_FAILURE; return;
switch (prlEventType) { switch (prlEventType) {
case PET_DSP_EVT_VM_STATE_CHANGED: case PET_DSP_EVT_VM_STATE_CHANGED:
return prlsdkHandleVmStateEvent(privconn, prlEvent, uuid); prlsdkHandleVmStateEvent(privconn, prlEvent, uuid);
break;
case PET_DSP_EVT_VM_CONFIG_CHANGED: case PET_DSP_EVT_VM_CONFIG_CHANGED:
return prlsdkHandleVmConfigEvent(privconn, uuid); prlsdkHandleVmConfigEvent(privconn, uuid);
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:
return prlsdkHandleVmAddedEvent(privconn, uuid); prlsdkHandleVmAddedEvent(privconn, uuid);
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:
return prlsdkHandleVmRemovedEvent(privconn, uuid); prlsdkHandleVmRemovedEvent(privconn, uuid);
break; break;
default: default:
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Can't handle event of type %d"), prlEventType); _("Can't handle event of type %d"), prlEventType);
return PRL_ERR_FAILURE;
} }
error: error:
return PRL_ERR_FAILURE; return;
} }
static PRL_RESULT static PRL_RESULT
prlsdkEventsHandler(PRL_HANDLE prlEvent, PRL_VOID_PTR opaque) prlsdkEventsHandler(PRL_HANDLE prlEvent, PRL_VOID_PTR opaque)
{ {
parallelsConnPtr privconn = opaque; parallelsConnPtr privconn = opaque;
PRL_RESULT pret = PRL_ERR_UNINITIALIZED; PRL_RESULT pret = PRL_ERR_FAILURE;
PRL_HANDLE_TYPE handleType; PRL_HANDLE_TYPE handleType;
PRL_EVENT_ISSUER_TYPE prlIssuerType = PIE_UNKNOWN; PRL_EVENT_ISSUER_TYPE prlIssuerType = PIE_UNKNOWN;
pret = PrlHandle_GetType(prlEvent, &handleType); pret = PrlHandle_GetType(prlEvent, &handleType);
prlsdkCheckRetGoto(pret, cleanup); prlsdkCheckRetGoto(pret, cleanup);
if (handleType != PHT_EVENT) {
/* Currently, there is no need to handle anything but events */ /* Currently, there is no need to handle anything but events */
pret = PRL_ERR_SUCCESS; if (handleType != PHT_EVENT)
goto cleanup; goto cleanup;
}
if (privconn == NULL) { if (privconn == NULL)
pret = PRL_ERR_INVALID_ARG;
goto cleanup; goto cleanup;
}
PrlEvent_GetIssuerType(prlEvent, &prlIssuerType); PrlEvent_GetIssuerType(prlEvent, &prlIssuerType);
prlsdkCheckRetGoto(pret, cleanup); prlsdkCheckRetGoto(pret, cleanup);
switch (prlIssuerType) { switch (prlIssuerType) {
case PIE_VIRTUAL_MACHINE: case PIE_VIRTUAL_MACHINE:
pret = prlsdkHandleVmEvent(privconn, prlEvent); prlsdkHandleVmEvent(privconn, prlEvent);
break; break;
default: default:
VIR_DEBUG("Skipping event of issuer type %d", prlIssuerType); VIR_DEBUG("Skipping event of issuer type %d", prlIssuerType);
} }
pret = PRL_ERR_SUCCESS;
cleanup: cleanup:
PrlHandle_Free(prlEvent); PrlHandle_Free(prlEvent);
return pret; return PRL_ERR_SUCCESS;
} }
int prlsdkSubscribeToPCSEvents(parallelsConnPtr privconn) int prlsdkSubscribeToPCSEvents(parallelsConnPtr privconn)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册