Author: kib
Date: Tue May  3 15:17:43 2016
New Revision: 298982
URL: https://svnweb.freebsd.org/changeset/base/298982

Log:
  Add EVFILT_VNODE open, read and close notifications.
  
  While there, order EVFILT_VNODE notes descriptions alphabetically.
  
  Based on submission, and tested by:   Vladimir Kondratyev <w...@cicgroup.ru>
  MFC after:    2 weeks

Modified:
  head/lib/libc/sys/kqueue.2
  head/sys/kern/vfs_subr.c
  head/sys/kern/vnode_if.src
  head/sys/sys/event.h
  head/sys/sys/vnode.h

Modified: head/lib/libc/sys/kqueue.2
==============================================================================
--- head/lib/libc/sys/kqueue.2  Tue May  3 15:14:17 2016        (r298981)
+++ head/lib/libc/sys/kqueue.2  Tue May  3 15:17:43 2016        (r298982)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd May 2, 2016
+.Dd May 3, 2016
 .Dt KQUEUE 2
 .Os
 .Sh NAME
@@ -367,14 +367,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 possesed 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
@@ -383,20 +397,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: head/sys/kern/vfs_subr.c
==============================================================================
--- head/sys/kern/vfs_subr.c    Tue May  3 15:14:17 2016        (r298981)
+++ head/sys/kern/vfs_subr.c    Tue May  3 15:17:43 2016        (r298982)
@@ -4722,6 +4722,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: head/sys/kern/vnode_if.src
==============================================================================
--- head/sys/kern/vnode_if.src  Tue May  3 15:14:17 2016        (r298981)
+++ head/sys/kern/vnode_if.src  Tue May  3 15:17:43 2016        (r298982)
@@ -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: head/sys/sys/event.h
==============================================================================
--- head/sys/sys/event.h        Tue May  3 15:14:17 2016        (r298981)
+++ head/sys/sys/event.h        Tue May  3 15:17:43 2016        (r298982)
@@ -121,6 +121,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 and EVFILT_PROCDESC, shared with userspace

Modified: head/sys/sys/vnode.h
==============================================================================
--- head/sys/sys/vnode.h        Tue May  3 15:14:17 2016        (r298981)
+++ head/sys/sys/vnode.h        Tue May  3 15:17:43 2016        (r298982)
@@ -774,6 +774,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);
@@ -783,6 +784,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);
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to