[Oracleasm-commits] jlbec commits r354 - in branches/oracleasm-1.0: . kernel

svn-commits@oss.oracle.com svn-commits at oss.oracle.com
Tue Jul 18 16:35:56 CDT 2006


Author: jlbec
Date: 2006-07-18 16:35:54 -0500 (Tue, 18 Jul 2006)
New Revision: 354

Added:
   branches/oracleasm-1.0/kernel/masklog.c
   branches/oracleasm-1.0/kernel/masklog.h
   branches/oracleasm-1.0/kernel/proc.c
   branches/oracleasm-1.0/kernel/proc.h
Modified:
   branches/oracleasm-1.0/configure.in
   branches/oracleasm-1.0/kernel/Makefile
   branches/oracleasm-1.0/kernel/oracleasm.c
Log:

o Introduce masklog to the mix



Modified: branches/oracleasm-1.0/configure.in
===================================================================
--- branches/oracleasm-1.0/configure.in	2006-07-18 21:20:38 UTC (rev 353)
+++ branches/oracleasm-1.0/configure.in	2006-07-18 21:35:54 UTC (rev 354)
@@ -17,9 +17,9 @@
 #
 MAJOR_VERSION=1
 MINOR_VERSION=0
-MICRO_VERSION=4
-INTERFACE_AGE=4
-BINARY_AGE=4
+MICRO_VERSION=5
+INTERFACE_AGE=5
+BINARY_AGE=5
 VERSION="${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}"
 AC_SUBST(MAJOR_VERSION)
 AC_SUBST(MINOR_VERSION)

Modified: branches/oracleasm-1.0/kernel/Makefile
===================================================================
--- branches/oracleasm-1.0/kernel/Makefile	2006-07-18 21:20:38 UTC (rev 353)
+++ branches/oracleasm-1.0/kernel/Makefile	2006-07-18 21:35:54 UTC (rev 354)
@@ -50,6 +50,7 @@
 MODULES = oracleasm.o
 
 SOURCES = oracleasm.c
+INCL_SOURCES = proc.c proc.h masklog.c masklog.h
 OBJECTS = $(subst .c,.o,$(SOURCES))
 
 HEADERS =					\
@@ -59,7 +60,7 @@
 	$(TOPDIR)/include/linux/asmdisk.h	\
 	$(TOPDIR)/include/asmerror.h
 
-oracleasm.o: $(HEADERS)
+oracleasm.o: $(HEADERS) $(INCL_SOURCES)
 
 INSTALL_RULES = install-asm
 
@@ -67,6 +68,6 @@
 	$(TOPDIR)/mkinstalldirs $(DESTDIR)$(MODULEDIR)
 	$(INSTALL_DATA) oracleasm.o $(DESTDIR)$(MODULEDIR)/oracleasm.o
 
-DIST_FILES = $(SOURCES)
+DIST_FILES = $(SOURCES) $(INCL_SOURCES)
 
 include $(TOPDIR)/Postamble.make

Added: branches/oracleasm-1.0/kernel/masklog.c
===================================================================
--- branches/oracleasm-1.0/kernel/masklog.c	2006-07-18 21:20:38 UTC (rev 353)
+++ branches/oracleasm-1.0/kernel/masklog.c	2006-07-18 21:35:54 UTC (rev 354)
@@ -0,0 +1,202 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * Copyright (C) 2004, 2005 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/proc_fs.h>
+#include <linux/seq_file.h>
+#include <linux/string.h>
+#include <asm/uaccess.h>
+
+#include "masklog.h"
+
+struct mlog_bits mlog_and_bits = MLOG_BITS_RHS(MLOG_INITIAL_AND_MASK);
+struct mlog_bits mlog_not_bits = MLOG_BITS_RHS(MLOG_INITIAL_NOT_MASK);
+
+static char *mlog_bit_names[MLOG_MAX_BITS];
+
+static void *mlog_name_from_pos(loff_t *caller_pos)
+{
+	loff_t pos = *caller_pos;
+	while (pos < ARRAY_SIZE(mlog_bit_names) && mlog_bit_names[pos] == NULL)
+		pos++;
+
+	if (pos >= ARRAY_SIZE(mlog_bit_names))
+		return NULL;
+
+	*caller_pos = pos;
+	return &mlog_bit_names[pos];
+}
+
+static void *mlog_seq_start(struct seq_file *seq, loff_t *pos)
+{
+	return mlog_name_from_pos(pos);
+}
+
+static void *mlog_seq_next(struct seq_file *seq, void *v, loff_t *pos)
+{
+	(*pos)++;
+	return mlog_name_from_pos(pos);
+}
+
+static int mlog_seq_show(struct seq_file *seq, void *v)
+{
+	char **name = v;
+	int bit = name - mlog_bit_names;
+	char *state;
+
+	if (__mlog_test_u64((u64)1 << bit, mlog_and_bits))
+		state = "allow";
+	else if (__mlog_test_u64((u64)1 << bit, mlog_not_bits))
+		state = "deny";
+	else
+		state = "off";
+
+	seq_printf(seq, "%s %s\n", *name, state);
+	return 0;
+}
+
+static void mlog_seq_stop(struct seq_file *p, void *v)
+{
+}
+
+static struct seq_operations mlog_seq_ops = {
+	.start = mlog_seq_start,
+	.next = mlog_seq_next,
+	.stop = mlog_seq_stop,
+	.show = mlog_seq_show,
+};
+
+static int mlog_fop_open(struct inode *inode, struct file *file)
+{
+	return seq_open(file, &mlog_seq_ops);
+}
+
+static ssize_t mlog_fop_write(struct file *filp, const char __user *buf,
+			      size_t count, loff_t *pos)
+{
+	char *name;
+	char str[32], *mask, *val;
+	unsigned i, masklen, namelen;
+
+	if (count == 0)
+		return 0;
+
+	/* count at least mask + space + 3 for "off" */
+	if (*pos != 0 || count < 5 || count >= sizeof(str))
+		return -EINVAL;
+
+	if (copy_from_user(str, buf, count))
+		return -EFAULT;
+
+	str[count] = '\0';
+
+	mask = str;
+	val = strchr(str, ' ');
+	if (val == NULL)
+		return -EINVAL;
+	*val = '\0';
+	val++;
+
+	if (strlen(val) == 0)
+		return -EINVAL;
+
+	masklen = strlen(mask);
+
+	for (i = 0; i < ARRAY_SIZE(mlog_bit_names); i++) {
+		name = mlog_bit_names[i];
+
+		if (name == NULL)
+			continue;
+
+		namelen = strlen(name);
+
+		if (namelen != masklen
+		    || strnicmp(mask, name, namelen))
+			continue;
+		break;
+	}
+	if (i == ARRAY_SIZE(mlog_bit_names))
+		return -EINVAL;
+
+	if (!strnicmp(val, "allow", 5)) {
+		__mlog_set_u64((u64)1 << i, mlog_and_bits);
+		__mlog_clear_u64((u64)1 << i, mlog_not_bits);
+	} else if (!strnicmp(val, "deny", 4)) {
+		__mlog_set_u64((u64)1 << i, mlog_not_bits);
+		__mlog_clear_u64((u64)1 << i, mlog_and_bits);
+	} else if (!strnicmp(val, "off", 3)) {
+		__mlog_clear_u64((u64)1 << i, mlog_not_bits);
+		__mlog_clear_u64((u64)1 << i, mlog_and_bits);
+	} else
+		return -EINVAL;
+
+	*pos += count;
+	return count;
+}
+
+static struct file_operations mlog_seq_fops = {
+	.owner = THIS_MODULE,
+	.open = mlog_fop_open,
+	.read = seq_read,
+	.write = mlog_fop_write,
+	.llseek = seq_lseek,
+	.release = seq_release,
+};
+
+#define set_a_string(which) do {					\
+	struct mlog_bits _bits = {{0,}, };				\
+	int _bit;							\
+	__mlog_set_u64(ML_##which, _bits);				\
+	_bit = find_first_bit(_bits.words, MLOG_MAX_BITS);		\
+	mlog_bit_names[_bit] = #which;					\
+} while (0)
+
+#define LOGMASK_PROC_NAME "log_mask"
+
+void mlog_remove_proc(struct proc_dir_entry *parent)
+{
+	remove_proc_entry(LOGMASK_PROC_NAME, parent);
+}
+
+int mlog_init_proc(struct proc_dir_entry *parent)
+{
+	struct proc_dir_entry *p;
+
+	set_a_string(ENTRY);
+	set_a_string(EXIT);
+	set_a_string(DISK);
+	set_a_string(REQUEST);
+	set_a_string(BH);
+	set_a_string(IOC);
+	set_a_string(ABI);
+
+	set_a_string(ERROR);
+	set_a_string(NOTICE);
+
+	p = create_proc_entry(LOGMASK_PROC_NAME, S_IRUGO, parent);
+	if (p == NULL)
+		return -ENOMEM;
+
+	p->proc_fops = &mlog_seq_fops;
+
+	return 0;
+}

