All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Grover <agrover@redhat.com>
To: dm-devel@redhat.com
Subject: [PATCH] dm-delay: Add a message to change delay
Date: Mon, 31 Aug 2015 14:24:36 -0700	[thread overview]
Message-ID: <1441056276-14288-1-git-send-email-agrover@redhat.com> (raw)

This enables runtime modification of the read and write delay values.

Make sure if the delay time is reduced to flush currently-delayed
bios first, to maintain ordering.

Signed-off-by: Andy Grover <agrover@redhat.com>
---
 Documentation/device-mapper/delay.txt |  8 +++++++
 drivers/md/dm-delay.c                 | 42 +++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/Documentation/device-mapper/delay.txt b/Documentation/device-mapper/delay.txt
index 15adc55..9e80751 100644
--- a/Documentation/device-mapper/delay.txt
+++ b/Documentation/device-mapper/delay.txt
@@ -10,6 +10,14 @@ Parameters:
 With separate write parameters, the first set is only used for reads.
 Delays are specified in milliseconds.
 
+Message Interface
+-----------------
+The delay target will accept a message of the following format:
+
+set_delay <read_delay> [<write_delay>]
+
+'man dmsetup' for more information on the message interface.
+
 Example scripts
 ===============
 [[
diff --git a/drivers/md/dm-delay.c b/drivers/md/dm-delay.c
index 57b6a19..04c2ab0 100644
--- a/drivers/md/dm-delay.c
+++ b/drivers/md/dm-delay.c
@@ -290,6 +290,47 @@ static int delay_map(struct dm_target *ti, struct bio *bio)
 	return delay_bio(dc, dc->read_delay, bio);
 }
 
+/* Message interface
+ *	set_delay <read_delay> [<write_delay>]
+*/
+static int delay_message(struct dm_target *ti, unsigned argc, char **argv)
+{
+	struct delay_c *dc = ti->private;
+	unsigned read_delay = dc->read_delay;
+	unsigned write_delay = dc->write_delay;
+	char dummy;
+
+	if (argc < 2 || argc > 3)
+		goto error;
+
+	if (strcasecmp(argv[0], "set_delay"))
+		goto error;
+
+	if (sscanf(argv[1], "%u%c", &read_delay, &dummy) != 1) {
+		ti->error = "Invalid read delay";
+		goto error;
+	}
+
+	if (argc == 3) {
+		if (sscanf(argv[2], "%u%c", &write_delay, &dummy) != 1) {
+			ti->error = "Invalid write delay";
+			goto error;
+		}
+	}
+
+	if (read_delay < dc->read_delay
+	    || write_delay < dc->write_delay)
+		flush_bios(flush_delayed_bios(dc, 1));
+
+	dc->read_delay = read_delay;
+	dc->write_delay = write_delay;
+	return 0;
+
+error:
+	DMWARN("unrecognised message received.");
+	return -EINVAL;
+}
+
 static void delay_status(struct dm_target *ti, status_type_t type,
 			 unsigned status_flags, char *result, unsigned maxlen)
 {
@@ -339,6 +380,7 @@ static struct target_type delay_target = {
 	.map	     = delay_map,
 	.presuspend  = delay_presuspend,
 	.resume	     = delay_resume,
+	.message     = delay_message,
 	.status	     = delay_status,
 	.iterate_devices = delay_iterate_devices,
 };
-- 
2.4.3

             reply	other threads:[~2015-08-31 21:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-31 21:24 Andy Grover [this message]
2015-09-01  2:05 ` [PATCH] dm-delay: Add a message to change delay Vivek Goyal
2015-09-01  5:02   ` Andy Grover
2015-09-01 12:14     ` Vivek Goyal
2015-09-01 13:09       ` Mike Snitzer
2015-09-01 14:17         ` Andy Grover
2015-09-01  8:55 ` [PATCH] " Zdenek Kabelac

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1441056276-14288-1-git-send-email-agrover@redhat.com \
    --to=agrover@redhat.com \
    --cc=dm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.