From owner-dev-commits-src-all@freebsd.org Sat Jun 12 01:00:43 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id EC3C8640121; Sat, 12 Jun 2021 01:00:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4G1zsl6NQVz3FyV; Sat, 12 Jun 2021 01:00:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C17A82CFA3; Sat, 12 Jun 2021 01:00:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 15C10hG9084716; Sat, 12 Jun 2021 01:00:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 15C10hJl084715; Sat, 12 Jun 2021 01:00:43 GMT (envelope-from git) Date: Sat, 12 Jun 2021 01:00:43 GMT Message-Id: <202106120100.15C10hJl084715@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 67d60dcce62c - main - bhyve: Add support for EVFILT_VNODE mevents. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 67d60dcce62c08250dceedaf761cb48bc74c75a4 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Jun 2021 01:00:44 -0000 The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=67d60dcce62c08250dceedaf761cb48bc74c75a4 commit 67d60dcce62c08250dceedaf761cb48bc74c75a4 Author: John Baldwin AuthorDate: 2021-06-12 00:59:13 +0000 Commit: John Baldwin CommitDate: 2021-06-12 01:00:24 +0000 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 --- usr.sbin/bhyve/mevent.c | 33 ++++++++++++++++++++++++++++----- usr.sbin/bhyve/mevent.h | 9 ++++++++- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/usr.sbin/bhyve/mevent.c b/usr.sbin/bhyve/mevent.c index a394b7c5d69f..0c5351cd31a9 100644 --- a/usr.sbin/bhyve/mevent.c +++ b/usr.sbin/bhyve/mevent.c @@ -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 diff --git a/usr.sbin/bhyve/mevent.h b/usr.sbin/bhyve/mevent.h index 503ec415a3b5..a26293867a09 100644 --- a/usr.sbin/bhyve/mevent.h +++ b/usr.sbin/bhyve/mevent.h @@ -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);