Added: branches/oracleasm-1.0/kernel/masklog.h
===================================================================
--- branches/oracleasm-1.0/kernel/masklog.h	2006-07-18 21:20:38 UTC (rev 353)
+++ branches/oracleasm-1.0/kernel/masklog.h	2006-07-18 21:35:54 UTC (rev 354)
@@ -0,0 +1,246 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * Copyright (C) 2005 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+#ifndef O2CLUSTER_MASKLOG_H
+#define O2CLUSTER_MASKLOG_H
+
+/*
+ * For now this is a trivial wrapper around printk() that gives the critical
+ * ability to enable sets of debugging output at run-time.  In the future this
+ * will almost certainly be redirected to relayfs so that it can pay a
+ * substantially lower heisenberg tax.
+ *
+ * Callers associate the message with a bitmask and a global bitmask is
+ * maintained with help from /proc.  If any of the bits match the message is
+ * output.
+ *
+ * We must have efficient bit tests on i386 and it seems gcc still emits crazy
+ * code for the 64bit compare.  It emits very good code for the dual unsigned
+ * long tests, though, completely avoiding tests that can never pass if the
+ * caller gives a constant bitmask that fills one of the longs with all 0s.  So
+ * the desire is to have almost all of the calls decided on by comparing just
+ * one of the longs.  This leads to having infrequently given bits that are
+ * frequently matched in the high bits.
+ *
+ * _ERROR and _NOTICE are used for messages that always go to the console and
+ * have appropriate KERN_ prefixes.  We wrap these in our function instead of
+ * just calling printk() so that this can eventually make its way through
+ * relayfs along with the debugging messages.  Everything else gets KERN_DEBUG.
+ * The inline tests and macro dance give GCC the opportunity to quite cleverly
+ * only emit the appropriage printk() when the caller passes in a constant
+ * mask, as is almost always the case.
+ *
+ * All this bitmask nonsense is hidden from the /proc interface so that Joel
+ * doesn't have an aneurism.  Reading the file gives a straight forward
+ * indication of which bits are on or off:
+ * 	ENTRY off
+ * 	EXIT off
+ * 	ERROR off
+ * 	NOTICE on
+ *
+ * Writing changes the state of a given bit and requires a strictly formatted
+ * single write() call:
+ *
+ * 	write(fd, "ENTRY on", 8);
+ *
+ * would turn the entry bit on.  "1" is also accepted in the place of "on", and
+ * "off" and "0" behave as expected.
+ *
+ * Some trivial shell can flip all the bits on or off:
+ *
+ * log_mask="/proc/fs/oracleasm/log_mask"
+ * cat $log_mask | (
+ * 	while read bit status; do
+ * 		# $1 is "on" or "off", say
+ * 		echo "$bit $1" > $log_mask
+ * 	done
+ * )
+ */
+
+/* for task_struct */
+#include <linux/sched.h>
+
+/* bits that are frequently given and infrequently matched in the low word */
+/* NOTE: If you add a flag, you need to also update mlog.c! */
+#define ML_ENTRY	0x0000000000000001ULL /* func call entry */
+#define ML_EXIT		0x0000000000000002ULL /* func call exit */
+#define ML_DISK		0x0000000000000004ULL /* Disk information */
+#define ML_REQUEST	0x0000000000000010ULL /* I/O requests */
+#define ML_BH		0x0000000000000020ULL /* bhs backing I/O */
+#define ML_IOC		0x0000000000000040ULL /* asm_iocs */
+#define ML_ABI		0x0000000000000100ULL /* ABI entry points */
+/* bits that are infrequently given and frequently matched in the high word */
+#define ML_ERROR	0x0000000100000000ULL /* sent to KERN_ERR */
+#define ML_NOTICE	0x0000000200000000ULL /* setn to KERN_NOTICE */
+
+#define MLOG_INITIAL_AND_MASK (ML_ERROR|ML_NOTICE)
+#define MLOG_INITIAL_NOT_MASK (ML_ENTRY|ML_EXIT)
+#ifndef MLOG_MASK_PREFIX
+#define MLOG_MASK_PREFIX 0
+#endif
+
+#define MLOG_MAX_BITS 64
+
+struct mlog_bits {
+	unsigned long words[MLOG_MAX_BITS / BITS_PER_LONG];
+};
+
+extern struct mlog_bits mlog_and_bits, mlog_not_bits;
+
+#if BITS_PER_LONG == 32
+
+#define __mlog_test_u64(mask, bits)			\
+	( (u32)(mask & 0xffffffff) & bits.words[0] || 	\
+	  ((u64)(mask) >> 32) & bits.words[1] )
+#define __mlog_set_u64(mask, bits) do {			\
+	bits.words[0] |= (u32)(mask & 0xffffffff);	\
+       	bits.words[1] |= (u64)(mask) >> 32;		\
+} while (0)
+#define __mlog_clear_u64(mask, bits) do {		\
+	bits.words[0] &= ~((u32)(mask & 0xffffffff));	\
+       	bits.words[1] &= ~((u64)(mask) >> 32);		\
+} while (0)
+#define MLOG_BITS_RHS(mask) {				\
+	{						\
+		[0] = (u32)(mask & 0xffffffff),		\
+		[1] = (u64)(mask) >> 32,		\
+	}						\
+}
+
+#else /* 32bit long above, 64bit long below */
+
+#define __mlog_test_u64(mask, bits)	((mask) & bits.words[0])
+#define __mlog_set_u64(mask, bits) do {		\
+	bits.words[0] |= (mask);		\
+} while (0)
+#define __mlog_clear_u64(mask, bits) do {	\
+	bits.words[0] &= ~(mask);		\
+} while (0)
+#define MLOG_BITS_RHS(mask) { { (mask) } }
+
+#endif
+
+/*
+ * smp_processor_id() "helpfully" screams when called outside preemptible
+ * regions in current kernels.  sles doesn't have the variants that don't
+ * scream.  just do this instead of trying to guess which we're building
+ * against.. *sigh*.
+ */
+#define __mlog_cpu_guess ({		\
+	unsigned long _cpu = get_cpu();	\
+	put_cpu();			\
+	_cpu;				\
+})
+
+/* In the following two macros, the whitespace after the ',' just
+ * before ##args is intentional. Otherwise, gcc 2.95 will eat the
+ * previous token if args expands to nothing.
+ */
+#define __mlog_printk(level, fmt, args...)				\
+	printk(level "(%u,%lu):%s:%d " fmt, current->pid,		\
+	       __mlog_cpu_guess, __PRETTY_FUNCTION__, __LINE__ ,	\
+	       ##args)
+
+#define mlog(mask, fmt, args...) do {					\
+	u64 __m = MLOG_MASK_PREFIX | (mask);				\
+	if (__mlog_test_u64(__m, mlog_and_bits) &&			\
+	    !__mlog_test_u64(__m, mlog_not_bits)) {			\
+		if (__m & ML_ERROR)					\
+			__mlog_printk(KERN_ERR, "ERROR: "fmt , ##args);	\
+		else if (__m & ML_NOTICE)				\
+			__mlog_printk(KERN_NOTICE, fmt , ##args);	\
+		else __mlog_printk(KERN_INFO, fmt , ##args);		\
+	}								\
+} while (0)
+
+#define mlog_errno(st) do {						\
+	if ((st) != -ERESTARTSYS && (st) != -EINTR)			\
+		mlog(ML_ERROR, "status = %lld\n", (long long)(st));	\
+} while (0)
+
+#define mlog_entry(fmt, args...) do {					\
+	mlog(ML_ENTRY, "ENTRY:" fmt , ##args);				\
+} while (0)
+
+#define mlog_entry_void() do {						\
+	mlog(ML_ENTRY, "ENTRY:\n");					\
+} while (0)
+
+/* We disable this for old compilers since they don't have support for
+ * __builtin_types_compatible_p.
+ */
+#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) && \
+    !defined(__CHECKER__)
+#define mlog_exit(st) do {						     \
+	if (__builtin_types_compatible_p(typeof(st), unsigned long))	     \
+		mlog(ML_EXIT, "EXIT: %lu\n", (unsigned long) (st));	     \
+	else if (__builtin_types_compatible_p(typeof(st), signed long))      \
+		mlog(ML_EXIT, "EXIT: %ld\n", (signed long) (st));	     \
+	else if (__builtin_types_compatible_p(typeof(st), unsigned int)	     \
+		 || __builtin_types_compatible_p(typeof(st), unsigned short) \
+		 || __builtin_types_compatible_p(typeof(st), unsigned char)) \
+		mlog(ML_EXIT, "EXIT: %u\n", (unsigned int) (st));	     \
+	else if (__builtin_types_compatible_p(typeof(st), signed int)	     \
+		 || __builtin_types_compatible_p(typeof(st), signed short)   \
+		 || __builtin_types_compatible_p(typeof(st), signed char))   \
+		mlog(ML_EXIT, "EXIT: %d\n", (signed int) (st));		     \
+	else if (__builtin_types_compatible_p(typeof(st), long long))	     \
+		mlog(ML_EXIT, "EXIT: %lld\n", (long long) (st));	     \
+	else								     \
+		mlog(ML_EXIT, "EXIT: %llu\n", (unsigned long long) (st));    \
+} while (0)
+#else
+#define mlog_exit(st) do {						     \
+	mlog(ML_EXIT, "EXIT: %lld\n", (long long) (st));		     \
+} while (0)
+#endif
+
+#define mlog_exit_ptr(ptr) do {						\
+	mlog(ML_EXIT, "EXIT: %p\n", ptr);				\
+} while (0)
+
+#define mlog_exit_void() do {						\
+	mlog(ML_EXIT, "EXIT\n");					\
+} while (0)
+
+#define mlog_bug_on_msg(cond, fmt, args...) do {			\
+	if (cond) {							\
+		mlog(ML_ERROR, "bug expression: " #cond "\n");		\
+		mlog(ML_ERROR, fmt, ##args);				\
+		BUG();							\
+	}								\
+} while (0)
+
+#if (BITS_PER_LONG == 32) || defined(CONFIG_X86_64)
+#define MLFi64 "lld"
+#define MLFu64 "llu"
+#define MLFx64 "llx"
+#else
+#define MLFi64 "ld"
+#define MLFu64 "lu"
+#define MLFx64 "lx"
+#endif
+
+#include <linux/proc_fs.h>
+int mlog_init_proc(struct proc_dir_entry *parent);
+void mlog_remove_proc(struct proc_dir_entry *parent);
+
+#endif /* O2CLUSTER_MASKLOG_H */

Modified: branches/oracleasm-1.0/kernel/oracleasm.c
===================================================================
--- branches/oracleasm-1.0/kernel/oracleasm.c	2006-07-18 21:20:38 UTC (rev 353)
+++ branches/oracleasm-1.0/kernel/oracleasm.c	2006-07-18 21:35:54 UTC (rev 354)
@@ -74,6 +74,14 @@
 #include "asmerror.h"
 
 
+#define __user
+#include "masklog.h"
+#include "proc.h"
+
+/* XXX ugly for now */
+#include "proc.c"
+
+
 #if PAGE_CACHE_SIZE % 1024
 #error Oh no, PAGE_CACHE_SIZE is not divisible by 1k! I cannot cope.
 #endif  /* PAGE_CACHE_SIZE % 1024 */
@@ -116,28 +124,8 @@
 # endif  /* BITS_PER_LONG == 64 */
 #endif  /* BITS_PER_LONG == 32 */
 
-/* Turn debugging on */
-#undef DEBUG 
-#undef DEBUG1
-#undef DEBUG_BROKEN
-#define dprintk(x...) do { ; } while (0)
-#define dprintk1(x...) do { ; } while (0)
-#undef LOG_ENABLE
 
 
-#ifndef LOG_ENABLE
-#define LOG_ENTRY() do { ; } while (0)
-#define LOG_EXIT() do { ; } while (0)
-#define LOG_EXIT_RET(x...) do { ; } while (0)
-#define LOG(x...) do { ; } while (0)
-#else
-#define LOG_ENTRY() do { printk("ASM: Entered %s\n", __FUNCTION__); } while (0)
-#define LOG_EXIT() do { printk("ASM: Exited %s\n", __FUNCTION__); } while (0)
-#define LOG_EXIT_RET(ret) do { printk("ASM: Exited %s with code 0x%lX\n", __FUNCTION__, (unsigned long)(ret)); } while (0)
-#define LOG printk
-#endif  /* LOG_ENABLE */
-
-
 static struct super_operations asmfs_ops;
 static struct address_space_operations asmfs_aops;
 static struct file_operations asmfs_dir_operations;
@@ -350,9 +338,9 @@
 	struct list_head *l, *p;
 	struct asm_disk_info *d = NULL;
 
-	LOG_ENTRY();
+	mlog_entry("(0x%p, %d)\n", aii, dev);
 
-	LOG("ASM: Looking up disk %d,%d\n", MAJOR(dev), MINOR(dev));
+	mlog(ML_DISK, "Looking up disk %d,%d\n", MAJOR(dev), MINOR(dev));
 	
 	spin_lock_irq(&aii->i_lock);
 	l = &(aii->disk_hash[ASM_HASH_DISK(dev)]);
@@ -371,7 +359,7 @@
 out:
 	spin_unlock_irq(&aii->i_lock);
 
-	LOG_EXIT_RET(d);
+	mlog_exit_ptr(d);
 	return d;
 }  /* asm_find_disk() */
 
