mirror of
git://sourceware.org/git/lvm2.git
synced 2025-03-10 16:58:47 +03:00
Fix vgcreate race which could allow two parallel vgcreates to succeed,
with the second vgcreate overwriting the first. Obtain lock before calling vg_create(), which checks for existence of vgname and fails if it already exists.
This commit is contained in:
parent
89ef434fe0
commit
9d9589d173
@ -1,5 +1,6 @@
|
|||||||
Version 2.02.44 -
|
Version 2.02.44 -
|
||||||
====================================
|
====================================
|
||||||
|
Fix race in vgcreate that would result in second caller overwriting first.
|
||||||
Fix uninitialised lv_count in vgdisplay -c.
|
Fix uninitialised lv_count in vgdisplay -c.
|
||||||
Don't skip updating pvid hash when lvmcache_info struct got swapped.
|
Don't skip updating pvid hash when lvmcache_info struct got swapped.
|
||||||
Add tinfo to termcap search path for pld-linux.
|
Add tinfo to termcap search path for pld-linux.
|
||||||
|
@ -46,11 +46,22 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
if (validate_vg_create_params(cmd, &vp_new))
|
if (validate_vg_create_params(cmd, &vp_new))
|
||||||
return EINVALID_CMD_LINE;
|
return EINVALID_CMD_LINE;
|
||||||
|
|
||||||
|
if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
|
||||||
|
log_error("Can't get lock for orphan PVs");
|
||||||
|
return ECMD_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!lock_vol(cmd, vp_new.vg_name, LCK_VG_WRITE | LCK_NONBLOCK)) {
|
||||||
|
log_error("Can't get lock for %s", vp_new.vg_name);
|
||||||
|
unlock_vg(cmd, VG_ORPHANS);
|
||||||
|
return ECMD_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
/* Create the new VG */
|
/* Create the new VG */
|
||||||
if (!(vg = vg_create(cmd, vp_new.vg_name, vp_new.extent_size,
|
if (!(vg = vg_create(cmd, vp_new.vg_name, vp_new.extent_size,
|
||||||
vp_new.max_pv, vp_new.max_lv, vp_new.alloc,
|
vp_new.max_pv, vp_new.max_lv, vp_new.alloc,
|
||||||
argc - 1, argv + 1)))
|
argc - 1, argv + 1)))
|
||||||
return ECMD_FAILED;
|
goto bad;
|
||||||
|
|
||||||
if (vp_new.max_lv != vg->max_lv)
|
if (vp_new.max_lv != vg->max_lv)
|
||||||
log_warn("WARNING: Setting maxlogicalvolumes to %d "
|
log_warn("WARNING: Setting maxlogicalvolumes to %d "
|
||||||
@ -63,18 +74,18 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
if (arg_count(cmd, addtag_ARG)) {
|
if (arg_count(cmd, addtag_ARG)) {
|
||||||
if (!(tag = arg_str_value(cmd, addtag_ARG, NULL))) {
|
if (!(tag = arg_str_value(cmd, addtag_ARG, NULL))) {
|
||||||
log_error("Failed to get tag");
|
log_error("Failed to get tag");
|
||||||
return ECMD_FAILED;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(vg->fid->fmt->features & FMT_TAGS)) {
|
if (!(vg->fid->fmt->features & FMT_TAGS)) {
|
||||||
log_error("Volume group format does not support tags");
|
log_error("Volume group format does not support tags");
|
||||||
return ECMD_FAILED;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!str_list_add(cmd->mem, &vg->tags, tag)) {
|
if (!str_list_add(cmd->mem, &vg->tags, tag)) {
|
||||||
log_error("Failed to add tag %s to volume group %s",
|
log_error("Failed to add tag %s to volume group %s",
|
||||||
tag, vp_new.vg_name);
|
tag, vp_new.vg_name);
|
||||||
return ECMD_FAILED;
|
goto bad;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,28 +99,13 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
clustered_message = "Non-clustered ";
|
clustered_message = "Non-clustered ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
|
|
||||||
log_error("Can't get lock for orphan PVs");
|
|
||||||
return ECMD_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!lock_vol(cmd, vp_new.vg_name, LCK_VG_WRITE | LCK_NONBLOCK)) {
|
|
||||||
log_error("Can't get lock for %s", vp_new.vg_name);
|
|
||||||
unlock_vg(cmd, VG_ORPHANS);
|
|
||||||
return ECMD_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!archive(vg)) {
|
if (!archive(vg)) {
|
||||||
unlock_vg(cmd, vp_new.vg_name);
|
goto bad;
|
||||||
unlock_vg(cmd, VG_ORPHANS);
|
|
||||||
return ECMD_FAILED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Store VG on disk(s) */
|
/* Store VG on disk(s) */
|
||||||
if (!vg_write(vg) || !vg_commit(vg)) {
|
if (!vg_write(vg) || !vg_commit(vg)) {
|
||||||
unlock_vg(cmd, vp_new.vg_name);
|
goto bad;
|
||||||
unlock_vg(cmd, VG_ORPHANS);
|
|
||||||
return ECMD_FAILED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unlock_vg(cmd, vp_new.vg_name);
|
unlock_vg(cmd, vp_new.vg_name);
|
||||||
@ -121,4 +117,9 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
clustered_message, *clustered_message ? 'v' : 'V', vg->name);
|
clustered_message, *clustered_message ? 'v' : 'V', vg->name);
|
||||||
|
|
||||||
return ECMD_PROCESSED;
|
return ECMD_PROCESSED;
|
||||||
|
|
||||||
|
bad:
|
||||||
|
unlock_vg(cmd, vp_new.vg_name);
|
||||||
|
unlock_vg(cmd, VG_ORPHANS);
|
||||||
|
return ECMD_FAILED;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user