From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MB0SS-0000yp-0a for qemu-devel@nongnu.org; Mon, 01 Jun 2009 01:53:16 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MB0SR-0000yV-1R for qemu-devel@nongnu.org; Mon, 01 Jun 2009 01:53:15 -0400 Received: from [199.232.76.173] (port=44994 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MB0SQ-0000yS-Kn for qemu-devel@nongnu.org; Mon, 01 Jun 2009 01:53:14 -0400 Received: from qw-out-1920.google.com ([74.125.92.146]:61030) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MB0SP-0003gL-Tl for qemu-devel@nongnu.org; Mon, 01 Jun 2009 01:53:14 -0400 Received: by qw-out-1920.google.com with SMTP id 4so3758257qwk.4 for ; Sun, 31 May 2009 22:53:11 -0700 (PDT) MIME-Version: 1.0 Date: Mon, 1 Jun 2009 13:53:10 +0800 Message-ID: From: Wei Kong Content-Type: multipart/alternative; boundary=0016363b85b08d772f046b430a97 Subject: [Qemu-devel] [PATCH] ioemu: fix flags in bdrv_open2 List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: xen-devel@lists.xensource.com Cc: qemu-devel@nongnu.org --0016363b85b08d772f046b430a97 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 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); } --0016363b85b08d772f046b430a97 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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=C2=A0=C2=A0=C2=A0=C2=A0 2009-06-01 10:30:42.000000000 +0800
@@ -393,1= 2 +393,13 @@ int bdrv_open2(BlockDriverState *bs, con
=C2=A0=C2=A0=C2=A0=C2=A0 }
=C2=A0=C2=A0=C2=A0=C2=A0 bs->drv =3D drv;<= br>=C2=A0=C2=A0=C2=A0=C2=A0 bs->opaque =3D qemu_mallocz(drv->instance= _size);
-=C2=A0=C2=A0=C2=A0 /* Note: for compatibility, we open disk ima= ge files as RDWR, and
-=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 RDONLY as fa= llback */
=C2=A0=C2=A0=C2=A0=C2=A0 if (!(flags & BDRV_O_FILE))
-=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 open_flags =3D BDRV_O_RDWR | (f= lags & BDRV_O_CACHE_MASK);
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 open_flags =3D flags & BDRV_O_CACHE_MASK;
=C2=A0=C2=A0=C2=A0=C2= =A0 else
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 open_flags =3D= flags & ~(BDRV_O_FILE | BDRV_O_SNAPSHOT);
+=C2=A0=C2=A0=C2=A0 if (!= (open_flags & BDRV_O_RDWR))
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bs->read_only =3D 1;
+=C2=A0=C2=A0=C2=A0=C2=A0 ret =3D drv->bdrv_open(bs, filename, open_flag= s);
=C2=A0=C2=A0=C2=A0=C2=A0 if ((ret =3D=3D -EACCES || ret =3D=3D -EPER= M) && !(flags & BDRV_O_FILE)) {
=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 ret =3D drv->bdrv_open(bs, filename, open_flags &a= mp; ~BDRV_O_RDWR);
diff -uNrp qemu-0.10.5/hw/usb-msd.c qemu-0.10.5.new/hw/usb-msd.c
--- qem= u-0.10.5/hw/usb-msd.c=C2=A0=C2=A0=C2=A0 2009-05-21 04:46:59.000000000 +0800=
+++ qemu-0.10.5.new/hw/usb-msd.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 2009-06-01 10:14:17.000000000 +0800
@@ -551,7 +551,7 @@ USBDevice *u= sb_msd_init(const char *file
=C2=A0=C2=A0=C2=A0=C2=A0 s =3D qemu_mallocz(sizeof(MSDState));

=C2= =A0=C2=A0=C2=A0=C2=A0 bdrv =3D bdrv_new("usb");
-=C2=A0=C2=A0= =C2=A0 if (bdrv_open2(bdrv, filename, 0, drv) < 0)
+=C2=A0=C2=A0=C2= =A0 if (bdrv_open2(bdrv, filename, BDRV_O_RDWR, drv) < 0)
=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto fail;
=C2=A0=C2=A0=C2=A0=C2=A0 s->bs =3D bdrv;
=C2=A0=C2=A0=C2=A0=C2=A0 *pb= s =3D 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=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 2009-05-21 04:= 47:00.000000000 +0800
+++ qemu-0.10.5.new/qemu-img.c=C2=A0 2009-06-01 10= :28:46.000000000 +0800
@@ -32,7 +32,7 @@
=C2=A0#endif

=C2=A0/* Default to cache=3Dwriteb= ack 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

=C2= =A0static void QEMU_NORETURN error(const char *fmt, ...)
=C2=A0{
@@ -185,7 +185,7 @@ static int read_password(char *buf, int
= =C2=A0#endif

=C2=A0static BlockDriverState *bdrv_new_open(const char= *filename,
-=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 const char *fmt)
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const char *fmt, int flags= )
=C2=A0{
=C2=A0=C2=A0=C2=A0=C2=A0 BlockDriverState *bs;
=C2=A0=C2=A0= =C2=A0=C2=A0 BlockDriver *drv;
@@ -201,7 +201,7 @@ static BlockDriverSta= te *bdrv_new_open(c
=C2=A0=C2=A0=C2=A0=C2=A0 } else {
=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 drv =3D NULL;
=C2=A0=C2=A0=C2=A0=C2=A0= }
-=C2=A0=C2=A0=C2=A0 if (bdrv_open2(bs, filename, BRDV_O_FLAGS, drv) &= lt; 0) {
+=C2=A0=C2=A0=C2=A0 if (bdrv_open2(bs, filename, flags, drv) < 0) {
= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 error("Could not open= '%s'", filename);
=C2=A0=C2=A0=C2=A0=C2=A0 }
=C2=A0=C2= =A0=C2=A0=C2=A0 if (bdrv_is_encrypted(bs)) {
@@ -253,7 +253,7 @@ static = int img_create(int argc, char **a
=C2=A0=C2=A0=C2=A0=C2=A0 size =3D 0;
=C2=A0=C2=A0=C2=A0=C2=A0 if (base_f= ilename) {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 BlockDriverS= tate *bs;
-=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bs =3D bdrv_new_op= en(base_filename, NULL);
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bs = =3D bdrv_new_open(base_filename, NULL, BDRV_O_RDWR);
=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bdrv_get_geometry(bs, &size);
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 size *=3D 512;
=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bdrv_delete(bs);
@@ -334,7 +3= 34,7 @@ static int img_commit(int argc, char **a
=C2=A0=C2=A0=C2=A0=C2= =A0 } else {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 drv =3D NU= LL;
=C2=A0=C2=A0=C2=A0=C2=A0 }
-=C2=A0=C2=A0=C2=A0 if (bdrv_open2(bs,= filename, BRDV_O_FLAGS, drv) < 0) {
+=C2=A0=C2=A0=C2=A0 if (bdrv_open2(bs, filename, BDRV_O_FLAGS|BDRV_O_RDWR, = drv) < 0) {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 error(&q= uot;Could not open '%s'", filename);
=C2=A0=C2=A0=C2=A0=C2= =A0 }
=C2=A0=C2=A0=C2=A0=C2=A0 ret =3D bdrv_commit(bs);
@@ -457,7 +45= 7,8 @@ static int img_convert(int argc, char **

=C2=A0=C2=A0=C2=A0=C2=A0 total_sectors =3D 0;
=C2=A0=C2=A0=C2=A0=C2= =A0 for (bs_i =3D 0; bs_i < bs_n; bs_i++) {
-=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 bs[bs_i] =3D bdrv_new_open(argv[optind + bs_i], fmt);+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bs[bs_i] =3D bdrv_new_open(arg= v[optind + bs_i], fmt,
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 BDRV_O_CACHE_WB|BDRV_O_RDONLY);
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!bs[bs_i])
=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 error(&q= uot;Could not open '%s'", argv[optind + bs_i]);
=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bdrv_get_geometry(bs[bs_i], &bs= _sectors);
@@ -487,7 +488,7 @@ static int img_convert(int argc, char **<= br> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }
=C2=A0=C2=A0=C2=A0=C2= =A0 }

-=C2=A0=C2=A0=C2=A0 out_bs =3D bdrv_new_open(out_filename, out= _fmt);
+=C2=A0=C2=A0=C2=A0 out_bs =3D bdrv_new_open(out_filename, out_fm= t, BDRV_O_CACHE_WB|BDRV_O_RDWR);

=C2=A0=C2=A0=C2=A0=C2=A0 bs_i =3D 0= ;
=C2=A0=C2=A0=C2=A0=C2=A0 bs_offset =3D 0;
@@ -710,7 +711,7 @@ stati= c int img_info(int argc, char **arg
=C2=A0=C2=A0=C2=A0=C2=A0 } else {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 drv =3D NULL;
=C2=A0=C2=A0=C2=A0=C2=A0 }
-=C2=A0=C2=A0= =C2=A0 if (bdrv_open2(bs, filename, BRDV_O_FLAGS, drv) < 0) {
+=C2=A0= =C2=A0=C2=A0 if (bdrv_open2(bs, filename, BDRV_O_FLAGS|BDRV_O_RDONLY, drv) = < 0) {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 error("C= ould not open '%s'", filename);
=C2=A0=C2=A0=C2=A0=C2=A0 }
=C2=A0=C2=A0=C2=A0=C2=A0 bdrv_get_format(bs, = fmt_name, sizeof(fmt_name));
@@ -814,7 +815,7 @@ static void img_snapsho= t(int argc, char
=C2=A0=C2=A0=C2=A0=C2=A0 if (!bs)
=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 error("Not enough memory");
-=C2=A0=C2=A0=C2=A0 if (bdrv_open2(bs, filename, 0, NULL) < 0) {
+=C2=A0=C2=A0=C2=A0 if (bdrv_open2(bs, filename, BDRV_O_RDWR, NULL) < 0)= {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 error("Could no= t open '%s'", filename);
=C2=A0=C2=A0=C2=A0=C2=A0 }

=
--0016363b85b08d772f046b430a97--