All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Snitzer <snitzer@redhat.com>
To: dm-devel@redhat.com
Subject: [PATCH v2 02/18] dm-exception-store-generalize-table-args
Date: Wed, 30 Sep 2009 10:44:24 -0400	[thread overview]
Message-ID: <20090930144423.GB16605@redhat.com> (raw)
In-Reply-To: <1254264823-11538-3-git-send-email-snitzer@redhat.com>

This patch is part of the work to generalize the dm-snapshot/
exception store API - necessary for future exception store
implementations.

This patch reworks 'dm_exception_store_create' arguments to make way for
cleaner interface when new constructor table format is introduced.

Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Reviewed-by: Mike Snitzer <snitzer@redhat.com>
---
v2: adjusted slightly to account for dm-snapshot-32bit-chunk-size.patch
---
 drivers/md/dm-exception-store.c |   36 +++++++++++++++---------------
 drivers/md/dm-exception-store.h |    4 +--
 drivers/md/dm-snap.c            |   47 ++++++++++++++++++++++++++++++++++------
 3 files changed, 61 insertions(+), 26 deletions(-)

Index: linux-2.6/drivers/md/dm-exception-store.c
===================================================================
--- linux-2.6.orig/drivers/md/dm-exception-store.c
+++ linux-2.6/drivers/md/dm-exception-store.c
@@ -186,16 +186,15 @@ int dm_exception_store_set_chunk_size(st
 	return 0;
 }
 
