mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
lvmetad: Fix a possible race in remove_metadata.
All operations on shared hash tables need to be protected by mutexes. Moreover, lookup and subsequent key removal need to happen atomically, to avoid races (and possible double free-ing) between multiple threads trying to manipulate the same VG.
This commit is contained in:
parent
fae1a611d2
commit
5294a6f77a
@ -601,19 +601,23 @@ static int remove_metadata(lvmetad_state *s, const char *vgid, int update_pvids)
|
||||
lock_vgid_to_metadata(s);
|
||||
old = dm_hash_lookup(s->vgid_to_metadata, vgid);
|
||||
oldname = dm_hash_lookup(s->vgid_to_vgname, vgid);
|
||||
unlock_vgid_to_metadata(s);
|
||||
|
||||
if (!old)
|
||||
if (!old) {
|
||||
unlock_vgid_to_metadata(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
assert(oldname);
|
||||
|
||||
if (update_pvids)
|
||||
/* FIXME: What should happen when update fails */
|
||||
update_pvid_to_vgid(s, old, "#orphan", 0);
|
||||
/* need to update what we have since we found a newer version */
|
||||
dm_hash_remove(s->vgid_to_metadata, vgid);
|
||||
dm_hash_remove(s->vgid_to_vgname, vgid);
|
||||
dm_hash_remove(s->vgname_to_vgid, oldname);
|
||||
unlock_vgid_to_metadata(s);
|
||||
|
||||
if (update_pvids)
|
||||
/* FIXME: What should happen when update fails */
|
||||
update_pvid_to_vgid(s, old, "#orphan", 0);
|
||||
dm_config_destroy(old);
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user