Skip to content

Commit 2073773

Browse files
committed
Merge branch 'md-next' into md-linus
2 parents b78b499 + 2953079 commit 2073773

File tree

16 files changed

+3429
-1262
lines changed

16 files changed

+3429
-1262
lines changed

drivers/md/bitmap.c

Lines changed: 98 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/mount.h>
2828
#include <linux/buffer_head.h>
2929
#include <linux/seq_file.h>
30+
#include <trace/events/block.h>
3031
#include "md.h"
3132
#include "bitmap.h"
3233

@@ -208,11 +209,13 @@ static struct md_rdev *next_active_rdev(struct md_rdev *rdev, struct mddev *mdde
208209

209210
static int write_sb_page(struct bitmap *bitmap, struct page *page, int wait)
210211
{
211-
struct md_rdev *rdev = NULL;
212+
struct md_rdev *rdev;
212213
struct block_device *bdev;
213214
struct mddev *mddev = bitmap->mddev;
214215
struct bitmap_storage *store = &bitmap->storage;
215216

217+
restart:
218+
rdev = NULL;
216219
while ((rdev = next_active_rdev(rdev, mddev)) != NULL) {
217220
int size = PAGE_SIZE;
218221
loff_t offset = mddev->bitmap_info.offset;
@@ -268,8 +271,8 @@ static int write_sb_page(struct bitmap *bitmap, struct page *page, int wait)
268271
page);
269272
}
270273

271-
if (wait)
272-
md_super_wait(mddev);
274+
if (wait && md_super_wait(mddev) < 0)
275+
goto restart;
273276
return 0;
274277

275278
bad_alignment:
@@ -405,17 +408,39 @@ static int read_page(struct file *file, unsigned long index,
405408
ret = -EIO;
406409
out:
407410
if (ret)
408-
printk(KERN_ALERT "md: bitmap read error: (%dB @ %llu): %d\n",
409-
(int)PAGE_SIZE,
410-
(unsigned long long)index << PAGE_SHIFT,
411-
ret);
411+
pr_err("md: bitmap read error: (%dB @ %llu): %d\n",
412+
(int)PAGE_SIZE,
413+
(unsigned long long)index << PAGE_SHIFT,
414+
ret);
412415
return ret;
413416
}
414417

415418
/*
416419
* bitmap file superblock operations
417420
*/
418421

422+
/*
423+
* bitmap_wait_writes() should be called before writing any bitmap
424+
* blocks, to ensure previous writes, particularly from
425+
* bitmap_daemon_work(), have completed.
426+
*/
427+
static void bitmap_wait_writes(struct bitmap *bitmap)
428+
{
429+
if (bitmap->storage.file)
430+
wait_event(bitmap->write_wait,
431+
atomic_read(&bitmap->pending_writes)==0);
432+
else
433+
/* Note that we ignore the return value. The writes
434+
* might have failed, but that would just mean that
435+
* some bits which should be cleared haven't been,
436+
* which is safe. The relevant bitmap blocks will
437+
* probably get written again, but there is no great
438+
* loss if they aren't.
439+
*/
440+
md_super_wait(bitmap->mddev);
441+
}
442+
443+
419444
/* update the event counter and sync the superblock to disk */
420445
void bitmap_update_sb(struct bitmap *bitmap)
421446
{
@@ -455,24 +480,24 @@ void bitmap_print_sb(struct bitmap *bitmap)
455480
if (!bitmap || !bitmap->storage.sb_page)
456481
return;
457482
sb = kmap_atomic(bitmap->storage.sb_page);
458-
printk(KERN_DEBUG "%s: bitmap file superblock:\n", bmname(bitmap));
459-
printk(KERN_DEBUG " magic: %08x\n", le32_to_cpu(sb->magic));
460-
printk(KERN_DEBUG " version: %d\n", le32_to_cpu(sb->version));
461-
printk(KERN_DEBUG " uuid: %08x.%08x.%08x.%08x\n",
462-
*(__u32 *)(sb->uuid+0),
463-
*(__u32 *)(sb->uuid+4),
464-
*(__u32 *)(sb->uuid+8),
465-
*(__u32 *)(sb->uuid+12));
466-
printk(KERN_DEBUG " events: %llu\n",
467-
(unsigned long long) le64_to_cpu(sb->events));
468-
printk(KERN_DEBUG "events cleared: %llu\n",
469-
(unsigned long long) le64_to_cpu(sb->events_cleared));
470-
printk(KERN_DEBUG " state: %08x\n", le32_to_cpu(sb->state));
471-
printk(KERN_DEBUG " chunksize: %d B\n", le32_to_cpu(sb->chunksize));
472-
printk(KERN_DEBUG " daemon sleep: %ds\n", le32_to_cpu(sb->daemon_sleep));
473-
printk(KERN_DEBUG " sync size: %llu KB\n",
474-
(unsigned long long)le64_to_cpu(sb->sync_size)/2);
475-
printk(KERN_DEBUG "max write behind: %d\n", le32_to_cpu(sb->write_behind));
483+
pr_debug("%s: bitmap file superblock:\n", bmname(bitmap));
484+
pr_debug(" magic: %08x\n", le32_to_cpu(sb->magic));
485+
pr_debug(" version: %d\n", le32_to_cpu(sb->version));
486+
pr_debug(" uuid: %08x.%08x.%08x.%08x\n",
487+
*(__u32 *)(sb->uuid+0),
488+
*(__u32 *)(sb->uuid+4),
489+
*(__u32 *)(sb->uuid+8),
490+
*(__u32 *)(sb->uuid+12));
491+
pr_debug(" events: %llu\n",
492+
(unsigned long long) le64_to_cpu(sb->events));
493+
pr_debug("events cleared: %llu\n",
494+
(unsigned long long) le64_to_cpu(sb->events_cleared));
495+
pr_debug(" state: %08x\n", le32_to_cpu(sb->state));
496+
pr_debug(" chunksize: %d B\n", le32_to_cpu(sb->chunksize));
497+
pr_debug(" daemon sleep: %ds\n", le32_to_cpu(sb->daemon_sleep));
498+
pr_debug(" sync size: %llu KB\n",
499+
(unsigned long long)le64_to_cpu(sb->sync_size)/2);
500+
pr_debug("max write behind: %d\n", le32_to_cpu(sb->write_behind));
476501
kunmap_atomic(sb);
477502
}
478503

@@ -506,14 +531,14 @@ static int bitmap_new_disk_sb(struct bitmap *bitmap)
506531
BUG_ON(!chunksize);
507532
if (!is_power_of_2(chunksize)) {
508533
kunmap_atomic(sb);
509-
printk(KERN_ERR "bitmap chunksize not a power of 2\n");
534+
pr_warn("bitmap chunksize not a power of 2\n");
510535
return -EINVAL;
511536
}
512537
sb->chunksize = cpu_to_le32(chunksize);
513538

514539
daemon_sleep = bitmap->mddev->bitmap_info.daemon_sleep;
515540
if (!daemon_sleep || (daemon_sleep > MAX_SCHEDULE_TIMEOUT)) {
516-
printk(KERN_INFO "Choosing daemon_sleep default (5 sec)\n");
541+
pr_debug("Choosing daemon_sleep default (5 sec)\n");
517542
daemon_sleep = 5 * HZ;
518543
}
519544
sb->daemon_sleep = cpu_to_le32(daemon_sleep);
@@ -584,7 +609,7 @@ static int bitmap_read_sb(struct bitmap *bitmap)
584609
/* to 4k blocks */
585610
bm_blocks = DIV_ROUND_UP_SECTOR_T(bm_blocks, 4096);
586611
offset = bitmap->mddev->bitmap_info.offset + (bitmap->cluster_slot * (bm_blocks << 3));
587-
pr_info("%s:%d bm slot: %d offset: %llu\n", __func__, __LINE__,
612+
pr_debug("%s:%d bm slot: %d offset: %llu\n", __func__, __LINE__,
588613
bitmap->cluster_slot, offset);
589614
}
590615

@@ -634,7 +659,7 @@ static int bitmap_read_sb(struct bitmap *bitmap)
634659
else if (write_behind > COUNTER_MAX)
635660
reason = "write-behind limit out of range (0 - 16383)";
636661
if (reason) {
637-
printk(KERN_INFO "%s: invalid bitmap file superblock: %s\n",
662+
pr_warn("%s: invalid bitmap file superblock: %s\n",
638663
bmname(bitmap), reason);
639664
goto out;
640665
}
@@ -648,18 +673,15 @@ static int bitmap_read_sb(struct bitmap *bitmap)
648673
* bitmap's UUID and event counter to the mddev's
649674
*/
650675
if (memcmp(sb->uuid, bitmap->mddev->uuid, 16)) {
651-
printk(KERN_INFO
652-
"%s: bitmap superblock UUID mismatch\n",
653-
bmname(bitmap));
676+
pr_warn("%s: bitmap superblock UUID mismatch\n",
677+
bmname(bitmap));
654678
goto out;
655679
}
656680
events = le64_to_cpu(sb->events);
657681
if (!nodes && (events < bitmap->mddev->events)) {
658-
printk(KERN_INFO
659-
"%s: bitmap file is out of date (%llu < %llu) "
660-
"-- forcing full recovery\n",
661-
bmname(bitmap), events,
662-
(unsigned long long) bitmap->mddev->events);
682+
pr_warn("%s: bitmap file is out of date (%llu < %llu) -- forcing full recovery\n",
683+
bmname(bitmap), events,
684+
(unsigned long long) bitmap->mddev->events);
663685
set_bit(BITMAP_STALE, &bitmap->flags);
664686
}
665687
}
@@ -679,8 +701,8 @@ static int bitmap_read_sb(struct bitmap *bitmap)
679701
if (err == 0 && nodes && (bitmap->cluster_slot < 0)) {
680702
err = md_setup_cluster(bitmap->mddev, nodes);
681703
if (err) {
682-
pr_err("%s: Could not setup cluster service (%d)\n",
683-
bmname(bitmap), err);
704+
pr_warn("%s: Could not setup cluster service (%d)\n",
705+
bmname(bitmap), err);
684706
goto out_no_sb;
685707
}
686708
bitmap->cluster_slot = md_cluster_ops->slot_number(bitmap->mddev);
@@ -847,15 +869,13 @@ static void bitmap_file_kick(struct bitmap *bitmap)
847869
ptr = file_path(bitmap->storage.file,
848870
path, PAGE_SIZE);
849871

850-
printk(KERN_ALERT
851-
"%s: kicking failed bitmap file %s from array!\n",
852-
bmname(bitmap), IS_ERR(ptr) ? "" : ptr);
872+
pr_warn("%s: kicking failed bitmap file %s from array!\n",
873+
bmname(bitmap), IS_ERR(ptr) ? "" : ptr);
853874

854875
kfree(path);
855876
} else
856-
printk(KERN_ALERT
857-
"%s: disabling internal bitmap due to errors\n",
858-
bmname(bitmap));
877+
pr_warn("%s: disabling internal bitmap due to errors\n",
878+
bmname(bitmap));
859879
}
860880
}
861881

