dm target:s introduce iterate devices fn

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

authored by

Mike Snitzer and committed by
Alasdair G Kergon
af4874e0 1197764e

+105 -6
+10 -1
drivers/md/dm-crypt.c
··· 1313 return min(max_size, q->merge_bvec_fn(q, bvm, biovec)); 1314 } 1315 1316 static struct target_type crypt_target = { 1317 .name = "crypt", 1318 - .version= {1, 6, 0}, 1319 .module = THIS_MODULE, 1320 .ctr = crypt_ctr, 1321 .dtr = crypt_dtr, ··· 1334 .resume = crypt_resume, 1335 .message = crypt_message, 1336 .merge = crypt_merge, 1337 }; 1338 1339 static int __init dm_crypt_init(void)
··· 1313 return min(max_size, q->merge_bvec_fn(q, bvm, biovec)); 1314 } 1315 1316 + static int crypt_iterate_devices(struct dm_target *ti, 1317 + iterate_devices_callout_fn fn, void *data) 1318 + { 1319 + struct crypt_config *cc = ti->private; 1320 + 1321 + return fn(ti, cc->dev, cc->start, data); 1322 + } 1323 + 1324 static struct target_type crypt_target = { 1325 .name = "crypt", 1326 + .version = {1, 7, 0}, 1327 .module = THIS_MODULE, 1328 .ctr = crypt_ctr, 1329 .dtr = crypt_dtr, ··· 1326 .resume = crypt_resume, 1327 .message = crypt_message, 1328 .merge = crypt_merge, 1329 + .iterate_devices = crypt_iterate_devices, 1330 }; 1331 1332 static int __init dm_crypt_init(void)
+19 -1
drivers/md/dm-delay.c
··· 318 return 0; 319 } 320 321 static struct target_type delay_target = { 322 .name = "delay", 323 - .version = {1, 0, 2}, 324 .module = THIS_MODULE, 325 .ctr = delay_ctr, 326 .dtr = delay_dtr, ··· 345 .presuspend = delay_presuspend, 346 .resume = delay_resume, 347 .status = delay_status, 348 }; 349 350 static int __init dm_delay_init(void)
··· 318 return 0; 319 } 320 321 + static int delay_iterate_devices(struct dm_target *ti, 322 + iterate_devices_callout_fn fn, void *data) 323 + { 324 + struct delay_c *dc = ti->private; 325 + int ret = 0; 326 + 327 + ret = fn(ti, dc->dev_read, dc->start_read, data); 328 + if (ret) 329 + goto out; 330 + 331 + if (dc->dev_write) 332 + ret = fn(ti, dc->dev_write, dc->start_write, data); 333 + 334 + out: 335 + return ret; 336 + } 337 + 338 static struct target_type delay_target = { 339 .name = "delay", 340 + .version = {1, 1, 0}, 341 .module = THIS_MODULE, 342 .ctr = delay_ctr, 343 .dtr = delay_dtr, ··· 328 .presuspend = delay_presuspend, 329 .resume = delay_resume, 330 .status = delay_status, 331 + .iterate_devices = delay_iterate_devices, 332 }; 333 334 static int __init dm_delay_init(void)
+10 -1
drivers/md/dm-linear.c
··· 134 return min(max_size, q->merge_bvec_fn(q, bvm, biovec)); 135 } 136 137 static struct target_type linear_target = { 138 .name = "linear", 139 - .version= {1, 0, 3}, 140 .module = THIS_MODULE, 141 .ctr = linear_ctr, 142 .dtr = linear_dtr, ··· 152 .status = linear_status, 153 .ioctl = linear_ioctl, 154 .merge = linear_merge, 155 }; 156 157 int __init dm_linear_init(void)
··· 134 return min(max_size, q->merge_bvec_fn(q, bvm, biovec)); 135 } 136 137 + static int linear_iterate_devices(struct dm_target *ti, 138 + iterate_devices_callout_fn fn, void *data) 139 + { 140 + struct linear_c *lc = ti->private; 141 + 142 + return fn(ti, lc->dev, lc->start, data); 143 + } 144 + 145 static struct target_type linear_target = { 146 .name = "linear", 147 + .version = {1, 1, 0}, 148 .module = THIS_MODULE, 149 .ctr = linear_ctr, 150 .dtr = linear_dtr, ··· 144 .status = linear_status, 145 .ioctl = linear_ioctl, 146 .merge = linear_merge, 147 + .iterate_devices = linear_iterate_devices, 148 }; 149 150 int __init dm_linear_init(void)
+22 -1
drivers/md/dm-mpath.c
··· 1450 return r ? : __blkdev_driver_ioctl(bdev, mode, cmd, arg); 1451 } 1452 1453 /*----------------------------------------------------------------- 1454 * Module setup 1455 *---------------------------------------------------------------*/ 1456 static struct target_type multipath_target = { 1457 .name = "multipath", 1458 - .version = {1, 0, 5}, 1459 .module = THIS_MODULE, 1460 .ctr = multipath_ctr, 1461 .dtr = multipath_dtr, ··· 1486 .status = multipath_status, 1487 .message = multipath_message, 1488 .ioctl = multipath_ioctl, 1489 }; 1490 1491 static int __init dm_multipath_init(void)
··· 1450 return r ? : __blkdev_driver_ioctl(bdev, mode, cmd, arg); 1451 } 1452 1453 + static int multipath_iterate_devices(struct dm_target *ti, 1454 + iterate_devices_callout_fn fn, void *data) 1455 + { 1456 + struct multipath *m = ti->private; 1457 + struct priority_group *pg; 1458 + struct pgpath *p; 1459 + int ret = 0; 1460 + 1461 + list_for_each_entry(pg, &m->priority_groups, list) { 1462 + list_for_each_entry(p, &pg->pgpaths, list) { 1463 + ret = fn(ti, p->path.dev, ti->begin, data); 1464 + if (ret) 1465 + goto out; 1466 + } 1467 + } 1468 + 1469 + out: 1470 + return ret; 1471 + } 1472 + 1473 /*----------------------------------------------------------------- 1474 * Module setup 1475 *---------------------------------------------------------------*/ 1476 static struct target_type multipath_target = { 1477 .name = "multipath", 1478 + .version = {1, 1, 0}, 1479 .module = THIS_MODULE, 1480 .ctr = multipath_ctr, 1481 .dtr = multipath_dtr, ··· 1466 .status = multipath_status, 1467 .message = multipath_message, 1468 .ioctl = multipath_ioctl, 1469 + .iterate_devices = multipath_iterate_devices, 1470 }; 1471 1472 static int __init dm_multipath_init(void)
+16 -1
drivers/md/dm-raid1.c
··· 1283 return 0; 1284 } 1285 1286 static struct target_type mirror_target = { 1287 .name = "mirror", 1288 - .version = {1, 0, 20}, 1289 .module = THIS_MODULE, 1290 .ctr = mirror_ctr, 1291 .dtr = mirror_dtr, ··· 1309 .postsuspend = mirror_postsuspend, 1310 .resume = mirror_resume, 1311 .status = mirror_status, 1312 }; 1313 1314 static int __init dm_mirror_init(void)
··· 1283 return 0; 1284 } 1285 1286 + static int mirror_iterate_devices(struct dm_target *ti, 1287 + iterate_devices_callout_fn fn, void *data) 1288 + { 1289 + struct mirror_set *ms = ti->private; 1290 + int ret = 0; 1291 + unsigned i; 1292 + 1293 + for (i = 0; !ret && i < ms->nr_mirrors; i++) 1294 + ret = fn(ti, ms->mirror[i].dev, 1295 + ms->mirror[i].offset, data); 1296 + 1297 + return ret; 1298 + } 1299 + 1300 static struct target_type mirror_target = { 1301 .name = "mirror", 1302 + .version = {1, 12, 0}, 1303 .module = THIS_MODULE, 1304 .ctr = mirror_ctr, 1305 .dtr = mirror_dtr, ··· 1295 .postsuspend = mirror_postsuspend, 1296 .resume = mirror_resume, 1297 .status = mirror_status, 1298 + .iterate_devices = mirror_iterate_devices, 1299 }; 1300 1301 static int __init dm_mirror_init(void)
+17 -1
drivers/md/dm-stripe.c
··· 313 return error; 314 } 315 316 static struct target_type stripe_target = { 317 .name = "striped", 318 - .version = {1, 1, 0}, 319 .module = THIS_MODULE, 320 .ctr = stripe_ctr, 321 .dtr = stripe_dtr, 322 .map = stripe_map, 323 .end_io = stripe_end_io, 324 .status = stripe_status, 325 }; 326 327 int __init dm_stripe_init(void)
··· 313 return error; 314 } 315 316 + static int stripe_iterate_devices(struct dm_target *ti, 317 + iterate_devices_callout_fn fn, void *data) 318 + { 319 + struct stripe_c *sc = ti->private; 320 + int ret = 0; 321 + unsigned i = 0; 322 + 323 + do 324 + ret = fn(ti, sc->stripe[i].dev, 325 + sc->stripe[i].physical_start, data); 326 + while (!ret && ++i < sc->stripes); 327 + 328 + return ret; 329 + } 330 + 331 static struct target_type stripe_target = { 332 .name = "striped", 333 + .version = {1, 2, 0}, 334 .module = THIS_MODULE, 335 .ctr = stripe_ctr, 336 .dtr = stripe_dtr, 337 .map = stripe_map, 338 .end_io = stripe_end_io, 339 .status = stripe_status, 340 + .iterate_devices = stripe_iterate_devices, 341 }; 342 343 int __init dm_stripe_init(void)
+11
include/linux/device-mapper.h
··· 11 #include <linux/bio.h> 12 #include <linux/blkdev.h> 13 14 struct dm_target; 15 struct dm_table; 16 struct mapped_device; ··· 82 typedef int (*dm_merge_fn) (struct dm_target *ti, struct bvec_merge_data *bvm, 83 struct bio_vec *biovec, int max_size); 84 85 /* 86 * Returns: 87 * 0: The target can handle the next I/O immediately. ··· 149 dm_ioctl_fn ioctl; 150 dm_merge_fn merge; 151 dm_busy_fn busy; 152 153 /* For internal device-mapper use. */ 154 struct list_head list;
··· 11 #include <linux/bio.h> 12 #include <linux/blkdev.h> 13 14 + struct dm_dev; 15 struct dm_target; 16 struct dm_table; 17 struct mapped_device; ··· 81 typedef int (*dm_merge_fn) (struct dm_target *ti, struct bvec_merge_data *bvm, 82 struct bio_vec *biovec, int max_size); 83 84 + typedef int (*iterate_devices_callout_fn) (struct dm_target *ti, 85 + struct dm_dev *dev, 86 + sector_t physical_start, 87 + void *data); 88 + 89 + typedef int (*dm_iterate_devices_fn) (struct dm_target *ti, 90 + iterate_devices_callout_fn fn, 91 + void *data); 92 + 93 /* 94 * Returns: 95 * 0: The target can handle the next I/O immediately. ··· 139 dm_ioctl_fn ioctl; 140 dm_merge_fn merge; 141 dm_busy_fn busy; 142 + dm_iterate_devices_fn iterate_devices; 143 144 /* For internal device-mapper use. */ 145 struct list_head list;