From owner-dev-commits-src-main@freebsd.org Tue Jan 19 05:08:14 2021 Return-Path: <owner-dev-commits-src-main@freebsd.org> Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 159CF4E504F; Tue, 19 Jan 2021 05:08:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DKc9m5x5wz4XBR; Tue, 19 Jan 2021 05:08:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EA0C720B3B; Tue, 19 Jan 2021 05:08:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 10J58AX3085746; Tue, 19 Jan 2021 05:08:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10J58AJK085745; Tue, 19 Jan 2021 05:08:10 GMT (envelope-from git) Date: Tue, 19 Jan 2021 05:08:10 GMT Message-Id: <202101190508.10J58AJK085745@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Bryan Venteicher <bryanv@FreeBSD.org> Subject: git: 149ab110dd5c - main - virtio_blk: Use DISKFLAG_WRITE_PROTECT for RO disks MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bryanv X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 149ab110dd5c9b6058142408a44ef2aa18b30037 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository <dev-commits-src-main.freebsd.org> List-Unsubscribe: <https://lists.freebsd.org/mailman/options/dev-commits-src-main>, <mailto:dev-commits-src-main-request@freebsd.org?subject=unsubscribe> List-Archive: <http://lists.freebsd.org/pipermail/dev-commits-src-main/> List-Post: <mailto:dev-commits-src-main@freebsd.org> List-Help: <mailto:dev-commits-src-main-request@freebsd.org?subject=help> List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main>, <mailto:dev-commits-src-main-request@freebsd.org?subject=subscribe> X-List-Received-Date: Tue, 19 Jan 2021 05:08:14 -0000 The branch main has been updated by bryanv: URL: https://cgit.FreeBSD.org/src/commit/?id=149ab110dd5c9b6058142408a44ef2aa18b30037 commit 149ab110dd5c9b6058142408a44ef2aa18b30037 Author: Bryan Venteicher <bryanv@FreeBSD.org> AuthorDate: 2021-01-19 04:55:24 +0000 Commit: Bryan Venteicher <bryanv@FreeBSD.org> CommitDate: 2021-01-19 04:55:24 +0000 virtio_blk: Use DISKFLAG_WRITE_PROTECT for RO disks Reviewed by: grehan (mentor) Differential Revision: https://reviews.freebsd.org/D27905 --- sys/dev/virtio/block/virtio_blk.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/sys/dev/virtio/block/virtio_blk.c b/sys/dev/virtio/block/virtio_blk.c index 091eb029530e..08df77d6de5b 100644 --- a/sys/dev/virtio/block/virtio_blk.c +++ b/sys/dev/virtio/block/virtio_blk.c @@ -76,11 +76,10 @@ struct vtblk_softc { uint64_t vtblk_features; uint32_t vtblk_flags; #define VTBLK_FLAG_INDIRECT 0x0001 -#define VTBLK_FLAG_READONLY 0x0002 -#define VTBLK_FLAG_DETACH 0x0004 -#define VTBLK_FLAG_SUSPEND 0x0008 -#define VTBLK_FLAG_BARRIER 0x0010 -#define VTBLK_FLAG_WCE_CONFIG 0x0020 +#define VTBLK_FLAG_DETACH 0x0002 +#define VTBLK_FLAG_SUSPEND 0x0004 +#define VTBLK_FLAG_BARRIER 0x0008 +#define VTBLK_FLAG_WCE_CONFIG 0x0010 struct virtqueue *vtblk_vq; struct sglist *vtblk_sglist; @@ -553,17 +552,6 @@ vtblk_strategy(struct bio *bp) return; } - /* - * Fail any write if RO. Unfortunately, there does not seem to - * be a better way to report our readonly'ness to GEOM above. - */ - if (sc->vtblk_flags & VTBLK_FLAG_READONLY && - (bp->bio_cmd == BIO_WRITE || bp->bio_cmd == BIO_FLUSH || - bp->bio_cmd == BIO_DELETE)) { - vtblk_bio_done(sc, bp, EROFS); - return; - } - if ((bp->bio_cmd != BIO_READ) && (bp->bio_cmd != BIO_WRITE) && (bp->bio_cmd != BIO_FLUSH) && (bp->bio_cmd != BIO_DELETE)) { vtblk_bio_done(sc, bp, EOPNOTSUPP); @@ -609,8 +597,6 @@ vtblk_setup_features(struct vtblk_softc *sc) if (virtio_with_feature(dev, VIRTIO_RING_F_INDIRECT_DESC)) sc->vtblk_flags |= VTBLK_FLAG_INDIRECT; - if (virtio_with_feature(dev, VIRTIO_BLK_F_RO)) - sc->vtblk_flags |= VTBLK_FLAG_READONLY; if (virtio_with_feature(dev, VIRTIO_BLK_F_CONFIG_WCE)) sc->vtblk_flags |= VTBLK_FLAG_WCE_CONFIG; @@ -701,11 +687,13 @@ vtblk_alloc_disk(struct vtblk_softc *sc, struct virtio_blk_config *blkcfg) dp->d_hba_subvendor = virtio_get_subvendor(dev); dp->d_hba_subdevice = virtio_get_subdevice(dev); - if (virtio_with_feature(dev, VIRTIO_BLK_F_FLUSH)) - dp->d_flags |= DISKFLAG_CANFLUSHCACHE; - - if ((sc->vtblk_flags & VTBLK_FLAG_READONLY) == 0) + if (virtio_with_feature(dev, VIRTIO_BLK_F_RO)) + dp->d_flags |= DISKFLAG_WRITE_PROTECT; + else { + if (virtio_with_feature(dev, VIRTIO_BLK_F_FLUSH)) + dp->d_flags |= DISKFLAG_CANFLUSHCACHE; dp->d_dump = vtblk_dump; + } /* Capacity is always in 512-byte units. */ dp->d_mediasize = blkcfg->capacity * VTBLK_BSIZE;