Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 340e01248478ba8b78a6d4d1809b1eff > files > 750

kvm-83-270.el5_11.src.rpm

From af468a6d39874da252cce508b83a8e290fd99ab5 Mon Sep 17 00:00:00 2001
From: Naphtali Sprei <nsprei@redhat.com>
Date: Thu, 15 Apr 2010 11:56:41 -0300
Subject: [PATCH 05/12] read-only: qemu-img: Allow opening an image with read-only

RH-Author: Naphtali Sprei <nsprei@redhat.com>
Message-id: <1271332608-5243-5-git-send-email-nsprei@redhat.com>
Patchwork-id: 8652
O-Subject: [RHEL 5.6 kvm PATCH v4 04/11] read-only: qemu-img: Allow opening an
	image with read-only
Bugzilla: 510630
RH-Acked-by: Christoph Hellwig <chellwig@redhat.com>
RH-Acked-by: Juan Quintela <quintela@redhat.com>
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>

Instead of the default to always open as read-write, allow
opening an image with read-only.

upstream commit: 9bc378c1430d0c227a8463501b6e0d03cf09adac

Signed-off-by: Naphtali Sprei <nsprei@redhat.com>
---
 qemu/qemu-img.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 qemu/qemu-img.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/qemu/qemu-img.c b/qemu/qemu-img.c
index 066c203..8b0c522 100644
--- a/qemu/qemu-img.c
+++ b/qemu/qemu-img.c
@@ -188,11 +188,13 @@ static int read_password(char *buf, int buf_size)
 #endif
 
 static BlockDriverState *bdrv_new_open(const char *filename,
-                                       const char *fmt)
+                                       const char *fmt,
+                                       int readonly)
 {
     BlockDriverState *bs;
     BlockDriver *drv;
     char password[256];
+    int flags = BRDV_O_FLAGS;
 
     bs = bdrv_new("");
     if (!bs)
@@ -204,7 +206,10 @@ static BlockDriverState *bdrv_new_open(const char *filename,
     } else {
         drv = NULL;
     }
-    if (bdrv_open2(bs, filename, BRDV_O_FLAGS | BDRV_O_RDWR, drv) < 0) {
+    if (!readonly) {
+        flags |= BDRV_O_RDWR;
+    }
+    if (bdrv_open2(bs, filename, flags, drv) < 0) {
         error("Could not open '%s'", filename);
     }
     if (bdrv_is_encrypted(bs)) {
@@ -268,7 +273,7 @@ static int img_create(int argc, char **argv)
                 error("Unknown basefile format '%s'", base_fmt);
         }
 
-        bs = bdrv_new_open(base_filename, base_fmt);
+        bs = bdrv_new_open(base_filename, base_fmt, 1);
         bdrv_get_geometry(bs, &size);
         size *= 512;
         bdrv_delete(bs);
@@ -569,7 +574,7 @@ static int img_convert(int argc, char **argv)
 
     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, 1);
         if (!bs[bs_i])
             error("Could not open '%s'", argv[optind + bs_i]);
         bdrv_get_geometry(bs[bs_i], &bs_sectors);
@@ -603,7 +608,7 @@ static int img_convert(int argc, char **argv)
         }
     }
 
-    out_bs = bdrv_new_open(out_filename, out_fmt);
+    out_bs = bdrv_new_open(out_filename, out_fmt, 0);
 
     bs_i = 0;
     bs_offset = 0;
-- 
1.7.0.3