@@ -381,8 +369,7 @@
 	struct list_head *l, *p;
 	struct asm_disk_info *d, *n;
 
-	if (!aii)
-		BUG();
+	mlog_bug_on_msg(!aii, "No inode\n");
 
 	/* FIXME: Maybe a kmem_cache_t later */
 	n = kmalloc(sizeof(*n), GFP_KERNEL);
@@ -398,8 +385,10 @@
 
 	list_for_each(p, l) {
 		d = list_entry(l, struct asm_disk_info, d_hash);
-		if (d->d_dev == dev)
+		if (d->d_dev == dev) {
+			atomic_inc(&d->d_count);
 			break;
+		}
 		d = NULL;
 	}
 out:
@@ -423,13 +412,14 @@
 
 static inline void asm_put_disk(struct asm_disk_info *d)
 {
-	if (!d)
-		BUG();
+	mlog_bug_on_msg(!d, "No disk to put\n");
 
 	if (atomic_dec_and_test(&d->d_count)) {
-		dprintk("ASM: Freeing disk 0x%.8lX\n", (unsigned long)d->d_dev);
-		if (!list_empty(&d->d_open))
-			BUG();
+		mlog(ML_DISK,
+		     "Freeing disk 0x%.8lX\n", (unsigned long)d->d_dev);
+		mlog_bug_on_msg(!list_empty(&d->d_open),
+				"Disk 0x%.8lX has openers\n",
+				(unsigned long)d->d_dev);
 
 		kfree(d);
 	}
@@ -565,7 +555,6 @@
 	struct inode * inode;
 	int error = -ENOSPC;
 
-	dprintk("ASM: Alloc'd dentry\n");
 	inode = asmfs_get_inode(dir->i_sb, mode, dev);
 
 	if (inode) {
@@ -759,8 +748,8 @@
 	struct asm_disk_info *d;
 	struct asm_disk_head *h;
 
-	if (!afi || !aii)
-		BUG();
+	mlog_bug_on_msg(!afi || !aii,
+			"Can't open disk without afi or aii\n");
 
 	h = kmalloc(sizeof(*h), GFP_KERNEL);
 	if (!h)
@@ -770,7 +759,11 @@
 	if (!d) {
 		/* FIXME: Need to verify it's a valid device here */
 		d = asm_add_disk(aii, dev);
-	}
+		mlog(ML_DISK, "First open of disk 0x%p (dev 0x%.8lX)\n",
+		     d, (unsigned long)d->d_dev);
+	} else
+		mlog(ML_DISK, "Open of disk 0x%p (dev 0x%.8lX)\n", d,
+		     (unsigned long)d->d_dev);
 
 	h->h_disk = d;
 	h->h_file = afi;
@@ -795,13 +788,16 @@
 	struct task_struct *tsk = current;
 	DECLARE_WAITQUEUE(wait, tsk);
 
-	if (!afi || !aii)
-		BUG();
+	mlog_bug_on_msg(!afi || !aii,
+			"Can't close disk without afi or aii\n");
 
 	d = asm_find_disk(aii, dev);
 	if (!d)
 		return -EINVAL;
 
+	mlog(ML_DISK, "Closing disk 0x%p (dev 0x%.8lX)\n",
+	     d, (unsigned long)d->d_dev);
+
 	spin_lock_irq(&afi->f_lock);
 	h = NULL;
 	list_for_each(p, &afi->f_disks) {
@@ -810,8 +806,9 @@
 			break;
 		h = NULL;
 	}
-	if (!h)
-		BUG();
+	mlog_bug_on_msg(!h,
+			"Trying to close disk 0x%.8lX with no connection to afi 0x%p",
+			(unsigned long)dev, afi);
 
 	list_del(&h->h_flist);
 	spin_unlock_irq(&afi->f_lock);
@@ -822,8 +819,9 @@
 	/* Last close */
 	if (list_empty(&d->d_open))
 	{
-		dprintk("Last close of disk 0x%.8lX (0x%p, pid=%d)\n",
-		       (unsigned long)d->d_dev, d, tsk->pid);
+		mlog(ML_DISK,
+		     "Last close of disk 0x%p (dev 0x%.8lX)\n",
+		     d, (unsigned long)d->d_dev);
 		list_del(&d->d_hash);
 
 		spin_unlock_irq(&aii->i_lock);
@@ -919,18 +917,18 @@
 	u16 tmp_status;
 
 	ioc = r->r_ioc;
-	dprintk("ASM: User IOC is 0x%p\n", ioc);
+	mlog(ML_IOC, "User IOC is 0x%p\n", ioc);
 
 	/* Need to get the current userspace bits because ASM_CANCELLED is currently set there */
-	dprintk("ASM: Getting tmp_status\n");
+	mlog(ML_IOC, "Getting tmp_status\n");
 	if (get_user(tmp_status, &(ioc->status_asm_ioc)))
 		return -EFAULT;
 	r->r_status |= tmp_status;
-	dprintk("ASM: Putting r_status (0x%08X)\n", r->r_status);
+	mlog(ML_IOC, "Putting r_status (0x%08X)\n", r->r_status);
 	if (put_user(r->r_status, &(ioc->status_asm_ioc)))
 		return -EFAULT;
 	if (r->r_status & ASM_ERROR) {
-		dprintk("ASM: Putting r_error (0x%08X)\n", r->r_error);
+		mlog(ML_IOC, "Putting r_error (0x%08X)\n", r->r_error);
 		if (put_user(r->r_error, &(ioc->error_asm_ioc)))
 			return -EFAULT;
 	}
@@ -938,10 +936,11 @@
 		if (put_user(r->r_elapsed, &(ioc->elaptime_asm_ioc)))
 			return -EFAULT;
 	}
-	dprintk("ASM: r_status:0x%08X, bitmask:0x%08X, combined:0x%08X\n",
-	       r->r_status,
-	       (ASM_SUBMITTED | ASM_COMPLETED | ASM_ERROR),
-	       (r->r_status & (ASM_SUBMITTED | ASM_COMPLETED | ASM_ERROR)));
+	mlog(ML_IOC,
+	     "r_status:0x%08X, bitmask:0x%08X, combined:0x%08X\n",
+	     r->r_status,
+	     (ASM_SUBMITTED | ASM_COMPLETED | ASM_ERROR),
+	     (r->r_status & (ASM_SUBMITTED | ASM_COMPLETED | ASM_ERROR)));
 	if (r->r_status & ASM_FREE) {
 		u64 z = 0ULL;
 		if (copy_to_user(&(ioc->reserved_asm_ioc),
@@ -950,7 +949,8 @@
 	} else if (r->r_status &
 		   (ASM_SUBMITTED | ASM_ERROR)) {
 		u64 key = (u64)(unsigned long)r;
-		dprintk("ASM: Putting key 0x%p\n", r);
+		mlog(ML_IOC, "Putting key 0x%p on asm_ioc 0x%p\n",
+		     r, ioc);
 		/* Only on first submit */
 		if (copy_to_user(&(ioc->reserved_asm_ioc),
 				 &key, sizeof(ioc->reserved_asm_ioc)))
@@ -996,9 +996,10 @@
 	struct asmfs_file_info *afi = r->r_file;
 	unsigned long flags;
 
-	if (!afi)
-		BUG();
+	mlog_entry("(0x%p)\n", r);
 
+	mlog_bug_on_msg(!afi, "Request 0x%p has no file\n", r);
+
 	if (d) {
 		r->r_disk = NULL;
 		atomic_dec(&d->d_ios);
@@ -1021,7 +1022,11 @@
 
 	r->r_elapsed = ((jiffies - r->r_elapsed) * 1000000) / HZ;
 
+	mlog(ML_REQUEST, "Finished request 0x%p\n", r);
+
 	wake_up(&afi->f_wait);
+
+	mlog_exit_void();
 }  /* asm_finish_io() */
 
 
@@ -1030,15 +1035,17 @@
 	struct asm_request *r = _req;
 	ssize_t err = 0;
 	
-	LOG_ENTRY();
-	if (!r)
-		BUG();
+	mlog_entry("(0x%p, 0x%p, %d)\n", _req, vec, (int)res);
 
-	if (!(r->r_status & ASM_SUBMITTED))
-		BUG();
+	mlog_bug_on_msg(!r, "kvec 0x%p has no request\n", vec);
 
-	LOG("ASM: Releasing kvec for request at 0x%p\n", r);
+	mlog_bug_on_msg(!(r->r_status & ASM_SUBMITTED),
+			"Request 0x%p was not submitted\n", r);
 
+	mlog(ML_REQUEST,
+	     "Releasing kvec for request at 0x%p, res = %d\n",
+	     r, (int)res);
+
 	if (res < 0) {
 		err = res;
 		res = 0;
@@ -1053,6 +1060,8 @@
 			else
 				err = -EIO;
 		}
+		mlog(ML_BH, "Freeing bh 0x%p from request 0x%p\n",
+		     tmp, r);
 		kmem_cache_free(bh_cachep, tmp);
 	}
 	r->r_bh = r->r_bhtail = NULL;
@@ -1065,7 +1074,9 @@
 
 	switch (err) {
 		default:
-			dprintk("ASM: Invalid error of %d!\n", err);
+			mlog(ML_REQUEST|ML_ERROR,
+			     "Invalid error of %d on request 0x%p!\n",
+			     err, r);
 			r->r_error = ASM_ERR_INVAL;
 			break;
 
@@ -1096,7 +1107,7 @@
 
 	asm_finish_io(r);
 
-	LOG_EXIT();
+	mlog_exit_void();
 }  /* asm_end_kvec_io() */
 
 
@@ -1104,18 +1115,20 @@
 {
 	struct asm_request *r;
 
-	LOG_ENTRY();
+	mlog_entry("(0x%p, %d)\n", bh, uptodate);
+
 	mark_buffer_uptodate(bh, uptodate);
 
 	r = bh->b_private;
-	LOG("ASM: Releasing buffer for request at 0x%p\n", r);
+	mlog(ML_BH, "Releasing buffer 0x%p for request at 0x%p\n",
+	     bh, r);
 	unlock_buffer(bh);
 
 	if (atomic_dec_and_test(&r->r_io_count)) {
 		asm_end_kvec_io(r, r->r_cb.vec, 0);
 	}
 
-	LOG_EXIT();
+	mlog_exit_void();
 }  /* asm_end_buffer_io() */
 
 
@@ -1137,10 +1150,10 @@
 # endif  /* LINUX_VERSION_CODE */
 #endif  /* CONFIG_UNITEDLINUX_KERNEL */
 
-	LOG_ENTRY();
-	if (!vec->nr)
-		BUG();
+	mlog_entry("(%d, 0x%p, %lu, %lu)\n", rw, r, blknr, nr);
 
+	mlog_bug_on_msg(!vec->nr, "Empty I/O on request 0x%p\n", r);
+
 	/* 
 	 * First, do some alignment and validity checks 
 	 */
@@ -1150,14 +1163,17 @@
 		if ((veclet->offset & (sector_size-1)) ||
 		    (veclet->length & (sector_size-1)) ||
 		    ((veclet->length + veclet->offset) > PAGE_SIZE)) {
-			dprintk("ASM: asm_build_io: tuple[%d]->offset=0x%x length=0x%x sector_size: 0x%x\n", i, veclet->offset, veclet->length, sector_size);
+			mlog(ML_REQUEST,
+			     "Bad veclet on request 0x%p: tuple[%d]->offset=0x%x length=0x%x sector_size: 0x%x\n",
+			     r, i, veclet->offset, veclet->length,
+			     sector_size);
 			return -EINVAL;
 		}
 	}
 
 	/* We deal in blocks, so this should be valid */
-	if (length != (nr * sector_size))
-		BUG();
+	mlog_bug_on_msg(length != (nr * sector_size),
+			"Length doesn't match sector count for request 0x%p\n", r);
 
 	/* 
 	 * OK to walk down the iovec doing page IO on each page we find. 
@@ -1165,7 +1181,7 @@
 	err = 0;
 
 	if (!nr) {
-		dprintk("ASM: asm_build_io: !i\n");
+		mlog(ML_REQUEST, "No veclets to I/O\n");
 		return -EINVAL;
 	}
 
@@ -1187,8 +1203,9 @@
 		unsigned iosize = veclet->length;
 		struct buffer_head *tmp;
 	       
-		if (!page)
-			BUG();
+		mlog_bug_on_msg(!page,
+				"Veclet missing page on request 0x%p\n",
+				r);
 
 		tmp = kmem_cache_alloc(bh_cachep, GFP_NOIO);
 		err = -ENOMEM;
@@ -1226,6 +1243,7 @@
 			clear_bit(BH_Dirty, &tmp->b_state);
 		}
 
+		mlog(ML_BH, "Adding bh 0x%p to request 0x%p\n", tmp, r);
 		if (r->r_bh)
 		{
 			r->r_bhtail->b_next = tmp;
@@ -1248,7 +1266,7 @@
 
 	atomic_set(&r->r_io_count, r->r_bh_count);
 
-	LOG_EXIT_RET(0);
+	mlog_exit(0);
 	return 0;
 
 error:
@@ -1260,7 +1278,7 @@
 	}
 	r->r_bhtail = NULL;
 
-	LOG_EXIT_RET(err);
+	mlog_exit(err);
 	return err;
 }  /* asm_build_io() */
 
@@ -1277,7 +1295,9 @@
 	struct buffer_head *bh;
 	kdev_t kdv;
 
-	LOG_ENTRY();
+	mlog_entry("(0x%p, 0x%p, 0x%p, 0x%p)\n", afi, aii, user_iocp,
+		   ioc);
+
 	if (!ioc)
 		return -EINVAL;
 
@@ -1295,7 +1315,9 @@
 		return 0;
 	}
 
-	LOG("ASM: New request at 0x%p alloc()ed for user ioc at 0x%p\n", r, user_iocp);
+	mlog(ML_REQUEST|ML_IOC,
+	     "New request at 0x%p alloc()ed for user ioc at 0x%p\n",
+	     r, user_iocp);
 
 	r->r_file = afi;
 	r->r_ioc = user_iocp;  /* Userspace asm_ioc */
@@ -1315,13 +1337,14 @@
 
 	count = ioc->rcount_asm_ioc * get_hardsect_size(d->d_dev);
 
-	LOG("ASM: first, 0x%08lX.%08lX; masked 0x%08lX\n",
-	    HIGH_UB4(ioc->first_asm_ioc), LOW_UB4(ioc->first_asm_ioc),
-	       (unsigned long)ioc->first_asm_ioc);
 	/* linux only supports unsigned long size sector numbers */
-	LOG("ASM: status: %u, buffer_asm_ioc: 0x%08lX, count: %u\n",
-	    ioc->status_asm_ioc,
-	    (unsigned long)ioc->buffer_asm_ioc, count);
+	mlog(ML_IOC,
+	     "user_iocp 0x%p: first = 0x%08lX.%08lX, masked = 0x%08lX status = %u, buffer_asm_ioc = 0x%08lX, count = %u\n",
+	     user_iocp,
+	     HIGH_UB4(ioc->first_asm_ioc), LOW_UB4(ioc->first_asm_ioc),
+	     (unsigned long)ioc->first_asm_ioc,
+	     ioc->status_asm_ioc,
+	     (unsigned long)ioc->buffer_asm_ioc, (unsigned int)count);
 	/* Note that priority is ignored for now */
 	ret = -EINVAL;
 	if (!ioc->buffer_asm_ioc ||
@@ -1353,7 +1376,9 @@
 	}
 
 
-	LOG("ASM: Passed checks\n");
+	mlog(ML_REQUEST|ML_IOC, 
+	     "Request 0x%p (user_ioc 0x%p) passed validation checks\n",
+	     r, user_iocp);
 
 	switch (ioc->operation_asm_ioc) {
 		default:
@@ -1392,23 +1417,23 @@
 
 	ret = asm_build_io(rw, r,
 			   ioc->first_asm_ioc, ioc->rcount_asm_ioc);
-	LOG("ASM: Return from asm_build_io() is %d\n", ret);
+	mlog(ML_REQUEST|ML_BH, "Return from asm_build_io() is %d\n",
+	     ret);
 	if (ret)
 		goto out_error;
 
 	r->r_elapsed = jiffies;  /* Set start time */
 
-	if (!r->r_cb.vec) {
-		printk("No vec!\n");
-		BUG();
-	}
+	mlog_bug_on_msg(!r->r_cb.vec, "Request 0x%p lost its vec\n", r);
+
 	bh = r->r_bh;
-	/* if (!bh) {
-		printk("No bh 1!\n");
-		BUG();
-	} */
+
+	mlog(ML_REQUEST, "Submitting request 0x%p\n", r);
 #ifdef RED_HAT_LINUX_KERNEL
 # if (LINUX_VERSION_CODE == KERNEL_VERSION(2,4,9)) || (LINUX_VERSION_CODE == KERNEL_VERSION(2,4,20)) || (LINUX_VERSION_CODE == KERNEL_VERSION(2,4,21))
+	mlog(ML_BH,
+	     "Submitting linked bhs starting with 0x%p for request 0x%p\n",
+	     bh, r);
 	submit_bh_linked(rw, bh);
 # else
 #  error Invalid Red Hat Linux kernel
@@ -1416,27 +1441,23 @@
 #else
 # ifdef CONFIG_UNITEDLINUX_KERNEL
 #  if (LINUX_VERSION_CODE == KERNEL_VERSION(2,4,19)) || (LINUX_VERSION_CODE == KERNEL_VERSION(2,4,21))
-	/*if (!bh) {
-		printk("No bh 2!\n");
-		BUG();
-	}*/
-	if (r->r_status & ASM_COMPLETED) {
-		printk("Already completed request 0x%p!\n", r);
-		BUG();
-	}
+
+	mlog_bug_on_msg(r->r_status & ASM_COMPLETED,
+			"Submitting already completed request 0x%p\n",
+			r);
 	while (bh)
 	{
-		if (!test_bit(BH_Atomic, &bh->b_state))
-			BUG();
-		/*if (!test_bit(BH_Lock, &bh->b_state))
-			BUG();*/
+		mlog_bug_on_msg(!test_bit(BH_Atomic, &bh->b_state),
+				"Request 0x%p has non-atomic bh\n", r);
+
+		mlog(ML_BH, "Submitting bh 0x%p for request 0x%p\n",
+		     bh, r);
 		submit_bh_blknr(rw, bh);
 		bh = bh->b_next;
 	}
-	if (!r->r_bh) {
-		printk("No r_bh on request 0x%p!\n", r);
-		BUG();
-	}
+	mlog_bug_on_msg(!r->r_bh, "No r_bh on request 0x%p!\n", r);
+
+	mlog(ML_BH, "Refiling blk_atomic_queue for request 0x%p\n", r);
 	blk_refile_atomic_queue(bh_elv_seq(r->r_bh));
 #  else
 #   error Invalid United Linux kernel
@@ -1449,11 +1470,12 @@
 out:
 	ret = asm_update_user_ioc(r);
 
-	LOG_EXIT_RET(ret);
+	mlog_exit(ret);
 	return ret;
 
 out_error:
-	/* printk("out_error on request 0x%p\n", r); */
+	mlog(ML_REQUEST, "Submit-side error %d for request 0x%p\n",
+	     ret, r);
 	asm_end_kvec_io(r, r->r_cb.vec, ret);
 	goto out;
 }  /* asm_submit_io() */
@@ -1471,13 +1493,14 @@
 	DECLARE_WAITQUEUE(wait, tsk);
 	DECLARE_WAITQUEUE(to_wait, tsk);
 
-	LOG_ENTRY();
+	mlog_entry("(0x%p, 0x%p, 0x%p, 0x%p)\n", afi, aii, iocp, to);
+
 	if (copy_from_user(&p, &(iocp->reserved_asm_ioc),
 			   sizeof(p)))
 		return -EFAULT;
 
-	LOG("ASM: User key is 0x%p\n",
-		(struct asm_request *)(unsigned long)p);
+	mlog(ML_REQUEST|ML_IOC, "User asm_ioc 0x%p has key 0x%p\n",
+	     iocp, (struct asm_request *)(unsigned long)p);
 	r = (struct asm_request *)(unsigned long)p;
 	if (!r)
 		return -EINVAL;
@@ -1490,7 +1513,8 @@
 		return -EINVAL;
 	}
 
