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

[lvm-devel] [PATCH] Separate the memlock counters for in-command use and for dmeventd.



Hi,

this is basically the other half of bug 537942 -- the first half I have
committed a few hours ago. This one however needs some review, since
it's a little late by European standards and I'd rather not break the
memlock refcounting code completely.

Index: lib/mm/memlock.c
===================================================================
RCS file: /cvs/lvm2/LVM2/lib/mm/memlock.c,v
retrieving revision 1.13
diff -u -p -r1.13 memlock.c
--- lib/mm/memlock.c	18 Nov 2009 18:22:32 -0000	1.13
+++ lib/mm/memlock.c	19 Nov 2009 00:07:53 -0000
@@ -53,6 +53,7 @@ static size_t _size_malloc = 2000000;
 
 static void *_malloc_mem = NULL;
 static int _memlock_count = 0;
+static int _memlock_count_dmeventd = 0;
 static int _priority;
 static int _default_priority;
 
@@ -125,20 +126,42 @@ static void _unlock_mem(void)
 
 void memlock_inc(void)
 {
-	if (!_memlock_count++)
+	if (!_memlock_count++ && !_memlock_count_dmeventd)
 		_lock_mem();
 	log_debug("memlock_count inc to %d", _memlock_count);
 }
 
 void memlock_dec(void)
 {
-	if (_memlock_count && (!--_memlock_count))
+	if (_memlock_count && (!--_memlock_count) && !_memlock_count_dmeventd)
 		_unlock_mem();
 	log_debug("memlock_count dec to %d", _memlock_count);
 	if (_memlock_count < 0)
 		log_error("Internal error: _memlock_count has dropped below 0.");
 }
 
+void memlock_inc_dmeventd(void)
+{
+	if (!_memlock_count_dmeventd++ && !_memlock_count)
+		_lock_mem();
+	log_debug("memlock_count_dmeventd inc to %d", _memlock_count_dmeventd);
+}
+
+void memlock_dec_dmeventd(void)
+{
+	if (_memlock_count_dmeventd && (!--_memlock_count_dmeventd) && !_memlock_count)
+		_unlock_mem();
+	log_debug("memlock_count_dmeventd dec to %d", _memlock_count_dmeventd);
+	if (_memlock_count_dmeventd < 0)
+		log_error("Internal error: _memlock_count_dmeventd has dropped below 0.");
+}
+
+/*
+ * This disregards the dmeventd locks, since we use memlock() to check whether
+ * it is safe to run a device scan, which would normally coincide with
+ * !memlock() -- but the dmeventd global memory lock breaks this assumption, so
+ * we do not take those into account here.
+ */
 int memlock(void)
 {
 	return _memlock_count;
Index: lib/mm/memlock.h
===================================================================
RCS file: /cvs/lvm2/LVM2/lib/mm/memlock.h,v
retrieving revision 1.4
diff -u -p -r1.4 memlock.h
--- lib/mm/memlock.h	20 Aug 2007 20:55:27 -0000	1.4
+++ lib/mm/memlock.h	19 Nov 2009 00:07:53 -0000
@@ -20,6 +20,8 @@ struct cmd_context;
 
 void memlock_inc(void);
 void memlock_dec(void);
+void memlock_inc_dmeventd(void);
+void memlock_dec_dmeventd(void);
 int memlock(void);
 void memlock_init(struct cmd_context *cmd);
 
Index: tools/lvmcmdlib.c
===================================================================
RCS file: /cvs/lvm2/LVM2/tools/lvmcmdlib.c,v
retrieving revision 1.9
diff -u -p -r1.9 lvmcmdlib.c
--- tools/lvmcmdlib.c	22 Feb 2009 22:11:59 -0000	1.9
+++ tools/lvmcmdlib.c	19 Nov 2009 00:07:53 -0000
@@ -82,9 +82,9 @@ int lvm2_run(void *handle, const char *c
 	/* FIXME Temporary - move to libdevmapper */
 	ret = ECMD_PROCESSED;
 	if (!strcmp(cmdline, "_memlock_inc"))
-		memlock_inc();
+		memlock_inc_dmeventd();
 	else if (!strcmp(cmdline, "_memlock_dec"))
-		memlock_dec();
+		memlock_dec_dmeventd();
 	else
 		ret = lvm_run_command(cmd, argc, argv);
 
Yours,
   Petr.

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