@@ -983,6 +1003,7 @@ void bitmap_unplug(struct bitmap *bitmap)
9831003
{
9841004
unsigned long i;
9851005
int dirty, need_write;
1006+
int writing = 0;
9861007

9871008
if (!bitmap || !bitmap->storage.filemap ||
9881009
test_bit(BITMAP_STALE, &bitmap->flags))
@@ -997,15 +1018,19 @@ void bitmap_unplug(struct bitmap *bitmap)
9971018
need_write = test_and_clear_page_attr(bitmap, i,
9981019
BITMAP_PAGE_NEEDWRITE);
9991020
if (dirty || need_write) {
1021+
if (!writing) {
1022+
bitmap_wait_writes(bitmap);
1023+
if (bitmap->mddev->queue)
1024+
blk_add_trace_msg(bitmap->mddev->queue,
1025+
"md bitmap_unplug");
1026+
}
10001027
clear_page_attr(bitmap, i, BITMAP_PAGE_PENDING);
10011028
write_page(bitmap, bitmap->storage.filemap[i], 0);
1029+
writing = 1;
10021030
}
10031031
}
1004-
if (bitmap->storage.file)
1005-
wait_event(bitmap->write_wait,
1006-
atomic_read(&bitmap->pending_writes)==0);
1007-
else
1008-
md_super_wait(bitmap->mddev);
1032+
if (writing)
1033+
bitmap_wait_writes(bitmap);
10091034

