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

[lvm-devel] [PATCH] (6/6) new handling for --partial flag



The last patch is a new one, removing partial_mode() altogether (the global
variable hack for enabling partial activation) which has never been quite
compatible with how we treat partial LVs and VGs now. This patch makes
--partial work again (to be more exact, it prevents partial activation from
happening when --partial is not passed).

Tue Jul 29 15:18:01 CEST 2008  me mornfall net
  tagged everything base 2
Mon Jul 28 15:25:16 CEST 2008  me mornfall net
  * Fix pvcreate conflicts.
Mon Jul 28 15:00:24 CEST 2008  me mornfall net
  * Refuse activation of partial LVs by default. Use --partial to override.
Wed Jul 16 18:45:52 CEST 2008  me mornfall net
  * Get rid of partial_mode.
Mon Jul 28 15:20:03 CEST 2008  me mornfall net
  tagged everything base 1
diff -rN -p -u old-hotspare-everything/daemons/clvmd/lvm-functions.c new-hotspare-everything/daemons/clvmd/lvm-functions.c
--- old-hotspare-everything/daemons/clvmd/lvm-functions.c	2008-07-29 15:26:44.161493573 +0200
+++ new-hotspare-everything/daemons/clvmd/lvm-functions.c	2008-07-29 15:26:44.185490029 +0200
@@ -413,9 +413,6 @@ int do_lock_lv(unsigned char command, un
 		}
 	}
 
-	if (lock_flags & LCK_PARTIAL_MODE)
-		init_partial(1);
-
 	if (lock_flags & LCK_MIRROR_NOSYNC_MODE)
 		init_mirror_in_sync(1);
 
@@ -454,9 +451,6 @@ int do_lock_lv(unsigned char command, un
 		break;
 	}
 
-	if (lock_flags & LCK_PARTIAL_MODE)
-		init_partial(0);
-
 	if (lock_flags & LCK_MIRROR_NOSYNC_MODE)
 		init_mirror_in_sync(0);
 
diff -rN -p -u old-hotspare-everything/lib/activate/activate.c new-hotspare-everything/lib/activate/activate.c
--- old-hotspare-everything/lib/activate/activate.c	2008-07-29 15:26:44.153489515 +0200
+++ new-hotspare-everything/lib/activate/activate.c	2008-07-29 15:26:44.225493342 +0200
@@ -1027,6 +1027,12 @@ static int _lv_activate(struct cmd_conte
 		return 0;
 	}
 
