From 599b8648133738b524ff4c58a72fc744b62fe142 Mon Sep 17 00:00:00 2001 From: Chunwei Chen Date: Wed, 18 Apr 2018 14:19:50 -0700 Subject: Fix ENOSPC in "Handle zap_add() failures in ..." Commit cc63068 caused ENOSPC error when copy a large amount of files between two directories. The reason is that the patch limits zap leaf expansion to 2 retries, and return ENOSPC when failed. The intent for limiting retries is to prevent pointlessly growing table to max size when adding a block full of entries with same name in different case in mixed mode. However, it turns out we cannot use any limit on the retry. When we copy files from one directory in readdir order, we are copying in hash order, one leaf block at a time. Which means that if the leaf block in source directory has expanded 6 times, and you copy those entries in that block, by the time you need to expand the leaf in destination directory, you need to expand it 6 times in one go. So any limit on the retry will result in error where it shouldn't. Note that while we do use different salt for different directories, it seems that the salt/hash function doesn't provide enough randomization to the hash distance to prevent this from happening. Since cc63068 has already been reverted. This patch adds it back and removes the retry limit. Also, as it turn out, failing on zap_add() has a serious side effect for mzap_upgrade(). When upgrading from micro zap to fat zap, it will call zap_add() to transfer entries one at a time. If it hit any error halfway through, the remaining entries will be lost, causing those files to become orphan. This patch add a VERIFY to catch it. Reviewed-by: Sanjeev Bagewadi Reviewed-by: Richard Yao Reviewed-by: Tony Hutter Reviewed-by: Albert Lee Reviewed-by: Brian Behlendorf Reviewed by: Matthew Ahrens Signed-off-by: Chunwei Chen Closes #7401 Closes #7421 --- module/zfs/zap.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'module/zfs/zap.c') diff --git a/module/zfs/zap.c b/module/zfs/zap.c index 2f6aed667..d899ccdb7 100644 --- a/module/zfs/zap.c +++ b/module/zfs/zap.c @@ -852,8 +852,16 @@ retry: } else if (err == EAGAIN) { err = zap_expand_leaf(zn, l, tag, tx, &l); zap = zn->zn_zap; /* zap_expand_leaf() may change zap */ - if (err == 0) + if (err == 0) { goto retry; + } else if (err == ENOSPC) { + /* + * If we failed to expand the leaf, then bailout + * as there is no point trying + * zap_put_leaf_maybe_grow_ptrtbl(). + */ + return (err); + } } out: -- cgit v1.2.3