1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

Add archiving.

This commit is contained in:
Alasdair Kergon 2002-01-09 13:17:14 +00:00
parent 89f1e3ddf0
commit 614a4508e6
15 changed files with 95 additions and 24 deletions

View File

@ -9,6 +9,7 @@
#include "dbg_malloc.h"
#include "format-text.h"
#include "lvm-string.h"
#include "toollib.h"
#include <limits.h>
@ -23,8 +24,16 @@ static struct {
int archive_init(const char *dir,
unsigned int keep_days, unsigned int keep_min)
{
_archive_params.dir = NULL;
if (!*dir)
return 1;
if (!create_dir(dir))
return 0;
if (!(_archive_params.dir = dbg_strdup(dir))) {
log_err("Couldn't create copy of archive dir.");
log_error("Couldn't copy archive directory name.");
return 0;
}
@ -36,6 +45,7 @@ int archive_init(const char *dir,
void archive_exit(void)
{
if (_archive_params.dir)
dbg_free(_archive_params.dir);
memset(&_archive_params, 0, sizeof(_archive_params));
}
@ -67,7 +77,7 @@ static int __archive(struct volume_group *vg)
int archive(struct volume_group *vg)
{
if (!_archive_params.enabled)
if (!_archive_params.enabled || !_archive_params.dir)
return 1;
if (test_mode()) {
@ -75,9 +85,10 @@ int archive(struct volume_group *vg)
return 1;
}
log_print("Creating archive of volume group '%s' ...", vg->name);
log_verbose("Archiving volume group %s metadata.", vg->name);
if (!__archive(vg)) {
log_error("Archiving failed.");
log_error("Volume group %s metadata archive failed.",
vg->name);
return 0;
}
@ -94,8 +105,15 @@ static struct {
int backup_init(const char *dir)
{
_backup_params.dir = NULL;
if (!*dir)
return 1;
if (!create_dir(dir))
return 0;
if (!(_backup_params.dir = dbg_strdup(dir))) {
log_err("Couldn't create copy of backup dir.");
log_error("Couldn't copy backup directory name.");
return 0;
}
@ -104,6 +122,7 @@ int backup_init(const char *dir)
void backup_exit(void)
{
if (_backup_params.dir)
dbg_free(_backup_params.dir);
memset(&_backup_params, 0, sizeof(_backup_params));
}
@ -121,12 +140,15 @@ static int __backup(struct volume_group *vg)
if (lvm_snprintf(name, sizeof(name), "%s/%s",
_backup_params.dir, vg->name) < 0) {
log_err("Couldn't generate backup filename for volume group.");
log_error("Failed to generate volume group metadata backup "
"filename.");
return 0;
}
log_verbose("Creating volume group backup %s", name);
if (!(tf = text_format_create(vg->cmd, name))) {
log_error("Couldn't create backup object.");
stack;
return 0;
}
@ -139,18 +161,19 @@ static int __backup(struct volume_group *vg)
int backup(struct volume_group *vg)
{
if (!_backup_params.enabled)
if (!_backup_params.enabled || !_backup_params.dir) {
log_print("WARNING: This metadata update is NOT backed up");
return 1;
}
if (test_mode()) {
log_print("Test mode: Skipping volume group backup.");
return 1;
}
log_print("Creating backup of volume group '%s' ...", vg->name);
if (!__backup(vg)) {
log_error("Backup failed.");
log_error("Backup of volume group %s metadata failed.",
vg->name);
return 0;
}

View File

@ -67,6 +67,9 @@ static int lvchange_single(struct logical_volume *lv)
return ECMD_FAILED;
}
if (!archive(lv->vg))
return 0;
/* access permission change */
if (arg_count(permission_ARG))
doit += lvchange_permission(lv);
@ -116,6 +119,7 @@ static int lvchange_permission(struct logical_volume *lv)
log_verbose("Setting logical volume %s read-only", lv->name);
}
log_very_verbose("Updating logical volume %s on disk(s)", lv->name);
if (!fid->ops->vg_write(fid, lv->vg))
return 0;

View File

@ -212,6 +212,9 @@ int lvcreate(int argc, char **argv)
extents = extents - size_rest + stripes;
}
if (!archive(vg))
return ECMD_FAILED;
if (!(lv = lv_create(lv_name, status, stripes, stripesize, extents,
vg, pvh)))
return ECMD_FAILED;

View File

@ -681,15 +681,19 @@ static void __init_log(struct config_file *cf)
_default_settings.test = find_config_int(cf->root, "log/test", '/', 0);
}
/*
* '_sys_dir' must have been set before calling this.
*/
static int _init_backup(struct config_file *cf)
{
int days, min;
char default_dir[PATH_MAX];
const char *dir;
if (!_sys_dir) {
log_warn("WARNING: Metadata changes will NOT be backed up");
backup_init("");
archive_init("", 0, 0);
return 1;
}
/* set up archiving */
_default_settings.archive =
find_config_bool(cmd->cf->root, "backup/archive", '/',

View File

@ -67,6 +67,9 @@ static int lvremove_single(struct logical_volume *lv)
}
}
if (!archive(vg))
return ECMD_FAILED;
if (!lv_deactivate(lv)) {
log_error("Unable to deactivate logical volume %s", lv->name);
}

View File

@ -111,6 +111,9 @@ int lvrename(int argc, char **argv)
lv = &list_item(lvh, struct lv_list)->lv;
if (!archive(lv->vg))
return ECMD_FAILED;
if (!(lv->name = pool_strdup(fid->cmd->mem, lv_name_new))) {
log_error("Failed to allocate space for new name");
return ECMD_FAILED;

View File

@ -296,6 +296,9 @@ int lvresize(int argc, char **argv)
}
}
if (!archive(vg))
return ECMD_FAILED;
if (!lv_reduce(lv, lv->le_count - extents))
return ECMD_FAILED;
}
@ -326,6 +329,9 @@ int lvresize(int argc, char **argv)
}
if (resize == LV_EXTEND) {
if (!archive(vg))
return ECMD_FAILED;
if (!argc) {
/* Use full list from VG */
pvh = &vg->pvs;

View File

@ -103,6 +103,8 @@ int pvchange_single(struct physical_volume *pv)
return 0;
}
pv = &list_item(pvh, struct pv_list)->pv;
if (!archive(vg))
return 0;
}
/* change allocatability for a PV */

