dm log: move region_size validation
authorMilan Broz <mbroz@redhat.com>
Tue, 6 Jan 2009 03:05:01 +0000 (03:05 +0000)
committerAlasdair G Kergon <agk@redhat.com>
Tue, 6 Jan 2009 03:05:01 +0000 (03:05 +0000)
Move log size validation from mirror target to log constructor.

Removed PAGE_SIZE restriction we no longer think necessary.

Signed-off-by: Milan Broz <mbroz@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
drivers/md/dm-log.c
drivers/md/dm-raid1.c

index 691cb9c22b5643381783fe22979eb39acf85f700..40ed70df6736754dc378df65ab3c6035c2246f72 100644 (file)
@@ -360,6 +360,17 @@ static int read_header(struct log_c *log)
        return 0;
 }
 
+static int _check_region_size(struct dm_target *ti, uint32_t region_size)
+{
+       if (region_size < 2 || region_size > ti->len)
+               return 0;
+
+       if (!is_power_of_2(region_size))
+               return 0;
+
+       return 1;
+}
+
 /*----------------------------------------------------------------
  * core log constructor/destructor
  *
@@ -395,8 +406,9 @@ static int create_log_context(struct dm_dirty_log *log, struct dm_target *ti,
                }
        }
 
-       if (sscanf(argv[0], "%u", &region_size) != 1) {
-               DMWARN("invalid region size string");
+       if (sscanf(argv[0], "%u", &region_size) != 1 ||
+           !_check_region_size(ti, region_size)) {
+               DMWARN("invalid region size %s", argv[0]);
                return -EINVAL;
        }
 
index 250f401668d520662f8e8d36b25abee520f24261..4d6bc101962e1965a1b98e0cc1e87363be4bcc3a 100644 (file)
@@ -808,12 +808,6 @@ static void free_context(struct mirror_set *ms, struct dm_target *ti,
        kfree(ms);
 }
 
-static inline int _check_region_size(struct dm_target *ti, uint32_t size)
-{
-       return !(size % (PAGE_SIZE >> 9) || !is_power_of_2(size) ||
-                size > ti->len);
-}
-
 static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
                      unsigned int mirror, char **argv)
 {
@@ -872,12 +866,6 @@ static struct dm_dirty_log *create_dirty_log(struct dm_target *ti,
                return NULL;
        }
 
-       if (!_check_region_size(ti, dl->type->get_region_size(dl))) {
-               ti->error = "Invalid region size";
-               dm_dirty_log_destroy(dl);
-               return NULL;
-       }
-
        return dl;
 }