diff options
Diffstat (limited to 'tools/toollib.c')
-rw-r--r-- | tools/toollib.c | 58 |
1 files changed, 33 insertions, 25 deletions
diff --git a/tools/toollib.c b/tools/toollib.c index 935d9f37..9b628ab0 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -57,30 +57,30 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv, char *lv_name = argv[opt]; /* does VG exist? */ - if (!(vg_name = extract_vgname(cmd->fid, lv_name))) { + if (!(vg_name = extract_vgname(cmd, lv_name))) { if (ret_max < ECMD_FAILED) ret_max = ECMD_FAILED; continue; } log_verbose("Finding volume group \"%s\"", vg_name); - if (!lock_vol(cmd, vg_name, lock_type)) { - log_error("Can't lock %s: skipping", vg_name); - continue; - } - if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vg_name))) { + if (!lock_vol(cmd, vg_name, lock_type)) { + log_error("Can't lock %s: skipping", vg_name); + continue; + } + if (!(vg = vg_read(cmd, vg_name))) { log_error("Volume group \"%s\" doesn't exist", vg_name); if (ret_max < ECMD_FAILED) ret_max = ECMD_FAILED; - unlock_vg(cmd, vg_name); + unlock_vg(cmd, vg_name); continue; } if (vg->status & EXPORTED_VG) { log_error("Volume group \"%s\" is exported", vg->name); - unlock_vg(cmd, vg_name); + unlock_vg(cmd, vg_name); return ECMD_FAILED; } @@ -102,26 +102,26 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv, } } else { log_verbose("Finding all logical volumes"); - if (!(vgs = cmd->fid->ops->get_vgs(cmd->fid))) { + if (!(vgs = get_vgs(cmd))) { log_error("No volume groups found"); return ECMD_FAILED; } list_iterate(vgh, vgs) { vg_name = list_item(vgh, struct name_list)->name; - if (!lock_vol(cmd, vg_name, lock_type)) { - log_error("Can't lock %s: skipping", vg_name); - continue; - } - if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vg_name))) { + if (!lock_vol(cmd, vg_name, lock_type)) { + log_error("Can't lock %s: skipping", vg_name); + continue; + } + if (!(vg = vg_read(cmd, vg_name))) { log_error("Volume group \"%s\" not found", vg_name); if (ret_max < ECMD_FAILED) ret_max = ECMD_FAILED; - unlock_vg(cmd, vg_name); + unlock_vg(cmd, vg_name); continue; } ret = process_each_lv_in_vg(cmd, vg, process_single); - unlock_vg(cmd, vg_name); + unlock_vg(cmd, vg_name); if (ret > ret_max) ret_max = ret; vg_count++; @@ -144,11 +144,19 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv, struct list *vgs; char *vg_name; + char *dev_dir = cmd->dev_dir; if (argc) { log_verbose("Using volume group(s) on command line"); for (; opt < argc; opt++) { vg_name = argv[opt]; + if (!strncmp(vg_name, dev_dir, strlen(dev_dir))) + vg_name += strlen(dev_dir); + if (strchr(vg_name, '/')) { + log_error("Invalid volume group name: %s", + vg_name); + continue; + } if (!lock_vol(cmd, vg_name, lock_type)) { log_error("Can't lock %s: skipping", vg_name); continue; @@ -159,7 +167,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv, } } else { log_verbose("Finding all volume groups"); - if (!(vgs = cmd->fid->ops->get_vgs(cmd->fid))) { + if (!(vgs = get_vgs(cmd))) { log_error("No volume groups found"); return ECMD_FAILED; } @@ -247,11 +255,11 @@ int is_valid_chars(char *n) return 1; } -char *extract_vgname(struct format_instance *fi, char *lv_name) +char *extract_vgname(struct cmd_context *cmd, char *lv_name) { char *vg_name = lv_name; char *st; - char *dev_dir = fi->cmd->dev_dir; + char *dev_dir = cmd->dev_dir; /* Path supplied? */ if (vg_name && strchr(vg_name, '/')) { @@ -267,7 +275,7 @@ char *extract_vgname(struct format_instance *fi, char *lv_name) return 0; } - vg_name = pool_strdup(fi->cmd->mem, vg_name); + vg_name = pool_strdup(cmd->mem, vg_name); if (!vg_name) { log_error("Allocation of vg_name failed"); return 0; @@ -277,7 +285,7 @@ char *extract_vgname(struct format_instance *fi, char *lv_name) return vg_name; } - if (!(vg_name = default_vgname(fi))) { + if (!(vg_name = default_vgname(cmd))) { if (lv_name) log_error("Path required for Logical Volume \"%s\"", lv_name); @@ -287,10 +295,10 @@ char *extract_vgname(struct format_instance *fi, char *lv_name) return vg_name; } -char *default_vgname(struct format_instance *fi) +char *default_vgname(struct cmd_context *cmd) { char *vg_path; - char *dev_dir = fi->cmd->dev_dir; + char *dev_dir = cmd->dev_dir; /* Take default VG from environment? */ vg_path = getenv("LVM_VG_NAME"); @@ -307,7 +315,7 @@ char *default_vgname(struct format_instance *fi) return 0; } - return pool_strdup(fi->cmd->mem, vg_path); + return pool_strdup(cmd->mem, vg_path); } struct list *create_pv_list(struct pool *mem, @@ -332,7 +340,7 @@ struct list *create_pv_list(struct pool *mem, return NULL; } - if (pvl->pv->pe_count == pvl->pv->pe_allocated) { + if (pvl->pv->pe_count == pvl->pv->pe_alloc_count) { log_err("No free extents on physical volume \"%s\"", argv[i]); continue; |