]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
Introduce the concept of a singleton table which contains exactly one target.
authorAlasdair G Kergon <agk@redhat.com>
Wed, 3 Aug 2011 00:43:44 +0000 (10:43 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 3 Aug 2011 00:43:44 +0000 (10:43 +1000)
If a target type sets the DM_TARGET_SINGLETON feature bit device-mapper
will ensure that any table that includes that target contains no others.

The thin provisioning pool target uses this.

Signed-off-by: Alasdair G Kergon <agk@redhat.com>
drivers/md/dm-table.c
include/linux/device-mapper.h

index 986b8754bb0813c59fb22a0feae7083740378f72..26aef82a88d8367890ddc8b6233097684d8d92c0 100644 (file)
@@ -55,6 +55,7 @@ struct dm_table {
        struct dm_target *targets;
 
        unsigned integrity_supported:1;
+       unsigned singleton:1;
 
        /*
         * Indicates the rw permissions for the new logical
@@ -740,6 +741,12 @@ int dm_table_add_target(struct dm_table *t, const char *type,
        char **argv;
        struct dm_target *tgt;
 
+       if (t->singleton) {
+               DMERR("%s: target type %s must appear alone in table",
+                     dm_device_name(t->md), t->targets->type->name);
+               return -EINVAL;
+       }
+
        if ((r = check_space(t)))
                return r;
 
@@ -758,6 +765,15 @@ int dm_table_add_target(struct dm_table *t, const char *type,
                return -EINVAL;
        }
 
+       if (dm_target_needs_singleton(tgt->type)) {
+               if (t->num_targets) {
+                       DMERR("%s: target type %s must appear alone in table",
+                             dm_device_name(t->md), type);
+                       return -EINVAL;
+               }
+               t->singleton = 1;
+       }
+
        tgt->table = t;
        tgt->begin = start;
        tgt->len = len;
index 3fa1f3d90ce0e21cb3ba27fa98d3201252f91f8e..310d0a65d12e29c489fb5fa3d2737a10427bfcc8 100644 (file)
@@ -127,10 +127,6 @@ void dm_put_device(struct dm_target *ti, struct dm_dev *d);
  * Information about a target type
  */
 
-/*
- * Target features
- */
-
 struct target_type {
        uint64_t features;
        const char *name;
@@ -159,6 +155,16 @@ struct target_type {
        struct list_head list;
 };
 
+/*
+ * Target features
+ */
+
+/*
+ * Any table that contains an instance of this target must have only one.
+ */
+#define DM_TARGET_SINGLETON            0x00000001
+#define dm_target_needs_singleton(type)        ((type)->features & DM_TARGET_SINGLETON)
+
 struct dm_target {
        struct dm_table *table;
        struct target_type *type;