From df91af91413f262e6ffdda04ef7b0a616b4023e2 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Tue, 29 Jan 2002 19:19:37 +0000 Subject: [PATCH] o A vgimport implementation o Require -a or parameters with vgexport/vgimport o Allow pvcreate -ff to destroy exported/partial VGs --- lib/format1/import-export.c | 7 ++++--- lib/log/log.c | 4 ---- tools/Makefile.in | 1 + tools/commands.h | 5 +++-- tools/lvm.c | 5 ++++- tools/pvcreate.c | 8 +------- tools/stub.h | 1 - tools/toollib.c | 2 +- tools/toollib.h | 2 ++ tools/vgcreate.c | 2 +- tools/vgexport.c | 10 ++++++++++ 11 files changed, 27 insertions(+), 20 deletions(-) diff --git a/lib/format1/import-export.c b/lib/format1/import-export.c index e730abd36..57b3470be 100644 --- a/lib/format1/import-export.c +++ b/lib/format1/import-export.c @@ -130,7 +130,7 @@ int export_pv(struct pool *mem, struct volume_group *vg, /* Does system_id need setting? */ if (!vg->system_id || strncmp(vg->system_id, EXPORTED_TAG, - sizeof(EXPORTED_TAG))) { + sizeof(EXPORTED_TAG) - 1)) { if (!_system_id(pvd->system_id, EXPORTED_TAG)) { stack; return 0; @@ -147,7 +147,7 @@ int export_pv(struct pool *mem, struct volume_group *vg, /* Is VG being imported? */ if (vg && !(vg->status & EXPORTED_VG) && vg->system_id && - !strncmp(vg->system_id, EXPORTED_TAG, sizeof(EXPORTED_TAG))) { + !strncmp(vg->system_id, EXPORTED_TAG, sizeof(EXPORTED_TAG) - 1)) { if (!_system_id(pvd->system_id, IMPORTED_TAG)) { stack; return 0; @@ -164,7 +164,8 @@ int export_pv(struct pool *mem, struct volume_group *vg, /* Update internal system_id if we changed it */ if (vg && (!vg->system_id || - strncmp(vg->system_id, pvd->system_id, sizeof(pvd->system_id)))) { + strncmp(vg->system_id, pvd->system_id, + sizeof(pvd->system_id)))) { if (!(vg->system_id = pool_strdup(mem, pvd->system_id))) log_error("System ID update failed"); } diff --git a/lib/log/log.c b/lib/log/log.c index 8845f69df..ac600dbe1 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -51,10 +51,6 @@ void init_test(int level) { void init_partial(int level) { _partial = level; - if (_partial) - log_print("Partial mode. Incomplete volume groups will " - "be activated read-only."); - } void init_cmd_name(int status) { diff --git a/tools/Makefile.in b/tools/Makefile.in index 11141b2e5..6fcd4c4fb 100644 --- a/tools/Makefile.in +++ b/tools/Makefile.in @@ -46,6 +46,7 @@ SOURCES=\ vgdisplay.c \ vgexport.c \ vgextend.c \ + vgimport.c \ vgmerge.c \ vgreduce.c \ vgremove.c \ diff --git a/tools/commands.h b/tools/commands.h index af7971d62..cc0903c75 100644 --- a/tools/commands.h +++ b/tools/commands.h @@ -438,14 +438,15 @@ xx(vgextend, xx(vgimport, "Register exported volume group with system", "vgimport " "\n" + "\t[-a/--all]\n" "\t[-d|--debug] " "\n" "\t[-f|--force] " "\n" "\t[-h|--help] " "\n" "\t[-t|--test] " "\n" "\t[-v|--verbose]" "\n" - "\tVolumeGroupName PhysicalVolumePath " "[PhysicalVolumePath...]\n", + "\tVolumeGroupName..." "\n", - force_ARG, test_ARG) + all_ARG, force_ARG, test_ARG) xx(vgmerge, "Merge volume groups", diff --git a/tools/lvm.c b/tools/lvm.c index 006c14fdc..1c9deb595 100644 --- a/tools/lvm.c +++ b/tools/lvm.c @@ -613,8 +613,11 @@ static int process_common_commands(struct command *com) _current_settings.backup = 1; } - if (arg_count(partial_ARG)) + if (arg_count(partial_ARG)) { init_partial(1); + log_print("Partial mode. Incomplete volume groups will " + "be activated read-only."); + } else init_partial(0); diff --git a/tools/pvcreate.c b/tools/pvcreate.c index e8c668d6d..39fdc04b4 100644 --- a/tools/pvcreate.c +++ b/tools/pvcreate.c @@ -43,13 +43,7 @@ static int pvcreate_check(const char *name) if (!pv->vg_name[0]) return 1; - /* never overwrite exported pv's */ - if (pv->status & EXPORTED_VG) { - log_error("Physical volume %s belongs to exported volume" - " group %s", name, pv->vg_name); - return 0; - } - + /* Allow partial & exported VGs to be destroyed. */ /* we must have -ff to overwrite a non orphan */ if (arg_count(force_ARG) < 2) { log_error("Can't initialize physical volume %s of " diff --git a/tools/stub.h b/tools/stub.h index 10e9cea82..29ef469fa 100644 --- a/tools/stub.h +++ b/tools/stub.h @@ -10,7 +10,6 @@ int lvmsadc(int argc, char **argv) {return 1;} int lvmsar(int argc, char **argv) {return 1;} int pvdata(int argc, char **argv) {return 1;} int pvmove(int argc, char **argv) {return 1;} -int vgimport(int argc, char **argv) {return 1;} int vgmknodes(int argc, char **argv) {return 1;} int vgsplit(int argc, char **argv) {return 1;} diff --git a/tools/toollib.c b/tools/toollib.c index 19bd5afc6..20c082a80 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -8,7 +8,7 @@ #include -int check_dir(const char *dir) +int dir_exists(const char *dir) { struct stat info; diff --git a/tools/toollib.h b/tools/toollib.h index 337fee796..98ca5e30b 100644 --- a/tools/toollib.h +++ b/tools/toollib.h @@ -45,6 +45,8 @@ int process_each_lv_in_vg(struct volume_group *vg, int (*process_single) (struct logical_volume * lv)); int is_valid_chars(char *n); +int dir_exists(const char *dir); + char *default_vgname(struct format_instance *fi); char *extract_vgname(struct format_instance *fi, char *lv_name); diff --git a/tools/vgcreate.c b/tools/vgcreate.c index 66cc55461..403a415de 100644 --- a/tools/vgcreate.c +++ b/tools/vgcreate.c @@ -67,7 +67,7 @@ int vgcreate(int argc, char **argv) vg_name += strlen(fid->cmd->dev_dir); snprintf(vg_path, PATH_MAX, "%s%s", fid->cmd->dev_dir, vg_name); - if (!check_dir(vg_path)) return ECMD_FAILED; + if (!dir_exists(vg_path)) return ECMD_FAILED; if (!is_valid_chars(vg_name)) { log_error("New volume group name '%s' has invalid characters", diff --git a/tools/vgexport.c b/tools/vgexport.c index 9ece85a13..2c55af95d 100644 --- a/tools/vgexport.c +++ b/tools/vgexport.c @@ -24,6 +24,16 @@ static int vgexport_single(const char *vg_name); int vgexport(int argc, char **argv) { + if (!argc && !arg_count(all_ARG)) { + log_error("Please supply volume groups or use -a for all."); + return ECMD_FAILED; + } + + if (argc && arg_count(all_ARG)) { + log_error("No arguments permitted when using -a for all."); + return ECMD_FAILED; + } + return process_each_vg(argc, argv, &vgexport_single); }