1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

o get_pvs for format 1

o fix vg_read if vg doesn't exist
This commit is contained in:
Joe Thornber 2001-10-08 17:53:43 +00:00
parent 67905e0d59
commit c8ca2a2993
3 changed files with 51 additions and 12 deletions

View File

@ -47,18 +47,18 @@ static int _import_vg(struct pool *mem,
} }
} }
return 1; return first ? 1 : 0;
} }
static int _import_pvs(struct pool *mem, struct volume_group *vg, static int _import_pvs(struct pool *mem, struct list_head *pvs,
struct list_head *pvs) struct list_head *results, int *count)
{ {
struct list_head *tmp; struct list_head *tmp;
struct disk_list *dl; struct disk_list *dl;
struct pv_list *pvl; struct pv_list *pvl;
struct physical_volume *pv; struct physical_volume *pv;
vg->pv_count = 0; *count = 0;
list_for_each(tmp, pvs) { list_for_each(tmp, pvs) {
dl = list_entry(tmp, struct disk_list, list); dl = list_entry(tmp, struct disk_list, list);
pvl = pool_alloc(mem, sizeof(*pvl)); pvl = pool_alloc(mem, sizeof(*pvl));
@ -89,8 +89,8 @@ static int _import_pvs(struct pool *mem, struct volume_group *vg,
pv->pe_count = dl->pv.pe_total; pv->pe_count = dl->pv.pe_total;
pv->pe_allocated = dl->pv.pe_allocated; pv->pe_allocated = dl->pv.pe_allocated;
list_add(&pvl->list, &vg->pvs); list_add(&pvl->list, results);
vg->pv_count++; (*count)++;
} }
return 1; return 1;
@ -276,7 +276,7 @@ static struct volume_group *_build_vg(struct pool *mem, struct list_head *pvs)
if (!_import_vg(mem, vg, pvs)) if (!_import_vg(mem, vg, pvs))
goto bad; goto bad;
if (!_import_pvs(mem, vg, pvs)) if (!_import_pvs(mem, pvs, &vg->pvs, &vg->pv_count))
goto bad; goto bad;
if (!_import_lvs(mem, vg, pvs)) if (!_import_lvs(mem, vg, pvs))
@ -362,6 +362,44 @@ static int _vg_write(struct io_space *is, struct volume_group *vg)
} }
#endif #endif
static struct list_head *_get_pvs(struct io_space *is)
{
struct pool *mem = pool_create(1024 * 10);
struct list_head pvs, *results;
uint32_t count;
if (!mem) {
stack;
return NULL;
}
if (!(results = pool_alloc(is->mem, sizeof(*results)))) {
stack;
return NULL;
}
INIT_LIST_HEAD(&pvs);
INIT_LIST_HEAD(results);
if (!read_pvs_in_vg(NULL, is->filter, mem, &pvs)) {
stack;
goto bad;
}
if (!_import_pvs(mem, &pvs, results, &count)) {
stack;
goto bad;
}
pool_destroy(mem);
return results;
bad:
pool_destroy(mem);
pool_free(mem, results);
return NULL;
}
void _destroy(struct io_space *ios) void _destroy(struct io_space *ios)
{ {
dbg_free(ios->prefix); dbg_free(ios->prefix);
@ -373,7 +411,7 @@ struct io_space *create_lvm1_format(const char *prefix, struct pool *mem,
{ {
struct io_space *ios = dbg_malloc(sizeof(*ios)); struct io_space *ios = dbg_malloc(sizeof(*ios));
ios->get_vgs = NULL; ios->get_vgs = _get_pvs;
ios->get_pvs = NULL; ios->get_pvs = NULL;
ios->pv_read = NULL; ios->pv_read = NULL;
ios->pv_write = NULL; ios->pv_write = NULL;

View File

@ -124,11 +124,11 @@ struct lv_list {
struct io_space { struct io_space {
/* Returns list of names of all vgs - vg /* Returns list of names of all vgs - vg
component only, not full path*/ component only, not full path*/
struct name_list *(*get_vgs)(struct io_space *is); struct list_head *(*get_vgs)(struct io_space *is);
/* Returns list of fully-populated pv /* Returns list of fully-populated pv_list
structures */ structures */
struct pv_list *(*get_pvs)(struct io_space *is); struct list_head *(*get_pvs)(struct io_space *is);
/* Return PV with given name (may be full /* Return PV with given name (may be full
or relative path) */ or relative path) */

View File

@ -37,7 +37,8 @@ static void _dump_lv(struct logical_volume *lv, FILE *fp)
for (i = 0; i < lv->le_count; i++) { for (i = 0; i < lv->le_count; i++) {
struct physical_volume *pv = lv->map[i].pv; struct physical_volume *pv = lv->map[i].pv;
fprintf(fp, "\t\tpv = '%s', ", pv ? pv->dev->name : "null ???"); fprintf(fp, "\t\tpv = '%s', ",
pv ? pv->dev->name : "null ???");
fprintf(fp, "\textent = %u\n", lv->map[i].pe); fprintf(fp, "\textent = %u\n", lv->map[i].pe);
} }
fprintf(fp, "\t}\n}\n\n"); fprintf(fp, "\t}\n}\n\n");