Skip to contentSkip to conversation

LVM2 ./WHATS_NEW lib/cache/lvmcache.c lib/cach ...

PATCH [email protected] 1 participant 1 message Jun 1, 2011

lore
Share & tools
lore
#0 lore raw

CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: agk at sourceware.org 2011-06-01 19:29:34

Modified files:

	.              : WHATS_NEW 
	lib/cache      : lvmcache.c lvmcache.h 
	lib/format1    : format1.c import-export.c 

lib/format_text: format-text.c import_vsn1.c
lib/metadata : metadata.c metadata.h pv.h vg.c vg.h
tools : pvcreate.c pvremove.c pvresize.c toollib.c

Log message:
Defer writing PV labels to vg_write. Store label_sector only in struct physical_volume.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.2003&r2=1.2004
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/cache/lvmcache.c.diff?cvsroot=lvm2&r1=1.110&r2=1.111
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/cache/lvmcache.h.diff?cvsroot=lvm2&r1=1.38&r2=1.39
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format1/format1.c.diff?cvsroot=lvm2&r1=1.138&r2=1.139
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format1/import-export.c.diff?cvsroot=lvm2&r1=1.117&r2=1.118
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/format-text.c.diff?cvsroot=lvm2&r1=1.180&r2=1.181
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/import_vsn1.c.diff?cvsroot=lvm2&r1=1.87&r2=1.88
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.c.diff?cvsroot=lvm2&r1=1.456&r2=1.457
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.h.diff?cvsroot=lvm2&r1=1.243&r2=1.244
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/pv.h.diff?cvsroot=lvm2&r1=1.10&r2=1.11
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/vg.c.diff?cvsroot=lvm2&r1=1.9&r2=1.10
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/vg.h.diff?cvsroot=lvm2&r1=1.11&r2=1.12
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvcreate.c.diff?cvsroot=lvm2&r1=1.94&r2=1.95
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvremove.c.diff?cvsroot=lvm2&r1=1.34&r2=1.35
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvresize.c.diff?cvsroot=lvm2&r1=1.44&r2=1.45
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/toollib.c.diff?cvsroot=lvm2&r1=1.226&r2=1.227

WHATS_NEW +2 -0
@@ -1,5 +1,7 @@
 Version 2.02.86 -  
 =================================
+  Defer writing PV labels to vg_write.
+  Store label_sector only in struct physical_volume.
   Permit --available with lvcreate so non-snapshot LVs need not be activated.
   Report sector containing label in verbose message.
   Clarify error message when unable to convert an LV into a snapshot of an LV.
lib/cache/lvmcache.c +26 -20

77 lines not on this page · raw message

lib/cache/lvmcache.h +1 -1
@@ -99,7 +99,7 @@
 struct lvmcache_info *info_from_pvid(const char *pvid, int valid_only);
 const char *vgname_from_vgid(struct dm_pool *mem, const char *vgid);
 struct device *device_from_pvid(struct cmd_context *cmd, const struct id *pvid,
-				unsigned *scan_done_once);
+				unsigned *scan_done_once, uint64_t *label_sector);
 const char *pvid_from_devname(struct cmd_context *cmd,
 			      const char *dev_name);
 char *lvmcache_vgname_from_pvid(struct cmd_context *cmd, const char *pvid);
lib/format1/format1.c +17 -3
@@ -406,6 +406,8 @@
 	struct disk_list *dl;
 	struct dm_list pvs;
 	struct lvmcache_info *info;
+	int pe_count, pe_size, pe_start;
+	int r = 1;
 
 	if (!(info = lvmcache_add(fmt->labeller, (char *) &pv->id, pv->dev,
 				  pv->vg_name, NULL, 0)))
@@ -418,6 +420,10 @@
 
 	dm_list_init(&pvs);
 
+	pe_count = pv->pe_count;
+	pe_size = pv->pe_size;
+	pe_start = pv->pe_start;
+
 	/* Ensure any residual PE structure is gone */
 	pv->pe_size = pv->pe_count = 0;
 	pv->pe_start = LVM1_PE_ALIGN;
@@ -430,6 +436,8 @@
 
 	dl->mem = mem;
 	dl->dev = pv->dev;
+	dm_list_init(&dl->uuids);
+	dm_list_init(&dl->lvds);
 
 	if (!export_pv(fmt->cmd, mem, NULL, &dl->pvd, pv))
 		goto_bad;
@@ -444,12 +452,18 @@
 	if (!write_disks(fmt, &pvs))
 		goto_bad;
 
-	dm_pool_destroy(mem);
-	return 1;
+	goto out;
 
       bad:
+	r = 0;
+
+      out:
+	pv->pe_size = pe_size;
+	pv->pe_count = pe_count;
+	pv->pe_start = pe_start;
+
 	dm_pool_destroy(mem);
-	return 0;
+	return r;
 }
 
 static int _format1_vg_setup(struct format_instance *fid, struct volume_group *vg)
