From patchwork Fri Feb 26 23:36:19 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonthan Brassow X-Patchwork-Id: 82506 Received: from mx02.colomx.prod.int.phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o1QNgW57015561 for ; Fri, 26 Feb 2010 23:43:11 GMT Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx02.colomx.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o1QNeTEP026837; Fri, 26 Feb 2010 18:40:29 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o1QNaQSK021702 for ; Fri, 26 Feb 2010 18:36:26 -0500 Received: from hydrogen.msp.redhat.com (hydrogen.msp.redhat.com [10.15.80.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o1QNaJ4q025948 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 26 Feb 2010 18:36:20 -0500 Received: from hydrogen.msp.redhat.com (localhost.localdomain [127.0.0.1]) by hydrogen.msp.redhat.com (8.14.1/8.14.1) with ESMTP id o1QNaJ21024278 for ; Fri, 26 Feb 2010 17:36:19 -0600 Received: (from jbrassow@localhost) by hydrogen.msp.redhat.com (8.14.1/8.14.1/Submit) id o1QNaJwv024277 for dm-devel@redhat.com; Fri, 26 Feb 2010 17:36:19 -0600 Date: Fri, 26 Feb 2010 17:36:19 -0600 From: Jonathan Brassow Message-Id: <201002262336.o1QNaJwv024277@hydrogen.msp.redhat.com> To: dm-devel@redhat.com X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-loop: dm-devel@redhat.com Subject: [dm-devel] [PATCH 4 of 10] LVM: add logic to allow mirrored log X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 26 Feb 2010 23:43:11 +0000 (UTC) Index: LVM2/lib/metadata/mirror.c =================================================================== --- LVM2.orig/lib/metadata/mirror.c +++ LVM2/lib/metadata/mirror.c @@ -1591,7 +1591,7 @@ static struct logical_volume *_set_up_mi struct alloc_handle *ah, struct logical_volume *lv, uint32_t log_count, - uint32_t region_size __attribute((unused)), + uint32_t region_size, alloc_policy_t alloc, int in_sync) { @@ -1635,6 +1635,12 @@ static struct logical_volume *_set_up_mi return NULL; } + if ((log_count > 1) && + !_form_mirror(cmd, ah, log_lv, log_count-1, region_size)) { + log_error("Failed to form mirrored log."); + return NULL; + } + if (!_init_mirror_log(cmd, log_lv, in_sync, &lv->tags, 1)) { log_error("Failed to initialise mirror log."); return NULL; Index: LVM2/tools/lvconvert.c =================================================================== --- LVM2.orig/tools/lvconvert.c +++ LVM2/tools/lvconvert.c @@ -647,9 +647,24 @@ static void _lvconvert_mirrors_repair_as } } -static int _using_corelog(struct logical_volume *lv) +/* + * _get_log_count + * @lv: the mirror LV + * + * Get the number of on-disk copies of the log. + * 0 = 'core' + * 1 = 'disk' + * 2+ = 'mirrored' + */ +static int _get_log_count(struct logical_volume *lv) { - return !first_seg(_original_lv(lv))->log_lv; + struct logical_volume *log_lv; + + log_lv = first_seg(_original_lv(lv))->log_lv; + if (!log_lv) + return 0; + + return lv_mirror_count(log_lv); } static int _lv_update_log_type(struct cmd_context *cmd, @@ -657,21 +672,48 @@ static int _lv_update_log_type(struct cm struct logical_volume *lv, int log_count) { - struct logical_volume *original_lv = _original_lv(lv); - if (_using_corelog(lv) && log_count) { + uint32_t region_size; + int old_log_count; + struct logical_volume *original_lv; + struct logical_volume *log_lv; + + old_log_count = _get_log_count(lv); + if (old_log_count == log_count) + return 1; + + original_lv = _original_lv(lv); + region_size = adjusted_mirror_region_size(lv->vg->extent_size, + lv->le_count, + lp->region_size); + + /* Add a log where there is none */ + if (!old_log_count) { if (!add_mirror_log(cmd, original_lv, log_count, - adjusted_mirror_region_size( - lv->vg->extent_size, - lv->le_count, - lp->region_size), - lp->pvh, lp->alloc)) + region_size, lp->pvh, lp->alloc)) return_0; - } else if (!_using_corelog(lv) && !log_count) { + return 1; + } + + /* Remove an existing log completely */ + if (!log_count) { if (!remove_mirror_log(cmd, original_lv, lp->pv_count ? lp->pvh : NULL)) return_0; + return 1; + } + + log_lv = first_seg(original_lv)->log_lv; + + /* Adding redundancy to the log */ + if (old_log_count < log_count) { + log_error("Adding log redundancy not supported yet."); + log_error("Try converting the log to 'core' first."); + return_0; } - return 1; + + /* Reducing redundancy of the log */ + return remove_mirror_images(log_lv, log_count, + lp->pv_count ? lp->pvh : NULL, 1U); } /* @@ -718,7 +760,7 @@ static int _lvconvert_mirrors(struct cmd struct lv_segment *seg; uint32_t existing_mirrors; const char *mirrorlog; - unsigned log_count = 1; + unsigned log_count = _get_log_count(lv); int r = 0; struct logical_volume *log_lv, *layer_lv; int failed_mirrors = 0, failed_log = 0; @@ -776,8 +818,7 @@ static int _lvconvert_mirrors(struct cmd if ((existing_mirrors > 1) && (lp->mirrors > 1) && (lp->mirrors != existing_mirrors) && !(lv->status & CONVERTING) && !arg_count(cmd, mirrorlog_ARG) && !arg_count(cmd, corelog_ARG)) { - log_count = (first_seg(lv)->log_lv) ? - lv_mirror_count(first_seg(lv)->log_lv) : 0; + log_count = _get_log_count(lv); } if (repair) { @@ -798,9 +839,15 @@ static int _lvconvert_mirrors(struct cmd return_0; lp->pvh = lp->failed_pvs = failed_pvs; log_lv = first_seg(lv)->log_lv; - if (!log_lv || log_lv->status & PARTIAL_LV) { + if (!log_lv) { failed_log = 1; log_count = 0; + } else { + log_count = lv_mirror_count(log_lv); + if (log_lv->status & PARTIAL_LV) { + failed_log = 1; + log_count -= _failed_mirrors_count(log_lv); + } } } else { /* @@ -992,7 +1039,7 @@ static int _lvconvert_mirrors(struct cmd } if (lp->mirrors == existing_mirrors) { - if (_using_corelog(lv) != !log_count) { + if (_get_log_count(lv) != log_count) { if (!_lv_update_log_type(cmd, lp, lv, log_count)) { stack; return failure_code;