public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
From: zkabelac@sourceware.org
To: lvm-devel@redhat.com, lvm2-cvs@sourceware.org
Subject: LVM2/lib/metadata metadata.h thin_manip.c
Date: Sat, 22 Oct 2011 16:44:00 -0000	[thread overview]
Message-ID: <20111022164424.8239.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	zkabelac@sourceware.org	2011-10-22 16:44:23

Modified files:
	lib/metadata   : metadata.h thin_manip.c 

Log message:
	Recoded way to insert thin pool into vg
	
	Code in _lv_insert_empty_sublvs  was not able to provide proper
	initialization order for thin pool LV.
	
	New function extend_pool() first adds metadata segment to pool LV which
	is still visible. Such LV is activate and cleared.
	
	Then new meta LV is created and metadata segments are moved there.
	Now the preallocated pool data segment is attached to the pool LV
	and layer _tpool is created. Finaly segment is marked as thin_pool.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.h.diff?cvsroot=lvm2&r1=1.260&r2=1.261
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/thin_manip.c.diff?cvsroot=lvm2&r1=1.12&r2=1.13

--- LVM2/lib/metadata/metadata.h	2011/10/22 16:42:11	1.260
+++ LVM2/lib/metadata/metadata.h	2011/10/22 16:44:23	1.261
@@ -69,6 +69,7 @@
 
 struct dm_config_tree;
 struct metadata_area;
+struct alloc_handle;
 
 /* Per-format per-metadata area operations */
 struct metadata_area_ops {
@@ -461,6 +462,8 @@
 			struct logical_volume *lv, uint32_t delete_id,
 			int read_only);
 int detach_pool_messages(struct lv_segment *seg);
+int extend_pool(struct logical_volume *lv, const struct segment_type *segtype,
+		struct alloc_handle *ah);
 
 /*
  * Begin skeleton for external LVM library
--- LVM2/lib/metadata/thin_manip.c	2011/10/19 16:42:14	1.12
+++ LVM2/lib/metadata/thin_manip.c	2011/10/22 16:44:23	1.13
@@ -13,6 +13,8 @@
  */
 
 #include "lib.h"
+#include "activate.h"
+#include "locking.h"
 #include "metadata.h"
 #include "segtype.h"
 #include "lv_alloc.h"
@@ -216,3 +218,96 @@
 
 	return max_id;
 }
+
+int extend_pool(struct logical_volume *pool_lv, const struct segment_type *segtype,
+		struct alloc_handle *ah)
+{
+	const struct segment_type *striped;
+	struct logical_volume *meta_lv, *data_lv;
+	struct lv_segment *seg;
+	const size_t len = strlen(pool_lv->name) + 16;
+	char name[len];
+
+	if (lv_is_thin_pool(pool_lv)) {
+		log_error("Resize of pool %s not yet implemented.", 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, 1, 1, pool_lv, striped, 1, 0, 0))
+		return_0;
+
+	if (activation()) {
+		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
+		 */
+
+		// FIXME: activate_lv_local_excl is actually wanted here
+		if (!activate_lv_local(pool_lv->vg->cmd, pool_lv) ||
+		    // FIXME: maybe -zero n  should  allow to recreate same thin pool
+		    // and different option should be used for zero_new_blocks
+		    /* Clear 4KB of metadata device for new thin-pool. */
+		    !set_lv(pool_lv->vg->cmd, pool_lv, UINT64_C(0), 0)) {
+			log_error("Aborting. Failed to wipe pool metadata %s.",
+				  pool_lv->name);
+			return 0;
+		}
+
+		if (!deactivate_lv_local(pool_lv->vg->cmd, pool_lv)) {
+			log_error("Aborting. Could not deactivate pool metadata %s.",
+				  pool_lv->name);
+			return 0;
+		}
+	} else {
+		log_error("Pool %s created without initilization.", pool_lv->name);
+	}
+
+	if (dm_snprintf(name, len, "%s_tmeta", pool_lv->name) < 0)
+		return_0;
+
+	if (!(meta_lv = lv_create_empty(name, NULL, LVM_READ | LVM_WRITE,
+					ALLOC_INHERIT, pool_lv->vg)))
+		return_0;
+
+	if (!move_lv_segments(meta_lv, pool_lv, 0, 0))
+		return_0;
+
+	/* Pool data segment */
+	if (!lv_add_segment(ah, 0, 1, pool_lv, striped, 1, 0, 0))
+		return_0;
+
+	if (!(data_lv = insert_layer_for_lv(pool_lv->vg->cmd, pool_lv,
+					    pool_lv->status, "_tpool")))
+		return_0;
+
+	seg = first_seg(pool_lv);
+	seg->segtype = segtype; /* Set as thin_pool segment */
+	seg->lv->status |= THIN_POOL;
+
+	if (!attach_pool_metadata_lv(seg, meta_lv))
+		return_0;
+
+	/* Drop reference as attach_pool_data_lv() takes it again */
+	remove_seg_from_segs_using_this_lv(data_lv, seg);
+	if (!attach_pool_data_lv(seg, data_lv))
+		return_0;
+
+	return 1;
+}


             reply	other threads:[~2011-10-22 16:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-22 16:44 zkabelac [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-01-25  8:55 zkabelac
2011-10-19 16:39 zkabelac
2011-10-03 18:39 zkabelac

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=20111022164424.8239.qmail@sourceware.org \
    --to=zkabelac@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: link
Be 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).