Page MenuHomeFreeBSD

D33402.id99905.diff
No OneTemporary

D33402.id99905.diff

Index: sys/geom/geom_dev.c
===================================================================
--- sys/geom/geom_dev.c
+++ sys/geom/geom_dev.c
@@ -54,6 +54,7 @@
#include <sys/disk.h>
#include <sys/fcntl.h>
#include <sys/limits.h>
+#include <sys/selinfo.h>
#include <sys/sysctl.h>
#include <geom/geom.h>
#include <geom/geom_int.h>
@@ -65,6 +66,7 @@
struct cdev *sc_alias;
int sc_open;
u_int sc_active;
+ struct selinfo sc_selinfo;
#define SC_A_DESTROY (1 << 31)
#define SC_A_OPEN (1 << 30)
#define SC_A_ACTIVE (SC_A_OPEN - 1)
@@ -74,6 +76,16 @@
static d_close_t g_dev_close;
static d_strategy_t g_dev_strategy;
static d_ioctl_t g_dev_ioctl;
+static d_kqfilter_t g_dev_kqfilter;
+
+static void gdev_filter_detach(struct knote *kn);
+static int gdev_filter_vnode(struct knote *kn, long hint);
+
+static struct filterops gdev_filterops_vnode = {
+ .f_isfd = 1,
+ .f_detach = gdev_filter_detach,
+ .f_event = gdev_filter_vnode,
+};
static struct cdevsw g_dev_cdevsw = {
.d_version = D_VERSION,
@@ -85,6 +97,7 @@
.d_strategy = g_dev_strategy,
.d_name = "g_dev",
.d_flags = D_DISK | D_TRACKCLOSE,
+ .d_kqfilter = g_dev_kqfilter,
};
static g_init_t g_dev_init;
@@ -214,6 +227,8 @@
g_trace(G_T_TOPOLOGY, "g_dev_destroy(%p(%s))", cp, gp->name);
snprintf(buf, sizeof(buf), "cdev=%s", gp->name);
devctl_notify("GEOM", "DEV", "DESTROY", buf);
+ knlist_clear(&sc->sc_selinfo.si_note, 0);
+ knlist_destroy(&sc->sc_selinfo.si_note);
if (cp->acr > 0 || cp->acw > 0 || cp->ace > 0)
g_access(cp, -cp->acr, -cp->acw, -cp->ace);
g_detach(cp);
@@ -305,8 +320,14 @@
static void
g_dev_resize(struct g_consumer *cp)
{
+ struct g_dev_softc *sc;
char buf[SPECNAMELEN + 6];
+ sc = cp->private;
+ mtx_lock(&sc->sc_mtx);
+ KNOTE_LOCKED(&sc->sc_selinfo.si_note, NOTE_ATTRIB);
+ mtx_unlock(&sc->sc_mtx);
+
snprintf(buf, sizeof(buf), "cdev=%s", cp->provider->name);
devctl_notify("GEOM", "DEV", "SIZECHANGE", buf);
}
@@ -378,6 +399,7 @@
dev = sc->sc_dev;
dev->si_flags |= SI_UNMAPPED;
dev->si_iosize_max = maxphys;
+ knlist_init_mtx(&sc->sc_selinfo.si_note, &sc->sc_mtx);
error = init_dumpdev(dev);
if (error != 0)
printf("%s: init_dumpdev() failed (gp->name=%s, error=%d)\n",
@@ -896,4 +918,43 @@
destroy_dev_sched_cb(dev, g_dev_callback, cp);
}
+static void
+gdev_filter_detach(struct knote *kn)
+{
+ struct g_dev_softc *sc;
+
+ sc = kn->kn_hook;
+
+ knlist_remove(&sc->sc_selinfo.si_note, kn, 0);
+}
+
+static int
+gdev_filter_vnode(struct knote *kn, long hint)
+{
+ kn->kn_fflags |= kn->kn_sfflags & hint;
+
+ return (kn->kn_fflags != 0);
+}
+
+static int
+g_dev_kqfilter(struct cdev *dev, struct knote *kn)
+{
+ struct g_dev_softc *sc;
+
+ sc = dev->si_drv1;
+
+ switch (kn->kn_filter) {
+ case EVFILT_VNODE:
+ kn->kn_fop = &gdev_filterops_vnode;
+ break;
+ default:
+ return (EINVAL);
+ }
+
+ kn->kn_hook = sc;
+ knlist_add(&sc->sc_selinfo.si_note, kn, 0);
+
+ return (0);
+}
+
DECLARE_GEOM_CLASS(g_dev_class, g_dev);

File Metadata

Mime Type
text/plain
Expires
Fri, Dec 27, 9:03 AM (10 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15612807
Default Alt Text
D33402.id99905.diff (2 KB)

Event Timeline