
# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1202203369 -3600 # Node ID 81c6269fff598c777f203b93a6ae3d9d2c3cd718 # Parent c2ff6825e25f513417f395ea334f4f7963f2729c RPCS: enumerateInstance(Name)s and getInstance with wrong hypervisor segfaults wbemein http://localhost/root/virt:CIM_ResourcePoolConfigurationService on a KVM system with no Xen segfaults. The same happens to wbemgi 'http://localhost:5988/root/virt:Xen_ResourcePoolConfigurationService.SystemCreationClassName="Xen_HostSystem",SystemName="localhost.localdomain",CreationClassName="Xen_ResourcePoolConfigurationService",Name="RPCS"' This patch also makes RPCS aware of the supported hypervisor type. Now only instances of the machine's supported hypervisor are returned. This approach is used all over the libvirt-cim providers, but was broken here. Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r c2ff6825e25f -r 81c6269fff59 src/Virt_ResourcePoolConfigurationService.c --- a/src/Virt_ResourcePoolConfigurationService.c Mon Feb 04 09:53:29 2008 -0800 +++ b/src/Virt_ResourcePoolConfigurationService.c Tue Feb 05 10:22:49 2008 +0100 @@ -94,21 +94,28 @@ DEFAULT_EQ(); DEFAULT_EQ(); DEFAULT_INST_CLEANUP(); -CMPIStatus rpcs_instance(const CMPIObjectPath *reference, - CMPIInstance **_inst, - const CMPIBroker *broker) +CMPIStatus get_rpcs(const CMPIObjectPath *reference, + CMPIInstance **_inst, + const CMPIBroker *broker, + bool is_get_inst) { CMPIInstance *inst; - CMPIInstance *host; - CMPIStatus s; - CMPIData prop; - - s = get_host_cs(broker, reference, &host); - if (s.rc != CMPI_RC_OK) - goto out; + CMPIStatus s = {CMPI_RC_OK, NULL}; + virConnectPtr conn = NULL; + const char *name = NULL; + const char *ccname = NULL; + + conn = connect_by_classname(broker, CLASSNAME(reference), &s); + if (conn == NULL) { + if (is_get_inst) + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance"); + goto out; + } inst = get_typed_instance(broker, - CLASSNAME(reference), + pfx_from_conn(conn), "ResourcePoolConfigurationService", NAMESPACE(reference)); if (inst == NULL) { @@ -119,32 +126,57 @@ CMPIStatus rpcs_instance(const CMPIObjec goto out; } - CMSetProperty(inst, "Name", - (CMPIValue *)"RPCS", CMPI_chars); - - prop = CMGetProperty(host, "CreationClassName", &s); + s = get_host_system_properties(&name, + &ccname, + reference, + broker); if (s.rc != CMPI_RC_OK) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, - "Unable to get CreationClassName from HostSystem"); - goto out; - } + "Unable to get host attributes"); + goto out; + } + + CMSetProperty(inst, "Name", + (CMPIValue *)"RPCS", CMPI_chars); + + CMSetProperty(inst, "SystemName", + (CMPIValue *)name, CMPI_chars); CMSetProperty(inst, "SystemCreationClassName", - (CMPIValue *)&prop.value.string, CMPI_string); - - prop = CMGetProperty(host, "Name", NULL); - if (s.rc != CMPI_RC_OK) { - cu_statusf(broker, &s, - CMPI_RC_ERR_FAILED, - "Unable to get Name from HostSystem"); - goto out; - } - - CMSetProperty(inst, "SystemName", - (CMPIValue *)&prop.value.string, CMPI_string); + (CMPIValue *)ccname, CMPI_chars); + + if (is_get_inst) { + s = cu_validate_ref(broker, reference, inst); + if (s.rc != CMPI_RC_OK) + goto out; + } *_inst = inst; + + out: + virConnectClose(conn); + + return s; +} + +static CMPIStatus return_rpcs(const CMPIResult *results, + const CMPIObjectPath *reference, + bool names_only, + bool is_get_inst) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst = NULL; + + s = get_rpcs(reference, &inst, _BROKER, is_get_inst); + if (s.rc != CMPI_RC_OK || inst == NULL) + goto out; + + if (names_only) + cu_return_instance_name(results, inst); + else + CMReturnInstance(results, inst); + out: return s; } @@ -155,24 +187,7 @@ static CMPIStatus GetInstance(CMPIInstan const CMPIObjectPath *reference, const char **properties) { - CMPIInstance *inst; - CMPIStatus s; - const char *prop = NULL; - - s = rpcs_instance(reference, &inst, _BROKER); - if (s.rc != CMPI_RC_OK) - return s; - - prop = cu_compare_ref(reference, inst); - if (prop != NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_NOT_FOUND, - "No such instance (%s)", prop); - } else { - CMReturnInstance(results, inst); - } - - return s; + return return_rpcs(results, reference, false, true); } static CMPIStatus EnumInstanceNames(CMPIInstanceMI *self, @@ -180,14 +195,7 @@ static CMPIStatus EnumInstanceNames(CMPI const CMPIResult *results, const CMPIObjectPath *reference) { - CMPIInstance *inst; - CMPIStatus s; - - s = rpcs_instance(reference, &inst, _BROKER); - if (s.rc == CMPI_RC_OK) - cu_return_instance_name(results, inst); - - return s; + return return_rpcs(results, reference, true, false); } static CMPIStatus EnumInstances(CMPIInstanceMI *self, @@ -196,15 +204,7 @@ static CMPIStatus EnumInstances(CMPIInst const CMPIObjectPath *reference, const char **properties) { - - CMPIInstance *inst; - CMPIStatus s; - - s = rpcs_instance(reference, &inst, _BROKER); - if (s.rc == CMPI_RC_OK) - CMReturnInstance(results, inst); - - return s; + return return_rpcs(results, reference, false, false); } diff -r c2ff6825e25f -r 81c6269fff59 src/Virt_ResourcePoolConfigurationService.h --- a/src/Virt_ResourcePoolConfigurationService.h Mon Feb 04 09:53:29 2008 -0800 +++ b/src/Virt_ResourcePoolConfigurationService.h Tue Feb 05 10:22:49 2008 +0100 @@ -19,6 +19,17 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -CMPIStatus rpcs_instance(const CMPIObjectPath *reference, - CMPIInstance **_inst, - const CMPIBroker *broker); +CMPIStatus get_rpcs(const CMPIObjectPath *reference, + CMPIInstance **_inst, + const CMPIBroker *broker, + bool is_get_inst); + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */