[PATCH 0 of 6] #2 Add migration support

Changes: - Added VirtualSystemIsMigratableTo*() methods - Fixed up reported issues There is a blank migratable check still, and I still need to do the MigrationSettingData class, but I'd like to get this into the tree before I do.

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1196787212 28800 # Node ID 4a7e5f2cbb2301be1421491d1ba03870983af27f # Parent 32b2c8519573142f2b3176c40501b0ca0c305a7c Add VirtualSystemMigrationCapabilities Changes: - Fixed array size for async methods - Added sync methods Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r 32b2c8519573 -r 4a7e5f2cbb23 src/Virt_VSMigrationCapabilities.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Virt_VSMigrationCapabilities.c Tue Dec 04 08:53:32 2007 -0800 @@ -0,0 +1,192 @@ +/* + * Copyright IBM Corp. 2007 + * + * Authors: + * Dan Smith <danms@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 "misc_util.h" +#include "std_instance.h" + +#include "Virt_VSMigrationCapabilities.h" + +const static CMPIBroker *_BROKER; + +#define SVPC_MIG_MVSTH 2 +#define SVPC_MIG_MVSTS 3 +#define SVPC_MIG_CVSIMTH 4 +#define SVPC_MIG_CVSIMTS 5 + +static CMPIStatus set_method_properties(const CMPIBroker *broker, + CMPIInstance *inst) +{ + CMPIArray *array; + CMPIStatus s; + uint16_t val; + + array = CMNewArray(broker, 2, CMPI_INTEGER, &s); + if (s.rc != CMPI_RC_OK) + return s; + + val = SVPC_MIG_MVSTH; + CMSetArrayElementAt(array, 0, (CMPIValue *)&val, CMPI_uint16); + + val = SVPC_MIG_MVSTS; + CMSetArrayElementAt(array, 1, (CMPIValue *)&val, CMPI_uint16); + + CMSetProperty(inst, "AsynchronousMethodsSupported", + (CMPIValue *)&array, CMPI_ARRAY); + + + array = CMNewArray(broker, 2, CMPI_INTEGER, &s); + if (s.rc != CMPI_RC_OK) + return s; + + val = SVPC_MIG_CVSIMTH; + CMSetArrayElementAt(array, 0, (CMPIValue *)&val, CMPI_uint16); + + val = SVPC_MIG_CVSIMTS; + CMSetArrayElementAt(array, 1, (CMPIValue *)&val, CMPI_uint16); + + CMSetProperty(inst, "SynchronousMethodsSupported", + (CMPIValue *)&array, CMPI_ARRAY); + + CMSetStatus(&s, CMPI_RC_OK); + + return s; +} + +CMPIStatus get_migration_caps(const CMPIObjectPath *ref, + CMPIInstance **_inst, + const CMPIBroker *broker) +{ + CMPIInstance *inst; + CMPIStatus s; + + inst = get_typed_instance(broker, + CLASSNAME(ref), + "VirtualSystemMigrationCapabilities", + NAMESPACE(ref)); + if (inst == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Unable to get instance for %s", CLASSNAME(ref)); + return s; + } + + CMSetProperty(inst, "InstanceID", + (CMPIValue *)"MigrationCapabilities", CMPI_chars); + + s = set_method_properties(broker, inst); + + if (s.rc == CMPI_RC_OK) + *_inst = inst; + + return s; +} + +static CMPIStatus return_vsmc(const CMPIObjectPath *ref, + const CMPIResult *results, + bool name_only) +{ + CMPIInstance *inst; + CMPIStatus s; + + s = get_migration_caps(ref, &inst, _BROKER); + + 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_vsmc(ref, results, true); +} + +static CMPIStatus EnumInstances(CMPIInstanceMI *self, + const CMPIContext *context, + const CMPIResult *results, + const CMPIObjectPath *ref, + const char **properties) +{ + + return return_vsmc(ref, results, false); +} + + +static CMPIStatus GetInstance(CMPIInstanceMI *self, + const CMPIContext *context, + const CMPIResult *results, + const CMPIObjectPath *ref, + const char **properties) +{ + CMPIInstance *inst; + CMPIStatus s; + const char *prop; + + s = get_migration_caps(ref, &inst, _BROKER); + if (s.rc != CMPI_RC_OK) + return s; + + prop = cu_compare_ref(ref, inst); + if (prop != NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", prop); + } else { + CMReturnInstance(results, inst); + } + + return s; +} + +DEFAULT_CI(); +DEFAULT_MI(); +DEFAULT_DI(); +DEFAULT_EQ(); +DEFAULT_INST_CLEANUP(); + +STD_InstanceMIStub(, Virt_VSMC, + _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: + */ diff -r 32b2c8519573 -r 4a7e5f2cbb23 src/Virt_VSMigrationCapabilities.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Virt_VSMigrationCapabilities.h Tue Dec 04 08:53:32 2007 -0800 @@ -0,0 +1,35 @@ +/* + * Copyright IBM Corp. 2007 + * + * Authors: + * Dan Smith <danms@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 + */ + +CMPIStatus get_migration_caps(const CMPIObjectPath *reference, + CMPIInstance **_inst, + const CMPIBroker *broker); + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */ +

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1196787215 28800 # Node ID 853bc758cb198acef26fb916fa913108ef50a3f8 # Parent 4a7e5f2cbb2301be1421491d1ba03870983af27f Add VirtualSystemMigrationCapabilties build support Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r 4a7e5f2cbb23 -r 853bc758cb19 Makefile.am --- a/Makefile.am Tue Dec 04 08:53:32 2007 -0800 +++ b/Makefile.am Tue Dec 04 08:53:35 2007 -0800 @@ -33,7 +33,8 @@ MOFS = \ schema/ResourceAllocationFromPool.mof \ schema/ElementAllocatedFromPool.mof \ schema/HostedService.mof \ - schema/ElementSettingData.mof + schema/ElementSettingData.mof \ + schema/VSMigrationCapabilities.mof INTEROP_MOFS = \ schema/ComputerSystem.mof \ @@ -72,7 +73,8 @@ REGS = \ schema/ResourceAllocationFromPool.registration \ schema/ElementAllocatedFromPool.registration \ schema/HostedService.registration \ - schema/ElementSettingData.registration + schema/ElementSettingData.registration \ + schema/VSMigrationCapabilities.registration INTEROP_REGS = \ schema/RegisteredProfile.registration \ diff -r 4a7e5f2cbb23 -r 853bc758cb19 schema/VSMigrationCapabilities.mof --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/VSMigrationCapabilities.mof Tue Dec 04 08:53:35 2007 -0800 @@ -0,0 +1,17 @@ +// Copyright IBM Corp. 2007 + +class Virt_VirtualSystemMigrationCapabilities : CIM_Capabilities { + + uint16 DestinationHostFormatsSupported[]; + + uint16 SynchronousMethodsSupported[]; + + uint16 AsynchronousMethodsSupported[]; + +}; + +class Xen_VirtualSystemMigrationCapabilities : Virt_VirtualSystemMigrationCapabilities { +}; + +class KVM_VirtualSystemMigrationCapabilities : Virt_VirtualSystemMigrationCapabilities { +}; diff -r 4a7e5f2cbb23 -r 853bc758cb19 schema/VSMigrationCapabilities.registration --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/VSMigrationCapabilities.registration Tue Dec 04 08:53:35 2007 -0800 @@ -0,0 +1,4 @@ +# Copyright IBM Corp. 2007 +# Classname Namespace ProviderName ProviderModule ProviderTypes +Xen_VirtualSystemMigrationCapabilities root/virt Virt_VSMC Virt_VSMigrationCapabilities instance +KVM_VirtualSystemMigrationCapabilities root/virt Virt_VSMC Virt_VSMigrationCapabilities instance \ No newline at end of file diff -r 4a7e5f2cbb23 -r 853bc758cb19 src/Makefile.am --- a/src/Makefile.am Tue Dec 04 08:53:32 2007 -0800 +++ b/src/Makefile.am Tue Dec 04 08:53:35 2007 -0800 @@ -50,7 +50,8 @@ provider_LTLIBRARIES = libVirt_ComputerS libVirt_ResourceAllocationFromPool.la \ libVirt_ElementAllocatedFromPool.la \ libVirt_HostedService.la \ - libVirt_ElementSettingData.la + libVirt_ElementSettingData.la \ + libVirt_VSMigrationCapabilities.la libVirt_ComputerSystem_la_SOURCES = Virt_ComputerSystem.c libVirt_Device_la_SOURCES = Virt_Device.c @@ -138,3 +139,5 @@ libVirt_ElementSettingData_la_DEPENDENCI libVirt_ElementSettingData_la_DEPENDENCIES = libVirt_VSSD.la libVirt_RASD.la libVirt_ElementSettingData_la_SOURCES = Virt_ElementSettingData.c libVirt_ElementSettingData_la_LIBADD = -lVirt_VSSD -lVirt_RASD + +libVirt_VSMigrationCapabilities_la_SOURCES = Virt_VSMigrationCapabilities.c \ No newline at end of file

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1196787215 28800 # Node ID 58bd9f06204f69bbdbe3724cf45b845a58dedd4a # Parent 853bc758cb198acef26fb916fa913108ef50a3f8 Add build support for VirtualSystemMigrationService Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r 853bc758cb19 -r 58bd9f06204f Makefile.am --- a/Makefile.am Tue Dec 04 08:53:35 2007 -0800 +++ b/Makefile.am Tue Dec 04 08:53:35 2007 -0800 @@ -34,7 +34,8 @@ MOFS = \ schema/ElementAllocatedFromPool.mof \ schema/HostedService.mof \ schema/ElementSettingData.mof \ - schema/VSMigrationCapabilities.mof + schema/VSMigrationCapabilities.mof \ + schema/VSMigrationService.mof INTEROP_MOFS = \ schema/ComputerSystem.mof \ @@ -74,7 +75,8 @@ REGS = \ schema/ElementAllocatedFromPool.registration \ schema/HostedService.registration \ schema/ElementSettingData.registration \ - schema/VSMigrationCapabilities.registration + schema/VSMigrationCapabilities.registration \ + schema/VSMigrationService.registration INTEROP_REGS = \ schema/RegisteredProfile.registration \ diff -r 853bc758cb19 -r 58bd9f06204f schema/VSMigrationService.mof --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/VSMigrationService.mof Tue Dec 04 08:53:35 2007 -0800 @@ -0,0 +1,41 @@ +// Copyright IBM Corp. 2007 + +// Placeholder definition until schema is available upstream + +class CIM_VirtualSystemMigrationService : CIM_Service { + uint32 VirtualSystemIsMigratableToHost( + [Out] + CIM_ConcreteJob REF Job, + [In, EmbeddedInstance("CIM_ResourceAllocationSettingData")] + string NewResourceSettingData[], + [In, EmbeddedInstance("CIM_SettingData")] + string MigrationSettingData, + [In, EmbeddedInstance("CIM_VirtualSystemSettingData")] + string NewSystemSettingData, + [In] + CIM_ComputerSystem REF ComputerSystem, + [In] + string DestinationHost); + + uint32 MigrateVirtualSystemToHost( + [Out] + CIM_ConcreteJob REF Job, + [In, EmbeddedInstance("CIM_ResourceAllocationSettingData")] + string NewResourceSettingData[], + [In, EmbeddedInstance("CIM_SettingData")] + string MigrationSettingData, + [In, EmbeddedInstance("CIM_VirtualSystemSettingData")] + string NewSystemSettingData, + [In] + CIM_ComputerSystem REF ComputerSystem, + [In] + string DestinationHost); + +}; + +class Xen_VirtualSystemMigrationService : CIM_VirtualSystemMigrationService { +}; + +class KVM_VirtualSystemMigrationService : CIM_VirtualSystemMigrationService { +}; + diff -r 853bc758cb19 -r 58bd9f06204f schema/VSMigrationService.registration --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/VSMigrationService.registration Tue Dec 04 08:53:35 2007 -0800 @@ -0,0 +1,4 @@ +# Copyright IBM Corp. 2007 +# Classname Namespace ProviderName ProviderModule ProviderTypes +Xen_VirtualSystemMigrationService root/virt Virt_VSMigrationService Virt_VSMigrationService instance method +KVM_VirtualSystemMigrationService root/virt Virt_VSMigrationService Virt_VSMigrationService instance method \ No newline at end of file diff -r 853bc758cb19 -r 58bd9f06204f src/Makefile.am --- a/src/Makefile.am Tue Dec 04 08:53:35 2007 -0800 +++ b/src/Makefile.am Tue Dec 04 08:53:35 2007 -0800 @@ -51,7 +51,8 @@ provider_LTLIBRARIES = libVirt_ComputerS libVirt_ElementAllocatedFromPool.la \ libVirt_HostedService.la \ libVirt_ElementSettingData.la \ - libVirt_VSMigrationCapabilities.la + libVirt_VSMigrationCapabilities.la \ + libVirt_VSMigrationService.la libVirt_ComputerSystem_la_SOURCES = Virt_ComputerSystem.c libVirt_Device_la_SOURCES = Virt_Device.c @@ -140,4 +141,6 @@ libVirt_ElementSettingData_la_SOURCES = libVirt_ElementSettingData_la_SOURCES = Virt_ElementSettingData.c libVirt_ElementSettingData_la_LIBADD = -lVirt_VSSD -lVirt_RASD -libVirt_VSMigrationCapabilities_la_SOURCES = Virt_VSMigrationCapabilities.c \ No newline at end of file +libVirt_VSMigrationCapabilities_la_SOURCES = Virt_VSMigrationCapabilities.c + +libVirt_VSMigrationService_la_SOURCES = Virt_VSMigrationService.c \ No newline at end of file

