[PATCH] (#3) Fix device_parsing of processors

# HG changeset patch # User Jay Gagnon <grendel@linux.vnet.ibm.com> # Date 1208284430 14400 # Node ID f07c4d4649dfabce47957ca276b5227290bcbcae # Parent 01b0a24fc16f9daff19f3733552f223ddf6d7a18 (#3) Fix device_parsing of processors. Kaitlin discovered that my changes to device_parsing.c make it so we only get one Processor as well, not just one Proc RASD. This moves the flattening step up a little higher so that enumerating on Processor works correctly. It's not the prettiest approach to things, but I think given Processor's unique Device-RASD relationship it's a good compromise. I would of course be open to suggestions for making it a bit more elegant. Changes from 1 to 2: Fix xml_parse_test.c's print_dev_vcpu, and by "fix" I mean "fix, because once again I made a change that breaks it." Changes from 2 to 3: VirtualQuantity is supposed to be 64-bit, not 32. Signed-off-by: Jay Gagnon <grendel@linux.vnet.ibm.com> diff -r 01b0a24fc16f -r f07c4d4649df libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Mon Apr 14 15:17:08 2008 -0700 +++ b/libxkutil/device_parsing.c Tue Apr 15 14:33:50 2008 -0400 @@ -337,6 +337,7 @@ static int parse_vcpu_device(xmlNode *no struct virt_device *list = NULL; char *count_str; int count; + int i; count_str = get_node_content(node); if (count_str == NULL) @@ -346,15 +347,24 @@ static int parse_vcpu_device(xmlNode *no free(count_str); - list = calloc(1, sizeof(*list)); + list = calloc(count, sizeof(*list)); if (list == NULL) goto err; - - list->dev.vcpu.quantity = count; + + for (i = 0; i < count; i++) { + struct virt_device *vdev = &list[i]; + struct vcpu_device *cdev = &vdev->dev.vcpu; + + cdev->number = i; + + vdev->type = CIM_RES_TYPE_PROC; + if (asprintf(&vdev->id, "%i", i) == -1) + vdev->id = NULL; + } *vdevs = list; - return 1; + return count; err: free(list); @@ -610,7 +620,7 @@ struct virt_device *virt_device_dup(stru dev->dev.mem.size = _dev->dev.mem.size; dev->dev.mem.maxsize = _dev->dev.mem.maxsize; } else if (dev->type == CIM_RES_TYPE_PROC) { - dev->dev.vcpu.quantity = _dev->dev.vcpu.quantity; + dev->dev.vcpu.number = _dev->dev.vcpu.number; } else if (dev->type == CIM_RES_TYPE_EMU) { DUP_FIELD(dev, _dev, dev.emu.path); } else if (dev->type == CIM_RES_TYPE_GRAPHICS) { @@ -662,32 +672,6 @@ static int _get_mem_device(const char *x return 1; } -static int _get_proc_device(const char *xml, struct virt_device **list) -{ - struct virt_device *proc_devs = NULL; - struct virt_device *proc_dev = NULL; - int ret; - - ret = parse_devices(xml, &proc_devs, CIM_RES_TYPE_PROC); - if (ret <= 0) - return ret; - - proc_dev = malloc(sizeof(*proc_dev)); - if (proc_dev == NULL) - return 0; - - memset(proc_dev, 0, sizeof(*proc_dev)); - - proc_dev->type = CIM_RES_TYPE_PROC; - proc_dev->id = strdup("proc"); - proc_dev->dev.vcpu.quantity = proc_devs[0].dev.vcpu.quantity; - *list = proc_dev; - - cleanup_virt_devices(&proc_devs, ret); - - return 1; -}; - int get_devices(virDomainPtr dom, struct virt_device **list, int type) { char *xml; @@ -699,8 +683,6 @@ int get_devices(virDomainPtr dom, struct if (type == CIM_RES_TYPE_MEM) ret = _get_mem_device(xml, list); - else if (type == CIM_RES_TYPE_PROC) - ret = _get_proc_device(xml, list); else ret = parse_devices(xml, list, type); diff -r 01b0a24fc16f -r f07c4d4649df libxkutil/device_parsing.h --- a/libxkutil/device_parsing.h Mon Apr 14 15:17:08 2008 -0700 +++ b/libxkutil/device_parsing.h Tue Apr 15 14:33:50 2008 -0400 @@ -50,7 +50,7 @@ struct mem_device { }; struct vcpu_device { - uint32_t quantity; + uint64_t number; }; struct emu_device { diff -r 01b0a24fc16f -r f07c4d4649df libxkutil/xml_parse_test.c --- a/libxkutil/xml_parse_test.c Mon Apr 14 15:17:08 2008 -0700 +++ b/libxkutil/xml_parse_test.c Tue Apr 15 14:33:50 2008 -0400 @@ -18,10 +18,12 @@ static void print_u64(FILE *d, const cha fprintf(d, "%-15s: %" PRIu64 "\n", name, val); } +#if 0 static void print_u32(FILE *d, const char *name, uint32_t val) { fprintf(d, "%-15s: %" PRIu32 "\n", name, val); } +#endif static void print_os(struct domain *dom, FILE *d) @@ -94,7 +96,7 @@ static void print_dev_vcpu(struct virt_d static void print_dev_vcpu(struct virt_device *dev, FILE *d) { - print_u32(d, "Virtual CPUs", dev->dev.vcpu.quantity); + print_u64(d, "Virtual CPU", dev->dev.vcpu.number); } static void print_dev_emu(struct virt_device *dev, diff -r 01b0a24fc16f -r f07c4d4649df src/Virt_RASD.c --- a/src/Virt_RASD.c Mon Apr 14 15:17:08 2008 -0700 +++ b/src/Virt_RASD.c Tue Apr 15 14:33:50 2008 -0400 @@ -169,8 +169,10 @@ static CMPIInstance *rasd_from_vdev(cons CMSetProperty(inst, "Limit", (CMPIValue *)&dev->dev.mem.maxsize, CMPI_uint64); } else if (dev->type == CIM_RES_TYPE_PROC) { + /* This would be the place to set the virtualquantity. */ + uint64_t quantity = dev->dev.vcpu.number + 1; CMSetProperty(inst, "VirtualQuantity", - (CMPIValue *)&dev->dev.vcpu.quantity, CMPI_uint32); + (CMPIValue *)&quantity, CMPI_uint64); } /* FIXME: Put the HostResource in place */ @@ -343,6 +345,22 @@ static CMPIStatus _get_rasds(const CMPIB if (count <= 0) goto out; + /* Bit hackish, but for proc we need to cut list down to one. */ + if (type == CIM_RES_TYPE_PROC) { + struct virt_device *tmp_dev = NULL; + tmp_dev = calloc(1, sizeof(*tmp_dev)); + tmp_dev = virt_device_dup(&devs[count - 1]); + + tmp_dev->id = strdup("proc"); + + for (i = 0; i < count; i++) + cleanup_virt_device(&devs[i]); + + free(devs); + devs = tmp_dev; + count = 1; + } + for (i = 0; i < count; i++) { CMPIInstance *dev = NULL; const char *host = NULL;

Jay Gagnon wrote:
# HG changeset patch # User Jay Gagnon <grendel@linux.vnet.ibm.com> # Date 1208284430 14400 # Node ID f07c4d4649dfabce47957ca276b5227290bcbcae # Parent 01b0a24fc16f9daff19f3733552f223ddf6d7a18 (#3) Fix device_parsing of processors.
Kaitlin discovered that my changes to device_parsing.c make it so we only get one Processor as well, not just one Proc RASD. This moves the flattening step up a little higher so that enumerating on Processor works correctly. It's not the prettiest approach to things, but I think given Processor's unique Device-RASD relationship it's a good compromise. I would of course be open to suggestions for making it a bit more elegant.
Changes from 1 to 2: Fix xml_parse_test.c's print_dev_vcpu, and by "fix" I mean "fix, because once again I made a change that breaks it."
Changes from 2 to 3: VirtualQuantity is supposed to be 64-bit, not 32.
+1 Pegasus 2.7 is happy this time around. =) -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Jay Gagnon
-
Kaitlin Rupert