diff options
author | David Teigland <teigland@redhat.com> | 2015-12-15 12:55:48 -0600 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2016-01-07 13:39:25 -0600 |
commit | 0b1526eae1d5803549720f403d5324fdd8f758ad (patch) | |
tree | 4dedf17839a64fa8f3d2fbfac3386eebfa794d77 /liblvm/lvm_pv.c | |
parent | 4304a95dfdb4791e23dbd4b0280c667eba5cb664 (diff) | |
download | lvm2-dev-dct-pvcreate-8.tar.gz |
pvcreate, vgcreate, vgextend: restructuring to use toollibdev-dct-pvcreate-8
- Pull out the hidden equivalent of process_each_pv
into an actual top level process_each_pv.
- Pull the prompts to the top level, and do not
run any prompts while locks are held.
The orphan lock is reacquired after the prompts are
done, and the devices being created are checked for
any change made while the lock was not held.
Previously, pvcreate_vol() was the shared function for
creating a PV for pvcreate, vgcreate, vgextend.
Now, it will be toollib function pvcreate_each_device().
pvcreate_vol() was called effectively as a helper, from
within vgcreate and vgextend code paths.
pvcreate_each_device() will be called at the same level
as other process_each functions.
One of the main problems with pvcreate_vol() is that
it included a hidden equivalent of process_each_pv for
each device being created:
pvcreate_vol() -> _pvcreate_check() ->
find_pv_by_name() -> get_pvs() ->
get_pvs_internal() -> _get_pvs() -> get_vgids() ->
/* equivalent to process_each_pv */
dm_list_iterate_items(vgids)
vg = vg_read_internal()
dm_list_iterate_items(&vg->pvs)
pvcreate_each_device() reorganizes the code so that
each-VG-each-PV loop is done once, and uses the standard
process_each_pv function at the top level of the function.
Diffstat (limited to 'liblvm/lvm_pv.c')
-rw-r--r-- | liblvm/lvm_pv.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/liblvm/lvm_pv.c b/liblvm/lvm_pv.c index fee1e8d15..ca9844c67 100644 --- a/liblvm/lvm_pv.c +++ b/liblvm/lvm_pv.c @@ -419,6 +419,7 @@ int lvm_pv_params_set_property(pv_create_params_t params, const char *name, static int _pv_create(pv_create_params_t params) { struct cmd_context *cmd = (struct cmd_context *)params->libh; + int rc = 0; if (params->pv_p.size) { if (params->pv_p.size % SECTOR_SIZE) { @@ -428,9 +429,16 @@ static int _pv_create(pv_create_params_t params) params->pv_p.size = params->pv_p.size >> SECTOR_SHIFT; } - if (!pvcreate_single(cmd, params->pv_name, ¶ms->pv_p)) + if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE, NULL)) { + log_errno(EINVAL, "Can't get lock for orphan PVs"); return -1; - return 0; + } + + if (!(pvcreate_vol(cmd, params->pv_name, ¶ms->pv_p, 1))) + rc = -1; + + unlock_vg(cmd, VG_ORPHANS); + return rc; } int lvm_pv_create(lvm_t libh, const char *pv_name, uint64_t size) |