1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-11 20:58:50 +03:00

o Changed find_pv_in_vg, and find_lv_in_vg to return a struct pv_list * and

struct lv_list * respectively.
This commit is contained in:
Joe Thornber 2002-01-21 14:28:12 +00:00
parent 752e80cd5a
commit e586401ecb
8 changed files with 54 additions and 46 deletions

View File

@ -232,25 +232,26 @@ struct physical_volume *pv_create(struct format_instance *fi,
return NULL; return NULL;
} }
struct list *find_pv_in_vg(struct volume_group *vg, const char *pv_name) struct pv_list *find_pv_in_vg(struct volume_group *vg, const char *pv_name)
{ {
struct list *pvh; struct list *pvh;
struct pv_list *pv; struct pv_list *pvl;
list_iterate(pvh, &vg->pvs) { list_iterate(pvh, &vg->pvs) {
pv = list_item(pvh, struct pv_list); pvl = list_item(pvh, struct pv_list);
/* FIXME check dev not name */ /* FIXME check dev not name */
if (!strcmp(dev_name(pv->pv.dev), pv_name)) if (!strcmp(dev_name(pvl->pv.dev), pv_name))
return pvh; return pvl;
} }
return NULL; return NULL;
} }
struct list *find_lv_in_vg(struct volume_group *vg, const char *lv_name) struct lv_list *find_lv_in_vg(struct volume_group *vg, const char *lv_name)
{ {
struct list *lvh; struct list *lvh;
struct lv_list *lvl;
const char *ptr; const char *ptr;
/* Use last component */ /* Use last component */
@ -259,21 +260,19 @@ struct list *find_lv_in_vg(struct volume_group *vg, const char *lv_name)
else else
ptr = lv_name; ptr = lv_name;
list_iterate(lvh, &vg->lvs) list_iterate(lvh, &vg->lvs) {
if (!strcmp(list_item(lvh, struct lv_list)->lv.name, ptr)) lvl = list_item(lvh, struct lv_list);
return lvh; if (!strcmp(lvl->lv.name, ptr))
return lvl;
}
return NULL; return NULL;
} }
struct logical_volume *find_lv(struct volume_group *vg, const char *lv_name) struct logical_volume *find_lv(struct volume_group *vg, const char *lv_name)
{ {
struct list *lvh; struct lv_list *lvl = find_lv_in_vg(vg, lv_name);
return lvl ? &lvl->lv : NULL;
if ((lvh = find_lv_in_vg(vg, lv_name)))
return &list_item(lvh, struct lv_list)->lv;
else
return NULL;
} }
struct physical_volume *find_pv(struct volume_group *vg, struct device *dev) struct physical_volume *find_pv(struct volume_group *vg, struct device *dev)

View File

