public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
* LVM2/lib format_text/format-text.c format_text ...
@ 2010-06-30 17:13 agk
  0 siblings, 0 replies; 4+ messages in thread
From: agk @ 2010-06-30 17:13 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	agk@sourceware.org	2010-06-30 17:13:07

Modified files:
	lib/format_text: format-text.c layout.h 
	lib/metadata   : metadata.c 

Log message:
	more metadataignore message/code cleanup

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/format-text.c.diff?cvsroot=lvm2&r1=1.138&r2=1.139
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/layout.h.diff?cvsroot=lvm2&r1=1.12&r2=1.13
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.c.diff?cvsroot=lvm2&r1=1.373&r2=1.374

--- LVM2/lib/format_text/format-text.c	2010/06/30 13:51:11	1.138
+++ LVM2/lib/format_text/format-text.c	2010/06/30 17:13:05	1.139
@@ -68,9 +68,9 @@
 	return (rlocn->flags & RAW_LOCN_IGNORED ? 1 : 0);
 }
 
-void rlocn_set_ignored(struct raw_locn *rlocn, int value)
+void rlocn_set_ignored(struct raw_locn *rlocn, unsigned mda_ignored)
 {
-	if (value)
+	if (mda_ignored)
 		rlocn->flags |= RAW_LOCN_IGNORED;
 	else
 		rlocn->flags &= ~RAW_LOCN_IGNORED;
--- LVM2/lib/format_text/layout.h	2010/06/28 20:31:01	1.12
+++ LVM2/lib/format_text/layout.h	2010/06/30 17:13:05	1.13
@@ -62,7 +62,7 @@
 } __attribute__ ((packed));
 
 int rlocn_is_ignored(const struct raw_locn *rlocn);
-void rlocn_set_ignored(struct raw_locn *rlocn, int value);
+void rlocn_set_ignored(struct raw_locn *rlocn, unsigned mda_ignored);
 
 /* On disk */
 /* Structure size limited to one sector */
--- LVM2/lib/metadata/metadata.c	2010/06/30 14:54:29	1.373
+++ LVM2/lib/metadata/metadata.c	2010/06/30 17:13:06	1.374
@@ -2615,13 +2615,12 @@
 
 	/* Rearrange the metadata_areas_in_use so ignored mdas come first. */
 	dm_list_init(&ignored);
-	dm_list_iterate_items_safe(mda, tmda, &vg->fid->metadata_areas_in_use) {
+	dm_list_iterate_items_safe(mda, tmda, &vg->fid->metadata_areas_in_use)
 		if (mda_is_ignored(mda))
 			dm_list_move(&ignored, &mda->list);
-	}
-	dm_list_iterate_items_safe(mda, tmda, &ignored) {
+
+	dm_list_iterate_items_safe(mda, tmda, &ignored)
 		dm_list_move(&vg->fid->metadata_areas_in_use, &mda->list);
-	}
 
 	/* Commit to each copy of the metadata area */
 	dm_list_iterate_items(mda, &vg->fid->metadata_areas_in_use) {
@@ -4067,12 +4066,8 @@
 
 void fid_add_mda(struct format_instance *fid, struct metadata_area *mda)
 {
-	if (mda_is_ignored(mda))
-		dm_list_add(&fid->metadata_areas_ignored,
-			    &mda->list);
-	else
-		dm_list_add(&fid->metadata_areas_in_use,
-			    &mda->list);
+	dm_list_add(mda_is_ignored(mda) ? &fid->metadata_areas_ignored :
+					  &fid->metadata_areas_in_use, &mda->list);
 }
 
 int fid_add_mdas(struct format_instance *fid, struct dm_list *mdas)
@@ -4149,20 +4144,20 @@
 	return (mda->flags & MDA_IGNORED);
 }
 
-void mda_set_ignored(struct metadata_area *mda, unsigned ignored)
+void mda_set_ignored(struct metadata_area *mda, unsigned mda_ignored)
 {
 	void *locn = mda->metadata_locn;
-	unsigned old_ignored = mda_is_ignored(mda);
+	unsigned old_mda_ignored = mda_is_ignored(mda);
 
-	if (ignored && !old_ignored)
+	if (mda_ignored && !old_mda_ignored)
 		mda->flags |= MDA_IGNORED;
-	else if (!ignored && old_ignored)
+	else if (!mda_ignored && old_mda_ignored)
 		mda->flags &= ~MDA_IGNORED;
 	else
 		return;	/* No change */
 
 	log_debug("%s ignored flag for mda %s at offset %" PRIu64 ".", 
-		  ignored ? "Setting" : "Clearing",
+		  mda_ignored ? "Setting" : "Clearing",
 		  mda->ops->mda_metadata_locn_name ? mda->ops->mda_metadata_locn_name(locn) : "",
 		  mda->ops->mda_metadata_locn_offset ? mda->ops->mda_metadata_locn_offset(locn) : UINT64_C(0));
 }
@@ -4191,20 +4186,18 @@
 	return used_count;
 }
 
-unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned ignored)
+unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned mda_ignored)
 {
 	struct lvmcache_info *info;
 	struct metadata_area *mda, *vg_mda, *tmda;
 	struct dm_list *vg_mdas_in_use, *vg_mdas_ignored;
 
-	info = info_from_pvid((const char *)&pv->id.uuid, 0);
-	if (!info)
+	if (!(info = info_from_pvid((const char *)&pv->id.uuid, 0)))
 		return_0;
 
 	if (is_orphan(pv)) {
-		dm_list_iterate_items(mda, &info->mdas) {
-			mda_set_ignored(mda, ignored);
-		}
+		dm_list_iterate_items(mda, &info->mdas)
+			mda_set_ignored(mda, mda_ignored);
 		return 1;
 	}
 
@@ -4212,7 +4205,8 @@
 	 * Do not allow disabling of the the last PV in a VG.
 	 */
 	if (pv_mda_used_count(pv) == vg_mda_used_count(pv->vg)) {
-		log_error("Cannot disable all metadata areas in Volume Group.");
+		log_error("Cannot disable all metadata areas in volume group %s.",
+			  pv->vg->name);
 		return 0;
 	}
 
@@ -4229,24 +4223,24 @@
 	 */
 	vg_mdas_in_use = &pv->vg->fid->metadata_areas_in_use;
 	vg_mdas_ignored = &pv->vg->fid->metadata_areas_ignored;
+
 	dm_list_iterate_items(mda, &info->mdas) {
-		if (mda_is_ignored(mda) && !ignored) {
+		if (mda_is_ignored(mda) && !mda_ignored)
 			/* Changing an ignored mda to one in_use requires moving it */
-			dm_list_iterate_items_safe(vg_mda, tmda, vg_mdas_ignored) {
+			dm_list_iterate_items_safe(vg_mda, tmda, vg_mdas_ignored)
 				if (mda_locns_match(mda, vg_mda)) {
-					mda_set_ignored(vg_mda, ignored);
+					mda_set_ignored(vg_mda, mda_ignored);
 					dm_list_move(vg_mdas_in_use, &vg_mda->list);
 				}
-			}
-		}
-		dm_list_iterate_items_safe(vg_mda, tmda, vg_mdas_in_use) {
-			if (mda_locns_match(mda, vg_mda)) {
-				mda_set_ignored(vg_mda, ignored);
-				/* don't move mda - needs written to disk */
-			}
-		}
-		mda_set_ignored(mda, ignored);
+
+		dm_list_iterate_items_safe(vg_mda, tmda, vg_mdas_in_use)
+			if (mda_locns_match(mda, vg_mda))
+				/* Don't move mda: needs writing to disk. */
+				mda_set_ignored(vg_mda, mda_ignored);
+
+		mda_set_ignored(mda, mda_ignored);
 	}
+
 	return 1;
 }
 
@@ -4267,31 +4261,30 @@
 {
 	const char *pv_name = pv_dev_name(pv);
 
-	if (mda_ignore && (pv_mda_used_count(pv) == 0)) {
-		log_error("Physical volume \"%s\" metadata already "
-			  "ignored", pv_name);
+	if (mda_ignore && !pv_mda_used_count(pv)) {
+		log_error("Metadata areas on physical volume \"%s\" already "
+			  "ignored.", pv_name);
 		return 0;
 	}
+
 	if (!mda_ignore && (pv_mda_used_count(pv) == pv_mda_count(pv))) {
-		log_error("Physical volume \"%s\" metadata already "
-			  "not ignored", pv_name);
+		log_error("Metadata areas on physical volume \"%s\" already "
+			  "marked as in-use.", pv_name);
 		return 0;
 	}
+
 	if (!pv_mda_count(pv)) {
 		log_error("Physical volume \"%s\" has no metadata "
-			  "areas ", pv_name);
-		return 0;
-	}
-	if (mda_ignore) {
-		log_verbose("Setting physical volume \"%s\" "
-			    "metadata ignored", pv_name);
-	} else {
-		log_verbose("Setting physical volume \"%s\" "
-			    "metadata not ignored", pv_name);
-	}
-	if (!pv_mda_set_ignored(pv, mda_ignore)) {
+			  "areas.", pv_name);
 		return 0;
 	}
+
+	log_verbose("Marking metadata areas on physical volume \"%s\" "
+		    "as %s.", pv_name, mda_ignore ? "ignored" : "in-use");
+
+	if (!pv_mda_set_ignored(pv, mda_ignore))
+		return_0;
+
 	/*
 	 * Update vg_mda_copies based on the mdas in this PV.
 	 * This is most likely what the user would expect - if they
@@ -4301,9 +4294,9 @@
 	 * This does not guarantee this PV's ignore bits will be
 	 * preserved in future operations.
 	 */
-	if (!is_orphan(pv) && vg_mda_copies(pv->vg)) {
+	if (!is_orphan(pv) && vg_mda_copies(pv->vg))
 		vg_set_mda_copies(pv->vg, vg_mda_used_count(pv->vg));
-	}
+
 	return 1;
 }
 
