[PATCH 0 of 3] Added HostedAccessPoint association (ComputerSystem <-> KVMRedirectionSAP)

It was necessary to change the return_console_sap function to make it return a inst_list type. The static keyword was removed to make it accessible from the association.

# HG changeset patch # User Richard Maciel <richardm@br.ibm.com> # Date 1227649453 7200 # Node ID 67c2a795a7e0fd9d0b6163b331e4375f3469f582 # Parent f21e9ebf0ad0573bf55be7c16a9d32a07d9ac899 * Created a new function in the Virt_KVMRedirectionSAP.c called enum_console_saps() that is responsible for returning a CMPIResult type containing the redirection saps * Function return_console_sap in Virt_KVMRedirectionSAP.c now only takes three arguments: the reference to the broker, the reference and a return argument that represent the list of redirection saps diff -r f21e9ebf0ad0 -r 67c2a795a7e0 src/Virt_KVMRedirectionSAP.c --- a/src/Virt_KVMRedirectionSAP.c Mon Nov 24 13:06:18 2008 -0800 +++ b/src/Virt_KVMRedirectionSAP.c Tue Nov 25 19:44:13 2008 -0200 @@ -241,26 +241,46 @@ return true; } -static CMPIStatus return_console_sap(const CMPIObjectPath *ref, - const CMPIResult *results, - bool names_only) +static CMPIStatus enum_console_saps(const CMPIObjectPath *ref, + const CMPIResult *results, + bool names_only) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + struct inst_list list; + + inst_list_init(&list); + + s = return_console_sap(_BROKER, ref, &list); + if (s.rc != CMPI_RC_OK) + goto out; + + if (names_only) + cu_return_instance_names(results, &list); + else + cu_return_instances(results, &list); + + out: + inst_list_free(&list); + return s; +} + +CMPIStatus return_console_sap(const CMPIBroker *broker, + const CMPIObjectPath *ref, + struct inst_list *list) { CMPIStatus s = {CMPI_RC_OK, NULL}; virConnectPtr conn; virDomainPtr *domain_list; struct domain *dominfo = NULL; - struct inst_list list; struct vnc_ports port_list; int count; int lport; int ret; int i; - conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); + conn = connect_by_classname(broker, CLASSNAME(ref), &s); if (conn == NULL) return s; - - inst_list_init(&list); port_list.list = NULL; port_list.max = 0; @@ -268,7 +288,7 @@ count = get_domain_list(conn, &domain_list); if (count < 0) { - cu_statusf(_BROKER, &s, + cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, "Failed to enumerate domains"); goto out; @@ -277,7 +297,7 @@ port_list.list = malloc(count * sizeof(struct vnc_port *)); if (port_list.list == NULL) { - cu_statusf(_BROKER, &s, + cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, "Unable to allocate guest port list"); goto out; @@ -286,7 +306,7 @@ for (i = 0; i < count; i++) { port_list.list[i] = malloc(sizeof(struct vnc_port)); if (port_list.list[i] == NULL) { - cu_statusf(_BROKER, &s, + cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, "Unable to allocate guest port list"); goto out; @@ -305,7 +325,7 @@ "%d", &lport); if (ret != 1) { - cu_statusf(_BROKER, &s, + cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, "Unable to guest's console port"); goto out; @@ -313,7 +333,7 @@ port_list.list[port_list.cur]->name = strdup(dominfo->name); if (port_list.list[port_list.cur]->name == NULL) { - cu_statusf(_BROKER, &s, + cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, "Unable to allocate string"); goto out; @@ -330,18 +350,12 @@ port_list.max = port_list.cur; port_list.cur = 0; - s = get_vnc_sessions(ref, conn, port_list, &list); + s = get_vnc_sessions(ref, conn, port_list, list); if (s.rc != CMPI_RC_OK) goto out; - if (names_only) - cu_return_instance_names(results, &list); - else - cu_return_instances(results, &list); - out: free(domain_list); - inst_list_free(&list); for (i = 0; i < count; i++) { free(port_list.list[i]->name); @@ -478,7 +492,7 @@ const CMPIResult *results, const CMPIObjectPath *reference) { - return return_console_sap(reference, results, true); + return enum_console_saps(reference, results, true); } static CMPIStatus EnumInstances(CMPIInstanceMI *self, @@ -488,7 +502,7 @@ const char **properties) { - return return_console_sap(reference, results, false); + return enum_console_saps(reference, results, false); } static CMPIStatus GetInstance(CMPIInstanceMI *self, diff -r f21e9ebf0ad0 -r 67c2a795a7e0 src/Virt_KVMRedirectionSAP.h --- a/src/Virt_KVMRedirectionSAP.h Mon Nov 24 13:06:18 2008 -0800 +++ b/src/Virt_KVMRedirectionSAP.h Tue Nov 25 19:44:13 2008 -0200 @@ -28,6 +28,10 @@ const CMPIObjectPath *reference, CMPIInstance **_inst); +CMPIStatus return_console_sap(const CMPIBroker *broker, + const CMPIObjectPath *ref, + struct inst_list *list); + /* * Local Variables: * mode: C

