[PATCH 0 of 4] #5 - Enable VSSD to validate client given object path and Adopt changed to VSSD interface to ESD & SDS & VSSDC

VSSD does now take care of the client given object path. The resulting interface changes have been adopted to - ESD by the second patch - SDS by the third patch - VSSDC by the fourth patch (diff to patch set 1) diff to patch set 2: - updated VSSD to compare a returned integer result explicitely diff to patch set 3: - fixed memory leak (on name) in get_vssd_by_ref - fixed get_vssd_by_name and get_vssd_by_ref to only return a valid instance pointer in case of success diff to patch set 4: - fix whitespace issues

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1204015905 -3600 # Node ID 330455bd74683ef91240d1d290da2339c7719a6c # Parent 1aef50fa67a9ba1a3687afe03e3b1bf455d57685 VSSD: validate client given object path wbemgi 'http://localhost:5988/root/virt:KVM_VirtualSystemSettingData.InstanceID="Xen:kvm1-f8"' on a KVM only system is returning an instance, but should not. wbemgi 'http://localhost:5988/root/virt:Xen_VirtualSystemSettingData.InstanceID="KVM:kvm1-f8"' on a KVM only system is seg faulting, but should not ;). Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 1aef50fa67a9 -r 330455bd7468 src/Virt_VSSD.c --- a/src/Virt_VSSD.c Mon Feb 25 09:09:02 2008 -0800 +++ b/src/Virt_VSSD.c Tue Feb 26 09:51:45 2008 +0100 @@ -135,42 +135,46 @@ static int instance_from_dom(virDomainPt return ret; } -CMPIInstance *get_vssd_instance(virDomainPtr dom, - const CMPIBroker *broker, - const CMPIObjectPath *ref) -{ - CMPIInstance *inst; - +static CMPIInstance *_get_vssd(const CMPIBroker *broker, + const CMPIObjectPath *reference, + virConnectPtr conn, + virDomainPtr dom, + CMPIStatus *s) +{ + CMPIInstance *inst = NULL; + inst = get_typed_instance(broker, - CLASSNAME(ref), + pfx_from_conn(conn), "VirtualSystemSettingData", - NAMESPACE(ref)); - - if (inst == NULL) - return NULL; - - if (instance_from_dom(dom, inst)) - return inst; - else - return NULL; -} - -static CMPIStatus enum_vssd(const CMPIObjectPath *reference, - const CMPIResult *results, - int names_only) + NAMESPACE(reference)); + + if (inst == NULL) { + cu_statusf(broker, s, + CMPI_RC_ERR_FAILED, + "Unable to init VirtualSystemSettingData instance"); + goto out; + } + + if (instance_from_dom(dom, inst) != 1) { + cu_statusf(broker, s, + CMPI_RC_ERR_FAILED, + "Unable to get VSSD instance from Domain"); + } + + out: + return inst; +} + +static CMPIStatus return_enum_vssd(const CMPIObjectPath *reference, + const CMPIResult *results, + bool names_only) { virConnectPtr conn; virDomainPtr *list; int count; int i; - CMPIStatus s; - const char *ns; - - if (!provider_is_responsible(_BROKER, reference, &s)) - return s; - - ns = NAMESPACE(reference); - + CMPIStatus s = {CMPI_RC_OK, NULL}; + conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); if (conn == NULL) return s; @@ -181,17 +185,14 @@ static CMPIStatus enum_vssd(const CMPIOb CMPI_RC_ERR_FAILED, "Failed to enumerate domains"); goto out; - } else if (count == 0) { - cu_statusf(_BROKER, &s, - CMPI_RC_OK, - ""); - goto out; - } + } else if (count == 0) + goto out; for (i = 0; i < count; i++) { - CMPIInstance *inst; - - inst = get_vssd_instance(list[i], _BROKER, reference); + CMPIInstance *inst = NULL; + + inst = _get_vssd(_BROKER, reference, conn, list[i], &s); + virDomainFree(list[i]); if (inst == NULL) continue; @@ -202,39 +203,83 @@ static CMPIStatus enum_vssd(const CMPIOb CMReturnInstance(results, inst); } - cu_statusf(_BROKER, &s, - CMPI_RC_OK, - ""); out: free(list); return s; - -} - -static CMPIInstance *get_vssd_for_name(const CMPIObjectPath *reference, - char *name) +} + +CMPIStatus get_vssd_by_name(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const char *name, + CMPIInstance **_inst) { virConnectPtr conn; virDomainPtr dom; - CMPIStatus s; - CMPIInstance *inst = NULL; - - conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); - if (conn == NULL) - return NULL; - + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst = NULL; + + conn = connect_by_classname(broker, CLASSNAME(reference), &s); + if (conn == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance"); + goto out; + } + dom = virDomainLookupByName(conn, name); - if (dom == NULL) - goto out; - - inst = get_vssd_instance(dom, _BROKER, reference); - + if (dom == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", + name); + goto out; + } + + inst = _get_vssd(broker, reference, conn, dom, &s); + + virDomainFree(dom); + + if (s.rc != CMPI_RC_OK) + goto out; + + *_inst = inst; + out: virConnectClose(conn); - virDomainFree(dom); - - return inst; + + return s; +} + +CMPIStatus get_vssd_by_ref(const CMPIBroker *broker, + const CMPIObjectPath *reference, + CMPIInstance **_inst) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst = NULL; + char *name = NULL; + + if (!parse_instanceid(reference, NULL, &name)) { + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (InstanceID)"); + goto out; + } + + s = get_vssd_by_name(broker, reference, name, &inst); + if (s.rc != CMPI_RC_OK) + goto out; + + s = cu_validate_ref(broker, reference, inst); + if (s.rc != CMPI_RC_OK) + goto out; + + *_inst = inst; + + out: + free(name); + + return s; } static CMPIStatus EnumInstanceNames(CMPIInstanceMI *self, @@ -242,7 +287,7 @@ static CMPIStatus EnumInstanceNames(CMPI const CMPIResult *results, const CMPIObjectPath *reference) { - return enum_vssd(reference, results, 1); + return return_enum_vssd(reference, results, true); } static CMPIStatus EnumInstances(CMPIInstanceMI *self, @@ -251,7 +296,7 @@ static CMPIStatus EnumInstances(CMPIInst const CMPIObjectPath *reference, const char **properties) { - return enum_vssd(reference, results, 0); + return return_enum_vssd(reference, results, false); } static CMPIStatus GetInstance(CMPIInstanceMI *self, @@ -261,26 +306,15 @@ static CMPIStatus GetInstance(CMPIInstan const char **properties) { CMPIStatus s; - CMPIInstance *inst; - char *locid; - - if (!parse_instanceid(reference, NULL, &locid)) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Invalid InstanceID specified"); - return s; - } - - inst = get_vssd_for_name(reference, locid); - if (inst) - CMReturnInstance(results, inst); - - cu_statusf(_BROKER, &s, - CMPI_RC_OK, - ""); - - free(locid); - + CMPIInstance *inst = NULL; + + s = get_vssd_by_ref(_BROKER, reference, &inst); + if (s.rc != CMPI_RC_OK) + goto out; + + CMReturnInstance(results, inst); + + out: return s; } diff -r 1aef50fa67a9 -r 330455bd7468 src/Virt_VSSD.h --- a/src/Virt_VSSD.h Mon Feb 25 09:09:02 2008 -0800 +++ b/src/Virt_VSSD.h Tue Feb 26 09:51:45 2008 +0100 @@ -21,8 +21,14 @@ #ifndef __VIRT_VSSD_H #define __VIRT_VSSD_H -CMPIInstance *get_vssd_instance(virDomainPtr dom, - const CMPIBroker *broker, - const CMPIObjectPath *ref); +CMPIStatus get_vssd_by_ref(const CMPIBroker *broker, + const CMPIObjectPath *reference, + CMPIInstance **_inst); + +CMPIStatus get_vssd_by_name(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const char *name, + CMPIInstance **_inst); + #endif

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1204016142 -3600 # Node ID 9e52e86e0765b889e7755c5c5c885342d644ed2c # Parent 330455bd74683ef91240d1d290da2339c7719a6c ESD: adopt interface changes in VSSD Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 330455bd7468 -r 9e52e86e0765 src/Virt_ElementSettingData.c --- a/src/Virt_ElementSettingData.c Tue Feb 26 09:51:45 2008 +0100 +++ b/src/Virt_ElementSettingData.c Tue Feb 26 09:55:42 2008 +0100 @@ -41,47 +41,20 @@ static CMPIStatus vssd_to_vssd(const CMP { CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIInstance *inst; - virConnectPtr conn = NULL; - virDomainPtr dom = NULL; - char *host = NULL; if (!match_hypervisor_prefix(ref, info)) return s; - if (!parse_instanceid(ref, NULL, &host)) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Unable to get system name"); + /* Special association case: + * VSSD instance is pointing to itself + */ + s = get_vssd_by_ref(_BROKER, ref, &inst); + if (s.rc != CMPI_RC_OK) goto out; - } - - conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); - if (conn == NULL) - goto out; - - dom = virDomainLookupByName(conn, host); - if (dom == NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "No such system `%s'", host); - goto out; - } - - inst = get_vssd_instance(dom, _BROKER, ref); - if (inst == NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Error getting VSSD for `%s'", host); - goto out; - } inst_list_add(list, inst); out: - virDomainFree(dom); - virConnectClose(conn); - free(host); - return s; }

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1204016311 -3600 # Node ID 972e31994c47cfbd4af63b83c1138bc83e6d2b23 # Parent 9e52e86e0765b889e7755c5c5c885342d644ed2c SDS: adopt interface changes in VSSD Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 9e52e86e0765 -r 972e31994c47 src/Virt_SettingsDefineState.c --- a/src/Virt_SettingsDefineState.c Tue Feb 26 09:55:42 2008 +0100 +++ b/src/Virt_SettingsDefineState.c Tue Feb 26 09:58:31 2008 +0100 @@ -199,18 +199,16 @@ static CMPIStatus vs_to_vssd(const CMPIO struct std_assoc_info *info, struct inst_list *list) { - virConnectPtr conn = NULL; - virDomainPtr dom = NULL; + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst; const char *name; - CMPIInstance *vssd; - CMPIStatus s = {CMPI_RC_OK, NULL}; if (!match_hypervisor_prefix(ref, info)) return s; - conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); - if (conn == NULL) - return s; + s = get_domain(_BROKER, ref, &inst); + if (s.rc != CMPI_RC_OK) + goto out; if (cu_get_str_path(ref, "Name", &name) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, @@ -219,27 +217,14 @@ static CMPIStatus vs_to_vssd(const CMPIO goto out; } - dom = virDomainLookupByName(conn, name); - if (dom == NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "No such domain `%s'", name); - goto out; - } - - vssd = get_vssd_instance(dom, _BROKER, ref); - if (vssd != NULL) - inst_list_add(list, vssd); - - cu_statusf(_BROKER, &s, - CMPI_RC_OK, - ""); - out: - virDomainFree(dom); - virConnectClose(conn); - + s = get_vssd_by_name(_BROKER, ref, name, &inst); + if (s.rc != CMPI_RC_OK) + goto out; + + inst_list_add(list, inst); + + out: return s; - } static CMPIStatus vssd_to_vs(const CMPIObjectPath *ref, @@ -253,9 +238,14 @@ static CMPIStatus vssd_to_vs(const CMPIO virConnectPtr conn = NULL; CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIInstance *cs; + CMPIInstance *inst; if (!match_hypervisor_prefix(ref, info)) return s; + + s = get_vssd_by_ref(_BROKER, ref, &inst); + if (s.rc != CMPI_RC_OK) + goto out; if (cu_get_str_path(ref, "InstanceID", &id) != CMPI_RC_OK) { cu_statusf(_BROKER, &s,

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1204016361 -3600 # Node ID f3320ebdb7dae05d2137349af824fbaf28f49f67 # Parent 972e31994c47cfbd4af63b83c1138bc83e6d2b23 VSSDC: adopt interface changes in VSSD Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 972e31994c47 -r f3320ebdb7da src/Virt_VSSDComponent.c --- a/src/Virt_VSSDComponent.c Tue Feb 26 09:58:31 2008 +0100 +++ b/src/Virt_VSSDComponent.c Tue Feb 26 09:59:21 2008 +0100 @@ -41,6 +41,7 @@ static CMPIStatus vssd_to_rasd(const CMP struct inst_list *list) { CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst = NULL; char *name = NULL; int i = 0; int types[] = { @@ -52,7 +53,11 @@ static CMPIStatus vssd_to_rasd(const CMP }; if (!match_hypervisor_prefix(ref, info)) - return s; + goto out; + + s = get_vssd_by_ref(_BROKER, ref, &inst); + if (s.rc != CMPI_RC_OK) + goto out; if (!parse_instanceid(ref, NULL, &name)) { cu_statusf(_BROKER, &s, @@ -70,48 +75,9 @@ static CMPIStatus vssd_to_rasd(const CMP list); } - cu_statusf(_BROKER, &s, - CMPI_RC_OK, - ""); - out: free(name); - return s; -} - -static CMPIStatus vssd_for_name(const char *host, - const CMPIObjectPath *ref, - CMPIInstance **inst) -{ - virConnectPtr conn = NULL; - virDomainPtr dom = NULL; - CMPIStatus s; - - conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); - if (conn == NULL) - goto out; - - dom = virDomainLookupByName(conn, host); - if (dom == NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "No such system `%s'", host); - goto out; - } - - *inst = get_vssd_instance(dom, _BROKER, ref); - if (*inst == NULL) - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Error getting VSSD for `%s'", host); - else - cu_statusf(_BROKER, &s, - CMPI_RC_OK, - ""); out: - virDomainFree(dom); - virConnectClose(conn); - return s; } @@ -144,9 +110,11 @@ static CMPIStatus rasd_to_vssd(const CMP goto out; } - s = vssd_for_name(host, ref, &vssd); - if (vssd) - inst_list_add(list, vssd); + s = get_vssd_by_name(_BROKER, ref, host, &vssd); + if (s.rc != CMPI_RC_OK) + goto out; + + inst_list_add(list, vssd); out: free(host);

HE> diff to patch set 4: HE> - fix whitespace issues Thanks Heidi :) -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com
participants (2)
-
Dan Smith
-
Heidi Eckhart