summaryrefslogtreecommitdiff
path: root/include/linux/blkdev.h
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2023-06-08 13:02:44 +0200
committerJens Axboe <axboe@kernel.dk>2023-06-12 08:04:04 -0600
commit3f0b3e785e8b54a40c530fa77b7ab37bec925c57 (patch)
tree94db68e2f6bd9e2f9270bbdd2481c8f43f64a8f1 /include/linux/blkdev.h
parent2736e8eeb0ccdc71d1f4256c9c9a28f58cc43307 (diff)
block: add a sb_open_mode helper
Add a helper to return the open flags for blkdev_get_by* for passed in super block flags instead of open coding the logic in many places. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Hannes Reinecke <hare@suse.de> Acked-by: Christian Brauner <brauner@kernel.org> Link: https://lore.kernel.org/r/20230608110258.189493-17-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'include/linux/blkdev.h')
-rw-r--r--include/linux/blkdev.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index d5b99796f12c..978036039020 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1473,6 +1473,13 @@ struct blk_holder_ops {
void (*mark_dead)(struct block_device *bdev);
};
+/*
+ * Return the correct open flags for blkdev_get_by_* for super block flags
+ * as stored in sb->s_flags.
+ */
+#define sb_open_mode(flags) \
+ (FMODE_READ | (((flags) & SB_RDONLY) ? 0 : FMODE_WRITE))
+
struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder,
const struct blk_holder_ops *hops);
struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,