[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[lvm-devel] LVM2 ./WHATS_NEW lib/format_text/format-text.c ...



CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	agk sourceware org	2007-11-05 17:17:56

Modified files:
	.              : WHATS_NEW 
	lib/format_text: format-text.c format-text.h layout.h 
	                 text_label.c 
	lib/metadata   : metadata.c metadata.h 
	lib/report     : columns.h report.c 

Log message:
	Add pv_mda_free and vg_mda_free fields to reports for raw text format.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.728&r2=1.729
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/format-text.c.diff?cvsroot=lvm2&r1=1.84&r2=1.85
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/format-text.h.diff?cvsroot=lvm2&r1=1.22&r2=1.23
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/layout.h.diff?cvsroot=lvm2&r1=1.7&r2=1.8
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/text_label.c.diff?cvsroot=lvm2&r1=1.18&r2=1.19
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.c.diff?cvsroot=lvm2&r1=1.142&r2=1.143
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.h.diff?cvsroot=lvm2&r1=1.173&r2=1.174
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/report/columns.h.diff?cvsroot=lvm2&r1=1.23&r2=1.24
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/report/report.c.diff?cvsroot=lvm2&r1=1.63&r2=1.64

--- LVM2/WHATS_NEW	2007/11/05 01:47:47	1.728
+++ LVM2/WHATS_NEW	2007/11/05 17:17:55	1.729
@@ -1,5 +1,7 @@
 Version 2.02.29 -
 ==================================
+  Fix human-readable output of odd numbers of sectors.
+  Add pv_mda_free and vg_mda_free fields to reports for raw text format.
   Add LVM2 version to 'Generated by' comment in metadata.
   Show 'not usable' space when PV is too large for device in pvdisplay.
   Ignore and fix up any excessive device size found in metadata.
--- LVM2/lib/format_text/format-text.c	2007/11/02 13:06:41	1.84
+++ LVM2/lib/format_text/format-text.c	2007/11/05 17:17:55	1.85
@@ -83,6 +83,13 @@
 	return 1;
 }
 
+static uint64_t _mda_free_sectors_raw(struct metadata_area *mda)
+{
+	struct mda_context *mdac = (struct mda_context *) mda->metadata_locn;
+
+	return mdac->free_sectors;
+}
+
 /*
  * Check if metadata area belongs to vg
  */
@@ -1043,7 +1050,8 @@
 
 const char *vgname_from_mda(const struct format_type *fmt,
 			    struct device_area *dev_area, struct id *vgid,
-			    uint32_t *vgstatus, char **creation_host)
+			    uint32_t *vgstatus, char **creation_host,
+			    uint64_t *mda_free_sectors)
 {
 	struct raw_locn *rlocn;
 	struct mda_header *mdah;
@@ -1052,6 +1060,10 @@
 	unsigned int len = 0;
 	char buf[NAME_LEN + 1] __attribute((aligned(8)));
 	char uuid[64] __attribute((aligned(8)));
+	uint64_t buffer_size, current_usage;
+
+	if (mda_free_sectors)
+		*mda_free_sectors = ((dev_area->size - MDA_HEADER_SIZE) / 2) >> SECTOR_SHIFT;
 
 	if (!dev_open(dev_area->dev)) {
 		stack;
@@ -1114,9 +1126,21 @@
 	}
 
 	log_debug("%s: Found metadata at %" PRIu64 " size %" PRIu64
-		  " for %s (%s)", 
+		  " (in area at %" PRIu64 " size %" PRIu64
+		  ") for %s (%s)", 
 		  dev_name(dev_area->dev), dev_area->start + rlocn->offset,
-		  rlocn->size, vgname, uuid);
+		  rlocn->size, dev_area->start, dev_area->size, vgname, uuid);
+
+	if (mda_free_sectors) {
+		current_usage = (rlocn->size + SECTOR_SIZE - UINT64_C(1)) -
+				 (rlocn->size + SECTOR_SIZE - UINT64_C(1)) % SECTOR_SIZE;
+		buffer_size = mdah->size - MDA_HEADER_SIZE;
+
+		if (current_usage * 2 >= buffer_size)
+			*mda_free_sectors = UINT64_C(0);
+		else
+			*mda_free_sectors = ((buffer_size - 2 * current_usage) / 2) >> SECTOR_SHIFT;
+	}
 
       out:
 	if (!dev_close(dev_area->dev))
