Subject: Re: mfi(4) and bio_register()
To: Juan RP <juan@xtrarom.org>
From: Martin Husemann <martin@duskware.de>
List: tech-kern
Date: 11/16/2007 11:33:33
--bg08WKrSYDhXBjb5
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Looking at bio.c I think the most simple solution is along the lines of the
attached patch. It kinda assumes autoconfig running only on one CPU, but
when we are ready to change that, we'll hopefully have generic atomic
operations and can replace the simple bool flag.

Martin
(This is not even compile tested)

--bg08WKrSYDhXBjb5
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=patch

Index: bio.c
===================================================================
RCS file: /cvsroot/src/sys/dev/bio.c,v
retrieving revision 1.2
diff -u -p -r1.2 bio.c
--- bio.c	2 Nov 2007 08:38:37 -0000	1.2
+++ bio.c	16 Nov 2007 10:19:04 -0000
@@ -52,7 +52,9 @@ struct bio_mapping {
 
 LIST_HEAD(, bio_mapping) bios = LIST_HEAD_INITIALIZER(bios);
 static kmutex_t bio_lock;
+static bool bio_lock_initialized = false;
 
+static void bio_initialize(void);
 void	bioattach(int);
 int	bioclose(dev_t, int, int, struct lwp *);
 int	bioioctl(dev_t, u_long, void *, int, struct lwp *);
@@ -67,11 +69,20 @@ const struct cdevsw bio_cdevsw = {
         nostop, notty, nopoll, nommap, nokqfilter, 0
 };
 
+static void
+bio_initialize(void)
+{
+	if (bio_lock_initialized)
+		return;
+	bio_lock_initialized = true;
+	mutex_init(&bio_lock, MUTEX_DRIVER, IPL_BIO);
+}
 
 void
 bioattach(int nunits)
 {
-	mutex_init(&bio_lock, MUTEX_DRIVER, IPL_BIO);
+	if (!bio_lock_initialized)
+		bio_initialize();
 }
 
 int
@@ -169,6 +180,9 @@ bio_register(struct device *dev, int (*i
 {
 	struct bio_mapping *bm;
 
+	if (!bio_lock_initialized)
+		bio_initialize();
+
 	bm = (struct bio_mapping *)malloc(sizeof(*bm), M_DEVBUF,
 	    M_NOWAIT|M_ZERO);
 	if (bm == NULL)

--bg08WKrSYDhXBjb5--