diff options
author | David Teigland <teigland@redhat.com> | 2015-05-14 09:10:03 -0500 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2015-05-19 08:52:42 -0500 |
commit | 62c49fb60eabaeb0098e840c215119ed8d51e577 (patch) | |
tree | 358d18e4f6306e467162de9a4629bb515db8b0dd | |
parent | 1c1a08b79a5cb3781415323546907e3180f47a6e (diff) | |
download | lvm2-dev-dct-lvmlockd-AE.tar.gz |
pvmove: locking with lvmlockddev-dct-lvmlockd-AE
-rw-r--r-- | tools/polldaemon.c | 7 | ||||
-rw-r--r-- | tools/pvmove.c | 29 |
2 files changed, 36 insertions, 0 deletions
diff --git a/tools/polldaemon.c b/tools/polldaemon.c index 83497b07b..906f0083b 100644 --- a/tools/polldaemon.c +++ b/tools/polldaemon.c @@ -171,6 +171,11 @@ int wait_for_single_lv(struct cmd_context *cmd, struct poll_operation_id *id, if (parms->wait_before_testing) _sleep_and_rescan_devices(parms); + if (!lockd_vg(cmd, id->vg_name, "sh", 0)) { + log_error("ABORTING: Can't lock VG for %s.", id->display_name); + return 0; + } + /* Locks the (possibly renamed) VG again */ vg = parms->poll_fns->get_copy_vg(cmd, id->vg_name, NULL, READ_FOR_UPDATE); if (vg_read_error(vg)) { @@ -213,6 +218,8 @@ int wait_for_single_lv(struct cmd_context *cmd, struct poll_operation_id *id, unlock_and_release_vg(cmd, vg, vg->name); + lockd_vg(cmd, vg->name, "un", 0); + /* * FIXME Sleeping after testing, while preferred, also works around * unreliable "finished" state checking in _percent_run. If the diff --git a/tools/pvmove.c b/tools/pvmove.c index 202c87c47..f085830a9 100644 --- a/tools/pvmove.c +++ b/tools/pvmove.c @@ -597,6 +597,7 @@ static int _set_up_pvmove(struct cmd_context *cmd, const char *pv_name, struct dm_list *lvs_changed; struct physical_volume *pv; struct logical_volume *lv_mirr; + uint32_t lockd_state; unsigned flags = PVMOVE_FIRST_TIME; unsigned exclusive; int r = ECMD_FAILED; @@ -629,6 +630,21 @@ static int _set_up_pvmove(struct cmd_context *cmd, const char *pv_name, /* Read VG */ log_verbose("Finding volume group \"%s\"", pv_vg_name(pv)); + /* + * TODO: once the move is started, the pvmove command exits and + * releases the VG lock, and the operation continues. Does the + * VG metadata state prevent other contradictory operations + * on the VG while the pvmove is in progress, and the VG + * lock is not held? + * + * lvpoll will periodically lock the vg, read the vg, + * check the process, unlock the vg, sleep and repeat + * + * TODO: pass lockd_state to vg_read. + */ + if (!lockd_vg(cmd, pv_vg_name(pv), "ex", 0, &lockd_state)) + return_ECMD_FAILED; + vg = poll_get_copy_vg(cmd, pv_vg_name(pv), NULL, READ_FOR_UPDATE); if (vg_read_error(vg)) { release_vg(vg); @@ -706,6 +722,7 @@ static int _read_poll_id_from_pvname(struct cmd_context *cmd, const char *pv_nam unsigned *in_progress) { int ret = 0; + uint32_t lockd_state; struct logical_volume *lv; struct physical_volume *pv; struct volume_group *vg; @@ -718,6 +735,9 @@ static int _read_poll_id_from_pvname(struct cmd_context *cmd, const char *pv_nam if (!(pv = find_pv_by_name(cmd, pv_name, 0, 0))) return_0; + if (!lockd_vg(cmd, pv_vg_name(pv), "sh", 0, &lockd_state)) + return_0; + /* need read-only access */ vg = poll_get_copy_vg(cmd, pv_vg_name(pv), NULL, 0); if (vg_read_error(vg)) { @@ -842,6 +862,15 @@ int pvmove(struct cmd_context *cmd, int argc, char **argv) if (colon) *colon = '\0'; + /* + * To do a reverse mapping from PV name to VG name, we need the + * correct global mapping of PVs to VGs. + */ + if (!lockd_gl(cmd, "sh", 0)) { + stack; + return ECMD_FAILED; + } + if (!arg_count(cmd, abort_ARG)) { if ((ret = _set_up_pvmove(cmd, pv_name, argc, argv, lvid, &vg_name, &lv_name)) != ECMD_PROCESSED) { stack; |