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

Merge tag 'md/4.3' of git://neil.brown.name/md

Pull md updates from Neil Brown:

- an assortment of little fixes, several for minor races only likely to
be hit during testing

- further cluster-md-raid1 development, not ready for real use yet.

- new RAID6 syndrome code for ARM NEON

- fix a race where a write can return before failure of one device is
properly recorded in metadata, so an immediate crash might result in
that write being lost.

* tag 'md/4.3' of git://neil.brown.name/md: (33 commits)
md/raid5: ensure device failure recorded before write request returns.
md/raid5: use bio_list for the list of bios to return.
md/raid10: ensure device failure recorded before write request returns.
md/raid1: ensure device failure recorded before write request returns.
md-cluster: remove inappropriate try_module_get from join()
md: extend spinlock protection in register_md_cluster_operations
md-cluster: Read the disk bitmap sb and check if it needs recovery
md-cluster: only call complete(&cinfo->completion) when node join cluster
md-cluster: add missed lockres_free
md-cluster: remove the unused sb_lock
md-cluster: init suspend_list and suspend_lock early in join
md-cluster: add the error check if failed to get dlm lock
md-cluster: init completion within lockres_init
md-cluster: fix deadlock issue on message lock
md-cluster: transfer the resync ownership to another node
md-cluster: split recover_slot for future code reuse
md-cluster: use %pU to print UUIDs
md: setup safemode_timer before it's being used
md/raid5: handle possible race as reshape completes.
md: sync sync_completed has correct value as recovery finishes.
...

