# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1225992264 28800
# Node ID 9385e61cd401162bef9c44bc11f64ca349a41abf
# Parent 20af5ae5b01c308d2cfab62899b2dbcb8d186567
Avoid clobbering disk flags on redefine
This patch makes sure we track the shareable and readonly flags that can
be present in a disk device.
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r 20af5ae5b01c -r 9385e61cd401 libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c Wed Nov 05 08:00:07 2008 -0800
+++ b/libxkutil/device_parsing.c Thu Nov 06 09:24:24 2008 -0800
@@ -24,6 +24,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <inttypes.h>
#include <sys/stat.h>
#include <libxml/tree.h>
@@ -235,6 +236,10 @@
ddev->virtual_dev = get_attr_value(child, "dev");
if (ddev->virtual_dev == NULL)
goto err;
+ } else if (XSTREQ(child->name, "readonly")) {
+ ddev->readonly = true;
+ } else if (XSTREQ(child->name, "shareable")) {
+ ddev->shareable = true;
}
}
if ((ddev->source == NULL) || (ddev->virtual_dev == NULL))
@@ -619,6 +624,8 @@
DUP_FIELD(dev, _dev, dev.disk.driver);
DUP_FIELD(dev, _dev, dev.disk.source);
DUP_FIELD(dev, _dev, dev.disk.virtual_dev);
+ dev->dev.disk.readonly = dev->dev.disk.readonly;
+ dev->dev.disk.shareable = dev->dev.disk.shareable;
} else if (dev->type == CIM_RES_TYPE_MEM) {
dev->dev.mem.size = _dev->dev.mem.size;
dev->dev.mem.maxsize = _dev->dev.mem.maxsize;
diff -r 20af5ae5b01c -r 9385e61cd401 libxkutil/device_parsing.h
--- a/libxkutil/device_parsing.h Wed Nov 05 08:00:07 2008 -0800
+++ b/libxkutil/device_parsing.h Thu Nov 06 09:24:24 2008 -0800
@@ -25,6 +25,7 @@
#define __DEVICE_PARSING_H
#include <stdint.h>
+#include <stdbool.h>
#include <libvirt/libvirt.h>
#include "../src/svpc_types.h"
@@ -36,6 +37,8 @@
char *source;
char *virtual_dev;
enum {DISK_UNKNOWN, DISK_PHY, DISK_FILE, DISK_FS} disk_type;
+ bool readonly;
+ bool shareable;
};
struct net_device {
diff -r 20af5ae5b01c -r 9385e61cd401 libxkutil/xmlgen.c
--- a/libxkutil/xmlgen.c Wed Nov 05 08:00:07 2008 -0800
+++ b/libxkutil/xmlgen.c Thu Nov 06 09:24:24 2008 -0800
@@ -113,7 +113,7 @@
return 1;
}
-static char *disk_block_xml(const char *path, const char *vdev)
+static char *disk_block_xml(struct disk_device *dev)
{
char *xml;
int ret;
@@ -122,16 +122,20 @@
"<disk type='block'
device='disk'>\n"
" <source dev='%s'/>\n"
" <target dev='%s'/>\n"
+ "%s"
+ "%s"
"</disk>\n",
- path,
- vdev);
+ dev->source,
+ dev->virtual_dev,
+ dev->readonly ? "<readonly/>\n" :
"",
+ dev->shareable ? "<shareable/>\n" :
"");
if (ret == -1)
xml = NULL;
return xml;
}
-static char *disk_file_xml(const char *path, const char *vdev)
+static char *disk_file_xml(struct disk_device *dev)
{
char *xml;
int ret;
@@ -140,16 +144,20 @@
"<disk type='file'
device='disk'>\n"
" <source file='%s'/>\n"
" <target dev='%s'/>\n"
+ "%s"
+ "%s"
"</disk>\n",
- path,
- vdev);
+ dev->source,
+ dev->virtual_dev,
+ dev->readonly ? "<readonly/>" : "",
+ dev->shareable ? "<shareable/>" :
"");
if (ret == -1)
xml = NULL;
return xml;
}
-static char *disk_fs_xml(const char *path, const char *vdev)
+static char *disk_fs_xml(struct disk_device *dev)
{
char *xml;
int ret;
@@ -159,8 +167,8 @@
" <source dir='%s'/>\n"
" <target dir='%s'/>\n"
"</filesystem>\n",
- path,
- vdev);
+ dev->source,
+ dev->virtual_dev);
if (ret == -1)
xml = NULL;
@@ -173,13 +181,13 @@
struct disk_device *disk = &dev->dev.disk;
if (disk->disk_type == DISK_PHY)
- _xml = disk_block_xml(disk->source, disk->virtual_dev);
+ _xml = disk_block_xml(disk);
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 */
- _xml = disk_file_xml(disk->source, disk->virtual_dev);
+ _xml = disk_file_xml(disk);
else if (disk->disk_type == DISK_FS)
- _xml = disk_fs_xml(disk->source, disk->virtual_dev);
+ _xml = disk_fs_xml(disk);
else
return false;