diff options
-rw-r--r-- | lib/log/log.c | 2 | ||||
-rw-r--r-- | tools/lvchange.c | 9 | ||||
-rw-r--r-- | tools/lvcreate.c | 8 | ||||
-rw-r--r-- | tools/lvm.c | 49 | ||||
-rw-r--r-- | tools/lvremove.c | 5 | ||||
-rw-r--r-- | tools/lvrename.c | 4 | ||||
-rw-r--r-- | tools/lvresize.c | 7 | ||||
-rw-r--r-- | tools/pvchange.c | 6 | ||||
-rw-r--r-- | tools/toollib.c | 35 | ||||
-rw-r--r-- | tools/toollib.h | 2 | ||||
-rw-r--r-- | tools/vgchange.c | 13 | ||||
-rw-r--r-- | tools/vgcreate.c | 2 | ||||
-rw-r--r-- | tools/vgextend.c | 9 | ||||
-rw-r--r-- | tools/vgmerge.c | 2 | ||||
-rw-r--r-- | tools/vgreduce.c | 2 | ||||
-rw-r--r-- | tools/vgremove.c | 2 | ||||
-rw-r--r-- | tools/vgrename.c | 5 |
17 files changed, 101 insertions, 61 deletions
diff --git a/lib/log/log.c b/lib/log/log.c index 60510421..5107a582 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -39,6 +39,8 @@ void init_verbose(int level) { void init_test(int level) { _test = level; + if (_test) + log_print("Test mode. Metadata will NOT be updated."); } int test_mode() { diff --git a/tools/lvchange.c b/tools/lvchange.c index 796201b2..69c6a2e4 100644 --- a/tools/lvchange.c +++ b/tools/lvchange.c @@ -89,8 +89,6 @@ static int lvchange_single(struct logical_volume *lv) log_print("Logical volume %s changed", lv->name); - /* FIXME autobackup */ - return 0; } @@ -122,6 +120,8 @@ static int lvchange_permission(struct logical_volume *lv) if (!fid->ops->vg_write(fid, lv->vg)) return 0; + autobackup(lv->vg); + log_very_verbose("Updating permissions for %s in kernel", lv->name); if (!lv_update_write_access(lv)) return 0; @@ -158,6 +158,7 @@ static int lvchange_availability(struct logical_volume *lv) lv->name); if (!fid->ops->vg_write(fid, lv->vg)) return 0; + autobackup(lv->vg); } if ((lv_stat & ACTIVE) && (active & ACTIVE)) @@ -221,6 +222,8 @@ static int lvchange_contiguous(struct logical_volume *lv) if (!fid->ops->vg_write(fid, lv->vg)) return 0; + autobackup(lv->vg); + return 1; } @@ -251,5 +254,7 @@ static int lvchange_readahead(struct logical_volume *lv) if (!fid->ops->vg_write(fid, lv->vg)) return 0; + autobackup(lv->vg); + return 1; } diff --git a/tools/lvcreate.c b/tools/lvcreate.c index c2064704..a941d337 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -6,6 +6,7 @@ */ #include "tools.h" + #include <fcntl.h> int lvcreate(int argc, char **argv) @@ -224,6 +225,8 @@ int lvcreate(int argc, char **argv) if (!fid->ops->vg_write(fid, vg)) return ECMD_FAILED; + autobackup(vg); + log_print("Logical volume %s created", lv->name); if (!lv_activate(lv)) @@ -259,10 +262,5 @@ int lvcreate(int argc, char **argv) } else log_print("WARNING: %s not zeroed", lv->name); -/******** FIXME backup - if ((ret = do_autobackup(vg_name, vg))) - return ret; -***********/ - return 0; } diff --git a/tools/lvm.c b/tools/lvm.c index f921508a..f8261b62 100644 --- a/tools/lvm.c +++ b/tools/lvm.c @@ -65,6 +65,9 @@ static int _debug; static int _default_verbose; static int _verbose; +static int _default_test; +static int _test; + /* * The lvm_sys_dir contains: * @@ -509,31 +512,22 @@ static int process_common_commands(struct command *com) if (arg_count(suspend_ARG)) kill(getpid(), SIGSTOP); - /* - * debug - */ _debug = _default_debug; if (arg_count(debug_ARG)) _debug = arg_count(debug_ARG); - /* - * verbose - */ _verbose = _default_verbose; if (arg_count(verbose_ARG)) _verbose = arg_count(verbose_ARG); - if (arg_count(quiet_ARG)) { _debug = 0; _verbose = 0; } - - if ((l = arg_count(test_ARG))) { - log_error("Test mode. Metadata will NOT be updated."); - init_test(l); - } + _test = _default_test; + if (arg_count(test_ARG)) + _test = arg_count(test_ARG); if (arg_count(help_ARG)) { usage(com->name); @@ -602,6 +596,7 @@ static int run_command(int argc, char **argv) init_debug(_debug); init_verbose(_verbose); + init_test(_test); ret = the_command->fn(argc, argv); @@ -611,6 +606,7 @@ static int run_command(int argc, char **argv) */ init_debug(_default_debug); init_verbose(_default_verbose); + init_test(_default_test); /* * free off any memory the command used. @@ -674,6 +670,9 @@ static void __init_log(struct config_file *cf) _default_verbose = find_config_int(cf->root, "log/verbose", '/', 0); init_verbose(_default_verbose); + + _default_test = find_config_int(cf->root, "log/test", '/', 0); + init_test(_default_test); } static int dev_cache_setup(struct config_file *cf) @@ -772,6 +771,9 @@ static struct dev_filter *filter_setup(struct config_file *cf) if (find_config_int(cf->root, "devices/write_cache_state", '/', 1)) _dump_filter = 1; + if (!*_sys_dir) + _dump_filter = 0; + if (!stat(lvm_cache, &st) && !persistent_filter_load(f4)) log_verbose("Failed to load existing device cache from %s", lvm_cache); @@ -783,6 +785,7 @@ static int _get_env_vars(void) { const char *e; + /* Set to "" to avoid using any system directory */ if ((e = getenv("LVM_SYSTEM_DIR"))) { if (lvm_snprintf(_sys_dir, sizeof(_sys_dir), "%s", e) < 0) { log_error("LVM_SYSTEM_DIR environment variable " @@ -797,11 +800,15 @@ static int _get_env_vars(void) static int init(void) { struct stat info; - char config_file[PATH_MAX]; + char config_file[PATH_MAX] = ""; if (!_get_env_vars()) return 0; + /* Create system directory if it doesn't already exist */ + if (!create_dir(_sys_dir)) + return 0; + if (!(cmd = dbg_malloc(sizeof(*cmd)))) { log_error("Failed to allocate command context"); return 0; @@ -818,8 +825,8 @@ static int init(void) /* send log messages to stderr for now */ init_log(stderr); - if (lvm_snprintf(config_file, sizeof(config_file), - "%s/lvm.conf", _sys_dir) < 0) { + if (*_sys_dir && lvm_snprintf(config_file, sizeof(config_file), + "%s/lvm.conf", _sys_dir) < 0) { log_error("lvm_sys_dir was too long"); return 0; } @@ -847,13 +854,19 @@ static int init(void) dm_log_init(print_log); - if (lvm_snprintf(_backup_dir, sizeof(_backup_dir), "%s/backup", - find_config_str(cmd->cf->root, "backup/dir", - '/', _sys_dir)) < 0) { + if (!*strncpy(_backup_dir, + find_config_str(cmd->cf->root, "backup/dir", '/', ""), + sizeof(_backup_dir)) && + *_sys_dir && + lvm_snprintf(_backup_dir, sizeof(_backup_dir), "%s/backup", + _sys_dir) < 0) { log_error("Backup directory given in config file too long"); return 0; } + if (!create_dir(_backup_dir)) + return 0; + _backup_days = find_config_int(cmd->cf->root, "backup/days", '/', _backup_days); diff --git a/tools/lvremove.c b/tools/lvremove.c index 5c474547..6b9cf7d4 100644 --- a/tools/lvremove.c +++ b/tools/lvremove.c @@ -87,10 +87,7 @@ static int lvremove_single(struct logical_volume *lv) if (!fid->ops->vg_write(fid, vg)) return ECMD_FAILED; -/******** FIXME - if ((ret = do_autobackup(vg->name, vg))) - return ret; -**********/ + autobackup(vg); log_print("logical volume %s successfully removed", lv->name); return 0; diff --git a/tools/lvrename.c b/tools/lvrename.c index f82da5f5..6fb6bbb5 100644 --- a/tools/lvrename.c +++ b/tools/lvrename.c @@ -122,11 +122,11 @@ int lvrename(int argc, char **argv) return ECMD_FAILED; } + autobackup(lv->vg); + /* FIXME Update symlink. */ lv_reactivate(lv); - /* FIXME backup */ - log_print("Renamed %s to %s in volume group %s%s", lv_name_old, lv_name_new, fid->cmd->dev_dir, vg_name); diff --git a/tools/lvresize.c b/tools/lvresize.c index 8f685734..c05cc0dc 100644 --- a/tools/lvresize.c +++ b/tools/lvresize.c @@ -345,17 +345,14 @@ int lvresize(int argc, char **argv) if (!fid->ops->vg_write(fid, vg)) return ECMD_FAILED; + autobackup(vg); + /* FIXME Ensure it always displays errors? */ if (!lv_reactivate(lv)) return ECMD_FAILED; /********* FIXME Resume *********/ -/********* FIXME Backup - if ((ret = do_autobackup(vg_name, vg))) - return ret; -************/ - log_print("Logical volume %s successfully resized", lv_name); return 0; diff --git a/tools/pvchange.c b/tools/pvchange.c index 487aec2d..2e403914 100644 --- a/tools/pvchange.c +++ b/tools/pvchange.c @@ -73,11 +73,6 @@ int pvchange(int argc, char **argv) } } -/******* FIXME Backup - if ((ret = do_autobackup(vg_name, vg))) - return ret; -*********/ - log_print("%d physical volume(s) changed / %d physical volume(s) " "not changed", done, total - done); @@ -144,6 +139,7 @@ int pvchange_single(struct physical_volume *pv) "volume group %s", pv_name, vg->name); return 0; } + autobackup(vg); } else { if (!(fid->ops->pv_write(fid, pv))) { log_error("Failed to store physical volume %s", diff --git a/tools/toollib.c b/tools/toollib.c index ae6e220e..4c1ae7c3 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -6,6 +6,8 @@ #include "tools.h" +#include <sys/stat.h> + static int _autobackup; static char _backup_dir[PATH_MAX]; static int _keep_days; /* keep for at least this number of days */ @@ -87,25 +89,52 @@ static int __autobackup(struct volume_group *vg) int autobackup(struct volume_group *vg) { - if (!_autobackup) { + if (!_autobackup || !*_backup_dir) { log_print("WARNING: You don't have an automatic backup of %s", vg->name); return 1; } + if (test_mode()) { + log_print("Test mode: Skipping automatic backup"); + return 1; + } + log_print("Creating automatic backup of volume group \"%s\" ...", vg->name); if (!__autobackup(vg)) { - log_err("Autobackup failed."); + log_error("Autobackup failed."); return 0; } - log_err("Autobackup not implemented yet."); return 1; } +int create_dir(const char *dir) +{ + struct stat info; + + if (!*dir) + return 1; + + if (stat(dir, &info) < 0 ) { + log_verbose("Creating directory %s", dir); + if (!mkdir(dir, S_IRWXU)) + return 1; + log_sys_error("mkdir", dir); + return 0; + } + + if (S_ISDIR(info.st_mode)) + return 1; + + log_error("Directory %s not found", dir); + return 0; +} + + int process_each_lv_in_vg(struct volume_group *vg, int (*process_single) (struct logical_volume *lv)) { diff --git a/tools/toollib.h b/tools/toollib.h index 5a222ca8..56de8d09 100644 --- a/tools/toollib.h +++ b/tools/toollib.h @@ -26,6 +26,8 @@ int autobackup_init(const char *backup_dir, int keep_days, int keep_number, int autobackup); int autobackup(struct volume_group *vg); +int create_dir(const char *dir); + int process_each_vg(int argc, char **argv, int (*process_single) (const char *vg_name)); diff --git a/tools/vgchange.c b/tools/vgchange.c index a0c31d59..7003fa01 100644 --- a/tools/vgchange.c +++ b/tools/vgchange.c @@ -117,6 +117,8 @@ void vgchange_available(struct volume_group *vg) if (!fid->ops->vg_write(fid, vg)) return; + autobackup(vg); + if (available && (lv_open = activate_lvs_in_vg(vg))) log_verbose("Activated %d logical volumes in " "volume group %s", lv_open, vg->name); @@ -153,11 +155,9 @@ void vgchange_allocation(struct volume_group *vg) if (!fid->ops->vg_write(fid, vg)) return; - log_print("Volume group %s successfully changed", vg->name); + autobackup(vg); -/********FIXME - do_autobackup(vg->name, vg); -*********/ + log_print("Volume group %s successfully changed", vg->name); return; } @@ -207,10 +207,9 @@ void vgchange_logicalvolume(struct volume_group *vg) if (!fid->ops->vg_write(fid, vg)) return; + autobackup(vg); + log_print("Volume group %s successfully changed", vg->name); -/*******FIXME - do_autobackup(vg->name, vg); -********/ return; } diff --git a/tools/vgcreate.c b/tools/vgcreate.c index e3847b4a..84a333df 100644 --- a/tools/vgcreate.c +++ b/tools/vgcreate.c @@ -88,6 +88,8 @@ int vgcreate(int argc, char **argv) if (!fid->ops->vg_write(fid, vg)) return ECMD_FAILED; + autobackup(vg); + log_print("Volume group %s successfully created", vg->name); return 0; diff --git a/tools/vgextend.c b/tools/vgextend.c index f8d01228..57fed525 100644 --- a/tools/vgextend.c +++ b/tools/vgextend.c @@ -72,13 +72,10 @@ int vgextend(int argc, char **argv) "physical volumes", vg_name, argc); /* store vg on disk(s) */ - if (!fid->ops->vg_write(fid, vg)) - return ECMD_FAILED; + if (!fid->ops->vg_write(fid, vg)) + return ECMD_FAILED; -/********* FIXME - if ((ret = do_autobackup(vg_name, vg))) - return ret; -*********/ + autobackup(vg); log_print("Volume group '%s' successfully extended", vg_name); diff --git a/tools/vgmerge.c b/tools/vgmerge.c index b3a49043..604989ba 100644 --- a/tools/vgmerge.c +++ b/tools/vgmerge.c @@ -146,6 +146,8 @@ int vgmerge_single(const char *vg_name_to, const char *vg_name_from) /* FIXME Remove /dev/vgfrom */ + autobackup(vg_to); + log_print("Volume group %s successfully merged into %s", vg_from->name, vg_to->name); return 0; diff --git a/tools/vgreduce.c b/tools/vgreduce.c index b284c3ad..f620e0b2 100644 --- a/tools/vgreduce.c +++ b/tools/vgreduce.c @@ -130,6 +130,8 @@ static int vgreduce_single(struct volume_group *vg, struct physical_volume *pv) return ECMD_FAILED; } + autobackup(vg); + log_print("Removed %s from volume group %s", name, vg->name); return 0; diff --git a/tools/vgremove.c b/tools/vgremove.c index 7b4cdd45..a1c0d600 100644 --- a/tools/vgremove.c +++ b/tools/vgremove.c @@ -74,6 +74,8 @@ static int vgremove_single(const char *vg_name) } } + autobackup(vg); + if (!ret) log_print("Volume group %s successfully removed", vg_name); else diff --git a/tools/vgrename.c b/tools/vgrename.c index 47848e32..b4dc723e 100644 --- a/tools/vgrename.c +++ b/tools/vgrename.c @@ -120,10 +120,7 @@ int vgrename(int argc, char **argv) /******* FIXME Any LV things to update? */ -/*********** - if ((ret = do_autobackup(vg_name_new, vg_old))) - return ECMD_FAILED; -**********/ + autobackup(vg_old); log_print("Volume group %s successfully renamed to %s", vg_name_old, vg_name_new); |