@@ -1143,7 +1167,7 @@
 	list_iterate_items(rl, raw_list) {
 		/* FIXME We're reading mdah twice here... */
 		if ((vgname = vgname_from_mda(fmt, &rl->dev_area, &vgid, &vgstatus,
-					      NULL))) {
+					      NULL, NULL))) {
 			if ((vg = _vg_read_raw_area(&fid, vgname,
 						    &rl->dev_area, 0)))
 				lvmcache_update_vg(vg);
@@ -1557,6 +1581,7 @@
 	.vg_precommit = _vg_precommit_raw,
 	.vg_commit = _vg_commit_raw,
 	.vg_revert = _vg_revert_raw,
+	.mda_free_sectors = _mda_free_sectors_raw,
 	.mda_in_vg = _mda_in_vg_raw,
 	.pv_analyze_mda = _pv_analyze_mda_raw,
 };
--- LVM2/lib/format_text/format-text.h	2007/08/20 20:55:26	1.22
+++ LVM2/lib/format_text/format-text.h	2007/11/05 17:17:55	1.23
@@ -57,6 +57,7 @@
 
 const char *vgname_from_mda(const struct format_type *fmt,
 			    struct device_area *dev_area, struct id *vgid,
-			    uint32_t *vgstatus, char **creation_host);
+			    uint32_t *vgstatus, char **creation_host,
+			    uint64_t *mda_free_sectors);
 
 #endif
--- LVM2/lib/format_text/layout.h	2007/08/20 20:55:26	1.7
+++ LVM2/lib/format_text/layout.h	2007/11/05 17:17:55	1.8
@@ -75,6 +75,7 @@
 
 struct mda_context {
 	struct device_area area;
+	uint64_t free_sectors;
 	struct raw_locn rlocn;	/* Store inbetween write and commit */
 };
 
--- LVM2/lib/format_text/text_label.c	2007/08/20 20:55:26	1.18
+++ LVM2/lib/format_text/text_label.c	2007/11/05 17:17:55	1.19
@@ -162,6 +162,7 @@
 	mdac->area.dev = dev;
 	mdac->area.start = start;
 	mdac->area.size = size;
+	mdac->free_sectors = UINT64_C(0);
 	memset(&mdac->rlocn, 0, sizeof(mdac->rlocn));
 
 	list_add(mdas, &mdal->list);
@@ -239,7 +240,8 @@
 	list_iterate_items(mda, &info->mdas) {
 		mdac = (struct mda_context *) mda->metadata_locn;
 		if ((vgname = vgname_from_mda(info->fmt, &mdac->area, 
-					      &vgid, &vgstatus, &creation_host)) &&
+					      &vgid, &vgstatus, &creation_host,
+					      &mdac->free_sectors)) &&
 		    !lvmcache_update_vgname_and_id(info, vgname,
 						   (char *) &vgid, vgstatus,
 						   creation_host))
--- LVM2/lib/metadata/metadata.c	2007/11/02 20:40:04	1.142
+++ LVM2/lib/metadata/metadata.c	2007/11/05 17:17:55	1.143
@@ -1820,7 +1820,7 @@
  */
 int is_orphan_vg(const char *vg_name)
 {
-	return (vg_name[0] ? 0 : 1);
+	return (!strcmp(vg_name, ORPHAN) ? 1 : 0);
 }
 
 /**
--- LVM2/lib/metadata/metadata.h	2007/11/02 13:06:41	1.173
+++ LVM2/lib/metadata/metadata.h	2007/11/05 17:17:55	1.174
@@ -113,6 +113,12 @@
 			  struct volume_group * vg, struct metadata_area * mda);
 	int (*vg_remove) (struct format_instance * fi, struct volume_group * vg,
 			  struct metadata_area * mda);
+
+	/*
+	 * Returns number of free sectors in given metadata area.
+	 */
+	uint64_t (*mda_free_sectors) (struct metadata_area *mda);
+
 	/*
 	 * Check if metadata area belongs to vg
 	 */
