[Libvirt-cim] [PATCH 4 of 5] Make disk devices detect dev= or file= as a flag for which to use

Dan Smith danms at us.ibm.com
Fri Jan 4 19:55:36 UTC 2008


# HG changeset patch
# User Dan Smith <danms at us.ibm.com>
# Date 1199480010 28800
# Node ID 389b558dcf738da99f2c23f87d62ea5255defd56
# Parent  6cd4300ae6a3509caec3a5076a6ccc498f06abcc
Make disk devices detect dev= or file= as a flag for which to use

Also make VSMS set the flag properly based on the mode of the path
we get in a RASD.

Signed-off-by: Dan Smith <danms at us.ibm.com>

diff -r 6cd4300ae6a3 -r 389b558dcf73 libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c	Fri Jan 04 12:53:30 2008 -0800
+++ b/libxkutil/device_parsing.c	Fri Jan 04 12:53:30 2008 -0800
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <sys/stat.h>
 #include <libxml/tree.h>
 #include <libxml/parser.h>
 #include <libxml/xpath.h>
@@ -149,11 +150,15 @@ static int parse_disk_device(xmlNode *dn
                                 goto err;
                 } else if (STREQ((char*)child->name, "source")) {
                         ddev->source = get_attr_value(child, "file");
-                        if (ddev->source)
+                        if (ddev->source) {
+                                ddev->disk_type = DISK_FILE;
                                 continue;
+                        }
                         ddev->source = get_attr_value(child, "dev");
-                        if (ddev->source)
+                        if (ddev->source) {
+                                ddev->disk_type = DISK_PHY;
                                 continue;
+                        }
                         goto err;
                 } else if (STREQ((char*)child->name, "target")) {
                         ddev->virtual_dev = get_attr_value(child, "dev");
@@ -825,6 +830,21 @@ int change_device(virDomainPtr dom, stru
         return 0;
 }
 
+int disk_type_from_file(const char *path)
+{
+        struct stat s;
+
+        if (stat(path, &s) < 0)
+                return DISK_UNKNOWN;
+
+        if (S_ISBLK(s.st_mode))
+                return DISK_PHY;
+        else if (S_ISREG(s.st_mode))
+                return DISK_FILE;
+        else
+                return DISK_UNKNOWN;
+}
+
 /*
  * Local Variables:
  * mode: C
diff -r 6cd4300ae6a3 -r 389b558dcf73 libxkutil/device_parsing.h
--- a/libxkutil/device_parsing.h	Fri Jan 04 12:53:30 2008 -0800
+++ b/libxkutil/device_parsing.h	Fri Jan 04 12:53:30 2008 -0800
@@ -35,6 +35,7 @@ struct disk_device {
         char *driver;
         char *source;
         char *virtual_dev;
+        enum {DISK_UNKNOWN, DISK_PHY, DISK_FILE} disk_type;
 };
 
 struct net_device {
@@ -126,6 +127,8 @@ struct domain {
 
 struct virt_device *virt_device_dup(struct virt_device *dev);
 
+int disk_type_from_file(const char *path);
+
 int get_dominfo(virDomainPtr dom, struct domain **dominfo);
 
 void cleanup_dominfo(struct domain **dominfo);
diff -r 6cd4300ae6a3 -r 389b558dcf73 libxkutil/xmlgen.c
--- a/libxkutil/xmlgen.c	Fri Jan 04 12:53:30 2008 -0800
+++ b/libxkutil/xmlgen.c	Fri Jan 04 12:53:30 2008 -0800
@@ -22,7 +22,6 @@
 #include <string.h>
 #include <stdlib.h>
 #include <inttypes.h>
-#include <sys/stat.h>
 #include <uuid/uuid.h>
 
 #include "xmlgen.h"
@@ -101,7 +100,6 @@ static char *disk_block_xml(const char *
 
         ret = asprintf(&xml,
                        "<disk type='block' device='disk'>\n"
-                       "  <driver name='phy'/>\n"
                        "  <source dev='%s'/>\n"
                        "  <target dev='%s'/>\n"
                        "</disk>\n",
@@ -120,7 +118,6 @@ static char *disk_file_xml(const char *p
 
         ret = asprintf(&xml,
                        "<disk type='file' device='disk'>\n"
-                       "  <driver name='tap' type='aio'/>\n"
                        "  <source file='%s'/>\n"
                        "  <target dev='%s'/>\n"
                        "</disk>\n",
@@ -134,17 +131,14 @@ static char *disk_file_xml(const char *p
 
 static char *disk_to_xml(struct disk_device *disk)
 {
-        struct stat s;
-
-        if (stat(disk->source, &s) < 0)
-                return NULL;
-
-        if (S_ISBLK(s.st_mode))
+        if (disk->disk_type == DISK_PHY)
                 return disk_block_xml(disk->source, disk->virtual_dev);
-        else
+        else if (disk->disk_type == DISK_FILE)
                 /* If it's not a block device, we assume a file,
                    which should be a reasonable fail-safe */
                 return disk_file_xml(disk->source, disk->virtual_dev);
+        else
+                return strdup("<!-- Unknown disk type -->\n");
 }
 
 static char *net_to_xml(struct net_device *net)
diff -r 6cd4300ae6a3 -r 389b558dcf73 src/Virt_VirtualSystemManagementService.c
--- a/src/Virt_VirtualSystemManagementService.c	Fri Jan 04 12:53:30 2008 -0800
+++ b/src/Virt_VirtualSystemManagementService.c	Fri Jan 04 12:53:30 2008 -0800
@@ -206,6 +206,7 @@ static int rasd_to_vdev(CMPIInstance *in
 
                 free(dev->dev.disk.source);
                 dev->dev.disk.source = strdup(val);
+                dev->dev.disk.disk_type = disk_type_from_file(val);
         } else if (type == VIRT_DEV_NET) {
                 free(dev->dev.net.mac);
                 dev->dev.net.mac = devid;




More information about the Libvirt-cim mailing list