Skip to content

Commit e7b94c5

Browse files
committed
Merge tag 'md-6.14-20250113' of https://git.kernel.org/pub/scm/linux/kernel/git/mdraid/linux into for-6.14/block
Pull MD updates from Song: "1. Reintroduce md-linear, by Yu Kuai. 2. md-bitmap refactor and fix, by Yu Kuai. 3. Replace kmap_atomic with kmap_local_page, by David Reaver." * tag 'md-6.14-20250113' of https://git.kernel.org/pub/scm/linux/kernel/git/mdraid/linux: md/md-bitmap: move bitmap_{start, end}write to md upper layer md/raid5: implement pers->bitmap_sector() md: add a new callback pers->bitmap_sector() md/md-bitmap: remove the last parameter for bimtap_ops->endwrite() md/md-bitmap: factor behind write counters out from bitmap_{start/end}write() md: Replace deprecated kmap_atomic() with kmap_local_page() md: reintroduce md-linear
2 parents 170e086 + c9b39e5 commit e7b94c5

File tree

17 files changed

+557
-180
lines changed

17 files changed

+557
-180
lines changed

drivers/md/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ config MD_BITMAP_FILE
6161
various kernel APIs and can only work with files on a file system not
6262
actually sitting on the MD device.
6363

64+
config MD_LINEAR
65+
tristate "Linear (append) mode"
66+
depends on BLK_DEV_MD
67+
help
68+
If you say Y here, then your multiple devices driver will be able to
69+
use the so-called linear mode, i.e. it will combine the hard disk
70+
partitions by simply appending one to the other.
71+
72+
To compile this as a module, choose M here: the module
73+
will be called linear.
74+
75+
If unsure, say Y.
76+
6477
config MD_RAID0
6578
tristate "RAID-0 (striping) mode"
6679
depends on BLK_DEV_MD

drivers/md/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ dm-zoned-y += dm-zoned-target.o dm-zoned-metadata.o dm-zoned-reclaim.o
2929

3030
md-mod-y += md.o md-bitmap.o
3131
raid456-y += raid5.o raid5-cache.o raid5-ppl.o
32+
linear-y += md-linear.o
3233

3334
# Note: link order is important. All raid personalities
3435
# and must come before md.o, as they each initialise
3536
# themselves, and md.o may use the personalities when it
3637
# auto-initialised.
3738

39+
obj-$(CONFIG_MD_LINEAR) += linear.o
3840
obj-$(CONFIG_MD_RAID0) += raid0.o
3941
obj-$(CONFIG_MD_RAID1) += raid1.o
4042
obj-$(CONFIG_MD_RAID10) += raid10.o

