Re: [PATCH 1/2] block: introduce new field flags in block_device

From: Yu Kuai
Date: Mon Nov 20 2023 - 08:24:21 EST


Hi,

在 2023/11/20 18:45, Hannes Reinecke 写道:
On 11/20/23 10:38, Yu Kuai wrote:
From: Yu Kuai <yukuai3@xxxxxxxxxx>

There are multiple switches in struct block_device, use seperate bool
fields for them is not gracefully. Add a new field flags and replace
swithes to a bit, there are no functional changes, and preapre to add
a new switch in the next patch.

Signed-off-by: Yu Kuai <yukuai3@xxxxxxxxxx>
---
  block/bdev.c              | 15 ++++++++-------
  block/blk-core.c          |  7 ++++---
  block/genhd.c             |  8 +++++---
  block/ioctl.c             |  2 +-
  include/linux/blk_types.h | 12 ++++++------
  include/linux/blkdev.h    |  5 +++--
  6 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/block/bdev.c b/block/bdev.c
index fc8d28d77495..cb849bcf61ae 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -408,10 +408,10 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno)
      bdev->bd_partno = partno;
      bdev->bd_inode = inode;
      bdev->bd_queue = disk->queue;
-    if (partno)
-        bdev->bd_has_submit_bio = disk->part0->bd_has_submit_bio;
+    if (partno && test_bit(BD_FLAG_HAS_SUBMIT_BIO, &disk->part0->flags))
+        set_bit(BD_FLAG_HAS_SUBMIT_BIO, &bdev->flags);
      else
-        bdev->bd_has_submit_bio = false;
+        clear_bit(BD_FLAG_HAS_SUBMIT_BIO, &bdev->flags);
      bdev->bd_stats = alloc_percpu(struct disk_stats);
      if (!bdev->bd_stats) {
          iput(inode);

Couldn't you achieve the very same result by using 'READ_ONCE()/WRITE_ONCE()' and keep the structure as-is?

Yes, remove this patch and add a new bool field in the next patch can
work as well, the idea here is replace multiple fields with a single
flag, and just use the flag in next patch. If people thinks add a new
bool field is better, I'll follow that.

Thanks,
Kuai


Cheers,

Hannes--
Dr. Hannes Reinecke                   Kernel Storage Architect
hare@xxxxxxx                              +49 911 74053 688
SUSE Software Solutions Germany GmbH, Frankenstr. 146, 90461 Nürnberg
Managing Directors: I. Totev, A. McDonald, W. Knoblich
(HRB 36809, AG Nürnberg)

.