[PATCH 0 of 2] Adding ElementSettingData.

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1195059885 28800 # Node ID dcff5fda5aa96ee449810d2eb37cbf36e5e76eaa # Parent c802d7801234023e14b60f3c2703ec2de063859b Updating build scripts to make / install/ and register provider. Also added the necessary mof /registration files. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r c802d7801234 -r dcff5fda5aa9 Makefile.am --- a/Makefile.am Wed Nov 14 09:04:30 2007 -0800 +++ b/Makefile.am Wed Nov 14 09:04:45 2007 -0800 @@ -31,7 +31,8 @@ MOFS = \ schema/NetPool.mof \ schema/ResourceAllocationFromPool.mof \ schema/ElementAllocatedFromPool.mof \ - schema/HostedService.mof + schema/HostedService.mof \ + schema/ElementSettingData.mof INTEROP_MOFS = \ schema/RegisteredProfile.mof \ @@ -67,7 +68,8 @@ REGS = \ schema/NetPool.registration \ schema/ResourceAllocationFromPool.registration \ schema/ElementAllocatedFromPool.registration \ - schema/HostedService.registration + schema/HostedService.registration \ + schema/ElementSettingData.registration INTEROP_REGS = \ schema/RegisteredProfile.registration \ diff -r c802d7801234 -r dcff5fda5aa9 schema/ElementSettingData.mof --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/ElementSettingData.mof Wed Nov 14 09:04:45 2007 -0800 @@ -0,0 +1,6 @@ +// Copyright IBM Corp. 2007 +class Xen_ElementSettingData : CIM_ElementSettingData { +}; + +class KVM_ElementSettingData : CIM_ElementSettingData { +}; diff -r c802d7801234 -r dcff5fda5aa9 schema/ElementSettingData.registration --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/ElementSettingData.registration Wed Nov 14 09:04:45 2007 -0800 @@ -0,0 +1,4 @@ +# Copyright IBM Corp. 2007 +# Classname Namespace ProviderName ProviderModule ProviderTypes ... +Xen_ElementSettingData root/virt Xen_ElementSettingDataProvider Virt_ElementSettingData association +KVM_ElementSettingData root/virt KVM_ElementSettingDataProvider Virt_ElementSettingData association diff -r c802d7801234 -r dcff5fda5aa9 src/Makefile.am --- a/src/Makefile.am Wed Nov 14 09:04:30 2007 -0800 +++ b/src/Makefile.am Wed Nov 14 09:04:45 2007 -0800 @@ -49,7 +49,8 @@ provider_LTLIBRARIES = libVirt_ComputerS libVirt_SettingsDefineState.la \ libVirt_ResourceAllocationFromPool.la \ libVirt_ElementAllocatedFromPool.la \ - libVirt_HostedService.la + libVirt_HostedService.la \ + libVirt_ElementSettingData.la libVirt_ComputerSystem_la_SOURCES = Virt_ComputerSystem.c libVirt_Device_la_SOURCES = Virt_Device.c @@ -116,3 +117,6 @@ libVirt_ElementAllocatedFromPool_la_LIBA libVirt_HostedService_la_SOURCES = Virt_HostedService.c libVirt_HostedService_la_LIBADD = -lVirt_VirtualSystemManagementService -lVirt_ResourcePoolConfigurationService + +libVirt_ElementSettingData_la_SOURCES = Virt_ElementSettingData.c +libVirt_ElementSettingData_la_LIBADD = -lVirt_VSSD

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1195059870 28800 # Node ID c802d7801234023e14b60f3c2703ec2de063859b # Parent aad2a74321d54e26b5b2c89dc8df0e95bd1860f8 Adding ElementSettingData association. This only handles the case defined in section "7.3.4.2 Single-Configuration Implementation Approach" of the VSP. Will update to handle the case(s) defined in the Resource Allocation Profile. The handler name is a bit ugly. I suspect this name will change when I add the RASD pieces. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r aad2a74321d5 -r c802d7801234 src/Virt_ElementSettingData.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Virt_ElementSettingData.c Wed Nov 14 09:04:30 2007 -0800 @@ -0,0 +1,182 @@ +/* + * Copyright IBM Corp. 2007 + * + * Authors: + * Kaitlin Rupert <karupert@us.ibm.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <cmpidt.h> +#include <cmpift.h> +#include <cmpimacs.h> + +#include "libcmpiutil.h" +#include "std_association.h" +#include "misc_util.h" + +#include "Virt_VSSD.h" + +const static CMPIBroker *_BROKER; + +static CMPIStatus get_dom_name_from_ref(const CMPIObjectPath *ref, + char **dom_name) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + char *id; + + id = cu_get_str_path(ref, "InstanceID"); + if (id == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Missing InstanceID"); + goto out; + } + + *dom_name = strdup(strchr(id, ':') + 1); + if (*dom_name == NULL) + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Error retrieving domain name."); + + free(id); + +out: + return s; +} + +static CMPIStatus vssd_to_sd(const CMPIObjectPath *ref, + struct std_assoc_info *info, + struct inst_list *list) +{ + CMPIStatus s; + CMPIInstance *inst; + virConnectPtr conn = NULL; + virDomainPtr dom = NULL; + char *host = NULL; + + ASSOC_MATCH(info->provider_name, CLASSNAME(ref)); + + s = get_dom_name_from_ref(ref, &host); + if (s.rc != CMPI_RC_OK) + goto out; + + conn = lv_connect(_BROKER, &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); + + return s; +} + +static CMPIInstance *make_ref(const CMPIObjectPath *ref, + const CMPIInstance *inst, + struct std_assoc_info *info, + struct std_assoc *assoc) +{ + CMPIInstance *refinst = NULL; + char *base; + + base = class_base_name(assoc->assoc_class); + if (base == NULL) + goto out; + + refinst = get_typed_instance(_BROKER, + base, + NAMESPACE(ref)); + + if (refinst != NULL) { + CMPIObjectPath *instop; + + instop = CMGetObjectPath(inst, NULL); + + set_reference(assoc, refinst, ref, instop); + + /* Set additional properties with values + * defined in the "Virtual System Profile." + */ + set_reference(assoc, refinst, ref, instop); + unsigned int lValue = 1; + CMSetProperty(refinst, "IsDefault", + (CMPIValue *)&lValue, CMPI_uint16); + + CMSetProperty(refinst, "IsNext", + (CMPIValue *)&lValue, CMPI_uint16); + + CMSetProperty(refinst, "IsMinimum", + (CMPIValue *)&lValue, CMPI_uint16); + + CMSetProperty(refinst, "IsMaximum", + (CMPIValue *)&lValue, CMPI_uint16); + } + +out: + return refinst; +} + +static struct std_assoc vssd_to_sd_fd_bkwd = { + .source_class = "CIM_VirtualSystemSettingData", + .source_prop = "ManagedElement", + + .target_class = "CIM_ManagedElement", + .target_prop = "SettingData", + + .assoc_class = "CIM_ElementSettingData", + + .handler = vssd_to_sd, + .make_ref = make_ref +}; + +static struct std_assoc *handlers[] = { + &vssd_to_sd_fd_bkwd, + NULL +}; + +STDA_AssocMIStub(, Xen_ElementSettingDataProvider, _BROKER, CMNoHook, handlers); +STDA_AssocMIStub(, KVM_ElementSettingDataProvider, _BROKER, CMNoHook, handlers); + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */

