File bdrv_open2_flags_2.patch of Package xen

Index: xen-3.3.1-testing/tools/ioemu-remote/hw/xen_blktap.c
===================================================================
--- xen-3.3.1-testing.orig/tools/ioemu-remote/hw/xen_blktap.c
+++ xen-3.3.1-testing/tools/ioemu-remote/hw/xen_blktap.c
@@ -229,6 +229,7 @@ static int open_disk(struct td_state *s,
 	BlockDriver* drv;
 	char* devname;
 	static int devnumber = 0;
+	int flags = readonly ? BDRV_O_RDONLY : BDRV_O_RDWR;
 	int i;
 
 	DPRINTF("Opening %s as blktap%d\n", path, devnumber);
@@ -251,7 +252,7 @@ static int open_disk(struct td_state *s,
 	DPRINTF("%s driver specified\n", drv ? drv->format_name : "No");
 
 	/* Open the image */
-	if (bdrv_open2(bs, path, 0, drv) != 0) {
+	if (bdrv_open2(bs, path, flags, drv) != 0) {
 		fprintf(stderr, "Could not open image file %s\n", path);
 		return -ENOMEM;
 	}
Index: xen-3.3.1-testing/tools/ioemu-remote/xenstore.c
===================================================================
--- xen-3.3.1-testing.orig/tools/ioemu-remote/xenstore.c
+++ xen-3.3.1-testing/tools/ioemu-remote/xenstore.c
@@ -63,7 +63,8 @@ static void insert_media(void *opaque)
     for (i = 0; i < MAX_DRIVES + 1; i++) {
         bs = drives_table[i].bdrv;
         if (media_filename[i] && bs && bs->filename[0] == '\0') {
-            bdrv_open2(bs, media_filename[i], 0, &bdrv_raw);
+            /* Temporary BDRV_O_RDWR */
+            bdrv_open2(bs, media_filename[i], BDRV_O_RDWR, &bdrv_raw);
             pstrcpy(bs->filename, sizeof(bs->filename), media_filename[i]);
             free(media_filename[i]);
             media_filename[i] = NULL;
@@ -154,9 +155,9 @@ void xenstore_parse_domain_config(int hv
 {
     char **e = NULL;
     char *buf = NULL, *path;
-    char *fpath = NULL, *bpath = NULL, *btype = NULL,
+    char *fpath = NULL, *bpath = NULL, *btype = NULL, *mode = NULL,
         *dev = NULL, *params = NULL, *type = NULL, *drv = NULL;
-    int i, j, any_hdN = 0, ret, is_tap;
+    int i, j, any_hdN = 0, ret, is_tap, flags;
     unsigned int len, num, hd_index, pci_devid = 0;
     BlockDriverState *bs;
     BlockDriver *format;
@@ -213,6 +214,7 @@ void xenstore_parse_domain_config(int hv
     }
         
     for (i = 0; i < num; i++) {
+        flags = 0; 
 	format = NULL; /* don't know what the format is yet */
 
         /* read the backend path */
@@ -301,6 +303,17 @@ void xenstore_parse_domain_config(int hv
 	    format = &bdrv_raw;
         }
 
+        /* read the mode of the device */
+        if (pasprintf(&buf, "%s/mode", bpath) == -1)
+            continue;
+        free(mode);
+        mode = xs_read(xsh, XBT_NULL, buf, &len);
+
+        if (!strcmp(mode, "r") || !strcmp(mode, "ro"))
+            flags |= BDRV_O_RDONLY;
+        if (!strcmp(mode, "w") || !strcmp(mode, "rw"))
+            flags |= BDRV_O_RDWR;
+
         /* 
          * check if device has a phantom vbd; the phantom is hooked
          * to the frontend device (for ease of cleanup), so lookup 
@@ -337,7 +350,7 @@ void xenstore_parse_domain_config(int hv
 #ifdef CONFIG_STUBDOM
         if (pasprintf(&buf, "%s/device/vbd/%s", path, e[i]) == -1)
             continue;
-	if (bdrv_open2(bs, buf, 0 /* snapshot */, &bdrv_vbd) == 0) {
+	if (bdrv_open2(bs, buf, flags, &bdrv_vbd) == 0) {
 	    pstrcpy(bs->filename, sizeof(bs->filename), params);
 	    continue;
 	}
@@ -368,7 +381,7 @@ void xenstore_parse_domain_config(int hv
 		}
 	    }
             pstrcpy(bs->filename, sizeof(bs->filename), params);
-            if (bdrv_open2(bs, params, 0 /* snapshot */, format) < 0) {
+            if (bdrv_open2(bs, params, flags, format) < 0) {
                 fprintf(stderr, "qemu: could not open vbd '%s' or hard disk image '%s' (drv '%s' format '%s')\n", buf, params, drv ? drv : "?", format ? format->format_name : "0");
             } else {
                 char* snapshot = get_snapshot_name(atoi(e[i]));
openSUSE Build Service is sponsored by