[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] ioemu: fix flags in bdrv_open2


  • To: xen-devel@xxxxxxxxxxxxxxxxxxx
  • From: Wei Kong <weikong.cn@xxxxxxxxx>
  • Date: Mon, 1 Jun 2009 13:53:10 +0800
  • Cc: qemu-devel@xxxxxxxxxx
  • Delivery-date: Sun, 31 May 2009 22:53:44 -0700
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:cc:content-type; b=s2L9W4e+syNpLciMZsSzUA60y22vqcPo32UkoSuTYGu9zms5oALMhN+VH7QwUS9YTB HVAKjRcEjfebnNqoKg7/SeUZPBOILxNIkx1g7xdZazllJOL/9xA7Ui/u+roT6HM436ij /fJyybQAf8snwrRddpiClGcP+6uCT31CrKanQ=
  • List-id: Xen developer discussion <xen-devel.lists.xensource.com>

this patch against for qemu-0.10.5, it's also for xen unstable.

---
If BDRV_O_FILE not set in flags, it doesn't means O_RDWR, the O_RDONLY in flags should be useful.

Signed-off-by: Wei Kong <weikong.cn@gmail.com>

diff -uNrp qemu-0.10.5/block.c qemu-0.10.5.new/block.c
--- qemu-0.10.5/block.c 2009-05-21 04:46:58.000000000 +0800
+++ qemu-0.10.5.new/block.cÂÂÂÂ 2009-06-01 10:30:42.000000000 +0800
@@ -393,12 +393,13 @@ int bdrv_open2(BlockDriverState *bs, con
ÂÂÂÂ }
ÂÂÂÂ bs->drv = drv;
ÂÂÂÂ bs->opaque = qemu_mallocz(drv->instance_size);
-ÂÂÂ /* 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_CACHE_MASK);
+ÂÂÂÂÂÂÂ open_flags = flags & BDRV_O_CACHE_MASK;
ÂÂÂÂ 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 || ret == -EPERM) && !(flags & BDRV_O_FILE)) {
ÂÂÂÂÂÂÂÂ ret = drv->bdrv_open(bs, filename, open_flags & ~BDRV_O_RDWR);
diff -uNrp qemu-0.10.5/hw/usb-msd.c qemu-0.10.5.new/hw/usb-msd.c
--- qemu-0.10.5/hw/usb-msd.cÂÂÂ 2009-05-21 04:46:59.000000000 +0800
+++ qemu-0.10.5.new/hw/usb-msd.cÂÂÂÂÂÂÂ 2009-06-01 10:14:17.000000000 +0800
@@ -551,7 +551,7 @@ USBDevice *usb_msd_init(const char *file
ÂÂÂÂ s = qemu_mallocz(sizeof(MSDState));

ÂÂÂÂ bdrv = bdrv_new("usb");
-ÂÂÂ if (bdrv_open2(bdrv, filename, 0, drv) < 0)
+ÂÂÂ if (bdrv_open2(bdrv, filename, BDRV_O_RDWR, drv) < 0)
ÂÂÂÂÂÂÂÂ goto fail;
ÂÂÂÂ s->bs = bdrv;
ÂÂÂÂ *pbs = bdrv;
diff -uNrp qemu-0.10.5/qemu-img.c qemu-0.10.5.new/qemu-img.c
--- qemu-0.10.5/qemu-img.cÂÂÂÂÂ 2009-05-21 04:47:00.000000000 +0800
+++ qemu-0.10.5.new/qemu-img.c 2009-06-01 10:28:46.000000000 +0800
@@ -32,7 +32,7 @@
Â#endif

Â/* Default to cache=writeback as data integrity is not important for qemu-tcg. */
-#define BRDV_O_FLAGS BDRV_O_CACHE_WB
+#define BDRV_O_FLAGS BDRV_O_CACHE_WB

Âstatic void QEMU_NORETURN error(const char *fmt, ...)
Â{
@@ -185,7 +185,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;
@@ -201,7 +201,7 @@ static BlockDriverState *bdrv_new_open(c
ÂÂÂÂ } else {
ÂÂÂÂÂÂÂÂ drv = NULL;
ÂÂÂÂ }
-ÂÂÂ if (bdrv_open2(bs, filename, BRDV_O_FLAGS, drv) < 0) {
+ÂÂÂ if (bdrv_open2(bs, filename, flags, drv) < 0) {
ÂÂÂÂÂÂÂÂ error("Could not open '%s'", filename);
ÂÂÂÂ }
ÂÂÂÂ if (bdrv_is_encrypted(bs)) {
@@ -253,7 +253,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);
@@ -334,7 +334,7 @@ static int img_commit(int argc, char **a
ÂÂÂÂ } else {
ÂÂÂÂÂÂÂÂ drv = NULL;
ÂÂÂÂ }
-ÂÂÂ if (bdrv_open2(bs, filename, BRDV_O_FLAGS, drv) < 0) {
+ÂÂÂ if (bdrv_open2(bs, filename, BDRV_O_FLAGS|BDRV_O_RDWR, drv) < 0) {
ÂÂÂÂÂÂÂÂ error("Could not open '%s'", filename);
ÂÂÂÂ }
ÂÂÂÂ ret = bdrv_commit(bs);
@@ -457,7 +457,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_CACHE_WB|BDRV_O_RDONLY);
ÂÂÂÂÂÂÂÂ if (!bs[bs_i])
ÂÂÂÂÂÂÂÂÂÂÂÂ error("Could not open '%s'", argv[optind + bs_i]);
ÂÂÂÂÂÂÂÂ bdrv_get_geometry(bs[bs_i], &bs_sectors);
@@ -487,7 +488,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_CACHE_WB|BDRV_O_RDWR);

ÂÂÂÂ bs_i = 0;
ÂÂÂÂ bs_offset = 0;
@@ -710,7 +711,7 @@ static int img_info(int argc, char **arg
ÂÂÂÂ } else {
ÂÂÂÂÂÂÂÂ drv = NULL;
ÂÂÂÂ }
-ÂÂÂ if (bdrv_open2(bs, filename, BRDV_O_FLAGS, drv) < 0) {
+ÂÂÂ if (bdrv_open2(bs, filename, BDRV_O_FLAGS|BDRV_O_RDONLY, drv) < 0) {
ÂÂÂÂÂÂÂÂ error("Could not open '%s'", filename);
ÂÂÂÂ }
ÂÂÂÂ bdrv_get_format(bs, fmt_name, sizeof(fmt_name));
@@ -814,7 +815,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);
ÂÂÂÂ }


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.