From owner-svn-src-head@FreeBSD.ORG Fri Apr 18 17:03:36 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C3A85896; Fri, 18 Apr 2014 17:03:36 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B037616AD; Fri, 18 Apr 2014 17:03:36 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s3IH3a56050313; Fri, 18 Apr 2014 17:03:36 GMT (envelope-from imp@svn.freebsd.org) Received: (from imp@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s3IH3Zn4050308; Fri, 18 Apr 2014 17:03:35 GMT (envelope-from imp@svn.freebsd.org) Message-Id: <201404181703.s3IH3Zn4050308@svn.freebsd.org> From: Warner Losh Date: Fri, 18 Apr 2014 17:03:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r264657 - head/sys/fs/nandfs X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Apr 2014 17:03:36 -0000 Author: imp Date: Fri Apr 18 17:03:35 2014 New Revision: 264657 URL: http://svnweb.freebsd.org/changeset/base/264657 Log: More properly account for free/reserved segments to avoid deadlock or worse when filling up a device and then trying to erase files to make space. Without enough space, you can't do that. Also, ensure that the metadata writes don't generate ENOSPC. They will be retried later since the buffers are still dirty... Submitted by: mjg@ Modified: head/sys/fs/nandfs/bmap.c head/sys/fs/nandfs/nandfs.h head/sys/fs/nandfs/nandfs_subr.c head/sys/fs/nandfs/nandfs_vfsops.c Modified: head/sys/fs/nandfs/bmap.c ============================================================================== --- head/sys/fs/nandfs/bmap.c Fri Apr 18 17:03:09 2014 (r264656) +++ head/sys/fs/nandfs/bmap.c Fri Apr 18 17:03:35 2014 (r264657) @@ -387,11 +387,10 @@ bmap_truncate_indirect(struct nandfs_nod if (modified) bcopy(copy, bp->b_data, fsdev->nd_blocksize); - error = nandfs_dirty_buf_meta(bp, 0); - if (error) - return (error); + /* Force success even if we can't dirty the buffer metadata when freeing space */ + nandfs_dirty_buf_meta(bp, 1); - return (error); + return (0); } int Modified: head/sys/fs/nandfs/nandfs.h ============================================================================== --- head/sys/fs/nandfs/nandfs.h Fri Apr 18 17:03:09 2014 (r264656) +++ head/sys/fs/nandfs/nandfs.h Fri Apr 18 17:03:35 2014 (r264657) @@ -200,6 +200,8 @@ struct nandfs_device { uint32_t nd_devblocksize; + uint32_t nd_segs_reserved; + /* Segment usage */ uint64_t nd_clean_segs; uint64_t *nd_free_base; Modified: head/sys/fs/nandfs/nandfs_subr.c ============================================================================== --- head/sys/fs/nandfs/nandfs_subr.c Fri Apr 18 17:03:09 2014 (r264656) +++ head/sys/fs/nandfs/nandfs_subr.c Fri Apr 18 17:03:35 2014 (r264657) @@ -910,7 +910,7 @@ nandfs_fs_full(struct nandfs_device *nff DPRINTF(BUF, ("%s: bufs:%jx space:%jx\n", __func__, (uintmax_t)nffsdev->nd_dirty_bufs, (uintmax_t)space)); - if (nffsdev->nd_dirty_bufs + (10 * bps) >= space) + if (nffsdev->nd_dirty_bufs + (nffsdev->nd_segs_reserved * bps) >= space) return (1); return (0); Modified: head/sys/fs/nandfs/nandfs_vfsops.c ============================================================================== --- head/sys/fs/nandfs/nandfs_vfsops.c Fri Apr 18 17:03:09 2014 (r264656) +++ head/sys/fs/nandfs/nandfs_vfsops.c Fri Apr 18 17:03:35 2014 (r264657) @@ -718,15 +718,24 @@ nandfs_mount_base(struct nandfs_device * nandfsdev->nd_ts.tv_sec = nandfsdev->nd_last_segsum.ss_create; nandfsdev->nd_last_cno = nandfsdev->nd_super.s_last_cno; nandfsdev->nd_fakevblk = 1; + /* + * FIXME: bogus calculation. Should use actual number of usable segments + * instead of total amount. + */ + nandfsdev->nd_segs_reserved = + nandfsdev->nd_fsdata.f_nsegments * + nandfsdev->nd_fsdata.f_r_segments_percentage / 100; nandfsdev->nd_last_ino = NANDFS_USER_INO; DPRINTF(VOLUMES, ("%s: last_pseg %#jx last_cno %#jx last_seq %#jx\n" - "fsdev: last_seg: seq %#jx num %#jx, next_seg_num %#jx\n", + "fsdev: last_seg: seq %#jx num %#jx, next_seg_num %#jx " + "segs_reserved %#jx\n", __func__, (uintmax_t)nandfsdev->nd_last_pseg, (uintmax_t)nandfsdev->nd_last_cno, (uintmax_t)nandfsdev->nd_seg_sequence, (uintmax_t)nandfsdev->nd_seg_sequence, (uintmax_t)nandfsdev->nd_seg_num, - (uintmax_t)nandfsdev->nd_next_seg_num)); + (uintmax_t)nandfsdev->nd_next_seg_num, + (uintmax_t)nandfsdev->nd_segs_reserved)); DPRINTF(VOLUMES, ("nandfs_mount: accepted super root\n"));