[PATCH] Enumeration on HostSystem class is returning dups

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1195733309 -3600 # Node ID 8c0410bfe3d3da3ef61aa40bfe75f1f23426b77d # Parent 278c59f67cb1fe0520e8dfa7b118cd907e8f10a1 Enumeration on HostSystem class is returning dups On systems where only one hypervisor is existing, the provider returned instance for all known subclasses (Xen, KVM). Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 278c59f67cb1 -r 8c0410bfe3d3 src/Virt_HostSystem.c --- a/src/Virt_HostSystem.c Tue Nov 20 16:26:00 2007 -0500 +++ b/src/Virt_HostSystem.c Thu Nov 22 13:08:29 2007 +0100 @@ -36,20 +36,24 @@ const static CMPIBroker *_BROKER; -static int set_host_system_properties(CMPIInstance *instance, - const char *classname) +static int set_host_system_properties(CMPIInstance *instance) { + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIObjectPath *op; char hostname[256] = {0}; - CMSetProperty(instance, "CreationClassName", - (CMPIValue *)classname, CMPI_chars); + op = CMGetObjectPath(instance, &s); + if ((s.rc == CMPI_RC_OK) || !CMIsNullObject(op)) { + CMSetProperty(instance, "CreationClassName", + (CMPIValue *)CLASSNAME(op), CMPI_chars); + } if (gethostname(hostname, sizeof(hostname) - 1) != 0) strcpy(hostname, "unknown"); CMSetProperty(instance, "Name", (CMPIValue *)hostname, CMPI_chars); - + return 1; } @@ -57,44 +61,32 @@ CMPIStatus get_host_cs(const CMPIBroker const CMPIObjectPath *reference, CMPIInstance **instance) { + CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIInstance *inst = NULL; - CMPIObjectPath *op; - CMPIStatus s; - char *ns; - char *classname; + virConnectPtr conn = NULL; - ns = NAMESPACE(reference); + conn = connect_by_classname(broker, CLASSNAME(reference), &s); + if (conn == NULL) + goto out; - classname = get_typed_class(CLASSNAME(reference), "HostSystem"); - if (classname == NULL) { - CMSetStatusWithChars(broker, &s, + inst = get_typed_instance(broker, + pfx_from_conn(conn), + "HostSystem", + NAMESPACE(reference)); + + if (inst == NULL) { + CMSetStatusWithChars(broker, &s, CMPI_RC_ERR_FAILED, - "Invalid class"); - goto out; + "Can't create HostSystem instance."); + goto err; } - op = CMNewObjectPath(broker, ns, classname, &s); - if ((s.rc != CMPI_RC_OK) || CMIsNullObject(op)) { - CMSetStatusWithChars(broker, &s, - CMPI_RC_ERR_FAILED, - "Cannot get object path for HostSystem"); - goto out; - } + set_host_system_properties(inst); - inst = CMNewInstance(broker, op, &s); - if ((s.rc != CMPI_RC_OK) || (CMIsNullObject(op))) { - CMSetStatusWithChars(broker, &s, - CMPI_RC_ERR_FAILED, - "Failed to instantiate HostSystem"); - goto out; - } - - set_host_system_properties(inst, classname); - + err: + virConnectClose(conn); out: *instance = inst; - - free(classname); return s; } @@ -103,17 +95,11 @@ static CMPIStatus return_host_cs(const C const CMPIResult *results, int name_only) { - CMPIStatus s; + CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIInstance *instance; - char *ns; - - if (!provider_is_responsible(_BROKER, reference, &s)) - return s; - - ns = NAMESPACE(reference); s = get_host_cs(_BROKER, reference, &instance); - if (s.rc != CMPI_RC_OK) + if (s.rc != CMPI_RC_OK || instance == NULL) goto out; if (name_only)

HE> # HG changeset patch HE> # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> HE> # Date 1195733309 -3600 HE> # Node ID 8c0410bfe3d3da3ef61aa40bfe75f1f23426b77d HE> # Parent 278c59f67cb1fe0520e8dfa7b118cd907e8f10a1 HE> Enumeration on HostSystem class is returning dups I think most of the changes in this patch are good, but I'm not quite sure why they prevent returning dups. Can you explain a little bit? HE> + err: HE> + virConnectClose(conn); HE> out: virConnectClose(NULL) is a no-op (like free(NULL)). Everywhere else in the code, we just have a single out label. I'd prefer that we remain consistent with that, unless there is a good reason not to for a particular instance. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

Dan Smith wrote:
HE> # HG changeset patch HE> # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> HE> # Date 1195733309 -3600 HE> # Node ID 8c0410bfe3d3da3ef61aa40bfe75f1f23426b77d HE> # Parent 278c59f67cb1fe0520e8dfa7b118cd907e8f10a1 HE> Enumeration on HostSystem class is returning dups
I think most of the changes in this patch are good, but I'm not quite sure why they prevent returning dups. Can you explain a little bit?
This was the result of an enumeration against CIM_ComputerSystem. The HostSystem provider returned instances of Xen_HostSystem, while I have no Xen installed on my system. [heidineu@localhost ~]$ wbemein http://localhost/root/virt:CIM_ComputerSystem localhost:5988/root/virt:KVM_HostSystem.CreationClassName="KVM_HostSystem",Name="localhost.localdomain" localhost:5988/root/virt:Xen_HostSystem.CreationClassName="Xen_HostSystem",Name="localhost.localdomain" localhost:5988/root/virt:KVM_ComputerSystem.CreationClassName="KVM_ComputerSystem",Name="qemu1" The reason why this happened is, that the provider_is_responsible() function checks only for "CIM" prefix now and no longer "compares" the requested class prefix against the hypervisor type installed on the machine. This is now done by connect_by_classname(). The result was, that the provider returned instances independent of the installed hypervisor.
HE> + err: HE> + virConnectClose(conn); HE> out:
virConnectClose(NULL) is a no-op (like free(NULL)). Everywhere else in the code, we just have a single out label. I'd prefer that we remain consistent with that, unless there is a good reason not to for a particular instance.
fixed -- Regards Heidi Eckhart Software Engineer Linux Technology Center - Open Hypervisor heidieck@linux.vnet.ibm.com ************************************************** IBM Deutschland Entwicklung GmbH Vorsitzender des Aufsichtsrats: Martin Jetter Geschaeftsfuehrung: Herbert Kircher Sitz der Gesellschaft: Boeblingen Registergericht: Amtsgericht Stuttgart, HRB 243294
participants (2)
-
Dan Smith
-
Heidi Eckhart