From 9b02bdbce0c661b78eb1ad42423771a71d27ffc2 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Mon, 3 Oct 2005 21:10:41 +0000 Subject: Refuse to run pvcreate/pvremove on devices we can't open exclusively. --- tools/pvcreate.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'tools/pvcreate.c') 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); } -- cgit