From owner-dev-commits-src-branches@freebsd.org  Thu Aug 12 17:02:30 2021
Return-Path: <owner-dev-commits-src-branches@freebsd.org>
Delivered-To: dev-commits-src-branches@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 53F8566F1E4;
 Thu, 12 Aug 2021 17:02:30 +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 4GltKL16Y9z3JN7;
 Thu, 12 Aug 2021 17:02:30 +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 0AA3626B81;
 Thu, 12 Aug 2021 17:02:30 +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 17CH2TQ3017772;
 Thu, 12 Aug 2021 17:02:29 GMT (envelope-from git@gitrepo.freebsd.org)
Received: (from git@localhost)
 by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17CH2TVH017771;
 Thu, 12 Aug 2021 17:02:29 GMT (envelope-from git)
Date: Thu, 12 Aug 2021 17:02:29 GMT
Message-Id: <202108121702.17CH2TVH017771@gitrepo.freebsd.org>
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org,
 dev-commits-src-branches@FreeBSD.org
From: John Baldwin <jhb@FreeBSD.org>
Subject: git: d7e2c1479ccf - stable/13 - 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/stable/13
X-Git-Reftype: branch
X-Git-Commit: d7e2c1479ccf5bbbe7d80c203e05300353d24e52
Auto-Submitted: auto-generated
X-BeenThere: dev-commits-src-branches@freebsd.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: Commits to the stable branches of the FreeBSD src repository
 <dev-commits-src-branches.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/dev-commits-src-branches>, 
 <mailto:dev-commits-src-branches-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/dev-commits-src-branches/>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Help: <mailto:dev-commits-src-branches-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/dev-commits-src-branches>, 
 <mailto:dev-commits-src-branches-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Thu, 12 Aug 2021 17:02:30 -0000

The branch stable/13 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=d7e2c1479ccf5bbbe7d80c203e05300353d24e52

commit d7e2c1479ccf5bbbe7d80c203e05300353d24e52
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2021-06-12 00:59:13 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2021-08-12 15:56:18 +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
    
    (cherry picked from commit 67d60dcce62c08250dceedaf761cb48bc74c75a4)
---
 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);