From owner-freebsd-hackers@FreeBSD.ORG Fri Feb 13 18:50:01 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from green.homeunix.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 4CD9916A4CF; Fri, 13 Feb 2004 18:50:01 -0800 (PST) Received: from green.homeunix.org (green@localhost [127.0.0.1]) by green.homeunix.org (8.12.10/8.12.9) with ESMTP id i1E2ntpe001421; Fri, 13 Feb 2004 21:49:55 -0500 (EST) (envelope-from green@green.homeunix.org) Received: from localhost (green@localhost)i1E2ns8R001417; Fri, 13 Feb 2004 21:49:54 -0500 (EST) Message-Id: <200402140249.i1E2ns8R001417@green.homeunix.org> X-Mailer: exmh version 2.6.3 04/04/2003 with nmh-1.0.4 To: freebsd-hackers@freebsd.org In-Reply-To: Message from Andrey Simonenko <20040213090838.GA221@pm514-9.comsys.ntu-kpi.kiev.ua> From: "Brian F. Feldman" Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 13 Feb 2004 21:49:53 -0500 Sender: green@green.homeunix.org cc: Andrey Simonenko Subject: Re: Changing v_op for vnode on the fly X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Feb 2004 02:50:01 -0000 Andrey Simonenko wrote: > Hello all, > > I want to control in a KLD module when any process make any > VOPs, which can change the content of some file. For this I change > v_op field in the needed vnode to my vnodeop_p, currently my VOPs > print some debug information and call original VOPs for the vnode. > > I can't simply wrap syscall entries for a process to control write() > and read() syscalls, because it is unknown in my task which process > can access a file and processes can mmap a file and modify or read it > directly in their memory. > > Is it enough to get exclusive lock on vnode, before changing > v_op pointer? Here is my code: > > vn_lock(cvp->vp, LK_EXCLUSIVE | LK_RETRY, p); > > if (flag > 0) > cvp->vp->v_op = catch_vnode_vnodeop_p; /* My vnodeop_p. */ > else > cvp->vp->v_op = cvp->vnodeop_p; /* Original v_op. */ > > VOP_UNLOCK(cvp->vp, 0, p); > > I made some tests and see that most of VOP_xxx require lock (shared > or exclusive) on vnode, as well this is documented in the manual pages. No, you are not allowed to change v_op, ever. Can you do what you're trying to do in the MAC framework? It seems like that is what you want to be doing! The other possibility is using something like umapfs/lomacfs/ unionfs. -- Brian Fundakowski Feldman \'[ FreeBSD ]''''''''''\ <> green@FreeBSD.org \ The Power to Serve! \ Opinions expressed are my own. \,,,,,,,,,,,,,,,,,,,,,,\