From 27f364af959c08b0f6e8973d1f82cafc23fbba11 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Wed, 2 Apr 2003 19:14:43 +0000 Subject: Allow for specification of major number as well as minor. --- tools/args.h | 3 +++ tools/commands.h | 10 +++++----- tools/lvchange.c | 33 ++++++++++++++++++++++----------- tools/lvcreate.c | 16 +++++++++++++--- tools/lvm.c | 17 +++++++++++++++++ tools/tools.h | 1 + 6 files changed, 61 insertions(+), 19 deletions(-) (limited to 'tools') diff --git a/tools/args.h b/tools/args.h index 32631901..df6c4660 100644 --- a/tools/args.h +++ b/tools/args.h @@ -8,6 +8,7 @@ * Put all long args that don't have a * corresponding short option first ... */ +/* *INDENT-OFF* */ arg(version_ARG, '\0', "version", NULL) arg(quiet_ARG, '\0', "quiet", NULL) arg(physicalvolumesize_ARG, '\0', "setphysicalvolumesize", size_mb_arg) @@ -61,6 +62,7 @@ arg(list_ARG, 'l', "list", NULL) arg(size_ARG, 'L', "size", size_mb_arg) arg(logicalextent_ARG, 'L', "logicalextent", int_arg_with_sign) arg(persistent_ARG, 'M', "persistent", yes_no_arg) +arg(major_ARG, 'j', "major", major_arg) arg(metadatatype_ARG, 'M', "metadatatype", metadatatype_arg) arg(minor_ARG, 'm', "minor", minor_arg) arg(maps_ARG, 'm', "maps", NULL) @@ -94,3 +96,4 @@ arg(zero_ARG, 'Z', "zero", yes_no_arg) /* this should always be last */ arg(ARG_COUNT, '-', "", NULL) +/* *INDENT-ON* */ diff --git a/tools/commands.h b/tools/commands.h index 4d8f9fd4..a4bd1bcc 100644 --- a/tools/commands.h +++ b/tools/commands.h @@ -56,7 +56,7 @@ xx(lvchange, "\t[-d|--debug]\n" "\t[-h|--help]\n" "\t[--ignorelockingfailure]\n" - "\t[-M|--persistent y|n] [--minor minor]\n" + "\t[-M|--persistent y|n] [--major major] [--minor minor]\n" "\t[-P|--partial] " "\n" "\t[-p|--permission r|rw]\n" "\t[-r|--readahead ReadAheadSectors]\n" @@ -66,7 +66,7 @@ xx(lvchange, "\tLogicalVolume[Path] [LogicalVolume[Path]...]\n", autobackup_ARG, available_ARG, contiguous_ARG, - ignorelockingfailure_ARG, minor_ARG, partial_ARG, permission_ARG, + ignorelockingfailure_ARG, major_ARG, minor_ARG, partial_ARG, permission_ARG, persistent_ARG, readahead_ARG, test_ARG) xx(lvcreate, @@ -79,7 +79,7 @@ xx(lvcreate, "\t[-i|--stripes Stripes [-I|--stripesize StripeSize]]\n" "\t{-l|--extents LogicalExtentsNumber |\n" "\t -L|--size LogicalVolumeSize[kKmMgGtT]}\n" - "\t[-M|--persistent {y|n}] [--minor minor]\n" + "\t[-M|--persistent {y|n}] [--major major] [--minor minor]\n" "\t[-n|--name LogicalVolumeName]\n" "\t[-p|--permission {r|rw}]\n" "\t[-r|--readahead ReadAheadSectors]\n" @@ -98,7 +98,7 @@ xx(lvcreate, "\t[-i|--stripes Stripes [-I|--stripesize StripeSize]]\n" "\t{-l|--extents LogicalExtentsNumber |\n" "\t -L|--size LogicalVolumeSize[kKmMgGtT]}\n" - "\t[-M|--persistent {y|n}] [--minor minor]\n" + "\t[-M|--persistent {y|n}] [--major major] [--minor minor]\n" "\t[-n|--name LogicalVolumeName]\n" "\t[-p|--permission {r|rw}]\n" "\t[-r|--readahead ReadAheadSectors]\n" @@ -107,7 +107,7 @@ xx(lvcreate, "\t[--version]\n" "\tOriginalLogicalVolume[Path] [PhysicalVolumePath...]\n\n", - autobackup_ARG, chunksize_ARG, contiguous_ARG, extents_ARG, minor_ARG, + autobackup_ARG, chunksize_ARG, contiguous_ARG, extents_ARG, major_ARG, minor_ARG, name_ARG, permission_ARG, persistent_ARG, readahead_ARG, size_ARG, snapshot_ARG, stripes_ARG, stripesize_ARG, test_ARG, zero_ARG) diff --git a/tools/lvchange.c b/tools/lvchange.c index 00010c04..b35c9beb 100644 --- a/tools/lvchange.c +++ b/tools/lvchange.c @@ -80,10 +80,6 @@ static int lvchange_availability(struct cmd_context *cmd, if (strcmp(arg_str_value(cmd, available_ARG, "n"), "n")) activate = 1; - if (arg_count(cmd, minor_ARG)) { - lv->minor = arg_int_value(cmd, minor_ARG, -1); - } - if (activate) { /* FIXME Tighter locking if lv_is_origin() */ log_verbose("Activating logical volume \"%s\"", lv->name); @@ -218,12 +214,18 @@ static int lvchange_persistent(struct cmd_context *cmd, } lv->status &= ~FIXED_MINOR; lv->minor = -1; - log_verbose("Disabling persistent minor for \"%s\"", lv->name); + lv->major = -1; + log_verbose("Disabling persistent device number for \"%s\"", + lv->name); } else { - if (!arg_count(cmd, minor_ARG)) { + if (!arg_count(cmd, minor_ARG) && lv->minor < 0) { log_error("Minor number must be specified with -My"); return 0; } + if (!arg_count(cmd, major_ARG) && lv->major < 0) { + log_error("Major number must be specified with -My"); + return 0; + } log_verbose("Ensuring %s is inactive. Reactivate with -ay.", lv->name); if (!lock_vol(cmd, lv->lvid.s, LCK_LV_DEACTIVATE)) { @@ -231,9 +233,10 @@ static int lvchange_persistent(struct cmd_context *cmd, return 0; } lv->status |= FIXED_MINOR; - lv->minor = arg_int_value(cmd, minor_ARG, -1); - log_verbose("Setting persistent minor number to %d for \"%s\"", - lv->minor, lv->name); + lv->minor = arg_int_value(cmd, minor_ARG, lv->minor); + lv->major = arg_int_value(cmd, major_ARG, lv->major); + log_verbose("Setting persistent device number to (%d, %d) " + "for \"%s\"", lv->major, lv->minor, lv->name); } if (!lock_vol(cmd, lv->lvid.s, LCK_LV_SUSPEND | LCK_HOLD)) { @@ -333,8 +336,10 @@ int lvchange(struct cmd_context *cmd, int argc, char **argv) { if (!arg_count(cmd, available_ARG) && !arg_count(cmd, contiguous_ARG) && !arg_count(cmd, permission_ARG) && !arg_count(cmd, readahead_ARG) - && !arg_count(cmd, minor_ARG) && !arg_count(cmd, persistent_ARG)) { - log_error("One or more of -a, -C, -m, -M, -p or -r required"); + && !arg_count(cmd, minor_ARG) && !arg_count(cmd, major_ARG) + && !arg_count(cmd, persistent_ARG)) { + log_error + ("One or more of -a, -C, -j, -m, -M, -p or -r required"); return EINVALID_CMD_LINE; } @@ -350,6 +355,12 @@ int lvchange(struct cmd_context *cmd, int argc, char **argv) return EINVALID_CMD_LINE; } + if ((arg_count(cmd, minor_ARG) || arg_count(cmd, major_ARG)) && + !arg_count(cmd, persistent_ARG)) { + log_error("--major and --minor require -My"); + return EINVALID_CMD_LINE; + } + if (arg_count(cmd, minor_ARG) && argc != 1) { log_error("Only give one logical volume when specifying minor"); return EINVALID_CMD_LINE; diff --git a/tools/lvcreate.c b/tools/lvcreate.c index 1b92fc7f..83fea1f5 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -14,6 +14,7 @@ struct lvcreate_params { int snapshot; int zero; int contiguous; + int major; int minor; char *origin; @@ -258,6 +259,7 @@ static int _read_params(struct lvcreate_params *lp, struct cmd_context *cmd, lp->permission = LVM_READ | LVM_WRITE; lp->minor = arg_int_value(cmd, minor_ARG, -1); + lp->major = arg_int_value(cmd, major_ARG, -1); /* Persistent minor */ if (arg_count(cmd, persistent_ARG)) { @@ -267,9 +269,15 @@ static int _read_params(struct lvcreate_params *lp, struct cmd_context *cmd, "--minor when using -My"); return 0; } + if (lp->major == -1) { + log_error("Please specify major number with " + "--major when using -My"); + return 0; + } } else { - if (lp->minor != -1) { - log_error("--minor not possible with -Mn"); + if ((lp->minor != -1) || (lp->major != -1)) { + log_error + ("--major and --minor incompatible with -Mn"); return 0; } } @@ -432,9 +440,11 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp) } if (lp->minor >= 0) { + lv->major = lp->major; lv->minor = lp->minor; lv->status |= FIXED_MINOR; - log_verbose("Setting minor number to %d", lv->minor); + log_verbose("Setting device number to (%d, %d)", lv->major, + lv->minor); } if (!archive(vg)) diff --git a/tools/lvm.c b/tools/lvm.c index b94e98a0..302c6aa4 100644 --- a/tools/lvm.c +++ b/tools/lvm.c @@ -213,6 +213,23 @@ int minor_arg(struct cmd_context *cmd, struct arg *a) return 1; } +int major_arg(struct cmd_context *cmd, struct arg *a) +{ + char *ptr; + + if (!_get_int_arg(a, &ptr) || (*ptr) || (a->sign == SIGN_MINUS)) + return 0; + + if (a->i_value > 255) { + log_error("Major number outside range 0-255"); + return 0; + } + + /* FIXME Also Check against /proc/devices */ + + return 1; +} + int string_arg(struct cmd_context *cmd, struct arg *a) { return 1; diff --git a/tools/tools.h b/tools/tools.h index 7f131b2d..873bad48 100644 --- a/tools/tools.h +++ b/tools/tools.h @@ -101,6 +101,7 @@ int size_kb_arg(struct cmd_context *cmd, struct arg *a); int size_mb_arg(struct cmd_context *cmd, struct arg *a); int int_arg(struct cmd_context *cmd, struct arg *a); int int_arg_with_sign(struct cmd_context *cmd, struct arg *a); +int major_arg(struct cmd_context *cmd, struct arg *a); int minor_arg(struct cmd_context *cmd, struct arg *a); int string_arg(struct cmd_context *cmd, struct arg *a); int permission_arg(struct cmd_context *cmd, struct arg *a); -- cgit