Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp357128iog; Wed, 29 Jun 2022 01:25:03 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uj7B8J5AKm6aQeV05NBg2ZDBdi4nbLZhSFjtuwh8mSQSqaZRJNydXozTahJ5ngC4Rd24Dj X-Received: by 2002:a63:18c:0:b0:40c:f9df:4499 with SMTP id 134-20020a63018c000000b0040cf9df4499mr1989911pgb.322.1656491103373; Wed, 29 Jun 2022 01:25:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656491103; cv=none; d=google.com; s=arc-20160816; b=d7bdwOdkR8n4sprhQ9bpwNiZytpgZzuOacQRrvJiFahe/7Lc7725nrlV82sb6+T2DJ rpoe2o5oaJZrgvFWXSgsjgIrTiURBKI5zHXmIqXt6Tq1nF3l2P0bsBuCWr8DOK7Gwb9t TOL2BlHMLKolJnnMSpv54kzJFsaHWHVVFFwLveeg+uHjTs3iNpDEJqB/BkijYh25Wgi9 K/NSKl8xCO7BpnJg23ohJZgg9iqBjJAs90CvhI2vMMocXY9+1MEfMaQz54IwsvAWaxxh 5Qd0jKNQ50rOEuKtMjNoGZvONMOCatGO9ocsQZdVFTRk3ETm/m+WeyuO02OPr4uZhD/f dvVg== 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=pjOb1eRTQzlUu7ItuSe+p5yo8TV0dnzZPS4vf4bvGo0=; b=FUFU2C+r6ACmdWgI8P9KW2sLgHDoPkTftWmieGiQPwL3Ceborh/OG6IJGHGs/QUUvw bY/773G82dNmp+yKZvjEKLvp6C4AXsJ81qscSosRuhuEu/C+83+iVqNnCI6lTLpDwwR1 BR3aOE+qzhd6J3Kmkt8Ogq54YHBISeypHw8ZYrkclGrAXs8bnMplP+IQNrxuywJlw3jO +1NN5k1upny/IBH1OCe6YjjwPiK0Oi0+l0rASy3pYoREnU1JyLQ2BObZ1S9OeROH7bmF o4SjCC4jk7Io1PIFTUyzRkUkYWqEdfeGJ8J9CJpzK9oc0v99wuZp3HTe/fPDfLgSOsNB OmYQ== 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 x17-20020aa78f11000000b0052528b49e49si20912976pfr.104.2022.06.29.01.24.51; Wed, 29 Jun 2022 01:25:03 -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 S231489AbiF2IP6 (ORCPT + 99 others); Wed, 29 Jun 2022 04:15:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229772AbiF2IP5 (ORCPT ); Wed, 29 Jun 2022 04:15:57 -0400 Received: from out199-2.us.a.mail.aliyun.com (out199-2.us.a.mail.aliyun.com [47.90.199.2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 670773B55B for ; Wed, 29 Jun 2022 01:15:55 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;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_---0VHn30-k_1656490550; Received: from localhost(mailfrom:hongnan.li@linux.alibaba.com fp:SMTPD_---0VHn30-k_1656490550) by smtp.aliyun-inc.com; Wed, 29 Jun 2022 16:15:51 +0800 From: Hongnan Li To: linux-erofs@lists.ozlabs.org, xiang@kernel.org, chao@kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH v3] erofs: update ctx->pos for every emitted dirent Date: Wed, 29 Jun 2022 16:15:50 +0800 Message-Id: <20220629081550.23501-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 | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/fs/erofs/dir.c b/fs/erofs/dir.c index 18e59821c597..6fc325052853 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,17 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx) initial = false; ofs = roundup(ofs, sizeof(struct erofs_dirent)); + ctx->pos = blknr_to_addr(i) + ofs; if (ofs >= nameoff) goto skip_this; } - err = erofs_fill_dentries(dir, ctx, de, &ofs, + err = erofs_fill_dentries(dir, ctx, de, (void *)de + ofs, nameoff, maxsize); -skip_this: - ctx->pos = blknr_to_addr(i) + ofs; - if (err) break; + ctx->pos = blknr_to_addr(i) + maxsize; +skip_this: ++i; ofs = 0; } -- 2.35.3