bdev: infrastructure for flags
authorAl Viro <viro@zeniv.linux.org.uk>
Fri, 12 Apr 2024 05:07:29 +0000 (01:07 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Thu, 2 May 2024 23:50:11 +0000 (19:50 -0400)
Replace bd_partno with a 32bit field (__bd_flags).  The lower 8 bits
contain the partition number, the upper 24 are for flags.

Helpers: bdev_{test,set,clear}_flag(bdev, flag), with atomic_or()
and atomic_andnot() used to set/clear.

NOTE: this commit does not actually move any flags over there - they
are still bool fields.  As the result, it shifts the fields wrt
cacheline boundaries; that's going to be restored once the first
3 flags are dealt with.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
block/bdev.c
include/linux/blk_types.h
include/linux/blkdev.h

index 7a5f611c3d2e3e83eb00be12b9131f49d8348f5e..2ec223315500ee1a093a6649046251ec33ee4b1d 100644 (file)
@@ -411,7 +411,7 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno)
        mutex_init(&bdev->bd_fsfreeze_mutex);
        spin_lock_init(&bdev->bd_size_lock);
        mutex_init(&bdev->bd_holder_lock);
-       bdev->bd_partno = partno;
+       atomic_set(&bdev->__bd_flags, partno);
        bdev->bd_inode = inode;
        bdev->bd_queue = disk->queue;
        if (partno)
index cb1526ec44b5f66572337fff1ba61dcc704a1d19..04f92737ab08a2da49e87b02147c1817e49598d2 100644 (file)
@@ -45,8 +45,9 @@ struct block_device {
        struct request_queue *  bd_queue;
        struct disk_stats __percpu *bd_stats;
        unsigned long           bd_stamp;
+       atomic_t                __bd_flags;     // partition number + flags
+#define BD_PARTNO              255     // lower 8 bits; assign-once
        bool                    bd_read_only;   /* read-only policy */
-       u8                      bd_partno;
        bool                    bd_write_holder;
        bool                    bd_has_submit_bio;
        dev_t                   bd_dev;
index 32549d6759557b81a11a834d44c3742d8f06df14..99917e5860fd2419dad64a5b80548d89c1b50bb4 100644 (file)
@@ -722,7 +722,22 @@ void disk_uevent(struct gendisk *disk, enum kobject_action action);
 
 static inline u8 bdev_partno(const struct block_device *bdev)
 {
-       return bdev->bd_partno;
+       return atomic_read(&bdev->__bd_flags) & BD_PARTNO;
+}
+
+static inline bool bdev_test_flag(const struct block_device *bdev, unsigned flag)
+{
+       return atomic_read(&bdev->__bd_flags) & flag;
+}
+
+static inline void bdev_set_flag(struct block_device *bdev, unsigned flag)
+{
+       atomic_or(flag, &bdev->__bd_flags);
+}
+
+static inline void bdev_clear_flag(struct block_device *bdev, unsigned flag)
+{
+       atomic_andnot(flag, &bdev->__bd_flags);
 }
 
 static inline int get_disk_ro(struct gendisk *disk)