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