Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

md/md-bitmap: add md_bitmap_registered/enabled() helper

There are no functional changes, prepare to handle the case that
mddev->bitmap_ops can be NULL, which is possible after introducing
CONFIG_MD_BITMAP.

Link: https://lore.kernel.org/linux-raid/20250707012711.376844-7-yukuai1@huaweicloud.com
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Reviewed-by: Xiao Ni <xni@redhat.com>

Yu Kuai 11033207 9c41ead0

+23 -14
+4 -12
drivers/md/md-bitmap.c
··· 232 232 return bitmap->mddev ? mdname(bitmap->mddev) : "mdX"; 233 233 } 234 234 235 - static bool __bitmap_enabled(struct bitmap *bitmap, bool flush) 235 + static bool bitmap_enabled(void *data, bool flush) 236 236 { 237 + struct bitmap *bitmap = data; 238 + 237 239 if (!flush) 238 240 return true; 239 241 ··· 245 243 */ 246 244 return !test_bit(BITMAP_STALE, &bitmap->flags) && 247 245 bitmap->storage.filemap != NULL; 248 - } 249 - 250 - static bool bitmap_enabled(struct mddev *mddev, bool flush) 251 - { 252 - struct bitmap *bitmap = mddev->bitmap; 253 - 254 - if (!bitmap) 255 - return false; 256 - 257 - return __bitmap_enabled(bitmap, flush); 258 246 } 259 247 260 248 /* ··· 1243 1251 int dirty, need_write; 1244 1252 int writing = 0; 1245 1253 1246 - if (!__bitmap_enabled(bitmap, true)) 1254 + if (!bitmap_enabled(bitmap, true)) 1247 1255 return; 1248 1256 1249 1257 /* look at each page to see if there are any set bits that need to be
+18 -1
drivers/md/md-bitmap.h
··· 62 62 }; 63 63 64 64 struct bitmap_operations { 65 - bool (*enabled)(struct mddev *mddev, bool flush); 65 + bool (*enabled)(void *data, bool flush); 66 66 int (*create)(struct mddev *mddev); 67 67 int (*resize)(struct mddev *mddev, sector_t blocks, int chunksize); 68 68 ··· 106 106 107 107 /* the bitmap API */ 108 108 void mddev_set_bitmap_ops(struct mddev *mddev); 109 + 110 + static inline bool md_bitmap_registered(struct mddev *mddev) 111 + { 112 + return mddev->bitmap_ops != NULL; 113 + } 114 + 115 + static inline bool md_bitmap_enabled(struct mddev *mddev, bool flush) 116 + { 117 + /* bitmap_ops must be registered before creating bitmap. */ 118 + if (!md_bitmap_registered(mddev)) 119 + return false; 120 + 121 + if (!mddev->bitmap) 122 + return false; 123 + 124 + return mddev->bitmap_ops->enabled(mddev->bitmap, flush); 125 + } 109 126 110 127 #endif
+1 -1
drivers/md/raid1-10.c
··· 140 140 * If bitmap is not enabled, it's safe to submit the io directly, and 141 141 * this can get optimal performance. 142 142 */ 143 - if (!mddev->bitmap_ops->enabled(mddev, true)) { 143 + if (!md_bitmap_enabled(mddev, true)) { 144 144 raid1_submit_write(bio); 145 145 return true; 146 146 }