[PATCH 0 of 3] Represent CDROM devices using DiskDrive class

# HG changeset patch # User Richard Maciel <rmaciel@linux.vnet.ibm.com> # Date 1239995297 10800 # Node ID c53de56e085d9ab893b5ef518dbcc4ccb9795531 # Parent 146ed7d63fbbc2edc78660ddc6ecc393ee61739c This patches changes the value of the constant representing LogicalDisk resource type from 17 to its correct value 31 Signed-off-by: Richard Maciel <rmaciel@linux.vnet.ibm.com> diff -r 146ed7d63fbb -r c53de56e085d src/svpc_types.h --- a/src/svpc_types.h Thu Apr 16 11:20:21 2009 -0700 +++ b/src/svpc_types.h Fri Apr 17 16:08:17 2009 -0300 @@ -26,7 +26,7 @@ #define CIM_RES_TYPE_PROC 3 #define CIM_RES_TYPE_MEM 4 #define CIM_RES_TYPE_NET 10 -#define CIM_RES_TYPE_DISK 17 +#define CIM_RES_TYPE_DISK 31 #define CIM_RES_TYPE_EMU 1 #define CIM_RES_TYPE_GRAPHICS 24 #define CIM_RES_TYPE_INPUT 13

# HG changeset patch # User Richard Maciel <rmaciel@linux.vnet.ibm.com> # Date 1238703532 10800 # Node ID 33c94f360449aa4324eb42d7a630b7959c36613c # Parent c53de56e085d9ab893b5ef518dbcc4ccb9795531 Add support for the DiskDrive class Signed-off-by: Richard Maciel <rmaciel@linux.vnet.ibm.com> diff -r c53de56e085d -r 33c94f360449 Makefile.am --- a/Makefile.am Fri Apr 17 16:08:17 2009 -0300 +++ b/Makefile.am Thu Apr 02 17:18:52 2009 -0300 @@ -55,7 +55,8 @@ schema/InputPool.mof \ schema/HostedAccessPoint.mof \ schema/ServiceAccessBySAP.mof \ - schema/SAPAvailableForElement.mof + schema/SAPAvailableForElement.mof \ + schema/DiskDrive.mof INTEROP_MOFS = \ schema/ComputerSystem.mof \ @@ -129,7 +130,8 @@ schema/InputPool.registration \ schema/HostedAccessPoint.registration \ schema/ServiceAccessBySAP.registration \ - schema/SAPAvailableForElement.registration + schema/SAPAvailableForElement.registration \ + schema/DiskDrive.registration INTEROP_REGS = \ schema/RegisteredProfile.registration \ diff -r c53de56e085d -r 33c94f360449 schema/DiskDrive.mof --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/DiskDrive.mof Thu Apr 02 17:18:52 2009 -0300 @@ -0,0 +1,29 @@ +// Copyright IBM Corp. 2009 + +[Description ( + "A class derived from CIM_DiskDrive to represent " + "the Xen DiskDrive on the system."), + Provider("cmpi::Virt_Device") +] +class Xen_DiskDrive : CIM_DiskDrive +{ +}; + +[Description ( + "A class derived from CIM_DiskDrive to represent " + "the KVM DiskDrive on the system."), + Provider("cmpi::Virt_Device") +] +class KVM_DiskDrive : CIM_DiskDrive +{ +}; + +[Description ( + "A class derived from CIM_DiskDrive to represent " + "the LXC DiskDrive on the system."), + Provider("cmpi::Virt_Device") +] +class LXC_DiskDrive : CIM_DiskDrive +{ +}; + diff -r c53de56e085d -r 33c94f360449 schema/DiskDrive.registration --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/DiskDrive.registration Thu Apr 02 17:18:52 2009 -0300 @@ -0,0 +1,5 @@ +# Copyright IBM Corp. 2007 +# Classname Namespace ProviderName ProviderModule ProviderTypes +Xen_DiskDrive root/virt Virt_Device Virt_Device instance +KVM_DiskDrive root/virt Virt_Device Virt_Device instance +LXC_DiskDrive root/virt Virt_Device Virt_Device instance

