mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-02 01:18:26 +03:00
Accept orphan VG names as parameters to lock_vol() and related functions.
This commit is contained in:
parent
24d21cfcee
commit
fa305e2ec6
@ -1,5 +1,6 @@
|
|||||||
Version 2.02.66 -
|
Version 2.02.66 -
|
||||||
===============================
|
===============================
|
||||||
|
Accept orphan VG names as parameters to lock_vol() and related functions.
|
||||||
Use is_orphan_vg in place of hard-coded prefix tests.
|
Use is_orphan_vg in place of hard-coded prefix tests.
|
||||||
|
|
||||||
Version 2.02.65 - 17th May 2010
|
Version 2.02.65 - 17th May 2010
|
||||||
|
2
lib/cache/lvmcache.c
vendored
2
lib/cache/lvmcache.c
vendored
@ -290,7 +290,7 @@ int vgname_is_locked(const char *vgname)
|
|||||||
if (!_lock_hash)
|
if (!_lock_hash)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return dm_hash_lookup(_lock_hash, vgname) ? 1 : 0;
|
return dm_hash_lookup(_lock_hash, is_orphan_vg(vgname) ? VG_ORPHANS : vgname) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lvmcache_unlock_vgname(const char *vgname)
|
void lvmcache_unlock_vgname(const char *vgname)
|
||||||
|
@ -417,16 +417,16 @@ int lock_vol(struct cmd_context *cmd, const char *vol, uint32_t flags)
|
|||||||
|
|
||||||
switch (flags & LCK_SCOPE_MASK) {
|
switch (flags & LCK_SCOPE_MASK) {
|
||||||
case LCK_VG:
|
case LCK_VG:
|
||||||
/*
|
|
||||||
* VG locks alphabetical, ORPHAN lock last
|
|
||||||
*/
|
|
||||||
if (!_blocking_supported)
|
if (!_blocking_supported)
|
||||||
flags |= LCK_NONBLOCK;
|
flags |= LCK_NONBLOCK;
|
||||||
|
|
||||||
if (!is_orphan_vg(vol) &&
|
/* Global VG_ORPHANS lock covers all orphan formats. */
|
||||||
((flags & LCK_TYPE_MASK) != LCK_UNLOCK) &&
|
if (is_orphan_vg(vol))
|
||||||
(!(flags & LCK_CACHE)) &&
|
vol = VG_ORPHANS;
|
||||||
!lvmcache_verify_lock_order(vol))
|
/* VG locks alphabetical, ORPHAN lock last */
|
||||||
|
else if (((flags & LCK_TYPE_MASK) != LCK_UNLOCK) &&
|
||||||
|
!(flags & LCK_CACHE) &&
|
||||||
|
!lvmcache_verify_lock_order(vol))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Lock VG to change on-disk metadata. */
|
/* Lock VG to change on-disk metadata. */
|
||||||
|
@ -3459,7 +3459,7 @@ int vg_check_status(const struct volume_group *vg, uint64_t status)
|
|||||||
return !_vg_bad_status_bits(vg, status);
|
return !_vg_bad_status_bits(vg, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct volume_group *_recover_vg(struct cmd_context *cmd, const char *lock_name,
|
static struct volume_group *_recover_vg(struct cmd_context *cmd,
|
||||||
const char *vg_name, const char *vgid,
|
const char *vg_name, const char *vgid,
|
||||||
uint32_t lock_flags)
|
uint32_t lock_flags)
|
||||||
{
|
{
|
||||||
@ -3469,11 +3469,11 @@ static struct volume_group *_recover_vg(struct cmd_context *cmd, const char *loc
|
|||||||
lock_flags &= ~LCK_TYPE_MASK;
|
lock_flags &= ~LCK_TYPE_MASK;
|
||||||
lock_flags |= LCK_WRITE;
|
lock_flags |= LCK_WRITE;
|
||||||
|
|
||||||
unlock_vg(cmd, lock_name);
|
unlock_vg(cmd, vg_name);
|
||||||
|
|
||||||
dev_close_all();
|
dev_close_all();
|
||||||
|
|
||||||
if (!lock_vol(cmd, lock_name, lock_flags))
|
if (!lock_vol(cmd, vg_name, lock_flags))
|
||||||
return_NULL;
|
return_NULL;
|
||||||
|
|
||||||
if (!(vg = vg_read_internal(cmd, vg_name, vgid, &consistent)))
|
if (!(vg = vg_read_internal(cmd, vg_name, vgid, &consistent)))
|
||||||
@ -3503,7 +3503,6 @@ static struct volume_group *_vg_lock_and_read(struct cmd_context *cmd, const cha
|
|||||||
uint64_t status_flags, uint32_t misc_flags)
|
uint64_t status_flags, uint32_t misc_flags)
|
||||||
{
|
{
|
||||||
struct volume_group *vg = NULL;
|
struct volume_group *vg = NULL;
|
||||||
const char *lock_name;
|
|
||||||
int consistent = 1;
|
int consistent = 1;
|
||||||
int consistent_in;
|
int consistent_in;
|
||||||
uint32_t failure = 0;
|
uint32_t failure = 0;
|
||||||
@ -3518,11 +3517,10 @@ static struct volume_group *_vg_lock_and_read(struct cmd_context *cmd, const cha
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
lock_name = is_orphan_vg(vg_name) ? VG_ORPHANS : vg_name;
|
already_locked = vgname_is_locked(vg_name);
|
||||||
already_locked = vgname_is_locked(lock_name);
|
|
||||||
|
|
||||||
if (!already_locked && !(misc_flags & READ_WITHOUT_LOCK) &&
|
if (!already_locked && !(misc_flags & READ_WITHOUT_LOCK) &&
|
||||||
!lock_vol(cmd, lock_name, lock_flags)) {
|
!lock_vol(cmd, vg_name, lock_flags)) {
|
||||||
log_error("Can't get lock for %s", vg_name);
|
log_error("Can't get lock for %s", vg_name);
|
||||||
return _vg_make_handle(cmd, vg, FAILED_LOCKING);
|
return _vg_make_handle(cmd, vg, FAILED_LOCKING);
|
||||||
}
|
}
|
||||||
@ -3555,7 +3553,7 @@ static struct volume_group *_vg_lock_and_read(struct cmd_context *cmd, const cha
|
|||||||
/* consistent == 0 when VG is not found, but failed == FAILED_NOTFOUND */
|
/* consistent == 0 when VG is not found, but failed == FAILED_NOTFOUND */
|
||||||
if (!consistent && !failure) {
|
if (!consistent && !failure) {
|
||||||
vg_release(vg);
|
vg_release(vg);
|
||||||
if (!(vg = _recover_vg(cmd, lock_name, vg_name, vgid, lock_flags))) {
|
if (!(vg = _recover_vg(cmd, vg_name, vgid, lock_flags))) {
|
||||||
log_error("Recovery of volume group \"%s\" failed.",
|
log_error("Recovery of volume group \"%s\" failed.",
|
||||||
vg_name);
|
vg_name);
|
||||||
failure |= FAILED_INCONSISTENT;
|
failure |= FAILED_INCONSISTENT;
|
||||||
@ -3592,7 +3590,7 @@ static struct volume_group *_vg_lock_and_read(struct cmd_context *cmd, const cha
|
|||||||
|
|
||||||
bad:
|
bad:
|
||||||
if (!already_locked && !(misc_flags & READ_WITHOUT_LOCK))
|
if (!already_locked && !(misc_flags & READ_WITHOUT_LOCK))
|
||||||
unlock_vg(cmd, lock_name);
|
unlock_vg(cmd, vg_name);
|
||||||
|
|
||||||
return _vg_make_handle(cmd, vg, failure);
|
return _vg_make_handle(cmd, vg, failure);
|
||||||
}
|
}
|
||||||
|
@ -34,15 +34,14 @@ static int _pv_resize_single(struct cmd_context *cmd,
|
|||||||
int r = 0;
|
int r = 0;
|
||||||
struct dm_list mdas;
|
struct dm_list mdas;
|
||||||
const char *pv_name = pv_dev_name(pv);
|
const char *pv_name = pv_dev_name(pv);
|
||||||
const char *vg_name;
|
const char *vg_name = pv_vg_name(pv);
|
||||||
struct lvmcache_info *info;
|
struct lvmcache_info *info;
|
||||||
int mda_count = 0;
|
int mda_count = 0;
|
||||||
struct volume_group *old_vg = vg;
|
struct volume_group *old_vg = vg;
|
||||||
|
|
||||||
dm_list_init(&mdas);
|
dm_list_init(&mdas);
|
||||||
|
|
||||||
if (is_orphan_vg(pv_vg_name(pv))) {
|
if (is_orphan_vg(vg_name)) {
|
||||||
vg_name = VG_ORPHANS;
|
|
||||||
if (!lock_vol(cmd, vg_name, LCK_VG_WRITE)) {
|
if (!lock_vol(cmd, vg_name, LCK_VG_WRITE)) {
|
||||||
log_error("Can't get lock for orphans");
|
log_error("Can't get lock for orphans");
|
||||||
return 0;
|
return 0;
|
||||||
@ -56,8 +55,6 @@ static int _pv_resize_single(struct cmd_context *cmd,
|
|||||||
|
|
||||||
mda_count = dm_list_size(&mdas);
|
mda_count = dm_list_size(&mdas);
|
||||||
} else {
|
} else {
|
||||||
vg_name = pv_vg_name(pv);
|
|
||||||
|
|
||||||
vg = vg_read_for_update(cmd, vg_name, NULL, 0);
|
vg = vg_read_for_update(cmd, vg_name, NULL, 0);
|
||||||
|
|
||||||
if (vg_read_error(vg)) {
|
if (vg_read_error(vg)) {
|
||||||
@ -70,7 +67,7 @@ static int _pv_resize_single(struct cmd_context *cmd,
|
|||||||
if (!(pvl = find_pv_in_vg(vg, pv_name))) {
|
if (!(pvl = find_pv_in_vg(vg, pv_name))) {
|
||||||
log_error("Unable to find \"%s\" in volume group \"%s\"",
|
log_error("Unable to find \"%s\" in volume group \"%s\"",
|
||||||
pv_name, vg->name);
|
pv_name, vg->name);
|
||||||
goto bad;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
pv = pvl->pv;
|
pv = pvl->pv;
|
||||||
@ -78,31 +75,31 @@ static int _pv_resize_single(struct cmd_context *cmd,
|
|||||||
if (!(info = info_from_pvid(pv->dev->pvid, 0))) {
|
if (!(info = info_from_pvid(pv->dev->pvid, 0))) {
|
||||||
log_error("Can't get info for PV %s in volume group %s",
|
log_error("Can't get info for PV %s in volume group %s",
|
||||||
pv_name, vg->name);
|
pv_name, vg->name);
|
||||||
goto bad;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
mda_count = dm_list_size(&info->mdas);
|
mda_count = dm_list_size(&info->mdas);
|
||||||
|
|
||||||
if (!archive(vg))
|
if (!archive(vg))
|
||||||
goto bad;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME Create function to test compatibility properly */
|
/* FIXME Create function to test compatibility properly */
|
||||||
if (mda_count > 1) {
|
if (mda_count > 1) {
|
||||||
log_error("%s: too many metadata areas for pvresize", pv_name);
|
log_error("%s: too many metadata areas for pvresize", pv_name);
|
||||||
goto bad;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(pv->fmt->features & FMT_RESIZE_PV)) {
|
if (!(pv->fmt->features & FMT_RESIZE_PV)) {
|
||||||
log_error("Physical volume %s format does not support resizing.",
|
log_error("Physical volume %s format does not support resizing.",
|
||||||
pv_name);
|
pv_name);
|
||||||
goto bad;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get new size */
|
/* Get new size */
|
||||||
if (!dev_get_size(pv_dev(pv), &size)) {
|
if (!dev_get_size(pv_dev(pv), &size)) {
|
||||||
log_error("%s: Couldn't get size.", pv_name);
|
log_error("%s: Couldn't get size.", pv_name);
|
||||||
goto bad;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new_size) {
|
if (new_size) {
|
||||||
@ -117,13 +114,13 @@ static int _pv_resize_single(struct cmd_context *cmd,
|
|||||||
if (size < PV_MIN_SIZE) {
|
if (size < PV_MIN_SIZE) {
|
||||||
log_error("%s: Size must exceed minimum of %ld sectors.",
|
log_error("%s: Size must exceed minimum of %ld sectors.",
|
||||||
pv_name, PV_MIN_SIZE);
|
pv_name, PV_MIN_SIZE);
|
||||||
goto bad;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size < pv_pe_start(pv)) {
|
if (size < pv_pe_start(pv)) {
|
||||||
log_error("%s: Size must exceed physical extent start of "
|
log_error("%s: Size must exceed physical extent start of "
|
||||||
"%" PRIu64 " sectors.", pv_name, pv_pe_start(pv));
|
"%" PRIu64 " sectors.", pv_name, pv_pe_start(pv));
|
||||||
goto bad;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
pv->size = size;
|
pv->size = size;
|
||||||
@ -137,34 +134,34 @@ static int _pv_resize_single(struct cmd_context *cmd,
|
|||||||
"least one physical extent of "
|
"least one physical extent of "
|
||||||
"%" PRIu32 " sectors.", pv_name,
|
"%" PRIu32 " sectors.", pv_name,
|
||||||
pv_pe_size(pv));
|
pv_pe_size(pv));
|
||||||
goto bad;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pv_resize(pv, vg, new_pe_count))
|
if (!pv_resize(pv, vg, new_pe_count))
|
||||||
goto_bad;
|
goto_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_verbose("Resizing volume \"%s\" to %" PRIu64 " sectors.",
|
log_verbose("Resizing volume \"%s\" to %" PRIu64 " sectors.",
|
||||||
pv_name, pv_size(pv));
|
pv_name, pv_size(pv));
|
||||||
|
|
||||||
log_verbose("Updating physical volume \"%s\"", pv_name);
|
log_verbose("Updating physical volume \"%s\"", pv_name);
|
||||||
if (!is_orphan_vg(pv_vg_name(pv))) {
|
if (!is_orphan_vg(vg_name)) {
|
||||||
if (!vg_write(vg) || !vg_commit(vg)) {
|
if (!vg_write(vg) || !vg_commit(vg)) {
|
||||||
log_error("Failed to store physical volume \"%s\" in "
|
log_error("Failed to store physical volume \"%s\" in "
|
||||||
"volume group \"%s\"", pv_name, vg->name);
|
"volume group \"%s\"", pv_name, vg->name);
|
||||||
goto bad;
|
goto out;
|
||||||
}
|
}
|
||||||
backup(vg);
|
backup(vg);
|
||||||
} else if (!(pv_write(cmd, pv, NULL, INT64_C(-1)))) {
|
} else if (!(pv_write(cmd, pv, NULL, INT64_C(-1)))) {
|
||||||
log_error("Failed to store physical volume \"%s\"",
|
log_error("Failed to store physical volume \"%s\"",
|
||||||
pv_name);
|
pv_name);
|
||||||
goto bad;;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_print("Physical volume \"%s\" changed", pv_name);
|
log_print("Physical volume \"%s\" changed", pv_name);
|
||||||
r = 1;
|
r = 1;
|
||||||
|
|
||||||
bad:
|
out:
|
||||||
unlock_vg(cmd, vg_name);
|
unlock_vg(cmd, vg_name);
|
||||||
if (!old_vg)
|
if (!old_vg)
|
||||||
vg_release(vg);
|
vg_release(vg);
|
||||||
|
Loading…
Reference in New Issue
Block a user