From owner-freebsd-fs@FreeBSD.ORG Wed Feb 2 02:11:42 2011 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 AB2D2106566B; Wed, 2 Feb 2011 02:11:42 +0000 (UTC) (envelope-from sarawgi.aditya@gmail.com) Received: from mail-iw0-f182.google.com (mail-iw0-f182.google.com [209.85.214.182]) by mx1.freebsd.org (Postfix) with ESMTP id 6484E8FC14; Wed, 2 Feb 2011 02:11:42 +0000 (UTC) Received: by iwn39 with SMTP id 39so7300667iwn.13 for ; Tue, 01 Feb 2011 18:11:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=zOrhvTXkz7Ycygi4/e3TjHJgLbhZ7d9HYHbpBPzrUKk=; b=l3Cn+R7nqvL5kQoS+YVnTUm+Xe3+mTn7u1cVIMQLv3CA8uVoK5wk2BCx7+0avgmVx7 8nt9qStUPxOz807XIEXUL2wnyznG3rmluL8zot6FLA4Xer4n6hGr9lz7pkLKj5cVRTjm 8xZ+BYLzEeWRs7XsZAWC7AUoQXO2Xje83Orl0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=BS/IQ7iM9wCg2ewoWIqkrmmzeE4TeZAHglGYC8UOIL28iC71i3pbJu/LJpQgm+YfQE xzFPokFl3Dby5AGsqVQKCguFo05n7ocTUeqPId8UBzcNG+5mDVmOvCI1Hz7IgwNFP6Mb +jxdQ/eRuKPs3zTkAbf8TZGc4+z4yoPCKyMXM= Received: by 10.42.177.129 with SMTP id bi1mr10358586icb.328.1296610872821; Tue, 01 Feb 2011 17:41:12 -0800 (PST) Received: from earth ([27.106.73.42]) by mx.google.com with ESMTPS id d13sm11758183ice.16.2011.02.01.17.41.10 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 01 Feb 2011 17:41:12 -0800 (PST) Date: Wed, 2 Feb 2011 07:12:55 +0530 From: Aditya Sarawgi To: John Baldwin Message-ID: <20110202014252.GA1574@earth> References: <4D47B954.3010600@FreeBSD.org> <201102011352.57998.jhb@freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201102011352.57998.jhb@freebsd.org> User-Agent: Mutt/1.5.20 (2009-06-14) Cc: freebsd-fs@freebsd.org Subject: Re: ext2fs crash in -current (r218056) 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, 02 Feb 2011 02:11:42 -0000 Hi John, I can see what you are saying. Can't we check the number of free blocks in the given cg without locking the fs. This way EXT2_LOCK(ump); return (0); } + if (fs->e2fs_gd[cg].ext2bgd_nbfree == 0) { + /* + * Another thread allocated the last block in this + * group while we were waiting for the buffer. + */ + brelse(bp); + EXT2_LOCK(ump); + return (0); + } bbp = (char *)bp->b_data; if (dtog(fs, bpref) != cg) UFS is doing something similar static ufs2_daddr_t ffs_alloccg(ip, cg, bpref, size, rsize) struct inode *ip; u_int cg; ufs2_daddr_t bpref; int size; int rsize; { struct fs *fs; struct cg *cgp; struct buf *bp; struct ufsmount *ump; ufs1_daddr_t bno; ufs2_daddr_t blkno; int i, allocsiz, error, frags; u_int8_t *blksfree; ump = ip->i_ump; fs = ip->i_fs; if (fs->fs_cs(fs, cg).cs_nbfree == 0 && size == fs->fs_bsize) return (0); UFS_UNLOCK(ump); error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize, NOCRED, &bp); if (error) goto fail; cgp = (struct cg *)bp->b_data; if (!cg_chkmagic(cgp) || (cgp->cg_cs.cs_nbfree == 0 && size == fs->fs_bsize)) goto fail; > Please try this: > > Index: ext2_alloc.c > =================================================================== > --- ext2_alloc.c (revision 218175) > +++ ext2_alloc.c (working copy) > @@ -650,6 +650,18 @@ > EXT2_LOCK(ump); > return (0); > } > + EXT2_LOCK(ump); > + if (fs->e2fs_gd[cg].ext2bgd_nbfree == 0) { > + /* > + * Another thread allocated the last block in this > + * group while we were waiting for the buffer. > + */ > + EXT2_UNLOCK(ump); > + brelse(bp); > + EXT2_LOCK(ump); > + return (0); > + } > + EXT2_UNLOCK(ump); > bbp = (char *)bp->b_data; > > if (dtog(fs, bpref) != cg) > @@ -776,6 +788,18 @@ > EXT2_LOCK(ump); > return (0); > } > + EXT2_LOCK(ump); > + if (fs->e2fs_gd[cg].ext2bgd_nifree == 0) { > + /* > + * Another thread allocated the last i-node in this > + * group while we were waiting for the buffer. > + */ > + EXT2_UNLOCK(ump); > + brelse(bp); > + EXT2_LOCK(ump); > + return (0); > + } > + EXT2_UNLOCK(ump); > ibp = (char *)bp->b_data; > if (ipref) { > ipref %= fs->e2fs->e2fs_ipg; -- Aditya Sarawgi