Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp423960imi; Fri, 22 Jul 2022 01:58:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1urW8mcXw+O/QtHluy9WlOVAvTcb081erN5LejZ24xFVzmLlyc7ykfysR1NcaBscuarelYW X-Received: by 2002:a63:2b15:0:b0:412:4d98:7956 with SMTP id r21-20020a632b15000000b004124d987956mr2282288pgr.325.1658480311901; Fri, 22 Jul 2022 01:58:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658480311; cv=none; d=google.com; s=arc-20160816; b=AnBN/cMSvbidSVJwaRM2zL64xjhp1YOzDJo0mHEl/MRK+/BhnTdFxth7WgkHLwOqtJ G78et+ded8YaVudKTkYMOj+kva6Iq2uMNrf3Hz+VYYlD0i7/uLmy22avkixssSWgyQ5n mmjQO4kI2QEWwsEYvpqIVZ6X9KKjMTni1Pz3cMjP74lsaJDEcJqGg/s8r7ad1as3c9xq jfCVFrv/EbEcBiJPBujQxRs4AekJJyJqs9s/Bsm3oqsaZ3mLtJDMT6EWUbhs+hs9DQdx AwhWsUu/BNV05X1ux+SHLmG2I1QDJXIph7w5ptGypNOJ0RJTOyAPQbcmbf8AmNnNrUrh AdpQ== 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 :message-id:date:subject:cc:to:from; bh=FqwMXsllWv8c33SLZmY0DwmN5qWwlBT5M93Vfr7pods=; b=vLw+ALPmAppU9+dhMRi3MacXyVMDGrf6jajK2mVRfigCMyXY1ULV4NaVvBfVJaJlq3 7Uz3W2/HDuaZaTqBIsrpjhbFO9J/Z0ZmHY3/2PP9FWHiGr6rynrsEUe9GQXbySX6KYqr 2V0k9QV2JLV6h9mm1A2y0qsAO7H9Zar+cnp1a5eu8hhF6ETV9fh7gyDHQLCxVYEt9aSp rZK2+amloLDgo51yYzUXNxK+efNko3hEjKXuiNgInIEsyxt0BU0Y9AGUA47rxycxB9uW tFSBsxPL7eH4kJhzGMMYrWPp2Es8QhybKa2LxTCq+lfrWybqCA+bZQaY/ZRn+/coXdvo nyoQ== 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 30-20020a63135e000000b003f5d8756675si5213995pgt.371.2022.07.22.01.58.16; Fri, 22 Jul 2022 01:58:31 -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 S234989AbiGVI1j (ORCPT + 99 others); Fri, 22 Jul 2022 04:27:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234984AbiGVI1i (ORCPT ); Fri, 22 Jul 2022 04:27:38 -0400 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87CFD9E7BD for ; Fri, 22 Jul 2022 01:27:35 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R841e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VK4RflD_1658478452; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VK4RflD_1658478452) by smtp.aliyun-inc.com; Fri, 22 Jul 2022 16:27:32 +0800 From: Jeffle Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH v4] erofs: update ctx->pos for every emitted dirent Date: Fri, 22 Jul 2022 16:27:32 +0800 Message-Id: <20220722082732.30935-1-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 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,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, 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 From: Hongnan Li 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. Also fix the update of ctx->pos when the initial file position has exceeded nameoff. Fixes: 3e917cc305c6 ("erofs: make filesystem exportable") Signed-off-by: Hongnan Li Signed-off-by: Jeffle Xu --- 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..47c85f1b80d8 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; +skip_this: + ctx->pos = blknr_to_addr(i) + maxsize; ++i; ofs = 0; } -- 2.27.0