Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp451526rwr; Wed, 19 Apr 2023 08:36:25 -0700 (PDT) X-Google-Smtp-Source: AKy350Y6E3tRvk2O6jZ81QZe/7pgqkuMtZQn2GbIHWQPwdmjOb5rx4mq8oRYKaDI9arBHx2rXo4F X-Received: by 2002:a05:6a21:78a2:b0:f0:dedb:83b8 with SMTP id bf34-20020a056a2178a200b000f0dedb83b8mr4939162pzc.19.1681918585045; Wed, 19 Apr 2023 08:36:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681918585; cv=none; d=google.com; s=arc-20160816; b=E/POUvMcCcNokc5TK66qfmozsZry9Ut+J62E/3Ukoul6e+q2WniGQm8cSxGbxze291 t9VuWcNIWCjDVyBCBh48vHjzcefNkFA72DLA9RPV5Jt/pyOfTfazUSHWA2drB32X7IQ3 u+mSXkH1pUFZOo7fF7OujxJijK1o6Hstv1kz6sO1MafcK7IApeHpvczXomg7ryEVfvPV r2BgQaBjnuGprtMx4v7yT2JM8JEZZTu+Zv1V7LcW+0DT/LTCpIJBWWkrRRs3PDmSsnoA KvevyWwGxbs81wgo3BVpSA2WyRk9kMiLrsXD1JhliSt4zKEDwcjNt3x0W0JnXiHzfbB+ IFGA== 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:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=0fnBR63fjg8I+ttH03vi4HM7bX97ZqFKA7oIwBOt55Q=; b=vl27p63J2LkcuMd+F0bHPKe7Z/X+eZ0y4zaVTJHBtd0l0iW+oluJCV+ChYVaUQ5JFx OqOKq6FfkLMJWYZQ7dyHZJ83kMOtbPdWr8UO9C61iC9Xae9HstupK1OhRGrNRiCjMNB6 plsLBvtTuZxjgeZ941H5D9G4ljtUNucoiAx7DtDimxUwdCqg/gikWv0/SeGJEtzAoW/4 zf4M24KyPDO9QDdR/E5Peu7kOGQJF9iskmLcSpxRLWvBnjo0atW5mcRTZIUO9L8SJ+2O bfTryUIcMIPh1lACeqd9UBu1p9EgBIVm7M3LLLI1NpttaFIe0lsC68bObhBBUjpvNcG9 n/0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OjKokYAL; 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 lw18-20020a17090b181200b002473c8f52fcsi2177154pjb.91.2023.04.19.08.36.08; Wed, 19 Apr 2023 08:36:25 -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=OjKokYAL; 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 S233466AbjDSPat (ORCPT + 99 others); Wed, 19 Apr 2023 11:30:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233276AbjDSPan (ORCPT ); Wed, 19 Apr 2023 11:30:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C76840E6 for ; Wed, 19 Apr 2023 08:30:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A9A7E61633 for ; Wed, 19 Apr 2023 15:30:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A03BC433D2; Wed, 19 Apr 2023 15:30:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681918240; bh=JMaZwA1dCOk+ofXmP6eFP+HvsGhy7OmhboIcr8AIwVM=; h=Date:Subject:From:To:Cc:References:In-Reply-To:From; b=OjKokYALqdz14ovnpWb2G0lrqzwH3Y3EtIWFGljrdFfcSge7bnQPXWWQxJfex8W1l 0P61ZJdja7F0v9+LEHFqOpf7Fb1mZ/jP9NLEXzIwaR0xJoeFJbxVcALufZO5Nt0u+9 7ebsyUvC9VhzfsGa75Y+TxWlXxU5OSZTJtj0iVivJi7dBSvllSK8zd9oItTXkVAm0P 6myos6Mm/2QMMYIQtvAsgo1ayN6hP0hEGVqrXUm8QLiK4uaYakH2DVLoEWwbQbLYT1 uUGIFDAFIKnPLTDj649tg3G0869C0hOxFbKZw+ve+iqHBRSshQYlcc6v3WfyUbxRqy hf4CNyR0fE0Cg== Message-ID: <18ed82d6-b191-9c04-23ac-caa0a16f263e@kernel.org> Date: Wed, 19 Apr 2023 23:30:36 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [f2fs-dev] [PATCH] f2fs: fix to tag FIEMAP_EXTENT_DELALLOC in fiemap() for delay allocated extent Content-Language: en-US From: Chao Yu To: Jaegeuk Kim Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net References: <20230405144359.930253-1-chao@kernel.org> <224e8756-7c63-fd53-a0f3-f3e2a7b4c13f@kernel.org> <538fd229-28ae-0ec5-ef07-35d505fbb8a9@kernel.org> <2341db3b-5a40-a9f0-51f1-29a8908e3e98@kernel.org> <2d3125e9-0e5c-644f-1ffa-e41ba55b4ecb@kernel.org> In-Reply-To: <2d3125e9-0e5c-644f-1ffa-e41ba55b4ecb@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_MED,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 2023/4/13 17:49, Chao Yu wrote: > On 2023/4/12 1:08, Jaegeuk Kim wrote: >> On 04/11, Chao Yu wrote: >>> On 2023/4/11 16:14, Chao Yu wrote: >>>> On 2023/4/11 1:57, Jaegeuk Kim wrote: >>>>> On 04/08, Chao Yu wrote: >>>>>> On 2023/4/8 4:59, Jaegeuk Kim wrote: >>>>>>> This breaks generic/009? >>>>>> >>>>>> I guess it is as expected? >>>>>> >>>>>> Please check description of fiemap ioctl manual from [1]: >>>>>> >>>>>> FIEMAP_EXTENT_UNKNOWN >>>>>> The location of this extent is currently unknown. This may >>>>>> indicate the data is stored on an inaccessible volume or that >>>>>> no storage has been allocated for the file yet. >>>>>> >>>>>> FIEMAP_EXTENT_DELALLOC >>>>>> This will also set FIEMAP_EXTENT_UNKNOWN. >>>>>> >>>>>> Delayed allocation - while there is data for this extent, its >>>>>> physical location has not been allocated yet. >>>>>> >>>>>> FIEMAP_EXTENT_UNWRITTEN >>>>>> Unwritten extent - the extent is allocated but its data has not >>>>>> been initialized. This indicates the extent’s data will be all >>>>>> zero if read through the filesystem but the contents are undefined >>>>>> if read directly from the device. >>>>>> >>>>>> [1] https://www.kernel.org/doc/html/latest/filesystems/fiemap.html >>>>>> >>>>>> According to its description, f2fs only support >>>>>> FIEMAP_EXTENT_{UNKNOWN, DELALLOC}, but not support >>>>>> FIEMAP_EXTENT_UNWRITTEN. >>>>> >>>>> No, I don't think so. >>>> >>>> Jaegeuk, >>>> >>>> Could you please check the detailed description of FIEMAP_EXTENT_UNWRITTEN? >>>> The flag indicates two conditions: >>>> 1. on-disk blkaddrs were allocated for extent, and the extent is tagged as >>>> unwritten status. >>>> 2. data readed on those blocks will be all zero. >>> >>> Sorry, I mean: >>> >>> 1. on-disk blkaddrs were allocated for extent; >>> 2. extent is tagged as unwritten status, data readed on those blocks will be >>> all zero. >> >> I was thinking fallocate/pin cases to give zero data. But, we may need to check >> the space discarded securely or disk support? > > I thought about similar scheme, we can add F2FS_GET_BLOCK_ZERO for fallocate/pin > case to zero data in valid block address, but the problem is how can we distinguish > zero/valid data from valid block address w/o additional unwritten flag of metadata. > > e.g. > 1. write page [0,511] w/ valid data; > 2. fallocate/pin page [512,1023] w/ zero data; > 3. fiemap file --- what output should it be? Thoughts? Thanks, > > Thanks, > >> >>> >>> Thanks, >>> >>>> >>>> So, let's check f2fs' status: >>>> - fallocate only reserve valid block count and set NEW_ADDR in dnode, so >>>> it does not match condition 1) >>>> - pin & fallocate preallocates blkaddrs and set blkaddrs in dnode, but >>>> content on those blkaddrs may contain zero or random data, so it does not >>>> match  condition 2) >>>> >>>> Christoph describes this issue in below patch as well, you can check it. >>>> da8c7fecc9c7 ("f2fs: rename F2FS_MAP_UNWRITTEN to F2FS_MAP_DELALLOC") >>>> >>>> Am I missing something? >>>> >>>> Thanks, >>>> >>>>> >>>>>> >>>>>> So 009, 092, 094 .. which expects unwritten status from extent will >>>>>> fail. >>>>>> >>>>>> How about disabling those testcase? >>>>>> >>>>>> Thanks, >>>>>> >>>>>>> >>>>>>> On 04/05, Chao Yu wrote: >>>>>>>> xfstest generic/614 fails to run due below reason: >>>>>>>> >>>>>>>> generic/614 1s ... [not run] test requires delayed allocation buffered writes >>>>>>>> >>>>>>>> The root cause is f2fs tags wrong fiemap flag for delay allocated >>>>>>>> extent. >>>>>>>> >>>>>>>> Quoted from fiemap.h: >>>>>>>> FIEMAP_EXTENT_UNKNOWN        0x00000002 /* Data location unknown. */ >>>>>>>> FIEMAP_EXTENT_DELALLOC        0x00000004 /* Location still pending. >>>>>>>>                             * Sets EXTENT_UNKNOWN. */ >>>>>>>> FIEMAP_EXTENT_UNWRITTEN        0x00000800 /* Space allocated, but >>>>>>>>                             * no data (i.e. zero). */ >>>>>>>> >>>>>>>> FIEMAP_EXTENT_UNWRITTEN means block address is preallocated, but w/o >>>>>>>> been written any data, which status f2fs is not supported now, for all >>>>>>>> NEW_ADDR block addresses, it means delay allocated blocks, so let's >>>>>>>> tag FIEMAP_EXTENT_DELALLOC instead. >>>>>>>> >>>>>>>> Testcase: >>>>>>>> xfs_io -f -c 'pwrite 0 64k' /mnt/f2fs/file; >>>>>>>> filefrag -v /mnt/f2fs/file >>>>>>>> >>>>>>>> Output: >>>>>>>> - Before >>>>>>>> Filesystem type is: f2f52010 >>>>>>>> Fize of /mnt/f2fs/file is 65536 (16 blocks of 4096 bytes) >>>>>>>>    ext:     logical_offset:        physical_offset: length:   expected: flags: >>>>>>>>      0:        0..      15:          0..        15:     16:             last,unwritten,merged,eof >>>>>>>> /mnt/f2fs/file: 1 extent found >>>>>>>> >>>>>>>> After: >>>>>>>> Filesystem type is: f2f52010 >>>>>>>> File size of /mnt/f2fs/file is 65536 (16 blocks of 4096 bytes) >>>>>>>>    ext:     logical_offset:        physical_offset: length:   expected: flags: >>>>>>>>      0:        0..      15:          0..         0:      0:             last,unknown_loc,delalloc,eof >>>>>>>> /mnt/f2fs/file: 1 extent found >>>>>>>> >>>>>>>> Fixes: 7f63eb77af7b ("f2fs: report unwritten area in f2fs_fiemap") >>>>>>>> Signed-off-by: Chao Yu >>>>>>>> --- >>>>>>>>    fs/f2fs/data.c | 7 +++++-- >>>>>>>>    1 file changed, 5 insertions(+), 2 deletions(-) >>>>>>>> >>>>>>>> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c >>>>>>>> index 359de650772e..3afc9764743e 100644 >>>>>>>> --- a/fs/f2fs/data.c >>>>>>>> +++ b/fs/f2fs/data.c >>>>>>>> @@ -1995,7 +1995,10 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, >>>>>>>>        } >>>>>>>>        if (size) { >>>>>>>> -        flags |= FIEMAP_EXTENT_MERGED; >>>>>>>> +        if (flags & FIEMAP_EXTENT_DELALLOC) >>>>>>>> +            phys = 0; >>>>>>>> +        else >>>>>>>> +            flags |= FIEMAP_EXTENT_MERGED; >>>>>>>>            if (IS_ENCRYPTED(inode)) >>>>>>>>                flags |= FIEMAP_EXTENT_DATA_ENCRYPTED; >>>>>>>> @@ -2035,7 +2038,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, >>>>>>>>                    size += blks_to_bytes(inode, 1); >>>>>>>>                } >>>>>>>>            } else if (map.m_flags & F2FS_MAP_DELALLOC) { >>>>>>>> -            flags = FIEMAP_EXTENT_UNWRITTEN; >>>>>>>> +            flags = FIEMAP_EXTENT_DELALLOC; >>>>>>>>            } >>>>>>>>            start_blk += bytes_to_blks(inode, size); >>>>>>>> -- >>>>>>>> 2.36.1 >>>> >>>> >>>> _______________________________________________ >>>> Linux-f2fs-devel mailing list >>>> Linux-f2fs-devel@lists.sourceforge.net >>>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel > > > _______________________________________________ > Linux-f2fs-devel mailing list > Linux-f2fs-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel