aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/netmap/netmap_freebsd.c
diff options
context:
space:
mode:
authorLuigi Rizzo <luigi@FreeBSD.org>2015-07-10 16:05:24 +0000
committerLuigi Rizzo <luigi@FreeBSD.org>2015-07-10 16:05:24 +0000
commit8fd44c939522ba184d0d611b2ada7e027b1c63c9 (patch)
tree7149342f547539760333f8fc1b92e4643e8a9930 /sys/dev/netmap/netmap_freebsd.c
parentea566832d78e0c81f7be7587ada8055876394558 (diff)
Notes
Diffstat (limited to 'sys/dev/netmap/netmap_freebsd.c')
-rw-r--r--sys/dev/netmap/netmap_freebsd.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/sys/dev/netmap/netmap_freebsd.c b/sys/dev/netmap/netmap_freebsd.c
index ebac6b0efe216..5646c08451e1d 100644
--- a/sys/dev/netmap/netmap_freebsd.c
+++ b/sys/dev/netmap/netmap_freebsd.c
@@ -576,7 +576,7 @@ netmap_mmap_single(struct cdev *cdev, vm_ooffset_t *foff,
goto err_unlock;
}
vmh->priv = priv;
- priv->np_refcount++;
+ priv->np_refs++;
NMG_UNLOCK();
obj = cdev_pager_allocate(vmh, OBJT_DEVICE,
@@ -593,7 +593,7 @@ netmap_mmap_single(struct cdev *cdev, vm_ooffset_t *foff,
err_deref:
NMG_LOCK();
- priv->np_refcount--;
+ priv->np_refs--;
err_unlock:
NMG_UNLOCK();
// err:
@@ -602,14 +602,14 @@ err_unlock:
}
/*
- * netmap_close() is called on every close(), but we do not need to do
- * anything at that moment, since the process may have other open file
- * descriptors for /dev/netmap. Instead, we pass netmap_dtor() to
+ * On FreeBSD the close routine is only called on the last close on
+ * the device (/dev/netmap) so we cannot do anything useful.
+ * To track close() on individual file descriptors we pass netmap_dtor() to
* devfs_set_cdevpriv() on open(). The FreeBSD kernel will call the destructor
* when the last fd pointing to the device is closed.
*
- * Unfortunately, FreeBSD does not automatically track active mmap()s on an fd,
- * so we have to track them by ourselvesi (see above). The result is that
+ * Note that FreeBSD does not even munmap() on close() so we also have
+ * to track mmap() ourselves, and postpone the call to
* netmap_dtor() is called when the process has no open fds and no active
* memory maps on /dev/netmap, as in linux.
*/
@@ -634,19 +634,15 @@ netmap_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
(void)devtype;
(void)td;
- // XXX wait or nowait ?
priv = malloc(sizeof(struct netmap_priv_d), M_DEVBUF,
M_NOWAIT | M_ZERO);
if (priv == NULL)
return ENOMEM;
-
error = devfs_set_cdevpriv(priv, netmap_dtor);
- if (error)
- return error;
-
- priv->np_refcount = 1;
-
- return 0;
+ if (error) {
+ free(priv, M_DEVBUF);
+ }
+ return error;
}
/******************** kqueue support ****************/