From b88362ff95fa3e8f5be2ae359f3a859efbf3d694 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Tue, 6 Sep 2011 19:25:42 +0000 Subject: [PATCH] add thin_manip.c like the other manip files move basic lv_is_* to macros data_lv -> pool_lv - we decided to call it 'pool' everywhere now --- lib/Makefile.in | 3 ++- lib/metadata/lv_manip.c | 20 ++----------------- lib/metadata/metadata-exported.h | 9 ++++++--- lib/metadata/metadata.h | 7 +++++++ lib/metadata/mirror.c | 8 -------- lib/metadata/replicator_manip.c | 8 -------- lib/metadata/thin_manip.c | 33 ++++++++++++++++++++++++++++++++ lib/thin/thin.c | 6 ++++-- tools/lvcreate.c | 8 +++----- 9 files changed, 57 insertions(+), 45 deletions(-) create mode 100644 lib/metadata/thin_manip.c diff --git a/lib/Makefile.in b/lib/Makefile.in index 6758a78c9..a46e59603 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -1,6 +1,6 @@ # # Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. -# Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved. +# Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. # # This file is part of LVM2. # @@ -93,6 +93,7 @@ SOURCES =\ metadata/replicator_manip.c \ metadata/segtype.c \ metadata/snapshot_manip.c \ + metadata/thin_manip.c \ metadata/vg.c \ misc/crc.c \ misc/lvm-exec.c \ diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index 36c1a2c90..f1c0db605 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -198,22 +198,6 @@ uint32_t find_free_lvnum(struct logical_volume *lv) return i; } -static int _attach_pool_metadata(struct lv_segment *seg, struct logical_volume *thin_pool_metadata) -{ - // FIXME Housekeeping needed here (cf attach_mirror_log) - seg->metadata_lv = thin_pool_metadata; - - return 1; -} - -static int _attach_pool_lv(struct lv_segment *seg, struct logical_volume *thin_pool_lv) -{ - // FIXME Housekeeping needed here (cf attach_mirror_log) - seg->thin_pool_lv = thin_pool_lv; - - return 1; -} - /* * All lv_segments get created here. */ @@ -268,12 +252,12 @@ struct lv_segment *alloc_lv_segment(struct dm_pool *mem, seg->pvmove_source_seg = pvmove_source_seg; dm_list_init(&seg->tags); - if (thin_pool_lv && !_attach_pool_lv(seg, thin_pool_lv)) + if (thin_pool_lv && !attach_pool_lv(seg, thin_pool_lv)) return_NULL; if (log_lv) { if (thin_pool_lv) { - if (!_attach_pool_metadata(seg, log_lv)) + if (!attach_pool_metadata(seg, log_lv)) return_NULL; } else if (!attach_mirror_log(seg, log_lv)) return_NULL; diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h index e0c1fd8c1..4948f0daa 100644 --- a/lib/metadata/metadata-exported.h +++ b/lib/metadata/metadata-exported.h @@ -132,6 +132,11 @@ #define VGMETADATACOPIES_ALL UINT32_MAX #define VGMETADATACOPIES_UNMANAGED 0 +#define lv_is_thin_volume(lv) ((lv)->status & THIN_VOLUME ? 1 : 0) +#define lv_is_thin_pool(lv) ((lv)->status & THIN_POOL ? 1 : 0) +#define lv_is_mirrored(lv) ((lv)->status & MIRRORED ? 1 : 0) +#define lv_is_rlog(lv) ((lv)->status & REPLICATOR_LOG ? 1 : 0) + /* Ordered list - see lv_manip.c */ typedef enum { AREA_UNASSIGNED, @@ -318,7 +323,7 @@ struct lv_segment { struct lv_segment_area *areas; struct lv_segment_area *meta_areas; /* For RAID */ - struct logical_volume *data_lv; /* For thin_pool */ + struct logical_volume *pool_lv; /* For thin_pool */ struct logical_volume *metadata_lv; /* For thin_pool */ uint64_t transaction_id; /* For thin_pool */ uint32_t zero_new_blocks; /* For thin_pool */ @@ -696,7 +701,6 @@ int lv_remove_mirrors(struct cmd_context *cmd, struct logical_volume *lv, int is_temporary_mirror_layer(const struct logical_volume *lv); struct logical_volume * find_temporary_mirror(const struct logical_volume *lv); -int lv_is_mirrored(const struct logical_volume *lv); uint32_t lv_mirror_count(const struct logical_volume *lv); uint32_t adjusted_mirror_region_size(uint32_t extent_size, uint32_t extents, uint32_t region_size); @@ -742,7 +746,6 @@ int lv_is_active_replicator_dev(const struct logical_volume *lv); int lv_is_replicator(const struct logical_volume *lv); int lv_is_replicator_dev(const struct logical_volume *lv); int lv_is_rimage(const struct logical_volume *lv); -int lv_is_rlog(const struct logical_volume *lv); int lv_is_slog(const struct logical_volume *lv); struct logical_volume *first_replicator_dev(const struct logical_volume *lv); /* -- metadata/replicator_manip.c */ diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h index e48c8980b..d48c6cc77 100644 --- a/lib/metadata/metadata.h +++ b/lib/metadata/metadata.h @@ -439,6 +439,13 @@ struct volume_group *import_vg_from_config_tree(const struct dm_config_tree *cft */ int fixup_imported_mirrors(struct volume_group *vg); +/* + * From thin_manip.c + */ +int attach_pool_metadata(struct lv_segment *seg, + struct logical_volume *thin_pool_metadata); +int attach_pool_lv(struct lv_segment *seg, struct logical_volume *thin_pool_lv); + /* * Begin skeleton for external LVM library */ diff --git a/lib/metadata/mirror.c b/lib/metadata/mirror.c index d7be24ee0..db187e206 100644 --- a/lib/metadata/mirror.c +++ b/lib/metadata/mirror.c @@ -72,14 +72,6 @@ struct logical_volume *find_temporary_mirror(const struct logical_volume *lv) return NULL; } -int lv_is_mirrored(const struct logical_volume *lv) -{ - if (lv->status & MIRRORED) - return 1; - - return 0; -} - /* * cluster_mirror_is_available * diff --git a/lib/metadata/replicator_manip.c b/lib/metadata/replicator_manip.c index 9f9dc97dd..2853e50df 100644 --- a/lib/metadata/replicator_manip.c +++ b/lib/metadata/replicator_manip.c @@ -445,14 +445,6 @@ int lv_is_rimage(const struct logical_volume *lv) return (lv->rdevice && lv->rdevice->lv == lv); } -/** - * Is this LV rlog - */ -int lv_is_rlog(const struct logical_volume *lv) -{ - return (lv->status & REPLICATOR_LOG); -} - /** * Is this LV sync log */ diff --git a/lib/metadata/thin_manip.c b/lib/metadata/thin_manip.c new file mode 100644 index 000000000..3f5207377 --- /dev/null +++ b/lib/metadata/thin_manip.c @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2011 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 + */ + +#include "lib.h" +#include "metadata.h" + +int attach_pool_metadata(struct lv_segment *seg, struct logical_volume *thin_pool_metadata) +{ + // FIXME Housekeeping needed here (cf attach_mirror_log) + seg->metadata_lv = thin_pool_metadata; + + return 1; +} + +int attach_pool_lv(struct lv_segment *seg, struct logical_volume *thin_pool_lv) +{ + // FIXME Housekeeping needed here (cf attach_mirror_log) + seg->thin_pool_lv = thin_pool_lv; + + return 1; +} + diff --git a/lib/thin/thin.c b/lib/thin/thin.c index eeaa38fb4..dcb60289c 100644 --- a/lib/thin/thin.c +++ b/lib/thin/thin.c @@ -51,12 +51,14 @@ static int _thin_pool_text_import(struct lv_segment *seg, const struct dm_config if (!dm_config_get_str(sn, "data", &lv_name)) return SEG_LOG_ERROR("Thin pool data must be a string in"); - if (!(seg->data_lv = find_lv(seg->lv->vg, lv_name))) +// Use attach_pool_lv + if (!(seg->pool_lv = find_lv(seg->lv->vg, lv_name))) return SEG_LOG_ERROR("Unknown pool data %s in", lv_name); if (!dm_config_get_str(sn, "metadata", &lv_name)) return SEG_LOG_ERROR("Thin pool metadata must be a string in"); +// Use attach_pool_metadata() if (!(seg->metadata_lv = find_lv(seg->lv->vg, lv_name))) return SEG_LOG_ERROR("Unknown pool metadata %s in", lv_name); @@ -72,7 +74,7 @@ static int _thin_pool_text_import(struct lv_segment *seg, const struct dm_config static int _thin_pool_text_export(const struct lv_segment *seg, struct formatter *f) { - outf(f, "data = \"%s\"", seg->data_lv->name); + outf(f, "data = \"%s\"", seg->pool_lv->name); outf(f, "metadata = \"%s\"", seg->metadata_lv->name); outf(f, "transaction_id = %" PRIu64, seg->transaction_id); if (seg->zero_new_blocks) diff --git a/tools/lvcreate.c b/tools/lvcreate.c index 6d6a7b981..e8722a3fa 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -192,7 +192,6 @@ static int _determine_snapshot_type(struct volume_group *vg, struct lvcreate_params *lp) { struct lv_list *lvl; - struct lv_segment *seg; if (!(lvl = find_lv_in_vg(vg, lp->origin))) { log_error("Snapshot origin LV %s not found in Volume group %s.", lp->origin, vg->name); @@ -200,12 +199,12 @@ static int _determine_snapshot_type(struct volume_group *vg, } /* FIXME Replace with lv_is_thin_volume() once more flags are added */ - if (seg_is_thin_volume(seg = first_seg(lvl->lv))) { + if (lv_is_thin_volume(lvl->lv)) { lp->thin = 1; if (!(lp->segtype = get_segtype_from_string(vg->cmd, "thin"))) return_0; - lp->pool = seg->thin_pool_lv->name; + lp->pool = first_seg(lvl->lv)->thin_pool_lv->name; } if (!lp->thin && !arg_count(vg->cmd, extents_ARG) && !arg_count(vg->cmd, size_ARG)) { @@ -804,8 +803,7 @@ static int _check_thin_parameters(struct volume_group *vg, struct lvcreate_param log_error("Pool %s not found in Volume group %s.", lp->pool, vg->name); return 0; } - /* FIXME Use lv_is_thin_pool() */ - if (!seg_is_thin_pool(first_seg(lvl->lv))) { + if (!lv_is_thin_pool(lvl->lv)) { log_error("Logical volume %s is not a thin pool.", lp->pool); return 0; }