@@ -4373,14 +4366,13 @@
 	 * may have changed from ignored to un-ignored and we need to write
 	 * the state to disk.
 	 */
-       dm_list_iterate_items(mda, &vg->fid->metadata_areas_in_use) {
+       dm_list_iterate_items(mda, &vg->fid->metadata_areas_in_use)
 	       if (!mda_is_ignored(mda))
 		       used_count++;
-       }
-       dm_list_iterate_items(mda, &vg->fid->metadata_areas_ignored) {
+
+       dm_list_iterate_items(mda, &vg->fid->metadata_areas_ignored)
 	       if (!mda_is_ignored(mda))
 		       used_count++;
-       }
 
        return used_count;
 }


^ permalink raw reply	[flat|nested] 4+ messages in thread
* LVM2/lib format_text/format-text.c format_text ...
@ 2011-02-21 12:17 prajnoha
  0 siblings, 0 replies; 4+ messages in thread
From: prajnoha @ 2011-02-21 12:17 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	prajnoha@sourceware.org	2011-02-21 12:17:54

Modified files:
	lib/format_text: format-text.c format-text.h 
	lib/metadata   : metadata.h 

Log message:
	Add new pv_remove_metadata_area interface function.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/format-text.c.diff?cvsroot=lvm2&r1=1.159&r2=1.160
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/format-text.h.diff?cvsroot=lvm2&r1=1.30&r2=1.31
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.h.diff?cvsroot=lvm2&r1=1.234&r2=1.235

--- LVM2/lib/format_text/format-text.c	2011/02/21 12:17:26	1.159
+++ LVM2/lib/format_text/format-text.c	2011/02/21 12:17:54	1.160
@@ -2272,6 +2272,29 @@
 	return 0;
 }
 
+int remove_metadata_area_from_pv(struct physical_volume *pv,
+				 unsigned mda_index)
+{
+	if (mda_index >= FMT_TEXT_MAX_MDAS_PER_PV) {
+		log_error(INTERNAL_ERROR "can't remove metadata area with "
+					 "index %u from PV %s. Metadata "
+					 "layou not supported by %s format.",
+					  mda_index, dev_name(pv->dev),
+					  pv->fmt->name);
+		return 0;
+	}
+
+	return fid_remove_mda(pv->fid, NULL, (const char *) &pv->id,
+			      ID_LEN, mda_index);
+}
+
+static int _text_pv_remove_metadata_area(const struct format_type *fmt,
+					 struct physical_volume *pv,
+					 unsigned mda_index)
+{
+	return remove_metadata_area_from_pv(pv, mda_index);
+}
+
 /* NULL vgname means use only the supplied context e.g. an archive file */
 static struct format_instance *_text_create_text_instance(const struct format_type *fmt,
 							   const struct format_instance_ctx *fic)
@@ -2347,6 +2370,7 @@
 	.pv_read = _text_pv_read,
 	.pv_setup = _text_pv_setup,
 	.pv_add_metadata_area = _text_pv_add_metadata_area,
+	.pv_remove_metadata_area = _text_pv_remove_metadata_area,
 	.pv_write = _text_pv_write,
 	.vg_setup = _text_vg_setup,
 	.lv_setup = _text_lv_setup,
--- LVM2/lib/format_text/format-text.h	2011/02/21 12:17:26	1.30
+++ LVM2/lib/format_text/format-text.h	2011/02/21 12:17:54	1.31
@@ -61,6 +61,8 @@
 			    uint64_t mda_start,
 			    uint64_t mda_size,
 			    unsigned mda_ignored);
+int remove_metadata_area_from_pv(struct physical_volume *pv,
+				 unsigned mda_index);
 int add_mda(const struct format_type *fmt, struct dm_pool *mem, struct dm_list *mdas,
 	    struct device *dev, uint64_t start, uint64_t size, unsigned ignored);
 void del_mdas(struct dm_list *mdas);
--- LVM2/lib/metadata/metadata.h	2011/02/21 12:17:26	1.234
+++ LVM2/lib/metadata/metadata.h	2011/02/21 12:17:54	1.235
@@ -278,6 +278,13 @@
 				     unsigned metadata_ignored);
 
 	/*
+	 * Remove metadata area from a PV. Changes will take effect on pv_write.
+	 */
+	int (*pv_remove_metadata_area) (const struct format_type *fmt,
+					struct physical_volume *pv,
+					unsigned metadata_index);
+
+	/*
 	 * Write a PV structure to disk. Fails if the PV is in a VG ie
 	 * pv->vg_name must be a valid orphan VG name
 	 */


^ permalink raw reply	[flat|nested] 4+ messages in thread
* LVM2/lib format_text/format-text.c format_text ...
@ 2011-02-21 12:17 prajnoha
  0 siblings, 0 replies; 4+ messages in thread
From: prajnoha @ 2011-02-21 12:17 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	prajnoha@sourceware.org	2011-02-21 12:17:26

Modified files:
	lib/format_text: format-text.c format-text.h 
	lib/metadata   : metadata.h 

