]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/md/raid5.c
[PATCH] md: small cleanups for raid5
[mirror_ubuntu-bionic-kernel.git] / drivers / md / raid5.c
index e2a40283e323b46335beedb18face0aad67eae00..334ff7a072839e6e7851878a529e96236ae216ee 100644 (file)
@@ -98,7 +98,7 @@ static inline void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh)
                        list_add_tail(&sh->lru, &conf->inactive_list);
                        atomic_dec(&conf->active_stripes);
                        if (!conf->inactive_blocked ||
-                           atomic_read(&conf->active_stripes) < (NR_STRIPES*3/4))
+                           atomic_read(&conf->active_stripes) < (conf->max_nr_stripes*3/4))
                                wake_up(&conf->wait_for_stripe);
                }
        }
@@ -264,7 +264,8 @@ static struct stripe_head *get_active_stripe(raid5_conf_t *conf, sector_t sector
                                conf->inactive_blocked = 1;
                                wait_event_lock_irq(conf->wait_for_stripe,
                                                    !list_empty(&conf->inactive_list) &&
-                                                   (atomic_read(&conf->active_stripes) < (NR_STRIPES *3/4)
+                                                   (atomic_read(&conf->active_stripes)
+                                                    < (conf->max_nr_stripes *3/4)
                                                     || !conf->inactive_blocked),
                                                    conf->device_lock,
                                                    unplug_slaves(conf->mddev);
@@ -416,7 +417,7 @@ static int raid5_end_read_request(struct bio * bi, unsigned int bytes_done,
                set_bit(R5_UPTODATE, &sh->dev[i].flags);
 #endif
                if (test_bit(R5_ReadError, &sh->dev[i].flags)) {
-                       printk("R5: read error corrected!!\n");
+                       printk(KERN_INFO "raid5: read error corrected!!\n");
                        clear_bit(R5_ReadError, &sh->dev[i].flags);
                        clear_bit(R5_ReWrite, &sh->dev[i].flags);
                }
@@ -427,13 +428,14 @@ static int raid5_end_read_request(struct bio * bi, unsigned int bytes_done,
                clear_bit(R5_UPTODATE, &sh->dev[i].flags);
                atomic_inc(&conf->disks[i].rdev->read_errors);
                if (conf->mddev->degraded)
-                       printk("R5: read error not correctable.\n");
+                       printk(KERN_WARNING "raid5: read error not correctable.\n");
                else if (test_bit(R5_ReWrite, &sh->dev[i].flags))
                        /* Oh, no!!! */
-                       printk("R5: read error NOT corrected!!\n");
+                       printk(KERN_WARNING "raid5: read error NOT corrected!!\n");
                else if (atomic_read(&conf->disks[i].rdev->read_errors)
                         > conf->max_nr_stripes)
-                       printk("raid5: Too many read errors, failing device.\n");
+                       printk(KERN_WARNING
+                              "raid5: Too many read errors, failing device.\n");
                else
                        retry = 1;
                if (retry)
@@ -603,7 +605,7 @@ static sector_t raid5_compute_sector(sector_t r_sector, unsigned int raid_disks,
                        *dd_idx = (*pd_idx + 1 + *dd_idx) % raid_disks;
                        break;
                default:
-                       printk("raid5: unsupported algorithm %d\n",
+                       printk(KERN_ERR "raid5: unsupported algorithm %d\n",
                                conf->algorithm);
        }
 
@@ -644,7 +646,7 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i)
                        i -= (sh->pd_idx + 1);
                        break;
                default:
-                       printk("raid5: unsupported algorithm %d\n",
+                       printk(KERN_ERR "raid5: unsupported algorithm %d\n",
                                conf->algorithm);
        }
 
@@ -653,7 +655,7 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i)
 
        check = raid5_compute_sector (r_sector, raid_disks, data_disks, &dummy1, &dummy2, conf);
        if (check != sh->sector || dummy1 != dd_idx || dummy2 != sh->pd_idx) {
-               printk("compute_blocknr: map not correct\n");
+               printk(KERN_ERR "compute_blocknr: map not correct\n");
                return 0;
        }
        return r_sector;
@@ -736,7 +738,7 @@ static void compute_block(struct stripe_head *sh, int dd_idx)
                if (test_bit(R5_UPTODATE, &sh->dev[i].flags))
                        ptr[count++] = p;
                else
-                       printk("compute_block() %d, stripe %llu, %d"
+                       printk(KERN_ERR "compute_block() %d, stripe %llu, %d"
                                " not present\n", dd_idx,
                                (unsigned long long)sh->sector, i);
 
@@ -1004,7 +1006,7 @@ static void handle_stripe(struct stripe_head *sh)
                if (dev->written) written++;
                rdev = conf->disks[i].rdev; /* FIXME, should I be looking rdev */
                if (!rdev || !test_bit(In_sync, &rdev->flags)) {
-                       /* The ReadError flag wil just be confusing now */
+                       /* The ReadError flag will just be confusing now */
                        clear_bit(R5_ReadError, &dev->flags);
                        clear_bit(R5_ReWrite, &dev->flags);
                }
@@ -1287,7 +1289,7 @@ static void handle_stripe(struct stripe_head *sh)
         * is available
         */
        if (syncing && locked == 0 &&
-           !test_bit(STRIPE_INSYNC, &sh->state) && failed <= 1) {
+           !test_bit(STRIPE_INSYNC, &sh->state)) {
                set_bit(STRIPE_HANDLE, &sh->state);
                if (failed == 0) {
                        char *pagea;
@@ -1305,21 +1307,20 @@ static void handle_stripe(struct stripe_head *sh)
                                if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery))
                                        /* don't try to repair!! */
                                        set_bit(STRIPE_INSYNC, &sh->state);
+                               else {
+                                       compute_block(sh, sh->pd_idx);
+                                       uptodate++;
+                               }
                        }
                }
                if (!test_bit(STRIPE_INSYNC, &sh->state)) {
+                       /* either failed parity check, or recovery is happening */
                        if (failed==0)
                                failed_num = sh->pd_idx;
-                       /* should be able to compute the missing block and write it to spare */
-                       if (!test_bit(R5_UPTODATE, &sh->dev[failed_num].flags)) {
-                               if (uptodate+1 != disks)
-                                       BUG();
-                               compute_block(sh, failed_num);
-                               uptodate++;
-                       }
-                       if (uptodate != disks)
-                               BUG();
                        dev = &sh->dev[failed_num];
+                       BUG_ON(!test_bit(R5_UPTODATE, &dev->flags));
+                       BUG_ON(uptodate != disks);
+
                        set_bit(R5_LOCKED, &dev->flags);
                        set_bit(R5_Wantwrite, &dev->flags);
                        clear_bit(STRIPE_DEGRADED, &sh->state);
@@ -1704,7 +1705,9 @@ static void raid5d (mddev_t *mddev)
 
                if (conf->seq_flush - conf->seq_write > 0) {
                        int seq = conf->seq_flush;
+                       spin_unlock_irq(&conf->device_lock);
                        bitmap_unplug(mddev->bitmap);
+                       spin_lock_irq(&conf->device_lock);
                        conf->seq_write = seq;
                        activate_bit_delay(conf);
                }
@@ -1819,7 +1822,8 @@ static int run(mddev_t *mddev)
        struct list_head *tmp;
 
        if (mddev->level != 5 && mddev->level != 4) {
-               printk("raid5: %s: raid level not set to 4/5 (%d)\n", mdname(mddev), mddev->level);
+               printk(KERN_ERR "raid5: %s: raid level not set to 4/5 (%d)\n",
+                      mdname(mddev), mddev->level);
                return -EIO;
        }
 
@@ -1915,7 +1919,7 @@ static int run(mddev_t *mddev)
                        goto abort;
                }
        }
-memory = conf->max_nr_stripes * (sizeof(struct stripe_head) +
+       memory = conf->max_nr_stripes * (sizeof(struct stripe_head) +
                 conf->raid_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024;
        if (grow_stripes(conf, conf->max_nr_stripes)) {
                printk(KERN_ERR