Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp10247908pxu; Tue, 29 Dec 2020 19:31:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJyTV3lYBpwpTKdCf9r3bAXjUnV8IfCTihjze8NSqHu1KzfvZOB4wSR2wfaQu8Us7K/BCZ+2 X-Received: by 2002:aa7:d9c1:: with SMTP id v1mr49199972eds.115.1609299084887; Tue, 29 Dec 2020 19:31:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609299084; cv=none; d=google.com; s=arc-20160816; b=nP7bddsTupEBcQC3LcP62ACkwqqN2+NYlK/k14Z4hg9jMUEqleR/bWaoyQ8Kiftbai b6bOIq9ZajtG1TpukVLJIw3tEPqlwtjNZBD8zUvOWZ1cC6Y+u6gL43dYD3BL77I9sfKa t1gfi2TBJzYV5JDyW/bON0UYqVqEntx7IrfpuwKAcE1BJF88DfAOa8hphwjpHlC28i25 wEXUfiY1LJ/qQBJAewHa02N0VjgMCOIi8CuSCkEJLhUOgfj0Euusl7jpfH6Wicjcpg5B 36ww4le4E3HXhxcBL2np4/Y4D/OvbAW09BYOFK+V0RZcflPUHs12y/mpB6ot1hlhWuPu 9cRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=ciafHl7kOnysfiZUDnLjdPPs82VFam/1FAWuGVwPThU=; b=fwlCgH/5W9S0DcmbGe7yD+6NdRaAB1ypXvI8IOUVEOeBpN5gycYGLT6dM2m/kfsdJZ qabdhI+PrORQzaDCyTzfM3z5sR1MWWRdTSLFi5dyo2QDVYLKpVKpi6nDoGnPScarCQSQ 4uArvejUChmEzXeQvw+eOn5smIVGQejluKnC31Hh/kzmV9qFWH4/eAlyRq0GasP1CGwZ eDxehxCrj5crChnsWelJLwrIUfGBhhkcFY4+Lk2+pPwDDvzd9D9YKESmt7RdEMyJe0S/ OmBtdB4Dk0Pd9483zVOSkqvqY0y18Oys1FS+WalbOwsdGmZC4gsOrAm4BpLf9XRGnaV8 GPMA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x59si22939126edc.544.2020.12.29.19.30.49; Tue, 29 Dec 2020 19:31:24 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726144AbgL3DaH (ORCPT + 99 others); Tue, 29 Dec 2020 22:30:07 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:10096 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726138AbgL3DaH (ORCPT ); Tue, 29 Dec 2020 22:30:07 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4D5Gvp10zMzMBhj; Wed, 30 Dec 2020 11:28:22 +0800 (CST) Received: from [10.174.179.106] (10.174.179.106) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Wed, 30 Dec 2020 11:29:15 +0800 Subject: Re: [PATCH v2] ext4: fix bug for rename with RENAME_WHITEOUT To: Theodore Ts'o CC: , , , , , , References: <20201229090208.1113218-1-yangerkun@huawei.com> From: yangerkun Message-ID: <867df7f3-ac50-11ab-7531-59a95b4cd55b@huawei.com> Date: Wed, 30 Dec 2020 11:29:14 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.106] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org ?? 2020/12/30 6:24, Theodore Ts'o ะด??: > On Tue, Dec 29, 2020 at 05:02:08PM +0800, yangerkun wrote: >> 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(small ext4 img, and consume all space, so the rename with dst >> path not exist will fail due to the ENOSPC return from ext4_add_entry in >> ext4_rename), the cleanup do drop the nlink for whiteout, but forget to >> restore 'ino' with source file. This will lead to "deleted inode >> referenced". > > Could you sendhave instructions how to reproduce this failure? Many thanks!! Hi, Follow step will reproduce it easily! 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/ && 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" static int ext4_rename(...) { ... whiteout = ext4_whiteout_for_rename(&old, credits, &handle); ... retval = ext4_setent(handle, &old, whiteout->i_ino, EXT4_FT_CHRDEV); // will replace dir entry with ... if (!new.bh) { retval = ext4_add_entry(handle, new.dentry, old.inode); // will fail with ENOSPC if (retval) goto end_rename; ... end_rename: ... if (whiteout) { // forget to restore the dir entry's ino if (retval) drop_nlink(whiteout); unlock_new_inode(whiteout); iput(whiteout); } ... } Thanks, Kun. > > - Ted > . >