dm target:s introduce iterate devices fn
authorMike Snitzer <snitzer@redhat.com>
Mon, 22 Jun 2009 09:12:33 +0000 (10:12 +0100)
committerAlasdair G Kergon <agk@redhat.com>
Mon, 22 Jun 2009 09:12:33 +0000 (10:12 +0100)
Add .iterate_devices to 'struct target_type' to allow a function to be
called for all devices in a DM target.  Implemented it for all targets
except those in dm-snap.c (origin and snapshot).

(The raid1 version number jumps to 1.12 because we originally reserved
1.1 to 1.11 for 'block_on_error' but ended up using 'handle_errors'
instead.)

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Cc: martin.petersen@oracle.com
drivers/md/dm-crypt.c
drivers/md/dm-delay.c
drivers/md/dm-linear.c
drivers/md/dm-mpath.c
drivers/md/dm-raid1.c
drivers/md/dm-stripe.c
include/linux/device-mapper.h

index 04db6c4004a8c387d6c361f7ce036173fa2e6bfb..9933eb861c7191b34fe43b9ac01deb5e44bd614f 100644 (file)
@@ -1313,9 +1313,17 @@ static int crypt_merge(struct dm_target *ti, struct bvec_merge_data *bvm,
        return min(max_size, q->merge_bvec_fn(q, bvm, biovec));
 }
 