Log message:
	Add new pv_add_metadata_area interface function.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/format-text.c.diff?cvsroot=lvm2&r1=1.158&r2=1.159
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/format-text.h.diff?cvsroot=lvm2&r1=1.29&r2=1.30
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.h.diff?cvsroot=lvm2&r1=1.233&r2=1.234

--- LVM2/lib/format_text/format-text.c	2011/02/21 12:15:59	1.158
+++ LVM2/lib/format_text/format-text.c	2011/02/21 12:17:26	1.159
@@ -2028,6 +2028,250 @@
 	return 1;
 }
 
+int add_metadata_area_to_pv(struct physical_volume *pv,
+			    unsigned mda_index,
+			    uint64_t mda_start,
+			    uint64_t mda_size,
+			    unsigned mda_ignored)
+{
+	struct metadata_area *mda;
+	struct mda_context *mdac;
+	struct mda_lists *mda_lists = (struct mda_lists *) pv->fmt->private;
+
+	if (mda_index >= FMT_TEXT_MAX_MDAS_PER_PV) {
+		log_error(INTERNAL_ERROR "can't add metadata area with "
+					 "index %u to PV %s. Metadata "
+					 "layout not supported by %s format.",
+					  mda_index, dev_name(pv->dev),
+					  pv->fmt->name);
+	}
+
+	if (!(mda = dm_malloc(sizeof(struct metadata_area)))) {
+		log_error("struct metadata_area allocation failed");
+		return 0;
+	}
+
+	if (!(mdac = dm_malloc(sizeof(struct mda_context)))) {
+		log_error("struct mda_context allocation failed");
+		dm_free(mda);
+		return 0;
+	}
+
+	mda->ops = mda_lists->raw_ops;
+	mda->metadata_locn = mdac;
+	mda->status = 0;
+
+	mdac->area.dev = pv->dev;
+	mdac->area.start = mda_start;
+	mdac->area.size = mda_size;
+	mdac->free_sectors = UINT64_C(0);
+	memset(&mdac->rlocn, 0, sizeof(mdac->rlocn));
+	mda_set_ignored(mda, mda_ignored);
+
+	fid_add_mda(pv->fid, mda, (char *) &pv->id, ID_LEN, mda_index);
+
+	return 1;
+}
+
+static int _text_pv_add_metadata_area(const struct format_type *fmt,
+				      struct physical_volume *pv,
+				      int pe_start_locked,
+				      unsigned mda_index,
+				      uint64_t mda_size,
+				      unsigned mda_ignored)
+{
+	struct format_instance *fid = pv->fid;
+	const char *pvid = (char *) &pv->id;
+	uint64_t pe_start, pe_end;
+	uint64_t alignment, alignment_offset;
+	uint64_t disk_size;
+	uint64_t mda_start;
+	uint64_t adjustment, limit;
+	uint64_t wipe_size = 8 << SECTOR_SHIFT;
+	size_t page_size = lvm_getpagesize();
+	struct metadata_area *mda;
+	struct mda_context *mdac;
+
+	if (mda_index >= FMT_TEXT_MAX_MDAS_PER_PV) {
+		log_error(INTERNAL_ERROR "invalid index of value %u used "
+			      "while trying to add metadata area on PV %s. "
+			      "Metadata layout not supported by %s format.",
+			       mda_index, pv_dev_name(pv), fmt->name);
+		return 0;
+	}
+
+	pe_start = pv->pe_start << SECTOR_SHIFT;
+	alignment = pv->pe_align << SECTOR_SHIFT;
+	alignment_offset = pv->pe_align_offset << SECTOR_SHIFT;
+	disk_size = pv->size << SECTOR_SHIFT;
+	mda_size = mda_size << SECTOR_SHIFT;
+
+	if (fid_get_mda_indexed(fid, pvid, ID_LEN, mda_index)) {
+		log_error(INTERNAL_ERROR "metadata area with index %u already "
+			"exists on PV %s.", mda_index, pv_dev_name(pv));
+		return 0;
+	}
+
+	/* First metadata area at the start of the device. */
+	if (mda_index == 0) {
+		/*
+		 * Try to fit MDA0 end within given pe_start limit if its value
+		 * is locked. If it's not locked, count with any existing MDA1.
+		 * If there's no MDA1, just use disk size as the limit.
+		 */
+		if (pe_start_locked)
+			limit = pe_start;
+		else if ((mda = fid_get_mda_indexed(fid, pvid, ID_LEN, 1)) &&
+			 (mdac = mda->metadata_locn))
+			limit = mdac->area.start;
+		else
+			limit = disk_size;
+
+		if (limit > disk_size)
+			goto bad;
+
+		mda_start = LABEL_SCAN_SIZE;
+
+		/* Align MDA0 start with page size if possible. */
+		if (limit - mda_start >= MDA_SIZE_MIN) {
+			if ((adjustment = mda_start % page_size))
+				mda_start += (page_size - adjustment);
+		}
+
+		/* Align MDA0 end position with given alignment if possible. */
+		if (alignment) {
+			if ((adjustment = (mda_start + mda_size) % alignment)) {
+				mda_size += (alignment - adjustment);
+				if (mda_start + mda_size > limit)
+					mda_size -= (alignment - adjustment);
+			}
+		}
+
+		/* Align MDA0 end position with given alignment offset if possible. */
+		if (alignment_offset &&
+		    (((mda_start + mda_size) % alignment) == 0)) {
+			mda_size += alignment_offset;
+			if (mda_start + mda_size > limit)
+				mda_size -= alignment_offset;
+		}
+
+		if (mda_start + mda_size > limit) {
+			log_warn("WARNING: metadata area size outreaches "
+				 "a limit on PV %s specified by its %s. "
+				 "Trying to adjust metadata area size.",
+				  pv_dev_name(pv),
+				  pe_start_locked ? "PE start" : "disk size");
+
+			/*
+			 * Try to decrease the MDA0 size with twice the
+			 * alignment and then align with given alignment.
+			 * If pe_start is locked, skip this type of
+			 * alignment since it would be useless.
+			 * Check first whether we can apply that!
+			 */
+			if (!pe_start_locked &&
+			    ((limit - mda_start) > alignment * 2)) {
+				mda_size = limit - mda_start - alignment * 2;
+
+				if ((adjustment = (mda_start + mda_size) % alignment))
+					mda_size += (alignment - adjustment);
+
+				/* Still too much? Then there's nothing else to do. */
+				if (mda_start + mda_size > limit)
+					goto bad;
+			}
+			/* Otherwise, give up and take any usable space. */
+			/* FIXME: We should probably check for some minimum MDA size here. */
+			else
+				mda_size = limit - mda_start;
+		}
+
+		/*
+		 * If PV's pe_start is not locked, update pe_start value with the
+		 * start of the area that follows the MDA0 we've just calculated.
+		 */
+		if (!pe_start_locked) {
+			pe_start = mda_start + mda_size;
+			pv->pe_start = pe_start >> SECTOR_SHIFT;
+		}
+	}
+	/* Second metadata area at the end of the device. */
+	else {
+		/*
+		 * Try to fit MDA1 start within given pe_end or pe_start limit
+		 * if it's locked. If pe_start and pe_end are not defined yet,
+		 * count with any existing MDA0 and pe_start. If MDA0 does not
+		 * exist, just use LABEL_SCAN_SIZE.
+		 */
+		pe_end = pv->pe_count ? (pv->pe_start +
+					 pv->pe_count * pv->pe_size - 1) << SECTOR_SHIFT
+				      : 0;
+		if (pe_start_locked)
+			limit = pe_end ? pe_end : pe_start;
+		else if (pe_start)
+			limit = pe_start;
+		/*
+		 * Normally MDA0's start + size should be pe_start.
+		 * The statemet here is probably useless since the
+		 * situation is covered by previous statement.
+		 */
+		else if ((mda = fid_get_mda_indexed(fid, pvid, ID_LEN, 0)) &&
+			 (mdac = mda->metadata_locn))
+			limit = mdac->area.start + mdac->area.size;
+		else
+			limit = LABEL_SCAN_SIZE;
+
+		if (limit > disk_size || mda_size > disk_size)
+			goto bad;
+
+		mda_start = disk_size - mda_size;
+
+		if (alignment) {
+			adjustment = mda_start % alignment;
+			if (adjustment)
+				mda_size += adjustment;
+		}
+
+		if (disk_size - mda_size < limit)
+			mda_size = disk_size - limit;
+
+		/*
+		 * If PV's pe_end not set yet, set it to the end of the
+		 * area that precedes the MDA1 we've just calculated.
+		 * FIXME: do we need to set this? Isn't it always set before?
+		 */
+		/*if (!pe_end) {
+			pe_end = mda_start;
+			pv->pe_end = pe_end >> SECTOR_SHIFT;
+		}*/
+	}
+
+	if (mda_size) {
+		/* Wipe metadata area with zeroes. */
+		if (!dev_set((struct device *) pv->dev, mda_start,
+			(size_t) ((mda_size > wipe_size) ?
+				  wipe_size : mda_size), 0)) {
+				log_error("Failed to wipe new metadata area "
+					  "at the %s of the %s",
+					   mda_index ? "end" : "start",
+					   pv_dev_name(pv));
+				return 0;
+		}
+
+		/* Finally, add new metadata area to PV's format instance. */
+		if (!add_metadata_area_to_pv(pv, mda_index, mda_start,
+					     mda_size, mda_ignored))
+			return_0;
+	}
+
+	return 1;
+
+bad:
+	log_error("Not enough space available for metadata area "
+		  "with index %u on PV %s.", mda_index, pv_dev_name(pv));
+	return 0;
+}
+
 /* NULL vgname means use only the supplied context e.g. an archive file */
 static struct format_instance *_text_create_text_instance(const struct format_type *fmt,
 							   const struct format_instance_ctx *fic)