-	LOG("ASM: asm_request is valid...we think\n");
+	mlog(ML_REQUEST|ML_IOC,
+	     "asm_request 0x%p is valid...we think\n", r);
 	if (!(r->r_status & (ASM_COMPLETED |
 			     ASM_BUSY | ASM_ERROR))) {
 		spin_unlock_irq(&afi->f_lock);
@@ -1508,11 +1532,17 @@
 			spin_unlock_irq(&afi->f_lock);
 
 			ret = -ETIMEDOUT;
-			if (to->timed_out)
+			if (to->timed_out) {
+				mlog(ML_REQUEST,
+				     "Timeout waiting for asm_request 0x%p\n", r);
 				break;
+			}
+
 			schedule();
 			if (signal_pending(tsk)) {
-				LOG("Signal pending\n");
+				mlog(ML_REQUEST,
+				     "Signal pending waiting for request 0x%p\n",
+				     r);
 				ret = -EINTR;
 				break;
 			}
@@ -1522,33 +1552,21 @@
 		remove_wait_queue(&to->wait, &to_wait);
 		
 		if (ret)
-			return ret;
+			goto out;
 	}
 
 	/* Somebody got here first */
 	ret = 0;
-	if (r->r_status & ASM_FREE)
+	if (r->r_status & ASM_FREE) {
+		mlog(ML_REQUEST | ML_NOTICE,
+		     "Already freed asm_request 0x%p\n", r);
 		goto out;  /* FIXME: Eek, holding lock */
-	if (list_empty(&afi->f_complete))
-		BUG();
-#ifdef DEBUG
-	{
-		/* Check that the request is on afi->f_complete */
-		struct list_head *p;
-		struct asm_request *q;
-		q = NULL;
-		list_for_each(p, &afi->f_complete) {
-			q = list_entry(p, struct asm_request, r_list);
-			if (q == r)
-				break;
-			q = NULL;
-		}
-		if (!q)
-			BUG();
 	}
-#endif  /* DEBUG */
+	mlog_bug_on_msg(list_empty(&afi->f_complete),
+			"Completion list is empty\n");
 
-	dprintk("ASM: Removing request 0x%p\n", r);
+	mlog(ML_REQUEST|ML_IOC,
+	     "Removing request 0x%p for asm_ioc 0x%p\n", r, iocp);
 	list_del_init(&r->r_list);
 	r->r_file = NULL;
 	r->r_status |= ASM_FREE;
@@ -1557,11 +1575,11 @@
 
 	ret = asm_update_user_ioc(r);
 
-	dprintk("ASM: Freeing request 0x%p\n", r);
+	mlog(ML_REQUEST, "Freeing request 0x%p\n", r);
 	asm_request_free(r);
 
 out:
-	LOG_EXIT_RET(ret);
+	mlog_exit(ret);
 	return ret;
 }  /* asm_maybe_wait_io() */
 