+433 -193
+2 -2
Documentation/md-cluster.txt
··· 91 91 this message inappropriate or redundant. 92 92 93 93 3. sender write LVB. 94 - sender down-convert MESSAGE from EX to CR 94 + sender down-convert MESSAGE from EX to CW 95 95 sender try to get EX of ACK 96 96 [ wait until all receiver has *processed* the MESSAGE ] 97 97 ··· 112 112 sender down-convert ACK from EX to CR 113 113 sender release MESSAGE 114 114 sender release TOKEN 115 - receiver upconvert to EX of MESSAGE 115 + receiver upconvert to PR of MESSAGE 116 116 receiver get CR of ACK 117 117 receiver release MESSAGE 118 118
+105 -54
drivers/md/md-cluster.c
··· 45 45 /* md_cluster_info flags */ 46 46 #define MD_CLUSTER_WAITING_FOR_NEWDISK 1 47 47 #define MD_CLUSTER_SUSPEND_READ_BALANCING 2 48 + #define MD_CLUSTER_BEGIN_JOIN_CLUSTER 3 48 49 49 50 50 51 struct md_cluster_info { ··· 53 52 dlm_lockspace_t *lockspace; 54 53 int slot_number; 55 54 struct completion completion; 56 - struct dlm_lock_resource *sb_lock; 57 55 struct mutex sb_mutex; 58 56 struct dlm_lock_resource *bitmap_lockres; 59 57 struct list_head suspend_list; ··· 75 75 NEWDISK, 76 76 REMOVE, 77 77 RE_ADD, 78 + BITMAP_NEEDS_SYNC, 78 79 }; 79 80 80 81 struct cluster_msg { ··· 100 99 { 101 100 int ret = 0; 102 101 103 - init_completion(&res->completion); 104 102 ret = dlm_lock(res->ls, mode, &res->lksb, 105 103 res->flags, res->name, strlen(res->name), 106 104 0, sync_ast, res, res->bast); ··· 124 124 res = kzalloc(sizeof(struct dlm_lock_resource), GFP_KERNEL); 125 125 if (!res) 126 126 return NULL; 127 + init_completion(&res->completion); 127 128 res->ls = cinfo->lockspace; 128 129 res->mddev = mddev; 129 130 namelen = strlen(name); ··· 166 165 167 166 static void lockres_free(struct dlm_lock_resource *res) 168 167 { 168 + int ret; 169 + 169 170 if (!res) 170 171 return; 171 172 172 - init_completion(&res->completion); 173 - dlm_unlock(res->ls, res->lksb.sb_lkid, 0, &res->lksb, res); 173 + /* cancel a lock request or a conversion request that is blocked */ 174 + res->flags |= DLM_LKF_CANCEL; 175 + retry: 176 + ret = dlm_unlock(res->ls, res->lksb.sb_lkid, 0, &res->lksb, res); 177 + if (unlikely(ret != 0)) { 178 + pr_info("%s: failed to unlock %s return %d\n", __func__, res->name, ret); 179 + 180 + /* if a lock conversion is cancelled, then the lock is put 181 + * back to grant queue, need to ensure it is unlocked */ 182 + if (ret == -DLM_ECANCEL) 183 + goto retry; 184 + } 185 + res->flags &= ~DLM_LKF_CANCEL; 174 186 wait_for_completion(&res->completion); 175 187 176 188 kfree(res->name); 177 189 kfree(res->lksb.sb_lvbptr); 178 190 kfree(res); 179 - } 180 - 181 - static char *pretty_uuid(char *dest, char *src) 182 - { 183 - int i, len = 0; 184 - 185 - for (i = 0; i < 16; i++) { 186 - if (i == 4 || i == 6 || i == 8 || i == 10) 187 - len += sprintf(dest + len, "-"); 188 - len += sprintf(dest + len, "%02x", (__u8)src[i]); 189 - } 190 - return dest; 191 191 } 192 192 193 193 static void add_resync_info(struct mddev *mddev, struct dlm_lock_resource *lockres, ··· 283 281 set_bit(MD_CLUSTER_SUSPEND_READ_BALANCING, &cinfo->state); 284 282 } 285 283 286 - static void recover_slot(void *arg, struct dlm_slot *slot) 284 + static void __recover_slot(struct mddev *mddev, int slot) 287 285 { 288 - struct mddev *mddev = arg; 289 286 struct md_cluster_info *cinfo = mddev->cluster_info; 290 287 291 - pr_info("md-cluster: %s Node %d/%d down. My slot: %d. Initiating recovery.\n", 292 - mddev->bitmap_info.cluster_name, 293 - slot->nodeid, slot->slot, 294 - cinfo->slot_number); 295 - set_bit(slot->slot - 1, &cinfo->recovery_map); 288 + set_bit(slot, &cinfo->recovery_map); 296 289 if (!cinfo->recovery_thread) { 297 290 cinfo->recovery_thread = md_register_thread(recover_bitmaps, 298 291 mddev, "recover"); ··· 299 302 md_wakeup_thread(cinfo->recovery_thread); 300 303 } 301 304 305 + static void recover_slot(void *arg, struct dlm_slot *slot) 306 + { 307 + struct mddev *mddev = arg; 308 + struct md_cluster_info *cinfo = mddev->cluster_info; 309 + 310 + pr_info("md-cluster: %s Node %d/%d down. My slot: %d. Initiating recovery.\n", 311 + mddev->bitmap_info.cluster_name, 312 + slot->nodeid, slot->slot, 313 + cinfo->slot_number); 314 + /* deduct one since dlm slot starts from one while the num of 315 + * cluster-md begins with 0 */ 316 + __recover_slot(mddev, slot->slot - 1); 317 + } 318 + 302 319 static void recover_done(void *arg, struct dlm_slot *slots, 303 320 int num_slots, int our_slot, 304 321 uint32_t generation) ··· 321 310 struct md_cluster_info *cinfo = mddev->cluster_info; 322 311 323 312 cinfo->slot_number = our_slot; 324 - complete(&cinfo->completion); 313 + /* completion is only need to be complete when node join cluster, 314 + * it doesn't need to run during another node's failure */ 315 + if (test_bit(MD_CLUSTER_BEGIN_JOIN_CLUSTER, &cinfo->state)) { 316 + complete(&cinfo->completion); 317 + clear_bit(MD_CLUSTER_BEGIN_JOIN_CLUSTER, &cinfo->state); 318 + } 325 319 clear_bit(MD_CLUSTER_SUSPEND_READ_BALANCING, &cinfo->state); 326 320 } 327 321 322 + /* the ops is called when node join the cluster, and do lock recovery 323 + * if node failure occurs */ 328 324 static const struct dlm_lockspace_ops md_ls_ops = { 329 325 .recover_prep = recover_prep, 330 326 .recover_slot = recover_slot, ··· 406 388 int len; 407 389 408 390 len = snprintf(disk_uuid, 64, "DEVICE_UUID="); 409 - pretty_uuid(disk_uuid + len, cmsg->uuid); 391 + sprintf(disk_uuid + len, "%pU", cmsg->uuid); 410 392 snprintf(raid_slot, 16, "RAID_DISK=%d", cmsg->raid_slot); 411 393 pr_info("%s:%d Sending kobject change with %s and %s\n", __func__, __LINE__, disk_uuid, raid_slot); 412 394 init_completion(&cinfo->newdisk_completion); ··· 475 457 __func__, __LINE__, msg->slot); 476 458 process_readd_disk(mddev, msg); 477 459 break; 460 + case BITMAP_NEEDS_SYNC: 461 + pr_info("%s: %d Received BITMAP_NEEDS_SYNC from %d\n", 462 + __func__, __LINE__, msg->slot); 463 + __recover_slot(mddev, msg->slot); 464 + break; 478 465 default: 479 466 pr_warn("%s:%d Received unknown message from %d\n", 480 467 __func__, __LINE__, msg->slot); ··· 495 472 struct dlm_lock_resource *ack_lockres = cinfo->ack_lockres; 496 473 struct dlm_lock_resource *message_lockres = cinfo->message_lockres; 497 474 struct cluster_msg msg; 475 + int ret; 498 476 499 477 /*get CR on Message*/ 500 478 if (dlm_lock_sync(message_lockres, DLM_LOCK_CR)) { ··· 508 484 process_recvd_msg(thread->mddev, &msg); 509 485 510 486 /*release CR on ack_lockres*/ 511 - dlm_unlock_sync(ack_lockres); 512 - /*up-convert to EX on message_lockres*/ 513 - dlm_lock_sync(message_lockres, DLM_LOCK_EX); 487 + ret = dlm_unlock_sync(ack_lockres); 488 + if (unlikely(ret != 0)) 489 + pr_info("unlock ack failed return %d\n", ret); 490 + /*up-convert to PR on message_lockres*/ 491 + ret = dlm_lock_sync(message_lockres, DLM_LOCK_PR); 492 + if (unlikely(ret != 0)) 493 + pr_info("lock PR on msg failed return %d\n", ret); 514 494 /*get CR on ack_lockres again*/ 515 - dlm_lock_sync(ack_lockres, DLM_LOCK_CR); 495 + ret = dlm_lock_sync(ack_lockres, DLM_LOCK_CR); 496 + if (unlikely(ret != 0)) 497 + pr_info("lock CR on ack failed return %d\n", ret); 516 498 /*release CR on message_lockres*/ 517 - dlm_unlock_sync(message_lockres); 499 + ret = dlm_unlock_sync(message_lockres); 500 + if (unlikely(ret != 0)) 501 + pr_info("unlock msg failed return %d\n", ret); 518 502 } 519 503 520 504 /* lock_comm() ··· 551 519 * The function: 552 520 * 1. Grabs the message lockresource in EX mode 553 521 * 2. Copies the message to the message LVB 554 - * 3. Downconverts message lockresource to CR 522 + * 3. Downconverts message lockresource to CW 555 523 * 4. Upconverts ack lock resource from CR to EX. This forces the BAST on other nodes 556 524 * and the other nodes read the message. The thread will wait here until all other 557 525 * nodes have released ack lock resource. ··· 572 540 573 541 memcpy(cinfo->message_lockres->lksb.sb_lvbptr, (void *)cmsg, 574 542 sizeof(struct cluster_msg)); 575 - /*down-convert EX to CR on Message*/ 576 - error = dlm_lock_sync(cinfo->message_lockres, DLM_LOCK_CR); 543 + /*down-convert EX to CW on Message*/ 544 + error = dlm_lock_sync(cinfo->message_lockres, DLM_LOCK_CW); 577 545 if (error) { 578 - pr_err("md-cluster: failed to convert EX to CR on MESSAGE(%d)\n", 546 + pr_err("md-cluster: failed to convert EX to CW on MESSAGE(%d)\n", 579 547 error); 580 - goto failed_message; 548 + goto failed_ack; 581 549 } 582 550 583 551 /*up-convert CR to EX on Ack*/ ··· 597 565 } 598 566 599 567 failed_ack: 600 - dlm_unlock_sync(cinfo->message_lockres); 568 + error = dlm_unlock_sync(cinfo->message_lockres); 569 + if (unlikely(error != 0)) { 570 + pr_err("md-cluster: failed convert to NL on MESSAGE(%d)\n", 571 + error); 572 + /* in case the message can't be released due to some reason */ 573 + goto failed_ack; 574 + } 601 575 failed_message: 602 576 return error; 603 577 } ··· 625 587 struct dlm_lock_resource *bm_lockres; 626 588 struct suspend_info *s; 627 589 char str[64]; 590 + sector_t lo, hi; 628 591 629 592 630 593 for (i = 0; i < total_slots; i++) { ··· 656 617 lockres_free(bm_lockres); 657 618 continue; 658 619 } 659 - if (ret) 620 + if (ret) { 621 + lockres_free(bm_lockres); 660 622 goto out; 661 - /* TODO: Read the disk bitmap sb and check if it needs recovery */ 623 + } 624 + 625 + /* Read the disk bitmap sb and check if it needs recovery */ 626 + ret = bitmap_copy_from_slot(mddev, i, &lo, &hi, false); 627 + if (ret) { 628 + pr_warn("md-cluster: Could not gather bitmaps from slot %d", i); 629 + lockres_free(bm_lockres); 630 + continue; 631 + } 632 + if ((hi > 0) && (lo < mddev->recovery_cp)) { 633 + set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 634 + mddev->recovery_cp = lo; 635 + md_check_recovery(mddev); 636 + } 637 + 662 638 dlm_unlock_sync(bm_lockres); 663 639 lockres_free(bm_lockres); 664 640 } ··· 687 633 int ret, ops_rv; 688 634 char str[64]; 689 635 690 - if (!try_module_get(THIS_MODULE)) 691 - return -ENOENT; 692 - 693 636 cinfo = kzalloc(sizeof(struct md_cluster_info), GFP_KERNEL); 694 637 if (!cinfo) 695 638 return -ENOMEM; 696 639 640 + INIT_LIST_HEAD(&cinfo->suspend_list); 641 + spin_lock_init(&cinfo->suspend_lock); 697 642 init_completion(&cinfo->completion); 643 + set_bit(MD_CLUSTER_BEGIN_JOIN_CLUSTER, &cinfo->state); 698 644 699 645 mutex_init(&cinfo->sb_mutex); 700 646 mddev->cluster_info = cinfo; 701 647 702 648 memset(str, 0, 64); 703 - pretty_uuid(str, mddev->uuid); 649 + sprintf(str, "%pU", mddev->uuid); 704 650 ret = dlm_new_lockspace(str, mddev->bitmap_info.cluster_name, 705 651 DLM_LSFL_FS, LVB_SIZE, 706 652 &md_ls_ops, mddev, &ops_rv, &cinfo->lockspace); ··· 711 657 pr_err("md-cluster: Slot allotted(%d) is greater than available slots(%d).", 712 658 cinfo->slot_number, nodes); 713 659 ret = -ERANGE; 714 - goto err; 715 - } 716 - cinfo->sb_lock = lockres_init(mddev, "cmd-super", 717 - NULL, 0); 718 - if (!cinfo->sb_lock) { 719 - ret = -ENOMEM; 720 660 goto err; 721 661 } 722 662 /* Initiate the communication resources */ ··· 753 705 goto err; 754 706 } 755 707 756 - INIT_LIST_HEAD(&cinfo->suspend_list); 757 - spin_lock_init(&cinfo->suspend_lock); 758 - 759 708 ret = gather_all_resync_info(mddev, nodes); 760 709 if (ret) 761 710 goto err; ··· 764 719 lockres_free(cinfo->ack_lockres); 765 720 lockres_free(cinfo->no_new_dev_lockres); 766 721 lockres_free(cinfo->bitmap_lockres); 767 - lockres_free(cinfo->sb_lock); 768 722 if (cinfo->lockspace) 769 723 dlm_release_lockspace(cinfo->lockspace, 2); 770 724 mddev->cluster_info = NULL; 771 725 kfree(cinfo); 772 - module_put(THIS_MODULE); 773 726 return ret; 774 727 } 775 728 ··· 783 740 lockres_free(cinfo->token_lockres); 784 741 lockres_free(cinfo->ack_lockres); 785 742 lockres_free(cinfo->no_new_dev_lockres); 786 - lockres_free(cinfo->sb_lock); 787 743 lockres_free(cinfo->bitmap_lockres); 788 744 dlm_release_lockspace(cinfo->lockspace, 2); 789 745 return 0; ··· 859 817 860 818 static void resync_finish(struct mddev *mddev) 861 819 { 820 + struct md_cluster_info *cinfo = mddev->cluster_info; 821 + struct cluster_msg cmsg; 822 + int slot = cinfo->slot_number - 1; 823 + 862 824 pr_info("%s:%d\n", __func__, __LINE__); 863 825 resync_send(mddev, RESYNCING, 0, 0); 826 + if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { 827 + cmsg.type = cpu_to_le32(BITMAP_NEEDS_SYNC); 828 + cmsg.slot = cpu_to_le32(slot); 829 + sendmsg(cinfo, &cmsg); 830 + } 864 831 } 865 832 866 833 static int area_resyncing(struct mddev *mddev, int direction,
+71 -39
drivers/md/md.c
··· 483 483 bioset_free(bs); 484 484 } 485 485 486 + static void md_safemode_timeout(unsigned long data); 487 + 486 488 void mddev_init(struct mddev *mddev) 487 489 { 488 490 mutex_init(&mddev->open_mutex); ··· 492 490 mutex_init(&mddev->bitmap_info.mutex); 493 491 INIT_LIST_HEAD(&mddev->disks); 494 492 INIT_LIST_HEAD(&mddev->all_mddevs); 495 - init_timer(&mddev->safemode_timer); 493 + setup_timer(&mddev->safemode_timer, md_safemode_timeout, 494 + (unsigned long) mddev); 496 495 atomic_set(&mddev->active, 1); 497 496 atomic_set(&mddev->openers, 0); 498 497 atomic_set(&mddev->active_io, 0); ··· 3258 3255 return 0; 3259 3256 } 3260 3257 3261 - static void md_safemode_timeout(unsigned long data); 3262 - 3263 3258 static ssize_t 3264 3259 safe_delay_show(struct mddev *mddev, char *page) 3265 3260 { ··· 4190 4189 type = "repair"; 4191 4190 } else if (test_bit(MD_RECOVERY_RECOVER, &recovery)) 4192 4191 type = "recover"; 4192 + else if (mddev->reshape_position != MaxSector) 4193 + type = "reshape"; 4193 4194 } 4194 4195 return sprintf(page, "%s\n", type); 4195 4196 } ··· 5183 5180 atomic_set(&mddev->max_corr_read_errors, 5184 5181 MD_DEFAULT_MAX_CORRECTED_READ_ERRORS); 5185 5182 mddev->safemode = 0; 5186 - mddev->safemode_timer.function = md_safemode_timeout; 5187 - mddev->safemode_timer.data = (unsigned long) mddev; 5188 5183 mddev->safemode_delay = (200 * HZ)/1000 +1; /* 200 msec delay */ 5189 5184 mddev->in_sync = 1; 5190 5185 smp_wmb(); ··· 5195 5194 if (sysfs_link_rdev(mddev, rdev)) 5196 5195 /* failure here is OK */; 5197 5196 5197 + if (mddev->degraded && !mddev->ro) 5198 + /* This ensures that recovering status is reported immediately 5199 + * via sysfs - until a lack of spares is confirmed. 5200 + */ 5201 + set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); 5198 5202 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 5199 5203 5200 5204 if (mddev->flags & MD_UPDATE_SB_FLAGS) ··· 5747 5741 5748 5742 err = 0; 5749 5743 spin_lock(&mddev->lock); 5750 - /* bitmap disabled, zero the first byte and copy out */ 5751 - if (!mddev->bitmap_info.file) 5752 - file->pathname[0] = '\0'; 5753 - else if ((ptr = file_path(mddev->bitmap_info.file, 5754 - file->pathname, sizeof(file->pathname))), 5755 - IS_ERR(ptr)) 5756 - err = PTR_ERR(ptr); 5757 - else 5758 - memmove(file->pathname, ptr, 5759 - sizeof(file->pathname)-(ptr-file->pathname)); 5744 + /* bitmap enabled */ 5745 + if (mddev->bitmap_info.file) { 5746 + ptr = file_path(mddev->bitmap_info.file, file->pathname, 5747 + sizeof(file->pathname)); 5748 + if (IS_ERR(ptr)) 5749 + err = PTR_ERR(ptr); 5750 + else 5751 + memmove(file->pathname, ptr, 5752 + sizeof(file->pathname)-(ptr-file->pathname)); 5753 + } 5760 5754 spin_unlock(&mddev->lock); 5761 5755 5762 5756 if (err == 0 && ··· 7075 7069 seq_printf(seq, "\n"); 7076 7070 } 7077 7071 7078 - static void status_resync(struct seq_file *seq, struct mddev *mddev) 7072 + static int status_resync(struct seq_file *seq, struct mddev *mddev) 7079 7073 { 7080 7074 sector_t max_sectors, resync, res; 7081 7075 unsigned long dt, db; ··· 7083 7077 int scale; 7084 7078 unsigned int per_milli; 7085 7079 7086 - if (mddev->curr_resync <= 3) 7087 - resync = 0; 7088 - else 7089 - resync = mddev->curr_resync 7090 - - atomic_read(&mddev->recovery_active); 7091 - 7092 7080 if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery) || 7093 7081 test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) 7094 7082 max_sectors = mddev->resync_max_sectors; 7095 7083 else 7096 7084 max_sectors = mddev->dev_sectors; 7085 + 7086 + resync = mddev->curr_resync; 7087 + if (resync <= 3) { 7088 + if (test_bit(MD_RECOVERY_DONE, &mddev->recovery)) 7089 + /* Still cleaning up */ 7090 + resync = max_sectors; 7091 + } else 7092 + resync -= atomic_read(&mddev->recovery_active); 7093 + 7094 + if (resync == 0) { 7095 + if (mddev->recovery_cp < MaxSector) { 7096 + seq_printf(seq, "\tresync=PENDING"); 7097 + return 1; 7098 + } 7099 + return 0; 7100 + } 7101 + if (resync < 3) { 7102 + seq_printf(seq, "\tresync=DELAYED"); 7103 + return 1; 7104 + } 7097 7105 7098 7106 WARN_ON(max_sectors == 0); 7099 7107 /* Pick 'scale' such that (resync>>scale)*1000 will fit ··· 7173 7153 ((unsigned long)rt % 60)/6); 7174 7154 7175 7155 seq_printf(seq, " speed=%ldK/sec", db/2/dt); 7156 + return 1; 7176 7157 } 7177 7158 7178 7159 static void *md_seq_start(struct seq_file *seq, loff_t *pos) ··· 7319 7298 mddev->pers->status(seq, mddev); 7320 7299 seq_printf(seq, "\n "); 7321 7300 if (mddev->pers->sync_request) { 7322 - if (mddev->curr_resync > 2) { 7323 - status_resync(seq, mddev); 7301 + if (status_resync(seq, mddev)) 7324 7302 seq_printf(seq, "\n "); 7325 - } else if (mddev->curr_resync >= 1) 7326 - seq_printf(seq, "\tresync=DELAYED\n "); 7327 - else if (mddev->recovery_cp < MaxSector) 7328 - seq_printf(seq, "\tresync=PENDING\n "); 7329 7303 } 7330 7304 } else 7331 7305 seq_printf(seq, "\n "); ··· 7403 7387 } 7404 7388 EXPORT_SYMBOL(unregister_md_personality); 7405 7389 7406 - int register_md_cluster_operations(struct md_cluster_operations *ops, struct module *module) 7390 + int register_md_cluster_operations(struct md_cluster_operations *ops, 7391 + struct module *module) 7407 7392 { 7408 - if (md_cluster_ops != NULL) 7409 - return -EALREADY; 7393 + int ret = 0; 7410 7394 spin_lock(&pers_lock); 7411 - md_cluster_ops = ops; 7412 - md_cluster_mod = module; 7395 + if (md_cluster_ops != NULL) 7396 + ret = -EALREADY; 7397 + else { 7398 + md_cluster_ops = ops; 7399 + md_cluster_mod = module; 7400 + } 7413 7401 spin_unlock(&pers_lock); 7414 - return 0; 7402 + return ret; 7415 7403 } 7416 7404 EXPORT_SYMBOL(register_md_cluster_operations); 7417 7405 ··· 7813 7793 > (max_sectors >> 4)) || 7814 7794 time_after_eq(jiffies, update_time + UPDATE_FREQUENCY) || 7815 7795 (j - mddev->curr_resync_completed)*2 7816 - >= mddev->resync_max - mddev->curr_resync_completed 7796 + >= mddev->resync_max - mddev->curr_resync_completed || 7797 + mddev->curr_resync_completed > mddev->resync_max 7817 7798 )) { 7818 7799 /* time to update curr_resync_completed */ 7819 7800 wait_event(mddev->recovery_wait, ··· 7859 7838 break; 7860 7839 7861 7840 j += sectors; 7841 + if (j > max_sectors) 7842 + /* when skipping, extra large numbers can be returned. */ 7843 + j = max_sectors; 7862 7844 if (j > 2) 7863 7845 mddev->curr_resync = j; 7864 7846 if (mddev_is_clustered(mddev)) ··· 7930 7906 blk_finish_plug(&plug); 7931 7907 wait_event(mddev->recovery_wait, !atomic_read(&mddev->recovery_active)); 7932 7908 7909 + if (!test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) && 7910 + !test_bit(MD_RECOVERY_INTR, &mddev->recovery) && 7911 + mddev->curr_resync > 2) { 7912 + mddev->curr_resync_completed = mddev->curr_resync; 7913 + sysfs_notify(&mddev->kobj, NULL, "sync_completed"); 7914 + } 7933 7915 /* tell personality that we are finished */ 7934 7916 mddev->pers->sync_request(mddev, max_sectors, &skipped); 7935 - 7936 - if (mddev_is_clustered(mddev)) 7937 - md_cluster_ops->resync_finish(mddev); 7938 7917 7939 7918 if (!test_bit(MD_RECOVERY_CHECK, &mddev->recovery) && 7940 7919 mddev->curr_resync > 2) { ··· 7972 7945 } 7973 7946 } 7974 7947 skip: 7948 + if (mddev_is_clustered(mddev)) 7949 + md_cluster_ops->resync_finish(mddev); 7950 + 7975 7951 set_bit(MD_CHANGE_DEVS, &mddev->flags); 7976 7952 7977 7953 spin_lock(&mddev->lock); ··· 7985 7955 mddev->resync_max = MaxSector; 7986 7956 } else if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) 7987 7957 mddev->resync_min = mddev->curr_resync_completed; 7958 + set_bit(MD_RECOVERY_DONE, &mddev->recovery); 7988 7959 mddev->curr_resync = 0; 7989 7960 spin_unlock(&mddev->lock); 7990 7961 7991 7962 wake_up(&resync_wait); 7992 - set_bit(MD_RECOVERY_DONE, &mddev->recovery); 7993 7963 md_wakeup_thread(mddev->thread); 7994 7964 return; 7995 7965 } ··· 8158 8128 */ 8159 8129 set_bit(MD_RECOVERY_INTR, &mddev->recovery); 8160 8130 md_reap_sync_thread(mddev); 8131 + clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery); 8161 8132 clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 8162 8133 goto unlock; 8163 8134 } ··· 8605 8574 /* Make sure they get written out promptly */ 8606 8575 sysfs_notify_dirent_safe(rdev->sysfs_state); 8607 8576 set_bit(MD_CHANGE_CLEAN, &rdev->mddev->flags); 8577 + set_bit(MD_CHANGE_PENDING, &rdev->mddev->flags); 8608 8578 md_wakeup_thread(rdev->mddev->thread); 8609 8579 } 8610 8580 return rv;
+39 -36
drivers/md/raid0.c
··· 83 83 char b[BDEVNAME_SIZE]; 84 84 char b2[BDEVNAME_SIZE]; 85 85 struct r0conf *conf = kzalloc(sizeof(*conf), GFP_KERNEL); 86 - bool discard_supported = false; 86 + unsigned short blksize = 512; 87 87 88 88 if (!conf) 89 89 return -ENOMEM; ··· 97 97 sectors = rdev1->sectors; 98 98 sector_div(sectors, mddev->chunk_sectors); 99 99 rdev1->sectors = sectors * mddev->chunk_sectors; 100 + 101 + blksize = max(blksize, queue_logical_block_size( 102 + rdev1->bdev->bd_disk->queue)); 100 103 101 104 rdev_for_each(rdev2, mddev) { 102 105 pr_debug("md/raid0:%s: comparing %s(%llu)" ··· 137 134 } 138 135 pr_debug("md/raid0:%s: FINAL %d zones\n", 139 136 mdname(mddev), conf->nr_strip_zones); 137 + /* 138 + * now since we have the hard sector sizes, we can make sure 139 + * chunk size is a multiple of that sector size 140 + */ 141 + if ((mddev->chunk_sectors << 9) % blksize) { 142 + printk(KERN_ERR "md/raid0:%s: chunk_size of %d not multiple of block size %d\n", 143 + mdname(mddev), 144 + mddev->chunk_sectors << 9, blksize); 145 + err = -EINVAL; 146 + goto abort; 147 + } 148 + 140 149 err = -ENOMEM; 141 150 conf->strip_zone = kzalloc(sizeof(struct strip_zone)* 142 151 conf->nr_strip_zones, GFP_KERNEL); ··· 203 188 } 204 189 dev[j] = rdev1; 205 190 206 - if (mddev->queue) 207 - disk_stack_limits(mddev->gendisk, rdev1->bdev, 208 - rdev1->data_offset << 9); 209 - 210 191 if (!smallest || (rdev1->sectors < smallest->sectors)) 211 192 smallest = rdev1; 212 193 cnt++; 213 - 214 - if (blk_queue_discard(bdev_get_queue(rdev1->bdev))) 215 - discard_supported = true; 216 194 } 217 195 if (cnt != mddev->raid_disks) { 218 196 printk(KERN_ERR "md/raid0:%s: too few disks (%d of %d) - " ··· 264 256 pr_debug("md/raid0:%s: current zone start: %llu\n", 265 257 mdname(mddev), 266 258 (unsigned long long)smallest->sectors); 267 - } 268 - 269 - /* 270 - * now since we have the hard sector sizes, we can make sure 271 - * chunk size is a multiple of that sector size 272 - */ 273 - if ((mddev->chunk_sectors << 9) % queue_logical_block_size(mddev->queue)) { 274 - printk(KERN_ERR "md/raid0:%s: chunk_size of %d not valid\n", 275 - mdname(mddev), 276 - mddev->chunk_sectors << 9); 277 - goto abort; 278 - } 279 - 280 - if (mddev->queue) { 281 - blk_queue_io_min(mddev->queue, mddev->chunk_sectors << 9); 282 - blk_queue_io_opt(mddev->queue, 283 - (mddev->chunk_sectors << 9) * mddev->raid_disks); 284 - 285 - if (!discard_supported) 286 - queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, mddev->queue); 287 - else 288 - queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, mddev->queue); 289 259 } 290 260 291 261 pr_debug("md/raid0:%s: done.\n", mdname(mddev)); ··· 364 378 if (md_check_no_bitmap(mddev)) 365 379 return -EINVAL; 366 380 367 - if (mddev->queue) { 368 - blk_queue_max_hw_sectors(mddev->queue, mddev->chunk_sectors); 369 - blk_queue_max_write_same_sectors(mddev->queue, mddev->chunk_sectors); 370 - blk_queue_max_discard_sectors(mddev->queue, mddev->chunk_sectors); 371 - } 372 - 373 381 /* if private is not null, we are here after takeover */ 374 382 if (mddev->private == NULL) { 375 383 ret = create_strip_zones(mddev, &conf); ··· 372 392 mddev->private = conf; 373 393 } 374 394 conf = mddev->private; 395 + if (mddev->queue) { 396 + struct md_rdev *rdev; 397 + bool discard_supported = false; 398 + 399 + rdev_for_each(rdev, mddev) { 400 + disk_stack_limits(mddev->gendisk, rdev->bdev, 401 + rdev->data_offset << 9); 402 + if (blk_queue_discard(bdev_get_queue(rdev->bdev))) 403 + discard_supported = true; 404 + } 405 + blk_queue_max_hw_sectors(mddev->queue, mddev->chunk_sectors); 406 + blk_queue_max_write_same_sectors(mddev->queue, mddev->chunk_sectors); 407 + blk_queue_max_discard_sectors(mddev->queue, mddev->chunk_sectors); 408 + 409 + blk_queue_io_min(mddev->queue, mddev->chunk_sectors << 9); 410 + blk_queue_io_opt(mddev->queue, 411 + (mddev->chunk_sectors << 9) * mddev->raid_disks); 412 + 413 + if (!discard_supported) 414 + queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, mddev->queue); 415 + else 416 + queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, mddev->queue); 417 + } 375 418 376 419 /* calculate array device size */ 377 420 md_set_array_sectors(mddev, raid0_size(mddev, 0, 0));
+29 -1
drivers/md/raid1.c
··· 1474 1474 */ 1475 1475 set_bit(MD_RECOVERY_INTR, &mddev->recovery); 1476 1476 set_bit(MD_CHANGE_DEVS, &mddev->flags); 1477 + set_bit(MD_CHANGE_PENDING, &mddev->flags); 1477 1478 printk(KERN_ALERT 1478 1479 "md/raid1:%s: Disk failure on %s, disabling device.\n" 1479 1480 "md/raid1:%s: Operation continuing on %d devices.\n", ··· 2236 2235 static void handle_write_finished(struct r1conf *conf, struct r1bio *r1_bio) 2237 2236 { 2238 2237 int m; 2238 + bool fail = false; 2239 2239 for (m = 0; m < conf->raid_disks * 2 ; m++) 2240 2240 if (r1_bio->bios[m] == IO_MADE_GOOD) { 2241 2241 struct md_rdev *rdev = conf->mirrors[m].rdev; ··· 2249 2247 * narrow down and record precise write 2250 2248 * errors. 2251 2249 */ 2250 + fail = true; 2252 2251 if (!narrow_write_error(r1_bio, m)) { 2253 2252 md_error(conf->mddev, 2254 2253 conf->mirrors[m].rdev); ··· 2261 2258 } 2262 2259 if (test_bit(R1BIO_WriteError, &r1_bio->state)) 2263 2260 close_write(r1_bio); 2264 - raid_end_bio_io(r1_bio); 2261 + if (fail) { 2262 + spin_lock_irq(&conf->device_lock); 2263 + list_add(&r1_bio->retry_list, &conf->bio_end_io_list); 2264 + spin_unlock_irq(&conf->device_lock); 2265 + md_wakeup_thread(conf->mddev->thread); 2266 + } else 2267 + raid_end_bio_io(r1_bio); 2265 2268 } 2266 2269 2267 2270 static void handle_read_error(struct r1conf *conf, struct r1bio *r1_bio) ··· 2372 2363 struct blk_plug plug; 2373 2364 2374 2365 md_check_recovery(mddev); 2366 + 2367 + if (!list_empty_careful(&conf->bio_end_io_list) && 2368 + !test_bit(MD_CHANGE_PENDING, &mddev->flags)) { 2369 + LIST_HEAD(tmp); 2370 + spin_lock_irqsave(&conf->device_lock, flags); 2371 + if (!test_bit(MD_CHANGE_PENDING, &mddev->flags)) { 2372 + list_add(&tmp, &conf->bio_end_io_list); 2373 + list_del_init(&conf->bio_end_io_list); 2374 + } 2375 + spin_unlock_irqrestore(&conf->device_lock, flags); 2376 + while (!list_empty(&tmp)) { 2377 + r1_bio = list_first_entry(&conf->bio_end_io_list, 2378 + struct r1bio, retry_list); 2379 + list_del(&r1_bio->retry_list); 2380 + raid_end_bio_io(r1_bio); 2381 + } 2382 + } 2375 2383 2376 2384 blk_start_plug(&plug); 2377 2385 for (;;) { ··· 2789 2763 conf->raid_disks = mddev->raid_disks; 2790 2764 conf->mddev = mddev; 2791 2765 INIT_LIST_HEAD(&conf->retry_list); 2766 + INIT_LIST_HEAD(&conf->bio_end_io_list); 2792 2767 2793 2768 spin_lock_init(&conf->resync_lock); 2794 2769 init_waitqueue_head(&conf->wait_barrier); ··· 3084 3057 3085 3058 unfreeze_array(conf); 3086 3059 3060 + set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); 3087 3061 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 3088 3062 md_wakeup_thread(mddev->thread); 3089 3063
+5
drivers/md/raid1.h
··· 61 61 * block, or anything else. 62 62 */ 63 63 struct list_head retry_list; 64 + /* A separate list of r1bio which just need raid_end_bio_io called. 65 + * This mustn't happen for writes which had any errors if the superblock 66 + * needs to be written. 67 + */ 68 + struct list_head bio_end_io_list; 64 69 65 70 /* queue pending writes to be submitted on unplug */ 66 71 struct bio_list pending_bio_list;
+30 -3
drivers/md/raid10.c
··· 1589 1589 set_bit(Blocked, &rdev->flags); 1590 1590 set_bit(Faulty, &rdev->flags); 1591 1591 set_bit(MD_CHANGE_DEVS, &mddev->flags); 1592 + set_bit(MD_CHANGE_PENDING, &mddev->flags); 1592 1593 spin_unlock_irqrestore(&conf->device_lock, flags); 1593 1594 printk(KERN_ALERT 1594 1595 "md/raid10:%s: Disk failure on %s, disabling device.\n" ··· 2624 2623 } 2625 2624 put_buf(r10_bio); 2626 2625 } else { 2626 + bool fail = false; 2627 2627 for (m = 0; m < conf->copies; m++) { 2628 2628 int dev = r10_bio->devs[m].devnum; 2629 2629 struct bio *bio = r10_bio->devs[m].bio; ··· 2636 2634 r10_bio->sectors, 0); 2637 2635 rdev_dec_pending(rdev, conf->mddev); 2638 2636 } else if (bio != NULL && bio->bi_error) { 2637 + fail = true; 2639 2638 if (!narrow_write_error(r10_bio, m)) { 2640 2639 md_error(conf->mddev, rdev); 2641 2640 set_bit(R10BIO_Degraded, ··· 2657 2654 if (test_bit(R10BIO_WriteError, 2658 2655 &r10_bio->state)) 2659 2656 close_write(r10_bio); 2660 - raid_end_bio_io(r10_bio); 2657 + if (fail) { 2658 + spin_lock_irq(&conf->device_lock); 2659 + list_add(&r10_bio->retry_list, &conf->bio_end_io_list); 2660 + spin_unlock_irq(&conf->device_lock); 2661 + md_wakeup_thread(conf->mddev->thread); 2662 + } else 2663 + raid_end_bio_io(r10_bio); 2661 2664 } 2662 2665 } 2663 2666 ··· 2677 2668 struct blk_plug plug; 2678 2669 2679 2670 md_check_recovery(mddev); 2671 + 2672 + if (!list_empty_careful(&conf->bio_end_io_list) && 2673 + !test_bit(MD_CHANGE_PENDING, &mddev->flags)) { 2674 + LIST_HEAD(tmp); 2675 + spin_lock_irqsave(&conf->device_lock, flags); 2676 + if (!test_bit(MD_CHANGE_PENDING, &mddev->flags)) { 2677 + list_add(&tmp, &conf->bio_end_io_list); 2678 + list_del_init(&conf->bio_end_io_list); 2679 + } 2680 + spin_unlock_irqrestore(&conf->device_lock, flags); 2681 + while (!list_empty(&tmp)) { 2682 + r10_bio = list_first_entry(&conf->bio_end_io_list, 2683 + struct r10bio, retry_list); 2684 + list_del(&r10_bio->retry_list); 2685 + raid_end_bio_io(r10_bio); 2686 + } 2687 + } 2680 2688 2681 2689 blk_start_plug(&plug); 2682 2690 for (;;) { ··· 3469 3443 conf->reshape_safe = conf->reshape_progress; 3470 3444 spin_lock_init(&conf->device_lock); 3471 3445 INIT_LIST_HEAD(&conf->retry_list); 3446 + INIT_LIST_HEAD(&conf->bio_end_io_list); 3472 3447 3473 3448 spin_lock_init(&conf->resync_lock); 3474 3449 init_waitqueue_head(&conf->wait_barrier); ··· 4124 4097 * at a time, possibly less if that exceeds RESYNC_PAGES, 4125 4098 * or we hit a bad block or something. 4126 4099 * This might mean we pause for normal IO in the middle of 4127 - * a chunk, but that is not a problem was mddev->reshape_position 4100 + * a chunk, but that is not a problem as mddev->reshape_position 4128 4101 * can record any location. 4129 4102 * 4130 4103 * If we will want to write to a location that isn't ··· 4148 4121 * 4149 4122 * In all this the minimum difference in data offsets 4150 4123 * (conf->offset_diff - always positive) allows a bit of slack, 4151 - * so next can be after 'safe', but not by more than offset_disk 4124 + * so next can be after 'safe', but not by more than offset_diff 4152 4125 * 4153 4126 * We need to prepare all the bios here before we start any IO 4154 4127 * to ensure the size we choose is acceptable to all devices.
+6
drivers/md/raid10.h
··· 53 53 sector_t offset_diff; 54 54 55 55 struct list_head retry_list; 56 + /* A separate list of r1bio which just need raid_end_bio_io called. 57 + * This mustn't happen for writes which had any errors if the superblock 58 + * needs to be written. 59 + */ 60 + struct list_head bio_end_io_list; 61 + 56 62 /* queue pending writes and submit them on unplug */ 57 63 struct bio_list pending_bio_list; 58 64 int pending_count;
+84 -56
drivers/md/raid5.c
··· 223 223 return slot; 224 224 } 225 225 226 - static void return_io(struct bio *return_bi) 226 + static void return_io(struct bio_list *return_bi) 227 227 { 228 - struct bio *bi = return_bi; 229 - while (bi) { 230 - 231 - return_bi = bi->bi_next; 232 - bi->bi_next = NULL; 228 + struct bio *bi; 229 + while ((bi = bio_list_pop(return_bi)) != NULL) { 233 230 bi->bi_iter.bi_size = 0; 234 231 trace_block_bio_complete(bdev_get_queue(bi->bi_bdev), 235 232 bi, 0); 236 233 bio_endio(bi); 237 - bi = return_bi; 238 234 } 239 235 } 240 236 ··· 1173 1177 static void ops_complete_biofill(void *stripe_head_ref) 1174 1178 { 1175 1179 struct stripe_head *sh = stripe_head_ref; 1176 - struct bio *return_bi = NULL; 1180 + struct bio_list return_bi = BIO_EMPTY_LIST; 1177 1181 int i; 1178 1182 1179 1183 pr_debug("%s: stripe %llu\n", __func__, ··· 1197 1201 while (rbi && rbi->bi_iter.bi_sector < 1198 1202 dev->sector + STRIPE_SECTORS) { 1199 1203 rbi2 = r5_next_bio(rbi, dev->sector); 1200 - if (!raid5_dec_bi_active_stripes(rbi)) { 1201 - rbi->bi_next = return_bi; 1202 - return_bi = rbi; 1203 - } 1204 + if (!raid5_dec_bi_active_stripes(rbi)) 1205 + bio_list_add(&return_bi, rbi); 1204 1206 rbi = rbi2; 1205 1207 } 1206 1208 } 1207 1209 } 1208 1210 clear_bit(STRIPE_BIOFILL_RUN, &sh->state); 1209 1211 1210 - return_io(return_bi); 1212 + return_io(&return_bi); 1211 1213 1212 1214 set_bit(STRIPE_HANDLE, &sh->state); 1213 1215 release_stripe(sh); ··· 2511 2517 set_bit(Blocked, &rdev->flags); 2512 2518 set_bit(Faulty, &rdev->flags); 2513 2519 set_bit(MD_CHANGE_DEVS, &mddev->flags); 2520 + set_bit(MD_CHANGE_PENDING, &mddev->flags); 2514 2521 printk(KERN_ALERT 2515 2522 "md/raid:%s: Disk failure on %s, disabling device.\n" 2516 2523 "md/raid:%s: Operation continuing on %d devices.\n", ··· 3064 3069 static void 3065 3070 handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh, 3066 3071 struct stripe_head_state *s, int disks, 3067 - struct bio **return_bi) 3072 + struct bio_list *return_bi) 3068 3073 { 3069 3074 int i; 3070 3075 BUG_ON(sh->batch_head); ··· 3109 3114 bi->bi_error = -EIO; 3110 3115 if (!raid5_dec_bi_active_stripes(bi)) { 3111 3116 md_write_end(conf->mddev); 3112 - bi->bi_next = *return_bi; 3113 - *return_bi = bi; 3117 + bio_list_add(return_bi, bi); 3114 3118 } 3115 3119 bi = nextbi; 3116 3120 } ··· 3133 3139 bi->bi_error = -EIO; 3134 3140 if (!raid5_dec_bi_active_stripes(bi)) { 3135 3141 md_write_end(conf->mddev); 3136 - bi->bi_next = *return_bi; 3137 - *return_bi = bi; 3142 + bio_list_add(return_bi, bi); 3138 3143 } 3139 3144 bi = bi2; 3140 3145 } ··· 3156 3163 r5_next_bio(bi, sh->dev[i].sector); 3157 3164 3158 3165 bi->bi_error = -EIO; 3159 - if (!raid5_dec_bi_active_stripes(bi)) { 3160 - bi->bi_next = *return_bi; 3161 - *return_bi = bi; 3162 - } 3166 + if (!raid5_dec_bi_active_stripes(bi)) 3167 + bio_list_add(return_bi, bi); 3163 3168 bi = nextbi; 3164 3169 } 3165 3170 } ··· 3436 3445 * never LOCKED, so we don't need to test 'failed' directly. 3437 3446 */ 3438 3447 static void handle_stripe_clean_event(struct r5conf *conf, 3439 - struct stripe_head *sh, int disks, struct bio **return_bi) 3448 + struct stripe_head *sh, int disks, struct bio_list *return_bi) 3440 3449 { 3441 3450 int i; 3442 3451 struct r5dev *dev; ··· 3470 3479 wbi2 = r5_next_bio(wbi, dev->sector); 3471 3480 if (!raid5_dec_bi_active_stripes(wbi)) { 3472 3481 md_write_end(conf->mddev); 3473 - wbi->bi_next = *return_bi; 3474 - *return_bi = wbi; 3482 + bio_list_add(return_bi, wbi); 3475 3483 } 3476 3484 wbi = wbi2; 3477 3485 } ··· 4603 4613 md_wakeup_thread(conf->mddev->thread); 4604 4614 } 4605 4615 4606 - return_io(s.return_bi); 4616 + if (!bio_list_empty(&s.return_bi)) { 4617 + if (test_bit(MD_CHANGE_PENDING, &conf->mddev->flags)) { 4618 + spin_lock_irq(&conf->device_lock); 4619 + bio_list_merge(&conf->return_bi, &s.return_bi); 4620 + spin_unlock_irq(&conf->device_lock); 4621 + md_wakeup_thread(conf->mddev->thread); 4622 + } else 4623 + return_io(&s.return_bi); 4624 + } 4607 4625 4608 4626 clear_bit_unlock(STRIPE_ACTIVE, &sh->state); 4609 4627 } ··· 4670 4672 4671 4673 static int in_chunk_boundary(struct mddev *mddev, struct bio *bio) 4672 4674 { 4675 + struct r5conf *conf = mddev->private; 4673 4676 sector_t sector = bio->bi_iter.bi_sector + get_start_sect(bio->bi_bdev); 4674 - unsigned int chunk_sectors = mddev->chunk_sectors; 4677 + unsigned int chunk_sectors; 4675 4678 unsigned int bio_sectors = bio_sectors(bio); 4676 4679 4677 - if (mddev->new_chunk_sectors < mddev->chunk_sectors) 4678 - chunk_sectors = mddev->new_chunk_sectors; 4680 + chunk_sectors = min(conf->chunk_sectors, conf->prev_chunk_sectors); 4679 4681 return chunk_sectors >= 4680 4682 ((sector & (chunk_sectors - 1)) + bio_sectors); 4681 4683 } ··· 5323 5325 sector_t stripe_addr; 5324 5326 int reshape_sectors; 5325 5327 struct list_head stripes; 5328 + sector_t retn; 5326 5329 5327 5330 if (sector_nr == 0) { 5328 5331 /* If restarting in the middle, skip the initial sectors */ ··· 5331 5332 conf->reshape_progress < raid5_size(mddev, 0, 0)) { 5332 5333 sector_nr = raid5_size(mddev, 0, 0) 5333 5334 - conf->reshape_progress; 5335 + } else if (mddev->reshape_backwards && 5336 + conf->reshape_progress == MaxSector) { 5337 + /* shouldn't happen, but just in case, finish up.*/ 5338 + sector_nr = MaxSector; 5334 5339 } else if (!mddev->reshape_backwards && 5335 5340 conf->reshape_progress > 0) 5336 5341 sector_nr = conf->reshape_progress; ··· 5343 5340 mddev->curr_resync_completed = sector_nr; 5344 5341 sysfs_notify(&mddev->kobj, NULL, "sync_completed"); 5345 5342 *skipped = 1; 5346 - return sector_nr; 5343 + retn = sector_nr; 5344 + goto finish; 5347 5345 } 5348 5346 } 5349 5347 ··· 5352 5348 * If old and new chunk sizes differ, we need to process the 5353 5349 * largest of these 5354 5350 */ 5355 - if (mddev->new_chunk_sectors > mddev->chunk_sectors) 5356 - reshape_sectors = mddev->new_chunk_sectors; 5357 - else 5358 - reshape_sectors = mddev->chunk_sectors; 5351 + 5352 + reshape_sectors = max(conf->chunk_sectors, conf->prev_chunk_sectors); 5359 5353 5360 5354 /* We update the metadata at least every 10 seconds, or when 5361 5355 * the data about to be copied would over-write the source of ··· 5368 5366 safepos = conf->reshape_safe; 5369 5367 sector_div(safepos, data_disks); 5370 5368 if (mddev->reshape_backwards) { 5371 - writepos -= min_t(sector_t, reshape_sectors, writepos); 5369 + BUG_ON(writepos < reshape_sectors); 5370 + writepos -= reshape_sectors; 5372 5371 readpos += reshape_sectors; 5373 5372 safepos += reshape_sectors; 5374 5373 } else { 5375 5374 writepos += reshape_sectors; 5375 + /* readpos and safepos are worst-case calculations. 5376 + * A negative number is overly pessimistic, and causes 5377 + * obvious problems for unsigned storage. So clip to 0. 5378 + */ 5376 5379 readpos -= min_t(sector_t, reshape_sectors, readpos); 5377 5380 safepos -= min_t(sector_t, reshape_sectors, safepos); 5378 5381 } ··· 5520 5513 * then we need to write out the superblock. 5521 5514 */ 5522 5515 sector_nr += reshape_sectors; 5523 - if ((sector_nr - mddev->curr_resync_completed) * 2 5516 + retn = reshape_sectors; 5517 + finish: 5518 + if (mddev->curr_resync_completed > mddev->resync_max || 5519 + (sector_nr - mddev->curr_resync_completed) * 2 5524 5520 >= mddev->resync_max - mddev->curr_resync_completed) { 5525 5521 /* Cannot proceed until we've updated the superblock... */ 5526 5522 wait_event(conf->wait_for_overlap, ··· 5548 5538 sysfs_notify(&mddev->kobj, NULL, "sync_completed"); 5549 5539 } 5550 5540 ret: 5551 - return reshape_sectors; 5541 + return retn; 5552 5542 } 5553 5543 5554 5544 static inline sector_t sync_request(struct mddev *mddev, sector_t sector_nr, int *skipped) ··· 5803 5793 pr_debug("+++ raid5d active\n"); 5804 5794 5805 5795 md_check_recovery(mddev); 5796 + 5797 + if (!bio_list_empty(&conf->return_bi) && 5798 + !test_bit(MD_CHANGE_PENDING, &mddev->flags)) { 5799 + struct bio_list tmp = BIO_EMPTY_LIST; 5800 + spin_lock_irq(&conf->device_lock); 5801 + if (!test_bit(MD_CHANGE_PENDING, &mddev->flags)) { 5802 + bio_list_merge(&tmp, &conf->return_bi); 5803 + bio_list_init(&conf->return_bi); 5804 + } 5805 + spin_unlock_irq(&conf->device_lock); 5806 + return_io(&tmp); 5807 + } 5806 5808 5807 5809 blk_start_plug(&plug); 5808 5810 handled = 0; ··· 6256 6234 /* size is defined by the smallest of previous and new size */ 6257 6235 raid_disks = min(conf->raid_disks, conf->previous_raid_disks); 6258 6236 6259 - sectors &= ~((sector_t)mddev->chunk_sectors - 1); 6260 - sectors &= ~((sector_t)mddev->new_chunk_sectors - 1); 6237 + sectors &= ~((sector_t)conf->chunk_sectors - 1); 6238 + sectors &= ~((sector_t)conf->prev_chunk_sectors - 1); 6261 6239 return sectors * (raid_disks - conf->max_degraded); 6262 6240 } 6263 6241 ··· 6475 6453 INIT_LIST_HEAD(&conf->hold_list); 6476 6454 INIT_LIST_HEAD(&conf->delayed_list); 6477 6455 INIT_LIST_HEAD(&conf->bitmap_list); 6456 + bio_list_init(&conf->return_bi); 6478 6457 init_llist_head(&conf->released_stripes); 6479 6458 atomic_set(&conf->active_stripes, 0); 6480 6459 atomic_set(&conf->preread_active_stripes, 0); ··· 6565 6542 if (conf->reshape_progress != MaxSector) { 6566 6543 conf->prev_chunk_sectors = mddev->chunk_sectors; 6567 6544 conf->prev_algo = mddev->layout; 6545 + } else { 6546 + conf->prev_chunk_sectors = conf->chunk_sectors; 6547 + conf->prev_algo = conf->algorithm; 6568 6548 } 6569 6549 6570 6550 conf->min_nr_stripes = NR_STRIPES; ··· 6687 6661 sector_t here_new, here_old; 6688 6662 int old_disks; 6689 6663 int max_degraded = (mddev->level == 6 ? 2 : 1); 6664 + int chunk_sectors; 6665 + int new_data_disks; 6690 6666 6691 6667 if (mddev->new_level != mddev->level) { 6692 6668 printk(KERN_ERR "md/raid:%s: unsupported reshape " ··· 6700 6672 /* reshape_position must be on a new-stripe boundary, and one 6701 6673 * further up in new geometry must map after here in old 6702 6674 * geometry. 6675 + * If the chunk sizes are different, then as we perform reshape 6676 + * in units of the largest of the two, reshape_position needs 6677 + * be a multiple of the largest chunk size times new data disks. 6703 6678 */ 6704 6679 here_new = mddev->reshape_position; 6705 - if (sector_div(here_new, mddev->new_chunk_sectors * 6706 - (mddev->raid_disks - max_degraded))) { 6680 + chunk_sectors = max(mddev->chunk_sectors, mddev->new_chunk_sectors); 6681 + new_data_disks = mddev->raid_disks - max_degraded; 6682 + if (sector_div(here_new, chunk_sectors * new_data_disks)) { 6707 6683 printk(KERN_ERR "md/raid:%s: reshape_position not " 6708 6684 "on a stripe boundary\n", mdname(mddev)); 6709 6685 return -EINVAL; 6710 6686 } 6711 - reshape_offset = here_new * mddev->new_chunk_sectors; 6687 + reshape_offset = here_new * chunk_sectors; 6712 6688 /* here_new is the stripe we will write to */ 6713 6689 here_old = mddev->reshape_position; 6714 - sector_div(here_old, mddev->chunk_sectors * 6715 - (old_disks-max_degraded)); 6690 + sector_div(here_old, chunk_sectors * (old_disks-max_degraded)); 6716 6691 /* here_old is the first stripe that we might need to read 6717 6692 * from */ 6718 6693 if (mddev->delta_disks == 0) { 6719 - if ((here_new * mddev->new_chunk_sectors != 6720 - here_old * mddev->chunk_sectors)) { 6721 - printk(KERN_ERR "md/raid:%s: reshape position is" 6722 - " confused - aborting\n", mdname(mddev)); 6723 - return -EINVAL; 6724 - } 6725 6694 /* We cannot be sure it is safe to start an in-place 6726 6695 * reshape. It is only safe if user-space is monitoring 6727 6696 * and taking constant backups. ··· 6737 6712 return -EINVAL; 6738 6713 } 6739 6714 } else if (mddev->reshape_backwards 6740 - ? (here_new * mddev->new_chunk_sectors + min_offset_diff <= 6741 - here_old * mddev->chunk_sectors) 6742 - : (here_new * mddev->new_chunk_sectors >= 6743 - here_old * mddev->chunk_sectors + (-min_offset_diff))) { 6715 + ? (here_new * chunk_sectors + min_offset_diff <= 6716 + here_old * chunk_sectors) 6717 + : (here_new * chunk_sectors >= 6718 + here_old * chunk_sectors + (-min_offset_diff))) { 6744 6719 /* Reading from the same stripe as writing to - bad */ 6745 6720 printk(KERN_ERR "md/raid:%s: reshape_position too early for " 6746 6721 "auto-recovery - aborting.\n", ··· 6992 6967 int i; 6993 6968 6994 6969 seq_printf(seq, " level %d, %dk chunk, algorithm %d", mddev->level, 6995 - mddev->chunk_sectors / 2, mddev->layout); 6970 + conf->chunk_sectors / 2, mddev->layout); 6996 6971 seq_printf (seq, " [%d/%d] [", conf->raid_disks, conf->raid_disks - mddev->degraded); 6997 6972 for (i = 0; i < conf->raid_disks; i++) 6998 6973 seq_printf (seq, "%s", ··· 7198 7173 * worth it. 7199 7174 */ 7200 7175 sector_t newsize; 7201 - sectors &= ~((sector_t)mddev->chunk_sectors - 1); 7176 + struct r5conf *conf = mddev->private; 7177 + 7178 + sectors &= ~((sector_t)conf->chunk_sectors - 1); 7202 7179 newsize = raid5_size(mddev, sectors, mddev->raid_disks); 7203 7180 if (mddev->external_size && 7204 7181 mddev->array_sectors > newsize) ··· 7439 7412 rdev->data_offset = rdev->new_data_offset; 7440 7413 smp_wmb(); 7441 7414 conf->reshape_progress = MaxSector; 7415 + conf->mddev->reshape_position = MaxSector; 7442 7416 spin_unlock_irq(&conf->device_lock); 7443 7417 wake_up(&conf->wait_for_overlap); 7444 7418
+4 -1
drivers/md/raid5.h
··· 265 265 int dec_preread_active; 266 266 unsigned long ops_request; 267 267 268 - struct bio *return_bi; 268 + struct bio_list return_bi; 269 269 struct md_rdev *blocked_rdev; 270 270 int handle_bad_blocks; 271 271 }; ··· 475 475 int bypass_threshold; /* preread nice */ 476 476 int skip_copy; /* Don't copy data from bio to stripe cache */ 477 477 struct list_head *last_hold; /* detect hold_list promotions */ 478 + 479 + /* bios to have bi_end_io called after metadata is synced */ 480 + struct bio_list return_bi; 478 481 479 482 atomic_t reshape_stripes; /* stripes with pending writes for reshape */ 480 483 /* unfortunately we need two cache names as we temporarily have
+12 -1
lib/raid6/neon.c
··· 40 40 (unsigned long)bytes, ptrs); \ 41 41 kernel_neon_end(); \ 42 42 } \ 43 + static void raid6_neon ## _n ## _xor_syndrome(int disks, \ 44 + int start, int stop, \ 45 + size_t bytes, void **ptrs) \ 46 + { \ 47 + void raid6_neon ## _n ## _xor_syndrome_real(int, \ 48 + int, int, unsigned long, void**); \ 49 + kernel_neon_begin(); \ 50 + raid6_neon ## _n ## _xor_syndrome_real(disks, \ 51 + start, stop, (unsigned long)bytes, ptrs); \ 52 + kernel_neon_end(); \ 53 + } \ 43 54 struct raid6_calls const raid6_neonx ## _n = { \ 44 55 raid6_neon ## _n ## _gen_syndrome, \ 45 - NULL, /* XOR not yet implemented */ \ 56 + raid6_neon ## _n ## _xor_syndrome, \ 46 57 raid6_have_neon, \ 47 58 "neonx" #_n, \ 48 59 0 \
+46
lib/raid6/neon.uc
··· 3 3 * neon.uc - RAID-6 syndrome calculation using ARM NEON instructions 4 4 * 5 5 * Copyright (C) 2012 Rob Herring 6 + * Copyright (C) 2015 Linaro Ltd. <ard.biesheuvel@linaro.org> 6 7 * 7 8 * Based on altivec.uc: 8 9 * Copyright 2002-2004 H. Peter Anvin - All Rights Reserved ··· 75 74 w1$$ = veorq_u8(w1$$, w2$$); 76 75 wq$$ = veorq_u8(w1$$, wd$$); 77 76 } 77 + vst1q_u8(&p[d+NSIZE*$$], wp$$); 78 + vst1q_u8(&q[d+NSIZE*$$], wq$$); 79 + } 80 + } 81 + 82 + void raid6_neon$#_xor_syndrome_real(int disks, int start, int stop, 83 + unsigned long bytes, void **ptrs) 84 + { 85 + uint8_t **dptr = (uint8_t **)ptrs; 86 + uint8_t *p, *q; 87 + int d, z, z0; 88 + 89 + register unative_t wd$$, wq$$, wp$$, w1$$, w2$$; 90 + const unative_t x1d = NBYTES(0x1d); 91 + 92 + z0 = stop; /* P/Q right side optimization */ 93 + p = dptr[disks-2]; /* XOR parity */ 94 + q = dptr[disks-1]; /* RS syndrome */ 95 + 96 + for ( d = 0 ; d < bytes ; d += NSIZE*$# ) { 97 + wq$$ = vld1q_u8(&dptr[z0][d+$$*NSIZE]); 98 + wp$$ = veorq_u8(vld1q_u8(&p[d+$$*NSIZE]), wq$$); 99 + 100 + /* P/Q data pages */ 101 + for ( z = z0-1 ; z >= start ; z-- ) { 102 + wd$$ = vld1q_u8(&dptr[z][d+$$*NSIZE]); 103 + wp$$ = veorq_u8(wp$$, wd$$); 104 + w2$$ = MASK(wq$$); 105 + w1$$ = SHLBYTE(wq$$); 106 + 107 + w2$$ = vandq_u8(w2$$, x1d); 108 + w1$$ = veorq_u8(w1$$, w2$$); 109 + wq$$ = veorq_u8(w1$$, wd$$); 110 + } 111 + /* P/Q left side optimization */ 112 + for ( z = start-1 ; z >= 0 ; z-- ) { 113 + w2$$ = MASK(wq$$); 114 + w1$$ = SHLBYTE(wq$$); 115 + 116 + w2$$ = vandq_u8(w2$$, x1d); 117 + wq$$ = veorq_u8(w1$$, w2$$); 118 + } 119 + w1$$ = vld1q_u8(&q[d+NSIZE*$$]); 120 + wq$$ = veorq_u8(wq$$, w1$$); 121 + 78 122 vst1q_u8(&p[d+NSIZE*$$], wp$$); 79 123 vst1q_u8(&q[d+NSIZE*$$], wq$$); 80 124 }