From 19d55079aecb5c022c1c09e0eace4f7da7381a62 Mon Sep 17 00:00:00 2001 From: Matthew Ahrens Date: Mon, 7 Jul 2014 11:49:36 -0800 Subject: Illumos 4950 - files sometimes can't be removed from a full filesystem 4950 files sometimes can't be removed from a full filesystem Reviewed by: Adam Leventhal Reviewed by: George Wilson Reviewed by: Sebastien Roy Reviewed by: Boris Protopopov Approved by: Dan McDonald References: https://www.illumos.org/issues/4950 https://github.com/illumos/illumos-gate/commit/4bb7380 Porting notes: - ZoL currently does not log discards to zvols, so the portion of this patch that modifies the discard logging to mark it as freeing space has been discarded. 2. may_delete_now had been removed from zfs_remove() in ZoL. It has been reintroduced. 3. We do not try to emulate vnodes, so the following lines are not valid on Linux: mutex_enter(&vp->v_lock); may_delete_now = vp->v_count == 1 && !vn_has_cached_data(vp); mutex_exit(&vp->v_lock); This has been replaced with: mutex_enter(&zp->z_lock); may_delete_now = atomic_read(&ip->i_count) == 1 && !(zp->z_is_mapped); mutex_exit(&zp->z_lock); Ported-by: Richard Yao Signed-off-by: Brian Behlendorf --- module/zfs/zfs_vnops.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'module/zfs/zfs_vnops.c') diff --git a/module/zfs/zfs_vnops.c b/module/zfs/zfs_vnops.c index 311613ae5..2f003de9f 100644 --- a/module/zfs/zfs_vnops.c +++ b/module/zfs/zfs_vnops.c @@ -20,7 +20,7 @@ */ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2013 by Delphix. All rights reserved. + * Copyright (c) 2012, 2015 by Delphix. All rights reserved. * Copyright 2014 Nexenta Systems, Inc. All rights reserved. * Copyright (c) 2015 by Chunwei Chen. All rights reserved. */ @@ -1525,6 +1525,7 @@ zfs_remove(struct inode *dip, char *name, cred_t *cr) uint64_t obj = 0; zfs_dirlock_t *dl; dmu_tx_t *tx; + boolean_t may_delete_now; boolean_t unlinked; uint64_t txtype; pathname_t *realnmp = NULL; @@ -1584,6 +1585,10 @@ top: dnlc_remove(dvp, name); #endif /* HAVE_DNLC */ + mutex_enter(&zp->z_lock); + may_delete_now = atomic_read(&ip->i_count) == 1 && !(zp->z_is_mapped); + mutex_exit(&zp->z_lock); + /* * We never delete the znode and always place it in the unlinked * set. The dentry cache will always hold the last reference and @@ -1609,6 +1614,14 @@ top: /* charge as an update -- would be nice not to charge at all */ dmu_tx_hold_zap(tx, zsb->z_unlinkedobj, FALSE, NULL); + /* + * Mark this transaction as typically resulting in a net free of + * space, unless object removal will be delayed indefinitely + * (due to active holds on the vnode due to the file being open). + */ + if (may_delete_now) + dmu_tx_mark_netfree(tx); + error = dmu_tx_assign(tx, waited ? TXG_WAITED : TXG_NOWAIT); if (error) { zfs_dirent_unlock(dl); -- cgit v1.2.3