All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] dm-switch: quickly load repetitive pattern
@ 2014-07-28 21:47 Mikulas Patocka
  2014-07-28 21:47 ` [PATCH 1/2] " Mikulas Patocka
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Mikulas Patocka @ 2014-07-28 21:47 UTC (permalink / raw)
  To: Mike Snitzer, Alasdair G. Kergon, dm-devel; +Cc: Jay Wang

Hi

Jay Wang requested a way to quickly load repetitive pattern into the 
dm-switch target. I created these two patches, Jay tested them in their 
product and they work as expected. So, I'm submitting the patches upstream 
for the next merge window.

Mikulas

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] dm-switch: quickly load repetitive pattern
  2014-07-28 21:47 [PATCH 0/2] dm-switch: quickly load repetitive pattern Mikulas Patocka
@ 2014-07-28 21:47 ` Mikulas Patocka
  2014-07-28 21:49   ` Mikulas Patocka
  2014-07-28 21:48 ` [PATCH 2/2] dm-switch: allow repetitive patterns Mikulas Patocka
  2014-07-28 21:49 ` [PATCH 1/2] dm-switch: introdice switch_region_table_read Mikulas Patocka
  2 siblings, 1 reply; 6+ messages in thread
From: Mikulas Patocka @ 2014-07-28 21:47 UTC (permalink / raw)
  To: Mike Snitzer, Alasdair G. Kergon, dm-devel; +Cc: Jay Wang

dm-switch: introdice switch_region_table_read

Move a code that reads the table to a separate function.
It will be needed for the next patch.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

---
 drivers/md/dm-switch.c |   18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

Index: linux-3.15/drivers/md/dm-switch.c
===================================================================
--- linux-3.15.orig/drivers/md/dm-switch.c	2014-06-26 22:25:10.000000000 +0200
+++ linux-3.15/drivers/md/dm-switch.c	2014-06-27 14:08:06.000000000 +0200
@@ -137,13 +137,23 @@ static void switch_get_position(struct s
 	*bit *= sctx->region_table_entry_bits;
 }
 
+static unsigned switch_region_table_read(struct switch_ctx *sctx, unsigned long region_nr)
+{
+	unsigned long region_index;
+	unsigned bit;
+
+	switch_get_position(sctx, region_nr, &region_index, &bit);
+
+	return (ACCESS_ONCE(sctx->region_table[region_index]) >> bit) &
+		((1 << sctx->region_table_entry_bits) - 1);
+}
+
 /*
  * Find which path to use at given offset.
  */
 static unsigned switch_get_path_nr(struct switch_ctx *sctx, sector_t offset)
 {
-	unsigned long region_index;
-	unsigned bit, path_nr;
+	unsigned path_nr;
 	sector_t p;
 
 	p = offset;
@@ -152,9 +162,7 @@ static unsigned switch_get_path_nr(struc
 	else
 		sector_div(p, sctx->region_size);
 
-	switch_get_position(sctx, p, &region_index, &bit);
-	path_nr = (ACCESS_ONCE(sctx->region_table[region_index]) >> bit) &
-	       ((1 << sctx->region_table_entry_bits) - 1);
+	path_nr = switch_region_table_read(sctx, p);
 
 	/* This can only happen if the processor uses non-atomic stores. */
 	if (unlikely(path_nr >= sctx->nr_paths))

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/2] dm-switch: allow repetitive patterns
  2014-07-28 21:47 [PATCH 0/2] dm-switch: quickly load repetitive pattern Mikulas Patocka
  2014-07-28 21:47 ` [PATCH 1/2] " Mikulas Patocka