@@ -2102,6 +2346,7 @@
 	.scan = _text_scan,
 	.pv_read = _text_pv_read,
 	.pv_setup = _text_pv_setup,
+	.pv_add_metadata_area = _text_pv_add_metadata_area,
 	.pv_write = _text_pv_write,
 	.vg_setup = _text_vg_setup,
 	.lv_setup = _text_lv_setup,
--- LVM2/lib/format_text/format-text.h	2011/02/21 12:05:50	1.29
+++ LVM2/lib/format_text/format-text.h	2011/02/21 12:17:26	1.30
@@ -56,6 +56,11 @@
 	   uint64_t start, uint64_t size);
 void del_das(struct dm_list *das);
 
+int add_metadata_area_to_pv(struct physical_volume *pv,
+			    unsigned mda_index,
+			    uint64_t mda_start,
+			    uint64_t mda_size,
+			    unsigned mda_ignored);
 int add_mda(const struct format_type *fmt, struct dm_pool *mem, struct dm_list *mdas,
 	    struct device *dev, uint64_t start, uint64_t size, unsigned ignored);
 void del_mdas(struct dm_list *mdas);
--- LVM2/lib/metadata/metadata.h	2011/02/21 12:16:00	1.233
+++ LVM2/lib/metadata/metadata.h	2011/02/21 12:17:26	1.234
@@ -35,6 +35,7 @@
 //#define MAX_RESTRICTED_LVS 255	/* Used by FMT_RESTRICTED_LVIDS */
 #define MIRROR_LOG_OFFSET	2	/* sectors */
 #define VG_MEMPOOL_CHUNK	10240	/* in bytes, hint only */
