From owner-freebsd-current@FreeBSD.ORG Sun Jul 22 21:44:43 2007 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8C37916A417 for ; Sun, 22 Jul 2007 21:44:43 +0000 (UTC) (envelope-from dmw@unete.cl) Received: from mail08.ifxnetworks.com (mail08.ifxnetworks.com [190.61.128.18]) by mx1.freebsd.org (Postfix) with ESMTP id 1C44B13C45A for ; Sun, 22 Jul 2007 21:44:42 +0000 (UTC) (envelope-from dmw@unete.cl) Received: (qmail 433 invoked from network); 22 Jul 2007 21:44:41 -0000 X-Spam-DCC: : mail08.ifxnetworks.com 102; Body=1 Fuz1=1 Fuz2=1 X-Spam-Checker-Version: SpamAssassin 3.2.1 (2007-05-02) on mail08.ifxnetworks.com X-Spam-Level: X-Spam-Status: No, score=0.1 required=7.0 tests=RDNS_NONE autolearn=disabled version=3.2.1 Received: from unknown (HELO quake) (dmw@unete.cl@[200.73.82.54]) (envelope-sender ) by mail08.ifxnetworks.com (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 22 Jul 2007 21:44:40 -0000 From: Daniel Molina Wegener Organization: DMW To: "FreeBSD -CURRENT" Date: Sun, 22 Jul 2007 17:44:04 -0400 User-Agent: KMail/1.9.6 MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_k+8oGQoNs9nDJvl" Message-Id: <200707221744.04207.dmw@unete.cl> Subject: [patch] added kevent vnode events X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: dmw@unete.cl List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Jul 2007 21:44:43 -0000 --Boundary-00=_k+8oGQoNs9nDJvl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello, I've added NOTE_OPEN, NOTE_CLOSE and NOTE_READ events into =20 the -CURRENT kevent code. The patch is attached. =C2=BFCan someone take a look and verify if the patch can be included in the =2DCURRENT code? Regards. =2D-=20 .O. | Daniel Molina Wegener | C/C++ Developer ..O | dmw [at] unete [dot] cl | FOSS Coding Adict OOO | BSD & Linux User | Standards Rocks! --Boundary-00=_k+8oGQoNs9nDJvl Content-Type: text/x-diff; charset="utf-8"; name="kevent-new-notes-man.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="kevent-new-notes-man.patch" Index: kqueue.2 =================================================================== RCS file: /home/ncvs/src/lib/libc/sys/kqueue.2,v retrieving revision 1.45 diff -u -r1.45 kqueue.2 --- kqueue.2 20 Nov 2006 22:20:04 -0000 1.45 +++ kqueue.2 22 Jul 2007 21:19:19 -0000 @@ -335,6 +335,12 @@ .Fn unlink system call was called on the file referenced by the descriptor. +.It NOTE_OPEN +An open ocurred on the file referenced by the descriptor. Kernel threads are hiddend and system process too for any user diferent to root. +.It NOTE_CLOSE +A close ocurred on the file referenced by the descriptor. Kernel threads are hiddend and system process too for any user diferent to root. +.It NOTE_READ +A read ocurred on the file referenced by the descriptor. Kernel threads are hiddend and system process too for any user diferent to root. .It NOTE_WRITE A write occurred on the file referenced by the descriptor. .It NOTE_EXTEND --Boundary-00=_k+8oGQoNs9nDJvl Content-Type: text/x-diff; charset="utf-8"; name="kevent-new-notes.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="kevent-new-notes.patch" ? .cscope.db ? .cscope.db.in ? .cscope.db.po Index: kern/vfs_subr.c =================================================================== RCS file: /home/ncvs/src/sys/kern/vfs_subr.c,v retrieving revision 1.705 diff -u -r1.705 vfs_subr.c --- kern/vfs_subr.c 12 Jun 2007 00:11:59 -0000 1.705 +++ kern/vfs_subr.c 22 Jul 2007 21:06:23 -0000 @@ -3637,6 +3637,46 @@ } void +vop_open_post(void *ap, int rc) +{ + struct vop_open_args *a = ap; + if (!rc) { + if ((a->a_td->td_proc->p_flag & P_KTHREAD) == 0) { + if (a->a_cred->cr_ruid == 0 + && a->a_cred->cr_uid == 0) { + VFS_KNOTE_LOCKED(a->a_vp, NOTE_OPEN); + } else { + if ((a->a_td->td_proc->p_flag + & P_KTHREAD + & P_SYSTEM) == 0) { + VFS_KNOTE_LOCKED(a->a_vp, NOTE_OPEN); + } + } + } + } +} + +void +vop_close_post(void *ap, int rc) +{ + struct vop_close_args *a = ap; + if (!rc) { + if ((a->a_td->td_proc->p_flag & P_KTHREAD) == 0) { + if (a->a_cred->cr_ruid == 0 + && a->a_cred->cr_uid == 0) { + VFS_KNOTE_LOCKED(a->a_vp, NOTE_CLOSE); + } else { + if ((a->a_td->td_proc->p_flag + & P_KTHREAD + & P_SYSTEM) == 0) { + VFS_KNOTE_LOCKED(a->a_vp, NOTE_CLOSE); + } + } + } + } +} + +void vop_remove_post(void *ap, int rc) { struct vop_remove_args *a = ap; Index: kern/vnode_if.src =================================================================== RCS file: /home/ncvs/src/sys/kern/vnode_if.src,v retrieving revision 1.87 diff -u -r1.87 vnode_if.src --- kern/vnode_if.src 31 May 2007 11:51:52 -0000 1.87 +++ kern/vnode_if.src 22 Jul 2007 21:06:24 -0000 @@ -124,6 +124,7 @@ %% open vp L L L +%! open post vop_open_post vop_open { IN struct vnode *vp; @@ -135,6 +136,7 @@ %% close vp E E E +%! close post vop_close_post vop_close { IN struct vnode *vp; @@ -176,6 +178,8 @@ %% read vp L L L +%! read pre VOP_READ_PRE +%! read post VOP_READ_POST vop_read { IN struct vnode *vp; Index: sys/event.h =================================================================== RCS file: /home/ncvs/src/sys/sys/event.h,v retrieving revision 1.37 diff -u -r1.37 event.h --- sys/event.h 24 Sep 2006 04:47:47 -0000 1.37 +++ sys/event.h 22 Jul 2007 21:06:31 -0000 @@ -94,6 +94,9 @@ #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 /* the vnode was opened */ +#define NOTE_CLOSE 0x0100 /* the vnode was closed */ +#define NOTE_READ 0x0200 /* the vnode was readed */ /* * data/hint flags for EVFILT_PROC, shared with userspace Index: sys/vnode.h =================================================================== RCS file: /home/ncvs/src/sys/sys/vnode.h,v retrieving revision 1.326 diff -u -r1.326 vnode.h --- sys/vnode.h 31 May 2007 11:51:52 -0000 1.326 +++ sys/vnode.h 22 Jul 2007 21:06:31 -0000 @@ -49,6 +49,7 @@ #include #include #include +#include /* * The vnode is the focus of all file activity in UNIX. There is a @@ -672,6 +673,8 @@ 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_close_post(void *a, int rc); void vop_remove_post(void *a, int rc); void vop_rename_post(void *a, int rc); void vop_rename_pre(void *a); @@ -703,6 +706,39 @@ | (noffset > osize ? NOTE_EXTEND : 0)); \ } +#define VOP_READ_PRE(ap) \ + struct vattr va; \ + struct thread *td; \ + int error, resid, osize, ooffset, noffset; \ + \ + osize = ooffset = noffset = 0; \ + if (!VN_KNLIST_EMPTY((ap)->a_vp)) { \ + error = VOP_GETATTR((ap)->a_vp, &va, (ap)->a_cred, \ + curthread); \ + if (error) \ + return (error); \ + } + +#define VOP_READ_POST(ap, ret) \ + resid = (ap)->a_uio->uio_resid; \ + td = (ap)->a_uio->uio_td; \ + if (resid == 0 && !VN_KNLIST_EMPTY((ap)->a_vp)) { \ + if ((td->td_proc->p_flag & P_KTHREAD) \ + == 0) { \ + if ((ap)->a_cred->cr_ruid == 0 \ + && (ap)->a_cred->cr_uid == 0) { \ + VFS_KNOTE_LOCKED(a->a_vp, NOTE_READ); \ + } else { \ + if ((td->td_proc->p_flag & P_SYSTEM) \ + == 0) { \ + VFS_KNOTE_LOCKED(a->a_vp, \ + NOTE_READ); \ + } \ + } \ + \ + } \ + } + #define VOP_LOCK(vp, flags, td) VOP_LOCK1(vp, flags, td, __FILE__, __LINE__) --Boundary-00=_k+8oGQoNs9nDJvl--