svn commit: r285699 - head/sys/dev/netmap

Luigi Rizzo luigi at FreeBSD.org
Sun Jul 19 18:07:27 UTC 2015


Author: luigi
Date: Sun Jul 19 18:07:25 2015
New Revision: 285699
URL: https://svnweb.freebsd.org/changeset/base/285699

Log:
  add a use count so the netmap module cannot be unloaded while in use.

Modified:
  head/sys/dev/netmap/netmap.c
  head/sys/dev/netmap/netmap_freebsd.c
  head/sys/dev/netmap/netmap_kern.h

Modified: head/sys/dev/netmap/netmap.c
==============================================================================
--- head/sys/dev/netmap/netmap.c	Sun Jul 19 18:06:30 2015	(r285698)
+++ head/sys/dev/netmap/netmap.c	Sun Jul 19 18:07:25 2015	(r285699)
@@ -542,6 +542,7 @@ SYSCTL_INT(_dev_netmap, OID_AUTO, generi
 SYSCTL_INT(_dev_netmap, OID_AUTO, generic_rings, CTLFLAG_RW, &netmap_generic_rings, 0 , "");
 
 NMG_LOCK_T	netmap_global_lock;
+int netmap_use_count = 0; /* number of active netmap instances */
 
 /*
  * mark the ring as stopped, and run through the locks
@@ -975,11 +976,11 @@ netmap_dtor_locked(struct netmap_priv_d 
 {
 	struct netmap_adapter *na = priv->np_na;
 
-	/* number of active mmaps on this fd (FreeBSD only) */
+	/* number of active references to this fd */
 	if (--priv->np_refs > 0) {
 		return 0;
 	}
-
+	netmap_use_count--;
 	if (!na) {
 		return 1; //XXX is it correct?
 	}

Modified: head/sys/dev/netmap/netmap_freebsd.c
==============================================================================
--- head/sys/dev/netmap/netmap_freebsd.c	Sun Jul 19 18:06:30 2015	(r285698)
+++ head/sys/dev/netmap/netmap_freebsd.c	Sun Jul 19 18:07:25 2015	(r285699)
@@ -642,6 +642,10 @@ netmap_open(struct cdev *dev, int oflags
 	error = devfs_set_cdevpriv(priv, netmap_dtor);
 	if (error) {
 		free(priv, M_DEVBUF);
+	} else {
+		NMG_LOCK();
+		netmap_use_count++;
+		NMG_UNLOCK();
 	}
 	return error;
 }
@@ -827,6 +831,16 @@ netmap_loader(__unused struct module *mo
 		break;
 
 	case MOD_UNLOAD:
+		/*
+		 * if some one is still using netmap,
+		 * then the module can not be unloaded.
+		 */
+		if (netmap_use_count) {
+			D("netmap module can not be unloaded - netmap_use_count: %d",
+					netmap_use_count);
+			error = EBUSY;
+			break;
+		}
 		netmap_fini();
 		break;
 

Modified: head/sys/dev/netmap/netmap_kern.h
==============================================================================
--- head/sys/dev/netmap/netmap_kern.h	Sun Jul 19 18:06:30 2015	(r285698)
+++ head/sys/dev/netmap/netmap_kern.h	Sun Jul 19 18:07:25 2015	(r285699)
@@ -1247,6 +1247,7 @@ extern int netmap_txsync_retry;
 extern int netmap_generic_mit;
 extern int netmap_generic_ringsize;
 extern int netmap_generic_rings;
+extern int netmap_use_count;
 
 /*
  * NA returns a pointer to the struct netmap adapter from the ifp,


More information about the svn-src-head mailing list