10101035
if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags))
10111036
bitmap_file_kick(bitmap);
@@ -1056,14 +1081,13 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
10561081

10571082
outofdate = test_bit(BITMAP_STALE, &bitmap->flags);
10581083
if (outofdate)
1059-
printk(KERN_INFO "%s: bitmap file is out of date, doing full "
1060-
"recovery\n", bmname(bitmap));
1084+
pr_warn("%s: bitmap file is out of date, doing full recovery\n", bmname(bitmap));
10611085

10621086
if (file && i_size_read(file->f_mapping->host) < store->bytes) {
1063-
printk(KERN_INFO "%s: bitmap file too short %lu < %lu\n",
1064-
bmname(bitmap),
1065-
(unsigned long) i_size_read(file->f_mapping->host),
1066-
store->bytes);
1087+
pr_warn("%s: bitmap file too short %lu < %lu\n",
1088+
bmname(bitmap),
1089+
(unsigned long) i_size_read(file->f_mapping->host),
1090+
store->bytes);
10671091
goto err;
10681092
}
10691093

@@ -1137,16 +1161,15 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
11371161
offset = 0;
11381162
}
11391163

1140-
printk(KERN_INFO "%s: bitmap initialized from disk: "
1141-
"read %lu pages, set %lu of %lu bits\n",
1142-
bmname(bitmap), store->file_pages,
1143-
bit_cnt, chunks);
1164+
pr_debug("%s: bitmap initialized from disk: read %lu pages, set %lu of %lu bits\n",
1165+
bmname(bitmap), store->file_pages,
1166+
bit_cnt, chunks);
11441167

