[Libvirt-cim] [PATCH] [RFC]Added 2 end points for the ServiceAffectsElement association, both related to the LogicalDevice class

Richard Maciel richardm at br.ibm.com
Wed Dec 17 18:57:41 UTC 2008


# HG changeset patch
# User Richard Maciel <richardm at br.ibm.com>
# Date 1229540211 7200
# Node ID 71c3b10e7f36b00694fba35319fd7b356efbd0c8
# Parent  d0a4eae208b634a9814ec68384b2cea267604718
[RFC]Added 2 end points for the ServiceAffectsElement association, both related to the LogicalDevice class.

- ConsoleRedirectionService <-> DisplayController

- ConsoleRedirectionService <-> PointingDevice

Signed-off-by: Richard Maciel <richardm at br.ibm.com>

diff -r d0a4eae208b6 -r 71c3b10e7f36 src/Makefile.am
--- a/src/Makefile.am	Fri Dec 12 19:58:01 2008 -0200
+++ b/src/Makefile.am	Wed Dec 17 16:56:51 2008 -0200
@@ -213,9 +213,9 @@
 
 libVirt_ConsoleRedirectionServiceCapabilities_la_SOURCES = Virt_ConsoleRedirectionServiceCapabilities.c
 
-libVirt_ServiceAffectsElement_la_DEPENDENCIES = libVirt_ComputerSystem.la libVirt_ConsoleRedirectionService.la
+libVirt_ServiceAffectsElement_la_DEPENDENCIES = libVirt_ComputerSystem.la libVirt_Device.la libVirt_ConsoleRedirectionService.la 
 libVirt_ServiceAffectsElement_la_SOURCES = Virt_ServiceAffectsElement.c
-libVirt_ServiceAffectsElement_la_LIBADD = -lVirt_ComputerSystem -lVirt_ConsoleRedirectionService
+libVirt_ServiceAffectsElement_la_LIBADD = -lVirt_ComputerSystem -lVirt_Device -lVirt_ConsoleRedirectionService
 
 libVirt_KVMRedirectionSAP_la_SOURCES = Virt_KVMRedirectionSAP.c
 
diff -r d0a4eae208b6 -r 71c3b10e7f36 src/Virt_ServiceAffectsElement.c
--- a/src/Virt_ServiceAffectsElement.c	Fri Dec 12 19:58:01 2008 -0200
+++ b/src/Virt_ServiceAffectsElement.c	Wed Dec 17 16:56:51 2008 -0200
@@ -29,11 +29,45 @@
 #include <libcmpiutil/libcmpiutil.h>
 #include <libcmpiutil/std_association.h>
 #include "misc_util.h"
+#include "svpc_types.h"
 
 #include "Virt_ComputerSystem.h"
 #include "Virt_ConsoleRedirectionService.h"
+#include "Virt_Device.h"
 
 const static CMPIBroker *_BROKER;
+
+static CMPIStatus add_devices_to_list(const CMPIObjectPath *ref,
+                                          const char *host,
+                                          int type,
+                                          struct inst_list *list)
+{
+        CMPIStatus s = {CMPI_RC_OK, NULL};
+        struct inst_list temp_list;
+        int i, iret;
+
+        inst_list_init(&temp_list);
+        
+        s = enum_devices(_BROKER, ref, host, type, &temp_list);
+        
+        if (s.rc != CMPI_RC_OK)
+                goto out;
+
+        for (i = 0; i < temp_list.cur; i++) {
+                iret = inst_list_add(list, temp_list.list[i]);
+                if (!iret) {
+                        cu_statusf(_BROKER, &s,
+                                   CMPI_RC_ERR_FAILED,
+                                   "Not enough space to add device to list");
+                        goto out;
+                }
+        } 
+
+ out:
+        inst_list_free(&temp_list);
+        
+        return s;
+}
 
 static CMPIStatus service_to_cs(const CMPIObjectPath *ref,
                                 struct std_assoc_info *info,
@@ -41,15 +75,60 @@
 {
         CMPIStatus s = {CMPI_RC_OK, NULL};
         CMPIInstance *instance = NULL;
+        const char *host = NULL;
+        int i, num_of_domains;
 
+        
         if (!match_hypervisor_prefix(ref, info))
-                return s;
+                goto out;
 
         s = get_console_rs(ref, &instance, _BROKER, info->context, true);
         if (s.rc != CMPI_RC_OK)
-                return s;
+                goto out;
 
         s = enum_domains(_BROKER, ref, list);
+        if (s.rc != CMPI_RC_OK)
+                goto out;
+       
+        num_of_domains = list->cur;
+ 
+        // For each domain, insert its video and pointer devices into
+        // the list
+        for (i = 0; i < num_of_domains; i++) {
+                s.rc = cu_get_str_prop(list->list[i], "Name", &host);
+                if (s.rc != CMPI_RC_OK) 
+                        goto out;
+
+                s = add_devices_to_list(ref, host, CIM_RES_TYPE_INPUT, list);
+                if (s.rc != CMPI_RC_OK)
+                        goto out;
+
+                s = add_devices_to_list(ref, host, CIM_RES_TYPE_GRAPHICS, list);
+                if (s.rc != CMPI_RC_OK)
+                        goto out;
+        }
+
+ out:
+        return s;
+}
+
+static CMPIStatus validate_cs_or_dev_ref(const CMPIContext *context,
+                                         const CMPIObjectPath *ref)
+{
+         CMPIStatus s = {CMPI_RC_OK, NULL};
+        CMPIInstance *inst = NULL;
+        char* classname;
+                                  
+        classname = class_base_name(CLASSNAME(ref));
+
+        if (STREQC(classname, "ComputerSystem")) {
+                s = get_domain_by_ref(_BROKER, ref, &inst);
+        } else if ( (STREQC(classname, "PointingDevice"))  || 
+                    (STREQC(classname, "DisplayController")) ) {
+                s = get_device_by_ref(_BROKER, ref, &inst);        
+        }
+
+        free(classname);
 
         return s;
 }
@@ -63,8 +142,8 @@
 
         if (!match_hypervisor_prefix(ref, info))
                 return s;
-
-        s = get_domain_by_ref(_BROKER, ref, &inst);
+        
+        s = validate_cs_or_dev_ref(info->context, ref);
         if (s.rc != CMPI_RC_OK)
                 return s;
 
@@ -83,6 +162,12 @@
         "Xen_ComputerSystem",
         "KVM_ComputerSystem",
         "LXC_ComputerSystem",
+        "Xen_PointingDevice",
+        "KVM_PointingDevice",
+        "LXC_PointingDevice",
+        "Xen_DisplayController",
+        "KVM_DisplayController",
+        "LXC_DisplayController",
         NULL
 };
 




More information about the Libvirt-cim mailing list