From patchwork Tue Oct 15 09:45:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 283561 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 297E92C016A for ; Tue, 15 Oct 2013 20:46:30 +1100 (EST) Received: from localhost ([::1]:40795 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VW1Cn-0006xN-M1 for incoming@patchwork.ozlabs.org; Tue, 15 Oct 2013 05:46:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36960) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VW1CS-0006ws-Te for qemu-devel@nongnu.org; Tue, 15 Oct 2013 05:46:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VW1CM-0005gd-TI for qemu-devel@nongnu.org; Tue, 15 Oct 2013 05:46:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:23136) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VW1CM-0005gY-LE for qemu-devel@nongnu.org; Tue, 15 Oct 2013 05:45:54 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r9F9jrgx025633 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 15 Oct 2013 05:45:53 -0400 Received: from T430s.nay.redhat.com ([10.66.6.118]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r9F9jo3k010885; Tue, 15 Oct 2013 05:45:51 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 15 Oct 2013 17:45:50 +0800 Message-Id: <1381830350-7240-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, stefanha@redhat.com, edivaldoapereira@yahoo.com.br Subject: [Qemu-devel] [PATCH v2] blockdev: fix cdrom read_only flag X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Since 0ebd24e0, cdrom doesn't have read-only on by default, which will error out when using an read only image. Fix it by setting the default value when parsing opts. Reported-by: Edivaldo de Araujo Pereira Signed-off-by: Fam Zheng Reviewed-by: Kevin Wolf --- v2: fix backward compatibility by force read-only with cdrom. (Kevin) Signed-off-by: Fam Zheng --- blockdev.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/blockdev.c b/blockdev.c index 4f76e28..b260477 100644 --- a/blockdev.c +++ b/blockdev.c @@ -625,7 +625,8 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) int cyls, heads, secs, translation; int max_devs, bus_id, unit_id, index; const char *devaddr; - bool read_only, copy_on_read; + bool read_only = false; + bool copy_on_read; Error *local_err = NULL; /* Change legacy command line options into QMP ones */ @@ -701,7 +702,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) media = MEDIA_DISK; } else if (!strcmp(value, "cdrom")) { media = MEDIA_CDROM; - qdict_put(bs_opts, "read-only", qstring_from_str("on")); + read_only = true; } else { error_report("'%s' invalid media", value); goto fail; @@ -709,7 +710,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) } /* copy-on-read is disabled with a warning for read-only devices */ - read_only = qemu_opt_get_bool(legacy_opts, "read-only", false); + read_only |= qemu_opt_get_bool(legacy_opts, "read-only", false); copy_on_read = qemu_opt_get_bool(legacy_opts, "copy-on-read", false); if (read_only && copy_on_read) {