i2c: rockchip: fix power off issue for rk818
[firefly-linux-kernel-4.4.55.git] / drivers / md / raid5.c
index 5e3c25d4562c2e497d8b50d6c21d9dfd75e2bdb4..ef18ca745b1ec6435d3ab2b6bc4168ed56c572bd 100644 (file)
 #include "raid0.h"
 #include "bitmap.h"
 
+static bool devices_handle_discard_safely = false;
+module_param(devices_handle_discard_safely, bool, 0644);
+MODULE_PARM_DESC(devices_handle_discard_safely,
+                "Set to Y if all devices in each array reliably return zeroes on reads from discarded regions");
 /*
  * Stripe cache
  */
@@ -1697,7 +1701,8 @@ static int resize_stripes(struct r5conf *conf, int newsize)
 
        conf->slab_cache = sc;
        conf->active_name = 1-conf->active_name;
-       conf->pool_size = newsize;
+       if (!err)
+               conf->pool_size = newsize;
        return err;
 }
 
@@ -2674,7 +2679,8 @@ static int fetch_block(struct stripe_head *sh, struct stripe_head_state *s,
             (s->failed >= 2 && fdev[1]->toread) ||
             (sh->raid_conf->level <= 5 && s->failed && fdev[0]->towrite &&
              !test_bit(R5_OVERWRITE, &fdev[0]->flags)) ||
-            (sh->raid_conf->level == 6 && s->failed && s->to_write))) {
+            ((sh->raid_conf->level == 6 || sh->sector >= sh->raid_conf->mddev->recovery_cp)
+             && s->failed && s->to_write))) {
                /* we would like to get this block, possibly by computing it,
                 * otherwise read it if the backing disk is insync
                 */
@@ -2848,7 +2854,8 @@ static void handle_stripe_dirtying(struct r5conf *conf,
         * generate correct data from the parity.
         */
        if (conf->max_degraded == 2 ||
-           (recovery_cp < MaxSector && sh->sector >= recovery_cp)) {
+           (recovery_cp < MaxSector && sh->sector >= recovery_cp &&
+            s->failed == 0)) {
                /* Calculate the real rcw later - for now make it
                 * look like rcw is cheaper
                 */
@@ -3561,6 +3568,8 @@ static void handle_stripe(struct stripe_head *sh)
                                set_bit(R5_Wantwrite, &dev->flags);
                                if (prexor)
                                        continue;
+                               if (s.failed > 1)
+                                       continue;
                                if (!test_bit(R5_Insync, &dev->flags) ||
                                    ((i == sh->pd_idx || i == sh->qd_idx)  &&
                                     s.failed == 0))
@@ -5609,7 +5618,7 @@ static int run(struct mddev *mddev)
                mddev->queue->limits.discard_granularity = stripe;
                /*
                 * unaligned part of discard request will be ignored, so can't
-                * guarantee discard_zerors_data
+                * guarantee discard_zeroes_data
                 */
                mddev->queue->limits.discard_zeroes_data = 0;
 
@@ -5634,6 +5643,18 @@ static int run(struct mddev *mddev)
                            !bdev_get_queue(rdev->bdev)->
                                                limits.discard_zeroes_data)
                                discard_supported = false;
+                       /* Unfortunately, discard_zeroes_data is not currently
+                        * a guarantee - just a hint.  So we only allow DISCARD
+                        * if the sysadmin has confirmed that only safe devices
+                        * are in use by setting a module parameter.
+                        */
+                       if (!devices_handle_discard_safely) {
+                               if (discard_supported) {
+                                       pr_info("md/raid456: discard support disabled due to uncertainty.\n");
+                                       pr_info("Set raid456.devices_handle_discard_safely=Y to override.\n");
+                               }
+                               discard_supported = false;
+                       }
                }
 
                if (discard_supported &&