dm raid: reject too many write_mostly devices
authorHeinz Mauelshagen <heinzm@redhat.com>
Wed, 15 Jun 2016 16:50:18 +0000 (18:50 +0200)
committerMike Snitzer <snitzer@redhat.com>
Mon, 18 Jul 2016 19:37:19 +0000 (15:37 -0400)
Signed-off-by: Heinz Mauelshagen <heinzm@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
drivers/md/dm-raid.c

index 0eceee802571880bd9217b4acdea11e322c00175..a38298589db865a7c57c137275c7044b12ac661f 100644 (file)
@@ -1025,7 +1025,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as,
 {
        int value, raid10_format = ALGORITHM_RAID10_DEFAULT;
        unsigned raid10_copies = 2;
-       unsigned i;
+       unsigned i, write_mostly = 0;
        unsigned region_size = 0;
        sector_t max_io_len;
        const char *arg, *key;
@@ -1179,6 +1179,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as,
                                return -EINVAL;
                        }
 
+                       write_mostly++;
                        set_bit(WriteMostly, &rs->dev[value].rdev.flags);
                        set_bit(__CTR_FLAG_WRITE_MOSTLY, &rs->ctr_flags);
                } else if (!strcasecmp(key, dm_raid_arg_name_by_flag(CTR_FLAG_MAX_WRITE_BEHIND))) {
@@ -1303,6 +1304,11 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as,
                return -EINVAL;
        }
 
+       if (write_mostly >= rs->md.raid_disks) {
+               rs->ti->error = "Can't set all raid1 devices to write_mostly";
+               return -EINVAL;
+       }
+
        if (validate_region_size(rs, region_size))
                return -EINVAL;