summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAlasdair Kergon <agk@redhat.com>2005-10-03 21:10:41 +0000
committerAlasdair Kergon <agk@redhat.com>2005-10-03 21:10:41 +0000
commit9b02bdbce0c661b78eb1ad42423771a71d27ffc2 (patch)
tree0a58dca8e1151eebe0a01c9117badee865abc57b /tools
parent9c9e30cd6d97089aa7ee6e16c553edc7c3a43988 (diff)
downloadlvm2-9b02bdbce0c661b78eb1ad42423771a71d27ffc2.tar.gz
lvm2-9b02bdbce0c661b78eb1ad42423771a71d27ffc2.tar.xz
lvm2-9b02bdbce0c661b78eb1ad42423771a71d27ffc2.zip
Refuse to run pvcreate/pvremove on devices we can't open exclusively.
Diffstat (limited to 'tools')
-rw-r--r--tools/pvcreate.c14
-rw-r--r--tools/pvremove.c6
2 files changed, 18 insertions, 2 deletions
diff --git a/tools/pvcreate.c b/tools/pvcreate.c
index a0b7807a..75995dd3 100644
--- a/tools/pvcreate.c
+++ b/tools/pvcreate.c
@@ -82,6 +82,12 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name)
return 0;
}
+ if (!dev_test_excl(dev)) {
+ log_error("Can't open %s exclusively. Mounted filesystem?",
+ name);
+ return 0;
+ }
+
/* Wipe superblock? */
if (dev_is_md(dev, &md_superblock) &&
((!arg_count(cmd, uuidstr_ARG) &&
@@ -218,8 +224,12 @@ static int pvcreate_single(struct cmd_context *cmd, const char *pv_name,
log_error("%s not opened: device not zeroed", pv_name);
goto error;
}
-
- dev_zero(dev, UINT64_C(0), (size_t) 2048);
+
+ if (!dev_zero(dev, UINT64_C(0), (size_t) 2048)) {
+ log_error("%s not wiped: aborting", pv_name);
+ dev_close(dev);
+ goto error;
+ }
dev_close(dev);
}
diff --git a/tools/pvremove.c b/tools/pvremove.c
index 6fd9daa0..1fce587a 100644
--- a/tools/pvremove.c
+++ b/tools/pvremove.c
@@ -86,6 +86,12 @@ static int pvremove_single(struct cmd_context *cmd, const char *pv_name,
goto error;
}
+ if (!dev_test_excl(dev)) {
+ log_error("Can't open %s exclusively. Mounted filesystem?",
+ dev_name(dev));
+ return 0;
+ }
+
/* Wipe existing label(s) */
if (!label_remove(dev)) {
log_error("Failed to wipe existing label(s) on %s", pv_name);