[Libvirt-cim] [PATCH 1 of 2] Add container XML parsing support. Currently I only have examples of disk

Dan Smith danms at us.ibm.com
Tue Mar 25 20:45:09 UTC 2008


# HG changeset patch
# User Dan Smith <danms at 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 at 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;




More information about the Libvirt-cim mailing list