From owner-svn-src-all@freebsd.org Mon May 16 02:42:54 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B599EB3C67D; Mon, 16 May 2016 02:42:54 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 85EC116BF; Mon, 16 May 2016 02:42:54 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4G2grua092116; Mon, 16 May 2016 02:42:53 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4G2grxU092111; Mon, 16 May 2016 02:42:53 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201605160242.u4G2grxU092111@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Mon, 16 May 2016 02:42:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r299886 - in stable/10: lib/libc/sys sys/kern sys/sys X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 May 2016 02:42:54 -0000 Author: kib Date: Mon May 16 02:42:53 2016 New Revision: 299886 URL: https://svnweb.freebsd.org/changeset/base/299886 Log: MFC r298982: Add EVFILT_VNODE open, read and close notifications. MFC r298984: Correct wording. Modified: stable/10/lib/libc/sys/kqueue.2 stable/10/sys/kern/vfs_subr.c stable/10/sys/kern/vnode_if.src stable/10/sys/sys/event.h stable/10/sys/sys/vnode.h Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libc/sys/kqueue.2 ============================================================================== --- stable/10/lib/libc/sys/kqueue.2 Mon May 16 02:35:33 2016 (r299885) +++ stable/10/lib/libc/sys/kqueue.2 Mon May 16 02:42:53 2016 (r299886) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 2, 2016 +.Dd May 3, 2016 .Dt KQUEUE 2 .Os .Sh NAME @@ -359,14 +359,28 @@ Takes a file descriptor as the identifie .Va fflags , and returns when one or more of the requested events occurs on the descriptor. The events to monitor are: -.Bl -tag -width "Dv NOTE_RENAME" +.Bl -tag -width "Dv NOTE_CLOSE_WRITE" +.It Dv NOTE_ATTRIB +The file referenced by the descriptor had its attributes changed. +.It Dv NOTE_CLOSE +A file descriptor referencing the monitored file, was closed. +The closed file descriptor did not have write access. +.It Dv NOTE_CLOSE_WRITE +A file descriptor referencing the monitored file, was closed. +The closed file descriptor has write access. +.Pp +This note, as well as +.Dv NOTE_CLOSE , +are not activated when files are closed forcibly by +.Xr unmount 2 or +.Xr revoke 2 . +Instead, +.Dv NOTE_REVOKE +is sent for such events. .It Dv NOTE_DELETE The .Fn unlink -system call -was called on the file referenced by the descriptor. -.It Dv NOTE_WRITE -A write occurred on the file referenced by the descriptor. +system call was called on the file referenced by the descriptor. .It Dv NOTE_EXTEND For regular file, the file referenced by the descriptor was extended. .Pp @@ -375,20 +389,24 @@ as the result of rename operation. The .Dv NOTE_EXTEND event is not reported when a name is changed inside the directory. -.It Dv NOTE_ATTRIB -The file referenced by the descriptor had its attributes changed. .It Dv NOTE_LINK The link count on the file changed. In particular, the .Dv NOTE_LINK event is reported if a subdirectory was created or deleted inside the directory referenced by the descriptor. +.It Dv NOTE_OPEN +The file referenced by the descriptor was opened. +.It Dv NOTE_READ +A read occurred on the file referenced by the descriptor. .It Dv NOTE_RENAME The file referenced by the descriptor was renamed. .It Dv NOTE_REVOKE Access to the file was revoked via .Xr revoke 2 or the underlying file system was unmounted. +.It Dv NOTE_WRITE +A write occurred on the file referenced by the descriptor. .El .Pp On return, Modified: stable/10/sys/kern/vfs_subr.c ============================================================================== --- stable/10/sys/kern/vfs_subr.c Mon May 16 02:35:33 2016 (r299885) +++ stable/10/sys/kern/vfs_subr.c Mon May 16 02:42:53 2016 (r299886) @@ -4446,6 +4446,45 @@ vop_symlink_post(void *ap, int rc) VFS_KNOTE_LOCKED(a->a_dvp, NOTE_WRITE); } +void +vop_open_post(void *ap, int rc) +{ + struct vop_open_args *a = ap; + + if (!rc) + VFS_KNOTE_LOCKED(a->a_vp, NOTE_OPEN); +} + +void +vop_close_post(void *ap, int rc) +{ + struct vop_close_args *a = ap; + + if (!rc && (a->a_cred != NOCRED || /* filter out revokes */ + (a->a_vp->v_iflag & VI_DOOMED) == 0)) { + VFS_KNOTE_LOCKED(a->a_vp, (a->a_fflag & FWRITE) != 0 ? + NOTE_CLOSE_WRITE : NOTE_CLOSE); + } +} + +void +vop_read_post(void *ap, int rc) +{ + struct vop_read_args *a = ap; + + if (!rc) + VFS_KNOTE_LOCKED(a->a_vp, NOTE_READ); +} + +void +vop_readdir_post(void *ap, int rc) +{ + struct vop_readdir_args *a = ap; + + if (!rc) + VFS_KNOTE_LOCKED(a->a_vp, NOTE_READ); +} + static struct knlist fs_knlist; static void Modified: stable/10/sys/kern/vnode_if.src ============================================================================== --- stable/10/sys/kern/vnode_if.src Mon May 16 02:35:33 2016 (r299885) +++ stable/10/sys/kern/vnode_if.src Mon May 16 02:42:53 2016 (r299886) @@ -121,6 +121,7 @@ vop_mknod { %% open vp L L L +%! open post vop_open_post vop_open { IN struct vnode *vp; @@ -132,6 +133,7 @@ vop_open { %% close vp L L L +%! close post vop_close_post vop_close { IN struct vnode *vp; @@ -186,6 +188,7 @@ vop_markatime { }; %% read vp L L L +%! read post vop_read_post vop_read { IN struct vnode *vp; @@ -326,6 +329,7 @@ vop_symlink { %% readdir vp L L L +%! readdir post vop_readdir_post vop_readdir { IN struct vnode *vp; Modified: stable/10/sys/sys/event.h ============================================================================== --- stable/10/sys/sys/event.h Mon May 16 02:35:33 2016 (r299885) +++ stable/10/sys/sys/event.h Mon May 16 02:42:53 2016 (r299886) @@ -118,6 +118,12 @@ struct kevent { #define NOTE_LINK 0x0010 /* link count changed */ #define NOTE_RENAME 0x0020 /* vnode was renamed */ #define NOTE_REVOKE 0x0040 /* vnode access was revoked */ +#define NOTE_OPEN 0x0080 /* vnode was opened */ +#define NOTE_CLOSE 0x0100 /* file closed, fd did not + allowed write */ +#define NOTE_CLOSE_WRITE 0x0200 /* file closed, fd did allowed + write */ +#define NOTE_READ 0x0400 /* file was read */ /* * data/hint flags for EVFILT_PROC, shared with userspace Modified: stable/10/sys/sys/vnode.h ============================================================================== --- stable/10/sys/sys/vnode.h Mon May 16 02:35:33 2016 (r299885) +++ stable/10/sys/sys/vnode.h Mon May 16 02:42:53 2016 (r299886) @@ -765,6 +765,7 @@ int dead_read(struct vop_read_args *ap); int dead_write(struct vop_write_args *ap); /* These are called from within the actual VOPS. */ +void vop_close_post(void *a, int rc); void vop_create_post(void *a, int rc); void vop_deleteextattr_post(void *a, int rc); void vop_link_post(void *a, int rc); @@ -774,6 +775,9 @@ void vop_lookup_post(void *a, int rc); void vop_lookup_pre(void *a); void vop_mkdir_post(void *a, int rc); void vop_mknod_post(void *a, int rc); +void vop_open_post(void *a, int rc); +void vop_read_post(void *a, int rc); +void vop_readdir_post(void *a, int rc); void vop_reclaim_post(void *a, int rc); void vop_remove_post(void *a, int rc); void vop_rename_post(void *a, int rc);