5544c1b
From 4812a358ff2d7442c33a517a6c80d7d3c301ec56 Mon Sep 17 00:00:00 2001
5544c1b
From: "Daniel P. Berrange" <berrange@redhat.com>
5544c1b
Date: Mon, 10 Sep 2012 12:11:31 +0100
5544c1b
Subject: [PATCH] Don't require encryption password for 'qemu-img info'
5544c1b
 command
5544c1b
5544c1b
The encryption password is only required if I/O is going to be
5544c1b
performed on a disk image. The 'qemu-img info' command merely
5544c1b
reports metadata, so it should not ask for a decryption password
5544c1b
5544c1b
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
5544c1b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5544c1b
(cherry picked from commit f0536bb848ad6eb2709a7dc675f261bd160c751b)
5544c1b
5544c1b
Conflicts:
5544c1b
5544c1b
	qemu-img.c
5544c1b
5544c1b
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1b
---
5544c1b
 qemu-img.c | 21 +++++++++++----------
5544c1b
 1 file changed, 11 insertions(+), 10 deletions(-)
5544c1b
5544c1b
diff --git a/qemu-img.c b/qemu-img.c
5544c1b
index b41e670..0d208e8 100644
5544c1b
--- a/qemu-img.c
5544c1b
+++ b/qemu-img.c
5544c1b
@@ -221,7 +221,8 @@ static int print_block_option_help(const char *filename, const char *fmt)
5544c1b
 
5544c1b
 static BlockDriverState *bdrv_new_open(const char *filename,
5544c1b
                                        const char *fmt,
5544c1b
-                                       int flags)
5544c1b
+                                       int flags,
5544c1b
+                                       bool require_io)
5544c1b
 {
5544c1b
     BlockDriverState *bs;
5544c1b
     BlockDriver *drv;
5544c1b
@@ -246,7 +247,7 @@ static BlockDriverState *bdrv_new_open(const char *filename,
5544c1b
         goto fail;
5544c1b
     }
5544c1b
 
5544c1b
-    if (bdrv_is_encrypted(bs)) {
5544c1b
+    if (bdrv_is_encrypted(bs) && require_io) {
5544c1b
         printf("Disk image '%s' is encrypted.\n", filename);
5544c1b
         if (read_password(password, sizeof(password)) < 0) {
5544c1b
             error_report("No password given");
5544c1b
@@ -413,7 +414,7 @@ static int img_check(int argc, char **argv)
5544c1b
     }
5544c1b
     filename = argv[optind++];
5544c1b
 
5544c1b
-    bs = bdrv_new_open(filename, fmt, flags);
5544c1b
+    bs = bdrv_new_open(filename, fmt, flags, true);
5544c1b
     if (!bs) {
5544c1b
         return 1;
5544c1b
     }
5544c1b
@@ -520,7 +521,7 @@ static int img_commit(int argc, char **argv)
5544c1b
         return -1;
5544c1b
     }
5544c1b
 
5544c1b
-    bs = bdrv_new_open(filename, fmt, flags);
5544c1b
+    bs = bdrv_new_open(filename, fmt, flags, true);
5544c1b
     if (!bs) {
5544c1b
         return 1;
5544c1b
     }
5544c1b
@@ -762,7 +763,7 @@ static int img_convert(int argc, char **argv)
5544c1b
 
5544c1b
     total_sectors = 0;
5544c1b
     for (bs_i = 0; bs_i < bs_n; bs_i++) {
5544c1b
-        bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt, BDRV_O_FLAGS);
5544c1b
+        bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt, BDRV_O_FLAGS, true);
5544c1b
         if (!bs[bs_i]) {
5544c1b
             error_report("Could not open '%s'", argv[optind + bs_i]);
5544c1b
             ret = -1;
5544c1b
@@ -881,7 +882,7 @@ static int img_convert(int argc, char **argv)
5544c1b
         return -1;
5544c1b
     }
5544c1b
 
5544c1b
-    out_bs = bdrv_new_open(out_filename, out_fmt, flags);
5544c1b
+    out_bs = bdrv_new_open(out_filename, out_fmt, flags, true);
5544c1b
     if (!out_bs) {
5544c1b
         ret = -1;
5544c1b
         goto out;
5544c1b
@@ -1135,7 +1136,7 @@ static int img_info(int argc, char **argv)
5544c1b
     }
5544c1b
     filename = argv[optind++];
5544c1b
 
5544c1b
-    bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_NO_BACKING);
5544c1b
+    bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_NO_BACKING, false);
5544c1b
     if (!bs) {
5544c1b
         return 1;
5544c1b
     }
5544c1b
@@ -1248,7 +1249,7 @@ static int img_snapshot(int argc, char **argv)
5544c1b
     filename = argv[optind++];
5544c1b
 
5544c1b
     /* Open the image */
5544c1b
-    bs = bdrv_new_open(filename, NULL, bdrv_oflags);
5544c1b
+    bs = bdrv_new_open(filename, NULL, bdrv_oflags, true);
5544c1b
     if (!bs) {
5544c1b
         return 1;
5544c1b
     }
5544c1b
@@ -1366,7 +1367,7 @@ static int img_rebase(int argc, char **argv)
5544c1b
      * Ignore the old backing file for unsafe rebase in case we want to correct
5544c1b
      * the reference to a renamed or moved backing file.
5544c1b
      */
5544c1b
-    bs = bdrv_new_open(filename, fmt, flags);
5544c1b
+    bs = bdrv_new_open(filename, fmt, flags, true);
5544c1b
     if (!bs) {
5544c1b
         return 1;
5544c1b
     }
5544c1b
@@ -1639,7 +1640,7 @@ static int img_resize(int argc, char **argv)
5544c1b
     n = qemu_opt_get_size(param, BLOCK_OPT_SIZE, 0);
5544c1b
     qemu_opts_del(param);
5544c1b
 
5544c1b
-    bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR);
5544c1b
+    bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR, true);
5544c1b
     if (!bs) {
5544c1b
         ret = -1;
5544c1b
         goto out;
5544c1b
-- 
5544c1b
1.7.12.1
5544c1b