public inbox for lvm2-cvs@sourceware.org help / color / mirror / Atom feed
From: agk@sourceware.org To: lvm-devel@redhat.com, lvm2-cvs@sourceware.org Subject: LVM2/lib/metadata mirror.c Date: Wed, 16 Jan 2008 19:09:00 -0000 [thread overview] Message-ID: <20080116190935.12526.qmail@sourceware.org> (raw) CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: agk@sourceware.org 2008-01-16 19:09:35 Modified files: lib/metadata : mirror.c Log message: reorder funcs Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/mirror.c.diff?cvsroot=lvm2&r1=1.53&r2=1.54 --- LVM2/lib/metadata/mirror.c 2008/01/16 19:00:59 1.53 +++ LVM2/lib/metadata/mirror.c 2008/01/16 19:09:35 1.54 @@ -51,6 +51,27 @@ } /* + * Return a temporary LV for resyncing added mirror image. + * Add other mirror legs to lvs list. + */ +static struct logical_volume *_find_tmp_mirror(struct logical_volume *lv) +{ + struct lv_segment *seg; + + if (!(lv->status & MIRRORED)) + return NULL; + + seg = first_seg(lv); + + /* Temporary mirror is always area_num == 0 */ + if (seg_type(seg, 0) == AREA_LV && + is_temporary_mirror_layer(seg_lv(seg, 0))) + return seg_lv(seg, 0); + + return NULL; +} + +/* * Returns the number of mirrors of the LV */ uint32_t lv_mirror_count(const struct logical_volume *lv) @@ -115,6 +136,136 @@ } /* + * This function writes a new header to the mirror log header to the lv + * + * Returns: 1 on success, 0 on failure + */ +static int _write_log_header(struct cmd_context *cmd, struct logical_volume *lv) +{ + struct device *dev; + char *name; + struct { /* The mirror log header */ + uint32_t magic; + uint32_t version; + uint64_t nr_regions; + } log_header; + + log_header.magic = xlate32(MIRROR_MAGIC); + log_header.version = xlate32(MIRROR_DISK_VERSION); + log_header.nr_regions = xlate64((uint64_t)-1); + + if (!(name = dm_pool_alloc(cmd->mem, PATH_MAX))) { + log_error("Name allocation failed - log header not written (%s)", + lv->name); + return 0; + } + + if (dm_snprintf(name, PATH_MAX, "%s%s/%s", cmd->dev_dir, + lv->vg->name, lv->name) < 0) { + log_error("Name too long - log header not written (%s)", lv->name); + return 0; + } + + log_verbose("Writing log header to device, %s", lv->name); + + if (!(dev = dev_cache_get(name, NULL))) { + log_error("%s: not found: log header not written", name); + return 0; + } + + if (!dev_open_quiet(dev)) + return 0; + + if (!dev_write(dev, UINT64_C(0), sizeof(log_header), &log_header)) { + log_error("Failed to write log header to %s", name); + dev_close_immediate(dev); + return 0; + } + + dev_close_immediate(dev); + + return 1; +} + +/* + * Initialize mirror log contents + */ +static int _init_mirror_log(struct cmd_context *cmd, + struct logical_volume *log_lv, int in_sync, + struct list *tags) +{ + struct str_list *sl; + + if (!activation() && in_sync) { + log_error("Aborting. Unable to create in-sync mirror log " + "while activation is disabled."); + return 0; + } + + /* Temporary tag mirror log for activation */ + list_iterate_items(sl, tags) + if (!str_list_add(cmd->mem, &log_lv->tags, sl->str)) { + log_error("Aborting. Unable to tag mirror log."); + return 0; + } + + /* store mirror log on disk(s) */ + if (!vg_write(log_lv->vg)) + return_0; + + backup(log_lv->vg); + + if (!vg_commit(log_lv->vg)) + return_0; + + if (!activate_lv(cmd, log_lv)) { + log_error("Aborting. Failed to activate mirror log."); + goto revert_new_lv; + } + + /* Remove the temporary tags */ + list_iterate_items(sl, tags) + if (!str_list_del(&log_lv->tags, sl->str)) + log_error("Failed to remove tag %s from mirror log.", + sl->str); + + if (activation() && !set_lv(cmd, log_lv, log_lv->size, + in_sync ? -1 : 0)) { + log_error("Aborting. Failed to wipe mirror log."); + goto deactivate_and_revert_new_lv; + } + + if (activation() && !_write_log_header(cmd, log_lv)) { + log_error("Aborting. Failed to write mirror log header."); + goto deactivate_and_revert_new_lv; + } + + if (!deactivate_lv(cmd, log_lv)) { + log_error("Aborting. Failed to deactivate mirror log. " + "Manual intervention required."); + return 0; + } + + log_lv->status &= ~VISIBLE_LV; + + return 1; + +deactivate_and_revert_new_lv: + if (!deactivate_lv(cmd, log_lv)) { + log_error("Unable to deactivate mirror log LV. " + "Manual intervention required."); + return 0; + } + +revert_new_lv: + if (!lv_remove(log_lv) || !vg_write(log_lv->vg) || + (backup(log_lv->vg), !vg_commit(log_lv->vg))) + log_error("Manual intervention may be required to remove " + "abandoned log LV before retrying."); + return 0; +} + +/* * Delete independent/orphan LV, it must acquire lock. */ static int _delete_lv(struct logical_volume *mirror_lv, struct logical_volume *lv) @@ -390,27 +541,6 @@ } /* - * Return a temporary LV for resyncing added mirror image. - * Add other mirror legs to lvs list. - */ -static struct logical_volume *_find_tmp_mirror(struct logical_volume *lv) -{ - struct lv_segment *seg; - - if (!(lv->status & MIRRORED)) - return NULL; - - seg = first_seg(lv); - - /* Temporary mirror is always area_num == 0 */ - if (seg_type(seg, 0) == AREA_LV && - is_temporary_mirror_layer(seg_lv(seg, 0))) - return seg_lv(seg, 0); - - return NULL; -} - -/* * Collapsing temporary mirror layers. * * When mirrors are added to already-mirrored LV, a temporary mirror layer @@ -926,136 +1056,6 @@ return 1; } -/* - * This function writes a new header to the mirror log header to the lv - * - * Returns: 1 on success, 0 on failure - */ -static int _write_log_header(struct cmd_context *cmd, struct logical_volume *lv) -{ - struct device *dev; - char *name; - struct { /* The mirror log header */ - uint32_t magic; - uint32_t version; - uint64_t nr_regions; - } log_header; - - log_header.magic = xlate32(MIRROR_MAGIC); - log_header.version = xlate32(MIRROR_DISK_VERSION); - log_header.nr_regions = xlate64((uint64_t)-1); - - if (!(name = dm_pool_alloc(cmd->mem, PATH_MAX))) { - log_error("Name allocation failed - log header not written (%s)", - lv->name); - return 0; - } - - if (dm_snprintf(name, PATH_MAX, "%s%s/%s", cmd->dev_dir, - lv->vg->name, lv->name) < 0) { - log_error("Name too long - log header not written (%s)", lv->name); - return 0; - } - - log_verbose("Writing log header to device, %s", lv->name); - - if (!(dev = dev_cache_get(name, NULL))) { - log_error("%s: not found: log header not written", name); - return 0; - } - - if (!dev_open_quiet(dev)) - return 0; - - if (!dev_write(dev, UINT64_C(0), sizeof(log_header), &log_header)) { - log_error("Failed to write log header to %s", name); - dev_close_immediate(dev); - return 0; - } - - dev_close_immediate(dev); - - return 1; -} - -/* - * Initialize mirror log contents - */ -static int _init_mirror_log(struct cmd_context *cmd, - struct logical_volume *log_lv, int in_sync, - struct list *tags) -{ - struct str_list *sl; - - if (!activation() && in_sync) { - log_error("Aborting. Unable to create in-sync mirror log " - "while activation is disabled."); - return 0; - } - - /* Temporary tag mirror log for activation */ - list_iterate_items(sl, tags) - if (!str_list_add(cmd->mem, &log_lv->tags, sl->str)) { - log_error("Aborting. Unable to tag mirror log."); - return 0; - } - - /* store mirror log on disk(s) */ - if (!vg_write(log_lv->vg)) - return_0; - - backup(log_lv->vg); - - if (!vg_commit(log_lv->vg)) - return_0; - - if (!activate_lv(cmd, log_lv)) { - log_error("Aborting. Failed to activate mirror log."); - goto revert_new_lv; - } - - /* Remove the temporary tags */ - list_iterate_items(sl, tags) - if (!str_list_del(&log_lv->tags, sl->str)) - log_error("Failed to remove tag %s from mirror log.", - sl->str); - - if (activation() && !set_lv(cmd, log_lv, log_lv->size, - in_sync ? -1 : 0)) { - log_error("Aborting. Failed to wipe mirror log."); - goto deactivate_and_revert_new_lv; - } - - if (activation() && !_write_log_header(cmd, log_lv)) { - log_error("Aborting. Failed to write mirror log header."); - goto deactivate_and_revert_new_lv; - } - - if (!deactivate_lv(cmd, log_lv)) { - log_error("Aborting. Failed to deactivate mirror log. " - "Manual intervention required."); - return 0; - } - - log_lv->status &= ~VISIBLE_LV; - - return 1; - -deactivate_and_revert_new_lv: - if (!deactivate_lv(cmd, log_lv)) { - log_error("Unable to deactivate mirror log LV. " - "Manual intervention required."); - return 0; - } - -revert_new_lv: - if (!lv_remove(log_lv) || !vg_write(log_lv->vg) || - (backup(log_lv->vg), !vg_commit(log_lv->vg))) - log_error("Manual intervention may be required to remove " - "abandoned log LV before retrying."); - return 0; -} - static struct logical_volume *_create_mirror_log(struct logical_volume *lv, struct alloc_handle *ah, alloc_policy_t alloc,
next reply other threads:[~2008-01-16 19:09 UTC|newest] Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top 2008-01-16 19:09 agk [this message] -- strict thread matches above, loose matches on Subject: below -- 2012-02-01 15:05 agk 2011-09-19 14:28 jbrassow 2011-09-16 16:41 jbrassow 2011-09-14 9:54 zkabelac 2011-09-14 4:10 jbrassow 2011-09-13 18:11 jbrassow 2011-06-24 23:39 agk 2011-04-12 14:13 zkabelac 2011-03-24 12:28 mornfall 2011-01-11 17:21 jbrassow 2010-07-09 17:57 jbrassow 2010-06-23 13:57 jbrassow 2010-04-20 12:14 agk 2010-04-01 14:54 agk 2010-01-08 10:50 zkabelac 2009-12-17 15:59 mornfall 2009-12-09 19:43 mbroz 2009-11-19 13:42 mornfall 2009-11-19 12:09 mornfall 2009-11-18 18:23 mornfall 2009-10-14 14:55 jbrassow 2009-04-23 16:43 mornfall 2008-09-19 4:30 agk 2008-09-19 0:20 agk 2008-01-17 13:37 agk 2008-01-16 19:50 agk 2008-01-16 19:38 agk 2008-01-16 19:11 agk 2006-11-10 20:15 agk 2004-05-05 18:35 agk
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20080116190935.12526.qmail@sourceware.org \ --to=agk@sourceware.org \ --cc=lvm-devel@redhat.com \ --cc=lvm2-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).