From fb9d44daf1bc24fe1038a2d0db95beb55016de1d Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Fri, 12 Aug 2005 20:02:21 +0000 Subject: [PATCH] Factor out generate_log_name_format(). --- WHATS_NEW | 2 +- tools/lvcreate.c | 18 ++---------------- tools/toollib.c | 18 ++++++++++++++++++ tools/toollib.h | 3 +++ 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 23b47e890..64dff7ea2 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,6 +1,6 @@ Version 2.01.15 - ================================= - Factor out adjusted_mirror_region_size(). + Factor out adjusted_mirror_region_size() and generate_log_name_format(). Move compose_log_line() into mirror directory. Factor out _get_library_path(). Don't kill idling clvmd threads. diff --git a/tools/lvcreate.c b/tools/lvcreate.c index 9f8b878aa..7c5c2b248 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -579,27 +579,13 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp) /* FIXME Calculate how many extents needed for the log */ len = strlen(lv_name) + 32; - if (!(log_name = alloca(len))) { + if (!(log_name = alloca(len)) || + !(generate_log_name_format(vg, lv_name, log_name, len))) { log_error("log_name allocation failed. " "Remove new LV and retry."); return 0; } - if (lvm_snprintf(log_name, len, "%s_mlog", lv_name) < 0) { - log_error("log_name allocation failed. " - "Remove new LV and retry."); - return 0; - } - - if (find_lv_in_vg(vg, log_name)) { - if (lvm_snprintf(log_name, len, "%s_mlog_%%d", - lv_name) < 0) { - log_error("log_name allocation failed. " - "Remove new LV and retry."); - return 0; - } - } - if (!(log_lv = lv_create_empty(vg->fid, log_name, NULL, VISIBLE_LV | LVM_READ | LVM_WRITE, lp->alloc, 0, vg))) { diff --git a/tools/toollib.c b/tools/toollib.c index 14c3dcbc9..f9239ceba 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -1058,6 +1058,24 @@ int validate_vg_name(struct cmd_context *cmd, const char *vg_name) return 1; } +int generate_log_name_format(struct volume_group *vg, const char *lv_name, + char *buffer, size_t size) +{ + if (lvm_snprintf(buffer, size, "%s_mlog", lv_name) < 0) { + stack; + return 0; + } + + if (find_lv_in_vg(vg, buffer) && + lvm_snprintf(buffer, size, "%s_mlog_%%d", + lv_name) < 0) { + stack; + return 0; + } + + return 1; +} + /* * Volumes may be zeroed to remove old application data. */ diff --git a/tools/toollib.h b/tools/toollib.h index 8001eac34..65ccaa667 100644 --- a/tools/toollib.h +++ b/tools/toollib.h @@ -94,6 +94,9 @@ int apply_lvname_restrictions(const char *name); int validate_vg_name(struct cmd_context *cmd, const char *vg_name); +int generate_log_name_format(struct volume_group *vg, const char *lv_name, + char *buffer, size_t size); + int zero_lv(struct cmd_context *cmd, struct logical_volume *lv); #endif