@@ -1574,14 +1592,14 @@
 	struct list_head *l;
 	struct asm_request *r;
 
-	LOG_ENTRY();
+	mlog_entry("(0x%p, 0x%p, 0x%p)\n", afi, aii, ioc);
+
 	spin_lock_irq(&afi->f_lock);
 
 	if (list_empty(&afi->f_complete)) {
 		spin_unlock_irq(&afi->f_lock);
 		*ioc = NULL;
-		LOG_EXIT_RET(0);
-		return 0;
+		goto out;
 	}
 
 	l = afi->f_complete.prev;
@@ -1594,16 +1612,12 @@
 
 	*ioc = r->r_ioc;
 	
-#ifdef DEBUG
-	if (!(r->r_status & (ASM_COMPLETED | ASM_ERROR)))
-		BUG();
-#endif /* DEBUG */
-
 	ret = asm_update_user_ioc(r);
 
 	asm_request_free(r);
 
-	LOG_EXIT_RET(ret);
+out:
+	mlog_exit(ret);
 	return ret;
 }  /* asm_complete_io() */
 
@@ -1619,7 +1633,9 @@
 	DECLARE_WAITQUEUE(wait, tsk);
 	DECLARE_WAITQUEUE(to_wait, tsk);
 
-	LOG_ENTRY();
+	mlog_entry("(0x%p, 0x%p, 0x%p, 0x%p, 0x%p)\n", afi, aii, io,
+		   to, status);
+
 	/* Early check - expensive stuff follows */
 	ret = -ETIMEDOUT;
 	if (to->timed_out)
