Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Fix regression introduced in tests/net/bpf and tests/net...



details:   https://anonhg.NetBSD.org/src/rev/a60e5b49ae45
branches:  trunk
changeset: 346559:a60e5b49ae45
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Tue Jul 19 02:47:45 2016 +0000

description:
Fix regression introduced in tests/net/bpf and tests/net/bpfilter

The rump code needs to call devsw_attach() in order to assign a dev_major
for bpf;  it then uses this to create rumps /dev/bpf node.  Unfortunately,
this leaves the devsw attached, so when the bpf module tries to initialize
itself, it gets an EEXIST error and fails.

So, once rump has figured what the dev_major should be, call devsw_detach()
to remove the devsw.  Then, when the module initialization code calls
devsw_attach() it will succeed.

diffstat:

 sys/net/bpf.c                           |  21 +++++++++------------
 sys/rump/dev/lib/libbpf/bpf_component.c |   6 ++++--
 2 files changed, 13 insertions(+), 14 deletions(-)

diffs (105 lines):

diff -r 8ede0bb9a7a9 -r a60e5b49ae45 sys/net/bpf.c
--- a/sys/net/bpf.c     Tue Jul 19 02:04:06 2016 +0000
+++ b/sys/net/bpf.c     Tue Jul 19 02:47:45 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bpf.c,v 1.202 2016/07/17 02:49:52 pgoyette Exp $       */
+/*     $NetBSD: bpf.c,v 1.203 2016/07/19 02:47:45 pgoyette Exp $       */
 
 /*
  * Copyright (c) 1990, 1991, 1993
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.202 2016/07/17 02:49:52 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.203 2016/07/19 02:47:45 pgoyette Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_bpf.h"
@@ -59,7 +59,6 @@
 #include <sys/queue.h>
 #include <sys/stat.h>
 #include <sys/module.h>
-#include <sys/once.h>
 #include <sys/atomic.h>
 
 #include <sys/file.h>
@@ -402,8 +401,8 @@
        d->bd_bif = NULL;
 }
 
-static int
-doinit(void)
+static void
+bpf_init(void)
 {
 
        mutex_init(&bpf_mtx, MUTEX_DEFAULT, IPL_NONE);
@@ -414,19 +413,18 @@
        bpf_gstats.bs_drop = 0;
        bpf_gstats.bs_capt = 0;
 
-       return 0;
+       return;
 }
 
 /*
- * bpfilterattach() is called at boot time.
+ * bpfilterattach() is called at boot time.  We don't need to do anything
+ * here, since any initialization will happen as part of module init code.
  */
 /* ARGSUSED */
 void
 bpfilterattach(int n)
 {
-       static ONCE_DECL(control);
 
-       RUN_ONCE(&control, doinit);
 }
 
 /*
@@ -2117,17 +2115,16 @@
 #endif
        int error = 0;
 
-
        switch (cmd) {
        case MODULE_CMD_INIT:
-               bpfilterattach(0);
+               bpf_init();
 #ifdef _MODULE
                bmajor = cmajor = NODEVMAJOR;
                error = devsw_attach("bpf", NULL, &bmajor,
                    &bpf_cdevsw, &cmajor);
-#endif
                if (error)
                        break;
+#endif
 
                bpf_ops_handover_enter(&bpf_ops_kernel);
                atomic_swap_ptr(&bpf_ops, &bpf_ops_kernel);
diff -r 8ede0bb9a7a9 -r a60e5b49ae45 sys/rump/dev/lib/libbpf/bpf_component.c
--- a/sys/rump/dev/lib/libbpf/bpf_component.c   Tue Jul 19 02:04:06 2016 +0000
+++ b/sys/rump/dev/lib/libbpf/bpf_component.c   Tue Jul 19 02:47:45 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bpf_component.c,v 1.2 2016/01/26 23:12:14 pooka Exp $  */
+/*     $NetBSD: bpf_component.c,v 1.3 2016/07/19 02:47:45 pgoyette Exp $       */
 
 /*
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bpf_component.c,v 1.2 2016/01/26 23:12:14 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf_component.c,v 1.3 2016/07/19 02:47:45 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -50,4 +50,6 @@
                panic("bpf devsw attach failed: %d", error);
        if ((error = rump_vfs_makeonedevnode(S_IFCHR, "/dev/bpf", cmaj, 0)) !=0)
                panic("cannot create bpf device nodes: %d", error);
+       if ((error = devsw_detach(NULL, &bpf_cdevsw)) != 0)
+               panic("cannot detach bpf devsw: %d", error);
 }



Home | Main Index | Thread Index | Old Index