9 #include <linux/module.h>
13 #include <linux/slab.h>
16 #define DM_MSG_PREFIX "striped"
17 #define DM_IO_ERROR_THRESHOLD 15
73 unsigned int stripe,
char **argv)
75 unsigned long long start;
78 if (
sscanf(argv[1],
"%llu%c", &start, &dummy) != 1)
94 static int stripe_ctr(
struct dm_target *ti,
unsigned int argc,
char **argv)
104 ti->
error =
"Not enough arguments";
108 if (
kstrtouint(argv[0], 10, &stripes) || !stripes) {
109 ti->
error =
"Invalid stripe count";
113 if (
kstrtouint(argv[1], 10, &chunk_size) || !chunk_size) {
114 ti->
error =
"Invalid chunk_size";
120 ti->
error =
"Target length not divisible by "
126 ti->
error =
"Target length not divisible by "
134 if (argc != (2 + 2 * stripes)) {
135 ti->
error =
"Not enough destinations "
140 sc = alloc_context(stripes);
142 ti->
error =
"Memory allocation for striped context "
154 if (stripes & (stripes - 1))
167 if (chunk_size & (chunk_size - 1))
175 for (i = 0; i <
stripes; i++) {
178 r = get_stripe(ti, sc, i, argv);
180 ti->
error =
"Couldn't parse stripe destination";
194 static void stripe_dtr(
struct dm_target *ti)
222 *stripe = chunk & (sc->
stripes - 1);
239 stripe_map_sector(sc, sector, &stripe, result);
240 if (stripe == target_stripe)
250 if (target_stripe < stripe)
254 static int stripe_map_discard(
struct stripe_c *sc,
struct bio *bio,
259 stripe_map_range_sector(sc, bio->bi_sector, target_stripe, &begin);
260 stripe_map_range_sector(sc, bio->bi_sector + bio_sectors(bio),
261 target_stripe, &end);
263 bio->bi_bdev = sc->
stripe[target_stripe].dev->bdev;
264 bio->bi_sector = begin + sc->
stripe[target_stripe].physical_start;
265 bio->bi_size = to_bytes(end - begin);
274 static int stripe_map(
struct dm_target *ti,
struct bio *bio,
279 unsigned target_request_nr;
284 bio->bi_bdev = sc->
stripe[target_request_nr].dev->bdev;
290 return stripe_map_discard(sc, bio, target_request_nr);
293 stripe_map_sector(sc, bio->bi_sector, &stripe, &bio->bi_sector);
315 unsigned status_flags,
char *result,
unsigned maxlen)
325 for (i = 0; i < sc->
stripes; i++) {
337 for (i = 0; i < sc->
stripes; i++)
339 (
unsigned long long)sc->
stripe[i].physical_start);
345 static int stripe_end_io(
struct dm_target *ti,
struct bio *bio,
349 char major_minor[16];
361 memset(major_minor, 0,
sizeof(major_minor));
363 MAJOR(disk_devt(bio->bi_bdev->bd_disk)),
364 MINOR(disk_devt(bio->bi_bdev->bd_disk)));
372 for (i = 0; i < sc->
stripes; i++)
383 static int stripe_iterate_devices(
struct dm_target *ti,
392 sc->
stripe[i].physical_start,
394 }
while (!ret && ++i < sc->stripes);
399 static void stripe_io_hints(
struct dm_target *ti,
400 struct queue_limits *limits)
409 static int stripe_merge(
struct dm_target *ti,
struct bvec_merge_data *bvm,
410 struct bio_vec *biovec,
int max_size)
413 sector_t bvm_sector = bvm->bi_sector;
417 stripe_map_sector(sc, bvm_sector, &stripe, &bvm_sector);
419 q = bdev_get_queue(sc->
stripe[stripe].dev->bdev);
420 if (!q->merge_bvec_fn)
424 bvm->bi_sector = sc->
stripe[
stripe].physical_start + bvm_sector;
426 return min(max_size, q->merge_bvec_fn(q, bvm, biovec));
431 .version = {1, 5, 0},
436 .end_io = stripe_end_io,
437 .status = stripe_status,
438 .iterate_devices = stripe_iterate_devices,
439 .io_hints = stripe_io_hints,
440 .merge = stripe_merge,
449 DMWARN(
"target registration failed");