From patchwork Wed Oct 14 15:52:29 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naphtali Sprei X-Patchwork-Id: 35985 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A6C7CB7063 for ; Thu, 15 Oct 2009 02:53:17 +1100 (EST) Received: from localhost ([127.0.0.1]:50234 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1My6A5-0002k5-V2 for incoming@patchwork.ozlabs.org; Wed, 14 Oct 2009 11:53:13 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1My69Z-0002jZ-Jp for qemu-devel@nongnu.org; Wed, 14 Oct 2009 11:52:41 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1My69V-0002gJ-S3 for qemu-devel@nongnu.org; Wed, 14 Oct 2009 11:52:41 -0400 Received: from [199.232.76.173] (port=43091 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1My69V-0002g7-PI for qemu-devel@nongnu.org; Wed, 14 Oct 2009 11:52:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:65218) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1My69V-0008M9-76 for qemu-devel@nongnu.org; Wed, 14 Oct 2009 11:52:37 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9EFqZQB001367 for ; Wed, 14 Oct 2009 11:52:36 -0400 Received: from [10.35.0.60] (dhcp-0-60.tlv.redhat.com [10.35.0.60]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9EFqU8x020523 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 14 Oct 2009 11:52:35 -0400 Message-ID: <4AD5F3BD.2040402@redhat.com> Date: Wed, 14 Oct 2009 17:52:29 +0200 From: Naphtali Sprei User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: qemu-devel@nongnu.org X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH] Pass the drive's readonly attribute to the guest OS X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Hi, as a preliminary step for adding read only flag for the -drive command, I've added code to pass the (existing) read only attribute of the drive to the guest OS (if it bother to ask). I've added for virtio and for scsi. Verified it already works for floppy. Searched like mad (in linux sources) for same read only/write protect attribute for ide, but all I found was only for ide-floppy. I assume it's not supported in ide drives. Please correct me if I'm wrong. I don't know about the other interface types for the drive command: sd, mtd, floppy, pflash. Where is usb ?? Will be happy to add those, too, if applicable. Please advise. I'm planning to investigate where qemu should check the read only attribute before exeuting any write command to drives, would be sent in a different patch. Naphtali Signed-off-by: Naphtali Sprei --- hw/scsi-disk.c | 3 ++- hw/virtio-blk.c | 3 +++ 2 files changed, 5 insertions(+), 1 deletions(-) diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 3940726..e4511fb 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -631,7 +631,8 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, memset(p, 0, 4); outbuf[1] = 0; /* Default media type. */ outbuf[3] = 0; /* Block descriptor length. */ - if (bdrv_get_type_hint(s->dinfo->bdrv) == BDRV_TYPE_CDROM) { + if (bdrv_get_type_hint(s->dinfo->bdrv) == BDRV_TYPE_CDROM || + bdrv_is_read_only(s->dinfo->bdrv)) { outbuf[2] = 0x80; /* Readonly. */ } p += 4; diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index 2630b99..e6df9f2 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -444,6 +444,9 @@ static uint32_t virtio_blk_get_features(VirtIODevice *vdev) #endif if (strcmp(s->serial_str, "0")) features |= 1 << VIRTIO_BLK_F_IDENTIFY; + + if (bdrv_is_read_only(s->bs)) + features |= 1 << VIRTIO_BLK_F_RO; return features; }