From abe198c0e8a99de8c330c7a571b839fe0720f0cf Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Tue, 3 May 2005 17:31:56 +0000 Subject: [PATCH] Don't create backup and archive dirs till needed. --- WHATS_NEW | 1 + lib/device/dev-cache.c | 30 ++++++++++++------------------ lib/format_text/archive.c | 6 +++--- tools/archiver.c | 12 ++++++------ 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 8dd7d2e7f..9a88255ae 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.01.10 - ================================ + Don't create backup and archive dirs till needed. Reinstate full PV size when removing from VG. Support loopfiles for testing. Tidy lv_segment interface. diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c index e9cc34510..1f2d31784 100644 --- a/lib/device/dev-cache.c +++ b/lib/device/dev-cache.c @@ -49,7 +49,6 @@ static struct { } _cache; #define _alloc(x) pool_zalloc(_cache.mem, (x)) -#define _strdup(x) pool_strdup(_cache.mem, (x)) #define _free(x) pool_free(_cache.mem, (x)) static int _insert(const char *path, int rec); @@ -70,14 +69,7 @@ struct device *dev_create_file(const char *filename, struct device *dev, dbg_free(dev); return NULL; } - if (!(alias->str = dbg_strdup(filename))) { - log_error("filename strdup failed"); - if (allocate) { - dbg_free(dev); - dbg_free(alias); - } - return NULL; - } + dev->flags = DEV_ALLOCED; } else { if (!(dev = _alloc(sizeof(*dev)))) { @@ -86,19 +78,21 @@ struct device *dev_create_file(const char *filename, struct device *dev, } if (!(alias = _alloc(sizeof(*alias)))) { log_error("struct str_list allocation failed"); - dbg_free(dev); - return NULL; - } - if (!(alias->str = _strdup(filename))) { - log_error("filename strdup failed"); - if (allocate) { - dbg_free(dev); - dbg_free(alias); - } + _free(dev); return NULL; } } } + + if (!(alias->str = dbg_strdup(filename))) { + log_error("filename strdup failed"); + if (allocate && use_malloc) { + dbg_free(dev); + dbg_free(alias); + } + return NULL; + } + dev->flags |= DEV_REGULAR; list_init(&dev->aliases); list_add(&dev->aliases, &alias->list); diff --git a/lib/format_text/archive.c b/lib/format_text/archive.c index 2075e4869..3f1b09f19 100644 --- a/lib/format_text/archive.c +++ b/lib/format_text/archive.c @@ -148,7 +148,7 @@ static struct list *_scan_archive(struct pool *mem, /* Sort fails beyond 5-digit indexes */ if ((count = scandir(dir, &dirent, NULL, alphasort)) < 0) { - log_err("Couldn't scan archive directory."); + log_err("Couldn't scan the archive directory (%s).", dir); return 0; } @@ -273,7 +273,7 @@ int archive_vg(struct volume_group *vg, * Now we want to rename this file to _index.vg. */ if (!(archives = _scan_archive(vg->cmd->mem, vg->name, dir))) { - log_err("Couldn't scan the archive directory (%s).", dir); + stack; return 0; } @@ -349,7 +349,7 @@ int archive_list(struct cmd_context *cmd, const char *dir, const char *vgname) struct archive_file *af; if (!(archives = _scan_archive(cmd->mem, vgname, dir))) { - log_err("Couldn't scan the archive directory (%s).", dir); + stack; return 0; } diff --git a/tools/archiver.c b/tools/archiver.c index acf48c96f..c18350cb4 100644 --- a/tools/archiver.c +++ b/tools/archiver.c @@ -36,9 +36,6 @@ int archive_init(const char *dir, unsigned int keep_days, unsigned int keep_min) if (!*dir) return 1; - if (!create_dir(dir)) - return 0; - if (!(_archive_params.dir = dbg_strdup(dir))) { log_error("Couldn't copy archive directory name."); return 0; @@ -106,6 +103,9 @@ int archive(struct volume_group *vg) return 1; } + if (!create_dir(_archive_params.dir)) + return 0; + log_verbose("Archiving volume group \"%s\" metadata.", vg->name); if (!__archive(vg)) { log_error("Volume group \"%s\" metadata archive failed.", @@ -134,9 +134,6 @@ int backup_init(const char *dir) if (!*dir) return 1; - if (!create_dir(dir)) - return 0; - if (!(_backup_params.dir = dbg_strdup(dir))) { log_error("Couldn't copy backup directory name."); return 0; @@ -189,6 +186,9 @@ int backup(struct volume_group *vg) return 1; } + if (!create_dir(_backup_params.dir)) + return 0; + if (!__backup(vg)) { log_error("Backup of volume group %s metadata failed.", vg->name);