lib/format1/import-export.c +3 -1
@@ -96,6 +96,8 @@
 	pv->pe_count = pvd->pe_total;
 	pv->pe_alloc_count = 0;
 	pv->pe_align = 0;
+        pv->is_labelled = 0; /* format1 PVs have no label */
+        pv->label_sector = 0;
 
 	/* Fix up pv size if missing or impossibly large */
 	if (!pv->size || pv->size > (1ULL << 62)) {
@@ -149,7 +151,7 @@
 
 	memcpy(pvd->pv_uuid, pv->id.uuid, ID_LEN);
 
-	if (pv->vg_name && !is_orphan(pv)) {
+	if (pv->vg_name && !is_orphan(pv) && !(pv->status & UNLABELLED_PV)) {
 		if (!_check_vg_name(pv->vg_name))
 			return_0;
 		strncpy((char *)pvd->vg_name, pv->vg_name, sizeof(pvd->vg_name));
lib/format_text/format-text.c +5 -30
@@ -45,10 +45,6 @@
 	uint32_t raw_metadata_buf_size;
 };
 
-struct text_fid_pv_context {
-	int64_t label_sector;
-};
-
 struct dir_list {
 	struct dm_list list;
 	char dir[0];
@@ -1252,11 +1248,9 @@
 /* Only for orphans */
 static int _text_pv_write(const struct format_type *fmt, struct physical_volume *pv)
 {
-	struct text_fid_pv_context *fid_pv_tc;
 	struct format_instance *fid = pv->fid;
 	const char *pvid = (const char *) (*pv->old_id.uuid ? &pv->old_id : &pv->id);
 	struct label *label;
-	int64_t label_sector;
 	struct lvmcache_info *info;
 	struct mda_context *mdac;
 	struct metadata_area *mda;
@@ -1271,15 +1265,7 @@
 		return_0;
 
 	label = info->label;
-
-	/*
-	 * We can change the label sector for a
-	 * plain PV that is not part of a VG only!
-	 */
-	if (fid && (!fid->type & FMT_INSTANCE_VG) &&
-	    (fid_pv_tc = (struct text_fid_pv_context *) pv->fid->private) &&
-	    ((label_sector = fid_pv_tc->label_sector) != -1))
-		label->sector = label_sector;
+	label->sector = pv->label_sector;
 
 	info->device_size = pv->size << SECTOR_SHIFT;
 	info->fmt = fmt;
@@ -1517,8 +1503,6 @@
 			       unsigned long data_alignment_offset,
 			       struct physical_volume *pv)
 {
-	struct text_fid_pv_context *fid_pv_tc;
-
 	/*
 	 * Try to keep the value of PE start set to a firm value if requested.
 	 * This is usefull when restoring existing PE start value (backups etc.).
@@ -1569,10 +1553,8 @@
 		return 0;
 	}
 
-	if (label_sector != -1) {
-		fid_pv_tc = (struct text_fid_pv_context *) pv->fid->private;
-		fid_pv_tc->label_sector = label_sector;
-	}
+	if (label_sector != -1)
+                pv->label_sector = label_sector;
 
 	return 1;
 }
@@ -1735,16 +1717,9 @@
 static int _create_pv_text_instance(struct format_instance *fid,
                                     const struct format_instance_ctx *fic)
 {
-	struct text_fid_pv_context *fid_pv_tc;
 	struct lvmcache_info *info;
 
-	if (!(fid_pv_tc = (struct text_fid_pv_context *)
-			dm_pool_zalloc(fid->mem, sizeof(*fid_pv_tc)))) {
-		log_error("Couldn't allocate text_fid_pv_context.");
-		return 0;
-	}
-	fid_pv_tc->label_sector = -1;
-	fid->private = (void *) fid_pv_tc;
+	fid->private = NULL;
 
 	if (!(fid->metadata_areas_index.array = dm_pool_zalloc(fid->mem,
 					FMT_TEXT_MAX_MDAS_PER_PV *
@@ -2332,7 +2307,7 @@
 		return 0;
 	}
 
-	if (!(dev_area.dev = device_from_pvid(cmd, &id, NULL))) {
+	if (!(dev_area.dev = device_from_pvid(cmd, &id, NULL, NULL))) {
 		char buffer[64] __attribute__((aligned(8)));
 
 		if (!id_write_format(&id, buffer, sizeof(buffer)))
lib/format_text/import_vsn1.c +4 -1
@@ -190,10 +190,13 @@
 		return 0;
 	}
 
+        pv->is_labelled = 1; /* All format_text PVs are labelled. */
+
 	/*
 	 * Convert the uuid into a device.
 	 */
-	if (!(pv->dev = device_from_pvid(fid->fmt->cmd, &pv->id, scan_done_once))) {
+	if (!(pv->dev = device_from_pvid(fid->fmt->cmd, &pv->id, scan_done_once,
+                                         &pv->label_sector))) {
 		char buffer[64] __attribute__((aligned(8)));
 
 		if (!id_write_format(&pv->id, buffer, sizeof(buffer)))
lib/metadata/metadata.c +84 -45

268 lines not on this page · raw message

lib/metadata/metadata.h +2 -1
@@ -470,7 +470,8 @@
 
 struct physical_volume *pv_by_path(struct cmd_context *cmd, const char *pv_name);
 int add_pv_to_vg(struct volume_group *vg, const char *pv_name,
-		 struct physical_volume *pv);
+		 struct physical_volume *pv, struct pvcreate_params *pp);
+
 int is_mirror_image_removable(struct logical_volume *mimage_lv, void *baton);
 
 uint64_t find_min_mda_size(struct dm_list *mdas);
lib/metadata/pv.h +6 -0
@@ -51,6 +51,12 @@
 	unsigned long pe_align;
 	unsigned long pe_align_offset;
 
+        /* This is true whenever the represented PV has a label associated. */
+        uint64_t is_labelled:1;
+
+        /* NB. label_sector is valid whenever is_labelled is true */
+	uint64_t label_sector;
+
 	struct dm_list segments;	/* Ordered pv_segments covering complete PV */
 	struct dm_list tags;
 };
lib/metadata/vg.c +1 -0
@@ -43,6 +43,7 @@
 	vg->alloc = ALLOC_NORMAL;
 
 	dm_list_init(&vg->pvs);
+	dm_list_init(&vg->pvs_to_create);
 	dm_list_init(&vg->lvs);
 	dm_list_init(&vg->tags);
 	dm_list_init(&vg->removed_pvs);
lib/metadata/vg.h +13 -0
@@ -31,6 +31,12 @@
 	ALLOC_INHERIT
 } alloc_policy_t;
 
+struct pv_to_create {
+	struct dm_list list;
+	struct physical_volume *pv;
+	struct pvcreate_params *pp;
+};
+
 struct volume_group {
 	struct cmd_context *cmd;
 	struct dm_pool *vgmem;
@@ -59,6 +65,13 @@
 	struct dm_list pvs;
 
 	/*
+	 * List of physical volumes that were used in vgextend but do not carry
+	 * a PV label yet. They need to be pvcreate'd at vg_write time.
+	 */
+
+	struct dm_list pvs_to_create;
+
+	/*
 	 * logical volumes
 	 * The following relationship should always hold:
 	 * dm_list_size(lvs) = user visible lv_count + snapshot_count + other invisible LVs
tools/pvcreate.c +1 -1
@@ -112,7 +112,7 @@
 
 		unescape_colons_and_at_signs(argv[i], NULL, NULL);
 
-		if (!(pv = pvcreate_single(cmd, argv[i], &pp))) {
+		if (!(pv = pvcreate_single(cmd, argv[i], &pp, 1))) {
 			stack;
 			ret = ECMD_FAILED;
 		}
tools/pvremove.c +2 -2
@@ -30,7 +30,7 @@
 
 	/* Is there a pv here already? */
 	/* If not, this is an error unless you used -f. */
-	if (!(pv = pv_read(cmd, name, NULL, 1, 0))) {
+	if (!(pv = pv_read(cmd, name, 1, 0))) {
 		if (arg_count(cmd, force_ARG))
 			return 1;
 		log_error("Physical Volume %s not found", name);
@@ -52,7 +52,7 @@
 			goto bad;
 		}
 		free_pv_fid(pv);
-		if (!(pv = pv_read(cmd, name, NULL, 1, 0))) {
+		if (!(pv = pv_read(cmd, name, 1, 0))) {
 			log_error("Failed to read physical volume %s", name);
 			goto bad;
 		}
tools/pvresize.c +1 -1
@@ -43,7 +43,7 @@
 			return 0;
 		}
 
-		if (!(pv = pv_read(cmd, pv_name, NULL, 1, 0))) {
+		if (!(pv = pv_read(cmd, pv_name, 1, 0))) {
 			unlock_vg(cmd, vg_name);
 			log_error("Unable to read PV \"%s\"", pv_name);
 			return 0;
tools/toollib.c +3 -3
@@ -651,7 +651,7 @@
 	}
 
 	while ((dev = dev_iter_get(iter))) {
-		if (!(pv = pv_read(cmd, dev_name(dev), NULL, 0, 0))) {
+		if (!(pv = pv_read(cmd, dev_name(dev), 0, 0))) {
 			memset(&pv_dummy, 0, sizeof(pv_dummy));
 			dm_list_init(&pv_dummy.tags);
 			dm_list_init(&pv_dummy.segments);
@@ -737,7 +737,7 @@
 				}
 				pv = pvl->pv;
 			} else {
-				if (!(pv = pv_read(cmd, argv[opt], NULL,
+				if (!(pv = pv_read(cmd, argv[opt],
 						   1, scan_label_only))) {
 					log_error("Failed to read physical "
 						  "volume \"%s\"", argv[opt]);
@@ -764,7 +764,7 @@
 					scanned = 1;
 					free_pv_fid(pv);
 					if (!(pv = pv_read(cmd, argv[opt],
-							   NULL, 1,
+							   1,
 							   scan_label_only))) {
 						log_error("Failed to read "
 							  "physical volume "