drivers/md/md-autodetect.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static int md_setup_ents __initdata;
4949
* instead of just one. -- KTK
5050
* 18May2000: Added support for persistent-superblock arrays:
5151
* md=n,0,factor,fault,device-list uses RAID0 for device n
52+
* md=n,-1,factor,fault,device-list uses LINEAR for device n
5253
* md=n,device-list reads a RAID superblock from the devices
5354
* elements in device-list are read by name_to_kdev_t so can be
5455
* a hex number or something like /dev/hda1 /dev/sdb
@@ -87,15 +88,18 @@ static int __init md_setup(char *str)
8788
md_setup_ents++;
8889
switch (get_option(&str, &level)) { /* RAID level */
8990
case 2: /* could be 0 or -1.. */
90-
if (level == 0) {
91+
if (level == 0 || level == LEVEL_LINEAR) {
9192
if (get_option(&str, &factor) != 2 || /* Chunk Size */
9293
get_option(&str, &fault) != 2) {
9394
printk(KERN_WARNING "md: Too few arguments supplied to md=.\n");
9495
return 0;
9596
}
9697
md_setup_args[ent].level = level;
9798
md_setup_args[ent].chunk = 1 << (factor+12);
98-
pername = "raid0";
99+
if (level == LEVEL_LINEAR)
100+
pername = "linear";
101+
else
102+
pername = "raid0";
99103
break;
100104
}
101105
fallthrough;

drivers/md/md-bitmap.c

Lines changed: 66 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ static void bitmap_update_sb(void *data)
682682
return;
683683
if (!bitmap->storage.sb_page) /* no superblock */
684684
return;
685-
sb = kmap_atomic(bitmap->storage.sb_page);
685+
sb = kmap_local_page(bitmap->storage.sb_page);
686686
sb->events = cpu_to_le64(bitmap->mddev->events);
687687
if (bitmap->mddev->events < bitmap->events_cleared)
688688
/* rocking back to read-only */
@@ -702,7 +702,7 @@ static void bitmap_update_sb(void *data)
702702
sb->nodes = cpu_to_le32(bitmap->mddev->bitmap_info.nodes);
703703
sb->sectors_reserved = cpu_to_le32(bitmap->mddev->
704704
bitmap_info.space);
705-
kunmap_atomic(sb);
705+
kunmap_local(sb);
706706

707707
if (bitmap->storage.file)
708708
write_file_page(bitmap, bitmap->storage.sb_page, 1);
@@ -717,7 +717,7 @@ static void bitmap_print_sb(struct bitmap *bitmap)
717717

718718
if (!bitmap || !bitmap->storage.sb_page)
719719
return;
720-
sb = kmap_atomic(bitmap->storage.sb_page);
720+
sb = kmap_local_page(bitmap->storage.sb_page);
721721
pr_debug("%s: bitmap file superblock:\n", bmname(bitmap));
722722
pr_debug(" magic: %08x\n", le32_to_cpu(sb->magic));
723723
pr_debug(" version: %u\n", le32_to_cpu(sb->version));
@@ -736,7 +736,7 @@ static void bitmap_print_sb(struct bitmap *bitmap)
736736
pr_debug(" sync size: %llu KB\n",
737737
(unsigned long long)le64_to_cpu(sb->sync_size)/2);
738738
pr_debug("max write behind: %u\n", le32_to_cpu(sb->write_behind));
739-
kunmap_atomic(sb);
739+
kunmap_local(sb);
740740
}
741741

742742
/*
@@ -760,15 +760,15 @@ static int md_bitmap_new_disk_sb(struct bitmap *bitmap)
760760
return -ENOMEM;
761761
bitmap->storage.sb_index = 0;
762762

763-
sb = kmap_atomic(bitmap->storage.sb_page);
763+
sb = kmap_local_page(bitmap->storage.sb_page);
764764

765765
sb->magic = cpu_to_le32(BITMAP_MAGIC);
766766
sb->version = cpu_to_le32(BITMAP_MAJOR_HI);
767767

768768
chunksize = bitmap->mddev->bitmap_info.chunksize;
769769
BUG_ON(!chunksize);
770770
if (!is_power_of_2(chunksize)) {
771-
kunmap_atomic(sb);
771+
kunmap_local(sb);
772772
pr_warn("bitmap chunksize not a power of 2\n");
773773
return -EINVAL;
774774
}
@@ -803,7 +803,7 @@ static int md_bitmap_new_disk_sb(struct bitmap *bitmap)
803803
sb->events_cleared = cpu_to_le64(bitmap->mddev->events);
804804
bitmap->mddev->bitmap_info.nodes = 0;
805805

806-
kunmap_atomic(sb);
806+
kunmap_local(sb);
807807

808808
return 0;
809809
}
@@ -865,7 +865,7 @@ static int md_bitmap_read_sb(struct bitmap *bitmap)
865865
return err;
866866

867867
err = -EINVAL;
868-
sb = kmap_atomic(sb_page);
868+
sb = kmap_local_page(sb_page);
869869

870870
chunksize = le32_to_cpu(sb->chunksize);
871871
daemon_sleep = le32_to_cpu(sb->daemon_sleep) * HZ;
@@ -932,7 +932,7 @@ static int md_bitmap_read_sb(struct bitmap *bitmap)
932932
err = 0;
933933

934934
out:
935-
kunmap_atomic(sb);
935+
kunmap_local(sb);
936936
if (err == 0 && nodes && (bitmap->cluster_slot < 0)) {
937937
/* Assigning chunksize is required for "re_read" */
938938
bitmap->mddev->bitmap_info.chunksize = chunksize;
@@ -1161,12 +1161,12 @@ static void md_bitmap_file_set_bit(struct bitmap *bitmap, sector_t block)
11611161
bit = file_page_offset(&bitmap->storage, chunk);
11621162

11631163
/* set the bit */
1164-
kaddr = kmap_atomic(page);
1164+
kaddr = kmap_local_page(page);
11651165
if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags))
11661166
set_bit(bit, kaddr);
11671167
else
11681168
set_bit_le(bit, kaddr);
1169-
kunmap_atomic(kaddr);
1169+
kunmap_local(kaddr);
11701170
pr_debug("set file bit %lu page %lu\n", bit, index);
11711171
/* record page number so it gets flushed to disk when unplug occurs */
11721172
set_page_attr(bitmap, index - node_offset, BITMAP_PAGE_DIRTY);
@@ -1190,12 +1190,12 @@ static void md_bitmap_file_clear_bit(struct bitmap *bitmap, sector_t block)
11901190
if (!page)
11911191
return;
11921192
bit = file_page_offset(&bitmap->storage, chunk);
1193-
paddr = kmap_atomic(page);
1193+
paddr = kmap_local_page(page);
11941194
if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags))
11951195
clear_bit(bit, paddr);
11961196
else
11971197
clear_bit_le(bit, paddr);
1198-
kunmap_atomic(paddr);
1198+
kunmap_local(paddr);
11991199
if (!test_page_attr(bitmap, index - node_offset, BITMAP_PAGE_NEEDWRITE)) {
12001200
set_page_attr(bitmap, index - node_offset, BITMAP_PAGE_PENDING);
12011201
bitmap->allclean = 0;
@@ -1214,12 +1214,12 @@ static int md_bitmap_file_test_bit(struct bitmap *bitmap, sector_t block)
12141214
if (!page)
12151215
return -EINVAL;
12161216
bit = file_page_offset(&bitmap->storage, chunk);
1217-
paddr = kmap_atomic(page);
1217+
paddr = kmap_local_page(page);
12181218
if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags))
12191219
set = test_bit(bit, paddr);
12201220
else
12211221
set = test_bit_le(bit, paddr);
1222-
kunmap_atomic(paddr);
1222+
kunmap_local(paddr);
12231223
return set;
12241224
}
12251225