@@ -1665,7 +1681,7 @@
 	remove_wait_queue(&to->wait, &to_wait);
 
 out:
-	LOG_EXIT_RET(ret);
+	mlog_exit(ret);
 	return ret;
 }  /* asm_wait_completion() */
 
@@ -1679,7 +1695,8 @@
 	asm_ioc *iocp;
 	asm_ioc tmp;
 
-	LOG_ENTRY();
+	mlog_entry("(0x%p, 0x%p, 0x%p)\n", afi, aii, io);
+
 	for (i = 0; i < io->io_reqlen; i++) {
 		ret = -EFAULT;
 		if (get_user(iocp,
@@ -1689,13 +1706,13 @@
 		if (copy_from_user(&tmp, iocp, sizeof(tmp)))
 			break;
 
-		LOG("ASM: Submitting user ioc at 0x%p\n", iocp);
+		mlog(ML_IOC, "Submitting user asm_ioc 0x%p\n", iocp);
 		ret = asm_submit_io(afi, aii, iocp, &tmp);
 		if (ret)
 			break;
 	}
 
-	LOG_EXIT_RET(ret);
+	mlog_exit(ret);
 	return ret;
 }  /* asm_submit_io_native() */
 
@@ -1709,18 +1726,20 @@
 	u32 i;
 	asm_ioc *iocp;
 
-	LOG_ENTRY();
+	mlog_entry("(0x%p, 0x%p, 0x%p, 0x%p)\n", afi, aii, io, to);
+
 	for (i = 0; i < io->io_waitlen; i++) {
 		if (get_user(iocp,
 			     ((asm_ioc **)((unsigned long)io->io_waitreqs)) + i))
 			return -EFAULT;
 
+		mlog(ML_IOC, "Waiting on user asm_ioc 0x%p\n", iocp);
 		ret = asm_maybe_wait_io(afi, aii, iocp, to);
 		if (ret)
 			break;
 	}
 
-	LOG_EXIT_RET(ret);
+	mlog_exit(ret);
 	return ret;
 }  /* asm_maybe_wait_io_native() */
 
@@ -1735,12 +1754,16 @@
 	u32 i;
 	asm_ioc *iocp;
 
-	LOG_ENTRY();
+	mlog_entry("(0x%p, 0x%p, 0x%p, 0x%p, 0x%p)\n", afi, aii, io,
+		   to, status);
+
 	for (i = 0; i < io->io_complen; i++) {
 		ret = asm_complete_io(afi, aii, &iocp);
 		if (ret)
 			break;
 		if (iocp) {
+			mlog(ML_IOC, "Completed user asm_ioc 0x%p\n",
+			     iocp);
 			ret = put_user(iocp,
 				       ((asm_ioc **)((unsigned long)io->io_completions)) + i);
 			       if (ret)
@@ -1762,7 +1785,7 @@
 
 	}
 
-	LOG_EXIT_RET(ret ? ret : i);
+	mlog_exit(ret ? ret : i);
 	return (ret ? ret : i);
 }  /* asm_complete_ios_native() */
 
@@ -1772,7 +1795,7 @@
 {
 	asm_ioc32 *ioc_32 = (asm_ioc32 *)ioc;
 
-	LOG_ENTRY();
+	mlog_entry("(0x%p)\n", ioc);
 
 	/*
 	 * Promote the 32bit pointers at the end of the asm_ioc32
@@ -1780,16 +1803,16 @@
 	 *
 	 * Promotion must be done from the tail backwards.
 	 */
-	LOG("Promoting (0x%X, 0x%X) to ",
-	    ioc_32->check_asm_ioc,
-	    ioc_32->buffer_asm_ioc);
+	mlog(ML_IOC, "Promoting (0x%X, 0x%X)\n",
+	     ioc_32->check_asm_ioc,
+	     ioc_32->buffer_asm_ioc);
 	ioc->check_asm_ioc = (u64)ioc_32->check_asm_ioc;
 	ioc->buffer_asm_ioc = (u64)ioc_32->buffer_asm_ioc;
-	LOG("(0x%lX, 0x%lX)\n",
-	    ioc->check_asm_ioc,
-	    ioc->buffer_asm_ioc);
+	mlog(ML_IOC, "Promoted to (0x%"MLFu64", 0x%"MLFu64")\n",
+	     ioc->check_asm_ioc,
+	     ioc->buffer_asm_ioc);
 
-	LOG_EXIT();
+	mlog_exit();
 }  /* asm_promote_64() */
 
 
@@ -1803,7 +1826,8 @@
 	asm_ioc32 *iocp;
 	asm_ioc tmp;
 
-	LOG_ENTRY();
+	mlog_entry("(0x%p, 0x%p, 0x%p)\n", afi, aii, io);
+
 	for (i = 0; i < io->io_reqlen; i++) {
 		ret = -EFAULT;
 		/*
@@ -1826,7 +1850,7 @@
 			break;
 	}
 
-	LOG_EXIT_RET(ret);
+	mlog_exit(ret);
 	return ret;
 }  /* asm_submit_io_thunk() */
 
@@ -1841,25 +1865,28 @@
 	u32 iocp_32;
 	asm_ioc *iocp;
 
-	LOG_ENTRY();
+	mlog_entry("(0x%p, 0x%p, 0x%p, 0x%p)\n", afi, aii, io, to);
+
 	for (i = 0; i < io->io_waitlen; i++) {
+		ret = -EFAULT;
 		/*
 		 * io->io_waitreqs is an asm_ioc32**, but the pointers
 		 * are 32bit pointers.
 		 */
 		if (get_user(iocp_32,
 			     ((u32 *)((unsigned long)io->io_waitreqs)) + i))
-			return -EFAULT;
+			break;
 
 		/* Remember, the this is pointing to 32bit userspace */
 		iocp = (asm_ioc *)(unsigned long)iocp_32;
 
+		mlog(ML_IOC, "Waiting on user asm_ioc 0x%p\n", iocp);
 		ret = asm_maybe_wait_io(afi, aii, iocp, to);
 		if (ret)
 			break;
 	}
 
-	LOG_EXIT_RET(ret);
+	mlog_exit(ret);
 	return ret;
 }  /* asm_maybe_wait_io_thunk() */
 
@@ -1875,18 +1902,22 @@
 	u32 iocp_32;
 	asm_ioc *iocp;
 
