[PATCH 0 of 2] Add beginnings of LXC XML parsing

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1206477801 25200 # Node ID b0e186e914481af381875b5f7465018bdb9fe1e1 # Parent 5b0c9449f1e59422f1e695a0da6b8f2c18a4ca43 Add container XML parsing support. Currently I only have examples of disk devices, so that's all we parse here. However, we now parse the container domain XML, as well as <filesystem> type devices as virt_dev_disk devices. This lets you enumerate LXC_LogicalDisk. All of the associations will need to be updated with the LXC variants before the relationships will work, but that should be all that is necessary. Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r 5b0c9449f1e5 -r b0e186e91448 libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Mon Mar 24 13:35:44 2008 -0700 +++ b/libxkutil/device_parsing.c Tue Mar 25 13:43:21 2008 -0700 @@ -36,7 +36,8 @@ #include "xmlgen.h" #include "../src/svpc_types.h" -#define DISK_XPATH (xmlChar *)"/domain/devices/disk" +#define DISK_XPATH (xmlChar *)"/domain/devices/disk | "\ + "/domain/devices/filesystem" #define VCPU_XPATH (xmlChar *)"/domain/vcpu" #define NET_XPATH (xmlChar *)"/domain/devices/interface" #define EMU_XPATH (xmlChar *)"/domain/devices/emulator" @@ -135,7 +136,63 @@ static char *get_node_content(xmlNode *n return buf; } -static int parse_disk_device(xmlNode *dnode, struct virt_device **vdevs) +static int parse_fs_device(xmlNode *dnode, struct virt_device **vdevs) +{ + struct virt_device *vdev = NULL; + struct disk_device *ddev = NULL; + xmlNode *child = NULL; + + vdev = calloc(1, sizeof(*vdev)); + if (vdev == NULL) + goto err; + + ddev = (&vdev->dev.disk); + + ddev->type = get_attr_value(dnode, "type"); + if (ddev->type == NULL) { + CU_DEBUG("No type"); + goto err; + } + + for (child = dnode->children; child != NULL; child = child->next) { + if (XSTREQ(child->name, "source")) { + ddev->source = get_attr_value(child, "dir"); + if (ddev->source == NULL) { + CU_DEBUG("No source dir"); + goto err; + } + } else if (XSTREQ(child->name, "target")) { + ddev->virtual_dev = get_attr_value(child, "dir"); + if (ddev->virtual_dev == NULL) { + CU_DEBUG("No target dir"); + goto err; + } + } + } + + if ((ddev->source == NULL) || (ddev->virtual_dev == NULL)) { + CU_DEBUG("S: %s D: %s", ddev->source, ddev->virtual_dev); + goto err; + } + + ddev->disk_type = DISK_FS; + + vdev->type = CIM_RES_TYPE_DISK; + vdev->id = strdup(ddev->virtual_dev); + + *vdevs = vdev; + + return 1; + + err: + CU_DEBUG("Error parsing fs"); + cleanup_disk_device(ddev); + free(vdev); + + return 0; +} + +static int parse_block_device(xmlNode *dnode, struct virt_device **vdevs) { struct virt_device *vdev = NULL; struct disk_device *ddev = NULL; @@ -195,6 +252,20 @@ static int parse_disk_device(xmlNode *dn return 0; } +static int parse_disk_device(xmlNode *dnode, struct virt_device **vdevs) +{ + CU_DEBUG("Disk node: %s", dnode->name); + + if (XSTREQ(dnode->name, "disk")) + return parse_block_device(dnode, vdevs); + else if (XSTREQ(dnode->name, "filesystem")) + return parse_fs_device(dnode, vdevs); + else { + CU_DEBUG("Unknown disk device: %s", dnode->name); + return 0; + } +} + static int parse_net_device(xmlNode *inode, struct virt_device **vdevs) { struct virt_device *vdev = NULL; @@ -668,6 +739,8 @@ static int parse_os(struct domain *domin else if (XSTREQ(child->name, "boot")) dominfo->os_info.fv.boot = get_attr_value(child, "dev"); + else if (XSTREQ(child->name, "init")) + STRPROP(dominfo, os_info.lxc.init, child); } if ((STREQC(dominfo->os_info.fv.type, "hvm")) && @@ -676,6 +749,8 @@ static int parse_os(struct domain *domin else if ((STREQC(dominfo->typestr, "kvm")) || (STREQC(dominfo->typestr, "qemu"))) dominfo->type = DOMAIN_KVM; + else if (STREQC(dominfo->typestr, "lxc")) + dominfo->type = DOMAIN_LXC; else if (STREQC(dominfo->os_info.pv.type, "linux")) dominfo->type = DOMAIN_XENPV; else @@ -836,6 +911,8 @@ void cleanup_dominfo(struct domain **dom free(dom->os_info.fv.type); free(dom->os_info.fv.loader); free(dom->os_info.fv.boot); + } else if (dom->type == DOMAIN_LXC) { + free(dom->os_info.lxc.init); } else { CU_DEBUG("Unknown domain type %i", dom->type); } diff -r 5b0c9449f1e5 -r b0e186e91448 libxkutil/device_parsing.h --- a/libxkutil/device_parsing.h Mon Mar 24 13:35:44 2008 -0700 +++ b/libxkutil/device_parsing.h Tue Mar 25 13:43:21 2008 -0700 @@ -35,7 +35,7 @@ struct disk_device { char *driver; char *source; char *virtual_dev; - enum {DISK_UNKNOWN, DISK_PHY, DISK_FILE} disk_type; + enum {DISK_UNKNOWN, DISK_PHY, DISK_FILE, DISK_FS} disk_type; }; struct net_device { @@ -88,8 +88,12 @@ struct fv_os_info { char *boot; }; +struct lxc_os_info { + char *init; +}; + struct domain { - enum { DOMAIN_XENPV, DOMAIN_XENFV, DOMAIN_KVM } type; + enum { DOMAIN_XENPV, DOMAIN_XENFV, DOMAIN_KVM, DOMAIN_LXC } type; char *name; char *typestr; /*xen, kvm, etc */ char *uuid; @@ -99,6 +103,7 @@ struct domain { union { struct pv_os_info pv; struct fv_os_info fv; + struct lxc_os_info lxc; } os_info; int on_poweroff;

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1206477901 25200 # Node ID c2b027700cb7a3075a9b9f56acd6d52cbd1f6fdf # Parent b0e186e914481af381875b5f7465018bdb9fe1e1 Make xml_parse_test work for LXC guests (for disk devices and system) Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r b0e186e91448 -r c2b027700cb7 libxkutil/xml_parse_test.c --- a/libxkutil/xml_parse_test.c Tue Mar 25 13:43:21 2008 -0700 +++ b/libxkutil/xml_parse_test.c Tue Mar 25 13:45:01 2008 -0700 @@ -44,6 +44,8 @@ static void print_os(struct domain *dom, print_value(d, "Type", dom->os_info.fv.type); print_value(d, "Loader", dom->os_info.fv.loader); print_value(d, "Boot", dom->os_info.fv.boot); + } else if (dom->type == DOMAIN_LXC) { + print_value(d, "Init", dom->os_info.lxc.init); } else { fprintf(d, "[ Unknown domain type %i ]\n", dom->type); }

Dan Smith wrote:
This set adds system and disk device parsing for LXC guests.
Code looks good, and I'll trust that you're using the xml right, for two reasons: one, you've done all the other xml stuff; two, no way I'm gonna try and figure that out if I don't have to. :) +1 -- -Jay

JG> Code looks good, and I'll trust that you're using the xml right, JG> for two reasons: one, you've done all the other xml stuff; two, no JG> way I'm gonna try and figure that out if I don't have to. :) Well, it's not easy to test in the full stack without a patched libvirt, and even still, it's not quite "there yet". However, the point of the tester tool is that you can test a static XML file, like the container description Dave posted on the libvirt list. Anyway, I've done that and it works. I'm sure that this will need plenty of refinement as libvirt gains more support :) -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com
participants (2)
-
Dan Smith
-
Jay Gagnon