From patchwork Fri Jan 29 02:15:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yang X-Patchwork-Id: 75640 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o0T2GEW4025525 for ; Fri, 29 Jan 2010 02:16:14 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755047Ab0A2CQM (ORCPT ); Thu, 28 Jan 2010 21:16:12 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754939Ab0A2CQM (ORCPT ); Thu, 28 Jan 2010 21:16:12 -0500 Received: from mga02.intel.com ([134.134.136.20]:42253 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752547Ab0A2CQL (ORCPT ); Thu, 28 Jan 2010 21:16:11 -0500 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 28 Jan 2010 18:15:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.49,364,1262592000"; d="scan'208";a="591375566" Received: from syang10-desktop.sh.intel.com (HELO syang10-desktop) ([10.239.36.165]) by orsmga001.jf.intel.com with ESMTP; 28 Jan 2010 18:16:03 -0800 Received: from yasker by syang10-desktop with local (Exim 4.69) (envelope-from ) id 1NagO3-0003hJ-HL; Fri, 29 Jan 2010 10:15:07 +0800 From: Sheng Yang To: Anthony Liguori Cc: Marcelo Tosatti , kvm@vger.kernel.org, qemu-devel@nongnu.org, Kevin Wolf , Sheng Yang , Naphtali Sprei Subject: [PATCH v2] qemu-img: Fix qemu-img can't create qcow image based on read-only image Date: Fri, 29 Jan 2010 10:15:06 +0800 Message-Id: <1264731306-14187-1-git-send-email-sheng@linux.intel.com> X-Mailer: git-send-email 1.6.3.3 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 29 Jan 2010 02:16:14 +0000 (UTC) diff --git a/qemu-img.c b/qemu-img.c index 3cea8ce..ac4d15e 100644 --- a/qemu-img.c +++ b/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)) { @@ -343,7 +348,7 @@ static int img_create(int argc, char **argv) } } - bs = bdrv_new_open(backing_file->value.s, fmt); + bs = bdrv_new_open(backing_file->value.s, fmt, 1); bdrv_get_geometry(bs, &size); size *= 512; bdrv_delete(bs); @@ -627,7 +632,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); @@ -685,7 +690,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;