[PATCH 0 of 2] #3 Add provider for VirtualSystemMigratonSettingData

This patchset adds support for the VirtualSystemMigrationSettingData provider. Updates: -(#3) Be sure to close the connection. -(#2) Add connect_by_classname() check.

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1202318299 28800 # Node ID cb802f02eb0d7de8d478d87703613d5e1319fd45 # Parent a64a399d1593d304c31ef146fd7661ef47d0619d Add new provider - VirtualSystemMigrationSettingData. Update from set 2 to set 3: -Be sure to close the connection Update from set 1 to set 2: -Add connect_by_classname() check. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r a64a399d1593 -r cb802f02eb0d src/Virt_VSMigrationSettingData.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Virt_VSMigrationSettingData.c Wed Feb 06 09:18:19 2008 -0800 @@ -0,0 +1,172 @@ +/* + * 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/libcmpiutil.h> +#include <libcmpiutil/std_instance.h> + +#include "misc_util.h" + +const static CMPIBroker *_BROKER; + +static CMPIStatus set_properties(const CMPIBroker *broker, + CMPIInstance *inst) +{ + CMPIStatus s; + uint16_t type = 3; /* Use live migration as default */ + uint16_t priority = 0; /* Use default priority */ + + CMSetProperty(inst, "MigrationType", + (CMPIValue *)&type, CMPI_uint16); + + CMSetProperty(inst, "Priority", + (CMPIValue *)&priority, CMPI_uint16); + + + CMSetStatus(&s, CMPI_RC_OK); + + return s; +} + +static CMPIStatus get_migration_sd(const CMPIObjectPath *ref, + CMPIInstance **_inst, + const CMPIBroker *broker, + bool is_get_inst) +{ + CMPIInstance *inst; + CMPIStatus s = {CMPI_RC_OK, NULL}; + virConnectPtr conn = NULL; + + conn = connect_by_classname(broker, CLASSNAME(ref), &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(ref), + "VirtualSystemMigrationSettingData", + NAMESPACE(ref)); + if (inst == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Unable to get instance for %s", CLASSNAME(ref)); + goto out; + } + + CMSetProperty(inst, "InstanceID", + (CMPIValue *)"MigrationSettingData", CMPI_chars); + + s = set_properties(broker, inst); + + if (s.rc != CMPI_RC_OK) + goto out; + + if (is_get_inst) { + s = cu_validate_ref(broker, ref, inst); + if (s.rc != CMPI_RC_OK) + goto out; + } + + *_inst = inst; + + out: + virConnectClose(conn); + + return s; +} + +static CMPIStatus return_vsmsd(const CMPIObjectPath *ref, + const CMPIResult *results, + bool name_only, + bool is_get_inst) +{ + CMPIInstance *inst = NULL; + CMPIStatus s; + + s = get_migration_sd(ref, &inst, _BROKER, is_get_inst); + + if (s.rc == CMPI_RC_OK) { + if (name_only) + cu_return_instance_name(results, inst); + else + CMReturnInstance(results, inst); + } + + return s; +} + +static CMPIStatus EnumInstanceNames(CMPIInstanceMI *self, + const CMPIContext *context, + const CMPIResult *results, + const CMPIObjectPath *ref) +{ + return return_vsmsd(ref, results, true, false); +} + +static CMPIStatus EnumInstances(CMPIInstanceMI *self, + const CMPIContext *context, + const CMPIResult *results, + const CMPIObjectPath *ref, + const char **properties) +{ + return return_vsmsd(ref, results, false, false); +} + + +static CMPIStatus GetInstance(CMPIInstanceMI *self, + const CMPIContext *context, + const CMPIResult *results, + const CMPIObjectPath *ref, + const char **properties) +{ + return return_vsmsd(ref, results, false, true); +} + +DEFAULT_CI(); +DEFAULT_MI(); +DEFAULT_DI(); +DEFAULT_EQ(); +DEFAULT_INST_CLEANUP(); + +STD_InstanceMIStub(, + Virt_VSMigrationSettingData, + _BROKER, + libvirt_cim_init()); + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */

Kaitlin Rupert wrote:
+static CMPIStatus return_vsmsd(const CMPIObjectPath *ref, + const CMPIResult *results, + bool name_only, + bool is_get_inst) +{ + CMPIInstance *inst = NULL; + CMPIStatus s; + + s = get_migration_sd(ref, &inst, _BROKER, is_get_inst);
This is seg faulting the provider for a request against Xen on a KVM only system (and reverse). The reason is that get_migration_sd() returns with OK but no instances for Xen. This inst==NULL seg faults the following returns.
+ + if (s.rc == CMPI_RC_OK) { + if (name_only) + cu_return_instance_name(results, inst); + else + CMReturnInstance(results, inst); + } + + return s; +} +
-- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor

Heidi Eckhart wrote:
Kaitlin Rupert wrote:
+static CMPIStatus return_vsmsd(const CMPIObjectPath *ref, + const CMPIResult *results, + bool name_only, + bool is_get_inst) +{ + CMPIInstance *inst = NULL; + CMPIStatus s; + + s = get_migration_sd(ref, &inst, _BROKER, is_get_inst);
This is seg faulting the provider for a request against Xen on a KVM only system (and reverse). The reason is that get_migration_sd() returns with OK but no instances for Xen. This inst==NULL seg faults the following returns.
Thanks Heidi - I thought I had tested for this, but I had tested incorrectly. I didn't have CMPIInstance *inst = NULL; in the previous patch, but I got compiler warnings this time around. I'll send a fix with a check for if ((s.rc == CMPI_RC_OK) && (inst != NULL)) since this is a case where we don't want to return an error if we cannot connect, but we also don't want to seg fault either. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1202318303 28800 # Node ID 8eb16e4040cd61d235aa8b34901f84b949adc080 # Parent cb802f02eb0d7de8d478d87703613d5e1319fd45 Add necessary pieces to build Virt_VSMigrationSettingData.c Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r cb802f02eb0d -r 8eb16e4040cd Makefile.am --- a/Makefile.am Wed Feb 06 09:18:19 2008 -0800 +++ b/Makefile.am Wed Feb 06 09:18:23 2008 -0800 @@ -36,7 +36,8 @@ MOFS = \ schema/HostedService.mof \ schema/ElementSettingData.mof \ schema/VSMigrationCapabilities.mof \ - schema/VSMigrationService.mof + schema/VSMigrationService.mof \ + schema/VSMigrationSettingData.mof INTEROP_MOFS = \ schema/ComputerSystem.mof \ @@ -79,7 +80,8 @@ REGS = \ schema/ElementSettingData.registration \ schema/VSMigrationCapabilities.registration \ schema/VSMigrationService.registration \ - schema/ElementConformsToProfile.registration + schema/ElementConformsToProfile.registration \ + schema/VSMigrationSettingData.registration INTEROP_REGS = \ schema/RegisteredProfile.registration \ @@ -112,3 +114,4 @@ clean-local: rm -f $(find . -name "*.orig") rm -f $(find . -name "*.rej") rm -f $(find . -name "*~") + diff -r cb802f02eb0d -r 8eb16e4040cd schema/VSMigrationSettingData.mof --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/VSMigrationSettingData.mof Wed Feb 06 09:18:23 2008 -0800 @@ -0,0 +1,15 @@ +// Copyright IBM Corp. 2007 + +class CIM_VirtualSystemMigrationSettingData : CIM_SettingData { + uint16 MigrationType; + + uint16 Priority; +}; + +[Provider("cmpi::Virt_VSMigrationSettingData")] +class Xen_VirtualSystemMigrationSettingData : CIM_VirtualSystemMigrationSettingData { +}; + +[Provider("cmpi::Virt_VSMigrationSettingData")] +class KVM_VirtualSystemMigrationSettingData : CIM_VirtualSystemMigrationSettingData { +}; diff -r cb802f02eb0d -r 8eb16e4040cd schema/VSMigrationSettingData.registration --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/VSMigrationSettingData.registration Wed Feb 06 09:18:23 2008 -0800 @@ -0,0 +1,4 @@ +# Copyright IBM Corp. 2007 +# Classname Namespace ProviderName ProviderModule ProviderTypes +Xen_VirtualSystemMigrationSettingData root/virt Virt_VSMigrationSettingData Virt_VSMigrationSettingData instance +KVM_VirtualSystemMigrationSettingData root/virt Virt_VSMigrationSettingData Virt_VSMigrationSettingData instance diff -r cb802f02eb0d -r 8eb16e4040cd src/Makefile.am --- a/src/Makefile.am Wed Feb 06 09:18:19 2008 -0800 +++ b/src/Makefile.am Wed Feb 06 09:18:23 2008 -0800 @@ -54,7 +54,8 @@ provider_LTLIBRARIES = libVirt_ComputerS libVirt_HostedService.la \ libVirt_ElementSettingData.la \ libVirt_VSMigrationCapabilities.la \ - libVirt_VSMigrationService.la + libVirt_VSMigrationService.la \ + libVirt_VSMigrationSettingData.la libVirt_ComputerSystem_la_SOURCES = Virt_ComputerSystem.c libVirt_Device_la_SOURCES = Virt_Device.c @@ -155,3 +156,5 @@ libVirt_VSMigrationService_la_SOURCES = libVirt_VSMigrationService_la_SOURCES = Virt_VSMigrationService.c libVirt_VSMigrationService_la_LIBADD = -lVirt_HostSystem +libVirt_VSMigrationSettingData_la_SOURCES = Virt_VSMigrationSettingData.c +
participants (2)
-
Heidi Eckhart
-
Kaitlin Rupert