Module Name: src Committed By: pgoyette Date: Tue Jul 19 02:47:45 UTC 2016
Modified Files: src/sys/net: bpf.c src/sys/rump/dev/lib/libbpf: bpf_component.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.202 -r1.203 src/sys/net/bpf.c cvs rdiff -u -r1.2 -r1.3 src/sys/rump/dev/lib/libbpf/bpf_component.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/net/bpf.c diff -u src/sys/net/bpf.c:1.202 src/sys/net/bpf.c:1.203 --- src/sys/net/bpf.c:1.202 Sun Jul 17 02:49:52 2016 +++ src/sys/net/bpf.c Tue Jul 19 02:47:45 2016 @@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.20 #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 @@ bpf_detachd(struct bpf_d *d) 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 @@ doinit(void) 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 @@ bpf_modcmd(modcmd_t cmd, void *arg) #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); Index: src/sys/rump/dev/lib/libbpf/bpf_component.c diff -u src/sys/rump/dev/lib/libbpf/bpf_component.c:1.2 src/sys/rump/dev/lib/libbpf/bpf_component.c:1.3 --- src/sys/rump/dev/lib/libbpf/bpf_component.c:1.2 Tue Jan 26 23:12:14 2016 +++ src/sys/rump/dev/lib/libbpf/bpf_component.c Tue Jul 19 02:47:45 2016 @@ -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 @@ RUMP_COMPONENT(RUMP_COMPONENT_NET) 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); }