From: Al Viro <viro@zeniv.linux.org.uk>
To: linux-fsdevel@vger.kernel.org
Cc: Yu Kuai <yukuai1@huaweicloud.com>,
linux-block@vger.kernel.org,
Christian Brauner <brauner@kernel.org>,
Christoph Hellwig <hch@lst.de>, Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 3/8] bdev: infrastructure for flags
Date: Sun, 28 Apr 2024 06:16:20 +0100 [thread overview]
Message-ID: <20240428051620.GC1549798@ZenIV> (raw)
In-Reply-To: <20240428051232.GU2118490@ZenIV>
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), where flag numbers
are zero-based. Use cmpxchg() to set/clear - all architectures support
it for u32.
NOTE: this commit does not actuall 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 | 2 +-
include/linux/blk_types.h | 2 +-
include/linux/blkdev.h | 33 ++++++++++++++++++++++++++++++++-
3 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/block/bdev.c b/block/bdev.c
index 7a5f611c3d2e..0c55f7abaac3 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -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;
+ bdev->__bd_flags = partno;
bdev->bd_inode = inode;
bdev->bd_queue = disk->queue;
if (partno)
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index cb1526ec44b5..274f7eb4138f 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -45,8 +45,8 @@ struct block_device {
struct request_queue * bd_queue;
struct disk_stats __percpu *bd_stats;
unsigned long bd_stamp;
+ u32 __bd_flags; // partition number + flags
bool bd_read_only; /* read-only policy */
- u8 bd_partno;
bool bd_write_holder;
bool bd_has_submit_bio;
dev_t bd_dev;
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 32549d675955..b9dbfb811533 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -722,7 +722,38 @@ 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 bdev->__bd_flags & 0xff;
+}
+
+static inline bool bdev_test_flag(const struct block_device *bdev, int flag)
+{
+ return bdev->__bd_flags & (1 << (flag + 8));
+}
+
+static inline void bdev_set_flag(struct block_device *bdev, int flag)
+{
+ u32 v = bdev->__bd_flags;
+
+ for (;;) {
+ u32 w = cmpxchg(&bdev->__bd_flags, v, v | (1 << (flag + 8)));
+
+ if (v == w)
+ return;
+ v = w;
+ }
+}
+
+static inline void bdev_clear_flag(struct block_device *bdev, int flag)
+{
+ u32 v = bdev->__bd_flags;
+
+ for (;;) {
+ u32 w = cmpxchg(&bdev->__bd_flags, v, v & ~(1 << (flag + 8)));
+
+ if (v == w)
+ return;
+ v = w;
+ }
}
static inline int get_disk_ro(struct gendisk *disk)
--
2.39.2
next prev parent reply other threads:[~2024-04-28 5:16 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-28 5:12 [PATCHES][RFC] packing struct block_device flags Al Viro
2024-04-28 5:14 ` [PATCH 1/8] Use bdev_is_paritition() instead of open-coding it Al Viro
2024-04-29 5:19 ` Christoph Hellwig
2024-04-28 5:15 ` [PATCH 2/8] wrapper for access to ->bd_partno Al Viro
2024-04-28 5:16 ` Al Viro [this message]
2024-04-28 5:17 ` [PATCH 4/8] bdev: move ->bd_read_only to ->__bd_flags Al Viro
2024-04-28 5:18 ` [PATCH 5/8] bdev: move ->bd_write_holder into ->__bd_flags Al Viro
2024-04-28 5:19 ` [PATCH 6/8] bdev: move ->bd_has_subit_bio to ->__bd_flags Al Viro
2024-04-28 5:19 ` [PATCH 7/8] bdev: move ->bd_ro_warned " Al Viro
2024-04-28 5:21 ` [PATCH 8/8] bdev: move ->bd_make_it_fail " Al Viro
2024-04-29 5:23 ` [PATCHES][RFC] packing struct block_device flags Christoph Hellwig
2024-04-29 7:31 ` Al Viro
2024-04-29 17:02 ` Al Viro
2024-04-29 18:13 ` Al Viro
2024-04-29 18:30 ` Al Viro
2024-05-03 0:06 ` Al Viro
2024-05-03 0:07 ` [PATCH 1/8] Use bdev_is_paritition() instead of open-coding it Al Viro
2024-05-03 0:07 ` [PATCH 2/8] wrapper for access to ->bd_partno Al Viro
2024-05-03 0:08 ` [PATCH v2 3/8] bdev: infrastructure for flags Al Viro
2024-05-03 0:09 ` [PATCH v2 4/8] bdev: move ->bd_read_only to ->__bd_flags Al Viro
2024-05-03 0:09 ` [PATCH v2 5/8] bdev: move ->bd_write_holder into ->__bd_flags Al Viro
2024-05-03 0:10 ` [PATCH v2 6/8] bdev: move ->bd_has_subit_bio to ->__bd_flags Al Viro
2024-05-03 0:10 ` [PATCH v2 7/8] bdev: move ->bd_ro_warned " Al Viro
2024-05-03 0:11 ` [PATCH v2 8/8] bdev: move ->bd_make_it_fail " Al Viro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240428051620.GC1549798@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=yukuai1@huaweicloud.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).