View File

@ -56,22 +56,18 @@ static int vgchange_single(const char *vg_name)
return ECMD_FAILED;
}
if (vg->status & EXPORTED_VG) {
if (vg->status & EXPORTED_VG)
log_error("Volume group %s is exported", vg_name);
return ECMD_FAILED;
}
if (arg_count(available_ARG)) {
if (arg_count(available_ARG))
vgchange_available(vg);
}
if (arg_count(allocation_ARG)) {
if (arg_count(allocation_ARG))
vgchange_allocation(vg);
}
if (arg_count(logicalvolume_ARG)) {
if (arg_count(logicalvolume_ARG))
vgchange_logicalvolume(vg);
}
return 0;
}
@ -102,6 +98,9 @@ void vgchange_available(struct volume_group *vg)
log_verbose("%d logical volume(s) in volume group %s "
"already active", lv_active, vg->name);
if (!archive(vg))
return;
if (available) {
vg->status |= ACTIVE;
list_iterate(lvh, &vg->lvs)
@ -147,6 +146,9 @@ void vgchange_allocation(struct volume_group *vg)
return;
}
if (!archive(vg))
return;
if (extendable)
vg->status |= EXTENDABLE_VG;
else
@ -202,6 +204,9 @@ void vgchange_logicalvolume(struct volume_group *vg)
}
****************/
if (!archive(vg))
return;
vg->max_lv = max_lv;
if (!fid->ops->vg_write(fid, vg))

View File

@ -84,6 +84,9 @@ int vgcreate(int argc, char **argv)
log_error("Warning: Setting maxphysicalvolumes to %d",
vg->max_pv);
if (!archive(vg))
return ECMD_FAILED;
/* Store VG on disk(s) */
if (!fid->ops->vg_write(fid, vg))
return ECMD_FAILED;

View File

@ -63,6 +63,9 @@ int vgextend(int argc, char **argv)
dummy = NULL;
**********/
if (!archive(vg))
return ECMD_FAILED;
/* extend vg */
if (!vg_extend(fid, vg, argc, argv))
return ECMD_FAILED;

View File

@ -112,6 +112,9 @@ int vgmerge_single(const char *vg_name_to, const char *vg_name_from)
/* FIXME List arg: vg_show_with_pv_and_lv(vg_to); */
if (!archive(vg_from) || !archive(vg_to))
return ECMD_FAILED;
/* Merge volume groups */
while (!list_empty(&vg_from->pvs)) {
struct list *pvh = vg_from->pvs.n;

View File

@ -111,6 +111,9 @@ static int vgreduce_single(struct volume_group *vg, struct physical_volume *pv)
pvh = find_pv_in_vg(vg, name);
if (!archive(vg))
return ECMD_FAILED;
log_verbose("Removing %s from volume group %s", name, vg->name);
list_del(pvh);
*pv->vg_name = '\0';

View File

@ -53,6 +53,9 @@ static int vgremove_single(const char *vg_name)
return ECMD_FAILED;
}
if (!archive(vg))
return ECMD_FAILED;
/************ FIXME
if (vg_remove_dir_and_group_and_nodes(vg_name) < 0) {
log_error("removing special files of volume group %s",

View File

@ -87,6 +87,9 @@ int vgrename(int argc, char **argv)
return ECMD_FAILED;
}
if (!archive(vg_old))
return ECMD_FAILED;
/* Change the volume group name */
strcpy(vg_old->name, vg_name_new);