+#define PV_PE_START_CALC	((uint64_t) -1) /* Calculate pe_start value */
 
 /*
  * Ceiling(n / sz)
@@ -267,6 +268,16 @@
 			 struct physical_volume * pv, struct volume_group * vg);
 
 	/*
+	 * Add metadata area to a PV. Changes will take effect on pv_write.
+	 */
+	int (*pv_add_metadata_area) (const struct format_type * fmt,
+				     struct physical_volume * pv,
+				     int pe_start_locked,
+				     unsigned metadata_index,
+				     uint64_t metadata_size,
+				     unsigned metadata_ignored);
+
+	/*
 	 * Write a PV structure to disk. Fails if the PV is in a VG ie
 	 * pv->vg_name must be a valid orphan VG name
 	 */


^ permalink raw reply	[flat|nested] 4+ messages in thread
* LVM2/lib format_text/format-text.c format_text ...
@ 2010-06-30 13:51 agk
  0 siblings, 0 replies; 4+ messages in thread
From: agk @ 2010-06-30 13:51 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	agk@sourceware.org	2010-06-30 13:51:13

Modified files:
	lib/format_text: format-text.c text_label.c 
	lib/metadata   : metadata.c metadata.h 

Log message:
	Improve various log messages.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/format-text.c.diff?cvsroot=lvm2&r1=1.137&r2=1.138
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/text_label.c.diff?cvsroot=lvm2&r1=1.34&r2=1.35
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.c.diff?cvsroot=lvm2&r1=1.368&r2=1.369
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.h.diff?cvsroot=lvm2&r1=1.213&r2=1.214

--- LVM2/lib/format_text/format-text.c	2010/06/30 12:17:24	1.137
+++ LVM2/lib/format_text/format-text.c	2010/06/30 13:51:11	1.138
@@ -1642,14 +1642,19 @@
 /*
  * Return a string description of the metadata location.
  */
-static const char * _metadata_locn_desc_raw(void *metadata_locn)
+static const char *_metadata_locn_name_raw(void *metadata_locn)
 {
-	struct mda_context *mdac;
+	struct mda_context *mdac = (struct mda_context *) metadata_locn;
 
-	mdac = (struct mda_context *) metadata_locn;
 	return dev_name(mdac->area.dev);
 }
 
