From patchwork Fri May 11 20:13:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10395299 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C6A8160236 for ; Fri, 11 May 2018 20:13:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD99C28D35 for ; Fri, 11 May 2018 20:13:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B120728FB5; Fri, 11 May 2018 20:13:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03EA128D35 for ; Fri, 11 May 2018 20:13:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751747AbeEKUNy (ORCPT ); Fri, 11 May 2018 16:13:54 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:43459 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751379AbeEKUNw (ORCPT ); Fri, 11 May 2018 16:13:52 -0400 Received: by mail-pg0-f68.google.com with SMTP id k11-v6so2863508pgo.10 for ; Fri, 11 May 2018 13:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=p1Lucc1n+MElOh4EkIQfWKwOKK+N4KvwEDnVr/sS/T4=; b=nZjB3APJWtpbWkO2reA3rytLnPk3AfcFq5z8HFh9dxX9duUgVza2IPJ9ILT8Cdw6ag OWhAfi4ddVtBgYqywzDcO+0iw7wPH6KD4QkXoOxZ/gKgEQg99oJ5BqVzNFzfmG3phmmw L2H87/BOK6GWiZ84Yc/KMcfePP/ei5AL+rwy7psuXD6WGhxRzqiqNzyivx7qqLrexa7M M8mfQj05GgO7hJIMgb3mhZojOSTv9xW9RiF1SgYESvgEFmeGzb8AIvayVkvkl+xF79Oe gZPd91JgJOpjUsPBXgqIfE/V5d5tJjE/pHc6XGkrxtMT06P/YRN+9hutUNWzguqlHZXG lFag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=p1Lucc1n+MElOh4EkIQfWKwOKK+N4KvwEDnVr/sS/T4=; b=c/hEvyxbmgcUxkj/WmdOwpfzU65CExBUuSATQ8oZgGBzkdHTbNVW4yGN2kpOmloXT0 /tS3SjZhnjaq9EwVf90JCzQBqrRVxHRgJMlYqWah4qJxuv5OhpQdin/cu8f6IM/EFL+S zk2Goo8OEGnpeqhDyrjJ6urrM0mP7L0eFDQ2N7qKsOO7a1U+DLWe/YgPFusOjKFROFzP pi2EUoJpO5idDqSw3q14eXHycU05aNvR5TFAxXUuynt3s/Zf2oXDo1FKYez/Vid75cgN x0Fqz+Qllgc4ZYqN0ZGU44nuuCkVhenPdcU2iiUVzOtuFwo1nt80eAAEYnlHL570HqfG ECzw== X-Gm-Message-State: ALKqPwd6c0PW5+/4TWpeK/7MHFbalS3jW1MBJ2asiAz6zKI0WUUDYN4H 7x0nZSsi1l5xwHRtaejWV38C5QWHGek= X-Google-Smtp-Source: AB8JxZoXcdfI/WrI4Fu+xlWCsljVDu9se0YT72pdIscmyydLd/9PpjP7rLlxScVxfrfSwviZghIDXA== X-Received: by 2002:a65:640e:: with SMTP id a14-v6mr381403pgv.406.1526069631724; Fri, 11 May 2018 13:13:51 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::7:51e4]) by smtp.gmail.com with ESMTPSA id x84-v6sm10088457pfi.160.2018.05.11.13.13.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 May 2018 13:13:51 -0700 (PDT) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com, Chris Mason , Josef Bacik , Nikolay Borisov , David Sterba Subject: [PATCH v4 02/12] Btrfs: fix error handling in btrfs_truncate_inode_items() Date: Fri, 11 May 2018 13:13:30 -0700 Message-Id: <0168c4c032f7de29f971b6de6afa61f9c88e6561.1526069051.git.osandov@fb.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval btrfs_truncate_inode_items() uses two variables for error handling, ret and err. These are not handled consistently, leading to a couple of bugs. - Errors from btrfs_del_items() are handled but not propagated to the caller - If btrfs_run_delayed_refs() fails and aborts the transaction, we continue running Just use ret everywhere and simplify things a bit, fixing both of these issues. Fixes: 79787eaab461 ("btrfs: replace many BUG_ONs with proper error handling") Fixes: 1262133b8d6f ("Btrfs: account for crcs in delayed ref processing") Reviewed-by: Nikolay Borisov Signed-off-by: Omar Sandoval --- fs/btrfs/inode.c | 55 ++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 0c644ad7e1cb..bfa0e094a60e 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4442,7 +4442,6 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, int pending_del_slot = 0; int extent_type = -1; int ret; - int err = 0; u64 ino = btrfs_ino(BTRFS_I(inode)); u64 bytes_deleted = 0; bool be_nice = false; @@ -4494,22 +4493,19 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, * up a huge file in a single leaf. Most of the time that * bytes_deleted is > 0, it will be huge by the time we get here */ - if (be_nice && bytes_deleted > SZ_32M) { - if (btrfs_should_end_transaction(trans)) { - err = -EAGAIN; - goto error; - } + if (be_nice && bytes_deleted > SZ_32M && + btrfs_should_end_transaction(trans)) { + ret = -EAGAIN; + goto out; } - path->leave_spinning = 1; ret = btrfs_search_slot(trans, root, &key, path, -1, 1); - if (ret < 0) { - err = ret; + if (ret < 0) goto out; - } if (ret > 0) { + ret = 0; /* there are no items in the tree for us to truncate, we're * done */ @@ -4620,7 +4616,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, * We have to bail so the last_size is set to * just before this extent. */ - err = NEED_TRUNCATE_BLOCK; + ret = NEED_TRUNCATE_BLOCK; break; } @@ -4687,7 +4683,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, pending_del_nr); if (ret) { btrfs_abort_transaction(trans, ret); - goto error; + break; } pending_del_nr = 0; } @@ -4698,8 +4694,8 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, trans->delayed_ref_updates = 0; ret = btrfs_run_delayed_refs(trans, updates * 2); - if (ret && !err) - err = ret; + if (ret) + break; } } /* @@ -4707,8 +4703,8 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, * and let the transaction restart */ if (should_end) { - err = -EAGAIN; - goto error; + ret = -EAGAIN; + break; } goto search_again; } else { @@ -4716,32 +4712,37 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, } } out: - if (pending_del_nr) { - ret = btrfs_del_items(trans, root, path, pending_del_slot, + if (ret >= 0 && pending_del_nr) { + int err; + + err = btrfs_del_items(trans, root, path, pending_del_slot, pending_del_nr); - if (ret) - btrfs_abort_transaction(trans, ret); + if (err) { + btrfs_abort_transaction(trans, err); + ret = err; + } } -error: if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { ASSERT(last_size >= new_size); - if (!err && last_size > new_size) + if (!ret && last_size > new_size) last_size = new_size; btrfs_ordered_update_i_size(inode, last_size, NULL); } btrfs_free_path(path); - if (be_nice && bytes_deleted > SZ_32M) { + if (be_nice && bytes_deleted > SZ_32M && (ret >= 0 || ret == -EAGAIN)) { unsigned long updates = trans->delayed_ref_updates; + int err; + if (updates) { trans->delayed_ref_updates = 0; - ret = btrfs_run_delayed_refs(trans, updates * 2); - if (ret && !err) - err = ret; + err = btrfs_run_delayed_refs(trans, updates * 2); + if (err) + ret = err; } } - return err; + return ret; } /*