From patchwork Tue Sep 29 22:53:27 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Snitzer X-Patchwork-Id: 50618 Received: from hormel.redhat.com (hormel1.redhat.com [209.132.177.33]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n8TMrlOD017204 for ; Tue, 29 Sep 2009 22:53:49 GMT Received: from listman.util.phx.redhat.com (listman.util.phx.redhat.com [10.8.4.110]) by hormel.redhat.com (Postfix) with ESMTP id 3ADCB619BBD; Tue, 29 Sep 2009 18:53:47 -0400 (EDT) Received: from int-mx01.intmail.prod.int.phx2.redhat.com (nat-pool.util.phx.redhat.com [10.8.5.200]) by listman.util.phx.redhat.com (8.13.1/8.13.1) with ESMTP id n8TMrjL2030475 for ; Tue, 29 Sep 2009 18:53:45 -0400 Received: from localhost (dhcp-100-18-171.bos.redhat.com [10.16.18.171]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8TMrjow007945; Tue, 29 Sep 2009 18:53:45 -0400 From: Mike Snitzer To: dm-devel@redhat.com Date: Tue, 29 Sep 2009 18:53:27 -0400 Message-Id: <1254264823-11538-3-git-send-email-snitzer@redhat.com> In-Reply-To: <1254264823-11538-1-git-send-email-snitzer@redhat.com> References: <1254264823-11538-1-git-send-email-snitzer@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-loop: dm-devel@redhat.com Cc: Subject: [dm-devel] [PATCH 02/18] dm-exception-store-generalize-table-args X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.5 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com diff --git a/drivers/md/dm-exception-store.c b/drivers/md/dm-exception-store.c index 8f49f27..674b49b 100644 --- a/drivers/md/dm-exception-store.c +++ b/drivers/md/dm-exception-store.c @@ -187,16 +187,15 @@ int dm_exception_store_set_chunk_size(struct dm_exception_store *store, 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; } @@ -207,16 +206,7 @@ int dm_exception_store_create(struct dm_target *ti, int argc, char **argv, 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; @@ -226,6 +216,12 @@ int dm_exception_store_create(struct dm_target *ti, int argc, char **argv, 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) { @@ -233,17 +229,21 @@ int dm_exception_store_create(struct dm_target *ti, int argc, char **argv, 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; diff --git a/drivers/md/dm-exception-store.h b/drivers/md/dm-exception-store.h index 3e8fa02..2110e3b 100644 --- a/drivers/md/dm-exception-store.h +++ b/drivers/md/dm-exception-store.h @@ -172,8 +172,8 @@ int dm_exception_store_set_chunk_size(struct dm_exception_store *store, unsigned long chunk_size_ulong, 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); diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c index 3734289..109fbea 100644 --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -581,6 +582,43 @@ static int init_hash_tables(struct dm_snapshot *s) } /* + * create_exception_store + * @args_used: returned value enables snapshot_ctr 'feature args' processing + * @store: contains newly allocated dm_exception_store + * + * Possible formats for argv:: + * p/n + * + * 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:

*/ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) @@ -602,12 +640,9 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) 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;