summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2016-05-06 15:20:54 -0500
committerDavid Teigland <teigland@redhat.com>2016-05-20 13:52:51 -0500
commit75f97427c697bce47cd24bcb53d14631f365eaf9 (patch)
tree36368282c57b94b256dd29605b0f860a58ac8ce4
parent48ec171bcbc80d7a14cb4c6e977a6c5fc5e7b82a (diff)
downloadlvm2-dev-dct-pvscan-5.tar.gz
pvcreate: hold ex lock on devicedev-dct-pvscan-5
-rw-r--r--lib/device/dev-io.c7
-rw-r--r--lib/device/device.h1
-rw-r--r--tools/toollib.c34
3 files changed, 34 insertions, 8 deletions
diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c
index a9a237417..3abaf489e 100644
--- a/lib/device/dev-io.c
+++ b/lib/device/dev-io.c
@@ -667,6 +667,13 @@ int dev_close_immediate(struct device *dev)
return _dev_close(dev, 1);
}
+int dev_close_try(struct device *dev)
+{
+ if (dev->fd < 0)
+ return 1;
+ return _dev_close(dev, 0);
+}
+
void dev_close_all(void)
{
struct dm_list *doh, *doht;
diff --git a/lib/device/device.h b/lib/device/device.h
index fa03f1061..0e7a1e1dc 100644
--- a/lib/device/device.h
+++ b/lib/device/device.h
@@ -123,6 +123,7 @@ int dev_open_readonly_buffered(struct device *dev);
int dev_open_readonly_quiet(struct device *dev);
int dev_close(struct device *dev);
int dev_close_immediate(struct device *dev);
+int dev_close_try(struct device *dev);
void dev_close_all(void);
int dev_test_excl(struct device *dev);
diff --git a/tools/toollib.c b/tools/toollib.c
index ff1effaf3..3e2ffd546 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -3871,11 +3871,10 @@ static int _pvcreate_check_single(struct cmd_context *cmd,
/*
* This test will fail if the device belongs to an MD array.
+ * dev_close_try() is used below for this error case.
*/
- if (!dev_test_excl(pv->dev)) {
- /* FIXME Detect whether device-mapper itself is still using it */
- log_error("Can't open %s exclusively. Mounted filesystem?",
- pv_dev_name(pv));
+ if (!dev_open_flags(pv->dev, O_EXCL | O_RDWR, 1, 1)) {
+ log_error("Can't open %s exclusively. Mounted filesystem?", pv_dev_name(pv));
dm_list_move(&pp->arg_fail, &pd->list);
return 1;
}
@@ -3978,10 +3977,8 @@ static int _pv_confirm_single(struct cmd_context *cmd,
return 1;
/* Repeat the same from check_single. */
- if (!dev_test_excl(pv->dev)) {
- /* FIXME Detect whether device-mapper itself is still using it */
- log_error("Can't open %s exclusively. Mounted filesystem?",
- pv_dev_name(pv));
+ if (!dev_open_flags(pv->dev, O_EXCL | O_RDWR, 1, 1)) {
+ log_error("Can't open %s exclusively. Mounted filesystem?", pv_dev_name(pv));
goto fail;
}
@@ -4378,6 +4375,9 @@ int pvcreate_each_device(struct cmd_context *cmd,
if (dm_list_empty(&pp->prompts))
goto do_command;
+ dm_list_iterate_items(pd, &pp->arg_process)
+ dev_close_try(pd->dev);
+
/*
* Prompts require asking the user, so release the orphans lock, ask
* the questions, reacquire the orphans lock, verify that the PVs were
@@ -4663,6 +4663,13 @@ do_command:
if (!dm_list_empty(&pp->arg_fail))
goto_bad;
+ dm_list_iterate_items(pd, &pp->arg_create)
+ dev_close_try(pd->dev);
+ dm_list_iterate_items(pd, &pp->arg_remove)
+ dev_close_try(pd->dev);
+ dm_list_iterate_items(pd, &pp->arg_fail)
+ dev_close_try(pd->dev);
+
/*
* Returns with VG_ORPHANS write lock held because vgcreate and
* vgextend want to use the newly created PVs.
@@ -4670,6 +4677,17 @@ do_command:
return 1;
bad:
+ dm_list_iterate_items(pd, &pp->arg_devices)
+ dev_close_try(pd->dev);
+ dm_list_iterate_items(pd, &pp->arg_process)
+ dev_close_try(pd->dev);
+ dm_list_iterate_items(pd, &pp->arg_create)
+ dev_close_try(pd->dev);
+ dm_list_iterate_items(pd, &pp->arg_remove)
+ dev_close_try(pd->dev);
+ dm_list_iterate_items(pd, &pp->arg_fail)
+ dev_close_try(pd->dev);
+
unlock_vg(cmd, VG_ORPHANS);
out:
return 0;