From patchwork Thu Jul 20 13:41:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luis Henriques X-Patchwork-Id: 123327 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3170899vqt; Thu, 20 Jul 2023 07:47:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlGCbWxQz/fNzim8KrD2FdW67d7/YntMiAy2M9tofQmpwGTd7pNKW2H9d/cEXcHrd3jhzQMv X-Received: by 2002:a17:902:b68c:b0:1b8:a389:43ef with SMTP id c12-20020a170902b68c00b001b8a38943efmr2145303pls.24.1689864461381; Thu, 20 Jul 2023 07:47:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689864461; cv=none; d=google.com; s=arc-20160816; b=yHOT085KfjEdMZrIhxv7wIvPuuPn8UQihtXhmw+YJcTzv0rg5nMdy+RVmSHKS0y9/j iqX/BkJhalCNElSCED2omm1Gvzvrn9DaTBRhlxeytEHWtEn1opDBvk79BbcZsxCPklLZ RLSJx624ZK8ZfZIxAkiRfBpEbN2m7jrjgxeD1Q+Gog2yIhEBUdHnCDFTQSigm36Z1qnc zn5Hj6yqRpzQ32nlObAnqByJIpFKKQXrWm6Es1NraKvY+O8b+6sDLkiQ5NHlvpp/3IX6 N+/tn4Gt966v2EY82/J4lUB5dsJTFWJQ16UOCAvpLeXep8GKDKn+CLnVg0MaacZOznvM UdsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=tmYRxGuocIo10P4xltez5btt1MOHtYPP9QgSYCfneJA=; fh=OuQpfXmZJYDHVkpuIAj7lb3POpelOp8wBkJmvP3qxa4=; b=N0mhQJuW9sX/qxHsbSLGxTwB5ELFUz1hG3coe+vkdG7sJKV2Y/BWHoEJfrGUsF9jFD gLkItSsdAhovULeEKu6Bjby+aaxCrBdYRQZUExMoB0pmOL4lC6lNWDrpiAy1Xe2DpcwF U3oXakqqwLzodKjcUR4CyMGcleo6OPNMQR3xM5hR1eSbxFnAyjg+Yx5bRo52HxwaP8H8 dlFUXiH5Zc+MBw4yNH62lO9a0SrYTA79UjV6VG6K3e7kZm/0tBGsuS17CwQU2zxnWa8W 0BzLxDOrPsqKC3/HlGSThYGjKGYKxHT+33rxfTUjCWgoM7u6HqrXCjJKHVNde9jdSXVP J6hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="MrU/a1rC"; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t3-20020a17090340c300b001b88997ababsi1030553pld.412.2023.07.20.07.47.27; Thu, 20 Jul 2023 07:47:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="MrU/a1rC"; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230336AbjGTNl3 (ORCPT + 99 others); Thu, 20 Jul 2023 09:41:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229927AbjGTNl1 (ORCPT ); Thu, 20 Jul 2023 09:41:27 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CBA91986; Thu, 20 Jul 2023 06:41:26 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9D27821C27; Thu, 20 Jul 2023 13:41:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1689860485; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=tmYRxGuocIo10P4xltez5btt1MOHtYPP9QgSYCfneJA=; b=MrU/a1rCHZDdoSg3U6X5LnqvXNIb58Spqw7w0jpBsLPHZKHlKHbPVj6conmj0vfxm58ukj gYPpypJjBA4nMrq1Wvq4Q+CXi+k0MLTqdJeiRiQCZY3a1zmqcNia13hd4MtWVwiVwUOPqN xoMGPHhAPbWpxgWMUtOTPvUVMoBhpOI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1689860485; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=tmYRxGuocIo10P4xltez5btt1MOHtYPP9QgSYCfneJA=; b=2o+IogIYWgNcFO4znAxvrS8NZrdqlVS2r9MJejKoFMiAt5VvRTdWtJ/ZopVTorreR+kOXZ Az1jNFA8wpYis3AA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2751B133DD; Thu, 20 Jul 2023 13:41:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id EZrsBYU5uWTSVwAAMHmgww (envelope-from ); Thu, 20 Jul 2023 13:41:25 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id 41c3dcbc; Thu, 20 Jul 2023 13:41:24 +0000 (UTC) From: =?utf-8?q?Lu=C3=ADs_Henriques?= To: Chris Mason , Josef Bacik , David Sterba , Johannes Thumshirn Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Lu?= =?utf-8?q?=C3=ADs_Henriques?= Subject: [PATCH v2] btrfs: propagate error from function unpin_extent_cache() Date: Thu, 20 Jul 2023 14:41:23 +0100 Message-Id: <20230720134123.13148-1-lhenriques@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771951317665621709 X-GMAIL-MSGID: 1771951317665621709 Function unpin_extent_cache() doesn't propagate an error if the call to lookup_extent_mapping() fails. This patch adds an error return (EINVAL) and simply logs it in the only caller. Signed-off-by: Luís Henriques --- Hi! As per David and Johannes reviews, I'm now proposing a different approach. Note that I kept the WARN_ON() instead of replacing it by an ASSERT(). In fact, I considered removing the WARN_ON() completely and simply return the error if em->start != start. But I guess it may useful for debug. Changes since v1: Instead of changing unpin_extent_cache() into a void function, make it propage an error code instead. fs/btrfs/extent_map.c | 4 +++- fs/btrfs/inode.c | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c index 0cdb3e86f29b..f4e7956edc05 100644 --- a/fs/btrfs/extent_map.c +++ b/fs/btrfs/extent_map.c @@ -304,8 +304,10 @@ int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len, WARN_ON(!em || em->start != start); - if (!em) + if (!em) { + ret = -EINVAL; goto out; + } em->generation = gen; clear_bit(EXTENT_FLAG_PINNED, &em->flags); diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index dbbb67293e34..21eb66fcc0df 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -3273,8 +3273,12 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent) ordered_extent->disk_num_bytes); } } - unpin_extent_cache(&inode->extent_tree, ordered_extent->file_offset, - ordered_extent->num_bytes, trans->transid); + + /* Proceed even if we fail to unpin extent from cache */ + if (unpin_extent_cache(&inode->extent_tree, ordered_extent->file_offset, + ordered_extent->num_bytes, trans->transid) < 0) + btrfs_warn(fs_info, "failed to unpin extent from cache"); + if (ret < 0) { btrfs_abort_transaction(trans, ret); goto out;