
# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1199827433 28800 # Node ID ebc8d09b3be6c1f1fe5b5a7ff865037298cd9f48 # Parent 3e5265023ddda5cfa24e7449c9f06bbd7dcaba5c Change behavior to get VCPU information from XML like other devices This is necessary for us to be able to show VCPU devices when a domain is offline. Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r 3e5265023ddd -r ebc8d09b3be6 libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Tue Jan 08 13:23:53 2008 -0800 +++ b/libxkutil/device_parsing.c Tue Jan 08 13:23:53 2008 -0800 @@ -36,6 +36,7 @@ #include "../src/svpc_types.h" #define DISK_XPATH (xmlChar *)"/domain/devices/disk" +#define VCPU_XPATH (xmlChar *)"/domain/vcpu" #define NET_XPATH (xmlChar *)"/domain/devices/interface" #define EMU_XPATH (xmlChar *)"/domain/devices/emulator" #define GRAPHICS_XPATH (xmlChar *)"/domain/devices/graphics" @@ -239,6 +240,45 @@ static int parse_net_device(xmlNode *ino return 0; } +static int parse_vcpu_device(xmlNode *node, struct virt_device **vdevs) +{ + struct virt_device *list = NULL; + char *count_str; + int count; + int i; + + count_str = get_node_content(node); + if (count_str == NULL) + count = 1; /* Default to 1 VCPU if non specified */ + else if (sscanf(count_str, "%i", &count) != 1) + count = 1; /* Default to 1 VCPU if garbage */ + + free(count_str); + + list = calloc(count, sizeof(*list)); + if (list == NULL) + goto err; + + for (i = 0; i < count; i++) { + struct virt_device *vdev = &list[i]; + struct vcpu_device *cdev = &vdev->dev.vcpu; + + cdev->number = i; + + vdev->type = VIRT_DEV_VCPU; + if (asprintf(&vdev->id, "%i", i) == -1) + vdev->id = NULL; + } + + *vdevs = list; + + return count; + err: + free(list); + + return 0; +} + static int parse_emu_device(xmlNode *node, struct virt_device **vdevs) { struct virt_device *vdev = NULL; @@ -322,6 +362,8 @@ static int do_parse(xmlNodeSet *nsv, int do_real_parse = &parse_net_device; else if (type == VIRT_DEV_DISK) do_real_parse = &parse_disk_device; + else if (type == VIRT_DEV_VCPU) + do_real_parse = parse_vcpu_device; else if (type == VIRT_DEV_EMU) do_real_parse = parse_emu_device; else if (type == VIRT_DEV_GRAPHICS) @@ -386,6 +428,8 @@ static int parse_devices(char *xml, stru xpathstr = NET_XPATH; else if (type == VIRT_DEV_DISK) xpathstr = DISK_XPATH; + else if (type == VIRT_DEV_VCPU) + xpathstr = VCPU_XPATH; else if (type == VIRT_DEV_EMU) xpathstr = EMU_XPATH; else if (type == VIRT_DEV_GRAPHICS) @@ -446,9 +490,6 @@ struct virt_device *virt_device_dup(stru dev->dev.mem.maxsize = _dev->dev.mem.maxsize; } else if (dev->type == VIRT_DEV_VCPU) { dev->dev.vcpu.number = _dev->dev.vcpu.number; - dev->dev.vcpu.state = _dev->dev.vcpu.state; - dev->dev.vcpu.cpuTime = _dev->dev.vcpu.cpuTime; - dev->dev.vcpu.cpu = _dev->dev.vcpu.cpu; } else if (dev->type == VIRT_DEV_EMU) { DUP_FIELD(dev, _dev, dev.emu.path); } else if (dev->type == VIRT_DEV_GRAPHICS) { @@ -573,42 +614,17 @@ int get_mem_devices(virDomainPtr dom, st int get_vcpu_devices(virDomainPtr dom, struct virt_device **list) { - int i, rc, ret, num_filled, num_vcpus; - virDomainInfo dom_info; - virVcpuInfoPtr vcpu_info = NULL; - struct virt_device *ret_list = NULL; - - rc = virDomainGetInfo(dom, &dom_info); - if (rc == -1) { - ret = -1; - goto out1; - } - - num_vcpus = dom_info.nrVirtCpu; - vcpu_info = calloc(num_vcpus, sizeof(virVcpuInfo)); - num_filled = virDomainGetVcpus(dom, vcpu_info, num_vcpus, NULL, 0); - if (num_vcpus != num_filled) { - ret = -1; - goto out2; - } - - ret_list = calloc(num_vcpus, sizeof(struct virt_device)); - for (i = 0; i < num_vcpus; i++) { - ret_list[i].type = VIRT_DEV_VCPU; - ret_list[i].dev.vcpu = vcpu_info[i]; - if (asprintf(&ret_list[i].id, "%d", - vcpu_info[i].number) == -1) { - ret = -1; - free(ret_list); - goto out2; - } - } - - ret = num_vcpus; - *list = ret_list; - out2: - free(vcpu_info); - out1: + char *xml; + int ret; + + xml = virDomainGetXMLDesc(dom, 0); + if (xml == NULL) + return 0; + + ret = parse_devices(xml, list, VIRT_DEV_VCPU); + + free(xml); + return ret; } diff -r 3e5265023ddd -r ebc8d09b3be6 libxkutil/device_parsing.h --- a/libxkutil/device_parsing.h Tue Jan 08 13:23:53 2008 -0800 +++ b/libxkutil/device_parsing.h Tue Jan 08 13:23:53 2008 -0800 @@ -49,6 +49,10 @@ struct mem_device { uint64_t maxsize; }; +struct vcpu_device { + uint32_t number; +}; + struct emu_device { char *path; }; @@ -72,7 +76,7 @@ struct virt_device { struct disk_device disk; struct net_device net; struct mem_device mem; - struct _virVcpuInfo vcpu; + struct vcpu_device vcpu; struct emu_device emu; struct graphics_device graphics; } dev; diff -r 3e5265023ddd -r ebc8d09b3be6 libxkutil/xml_parse_test.c --- a/libxkutil/xml_parse_test.c Tue Jan 08 13:23:53 2008 -0800 +++ b/libxkutil/xml_parse_test.c Tue Jan 08 13:23:53 2008 -0800 @@ -14,6 +14,11 @@ static void print_u64(FILE *d, const cha static void print_u64(FILE *d, const char *name, uint64_t val) { fprintf(d, "%-15s: %" PRIu64 "\n", name, val); +} + +static void print_u32(FILE *d, const char *name, uint32_t val) +{ + fprintf(d, "%-15s: %" PRIu32 "\n", name, val); } static void print_os(struct domain *dom, @@ -84,7 +89,7 @@ static void print_dev_vcpu(struct virt_d static void print_dev_vcpu(struct virt_device *dev, FILE *d) { - print_value(d, "Virtual CPU", "Present"); + print_u32(d, "Virtual CPU", dev->dev.vcpu.number); } static void print_dev_emu(struct virt_device *dev, diff -r 3e5265023ddd -r ebc8d09b3be6 libxkutil/xmlgen.c --- a/libxkutil/xmlgen.c Tue Jan 08 13:23:53 2008 -0800 +++ b/libxkutil/xmlgen.c Tue Jan 08 13:23:53 2008 -0800 @@ -163,7 +163,7 @@ static char *net_to_xml(struct net_devic return xml; } -static char *proc_to_xml(struct _virVcpuInfo *proc) +static char *proc_to_xml(struct vcpu_device *proc) { return strdup(""); } diff -r 3e5265023ddd -r ebc8d09b3be6 src/Virt_Device.c --- a/src/Virt_Device.c Tue Jan 08 13:23:53 2008 -0800 +++ b/src/Virt_Device.c Tue Jan 08 13:23:53 2008 -0800 @@ -187,7 +187,7 @@ static CMPIInstance *mem_instance(const } static CMPIInstance *vcpu_instance(const CMPIBroker *broker, - struct _virVcpuInfo *dev, + struct vcpu_device *dev, const virDomainPtr dom, const char *ns) {