mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-23 21:35:29 +03:00
Add is_orphan_vg() and change all hardcoded checks to use it.
This commit is contained in:
parent
db02dc218e
commit
ee79277774
@ -1,5 +1,6 @@
|
||||
Version 2.02.29 -
|
||||
==================================
|
||||
Add is_orphan_vg() and change all hardcoded checks to use it.
|
||||
Detect md superblocks version 1.0, 1.1 and 1.2.
|
||||
Add _alloc_pv() and _free_pv() from _pv_create() code and fix error paths.
|
||||
Add pv_dev_name() to access PV device name.
|
||||
|
4
lib/cache/lvmcache.c
vendored
4
lib/cache/lvmcache.c
vendored
@ -633,7 +633,7 @@ static int _lvmcache_update_vgname(struct lvmcache_info *info,
|
||||
return 0;
|
||||
}
|
||||
/* Ensure orphans appear last on list_iterate */
|
||||
if (!*vgname)
|
||||
if (is_orphan_vg(vgname))
|
||||
list_add(&_vginfos, &vginfo->list);
|
||||
else
|
||||
list_add_h(&_vginfos, &vginfo->list);
|
||||
@ -649,7 +649,7 @@ static int _lvmcache_update_vgname(struct lvmcache_info *info,
|
||||
vginfo->fmt = info->fmt;
|
||||
|
||||
log_debug("lvmcache: %s: now %s%s%s%s%s", dev_name(info->dev),
|
||||
*vgname ? "in VG " : "orphaned", vgname,
|
||||
is_orphan_vg(vgname) ? "in VG " : "orphaned", vgname,
|
||||
vginfo->vgid[0] ? " (" : "",
|
||||
vginfo->vgid[0] ? vginfo->vgid : "",
|
||||
vginfo->vgid[0] ? ")" : "");
|
||||
|
@ -480,7 +480,7 @@ int read_pvs_in_vg(const struct format_type *fmt, const char *vg_name,
|
||||
}
|
||||
|
||||
/* Did we find the whole VG? */
|
||||
if (!vg_name || !*vg_name ||
|
||||
if (!vg_name || is_orphan_vg(vg_name) ||
|
||||
(data && *data->pvd.vg_name &&
|
||||
list_size(head) == data->vgd.pv_cur))
|
||||
return 1;
|
||||
|
@ -1438,7 +1438,8 @@ static int _text_pv_read(const struct format_type *fmt, const char *pv_name,
|
||||
info = (struct lvmcache_info *) label->info;
|
||||
|
||||
/* Have we already cached vgname? */
|
||||
if (info->vginfo && info->vginfo->vgname && *info->vginfo->vgname &&
|
||||
if (info->vginfo && info->vginfo->vgname &&
|
||||
!is_orphan_vg(info->vginfo->vgname) &&
|
||||
get_pv_from_vg_by_id(info->fmt, info->vginfo->vgname,
|
||||
info->vginfo->vgid, info->dev->pvid, pv)) {
|
||||
return 1;
|
||||
@ -1449,7 +1450,7 @@ static int _text_pv_read(const struct format_type *fmt, const char *pv_name,
|
||||
lvmcache_label_scan(fmt->cmd, 2);
|
||||
|
||||
if (info->vginfo && info->vginfo->vgname &&
|
||||
*info->vginfo->vgname &&
|
||||
!is_orphan_vg(info->vginfo->vgname) &&
|
||||
get_pv_from_vg_by_id(info->fmt, info->vginfo->vgname,
|
||||
info->vginfo->vgid,
|
||||
info->dev->pvid, pv)) {
|
||||
|
@ -288,7 +288,7 @@ int check_lvm1_vg_inactive(struct cmd_context *cmd, const char *vgname)
|
||||
char path[PATH_MAX];
|
||||
|
||||
/* We'll allow operations on orphans */
|
||||
if (!*vgname)
|
||||
if (is_orphan_vg(vgname))
|
||||
return 1;
|
||||
|
||||
if (dm_snprintf(path, sizeof(path), "%s/lvm/VGs/%s", cmd->proc_dir,
|
||||
|
@ -304,6 +304,7 @@ struct list *get_vgids(struct cmd_context *cmd, int full_scan);
|
||||
|
||||
int pv_write(struct cmd_context *cmd, struct physical_volume *pv,
|
||||
struct list *mdas, int64_t label_sector);
|
||||
int is_orphan_vg(const char *vg_name);
|
||||
int is_orphan(pv_t *pv);
|
||||
vg_t *vg_lock_and_read(struct cmd_context *cmd, const char *vg_name,
|
||||
uint32_t lock_flags, uint32_t status_flags,
|
||||
|
@ -93,7 +93,7 @@ int add_pv_to_vg(struct volume_group *vg, const char *pv_name,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (*pv->vg_name) {
|
||||
if (!is_orphan_vg(pv->vg_name)) {
|
||||
log_error("Physical volume '%s' is already in volume group "
|
||||
"'%s'", pv_name, pv->vg_name);
|
||||
return 0;
|
||||
@ -928,7 +928,7 @@ static struct physical_volume *_find_pv_by_name(struct cmd_context *cmd,
|
||||
}
|
||||
|
||||
/* FIXME Can fail when no PV mda */
|
||||
if (!pv->vg_name[0]) {
|
||||
if (is_orphan_vg(pv->vg_name)) {
|
||||
log_error("Physical volume %s not in a volume group", pv_name);
|
||||
return NULL;
|
||||
}
|
||||
@ -1272,7 +1272,7 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
|
||||
struct list all_pvs;
|
||||
char uuid[64] __attribute((aligned(8)));
|
||||
|
||||
if (!*vgname) {
|
||||
if (is_orphan_vg(vgname)) {
|
||||
if (use_precommitted) {
|
||||
log_error("Internal error: vg_read requires vgname "
|
||||
"with pre-commit.");
|
||||
@ -1536,7 +1536,7 @@ static struct volume_group *_vg_read_by_vgid(struct cmd_context *cmd,
|
||||
|
||||
/* Is corresponding vgname already cached? */
|
||||
if ((vginfo = vginfo_from_vgid(vgid)) &&
|
||||
vginfo->vgname && *vginfo->vgname) {
|
||||
vginfo->vgname && !is_orphan_vg(vginfo->vgname)) {
|
||||
if ((vg = _vg_read(cmd, vginfo->vgname, vgid,
|
||||
&consistent, precommitted)) &&
|
||||
!strncmp((char *)vg->id.uuid, vgid, ID_LEN)) {
|
||||
@ -1566,7 +1566,7 @@ static struct volume_group *_vg_read_by_vgid(struct cmd_context *cmd,
|
||||
|
||||
list_iterate_items(strl, vgnames) {
|
||||
vgname = strl->str;
|
||||
if (!vgname || !*vgname)
|
||||
if (!vgname || is_orphan_vg(vgname))
|
||||
continue; // FIXME Unnecessary?
|
||||
consistent = 0;
|
||||
if ((vg = _vg_read(cmd, vgname, vgid, &consistent,
|
||||
@ -1778,7 +1778,7 @@ static int _pv_write(struct cmd_context *cmd __attribute((unused)),
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (*pv->vg_name || pv->pe_alloc_count) {
|
||||
if (!is_orphan_vg(pv->vg_name) || pv->pe_alloc_count) {
|
||||
log_error("Assertion failed: can't _pv_write non-orphan PV "
|
||||
"(in VG %s)", pv->vg_name);
|
||||
return 0;
|
||||
@ -1814,16 +1814,24 @@ int pv_write_orphan(struct cmd_context *cmd, struct physical_volume *pv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* is_orphan_vg - Determine whether a vg_name is an orphan
|
||||
* @vg_name: pointer to the vg_name
|
||||
*/
|
||||
int is_orphan_vg(const char *vg_name)
|
||||
{
|
||||
return (vg_name[0] ? 0 : 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* is_orphan - Determine whether a pv is an orphan based on its vg_name
|
||||
* @pv: handle to the physical volume
|
||||
*/
|
||||
int is_orphan(pv_t *pv)
|
||||
{
|
||||
return (pv_field(pv, vg_name)[0] ? 0 : 1);
|
||||
return is_orphan_vg(pv_field(pv, vg_name));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns:
|
||||
* 0 - fail
|
||||
|
@ -180,7 +180,7 @@ struct format_handler {
|
||||
|
||||
/*
|
||||
* Write a PV structure to disk. Fails if the PV is in a VG ie
|
||||
* pv->vg_name must be null.
|
||||
* pv->vg_name must be a valid orphan VG name
|
||||
*/
|
||||
int (*pv_write) (const struct format_type * fmt,
|
||||
struct physical_volume * pv, struct list * mdas,
|
||||
|
@ -455,7 +455,7 @@ int pv_resize_single(struct cmd_context *cmd,
|
||||
|
||||
list_init(&mdas);
|
||||
|
||||
if (!*pv_vg_name(pv)) {
|
||||
if (is_orphan_vg(pv_vg_name(pv))) {
|
||||
vg_name = ORPHAN;
|
||||
|
||||
if (!lock_vol(cmd, vg_name, LCK_VG_WRITE)) {
|
||||
@ -572,7 +572,7 @@ int pv_resize_single(struct cmd_context *cmd,
|
||||
pv_name, pv_size(pv));
|
||||
|
||||
log_verbose("Updating physical volume \"%s\"", pv_name);
|
||||
if (*pv_vg_name(pv)) {
|
||||
if (!is_orphan_vg(pv_vg_name(pv))) {
|
||||
if (!vg_write(vg) || !vg_commit(vg)) {
|
||||
unlock_vg(cmd, pv_vg_name(pv));
|
||||
log_error("Failed to store physical volume \"%s\" in "
|
||||
|
@ -341,7 +341,7 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv,
|
||||
|
||||
list_iterate_items(strl, vgnames) {
|
||||
vgname = strl->str;
|
||||
if (!vgname || !*vgname)
|
||||
if (!vgname || is_orphan_vg(vgname))
|
||||
continue; /* FIXME Unnecessary? */
|
||||
if (!lock_vol(cmd, vgname, lock_type)) {
|
||||
log_error("Can't lock %s: skipping", vgname);
|
||||
@ -576,7 +576,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
|
||||
list_iterate_items(sl, vgids) {
|
||||
vgid = sl->str;
|
||||
if (!vgid || !(vg_name = vgname_from_vgid(cmd->mem, vgid)) ||
|
||||
!*vg_name)
|
||||
is_orphan_vg(vg_name))
|
||||
continue;
|
||||
ret_max = _process_one_vg(cmd, vg_name, vgid, &tags,
|
||||
&arg_vgnames,
|
||||
@ -588,7 +588,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
|
||||
} else {
|
||||
list_iterate_items(sl, vgnames) {
|
||||
vg_name = sl->str;
|
||||
if (!vg_name || !*vg_name)
|
||||
if (!vg_name || is_orphan_vg(vg_name))
|
||||
continue; /* FIXME Unnecessary? */
|
||||
ret_max = _process_one_vg(cmd, vg_name, NULL, &tags,
|
||||
&arg_vgnames,
|
||||
@ -1199,6 +1199,9 @@ int validate_vg_name(struct cmd_context *cmd, const char *vg_name)
|
||||
if (!validate_name(vg_name))
|
||||
return 0;
|
||||
|
||||
if (is_orphan_vg(vg_name))
|
||||
return 0;
|
||||
|
||||
snprintf(vg_path, PATH_MAX, "%s%s", cmd->dev_dir, vg_name);
|
||||
if (path_exists(vg_path)) {
|
||||
log_error("%s: already exists in filesystem", vg_path);
|
||||
|
@ -65,7 +65,8 @@ static int vg_rename_path(struct cmd_context *cmd, const char *old_vg_path,
|
||||
|
||||
list_iterate_items(sl, vgids) {
|
||||
vgid = sl->str;
|
||||
if (!vgid || !(vg_name = vgname_from_vgid(NULL, vgid)) || !*vg_name)
|
||||
if (!vgid || !(vg_name = vgname_from_vgid(NULL, vgid))
|
||||
|| is_orphan_vg(vg_name))
|
||||
continue;
|
||||
if (!strcmp(vg_name, vg_name_old)) {
|
||||
if (match) {
|
||||
|
Loading…
Reference in New Issue
Block a user