-	LOG_ENTRY();
+	mlog_entry("(0x%p, 0x%p, 0x%p, 0x%p, 0x%p)\n", afi, aii, io,
+		   to, status);
+
 	for (i = 0; i < io->io_complen; i++) {
 		ret = asm_complete_io(afi, aii, &iocp);
 		if (ret)
 			break;
 		if (iocp) {
+			mlog(ML_IOC, "Completed user asm_ioc 0x%p\n",
+			     iocp);
 			iocp_32 = (u32)(unsigned long)iocp;
 
 			ret = put_user(iocp_32,
 				       ((u32 *)((unsigned long)io->io_completions)) + i);
 			       if (ret)
-				   break;
+				       break;
 			continue;
 		}
 
@@ -1903,7 +1934,7 @@
 		i--; /* Reset this completion */
 	}
 
-	LOG_EXIT_RET(ret ? ret : i);
+	mlog_exit(ret ? ret : i);
 	return (ret ? ret : i);
 }  /* asm_complete_ios_thunk() */
 
@@ -1918,14 +1949,15 @@
 	u32 status = 0;
 	struct timeout to;
 
-	LOG_ENTRY();
+	mlog_entry("(0x%p, 0x%p, 0x%p, %d)\n", afi, aii, io, bpl);
 
 	init_timeout(&to);
 
 	if (io->io_timeout) {
 		struct timespec ts;
 
-		LOG("ASM: asm_do_io() was passed a timeout\n");
+		mlog(ML_ABI, "Passed timeout 0x%"MLFu64"\n",
+		     io->io_timeout);
 		ret = -EFAULT;
 		if (copy_from_user(&ts,
 				   (struct timespec *)(unsigned long)io->io_timeout,
@@ -1941,8 +1973,9 @@
 
 	ret = 0;
 	if (io->io_requests) {
-		LOG("ASM: oracleasm_io has requests; reqlen %d\n",
-		    io->io_reqlen);
+		mlog(ML_ABI,
+		     "oracleasm_io has requests; reqlen %d\n",
+		     io->io_reqlen);
 		ret = -EINVAL;
 		if (bpl == ASM_BPL_32)
 			ret = asm_submit_io_32(afi, aii, io);
@@ -1956,8 +1989,9 @@
 	}
 
 	if (io->io_waitreqs) {
-		LOG("ASM: oracleasm_io has waits; waitlen %d\n",
-		    io->io_waitlen);
+		mlog(ML_ABI,
+		     "oracleasm_io has waits; waitlen %d\n",
+		     io->io_waitlen);
 		ret = -EINVAL;
 		if (bpl == ASM_BPL_32)
 			ret = asm_maybe_wait_io_32(afi, aii, io, &to);
@@ -1973,8 +2007,9 @@
 	}
 
 	if (io->io_completions) {
-		LOG("ASM: oracleasm_io has completes; complen %d\n",
-		    io->io_complen);
+		mlog(ML_ABI,
+		     "oracleasm_io has completes; complen %d\n",
+		     io->io_complen);
 		ret = -EINVAL;
 		if (bpl == ASM_BPL_32)
 			ret = asm_complete_ios_32(afi, aii, io,
@@ -1999,7 +2034,7 @@
 out:
 	if (put_user(status, (u32 *)(unsigned long)io->io_statusp))
 		ret = -EFAULT;
-	LOG_EXIT_RET(ret);
+	mlog_exit(ret);
 	return ret;
 }  /* asm_do_io() */
 
@@ -2009,13 +2044,18 @@
 	struct asmfs_inode_info * aii;
 	struct asmfs_file_info * afi;
 
-	if (ASMFS_FILE(file))
-		BUG();
+	mlog_entry("(0x%p, 0x%p)\n", inode, file);
 
+	mlog_bug_on_msg(ASMFS_FILE(file),
+			"Trying to repen filp 0x%p\n", file);
+
+	mlog(ML_ABI, "Opening filp 0x%p\n", file);
 	afi = (struct asmfs_file_info *)kmalloc(sizeof(*afi),
 						GFP_KERNEL);
-	if (!afi)
+	if (!afi) {
+		mlog_exit(-ENOMEM);
 		return -ENOMEM;
+	}
 	afi->f_file = file;
 	spin_lock_init(&afi->f_lock);
 	INIT_LIST_HEAD(&afi->f_ctx);
@@ -2031,6 +2071,9 @@
 
 	ASMFS_FILE(file) = afi;
 
+	mlog(ML_ABI, "Filp 0x%p has afi 0x%p\n", file, afi);
+
+	mlog_exit(0);
 	return 0;
 }  /* asmfs_file_open() */
 
@@ -2046,13 +2089,17 @@
 	struct task_struct *tsk = current;
 	DECLARE_WAITQUEUE(wait, tsk);
 
+	mlog_entry("(0x%p, 0x%p)\n", inode, file);
+
 	aii = ASMFS_INODE(inode);
 	afi = ASMFS_FILE(file);
 	ASMFS_FILE(file) = NULL;
 
-	if (!afi)
-		BUG();
+	mlog_bug_on_msg(!afi, "No asmfs_file_info on filp 0x%p\n",
+			file);
 
+	mlog(ML_ABI, "Release for filp 0x%p (afi = 0x%p)\n", file, afi);
+
 	/*
 	 * Shouldn't need the lock, no one else has a reference
 	 * asm_disk_close will need to take it when completing I/O
@@ -2079,8 +2126,9 @@
 		if (list_empty(&afi->f_ios))
 		    break;
 		spin_unlock_irq(&afi->f_lock);
-		dprintk("There are still I/Os hanging off of afi 0x%p\n",
-		       afi);
+		mlog(ML_ABI|ML_REQUEST,
+		     "There are still I/Os hanging off of afi 0x%p\n",
+		     afi);
 		schedule();
 	} while (1);
 	set_task_state(tsk, TASK_RUNNING);
@@ -2098,9 +2146,10 @@
 	}
 	spin_unlock_irq(&afi->f_lock);
 
-	dprintk("ASM: Done with afi 0x%p\n", afi);
+	mlog(ML_ABI, "Done with afi 0x%p from filp 0x%p\n", afi, file);
 	kfree(afi);
 
+	mlog_exit(0);
 	return 0;
 }  /* asmfs_file_release() */
 
@@ -2115,25 +2164,26 @@
 	struct asmfs_inode_info *aii = ASMFS_INODE(inode);
 	struct oracleasm_io io;
 	struct oracleasm_disk_query dq;
-	int ret;
+	int ret = 0;
 
-	LOG_ENTRY();
+	mlog_entry("(0x%p, 0x%p, %u, %lu)\n", inode, file, cmd, arg);
 
 	switch (cmd) {
 		default:
-			LOG("ASM: Invalid ioctl 0x%u\n", cmd);
-			return -ENOTTY;
+			mlog(ML_ABI, "Invalid ioctl 0x%u\n", cmd);
+			ret = -ENOTTY;
 			break;
 
 		case ASMIOC_QUERYDISK:
-			LOG("ASM: Operation is ASMIOC_QUERYDISK\n");
+			mlog(ML_ABI, "Operation is ASMIOC_QUERYDISK\n");
 			if (copy_from_user(&dq,
 					   (struct oracleasm_disk_query *)arg,
-					   sizeof(dq)))
-				return -EFAULT;
+					   sizeof(dq))) {
+				ret = -EFAULT;
+				break;
+			}
+
 			kdv = to_kdev_t(dq.dq_rdev);
-			LOG("ASM: Checking disk %d,%d\n", MAJOR(kdv),
-			    MINOR(kdv));
 #if 0
 			/* Right now we trust only SCSI ->request_fn */
 			if (!SCSI_DISK_MAJOR(MAJOR(kdv)))
@@ -2147,20 +2197,19 @@
 			dq.dq_maxio = ASM_MAX_IOSIZE;
 			if (copy_to_user((struct oracleasm_disk_query *)arg,
 					 &dq, sizeof(dq)))
-				return -EFAULT;
-			LOG("ASM: Valid disk %d,%d\n", MAJOR(kdv),
-			    MINOR(kdv));
+				ret = -EFAULT;
 			break;
 
 		case ASMIOC_OPENDISK:
-			LOG("ASM: Operation is ASMIOC_OPENDISK\n");
+			mlog(ML_ABI, "Operation is ASMIOC_OPENDISK\n");
 			if (copy_from_user(&dq,
 					   (struct oracleasm_disk_query *)arg,
-					   sizeof(dq)))
-				return -EFAULT;
+					   sizeof(dq))) {
+				ret = -EFAULT;
+				break;
+			}
+
 			kdv = to_kdev_t(dq.dq_rdev);
-			LOG("ASM: Opening disk %d,%d\n", MAJOR(kdv),
-			    MINOR(kdv));
 
 			ret = asm_validate_disk(kdv);
 			if (ret)
@@ -2172,86 +2221,107 @@
 #warning Doesnt free disk on EFAULT
 			if (copy_to_user((struct oracleasm_disk_query *)arg,
 					 &dq, sizeof(dq)))
-			    return -EFAULT;
-			LOG("ASM: Opened handle 0x%.8lX\n",
-			    (unsigned long)dq.dq_rdev);
+			    ret = -EFAULT;
 			break;
 
 		case ASMIOC_CLOSEDISK:
