Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp584482imw; Fri, 15 Jul 2022 09:01:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ssBvvRyMQh5EjQRCIEjAbrpafSF/852KG6uYoID2rN8jy1a6+/YmelylSQ+wU4p5pGzJtD X-Received: by 2002:a63:1848:0:b0:416:1821:aa0b with SMTP id 8-20020a631848000000b004161821aa0bmr13012182pgy.394.1657900860649; Fri, 15 Jul 2022 09:01:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657900860; cv=none; d=google.com; s=arc-20160816; b=aDPdTre/xyg/LBfD/ymLlkk22ZPZfJqzNr2CMVvX8Cpgy/oGOVfoY1Jxpz/7D8BH2P dQHdLsm22ELcGk79DtRZFpbLHIgz8/cCud66iIbIH8GotuvMeTlzIFtWOJb2hTT1HGnm eL3jSrBnN7bFjjD0Yxh+yXtBwnWYBQjB8fZcorTMGyXJlZfMaB++BUrudxpMtj7zuX/k Jk64efZyMwQYWDZ1SLw98fuRCGytbVQECJkYSAkGKsbpPPHCdyLVXV5TNony1bXvoULd 4QFlmG+WXeR6fQx0lFT/yj7DNUAwKlEoIWZA00gyMZ209jANvC2WhmZv+tg4APXkYwQW vHkw== 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=wD8fS4J4A+WA7+Dmkld77AwiZO1S6CqMIpg3nrukJyo=; b=tnZ+SRy83ezck2BmWXUaK0bHFCRrFSufWQCU5z1RhRTaLMkjWiyQaemxmbWLk1Sea4 vGPGFh8bwVxj6z577GSMw0n7otj54g2wD5ZRjwRXw3jajOBU2j8s9tr9b3NxV10x5RKe qBI7Rw09UI9poLI8+hr8IWTxCbzQOJvUVeyS8rmu/ffPfvqYcWERuhcEyl0QC5AnqGLu ag8rMGjZt0F9ps5V2w1cJ/3g5NDcuS3mcTmh2AIx26wKfSuIGevj1enbrBVNG+/AJTQn nSg27vG9Udx9R5t0+0/JTqo6DHGh9OwcX6wiJiy6c55VZdly3YMIuKijKnt4gdL9JBtk /K3Q== 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 q26-20020a62e11a000000b0052ad3d43859si5715899pfh.23.2022.07.15.09.00.45; Fri, 15 Jul 2022 09:01:00 -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 S235816AbiGOPnK (ORCPT + 99 others); Fri, 15 Jul 2022 11:43:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235064AbiGOPmg (ORCPT ); Fri, 15 Jul 2022 11:42:36 -0400 Received: from out30-42.freemail.mail.aliyun.com (out30-42.freemail.mail.aliyun.com [115.124.30.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BB055B7BC for ; Fri, 15 Jul 2022 08:42:32 -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=ay29a033018046059;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VJPnC8s_1657899747; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJPnC8s_1657899747) by smtp.aliyun-inc.com; Fri, 15 Jul 2022 23:42:28 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH v2 14/16] erofs: introduce z_erofs_do_decompressed_bvec() Date: Fri, 15 Jul 2022 23:42:01 +0800 Message-Id: <20220715154203.48093-15-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220715154203.48093-1-hsiangkao@linux.alibaba.com> References: <20220715154203.48093-1-hsiangkao@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,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 Both out_bvecs and in_bvecs share the common logic for decompressed buffers. So let's make a helper for this. Signed-off-by: Gao Xiang --- fs/erofs/zdata.c | 49 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index d93ba0adcf9e..d4db2c1d53a6 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -861,6 +861,26 @@ struct z_erofs_decompress_backend { unsigned int onstack_used; }; +static int z_erofs_do_decompressed_bvec(struct z_erofs_decompress_backend *be, + struct z_erofs_bvec *bvec) +{ + unsigned int pgnr = (bvec->offset + be->pcl->pageofs_out) >> PAGE_SHIFT; + struct page *oldpage; + + DBG_BUGON(pgnr >= be->pcl->nr_pages); + oldpage = be->decompressed_pages[pgnr]; + be->decompressed_pages[pgnr] = bvec->page; + + /* error out if one pcluster is refenenced multiple times. */ + if (oldpage) { + DBG_BUGON(1); + z_erofs_page_mark_eio(oldpage); + z_erofs_onlinepage_endio(oldpage); + return -EFSCORRUPTED; + } + return 0; +} + static int z_erofs_parse_out_bvecs(struct z_erofs_decompress_backend *be) { struct z_erofs_pcluster *pcl = be->pcl; @@ -871,27 +891,14 @@ static int z_erofs_parse_out_bvecs(struct z_erofs_decompress_backend *be) z_erofs_bvec_iter_begin(&biter, &pcl->bvset, Z_EROFS_INLINE_BVECS, 0); for (i = 0; i < pcl->vcnt; ++i) { struct z_erofs_bvec bvec; - unsigned int pgnr; z_erofs_bvec_dequeue(&biter, &bvec, &old_bvpage); if (old_bvpage) z_erofs_put_shortlivedpage(be->pagepool, old_bvpage); - pgnr = (bvec.offset + pcl->pageofs_out) >> PAGE_SHIFT; - DBG_BUGON(pgnr >= pcl->nr_pages); DBG_BUGON(z_erofs_page_is_invalidated(bvec.page)); - /* - * currently EROFS doesn't support multiref(dedup), - * so here erroring out one multiref page. - */ - if (be->decompressed_pages[pgnr]) { - DBG_BUGON(1); - z_erofs_page_mark_eio(be->decompressed_pages[pgnr]); - z_erofs_onlinepage_endio(be->decompressed_pages[pgnr]); - err = -EFSCORRUPTED; - } - be->decompressed_pages[pgnr] = bvec.page; + err = z_erofs_do_decompressed_bvec(be, &bvec); } old_bvpage = z_erofs_bvec_iter_end(&biter); @@ -911,7 +918,6 @@ static int z_erofs_parse_in_bvecs(struct z_erofs_decompress_backend *be, for (i = 0; i < pclusterpages; ++i) { struct z_erofs_bvec *bvec = &pcl->compressed_bvecs[i]; struct page *page = bvec->page; - unsigned int pgnr; /* compressed pages ought to be present before decompressing */ if (!page) { @@ -933,18 +939,7 @@ static int z_erofs_parse_in_bvecs(struct z_erofs_decompress_backend *be, err = -EIO; continue; } - - pgnr = (bvec->offset + pcl->pageofs_out) >> PAGE_SHIFT; - DBG_BUGON(pgnr >= pcl->nr_pages); - if (be->decompressed_pages[pgnr]) { - DBG_BUGON(1); - z_erofs_page_mark_eio( - be->decompressed_pages[pgnr]); - z_erofs_onlinepage_endio( - be->decompressed_pages[pgnr]); - err = -EFSCORRUPTED; - } - be->decompressed_pages[pgnr] = page; + err = z_erofs_do_decompressed_bvec(be, bvec); *overlapped = true; } } -- 2.24.4