Re: [Qemu-devel] [PATCH v13 04/20] qemu-img: Add --unsafe-read option to subcommands

2017-04-20 Thread Fam Zheng
On Thu, 04/20 12:20, Kevin Wolf wrote:
> Am 20.04.2017 um 09:52 hat Fam Zheng geschrieben:
> > Signed-off-by: Fam Zheng 
> 
> This one conflicts with my block-next branch, probably Peter's
> simplification of img_convert().

Probably, thanks for pointing out. I've tried to resolve it and it's
straightforward. I'll send v14 basing off your block-next, once you've done
reviewing.

For now, the rebased branch, including the two small fixes, is pushed to my
github branch:

git://github.com/famz/qemu.git image-lock

Fam



Re: [Qemu-devel] [PATCH v13 04/20] qemu-img: Add --unsafe-read option to subcommands

2017-04-20 Thread Kevin Wolf
Am 20.04.2017 um 09:52 hat Fam Zheng geschrieben:
> Signed-off-by: Fam Zheng 

This one conflicts with my block-next branch, probably Peter's
simplification of img_convert().

Kevin



[Qemu-devel] [PATCH v13 04/20] qemu-img: Add --unsafe-read option to subcommands

2017-04-20 Thread Fam Zheng
Signed-off-by: Fam Zheng 
---
 qemu-img.c | 148 +++--
 1 file changed, 114 insertions(+), 34 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index b220cf7..b9dcd3e 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -283,12 +283,15 @@ static int img_open_password(BlockBackend *blk, const 
char *filename,
 
 static BlockBackend *img_open_opts(const char *optstr,
QemuOpts *opts, int flags, bool 
writethrough,
-   bool quiet)
+   bool quiet, bool unsafe)
 {
 QDict *options;
 Error *local_err = NULL;
 BlockBackend *blk;
 options = qemu_opts_to_qdict(opts, NULL);
+if (unsafe) {
+flags |= BDRV_O_UNSAFE_READ;
+}
 blk = blk_new_open(NULL, NULL, options, flags, _err);
 if (!blk) {
 error_reportf_err(local_err, "Could not open '%s': ", optstr);
@@ -305,7 +308,7 @@ static BlockBackend *img_open_opts(const char *optstr,
 
 static BlockBackend *img_open_file(const char *filename,
const char *fmt, int flags,
-   bool writethrough, bool quiet)
+   bool writethrough, bool quiet, bool unsafe)
 {
 BlockBackend *blk;
 Error *local_err = NULL;
@@ -316,6 +319,9 @@ static BlockBackend *img_open_file(const char *filename,
 qdict_put(options, "driver", qstring_from_str(fmt));
 }
 
+if (unsafe) {
+flags |= BDRV_O_UNSAFE_READ;
+}
 blk = blk_new_open(filename, NULL, options, flags, _err);
 if (!blk) {
 error_reportf_err(local_err, "Could not open '%s': ", filename);
@@ -334,7 +340,7 @@ static BlockBackend *img_open_file(const char *filename,
 static BlockBackend *img_open(bool image_opts,
   const char *filename,
   const char *fmt, int flags, bool writethrough,
-  bool quiet)
+  bool quiet, bool unsafe)
 {
 BlockBackend *blk;
 if (image_opts) {
@@ -348,9 +354,9 @@ static BlockBackend *img_open(bool image_opts,
 if (!opts) {
 return NULL;
 }
-blk = img_open_opts(filename, opts, flags, writethrough, quiet);
+blk = img_open_opts(filename, opts, flags, writethrough, quiet, 
unsafe);
 } else {
-blk = img_open_file(filename, fmt, flags, writethrough, quiet);
+blk = img_open_file(filename, fmt, flags, writethrough, quiet, unsafe);
 }
 return blk;
 }
@@ -650,6 +656,7 @@ static int img_check(int argc, char **argv)
 ImageCheck *check;
 bool quiet = false;
 bool image_opts = false;
+bool unsafe_read = false;
 
 fmt = NULL;
 output = NULL;
@@ -664,9 +671,10 @@ static int img_check(int argc, char **argv)
 {"output", required_argument, 0, OPTION_OUTPUT},
 {"object", required_argument, 0, OPTION_OBJECT},
 {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
+{"unsafe-read", no_argument, 0, 'U'},
 {0, 0, 0, 0}
 };
-c = getopt_long(argc, argv, ":hf:r:T:q",
+c = getopt_long(argc, argv, ":hf:r:T:qU",
 long_options, _index);
 if (c == -1) {
 break;
@@ -705,6 +713,9 @@ static int img_check(int argc, char **argv)
 case 'q':
 quiet = true;
 break;
+case 'U':
+unsafe_read = true;
+break;
 case OPTION_OBJECT: {
 QemuOpts *opts;
 opts = qemu_opts_parse_noisily(_object_opts,
@@ -744,7 +755,8 @@ static int img_check(int argc, char **argv)
 return 1;
 }
 
-blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
+blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet,
+   unsafe_read);
 if (!blk) {
 return 1;
 }
@@ -864,6 +876,7 @@ static int img_commit(int argc, char **argv)
 CommonBlockJobCBInfo cbi;
 bool image_opts = false;
 AioContext *aio_context;
+bool unsafe_read = false;
 
 fmt = NULL;
 cache = BDRV_DEFAULT_CACHE;
@@ -873,9 +886,10 @@ static int img_commit(int argc, char **argv)
 {"help", no_argument, 0, 'h'},
 {"object", required_argument, 0, OPTION_OBJECT},
 {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
+{"unsafe-read", no_argument, 0, 'U'},
 {0, 0, 0, 0}
 };
-c = getopt_long(argc, argv, ":f:ht:b:dpq",
+c = getopt_long(argc, argv, ":f:ht:b:dpqU",
 long_options, NULL);
 if (c == -1) {
 break;
@@ -910,6 +924,9 @@ static int img_commit(int argc, char **argv)
 case 'q':
 quiet = true;
 break;
+case 'U':
+unsafe_read = true;
+break;
 case OPTION_OBJECT: {