Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1136pxb; Tue, 19 Jan 2021 22:59:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5NwtRqQi0+pypCsyp1W+Mt51OSBocaeKYpJoWFH+K0+M0e4H6u5CLNAxSGvHu8cY6adY0 X-Received: by 2002:a17:906:1d5a:: with SMTP id o26mr5322692ejh.301.1611125989553; Tue, 19 Jan 2021 22:59:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611125989; cv=none; d=google.com; s=arc-20160816; b=iOm0RzVCnDMW9wF3c7e6yszqhuTKQsOrfrcF9hfPqnEeym2gTi7PO1uZE9v3Ffwico yomSneo1Mq9sMn1pUJAjoE7DV/ZBhq+wiuS2LnvvQkmO6QbGr2T4/qaaMaOy97CIDCse wqdpVNnwyHL/gh4YjYbfFX76k+Qi7kYRB54n7cTcZmbj+9X6pha3/Bb6kwwzw27ihTLB wAFyqfMloBqXJVYGvcwTd08rVubC12WbntxUelqu33w6JsymEdd/1irgBjMJW47oQCUz IODKqdi7AeWN6ipwvHRubO7xm3KcEqeODK5JZA2HorahNnYLbBRye/eW3DZ14Wa2aPyE 3VfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=8Bzkf7Ld2rxa9FcnXEU6RIP9KlVPZQPWVVVy1sBXrxc=; b=PZCdqITreC+EvOeDRkNCTg3J5q/1kq9eHBQ8w61Tn7ETN2AaLqJzBGK39qNaltvGES SxGPgGaFPsfZDk7Kd/ikSidgezBAQGmd7AD+MIVJnTSxm+jaugs+WI3PCPg4aizb8BgU OFZoOBF78Yw+msuHbCoE4ZfusUkiCfkL/TK8Y+ZNLs2OLlPhD8pxOay2sB7zOomv89C2 z/1bT5yKg042xMsXBiWmSC7bIhl+O+TGXzjLTPhMl97Iab9TW1eI/VLgk9WP5OWVTKQ2 MbbS1xAkizOIuTFqJTqV5XuPasP7JSftjBfsCh+yOkf1HriIkX5wsJLo6WYwoyQN2G3o Y67g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=D6owGlKu; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h18si516534edv.41.2021.01.19.22.59.00; Tue, 19 Jan 2021 22:59:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=D6owGlKu; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726683AbhATG61 (ORCPT + 99 others); Wed, 20 Jan 2021 01:58:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725827AbhATG6U (ORCPT ); Wed, 20 Jan 2021 01:58:20 -0500 Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9CCAC061575; Tue, 19 Jan 2021 22:57:39 -0800 (PST) Received: by mail-io1-xd34.google.com with SMTP id p72so20149462iod.12; Tue, 19 Jan 2021 22:57:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8Bzkf7Ld2rxa9FcnXEU6RIP9KlVPZQPWVVVy1sBXrxc=; b=D6owGlKuLWuHRp6fVEbwbq/7wQS31AaZL+rfslaqriM91tGkiPPt+U83dCNDagIo1E XC1cJUdLxIwtPrZkd++CRg9NhTLlF5gAZ8Uy7Zt/FZmLz84yCtH+z+J400cosgm9swG9 bH+m52U+YKVuFJ4fO+bhJI3iTdr+3Rv4Jl+l2x2g+yD8XZhmGbjT+dDIx3j9R/FyRQbd SIQv0OvdqsbhAKPJ7vpvfRX8cuK7p454226X3OoIl3UHaWEPmGqqEtqDY+J3LHcdVJgo i62imdLUTtFI/X3tgtQVs7/ufkuL8LHEhXgh1Ix5K9bCPCw51W5w169V+nUHXmUysFPV Tc0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8Bzkf7Ld2rxa9FcnXEU6RIP9KlVPZQPWVVVy1sBXrxc=; b=XmsXIIA5EYVqUycJFYdFSXGsAjoHRRjnsH+oJAFFui1LFnU7kPbLKsslRkr+HQgx61 VFo13FtU6+BN/2ClGyuF2a0yKjWIRYdJjA1WX/O5PQjEk5XSkEXuV8b1P0zIGKNZPYBo DQNzj01vWrgWeM6/vlRtR/jq8D0NsMm7InD5cX6TlzZwrezu/+pORhZkwDYZ/aYMWsVF 3XWp3lRU7fIrKOC4xgW6AAp3F5xxam889gVqIfRI7XWDbzqjndzXebS+48Zl28s/ADR3 VoFRF5FjdO8QzpeH1X6DC09dQsVMVq/E8mOLvMCEsIjhEuKQCmgZiDJFgpIxQ5F5H0vO mZmg== X-Gm-Message-State: AOAM5302705afKx3xg0SkfqfsjQAAXe1jq1j2CA8Lqt2jNOpYzv/Jx7D yxZUYp6AJi8+4/oUjSCKkfCaWtFEoN6PVtfVUy8= X-Received: by 2002:a02:b0dc:: with SMTP id w28mr6527528jah.123.1611125859315; Tue, 19 Jan 2021 22:57:39 -0800 (PST) MIME-Version: 1.0 References: <20210105062857.3566-1-yangerkun@huawei.com> In-Reply-To: From: Amir Goldstein Date: Wed, 20 Jan 2021 08:57:28 +0200 Message-ID: Subject: Re: [PATCH v3] ext4: fix bug for rename with RENAME_WHITEOUT To: "Theodore Ts'o" , harshad shirwadkar Cc: yangerkun , Ext4 , Andreas Dilger , Jan Kara , "zhangyi (F)" , lihaotian9@huawei.com, lutianxiong@huawei.com, linfeilong@huawei.com, fstests , Miklos Szeredi , Vijaychidambaram Velayudhan Pillai Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Thu, Jan 14, 2021 at 5:53 AM Theodore Ts'o wrote: > > On Tue, Jan 05, 2021 at 02:28:57PM +0800, yangerkun wrote: > > We got a "deleted inode referenced" warning cross our fsstress test. The > > bug can be reproduced easily with following steps: > > > > cd /dev/shm > > mkdir test/ > > fallocate -l 128M img > > mkfs.ext4 -b 1024 img > > mount img test/ > > dd if=/dev/zero of=test/foo bs=1M count=128 > > mkdir test/dir/ && cd test/dir/ > > for ((i=0;i<1000;i++)); do touch file$i; done # consume all block > > cd ~ && renameat2(AT_FDCWD, /dev/shm/test/dir/file1, AT_FDCWD, > > /dev/shm/test/dir/dst_file, RENAME_WHITEOUT) # ext4_add_entry in > > ext4_rename will return ENOSPC!! > > cd /dev/shm/ && umount test/ && mount img test/ && ls -li test/dir/file1 > > We will get the output: > > "ls: cannot access 'test/dir/file1': Structure needs cleaning" > > and the dmesg show: > > "EXT4-fs error (device loop0): ext4_lookup:1626: inode #2049: comm ls: > > deleted inode referenced: 139" > > > > ext4_rename will create a special inode for whiteout and use this 'ino' > > to replace the source file's dir entry 'ino'. Once error happens > > latter(the error above was the ENOSPC return from ext4_add_entry in > > ext4_rename since all space has been consumed), the cleanup do drop the > > nlink for whiteout, but forget to restore 'ino' with source file. This > > will trigger the bug describle as above. > > > > Signed-off-by: yangerkun > Apropos RENAME_WHITEOUT, it seems to be missing __ext4_fc_track_link(). I guess test coverage of RENAME_WHITEOUT in fstests is not much. I have been seeing trickles of bug fixes for RENAME_WHITEOUT for almost every filesystem that supports it. But I must say it would have been very hard to catch missing ext4_fc_track_* without specialized fs fuzzer such as the CrashMonkey generated tests. And as long as I am ranting, I'd like to point out that it is a shame that whiteout was not implemented as a special (constant) inode whose nlink is irrelevant (or a special dirent with d_ino 0 and d_type DT_WHT for that matter). It would have been a rather small RO_COMPAT on-disk change for ext4. It could also be implemented in slightly more backward compat manner by maintaining a valid nlink and postpone setting the RO_COMPAT flag until EXT4_LINK_MAX is reached. As things stand now, overlayfs makes an effort to maintain a singleton hardlinked whiteout inode, without being able to use it with RENAME_WHITEOUT and filesystems have to take special care to journal the metadata of all individual whiteout inodes, without any added value to the only user (overlayfs). But I guess that train has left the station long ago... Thanks, Amir.