Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=1d7b2715e51b399dd... Commit: 1d7b2715e51b399dd275a832f488cd712b044844 Parent: 998af1a4fbf82cb9d5a2ba0c3c547ede39466a28 Author: Zdenek Kabelac zkabelac@redhat.com AuthorDate: Thu Jan 23 09:56:17 2014 +0100 Committer: Zdenek Kabelac zkabelac@redhat.com CommitterDate: Thu Jan 23 09:57:22 2014 +0100
missed pool_manip.c
Seems like this file is missing from the thin_manip move. Make the tree compilable again. --- lib/metadata/pool_manip.c | 305 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 305 insertions(+), 0 deletions(-)
diff --git a/lib/metadata/pool_manip.c b/lib/metadata/pool_manip.c new file mode 100644 index 0000000..a36c0c7 --- /dev/null +++ b/lib/metadata/pool_manip.c @@ -0,0 +1,305 @@ +/* + * Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved. + * + * This file is part of LVM2. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License v.2.1. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * This file holds common pool functions. + */ + +#include "lib.h" +#include "activate.h" +#include "locking.h" +#include "metadata.h" +#include "segtype.h" +#include "lv_alloc.h" +#include "defaults.h" +#include "display.h" + +int attach_pool_metadata_lv(struct lv_segment *pool_seg, + struct logical_volume *metadata_lv) +{ + if (!seg_is_thin_pool(pool_seg)) { + log_error(INTERNAL_ERROR + "Unable to attach pool metadata LV to %s segtype.", + pool_seg->segtype->ops->name(pool_seg)); + return 0; + } + pool_seg->metadata_lv = metadata_lv; + metadata_lv->status |= THIN_POOL_METADATA; + lv_set_hidden(metadata_lv); + + return add_seg_to_segs_using_this_lv(metadata_lv, pool_seg); +} + +int attach_pool_data_lv(struct lv_segment *pool_seg, + struct logical_volume *pool_data_lv) +{ + if (!seg_is_thin_pool(pool_seg)) { + log_error(INTERNAL_ERROR + "Unale to attach pool data LV to %s segtype.", + pool_seg->segtype->ops->name(pool_seg)); + return 0; + } + + if (!set_lv_segment_area_lv(pool_seg, 0, pool_data_lv, + 0, THIN_POOL_DATA)) + return_0; + + pool_seg->lv->status |= THIN_POOL; + lv_set_hidden(pool_data_lv); + + return 1; +} + +int attach_pool_lv(struct lv_segment *seg, + struct logical_volume *pool_lv, + struct logical_volume *origin, + struct logical_volume *merge_lv) +{ + if (!seg_is_thin_volume(seg)) { + log_error(INTERNAL_ERROR "Unable to attach pool to %s/%s" + " that is thin volume.", + pool_lv->vg->name, seg->lv->name); + return 0; + } + + seg->pool_lv = pool_lv; + seg->origin = origin; + seg->lv->status |= THIN_VOLUME; + + if (origin && !add_seg_to_segs_using_this_lv(origin, seg)) + return_0; + + if (!add_seg_to_segs_using_this_lv(pool_lv, seg)) + return_0; + + if (merge_lv) { + if (origin != merge_lv) { + if (!add_seg_to_segs_using_this_lv(merge_lv, seg)) + return_0; + } + + init_snapshot_merge(seg, merge_lv); + } + + return 1; +} + +int detach_pool_lv(struct lv_segment *seg) +{ + struct lv_thin_message *tmsg, *tmp; + struct seg_list *sl, *tsl; + int no_update = 0; + + if (!seg->pool_lv) { + log_error(INTERNAL_ERROR + "No pool associated with %s LV, %s.", + seg->segtype->ops->name(seg), seg->lv->name); + return 0; + } + + if (!lv_is_thin_pool(seg->pool_lv)) { + log_error(INTERNAL_ERROR + "Cannot detach pool from LV %s.", + seg->lv->name); + return 0; + } + + /* Drop any message referencing removed segment */ + dm_list_iterate_items_safe(tmsg, tmp, &(first_seg(seg->pool_lv)->thin_messages)) { + switch (tmsg->type) { + case DM_THIN_MESSAGE_CREATE_SNAP: + case DM_THIN_MESSAGE_CREATE_THIN: + if (tmsg->u.lv == seg->lv) { + log_debug_metadata("Discarding message for LV %s.", + tmsg->u.lv->name); + dm_list_del(&tmsg->list); + no_update = 1; /* Replacing existing */ + } + break; + case DM_THIN_MESSAGE_DELETE: + if (tmsg->u.delete_id == seg->device_id) { + log_error(INTERNAL_ERROR "Trying to delete %u again.", + tmsg->u.delete_id); + return 0; + } + break; + default: + log_error(INTERNAL_ERROR "Unsupported message type %u.", tmsg->type); + break; + } + } + + if (!detach_thin_external_origin(seg)) + return_0; + + if (!attach_pool_message(first_seg(seg->pool_lv), + DM_THIN_MESSAGE_DELETE, + NULL, seg->device_id, no_update)) + return_0; + + if (!remove_seg_from_segs_using_this_lv(seg->pool_lv, seg)) + return_0; + + if (seg->origin && + !remove_seg_from_segs_using_this_lv(seg->origin, seg)) + return_0; + + /* If thin origin, remove it from related thin snapshots */ + /* + * TODO: map removal of origin as snapshot lvconvert --merge? + * i.e. rename thin snapshot to origin thin origin + */ + dm_list_iterate_items_safe(sl, tsl, &seg->lv->segs_using_this_lv) { + if (!seg_is_thin_volume(sl->seg) || + (seg->lv != sl->seg->origin)) + continue; + + if (!remove_seg_from_segs_using_this_lv(seg->lv, sl->seg)) + return_0; + /* Thin snapshot is now regular thin volume */ + sl->seg->origin = NULL; + } + + seg->lv->status &= ~THIN_VOLUME; + seg->pool_lv = NULL; + seg->origin = NULL; + + return 1; +} + +struct lv_segment *find_pool_seg(const struct lv_segment *seg) +{ + struct lv_segment *pool_seg; + + pool_seg = get_only_segment_using_this_lv(seg->lv); + + if (!pool_seg) { + log_error("Failed to find pool_seg for %s", seg->lv->name); + return NULL; + } + + if (!seg_is_thin_pool(pool_seg)) { + log_error("%s on %s is not a pool segment.", + pool_seg->lv->name, seg->lv->name); + return NULL; + } + + return pool_seg; +} + +int create_pool(struct logical_volume *pool_lv, + const struct segment_type *segtype, + struct alloc_handle *ah, uint32_t stripes, uint32_t stripe_size) +{ + const struct segment_type *striped; + struct logical_volume *meta_lv, *data_lv; + struct lv_segment *seg; + char name[NAME_LEN]; + + if (pool_lv->le_count) { + log_error(INTERNAL_ERROR "Pool %s has already extents.", + pool_lv->name); + return 0; + } + + /* LV is not yet a pool, so it's extension from lvcreate */ + if (!(striped = get_segtype_from_string(pool_lv->vg->cmd, "striped"))) + return_0; + + if (activation() && segtype->ops->target_present && + !segtype->ops->target_present(pool_lv->vg->cmd, NULL, NULL)) { + log_error("%s: Required device-mapper target(s) not " + "detected in your kernel.", segtype->name); + return 0; + } + + /* Metadata segment */ + if (!lv_add_segment(ah, stripes, 1, pool_lv, striped, 1, 0, 0)) + return_0; + + if (!activation()) + log_warn("WARNING: Pool %s is created without initialization.", + pool_lv->name); + else { + if (!vg_write(pool_lv->vg) || !vg_commit(pool_lv->vg)) + return_0; + + /* + * If killed here, only the VISIBLE striped pool LV is left + * and user could easily remove it. + * + * FIXME: implement lazy clearing when activation is disabled + */ + /* pool_lv is a new LV so the VG lock protects us */ + if (!activate_lv_local(pool_lv->vg->cmd, pool_lv) || + /* Clear 4KB of metadata device for new thin-pool. */ + !wipe_lv(pool_lv, (struct wipe_params) { .do_zero = 1 })) { + log_error("Aborting. Failed to wipe pool metadata %s.", + pool_lv->name); + goto bad; + } + } + + if (dm_snprintf(name, sizeof(name), "%s_%s", pool_lv->name, + "tmeta") < 0) { + log_error("Name is too long to be a pool name."); + goto bad; + } + + if (!(meta_lv = lv_create_empty(name, NULL, LVM_READ | LVM_WRITE, + ALLOC_INHERIT, pool_lv->vg))) + goto_bad; + + if (!move_lv_segments(meta_lv, pool_lv, 0, 0)) + goto_bad; + + /* Pool data segment */ + if (!lv_add_segment(ah, 0, stripes, pool_lv, striped, stripe_size, 0, 0)) + goto_bad; + + if (!(data_lv = insert_layer_for_lv(pool_lv->vg->cmd, pool_lv, + pool_lv->status, + "_tdata"))) + goto_bad; + + seg = first_seg(pool_lv); + /* Drop reference as attach_pool_data_lv() takes it again */ + if (!remove_seg_from_segs_using_this_lv(data_lv, seg)) + goto_bad; + + seg->segtype = segtype; /* Set as thin_pool segment */ + + if (!attach_pool_data_lv(seg, data_lv)) + goto_bad; + + if (!attach_pool_metadata_lv(seg, meta_lv)) + goto_bad; + + return 1; + +bad: + if (activation()) { + if (deactivate_lv_local(pool_lv->vg->cmd, pool_lv)) { + log_error("Aborting. Could not deactivate pool %s.", + pool_lv->name); + return 0; + } + if (!lv_remove(pool_lv) || + !vg_write(pool_lv->vg) || !vg_commit(pool_lv->vg)) + log_error("Manual intervention may be required to " + "remove abandoned LV(s) before retrying."); + } + + return 0; +}
lvm2-commits@lists.fedorahosted.org