+static int crypt_iterate_devices(struct dm_target *ti,
+                                iterate_devices_callout_fn fn, void *data)
+{
+       struct crypt_config *cc = ti->private;
+
+       return fn(ti, cc->dev, cc->start, data);
+}
+
 static struct target_type crypt_target = {
        .name   = "crypt",
-       .version= {1, 6, 0},
+       .version = {1, 7, 0},
        .module = THIS_MODULE,
        .ctr    = crypt_ctr,
        .dtr    = crypt_dtr,
@@ -1326,6 +1334,7 @@ static struct target_type crypt_target = {
        .resume = crypt_resume,
        .message = crypt_message,
        .merge  = crypt_merge,
+       .iterate_devices = crypt_iterate_devices,
 };
 
 static int __init dm_crypt_init(void)
index 8ad8a9044bbfe0aa757361ad876778ce76d6bc8f..4e5b843cd4d77fb388920991eefd5540e2399aef 100644 (file)
@@ -318,9 +318,26 @@ static int delay_status(struct dm_target *ti, status_type_t type,
        return 0;
 }
 
+static int delay_iterate_devices(struct dm_target *ti,
+                                iterate_devices_callout_fn fn, void *data)
+{
+       struct delay_c *dc = ti->private;
+       int ret = 0;
+
+       ret = fn(ti, dc->dev_read, dc->start_read, data);
+       if (ret)
+               goto out;
+
+       if (dc->dev_write)
+               ret = fn(ti, dc->dev_write, dc->start_write, data);
+
+out:
+       return ret;
+}
+
 static struct target_type delay_target = {
        .name        = "delay",
-       .version     = {1, 0, 2},
+       .version     = {1, 1, 0},
        .module      = THIS_MODULE,
        .ctr         = delay_ctr,
        .dtr         = delay_dtr,
@@ -328,6 +345,7 @@ static struct target_type delay_target = {
        .presuspend  = delay_presuspend,
        .resume      = delay_resume,
        .status      = delay_status,
+       .iterate_devices = delay_iterate_devices,
 };
 
 static int __init dm_delay_init(void)
index ecbb17421da47d1631f0c7055357f52b88c4b6b7..9184b6deb8685dc3660e21dd438f6aa8fcd200b3 100644 (file)
@@ -134,9 +134,17 @@ static int linear_merge(struct dm_target *ti, struct bvec_merge_data *bvm,
        return min(max_size, q->merge_bvec_fn(q, bvm, biovec));
 }
 
+static int linear_iterate_devices(struct dm_target *ti,
+                                 iterate_devices_callout_fn fn, void *data)
+{
+       struct linear_c *lc = ti->private;
+
+       return fn(ti, lc->dev, lc->start, data);
+}
+
 static struct target_type linear_target = {
        .name   = "linear",
-       .version= {1, 0, 3},
+       .version = {1, 1, 0},
        .module = THIS_MODULE,
        .ctr    = linear_ctr,
        .dtr    = linear_dtr,
@@ -144,6 +152,7 @@ static struct target_type linear_target = {
        .status = linear_status,
        .ioctl  = linear_ioctl,
        .merge  = linear_merge,
+       .iterate_devices = linear_iterate_devices,
 };
 
 int __init dm_linear_init(void)
index 890c0e8ed13eaae7d78c75f81eb3503314d1dac2..f8aeaaa54afe1bd5a65ae3a2bb02d1b7dc323708 100644 (file)
@@ -1450,12 +1450,32 @@ static int multipath_ioctl(struct dm_target *ti, unsigned int cmd,
        return r ? : __blkdev_driver_ioctl(bdev, mode, cmd, arg);
 }
 
+static int multipath_iterate_devices(struct dm_target *ti,
+                                    iterate_devices_callout_fn fn, void *data)
+{
+       struct multipath *m = ti->private;
+       struct priority_group *pg;
+       struct pgpath *p;
+       int ret = 0;
+
+       list_for_each_entry(pg, &m->priority_groups, list) {
+               list_for_each_entry(p, &pg->pgpaths, list) {
+                       ret = fn(ti, p->path.dev, ti->begin, data);
+                       if (ret)
+                               goto out;
+               }
+       }
+
+out:
+       return ret;
+}
+
 /*-----------------------------------------------------------------
  * Module setup
  *---------------------------------------------------------------*/
 static struct target_type multipath_target = {
        .name = "multipath",
-       .version = {1, 0, 5},
+       .version = {1, 1, 0},
        .module = THIS_MODULE,
        .ctr = multipath_ctr,
        .dtr = multipath_dtr,
@@ -1466,6 +1486,7 @@ static struct target_type multipath_target = {
        .status = multipath_status,
        .message = multipath_message,
        .ioctl  = multipath_ioctl,
+       .iterate_devices = multipath_iterate_devices,
 };
 
 static int __init dm_multipath_init(void)
index 076fbb4e967a4a651116c029983237d942b3f1ac..ce8868c768cce1c411d3ba76d4eae5b9011bee64 100644 (file)
@@ -1283,9 +1283,23 @@ static int mirror_status(struct dm_target *ti, status_type_t type,
        return 0;
 }
 
+static int mirror_iterate_devices(struct dm_target *ti,
+                                 iterate_devices_callout_fn fn, void *data)
+{
+       struct mirror_set *ms = ti->private;
+       int ret = 0;
+       unsigned i;
+
+       for (i = 0; !ret && i < ms->nr_mirrors; i++)
+               ret = fn(ti, ms->mirror[i].dev,
+                        ms->mirror[i].offset, data);
+
+       return ret;
+}
+
 static struct target_type mirror_target = {
        .name    = "mirror",
-       .version = {1, 0, 20},
+       .version = {1, 12, 0},
        .module  = THIS_MODULE,
        .ctr     = mirror_ctr,
        .dtr     = mirror_dtr,
@@ -1295,6 +1309,7 @@ static struct target_type mirror_target = {
        .postsuspend = mirror_postsuspend,
        .resume  = mirror_resume,
        .status  = mirror_status,
+       .iterate_devices = mirror_iterate_devices,
 };
 
 static int __init dm_mirror_init(void)
index c64fe827a5f19abc60c2040b0690ca9b5003598c..b240e85ae39aa4b444135b0a71823e35b03aac49 100644 (file)
@@ -313,15 +313,31 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
        return error;
 }
 
+static int stripe_iterate_devices(struct dm_target *ti,
+                                 iterate_devices_callout_fn fn, void *data)
+{
+       struct stripe_c *sc = ti->private;
+       int ret = 0;
+       unsigned i = 0;
+
+       do
+               ret = fn(ti, sc->stripe[i].dev,
+                        sc->stripe[i].physical_start, data);
+       while (!ret && ++i < sc->stripes);
+
+       return ret;
+}
+
 static struct target_type stripe_target = {
        .name   = "striped",
-       .version = {1, 1, 0},
+       .version = {1, 2, 0},
        .module = THIS_MODULE,
        .ctr    = stripe_ctr,
        .dtr    = stripe_dtr,
        .map    = stripe_map,
        .end_io = stripe_end_io,
        .status = stripe_status,
+       .iterate_devices = stripe_iterate_devices,
 };
 
 int __init dm_stripe_init(void)
index 236880c1dc3fca9c65a02de09061f360ce436d9f..deac3b4e5e18afdc4dfbf4c86715590b615ad02f 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/bio.h>
 #include <linux/blkdev.h>
 
+struct dm_dev;
 struct dm_target;
 struct dm_table;
 struct mapped_device;
@@ -81,6 +82,15 @@ typedef int (*dm_ioctl_fn) (struct dm_target *ti, unsigned int cmd,
 typedef int (*dm_merge_fn) (struct dm_target *ti, struct bvec_merge_data *bvm,
                            struct bio_vec *biovec, int max_size);
 
+typedef int (*iterate_devices_callout_fn) (struct dm_target *ti,
+                                          struct dm_dev *dev,
+                                          sector_t physical_start,
+                                          void *data);
+
+typedef int (*dm_iterate_devices_fn) (struct dm_target *ti,
+                                     iterate_devices_callout_fn fn,
+                                     void *data);
+
 /*
  * Returns:
  *    0: The target can handle the next I/O immediately.
@@ -139,6 +149,7 @@ struct target_type {
        dm_ioctl_fn ioctl;
        dm_merge_fn merge;
        dm_busy_fn busy;
+       dm_iterate_devices_fn iterate_devices;
 
        /* For internal device-mapper use. */
        struct list_head list;