mirror of
git://sourceware.org/git/lvm2.git
synced 2025-03-10 16:58:47 +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:
parent
752e80cd5a
commit
e586401ecb
@ -232,25 +232,26 @@ struct physical_volume *pv_create(struct format_instance *fi,
|
||||
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 pv_list *pv;
|
||||
struct pv_list *pvl;
|
||||
|
||||
list_iterate(pvh, &vg->pvs) {
|
||||
pv = list_item(pvh, struct pv_list);
|
||||
pvl = list_item(pvh, struct pv_list);
|
||||
/* FIXME check dev not name */
|
||||
if (!strcmp(dev_name(pv->pv.dev), pv_name))
|
||||
return pvh;
|
||||
if (!strcmp(dev_name(pvl->pv.dev), pv_name))
|
||||
return pvl;
|
||||
}
|
||||
|
||||
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 lv_list *lvl;
|
||||
const char *ptr;
|
||||
|
||||
/* Use last component */
|
||||
@ -259,21 +260,19 @@ struct list *find_lv_in_vg(struct volume_group *vg, const char *lv_name)
|
||||
else
|
||||
ptr = lv_name;
|
||||
|
||||
list_iterate(lvh, &vg->lvs)
|
||||
if (!strcmp(list_item(lvh, struct lv_list)->lv.name, ptr))
|
||||
return lvh;
|
||||
list_iterate(lvh, &vg->lvs) {
|
||||
lvl = list_item(lvh, struct lv_list);
|
||||
if (!strcmp(lvl->lv.name, ptr))
|
||||
return lvl;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct logical_volume *find_lv(struct volume_group *vg, const char *lv_name)
|
||||
{
|
||||
struct list *lvh;
|
||||
|
||||
if ((lvh = find_lv_in_vg(vg, lv_name)))
|
||||
return &list_item(lvh, struct lv_list)->lv;
|
||||
else
|
||||
return NULL;
|
||||
struct lv_list *lvl = find_lv_in_vg(vg, lv_name);
|
||||
return lvl ? &lvl->lv : NULL;
|
||||
}
|
||||
|
||||
struct physical_volume *find_pv(struct volume_group *vg, struct device *dev)
|
||||
|
@ -283,10 +283,10 @@ struct physical_volume *pv_find(struct volume_group *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 */
|
||||
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) */
|
||||
/* or environment var */
|
||||
|
@ -23,7 +23,8 @@ int lvcreate(int argc, char **argv)
|
||||
uint32_t extents = 0;
|
||||
struct volume_group *vg;
|
||||
struct logical_volume *lv;
|
||||
struct list *lvh, *pvh, *pvl;
|
||||
struct list *pvh;
|
||||
struct pv_list *pvl;
|
||||
char *lv_name = NULL;
|
||||
char *vg_name;
|
||||
char *st;
|
||||
@ -95,6 +96,7 @@ int lvcreate(int argc, char **argv)
|
||||
log_error("Please provide a volume group name");
|
||||
return EINVALID_CMD_LINE;
|
||||
}
|
||||
|
||||
} else {
|
||||
/* Ensure lv_name doesn't contain a different VG! */
|
||||
if (lv_name && strchr(lv_name, '/')) {
|
||||
@ -121,7 +123,7 @@ int lvcreate(int argc, char **argv)
|
||||
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 "
|
||||
"volume group %s", lv_name, vg_name);
|
||||
return ECMD_FAILED;
|
||||
@ -141,14 +143,16 @@ int lvcreate(int argc, char **argv)
|
||||
vg->name);
|
||||
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"
|
||||
" %s", argv[opt]);
|
||||
continue;
|
||||
/* FIXME But check not null at end! */
|
||||
}
|
||||
list_add(pvh, pvl);
|
||||
|
||||
// FIXME: pv_lists should be duplicated.
|
||||
list_add(pvh, &pvl->list);
|
||||
}
|
||||
} else {
|
||||
/* Use full list from VG */
|
||||
|
@ -30,7 +30,7 @@ int lvrename(int argc, char **argv)
|
||||
|
||||
struct volume_group *vg;
|
||||
struct logical_volume *lv;
|
||||
struct list *lvh;
|
||||
struct lv_list *lvl;
|
||||
|
||||
if (argc != 2) {
|
||||
log_error("Old and new logical volume required");
|
||||
@ -90,19 +90,19 @@ int lvrename(int argc, char **argv)
|
||||
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 "
|
||||
"volume group %s", lv_name_new, vg_name);
|
||||
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 "
|
||||
"volume group %s", lv_name_old, vg_name);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
lv = &list_item(lvh, struct lv_list)->lv;
|
||||
lv = &lvl->lv;
|
||||
|
||||
if (!archive(lv->vg))
|
||||
return ECMD_FAILED;
|
||||
|
@ -34,7 +34,9 @@ int lvresize(int argc, char **argv)
|
||||
char *st;
|
||||
char *dummy;
|
||||
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;
|
||||
|
||||
enum {
|
||||
@ -107,13 +109,13 @@ int lvresize(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* 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",
|
||||
lv_name, vg_name);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
lv = &list_item(lvh, struct lv_list)->lv;
|
||||
lv = &lvl->lv;
|
||||
|
||||
if (size) {
|
||||
/* No of 512-byte sectors */
|
||||
@ -301,14 +303,16 @@ int lvresize(int argc, char **argv)
|
||||
vg->name);
|
||||
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"
|
||||
" %s", argv[opt]);
|
||||
continue;
|
||||
/* FIXME Buy check not empty at end! */
|
||||
}
|
||||
list_add(pvh, pvl);
|
||||
|
||||
// FIXME: pv_list's need to be copied.
|
||||
list_add(pvh, &pvl->list);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ int pvchange(int argc, char **argv)
|
||||
int pvchange_single(struct physical_volume *pv)
|
||||
{
|
||||
struct volume_group *vg = NULL;
|
||||
struct list *pvh;
|
||||
struct pv_list *pvl;
|
||||
|
||||
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);
|
||||
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",
|
||||
pv_name, vg->name);
|
||||
return 0;
|
||||
}
|
||||
pv = &list_item(pvh, struct pv_list)->pv;
|
||||
pv = &pvl->pv;
|
||||
if (!archive(vg))
|
||||
return 0;
|
||||
}
|
||||
|
@ -64,10 +64,10 @@ int process_each_lv(int argc, char **argv,
|
||||
int ret = 0;
|
||||
int vg_count = 0;
|
||||
|
||||
struct list *lvh;
|
||||
struct list *vgh, *vgs;
|
||||
struct volume_group *vg;
|
||||
struct logical_volume *lv;
|
||||
struct lv_list *lvl;
|
||||
|
||||
char *vg_name;
|
||||
|
||||
@ -92,7 +92,7 @@ int process_each_lv(int argc, char **argv,
|
||||
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 "
|
||||
"in volume group %s",
|
||||
lv_name, vg_name);
|
||||
@ -101,7 +101,7 @@ int process_each_lv(int argc, char **argv,
|
||||
continue;
|
||||
}
|
||||
|
||||
lv = &list_item(lvh, struct lv_list)->lv;
|
||||
lv = &lvl->lv;
|
||||
|
||||
if ((ret = process_single(lv)) > ret_max)
|
||||
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 = 0;
|
||||
|
||||
struct list *pvh;
|
||||
struct pv_list *pvl;
|
||||
|
||||
if (argc) {
|
||||
log_verbose("Using physical volume(s) on command line");
|
||||
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 "
|
||||
"Volume Group %s", argv[opt],
|
||||
vg->name);
|
||||
continue;
|
||||
}
|
||||
ret = process_single(vg,
|
||||
&list_item(pvh,
|
||||
struct pv_list)->pv);
|
||||
ret = process_single(vg, &pvl->pv);
|
||||
if (ret > ret_max)
|
||||
ret_max = ret;
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ int vgreduce(int argc, char **argv)
|
||||
/* Or take pv_name instead? */
|
||||
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);
|
||||
|
||||
if (pv->pe_allocated) {
|
||||
@ -102,13 +102,16 @@ static int vgreduce_single(struct volume_group *vg, struct physical_volume *pv)
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
pvh = find_pv_in_vg(vg, name);
|
||||
pvl = find_pv_in_vg(vg, name);
|
||||
|
||||
if (!archive(vg))
|
||||
return ECMD_FAILED;
|
||||
|
||||
log_verbose("Removing %s from volume group %s", name, vg->name);
|
||||
list_del(pvh);
|
||||
|
||||
if (pvl)
|
||||
list_del(&pvl->list);
|
||||
|
||||
*pv->vg_name = '\0';
|
||||
vg->pv_count--;
|
||||
vg->free_count -= pv->pe_count - pv->pe_allocated;
|
||||
|
Loading…
x
Reference in New Issue
Block a user