git: 149ab110dd5c - main - virtio_blk: Use DISKFLAG_WRITE_PROTECT for RO disks
Bryan Venteicher
bryanv at FreeBSD.org
Tue Jan 19 05:08:14 UTC 2021
The branch main has been updated by bryanv:
URL: https://cgit.FreeBSD.org/src/commit/?id=149ab110dd5c9b6058142408a44ef2aa18b30037
commit 149ab110dd5c9b6058142408a44ef2aa18b30037
Author: Bryan Venteicher <bryanv at FreeBSD.org>
AuthorDate: 2021-01-19 04:55:24 +0000
Commit: Bryan Venteicher <bryanv at 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;
More information about the dev-commits-src-main
mailing list