@ 2014-07-28 21:48 ` Mikulas Patocka
  2014-07-28 22:11   ` [PATCH 2/2 v2] " Mikulas Patocka
  2014-07-28 21:49 ` [PATCH 1/2] dm-switch: introdice switch_region_table_read Mikulas Patocka
  2 siblings, 1 reply; 6+ messages in thread
From: Mikulas Patocka @ 2014-07-28 21:48 UTC (permalink / raw)
  To: Mike Snitzer, Alasdair G. Kergon, dm-devel; +Cc: Jay Wang

This patch allows repetitive patterns in dm-switch. In
set_regions_mappings message, the user may 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

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

---
 drivers/md/dm-switch.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

Index: linux-3.15/drivers/md/dm-switch.c
===================================================================
--- linux-3.15.orig/drivers/md/dm-switch.c	2014-06-27 14:09:39.000000000 +0200
+++ linux-3.15/drivers/md/dm-switch.c	2014-06-27 22:36:42.000000000 +0200
@@ -380,6 +380,49 @@ static int process_set_region_mappings(s
 		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 {

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] dm-switch: introdice switch_region_table_read
  2014-07-28 21:47 [PATCH 0/2] dm-switch: quickly load repetitive pattern Mikulas Patocka
  2014-07-28 21:47 ` [PATCH 1/2] " Mikulas Patocka
  2014-07-28 21:48 ` [PATCH 2/2] dm-switch: allow repetitive patterns Mikulas Patocka
@ 2014-07-28 21:49 ` Mikulas Patocka
  2 siblings, 0 replies; 6+ messages in thread
From: Mikulas Patocka @ 2014-07-28 21:49 UTC (permalink / raw)
  To: Mike Snitzer, Alasdair G. Kergon, dm-devel; +Cc: Jay Wang

Move a code that reads the table to a separate function.
It will be needed for the next patch.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

---
 drivers/md/dm-switch.c |   18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

Index: linux-3.15/drivers/md/dm-switch.c
===================================================================
--- linux-3.15.orig/drivers/md/dm-switch.c	2014-06-26 22:25:10.000000000 +0200
+++ linux-3.15/drivers/md/dm-switch.c	2014-06-27 14:08:06.000000000 +0200
@@ -137,13 +137,23 @@ static void switch_get_position(struct s
 	*bit *= sctx->region_table_entry_bits;
 }
 