@ -283,10 +283,10 @@ struct physical_volume *pv_find(struct volume_group *vg,
/* Find a PV within a given VG */ /* Find a PV within a given VG */
struct list *find_pv_in_vg(struct volume_group *vg, const char *pv_name); struct pv_list *find_pv_in_vg(struct volume_group *vg, const char *pv_name);
/* Find an LV within a given VG */ /* Find an LV within a given VG */
struct list *find_lv_in_vg(struct volume_group *vg, const char *lv_name); struct lv_list *find_lv_in_vg(struct volume_group *vg, const char *lv_name);
/* Return the VG that contains a given LV (based on path given in lv_name) */ /* Return the VG that contains a given LV (based on path given in lv_name) */
/* or environment var */ /* or environment var */

View File

@ -23,7 +23,8 @@ int lvcreate(int argc, char **argv)
uint32_t extents = 0; uint32_t extents = 0;
struct volume_group *vg; struct volume_group *vg;
struct logical_volume *lv; struct logical_volume *lv;
struct list *lvh, *pvh, *pvl; struct list *pvh;
struct pv_list *pvl;
char *lv_name = NULL; char *lv_name = NULL;
char *vg_name; char *vg_name;
char *st; char *st;
@ -95,6 +96,7 @@ int lvcreate(int argc, char **argv)
log_error("Please provide a volume group name"); log_error("Please provide a volume group name");
return EINVALID_CMD_LINE; return EINVALID_CMD_LINE;
} }
} else { } else {
/* Ensure lv_name doesn't contain a different VG! */ /* Ensure lv_name doesn't contain a different VG! */
if (lv_name && strchr(lv_name, '/')) { if (lv_name && strchr(lv_name, '/')) {
@ -121,7 +123,7 @@ int lvcreate(int argc, char **argv)
return ECMD_FAILED; return ECMD_FAILED;
} }
if (lv_name && (lvh = find_lv_in_vg(vg, lv_name))) { if (lv_name && find_lv_in_vg(vg, lv_name)) {
log_error("Logical volume %s already exists in " log_error("Logical volume %s already exists in "
"volume group %s", lv_name, vg_name); "volume group %s", lv_name, vg_name);
return ECMD_FAILED; return ECMD_FAILED;
@ -141,14 +143,16 @@ int lvcreate(int argc, char **argv)
vg->name); vg->name);
return EINVALID_CMD_LINE; return EINVALID_CMD_LINE;
} }
if (list_item(pvl, struct pv_list)->pv.pe_count ==
list_item(pvl, struct pv_list)->pv.pe_allocated) { if (pvl->pv.pe_count == pvl->pv.pe_allocated) {
log_error("No free extents on physical volume" log_error("No free extents on physical volume"
" %s", argv[opt]); " %s", argv[opt]);
continue; continue;
/* FIXME But check not null at end! */ /* FIXME But check not null at end! */
} }
list_add(pvh, pvl);
// FIXME: pv_lists should be duplicated.
list_add(pvh, &pvl->list);
} }
} else { } else {
/* Use full list from VG */ /* Use full list from VG */

View File

@ -30,7 +30,7 @@ int lvrename(int argc, char **argv)
struct volume_group *vg; struct volume_group *vg;
struct logical_volume *lv; struct logical_volume *lv;
struct list *lvh; struct lv_list *lvl;
if (argc != 2) { if (argc != 2) {
log_error("Old and new logical volume required"); log_error("Old and new logical volume required");
@ -90,19 +90,19 @@ int lvrename(int argc, char **argv)
return ECMD_FAILED; return ECMD_FAILED;
} }
if ((lvh = find_lv_in_vg(vg, lv_name_new))) { if (find_lv_in_vg(vg, lv_name_new)) {
log_error("Logical volume %s already exists in " log_error("Logical volume %s already exists in "
"volume group %s", lv_name_new, vg_name); "volume group %s", lv_name_new, vg_name);
return ECMD_FAILED; return ECMD_FAILED;
} }
if (!(lvh = find_lv_in_vg(vg, lv_name_old))) { if (!(lvl = find_lv_in_vg(vg, lv_name_old))) {
log_error("Existing logical volume %s not found in " log_error("Existing logical volume %s not found in "
"volume group %s", lv_name_old, vg_name); "volume group %s", lv_name_old, vg_name);
return ECMD_FAILED; return ECMD_FAILED;
} }
lv = &list_item(lvh, struct lv_list)->lv; lv = &lvl->lv;
if (!archive(lv->vg)) if (!archive(lv->vg))
return ECMD_FAILED; return ECMD_FAILED;

View File

@ -34,7 +34,9 @@ int lvresize(int argc, char **argv)
char *st; char *st;
char *dummy; char *dummy;
const char *cmd_name; const char *cmd_name;
struct list *lvh, *pvh, *pvl, *segh; struct list *pvh, *segh;
struct lv_list *lvl;
struct pv_list *pvl;
int opt = 0; int opt = 0;
enum { enum {
@ -107,13 +109,13 @@ int lvresize(int argc, char **argv)
} }
/* does LV exist? */ /* does LV exist? */
if (!(lvh = find_lv_in_vg(vg, lv_name))) { if (!(lvl = find_lv_in_vg(vg, lv_name))) {
log_error("Logical volume %s not found in volume group %s", log_error("Logical volume %s not found in volume group %s",
lv_name, vg_name); lv_name, vg_name);
return ECMD_FAILED; return ECMD_FAILED;
} }
lv = &list_item(lvh, struct lv_list)->lv; lv = &lvl->lv;
if (size) { if (size) {
/* No of 512-byte sectors */ /* No of 512-byte sectors */
@ -301,14 +303,16 @@ int lvresize(int argc, char **argv)
vg->name); vg->name);
return EINVALID_CMD_LINE; return EINVALID_CMD_LINE;
} }
if (list_item(pvl, struct pv_list)->pv.pe_count ==
list_item(pvl, struct pv_list)->pv.pe_allocated) { if (pvl->pv.pe_count == pvl->pv.pe_allocated) {
log_error("No free extents on physical volume" log_error("No free extents on physical volume"
" %s", argv[opt]); " %s", argv[opt]);
continue; continue;
/* FIXME Buy check not empty at end! */ /* FIXME Buy check not empty at end! */
} }
list_add(pvh, pvl);
// FIXME: pv_list's need to be copied.
list_add(pvh, &pvl->list);
} }
} }

