summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAlasdair Kergon <agk@redhat.com>2002-02-11 20:50:53 +0000
committerAlasdair Kergon <agk@redhat.com>2002-02-11 20:50:53 +0000
commit60274aba6ec2c6a6a0e1e2656d97a574b79f5775 (patch)
tree83945d99849698a91fbbbc7abcfdceee2538cf49 /tools
parent8d6a8717bb59c5ff36150e8e43a9138af9ac3f63 (diff)
downloadlvm2-60274aba6ec2c6a6a0e1e2656d97a574b79f5775.tar.gz
lvm2-60274aba6ec2c6a6a0e1e2656d97a574b79f5775.tar.xz
lvm2-60274aba6ec2c6a6a0e1e2656d97a574b79f5775.zip
Preparation for an LVM2 liblvm - pass cmd_context into each tool and
link some globals that the tools need into that structure.
Diffstat (limited to 'tools')
-rw-r--r--tools/archive.c19
-rw-r--r--tools/archive.h6
-rw-r--r--tools/args.h2
-rw-r--r--tools/errors.h30
-rw-r--r--tools/lvchange.c88
-rw-r--r--tools/lvcreate.c70
-rw-r--r--tools/lvdisplay.c31
-rw-r--r--tools/lvextend.c4
-rw-r--r--tools/lvm.c77
-rw-r--r--tools/lvmchange.c2
-rw-r--r--tools/lvmdiskscan.c20
-rw-r--r--tools/lvreduce.c4
-rw-r--r--tools/lvremove.c12
-rw-r--r--tools/lvrename.c14
-rw-r--r--tools/lvresize.c40
-rw-r--r--tools/lvscan.c12
-rw-r--r--tools/pvchange.c28
-rw-r--r--tools/pvcreate.c36
-rw-r--r--tools/pvdisplay.c22
-rw-r--r--tools/pvscan.c28
-rw-r--r--tools/stub.h14
-rw-r--r--tools/toollib.c52
-rw-r--r--tools/toollib.h23
-rw-r--r--tools/tools.h59
-rw-r--r--tools/vgcfgbackup.c14
-rw-r--r--tools/vgcfgrestore.c15
-rw-r--r--tools/vgchange.c58
-rw-r--r--tools/vgck.c10
-rw-r--r--tools/vgcreate.c18
-rw-r--r--tools/vgdisplay.c28
-rw-r--r--tools/vgexport.c16
-rw-r--r--tools/vgextend.c8
-rw-r--r--tools/vgimport.c16
-rw-r--r--tools/vgmerge.c16
-rw-r--r--tools/vgreduce.c18
-rw-r--r--tools/vgremove.c12
-rw-r--r--tools/vgrename.c12
-rw-r--r--tools/vgscan.c12
38 files changed, 447 insertions, 499 deletions
diff --git a/tools/archive.c b/tools/archive.c
index 451c17d5..5a44f6dd 100644
--- a/tools/archive.c
+++ b/tools/archive.c
@@ -113,9 +113,9 @@ int archive(struct volume_group *vg)
return 1;
}
-int archive_display(const char *vg_name)
+int archive_display(struct cmd_context *cmd, const char *vg_name)
{
- return archive_list(fid->cmd, the_um, _archive_params.dir, vg_name);
+ return archive_list(cmd, cmd->um, _archive_params.dir, vg_name);
}
@@ -176,7 +176,7 @@ static int __backup(struct volume_group *vg)
log_verbose("Creating volume group backup \"%s\"", name);
- if (!(tf = text_format_create(vg->cmd, name, the_um, desc))) {
+ if (!(tf = text_format_create(vg->cmd, name, vg->cmd->um, desc))) {
stack;
return 0;
}
@@ -232,7 +232,8 @@ static struct volume_group *_read_vg(struct cmd_context *cmd,
struct volume_group *vg;
struct format_instance *tf;
- if (!(tf = text_format_create(cmd, file, the_um, cmd->cmd_line))) {
+ if (!(tf = text_format_create(cmd, file, cmd->um,
+ cmd->cmd_line))) {
log_error("Couldn't create text format object.");
return NULL;
}
@@ -244,14 +245,14 @@ static struct volume_group *_read_vg(struct cmd_context *cmd,
return vg;
}
-int backup_restore_from_file(const char *vg_name, const char *file)
+int backup_restore_from_file(struct cmd_context *cmd, const char *vg_name, const char *file)
{
struct volume_group *vg;
/*
* Read in the volume group.
*/
- if (!(vg = _read_vg(fid->cmd, vg_name, file))) {
+ if (!(vg = _read_vg(cmd, vg_name, file))) {
stack;
return 0;
}
@@ -267,7 +268,7 @@ int backup_restore_from_file(const char *vg_name, const char *file)
/*
* Write the vg.
*/
- if (!fid->ops->vg_write(fid, vg)) {
+ if (!cmd->fid->ops->vg_write(cmd->fid, vg)) {
stack;
return 0;
}
@@ -275,7 +276,7 @@ int backup_restore_from_file(const char *vg_name, const char *file)
return 1;
}
-int backup_restore(const char *vg_name)
+int backup_restore(struct cmd_context *cmd, const char *vg_name)
{
char path[PATH_MAX];
@@ -285,5 +286,5 @@ int backup_restore(const char *vg_name)
return 0;
}
- return backup_restore_from_file(vg_name, path);
+ return backup_restore_from_file(cmd, vg_name, path);
}
diff --git a/tools/archive.h b/tools/archive.h
index e10eca76..b910cc08 100644
--- a/tools/archive.h
+++ b/tools/archive.h
@@ -33,7 +33,7 @@ void archive_exit(void);
void archive_enable(int flag);
int archive(struct volume_group *vg);
-int archive_display(const char *vg_name);
+int archive_display(struct cmd_context *cmd, const char *vg_name);
int backup_init(const char *dir);
void backup_exit(void);
@@ -42,7 +42,7 @@ void backup_enable(int flag);
int backup(struct volume_group *vg);
int backup_remove(const char *vg_name);
-int backup_restore_from_file(const char *vg_name, const char *file);
-int backup_restore(const char *vg_name);
+int backup_restore_from_file(struct cmd_context *cmd, const char *vg_name, const char *file);
+int backup_restore(struct cmd_context *cmd, const char *vg_name);
#endif
diff --git a/tools/args.h b/tools/args.h
index 67f98d19..a294166a 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2001 Sistina Software (UK) Limited.
*
- * This file is released under the GPL.
+ * This file is released under the LGPL.
*/
/*
diff --git a/tools/errors.h b/tools/errors.h
deleted file mode 100644
index ad738fe5..00000000
--- a/tools/errors.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2001 Sistina Software
- *
- * LVM is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * LVM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with LVM; see the file COPYING. If not, write to
- * the Free Software Foundation, 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- */
-
-#ifndef _LVM_ERRORS_H
-#define _LVM_ERRORS_H
-
-#define EINVALID_CMD_LINE 1
-#define ENO_SUCH_CMD 3
-#define ECMD_PROCESSED 4
-#define ECMD_FAILED 5
-
-#endif
-
diff --git a/tools/lvchange.c b/tools/lvchange.c
index 3272a2eb..aaea3bea 100644
--- a/tools/lvchange.c
+++ b/tools/lvchange.c
@@ -20,18 +20,18 @@
#include "tools.h"
-static int lvchange_single(struct logical_volume *lv);
-static int lvchange_permission(struct logical_volume *lv);
-static int lvchange_availability(struct logical_volume *lv);
-static int lvchange_contiguous(struct logical_volume *lv);
-static int lvchange_readahead(struct logical_volume *lv);
-static int lvchange_persistent(struct logical_volume *lv);
-
-int lvchange(int argc, char **argv)
+static int lvchange_single(struct cmd_context *cmd, struct logical_volume *lv);
+static int lvchange_permission(struct cmd_context *cmd, struct logical_volume *lv);
+static int lvchange_availability(struct cmd_context *cmd, struct logical_volume *lv);
+static int lvchange_contiguous(struct cmd_context *cmd, struct logical_volume *lv);
+static int lvchange_readahead(struct cmd_context *cmd, struct logical_volume *lv);
+static int lvchange_persistent(struct cmd_context *cmd, struct logical_volume *lv);
+
+int lvchange(struct cmd_context *cmd, int argc, char **argv)
{
- if (!arg_count(available_ARG) && !arg_count(contiguous_ARG)
- && !arg_count(permission_ARG) && !arg_count(readahead_ARG)
- && !arg_count(minor_ARG) && !arg_count(persistent_ARG)) {
+ if (!arg_count(cmd,available_ARG) && !arg_count(cmd,contiguous_ARG)
+ && !arg_count(cmd,permission_ARG) && !arg_count(cmd,readahead_ARG)
+ && !arg_count(cmd,minor_ARG) && !arg_count(cmd,persistent_ARG)) {
log_error("One or more of -a, -C, -m, -M, -p or -r required");
return EINVALID_CMD_LINE;
}
@@ -41,22 +41,22 @@ int lvchange(int argc, char **argv)
return EINVALID_CMD_LINE;
}
- if (arg_count(minor_ARG) && argc != 1) {
+ if (arg_count(cmd,minor_ARG) && argc != 1) {
log_error("Only give one logical volume when specifying minor");
return EINVALID_CMD_LINE;
}
- return process_each_lv(argc, argv, &lvchange_single);
+ return process_each_lv(cmd, argc, argv, &lvchange_single);
}
-static int lvchange_single(struct logical_volume *lv)
+static int lvchange_single(struct cmd_context *cmd, struct logical_volume *lv)
{
int doit = 0;
int archived = 0;
if (!(lv->vg->status & LVM_WRITE) &&
- (arg_count(contiguous_ARG) || arg_count(permission_ARG) ||
- arg_count(readahead_ARG) || arg_count(persistent_ARG))) {
+ (arg_count(cmd,contiguous_ARG) || arg_count(cmd,permission_ARG) ||
+ arg_count(cmd,readahead_ARG) || arg_count(cmd,persistent_ARG))) {
log_error("Only -a permitted with read-only volume "
"group \"%s\"", lv->vg->name);
return EINVALID_CMD_LINE;
@@ -75,53 +75,53 @@ static int lvchange_single(struct logical_volume *lv)
}
/* access permission change */
- if (arg_count(permission_ARG)) {
+ if (arg_count(cmd,permission_ARG)) {
if (!archive(lv->vg))
return ECMD_FAILED;
archived = 1;
- doit += lvchange_permission(lv);
+ doit += lvchange_permission(cmd, lv);
}
/* allocation policy change */
- if (arg_count(contiguous_ARG)) {
+ if (arg_count(cmd,contiguous_ARG)) {
if (!archived && !archive(lv->vg))
return ECMD_FAILED;
archived = 1;
- doit += lvchange_contiguous(lv);
+ doit += lvchange_contiguous(cmd, lv);
}
/* read ahead sector change */
- if (arg_count(readahead_ARG)) {
+ if (arg_count(cmd,readahead_ARG)) {
if (!archived && !archive(lv->vg))
return ECMD_FAILED;
archived = 1;
- doit += lvchange_readahead(lv);
+ doit += lvchange_readahead(cmd, lv);
}
/* read ahead sector change */
- if (arg_count(persistent_ARG)) {
+ if (arg_count(cmd,persistent_ARG)) {
if (!archived && !archive(lv->vg))
return ECMD_FAILED;
archived = 1;
- doit += lvchange_persistent(lv);
+ doit += lvchange_persistent(cmd, lv);
}
if (doit)
log_print("Logical volume \"%s\" changed", lv->name);
/* availability change */
- if (arg_count(available_ARG))
- if (!lvchange_availability(lv))
+ if (arg_count(cmd,available_ARG))
+ if (!lvchange_availability(cmd, lv))
return ECMD_FAILED;
return 0;
}
-static int lvchange_permission(struct logical_volume *lv)
+static int lvchange_permission(struct cmd_context *cmd, struct logical_volume *lv)
{
int lv_access;
- lv_access = arg_int_value(permission_ARG, 0);
+ lv_access = arg_int_value(cmd,permission_ARG, 0);
if ((lv_access & LVM_WRITE) && (lv->status & LVM_WRITE)) {
log_error("Logical volume \"%s\" is already writable", lv->name);
@@ -143,7 +143,7 @@ static int lvchange_permission(struct logical_volume *lv)
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
- if (!fid->ops->vg_write(fid, lv->vg))
+ if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg))
return 0;
backup(lv->vg);
@@ -155,16 +155,16 @@ static int lvchange_permission(struct logical_volume *lv)
return 1;
}
-static int lvchange_availability(struct logical_volume *lv)
+static int lvchange_availability(struct cmd_context *cmd, struct logical_volume *lv)
{
int activate = 0;
int active;
- if (strcmp(arg_str_value(available_ARG, "n"), "n"))
+ if (strcmp(arg_str_value(cmd,available_ARG, "n"), "n"))
activate = 1;
- if (arg_count(minor_ARG)) {
- lv->minor = arg_int_value(minor_ARG, -1);
+ if (arg_count(cmd,minor_ARG)) {
+ lv->minor = arg_int_value(cmd,minor_ARG, -1);
}
if ((active = lv_active(lv)) < 0) {
@@ -204,11 +204,11 @@ static int lvchange_availability(struct logical_volume *lv)
return 1;
}
-static int lvchange_contiguous(struct logical_volume *lv)
+static int lvchange_contiguous(struct cmd_context *cmd, struct logical_volume *lv)
{
int lv_allocation = 0;
- if (strcmp(arg_str_value(contiguous_ARG, "n"), "n"))
+ if (strcmp(arg_str_value(cmd,contiguous_ARG, "n"), "n"))
lv_allocation |= ALLOC_CONTIGUOUS;
if ((lv_allocation & ALLOC_CONTIGUOUS) &&
@@ -244,7 +244,7 @@ static int lvchange_contiguous(struct logical_volume *lv)
log_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
- if (!fid->ops->vg_write(fid, lv->vg))
+ if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg))
return 0;
backup(lv->vg);
@@ -252,11 +252,11 @@ static int lvchange_contiguous(struct logical_volume *lv)
return 1;
}
-static int lvchange_readahead(struct logical_volume *lv)
+static int lvchange_readahead(struct cmd_context *cmd, struct logical_volume *lv)
{
int read_ahead = 0;
- read_ahead = arg_int_value(readahead_ARG, 0);
+ read_ahead = arg_int_value(cmd,readahead_ARG, 0);
/******* FIXME Ranges?
if (read_ahead < LVM_MIN_READ_AHEAD || read_ahead > LVM_MAX_READ_AHEAD) {
@@ -276,7 +276,7 @@ static int lvchange_readahead(struct logical_volume *lv)
log_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
- if (!fid->ops->vg_write(fid, lv->vg))
+ if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg))
return 0;
backup(lv->vg);
@@ -284,9 +284,9 @@ static int lvchange_readahead(struct logical_volume *lv)
return 1;
}
-static int lvchange_persistent(struct logical_volume *lv)
+static int lvchange_persistent(struct cmd_context *cmd, struct logical_volume *lv)
{
- if (!strcmp(arg_str_value(persistent_ARG, "n"), "n")) {
+ if (!strcmp(arg_str_value(cmd,persistent_ARG, "n"), "n")) {
if (!(lv->status & FIXED_MINOR)) {
log_error("Minor number is already not persistent "
"for \"%s\"", lv->name);
@@ -300,19 +300,19 @@ static int lvchange_persistent(struct logical_volume *lv)
log_error("Cannot change minor number when active");
return 0;
}
- if (!arg_count(minor_ARG)) {
+ if (!arg_count(cmd,minor_ARG)) {
log_error("Minor number must be specified with -My");
return 0;
}
lv->status |= FIXED_MINOR;
- lv->minor = arg_int_value(minor_ARG, -1);
+ lv->minor = arg_int_value(cmd,minor_ARG, -1);
log_verbose("Setting persistent minor number to %d for \"%s\"",
lv->minor, lv->name);
}
log_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
- if (!fid->ops->vg_write(fid, lv->vg))
+ if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg))
return 0;
backup(lv->vg);
diff --git a/tools/lvcreate.c b/tools/lvcreate.c
index 14608d48..dc86fb0c 100644
--- a/tools/lvcreate.c
+++ b/tools/lvcreate.c
@@ -9,7 +9,7 @@
#include <fcntl.h>
-int lvcreate(int argc, char **argv)
+int lvcreate(struct cmd_context *cmd, int argc, char **argv)
{
int zero;
uint32_t read_ahead = 0;
@@ -28,38 +28,38 @@ int lvcreate(int argc, char **argv)
char *vg_name;
char *st;
- if (arg_count(snapshot_ARG) || arg_count(chunksize_ARG)) {
+ if (arg_count(cmd,snapshot_ARG) || arg_count(cmd,chunksize_ARG)) {
log_error("Snapshots are not yet supported in LVM2.");
return EINVALID_CMD_LINE;
}
/* mutually exclusive */
- if ((arg_count(zero_ARG) && arg_count(snapshot_ARG)) ||
- (arg_count(extents_ARG) && arg_count(size_ARG))) {
+ if ((arg_count(cmd,zero_ARG) && arg_count(cmd,snapshot_ARG)) ||
+ (arg_count(cmd,extents_ARG) && arg_count(cmd,size_ARG))) {
log_error("Invalid combination of arguments");
return EINVALID_CMD_LINE;
}
- if (arg_count(size_ARG) + arg_count(extents_ARG) == 0) {
+ if (arg_count(cmd,size_ARG) + arg_count(cmd,extents_ARG) == 0) {
log_error("Please indicate size using option -l or -L");
return EINVALID_CMD_LINE;
}
- if (strcmp(arg_str_value(contiguous_ARG, "n"), "n"))
+ if (strcmp(arg_str_value(cmd,contiguous_ARG, "n"), "n"))
status |= ALLOC_CONTIGUOUS;
else
status |= ALLOC_SIMPLE;
- zero = strcmp(arg_str_value(zero_ARG, "y"), "n");
+ zero = strcmp(arg_str_value(cmd,zero_ARG, "y"), "n");
- if (arg_count(stripes_ARG)) {
- stripes = arg_int_value(stripes_ARG, 1);
+ if (arg_count(cmd,stripes_ARG)) {
+ stripes = arg_int_value(cmd,stripes_ARG, 1);
if (stripes == 1)
log_print("Redundant stripes argument: default is 1");
}
- if (arg_count(stripesize_ARG))
- stripesize = 2 * arg_int_value(stripesize_ARG, 0);
+ if (arg_count(cmd,stripesize_ARG))
+ stripesize = 2 * arg_int_value(cmd,stripesize_ARG, 0);
if (stripes == 1 && stripesize) {
log_print("Ignoring stripesize argument with single stripe");
@@ -71,27 +71,27 @@ int lvcreate(int argc, char **argv)
log_print("Using default stripesize %dKB", stripesize / 2);
}
- if (arg_count(permission_ARG))
- status |= arg_int_value(permission_ARG, 0);
+ if (arg_count(cmd,permission_ARG))
+ status |= arg_int_value(cmd,permission_ARG, 0);
else
status |= LVM_READ | LVM_WRITE;
- if (arg_count(readahead_ARG))
- read_ahead = arg_int_value(readahead_ARG, 0);
+ if (arg_count(cmd,readahead_ARG))
+ read_ahead = arg_int_value(cmd,readahead_ARG, 0);
- if (arg_count(extents_ARG))
- extents = arg_int_value(extents_ARG, 0);
+ if (arg_count(cmd,extents_ARG))
+ extents = arg_int_value(cmd,extents_ARG, 0);
/* Size returned in kilobyte units; held in sectors */
- if (arg_count(size_ARG))
- size = arg_int_value(size_ARG, 0);
+ if (arg_count(cmd,size_ARG))
+ size = arg_int_value(cmd,size_ARG, 0);
- if (arg_count(name_ARG))
- lv_name = arg_value(name_ARG);
+ if (arg_count(cmd,name_ARG))
+ lv_name = arg_value(cmd,name_ARG);
/* If VG not on command line, try -n arg and then environment */
if (!argc) {
- if (!(vg_name = extract_vgname(fid, lv_name))) {
+ if (!(vg_name = extract_vgname(cmd->fid, lv_name))) {
log_error("Please provide a volume group name");
return EINVALID_CMD_LINE;
}
@@ -99,7 +99,7 @@ int lvcreate(int argc, char **argv)
} else {
/* Ensure lv_name doesn't contain a different VG! */
if (lv_name && strchr(lv_name, '/')) {
- if (!(vg_name = extract_vgname(fid, lv_name)))
+ if (!(vg_name = extract_vgname(cmd->fid, lv_name)))
return EINVALID_CMD_LINE;
if (strcmp(vg_name, argv[0])) {
log_error("Inconsistent volume group names "
@@ -124,7 +124,7 @@ int lvcreate(int argc, char **argv)
return ECMD_FAILED;
}
- if (!(vg = fid->ops->vg_read(fid, vg_name))) {
+ if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vg_name))) {
log_error("Volume group \"%s\" doesn't exist", vg_name);
goto error;
}
@@ -150,7 +150,7 @@ int lvcreate(int argc, char **argv)
pvh = &vg->pvs;
else {
- if (!(pvh = create_pv_list(fid->cmd->mem, vg,
+ if (!(pvh = create_pv_list(cmd->mem, vg,
argc - opt, argv + opt))) {
stack;
goto error;
@@ -209,27 +209,27 @@ int lvcreate(int argc, char **argv)
if (!archive(vg))
goto error;
- if (!(lv = lv_create(fid, lv_name, status,
+ if (!(lv = lv_create(cmd->fid, lv_name, status,
stripes, stripesize, extents,
vg, pvh)))
goto error;
- if (arg_count(readahead_ARG)) {
+ if (arg_count(cmd,readahead_ARG)) {
log_verbose("Setting read ahead sectors");
lv->read_ahead = read_ahead;
}
- if (arg_count(minor_ARG)) {
+ if (arg_count(cmd,minor_ARG)) {
lv->status |= FIXED_MINOR;
- lv->minor = arg_int_value(minor_ARG, -1);
+ lv->minor = arg_int_value(cmd,minor_ARG, -1);
log_verbose("Setting minor number to %d", lv->minor);
}
- if (arg_count(persistent_ARG)) {
- if (!strcmp(arg_str_value(persistent_ARG, "n"), "n"))
+ if (arg_count(cmd,persistent_ARG)) {
+ if (!strcmp(arg_str_value(cmd,persistent_ARG, "n"), "n"))
lv->status &= ~FIXED_MINOR;
else
- if (!arg_count(minor_ARG)) {
+ if (!arg_count(cmd,minor_ARG)) {
log_error("Please specify minor number with "
"--minor when using -My");
goto error;
@@ -238,7 +238,7 @@ int lvcreate(int argc, char **argv)
}
/* store vg on disk(s) */
- if (!fid->ops->vg_write(fid, vg))
+ if (!cmd->fid->ops->vg_write(cmd->fid, vg))
goto error;
backup(vg);
@@ -252,12 +252,12 @@ int lvcreate(int argc, char **argv)
struct device *dev;
char *name;
- if (!(name = pool_alloc(fid->cmd->mem, PATH_MAX))) {
+ if (!(name = pool_alloc(cmd->mem, PATH_MAX))) {
log_error("Name allocation failed - device not zeroed");
goto error;
}
- if (lvm_snprintf(name, PATH_MAX, "%s%s/%s", fid->cmd->dev_dir,
+ if (lvm_snprintf(name, PATH_MAX, "%s%s/%s", cmd->dev_dir,
lv->vg->name, lv->name) < 0) {
log_error("Name too long - device not zeroed (%s)",
lv->name);
diff --git a/tools/lvdisplay.c b/tools/lvdisplay.c
index 1ad1db0b..d7063f09 100644
--- a/tools/lvdisplay.c
+++ b/tools/lvdisplay.c
@@ -20,27 +20,28 @@
#include "tools.h"
-int lvdisplay(int argc, char **argv)
+int lvdisplay_single(struct cmd_context *cmd, struct logical_volume *lv)
{
- /* FIXME Allow VG args via process_each */
-
- if (arg_count(colon_ARG) && arg_count(verbose_ARG)) {
- log_error("Options -v and -c are incompatible");
- return EINVALID_CMD_LINE;
+ if (arg_count(cmd,colon_ARG))
+ lvdisplay_colons(lv);
+ else {
+ lvdisplay_full(cmd, lv);
+ if (arg_count(cmd,maps_ARG))
+ lvdisplay_segments(lv);
}
- return process_each_lv(argc, argv, &lvdisplay_single);
+ return 0;
}
-int lvdisplay_single(struct logical_volume *lv)
+int lvdisplay(struct cmd_context *cmd, int argc, char **argv)
{
- if (arg_count(colon_ARG))
- lvdisplay_colons(lv);
- else {
- lvdisplay_full(lv);
- if (arg_count(maps_ARG))
- lvdisplay_segments(lv);
+ /* FIXME Allow VG args via process_each */
+
+ if (arg_count(cmd,colon_ARG) && arg_count(cmd,verbose_ARG)) {
+ log_error("Options -v and -c are incompatible");
+ return EINVALID_CMD_LINE;
}
- return 0;
+ return process_each_lv(cmd, argc, argv, &lvdisplay_single);
}
+
diff --git a/tools/lvextend.c b/tools/lvextend.c
index 48e03665..1425ce9b 100644
--- a/tools/lvextend.c
+++ b/tools/lvextend.c
@@ -20,7 +20,7 @@
#include "tools.h"
-int lvextend(int argc, char **argv)
+int lvextend(struct cmd_context *cmd, int argc, char **argv)
{
- return lvresize(argc, argv);
+ return lvresize(cmd, argc, argv);
}
diff --git a/tools/lvm.c b/tools/lvm.c
index a77db806..18bcb40b 100644
--- a/tools/lvm.c
+++ b/tools/lvm.c
@@ -31,7 +31,9 @@
#endif
#endif
-/* define exported table of valid switches */
+/*
+ * Exported table of valid switches
+ */
struct arg the_args[ARG_COUNT + 1] = {
#define arg(a, b, c, d) {b, "--" c, d, 0, NULL},
@@ -40,19 +42,10 @@ struct arg the_args[ARG_COUNT + 1] = {
};
+
static int _array_size;
static int _num_commands;
static struct command *_commands;
-
-/* Exported LVM1 disk format */
-struct format_instance *fid;
-
-/* Map of uuid -> device */
-struct uuid_map *the_um;
-
-/* Export command being processed */
-struct command *the_command;
-
struct cmd_context *cmd;
/* Whether or not to dump persistent filter state */
@@ -558,14 +551,14 @@ static int merge_synonym(int oldarg, int newarg)
{
struct arg *old, *new;
- if (arg_count(oldarg) && arg_count(newarg)) {
+ if (arg_count(cmd,oldarg) && arg_count(cmd,newarg)) {
log_error("%s and %s are synonyms. Please only supply one.",
the_args[oldarg].long_arg,
the_args[newarg].long_arg);
return 0;
}
- if (!arg_count(oldarg))
+ if (!arg_count(cmd,oldarg))
return 1;
old = the_args + oldarg;
@@ -579,7 +572,7 @@ static int merge_synonym(int oldarg, int newarg)
return 1;
}
-int version(int argc, char **argv)
+int version(struct cmd_context *cmd, int argc, char **argv)
{
char version[80];
@@ -596,39 +589,39 @@ static int process_common_commands(struct command *com)
{
_current_settings = _default_settings;
- if (arg_count(suspend_ARG))
+ if (arg_count(cmd,suspend_ARG))
kill(getpid(), SIGSTOP);
- if (arg_count(debug_ARG))
+ if (arg_count(cmd,debug_ARG))
_current_settings.debug = _LOG_FATAL +
- (arg_count(debug_ARG) - 1);
+ (arg_count(cmd,debug_ARG) - 1);
- if (arg_count(verbose_ARG))
- _current_settings.verbose = arg_count(verbose_ARG);
+ if (arg_count(cmd,verbose_ARG))
+ _current_settings.verbose = arg_count(cmd,verbose_ARG);
- if (arg_count(quiet_ARG)) {
+ if (arg_count(cmd,quiet_ARG)) {
_current_settings.debug = 0;
_current_settings.verbose = 0;
}
- if (arg_count(test_ARG))
- _current_settings.test = arg_count(test_ARG);
+ if (arg_count(cmd,test_ARG))
+ _current_settings.test = arg_count(cmd,test_ARG);
- if (arg_count(help_ARG)) {
+ if (arg_count(cmd,help_ARG)) {
usage(com->name);
return ECMD_PROCESSED;
}
- if (arg_count(version_ARG)) {
- return version(0, (char **)NULL);
+ if (arg_count(cmd,version_ARG)) {
+ return version(cmd, 0, (char **)NULL);
}
- if (arg_count(autobackup_ARG)) {
+ if (arg_count(cmd,autobackup_ARG)) {
_current_settings.archive = 1;
_current_settings.backup = 1;
}
- if (arg_count(partial_ARG)) {
+ if (arg_count(cmd,partial_ARG)) {
init_partial(1);
log_print("Partial mode. Incomplete volume groups will "
"be activated read-only.");
@@ -646,7 +639,7 @@ static int process_common_commands(struct command *com)
return 0;
}
-int help(int argc, char **argv)
+int help(struct cmd_context *cmd, int argc, char **argv)
{
if (!argc)
display_help();
@@ -725,17 +718,17 @@ static int run_command(int argc, char **argv)
if (!(cmd->cmd_line = _copy_command_line(cmd->mem, argc, argv)))
return ECMD_FAILED;
- if (!(the_command = find_command(argv[0])))
+ if (!(cmd->command = find_command(argv[0])))
return ENO_SUCH_CMD;
- if (!process_command_line(the_command, &argc, &argv)) {
+ if (!process_command_line(cmd->command, &argc, &argv)) {
log_error("Error during parsing of command line.");
return EINVALID_CMD_LINE;
}
- set_cmd_name(the_command->name);
+ set_cmd_name(cmd->command->name);
- if ((ret = process_common_commands(the_command)))
+ if ((ret = process_common_commands(cmd->command)))
return ret;
_use_settings(&_current_settings);
@@ -748,7 +741,7 @@ static int run_command(int argc, char **argv)
return 0;
}
- ret = the_command->fn(argc, argv);
+ ret = cmd->command->fn(cmd, argc, argv);
fin_locking();
@@ -766,7 +759,7 @@ static int run_command(int argc, char **argv)
pool_empty(cmd->mem);
if (ret == EINVALID_CMD_LINE && !_interactive)
- usage(the_command->name);
+ usage(cmd->command->name);
return ret;
@@ -1018,7 +1011,7 @@ static struct dev_filter *filter_setup(struct config_file *cf)
return f4;
}
-static int _init_uuid_map(struct dev_filter *filter)
+static struct uuid_map *_init_uuid_map(struct dev_filter *filter)
{
label_init();
@@ -1033,12 +1026,12 @@ static int _init_uuid_map(struct dev_filter *filter)
return 0;
}
- return (the_um = uuid_map_create(filter)) ? 1 : 0;
+ return uuid_map_create(filter);
}
static void _exit_uuid_map(void)
{
- uuid_map_destroy(the_um);
+ uuid_map_destroy(cmd->um);
label_exit();
_lvm1_label->ops->destroy(_lvm1_label);
_lvm1_label = NULL;
@@ -1078,6 +1071,8 @@ static int init(void)
return 0;
}
+ cmd->args = &the_args[0];
+
if (!(cmd->cf = create_config_file())) {
stack;
return 0;
@@ -1144,7 +1139,7 @@ static int init(void)
}
/* the uuid map uses the filter */
- if (!_init_uuid_map(cmd->filter)) {
+ if (!(cmd->um = _init_uuid_map(cmd->filter))) {
log_err("Failed to set up the uuid map.");
return 0;
}
@@ -1154,7 +1149,7 @@ static int init(void)
return 0;
}
- if (!(fid = create_lvm1_format(cmd)))
+ if (!(cmd->fid = create_lvm1_format(cmd)))
return 0;
_use_settings(&_default_settings);
@@ -1176,16 +1171,16 @@ static void fin(void)
if (_dump_filter)
persistent_filter_dump(cmd->filter);
- fid->ops->destroy(fid);
+ cmd->fid->ops->destroy(cmd->fid);
cmd->filter->destroy(cmd->filter);
pool_destroy(cmd->mem);
vgcache_destroy();
dev_cache_exit();
destroy_config_file(cmd->cf);
- dbg_free(cmd);
archive_exit();
backup_exit();
_exit_uuid_map();
+ dbg_free(cmd);
__fin_commands();
dump_memory();
diff --git a/tools/lvmchange.c b/tools/lvmchange.c
index 42b186b5..c500d04c 100644
--- a/tools/lvmchange.c
+++ b/tools/lvmchange.c
@@ -20,7 +20,7 @@
#include "tools.h"
-int lvmchange(int argc, char **argv)
+int lvmchange(struct cmd_context *cmd, int argc, char **argv)
{
log_print("With the device mapper, this program is obsolete.");
return 0;
diff --git a/tools/lvmdiskscan.c b/tools/lvmdiskscan.c
index a20b917d..ab793967 100644
--- a/tools/lvmdiskscan.c
+++ b/tools/lvmdiskscan.c
@@ -13,7 +13,7 @@
#include "tools.h"
-int _get_max_dev_name_len(void);
+int _get_max_dev_name_len(struct dev_filter *filter);
void _count(struct device*, int*, int*);
void _print(struct device*, uint64_t, char*);
int _check_device(struct device*);
@@ -24,19 +24,19 @@ int pv_disks_found = 0;
int pv_parts_found = 0;
int max_len;
-int lvmdiskscan(int argc, char **argv)
+int lvmdiskscan(struct cmd_context *cmd, int argc, char **argv)
{
uint64_t size;
struct dev_iter *iter;
struct device *dev;
struct physical_volume *pv;
- if (arg_count(lvmpartition_ARG))
+ if (arg_count(cmd,lvmpartition_ARG))
log_print("WARNING: only considering LVM devices");
- max_len = _get_max_dev_name_len();
+ max_len = _get_max_dev_name_len(cmd->filter);
- if (!(iter = dev_iter_create(fid->cmd->filter))) {
+ if (!(iter = dev_iter_create(cmd->filter))) {
log_error("dev_iter_create failed");
return 0;
}
@@ -44,7 +44,7 @@ int lvmdiskscan(int argc, char **argv)
/* Do scan */
for (dev = dev_iter_get(iter); dev; dev = dev_iter_get(iter)) {
/* Try if it is a PV first */
- if((pv = fid->ops->pv_read(fid, dev_name(dev)))) {
+ if((pv = cmd->fid->ops->pv_read(cmd->fid, dev_name(dev)))) {
if(!dev_get_size(dev, &size)) {
log_error("Couldn't get size of \"%s\"",
dev_name(dev));
@@ -55,7 +55,7 @@ int lvmdiskscan(int argc, char **argv)
continue;
}
/* If user just wants PVs we are done */
- if (arg_count(lvmpartition_ARG)) continue;
+ if (arg_count(cmd,lvmpartition_ARG)) continue;
/* What other device is it? */
if(!_check_device(dev)) continue;
@@ -63,7 +63,7 @@ int lvmdiskscan(int argc, char **argv)
dev_iter_destroy(iter);
/* Display totals */
- if (!arg_count(lvmpartition_ARG)) {
+ if (!arg_count(cmd,lvmpartition_ARG)) {
log_print("%d disk%s",
disks_found, disks_found == 1 ? "" : "s");
log_print("%d partition%s",
@@ -103,13 +103,13 @@ int _check_device(struct device *dev) {
}
-int _get_max_dev_name_len(void) {
+int _get_max_dev_name_len(struct dev_filter *filter) {
int len = 0;
int max_len = 0;
struct dev_iter *iter;
struct device *dev;
- if (!(iter = dev_iter_create(fid->cmd->filter))) {
+ if (!(iter = dev_iter_create(filter))) {
log_error("dev_iter_create failed");
return 0;
}
diff --git a/tools/lvreduce.c b/tools/lvreduce.c
index 3425de2f..a3b1f12a 100644
--- a/tools/lvreduce.c
+++ b/tools/lvreduce.c
@@ -20,7 +20,7 @@
#include "tools.h"
-int lvreduce(int argc, char **argv)
+int lvreduce(struct cmd_context *cmd, int argc, char **argv)
{
- return lvresize(argc, argv);
+ return lvresize(cmd, argc, argv);
}
diff --git a/tools/lvremove.c b/tools/lvremove.c
index 35b5f1b3..11709498 100644
--- a/tools/lvremove.c
+++ b/tools/lvremove.c
@@ -20,19 +20,19 @@
#include "tools.h"
-static int lvremove_single(struct logical_volume *lv);
+static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv);
-int lvremove(int argc, char **argv)
+int lvremove(struct cmd_context *cmd, int argc, char **argv)
{
if (!argc) {
log_error("Please enter one or more logical volume paths");
return EINVALID_CMD_LINE;
}
- return process_each_lv(argc, argv, &lvremove_single);
+ return process_each_lv(cmd, argc, argv, &lvremove_single);
}
-static int lvremove_single(struct logical_volume *lv)
+static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv)
{
struct volume_group *vg;
int active;
@@ -57,7 +57,7 @@ static int lvremove_single(struct logical_volume *lv)
active = lv_active(lv);
- if (active && !arg_count(force_ARG)) {
+ if (active && !arg_count(cmd,force_ARG)) {
if (yes_no_prompt
("Do you really want to remove active logical volume \"%s\"? "
"[y/n]: ", lv->name) == 'n') {
@@ -80,7 +80,7 @@ static int lvremove_single(struct logical_volume *lv)
}
/* store it on disks */
- if (!fid->ops->vg_write(fid, vg))
+ if (!cmd->fid->ops->vg_write(cmd->fid, vg))
return ECMD_FAILED;
backup(vg);
diff --git a/tools/lvrename.c b/tools/lvrename.c
index ed56ee1e..3adb0222 100644
--- a/tools/lvrename.c
+++ b/tools/lvrename.c
@@ -20,7 +20,7 @@
#include "tools.h"
-int lvrename(int argc, char **argv)
+int lvrename(struct cmd_context *cmd, int argc, char **argv)
{
int maxlen;
int active;
@@ -40,13 +40,13 @@ int lvrename(int argc, char **argv)
lv_name_old = argv[0];
lv_name_new = argv[1];
- if (!(vg_name = extract_vgname(fid, lv_name_old))) {
+ if (!(vg_name = extract_vgname(cmd->fid, lv_name_old))) {
log_error("Please provide a volume group name");
return EINVALID_CMD_LINE;
}
if (strchr(lv_name_new, '/') &&
- (vg_name_new = extract_vgname(fid, lv_name_new)) &&
+ (vg_name_new = extract_vgname(cmd->fid, lv_name_new)) &&
strcmp(vg_name, vg_name_new)) {
log_error("Logical volume names must "
"have the same volume group (\"%s\" or \"%s\")",
@@ -61,7 +61,7 @@ int lvrename(int argc, char **argv)
lv_name_new = st + 1;
/* Check sanity of new name */
- maxlen = NAME_LEN - strlen(vg_name) - strlen(fid->cmd->dev_dir) - 3;
+ maxlen = NAME_LEN - strlen(vg_name) - strlen(cmd->dev_dir) - 3;
if (strlen(lv_name_new) > maxlen) {
log_error("New logical volume path exceeds maximum length "
"of %d!", maxlen);
@@ -91,7 +91,7 @@ int lvrename(int argc, char **argv)
return ECMD_FAILED;
}
- if (!(vg = fid->ops->vg_read(fid, vg_name))) {
+ if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vg_name))) {
log_error("Volume group \"%s\" doesn't exist", vg_name);
goto error;
}
@@ -133,14 +133,14 @@ int lvrename(int argc, char **argv)
goto error;
}
- if (!(lv->name = pool_strdup(fid->cmd->mem, lv_name_new))) {
+ if (!(lv->name = pool_strdup(cmd->mem, lv_name_new))) {
log_error("Failed to allocate space for new name");
goto error;
}
/* store it on disks */
log_verbose("Writing out updated volume group");
- if (!(fid->ops->vg_write(fid, vg))) {
+ if (!(cmd->fid->ops->vg_write(cmd->fid, vg))) {
goto error;
}
diff --git a/tools/lvresize.c b/tools/lvresize.c
index 16439251..0c432b6a 100644
--- a/tools/lvresize.c
+++ b/tools/lvresize.c
@@ -20,7 +20,7 @@
#include "tools.h"
-int lvresize(int argc, char **argv)
+int lvresize(struct cmd_context *cmd, int argc, char **argv)
{
struct volume_group *vg;
struct logical_volume *lv;
@@ -45,25 +45,25 @@ int lvresize(int argc, char **argv)
LV_EXTEND = 2
} resize = LV_ANY;
- cmd_name = command_name();
+ cmd_name = command_name(cmd);
if (!strcmp(cmd_name, "lvreduce"))
resize = LV_REDUCE;
if (!strcmp(cmd_name, "lvextend"))
resize = LV_EXTEND;
- if (arg_count(extents_ARG) + arg_count(size_ARG) != 1) {
+ if (arg_count(cmd,extents_ARG) + arg_count(cmd,size_ARG) != 1) {
log_error("Please specify either size or extents (not both)");
return EINVALID_CMD_LINE;
}
- if (arg_count(extents_ARG)) {
- extents = arg_int_value(extents_ARG, 0);
- sign = arg_sign_value(extents_ARG, SIGN_NONE);
+ if (arg_count(cmd,extents_ARG)) {
+ extents = arg_int_value(cmd,extents_ARG, 0);
+ sign = arg_sign_value(cmd,extents_ARG, SIGN_NONE);
}
- if (arg_count(size_ARG)) {
- size = arg_int_value(size_ARG, 0);
- sign = arg_sign_value(size_ARG, SIGN_NONE);
+ if (arg_count(cmd,size_ARG)) {
+ size = arg_int_value(cmd,size_ARG, 0);
+ sign = arg_sign_value(cmd,size_ARG, SIGN_NONE);
}
if (resize == LV_EXTEND && sign == SIGN_MINUS) {
@@ -76,14 +76,14 @@ int lvresize(int argc, char **argv)
return EINVALID_CMD_LINE;
}
- if (arg_count(stripes_ARG)) {
+ if (arg_count(cmd,stripes_ARG)) {
log_print("Varied striping not yet supported. Ignoring.");
- /* FUTURE stripes = arg_int_value(stripes_ARG, 1); */
+ /* FUTURE stripes = arg_int_value(cmd,stripes_ARG, 1); */
}
- if (arg_count(stripesize_ARG)) {
+ if (arg_count(cmd,stripesize_ARG)) {
log_print("Varied stripesize not yet supported. Ignoring.");
- /* FUTURE stripesize = 2 * arg_int_value(stripesize_ARG, 0); */
+ /* FUTURE stripesize = 2 * arg_int_value(cmd,stripesize_ARG, 0); */
}
if (!argc) {
@@ -95,7 +95,7 @@ int lvresize(int argc, char **argv)
argv++;
argc--;
- if (!(vg_name = extract_vgname(fid, lv_name))) {
+ if (!(vg_name = extract_vgname(cmd->fid, lv_name))) {
log_error("Please provide a volume group name");
return EINVALID_CMD_LINE;
}
@@ -110,7 +110,7 @@ int lvresize(int argc, char **argv)
return ECMD_FAILED;
}
- if (!(vg = fid->ops->vg_read(fid, vg_name))) {
+ if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vg_name))) {
log_error("Volume group %s doesn't exist", vg_name);
goto error;
}
@@ -290,7 +290,7 @@ int lvresize(int argc, char **argv)
dbg_free(dummy);
}
- if (!arg_count(force_ARG)) {
+ if (!arg_count(cmd,force_ARG)) {
if (yes_no_prompt("Do you really want to reduce %s?"
" [y/n]: ", lv_name) == 'n') {
log_print("Logical volume %s NOT reduced",
@@ -302,12 +302,12 @@ int lvresize(int argc, char **argv)
if (!archive(vg))
goto error;
- if (!lv_reduce(fid, lv, lv->le_count - extents))
+ if (!lv_reduce(cmd->fid, lv, lv->le_count - extents))
goto error;
}
if ((resize == LV_EXTEND && argc) &&
- !(pvh = create_pv_list(fid->cmd->mem, vg,
+ !(pvh = create_pv_list(cmd->mem, vg,
argc - opt, argv + opt))) {
stack;
goto error;
@@ -325,7 +325,7 @@ int lvresize(int argc, char **argv)
log_print("Extending logical volume %s to %s", lv_name, dummy);
dbg_free(dummy);
- if (!lv_extend(fid, lv, stripes, stripesize,
+ if (!lv_extend(cmd->fid, lv, stripes, stripesize,
extents - lv->le_count, pvh))
goto error;
}
@@ -336,7 +336,7 @@ int lvresize(int argc, char **argv)
/********* FIXME Suspend lv ***********/
/* store vg on disk(s) */
- if (!fid->ops->vg_write(fid, vg))
+ if (!cmd->fid->ops->vg_write(cmd->fid, vg))
goto error;
backup(vg);
diff --git a/tools/lvscan.c b/tools/lvscan.c
index 52896fda..a0dd9c86 100644
--- a/tools/lvscan.c
+++ b/tools/lvscan.c
@@ -20,16 +20,16 @@
#include "tools.h"
-static int lvscan_single(struct logical_volume *lv);
+static int lvscan_single(struct cmd_context *cmd, struct logical_volume *lv);
-int lvscan(int argc, char **argv)
+int lvscan(struct cmd_context *cmd, int argc, char **argv)
{
if (argc) {
log_error("No additional command line arguments allowed");
return EINVALID_CMD_LINE;
}
- return process_each_lv(argc, argv, &lvscan_single);
+ return process_each_lv(cmd, argc, argv, &lvscan_single);
/*********** FIXME Count! Add private struct to process_each*
if (!lv_total)
@@ -54,7 +54,7 @@ int lvscan(int argc, char **argv)
}
-static int lvscan_single(struct logical_volume *lv)
+static int lvscan_single(struct cmd_context *cmd, struct logical_volume *lv)
{
int active = 0;
int lv_total = 0;
@@ -88,7 +88,7 @@ static int lvscan_single(struct logical_volume *lv)
dummy = display_size(lv->size / 2, SIZE_SHORT);
log_print("%s%s '%s%s/%s' [%s]%s%s", active_str, snapshot_str,
- fid->cmd->dev_dir, lv->vg->name, lv->name, dummy,
+ cmd->dev_dir, lv->vg->name, lv->name, dummy,
(lv->status & ALLOC_STRICT) ? " strict" : "",
(lv->status & ALLOC_CONTIGUOUS) ? " contiguous" : "");
@@ -102,7 +102,7 @@ static int lvscan_single(struct logical_volume *lv)
****************/
/******** FIXME Device number display & Snapshot
- if (arg_count(blockdevice_ARG))
+ if (arg_count(cmd,blockdevice_ARG))
printf(" %d:%d",
MAJOR(lv->lv_dev),
MINOR(lv->lv_dev));
diff --git a/tools/pvchange.c b/tools/pvchange.c
index 371cddbb..cb36a4d1 100644
--- a/tools/pvchange.c
+++ b/tools/pvchange.c
@@ -20,9 +20,9 @@
#include "tools.h"
-int pvchange_single(struct physical_volume *pv);
+int pvchange_single(struct cmd_context *cmd, struct physical_volume *pv);
-int pvchange(int argc, char **argv)
+int pvchange(struct cmd_context *cmd, int argc, char **argv)
{
int opt = 0;
int done = 0;
@@ -33,17 +33,17 @@ int pvchange(int argc, char **argv)
struct list *pvh, *pvs;
- if (arg_count(allocatable_ARG) == 0) {
+ if (arg_count(cmd,allocatable_ARG) == 0) {
log_error("Please give the x option");
return EINVALID_CMD_LINE;
}
- if (!(arg_count(all_ARG)) && !argc) {
+ if (!(arg_count(cmd,all_ARG)) && !argc) {
log_error("Please give a physical volume path");
return EINVALID_CMD_LINE;
}
- if (arg_count(all_ARG) && argc) {
+ if (arg_count(cmd,all_ARG) && argc) {
log_error("Option a and PhysicalVolumePath are exclusive");
return EINVALID_CMD_LINE;
}
@@ -52,23 +52,23 @@ int pvchange(int argc, char **argv)
log_verbose("Using physical volume(s) on command line");
for (; opt < argc; opt++) {
pv_name = argv[opt];
- if (!(pv = fid->ops->pv_read(fid, pv_name))) {
+ if (!(pv = cmd->fid->ops->pv_read(cmd->fid, pv_name))) {
log_error("Failed to read physical volume \"%s\"",
pv_name);
continue;
}
total++;
- done += pvchange_single(pv);
+ done += pvchange_single(cmd, pv);
}
} else {
log_verbose("Scanning for physical volume names");
- if (!(pvs = fid->ops->get_pvs(fid))) {
+ if (!(pvs = cmd->fid->ops->get_pvs(cmd->fid))) {
return ECMD_FAILED;
}
list_iterate(pvh, pvs) {
total++;
- done += pvchange_single(
+ done += pvchange_single(cmd,
list_item(pvh, struct pv_list)->pv);
}
}
@@ -81,14 +81,14 @@ int pvchange(int argc, char **argv)
return 0;
}
-int pvchange_single(struct physical_volume *pv)
+int pvchange_single(struct cmd_context *cmd, struct physical_volume *pv)
{
struct volume_group *vg = NULL;
struct pv_list *pvl;
const char *pv_name = dev_name(pv->dev);
- int allocatable = !strcmp(arg_str_value(allocatable_ARG, "n"), "y");
+ int allocatable = !strcmp(arg_str_value(cmd,allocatable_ARG, "n"), "y");
/* If in a VG, must change using volume group. */
if (*pv->vg_name) {
@@ -100,7 +100,7 @@ int pvchange_single(struct physical_volume *pv)
return ECMD_FAILED;
}
- if (!(vg = fid->ops->vg_read(fid, pv->vg_name))) {
+ if (!(vg = cmd->fid->ops->vg_read(cmd->fid, pv->vg_name))) {
lock_vol(pv->vg_name, LCK_VG | LCK_NONE);
log_error("Unable to find volume group of \"%s\"",
pv_name);
@@ -157,7 +157,7 @@ int pvchange_single(struct physical_volume *pv)
log_verbose("Updating physical volume \"%s\"", pv_name);
if (*pv->vg_name) {
- if (!(fid->ops->vg_write(fid,vg))) {
+ if (!(cmd->fid->ops->vg_write(cmd->fid,vg))) {
lock_vol(pv->vg_name, LCK_VG | LCK_NONE);
log_error("Failed to store physical volume \"%s\" in "
"volume group \"%s\"", pv_name, vg->name);
@@ -166,7 +166,7 @@ int pvchange_single(struct physical_volume *pv)
backup(vg);
lock_vol(pv->vg_name, LCK_VG | LCK_NONE);
} else {
- if (!(fid->ops->pv_write(fid, pv))) {
+ if (!(cmd->fid->ops->pv_write(cmd->fid, pv))) {
log_error("Failed to store physical volume \"%s\"",
pv_name);
return 0;
diff --git a/tools/pvcreate.c b/tools/pvcreate.c
index 7effa611..b0c7e1a2 100644
--- a/tools/pvcreate.c
+++ b/tools/pvcreate.c
@@ -27,16 +27,16 @@ const char _really_init[] =
* See if we may pvcreate on this device.
* 0 indicates we may not.
*/
-static int pvcreate_check(const char *name)
+static int pvcreate_check(struct cmd_context *cmd, const char *name)
{
struct physical_volume *pv;
/* is the partition type set correctly ? */
- if ((arg_count(force_ARG) < 1) && !is_lvm_partition(name))
+ if ((arg_count(cmd,force_ARG) < 1) && !is_lvm_partition(name))
return 0;
/* is there a pv here already */
- if (!(pv = fid->ops->pv_read(fid, name)))
+ if (!(pv = cmd->fid->ops->pv_read(cmd->fid, name)))
return 1;
/* orphan ? */
@@ -45,20 +45,20 @@ static int pvcreate_check(const char *name)
/* Allow partial & exported VGs to be destroyed. */
/* we must have -ff to overwrite a non orphan */
- if (arg_count(force_ARG) < 2) {
+ if (arg_count(cmd,force_ARG) < 2) {
log_error("Can't initialize physical volume \"%s\" of "
"volume group \"%s\" without -ff", name, pv->vg_name);
return 0;
}
/* prompt */
- if (!arg_count(yes_ARG) &&
+ if (!arg_count(cmd,yes_ARG) &&
yes_no_prompt(_really_init, name, pv->vg_name) == 'n') {
log_print("Physical volume \"%s\" not initialized", name);
return 0;
}
- if (arg_count(force_ARG)) {
+ if (arg_count(cmd,force_ARG)) {
log_print("WARNING: Forcing physical volume creation on "
"%s%s%s%s", name,
pv->vg_name[0] ? " of volume group \"" : "",
@@ -69,18 +69,18 @@ static int pvcreate_check(const char *name)
return 1;
}
-static void pvcreate_single(const char *pv_name)
+static void pvcreate_single(struct cmd_context *cmd, const char *pv_name)
{
struct physical_volume *pv;
struct id id, *idp = NULL;
char *uuid;
struct device *dev;
- if (arg_count(uuidstr_ARG)) {
- uuid = arg_str_value(uuidstr_ARG,"");
+ if (arg_count(cmd,uuidstr_ARG)) {
+ uuid = arg_str_value(cmd,uuidstr_ARG,"");
if (!id_read_format(&id, uuid))
return;
- if ((dev = uuid_map_lookup(the_um, &id))) {
+ if ((dev = uuid_map_lookup(cmd->um, &id))) {
log_error("uuid %s already in use on \"%s\"", uuid,
dev_name(dev));
return;
@@ -88,10 +88,10 @@ static void pvcreate_single(const char *pv_name)
idp = &id;
}
- if (!pvcreate_check(pv_name))
+ if (!pvcreate_check(cmd, pv_name))
return;
- if (!(pv = pv_create(fid, pv_name, idp))) {
+ if (!(pv = pv_create(cmd->fid, pv_name, idp))) {
log_err("Failed to setup physical volume \"%s\"", pv_name);
return;
}
@@ -101,7 +101,7 @@ static void pvcreate_single(const char *pv_name)
pv_name, pv->size);
log_verbose("Writing physical volume data to disk \"%s\"", pv_name);
- if (!(fid->ops->pv_write(fid, pv))) {
+ if (!(cmd->fid->ops->pv_write(cmd->fid, pv))) {
log_error("Failed to write physical volume \"%s\"", pv_name);
return;
}
@@ -109,7 +109,7 @@ static void pvcreate_single(const char *pv_name)
log_print("Physical volume \"%s\" successfully created", pv_name);
}
-int pvcreate(int argc, char **argv)
+int pvcreate(struct cmd_context *cmd, int argc, char **argv)
{
int i;
@@ -118,19 +118,19 @@ int pvcreate(int argc, char **argv)
return EINVALID_CMD_LINE;
}
- if (arg_count(uuidstr_ARG) && argc != 1) {
+ if (arg_count(cmd,uuidstr_ARG) && argc != 1) {
log_error("Can only set uuid on one volume at once");
return EINVALID_CMD_LINE;
}
- if (arg_count(yes_ARG) && !arg_count(force_ARG)) {
+ if (arg_count(cmd,yes_ARG) && !arg_count(cmd,force_ARG)) {
log_error("Option y can only be given with option f");
return EINVALID_CMD_LINE;
}
for (i = 0; i < argc; i++) {
- pvcreate_single(argv[i]);
- pool_empty(fid->cmd->mem);
+ pvcreate_single(cmd, argv[i]);
+ pool_empty(cmd->mem);
}
return 0;
diff --git a/tools/pvdisplay.c b/tools/pvdisplay.c
index 000f5d5e..70e5977a 100644
--- a/tools/pvdisplay.c
+++ b/tools/pvdisplay.c
@@ -20,16 +20,16 @@
#include "tools.h"
-void pvdisplay_single(struct physical_volume *pv);
+void pvdisplay_single(struct cmd_context *cmd, struct physical_volume *pv);
-int pvdisplay(int argc, char **argv)
+int pvdisplay(struct cmd_context *cmd, int argc, char **argv)
{
int opt=0;
struct list *pvh, *pvs;
struct physical_volume *pv;
- if (arg_count(colon_ARG) && arg_count(maps_ARG)) {
+ if (arg_count(cmd,colon_ARG) && arg_count(cmd,maps_ARG)) {
log_error("Option -v not allowed with option -c");
return EINVALID_CMD_LINE;
}
@@ -38,27 +38,27 @@ int pvdisplay(int argc, char **argv)
log_very_verbose("Using physical volume(s) on command line");
for (; opt < argc; opt++) {
- if (!(pv = fid->ops->pv_read(fid, argv[opt]))) {
+ if (!(pv = cmd->fid->ops->pv_read(cmd->fid, argv[opt]))) {
log_error("Failed to read physical "
"volume \"%s\"",
argv[opt]);
continue;
}
- pvdisplay_single(pv);
+ pvdisplay_single(cmd, pv);
}
} else {
log_verbose("Scanning for physical volume names");
- if (!(pvs = fid->ops->get_pvs(fid)))
+ if (!(pvs = cmd->fid->ops->get_pvs(cmd->fid)))
return ECMD_FAILED;
list_iterate(pvh, pvs)
- pvdisplay_single(list_item(pvh, struct pv_list)->pv);
+ pvdisplay_single(cmd, list_item(pvh, struct pv_list)->pv);
}
return 0;
}
-void pvdisplay_single(struct physical_volume *pv)
+void pvdisplay_single(struct cmd_context *cmd, struct physical_volume *pv)
{
char *sz;
uint64_t size;
@@ -70,7 +70,7 @@ void pvdisplay_single(struct physical_volume *pv)
else
size = (pv->pe_count - pv->pe_allocated) * pv->pe_size;
- if (arg_count(short_ARG)) {
+ if (arg_count(cmd,short_ARG)) {
sz = display_size(size / 2, SIZE_SHORT);
log_print("Device \"%s\" has a capacity of %s", pv_name, sz);
dbg_free(sz);
@@ -103,14 +103,14 @@ void pvdisplay_single(struct physical_volume *pv)
ret = pv_check_consistency (pv)
*/
- if (arg_count(colon_ARG)) {
+ if (arg_count(cmd,colon_ARG)) {
pvdisplay_colons(pv);
return;
}
pvdisplay_full(pv);
- if (!arg_count(maps_ARG))
+ if (!arg_count(cmd,maps_ARG))
return;
/******* FIXME
diff --git a/tools/pvscan.c b/tools/pvscan.c
index 44229ede..9704675a 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -20,12 +20,12 @@
#include "tools.h"
-void pvscan_display_single(struct physical_volume *pv);
+void pvscan_display_single(struct cmd_context *cmd, struct physical_volume *pv);
int pv_max_name_len = 0;
int vg_max_name_len = 0;
-int pvscan(int argc, char **argv)
+int pvscan(struct cmd_context *cmd, int argc, char **argv)
{
int new_pvs_found = 0;
int pvs_found = 0;
@@ -43,21 +43,21 @@ int pvscan(int argc, char **argv)
pv_max_name_len = 0;
vg_max_name_len = 0;
- if (arg_count(novolumegroup_ARG) && arg_count(exported_ARG)) {
+ if (arg_count(cmd,novolumegroup_ARG) && arg_count(cmd,exported_ARG)) {
log_error("Options -e and -n are incompatible");
return EINVALID_CMD_LINE;
}
- if (arg_count(exported_ARG) || arg_count(novolumegroup_ARG))
+ if (arg_count(cmd,exported_ARG) || arg_count(cmd,novolumegroup_ARG))
log_print("WARNING: only considering physical volumes %s",
- arg_count(exported_ARG) ?
+ arg_count(cmd,exported_ARG) ?
"of exported volume group(s)" : "in no volume group");
log_verbose("Wiping cache of LVM-capable devices");
- persistent_filter_wipe(fid->cmd->filter);
+ persistent_filter_wipe(cmd->filter);
log_verbose("Walking through all physical volumes");
- if (!(pvs = fid->ops->get_pvs(fid)))
+ if (!(pvs = cmd->fid->ops->get_pvs(cmd->fid)))
return ECMD_FAILED;
/* eliminate exported/new if required */
@@ -65,8 +65,8 @@ int pvscan(int argc, char **argv)
pvl = list_item(pvh, struct pv_list);
pv = pvl->pv;
- if ((arg_count(exported_ARG) && !(pv->status & EXPORTED_VG))
- || (arg_count(novolumegroup_ARG) && (*pv->vg_name))) {
+ if ((arg_count(cmd,exported_ARG) && !(pv->status & EXPORTED_VG))
+ || (arg_count(cmd,novolumegroup_ARG) && (*pv->vg_name))) {
list_del(&pvl->list);
continue;
}
@@ -108,7 +108,7 @@ int pvscan(int argc, char **argv)
vg_max_name_len += 2;
list_iterate(pvh, pvs)
- pvscan_display_single(list_item(pvh, struct pv_list)->pv);
+ pvscan_display_single(cmd, list_item(pvh, struct pv_list)->pv);
if (!pvs_found) {
log_print("No matching physical volumes found");
@@ -129,7 +129,7 @@ int pvscan(int argc, char **argv)
return 0;
}
-void pvscan_display_single(struct physical_volume *pv)
+void pvscan_display_single(struct cmd_context *cmd, struct physical_volume *pv)
{
char uuid[64];
int vg_name_len = 0;
@@ -141,12 +141,12 @@ void pvscan_display_single(struct physical_volume *pv)
char vg_name_this[NAME_LEN] = { 0, };
/* short listing? */
- if (arg_count(short_ARG) > 0) {
+ if (arg_count(cmd,short_ARG) > 0) {
log_print("%s", dev_name(pv->dev));
return;
}
- if (arg_count(verbose_ARG) > 1) {
+ if (arg_count(cmd,verbose_ARG) > 1) {
/* FIXME As per pv_display! Drop through for now. */
/* pv_show(pv); */
@@ -161,7 +161,7 @@ void pvscan_display_single(struct physical_volume *pv)
vg_name_len = strlen(pv->vg_name) + 1;
- if (arg_count(uuid_ARG)) {
+ if (arg_count(cmd,uuid_ARG)) {
if (!id_write_format(&pv->id, uuid, sizeof(uuid))) {
stack;
return;
diff --git a/tools/stub.h b/tools/stub.h
index e0bcb107..153a0fbf 100644
--- a/tools/stub.h
+++ b/tools/stub.h
@@ -6,11 +6,11 @@
#define unimplemented \
{ log_error("Command not implemented yet."); return ECMD_FAILED;}
-int e2fsadm(int argc, char **argv) unimplemented
-int lvmsadc(int argc, char **argv) unimplemented
-int lvmsar(int argc, char **argv) unimplemented
-int pvdata(int argc, char **argv) unimplemented
-int pvmove(int argc, char **argv) unimplemented
-int vgmknodes(int argc, char **argv) unimplemented
-int vgsplit(int argc, char **argv) unimplemented
+int e2fsadm(struct cmd_context *cmd, int argc, char **argv) unimplemented
+int lvmsadc(struct cmd_context *cmd, int argc, char **argv) unimplemented
+int lvmsar(struct cmd_context *cmd, int argc, char **argv) unimplemented
+int pvdata(struct cmd_context *cmd, int argc, char **argv) unimplemented
+int pvmove(struct cmd_context *cmd, int argc, char **argv) unimplemented
+int vgmknodes(struct cmd_context *cmd, int argc, char **argv) unimplemented
+int vgsplit(struct cmd_context *cmd, int argc, char **argv) unimplemented
diff --git a/tools/toollib.c b/tools/toollib.c
index 4a466a00..7e178318 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -8,8 +8,8 @@
#include <sys/stat.h>
-int process_each_lv_in_vg(struct volume_group *vg,
- int (*process_single) (struct logical_volume *lv))
+int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
+ int (*process_single) (struct cmd_context *cmd, struct logical_volume *lv))
{
int ret_max = 0;
int ret = 0;
@@ -24,7 +24,7 @@ int process_each_lv_in_vg(struct volume_group *vg,
list_iterate(lvh, &vg->lvs) {
lv = list_item(lvh, struct lv_list)->lv;
- ret = process_single(lv);
+ ret = process_single(cmd, lv);
if (ret > ret_max)
ret_max = ret;
}
@@ -33,8 +33,8 @@ int process_each_lv_in_vg(struct volume_group *vg,
}
-int process_each_lv(int argc, char **argv,
- int (*process_single) (struct logical_volume *lv))
+int process_each_lv(struct cmd_context *cmd, int argc, char **argv,
+ int (*process_single) (struct cmd_context *cmd, struct logical_volume *lv))
{
int opt = 0;
int ret_max = 0;
@@ -54,14 +54,14 @@ int process_each_lv(int argc, char **argv,
char *lv_name = argv[opt];
/* does VG exist? */
- if (!(vg_name = extract_vgname(fid, lv_name))) {
+ if (!(vg_name = extract_vgname(cmd->fid, lv_name))) {
if (ret_max < ECMD_FAILED)
ret_max = ECMD_FAILED;
continue;
}
log_verbose("Finding volume group \"%s\"", vg_name);
- if (!(vg = fid->ops->vg_read(fid, vg_name))) {
+ if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vg_name))) {
log_error("Volume group \"%s\" doesn't exist",
vg_name);
if (ret_max < ECMD_FAILED)
@@ -86,25 +86,25 @@ int process_each_lv(int argc, char **argv,
lv = lvl->lv;
- if ((ret = process_single(lv)) > ret_max)
+ if ((ret = process_single(cmd, lv)) > ret_max)
ret_max = ret;
}
} else {
log_verbose("Finding all logical volumes");
- if (!(vgs = fid->ops->get_vgs(fid))) {
+ if (!(vgs = cmd->fid->ops->get_vgs(cmd->fid))) {
log_error("No volume groups found");
return ECMD_FAILED;
}
list_iterate(vgh, vgs) {
vg_name = list_item(vgh, struct name_list)->name;
- if (!(vg = fid->ops->vg_read(fid, vg_name))) {
+ if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vg_name))) {
log_error("Volume group \"%s\" not found",
vg_name);
if (ret_max < ECMD_FAILED)
ret_max = ECMD_FAILED;
continue;
}
- ret = process_each_lv_in_vg(vg, process_single);
+ ret = process_each_lv_in_vg(cmd, vg, process_single);
if (ret > ret_max)
ret_max = ret;
vg_count++;
@@ -114,8 +114,8 @@ int process_each_lv(int argc, char **argv,
return ret_max;
}
-int process_each_vg(int argc, char **argv, int lock_type,
- int (*process_single) (const char *vg_name))
+int process_each_vg(struct cmd_context *cmd, int argc, char **argv, int lock_type,
+ int (*process_single) (struct cmd_context *cmd, const char *vg_name))
{
int opt = 0;
int ret_max = 0;
@@ -134,13 +134,13 @@ int process_each_vg(int argc, char **argv, int lock_type,
log_error("Can't lock %s: skipping", vg_name);
continue;
}
- if ((ret = process_single(vg_name)) > ret_max)
+ if ((ret = process_single(cmd, vg_name)) > ret_max)
ret_max = ret;
lock_vol((void *)vg_name, LCK_VG | LCK_NONE);
}
} else {
log_verbose("Finding all volume groups");
- if (!(vgs = fid->ops->get_vgs(fid))) {
+ if (!(vgs = cmd->fid->ops->get_vgs(cmd->fid))) {
log_error("No volume groups found");
return ECMD_FAILED;
}
@@ -150,7 +150,7 @@ int process_each_vg(int argc, char **argv, int lock_type,
log_error("Can't lock %s: skipping", vg_name);
continue;
}
- ret = process_single(vg_name);
+ ret = process_single(cmd, vg_name);
if (ret > ret_max)
ret_max = ret;
@@ -161,8 +161,8 @@ int process_each_vg(int argc, char **argv, int lock_type,
return ret_max;
}
-int process_each_pv_in_vg(struct volume_group *vg,
- int (*process_single) (struct volume_group *vg,
+int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
+ int (*process_single) (struct cmd_context *cmd, struct volume_group *vg,
struct physical_volume *pv))
{
int ret_max = 0;
@@ -173,15 +173,15 @@ int process_each_pv_in_vg(struct volume_group *vg,
list_iterate(pvh, &vg->pvs) {
pv = list_item(pvh, struct pv_list)->pv;
- if ((ret = process_single(vg, pv)) > ret_max)
+ if ((ret = process_single(cmd, vg, pv)) > ret_max)
ret_max = ret;
}
return ret_max;
}
-int process_each_pv(int argc, char **argv, struct volume_group *vg,
- int (*process_single) (struct volume_group *vg,
+int process_each_pv(struct cmd_context *cmd, int argc, char **argv, struct volume_group *vg,
+ int (*process_single) (struct cmd_context *cmd, struct volume_group *vg,
struct physical_volume *pv))
{
int opt = 0;
@@ -199,13 +199,13 @@ int process_each_pv(int argc, char **argv, struct volume_group *vg,
vg->name);
continue;
}
- ret = process_single(vg, pvl->pv);
+ ret = process_single(cmd, vg, pvl->pv);
if (ret > ret_max)
ret_max = ret;
}
} else {
log_verbose("Using all physical volume(s) in volume group");
- process_each_pv_in_vg(vg, process_single);
+ process_each_pv_in_vg(cmd, vg, process_single);
}
return ret_max;
@@ -240,7 +240,7 @@ char *extract_vgname(struct format_instance *fi, char *lv_name)
return 0;
}
- vg_name = pool_strdup(fid->cmd->mem, vg_name);
+ vg_name = pool_strdup(fi->cmd->mem, vg_name);
if (!vg_name) {
log_error("Allocation of vg_name failed");
return 0;
@@ -250,7 +250,7 @@ char *extract_vgname(struct format_instance *fi, char *lv_name)
return vg_name;
}
- if (!(vg_name = default_vgname(fid))) {
+ if (!(vg_name = default_vgname(fi))) {
if (lv_name)
log_error("Path required for Logical Volume \"%s\"",
lv_name);
@@ -280,7 +280,7 @@ char *default_vgname(struct format_instance *fi)
return 0;
}
- return pool_strdup(fid->cmd->mem, vg_path);
+ return pool_strdup(fi->cmd->mem, vg_path);
}
struct list *create_pv_list(struct pool *mem,
diff --git a/tools/toollib.h b/tools/toollib.h
index d43a0b9d..ae154469 100644
--- a/tools/toollib.h
+++ b/tools/toollib.h
@@ -21,26 +21,29 @@
#ifndef _LVM_TOOLLIB_H
#define _LVM_TOOLLIB_H
+#include "metadata.h"
+#include "pool.h"
+
int autobackup_set(void);
int autobackup_init(const char *backup_dir, int keep_days, int keep_number,
int autobackup);
int autobackup(struct volume_group *vg);
-int process_each_vg(int argc, char **argv, int lock_type,
- int (*process_single) (const char *vg_name));
+int process_each_vg(struct cmd_context *cmd, int argc, char **argv, int lock_type,
+ int (*process_single) (struct cmd_context *cmd, const char *vg_name));
-int process_each_pv(int argc, char **argv, struct volume_group *vg,
- int (*process_single) (struct volume_group * vg,
+int process_each_pv(struct cmd_context *cmd, int argc, char **argv, struct volume_group *vg,
+ int (*process_single) (struct cmd_context *cmd, struct volume_group * vg,
struct physical_volume * pv));
-int process_each_lv(int argc, char **argv,
- int (*process_single) (struct logical_volume * lv));
+int process_each_lv(struct cmd_context *cmd, int argc, char **argv,
+ int (*process_single) (struct cmd_context *cmd, struct logical_volume * lv));
-int process_each_pv_in_vg(struct volume_group *vg,
- int (*process_single) (struct volume_group * vg,
+int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
+ int (*process_single) (struct cmd_context *cmd, struct volume_group * vg,
struct physical_volume * pv));
-int process_each_lv_in_vg(struct volume_group *vg,
- int (*process_single) (struct logical_volume * lv));
+int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
+ int (*process_single) (struct cmd_context *cmd, struct logical_volume * lv));
int is_valid_chars(char *n);
diff --git a/tools/tools.h b/tools/tools.h
index 512b7fea..de0b7f7f 100644
--- a/tools/tools.h
+++ b/tools/tools.h
@@ -1,20 +1,7 @@
/*
- * Copyright (C) 2001 Sistina Software
+ * Copyright (C) 2001 Sistina Software (UK) Limited.
*
- * LVM is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * LVM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU CC; see the file COPYING. If not, write to
- * the Free Software Foundation, 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * This file is released under the LGPL.
*/
#ifndef _LVM_LVM_H
@@ -43,6 +30,7 @@
#include "activate.h"
#include "archive.h"
#include "locking.h"
+#include "toolcontext.h"
#include <stdio.h>
#include <stdarg.h>
@@ -57,9 +45,9 @@
#define MAX_ARGS 64
/* command functions */
-typedef int (*command_fn)(int argc, char **argv);
+typedef int (*command_fn)(struct cmd_context *cmd, int argc, char **argv);
-#define xx(a, b...) int a(int argc, char **argv);
+#define xx(a, b...) int a(struct cmd_context *cmd, int argc, char **argv);
#include "commands.h"
#undef xx
@@ -88,8 +76,6 @@ struct arg {
sign_t sign;
};
-extern struct arg the_args[ARG_COUNT + 1];
-
/* a register of the lvm commands */
struct command {
const char *name;
@@ -101,9 +87,6 @@ struct command {
int *valid_args;
};
-extern struct command *the_command;
-extern struct uuid_map *the_um;
-
void usage(const char *name);
/* the argument verify/normalise functions */
@@ -118,41 +101,37 @@ int permission_arg(struct arg *a);
char yes_no_prompt(const char *prompt, ...);
/* we use the enums to access the switches */
-static inline int arg_count(int a) {
- return the_args[a].count;
+static inline int arg_count(struct cmd_context *cmd, int a) {
+ return cmd->args[a].count;
}
-static inline char *arg_value(int a) {
- return the_args[a].value;
+static inline char *arg_value(struct cmd_context *cmd, int a) {
+ return cmd->args[a].value;
}
-static inline char *arg_str_value(int a, char *def)
+static inline char *arg_str_value(struct cmd_context *cmd, int a, char *def)
{
- return arg_count(a) ? the_args[a].value : def;
+ return arg_count(cmd, a) ? cmd->args[a].value : def;
}
-static inline uint32_t arg_int_value(int a, uint32_t def)
+static inline uint32_t arg_int_value(struct cmd_context *cmd, int a, uint32_t def)
{
- return arg_count(a) ? the_args[a].i_value : def;
+ return arg_count(cmd, a) ? cmd->args[a].i_value : def;
}
-static inline sign_t arg_sign_value(int a, sign_t def)
+static inline sign_t arg_sign_value(struct cmd_context *cmd, int a, sign_t def)
{
- return arg_count(a) ? the_args[a].sign : def;
+ return arg_count(cmd, a) ? cmd->args[a].sign : def;
}
-static inline int arg_count_increment(int a)
+static inline int arg_count_increment(struct cmd_context *cmd, int a)
{
- return the_args[a].count++;
+ return cmd->args[a].count++;
}
-static inline const char *command_name(void)
+static inline const char *command_name(struct cmd_context *cmd)
{
- return the_command->name;
+ return cmd->command->name;
}
-extern struct format_instance *fid;
-
-extern int lvdisplay_single(struct logical_volume *lv);
-
#endif
diff --git a/tools/vgcfgbackup.c b/tools/vgcfgbackup.c
index dbfcb63e..777147dc 100644
--- a/tools/vgcfgbackup.c
+++ b/tools/vgcfgbackup.c
@@ -13,7 +13,7 @@ static int _backup_to_file(const char *file, struct volume_group *vg)
int r;
struct format_instance *tf;
- if (!(tf = text_format_create(vg->cmd, file, the_um,
+ if (!(tf = text_format_create(vg->cmd, file, vg->cmd->um,
vg->cmd->cmd_line))) {
log_error("Couldn't create backup object.");
return 0;
@@ -26,18 +26,18 @@ static int _backup_to_file(const char *file, struct volume_group *vg)
return r;
}
-static int vg_backup_single(const char *vg_name)
+static int vg_backup_single(struct cmd_context *cmd, const char *vg_name)
{
struct volume_group *vg;
log_verbose("Checking for volume group \"%s\"", vg_name);
- if (!(vg = fid->ops->vg_read(fid, vg_name))) {
+ if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vg_name))) {
log_error("Volume group \"%s\" not found", vg_name);
return ECMD_FAILED;
}
- if (arg_count(file_ARG)) {
- _backup_to_file(arg_value(file_ARG), vg);
+ if (arg_count(cmd,file_ARG)) {
+ _backup_to_file(arg_value(cmd,file_ARG), vg);
} else {
/* just use the normal backup code */
@@ -52,8 +52,8 @@ static int vg_backup_single(const char *vg_name)
return 0;
}
-int vgcfgbackup(int argc, char **argv)
+int vgcfgbackup(struct cmd_context *cmd, int argc, char **argv)
{
- return process_each_vg(argc, argv, LCK_READ, &vg_backup_single);
+ return process_each_vg(cmd, argc, argv, LCK_READ, &vg_backup_single);
}
diff --git a/tools/vgcfgrestore.c b/tools/vgcfgrestore.c
index 19e45671..0a032234 100644
--- a/tools/vgcfgrestore.c
+++ b/tools/vgcfgrestore.c
@@ -6,9 +6,7 @@
#include "tools.h"
-#include <stdio.h>
-
-int vgcfgrestore(int argc, char **argv)
+int vgcfgrestore(struct cmd_context *cmd, int argc, char **argv)
{
if (argc != 1) {
log_err("Please specify a *single* volume group to restore.");
@@ -19,16 +17,17 @@ int vgcfgrestore(int argc, char **argv)
* FIXME: overloading the -l arg for now to display a
* list of archive files for a particular vg
*/
- if (arg_count(list_ARG)) {
- if (!archive_display(argv[0]))
+ if (arg_count(cmd,list_ARG)) {
+ if (!archive_display(cmd, argv[0]))
return ECMD_FAILED;
return 0;
}
- if (!(arg_count(file_ARG) ?
- backup_restore_from_file(argv[0], arg_str_value(file_ARG, "")) :
- backup_restore(argv[0]))) {
+ if (!(arg_count(cmd,file_ARG) ?
+ backup_restore_from_file(cmd, argv[0],
+ arg_str_value(cmd,file_ARG, "")) :
+ backup_restore(cmd, argv[0]))) {
log_err("Restore failed.");
return ECMD_FAILED;
}
diff --git a/tools/vgchange.c b/tools/vgchange.c
index aac06152..dc588db2 100644
--- a/tools/vgchange.c
+++ b/tools/vgchange.c
@@ -20,46 +20,46 @@
#include "tools.h"
-static int vgchange_single(const char *vg_name);
-void vgchange_available(struct volume_group *vg);
-void vgchange_resizeable(struct volume_group *vg);
-void vgchange_logicalvolume(struct volume_group *vg);
+static int vgchange_single(struct cmd_context *cmd, const char *vg_name);
+void vgchange_available(struct cmd_context *cmd, struct volume_group *vg);
+void vgchange_resizeable(struct cmd_context *cmd, struct volume_group *vg);
+void vgchange_logicalvolume(struct cmd_context *cmd, struct volume_group *vg);
-int vgchange(int argc, char **argv)
+int vgchange(struct cmd_context *cmd, int argc, char **argv)
{
- if (!(arg_count(available_ARG) + arg_count(logicalvolume_ARG) +
- arg_count(resizeable_ARG))) {
+ if (!(arg_count(cmd,available_ARG) + arg_count(cmd,logicalvolume_ARG) +
+ arg_count(cmd,resizeable_ARG))) {
log_error("One of -a, -l or -x options required");
return EINVALID_CMD_LINE;
}
- if (arg_count(available_ARG) + arg_count(logicalvolume_ARG) +
- arg_count(resizeable_ARG) > 1) {
+ if (arg_count(cmd,available_ARG) + arg_count(cmd,logicalvolume_ARG) +
+ arg_count(cmd,resizeable_ARG) > 1) {
log_error("Only one of -a, -l or -x options allowed");
return EINVALID_CMD_LINE;
}
- if (arg_count(available_ARG) == 1 && arg_count(autobackup_ARG)) {
+ if (arg_count(cmd,available_ARG) == 1 && arg_count(cmd,autobackup_ARG)) {
log_error("-A option not necessary with -a option");
return EINVALID_CMD_LINE;
}
- return process_each_vg(argc, argv,
- (arg_count(available_ARG)) ?
+ return process_each_vg(cmd, argc, argv,
+ (arg_count(cmd,available_ARG)) ?
LCK_READ : LCK_WRITE,
&vgchange_single);
}
-static int vgchange_single(const char *vg_name)
+static int vgchange_single(struct cmd_context *cmd, const char *vg_name)
{
struct volume_group *vg;
- if (!(vg = fid->ops->vg_read(fid, vg_name))) {
+ if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vg_name))) {
log_error("Unable to find volume group \"%s\"", vg_name);
return ECMD_FAILED;
}
- if (!(vg->status & LVM_WRITE) && !arg_count(available_ARG)) {
+ if (!(vg->status & LVM_WRITE) && !arg_count(cmd,available_ARG)) {
log_error("Volume group \"%s\" is read-only", vg->name);
return ECMD_FAILED;
}
@@ -69,22 +69,22 @@ static int vgchange_single(const char *vg_name)
return ECMD_FAILED;
}
- if (arg_count(available_ARG))
- vgchange_available(vg);
+ if (arg_count(cmd,available_ARG))
+ vgchange_available(cmd, vg);
- if (arg_count(resizeable_ARG))
- vgchange_resizeable(vg);
+ if (arg_count(cmd,resizeable_ARG))
+ vgchange_resizeable(cmd, vg);
- if (arg_count(logicalvolume_ARG))
- vgchange_logicalvolume(vg);
+ if (arg_count(cmd,logicalvolume_ARG))
+ vgchange_logicalvolume(cmd, vg);
return 0;
}
-void vgchange_available(struct volume_group *vg)
+void vgchange_available(struct cmd_context *cmd, struct volume_group *vg)
{
int lv_open, lv_active;
- int available = !strcmp(arg_str_value(available_ARG, "n"), "y");
+ int available = !strcmp(arg_str_value(cmd,available_ARG, "n"), "y");
/* FIXME: Force argument to deactivate them? */
if (!available && (lv_open = lvs_in_vg_opened(vg))) {
@@ -110,9 +110,9 @@ void vgchange_available(struct volume_group *vg)
return;
}
-void vgchange_resizeable(struct volume_group *vg)
+void vgchange_resizeable(struct cmd_context *cmd, struct volume_group *vg)
{
- int resizeable = !strcmp(arg_str_value(resizeable_ARG, "n"), "y");
+ int resizeable = !strcmp(arg_str_value(cmd,resizeable_ARG, "n"), "y");
if (resizeable && (vg->status & RESIZEABLE_VG)) {
log_error("Volume group \"%s\" is already resizeable", vg->name);
@@ -133,7 +133,7 @@ void vgchange_resizeable(struct volume_group *vg)
else
vg->status &= ~RESIZEABLE_VG;
- if (!fid->ops->vg_write(fid, vg))
+ if (!cmd->fid->ops->vg_write(cmd->fid, vg))
return;
backup(vg);
@@ -143,9 +143,9 @@ void vgchange_resizeable(struct volume_group *vg)
return;
}
-void vgchange_logicalvolume(struct volume_group *vg)
+void vgchange_logicalvolume(struct cmd_context *cmd, struct volume_group *vg)
{
- int max_lv = arg_int_value(logicalvolume_ARG, 0);
+ int max_lv = arg_int_value(cmd,logicalvolume_ARG, 0);
if (!(vg->status & RESIZEABLE_VG)) {
log_error("Volume group \"%s\" must be resizeable "
@@ -182,7 +182,7 @@ void vgchange_logicalvolume(struct volume_group *vg)
vg->max_lv = max_lv;
- if (!fid->ops->vg_write(fid, vg))
+ if (!cmd->fid->ops->vg_write(cmd->fid, vg))
return;
backup(vg);
diff --git a/tools/vgck.c b/tools/vgck.c
index 9d9343a5..a535a27e 100644
--- a/tools/vgck.c
+++ b/tools/vgck.c
@@ -20,20 +20,20 @@
#include "tools.h"
-static int vgck_single(const char *vg_name);
+static int vgck_single(struct cmd_context *cmd, const char *vg_name);
-int vgck(int argc, char **argv)
+int vgck(struct cmd_context *cmd, int argc, char **argv)
{
- return process_each_vg(argc, argv, LCK_READ, &vgck_single);
+ return process_each_vg(cmd, argc, argv, LCK_READ, &vgck_single);
}
-static int vgck_single(const char *vg_name)
+static int vgck_single(struct cmd_context *cmd, const char *vg_name)
{
struct volume_group *vg;
log_verbose("Checking volume group \"%s\"", vg_name);
- if (!(vg = fid->ops->vg_read(fid, vg_name))) {
+ if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vg_name))) {
log_error("Volume group \"%s\" not found", vg_name);
return ECMD_FAILED;
}
diff --git a/tools/vgcreate.c b/tools/vgcreate.c
index 1fdc12be..2a50da7e 100644
--- a/tools/vgcreate.c
+++ b/tools/vgcreate.c
@@ -26,7 +26,7 @@
#define DEFAULT_EXTENT 4096 /* In KB */
-int vgcreate(int argc, char **argv)
+int vgcreate(struct cmd_context *cmd, int argc, char **argv)
{
int max_lv, max_pv;
uint32_t extent_size;
@@ -46,11 +46,11 @@ int vgcreate(int argc, char **argv)
}
vg_name = argv[0];
- max_lv = arg_int_value(maxlogicalvolumes_ARG, DEFAULT_LV);
- max_pv = arg_int_value(maxphysicalvolumes_ARG, DEFAULT_PV);
+ max_lv = arg_int_value(cmd,maxlogicalvolumes_ARG, DEFAULT_LV);
+ max_pv = arg_int_value(cmd,maxphysicalvolumes_ARG, DEFAULT_PV);
/* Units of 512-byte sectors */
- extent_size = arg_int_value(physicalextentsize_ARG, DEFAULT_EXTENT) * 2;
+ extent_size = arg_int_value(cmd,physicalextentsize_ARG, DEFAULT_EXTENT) * 2;
if (max_lv < 1) {
log_error("maxlogicalvolumes too low");
@@ -63,10 +63,10 @@ int vgcreate(int argc, char **argv)
}
/* Strip dev_dir if present */
- if (!strncmp(vg_name, fid->cmd->dev_dir, strlen(fid->cmd->dev_dir)))
- vg_name += strlen(fid->cmd->dev_dir);
+ if (!strncmp(vg_name, cmd->dev_dir, strlen(cmd->dev_dir)))
+ vg_name += strlen(cmd->dev_dir);
- snprintf(vg_path, PATH_MAX, "%s%s", fid->cmd->dev_dir, vg_name);
+ snprintf(vg_path, PATH_MAX, "%s%s", cmd->dev_dir, vg_name);
if (path_exists(vg_path)) {
log_error("%s: already exists in filesystem", vg_path);
return ECMD_FAILED;
@@ -79,7 +79,7 @@ int vgcreate(int argc, char **argv)
}
/* Create the new VG */
- if (!(vg = vg_create(fid, vg_name, extent_size, max_pv, max_lv,
+ if (!(vg = vg_create(cmd->fid, vg_name, extent_size, max_pv, max_lv,
argc - 1, argv + 1)))
return ECMD_FAILED;
@@ -109,7 +109,7 @@ int vgcreate(int argc, char **argv)
}
/* Store VG on disk(s) */
- if (!fid->ops->vg_write(fid, vg)) {
+ if (!cmd->fid->ops->vg_write(cmd->fid, vg)) {
lock_vol(vg_name, LCK_VG | LCK_NONE);
lock_vol("", LCK_VG | LCK_NONE);
return ECMD_FAILED;
diff --git a/tools/vgdisplay.c b/tools/vgdisplay.c
index c096d40c..45a5d561 100644
--- a/tools/vgdisplay.c
+++ b/tools/vgdisplay.c
@@ -20,16 +20,16 @@
#include "tools.h"
-static int vgdisplay_single(const char *vg_name);
+static int vgdisplay_single(struct cmd_context *cmd, const char *vg_name);
-int vgdisplay(int argc, char **argv)
+int vgdisplay(struct cmd_context *cmd, int argc, char **argv)
{
- if (arg_count(colon_ARG) && arg_count(short_ARG)) {
+ if (arg_count(cmd,colon_ARG) && arg_count(cmd,short_ARG)) {
log_error("Option -c is not allowed with option -s");
return EINVALID_CMD_LINE;
}
- if (argc && arg_count(activevolumegroups_ARG)) {
+ if (argc && arg_count(cmd,activevolumegroups_ARG)) {
log_error("Option -A is not allowed with volume group names");
return EINVALID_CMD_LINE;
}
@@ -45,14 +45,14 @@ int vgdisplay(int argc, char **argv)
}
**********/
- process_each_vg(argc, argv, LCK_READ, &vgdisplay_single);
+ process_each_vg(cmd, argc, argv, LCK_READ, &vgdisplay_single);
/******** FIXME Need to count number processed
- Add this to process_each_vg if arg_count(activevolumegroups_ARG) ?
+ Add this to process_each_vg if arg_count(cmd,activevolumegroups_ARG) ?
if (opt == argc) {
log_print("no ");
- if (arg_count(activevolumegroups_ARG))
+ if (arg_count(cmd,activevolumegroups_ARG))
printf("active ");
printf("volume groups found\n\n");
return LVM_E_NO_VG;
@@ -62,7 +62,7 @@ int vgdisplay(int argc, char **argv)
return 0;
}
-static int vgdisplay_single(const char *vg_name)
+static int vgdisplay_single(struct cmd_context *cmd, const char *vg_name)
{
struct volume_group *vg;
@@ -70,7 +70,7 @@ static int vgdisplay_single(const char *vg_name)
/* FIXME Do the active check here if activevolumegroups_ARG ? */
log_very_verbose("Finding volume group \"%s\"", vg_name);
- if (!(vg = fid->ops->vg_read(fid, vg_name))) {
+ if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vg_name))) {
log_error("Volume group \"%s\" doesn't exist", vg_name);
return ECMD_FAILED;
}
@@ -78,25 +78,25 @@ static int vgdisplay_single(const char *vg_name)
if (vg->status & EXPORTED_VG)
log_print("WARNING: volume group \"%s\" is exported", vg_name);
- if (arg_count(colon_ARG)) {
+ if (arg_count(cmd,colon_ARG)) {
vgdisplay_colons(vg);
return 0;
}
- if (arg_count(short_ARG)) {
+ if (arg_count(cmd,short_ARG)) {
vgdisplay_short(vg);
return 0;
}
vgdisplay_full(vg); /* was vg_show */
- if (arg_count(verbose_ARG)) {
+ if (arg_count(cmd,verbose_ARG)) {
vgdisplay_extents(vg);
- process_each_lv_in_vg(vg, &lvdisplay_full);
+ process_each_lv_in_vg(cmd, vg, &lvdisplay_full);
log_print("--- Physical volumes ---");
- process_each_pv_in_vg(vg, &pvdisplay_short);
+ process_each_pv_in_vg(cmd, vg, &pvdisplay_short);
}
return 0;
diff --git a/tools/vgexport.c b/tools/vgexport.c
index 05fdb781..19d683cb 100644
--- a/tools/vgexport.c
+++ b/tools/vgexport.c
@@ -20,28 +20,28 @@
#include "tools.h"
-static int vgexport_single(const char *vg_name);
+static int vgexport_single(struct cmd_context *cmd, const char *vg_name);
-int vgexport(int argc, char **argv)
+int vgexport(struct cmd_context *cmd, int argc, char **argv)
{
- if (!argc && !arg_count(all_ARG)) {
+ if (!argc && !arg_count(cmd,all_ARG)) {
log_error("Please supply volume groups or use -a for all.");
return ECMD_FAILED;
}
- if (argc && arg_count(all_ARG)) {
+ if (argc && arg_count(cmd,all_ARG)) {
log_error("No arguments permitted when using -a for all.");
return ECMD_FAILED;
}
- return process_each_vg(argc, argv, LCK_READ, &vgexport_single);
+ return process_each_vg(cmd, argc, argv, LCK_READ, &vgexport_single);
}
-static int vgexport_single(const char *vg_name)
+static int vgexport_single(struct cmd_context *cmd, const char *vg_name)
{
struct volume_group *vg;
- if (!(vg = fid->ops->vg_read(fid, vg_name))) {
+ if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vg_name))) {
log_error("Unable to find volume group \"%s\"", vg_name);
goto error;
}
@@ -67,7 +67,7 @@ static int vgexport_single(const char *vg_name)
vg->status |= EXPORTED_VG;
- if (!fid->ops->vg_write(fid,vg))
+ if (!cmd->fid->ops->vg_write(cmd->fid,vg))
goto error;
backup(vg);
diff --git a/tools/vgextend.c b/tools/vgextend.c
index b51533bd..6da50337 100644
--- a/tools/vgextend.c
+++ b/tools/vgextend.c
@@ -20,7 +20,7 @@
#include "tools.h"
-int vgextend(int argc, char **argv)
+int vgextend(struct cmd_context *cmd, int argc, char **argv)
{
char *vg_name;
struct volume_group *vg = NULL;
@@ -52,7 +52,7 @@ int vgextend(int argc, char **argv)
goto error;
}
- if (!(vg = fid->ops->vg_read(fid, vg_name))) {
+ if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vg_name))) {
log_error("Volume group \"%s\" not found.", vg_name);
goto error;
}
@@ -83,7 +83,7 @@ int vgextend(int argc, char **argv)
goto error;
/* extend vg */
- if (!vg_extend(fid, vg, argc, argv))
+ if (!vg_extend(cmd->fid, vg, argc, argv))
goto error;
/* ret > 0 */
@@ -91,7 +91,7 @@ int vgextend(int argc, char **argv)
"physical volumes", vg_name, argc);
/* store vg on disk(s) */
- if (!fid->ops->vg_write(fid, vg))
+ if (!cmd->fid->ops->vg_write(cmd->fid, vg))
goto error;
backup(vg);
diff --git a/tools/vgimport.c b/tools/vgimport.c
index e30ab252..e6467ca2 100644
--- a/tools/vgimport.c
+++ b/tools/vgimport.c
@@ -20,28 +20,28 @@
#include "tools.h"
-static int vgimport_single(const char *vg_name);
+static int vgimport_single(struct cmd_context *cmd, const char *vg_name);
-int vgimport(int argc, char **argv)
+int vgimport(struct cmd_context *cmd, int argc, char **argv)
{
- if (!argc && !arg_count(all_ARG)) {
+ if (!argc && !arg_count(cmd,all_ARG)) {
log_error("Please supply volume groups or use -a for all.");
return ECMD_FAILED;
}
- if (argc && arg_count(all_ARG)) {
+ if (argc && arg_count(cmd,all_ARG)) {
log_error("No arguments permitted when using -a for all.");
return ECMD_FAILED;
}
- return process_each_vg(argc, argv, LCK_WRITE, &vgimport_single);
+ return process_each_vg(cmd, argc, argv, LCK_WRITE, &vgimport_single);
}
-static int vgimport_single(const char *vg_name)
+static int vgimport_single(struct cmd_context *cmd, const char *vg_name)
{
struct volume_group *vg;
- if (!(vg = fid->ops->vg_read(fid, vg_name))) {
+ if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vg_name))) {
log_error("Unable to find exported volume group \"%s\"",
vg_name);
goto error;
@@ -62,7 +62,7 @@ static int vgimport_single(const char *vg_name)
vg->status &= ~EXPORTED_VG;
- if (!fid->ops->vg_write(fid,vg))
+ if (!cmd->fid->ops->vg_write(cmd->fid,vg))
goto error;
backup(vg);
diff --git a/tools/vgmerge.c b/tools/vgmerge.c
index 9c134f0e..6e14d014 100644
--- a/tools/vgmerge.c
+++ b/tools/vgmerge.c
@@ -20,9 +20,9 @@
#include "tools.h"
-int vgmerge_single(const char *vg_name_to, const char *vg_name_from);
+int vgmerge_single(struct cmd_context *cmd, const char *vg_name_to, const char *vg_name_from);
-int vgmerge(int argc, char **argv)
+int vgmerge(struct cmd_context *cmd, int argc, char **argv)
{
char *vg_name_to;
int opt = 0;
@@ -38,7 +38,7 @@ int vgmerge(int argc, char **argv)
argv++;
for (; opt < argc; opt++) {
- ret = vgmerge_single(vg_name_to, argv[opt]);
+ ret = vgmerge_single(cmd, vg_name_to, argv[opt]);
if (ret > ret_max)
ret_max = ret;
}
@@ -46,7 +46,7 @@ int vgmerge(int argc, char **argv)
return ret_max;
}
-int vgmerge_single(const char *vg_name_to, const char *vg_name_from)
+int vgmerge_single(struct cmd_context *cmd, const char *vg_name_to, const char *vg_name_from)
{
struct volume_group *vg_to, *vg_from;
struct list *lvh1, *lvh2;
@@ -63,7 +63,7 @@ int vgmerge_single(const char *vg_name_to, const char *vg_name_from)
return ECMD_FAILED;
}
- if (!(vg_to = fid->ops->vg_read(fid, vg_name_to))) {
+ if (!(vg_to = cmd->fid->ops->vg_read(cmd->fid, vg_name_to))) {
log_error("Volume group \"%s\" doesn't exist", vg_name_to);
lock_vol(vg_name_to, LCK_VG | LCK_NONE);
return ECMD_FAILED;
@@ -88,7 +88,7 @@ int vgmerge_single(const char *vg_name_to, const char *vg_name_from)
return ECMD_FAILED;
}
- if (!(vg_from = fid->ops->vg_read(fid, vg_name_from))) {
+ if (!(vg_from = cmd->fid->ops->vg_read(cmd->fid, vg_name_from))) {
log_error("Volume group \"%s\" doesn't exist", vg_name_from);
goto error;
}
@@ -164,7 +164,7 @@ int vgmerge_single(const char *vg_name_to, const char *vg_name_from)
list_add(&vg_to->pvs, pvh);
pv = list_item(pvh, struct pv_list)->pv;
- pv->vg_name = pool_strdup(fid->cmd->mem, vg_to->name);
+ pv->vg_name = pool_strdup(cmd->mem, vg_to->name);
}
vg_to->pv_count += vg_from->pv_count;
@@ -181,7 +181,7 @@ int vgmerge_single(const char *vg_name_to, const char *vg_name_from)
/* store it on disks */
log_verbose("Writing out updated volume group");
- if (!(fid->ops->vg_write(fid, vg_to))) {
+ if (!(cmd->fid->ops->vg_write(cmd->fid, vg_to))) {
goto error;
}
diff --git a/tools/vgreduce.c b/tools/vgreduce.c
index 98b31348..1f2d9c06 100644
--- a/tools/vgreduce.c
+++ b/tools/vgreduce.c
@@ -20,9 +20,9 @@
#include "tools.h"
-static int vgreduce_single(struct volume_group *vg, struct physical_volume *pv);
+static int vgreduce_single(struct cmd_context *cmd, struct volume_group *vg, struct physical_volume *pv);
-int vgreduce(int argc, char **argv)
+int vgreduce(struct cmd_context *cmd, int argc, char **argv)
{
struct volume_group *vg;
char *vg_name;
@@ -34,12 +34,12 @@ int vgreduce(int argc, char **argv)
return EINVALID_CMD_LINE;
}
- if (argc == 1 && !arg_count(all_ARG)) {
+ if (argc == 1 && !arg_count(cmd,all_ARG)) {
log_error("Please enter physical volume paths or option -a");
return EINVALID_CMD_LINE;
}
- if (argc > 1 && arg_count(all_ARG)) {
+ if (argc > 1 && arg_count(cmd,all_ARG)) {
log_error("Option -a and physical volume paths mutually "
"exclusive");
return EINVALID_CMD_LINE;
@@ -55,7 +55,7 @@ int vgreduce(int argc, char **argv)
return ECMD_FAILED;
}
- if (!(vg = fid->ops->vg_read(fid, vg_name))) {
+ if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vg_name))) {
log_error("Volume group \"%s\" doesn't exist", vg_name);
lock_vol(vg_name, LCK_VG | LCK_NONE);
return ECMD_FAILED;
@@ -81,7 +81,7 @@ int vgreduce(int argc, char **argv)
/* FIXME: Pass private structure through to all these functions */
/* and update in batch here? */
- ret = process_each_pv(argc, argv, vg, vgreduce_single);
+ ret = process_each_pv(cmd, argc, argv, vg, vgreduce_single);
lock_vol(vg_name, LCK_VG | LCK_NONE);
@@ -105,7 +105,7 @@ int vgreduce(int argc, char **argv)
}
/* Or take pv_name instead? */
-static int vgreduce_single(struct volume_group *vg, struct physical_volume *pv)
+static int vgreduce_single(struct cmd_context *cmd, struct volume_group *vg, struct physical_volume *pv)
{
struct pv_list *pvl;
const char *name = dev_name(pv->dev);
@@ -142,14 +142,14 @@ static int vgreduce_single(struct volume_group *vg, struct physical_volume *pv)
vg->free_count -= pv->pe_count - pv->pe_allocated;
vg->extent_count -= pv->pe_count;
- if (!(fid->ops->vg_write(fid, vg))) {
+ if (!(cmd->fid->ops->vg_write(cmd->fid, vg))) {
log_error("Removal of physical volume \"%s\" from "
"\"%s\" failed",
name, vg->name);
return ECMD_FAILED;
}
- if (!fid->ops->pv_write(fid, pv)) {
+ if (!cmd->fid->ops->pv_write(cmd->fid, pv)) {
log_error("Failed to clear metadata from physical "
"volume \"%s\" "
"after removal from \"%s\"", name, vg->name);
diff --git a/tools/vgremove.c b/tools/vgremove.c
index 2d29a4d9..dce0281b 100644
--- a/tools/vgremove.c
+++ b/tools/vgremove.c
@@ -20,9 +20,9 @@
#include "tools.h"
-static int vgremove_single(const char *vg_name);
+static int vgremove_single(struct cmd_context *cmd, const char *vg_name);
-int vgremove(int argc, char **argv)
+int vgremove(struct cmd_context *cmd, int argc, char **argv)
{
int ret;
@@ -31,7 +31,7 @@ int vgremove(int argc, char **argv)
return ECMD_FAILED;
}
- ret = process_each_vg(argc, argv, LCK_WRITE | LCK_NONBLOCK,
+ ret = process_each_vg(cmd, argc, argv, LCK_WRITE | LCK_NONBLOCK,
&vgremove_single);
lock_vol("", LCK_VG | LCK_NONE);
@@ -39,7 +39,7 @@ int vgremove(int argc, char **argv)
return ret;
}
-static int vgremove_single(const char *vg_name)
+static int vgremove_single(struct cmd_context *cmd, const char *vg_name)
{
struct volume_group *vg;
struct physical_volume *pv;
@@ -47,7 +47,7 @@ static int vgremove_single(const char *vg_name)
int ret = 0;
log_verbose("Checking for volume group \"%s\"", vg_name);
- if (!(vg = fid->ops->vg_read(fid, vg_name))) {
+ if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vg_name))) {
log_error("Volume group \"%s\" doesn't exist", vg_name);
return ECMD_FAILED;
}
@@ -87,7 +87,7 @@ static int vgremove_single(const char *vg_name)
"volume group \"%s\"",
dev_name(pv->dev), vg_name);
*pv->vg_name = '\0';
- if (!(fid->ops->pv_write(fid, pv))) {
+ if (!(cmd->fid->ops->pv_write(cmd->fid, pv))) {
log_error("Failed to remove physical volume \"%s\""
" from volume group \"%s\"",
dev_name(pv->dev), vg_name);
diff --git a/tools/vgrename.c b/tools/vgrename.c
index 81b84670..e9f95f1e 100644
--- a/tools/vgrename.c
+++ b/tools/vgrename.c
@@ -20,7 +20,7 @@
#include "tools.h"
-int vgrename(int argc, char **argv)
+int vgrename(struct cmd_context *cmd, int argc, char **argv)
{
char *dev_dir;
int length;
@@ -40,7 +40,7 @@ int vgrename(int argc, char **argv)
vg_name_old = argv[0];
vg_name_new = argv[1];
- dev_dir = fid->cmd->dev_dir;
+ dev_dir = cmd->dev_dir;
length = strlen(dev_dir);
/* If present, strip dev_dir */
@@ -74,7 +74,7 @@ int vgrename(int argc, char **argv)
return ECMD_FAILED;
}
- if (!(vg_old = fid->ops->vg_read(fid, vg_name_old))) {
+ if (!(vg_old = cmd->fid->ops->vg_read(cmd->fid, vg_name_old))) {
log_error("Volume group \"%s\" doesn't exist", vg_name_old);
lock_vol(vg_name_old, LCK_VG | LCK_NONE);
return ECMD_FAILED;
@@ -112,7 +112,7 @@ int vgrename(int argc, char **argv)
return ECMD_FAILED;
}
- if ((vg_new = fid->ops->vg_read(fid, vg_name_new))) {
+ if ((vg_new = cmd->fid->ops->vg_read(cmd->fid, vg_name_new))) {
log_error("New volume group \"%s\" already exists",
vg_name_new);
goto error;
@@ -150,7 +150,7 @@ int vgrename(int argc, char **argv)
/* store it on disks */
log_verbose("Writing out updated volume group");
- if (!(fid->ops->vg_write(fid, vg_old))) {
+ if (!(cmd->fid->ops->vg_write(cmd->fid, vg_old))) {
goto error;
}
@@ -182,7 +182,7 @@ char *lv_change_vgname(char *vg_name, char *lv_name)
** check if lv_name includes a path
if ((lv_name_ptr = strrchr(lv_name, '/'))) {
lv_name_ptr++;
- sprintf(lv_name_buf, "%s%s/%s%c", fid->cmd->dev_dir, vg_name,
+ sprintf(lv_name_buf, "%s%s/%s%c", cmd->dev_dir, vg_name,
lv_name_ptr, 0);}
else
strncpy(lv_name_buf, lv_name, NAME_LEN - 1); return lv_name_buf;}
diff --git a/tools/vgscan.c b/tools/vgscan.c
index bdb43978..3a36b92b 100644
--- a/tools/vgscan.c
+++ b/tools/vgscan.c
@@ -20,9 +20,9 @@
#include "tools.h"
-static int vgscan_single(const char *vg_name);
+static int vgscan_single(struct cmd_context *cmd, const char *vg_name);
-int vgscan(int argc, char **argv)
+int vgscan(struct cmd_context *cmd, int argc, char **argv)
{
if (argc) {
log_error("Too many parameters on command line");
@@ -30,23 +30,23 @@ int vgscan(int argc, char **argv)
}
log_verbose("Wiping cache of LVM-capable devices");
- persistent_filter_wipe(fid->cmd->filter);
+ persistent_filter_wipe(cmd->filter);
log_verbose("Wiping internal cache of PVs in VGs");
vgcache_destroy();
log_print("Reading all physical volumes. This may take a while...");
- return process_each_vg(argc, argv, LCK_READ, &vgscan_single);
+ return process_each_vg(cmd, argc, argv, LCK_READ, &vgscan_single);
}
-static int vgscan_single(const char *vg_name)
+static int vgscan_single(struct cmd_context *cmd, const char *vg_name)
{
struct volume_group *vg;
log_verbose("Checking for volume group \"%s\"", vg_name);
- if (!(vg = fid->ops->vg_read(fid, vg_name))) {
+ if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vg_name))) {
log_error("Volume group \"%s\" not found", vg_name);
return ECMD_FAILED;
}