11451168
return 0;
11461169

11471170
err:
1148-
printk(KERN_INFO "%s: bitmap initialisation failed: %d\n",
1149-
bmname(bitmap), ret);
1171+
pr_warn("%s: bitmap initialisation failed: %d\n",
1172+
bmname(bitmap), ret);
11501173
return ret;
11511174
}
11521175

@@ -1225,6 +1248,10 @@ void bitmap_daemon_work(struct mddev *mddev)
12251248
}
12261249
bitmap->allclean = 1;
12271250

1251+
if (bitmap->mddev->queue)
1252+
blk_add_trace_msg(bitmap->mddev->queue,
1253+
"md bitmap_daemon_work");
1254+
12281255
/* Any file-page which is PENDING now needs to be written.
12291256
* So set NEEDWRITE now, then after we make any last-minute changes
12301257
* we will write it.
@@ -1289,6 +1316,7 @@ void bitmap_daemon_work(struct mddev *mddev)
12891316
}
12901317
spin_unlock_irq(&counts->lock);
12911318

1319+
bitmap_wait_writes(bitmap);
12921320
/* Now start writeout on any page in NEEDWRITE that isn't DIRTY.
12931321
* DIRTY pages need to be written by bitmap_unplug so it can wait
12941322
* for them.
@@ -1595,7 +1623,7 @@ void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector, bool force)
15951623
atomic_read(&bitmap->mddev->recovery_active) == 0);
15961624

15971625
bitmap->mddev->curr_resync_completed = sector;
1598-
set_bit(MD_CHANGE_CLEAN, &bitmap->mddev->flags);
1626+
set_bit(MD_SB_CHANGE_CLEAN, &bitmap->mddev->sb_flags);
15991627
sector &= ~((1ULL << bitmap->counts.chunkshift) - 1);
16001628
s = 0;
16011629
while (s < sector && s < bitmap->mddev->resync_max_sectors) {
@@ -1825,8 +1853,8 @@ struct bitmap *bitmap_create(struct mddev *mddev, int slot)
18251853
if (err)
18261854
goto error;
18271855

1828-
printk(KERN_INFO "created bitmap (%lu pages) for device %s\n",
1829-
bitmap->counts.pages, bmname(bitmap));
1856+
pr_debug("created bitmap (%lu pages) for device %s\n",
1857+
bitmap->counts.pages, bmname(bitmap));
18301858

18311859
err = test_bit(BITMAP_WRITE_ERROR, &bitmap->flags) ? -EIO : 0;
18321860
if (err)
@@ -2029,8 +2057,10 @@ int bitmap_resize(struct bitmap *bitmap, sector_t blocks,
20292057
!bitmap->mddev->bitmap_info.external,
20302058
mddev_is_clustered(bitmap->mddev)
20312059
? bitmap->cluster_slot : 0);
2032-
if (ret)
2060+
if (ret) {
2061+
bitmap_file_unmap(&store);
20332062
goto err;
2063+
}
20342064

20352065
pages = DIV_ROUND_UP(chunks, PAGE_COUNTER_RATIO);
20362066

@@ -2089,7 +2119,7 @@ int bitmap_resize(struct bitmap *bitmap, sector_t blocks,
20892119
bitmap->mddev->bitmap_info.chunksize = 1 << (old_counts.chunkshift +
20902120
BITMAP_BLOCK_SHIFT);
20912121
blocks = old_counts.chunks << old_counts.chunkshift;
2092-
pr_err("Could not pre-allocate in-memory bitmap for cluster raid\n");
2122+
pr_warn("Could not pre-allocate in-memory bitmap for cluster raid\n");
20932123
break;
20942124
} else
20952125
bitmap->counts.bp[page].count += 1;
@@ -2266,7 +2296,7 @@ location_store(struct mddev *mddev, const char *buf, size_t len)
22662296
/* Ensure new bitmap info is stored in
22672297
* metadata promptly.
22682298
*/
2269-
set_bit(MD_CHANGE_DEVS, &mddev->flags);
2299+
set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
22702300
md_wakeup_thread(mddev->thread);
22712301
}
22722302
rv = 0;

drivers/md/dm-raid.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,7 +2011,7 @@ static int super_load(struct md_rdev *rdev, struct md_rdev *refdev)
20112011
sb->compat_features = cpu_to_le32(FEATURE_FLAG_SUPPORTS_V190);
20122012

20132013
/* Force writing of superblocks to disk */
2014-
set_bit(MD_CHANGE_DEVS, &rdev->mddev->flags);
2014+
set_bit(MD_SB_CHANGE_DEVS, &rdev->mddev->sb_flags);
20152015

20162016
/* Any superblock is better than none, choose that if given */
20172017
return refdev ? 0 : 1;
@@ -3497,7 +3497,7 @@ static void rs_update_sbs(struct raid_set *rs)
34973497
struct mddev *mddev = &rs->md;
34983498
int ro = mddev->ro;
34993499

3500-
set_bit(MD_CHANGE_DEVS, &mddev->flags);
3500+
set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
35013501
mddev->ro = 0;
35023502
md_update_sb(mddev, 1);
35033503
mddev->ro = ro;

0 commit comments

Comments
 (0)