@@ -1388,9 +1388,9 @@ static int md_bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
13881388
* If the bitmap is out of date, dirty the whole page
13891389
* and write it out
13901390
*/
1391-
paddr = kmap_atomic(page);
1391+
paddr = kmap_local_page(page);
13921392
memset(paddr + offset, 0xff, PAGE_SIZE - offset);
1393-
kunmap_atomic(paddr);
1393+
kunmap_local(paddr);
13941394

13951395
filemap_write_page(bitmap, i, true);
13961396
if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) {
@@ -1406,12 +1406,12 @@ static int md_bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
14061406
void *paddr;
14071407
bool was_set;
14081408

1409-
paddr = kmap_atomic(page);
1409+
paddr = kmap_local_page(page);
14101410
if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags))
14111411
was_set = test_bit(bit, paddr);
14121412
else
14131413
was_set = test_bit_le(bit, paddr);
1414-
kunmap_atomic(paddr);
1414+
kunmap_local(paddr);
14151415

14161416
if (was_set) {
14171417
/* if the disk bit is set, set the memory bit */
@@ -1546,10 +1546,10 @@ static void bitmap_daemon_work(struct mddev *mddev)
15461546
bitmap_super_t *sb;
15471547
bitmap->need_sync = 0;
15481548
if (bitmap->storage.filemap) {
1549-
sb = kmap_atomic(bitmap->storage.sb_page);
1549+
sb = kmap_local_page(bitmap->storage.sb_page);
15501550
sb->events_cleared =
15511551
cpu_to_le64(bitmap->events_cleared);
1552-
kunmap_atomic(sb);
1552+
kunmap_local(sb);
15531553
set_page_attr(bitmap, 0,
15541554
BITMAP_PAGE_NEEDWRITE);
15551555
}
@@ -1671,24 +1671,13 @@ __acquires(bitmap->lock)
16711671
}
16721672

