File bdrv_open2_fix_flags.patch of Package xen
diff -uNrp xen-3.3.1-testing.orig/tools/ioemu-remote/block.c xen-3.3.1-testing/tools/ioemu-remote/block.c
--- xen-3.3.1-testing.orig/tools/ioemu-remote/block.c 2009-06-09 13:23:45.000000000 +0800
+++ xen-3.3.1-testing/tools/ioemu-remote/block.c 2009-06-09 13:30:20.000000000 +0800
@@ -367,7 +367,7 @@ int bdrv_file_open(BlockDriverState **pb
int bdrv_open(BlockDriverState *bs, const char *filename, int flags)
{
- return bdrv_open2(bs, filename, flags, NULL);
+ return bdrv_open2(bs, filename, flags | BDRV_O_RDWR, NULL);
}
int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
@@ -433,12 +433,13 @@ int bdrv_open2(BlockDriverState *bs, con
bs->total_sectors = 0; /* driver will set if it does not do getlength */
if (bs->opaque == NULL && drv->instance_size > 0)
return -1;
- /* Note: for compatibility, we open disk image files as RDWR, and
- RDONLY as fallback */
if (!(flags & BDRV_O_FILE))
- open_flags = BDRV_O_RDWR | (flags & BDRV_O_DIRECT);
+ open_flags = flags;
else
open_flags = flags & ~(BDRV_O_FILE | BDRV_O_SNAPSHOT);
+ if (!(open_flags & BDRV_O_RDWR))
+ bs->read_only = 1;
+
ret = drv->bdrv_open(bs, filename, open_flags);
if (ret == -EACCES && !(flags & BDRV_O_FILE)) {
ret = drv->bdrv_open(bs, filename, BDRV_O_RDONLY);
@@ -468,7 +469,7 @@ int bdrv_open2(BlockDriverState *bs, con
}
path_combine(backing_filename, sizeof(backing_filename),
filename, bs->backing_file);
- if (bdrv_open2(bs->backing_hd, backing_filename, 0, &bdrv_raw) < 0)
+ if (bdrv_open2(bs->backing_hd, backing_filename, open_flags, &bdrv_raw) < 0)
goto fail;
}
diff -uNrp xen-3.3.1-testing.orig/tools/ioemu-remote/hw/usb-msd.c xen-3.3.1-testing/tools/ioemu-remote/hw/usb-msd.c
--- xen-3.3.1-testing.orig/tools/ioemu-remote/hw/usb-msd.c 2009-06-09 13:23:45.000000000 +0800
+++ xen-3.3.1-testing/tools/ioemu-remote/hw/usb-msd.c 2009-06-09 13:24:36.000000000 +0800
@@ -523,7 +523,7 @@ USBDevice *usb_msd_init(const char *file
return NULL;
bdrv = bdrv_new("usb");
- if (bdrv_open2(bdrv, filename, 0, drv) < 0)
+ if (bdrv_open2(bdrv, filename, BDRV_O_RDWR, drv) < 0)
goto fail;
if (qemu_key_check(bdrv, filename))
goto fail;
diff -uNrp xen-3.3.1-testing.orig/tools/ioemu-remote/qemu-img.c xen-3.3.1-testing/tools/ioemu-remote/qemu-img.c
--- xen-3.3.1-testing.orig/tools/ioemu-remote/qemu-img.c 2009-06-09 13:23:45.000000000 +0800
+++ xen-3.3.1-testing/tools/ioemu-remote/qemu-img.c 2009-06-09 13:34:53.000000000 +0800
@@ -167,7 +167,7 @@ static int read_password(char *buf, int
#endif
static BlockDriverState *bdrv_new_open(const char *filename,
- const char *fmt)
+ const char *fmt, int flags)
{
BlockDriverState *bs;
BlockDriver *drv;
@@ -183,7 +183,7 @@ static BlockDriverState *bdrv_new_open(c
} else {
drv = NULL;
}
- if (bdrv_open2(bs, filename, 0, drv) < 0) {
+ if (bdrv_open2(bs, filename, flags, drv) < 0) {
error("Could not open '%s'", filename);
}
if (bdrv_is_encrypted(bs)) {
@@ -235,7 +235,7 @@ static int img_create(int argc, char **a
size = 0;
if (base_filename) {
BlockDriverState *bs;
- bs = bdrv_new_open(base_filename, NULL);
+ bs = bdrv_new_open(base_filename, NULL, BDRV_O_RDWR);
bdrv_get_geometry(bs, &size);
size *= 512;
bdrv_delete(bs);
@@ -314,7 +314,7 @@ static int img_commit(int argc, char **a
} else {
drv = NULL;
}
- if (bdrv_open2(bs, filename, 0, drv) < 0) {
+ if (bdrv_open2(bs, filename, BDRV_O_RDWR, drv) < 0) {
error("Could not open '%s'", filename);
}
ret = bdrv_commit(bs);
@@ -423,7 +423,8 @@ static int img_convert(int argc, char **
total_sectors = 0;
for (bs_i = 0; bs_i < bs_n; bs_i++) {
- bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt);
+ bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt,
+ BDRV_O_RDONLY);
if (!bs[bs_i])
error("Could not open '%s'", argv[optind + bs_i]);
bdrv_get_geometry(bs[bs_i], &bs_sectors);
@@ -451,7 +452,7 @@ static int img_convert(int argc, char **
}
}
- out_bs = bdrv_new_open(out_filename, out_fmt);
+ out_bs = bdrv_new_open(out_filename, out_fmt, BDRV_O_RDWR);
bs_i = 0;
bs_offset = 0;
@@ -657,7 +658,7 @@ static int img_info(int argc, char **arg
} else {
drv = NULL;
}
- if (bdrv_open2(bs, filename, 0, drv) < 0) {
+ if (bdrv_open2(bs, filename, BDRV_O_RDONLY, drv) < 0) {
error("Could not open '%s'", filename);
}
bdrv_get_format(bs, fmt_name, sizeof(fmt_name));
@@ -751,7 +752,7 @@ static void img_snapshot(int argc, char
if (!bs)
error("Not enough memory");
- if (bdrv_open2(bs, filename, 0, NULL) < 0) {
+ if (bdrv_open2(bs, filename, BDRV_O_RDWR, NULL) < 0) {
error("Could not open '%s'", filename);
}