From owner-freebsd-fs@FreeBSD.ORG Wed May 27 15:35:53 2009 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3207B106564A for ; Wed, 27 May 2009 15:35:53 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.terabit.net.ua (mail.terabit.net.ua [195.137.202.147]) by mx1.freebsd.org (Postfix) with ESMTP id C99EE8FC16 for ; Wed, 27 May 2009 15:35:52 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from skuns.zoral.com.ua ([91.193.166.194] helo=mail.zoral.com.ua) by mail.terabit.net.ua with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63 (FreeBSD)) (envelope-from ) id 1M9LAS-000Mc8-V1; Wed, 27 May 2009 18:35:50 +0300 Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id n4RFZhk6058073 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 27 May 2009 18:35:43 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.3/8.14.3) with ESMTP id n4RFZhb5052845; Wed, 27 May 2009 18:35:43 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.3/8.14.3/Submit) id n4RFZhEl052844; Wed, 27 May 2009 18:35:43 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Wed, 27 May 2009 18:35:43 +0300 From: Kostik Belousov To: Jaakko Heinonen Message-ID: <20090527153543.GK1927@deviant.kiev.zoral.com.ua> References: <20090527150258.GA3666@a91-153-125-115.elisa-laajakaista.fi> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="N2sd0375daQhR1Ll" Content-Disposition: inline In-Reply-To: <20090527150258.GA3666@a91-153-125-115.elisa-laajakaista.fi> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.1 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua X-Virus-Scanned: mail.terabit.net.ua 1M9LAS-000Mc8-V1 4dd2c6e967f6755c3ec7161eff7f4767 X-Terabit: YES Cc: freebsd-fs@freebsd.org Subject: Re: VOP_WRITE & read-only file system X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 May 2009 15:35:53 -0000 --N2sd0375daQhR1Ll Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, May 27, 2009 at 06:02:59PM +0300, Jaakko Heinonen wrote: >=20 > Hi, >=20 > I found a few ways to get VOP_WRITE called for a read-only system. Looks > like there is an assumption in (UFS) file system code that VOP_WRITE is > not called for read-only file-systems and indeed the assumption is true > in typical cases. Calling VOP_WRITE for a read-only file system leads to > erratic behavior at least with UFS. >=20 > Ways I found: >=20 > 1) mmap(2) > - mmap(2) a file > - close(2) the file handle > - remount file-system as read-only > - modify mapped memory >=20 > 2) ktrace(2) > - start ktracing a process > - remount file-system as read-only >=20 > 3) alq(9) > - I didn't really test this but it looks obvious >=20 > At which level this should be fixed? Is it caller's responsibility not > to call VOP_WRITE if the file system is read-only or should there be a > check in VOP_WRITE? Yes, the issue is there. Real cause for the problem is that mmap() does not increment v_writecnt of the vnode that backs shared writable mappings. I have a patch that fixes this, see http://people.freebsd.org/~kib/misc/vm_map_delete.3.patch It is complicated because you cannot lock a vnode while holding user map lock, and you need to increment v_writecnt during mmap (that is relatively easy, by locking vnode in advance) and when map entry is splitted (that is hard). >=20 > Another concern is races during remount. I don't see that UFS has > protection against read-only flag changing during VOPs. During remount rw->ro or unmount, UFS filesystem is suspended, see r183074. Suspension waits for the currently executing vops that modify the file system, and then blocks new vops until suspension is lifted. --N2sd0375daQhR1Ll Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (FreeBSD) iEYEARECAAYFAkodXc8ACgkQC3+MBN1Mb4hfUACePXI5gMUQLbD1MMU0XVZoemn4 KDEAoIJa35IKJkfclbGb4cKTNXMXgB3T =lo4I -----END PGP SIGNATURE----- --N2sd0375daQhR1Ll--