[PATCH 0 of 3] Adding ElementSettingData.

Cleaned up previous patch - removed buggy InstanceID parsing code from ElementSettingData. Created a new function in libxutil/misc_util.c based on the InstanceID parsing of VSSDComponent. Enhanced parse_id() functionality to return both pfx and name. Added a parse_instanceid() wrapper function.

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1195150277 28800 # Node ID e80e9e777ac770ce8e5e9a25883af47eb05a266a # Parent ae4810e6764b1ea14df6f429eab972593e919e37 Add function to parse InstanceIDs. This function currently supports InstanceIDs in the format <Org>:<LocalID>, such as "Xen:Domain-0" for VSSD. The functionality is based on the parsing from VSSDComponent, so the code for parsing the InstanceID is replaced by the function. Updated function so that it can return both the InstanceID prefix (org) and the localID. The call has the option of supplying NULL for either argument. Also added a wrapper function that takes a CMPIObjectPath ref, grabs the instanceID, and then calls the parse_id() function. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r ae4810e6764b -r e80e9e777ac7 libxkutil/misc_util.c --- a/libxkutil/misc_util.c Thu Nov 15 09:49:47 2007 -0800 +++ b/libxkutil/misc_util.c Thu Nov 15 10:11:17 2007 -0800 @@ -371,6 +371,52 @@ bool domain_online(virDomainPtr dom) (info.state == VIR_DOMAIN_RUNNING); } +int parse_id(char *id, + char **pfx, + char **name) +{ + int ret; + char *tmp_pfx; + char *tmp_name; + + ret = sscanf(id, "%a[^:]:%as", &tmp_pfx, &tmp_name); + if (ret != 2) { + ret = 0; + goto out; + } + + if (pfx) + *pfx = strdup(tmp_pfx); + + if (name) + *name = strdup(tmp_name); + + ret = 1; + + out: + free(tmp_pfx); + free(tmp_name); + + return ret; +} + +bool parse_instanceid(const CMPIObjectPath *ref, + char **pfx, + char **name) +{ + int ret; + char *id = NULL; + + id = cu_get_str_path(ref, "InstanceID"); + if (id == NULL) + return false; + + ret = parse_id(id, pfx, name); + if (!ret) + return false; + + return true; +} /* * Local Variables: diff -r ae4810e6764b -r e80e9e777ac7 libxkutil/misc_util.h --- a/libxkutil/misc_util.h Thu Nov 15 09:49:47 2007 -0800 +++ b/libxkutil/misc_util.h Thu Nov 15 10:11:17 2007 -0800 @@ -89,6 +89,9 @@ char *association_prefix(const char *pro char *association_prefix(const char *provider_name); bool match_pn_to_cn(const char *pn, const char *cn); +int parse_id(char *id, char **pfx, char **name); +bool parse_instanceid(const CMPIObjectPath *ref, char **pfx, char **name); + #define ASSOC_MATCH(pn, cn) \ if (!match_pn_to_cn((pn), (cn))) { \ return (CMPIStatus){CMPI_RC_OK, NULL}; \ diff -r ae4810e6764b -r e80e9e777ac7 src/Virt_VSSDComponent.c --- a/src/Virt_VSSDComponent.c Thu Nov 15 09:49:47 2007 -0800 +++ b/src/Virt_VSSDComponent.c Thu Nov 15 10:11:17 2007 -0800 @@ -41,10 +41,7 @@ static CMPIStatus vssd_to_rasd(const CMP struct inst_list *list) { CMPIStatus s; - char *id = NULL; - char *pfx = NULL; char *name = NULL; - int ret; int i = 0; int types[] = { CIM_RASD_TYPE_PROC, @@ -56,19 +53,10 @@ static CMPIStatus vssd_to_rasd(const CMP ASSOC_MATCH(info->provider_name, CLASSNAME(ref)); - id = cu_get_str_path(ref, "InstanceID"); - if (id == NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Missing InstanceID"); - goto out; - } - - ret = sscanf(id, "%a[^:]:%as", &pfx, &name); - if (ret != 2) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Invalid InstanceID"); + if (!parse_instanceid(ref, NULL, &name)) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get system name"); goto out; } @@ -83,8 +71,6 @@ static CMPIStatus vssd_to_rasd(const CMP CMSetStatus(&s, CMPI_RC_OK); out: - free(id); - free(pfx); free(name); return s;

KR> +bool parse_instanceid(const CMPIObjectPath *ref, KR> + char **pfx, KR> + char **name) KR> +{ KR> + int ret; KR> + char *id = NULL; KR> + KR> + id = cu_get_str_path(ref, "InstanceID"); KR> + if (id == NULL) KR> + return false; KR> + KR> + ret = parse_id(id, pfx, name); KR> + if (!ret) KR> + return false; KR> + KR> + return true; KR> +} You leak "id" here :) -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1195148987 28800 # Node ID ae4810e6764b1ea14df6f429eab972593e919e37 # Parent e2459a1be808c519f2e22a6cc186bd8c9c9f7f12 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 e2459a1be808 -r ae4810e6764b Makefile.am --- a/Makefile.am Thu Nov 15 09:49:45 2007 -0800 +++ b/Makefile.am Thu Nov 15 09:49:47 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 e2459a1be808 -r ae4810e6764b schema/ElementSettingData.mof --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/ElementSettingData.mof Thu Nov 15 09:49:47 2007 -0800 @@ -0,0 +1,6 @@ +// Copyright IBM Corp. 2007 +class Xen_ElementSettingData : CIM_ElementSettingData { +}; + +class KVM_ElementSettingData : CIM_ElementSettingData { +}; diff -r e2459a1be808 -r ae4810e6764b schema/ElementSettingData.registration --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/ElementSettingData.registration Thu Nov 15 09:49:47 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 e2459a1be808 -r ae4810e6764b src/Makefile.am --- a/src/Makefile.am Thu Nov 15 09:49:45 2007 -0800 +++ b/src/Makefile.am Thu Nov 15 09:49:47 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 1195148985 28800 # Node ID e2459a1be808c519f2e22a6cc186bd8c9c9f7f12 # 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 e2459a1be808 src/Virt_ElementSettingData.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Virt_ElementSettingData.c Thu Nov 15 09:49:45 2007 -0800 @@ -0,0 +1,161 @@ +/* + * 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 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)); + + if (!parse_instanceid(ref, NULL, &host)) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get system name"); + 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); + free(host); + + 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; + uint16_t prop_value = 1; + + 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." + */ + CMSetProperty(refinst, "IsDefault", + (CMPIValue *)&prop_value, CMPI_uint16); + + CMSetProperty(refinst, "IsNext", + (CMPIValue *)&prop_value, CMPI_uint16); + + CMSetProperty(refinst, "IsMinimum", + (CMPIValue *)&prop_value, CMPI_uint16); + + CMSetProperty(refinst, "IsMaximum", + (CMPIValue *)&prop_value, CMPI_uint16); + } + +out: + free(base); + + 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: + */
participants (2)
-
Dan Smith
-
Kaitlin Rupert