1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-10 16:58:47 +03:00

use scan_vgs_for_pvs to detect non-orphans without MDAs

This commit is contained in:
Alasdair Kergon 2008-01-16 18:15:26 +00:00
parent 6ab424acda
commit fb3226a3ed
7 changed files with 72 additions and 14 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.30 - Version 2.02.30 -
=================================== ===================================
Fix process_all_pvs to detect non-orphans with no MDAs correctly.
Don't use block_on_error with mirror targets version 1.12 and above. Don't use block_on_error with mirror targets version 1.12 and above.
Update vgsplit to include vgcreate-style options when new VG is destination. Update vgsplit to include vgcreate-style options when new VG is destination.
Update vgsplit to accept existing VG as destination. Update vgsplit to accept existing VG as destination.

View File

@ -310,6 +310,7 @@ struct list *get_pvs(struct cmd_context *cmd);
/* Set full_scan to 1 to re-read every (filtered) device label */ /* Set full_scan to 1 to re-read every (filtered) device label */
struct list *get_vgs(struct cmd_context *cmd, int full_scan); struct list *get_vgs(struct cmd_context *cmd, int full_scan);
struct list *get_vgids(struct cmd_context *cmd, int full_scan); struct list *get_vgids(struct cmd_context *cmd, int full_scan);
int scan_vgs_for_pvs(struct cmd_context *cmd);
int pv_write(struct cmd_context *cmd, struct physical_volume *pv, int pv_write(struct cmd_context *cmd, struct physical_volume *pv,
struct list *mdas, int64_t label_sector); struct list *mdas, int64_t label_sector);

View File

@ -1015,7 +1015,16 @@ static struct physical_volume *_find_pv_by_name(struct cmd_context *cmd,
return NULL; return NULL;
} }
/* FIXME Can fail when no PV mda */ if (is_orphan_vg(pv->vg_name)) {
/* If a PV has no MDAs - need to search all VGs for it */
if (!scan_vgs_for_pvs(cmd))
return_NULL;
if (!(pv = _pv_read(cmd, pv_name, NULL, NULL, 1))) {
log_error("Physical volume %s not found", pv_name);
return NULL;
}
}
if (is_orphan_vg(pv->vg_name)) { if (is_orphan_vg(pv->vg_name)) {
log_error("Physical volume %s not in a volume group", pv_name); log_error("Physical volume %s not in a volume group", pv_name);
return NULL; return NULL;
@ -1788,7 +1797,7 @@ struct list *get_vgids(struct cmd_context *cmd, int full_scan)
return lvmcache_get_vgids(cmd, full_scan); return lvmcache_get_vgids(cmd, full_scan);
} }
struct list *get_pvs(struct cmd_context *cmd) static int _get_pvs(struct cmd_context *cmd, struct list **pvslist)
{ {
struct str_list *strl; struct str_list *strl;
struct list *results; struct list *results;
@ -1802,17 +1811,19 @@ struct list *get_pvs(struct cmd_context *cmd)
lvmcache_label_scan(cmd, 0); lvmcache_label_scan(cmd, 0);
if (!(results = dm_pool_alloc(cmd->mem, sizeof(*results)))) { if (pvslist) {
log_error("PV list allocation failed"); if (!(results = dm_pool_alloc(cmd->mem, sizeof(*results)))) {
return NULL; log_error("PV list allocation failed");
} return NULL;
}
list_init(results); list_init(results);
}
/* Get list of VGs */ /* Get list of VGs */
if (!(vgids = get_vgids(cmd, 0))) { if (!(vgids = get_vgids(cmd, 0))) {
log_error("get_pvs: get_vgs failed"); log_error("get_pvs: get_vgs failed");
return NULL; return 0;
} }
/* Read every VG to ensure cache consistency */ /* Read every VG to ensure cache consistency */
@ -1839,16 +1850,36 @@ struct list *get_pvs(struct cmd_context *cmd)
vgname); vgname);
/* Move PVs onto results list */ /* Move PVs onto results list */
list_iterate_safe(pvh, tmp, &vg->pvs) { if (pvslist)
list_add(results, pvh); list_iterate_safe(pvh, tmp, &vg->pvs)
} list_add(results, pvh);
} }
init_pvmove(old_pvmove); init_pvmove(old_pvmove);
init_partial(old_partial); init_partial(old_partial);
if (pvslist)
*pvslist = results;
else
dm_pool_free(cmd->mem, vgids);
return 1;
}
struct list *get_pvs(struct cmd_context *cmd)
{
struct list *results;
if (!_get_pvs(cmd, &results))
return NULL;
return results; return results;
} }
int scan_vgs_for_pvs(struct cmd_context *cmd)
{
return _get_pvs(cmd, NULL);
}
/* FIXME: liblvm todo - make into function that takes handle */ /* FIXME: liblvm todo - make into function that takes handle */
int pv_write(struct cmd_context *cmd __attribute((unused)), int pv_write(struct cmd_context *cmd __attribute((unused)),
struct physical_volume *pv, struct physical_volume *pv,

View File

@ -584,7 +584,6 @@ static int _process_command_line(struct cmd_context *cmd, int *argc,
a->ui64_value = 0; a->ui64_value = 0;
} }
memset(str, 0, sizeof(str));
/* fill in the short and long opts */ /* fill in the short and long opts */
for (i = 0; i < cmd->command->num_args; i++) for (i = 0; i < cmd->command->num_args; i++)
_add_getopt_arg(cmd->command->valid_args[i], &ptr, &o); _add_getopt_arg(cmd->command->valid_args[i], &ptr, &o);

View File

@ -51,7 +51,8 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name)
* system. * system.
*/ */
if (pv && is_orphan(pv)) { if (pv && is_orphan(pv)) {
(void) get_vgs(cmd, 1); if (!scan_vgs_for_pvs(cmd))
return_0;
pv = pv_read(cmd, name, NULL, NULL, 0); pv = pv_read(cmd, name, NULL, NULL, 0);
} }