+static uint64_t const _metadata_locn_offset_raw(void *metadata_locn)
+{
+	struct mda_context *mdac = (struct mda_context *) metadata_locn;
+
+	return mdac->area.start;
+}
 
 static int _text_pv_read(const struct format_type *fmt, const char *pv_name,
 		    struct physical_volume *pv, struct dm_list *mdas,
@@ -1743,7 +1748,8 @@
 	.vg_commit = _vg_commit_raw,
 	.vg_revert = _vg_revert_raw,
 	.mda_metadata_locn_copy = _metadata_locn_copy_raw,
-	.mda_metadata_locn_desc = _metadata_locn_desc_raw,
+	.mda_metadata_locn_name = _metadata_locn_name_raw,
+	.mda_metadata_locn_offset = _metadata_locn_offset_raw,
 	.mda_free_sectors = _mda_free_sectors_raw,
 	.mda_total_sectors = _mda_total_sectors_raw,
 	.mda_in_vg = _mda_in_vg_raw,
--- LVM2/lib/format_text/text_label.c	2010/06/30 12:17:24	1.34
+++ LVM2/lib/format_text/text_label.c	2010/06/30 13:51:11	1.35
@@ -314,10 +314,10 @@
 		mda_set_ignored(mda, rlocn_is_ignored(mdah->raw_locns));
 
 		if (mda_is_ignored(mda)) {
-			log_verbose("Skipping mda with ignored flag on "
-				    "device %s at offset %"PRIu64,
-				    dev_name(mdac->area.dev),
-				    mdac->area.start);
+			log_debug("Skipping mda with ignored flag on "
+				  "device %s at offset %"PRIu64,
+				  dev_name(mdac->area.dev),
+				  mdac->area.start);
 			if (!dev_close(mdac->area.dev))
 				stack;
 			continue;
--- LVM2/lib/metadata/metadata.c	2010/06/30 12:17:24	1.368
+++ LVM2/lib/metadata/metadata.c	2010/06/30 13:51:13	1.369
@@ -58,8 +58,6 @@
 static uint32_t _vg_bad_status_bits(const struct volume_group *vg,
 				    uint64_t status);
 
-static int _vg_adjust_ignored_mdas(struct volume_group *vg);
-
 const char _really_init[] =
     "Really INITIALIZE physical volume \"%s\" of volume group \"%s\" [y/n]? ";
 
@@ -1011,10 +1009,13 @@
 {
 	struct metadata_area *mda;
 
-	log_verbose("Setting ignore flag for %"PRIu32" mdas on vg %s",
-		    num_to_ignore, vg->name);
+	log_debug("Adjusting ignored mdas on vg %s: %" PRIu32 " mdas in use "
+		  "but %" PRIu32 " required.  Changing %" PRIu32 " flags.",
+		  vg->name, vg_mda_copies(vg), vg_mda_used_count(vg), num_to_ignore);
+
 	if (!num_to_ignore)
 		return 1;
+
 	/* FIXME: flip bits on random mdas */
 	dm_list_iterate_items(mda, &vg->fid->metadata_areas_in_use) {
 		if (!mda_is_ignored(mda)) {
@@ -1024,8 +1025,10 @@
 		if (!num_to_ignore)
 			return 1;
 	}
-	log_error("Unable to find %"PRIu32" metadata areas to ignore "
+
+	log_error(INTERNAL_ERROR "Unable to find %"PRIu32" metadata areas to ignore "
 		  "on volume group %s", num_to_ignore, vg->name);
+
 	return 0;
 }
 
@@ -1033,11 +1036,14 @@
 {
 	struct metadata_area *mda, *tmda;
 
-	log_verbose("Clearing ignore flag for %"PRIu32" mdas on vg %s",
-		    num_to_unignore, vg->name);
 	if (!num_to_unignore)
 		return 1;
-	/* FIXME: flip bits on random mdas */
+
+	log_debug("Adjusting ignored mdas on vg %s: %" PRIu32 " mdas in use "
+		  "but %" PRIu32 " required.  Changing %" PRIu32 " flags.",
+		  vg->name, vg_mda_copies(vg), vg_mda_used_count(vg), num_to_unignore);
+
+	/* FIXME: Select mdas to change at random */
 	dm_list_iterate_items_safe(mda, tmda, &vg->fid->metadata_areas_ignored) {
 		if (mda_is_ignored(mda)) {
 			mda_set_ignored(mda, 0);
@@ -1048,6 +1054,7 @@
 		if (!num_to_unignore)
 			return 1;
 	}
+
 	dm_list_iterate_items(mda, &vg->fid->metadata_areas_in_use) {
 		if (mda_is_ignored(mda)) {
 			mda_set_ignored(mda, 0);
@@ -1056,8 +1063,10 @@
 		if (!num_to_unignore)
 			return 1;
 	}
-	log_error("Unable to find %"PRIu32" metadata areas to un-ignore "
-		  "on volume group %s", num_to_unignore, vg->name);
+
+	log_error(INTERNAL_ERROR "Unable to find %"PRIu32" metadata areas to unignore "
+		 "on volume group %s", num_to_unignore, vg->name);
+
 	return 0;
 }
 
@@ -1067,15 +1076,12 @@
 	int ret = 1;
 
 	mda_copies = vg_mda_used_count(vg);
-	log_verbose("Adjusting ignored mdas on vg %s, vg_mda_used_count=%"
-		    PRIu32", vg_mda_copies=%"PRIu32,
-		    vg->name, mda_copies, vg_mda_copies(vg));
 	if (vg->mda_copies == VGMETADATACOPIES_UNMANAGED)
 		goto skip_adjust;
 
-	if (mda_copies > vg->mda_copies) {
+	if (mda_copies > vg->mda_copies)
 		ret = _vg_ignore_mdas(vg, mda_copies - vg->mda_copies);
-	} else if (mda_copies < vg->mda_copies) {
+	else if (mda_copies < vg->mda_copies) {
 		/* not an error to have vg_mda_count larger than total mdas */
 		if (vg->mda_copies >= vg_mda_count(vg))
 			count = vg_mda_count(vg) - vg_mda_used_count(vg);
@@ -1083,6 +1089,7 @@
 			count = vg->mda_copies - mda_copies;
 		ret = _vg_unignore_mdas(vg, count);
 	}
+
 	/*
 	 * The VGMETADATACOPIES_ALL value will never be written disk.
 	 * It is a special cmdline value that means 2 things:
@@ -1093,7 +1100,7 @@
 		vg->mda_copies = VGMETADATACOPIES_UNMANAGED;
 
 	if (!ret)
-		return ret;
+		return_0;
 
 skip_adjust:
 	/*
@@ -1104,10 +1111,13 @@
 	 * below check and retain correctness.
 	 */
 	if (!dm_list_size(&vg->fid->metadata_areas_in_use) ||
-	    !vg_mda_used_count(vg)) {
+	    !vg_mda_used_count(vg))
 		ret = _vg_unignore_mdas(vg, 1);
-	}
-	return ret;
+
+	if (!ret)
+		return_0;
+
+	return 1;
 }
 
 uint32_t vg_mda_copies(const struct volume_group *vg)
@@ -1115,16 +1125,19 @@
 	return vg->mda_copies;
 }
 
-int vg_set_mda_copies(struct volume_group *vg, uint32_t copies)
+int vg_set_mda_copies(struct volume_group *vg, uint32_t mda_copies)
 {
 	/* FIXME: add checks, etc, and set the value */
 	/*
 	 * FIXME: Before we set a larger value, we may need to
 	 * enable some mdas on PVS
 	 */
-	vg->mda_copies = copies;
-	log_verbose("Setting mda_copies = %"PRIu32" on vg %s",
-		    copies, vg->name);
+	vg->mda_copies = mda_copies;
+
+	/* FIXME Use log_verbose when this is due to specific cmdline request. */
+	log_debug("Setting mda_copies to %"PRIu32" for VG %s",
+		    mda_copies, vg->name);
+
 	return 1;
 }
 
@@ -2528,7 +2541,8 @@
 		return 0;
 	}
 
-	_vg_adjust_ignored_mdas(vg);
+	if (!_vg_adjust_ignored_mdas(vg))
+		return_0;
 
 	if (dm_list_empty(&vg->fid->metadata_areas_in_use)) {
 		log_error("Aborting vg_write: No metadata areas to write to!");
@@ -4138,22 +4152,19 @@
 void mda_set_ignored(struct metadata_area *mda, unsigned ignored)
 {
 	void *locn = mda->metadata_locn;
+	unsigned old_ignored = mda_is_ignored(mda);
 
-	if (ignored) {
+	if (ignored && !old_ignored)
 		mda->flags |= MDA_IGNORED;
-	} else {
+	else if (!ignored && old_ignored)
 		mda->flags &= ~MDA_IGNORED;
-	}
-	if (mda->ops->mda_metadata_locn_desc)
-		log_verbose("%s mda ignored flag for "
-			    "metadata_locn %s.",
-			    ignored ? "Setting" : "Clearing",
-			    mda->ops->mda_metadata_locn_desc(locn));
 	else
-		log_verbose("%s mda ignored flag for "
-			    "metadata_locn %p.",
-			    ignored ? "Setting" : "Clearing",
-			    locn);
+		return;	/* No change */
+
+	log_debug("%s ignored flag for mda %s at offset %" PRIu64 ".", 
+		  ignored ? "Setting" : "Clearing",
+		  mda->ops->mda_metadata_locn_name ? mda->ops->mda_metadata_locn_name(locn) : "",
+		  mda->ops->mda_metadata_locn_offset ? mda->ops->mda_metadata_locn_offset(locn) : UINT64_C(0));
 }
 
 uint32_t pv_mda_count(const struct physical_volume *pv)
@@ -4201,9 +4212,7 @@
 	 * Do not allow disabling of the the last PV in a VG.
 	 */
 	if (pv_mda_used_count(pv) == vg_mda_used_count(pv->vg)) {
-		log_error("Cannot disable metadata - volume group "
-			  "needs at least one physical volume with "
-			  "metadata areas in use.\n");
+		log_error("Cannot disable all metadata areas in Volume Group.");
 		return 0;
 	}
 
--- LVM2/lib/metadata/metadata.h	2010/06/29 22:37:32	1.213
+++ LVM2/lib/metadata/metadata.h	2010/06/30 13:51:13	1.214
@@ -139,10 +139,12 @@
 	 * Per location copy constructor.
 	 */
 	void *(*mda_metadata_locn_copy) (struct dm_pool *mem, void *metadata_locn);
+
 	/*
-	 * Per location description - useful for logging.
+	 * Per location description for logging.
 	 */
-	const char *(*mda_metadata_locn_desc) (void *metadata_locn);
+	const char *(*mda_metadata_locn_name) (void *metadata_locn);
+	uint64_t const (*mda_metadata_locn_offset) (void *metadata_locn);
 
 	/*
 	 * Returns number of free sectors in given metadata area.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-02-21 12:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-30 17:13 LVM2/lib format_text/format-text.c format_text agk
  -- strict thread matches above, loose matches on Subject: below --
2011-02-21 12:17 prajnoha
2011-02-21 12:17 prajnoha
2010-06-30 13:51 agk

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).