Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp9785959rwp; Thu, 20 Jul 2023 09:37:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlFPU/sNdxdrUwThV5qedBJjGyrmEMIkn+JhEfC/Wkrt98/rLh9thm5Qs+SjxpzmNh7BE0bM X-Received: by 2002:a17:907:90d5:b0:988:4dc:e3a3 with SMTP id gk21-20020a17090790d500b0098804dce3a3mr4511687ejb.31.1689871043309; Thu, 20 Jul 2023 09:37:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689871043; cv=none; d=google.com; s=arc-20160816; b=h0wp5q+Y0T+E2X76+YDfr+32RAOWrdMWz2rxM4gcDQFjXShRIi5wcDPLjhMYDFU5or HCk+/AYOxCIQozBVUIDvAzeD5pDT41+6kyZXbmRQw2qCc/7l8wuysQ/N0Onntrgqv8Jj Pk2KQa8V4Qkvepk8UMdfHWLIFCcYLStyzhODNzV3mglyNgKqXPj8+bp/p3I3Wwcj/IgQ 5Cy03sFuSNyWOvluqaklaAUdWhbYsDnBskaHZ7ar+G2bwwtzwGsZ98xanelVeyb89kjz uTuPSBjQmxIkuC6Pd8VAgde/tyx8eHKFPNfSh4NOG9zdE6WwMikaeyxT+0zEPjlLBFij Z9JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=qQk69QcKebh3AYRaklDCEVb9jpq4SAjppM4CFe90Odw=; fh=0GRCLGOnj2xEcRsAbu3tzoaAu0If35nXhl2mmTLQU3A=; b=Ii7Jncf2b0cM6kIPMt/sbfF/GdFUBUkr0YSoGmuo0R2WMUg/zK2GCZ+ptOK6RKQvQD BnBN5YC9icVMvs96B1F7/ZADjDWVWGwWmFRn1LOvBkDeIigb3NaNig1vke3JKnSwg/vL 67vFDuT3cFch4O/ycLYox7cLfTNLa5CEj6S6987JhDUSquMsCtaM725DTt6wvggBgAGs ZyKt44uwaKXGb+FApSrjMlwAkXff+3np28lQ5ffLCsVdDtj4o3jJwEzXFE4XRLvZtBQt 5xEMRY7EjTL+EeO+TwI7l3jiirPDAvW+bLjudnvATepGZ/YCe2KPLPg040iNDZqCo3wj sZQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZDJHFFIU; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v21-20020a1709060b5500b00992e50eafcfsi877739ejg.772.2023.07.20.09.36.58; Thu, 20 Jul 2023 09:37:23 -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=@kernel.org header.s=k20201202 header.b=ZDJHFFIU; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229809AbjGTQQA (ORCPT + 99 others); Thu, 20 Jul 2023 12:16:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbjGTQPx (ORCPT ); Thu, 20 Jul 2023 12:15:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC57910D2; Thu, 20 Jul 2023 09:15:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 506ED61B50; Thu, 20 Jul 2023 16:15:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8DA7C433CB; Thu, 20 Jul 2023 16:15:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689869750; bh=TPAunApq8i+SUaaLwE46mDZ/trLDSerwE/ZkljV1r8k=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ZDJHFFIUC34apAn8IgrUn1PPm61Jv6ZFkvi0V9I53Tp94QK90+YfXJ54x3zJ/8TRA tnwnPOJRItt/3M+BqVVgpWd0b5EgYrW0/OvuQ0KF1sLc385RNNH2mb5PkrcVwxRzF+ l3hCIku24/+eGUIu0YtJWYDGAm8mU1vKpRSjcAb5/6dwBW8kRPKs8EqdoldtRgZMA8 dUO67b/CVAZCWFVwWJBCphX5xU7hrsXm/lP0vo+z+qpi1XdC5esXBxZBNFq4H9+jDr t5jibgRKeqheE2Kx09vOOM3yPQSocBYmpcSYbSIT+uVUhcRGOWlBUN/ybFRf32CcON 0cF5jtRCRd+CA== Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-1b06777596cso733111fac.2; Thu, 20 Jul 2023 09:15:50 -0700 (PDT) X-Gm-Message-State: ABy/qLZ2A+jHbaqN2d9xKHUj5sRgcAV5snYjq3NiCeNO9l3L3I1SkBiH 91IAfYQTthIUAsfr5yMSLD+yRRaD1iqi1MYxqrw= X-Received: by 2002:a05:6870:3929:b0:1ba:989b:ca65 with SMTP id b41-20020a056870392900b001ba989bca65mr2442801oap.19.1689869749868; Thu, 20 Jul 2023 09:15:49 -0700 (PDT) MIME-Version: 1.0 References: <20230720134123.13148-1-lhenriques@suse.de> In-Reply-To: <20230720134123.13148-1-lhenriques@suse.de> From: Filipe Manana Date: Thu, 20 Jul 2023 17:15:13 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] btrfs: propagate error from function unpin_extent_cache() To: =?UTF-8?Q?Lu=C3=ADs_Henriques?= Cc: Chris Mason , Josef Bacik , David Sterba , Johannes Thumshirn , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 On Thu, Jul 20, 2023 at 5:05=E2=80=AFPM Lu=C3=ADs Henriques wrote: > > 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=C3=ADs 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(). I= n > fact, I considered removing the WARN_ON() completely and simply return th= e > error if em->start !=3D 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 !=3D start); > > - if (!em) > + if (!em) { > + ret =3D -EINVAL; > goto out; > + } > > em->generation =3D 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_offs= et, > - 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"); Well, this is not very useful. It doesn't provide any more useful information than what we get from the WARN_ON() at unpin_extent_cache(), making the patch not useful. This warning has actually happened a few times when running fstests that exercise relocation (not sure if it's gone and accidently fixed by something recently). But to make this more useful, I would place the message at unpin_extent_cache() with useful information such as: - inode number - id of the root the inode belongs to - the file offset (the start argument) and extent length (or end offset) - why the warning triggered: we didn't find the extent map or we found one with a different start offset - if we found an unexpected extent map, dump its flags (so we can see if it happens only with compressed or prealloc extents for e.g.) and other details (length/end offset for e.g.) Thanks. > + > if (ret < 0) { > btrfs_abort_transaction(trans, ret); > goto out;