Hi Dan, [...]
+ +// Placeholder definition until schema is available upstream + +class CIM_VirtualSystemMigrationService : CIM_Service { + uint32 VirtualSystemIsMigratableToHost(
That one is called 'CheckVirtualSystemIsMigratableToHost' upstream - although I like your shorted name better as 'Check' is already implied by the rest :-). Think I will comment as such to the author of that CR [1].
+ [Out] + CIM_ConcreteJob REF Job, + [In, EmbeddedInstance("CIM_ResourceAllocationSettingData")] + string NewResourceSettingData[], + [In, EmbeddedInstance("CIM_SettingData")] + string MigrationSettingData, + [In, EmbeddedInstance("CIM_VirtualSystemSettingData")] + string NewSystemSettingData, + [In] + CIM_ComputerSystem REF ComputerSystem, + [In] + string DestinationHost);
Method arguments have a different order in the CR.
+ + uint32 MigrateVirtualSystemToHost( + [Out] + CIM_ConcreteJob REF Job, + [In, EmbeddedInstance("CIM_ResourceAllocationSettingData")] + string NewResourceSettingData[], + [In, EmbeddedInstance("CIM_SettingData")] + string MigrationSettingData, + [In, EmbeddedInstance("CIM_VirtualSystemSettingData")] + string NewSystemSettingData, + [In] + CIM_ComputerSystem REF ComputerSystem, + [In] + string DestinationHost); + +};
Same comment. Cheers, Jim [1] http://www.dmtf.org/apps/org/workgroup/cim-core/download.php/32768/CIMCoreCR...

