From 5b7d1629470e3ae81cd674c2af495f6ec9262b6e Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Tue, 17 Jul 2007 16:13:12 +0000 Subject: [PATCH] Fix snapshot cow area deactivation if origin is not active. (2.02.13) --- WHATS_NEW | 1 + tools/lvcreate.c | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/WHATS_NEW b/WHATS_NEW index 56f579e93..a00c3b7c4 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.27 - ================================ + Fix snapshot cow area deactivation if origin is not active. (2.02.13) Fix configure libdevmapper.h check when --with-dmdir is used. Turn _add_pv_to_vg() into external library function add_pv_to_vg(). Add pv_by_path() external library function. diff --git a/tools/lvcreate.c b/tools/lvcreate.c index 4da683fa1..7cc8302a2 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -478,10 +478,11 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp) struct logical_volume *lv, *org = NULL, *log_lv = NULL; struct list *pvh, tags; const char *tag = NULL; - int consistent = 1; + int consistent = 1, origin_active = 0; struct alloc_handle *ah = NULL; char lv_name_buf[128]; const char *lv_name; + struct lvinfo info; status |= lp->permission | VISIBLE_LV; @@ -615,6 +616,13 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp) /* Must zero cow */ status |= LVM_WRITE; + + if (!lv_info(cmd, org, &info, 0)) { + log_error("Check for existence of snapshot origin " + "'%s' failed.", org->name); + return 0; + } + origin_active = info.exists; } if (!lp->extents) { @@ -792,6 +800,13 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp) if (!(lp->permission & LVM_WRITE)) lv->status &= ~LVM_WRITE; + /* COW area must be deactivated if origin is not active */ + if (!origin_active && !deactivate_lv(cmd, lv)) { + log_error("Aborting. Couldn't deactivate snapshot " + "COW area."); + return 0; + } + /* cow LV remains active and becomes snapshot LV */ if (!vg_add_snapshot(vg->fid, NULL, org, lv, NULL,