mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
o Add autobackup support to tools (follows most vg_write calls).
o Skip autobackup when in test mode. o Set test mode from config file. o Create system/backup dirs if not present (unless LVM_SYSTEM_DIR holds "").
This commit is contained in:
parent
129c5d50a1
commit
cc21948339
@ -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() {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
49
tools/lvm.c
49
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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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",
|
||||
|
@ -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))
|
||||
{
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user