Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp46419iol; Wed, 8 Jun 2022 21:21:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTBcsX5sV7Fs1iG24bPlkAnvO/mfNCeFUSdkxb8eLGIr4kbED1U/xxn/qqe45DgrqqWQtR X-Received: by 2002:a05:6a00:2402:b0:4e1:3df2:5373 with SMTP id z2-20020a056a00240200b004e13df25373mr104931075pfh.40.1654748484596; Wed, 08 Jun 2022 21:21:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654748484; cv=none; d=google.com; s=arc-20160816; b=GDItjJbKN6EmjmaEIDmn1qBPj7W+eMP2kEdNgLpXDfSBcrPHgtDelyxHKb4FLZlstM GXQfXtNMKO1lf6KM0NIRE/Q5UCdYKXMmMpgWQEH4dzDhyWHix3RmXwXt0w/nxFHiaPg/ RB91iV0xzPuk0tdZhwY8G8gO5kVJbHPsJ8mc96z93x4J+IkilKBXC0itG1KtMcZWuSku WkQOAzoaaWWIhUWSwhI6rzj47XgP4ojSLQIcDQBBwpJyQn4GeLICfIaKlsuphDYWzBFp EpJAvKOHrj+pkybcKViotQMar3uVAyYw1cUmC26TncXggwKV5TwHvxUAF9VWL1LrUZA5 UALQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=PsKDmE2L9q1IQI6wppMCMtUl6JvGjcTHbJKV3xSCmw8=; b=H+sU/AqoXWVJGJHmkwv/8Zf2ArrZI6Ipv5K1f/M3JvLKs3pamJYSFydmLKhT7SuXHv 8e5EVY+gOmH7bpllIK3OwNSd4+iZbUuyRupFly6TH1dJwB9KXDL/qV5sLsAJHaMHyEko kUPhGz46SULfwxslRr9o7Cc6jTOsoUypVWvgxoP4FBtsKbq6ynRsfJmf4XTBTKCczwVV HOhxHgWY0pofDyhDPqSsW2hfZbU08IIwiNL6MpVhp2NsTsKcRhSCY732RcLeheyo4PG/ RwEYP5MpHG+5sXhhYQwzDLl7z6vGGRwxXEzRRgrUcxQZ8kRtGL5j/oNSA38BvhFORqRk dAdA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x64-20020a638643000000b003fe4c06ccd4si2272964pgd.671.2022.06.08.21.21.12; Wed, 08 Jun 2022 21:21:24 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234767AbiFIDkT (ORCPT + 99 others); Wed, 8 Jun 2022 23:40:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231253AbiFIDkN (ORCPT ); Wed, 8 Jun 2022 23:40:13 -0400 Received: from out199-18.us.a.mail.aliyun.com (out199-18.us.a.mail.aliyun.com [47.90.199.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB179262E00 for ; Wed, 8 Jun 2022 20:40:10 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=hongnan.li@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VFqInsP_1654746006; Received: from localhost(mailfrom:hongnan.li@linux.alibaba.com fp:SMTPD_---0VFqInsP_1654746006) by smtp.aliyun-inc.com; Thu, 09 Jun 2022 11:40:06 +0800 From: Hongnan Li To: linux-erofs@lists.ozlabs.org, xiang@kernel.org, chao@kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2] erofs: update ctx->pos for every emitted dirent Date: Thu, 9 Jun 2022 11:40:06 +0800 Message-Id: <20220609034006.76649-1-hongnan.li@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20220527072536.68516-1-hongnan.li@linux.alibaba.com> References: <20220527072536.68516-1-hongnan.li@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL 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 erofs_readdir update ctx->pos after filling a batch of dentries and it may cause dir/files duplication for NFS readdirplus which depends on ctx->pos to fill dir correctly. So update ctx->pos for every emitted dirent in erofs_fill_dentries to fix it. Fixes: 3e917cc305c6 ("erofs: make filesystem exportable") Signed-off-by: Hongnan Li --- fs/erofs/dir.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/erofs/dir.c b/fs/erofs/dir.c index 18e59821c597..94ef5287237a 100644 --- a/fs/erofs/dir.c +++ b/fs/erofs/dir.c @@ -22,10 +22,9 @@ static void debug_one_dentry(unsigned char d_type, const char *de_name, } static int erofs_fill_dentries(struct inode *dir, struct dir_context *ctx, - void *dentry_blk, unsigned int *ofs, + void *dentry_blk, struct erofs_dirent *de, unsigned int nameoff, unsigned int maxsize) { - struct erofs_dirent *de = dentry_blk + *ofs; const struct erofs_dirent *end = dentry_blk + nameoff; while (de < end) { @@ -59,9 +58,8 @@ static int erofs_fill_dentries(struct inode *dir, struct dir_context *ctx, /* stopped by some reason */ return 1; ++de; - *ofs += sizeof(struct erofs_dirent); + ctx->pos += sizeof(struct erofs_dirent); } - *ofs = maxsize; return 0; } @@ -95,7 +93,7 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx) "invalid de[0].nameoff %u @ nid %llu", nameoff, EROFS_I(dir)->nid); err = -EFSCORRUPTED; - goto skip_this; + break; } maxsize = min_t(unsigned int, @@ -106,17 +104,19 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx) initial = false; ofs = roundup(ofs, sizeof(struct erofs_dirent)); - if (ofs >= nameoff) + if (ofs >= nameoff) { + ctx->pos = blknr_to_addr(i) + ofs; goto skip_this; + } } - err = erofs_fill_dentries(dir, ctx, de, &ofs, - nameoff, maxsize); -skip_this: ctx->pos = blknr_to_addr(i) + ofs; - + err = erofs_fill_dentries(dir, ctx, de, (void *)de + ofs, + nameoff, maxsize); if (err) break; + ctx->pos = blknr_to_addr(i) + maxsize; +skip_this: ++i; ofs = 0; } -- 2.35.3