summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2016-03-04 16:30:04 -0600
committerDavid Teigland <teigland@redhat.com>2016-03-07 12:06:26 -0600
commit77d4d75d1699cfd30cfbf2fdb9f69ec705c1ecfb (patch)
treeca526692d6a70f04576bfc355d9f1b9c140fc919
parentc8b7ecc78dad71e1770a25d11533c1f726c575bc (diff)
downloadlvm2-dev-dct-lvm-using-dev-4.tar.gz
pvs: warn if no PV is found for a device lvm is usingdev-dct-lvm-using-dev-4
After 'pvs' reports all PVs, if there are devices that were not reported which lvm is currently using for LVs then print a warning.
-rw-r--r--lib/activate/activate.c2
-rw-r--r--lib/activate/dev_manager.c8
-rw-r--r--lib/activate/dev_manager.h2
-rw-r--r--lib/device/dev-cache.c4
-rw-r--r--lib/device/device.h1
-rw-r--r--tools/toollib.c56
6 files changed, 66 insertions, 7 deletions
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
index 88a39fa9f..2e64ca16e 100644
--- a/lib/activate/activate.c
+++ b/lib/activate/activate.c
@@ -2395,7 +2395,7 @@ int pv_uses_vg(struct physical_volume *pv,
*/
int lvs_using_device(struct device *dev)
{
- return dev_manager_lvm_using_device(dev);
+ return dev_manager_lvm_using_device(MAJOR(dev->dev), MINOR(dev->dev));
}
void activation_release(void)
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index 78d9b622a..a5d8b2d55 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -3188,14 +3188,12 @@ static int _is_lvm_uuid(char *dm_name)
if (!strncmp(uuid, UUID_PREFIX, sizeof(UUID_PREFIX) - 1))
ret = 1;
-
- /* Verify that a uuid follows the LVM prefix? */
out:
dm_task_destroy(dmt);
return ret;
}
-int dev_manager_lvm_using_device(struct device *dev)
+int dev_manager_lvm_using_device(uint32_t major, uint32_t minor)
{
struct dm_task *dmt;
struct dm_task *dmt2;
@@ -3234,8 +3232,8 @@ int dev_manager_lvm_using_device(struct device *dev)
goto next;
for (i = 0; i < deps->count; i++) {
- if ((MAJOR(dev->dev) == (int) MAJOR(deps->device[i])) &&
- (MINOR(dev->dev) == (int) MINOR(deps->device[i]))) {
+ if ((major == (int) MAJOR(deps->device[i])) &&
+ (minor == (int) MINOR(deps->device[i]))) {
is_used = 1;
break;
}
diff --git a/lib/activate/dev_manager.h b/lib/activate/dev_manager.h
index fb042b6b3..c035c3256 100644
--- a/lib/activate/dev_manager.h
+++ b/lib/activate/dev_manager.h
@@ -97,6 +97,6 @@ int dev_manager_execute(struct dev_manager *dm);
int dev_manager_device_uses_vg(struct device *dev,
struct volume_group *vg);
-int dev_manager_lvm_using_device(struct device *dev);
+int dev_manager_lvm_using_device(uint32_t major, uint32_t minor);
#endif
diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c
index 47ae1403e..6355bf5ec 100644
--- a/lib/device/dev-cache.c
+++ b/lib/device/dev-cache.c
@@ -17,6 +17,7 @@
#include "btree.h"
#include "config.h"
#include "toolcontext.h"
+#include "activate.h"
#ifdef UDEV_SYNC_SUPPORT
#include <libudev.h>
@@ -409,6 +410,8 @@ static int _insert_dev(const char *path, dev_t d)
return 0;
}
+ dev->lvm_using = lvs_using_device(dev);
+
return 1;
}
@@ -1110,3 +1113,4 @@ const char *dev_name(const struct device *dev)
return (dev && dev->aliases.n) ? dm_list_item(dev->aliases.n, struct dm_str_list)->str :
unknown_device_name();
}
+
diff --git a/lib/device/device.h b/lib/device/device.h
index 6b01fb6e7..59a4008be 100644
--- a/lib/device/device.h
+++ b/lib/device/device.h
@@ -61,6 +61,7 @@ struct device {
int phys_block_size;
int block_size;
int read_ahead;
+ int lvm_using;
uint32_t flags;
unsigned size_seqno;
uint64_t size;
diff --git a/tools/toollib.c b/tools/toollib.c
index 14aca1503..edc3e5151 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -2879,6 +2879,40 @@ out:
return r;
}
+static int _get_active_devices(struct cmd_context *cmd, struct dm_list *active_devices)
+{
+ struct dev_iter *iter;
+ struct device *dev;
+ struct device_id_list *dil;
+ int r = ECMD_FAILED;
+
+ log_debug("Getting list of active devices");
+
+ if (!(iter = dev_iter_create(NULL, 0))) {
+ log_error("dev_iter creation failed.");
+ return ECMD_FAILED;
+ }
+
+ while ((dev = dev_iter_get(iter))) {
+ if (!(dil = dm_pool_alloc(cmd->mem, sizeof(*dil)))) {
+ log_error("device_id_list alloc failed.");
+ goto out;
+ }
+
+ if (!dev->lvm_using)
+ continue;
+
+ strncpy(dil->pvid, dev->pvid, ID_LEN);
+ dil->dev = dev;
+ dm_list_add(active_devices, &dil->list);
+ }
+
+ r = ECMD_PROCESSED;
+out:
+ dev_iter_destroy(iter);
+ return r;
+}
+
static int _device_list_remove(struct dm_list *devices, struct device *dev)
{
struct device_id_list *dil;
@@ -3296,6 +3330,7 @@ int process_each_pv(struct cmd_context *cmd,
struct dm_list arg_missed; /* device_id_list */
struct dm_list all_vgnameids; /* vgnameid_list */
struct dm_list all_devices; /* device_id_list */
+ struct dm_list act_devices; /* device_id_list */
struct device_id_list *dil;
int process_all_pvs;
int process_all_devices;
@@ -3327,6 +3362,7 @@ int process_each_pv(struct cmd_context *cmd,
dm_list_init(&arg_missed);
dm_list_init(&all_vgnameids);
dm_list_init(&all_devices);
+ dm_list_init(&act_devices);
/*
* Create two lists from argv:
@@ -3385,6 +3421,26 @@ int process_each_pv(struct cmd_context *cmd,
return ret;
}
+ /*
+ * Print a warning if this command is meant to process all PVs, but is
+ * not processing a device that LVM is currently using for an active
+ * LV, probably because a filter is excluding it. This is done by
+ * creating a list of devices that are currently in use by LVM, and
+ * then warning if one of them is not in the list of all devices that
+ * are being processed.
+ */
+ if (process_all_pvs) {
+ if ((ret = _get_active_devices(cmd, &act_devices) != ECMD_PROCESSED)) {
+ stack;
+ return ret;
+ }
+
+ dm_list_iterate_items(dil, &act_devices) {
+ if (!_device_list_find_dev(&all_devices, dil->dev))
+ log_warn("WARNING: Not processing PV for device %s which lvm is using.", dev_name(dil->dev));
+ }
+ }
+
if ((ret = _get_arg_devices(cmd, &arg_pvnames, &arg_devices)) != ECMD_PROCESSED)
/* get_arg_devices reports the error for any PV names not found. */
ret_max = ECMD_FAILED;