From: Alasdair Kergon Date: Tue, 6 Mar 2012 02:30:49 +0000 (+0000) Subject: Switch pvscan --cache major:minor to --major --minor. X-Git-Tag: v2_02_96~172 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=b343d75a5ab76eabd99d056453f18e139ff997e9;p=lvm2.git Switch pvscan --cache major:minor to --major --minor. --- diff --git a/WHATS_NEW b/WHATS_NEW index 15bb79f16..fcb57a1ef 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -4,6 +4,7 @@ Version 2.02.95 - Print just warning on thin pool check callback path for failing check. Always use 64bit math with VG extent_size expression. Validate udev structures in _insert_udev_dir(). + Take repeatable --major --minor with pvscan --cache instead of major:minor. Scan all devices for lvmetad if 'pvscan --cache' used without device list. Populate lvmcache from lvmetad before displaying PVs in pvscan. (2.02.94) Suppress incorrect -n pvscan warning now always displayed. (2.02.94) diff --git a/man/pvscan.8.in b/man/pvscan.8.in index 6f6f829af..014ef4ddf 100644 --- a/man/pvscan.8.in +++ b/man/pvscan.8.in @@ -3,7 +3,6 @@ pvscan \- scan all disks for physical volumes .SH SYNOPSIS .B pvscan -.RB [ \-\-cache " " [ DevicePath ... ] ] .RB [ \-d | \-\-debug ] .RB [ \-h | \-\-help ] .RB [ \-v | \-\-verbose ] @@ -13,6 +12,19 @@ pvscan \- scan all disks for physical volumes .RB [ \-n | \-\-novolumegroup ] .RB [ \-s | \-\-short ] .RB [ \-u | \-\-uuid ] +.BR + +.B pvscan +.RB [ \-d | \-\-debug ] +.RB [ \-h | \-\-help ] +.RB \-\-cache +.RB [ \-\-major +.IR major +.RB \-\-minor +.IR minor +| +.RI DevicePath +] ... .SH DESCRIPTION .B pvscan scans all supported LVM block devices in the system for physical volumes. @@ -31,7 +43,7 @@ Short listing format. .BR \-u ", " \-\-uuid Show UUIDs (Uniform Unique Identifiers) in addition to device special names. .TP -.BR \-\-cache " " [ DevicePath... ] +.BR \-\-cache " " [ " " \-\-major " " major " " \-\-minor " " minor " " | " " DevicePath " " ] " " ... Scan one or more devices and instruct the lvmetad daemon to update its cached state accordingly. Called internally by udev rules. All devices listed explicitly are processed \fBregardless\fP of any device diff --git a/tools/args.h b/tools/args.h index 321f3f6fa..f2fa14b4e 100644 --- a/tools/args.h +++ b/tools/args.h @@ -44,7 +44,7 @@ arg(addtag_ARG, '\0', "addtag", tag_arg, ARG_GROUPABLE) arg(deltag_ARG, '\0', "deltag", tag_arg, ARG_GROUPABLE) arg(refresh_ARG, '\0', "refresh", NULL, 0) arg(mknodes_ARG, '\0', "mknodes", NULL, 0) -arg(minor_ARG, '\0', "minor", minor_arg, 0) +arg(minor_ARG, '\0', "minor", minor_arg, ARG_GROUPABLE) arg(type_ARG, '\0', "type", segtype_arg, 0) arg(alloc_ARG, '\0', "alloc", alloc_arg, 0) arg(separator_ARG, '\0', "separator", string_arg, 0) @@ -115,7 +115,7 @@ arg(size_ARG, 'L', "size", size_mb_arg, 0) arg(logicalextent_ARG, 'L', "logicalextent", int_arg_with_sign, 0) arg(persistent_ARG, 'M', "persistent", yes_no_arg, 0) arg(merge_ARG, '\0', "merge", NULL, 0) -arg(major_ARG, 'j', "major", major_arg, 0) +arg(major_ARG, 'j', "major", major_arg, ARG_GROUPABLE) arg(mirrors_ARG, 'm', "mirrors", int_arg_with_sign, 0) arg(metadatatype_ARG, 'M', "metadatatype", metadatatype_arg, 0) arg(maps_ARG, 'm', "maps", NULL, 0) diff --git a/tools/commands.h b/tools/commands.h index ac25b1a37..bdef54687 100644 --- a/tools/commands.h +++ b/tools/commands.h @@ -663,7 +663,7 @@ xx(pvscan, "List all physical volumes", PERMITTED_READ_ONLY, "pvscan " "\n" - "\t[--cache [DevicePath...]] " "\n" + "\t[--cache [ DevicePath | --major major --minor minor]...\n" "\t[-d|--debug] " "\n" "\t{-e|--exported | -n|--novolumegroup} " "\n" "\t[-h|-?|--help]" "\n" @@ -674,8 +674,8 @@ xx(pvscan, "\t[-v|--verbose] " "\n" "\t[--version]\n", - cache_ARG, exported_ARG, ignorelockingfailure_ARG, novolumegroup_ARG, - partial_ARG, short_ARG, uuid_ARG) + cache_ARG, exported_ARG, ignorelockingfailure_ARG, major_ARG, minor_ARG, + novolumegroup_ARG, partial_ARG, short_ARG, uuid_ARG) xx(segtypes, "List available segment types", diff --git a/tools/lvchange.c b/tools/lvchange.c index 202a42abb..55799c66d 100644 --- a/tools/lvchange.c +++ b/tools/lvchange.c @@ -456,6 +456,14 @@ static int lvchange_persistent(struct cmd_context *cmd, log_error("Minor number must be specified with -My"); return 0; } + if (arg_count(cmd, major_ARG) > 1) { + log_error("Option -j/--major may not be repeated."); + return 0; + } + if (arg_count(cmd, minor_ARG) > 1) { + log_error("Option --minor may not be repeated."); + return 0; + } if (!arg_count(cmd, major_ARG) && lv->major < 0) { log_error("Major number must be specified with -My"); return 0; diff --git a/tools/lvcreate.c b/tools/lvcreate.c index ea5111bd7..def36b975 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -587,6 +587,16 @@ static int _read_activation_params(struct lvcreate_params *lp, struct cmd_contex if (!(lp->permission & LVM_WRITE)) lp->zero = 0; + if (arg_count(cmd, major_ARG) > 1) { + log_error("Option -j/--major may not be repeated."); + return 0; + } + + if (arg_count(cmd, minor_ARG) > 1) { + log_error("Option --minor may not be repeated."); + return 0; + } + lp->minor = arg_int_value(cmd, minor_ARG, -1); lp->major = arg_int_value(cmd, major_ARG, -1); diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c index 0a0d05795..6efd08246 100644 --- a/tools/lvmcmdline.c +++ b/tools/lvmcmdline.c @@ -89,6 +89,11 @@ const char *grouped_arg_str_value(const struct arg_values *av, int a, const char return grouped_arg_count(av, a) ? av[a].value : def; } +int32_t grouped_arg_int_value(const struct arg_values *av, int a, const int32_t def) +{ + return grouped_arg_count(av, a) ? av[a].i_value : def; +} + int32_t arg_int_value(struct cmd_context *cmd, int a, const int32_t def) { return arg_count(cmd, a) ? cmd->arg_values[a].i_value : def; diff --git a/tools/pvscan.c b/tools/pvscan.c index c21917783..f0e740817 100644 --- a/tools/pvscan.c +++ b/tools/pvscan.c @@ -21,52 +21,6 @@ int pv_max_name_len = 0; int vg_max_name_len = 0; -static dev_t _parse_devt(const char *str) -{ /* Oh. */ - char *where = (char *) str; - int major = strtol(str, &where, 10); - int minor; - - if (where == str) - return -1; - - if (*where != ':') - return -1; - - str = ++where; - minor = strtol(str, &where, 10); - - if (where == str) - return -1; - - if (*where) - return -1; - - return MKDEV(major, minor); -} - -/* - * Convert pv_name to struct device or to *devno. - */ -static struct device *_device_from_pv_name(const char *pv_name, dev_t *devno) -{ - struct device *dev; - - if ((dev = dev_cache_get(pv_name, NULL))) - return dev; - - if ((*devno = _parse_devt(pv_name)) == -1) { - log_error("Unrecognised device name %s. " - "(Use MAJOR:MINOR for new devices.)", pv_name); - return NULL; - } - - if ((dev = dev_cache_get_by_devt(*devno, NULL))) - return dev; - - return NULL; -} - static void _pvscan_display_single(struct cmd_context *cmd, struct physical_volume *pv, void *handle __attribute__((unused))) @@ -176,14 +130,28 @@ static int _pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv) int ret = ECMD_PROCESSED; struct device *dev; const char *pv_name; + int32_t major = -1; + int32_t minor = -1; + int devno_args = 0; + struct arg_value_group_list *current_group; dev_t devno; + char *buf; + + if (arg_count(cmd, major_ARG) + arg_count(cmd, minor_ARG)) + devno_args = 1; + if (devno_args && (!arg_count(cmd, major_ARG) || !arg_count(cmd, minor_ARG))) { + log_error("Both --major and --minor required to identify devices."); + return EINVALID_CMD_LINE; + } + if (!lock_vol(cmd, VG_GLOBAL, LCK_VG_READ)) { log_error("Unable to obtain global lock."); return ECMD_FAILED; } - if (!argc) { + /* Scan everything? */ + if (!argc && !devno_args) { if (!_pvscan_lvmetad_all_devs(cmd)) ret = ECMD_FAILED; goto out; @@ -191,19 +159,52 @@ static int _pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv) log_verbose("Using physical volume(s) on command line"); + /* Process any command line PVs first. */ while (argc--) { pv_name = *argv++; - dev = _device_from_pv_name(pv_name, &devno); + dev = dev_cache_get(pv_name, NULL); + if (!dev) { + log_error("Physical Volume %s not found.", pv_name); + ret = ECMD_FAILED; + continue; + } - if (!dev && devno != -1) { + if (!pvscan_lvmetad_single(cmd, dev)) { + ret = ECMD_FAILED; + break; + } + if (sigint_caught()) + break; + } + + if (!devno_args) + goto out; + + /* Process any grouped --major --minor args */ + dm_list_iterate_items(current_group, &cmd->arg_value_groups) { + major = grouped_arg_int_value(current_group->arg_values, major_ARG, major); + minor = grouped_arg_int_value(current_group->arg_values, minor_ARG, minor); + + if (major < 0 || minor < 0) + continue; + + devno = MKDEV(major, minor); + + if (!(dev = dev_cache_get_by_devt(devno, NULL))) { + if (!dm_asprintf(&buf, "%" PRIi32 ":%" PRIi32, major, minor)) + stack; /* FIXME Filters? */ - if (!lvmetad_pv_gone(devno, pv_name)) { + if (!lvmetad_pv_gone(devno, buf ? : "")) { ret = ECMD_FAILED; + if (buf) + dm_free(buf); break; } log_print("Device %s not found. " - "Cleared from lvmetad cache.", pv_name); + "Cleared from lvmetad cache.", buf ? : ""); + if (buf) + dm_free(buf); continue; } @@ -241,6 +242,11 @@ int pvscan(struct cmd_context *cmd, int argc, char **argv) if (arg_count(cmd, cache_ARG)) return _pvscan_lvmetad(cmd, argc, argv); + if (arg_count(cmd, major_ARG) + arg_count(cmd, minor_ARG)) { + log_error("--major and --minor are only valid with --cache."); + return EINVALID_CMD_LINE; + } + if (arg_count(cmd, novolumegroup_ARG) && arg_count(cmd, exported_ARG)) { log_error("Options -e and -n are incompatible"); return EINVALID_CMD_LINE; diff --git a/tools/tools.h b/tools/tools.h index 71c310acc..faceeac9a 100644 --- a/tools/tools.h +++ b/tools/tools.h @@ -173,6 +173,7 @@ int arg_count_increment(struct cmd_context *cmd, int a); unsigned grouped_arg_count(const struct arg_values *av, int a); unsigned grouped_arg_is_set(const struct arg_values *av, int a); const char *grouped_arg_str_value(const struct arg_values *av, int a, const char *def); +int32_t grouped_arg_int_value(const struct arg_values *av, int a, const int32_t def); const char *command_name(struct cmd_context *cmd); diff --git a/udev/69-dm-lvm-metad.rules b/udev/69-dm-lvm-metad.rules index e96c2c555..d6e416954 100644 --- a/udev/69-dm-lvm-metad.rules +++ b/udev/69-dm-lvm-metad.rules @@ -20,6 +20,6 @@ SUBSYSTEM!="block", GOTO="lvm_end" KERNEL=="dm-[0-9]*", ENV{DM_UDEV_RULES_VSN}!="?*", GOTO="lvm_end" # Only process devices already marked as a PV - this requires blkid to be called before. -ENV{ID_FS_TYPE}=="LVM2_member|LVM1_member", RUN+="$env{DM_SBIN_PATH}/pvscan --cache $major:$minor" +ENV{ID_FS_TYPE}=="LVM2_member|LVM1_member", RUN+="$env{DM_SBIN_PATH}/pvscan --cache --major $major --minor $minor" LABEL="lvm_end"