From owner-svn-src-head@freebsd.org Sun Jul 19 18:07:26 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EAF679A66B1; Sun, 19 Jul 2015 18:07:26 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C34401CF3; Sun, 19 Jul 2015 18:07:26 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t6JI7QnW096007; Sun, 19 Jul 2015 18:07:26 GMT (envelope-from luigi@FreeBSD.org) Received: (from luigi@localhost) by repo.freebsd.org (8.14.9/8.14.9/Submit) id t6JI7PHO096002; Sun, 19 Jul 2015 18:07:25 GMT (envelope-from luigi@FreeBSD.org) Message-Id: <201507191807.t6JI7PHO096002@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: luigi set sender to luigi@FreeBSD.org using -f From: Luigi Rizzo Date: Sun, 19 Jul 2015 18:07:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r285699 - head/sys/dev/netmap X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 19 Jul 2015 18:07:27 -0000 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,