mirror of
git://sourceware.org/git/lvm2.git
synced 2025-03-10 16:58:47 +03:00
Fix vgreduce to use vg_split_mdas to check sufficient mdas remain.
Add (empty) orphan VGs to lvmcache during initialisation. Fix orphan VG name used for format_pool.
This commit is contained in:
parent
ad607a23f1
commit
6eb44b5091
@ -1,5 +1,8 @@
|
|||||||
Version 2.02.34 -
|
Version 2.02.34 -
|
||||||
===================================
|
===================================
|
||||||
|
Fix vgreduce to use vg_split_mdas to check sufficient mdas remain.
|
||||||
|
Add (empty) orphan VGs to lvmcache during initialisation.
|
||||||
|
Fix orphan VG name used for format_pool.
|
||||||
Create a fid for internal orphan VGs.
|
Create a fid for internal orphan VGs.
|
||||||
Update lvmcache VG lock state for all locking types now.
|
Update lvmcache VG lock state for all locking types now.
|
||||||
Fix output if overriding command_names on cmdline.
|
Fix output if overriding command_names on cmdline.
|
||||||
|
116
lib/cache/lvmcache.c
vendored
116
lib/cache/lvmcache.c
vendored
@ -536,34 +536,38 @@ struct device *device_from_pvid(struct cmd_context *cmd, struct id *pvid)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _drop_vginfo(struct lvmcache_info *info)
|
/*
|
||||||
|
* vginfo must be info->vginfo unless info is NULL
|
||||||
|
*/
|
||||||
|
static int _drop_vginfo(struct lvmcache_info *info, struct lvmcache_vginfo *vginfo)
|
||||||
{
|
{
|
||||||
if (!list_empty(&info->list)) {
|
if (info && !list_empty(&info->list)) {
|
||||||
list_del(&info->list);
|
list_del(&info->list);
|
||||||
list_init(&info->list);
|
list_init(&info->list);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->vginfo && list_empty(&info->vginfo->infos)) {
|
if (vginfo && !is_orphan_vg(vginfo->vgname) && list_empty(&vginfo->infos)) {
|
||||||
dm_hash_remove(_vgname_hash, info->vginfo->vgname);
|
dm_hash_remove(_vgname_hash, vginfo->vgname);
|
||||||
if (info->vginfo->next) {
|
if (vginfo->next) {
|
||||||
if (!dm_hash_insert(_vgname_hash, info->vginfo->vgname, info->vginfo->next)) {
|
if (!dm_hash_insert(_vgname_hash, vginfo->vgname, vginfo->next)) {
|
||||||
log_error("vg hash re-insertion failed: %s",
|
log_error("vg hash re-insertion failed: %s",
|
||||||
info->vginfo->vgname);
|
vginfo->vgname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->vginfo->vgname)
|
if (vginfo->vgname)
|
||||||
dm_free(info->vginfo->vgname);
|
dm_free(vginfo->vgname);
|
||||||
if (info->vginfo->creation_host)
|
if (vginfo->creation_host)
|
||||||
dm_free(info->vginfo->creation_host);
|
dm_free(vginfo->creation_host);
|
||||||
if (*info->vginfo->vgid)
|
if (*vginfo->vgid)
|
||||||
dm_hash_remove(_vgid_hash, info->vginfo->vgid);
|
dm_hash_remove(_vgid_hash, vginfo->vgid);
|
||||||
list_del(&info->vginfo->list);
|
list_del(&vginfo->list);
|
||||||
dm_free(info->vginfo);
|
dm_free(info->vginfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
info->vginfo = NULL;
|
if (info)
|
||||||
|
info->vginfo = NULL;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -574,7 +578,7 @@ void lvmcache_del(struct lvmcache_info *info)
|
|||||||
if (info->dev->pvid[0] && _pvid_hash)
|
if (info->dev->pvid[0] && _pvid_hash)
|
||||||
dm_hash_remove(_pvid_hash, info->dev->pvid);
|
dm_hash_remove(_pvid_hash, info->dev->pvid);
|
||||||
|
|
||||||
_drop_vginfo(info);
|
_drop_vginfo(info, info->vginfo);
|
||||||
|
|
||||||
info->label->labeller->ops->destroy_label(info->label->labeller,
|
info->label->labeller->ops->destroy_label(info->label->labeller,
|
||||||
info->label);
|
info->label);
|
||||||
@ -599,31 +603,36 @@ static int _lvmcache_update_pvid(struct lvmcache_info *info, const char *pvid)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _lvmcache_update_vgid(struct lvmcache_info *info, const char *vgid)
|
/*
|
||||||
|
* vginfo must be info->vginfo unless info is NULL (orphans)
|
||||||
|
*/
|
||||||
|
static int _lvmcache_update_vgid(struct lvmcache_info *info,
|
||||||
|
struct lvmcache_vginfo *vginfo,
|
||||||
|
const char *vgid)
|
||||||
{
|
{
|
||||||
if (!vgid || !info->vginfo ||
|
if (!vgid || !vginfo ||
|
||||||
!strncmp(info->vginfo->vgid, vgid, ID_LEN))
|
!strncmp(vginfo->vgid, vgid, ID_LEN))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (info->vginfo && *info->vginfo->vgid)
|
if (vginfo && *vginfo->vgid)
|
||||||
dm_hash_remove(_vgid_hash, info->vginfo->vgid);
|
dm_hash_remove(_vgid_hash, vginfo->vgid);
|
||||||
if (!vgid) {
|
if (!vgid) {
|
||||||
log_debug("lvmcache: %s: clearing VGID", dev_name(info->dev));
|
log_debug("lvmcache: %s: clearing VGID", info ? dev_name(info->dev) : vginfo->vgname);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(info->vginfo->vgid, vgid, ID_LEN);
|
strncpy(vginfo->vgid, vgid, ID_LEN);
|
||||||
info->vginfo->vgid[ID_LEN] = '\0';
|
vginfo->vgid[ID_LEN] = '\0';
|
||||||
if (!dm_hash_insert(_vgid_hash, info->vginfo->vgid, info->vginfo)) {
|
if (!dm_hash_insert(_vgid_hash, vginfo->vgid, vginfo)) {
|
||||||
log_error("_lvmcache_update: vgid hash insertion failed: %s",
|
log_error("_lvmcache_update: vgid hash insertion failed: %s",
|
||||||
info->vginfo->vgid);
|
vginfo->vgid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_orphan_vg(info->vginfo->vgname))
|
if (!is_orphan_vg(vginfo->vgname))
|
||||||
log_debug("lvmcache: %s: setting %s VGID to %s",
|
log_debug("lvmcache: %s: setting %s VGID to %s",
|
||||||
dev_name(info->dev), info->vginfo->vgname,
|
dev_name(info->dev), vginfo->vgname,
|
||||||
info->vginfo->vgid);
|
vginfo->vgid);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -714,16 +723,18 @@ static int _insert_vginfo(struct lvmcache_vginfo *new_vginfo, const char *vgid,
|
|||||||
|
|
||||||
static int _lvmcache_update_vgname(struct lvmcache_info *info,
|
static int _lvmcache_update_vgname(struct lvmcache_info *info,
|
||||||
const char *vgname, const char *vgid,
|
const char *vgname, const char *vgid,
|
||||||
uint32_t vgstatus, const char *creation_host)
|
uint32_t vgstatus, const char *creation_host,
|
||||||
|
const struct format_type *fmt)
|
||||||
{
|
{
|
||||||
struct lvmcache_vginfo *vginfo, *primary_vginfo;
|
struct lvmcache_vginfo *vginfo, *primary_vginfo;
|
||||||
// struct lvmcache_vginfo *old_vginfo, *next;
|
// struct lvmcache_vginfo *old_vginfo, *next;
|
||||||
|
|
||||||
if (!vgname || (info->vginfo && !strcmp(info->vginfo->vgname, vgname)))
|
if (!vgname || (info && info->vginfo && !strcmp(info->vginfo->vgname, vgname)))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* Remove existing vginfo entry */
|
/* Remove existing vginfo entry */
|
||||||
_drop_vginfo(info);
|
if (info)
|
||||||
|
_drop_vginfo(info, info->vginfo);
|
||||||
|
|
||||||
/* Get existing vginfo or create new one */
|
/* Get existing vginfo or create new one */
|
||||||
if (!(vginfo = vginfo_from_vgname(vgname, vgid))) {
|
if (!(vginfo = vginfo_from_vgname(vgname, vgid))) {
|
||||||
@ -791,18 +802,25 @@ static int _lvmcache_update_vgname(struct lvmcache_info *info,
|
|||||||
***/
|
***/
|
||||||
}
|
}
|
||||||
|
|
||||||
info->vginfo = vginfo;
|
if (info) {
|
||||||
list_add(&vginfo->infos, &info->list);
|
info->vginfo = vginfo;
|
||||||
|
list_add(&vginfo->infos, &info->list);
|
||||||
|
} else if (!_lvmcache_update_vgid(info, vginfo, vgid)) /* Orphans */
|
||||||
|
return_0;
|
||||||
|
|
||||||
_update_cache_vginfo_lock_state(vginfo, vgname_is_locked(vgname));
|
_update_cache_vginfo_lock_state(vginfo, vgname_is_locked(vgname));
|
||||||
|
|
||||||
/* FIXME Check consistency of list! */
|
/* FIXME Check consistency of list! */
|
||||||
vginfo->fmt = info->fmt;
|
vginfo->fmt = fmt;
|
||||||
|
|
||||||
log_debug("lvmcache: %s: now in VG %s%s%s%s", dev_name(info->dev),
|
if (info)
|
||||||
vgname, vginfo->vgid[0] ? " (" : "",
|
log_debug("lvmcache: %s: now in VG %s%s%s%s",
|
||||||
vginfo->vgid[0] ? vginfo->vgid : "",
|
dev_name(info->dev),
|
||||||
vginfo->vgid[0] ? ")" : "");
|
vgname, vginfo->vgid[0] ? " (" : "",
|
||||||
|
vginfo->vgid[0] ? vginfo->vgid : "",
|
||||||
|
vginfo->vgid[0] ? ")" : "");
|
||||||
|
else
|
||||||
|
log_debug("lvmcache: initialised VG %s", vgname);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -842,6 +860,16 @@ static int _lvmcache_update_vgstatus(struct lvmcache_info *info, uint32_t vgstat
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int lvmcache_add_orphan_vginfo(const char *vgname, struct format_type *fmt)
|
||||||
|
{
|
||||||
|
if (!_lock_hash && !lvmcache_init()) {
|
||||||
|
log_error("Internal cache initialisation failed");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _lvmcache_update_vgname(NULL, vgname, vgname, 0, "", fmt);
|
||||||
|
}
|
||||||
|
|
||||||
int lvmcache_update_vgname_and_id(struct lvmcache_info *info,
|
int lvmcache_update_vgname_and_id(struct lvmcache_info *info,
|
||||||
const char *vgname, const char *vgid,
|
const char *vgname, const char *vgid,
|
||||||
uint32_t vgstatus, const char *creation_host)
|
uint32_t vgstatus, const char *creation_host)
|
||||||
@ -852,9 +880,10 @@ int lvmcache_update_vgname_and_id(struct lvmcache_info *info,
|
|||||||
vgname = info->fmt->orphan_vg_name;
|
vgname = info->fmt->orphan_vg_name;
|
||||||
vgid = vgname;
|
vgid = vgname;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_lvmcache_update_vgname(info, vgname, vgid, vgstatus,
|
if (!_lvmcache_update_vgname(info, vgname, vgid, vgstatus,
|
||||||
creation_host) ||
|
creation_host, info->fmt) ||
|
||||||
!_lvmcache_update_vgid(info, vgid) ||
|
!_lvmcache_update_vgid(info, info->vginfo, vgid) ||
|
||||||
!_lvmcache_update_vgstatus(info, vgstatus, creation_host))
|
!_lvmcache_update_vgstatus(info, vgstatus, creation_host))
|
||||||
return_0;
|
return_0;
|
||||||
|
|
||||||
@ -1036,7 +1065,7 @@ static void _lvmcache_destroy_lockname(struct dm_hash_node *n)
|
|||||||
dm_hash_get_key(_lock_hash, n));
|
dm_hash_get_key(_lock_hash, n));
|
||||||
}
|
}
|
||||||
|
|
||||||
void lvmcache_destroy(void)
|
void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans)
|
||||||
{
|
{
|
||||||
struct dm_hash_node *n;
|
struct dm_hash_node *n;
|
||||||
log_verbose("Wiping internal VG cache");
|
log_verbose("Wiping internal VG cache");
|
||||||
@ -1069,4 +1098,7 @@ void lvmcache_destroy(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
list_init(&_vginfos);
|
list_init(&_vginfos);
|
||||||
|
|
||||||
|
if (retain_orphans)
|
||||||
|
init_lvmcache_orphans(cmd);
|
||||||
}
|
}
|
||||||
|
3
lib/cache/lvmcache.h
vendored
3
lib/cache/lvmcache.h
vendored
@ -63,7 +63,7 @@ struct lvmcache_info {
|
|||||||
};
|
};
|
||||||
|
|
||||||
int lvmcache_init(void);
|
int lvmcache_init(void);
|
||||||
void lvmcache_destroy(void);
|
void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans);
|
||||||
|
|
||||||
/* Set full_scan to 1 to reread every filtered device label or
|
/* Set full_scan to 1 to reread every filtered device label or
|
||||||
* 2 to rescan /dev for new devices */
|
* 2 to rescan /dev for new devices */
|
||||||
@ -74,6 +74,7 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
|
|||||||
struct device *dev,
|
struct device *dev,
|
||||||
const char *vgname, const char *vgid,
|
const char *vgname, const char *vgid,
|
||||||
uint32_t vgstatus);
|
uint32_t vgstatus);
|
||||||
|
int lvmcache_add_orphan_vginfo(const char *vgname, struct format_type *fmt);
|
||||||
void lvmcache_del(struct lvmcache_info *info);
|
void lvmcache_del(struct lvmcache_info *info);
|
||||||
|
|
||||||
/* Update things */
|
/* Update things */
|
||||||
|
@ -721,6 +721,17 @@ static int _init_formats(struct cmd_context *cmd)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int init_lvmcache_orphans(struct cmd_context *cmd)
|
||||||
|
{
|
||||||
|
struct format_type *fmt;
|
||||||
|
|
||||||
|
list_iterate_items(fmt, &cmd->formats)
|
||||||
|
if (!lvmcache_add_orphan_vginfo(fmt->orphan_vg_name, fmt))
|
||||||
|
return_0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int _init_segtypes(struct cmd_context *cmd)
|
static int _init_segtypes(struct cmd_context *cmd)
|
||||||
{
|
{
|
||||||
struct segment_type *segtype;
|
struct segment_type *segtype;
|
||||||
@ -981,6 +992,9 @@ struct cmd_context *create_toolcontext(struct arg *the_args, unsigned is_static,
|
|||||||
if (!_init_formats(cmd))
|
if (!_init_formats(cmd))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
if (!init_lvmcache_orphans(cmd))
|
||||||
|
goto error;
|
||||||
|
|
||||||
if (!_init_segtypes(cmd))
|
if (!_init_segtypes(cmd))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
@ -1044,7 +1058,7 @@ int refresh_toolcontext(struct cmd_context *cmd)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
activation_release();
|
activation_release();
|
||||||
lvmcache_destroy();
|
lvmcache_destroy(cmd, 0);
|
||||||
label_exit();
|
label_exit();
|
||||||
_destroy_segtypes(&cmd->segtypes);
|
_destroy_segtypes(&cmd->segtypes);
|
||||||
_destroy_formats(&cmd->formats);
|
_destroy_formats(&cmd->formats);
|
||||||
@ -1086,6 +1100,9 @@ int refresh_toolcontext(struct cmd_context *cmd)
|
|||||||
if (!_init_formats(cmd))
|
if (!_init_formats(cmd))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if (!init_lvmcache_orphans(cmd))
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (!_init_segtypes(cmd))
|
if (!_init_segtypes(cmd))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -1107,7 +1124,7 @@ void destroy_toolcontext(struct cmd_context *cmd)
|
|||||||
|
|
||||||
archive_exit(cmd);
|
archive_exit(cmd);
|
||||||
backup_exit(cmd);
|
backup_exit(cmd);
|
||||||
lvmcache_destroy();
|
lvmcache_destroy(cmd, 0);
|
||||||
label_exit();
|
label_exit();
|
||||||
_destroy_segtypes(&cmd->segtypes);
|
_destroy_segtypes(&cmd->segtypes);
|
||||||
_destroy_formats(&cmd->formats);
|
_destroy_formats(&cmd->formats);
|
||||||
|
@ -95,5 +95,6 @@ struct cmd_context *create_toolcontext(struct arg *the_args, unsigned is_static,
|
|||||||
void destroy_toolcontext(struct cmd_context *cmd);
|
void destroy_toolcontext(struct cmd_context *cmd);
|
||||||
int refresh_toolcontext(struct cmd_context *cmd);
|
int refresh_toolcontext(struct cmd_context *cmd);
|
||||||
int config_files_changed(struct cmd_context *cmd);
|
int config_files_changed(struct cmd_context *cmd);
|
||||||
|
int init_lvmcache_orphans(struct cmd_context *cmd);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -24,8 +24,6 @@
|
|||||||
#include "format_pool.h"
|
#include "format_pool.h"
|
||||||
#include "pool_label.h"
|
#include "pool_label.h"
|
||||||
|
|
||||||
#define FMT_POOL_NAME "pool"
|
|
||||||
|
|
||||||
/* Must be called after pvs are imported */
|
/* Must be called after pvs are imported */
|
||||||
static struct user_subpool *_build_usp(struct list *pls, struct dm_pool *mem,
|
static struct user_subpool *_build_usp(struct list *pls, struct dm_pool *mem,
|
||||||
int *sps)
|
int *sps)
|
||||||
@ -316,7 +314,7 @@ struct format_type *init_format(struct cmd_context *cmd)
|
|||||||
fmt->ops = &_format_pool_ops;
|
fmt->ops = &_format_pool_ops;
|
||||||
fmt->name = FMT_POOL_NAME;
|
fmt->name = FMT_POOL_NAME;
|
||||||
fmt->alias = NULL;
|
fmt->alias = NULL;
|
||||||
fmt->orphan_vg_name = ORPHAN_VG_NAME(FMT_POOL_NAME);
|
fmt->orphan_vg_name = FMT_POOL_ORPHAN_VG_NAME;
|
||||||
fmt->features = 0;
|
fmt->features = 0;
|
||||||
fmt->private = NULL;
|
fmt->private = NULL;
|
||||||
|
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
|
|
||||||
#include "metadata.h"
|
#include "metadata.h"
|
||||||
|
|
||||||
|
#define FMT_POOL_NAME "pool"
|
||||||
|
#define FMT_POOL_ORPHAN_VG_NAME ORPHAN_VG_NAME(FMT_POOL_NAME)
|
||||||
|
|
||||||
#ifdef POOL_INTERNAL
|
#ifdef POOL_INTERNAL
|
||||||
struct format_type *init_pool_format(struct cmd_context *cmd);
|
struct format_type *init_pool_format(struct cmd_context *cmd);
|
||||||
#endif
|
#endif
|
||||||
|
@ -692,6 +692,10 @@ int vg_change_pesize(struct cmd_context *cmd __attribute((unused)),
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Separate metadata areas after splitting a VG.
|
||||||
|
* Also accepts orphan VG as destination (for vgreduce).
|
||||||
|
*/
|
||||||
int vg_split_mdas(struct cmd_context *cmd __attribute((unused)),
|
int vg_split_mdas(struct cmd_context *cmd __attribute((unused)),
|
||||||
struct volume_group *vg_from, struct volume_group *vg_to)
|
struct volume_group *vg_from, struct volume_group *vg_to)
|
||||||
{
|
{
|
||||||
@ -708,11 +712,16 @@ int vg_split_mdas(struct cmd_context *cmd __attribute((unused)),
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mda->ops->mda_in_vg(vg_from->fid, vg_from, mda))
|
if (!mda->ops->mda_in_vg(vg_from->fid, vg_from, mda)) {
|
||||||
list_move(&mda->list, mdas_to);
|
if (is_orphan_vg(vg_to->name))
|
||||||
|
list_del(&mda->list);
|
||||||
|
else
|
||||||
|
list_move(&mda->list, mdas_to);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list_empty(mdas_from) || list_empty(mdas_to))
|
if (list_empty(mdas_from) ||
|
||||||
|
(!is_orphan_vg(vg_to->name) && list_empty(mdas_to)))
|
||||||
return common_mda;
|
return common_mda;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -1366,6 +1375,8 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd,
|
|||||||
struct volume_group *vg;
|
struct volume_group *vg;
|
||||||
struct physical_volume *pv;
|
struct physical_volume *pv;
|
||||||
|
|
||||||
|
lvmcache_label_scan(cmd, 0);
|
||||||
|
|
||||||
if (!(vginfo = vginfo_from_vgname(orphan_vgname, NULL)))
|
if (!(vginfo = vginfo_from_vgname(orphan_vgname, NULL)))
|
||||||
return_NULL;
|
return_NULL;
|
||||||
|
|
||||||
|
@ -938,7 +938,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
out:
|
out:
|
||||||
if (test_mode()) {
|
if (test_mode()) {
|
||||||
log_verbose("Test mode: Wiping internal cache");
|
log_verbose("Test mode: Wiping internal cache");
|
||||||
lvmcache_destroy();
|
lvmcache_destroy(cmd, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd->cft_override) {
|
if (cmd->cft_override) {
|
||||||
|
@ -81,7 +81,7 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name)
|
|||||||
unlock_vg(cmd, VG_ORPHANS);
|
unlock_vg(cmd, VG_ORPHANS);
|
||||||
|
|
||||||
persistent_filter_wipe(cmd->filter);
|
persistent_filter_wipe(cmd->filter);
|
||||||
lvmcache_destroy();
|
lvmcache_destroy(cmd, 1);
|
||||||
|
|
||||||
init_md_filtering(0);
|
init_md_filtering(0);
|
||||||
if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
|
if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
|
||||||
|
@ -130,7 +130,7 @@ int pvscan(struct cmd_context *cmd, int argc __attribute((unused)),
|
|||||||
}
|
}
|
||||||
|
|
||||||
persistent_filter_wipe(cmd->filter);
|
persistent_filter_wipe(cmd->filter);
|
||||||
lvmcache_destroy();
|
lvmcache_destroy(cmd, 1);
|
||||||
|
|
||||||
log_verbose("Walking through all physical volumes");
|
log_verbose("Walking through all physical volumes");
|
||||||
if (!(pvslist = get_pvs(cmd))) {
|
if (!(pvslist = get_pvs(cmd))) {
|
||||||
|
@ -353,6 +353,8 @@ static int _vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
|
|||||||
void *handle __attribute((unused)))
|
void *handle __attribute((unused)))
|
||||||
{
|
{
|
||||||
struct pv_list *pvl;
|
struct pv_list *pvl;
|
||||||
|
struct volume_group *orphan_vg;
|
||||||
|
int consistent = 1;
|
||||||
const char *name = pv_dev_name(pv);
|
const char *name = pv_dev_name(pv);
|
||||||
|
|
||||||
if (pv_pe_alloc_count(pv)) {
|
if (pv_pe_alloc_count(pv)) {
|
||||||
@ -366,10 +368,17 @@ static int _vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
|
|||||||
return ECMD_FAILED;
|
return ECMD_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE | LCK_NONBLOCK)) {
|
||||||
|
log_error("Can't get lock for orphan PVs");
|
||||||
|
return ECMD_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
pvl = find_pv_in_vg(vg, name);
|
pvl = find_pv_in_vg(vg, name);
|
||||||
|
|
||||||
if (!archive(vg))
|
if (!archive(vg)) {
|
||||||
|
unlock_vg(cmd, VG_ORPHANS);
|
||||||
return ECMD_FAILED;
|
return ECMD_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
log_verbose("Removing \"%s\" from volume group \"%s\"", name, vg->name);
|
log_verbose("Removing \"%s\" from volume group \"%s\"", name, vg->name);
|
||||||
|
|
||||||
@ -381,6 +390,7 @@ static int _vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
|
|||||||
|
|
||||||
if (!dev_get_size(pv_dev(pv), &pv->size)) {
|
if (!dev_get_size(pv_dev(pv), &pv->size)) {
|
||||||
log_error("%s: Couldn't get size.", pv_dev_name(pv));
|
log_error("%s: Couldn't get size.", pv_dev_name(pv));
|
||||||
|
unlock_vg(cmd, VG_ORPHANS);
|
||||||
return ECMD_FAILED;
|
return ECMD_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,9 +398,24 @@ static int _vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
|
|||||||
vg->free_count -= pv_pe_count(pv) - pv_pe_alloc_count(pv);
|
vg->free_count -= pv_pe_count(pv) - pv_pe_alloc_count(pv);
|
||||||
vg->extent_count -= pv_pe_count(pv);
|
vg->extent_count -= pv_pe_count(pv);
|
||||||
|
|
||||||
|
if(!(orphan_vg = vg_read(cmd, vg->fid->fmt->orphan_vg_name, NULL, &consistent)) ||
|
||||||
|
!consistent) {
|
||||||
|
log_error("Unable to read existing orphan PVs");
|
||||||
|
unlock_vg(cmd, VG_ORPHANS);
|
||||||
|
return ECMD_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!vg_split_mdas(cmd, vg, orphan_vg) || !vg->pv_count) {
|
||||||
|
log_error("Cannot remove final metadata area on \"%s\" from \"%s\"",
|
||||||
|
name, vg->name);
|
||||||
|
unlock_vg(cmd, VG_ORPHANS);
|
||||||
|
return ECMD_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
if (!vg_write(vg) || !vg_commit(vg)) {
|
if (!vg_write(vg) || !vg_commit(vg)) {
|
||||||
log_error("Removal of physical volume \"%s\" from "
|
log_error("Removal of physical volume \"%s\" from "
|
||||||
"\"%s\" failed", name, vg->name);
|
"\"%s\" failed", name, vg->name);
|
||||||
|
unlock_vg(cmd, VG_ORPHANS);
|
||||||
return ECMD_FAILED;
|
return ECMD_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -398,9 +423,11 @@ static int _vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
|
|||||||
log_error("Failed to clear metadata from physical "
|
log_error("Failed to clear metadata from physical "
|
||||||
"volume \"%s\" "
|
"volume \"%s\" "
|
||||||
"after removal from \"%s\"", name, vg->name);
|
"after removal from \"%s\"", name, vg->name);
|
||||||
|
unlock_vg(cmd, VG_ORPHANS);
|
||||||
return ECMD_FAILED;
|
return ECMD_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unlock_vg(cmd, VG_ORPHANS);
|
||||||
backup(vg);
|
backup(vg);
|
||||||
|
|
||||||
log_print("Removed \"%s\" from volume group \"%s\"", name, vg->name);
|
log_print("Removed \"%s\" from volume group \"%s\"", name, vg->name);
|
||||||
|
@ -151,7 +151,7 @@ static int vg_rename_path(struct cmd_context *cmd, const char *old_vg_path,
|
|||||||
|
|
||||||
/* FIXME lvmcache corruption - vginfo duplicated instead of renamed */
|
/* FIXME lvmcache corruption - vginfo duplicated instead of renamed */
|
||||||
persistent_filter_wipe(cmd->filter);
|
persistent_filter_wipe(cmd->filter);
|
||||||
lvmcache_destroy();
|
lvmcache_destroy(cmd, 1);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ int vgscan(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
persistent_filter_wipe(cmd->filter);
|
persistent_filter_wipe(cmd->filter);
|
||||||
lvmcache_destroy();
|
lvmcache_destroy(cmd, 1);
|
||||||
|
|
||||||
log_print("Reading all physical volumes. This may take a while...");
|
log_print("Reading all physical volumes. This may take a while...");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user