# HG changeset patch # User Richard Maciel <richardm@br.ibm.com> # Date 1227649513 7200 # Node ID 4e72a1e95996bfc7dbd4f33da5a565535c7a4b0e # Parent 67c2a795a7e0fd9d0b6163b331e4375f3469f582 * Added schema/HostedAccessPoint.mof (and .registration) to create and register the new associations * Changed Makefile.am to regiser HostedAccessPoint association diff -r 67c2a795a7e0 -r 4e72a1e95996 Makefile.am --- a/Makefile.am Tue Nov 25 19:44:13 2008 -0200 +++ b/Makefile.am Tue Nov 25 19:45:13 2008 -0200 @@ -51,7 +51,8 @@ schema/DisplayController.mof \ schema/PointingDevice.mof \ schema/GraphicsPool.mof \ - schema/InputPool.mof + schema/InputPool.mof \ + schema/HostedAccessPoint.mof INTEROP_MOFS = \ schema/ComputerSystem.mof \ @@ -117,7 +118,8 @@ schema/DisplayController.registration \ schema/PointingDevice.registration \ schema/GraphicsPool.registration \ - schema/InputPool.registration + schema/InputPool.registration \ + schema/HostedAccessPoint.registration INTEROP_REGS = \ schema/RegisteredProfile.registration \ diff -r 67c2a795a7e0 -r 4e72a1e95996 schema/HostedAccessPoint.mof --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/HostedAccessPoint.mof Tue Nov 25 19:45:13 2008 -0200 @@ -0,0 +1,22 @@ +// Copyright IBM Corp. 2007 + +[Association, + Provider("cmpi::Virt_HostedAccessPoint") +] +class Xen_HostedAccessPoint : CIM_HostedAccessPoint +{ +}; + +[Association, + Provider("cmpi::Virt_HostedAccessPoint") +] +class KVM_HostedAccessPoint : CIM_HostedAccessPoint +{ +}; + +[Association, + Provider("cmpi::Virt_HostedAccessPoint") +] +class LXC_HostedAccessPoint : CIM_HostedAccessPoint +{ +}; diff -r 67c2a795a7e0 -r 4e72a1e95996 schema/HostedAccessPoint.registration --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/HostedAccessPoint.registration Tue Nov 25 19:45:13 2008 -0200 @@ -0,0 +1,5 @@ +# Copyright IBM Corp. 2007 +# Classname Namespace ProviderName ProviderModule ProviderTypes +Xen_HostedAccessPoint root/virt Virt_HostedAccessPoint Virt_HostedAccessPoint association +KVM_HostedAccessPoint root/virt Virt_HostedAccessPoint Virt_HostedAccessPoint association +LXC_HostedAccessPoint root/virt Virt_HostedAccessPoint Virt_HostedAccessPoint association