+	if ((!lv->vg->cmd->partial_activate) && (lv->status & PARTIAL_LV)) {
+		log_error("Refusing activation of partial LV %s. Use --partial to override.",
+			  lv->name);
+		return_0;
+	}
+
 	if (test_mode()) {
 		_skip("Activating '%s'.", lv->name);
 		return 1;
diff -rN -p -u old-hotspare-everything/lib/commands/toolcontext.h new-hotspare-everything/lib/commands/toolcontext.h
--- old-hotspare-everything/lib/commands/toolcontext.h	2008-07-29 15:26:44.161493573 +0200
+++ new-hotspare-everything/lib/commands/toolcontext.h	2008-07-29 15:26:44.221492256 +0200
@@ -66,9 +66,10 @@ struct cmd_context {
 	struct command *command;
 	struct arg *args;
 	char **argv;
-	unsigned is_static;	/* Static binary? */
-	unsigned is_long_lived;	/* Optimises persistent_filter handling */
-	unsigned handles_missing_pvs;
+	unsigned is_static:1;	/* Static binary? */
+	unsigned is_long_lived:1;	/* Optimises persistent_filter handling */
+	unsigned handles_missing_pvs:1;
+	unsigned partial_activate:1;
 
 	struct dev_filter *filter;
 	int dump_filter;	/* Dump filter when exiting? */
diff -rN -p -u old-hotspare-everything/lib/format1/disk-rep.h new-hotspare-everything/lib/format1/disk-rep.h
--- old-hotspare-everything/lib/format1/disk-rep.h	2008-07-29 15:26:44.161493573 +0200
+++ new-hotspare-everything/lib/format1/disk-rep.h	2008-07-29 15:26:44.229493939 +0200
@@ -212,7 +212,7 @@ int export_pv(struct cmd_context *cmd, s
 	      struct pv_disk *pvd, struct physical_volume *pv);
 
 int import_vg(struct dm_pool *mem,
-	      struct volume_group *vg, struct disk_list *dl, int partial);
+	      struct volume_group *vg, struct disk_list *dl);
 int export_vg(struct vg_disk *vgd, struct volume_group *vg);
 
 int import_lv(struct dm_pool *mem, struct logical_volume *lv, struct lv_disk *lvd);
diff -rN -p -u old-hotspare-everything/lib/format1/format1.c new-hotspare-everything/lib/format1/format1.c
--- old-hotspare-everything/lib/format1/format1.c	2008-07-29 15:26:44.161493573 +0200
+++ new-hotspare-everything/lib/format1/format1.c	2008-07-29 15:26:44.229493939 +0200
@@ -23,7 +23,7 @@
 #include "segtype.h"
 
 /* VG consistency checks */
-static int _check_vgs(struct list *pvs, int *partial)
+static int _check_vgs(struct list *pvs)
 {
 	struct list *pvh, *t;
 	struct disk_list *dl = NULL;
@@ -33,8 +33,6 @@ static int _check_vgs(struct list *pvs, 
 	uint32_t exported = 0;
 	int first_time = 1;
 
-	*partial = 0;
-
 	/*
 	 * If there are exported and unexported PVs, ignore exported ones.
 	 * This means an active VG won't be affected if disks are inserted
@@ -98,10 +96,6 @@ static int _check_vgs(struct list *pvs, 
 				  dl->vgd.pe_total, dl->vgd.pe_allocated,
 				  dl->vgd.pvg_total);
 			list_del(pvh);
-			if (partial_mode()) {
-				*partial = 1;
-				continue;
-			}
 			return 0;
 		}
 		pv_count++;
@@ -111,9 +105,6 @@ static int _check_vgs(struct list *pvs, 
 	if (pv_count != first->vgd.pv_cur) {
 		log_error("%d PV(s) found for VG %s: expected %d",
 			  pv_count, first->pvd.vg_name, first->vgd.pv_cur);
-		if (!partial_mode())
-			return 0;
-		*partial = 1;
 	}
 
 	return 1;
@@ -125,7 +116,6 @@ static struct volume_group *_build_vg(st
 	struct dm_pool *mem = fid->fmt->cmd->mem;
 	struct volume_group *vg = dm_pool_alloc(mem, sizeof(*vg));
 	struct disk_list *dl;
-	int partial;
 
 	if (!vg)
 		goto_bad;
@@ -142,12 +132,12 @@ static struct volume_group *_build_vg(st
 	list_init(&vg->lvs);
 	list_init(&vg->tags);
 
-	if (!_check_vgs(pvs, &partial))
+	if (!_check_vgs(pvs))
 		goto_bad;
 
 	dl = list_item(pvs->n, struct disk_list);
 
-	if (!import_vg(mem, vg, dl, partial))
+	if (!import_vg(mem, vg, dl))
 		goto_bad;
 
 	if (!import_pvs(fid->fmt, mem, vg, pvs, &vg->pvs, &vg->pv_count))
diff -rN -p -u old-hotspare-everything/lib/format1/import-export.c new-hotspare-everything/lib/format1/import-export.c
--- old-hotspare-everything/lib/format1/import-export.c	2008-07-29 15:26:44.161493573 +0200
+++ new-hotspare-everything/lib/format1/import-export.c	2008-07-29 15:26:44.229493939 +0200
@@ -213,7 +213,7 @@ int export_pv(struct cmd_context *cmd, s
 }
 
 int import_vg(struct dm_pool *mem,
-	      struct volume_group *vg, struct disk_list *dl, int partial)
+	      struct volume_group *vg, struct disk_list *dl)
 {
 	struct vg_disk *vgd = &dl->vgd;
 	memcpy(vg->id.uuid, vgd->vg_uuid, ID_LEN);
@@ -235,10 +235,10 @@ int import_vg(struct dm_pool *mem,
 	if (vgd->vg_status & VG_EXTENDABLE)
 		vg->status |= RESIZEABLE_VG;
 
-	if (partial || (vgd->vg_access & VG_READ))
+	if (vgd->vg_access & VG_READ)
 		vg->status |= LVM_READ;
 
-	if (!partial && (vgd->vg_access & VG_WRITE))
+	if (vgd->vg_access & VG_WRITE)
 		vg->status |= LVM_WRITE;
 
 	if (vgd->vg_access & VG_CLUSTERED)
@@ -254,9 +254,6 @@ int import_vg(struct dm_pool *mem,
 	vg->max_pv = vgd->pv_max;
 	vg->alloc = ALLOC_NORMAL;
 
-	if (partial)
-		vg->status |= PARTIAL_VG;
-
 	return 1;
 }
 
diff -rN -p -u old-hotspare-everything/lib/format_text/archiver.c new-hotspare-everything/lib/format_text/archiver.c
--- old-hotspare-everything/lib/format_text/archiver.c	2008-07-29 15:26:44.161493573 +0200
+++ new-hotspare-everything/lib/format_text/archiver.c	2008-07-29 15:26:44.225493342 +0200
@@ -134,10 +134,8 @@ int archive_display(struct cmd_context *
 {
 	int r1, r2;
 
-	init_partial(1);
 	r1 = archive_list(cmd, cmd->archive_params->dir, vg_name);
 	r2 = backup_list(cmd, cmd->backup_params->dir, vg_name);
-	init_partial(0);
 
 	return r1 && r2;
 }
@@ -146,9 +144,7 @@ int archive_display_file(struct cmd_cont
 {
 	int r;
 
-	init_partial(1);
 	r = archive_list_file(cmd, file);
-	init_partial(0);
 
 	return r;
 }
diff -rN -p -u old-hotspare-everything/lib/locking/cluster_locking.c new-hotspare-everything/lib/locking/cluster_locking.c
--- old-hotspare-everything/lib/locking/cluster_locking.c	2008-07-29 15:26:44.157491998 +0200
+++ new-hotspare-everything/lib/locking/cluster_locking.c	2008-07-29 15:26:44.221492256 +0200
@@ -315,9 +315,6 @@ static int _lock_for_cluster(unsigned ch
 	args[0] = flags & 0x7F; /* Maskoff lock flags */
 	args[1] = flags & 0xC0; /* Bitmap flags */
 
-	if (partial_mode())
-		args[1] |= LCK_PARTIAL_MODE;
-
 	if (mirror_in_sync())
 		args[1] |= LCK_MIRROR_NOSYNC_MODE;
 
diff -rN -p -u old-hotspare-everything/lib/locking/locking.h new-hotspare-everything/lib/locking/locking.h
--- old-hotspare-everything/lib/locking/locking.h	2008-07-29 15:26:44.157491998 +0200
+++ new-hotspare-everything/lib/locking/locking.h	2008-07-29 15:26:44.221492256 +0200
@@ -83,7 +83,6 @@ int check_lvm1_vg_inactive(struct cmd_co
 /*
  * Additional lock bits for cluster communication
  */
-#define LCK_PARTIAL_MODE	0x00000001U	/* Running in partial mode */
 #define LCK_MIRROR_NOSYNC_MODE	0x00000002U	/* Mirrors don't require sync */
 #define LCK_DMEVENTD_MONITOR_MODE	0x00000004U	/* Register with dmeventd */
 
diff -rN -p -u old-hotspare-everything/lib/log/log.c new-hotspare-everything/lib/log/log.c
--- old-hotspare-everything/lib/log/log.c	2008-07-29 15:26:44.157491998 +0200
+++ new-hotspare-everything/lib/log/log.c	2008-07-29 15:26:44.237495132 +0200
@@ -29,7 +29,6 @@ static struct str_list _log_dev_alias;
 
 static int _verbose_level = VERBOSE_BASE_LEVEL;
 static int _test = 0;
-static int _partial = 0;
 static int _md_filtering = 0;
 static int _pvmove = 0;
 static int _full_scan_done = 0;	/* Restrict to one full scan during each cmd */
@@ -154,11 +153,6 @@ void init_test(int level)
 	_test = level;
 }
 
-void init_partial(int level)
-{
-	_partial = level;
-}
-
 void init_md_filtering(int level)
 {
 	_md_filtering = level;
@@ -254,11 +248,6 @@ int test_mode()
 	return _test;
 }
 
-int partial_mode()
-{
-	return _partial;
-}
-
 int md_filtering()
 {
 	return _md_filtering;
diff -rN -p -u old-hotspare-everything/lib/log/log.h new-hotspare-everything/lib/log/log.h
--- old-hotspare-everything/lib/log/log.h	2008-07-29 15:26:44.157491998 +0200
+++ new-hotspare-everything/lib/log/log.h	2008-07-29 15:26:44.237495132 +0200
@@ -64,7 +64,6 @@ void fin_syslog(void);
 
 void init_verbose(int level);
 void init_test(int level);
-void init_partial(int level);
 void init_md_filtering(int level);
 void init_pvmove(int level);
 void init_full_scan_done(int level);
@@ -84,7 +83,6 @@ void init_error_message_produced(int err
 void set_cmd_name(const char *cmd_name);
 
 int test_mode(void);
-int partial_mode(void);
 int md_filtering(void);
 int pvmove_mode(void);
 int full_scan_done(void);
diff -rN -p -u old-hotspare-everything/lib/metadata/metadata.c new-hotspare-everything/lib/metadata/metadata.c
--- old-hotspare-everything/lib/metadata/metadata.c	2008-07-29 15:26:44.157491998 +0200
+++ new-hotspare-everything/lib/metadata/metadata.c	2008-07-29 15:26:44.233491812 +0200
@@ -468,19 +468,15 @@ struct volume_group *vg_create(struct cm
 	struct volume_group *vg;
 	struct dm_pool *mem = cmd->mem;
 	int consistent = 0;
-	int old_partial;
 
 	if (!(vg = dm_pool_zalloc(mem, sizeof(*vg))))
 		return_NULL;
 
 	/* is this vg name already in use ? */
-	old_partial = partial_mode();
-	init_partial(1);
 	if (vg_read(cmd, vg_name, NULL, &consistent)) {
 		log_err("A volume group called '%s' already exists.", vg_name);
 		goto bad;
 	}
-	init_partial(old_partial);
 
 	if (!id_create(&vg->id)) {
 		log_err("Couldn't create uuid for volume group '%s'.", vg_name);
@@ -1978,8 +1974,6 @@ static struct volume_group *_vg_read_by_
 			if (!consistent) {
 				log_error("Volume group %s metadata is "
 					  "inconsistent", vg->name);
-				if (!partial_mode())
-					return NULL;
 			}
 			return vg;
 		}
@@ -2141,7 +2135,6 @@ static int _get_pvs(struct cmd_context *
 	struct list *vgids;
 	struct volume_group *vg;
 	int consistent = 0;
-	int old_partial;
 	int old_pvmove;
 
 	lvmcache_label_scan(cmd, 0);
@@ -2163,9 +2156,7 @@ static int _get_pvs(struct cmd_context *
 
 	/* Read every VG to ensure cache consistency */
 	/* Orphan VG is last on list */
-	old_partial = partial_mode();
 	old_pvmove = pvmove_mode();
-	init_partial(1);
 	init_pvmove(1);
 	list_iterate_items(strl, vgids) {
 		vgid = strl->str;
@@ -2190,7 +2181,6 @@ static int _get_pvs(struct cmd_context *
 				list_add(results, pvh);
 	}
 	init_pvmove(old_pvmove);
-	init_partial(old_partial);
 
 	if (pvslist)
 		*pvslist = results;
diff -rN -p -u old-hotspare-everything/tools/lvmcmdline.c new-hotspare-everything/tools/lvmcmdline.c
--- old-hotspare-everything/tools/lvmcmdline.c	2008-07-29 15:26:44.157491998 +0200
+++ new-hotspare-everything/tools/lvmcmdline.c	2008-07-29 15:26:44.201495000 +0200
@@ -710,13 +710,13 @@ static int _get_settings(struct cmd_cont
 	cmd->current_settings.archive = arg_int_value(cmd, autobackup_ARG, cmd->current_settings.archive);
 	cmd->current_settings.backup = arg_int_value(cmd, autobackup_ARG, cmd->current_settings.backup);
 	cmd->current_settings.cache_vgmetadata = cmd->command->flags & CACHE_VGMETADATA ? 1 : 0;
+	cmd->partial_activate = 0;
 
 	if (arg_count(cmd, partial_ARG)) {
-		init_partial(1);
+		cmd->partial_activate = 1;
 		log_print("Partial mode. Incomplete volume groups will "
 			  "be activated read-only.");
-	} else
-		init_partial(0);
+	}
 
 	if (arg_count(cmd, ignorelockingfailure_ARG))
 		init_ignorelockingfailure(1);
diff -rN -p -u old-hotspare-everything/tools/pvcreate.c new-hotspare-everything/tools/pvcreate.c
--- old-hotspare-everything/tools/pvcreate.c	2008-07-29 15:26:44.157491998 +0200
+++ new-hotspare-everything/tools/pvcreate.c	2008-07-29 15:26:44.205494968 +0200
@@ -49,7 +49,6 @@ static int pvcreate_check(struct cmd_con
 	/* FIXME Check partition type is LVM unless --force is given */
 
 	/* Is there a pv here already? */
-	/* FIXME Use partial mode here? */
 	pv = pv_read(cmd, name, NULL, NULL, 0);
 
 	/*
@@ -269,13 +268,11 @@ static int pvcreate_validate_params(stru
 	if (arg_count(cmd, restorefile_ARG)) {
 		pp->restorefile = arg_str_value(cmd, restorefile_ARG, "");
 		/* The uuid won't already exist */
-		init_partial(1);
 		if (!(vg = backup_read_vg(cmd, NULL, pp->restorefile))) {
 			log_error("Unable to read volume group from %s",
 				  pp->restorefile);
 			return 0;
 		}
-		init_partial(0);
 		if (!(existing_pv = find_pv_in_vg_by_uuid(vg, pp->idp))) {
 			log_error("Can't find uuid %s in backup file %s",
 				  uuid, pp->restorefile);
diff -rN -p -u old-hotspare-everything/tools/vgcfgbackup.c new-hotspare-everything/tools/vgcfgbackup.c
--- old-hotspare-everything/tools/vgcfgbackup.c	2008-07-29 15:26:44.157491998 +0200
+++ new-hotspare-everything/tools/vgcfgbackup.c	2008-07-29 15:26:44.201495000 +0200
@@ -96,8 +96,7 @@ int vgcfgbackup(struct cmd_context *cmd,
 	int ret;
 	char *last_filename = NULL;
 
-	if (partial_mode())
-		init_pvmove(1);
+	init_pvmove(1);
 
 	ret = process_each_vg(cmd, argc, argv, LCK_VG_READ, 0, &last_filename,
 			      &vg_backup_single);
diff -rN -p -u old-hotspare-everything/tools/vgreduce.c new-hotspare-everything/tools/vgreduce.c
--- old-hotspare-everything/tools/vgreduce.c	2008-07-29 15:26:44.157491998 +0200
+++ new-hotspare-everything/tools/vgreduce.c	2008-07-29 15:26:44.205494968 +0200
@@ -228,14 +228,11 @@ static int _make_vg_consistent(struct cm
 
 		if (!test_mode()) {
 			/* Suspend lvs_changed */
-			init_partial(1);
 			if (!suspend_lvs(cmd, &lvs_changed)) {
 				stack;
-				init_partial(0);
 				vg_revert(vg);
 				return 0;
 			}
-			init_partial(0);
 		}
 
 		if (!vg_commit(vg)) {
@@ -531,7 +528,6 @@ int vgreduce(struct cmd_context *cmd, in
 			return ECMD_PROCESSED;
 		}
 
-		init_partial(1);
 		consistent = !arg_count(cmd, force_ARG);
 		if (!(vg = vg_read(cmd, vg_name, NULL, &consistent))) {
 			log_error("Volume group \"%s\" not found", vg_name);
@@ -543,14 +539,12 @@ int vgreduce(struct cmd_context *cmd, in
 			return ECMD_FAILED;
 		}
 		if (!archive(vg)) {
-			init_partial(0);
 			unlock_vg(cmd, vg_name);
 			return ECMD_FAILED;
 		}
 
 		if (arg_count(cmd, force_ARG)) {
 			if (!_make_vg_consistent(cmd, vg)) {
-				init_partial(0);
 				unlock_vg(cmd, vg_name);
 				return ECMD_FAILED;
 			}

-- 
Peter Rockai | me()mornfall!net | prockai()redhat!com
 http://blog.mornfall.net | http://web.mornfall.net

"In My Egotistical Opinion, most people's C programs should be
 indented six feet downward and covered with dirt."
     -- Blair P. Houghton on the subject of C program indentation

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