Date: Sun, 22 Jul 2007 17:44:04 -0400 From: Daniel Molina Wegener <dmw@unete.cl> To: "FreeBSD -CURRENT" <freebsd-current@freebsd.org> Subject: [patch] added kevent vnode events Message-ID: <200707221744.04207.dmw@unete.cl>
next in thread | raw e-mail | index | archive | help
--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 <sys/uio.h>
#include <sys/acl.h>
#include <sys/ktr.h>
+#include <sys/proc.h>
/*
* 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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707221744.04207.dmw>
