File disk-rasd-emu-type.patch of Package libvirt-cim
# HG changeset patch
# User Dan Smith <danms@us.ibm.com>
# Date 1226005676 28800
# Node ID 049f0bb012190e680257d00463138391405a5c60
# Parent 9385e61cd401162bef9c44bc11f64ca349a41abf
Add an EmulatedType field to DiskRASD to select CDROM or Disk
This seems like a pretty reasonable way to do this, but comments are welcome.
I had initially planned to have a specific RASD type to represent a CDROM,
but I don't think that makes much sense, and is significantly more complex.
Adding this gives us a way to set and query the CDROM-ness of a disk, and
with the following patch, avoids dropping this qualifier from existing
configurations.
Signed-off-by: Dan Smith <danms@us.ibm.com>
Index: libvirt-cim-0.5.2/schema/ResourceAllocationSettingData.mof
===================================================================
--- libvirt-cim-0.5.2.orig/schema/ResourceAllocationSettingData.mof
+++ libvirt-cim-0.5.2/schema/ResourceAllocationSettingData.mof
@@ -21,6 +21,10 @@ class Xen_DiskResourceAllocationSettingD
[Description ("Device as seen by the guest")]
string VirtualDevice;
+ [Description ("Device emulation type"),
+ ValueMap {"0", "1"},
+ Values {"Disk", "CDROM"}]
+ uint16 EmulatedType;
};
[Description ("KVM virtual disk configuration"),
@@ -32,6 +36,10 @@ class KVM_DiskResourceAllocationSettingD
[Description ("Device as seen by the guest")]
string VirtualDevice;
+ [Description ("Device emulation type"),
+ ValueMap {"0", "1"},
+ Values {"Disk", "CDROM"}]
+ uint16 EmulatedType;
};
[Description ("LXC virtual disk configuration"),
Index: libvirt-cim-0.5.2/src/Virt_RASD.c
===================================================================
--- libvirt-cim-0.5.2.orig/src/Virt_RASD.c
+++ libvirt-cim-0.5.2/src/Virt_RASD.c
@@ -224,6 +224,7 @@ static CMPIStatus set_disk_rasd_params(c
CMPIInstance *inst)
{
uint64_t cap = 0;
+ uint16_t type;
CMPIStatus s = {CMPI_RC_OK, NULL};
get_vol_size(broker, ref, dev->dev.disk.source, &cap);
@@ -244,6 +245,20 @@ static CMPIStatus set_disk_rasd_params(c
(CMPIValue *)dev->dev.disk.source,
CMPI_chars);
+ /* There's not much we can do here if we don't recognize the type,
+ * so it seems that assuming 'disk' is a reasonable default
+ */
+ if ((dev->dev.disk.device != NULL) &&
+ STREQ(dev->dev.disk.device, "cdrom"))
+ type = VIRT_DISK_TYPE_CDROM;
+ else
+ type = VIRT_DISK_TYPE_DISK;
+
+ CMSetProperty(inst,
+ "EmulatedType",
+ (CMPIValue *)&type,
+ CMPI_uint16);
+
return s;
}
Index: libvirt-cim-0.5.2/src/Virt_RASD.h
===================================================================
--- libvirt-cim-0.5.2.orig/src/Virt_RASD.h
+++ libvirt-cim-0.5.2/src/Virt_RASD.h
@@ -23,6 +23,9 @@
#include "device_parsing.h"
+#define VIRT_DISK_TYPE_DISK 0
+#define VIRT_DISK_TYPE_CDROM 1
+
char *rasd_to_xml(CMPIInstance *rasd);
/**
Index: libvirt-cim-0.5.2/src/Virt_VirtualSystemManagementService.c
===================================================================
--- libvirt-cim-0.5.2.orig/src/Virt_VirtualSystemManagementService.c
+++ libvirt-cim-0.5.2/src/Virt_VirtualSystemManagementService.c
@@ -402,6 +402,7 @@ static const char *disk_rasd_to_vdev(CMP
struct virt_device *dev)
{
const char *val = NULL;
+ uint16_t type;
if (cu_get_str_prop(inst, "VirtualDevice", &val) != CMPI_RC_OK)
return "Missing `VirtualDevice' property";
@@ -416,6 +417,16 @@ static const char *disk_rasd_to_vdev(CMP
dev->dev.disk.source = strdup(val);
dev->dev.disk.disk_type = disk_type_from_file(val);
+ if (cu_get_u16_prop(inst, "EmulatedType", &type) != CMPI_RC_OK)
+ type = VIRT_DISK_TYPE_DISK;
+
+ if (type == VIRT_DISK_TYPE_DISK)
+ dev->dev.disk.device = strdup("disk");
+ else if (type == VIRT_DISK_TYPE_CDROM)
+ dev->dev.disk.device = strdup("cdrom");
+ else
+ return "Invalid value for EmulatedType";
+
free(dev->id);
dev->id = strdup(dev->dev.disk.virtual_dev);