From patchwork Mon Feb 18 13:06:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 10817973 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A15D817FB for ; Mon, 18 Feb 2019 13:09:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 904902AA5B for ; Mon, 18 Feb 2019 13:09:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8477B2AA5F; Mon, 18 Feb 2019 13:09:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F093D2AA5B for ; Mon, 18 Feb 2019 13:09:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730908AbfBRNJ6 (ORCPT ); Mon, 18 Feb 2019 08:09:58 -0500 Received: from foss.arm.com ([217.140.101.70]:57982 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730512AbfBRNJ5 (ORCPT ); Mon, 18 Feb 2019 08:09:57 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1804A15AD; Mon, 18 Feb 2019 05:09:57 -0800 (PST) Received: from ostrya.cambridge.arm.com (ostrya.cambridge.arm.com [10.1.197.2]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7B35C3F720; Mon, 18 Feb 2019 05:09:55 -0800 (PST) From: Jean-Philippe Brucker To: kvm@vger.kernel.org Cc: will.deacon@arm.com, andre.przywara@arm.com Subject: [PATCH kvmtool 2/9] virtio/blk: Set VIRTIO_BLK_F_RO when the disk is read-only Date: Mon, 18 Feb 2019 13:06:55 +0000 Message-Id: <20190218130702.32575-3-jean-philippe.brucker@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218130702.32575-1-jean-philippe.brucker@arm.com> References: <20190218130702.32575-1-jean-philippe.brucker@arm.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since we don't currently tell the guest when the disk backend is read-only, it will report any inconsistent read after write as an error. An image may be read-only either because user requested it on the command-line, or because write support isn't implemented. Pass the read-only attribute using the VIRTIO_BLK_F_RO feature. Signed-off-by: Jean-Philippe Brucker Reviewed-by: Andre Przywara --- disk/core.c | 9 +++++++-- include/kvm/disk-image.h | 1 + virtio/blk.c | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/disk/core.c b/disk/core.c index dd2f258b0..4c7c4f030 100644 --- a/disk/core.c +++ b/disk/core.c @@ -139,8 +139,10 @@ static struct disk_image *disk_image__open(const char *filename, bool readonly, /* blk device ?*/ disk = blkdev__probe(filename, flags, &st); - if (!IS_ERR_OR_NULL(disk)) + if (!IS_ERR_OR_NULL(disk)) { + disk->readonly = readonly; return disk; + } fd = open(filename, flags); if (fd < 0) @@ -150,13 +152,16 @@ static struct disk_image *disk_image__open(const char *filename, bool readonly, disk = qcow_probe(fd, true); if (!IS_ERR_OR_NULL(disk)) { pr_warning("Forcing read-only support for QCOW"); + disk->readonly = true; return disk; } /* raw image ?*/ disk = raw_image__probe(fd, &st, readonly); - if (!IS_ERR_OR_NULL(disk)) + if (!IS_ERR_OR_NULL(disk)) { + disk->readonly = readonly; return disk; + } if (close(fd) < 0) pr_warning("close() failed"); diff --git a/include/kvm/disk-image.h b/include/kvm/disk-image.h index b72805242..4746e88c9 100644 --- a/include/kvm/disk-image.h +++ b/include/kvm/disk-image.h @@ -59,6 +59,7 @@ struct disk_image { void *priv; void *disk_req_cb_param; void (*disk_req_cb)(void *param, long len); + bool readonly; bool async; int evt; #ifdef CONFIG_HAS_AIO diff --git a/virtio/blk.c b/virtio/blk.c index a57df2e96..6e7a1ee36 100644 --- a/virtio/blk.c +++ b/virtio/blk.c @@ -148,10 +148,13 @@ static u8 *get_config(struct kvm *kvm, void *dev) static u32 get_host_features(struct kvm *kvm, void *dev) { + struct blk_dev *bdev = dev; + return 1UL << VIRTIO_BLK_F_SEG_MAX | 1UL << VIRTIO_BLK_F_FLUSH | 1UL << VIRTIO_RING_F_EVENT_IDX - | 1UL << VIRTIO_RING_F_INDIRECT_DESC; + | 1UL << VIRTIO_RING_F_INDIRECT_DESC + | (bdev->disk->readonly ? 1UL << VIRTIO_BLK_F_RO : 0); } static void set_guest_features(struct kvm *kvm, void *dev, u32 features)