OSDN Git Service

dm switch: efficiently support repetitive patterns
authorMikulas Patocka <mpatocka@redhat.com>
Mon, 28 Jul 2014 22:11:25 +0000 (18:11 -0400)
committerMike Snitzer <snitzer@redhat.com>
Fri, 1 Aug 2014 16:30:37 +0000 (12:30 -0400)
Add support for quickly loading a repetitive pattern into the
dm-switch target.

In the "set_regions_mappings" message, the user may now use "Rn,m" as
one of the arguments.  "n" and "m" are hexadecimal numbers.  The "Rn,m"
argument repeats the last "n" arguments in the following "m" slots.

For example:
dmsetup message switch 0 set_region_mappings 1000:1 :2 R2,10
is equivalent to
dmsetup message switch 0 set_region_mappings 1000:1 :2 :1 :2 :1 :2 :1 :2 \
:1 :2 :1 :2 :1 :2 :1 :2 :1 :2

Requested-by: Jay Wang <jwang@nimblestorage.com>
Tested-by: Jay Wang <jwang@nimblestorage.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Documentation/device-mapper/switch.txt
drivers/md/dm-switch.c

index 2fa7493..8897d04 100644 (file)
@@ -106,6 +106,11 @@ which paths.
     The path number in the range 0 ... (<num_paths> - 1).
     Expressed in hexadecimal (WITHOUT any prefix like 0x).
 
+R<n>,<m>
+    This parameter allows repetitive patterns to be loaded quickly. <n> and <m>
+    are hexadecimal numbers. The last <n> mappings are repeated in the next <m>
+    slots.
+
 Status
 ======
 
@@ -124,3 +129,10 @@ Create a switch device with 64kB region size:
 Set mappings for the first 7 entries to point to devices switch0, switch1,
 switch2, switch0, switch1, switch2, switch1:
     dmsetup message switch 0 set_region_mappings 0:0 :1 :2 :0 :1 :2 :1
+
+Set repetitive mapping. This command:
+    dmsetup message switch 0 set_region_mappings 1000:1 :2 R2,10
+is equivalent to:
+    dmsetup message switch 0 set_region_mappings 1000:1 :2 :1 :2 :1 :2 :1 :2 \
+       :1 :2 :1 :2 :1 :2 :1 :2 :1 :2
+
index c40e095..50fca46 100644 (file)
@@ -371,7 +371,7 @@ static __always_inline unsigned long parse_hex(const char **string)
 }
 
 static int process_set_region_mappings(struct switch_ctx *sctx,
-                            unsigned argc, char **argv)
+                                      unsigned argc, char **argv)
 {
        unsigned i;
        unsigned long region_index = 0;
@@ -380,6 +380,51 @@ static int process_set_region_mappings(struct switch_ctx *sctx,
                unsigned long path_nr;
                const char *string = argv[i];
 
+               if ((*string & 0xdf) == 'R') {
+                       unsigned long cycle_length, num_write;
+
+                       string++;
+                       if (unlikely(*string == ',')) {
+                               DMWARN("invalid set_region_mappings argument: '%s'", argv[i]);
+                               return -EINVAL;
+                       }
+                       cycle_length = parse_hex(&string);
+                       if (unlikely(*string != ',')) {
+                               DMWARN("invalid set_region_mappings argument: '%s'", argv[i]);
+                               return -EINVAL;
+                       }
+                       string++;
+                       if (unlikely(!*string)) {
+                               DMWARN("invalid set_region_mappings argument: '%s'", argv[i]);
+                               return -EINVAL;
+                       }
+                       num_write = parse_hex(&string);
+                       if (unlikely(*string)) {
+                               DMWARN("invalid set_region_mappings argument: '%s'", argv[i]);
+                               return -EINVAL;
+                       }
+
+                       if (unlikely(!cycle_length) || unlikely(cycle_length - 1 > region_index)) {
+                               DMWARN("invalid set_region_mappings cycle length: %lu > %lu",
+                                      cycle_length - 1, region_index);
+                               return -EINVAL;
+                       }
+                       if (unlikely(region_index + num_write < region_index) ||
+                           unlikely(region_index + num_write >= sctx->nr_regions)) {
+                               DMWARN("invalid set_region_mappings region number: %lu + %lu >= %lu",
+                                      region_index, num_write, sctx->nr_regions);
+                               return -EINVAL;
+                       }
+
+                       while (num_write--) {
+                               region_index++;
+                               path_nr = switch_region_table_read(sctx, region_index - cycle_length);
+                               switch_region_table_write(sctx, region_index, path_nr);
+                       }
+
+                       continue;
+               }
+
                if (*string == ':')
                        region_index++;
                else {
@@ -508,7 +553,7 @@ static int switch_iterate_devices(struct dm_target *ti,
 
 static struct target_type switch_target = {
        .name = "switch",
-       .version = {1, 0, 0},
+       .version = {1, 1, 0},
        .module = THIS_MODULE,
        .ctr = switch_ctr,
        .dtr = switch_dtr,