aboutsummaryrefslogtreecommitdiff
path: root/include/linux/blkdev.h
diff options
context:
space:
mode:
authorGravatar Christoph Hellwig <hch@lst.de> 2022-03-30 07:29:06 +0200
committerGravatar Jens Axboe <axboe@kernel.dk> 2022-04-18 06:54:09 -0600
commitdbdc1be32591af023db2812706f01e6cd2f42bfc (patch)
treeecdb59b4ebcdc9bb0f1eea5e086aa9ea0e3c733f /include/linux/blkdev.h
parentzram: cleanup zram_remove (diff)
downloadlinux-dbdc1be32591af023db2812706f01e6cd2f42bfc.tar.gz
linux-dbdc1be32591af023db2812706f01e6cd2f42bfc.tar.bz2
linux-dbdc1be32591af023db2812706f01e6cd2f42bfc.zip
block: add a disk_openers helper
Add a helper that returns the openers for a given gendisk to avoid having drivers poke into disk->part0 to get at this information in a somewhat cumbersome way. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20220330052917.2566582-5-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'include/linux/blkdev.h')
-rw-r--r--include/linux/blkdev.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index c9b5925af5a3..436645bde13f 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -176,6 +176,21 @@ static inline bool disk_live(struct gendisk *disk)
return !inode_unhashed(disk->part0->bd_inode);
}
+/**
+ * disk_openers - returns how many openers are there for a disk
+ * @disk: disk to check
+ *
+ * This returns the number of openers for a disk. Note that this value is only
+ * stable if disk->open_mutex is held.
+ *
+ * Note: Due to a quirk in the block layer open code, each open partition is
+ * only counted once even if there are multiple openers.
+ */
+static inline unsigned int disk_openers(struct gendisk *disk)
+{
+ return disk->part0->bd_openers;
+}
+
/*
* The gendisk is refcounted by the part0 block_device, and the bd_device
* therein is also used for device model presentation in sysfs.