summaryrefslogtreecommitdiff
path: root/tools/vgcfgrestore.c
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2016-06-08 14:42:03 -0500
committerAlasdair G Kergon <agk@redhat.com>2016-06-28 02:30:31 +0100
commita7c45ddc59449fa8b1823bcab31e3fbb64fed97c (patch)
tree7ff3a663fadb54a88922228ac1c0e3eb345d976f /tools/vgcfgrestore.c
parentcc3e7c7c31de8d69d9f1eb610181584482ee90a3 (diff)
downloadlvm2-a7c45ddc59449fa8b1823bcab31e3fbb64fed97c.tar.gz
lvmetad: two phase vg_update
Previously, a command sent lvmetad new VG metadata in vg_commit(). In vg_commit(), devices are suspended, so any memory allocation done by the command while sending to lvmetad, or by lvmetad while updating its cache could deadlock if memory reclaim was triggered. Now lvmetad is updated in unlock_vg(), after devices are resumed. The new method for updating VG metadata in lvmetad is in two phases: 1. In vg_write(), before devices are suspended, the command sends lvmetad a short message ("set_vg_info") telling it what the new VG seqno will be. lvmetad sees that the seqno is newer than the seqno of its cached VG, so it sets the INVALID flag for the cached VG. If sending the message to lvmetad fails, the command fails before the metadata is committed and the change is not made. If sending the message succeeds, vg_commit() is called. 2. In unlock_vg(), after devices are resumed, the command sends lvmetad the standard vg_update message with the new metadata. lvmetad sees that the seqno in the new metadata matches the seqno it saved from set_vg_info, and knows it has the latest copy, so it clears the INVALID flag for the cached VG. If a command fails between 1 and 2 (after committing the VG on disk, but before sending lvmetad the new metadata), the cached VG retains the INVALID flag in lvmetad. A subsequent command will read the cached VG from lvmetad, see the INVALID flag, ignore the cached copy, read the VG from disk instead, update the lvmetad copy with the latest copy from disk, (this clears the INVALID flag in lvmetad), and use the correct VG metadata for the command. (This INVALID mechanism already existed for use by lvmlockd.)
Diffstat (limited to 'tools/vgcfgrestore.c')
-rw-r--r--tools/vgcfgrestore.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/tools/vgcfgrestore.c b/tools/vgcfgrestore.c
index 8a60ab3a6..b5a2add12 100644
--- a/tools/vgcfgrestore.c
+++ b/tools/vgcfgrestore.c
@@ -70,7 +70,7 @@ int vgcfgrestore(struct cmd_context *cmd, int argc, char **argv)
if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE, NULL)) {
log_error("Unable to lock orphans");
- unlock_vg(cmd, vg_name);
+ unlock_vg(cmd, NULL, vg_name);
return ECMD_FAILED;
}
@@ -81,8 +81,8 @@ int vgcfgrestore(struct cmd_context *cmd, int argc, char **argv)
arg_str_value(cmd, file_ARG, ""),
arg_count(cmd, force_long_ARG)) :
backup_restore(cmd, vg_name, arg_count(cmd, force_long_ARG)))) {
- unlock_vg(cmd, VG_ORPHANS);
- unlock_vg(cmd, vg_name);
+ unlock_vg(cmd, NULL, VG_ORPHANS);
+ unlock_vg(cmd, NULL, vg_name);
log_error("Restore failed.");
ret = ECMD_FAILED;
goto rescan;
@@ -91,8 +91,8 @@ int vgcfgrestore(struct cmd_context *cmd, int argc, char **argv)
ret = ECMD_PROCESSED;
log_print_unless_silent("Restored volume group %s", vg_name);
- unlock_vg(cmd, VG_ORPHANS);
- unlock_vg(cmd, vg_name);
+ unlock_vg(cmd, NULL, VG_ORPHANS);
+ unlock_vg(cmd, NULL, vg_name);
rescan:
if (lvmetad_rescan) {
if (!lvmetad_connect(cmd)) {