KR> + *dom_name = strdup(strchr(id, ':') + 1); This is a crash waiting to happen. If strchr() returns NULL because the ':' isn't found, then it'll try to strdup(NULL + 1), which will just trample through memory until it hits a '\0' or runs into a segfault. KR> +static CMPIStatus vssd_to_sd(const CMPIObjectPath *ref, KR> + struct std_assoc_info *info, KR> + struct inst_list *list) KR> +{ KR> + CMPIStatus s; KR> + CMPIInstance *inst; KR> + virConnectPtr conn = NULL; KR> + virDomainPtr dom = NULL; KR> + char *host = NULL; KR> + KR> + ASSOC_MATCH(info->provider_name, CLASSNAME(ref)); KR> + KR> + s = get_dom_name_from_ref(ref, &host); KR> + if (s.rc != CMPI_RC_OK) KR> + goto out; KR> + KR> + conn = lv_connect(_BROKER, &s); KR> + if (conn == NULL) KR> + goto out; KR> + KR> + dom = virDomainLookupByName(conn, host); KR> + if (dom == NULL) { KR> + cu_statusf(_BROKER, &s, KR> + CMPI_RC_ERR_FAILED, KR> + "No such system `%s'", host); KR> + goto out; KR> + } KR> + KR> + inst = get_vssd_instance(dom, _BROKER, ref); KR> + if (inst == NULL) { KR> + cu_statusf(_BROKER, &s, KR> + CMPI_RC_ERR_FAILED, KR> + "Error getting VSSD for `%s'", host); KR> + goto out; KR> + } KR> + KR> + inst_list_add(list, inst); KR> + KR> + out: KR> + virDomainFree(dom); KR> + virConnectClose(conn); KR> + You leak "host" here. KR> +static CMPIInstance *make_ref(const CMPIObjectPath *ref, KR> + const CMPIInstance *inst, KR> + struct std_assoc_info *info, KR> + struct std_assoc *assoc) KR> +{ KR> + CMPIInstance *refinst = NULL; KR> + char *base; KR> + KR> + base = class_base_name(assoc->assoc_class); KR> + if (base == NULL) KR> + goto out; KR> + KR> + refinst = get_typed_instance(_BROKER, KR> + base, KR> + NAMESPACE(ref)); KR> + KR> + if (refinst != NULL) { KR> + CMPIObjectPath *instop; KR> + KR> + instop = CMGetObjectPath(inst, NULL); KR> + KR> + set_reference(assoc, refinst, ref, instop); KR> + KR> + /* Set additional properties with values KR> + * defined in the "Virtual System Profile." KR> + */ KR> + set_reference(assoc, refinst, ref, instop); Are you making the same set_reference() call twice in a row? KR> + unsigned int lValue = 1; Please don't define new variables in the middle of a block. KR> + CMSetProperty(refinst, "IsDefault", KR> + (CMPIValue *)&lValue, CMPI_uint16); "lValue" is an unsigned int, which is not a uint16. Define lValue as a uint16_t. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com
participants (2)
-
Dan Smith
-
Kaitlin Rupert