# HG changeset patch # User Richard Maciel <richardm@br.ibm.com> # Date 1227649866 7200 # Node ID 26073731679da6e273bd55c8b99f835e402af98c # Parent 4e72a1e95996bfc7dbd4f33da5a565535c7a4b0e * Created Virt_HostedAccessPoint.c file * Changed src/Makefile.am file, so the libvirt build creates the libHostedAccessPoint.la library This patch implements the HostedAccessPoint association using the standard procedure. diff -r 4e72a1e95996 -r 26073731679d src/Makefile.am --- a/src/Makefile.am Tue Nov 25 19:45:13 2008 -0200 +++ b/src/Makefile.am Tue Nov 25 19:51:06 2008 -0200 @@ -72,7 +72,8 @@ libVirt_HostedService.la \ libVirt_ElementSettingData.la \ libVirt_ConcreteComponent.la \ - libVirt_ServiceAffectsElement.la + libVirt_ServiceAffectsElement.la \ + libVirt_HostedAccessPoint.la libVirt_ComputerSystem_la_SOURCES = Virt_ComputerSystem.c libVirt_ComputerSystem_la_DEPENDENCIES = libVirt_VirtualSystemSnapshotService.la @@ -216,3 +217,7 @@ libVirt_KVMRedirectionSAP_la_SOURCES = Virt_KVMRedirectionSAP.c +libVirt_HostedAccessPoint_la_DEPENDENCIES = libVirt_HostSystem.la libVirt_KVMRedirectionSAP.la +libVirt_HostedAccessPoint_la_SOURCES = Virt_HostedAccessPoint.c +libVirt_HostedAccessPoint_la_LIBADD = -lVirt_HostSystem -lVirt_KVMRedirectionSAP + diff -r 4e72a1e95996 -r 26073731679d src/Virt_HostedAccessPoint.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Virt_HostedAccessPoint.c Tue Nov 25 19:51:06 2008 -0200 @@ -0,0 +1,160 @@ +/* + * Copyright IBM Corp. 2008 + * + * Authors: + * Richard Maciel <richardm@br.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 <string.h> +#include <stdlib.h> +#include <stdio.h> +#include <stdbool.h> + +#include "cmpidt.h" +#include "cmpift.h" +#include "cmpimacs.h" + +#include <libcmpiutil/libcmpiutil.h> +#include <libcmpiutil/std_association.h> +#include "misc_util.h" + +#include "Virt_HostSystem.h" +#include "Virt_KVMRedirectionSAP.h" + +static const CMPIBroker *_BROKER; + +static CMPIStatus rsap_to_host(const CMPIObjectPath *ref, + struct std_assoc_info *info, + struct inst_list *list) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *instance = NULL; + + if (!match_hypervisor_prefix(ref, info)) + goto out; + + s = get_console_sap_by_ref(_BROKER, ref, &instance); + if (s.rc != CMPI_RC_OK) + goto out; + + s = get_host(_BROKER, info->context, ref, &instance, false); + if (s.rc == CMPI_RC_OK) + inst_list_add(list, instance); + + out: + return s; +} + + +static CMPIStatus host_to_rsap(const CMPIObjectPath *ref, + struct std_assoc_info *info, + struct inst_list *list) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *instance = NULL; + CMPIObjectPath *vref = NULL; + + if (!match_hypervisor_prefix(ref, info)) + goto out; + + s = get_host(_BROKER, info->context, ref, &instance, true); + if (s.rc != CMPI_RC_OK) + goto out; + + vref = convert_sblim_hostsystem(_BROKER, ref, info); + if (vref == NULL) + goto out; + + s = return_console_sap(_BROKER, vref, list); + + if (s.rc != CMPI_RC_OK) + goto out; + + out: + return s; +} + +LIBVIRT_CIM_DEFAULT_MAKEREF() + +static char* antecedent[] = { + "Xen_HostSystem", + "KVM_HostSystem", + "LXC_HostSystem", + "Linux_ComputerSystem", + NULL +}; + +static char* dependent[] = { + "Xen_KVMRedirectionSAP", + "KVM_KVMRedirectionSAP", + "LXC_KVMRedirectionSAP", + NULL +}; + +static char* assoc_classname[] = { + "Xen_HostedAccessPoint", + "KVM_HostedAccessPoint", + "LXC_HostedAccessPoint", + NULL +}; + +static struct std_assoc _host_to_rsap = { + .source_class = (char **)&antecedent, + .source_prop = "Antecedent", + + .target_class = (char **)&dependent, + .target_prop = "Dependent", + + .assoc_class = (char **)&assoc_classname, + + .handler = host_to_rsap, + .make_ref = make_ref +}; + +static struct std_assoc _rsap_to_host = { + .source_class = (char **)&dependent, + .source_prop = "Dependent", + + .target_class = (char **)&antecedent, + .target_prop = "Antecedent", + + .assoc_class = (char **)&assoc_classname, + + .handler = rsap_to_host, + .make_ref = make_ref +}; + +static struct std_assoc *handlers[] = { + &_host_to_rsap, + &_rsap_to_host, + NULL +}; + +STDA_AssocMIStub(, + Virt_HostedAccessPoint, + _BROKER, + libvirt_cim_init(), + handlers); + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */

Richard Maciel wrote:
# HG changeset patch # User Richard Maciel <richardm@br.ibm.com> # Date 1227649866 7200 # Node ID 26073731679da6e273bd55c8b99f835e402af98c # Parent 4e72a1e95996bfc7dbd4f33da5a565535c7a4b0e * Created Virt_HostedAccessPoint.c file * Changed src/Makefile.am file, so the libvirt build creates the libHostedAccessPoint.la library
This patch implements the HostedAccessPoint association using the standard procedure.
This association will return an error if the SBLIM base providers are used. You'll want to register the provider to the cimv2 namespace.
+static CMPIStatus host_to_rsap(const CMPIObjectPath *ref, + struct std_assoc_info *info, + struct inst_list *list) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *instance = NULL; + CMPIObjectPath *vref = NULL; + + if (!match_hypervisor_prefix(ref, info)) + goto out;
If the SBLIM providers are installed, the class prefix will be "Linux_" - so you'll need to do this check only if the classname doesn't start with "Linux_". Take a look at Virt_HostedDependency for how to support SBLIM host refs. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Kaitlin Rupert
-
Richard Maciel