summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlasdair Kergon <agk@redhat.com>2012-03-02 16:58:41 +0000
committerAlasdair Kergon <agk@redhat.com>2012-03-02 16:58:41 +0000
commitd06f64dd29a689ab0e97659a37ccb83819b75c3a (patch)
treee02578d71ce48575496b0d5a9b77aa7154423faa
parent6a5706a3a52607d1d7a2517aad4ba2727e0986e2 (diff)
downloadlvm2-d06f64dd29a689ab0e97659a37ccb83819b75c3a.tar.gz
lvm2-d06f64dd29a689ab0e97659a37ccb83819b75c3a.tar.xz
lvm2-d06f64dd29a689ab0e97659a37ccb83819b75c3a.zip
Allow multiple device names with pvscan --lvmetad.
Hold global lock in pvscan --lvmetad. (This might need refinement.) Add PV name to "PV gone" messages. Adjust some log message severities. (More changes needed.)
-rw-r--r--lib/cache/lvmetad.c56
-rw-r--r--lib/cache/lvmetad.h6
-rw-r--r--man/pvscan.8.in4
-rw-r--r--tools/commands.h2
-rw-r--r--tools/pvremove.c2
-rw-r--r--tools/pvscan.c39
6 files changed, 67 insertions, 42 deletions
diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c
index 3847ee65..b1e46041 100644
--- a/lib/cache/lvmetad.c
+++ b/lib/cache/lvmetad.c
@@ -31,7 +31,7 @@ void lvmetad_init(void)
if (_using_lvmetad) { /* configured by the toolcontext */
_lvmetad = lvmetad_open(socket ?: DEFAULT_RUN_DIR "/lvmetad.socket");
if (_lvmetad.socket_fd < 0 || _lvmetad.error) {
- log_warn("Failed to connect to lvmetad: %s. Falling back to scanning.", strerror(_lvmetad.error));
+ log_warn("WARNING: Failed to connect to lvmetad: %s. Falling back to scanning.", strerror(_lvmetad.error));
_using_lvmetad = 0;
}
}
@@ -91,7 +91,7 @@ static struct lvmcache_info *_pv_populate_lvmcache(
struct format_type *fmt = fmt_name ? get_format_by_name(cmd, fmt_name) : NULL;
if (!fmt) {
- log_warn("No format for PV %s. It is probably missing.", pvid_txt);
+ log_error("PV %s not recognised. Is the device missing?", pvid_txt);
return NULL;
}
@@ -100,12 +100,12 @@ static struct lvmcache_info *_pv_populate_lvmcache(
device = dev_cache_get_by_devt(fallback, cmd->filter);
if (!device) {
- log_warn("No device for PV %s.", pvid_txt);
+ log_error("No device found for PV %s.", pvid_txt);
return NULL;
}
if (!pvid_txt || !id_read_format(&pvid, pvid_txt)) {
- log_warn("Missing or ill-formatted PVID for PV: %s.", pvid_txt);
+ log_error("Missing or ill-formatted PVID for PV: %s.", pvid_txt);
return NULL;
}
@@ -556,7 +556,7 @@ int lvmetad_pv_found(struct id pvid, struct device *device, const struct format_
return _lvmetad_handle_reply(reply, "update PV", uuid);
}
-int lvmetad_pv_gone(dev_t device)
+static int _lvmetad_pv_gone(dev_t device, const char *pv_name)
{
if (!_using_lvmetad)
return 1;
@@ -564,7 +564,12 @@ int lvmetad_pv_gone(dev_t device)
daemon_reply reply =
daemon_send_simple(_lvmetad, "pv_gone", "device = %d", device, NULL);
- return _lvmetad_handle_reply(reply, "drop PV", "");
+ return _lvmetad_handle_reply(reply, "drop PV", pv_name);
+}
+
+int lvmetad_pv_gone(struct device *dev)
+{
+ return _lvmetad_pv_gone(dev->dev, dev_name(dev));
}
int lvmetad_active(void)
@@ -623,7 +628,7 @@ static dev_t _parse_devt(const char *str)
return MKDEV(major, minor);
}
-int pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv)
+int pvscan_lvmetad_single(struct cmd_context *cmd, const char *pv_name)
{
struct device *dev;
struct label *label;
@@ -633,37 +638,32 @@ int pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv)
/* Create a dummy instance. */
struct format_instance_ctx fic = { .type = 0 };
- if (argc != 1) {
- log_error("Exactly one device parameter required.");
- return 0;
- }
-
if (!lvmetad_active()) {
log_error("Cannot proceed since lvmetad is not active.");
return 0;
}
- dev = dev_cache_get(argv[0], NULL);
- if (!dev && _parse_devt(argv[0]) != -1)
- dev = dev_cache_get_by_devt(_parse_devt(argv[0]), NULL);
+ dev = dev_cache_get(pv_name, NULL);
+ if (!dev && _parse_devt(pv_name) != -1)
+ dev = dev_cache_get_by_devt(_parse_devt(pv_name), NULL);
if (!dev) {
- if (_parse_devt(argv[0]) == -1) {
- log_error("For devices that do not exist, we need a MAJOR:MINOR pair.");
+ if (_parse_devt(pv_name) == -1) {
+ log_error("Unrecognised device name %s. (Use MAJOR:MINOR for new devices.)", pv_name);
return 0;
}
- if (!lvmetad_pv_gone(_parse_devt(argv[0])))
- goto fatal;
+ if (!_lvmetad_pv_gone(_parse_devt(pv_name), pv_name))
+ goto_bad;
- log_info("Device %s not found and was wiped from lvmetad.", argv[0]);
+ log_print("Device %s not found. Cleared from lvmetad cache.", pv_name);
return 1;
}
if (!label_read(dev, &label, 0)) {
- log_warn("No PV label found on %s.", dev_name(dev));
- if (!lvmetad_pv_gone(dev->dev))
- goto fatal;
+ log_print("No PV label found on %s.", dev_name(dev));
+ if (!lvmetad_pv_gone(dev))
+ goto_bad;
return 1;
}
@@ -684,13 +684,15 @@ int pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv)
* sync needs to be killed.
*/
if (!lvmetad_pv_found(*(struct id *)dev->pvid, dev, lvmcache_fmt(info),
- label->sector, baton.vg))
- goto fatal;
+ label->sector, baton.vg)) {
+ release_vg(baton.vg);
+ goto_bad;
+ }
release_vg(baton.vg);
return 1;
-fatal:
- release_vg(baton.vg);
+
+bad:
/* FIXME kill lvmetad automatically if we can */
log_error("Update of lvmetad failed. This is a serious problem.\n "
"It is strongly recommended that you restart lvmetad immediately.");
diff --git a/lib/cache/lvmetad.h b/lib/cache/lvmetad.h
index ff38096c..32a7e2f2 100644
--- a/lib/cache/lvmetad.h
+++ b/lib/cache/lvmetad.h
@@ -71,7 +71,7 @@ int lvmetad_pv_found(struct id pvid, struct device *device,
* multiple device names, so this needs a unique and stable name, the same as
* provided to lvmetad_pv_found.
*/
-int lvmetad_pv_gone(dev_t device);
+int lvmetad_pv_gone(struct device *dev);
/*
* Request a list of all PVs available to lvmetad. If requested, this will also
@@ -99,7 +99,7 @@ struct volume_group *lvmetad_vg_lookup(struct cmd_context *cmd,
* Scan a single device and update lvmetad with the result(s). If the device
* node does not exist, it must be supplied in a major:minor format.
*/
-int pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv);
+int pvscan_lvmetad_single(struct cmd_context *cmd, const char *pv_name);
# else /* LVMETAD_SUPPORT */
@@ -109,7 +109,7 @@ int pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv);
# define lvmetad_vg_update(vg) (1)
# define lvmetad_vg_remove(vg) (1)
# define lvmetad_pv_found(pvid, device, fmt, label_sector, vg) (1)
-# define lvmetad_pv_gone(device) (1)
+# define lvmetad_pv_gone(dev) (1)
# define lvmetad_pv_list_to_lvmcache(cmd) (1)
# define lvmetad_pv_lookup(cmd, pvid) (0)
# define lvmetad_pv_lookup_by_devt(cmd, dev) (0)
diff --git a/man/pvscan.8.in b/man/pvscan.8.in
index 8fbb4769..8d012697 100644
--- a/man/pvscan.8.in
+++ b/man/pvscan.8.in
@@ -12,7 +12,7 @@ pvscan \- scan all disks for physical volumes
.RB [ \-n | \-\-novolumegroup ]
.RB [ \-s | \-\-short ]
.RB [ \-u | \-\-uuid ]
-.RB [ \-\-lvmetad " " DevicePath ]
+.RB [ \-\-lvmetad " " DevicePath [ DevicePath ... ] ]
.SH DESCRIPTION
.B pvscan
scans all supported LVM block devices in the system for physical volumes.
@@ -31,7 +31,7 @@ Short listing format.
.BR \-u ", " \-\-uuid
Show UUIDs (Uniform Unique Identifiers) in addition to device special names.
.TP
-.BR \-\-lvmetad " " DevicePath
+.BR \-\-lvmetad " " DevicePath [ DevicePath... ]
Scan a single device and contact lvmetad to update its cached state. Called
internally by udev rules. The device is processed \fBregardless\fP of any device
filters set in lvm.conf.
diff --git a/tools/commands.h b/tools/commands.h
index 3a968bde..21f1adc1 100644
--- a/tools/commands.h
+++ b/tools/commands.h
@@ -670,7 +670,7 @@ xx(pvscan,
"\t[-P|--partial] " "\n"
"\t[-s|--short] " "\n"
"\t[-u|--uuid] " "\n"
- "\t[--lvmetad DevicePath] " "\n"
+ "\t[--lvmetad DevicePath [DevicePath...]] " "\n"
"\t[-v|--verbose] " "\n"
"\t[--version]\n",
diff --git a/tools/pvremove.c b/tools/pvremove.c
index efd8cb7f..f90f88a2 100644
--- a/tools/pvremove.c
+++ b/tools/pvremove.c
@@ -129,7 +129,7 @@ static int pvremove_single(struct cmd_context *cmd, const char *pv_name,
}
/* FIXME Avoid error if we expect that daemon might not know device */
- if (!lvmetad_pv_gone(dev->dev))
+ if (!lvmetad_pv_gone(dev))
goto_out;
log_print("Labels on physical volume \"%s\" successfully wiped",
diff --git a/tools/pvscan.c b/tools/pvscan.c
index 7cc9d433..3a7c8ba9 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -99,6 +99,35 @@ static void _pvscan_display_single(struct cmd_context *cmd,
pv_pe_size(pv)));
}
+static int _pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv)
+{
+ int ret = ECMD_PROCESSED;
+
+ if (!argc) {
+ log_error("List of Physical Volumes to tell lvmetad to cache required.");
+ return EINVALID_CMD_LINE;
+ }
+
+ if (!lock_vol(cmd, VG_GLOBAL, LCK_VG_READ)) {
+ log_error("Unable to obtain global lock.");
+ return ECMD_FAILED;
+ }
+
+ log_verbose("Using physical volume(s) on command line");
+ while (argc--) {
+ if (!pvscan_lvmetad_single(cmd, *argv++)) {
+ ret = ECMD_FAILED;
+ break;
+ }
+ if (sigint_caught())
+ break;
+ }
+
+ unlock_vg(cmd, VG_GLOBAL);
+
+ return ret;
+}
+
int pvscan(struct cmd_context *cmd, int argc, char **argv)
{
int new_pvs_found = 0;
@@ -115,20 +144,14 @@ int pvscan(struct cmd_context *cmd, int argc, char **argv)
pv_max_name_len = 0;
vg_max_name_len = 0;
- if (arg_count(cmd, lvmetad_ARG)) {
- if (!pvscan_lvmetad(cmd, argc, argv)) {
- stack;
- return ECMD_FAILED;
- }
- return ECMD_PROCESSED;
- }
+ if (arg_count(cmd, lvmetad_ARG))
+ return _pvscan_lvmetad(cmd, argc, argv);
if (arg_count(cmd, novolumegroup_ARG) && arg_count(cmd, exported_ARG)) {
log_error("Options -e and -n are incompatible");
return EINVALID_CMD_LINE;
}
- if (arg_count(cmd, exported_ARG) || arg_count(cmd, novolumegroup_ARG))
log_warn("WARNING: only considering physical volumes %s",
arg_count(cmd, exported_ARG) ?
"of exported volume group(s)" : "in no volume group");