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

This commit is contained in:
Luigi Rizzo 2015-07-19 18:07:25 +00:00
parent 10b8ef3d6a
commit 847adfb7b3
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=285699
3 changed files with 18 additions and 2 deletions

View File

@ -542,6 +542,7 @@ SYSCTL_INT(_dev_netmap, OID_AUTO, generic_ringsize, CTLFLAG_RW, &netmap_generic_
SYSCTL_INT(_dev_netmap, OID_AUTO, generic_rings, CTLFLAG_RW, &netmap_generic_rings, 0 , ""); SYSCTL_INT(_dev_netmap, OID_AUTO, generic_rings, CTLFLAG_RW, &netmap_generic_rings, 0 , "");
NMG_LOCK_T netmap_global_lock; 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 * mark the ring as stopped, and run through the locks
@ -975,11 +976,11 @@ netmap_dtor_locked(struct netmap_priv_d *priv)
{ {
struct netmap_adapter *na = priv->np_na; 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) { if (--priv->np_refs > 0) {
return 0; return 0;
} }
netmap_use_count--;
if (!na) { if (!na) {
return 1; //XXX is it correct? return 1; //XXX is it correct?
} }

View File

@ -642,6 +642,10 @@ netmap_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
error = devfs_set_cdevpriv(priv, netmap_dtor); error = devfs_set_cdevpriv(priv, netmap_dtor);
if (error) { if (error) {
free(priv, M_DEVBUF); free(priv, M_DEVBUF);
} else {
NMG_LOCK();
netmap_use_count++;
NMG_UNLOCK();
} }
return error; return error;
} }
@ -827,6 +831,16 @@ netmap_loader(__unused struct module *module, int event, __unused void *arg)
break; break;
case MOD_UNLOAD: 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(); netmap_fini();
break; break;

View File

@ -1247,6 +1247,7 @@ extern int netmap_txsync_retry;
extern int netmap_generic_mit; extern int netmap_generic_mit;
extern int netmap_generic_ringsize; extern int netmap_generic_ringsize;
extern int netmap_generic_rings; extern int netmap_generic_rings;
extern int netmap_use_count;
/* /*
* NA returns a pointer to the struct netmap adapter from the ifp, * NA returns a pointer to the struct netmap adapter from the ifp,