From: Omar Sandoval <osan...@fb.com> Jun Wu at Facebook reported that an internal service was seeing a return value of 1 from ftruncate() on Btrfs in some cases. This is coming from the NEED_TRUNCATE_BLOCK return value from btrfs_truncate_inode_items().
btrfs_truncate() uses two variables for error handling, ret and err. When btrfs_truncate_inode_items() returns non-zero, we set err to the return value. However, NEED_TRUNCATE_BLOCK is not an error. Make sure we only set err if ret is an error (i.e., negative). Fixes: ddfae63cc8e0 ("btrfs: move btrfs_truncate_block out of trans handle") Reported-by: Jun Wu <qu...@fb.com> Cc: sta...@vger.kernel.org Signed-off-by: Omar Sandoval <osan...@fb.com> --- This version makes the minimal fix which should be good for v4.17 and stable. I'll submit a cleanup separately. fs/btrfs/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index d241285a0d2a..f276da70f659 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -9117,7 +9117,8 @@ static int btrfs_truncate(struct inode *inode, bool skip_writeback) BTRFS_EXTENT_DATA_KEY); trans->block_rsv = &fs_info->trans_block_rsv; if (ret != -ENOSPC && ret != -EAGAIN) { - err = ret; + if (ret < 0) + err = ret; break; } -- 2.17.0 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html