-			LOG("ASM: Operation is ASMIOC_CLOSEDISK\n");
+			mlog(ML_ABI, "Operation is ASMIOC_CLOSEDISK\n");
 			if (copy_from_user(&dq,
 					   (struct oracleasm_disk_query *)arg,
-					   sizeof(dq)))
-				return -EFAULT;
-			LOG("ASM: Closing handle 0x%.8lX\n", (unsigned long)dq.dq_rdev);
+					   sizeof(dq))) {
+				ret = -EFAULT;
+				break;
+			}
+
 			kdv = to_kdev_t(dq.dq_rdev);
-			return asm_disk_close(afi, aii, kdv);
+			ret = asm_disk_close(afi, aii, kdv);
 			break;
 
 		case ASMIOC_IODISK32:
-			LOG("ASM: Operation is ASMIOC_IODISK32\n");
+			mlog(ML_ABI, "Operation is ASMIOC_IODISK32\n");
 			if (copy_from_user(&io,
 					   (struct oracleasm_io *)arg,
-					   sizeof(io)))
-				return -EFAULT;
-			return asm_do_io(afi, aii, &io, ASM_BPL_32);
+					   sizeof(io))) {
+				ret = -EFAULT;
+				break;
+			}
+
+			ret = asm_do_io(afi, aii, &io, ASM_BPL_32);
 			break;
 
 #if BITS_PER_LONG == 64
 		case ASMIOC_IODISK64:
-			LOG("ASM: Operation is ASM_IODISK64\n");
+			mlog(ML_ABI, "Operation is ASM_IODISK64\n");
 			if (copy_from_user(&io,
 					   (struct oracleasm_io *)arg,
-					   sizeof(io)))
-				return -EFAULT;
-			return asm_do_io(afi, aii, &io, ASM_BPL_64);
+					   sizeof(io))) {
+				ret = -EFAULT;
+				break;
+			}
+
+			ret = asm_do_io(afi, aii, &io, ASM_BPL_64);
 			break;
 #endif  /* BITS_PER_LONG == 64 */
 
 		case ASMIOC_DUMP:
-			LOG("ASM: Operation is ASMIOC_DUMP\n");
+			mlog(ML_ABI, "Operation is ASMIOC_DUMP\n");
 			/* Dump data */
 			/* Currently unimplemented */
 			break;
 	}
 
-	LOG_EXIT_RET(0);
-	return 0;
+	mlog_exit(ret);
+	return ret;
 }
 
-static int asmfs_dir_ioctl(struct inode * inode, struct file * file, unsigned int cmd, unsigned long arg)
+static int asmfs_dir_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
 {
 	struct oracleasm_get_iid new_iid;
 	struct asmfs_sb_info *asb = ASMFS_SB(inode->i_sb);
+	int ret = 0;
 
+	mlog_entry("(0x%p, 0x%p, %u, %lu)\n", inode, file, cmd, arg);
+
 	switch (cmd) {
 		default:
-			return -ENOTTY;
+			ret = -ENOTTY;
 			break;
 
 		case ASMIOC_GETIID:
 			if (copy_from_user(&new_iid,
 					   (struct oracleasm_get_iid *)arg,
-					   sizeof(new_iid)))
-			    return -EFAULT;
-			if (new_iid.gi_version != (u64)ASM_ABI_VERSION)
-			    return -EINVAL;
+					   sizeof(new_iid))) {
+				ret = -EFAULT;
+				break;
+			}
+
+			if (new_iid.gi_version != (u64)ASM_ABI_VERSION) {
+				ret = -EINVAL;
+				break;
+			}
+
 			lock_asb(asb);
 			new_iid.gi_iid = (u64)asb->next_iid;
 			asb->next_iid++;
 			unlock_asb(asb);
 			if (copy_to_user((struct oracleasm_get_iid *)arg,
 					 &new_iid, sizeof(new_iid)))
-			    return -EFAULT;
+			    ret = -EFAULT;
 			break;
 
 		case ASMIOC_CHECKIID:
 			if (copy_from_user(&new_iid,
 					   (struct oracleasm_get_iid *)arg,
-					   sizeof(new_iid)))
-			    return -EFAULT;
-			if (new_iid.gi_version != (u64)ASM_ABI_VERSION)
-			    return -EINVAL;
+					   sizeof(new_iid))) {
+			    ret = -EFAULT;
+			    break;
+			}
+
+			if (new_iid.gi_version != (u64)ASM_ABI_VERSION) {
+			    ret = -EINVAL;
+			    break;
+			}
+
 			lock_asb(asb);
 			if (new_iid.gi_iid >= (u64)asb->next_iid)
 			    new_iid.gi_iid = (u64)0;
@@ -2260,12 +2330,13 @@
 			{
 			    if (copy_to_user((struct oracleasm_get_iid *)arg,
 					     &new_iid, sizeof(new_iid)))
-				return -EFAULT;
+				ret = -EFAULT;
 			}
 			break;
 	}
 
-	return 0;
+	mlog_exit(ret);
+	return ret;
 }
 
 static int asmfs_sync_file(struct file * file, struct dentry *dentry, int datasync)
@@ -2525,23 +2596,39 @@
 {
 	int ret;
 
-	LOG("sizeof asm_ioc32: %u\n", sizeof(asm_ioc32));
 	asm_request_cachep =
 		kmem_cache_create("asm_request",
 				  sizeof(struct asm_request),
 				  0, SLAB_HWCACHE_ALIGN, NULL, NULL);
-	if (!asm_request_cachep)
-		panic("Unable to create asm_request cache\n");
+	if (!asm_request_cachep) {
+		printk("Unable to create asm_request cache\n");
+		return -ENOMEM;
+	}
 
 #ifdef CONFIG_COMPAT
 	ret = init_asmfs_ioctl32();
-	if (ret)
+	if (ret) {
+		printk("Unable to initialize compat ioctls\n");
 		kmem_cache_destroy(asm_request_cachep);
+		return ret;
+	}
 #endif  /* CONFIG_COMPAT */
 
+	ret = init_oracleasm_proc();
+	if (ret) {
+		printk("Unable to initialize proc interface\n");
+		kmem_cache_destroy(asm_request_cachep);
+#ifdef CONFIG_COMPAT
+		exit_asmfs_ioctl32();
+#endif  /* CONFIG_COMPAT */
+		return ret;
+	}
+
 	init_asmfs_dir_operations();
 	ret = register_filesystem(&asmfs_fs_type);
 	if (ret) {
+		printk("Unable to register oracleasm filesystem\n");
+		exit_oracleasm_proc();
 		kmem_cache_destroy(asm_request_cachep);
 #ifdef CONFIG_COMPAT
 		exit_asmfs_ioctl32();
@@ -2554,6 +2641,7 @@
 static void __exit exit_asmfs_fs(void)
 {
 	unregister_filesystem(&asmfs_fs_type);
+	exit_oracleasm_proc();
 	kmem_cache_destroy(asm_request_cachep);
 #ifdef CONFIG_COMPAT
 	exit_asmfs_ioctl32();

Added: branches/oracleasm-1.0/kernel/proc.c
===================================================================
--- branches/oracleasm-1.0/kernel/proc.c	2006-07-18 21:20:38 UTC (rev 353)
+++ branches/oracleasm-1.0/kernel/proc.c	2006-07-18 21:35:54 UTC (rev 354)
@@ -0,0 +1,55 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * Copyright (C) 2006 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/proc_fs.h>
+
+#include "proc.h"
+#include "masklog.h"
+
+/* Yuk, but whatever */
+#include "masklog.c"
+
+static struct proc_dir_entry *asm_proc;
+#define ASM_PROC_PATH "fs/oracleasm"
+
+int init_oracleasm_proc(void)
+{
+	int rc;
+
+	asm_proc = proc_mkdir(ASM_PROC_PATH, NULL);
+	if (asm_proc == NULL) {
+		rc = -ENOMEM; /* shrug */
+		goto out;
+	}
+
+	rc = mlog_init_proc(asm_proc);
+	if (rc)
+		remove_proc_entry(ASM_PROC_PATH, NULL);
+
+out:
+	return rc;
+}
+
+void exit_oracleasm_proc(void)
+{
+	mlog_remove_proc(asm_proc);
+	remove_proc_entry(ASM_PROC_PATH, NULL);
+}

Added: branches/oracleasm-1.0/kernel/proc.h
===================================================================
--- branches/oracleasm-1.0/kernel/proc.h	2006-07-18 21:20:38 UTC (rev 353)
+++ branches/oracleasm-1.0/kernel/proc.h	2006-07-18 21:35:54 UTC (rev 354)
@@ -0,0 +1,27 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * Copyright (C) 2006 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+#ifndef __ASM_PROC_H
+#define __ASM_PROC_H
+
+int init_oracleasm_proc(void);
+void exit_oracleasm_proc(void);
+
+#endif  /* _ASM_PROC_H */




More information about the Oracleasm-commits mailing list