From owner-freebsd-fs@FreeBSD.ORG Fri Dec 31 06:48:11 2004 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BD24216A4CE for ; Fri, 31 Dec 2004 06:48:11 +0000 (GMT) Received: from mail-svr1.cs.utah.edu (brahma.cs.utah.edu [155.98.64.200]) by mx1.FreeBSD.org (Postfix) with ESMTP id 82ED943D1D for ; Fri, 31 Dec 2004 06:48:11 +0000 (GMT) (envelope-from saggarwa@cs.utah.edu) Received: from localhost (localhost [127.0.0.1]) by mail-svr1.cs.utah.edu (Postfix) with ESMTP id 1BB1E346EB for ; Thu, 30 Dec 2004 23:48:11 -0700 (MST) Received: from mail-svr1.cs.utah.edu ([127.0.0.1]) by localhost (mail-svr1.cs.utah.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 20880-08 for ; Thu, 30 Dec 2004 23:48:10 -0700 (MST) Received: from faith.cs.utah.edu (faith.cs.utah.edu [155.98.65.40]) by mail-svr1.cs.utah.edu (Postfix) with ESMTP id 7D378346EE for ; Thu, 30 Dec 2004 23:48:10 -0700 (MST) Received: by faith.cs.utah.edu (Postfix, from userid 4973) id E359C2EC21; Thu, 30 Dec 2004 23:48:08 -0700 (MST) Received: from localhost (localhost [127.0.0.1]) by faith.cs.utah.edu (Postfix) with ESMTP id 3347234406 for ; Fri, 31 Dec 2004 06:48:08 +0000 (UTC) Date: Thu, 30 Dec 2004 23:48:08 -0700 (MST) From: Siddharth Aggarwal To: freebsd-fs@freebsd.org Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: amavisd-new at cs.utah.edu Subject: Freezing filesystem activity X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Dec 2004 06:48:11 -0000 I want to freeze any filesystem activity in the kernel (a pseudo driver) i.e. while my driver code is executing (this code basically flushes buffer cache blocks to disk), I donot want any other filesystem operations coming in. I tried this by locking the filesystem before my code and unlocking right after as shown below. There is a problem because it causes a hang (rather it seems as if 1. The flush is happening indefinitely as if the filesystem never got locked and hence more disk updates keep coming in or 2. The filesystem unlock is not happening properly and hence nothing can proceed. Any suggestions to rectify or probe this problem? Thanks, Sid. my_code() { vp = lock_filesystem(); sync(); // flush to disk unlock_filesystem(vp); } struct vnode * lock_filesystem() { NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, "/", curproc); if ((error = vn_open(&nd, FREAD, 0)) != 0) { printf ("Error opening filesystem \n"); return 0; } vp = nd.ni_vp; vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curproc); NDFREE(&nd, NDF_ONLY_PNBUF); return vp; } unlock_filesystem(struct vnode * vp) { VOP_UNLOCK(vp, 0, curproc); } From owner-freebsd-fs@FreeBSD.ORG Fri Dec 31 15:33:43 2004 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C568616A4CE for ; Fri, 31 Dec 2004 15:33:43 +0000 (GMT) Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id 547F443D48 for ; Fri, 31 Dec 2004 15:33:43 +0000 (GMT) (envelope-from robert@fledge.watson.org) Received: from fledge.watson.org (localhost [127.0.0.1]) by fledge.watson.org (8.13.1/8.13.1) with ESMTP id iBVFU0bZ096124; Fri, 31 Dec 2004 10:30:00 -0500 (EST) (envelope-from robert@fledge.watson.org) Received: from localhost (robert@localhost)iBVFU0qj096121; Fri, 31 Dec 2004 15:30:00 GMT (envelope-from robert@fledge.watson.org) Date: Fri, 31 Dec 2004 15:30:00 +0000 (GMT) From: Robert Watson X-Sender: robert@fledge.watson.org To: Siddharth Aggarwal In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-fs@freebsd.org Subject: Re: Freezing filesystem activity X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Dec 2004 15:33:43 -0000 On Thu, 30 Dec 2004, Siddharth Aggarwal wrote: > I want to freeze any filesystem activity in the kernel (a pseudo driver) > i.e. while my driver code is executing (this code basically flushes > buffer cache blocks to disk), I donot want any other filesystem > operations coming in. I tried this by locking the filesystem before my > code and unlocking right after as shown below. There is a problem > because it causes a hang (rather it seems as if If you would just like to freeze file system write operations, a facility for this already exists via the vn_start_write() and vn_write_finished() calls, which are used to gate access to the file system during snapshot operations. All processes that attempt to start a write operation on the file system once it's frozen will block waiting until the write lock is released. If you also need to freeze read operations, that would require fairly substantial modifications to the kernel to implement something not disimilar to the above. Robert N M Watson > > 1. The flush is happening indefinitely > as if the filesystem never got locked and hence more disk updates keep > coming in > > or > > 2. The filesystem unlock is not happening properly and hence nothing can > proceed. > > Any suggestions to rectify or probe this problem? > > Thanks, > Sid. > > my_code() > { > vp = lock_filesystem(); > sync(); // flush to disk > unlock_filesystem(vp); > } > > struct vnode * lock_filesystem() > { > NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, "/", curproc); > if ((error = vn_open(&nd, FREAD, 0)) != 0) { > printf ("Error opening filesystem \n"); > return 0; > } > vp = nd.ni_vp; > vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curproc); > NDFREE(&nd, NDF_ONLY_PNBUF); > return vp; > } > > unlock_filesystem(struct vnode * vp) > { > VOP_UNLOCK(vp, 0, curproc); > } > > _______________________________________________ > freebsd-fs@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-fs > To unsubscribe, send any mail to "freebsd-fs-unsubscribe@freebsd.org" > From owner-freebsd-fs@FreeBSD.ORG Fri Dec 31 15:41:29 2004 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 45D1816A4CE; Fri, 31 Dec 2004 15:41:29 +0000 (GMT) Received: from mail-svr1.cs.utah.edu (brahma.cs.utah.edu [155.98.64.200]) by mx1.FreeBSD.org (Postfix) with ESMTP id CB84E43D2D; Fri, 31 Dec 2004 15:41:28 +0000 (GMT) (envelope-from saggarwa@cs.utah.edu) Received: from localhost (localhost [127.0.0.1]) by mail-svr1.cs.utah.edu (Postfix) with ESMTP id 79E4B346EF; Fri, 31 Dec 2004 08:41:28 -0700 (MST) Received: from mail-svr1.cs.utah.edu ([127.0.0.1]) by localhost (mail-svr1.cs.utah.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 27694-04; Fri, 31 Dec 2004 08:41:28 -0700 (MST) Received: from faith.cs.utah.edu (faith.cs.utah.edu [155.98.65.40]) by mail-svr1.cs.utah.edu (Postfix) with ESMTP id 2DF9C346EB; Fri, 31 Dec 2004 08:41:28 -0700 (MST) Received: by faith.cs.utah.edu (Postfix, from userid 4973) id B59172EC21; Fri, 31 Dec 2004 08:41:26 -0700 (MST) Received: from localhost (localhost [127.0.0.1]) by faith.cs.utah.edu (Postfix) with ESMTP id 0CCD734406; Fri, 31 Dec 2004 15:41:26 +0000 (UTC) Date: Fri, 31 Dec 2004 08:41:25 -0700 (MST) From: Siddharth Aggarwal To: Robert Watson In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: amavisd-new at cs.utah.edu cc: freebsd-fs@freebsd.org Subject: Re: Freezing filesystem activity X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Dec 2004 15:41:29 -0000 On Fri, 31 Dec 2004, Robert Watson wrote: > On Thu, 30 Dec 2004, Siddharth Aggarwal wrote: > > > I want to freeze any filesystem activity in the kernel (a pseudo driver) > > i.e. while my driver code is executing (this code basically flushes > > buffer cache blocks to disk), I donot want any other filesystem > > operations coming in. I tried this by locking the filesystem before my > > code and unlocking right after as shown below. There is a problem > > because it causes a hang (rather it seems as if > > If you would just like to freeze file system write operations, a facility > for this already exists via the vn_start_write() and vn_write_finished() > calls, which are used to gate access to the file system during snapshot > operations. All processes that attempt to start a write operation on the > file system once it's frozen will block waiting until the write lock is > released. If you also need to freeze read operations, that would require > fairly substantial modifications to the kernel to implement something not > disimilar to the above. > > Robert N M Watson > > Thanks for your reply. I believe these functions are available in BSD 5.x and upwards. I am trying to implement this in BSD 4.7. Do you have any suggestions how I can do this (equivalent of vn_start_write() and vn_write_finished())?