# HG changeset patch # User Richard Maciel <rmaciel@linux.vnet.ibm.com> # Date 1239995297 10800 # Node ID c2f18f10ab7eb1049998f8e1ae393fecd914910d # Parent 33c94f360449aa4324eb42d7a630b7959c36613c Add support for representing a cdrom device using the DiskDrive class Signed-off-by: Richard Maciel <rmaciel@linux.vnet.ibm.com> diff -r 33c94f360449 -r c2f18f10ab7e libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Thu Apr 02 17:18:52 2009 -0300 +++ b/libxkutil/device_parsing.c Fri Apr 17 16:08:17 2009 -0300 @@ -92,7 +92,8 @@ if (dev == NULL) return; /* free()-like semantics */ - if (dev->type == CIM_RES_TYPE_DISK) + if ((dev->type == CIM_RES_TYPE_DISK) || + (dev->type == CIM_RES_TYPE_DRIVE)) cleanup_disk_device(&dev->dev.disk); else if (dev->type == CIM_RES_TYPE_NET) cleanup_net_device(&dev->dev.net); @@ -254,7 +255,14 @@ if ((ddev->source == NULL) || (ddev->virtual_dev == NULL)) goto err; - vdev->type = CIM_RES_TYPE_DISK; + if (STREQ(ddev->device, "disk")) { + vdev->type = CIM_RES_TYPE_DISK; + } else if (STREQ(ddev->device, "cdrom")) { + vdev->type = CIM_RES_TYPE_DRIVE; + } else { + goto err; + } + vdev->id = strdup(ddev->virtual_dev); *vdevs = vdev; @@ -513,6 +521,57 @@ return true; } +static bool filter_list_by_type(int type, struct virt_device **list, int *size) +{ + struct virt_device *filtd_list = NULL; + struct virt_device *_list = NULL; + int filtd_count = 0; + int devlstidx = 0; + + filtd_list = calloc(*size, sizeof(**list)); + if (filtd_list == NULL) + goto err; + + /* To be valid, item from list must have the same type + * than the provided in type parameter + */ + for (devlstidx = 0; devlstidx < *size; devlstidx++) { + if (list[devlstidx]->type == type) { + CU_DEBUG("Item from list (id `%s') accepted by filter", + list[devlstidx]->id); + + memcpy(&filtd_list[filtd_count], + list[devlstidx], + sizeof(**list)); + + filtd_count++; + } + } + + CU_DEBUG("Number of filtered items: %d", filtd_count); + + _list = realloc(filtd_list, + filtd_count * sizeof(*filtd_list)); + + if (_list == NULL && filtd_count != 0) + goto err; + + free(*list); + + *list = _list; + + *size = filtd_count; + + return true; + + err: + free(filtd_list); + + CU_DEBUG("Error when filtering list"); + + return false; +} + static int do_parse(xmlNodeSet *nsv, int type, struct virt_device **l) { int devidx; @@ -525,7 +584,8 @@ /* point to correct parser function according to type */ if (type == CIM_RES_TYPE_NET) do_real_parse = &parse_net_device; - else if (type == CIM_RES_TYPE_DISK) + else if ((type == CIM_RES_TYPE_DISK) || + (type == CIM_RES_TYPE_DRIVE)) do_real_parse = &parse_disk_device; else if (type == CIM_RES_TYPE_PROC) do_real_parse = parse_vcpu_device; @@ -558,6 +618,15 @@ if (devices <= 0) continue; + if ((type == CIM_RES_TYPE_DISK) || + (type == CIM_RES_TYPE_DRIVE)) { + if (!filter_list_by_type(type, &tmp_list, &devices)) { + goto end; + } + if (devices == 0) + goto end; + } + if (!resize_devlist(&list, lstidx + devices)) { /* Skip these devices and try again for the * next cycle, which will probably fail, but @@ -595,7 +664,8 @@ if (type == CIM_RES_TYPE_NET) xpathstr = NET_XPATH; - else if (type == CIM_RES_TYPE_DISK) + else if ((type == CIM_RES_TYPE_DISK) || + (type == CIM_RES_TYPE_DRIVE)) xpathstr = DISK_XPATH; else if (type == CIM_RES_TYPE_PROC) xpathstr = VCPU_XPATH; diff -r 33c94f360449 -r c2f18f10ab7e src/Virt_Device.c --- a/src/Virt_Device.c Thu Apr 02 17:18:52 2009 -0300 +++ b/src/Virt_Device.c Fri Apr 17 16:08:17 2009 -0300 @@ -140,6 +140,26 @@ return inst; } +static CMPIInstance *drive_instance(const CMPIBroker *broker, + struct disk_device *dev, + const virDomainPtr dom, + const char *ns) +{ + CMPIInstance *inst; + virConnectPtr conn; + + conn = virDomainGetConnect(dom); + inst = get_typed_instance(broker, + pfx_from_conn(conn), + "DiskDrive", + ns); + + if (!disk_set_name(inst, dev)) + return NULL; + + return inst; +} + static int mem_set_size(CMPIInstance *instance, struct mem_device *dev) { @@ -440,6 +460,11 @@ &dev->dev.disk, dom, ns); + else if (dev->type == CIM_RES_TYPE_DRIVE) + instance = drive_instance(broker, + &dev->dev.disk, + dom, + ns); else if (dev->type == CIM_RES_TYPE_MEM) instance = mem_instance(broker, &dev->dev.mem, @@ -486,6 +511,8 @@ return CIM_RES_TYPE_NET; else if (strstr(classname, "LogicalDisk")) return CIM_RES_TYPE_DISK; + else if (strstr(classname, "DiskDrive")) + return CIM_RES_TYPE_DRIVE; else if (strstr(classname, "Memory")) return CIM_RES_TYPE_MEM; else if (strstr(classname, "Processor")) diff -r 33c94f360449 -r c2f18f10ab7e src/svpc_types.h --- a/src/svpc_types.h Thu Apr 02 17:18:52 2009 -0300 +++ b/src/svpc_types.h Fri Apr 17 16:08:17 2009 -0300 @@ -27,12 +27,13 @@ #define CIM_RES_TYPE_MEM 4 #define CIM_RES_TYPE_NET 10 #define CIM_RES_TYPE_DISK 31 +#define CIM_RES_TYPE_DRIVE 17 #define CIM_RES_TYPE_EMU 1 #define CIM_RES_TYPE_GRAPHICS 24 #define CIM_RES_TYPE_INPUT 13 #define CIM_RES_TYPE_UNKNOWN 1000 -#define CIM_RES_TYPE_COUNT 6 +#define CIM_RES_TYPE_COUNT 7 const static int cim_res_types[CIM_RES_TYPE_COUNT] = {CIM_RES_TYPE_NET, CIM_RES_TYPE_DISK, @@ -40,6 +41,7 @@ CIM_RES_TYPE_PROC, CIM_RES_TYPE_GRAPHICS, CIM_RES_TYPE_INPUT, + CIM_RES_TYPE_DRIVE, }; #define CIM_VSSD_RECOVERY_NONE 2

This set of changes breaks the behavior of several providers. Those issues need to be addressed and included in this patchset before it can be applied. Broken behavior: ElementAllocatedFromPool: -Can no longer associate a disk to the pool it was allocated from. -Can no longer associate a pool to the disks that have been allocated from it SettingsDefineCapabilities: Can no longer generate template RASDs for disk and cdrom devices DiskResourceAllocationSettingData: enum doesn't return instances for DiskDrives ResourceAllocationFromPool: Unable to associate DiskRASDs to pools or pools to DiskRASDs
+static CMPIInstance *drive_instance(const CMPIBroker *broker, + struct disk_device *dev, + const virDomainPtr dom, + const char *ns) +{ + CMPIInstance *inst; + virConnectPtr conn; + + conn = virDomainGetConnect(dom);
Need to check to see if conn is NULL. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Kaitlin Rupert
-
Richard Maciel