View File

@ -26,7 +26,7 @@ static int _pvdisplay_single(struct cmd_context *cmd,
const char *pv_name = pv_dev_name(pv); const char *pv_name = pv_dev_name(pv);
const char *vg_name = NULL; const char *vg_name = NULL;
if (!is_orphan(pv) && !vg) { if (!is_orphan(pv) && !vg) {
vg_name = pv_vg_name(pv); vg_name = pv_vg_name(pv);
if (!(vg = vg_lock_and_read(cmd, vg_name, (char *)&pv->vgid, if (!(vg = vg_lock_and_read(cmd, vg_name, (char *)&pv->vgid,
LCK_VG_READ, CLUSTERED, 0))) { LCK_VG_READ, CLUSTERED, 0))) {

View File

@ -696,6 +696,7 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv,
struct str_list *sll; struct str_list *sll;
char *tagname; char *tagname;
int consistent = 1; int consistent = 1;
int scanned = 0;
list_init(&tags); list_init(&tags);
@ -738,6 +739,30 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv,
ret_max = ECMD_FAILED; ret_max = ECMD_FAILED;
continue; continue;
} }
/*
* If a PV has no MDAs it may appear to be an
* orphan until the metadata is read off
* another PV in the same VG. Detecting this
* means checking every VG by scanning every
* PV on the system.
*/
if (!scanned && is_orphan(pv)) {
if (!scan_vgs_for_pvs(cmd)) {
stack;
ret_max = ECMD_FAILED;
continue;
}
scanned = 1;
if (!(pv = pv_read(cmd, argv[opt],
NULL, NULL, 1))) {
log_error("Failed to read "
"physical volume "
"\"%s\"", argv[opt]);
ret_max = ECMD_FAILED;
continue;
}
}
} }
ret = process_single(cmd, vg, pv, handle); ret = process_single(cmd, vg, pv, handle);