dm-buffered: fix arguments Fix arguments so that they can be specified in any order - just like in other targets. Signed-off-by: Mikulas Patocka --- drivers/md/dm-buffered-target.c | 79 +++++++++++++--------------------------- 1 file changed, 26 insertions(+), 53 deletions(-) Index: linux-2.6/drivers/md/dm-buffered-target.c =================================================================== --- linux-2.6.orig/drivers/md/dm-buffered-target.c +++ linux-2.6/drivers/md/dm-buffered-target.c @@ -17,8 +17,7 @@ #define DM_MSG_PREFIX "buffered" -#define DEFAULT_BUFFERED_BLOCK_SIZE (SECTOR_SIZE << 3) /* 4KiB */ -#define MAX_BUFFERED_BLOCK_SIZE (SECTOR_SIZE << 13) /* 4MiB */ +#define DEFAULT_BUFFERED_BLOCK_SIZE (SECTOR_SIZE << 3) /* 4KiB */ enum stats { S_BUFFER_SPLITS, S_PREFLUSHS, S_FUA, S_SYNCS, S_READS, S_PREFETCHED_READS, S_PREFETCHED_WRITES, S_END, }; @@ -38,7 +37,6 @@ struct buffered_c { unsigned int block_shift; unsigned int buffer_size; unsigned int buffer_size_set:1; - unsigned int buffer_size_default:1; unsigned int discard:1; unsigned int discard_set:1; unsigned int discard_passdown:1; @@ -367,8 +365,8 @@ static int buffered_ctr(struct dm_target struct buffered_c *bc; int i, r; - if (argc < 2 || argc > 7) { - ti->error = "Requires 2 - 7 arguments"; + if (argc < 2) { + ti->error = "Requires at least 2 arguments"; return -EINVAL; } @@ -387,60 +385,37 @@ static int buffered_ctr(struct dm_target goto bad; } - if (argc > 2) { - if (!strcasecmp(argv[2], "-")) { - bc->buffer_size_default = true; - bc->buffer_size = DEFAULT_BUFFERED_BLOCK_SIZE; - } else { - bc->buffer_size_set = true; - r = (kstrtouint(argv[2], 10, &bc->buffer_size) || - !is_power_of_2(bc->buffer_size) || - bc->buffer_size < SECTOR_SIZE || - bc->buffer_size > MAX_BUFFERED_BLOCK_SIZE) ? -EINVAL : 0; - if (r) { + for (i = 2; i < argc; i++) { + const char *arg = argv[i]; + char dummy; + if (sscanf(arg, "block_size:%u%c", &bc->buffer_size, &dummy) == 1) { + if (!is_power_of_2(bc->buffer_size) || + bc->buffer_size < SECTOR_SIZE) { ti->error = "Invalid block size"; + r = -EINVAL; goto bad; } - } - } - - if (argc > 3) { - bc->discard_set = 1; - - if (!strcasecmp(argv[3], "no_discard")) { + bc->buffer_size_set = 1; + } else if (!strcmp(arg, "no_discard")) { bc->discard = 0; - } else if (!strcasecmp(argv[3], "discard")) { + bc->discard_set = 1; + } else if (!strcmp(arg, "discard")) { bc->discard = 1; - } else { - ti->error = "Invalid discard parameter"; - r = -EINVAL; - goto bad; - } - } - - if (argc > 4) { - bc->discard_passdown_set = 1; - - if (!strcasecmp(argv[4], "no_discard_passdown")) { + bc->discard_set = 1; + } else if (!strcmp(arg, "no_discard_passdown")) { bc->discard_passdown = 0; - } else if (!strcasecmp(argv[4], "discard_passdown")) { + bc->write_zeroes_set = 1; + } else if (!strcmp(arg, "discard_passdown")) { bc->discard_passdown = 1; - } else { - ti->error = "Invalid discard passdown parameter"; - r = -EINVAL; - goto bad; - } - } - - if (argc > 5) { - bc->write_zeroes_set = 1; - - if (!strcasecmp(argv[5], "no_write_zeroes")) { + bc->write_zeroes_set = 1; + } else if (!strcmp(arg, "no_write_zeroes")) { bc->write_zeroes = 0; - } else if (!strcasecmp(argv[5], "write_zeroes")) { + bc->write_zeroes_set = 1; + } else if (!strcmp(arg, "write_zeroes")) { bc->write_zeroes = 1; + bc->write_zeroes_set = 1; } else { - ti->error = "Invalid write zeroes parameter"; + ti->error = "Invalid argument"; r = -EINVAL; goto bad; } @@ -565,10 +540,8 @@ static void buffered_status(struct dm_ta switch (type) { case STATUSTYPE_TABLE: DMEMIT("%s %llu", bc->dev->name, (u64)bc->start); - if (bc->buffer_size_default) - DMEMIT(" -"); if (bc->buffer_size_set) - DMEMIT(" %u", bc->buffer_size); + DMEMIT(" block_size:%u", bc->buffer_size); if (bc->discard_set) DMEMIT(" %s", bc->discard ? "discard" : "no_discard"); if (bc->discard_passdown_set) @@ -646,7 +619,7 @@ static void buffered_io_hints(struct dm_ blk_limits_io_min(limits, limits->logical_block_size); blk_limits_io_opt(limits, bc->buffer_size); if (ti->num_write_zeroes_bios) - limits->max_write_zeroes_sectors = min(ti->len, to_sector(MAX_BUFFERED_BLOCK_SIZE)); + limits->max_write_zeroes_sectors = UINT_MAX; } static struct target_type buffered_target = {