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

[lvm-devel] [PATCH] A different implementation of --ignorelockingfailure.



Hi,

two ends are addressed by this patch: getting rid of some global state and also
restricting --ignorelockingfailure to only allow what it is supposed to allow
(instead of a few hacked-in checks at some places and our belief that the users
will be well-behaved).

Yours,
   Petr.

Thu Jan 22 11:12:30 CET 2009  Petr Rockai <me mornfall net>
  * Remove lockingfailed().
  
  We provide a lock type that behaves like no_locking, but is not
  clustered. Moreover, it also forbids any write locks. This magically (and
  consistently) prevents use of clustered VGs, or changing local VGs with
  --ignorelockingfailure. As a bonus, we can remove the special hacks in a few
  places. Of course, people looking for trouble can always set their locking_type
  to 0 to override.
diff -rN -u -p old-lvmlib/lib/locking/locking.c new-lvmlib/lib/locking/locking.c
--- old-lvmlib/lib/locking/locking.c	2009-01-22 11:14:00.158779503 +0100
+++ new-lvmlib/lib/locking/locking.c	2009-01-22 11:14:00.202779927 +0100
@@ -211,8 +211,6 @@ static void _update_vg_lock_count(uint32
  */
 int init_locking(int type, struct cmd_context *cmd)
 {
-	init_lockingfailed(0);
-
 	switch (type) {
 	case 0:
 		init_no_locking(&_locking, cmd);
@@ -271,9 +269,7 @@ int init_locking(int type, struct cmd_co
 
 	/* FIXME Ensure only read ops are permitted */
 	log_verbose("Locking disabled - only read operations permitted.");
-
-	init_no_locking(&_locking, cmd);
-	init_lockingfailed(1);
+	init_boottime_locking(&_locking, cmd);
 
 	return 1;
 }
diff -rN -u -p old-lvmlib/lib/locking/locking_types.h new-lvmlib/lib/locking/locking_types.h
--- old-lvmlib/lib/locking/locking_types.h	2009-01-22 11:14:00.158779503 +0100
+++ new-lvmlib/lib/locking/locking_types.h	2009-01-22 11:14:00.202779927 +0100
@@ -38,6 +38,8 @@ struct locking_type {
  */
 int init_no_locking(struct locking_type *locking, struct cmd_context *cmd);
 
+int init_boottime_locking(struct locking_type *locking, struct cmd_context *cmd);
+
 int init_file_locking(struct locking_type *locking, struct cmd_context *cmd);
 
 int init_external_locking(struct locking_type *locking, struct cmd_context *cmd);
diff -rN -u -p old-lvmlib/lib/locking/no_locking.c new-lvmlib/lib/locking/no_locking.c
--- old-lvmlib/lib/locking/no_locking.c	2009-01-22 11:14:00.158779503 +0100
+++ new-lvmlib/lib/locking/no_locking.c	2009-01-22 11:14:00.202779927 +0100
@@ -66,6 +66,17 @@ static int _no_lock_resource(struct cmd_
 	return 1;
 }
 
+static int _boottime_lock_resource(struct cmd_context *cmd,
+				   const char *resource,
+				   uint32_t flags)
+{
+	if (flags & LCK_TYPE_MASK == LCK_WRITE) {
+		log_error("Write locks are prohibited with --ignorelockingfailure.");
+		return 0;
+	}
+	return _no_lock_resource(cmd, resource, flags);
+}
+
 int init_no_locking(struct locking_type *locking, struct cmd_context *cmd __attribute((unused)))
 {
 	locking->lock_resource = _no_lock_resource;
@@ -75,3 +86,13 @@ int init_no_locking(struct locking_type 
 
 	return 1;
 }
+
+int init_boottime_locking(struct locking_type *locking, struct cmd_context *cmd __attribute((unused)))
+{
+	locking->lock_resource = _boottime_lock_resource;
+	locking->reset_locking = _no_reset_locking;
+	locking->fin_locking = _no_fin_locking;
+	locking->flags = 0;
+
+	return 1;
+}
diff -rN -u -p old-lvmlib/lib/metadata/metadata.c new-lvmlib/lib/metadata/metadata.c
--- old-lvmlib/lib/metadata/metadata.c	2009-01-22 11:14:00.154779134 +0100
+++ new-lvmlib/lib/metadata/metadata.c	2009-01-22 11:14:00.206780576 +0100
@@ -2386,8 +2386,7 @@ static uint32_t _vg_check_status(const s
 	uint32_t failure = 0;
 
 	if ((status & CLUSTERED) &&
-	    (vg_is_clustered(vg)) && !locking_is_clustered() &&
-	    !lockingfailed()) {
+	    (vg_is_clustered(vg)) && !locking_is_clustered()) {
 		log_error("Skipping clustered volume group %s", vg->name);
 		return FAILED_CLUSTERED;
 	}
diff -rN -u -p old-lvmlib/lib/misc/lvm-globals.c new-lvmlib/lib/misc/lvm-globals.c
--- old-lvmlib/lib/misc/lvm-globals.c	2009-01-22 11:14:00.154779134 +0100
+++ new-lvmlib/lib/misc/lvm-globals.c	2009-01-22 11:14:00.206780576 +0100
@@ -31,7 +31,6 @@ static int _trust_cache = 0; /* Don't sc
 static int _debug_level = 0;
 static int _log_cmd_name = 0;
 static int _ignorelockingfailure = 0;
-static int _lockingfailed = 0;
 static int _security_level = SECURITY_LEVEL;
 static char _cmd_name[30] = "";
 static int _mirror_in_sync = 0;
@@ -77,11 +76,6 @@ void init_ignorelockingfailure(int level
 	_ignorelockingfailure = level;
 }
 
-void init_lockingfailed(int level)
-{
-	_lockingfailed = level;
-}
-
 void init_security_level(int level)
 {
 	_security_level = level;
@@ -161,11 +155,6 @@ int trust_cache()
 	return _trust_cache;
 }
 
-int lockingfailed()
-{
-	return _lockingfailed;
-}
-
 int ignorelockingfailure()
 {
 	return _ignorelockingfailure;
diff -rN -u -p old-lvmlib/man/lvm.conf.5 new-lvmlib/man/lvm.conf.5
--- old-lvmlib/man/lvm.conf.5	2009-01-22 11:14:00.054777458 +0100
+++ new-lvmlib/man/lvm.conf.5	2009-01-22 11:14:00.218780704 +0100
@@ -1,4 +1,4 @@
-.TH LVM.CONF 5 "LVM TOOLS" "Sistina Software UK" \" -*- nroff -*-
+.TH LVM.CONF 5 "LVM TOOLS 2.02.44-cvs (2008-11-19)" "Sistina Software UK" \" -*- nroff -*-
 .SH NAME
 lvm.conf \- Configuration file for LVM2
 .SH SYNOPSIS
diff -rN -u -p old-lvmlib/tools/lvchange.c new-lvmlib/tools/lvchange.c
--- old-lvmlib/tools/lvchange.c	2009-01-22 11:14:00.154779134 +0100
+++ new-lvmlib/tools/lvchange.c	2009-01-22 11:14:00.242779145 +0100
@@ -119,12 +119,6 @@ static int lvchange_availability(struct 
 		if (!deactivate_lv(cmd, lv))
 			return_0;
 	} else {
-		if (lockingfailed() && (vg_is_clustered(lv->vg))) {
-			log_verbose("Locking failed: ignoring clustered "
-				    "logical volume %s", lv->name);
-			return 0;
-		}
-
 		if (lv_is_origin(lv) || (activate == CHANGE_AE)) {
 			log_verbose("Activating logical volume \"%s\" "
 				    "exclusively", lv->name);
diff -rN -u -p old-lvmlib/tools/vgchange.c new-lvmlib/tools/vgchange.c
--- old-lvmlib/tools/vgchange.c	2009-01-22 11:14:00.154779134 +0100
+++ new-lvmlib/tools/vgchange.c	2009-01-22 11:14:00.246780631 +0100
@@ -138,14 +138,8 @@ static int _vgchange_available(struct cm
 		return ECMD_FAILED;
 	}
 
-	if (activate && lockingfailed() && (vg_is_clustered(vg))) {
-		log_error("Locking inactive: ignoring clustered "
-			  "volume group %s", vg->name);
-		return ECMD_FAILED;
-	}
-
 	/* FIXME Move into library where clvmd can use it */
-	if (activate && !lockingfailed())
+	if (activate)
 		check_current_backup(vg);
 
 	if (activate && (active = lvs_in_vg_activated(vg))) {

-- 
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]