Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp503310rdb; Tue, 19 Sep 2023 01:45:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEoxbxcdWCvzy4N1kBZA+mp4XyTSpL5YTIkmCsKiamNfxS6vH1+v4/C+zz0zfYMzy9u8Tqq X-Received: by 2002:a05:6a00:b4b:b0:68f:c261:ddfe with SMTP id p11-20020a056a000b4b00b0068fc261ddfemr11373330pfo.28.1695113152536; Tue, 19 Sep 2023 01:45:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695113152; cv=none; d=google.com; s=arc-20160816; b=po+yMlupc6PUNf3wMwYegSZOfeGRMdrZckJBTMuUC+0q8tEE9HzLHpWFvhsfbw3WHb DYWq0GNYEJNDs5MIrYEwmYqFg/EoxU5yIcICKSxSF/3RvJelg0ZDOVE9Ip5R0CnDdViZ bFuQzpleEPZ9AYCfVyABqEUBuXU75GgQ7RBp7Ob3R38mk7ONhqz7E3oCIkoKWf6J13Et GgB46Vz7U7u7QXYtdVNVhST+d5ReYJmPA9hjCXa6yk1FiZLawFh8ryICsymt1g8I9XHo CH5nYwqBhVHrWzDjgj8x0XGTIlD58k7cFaQq5+5nKeyYsbcu3FjTNe+lwO+C0ouWN8v1 RRgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=1qyLoA8TT0bit01uyUmgXDLI8KadydZDu/PI6xCrN/Q=; fh=btZ+eXd4/B+k0aLQGXrnrfsFmqhObyZ5fz+IgVc1gkM=; b=cRJPX0dbpnSsiAk31s75bvBMhzAsBhJydJTm3MyYjLwvQ5DuCe+B74OxdpsDscl1MT XwRrLeD4qQlW/eHu6Qf/dF8EpREZd7e8eBKGCw68z0BImXCBmdHfT51hxeW193wI3zCV FqPxQL9Vb+UgiUBahv6Lf4B6jqlIeEIeRfpbkxhBmPkam3VCssHYdU1CK4fWZu09bNmW o4ROYUXecxKg/3UIwfZ/t05mg6wIGRMEYc6ukWUn+5SRuESIvnncfsQtLUtuyZGbnEnS BB1RJuOipMf5ANHxzAwO/vNeWduY1U5aopyTuqwyvURgrnqoGxQGvic2U+iFq2LuNTVy sOXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fromorbit-com.20230601.gappssmtp.com header.s=20230601 header.b=D5U1Iqq0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=fromorbit.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id bs65-20020a632844000000b005780c629ec8si8180827pgb.617.2023.09.19.01.45.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 01:45:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@fromorbit-com.20230601.gappssmtp.com header.s=20230601 header.b=D5U1Iqq0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=fromorbit.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id D781E84AC674; Sun, 17 Sep 2023 15:49:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237977AbjIQWqw (ORCPT + 99 others); Sun, 17 Sep 2023 18:46:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239627AbjIQWqY (ORCPT ); Sun, 17 Sep 2023 18:46:24 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4D43CFD for ; Sun, 17 Sep 2023 15:44:55 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1c43fe0c0bfso12647165ad.1 for ; Sun, 17 Sep 2023 15:44:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fromorbit-com.20230601.gappssmtp.com; s=20230601; t=1694990695; x=1695595495; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=1qyLoA8TT0bit01uyUmgXDLI8KadydZDu/PI6xCrN/Q=; b=D5U1Iqq0kZyoDMADIN6UnnxeUHZBU0TK+zLoYnULYfQwTs67Bx3SnTLbmtvLJetXfB 7PMnvR96paGgA/48BoW+yZrgEr/hKWDtDOdsnwa0Pbl14U5Qp3EKXvDj3jfPZlWU3+PF zJtetdK7vPZEPJ9cn0DfNb4u2bV/Qodjt8KIBmJcO8TTZ6OV4ScUMYqP9fhYXArY4jQq cKDOmwZOdj+UEEu2PFMSzKN9KQ0oPlg+U7472X9iowox2+RoqyQxw153PGxY8lkaUBDe eWjcvL5W+tjqMyzEkDsPU4n1jFhr4IUxIji5EmGxw/ouD1dBB+0Bh7Ew/IAzG1d8ffSa Zi9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694990695; x=1695595495; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=1qyLoA8TT0bit01uyUmgXDLI8KadydZDu/PI6xCrN/Q=; b=cVDHsyfaEhlmSOtSXwVsiJnusoq3Z9QJ6dvDaVqZgUjNX4jK1iX2YwK0s0ps5jpkuF OoJA83PtKao2Tz+HoqR1Bh0ncjAwnRxIBRkQKOTIE0LPnyoJMWLrM9I9rEHSSzfZdt4e BnbQtdGvPRrKgYC2jl4YHq95nlOLBFQxCBGLepN+K+sr7CdySzpGEM3oDnUMrB66qLaS bcVFatPXyzEo/RNdMy26uuC4dp0ZgVNUIsAQTjWnZNkd4rupUGzcT5MICFw61c2k440H dxbXwa7wTnUdpD3ba9dpEAlFdVVaNFVX4ulaZCH1pGL31u8Pmxnmkl3GLJcDuVPInqXC JVIQ== X-Gm-Message-State: AOJu0Yylogzvf+TSuV0zoQlomeXcyho/Xq6UHhq0WAaw2gDZhQ7aA9Pl 3g92JiXWJYGmlEB/pr9uxLX60Q== X-Received: by 2002:a17:903:2643:b0:1bf:703d:cc6b with SMTP id je3-20020a170903264300b001bf703dcc6bmr5214643plb.10.1694990695330; Sun, 17 Sep 2023 15:44:55 -0700 (PDT) Received: from dread.disaster.area (pa49-180-20-59.pa.nsw.optusnet.com.au. [49.180.20.59]) by smtp.gmail.com with ESMTPSA id y1-20020a170902ed4100b001c446f12973sm3778194plb.203.2023.09.17.15.44.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Sep 2023 15:44:54 -0700 (PDT) Received: from dave by dread.disaster.area with local (Exim 4.96) (envelope-from ) id 1qi0VX-00267d-35; Mon, 18 Sep 2023 08:44:51 +1000 Date: Mon, 18 Sep 2023 08:44:51 +1000 From: Dave Chinner To: cheng.lin130@zte.com.cn Cc: djwong@kernel.org, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, jiang.yong5@zte.com.cn, wang.liang82@zte.com.cn, liu.dong3@zte.com.cn Subject: Re: [PATCH v3] xfs: introduce protection for drop nlink Message-ID: References: <202309151750563356840@zte.com.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202309151750563356840@zte.com.cn> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Sun, 17 Sep 2023 15:49:32 -0700 (PDT) On Fri, Sep 15, 2023 at 05:50:56PM +0800, cheng.lin130@zte.com.cn wrote: > > On Wed, Sep 13, 2023 at 05:44:45PM +0800, cheng.lin130@zte.com.cn wrote: > > > From: Cheng Lin > > > > > > When abnormal drop_nlink are detected on the inode, > > > shutdown filesystem, to avoid corruption propagation. > > > > > > Signed-off-by: Cheng Lin > > > --- > > > fs/xfs/xfs_inode.c | 9 +++++++++ > > > 1 file changed, 9 insertions(+) > > > > > > diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c > > > index 9e62cc500..40cc106ae 100644 > > > --- a/fs/xfs/xfs_inode.c > > > +++ b/fs/xfs/xfs_inode.c > > > @@ -919,6 +919,15 @@ xfs_droplink( > > > xfs_trans_t *tp, > > > xfs_inode_t *ip) > > > { > > > + > > > + if (VFS_I(ip)->i_nlink == 0) { > > > + xfs_alert(ip->i_mount, > > > + "%s: Deleting inode %llu with no links.", > > > + __func__, ip->i_ino); > > > + tp->t_flags |= XFS_TRANS_DIRTY; > > Marking the transaction dirty is not necessary. > > Otherwise this seems fine. > Another strategy: > Set nlink to an invalid value(like XFS_NLINK_PINNED), and > Complete this transaction before shutdown fs. To make sure > nlink not be zero. If the nlink of a directory are zero, it may > be cleaned up. > Is that appropriate? No, all I'm asking you to do is drop dirtying of the transaction from this patch because it is a) unnecessary and b) a layering violation. It is unnecessary because the transaction will almost always be dirty before we get to xfs_droplink(). In the cases where it isn't dirty (e.g. xfs_remove() on a directory) we explicitly check that nlink == 2 before proceeding to call xfs_droplink(). Hence we can't actually get to xfs_droplink() with a clean transaction, and so marking it dirty here on underrun is unnecessary as returning an error from xfs_droplink() will result in shutting down the filesystem when the transaction is cancelled. -Dave. -- Dave Chinner david@fromorbit.com