mirror of
git://sourceware.org/git/lvm2.git
synced 2025-07-17 00:58:59 +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:
@ -601,19 +601,23 @@ static int remove_metadata(lvmetad_state *s, const char *vgid, int update_pvids)
|
|||||||
lock_vgid_to_metadata(s);
|
lock_vgid_to_metadata(s);
|
||||||
old = dm_hash_lookup(s->vgid_to_metadata, vgid);
|
old = dm_hash_lookup(s->vgid_to_metadata, vgid);
|
||||||
oldname = dm_hash_lookup(s->vgid_to_vgname, 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;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
assert(oldname);
|
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 */
|
/* 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_metadata, vgid);
|
||||||
dm_hash_remove(s->vgid_to_vgname, vgid);
|
dm_hash_remove(s->vgid_to_vgname, vgid);
|
||||||
dm_hash_remove(s->vgname_to_vgid, oldname);
|
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);
|
dm_config_destroy(old);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user