--- LVM2/lib/report/columns.h	2007/09/11 13:49:51	1.23
+++ LVM2/lib/report/columns.h	2007/11/05 17:17:55	1.24
@@ -48,6 +48,7 @@
 FIELD(PVS, pv, NUM, "Alloc", pe_alloc_count, 5, uint32, "pv_pe_alloc_count", "Total number of allocated Physical Extents.")
 FIELD(PVS, pv, STR, "PV Tags", tags, 7, tags, "pv_tags", "Tags, if any.")
 FIELD(PVS, pv, NUM, "#PMda", id, 5, pvmdas, "pv_mda_count", "Number of metadata areas on this device.")
+FIELD(PVS, pv, NUM, "#PMdaFree", id, 9, pvmdafree, "pv_mda_free", "Free metadata area space on this device in current units.")
 
 FIELD(VGS, vg, STR, "Fmt", cmd, 3, vgfmt, "vg_fmt", "Type of metadata.")
 FIELD(VGS, vg, STR, "VG UUID", id, 38, uuid, "vg_uuid", "Unique identifier.")
@@ -67,6 +68,7 @@
 FIELD(VGS, vg, NUM, "Seq", seqno, 3, uint32, "vg_seqno", "Revision number of internal metadata.  Incremented whenever it changes.")
 FIELD(VGS, vg, STR, "VG Tags", tags, 7, tags, "vg_tags", "Tags, if any.")
 FIELD(VGS, vg, NUM, "#VMda", cmd, 5, vgmdas, "vg_mda_count", "Number of metadata areas in use by this VG.")
+FIELD(VGS, vg, NUM, "#VMdaFree", cmd, 9, vgmdafree, "vg_mda_free", "Free metadata area space for this VG in current units.")
 
 FIELD(SEGS, seg, STR, "Type", list, 4, segtype, "segtype", "Type of LV segment")
 FIELD(SEGS, seg, NUM, "#Str", area_count, 4, uint32, "stripes", "Number of stripes or mirror legs.")
--- LVM2/lib/report/report.c	2007/09/11 13:49:52	1.63
+++ LVM2/lib/report/report.c	2007/11/05 17:17:55	1.64
@@ -745,6 +745,53 @@
 	return _uint32_disp(rh, mem, field, &count, private);
 }
 
+static int _pvmdafree_disp(struct dm_report *rh, struct dm_pool *mem,
+			   struct dm_report_field *field,
+			   const void *data, void *private)
+{
+	struct lvmcache_info *info; 
+	uint64_t freespace = UINT64_MAX, mda_free;
+	const char *pvid = (const char *)(&((struct id *) data)->uuid);
+	struct metadata_area *mda;
+
+	info = info_from_pvid(pvid);
+
+	list_iterate_items(mda, &info->mdas) {
+		if (!mda->ops->mda_free_sectors)
+			continue;
+		mda_free = mda->ops->mda_free_sectors(mda);
+		if (mda_free < freespace)
+			freespace = mda_free;
+	}
+
+	if (freespace == UINT64_MAX)
+		freespace = UINT64_C(0);
+
+	return _size64_disp(rh, mem, field, &freespace, private);
+}
+
+static int _vgmdafree_disp(struct dm_report *rh, struct dm_pool *mem,
+			   struct dm_report_field *field,
+			   const void *data, void *private)
+{
+	const struct volume_group *vg = (const struct volume_group *) data;
+	uint64_t freespace = UINT64_MAX, mda_free;
+	struct metadata_area *mda;
+
+	list_iterate_items(mda, &vg->fid->metadata_areas) {
+		if (!mda->ops->mda_free_sectors)
+			continue;
+		mda_free = mda->ops->mda_free_sectors(mda);
+		if (mda_free < freespace)
+			freespace = mda_free;
+	}
+
+	if (freespace == UINT64_MAX)
+		freespace = UINT64_C(0);
+
+	return _size64_disp(rh, mem, field, &freespace, private);
+}
+
 static int _lvsegcount_disp(struct dm_report *rh, struct dm_pool *mem,
 			    struct dm_report_field *field,
 			    const void *data, void *private)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]