JF> That one is called 'CheckVirtualSystemIsMigratableToHost' upstream Ah, thanks Jim. I actually expect we will pull in a recent DMTF MOF to cover our inheritance here, so I was just putting something in place temporarily. I'll correct it though so it doesn't get overlooked. JF> - although I like your shorted name better as 'Check' is already JF> implied by the rest :-). Think I will comment as such to the JF> author of that CR [1]. No complaints here :) JF> Method arguments have a different order in the CR. I'll fix this as well when I put together my next round of migration patches. Thanks! -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1196787286 28800 # Node ID 058dc68a17d0303c8272f9b2c52916f783ba3ae8 # Parent 58bd9f06204f69bbdbe3724cf45b845a58dedd4a Add VirtualSystemMigrationService Changes: - Added rough IsMigratable support - Added method return code support - Fixed unnecessary status - Fixed conn instead of dconn in failure path Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r 58bd9f06204f -r 058dc68a17d0 src/Virt_VSMigrationService.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Virt_VSMigrationService.c Tue Dec 04 08:54:46 2007 -0800 @@ -0,0 +1,517 @@ +/* + * Copyright IBM Corp. 2007 + * + * Authors: + * Dan Smith <danms@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 <libvirt.h> + +#include <cmpidt.h> +#include <cmpift.h> +#include <cmpimacs.h> + +#include "libcmpiutil.h" +#include "misc_util.h" +#include "std_instance.h" +#include "std_invokemethod.h" + +#include "Virt_VSMigrationService.h" + +#define METHOD_RETURN(r, v) do { \ + uint32_t rc = v; \ + CMReturnData(r, (CMPIValue *)&rc, CMPI_uint32); \ + } while (0); + +const static CMPIBroker *_BROKER; + +static const char *transport_from_ref(const CMPIObjectPath *ref) +{ + const char *cn; + + cn = CLASSNAME(ref); + + if (STARTS_WITH(cn, "Xen")) + return "xen+ssh"; + else if (STARTS_WITH(cn, "KVM")) + return "qemu+ssh"; + else + return NULL; +} + +static char *dest_uri(const CMPIObjectPath *ref, + const char *dest) +{ + char *uri; + const char *tport = NULL; + + tport = transport_from_ref(ref); + if (tport == NULL) { + CU_DEBUG("Failed to get transport for %s", CLASSNAME(ref)); + return NULL; + } + + if (asprintf(&uri, "%s://%s/", tport, dest) == -1) + uri = NULL; + + return uri; +} + +static CMPIStatus check_caps(virConnectPtr conn, virConnectPtr dconn) +{ + return (CMPIStatus){CMPI_RC_OK, NULL}; +} + +static CMPIStatus check_hver(virConnectPtr conn, virConnectPtr dconn) +{ + CMPIStatus s; + unsigned long local; + unsigned long remote; + + if (virConnectGetVersion(conn, &local)) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get local Hypervisor version"); + goto out; + } + + if (virConnectGetVersion(dconn, &remote)) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get remote hypervisor version"); + goto out; + } + + if (remote >= local) { + CU_DEBUG("Version check OK (%lu >= %lu)", remote, local); + CMSetStatus(&s, CMPI_RC_OK); + } else { + CU_DEBUG("Version check FAILED (%lu < %lu)", remote, local); + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Remote hypervisor is older than local (%lu < %lu)", + remote, local); + } + + CMSetStatus(&s, CMPI_RC_OK); + + out: + return s; +} + +static CMPIStatus vs_migratable(const CMPIObjectPath *ref, + const char *domain, + const char *destination, + const CMPIResult *results) +{ + CMPIStatus s; + char *uri = NULL; + virConnectPtr conn = NULL; + virConnectPtr dconn = NULL; + uint32_t retcode = 1; + + uri = dest_uri(ref, destination); + if (uri == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to construct a valid libvirt URI"); + goto out; + } + + conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); + if (conn == NULL) + goto out; + + dconn = virConnectOpen(uri); + if (dconn == NULL) { + CU_DEBUG("Failed to connect to remote host (%s)", uri); + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to connect to remote host (%s)", uri); + goto out; + } + + s = check_hver(conn, dconn); + if (s.rc != CMPI_RC_OK) + goto out; + + s = check_caps(conn, dconn); + if (s.rc != CMPI_RC_OK) + goto out; + + retcode = 0; + CMSetStatus(&s, CMPI_RC_OK); + + out: + CMReturnData(results, (CMPIValue *)&retcode, CMPI_uint32); + + free(uri); + virConnectClose(conn); + virConnectClose(dconn); + + return s; +} + +static CMPIStatus vs_migratable_host(CMPIMethodMI *self, + const CMPIContext *ctx, + const CMPIResult *results, + const CMPIObjectPath *ref, + const CMPIArgs *argsin, + CMPIArgs *argsout) +{ + CMPIStatus s; + const char *dhost = NULL; + CMPIObjectPath *system; + const char *name = NULL; + + cu_get_str_arg(argsin, "DestinationHost", &dhost); + cu_get_ref_arg(argsin, "ComputerSystem", &system); + + if (cu_get_str_path(system, "Name", &name) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Missing key (Name) in ComputerSystem"); + METHOD_RETURN(results, 1); + return s; + } + + return vs_migratable(ref, name, dhost, results); +} + +static CMPIStatus vs_migratable_system(CMPIMethodMI *self, + const CMPIContext *ctx, + const CMPIResult *results, + const CMPIObjectPath *ref, + const CMPIArgs *argsin, + CMPIArgs *argsout) +{ + CMPIStatus s; + CMPIObjectPath *dsys; + CMPIObjectPath *sys; + const char *dname; + const char *name; + + cu_get_ref_arg(argsin, "DestinationSystem", &dsys); + cu_get_ref_arg(argsin, "ComputerSystem", &sys); + + if (cu_get_str_path(dsys, "Name", &dname) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Missing key (Name) in DestinationSystem"); + METHOD_RETURN(results, 1); + return s; + } + + if (cu_get_str_path(sys, "Name", &name) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Missing key (Name) in ComputerSystem"); + METHOD_RETURN(results, 1); + return s; + } + + return vs_migratable(ref, name, dname, results); +} + +static CMPIStatus migrate_vs(const CMPIObjectPath *ref, + const char *domain, + const char *destination, + const CMPIResult *results) +{ + CMPIStatus s; + virConnectPtr conn = NULL; + virConnectPtr dconn = NULL; + virDomainPtr dom = NULL; + virDomainPtr ddom = NULL; + char *uri = NULL; + uint32_t retcode = 1; + + uri = dest_uri(ref, destination); + if (uri == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to construct a valid libvirt URI"); + goto out; + } + + conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); + if (conn == NULL) + goto out; + + dom = virDomainLookupByName(conn, domain); + if (dom == NULL) { + CU_DEBUG("Failed to lookup `%s'", domain); + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to lookup domain `%s'", domain); + goto out; + } + + dconn = virConnectOpen(uri); + if (dconn == NULL) { + CU_DEBUG("Failed to connect to remote host (%s)", uri); + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to connect to remote host (%s)", uri); + goto out; + } + + CU_DEBUG("Migrating %s -> %s", domain, uri); + + ddom = virDomainMigrate(dom, dconn, VIR_MIGRATE_LIVE, NULL, NULL, 0); + if (ddom == NULL) { + CU_DEBUG("Migration failed"); + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Migration Failed"); + goto out; + } + + CU_DEBUG("Migration succeeded"); + retcode = 0; + CMSetStatus(&s, CMPI_RC_OK); + + out: + CMReturnData(results, (CMPIValue *)&retcode, CMPI_uint32); + + free(uri); + virDomainFree(dom); + virDomainFree(ddom); + virConnectClose(conn); + virConnectClose(dconn); + + return s; +} + +static CMPIStatus migrate_vs_host(CMPIMethodMI *self, + const CMPIContext *ctx, + const CMPIResult *results, + const CMPIObjectPath *ref, + const CMPIArgs *argsin, + CMPIArgs *argsout) +{ + CMPIStatus s; + const char *dhost = NULL; + CMPIObjectPath *system; + const char *name = NULL; + + cu_get_str_arg(argsin, "DestinationHost", &dhost); + cu_get_ref_arg(argsin, "ComputerSystem", &system); + + if (cu_get_str_path(system, "Name", &name) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Missing key (Name) in ComputerSystem"); + METHOD_RETURN(results, 1); + return s; + } + + return migrate_vs(ref, name, dhost, results); +} + +static CMPIStatus migrate_vs_system(CMPIMethodMI *self, + const CMPIContext *ctx, + const CMPIResult *results, + const CMPIObjectPath *ref, + const CMPIArgs *argsin, + CMPIArgs *argsout) +{ + CMPIStatus s; + CMPIObjectPath *dsys; + CMPIObjectPath *sys; + const char *dname; + const char *name; + + cu_get_ref_arg(argsin, "DestinationSystem", &dsys); + cu_get_ref_arg(argsin, "ComputerSystem", &sys); + + if (cu_get_str_path(dsys, "Name", &dname) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Missing key (Name) in DestinationSystem"); + METHOD_RETURN(results, 1); + return s; + } + + if (cu_get_str_path(sys, "Name", &name) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Missing key (Name) in ComputerSystem"); + METHOD_RETURN(results, 1); + return s; + } + + return migrate_vs(ref, name, dname, results); +} + +static struct method_handler vsimth = { + .name = "VirtualSystemIsMigratableToHost", + .handler = vs_migratable_host, + .args = {{"ComputerSystem", CMPI_ref}, + {"DestinationHost", CMPI_string}, + ARG_END + } +}; + +static struct method_handler vsimts = { + .name = "VirtualSystemIsMigratableToSystem", + .handler = vs_migratable_system, + .args = {{"ComputerSystem", CMPI_ref}, + {"DestinationSystem", CMPI_ref}, + ARG_END + } +}; + +static struct method_handler mvsth = { + .name = "MigrateVirtualSystemToHost", + .handler = migrate_vs_host, + .args = {{"ComputerSystem", CMPI_ref}, + {"DestinationHost", CMPI_string}, + ARG_END + } +}; + +static struct method_handler mvsts = { + .name = "MigrateVirtualSystemToSystem", + .handler = migrate_vs_system, + .args = {{"ComputerSystem", CMPI_ref}, + {"DestinationSystem", CMPI_ref}, + ARG_END + } +}; + +static struct method_handler *my_handlers[] = { + &vsimth, + &vsimts, + &mvsth, + &mvsts, + NULL +}; + +STDIM_MethodMIStub(, Virt_VSMigrationService, _BROKER, + libvirt_cim_init(), my_handlers); + +CMPIStatus get_migration_service(const CMPIObjectPath *ref, + CMPIInstance **_inst, + const CMPIBroker *broker) +{ + CMPIInstance *inst; + CMPIStatus s = {CMPI_RC_OK, NULL}; + + inst = get_typed_instance(broker, + CLASSNAME(ref), + "VirtualSystemMigrationService", + NAMESPACE(ref)); + if (inst == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Unable to get instance for %s", CLASSNAME(ref)); + return s; + } + + CMSetProperty(inst, "Name", + (CMPIValue *)"MigrationService", CMPI_chars); + + *_inst = inst; + + return s; +} + +static CMPIStatus return_vsms(const CMPIObjectPath *ref, + const CMPIResult *results, + bool name_only) +{ + CMPIInstance *inst; + CMPIStatus s; + + s = get_migration_service(ref, &inst, _BROKER); + 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_vsms(ref, results, true); +} + +static CMPIStatus EnumInstances(CMPIInstanceMI *self, + const CMPIContext *context, + const CMPIResult *results, + const CMPIObjectPath *ref, + const char **properties) +{ + + return return_vsms(ref, results, false); +} + + +static CMPIStatus GetInstance(CMPIInstanceMI *self, + const CMPIContext *context, + const CMPIResult *results, + const CMPIObjectPath *ref, + const char **properties) +{ + CMPIInstance *inst; + CMPIStatus s; + const char *prop; + + s = get_migration_service(ref, &inst, _BROKER); + if (s.rc != CMPI_RC_OK) + return s; + + prop = cu_compare_ref(ref, inst); + if (prop != NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", prop); + } else { + CMReturnInstance(results, inst); + } + + return s; +} + +DEFAULT_CI(); +DEFAULT_MI(); +DEFAULT_DI(); +DEFAULT_EQ(); +DEFAULT_INST_CLEANUP(); + +STD_InstanceMIStub(, Virt_VSMigrationService, + _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: + */ diff -r 58bd9f06204f -r 058dc68a17d0 src/Virt_VSMigrationService.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Virt_VSMigrationService.h Tue Dec 04 08:54:46 2007 -0800 @@ -0,0 +1,35 @@ +/* + * Copyright IBM Corp. 2007 + * + * Authors: + * Dan Smith <danms@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 + */ + +CMPIStatus get_migration_service(const CMPIObjectPath *reference, + CMPIInstance **_inst, + const CMPIBroker *broker); + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */ +

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1196787355 28800 # Node ID b71790bb1ff44e6cbd8eebf28caee6ce3c21a340 # Parent 058dc68a17d0303c8272f9b2c52916f783ba3ae8 Add HostedService support for VirtualSystemMigrationService Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r 058dc68a17d0 -r b71790bb1ff4 src/Makefile.am --- a/src/Makefile.am Tue Dec 04 08:54:46 2007 -0800 +++ b/src/Makefile.am Tue Dec 04 08:55:55 2007 -0800 @@ -133,9 +133,9 @@ libVirt_ElementAllocatedFromPool_la_SOUR libVirt_ElementAllocatedFromPool_la_SOURCES = Virt_ElementAllocatedFromPool.c libVirt_ElementAllocatedFromPool_la_LIBADD = -lVirt_DevicePool -lVirt_Device -libVirt_HostedService_la_DEPENDENCIES = libVirt_VirtualSystemManagementService.la libVirt_ResourcePoolConfigurationService.la +libVirt_HostedService_la_DEPENDENCIES = libVirt_VirtualSystemManagementService.la libVirt_ResourcePoolConfigurationService.la libVirt_VSMigrationService.la libVirt_HostedService_la_SOURCES = Virt_HostedService.c -libVirt_HostedService_la_LIBADD = -lVirt_VirtualSystemManagementService -lVirt_ResourcePoolConfigurationService +libVirt_HostedService_la_LIBADD = -lVirt_VirtualSystemManagementService -lVirt_ResourcePoolConfigurationService -lVirt_VSMigrationService libVirt_ElementSettingData_la_DEPENDENCIES = libVirt_VSSD.la libVirt_RASD.la libVirt_ElementSettingData_la_SOURCES = Virt_ElementSettingData.c diff -r 058dc68a17d0 -r b71790bb1ff4 src/Virt_HostedService.c --- a/src/Virt_HostedService.c Tue Dec 04 08:54:46 2007 -0800 +++ b/src/Virt_HostedService.c Tue Dec 04 08:55:55 2007 -0800 @@ -33,6 +33,7 @@ #include "Virt_HostSystem.h" #include "Virt_VirtualSystemManagementService.h" #include "Virt_ResourcePoolConfigurationService.h" +#include "Virt_VSMigrationService.h" const static CMPIBroker *_BROKER; @@ -72,6 +73,12 @@ static CMPIStatus host_to_service(const return s; if (!CMIsNullObject(inst)) inst_list_add(list, inst); + + s = get_migration_service(ref, &inst, _BROKER); + if (s.rc != CMPI_RC_OK) + return s; + if (!CMIsNullObject(inst)) + inst_list_add(list, inst); return s; } @@ -116,8 +123,10 @@ char* dependent[] = { char* dependent[] = { "Xen_ResourcePoolConfigurationService", "Xen_VirtualSystemManagementService", + "Xen_VirtualSystemMigrationService", "KVM_ResourcePoolConfigurationService", "KVM_VirtualSystemManagementService", + "KVM_VirtualSystemMigrationService", NULL };

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1196787356 28800 # Node ID bde7af5c35fa76a58a825817f181d2e6a08096ee # Parent b71790bb1ff44e6cbd8eebf28caee6ce3c21a340 Add ElementCapabilities support for VirtualSystemMigrationCapabilities Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r b71790bb1ff4 -r bde7af5c35fa src/Makefile.am --- a/src/Makefile.am Tue Dec 04 08:55:55 2007 -0800 +++ b/src/Makefile.am Tue Dec 04 08:55:56 2007 -0800 @@ -88,12 +88,13 @@ libVirt_ElementConformsToProfile_la_LIBA libVirt_EnabledLogicalElementCapabilities_la_SOURCES = Virt_EnabledLogicalElementCapabilities.c -libVirt_ElementCapabilities_la_DEPENDENCIES = libVirt_VirtualSystemManagementCapabilities.la libVirt_EnabledLogicalElementCapabilities.la libVirt_ComputerSystem.la libVirt_HostSystem.la +libVirt_ElementCapabilities_la_DEPENDENCIES = libVirt_VirtualSystemManagementCapabilities.la libVirt_EnabledLogicalElementCapabilities.la libVirt_ComputerSystem.la libVirt_HostSystem.la libVirt_VSMigrationCapabilities.la libVirt_ElementCapabilities_la_SOURCES = Virt_ElementCapabilities.c libVirt_ElementCapabilities_la_LIBADD = -lVirt_VirtualSystemManagementCapabilities \ -lVirt_EnabledLogicalElementCapabilities \ -lVirt_ComputerSystem \ - -lVirt_HostSystem + -lVirt_HostSystem \ + -lVirt_VSMigrationCapabilities libVirt_AllocationCapabilities_la_DEPENDENCIES = libVirt_RASD.la libVirt_DevicePool.la libVirt_AllocationCapabilities_la_SOURCES = Virt_AllocationCapabilities.c diff -r b71790bb1ff4 -r bde7af5c35fa src/Virt_ElementCapabilities.c --- a/src/Virt_ElementCapabilities.c Tue Dec 04 08:55:55 2007 -0800 +++ b/src/Virt_ElementCapabilities.c Tue Dec 04 08:55:56 2007 -0800 @@ -37,6 +37,7 @@ #include "Virt_EnabledLogicalElementCapabilities.h" #include "Virt_ComputerSystem.h" #include "Virt_HostSystem.h" +#include "Virt_VSMigrationCapabilities.h" /* Associate an XXX_Capabilities to the proper XXX_ManagedElement. * @@ -70,6 +71,11 @@ static CMPIStatus sys_to_cap(const CMPIO s = get_vsm_cap(_BROKER, ref, &inst); if (s.rc == CMPI_RC_OK) inst_list_add(list, inst); + + s = get_migration_caps(ref, &inst, _BROKER); + if (s.rc == CMPI_RC_OK) + inst_list_add(list, inst); + out: return s; } @@ -249,8 +255,10 @@ char* host_system[] = { char* virtual_system_management_capabilities[] = { "Xen_VirtualSystemManagementCapabilities", + "Xen_VirtualSystemMigrationCapabilities", "KVM_VirtualSystemManagementCapabilities", - NULL + "KVM_VirtualSystemMigrationCapabilities", + NULL, }; struct std_assoc system_to_vsm_cap = {

Dan Smith wrote:
Changes: - Added VirtualSystemIsMigratableTo*() methods - Fixed up reported issues
There is a blank migratable check still, and I still need to do the MigrationSettingData class, but I'd like to get this into the tree before I do.
I haven't had a chance to apply this patch and test, but it looks good from the read through. +1 -- Kaitlin Rupert IBM Linux Technology Center karupert@us.ibm.com
participants (3)
-
Dan Smith
-
Jim Fehlig
-
Kaitlin Rupert