-int dm_exception_store_create(struct dm_target *ti, int argc, char **argv,
-			      unsigned *args_used,
+int dm_exception_store_create(const char *type_name, struct dm_target *ti,
+			      int argc, char **argv,
 			      struct dm_exception_store **store)
 {
 	int r = 0;
 	struct dm_exception_store_type *type = NULL;
 	struct dm_exception_store *tmp_store;
-	char persistent;
 
-	if (argc < 3) {
+	if (argc < 2) {
 		ti->error = "Insufficient exception store arguments";
 		return -EINVAL;
 	}
@@ -206,16 +205,7 @@ int dm_exception_store_create(struct dm_
 		return -ENOMEM;
 	}
 
-	persistent = toupper(*argv[1]);
-	if (persistent == 'P')
-		type = get_type("P");
-	else if (persistent == 'N')
-		type = get_type("N");
-	else {
-		ti->error = "Persistent flag is not P or N";
-		return -EINVAL;
-	}
-
+	type = get_type(type_name);
 	if (!type) {
 		ti->error = "Exception store type not recognised";
 		r = -EINVAL;
@@ -225,6 +215,12 @@ int dm_exception_store_create(struct dm_
 	tmp_store->type = type;
 	tmp_store->ti = ti;
 
+	/*
+	 * COW-dev and chunk_size are common to all types of
+	 * exception stores and are stored directly in the
+	 * dm_exception_store and not passed on to the
+	 * constructor for the dm_exception_store_type
+	 */
 	r = dm_get_device(ti, argv[0], 0, 0,
 			  FMODE_READ | FMODE_WRITE, &tmp_store->cow);
 	if (r) {
@@ -232,17 +228,21 @@ int dm_exception_store_create(struct dm_
 		goto bad_cow;
 	}
 
-	r = set_chunk_size(tmp_store, argv[2], &ti->error);
-	if (r)
+	r = set_chunk_size(tmp_store, argv[1], &ti->error);
+	if (r) {
+		ti->error = "Unable to set chunk size";
 		goto bad_cow;
+	}
+
+	argc -= 2;
+	argv += 2;
 
-	r = type->ctr(tmp_store, 0, NULL);
+	r = type->ctr(tmp_store, argc, argv);
 	if (r) {
 		ti->error = "Exception store type constructor failed";
 		goto bad_ctr;
 	}
 
-	*args_used = 3;
 	*store = tmp_store;
 	return 0;
 
Index: linux-2.6/drivers/md/dm-exception-store.h
===================================================================
--- linux-2.6.orig/drivers/md/dm-exception-store.h
+++ linux-2.6/drivers/md/dm-exception-store.h
@@ -172,8 +172,8 @@ int dm_exception_store_set_chunk_size(st
 				      unsigned chunk_size,
 				      char **error);
 
-int dm_exception_store_create(struct dm_target *ti, int argc, char **argv,
-			      unsigned *args_used,
+int dm_exception_store_create(const char *type_name, struct dm_target *ti,
+			      int argc, char **argv,
 			      struct dm_exception_store **store);
 void dm_exception_store_destroy(struct dm_exception_store *store);
 
Index: linux-2.6/drivers/md/dm-snap.c
===================================================================
--- linux-2.6.orig/drivers/md/dm-snap.c
+++ linux-2.6/drivers/md/dm-snap.c
@@ -7,6 +7,7 @@
  */
 
 #include <linux/blkdev.h>
+#include <linux/ctype.h>
 #include <linux/device-mapper.h>
 #include <linux/delay.h>
 #include <linux/fs.h>
@@ -581,6 +582,43 @@ static int init_hash_tables(struct dm_sn
 }
 
 /*
+ * create_exception_store
+ * @args_used: returned value enables snapshot_ctr 'feature args' processing
+ * @store: contains newly allocated dm_exception_store
+ *
+ * Possible formats for argv::
+ *     <COW-dev> p/n <chunk-size>
+ *
+ * Returns: 0 on success, -Exxx on error
+ */
+static int create_exception_store(struct dm_target *ti, unsigned argc,
+				  char **argv, unsigned *args_used,
+				  struct dm_exception_store **store)
+{
+	char *tmp_argv[2];
+	char old_type_name[2];
+
+	*store = NULL;
+
+	if (1 /* less change patch to patch */) {
+		if (argc < 3) {
+			ti->error = "Insufficient exception store arguments";
+			return -EINVAL;
+		}
+
+		tmp_argv[0] = argv[0];  /* COW dev */
+		tmp_argv[1] = argv[2];  /* chunk size */
+
+		*args_used = 3;
+		old_type_name[0] = toupper(*argv[1]);
+		old_type_name[1] = '\0';
+
+		return dm_exception_store_create(old_type_name, ti, 2,
+						 tmp_argv, store);
+	}
+}
+
+/*
  * Construct a snapshot mapping: <origin_dev> <COW-dev> <p/n> <chunk-size>
  */
 static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
@@ -602,12 +640,9 @@ static int snapshot_ctr(struct dm_target
 	argv++;
 	argc--;
 
-	r = dm_exception_store_create(ti, argc, argv, &args_used, &store);
-	if (r) {
-		ti->error = "Couldn't create exception store";
-		r = -EINVAL;
-		goto bad_args;
-	}
+	r = create_exception_store(ti, argc, argv, &args_used, &store);
+	if (r)
+		return r;
 
 	argv += args_used;
 	argc -= args_used;

  reply	other threads:[~2009-09-30 14:44 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-29 22:53 [PATCH 00/18] Clusterized exception store preparation Mike Snitzer
2009-09-29 22:53 ` [PATCH 01/18] dm-snap-consolidate-insert_exception-functions Mike Snitzer
2009-09-29 22:53 ` [PATCH 02/18] dm-exception-store-generalize-table-args Mike Snitzer
2009-09-30 14:44   ` Mike Snitzer [this message]
2009-09-29 22:53 ` [PATCH 03/18] dm-snapshot-new-ctr-table-format Mike Snitzer
2009-09-29 22:53 ` [PATCH 04/18] dm-snapshot-rename-dm_snap_exception-to-dm_exception Mike Snitzer
2009-09-29 22:53 ` [PATCH 05/18] dm-snapshot-rename-exception_table-to-dm_exception_table Mike Snitzer
2009-09-29 22:53 ` [PATCH 06/18] dm-snapshot-rename-exception-functions Mike Snitzer
2009-09-29 22:53 ` [PATCH 07/18] dm-snapshot-use-allocated-exception-tables Mike Snitzer
2009-09-29 22:53 ` [PATCH 08/18] dm-snapshot-exception-function-changes-1 Mike Snitzer
2009-09-29 22:53 ` [PATCH 09/18] dm-snapshot-exception-function-changes-2 Mike Snitzer
2009-09-29 22:53 ` [PATCH 10/18] dm-snapshot-exception-function-changes-3 Mike Snitzer
2009-09-29 22:53 ` [PATCH 11/18] dm-snapshot-exception-function-changes-4 Mike Snitzer
2009-09-29 22:53 ` [PATCH 12/18] dm-snapshot-exception-function-changes-5 Mike Snitzer
2009-09-29 22:53 ` [PATCH 13/18] dm-snapshot-exception-function-changes-6 Mike Snitzer
2009-09-29 22:53 ` [PATCH 14/18] dm-snapshot-move-exception-code-to-new-file Mike Snitzer
2009-09-29 22:53 ` [PATCH 15/18] dm-exception-store-create-local-exception-caches Mike Snitzer
2009-09-29 22:53 ` [PATCH 16/18] dm-exception-store-add-lookup_exception-to-API Mike Snitzer
2009-09-29 22:53 ` [PATCH 17/18] dm-snapshot-remove-completed-exception-cache Mike Snitzer
2009-09-29 22:53 ` [PATCH 18/18] dm-exstore-persistent-allow-metadata-reread Mike Snitzer
2009-09-30 14:46   ` [PATCH v2 " Mike Snitzer

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=20090930144423.GB16605@redhat.com \
    --to=snitzer@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.