16731673
static int bitmap_startwrite(struct mddev *mddev, sector_t offset,
1674-
unsigned long sectors, bool behind)
1674+
unsigned long sectors)
16751675
{
16761676
struct bitmap *bitmap = mddev->bitmap;
16771677

16781678
if (!bitmap)
16791679
return 0;
16801680

1681-
if (behind) {
1682-
int bw;
1683-
atomic_inc(&bitmap->behind_writes);
1684-
bw = atomic_read(&bitmap->behind_writes);
1685-
if (bw > bitmap->behind_writes_used)
1686-
bitmap->behind_writes_used = bw;
1687-
1688-
pr_debug("inc write-behind count %d/%lu\n",
1689-
bw, bitmap->mddev->bitmap_info.max_write_behind);
1690-
}
1691-
16921681
while (sectors) {
16931682
sector_t blocks;
16941683
bitmap_counter_t *bmc;
@@ -1737,21 +1726,13 @@ static int bitmap_startwrite(struct mddev *mddev, sector_t offset,
17371726
}
17381727

17391728
static void bitmap_endwrite(struct mddev *mddev, sector_t offset,
1740-
unsigned long sectors, bool success, bool behind)
1729+
unsigned long sectors)
17411730
{
17421731
struct bitmap *bitmap = mddev->bitmap;
17431732

17441733
if (!bitmap)
17451734
return;
17461735

1747-
if (behind) {
1748-
if (atomic_dec_and_test(&bitmap->behind_writes))
1749-
wake_up(&bitmap->behind_wait);
1750-
pr_debug("dec write-behind count %d/%lu\n",
1751-
atomic_read(&bitmap->behind_writes),
1752-
bitmap->mddev->bitmap_info.max_write_behind);
1753-
}
1754-
17551736
while (sectors) {
17561737
sector_t blocks;
17571738
unsigned long flags;
@@ -1764,15 +1745,16 @@ static void bitmap_endwrite(struct mddev *mddev, sector_t offset,
17641745
return;
17651746
}
17661747

1767-
if (success && !bitmap->mddev->degraded &&
1768-
bitmap->events_cleared < bitmap->mddev->events) {
1769-
bitmap->events_cleared = bitmap->mddev->events;
1770-
bitmap->need_sync = 1;
1771-
sysfs_notify_dirent_safe(bitmap->sysfs_can_clear);
1772-
}
1773-
1774-
if (!success && !NEEDED(*bmc))
1748+
if (!bitmap->mddev->degraded) {
1749+
if (bitmap->events_cleared < bitmap->mddev->events) {
1750+
bitmap->events_cleared = bitmap->mddev->events;
1751+
bitmap->need_sync = 1;
1752+
sysfs_notify_dirent_safe(
1753+
bitmap->sysfs_can_clear);
1754+
}
1755+
} else if (!NEEDED(*bmc)) {
17751756
*bmc |= NEEDED_MASK;
1757+
}
17761758

17771759
if (COUNTER(*bmc) == COUNTER_MAX)
17781760
wake_up(&bitmap->overflow_wait);
@@ -2062,6 +2044,37 @@ static void md_bitmap_free(void *data)
20622044
kfree(bitmap);
20632045
}
20642046

2047+
static void bitmap_start_behind_write(struct mddev *mddev)
2048+
{
2049+
struct bitmap *bitmap = mddev->bitmap;
2050+
int bw;
2051+
2052+
if (!bitmap)
2053+
return;
2054+
2055+
atomic_inc(&bitmap->behind_writes);
2056+
bw = atomic_read(&bitmap->behind_writes);
2057+
if (bw > bitmap->behind_writes_used)
2058+
bitmap->behind_writes_used = bw;
2059+
2060+
pr_debug("inc write-behind count %d/%lu\n",
2061+
bw, bitmap->mddev->bitmap_info.max_write_behind);
2062+
}
2063+
2064+
static void bitmap_end_behind_write(struct mddev *mddev)
2065+
{
2066+
struct bitmap *bitmap = mddev->bitmap;
2067+
2068+
if (!bitmap)
2069+
return;
2070+
2071+
if (atomic_dec_and_test(&bitmap->behind_writes))
2072+
wake_up(&bitmap->behind_wait);
2073+
pr_debug("dec write-behind count %d/%lu\n",
2074+
atomic_read(&bitmap->behind_writes),
2075+
bitmap->mddev->bitmap_info.max_write_behind);
2076+
}
2077+
20652078
static void bitmap_wait_behind_writes(struct mddev *mddev)
20662079
{
20672080
struct bitmap *bitmap = mddev->bitmap;
@@ -2981,6 +2994,9 @@ static struct bitmap_operations bitmap_ops = {
29812994
.dirty_bits = bitmap_dirty_bits,
29822995
.unplug = bitmap_unplug,
29832996
.daemon_work = bitmap_daemon_work,
2997+
2998+
.start_behind_write = bitmap_start_behind_write,
2999+
.end_behind_write = bitmap_end_behind_write,
29843000
.wait_behind_writes = bitmap_wait_behind_writes,
29853001

29863002
.startwrite = bitmap_startwrite,

drivers/md/md-bitmap.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,15 @@ struct bitmap_operations {
8484
unsigned long e);
8585
void (*unplug)(struct mddev *mddev, bool sync);
8686
void (*daemon_work)(struct mddev *mddev);
87+
88+
void (*start_behind_write)(struct mddev *mddev);
89+
void (*end_behind_write)(struct mddev *mddev);
8790
void (*wait_behind_writes)(struct mddev *mddev);
8891

8992
int (*startwrite)(struct mddev *mddev, sector_t offset,
90-
unsigned long sectors, bool behind);
93+
unsigned long sectors);
9194
void (*endwrite)(struct mddev *mddev, sector_t offset,
92-
unsigned long sectors, bool success, bool behind);
95+
unsigned long sectors);
9396
bool (*start_sync)(struct mddev *mddev, sector_t offset,
9497
sector_t *blocks, bool degraded);
9598
void (*end_sync)(struct mddev *mddev, sector_t offset, sector_t *blocks);

0 commit comments

Comments
 (0)