]> sourceware.org Git - lvm2.git/commitdiff
Switch pvscan --cache major:minor to --major --minor.
authorAlasdair Kergon <agk@redhat.com>
Tue, 6 Mar 2012 02:30:49 +0000 (02:30 +0000)
committerAlasdair Kergon <agk@redhat.com>
Tue, 6 Mar 2012 02:30:49 +0000 (02:30 +0000)
WHATS_NEW
man/pvscan.8.in
tools/args.h
tools/commands.h
tools/lvchange.c
tools/lvcreate.c
tools/lvmcmdline.c
tools/pvscan.c
tools/tools.h
udev/69-dm-lvm-metad.rules

index 15bb79f16b5bcd3595e064ed115524845d0950ec..fcb57a1efd4da356ba0b0b5edf5a570ab127677e 100644 (file)
--- 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)
index 6f6f829af744c85ab9dde13e08795d0b1c00fafe..014ef4ddf0f751023da104112ed1d8138490a40a 100644 (file)
@@ -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
index 321f3f6fa8ea3140d620f60da60ec41831f39da0..f2fa14b4e2b5848abd3d171c7d10784e8b9a9c0c 100644 (file)
@@ -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)
index ac25b1a37654b6ebf6f7cd0de60d9baee09d4b56..bdef54687ced6c5dfa21e29bc4149db9fb195c5c 100644 (file)
@@ -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",
index 202a42abb224ca0779477b9357587c6c3c36af4f..55799c66d2ba0f40be84ab968917b79fdcbeb049 100644 (file)
@@ -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;
index ea5111bd77bac520dd6167b7200ca2e0a30bca66..def36b9753008de36cccdcb589d90bce4db63995 100644 (file)
@@ -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);
 
index 0a0d05795bc4b658c6e107337a416806b59e7cc0..6efd08246dc7bc93addcdf4786350c11cfde8da7 100644 (file)
@@ -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;
index c21917783619aff3735c3e0a1ee0b62aeff7c245..f0e740817acac30db0bb803e366e014439b26d5c 100644 (file)
 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;
index 71c310acced87cdffa7de20d3d9ae4f540dd0b49..faceeac9aa1e3b6c590965df828e3e915881fe0d 100644 (file)
@@ -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);
 
index e96c2c555e78e0b300dc760000bb29cbe578b8b7..d6e416954a70d040eb854641bcd2dac922201ff9 100644 (file)
@@ -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"
This page took 0.057235 seconds and 5 git commands to generate.