+static unsigned switch_region_table_read(struct switch_ctx *sctx, unsigned long region_nr)
+{
+	unsigned long region_index;
+	unsigned bit;
+
+	switch_get_position(sctx, region_nr, &region_index, &bit);
+
+	return (ACCESS_ONCE(sctx->region_table[region_index]) >> bit) &
+		((1 << sctx->region_table_entry_bits) - 1);
+}
+
 /*
  * Find which path to use at given offset.
  */
 static unsigned switch_get_path_nr(struct switch_ctx *sctx, sector_t offset)
 {
-	unsigned long region_index;
-	unsigned bit, path_nr;
+	unsigned path_nr;
 	sector_t p;
 
 	p = offset;
@@ -152,9 +162,7 @@ static unsigned switch_get_path_nr(struc
 	else
 		sector_div(p, sctx->region_size);
 
-	switch_get_position(sctx, p, &region_index, &bit);
-	path_nr = (ACCESS_ONCE(sctx->region_table[region_index]) >> bit) &
-	       ((1 << sctx->region_table_entry_bits) - 1);
+	path_nr = switch_region_table_read(sctx, p);
 
 	/* This can only happen if the processor uses non-atomic stores. */
 	if (unlikely(path_nr >= sctx->nr_paths))

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] dm-switch: quickly load repetitive pattern
  2014-07-28 21:47 ` [PATCH 1/2] " Mikulas Patocka
@ 2014-07-28 21:49   ` Mikulas Patocka
  0 siblings, 0 replies; 6+ messages in thread
From: Mikulas Patocka @ 2014-07-28 21:49 UTC (permalink / raw)
  To: Mike Snitzer, Alasdair G. Kergon, dm-devel; +Cc: Jay Wang

I resent this patch with a correct subject...



On Mon, 28 Jul 2014, Mikulas Patocka wrote:

> dm-switch: introdice switch_region_table_read
> 
> Move a code that reads the table to a separate function.
> It will be needed for the next patch.
> 
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> 
> ---
>  drivers/md/dm-switch.c |   18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
> 
> Index: linux-3.15/drivers/md/dm-switch.c
> ===================================================================
> --- linux-3.15.orig/drivers/md/dm-switch.c	2014-06-26 22:25:10.000000000 +0200
> +++ linux-3.15/drivers/md/dm-switch.c	2014-06-27 14:08:06.000000000 +0200
> @@ -137,13 +137,23 @@ static void switch_get_position(struct s
>  	*bit *= sctx->region_table_entry_bits;
>  }
>  
> +static unsigned switch_region_table_read(struct switch_ctx *sctx, unsigned long region_nr)
> +{
> +	unsigned long region_index;
> +	unsigned bit;
> +
> +	switch_get_position(sctx, region_nr, &region_index, &bit);
> +
> +	return (ACCESS_ONCE(sctx->region_table[region_index]) >> bit) &
> +		((1 << sctx->region_table_entry_bits) - 1);
> +}
> +
>  /*
>   * Find which path to use at given offset.
>   */
>  static unsigned switch_get_path_nr(struct switch_ctx *sctx, sector_t offset)
>  {
> -	unsigned long region_index;
> -	unsigned bit, path_nr;
> +	unsigned path_nr;
>  	sector_t p;
>  
>  	p = offset;
> @@ -152,9 +162,7 @@ static unsigned switch_get_path_nr(struc
>  	else
>  		sector_div(p, sctx->region_size);
>  
> -	switch_get_position(sctx, p, &region_index, &bit);
> -	path_nr = (ACCESS_ONCE(sctx->region_table[region_index]) >> bit) &
> -	       ((1 << sctx->region_table_entry_bits) - 1);
> +	path_nr = switch_region_table_read(sctx, p);
>  
>  	/* This can only happen if the processor uses non-atomic stores. */
>  	if (unlikely(path_nr >= sctx->nr_paths))
> 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/2 v2] dm-switch: allow repetitive patterns
  2014-07-28 21:48 ` [PATCH 2/2] dm-switch: allow repetitive patterns Mikulas Patocka
@ 2014-07-28 22:11   ` Mikulas Patocka
  0 siblings, 0 replies; 6+ messages in thread
From: Mikulas Patocka @ 2014-07-28 22:11 UTC (permalink / raw)
  To: Mike Snitzer, Alasdair G. Kergon, dm-devel; +Cc: Jay Wang

[ version 2 of the patch - incremented target version and added 
documentation ]

From: Mikulas Patocka <mpatocka@redhat.com>

This patch allows repetitive patterns in dm-switch. In
set_regions_mappings message, the user may 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

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

---
 Documentation/device-mapper/switch.txt |   12 ++++++++
 drivers/md/dm-switch.c                 |   45 ++++++++++++++++++++++++++++++++-
 2 files changed, 56 insertions(+), 1 deletion(-)

Index: linux-3.16-rc5/drivers/md/dm-switch.c
===================================================================
--- linux-3.16-rc5.orig/drivers/md/dm-switch.c	2014-07-14 16:26:23.000000000 +0200
+++ linux-3.16-rc5/drivers/md/dm-switch.c	2014-07-28 23:55:27.000000000 +0200
@@ -380,6 +380,49 @@ static int process_set_region_mappings(s
 		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 +551,7 @@ static int switch_iterate_devices(struct
 
 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,
Index: linux-3.16-rc5/Documentation/device-mapper/switch.txt
===================================================================
--- linux-3.16-rc5.orig/Documentation/device-mapper/switch.txt	2014-07-28 23:55:45.000000000 +0200
+++ linux-3.16-rc5/Documentation/device-mapper/switch.txt	2014-07-29 00:07:59.000000000 +0200
@@ -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 to quickly load repetitive patterns. <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 
 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
+

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-07-28 22:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-28 21:47 [PATCH 0/2] dm-switch: quickly load repetitive pattern Mikulas Patocka
2014-07-28 21:47 ` [PATCH 1/2] " Mikulas Patocka
2014-07-28 21:49   ` Mikulas Patocka
2014-07-28 21:48 ` [PATCH 2/2] dm-switch: allow repetitive patterns Mikulas Patocka
2014-07-28 22:11   ` [PATCH 2/2 v2] " Mikulas Patocka
2014-07-28 21:49 ` [PATCH 1/2] dm-switch: introdice switch_region_table_read Mikulas Patocka

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.