Skip to content

Commit 1116b9f

Browse files
author
Al Viro
committed
bdev: infrastructure for flags
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>
1 parent b8c873e commit 1116b9f

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

block/bdev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno)
411411
mutex_init(&bdev->bd_fsfreeze_mutex);
412412
spin_lock_init(&bdev->bd_size_lock);
413413
mutex_init(&bdev->bd_holder_lock);
414-
bdev->bd_partno = partno;
414+
atomic_set(&bdev->__bd_flags, partno);
415415
bdev->bd_inode = inode;
416416
bdev->bd_queue = disk->queue;
417417
if (partno)

include/linux/blk_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ struct block_device {
4545
struct request_queue * bd_queue;
4646
struct disk_stats __percpu *bd_stats;
4747
unsigned long bd_stamp;
48+
atomic_t __bd_flags; // partition number + flags
49+
#define BD_PARTNO 255 // lower 8 bits; assign-once
4850
bool bd_read_only; /* read-only policy */
49-
u8 bd_partno;
5051
bool bd_write_holder;
5152
bool bd_has_submit_bio;
5253
dev_t bd_dev;

include/linux/blkdev.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,22 @@ void disk_uevent(struct gendisk *disk, enum kobject_action action);
722722

723723
static inline u8 bdev_partno(const struct block_device *bdev)
724724
{
725-
return bdev->bd_partno;
725+
return atomic_read(&bdev->__bd_flags) & BD_PARTNO;
726+
}
727+
728+
static inline bool bdev_test_flag(const struct block_device *bdev, unsigned flag)
729+
{
730+
return atomic_read(&bdev->__bd_flags) & flag;
731+
}
732+
733+
static inline void bdev_set_flag(struct block_device *bdev, unsigned flag)
734+
{
735+
atomic_or(flag, &bdev->__bd_flags);
736+
}
737+
738+
static inline void bdev_clear_flag(struct block_device *bdev, unsigned flag)
739+
{
740+
atomic_andnot(flag, &bdev->__bd_flags);
726741
}
727742

728743
static inline int get_disk_ro(struct gendisk *disk)

0 commit comments

Comments
 (0)