bhyve: Add support for EVFILT_VNODE mevents.

This allows registering an event to watch for changes to a file's
attributes.  This is a bit imperfect as it would be nice to have a way
to determine if an fd can use EVFILT_VNODE successfully.  mevent's
current structure does not permit that and a failure to register a
single kevent impacts several other kevents.

Reviewed by:	grehan, markj
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D30503
This commit is contained in:
John Baldwin 2021-06-11 17:59:13 -07:00
parent e8424e2947
commit 67d60dcce6
2 changed files with 36 additions and 6 deletions

View File

@ -80,6 +80,7 @@ struct mevent {
int me_cq;
int me_state; /* Desired kevent flags. */
int me_closefd;
int me_fflags;
LIST_ENTRY(mevent) me_list;
};
@ -165,6 +166,9 @@ mevent_kq_filter(struct mevent *mevp)
if (mevp->me_type == EVF_SIGNAL)
retval = EVFILT_SIGNAL;
if (mevp->me_type == EVF_VNODE)
retval = EVFILT_VNODE;
return (retval);
}
@ -177,8 +181,18 @@ mevent_kq_flags(struct mevent *mevp)
static int
mevent_kq_fflags(struct mevent *mevp)
{
/* XXX nothing yet, perhaps EV_EOF for reads ? */
return (0);
int retval;
retval = 0;
switch (mevp->me_type) {
case EVF_VNODE:
if ((mevp->me_fflags & EVFF_ATTRIB) != 0)
retval |= NOTE_ATTRIB;
break;
}
return (retval);
}
static void
@ -255,7 +269,7 @@ mevent_handle(struct kevent *kev, int numev)
static struct mevent *
mevent_add_state(int tfd, enum ev_type type,
void (*func)(int, enum ev_type, void *), void *param,
int state)
int state, int fflags)
{
struct kevent kev;
struct mevent *lp, *mevp;
@ -305,6 +319,7 @@ mevent_add_state(int tfd, enum ev_type type,
mevp->me_func = func;
mevp->me_param = param;
mevp->me_state = state;
mevp->me_fflags = fflags;
/*
* Try to add the event. If this fails, report the failure to
@ -332,7 +347,15 @@ mevent_add(int tfd, enum ev_type type,
void (*func)(int, enum ev_type, void *), void *param)
{
return (mevent_add_state(tfd, type, func, param, EV_ADD));
return (mevent_add_state(tfd, type, func, param, EV_ADD, 0));
}
struct mevent *
mevent_add_flags(int tfd, enum ev_type type, int fflags,
void (*func)(int, enum ev_type, void *), void *param)
{
return (mevent_add_state(tfd, type, func, param, EV_ADD, fflags));
}
struct mevent *
@ -340,7 +363,7 @@ mevent_add_disabled(int tfd, enum ev_type type,
void (*func)(int, enum ev_type, void *), void *param)
{
return (mevent_add_state(tfd, type, func, param, EV_ADD | EV_DISABLE));
return (mevent_add_state(tfd, type, func, param, EV_ADD | EV_DISABLE, 0));
}
static int

View File

@ -35,14 +35,21 @@ enum ev_type {
EVF_READ,
EVF_WRITE,
EVF_TIMER,
EVF_SIGNAL
EVF_SIGNAL,
EVF_VNODE,
};
/* Filter flags for EVF_VNODE */
#define EVFF_ATTRIB 0x0001
struct mevent;
struct mevent *mevent_add(int fd, enum ev_type type,
void (*func)(int, enum ev_type, void *),
void *param);
struct mevent *mevent_add_flags(int fd, enum ev_type type, int fflags,
void (*func)(int, enum ev_type, void *),
void *param);
struct mevent *mevent_add_disabled(int fd, enum ev_type type,
void (*func)(int, enum ev_type, void *),
void *param);