Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp10648496rwp; Fri, 21 Jul 2023 02:41:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlEdP2gcWoe0bOmcOSx+7BhhF8gHu702fWRzWHFpZBiefjBFRl9JyCM+LYvTfWb/WdICWhNW X-Received: by 2002:a17:906:58d4:b0:988:565f:bf46 with SMTP id e20-20020a17090658d400b00988565fbf46mr8308145ejs.32.1689932479607; Fri, 21 Jul 2023 02:41:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689932479; cv=none; d=google.com; s=arc-20160816; b=nctSqUEG/MaWdwjJkcCJeHp3oM+IXX/oUfO9YHntRXN28uynVzlhUoNQyN3PBZYhCD bEi7asZkNR0LjaWyNQ/oYw+3Lin8maaFV1BueBfrNLnw9WZxJRznwQKsLIDy4x9xtRrv whx9Jrtu20v5prY/cUROWJgugdrkpZjwu5nIlGcwpOrREbd0y9Hoc1P7TaEUbNTc8EeY NspXCrGg9oyne+tHrXAnMkqB2Mb0LAC3eID0jhvyqB1x8SX/6ZK7eVuK0nsl/uZ/JTpq vEoUb3G0OS/1CB3NH2zNa+lZA1KuPSAMNxVYLCqEYOoxOOJ646YuqiKQqctvDhL3kZaq Jyiw== 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:in-reply-to:date:references:subject:cc:to:from :dkim-signature:dkim-signature; bh=qVcf7rz5f+9m6sax0l/1jeoGOzJiq/lgITLiq23Ep8I=; fh=MvUiUR3NPOnlwiKGyyVSnMXHA7sqny55W9kwZiSqdIk=; b=OzbvhxJ8b90saIKDieAbREodN65p1OjsTrN0PbZKYRxoOuccvn44ffTaBPnxgSHX7q TXqzICnzUc9EDuiTuTVCJxYLwMG5R/Y/egKl3XjIRC7QMicYPXU3JtJWwmGiD1YNLx6w p2r9RdLaN7OtTen7oKuOzSbcN8bXi6C41hstKkIJXA8/ANglYW9A9m8F/P856ZmEK+ZR BKk0DjzGwLBN7RJw406wQLrEV5Cb4a/ikGIid8Feom88TciVzqlXJbEfwO41s/f6UnLH J6kpXa2BQ658AzuNQCx27OTS4DVNynzth1BM+sguvvzQeySwNDnrmnz6hHrZpZo59V0q fuIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=YjgTefls; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h11-20020a17090634cb00b00988e62b24ecsi1777529ejb.760.2023.07.21.02.40.55; Fri, 21 Jul 2023 02:41:19 -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=YjgTefls; 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 S230481AbjGUJCc (ORCPT + 99 others); Fri, 21 Jul 2023 05:02:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229711AbjGUJCa (ORCPT ); Fri, 21 Jul 2023 05:02:30 -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 C80C62D4B; Fri, 21 Jul 2023 02:02:28 -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 75DB921979; Fri, 21 Jul 2023 09:02:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1689930147; 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: in-reply-to:in-reply-to:references:references; bh=qVcf7rz5f+9m6sax0l/1jeoGOzJiq/lgITLiq23Ep8I=; b=YjgTeflsWpVpeDGeqjDN1A1y/XFatnIBbOINNpk6SnD8DIOWAXKO7ofjWUUm4XaMZA/fAZ TFqUUrPK6Ug86vItsxn73no0E+JVPX1AScMXt8WsrUah+Z9YilK3lujTM8qjgQaKU8eKrH R77iM7kuonJstc6Vo2izWW/uVyNEb7M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1689930147; 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: in-reply-to:in-reply-to:references:references; bh=qVcf7rz5f+9m6sax0l/1jeoGOzJiq/lgITLiq23Ep8I=; b=Hi8StsxebSUS3i28sfFufYxpzMBJxd2okPmcyNY7kl6GnLDoWTLkV6rrBYCVZWS1XdVdU2 igjm8HkdwAcVwpDg== 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 E8E17134B0; Fri, 21 Jul 2023 09:02:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id rsTANaJJumTeZAAAMHmgww (envelope-from ); Fri, 21 Jul 2023 09:02:26 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id a18f298f; Fri, 21 Jul 2023 09:02:24 +0000 (UTC) From: =?utf-8?Q?Lu=C3=ADs_Henriques?= To: Filipe Manana Cc: Chris Mason , Josef Bacik , David Sterba , Johannes Thumshirn , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] btrfs: propagate error from function unpin_extent_cache() References: <20230720134123.13148-1-lhenriques@suse.de> Date: Fri, 21 Jul 2023 10:02:24 +0100 In-Reply-To: (Filipe Manana's message of "Thu, 20 Jul 2023 17:15:13 +0100") Message-ID: <874jlx1vtr.fsf@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Filipe Manana writes: > 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 approac= h. >> 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 t= he >> 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_off= set, >> - 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). Oh! In that case replacing the WARN_ON() by an ASSERT() would have definitely be a bad idea. > 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, Filipe. This all makes sense. And in this case I guess I should go back to the initial approach of changing the function to a void function, but adding all this useful information. Cheers, --=20 Lu=C3=ADs