View File

@ -82,7 +82,7 @@ int pvchange(int argc, char **argv)
int pvchange_single(struct physical_volume *pv) int pvchange_single(struct physical_volume *pv)
{ {
struct volume_group *vg = NULL; struct volume_group *vg = NULL;
struct list *pvh; struct pv_list *pvl;
const char *pv_name = dev_name(pv->dev); const char *pv_name = dev_name(pv->dev);
@ -97,12 +97,12 @@ int pvchange_single(struct physical_volume *pv)
log_error("Unable to find volume group of %s", pv_name); log_error("Unable to find volume group of %s", pv_name);
return 0; return 0;
} }
if (!(pvh = 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);
return 0; return 0;
} }
pv = &list_item(pvh, struct pv_list)->pv; pv = &pvl->pv;
if (!archive(vg)) if (!archive(vg))
return 0; return 0;
} }

View File

@ -64,10 +64,10 @@ int process_each_lv(int argc, char **argv,
int ret = 0; int ret = 0;
int vg_count = 0; int vg_count = 0;
struct list *lvh;
struct list *vgh, *vgs; struct list *vgh, *vgs;
struct volume_group *vg; struct volume_group *vg;
struct logical_volume *lv; struct logical_volume *lv;
struct lv_list *lvl;
char *vg_name; char *vg_name;
@ -92,7 +92,7 @@ int process_each_lv(int argc, char **argv,
continue; continue;
} }
if (!(lvh = find_lv_in_vg(vg, lv_name))) { if (!(lvl = find_lv_in_vg(vg, lv_name))) {
log_error("Can't find logical volume %s " log_error("Can't find logical volume %s "
"in volume group %s", "in volume group %s",
lv_name, vg_name); lv_name, vg_name);
@ -101,7 +101,7 @@ int process_each_lv(int argc, char **argv,
continue; continue;
} }
lv = &list_item(lvh, struct lv_list)->lv; lv = &lvl->lv;
if ((ret = process_single(lv)) > ret_max) if ((ret = process_single(lv)) > ret_max)
ret_max = ret; ret_max = ret;
@ -190,20 +190,18 @@ int process_each_pv(int argc, char **argv, struct volume_group *vg,
int ret_max = 0; int ret_max = 0;
int ret = 0; int ret = 0;
struct list *pvh; struct pv_list *pvl;
if (argc) { if (argc) {
log_verbose("Using physical volume(s) on command line"); log_verbose("Using physical volume(s) on command line");
for (; opt < argc; opt++) { for (; opt < argc; opt++) {
if (!(pvh = find_pv_in_vg(vg, argv[opt]))) { if (!(pvl = find_pv_in_vg(vg, argv[opt]))) {
log_error("Physical Volume %s not found in " log_error("Physical Volume %s not found in "
"Volume Group %s", argv[opt], "Volume Group %s", argv[opt],
vg->name); vg->name);
continue; continue;
} }
ret = process_single(vg, ret = process_single(vg, &pvl->pv);
&list_item(pvh,
struct pv_list)->pv);
if (ret > ret_max) if (ret > ret_max)
ret_max = ret; ret_max = ret;
} }

View File

@ -82,7 +82,7 @@ int vgreduce(int argc, char **argv)
/* Or take pv_name instead? */ /* Or take pv_name instead? */
static int vgreduce_single(struct volume_group *vg, struct physical_volume *pv) static int vgreduce_single(struct volume_group *vg, struct physical_volume *pv)
{ {
struct list *pvh; struct pv_list *pvl;
const char *name = dev_name(pv->dev); const char *name = dev_name(pv->dev);
if (pv->pe_allocated) { if (pv->pe_allocated) {
@ -102,13 +102,16 @@ static int vgreduce_single(struct volume_group *vg, struct physical_volume *pv)
return ECMD_FAILED; return ECMD_FAILED;
} }
pvh = find_pv_in_vg(vg, name); pvl = find_pv_in_vg(vg, name);
if (!archive(vg)) if (!archive(vg))
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);
list_del(pvh);
if (pvl)
list_del(&pvl->list);
*pv->vg_name = '\0'; *pv->vg_name = '\0';
vg->pv_count--; vg->pv_count--;
vg->free_count -= pv->pe_count - pv->pe_allocated; vg->free_count -= pv->pe_count - pv->pe_allocated;