Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3994069rdb; Mon, 11 Dec 2023 06:10:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IF7H0PfaEF2zaKddS/GY/bLRW+r4zbfYUt3uMNO7EUER75zEB1RIGjxTXOyMXZU18Ds5Q0x X-Received: by 2002:a17:902:e74e:b0:1d0:bfb7:670f with SMTP id p14-20020a170902e74e00b001d0bfb7670fmr2424827plf.69.1702303815082; Mon, 11 Dec 2023 06:10:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702303815; cv=none; d=google.com; s=arc-20160816; b=VeFN2rvSEYQQOOpzn9plvhQ2jKo07S19cTAPU4iRU6mRV9NDrP+Nj4Sv24pTV2NpmM 4NjzaTqEQ5cDK8MQaRFVYMFWPu6ArQT+kQVM0ZpwjhAMh6ZoN5uQUNpJpPrWByymxucT cve7htNkeHh16Vjp8XyM691BySDQHxdlLKBx7Z7OajthM5u5Ojnw1nb+BkCZjtF8YVnY uLT8gwb3E/vGoudDeBWxQuFRykt0MbvdH1c5rGkZ8RBsXsimgjw1AEEtns6ibyFLNPGF NKxmJ/gWtCJNwi2yqIfk+GGSgrtdbsQu9l5hJuXcokvsC6I7HrBB6ajaJUlptlefLGvC gpPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=+5eoTY+kHSQyS1FB8stVr43IKCT0fUFvr2OIGE7sCwM=; fh=ewjcwSOkiqoDqBkoSn9uLOsJItfx5w5YcyErEa5iLiM=; b=GCag66A0TgOD2ksd/WHssvkwPxnT/qQoPS0s5Y8lgLIEhPYYv883ir9MkUzmvqBeik cUyR/H19OAkLEOlA7NZHImkaJQtAjK9UldzRAinyeYc2H9Whtw8cOuu1DgkqaEMfSRYl 3E8U3f6YPJThYAc/C7zUBj01Ag/Urd/tQJU8SL2RppzkDmp+RMsaNoLK4B7p5SgqYfNq aVgn+pO6OCS3tiujKW5W6CTffIRiIO5Soo/+PDiUfvHMkg+N1Lkr5veB4YXkOeWTLKTv qD1BS+O7tAkyyQYJLnsfmfQVsWVO8qKsduOmAHRGofw8VWV/aqt1sWkYLI8Ci3ClKo5+ 45Gg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-363-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-ext4+bounces-363-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id c10-20020a170902d48a00b001d07126d233si6377600plg.564.2023.12.11.06.10.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 06:10:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-363-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-363-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-ext4+bounces-363-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A6394B216B3 for ; Mon, 11 Dec 2023 14:09:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC6AF4AF96; Mon, 11 Dec 2023 14:07:37 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68C335240; Mon, 11 Dec 2023 06:07:27 -0800 (PST) Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Spk8W66xrz4f3kKy; Mon, 11 Dec 2023 22:07:23 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 017EC1A07A3; Mon, 11 Dec 2023 22:07:25 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgDn6xGTF3dlDYFxDQ--.28013S8; Mon, 11 Dec 2023 22:07:24 +0800 (CST) From: Yu Kuai To: axboe@kernel.dk, roger.pau@citrix.com, colyli@suse.de, kent.overstreet@gmail.com, joern@lazybastard.org, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, sth@linux.ibm.com, hoeppner@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, jejb@linux.ibm.com, martin.petersen@oracle.com, clm@fb.com, josef@toxicpanda.com, dsterba@suse.com, viro@zeniv.linux.org.uk, brauner@kernel.org, nico@fluxnic.net, xiang@kernel.org, chao@kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, agruenba@redhat.com, jack@suse.com, konishi.ryusuke@gmail.com, willy@infradead.org, akpm@linux-foundation.org, p.raghav@samsung.com, hare@suse.de Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, linux-bcache@vger.kernel.org, linux-mtd@lists.infradead.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, linux-bcachefs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-erofs@lists.ozlabs.org, linux-ext4@vger.kernel.org, gfs2@lists.linux.dev, linux-nilfs@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [PATCH RFC v2 for-6.8/block 04/18] mtd: block2mtd: use bdev apis Date: Mon, 11 Dec 2023 22:05:38 +0800 Message-Id: <20231211140552.973290-5-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211140552.973290-1-yukuai1@huaweicloud.com> References: <20231211140552.973290-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgDn6xGTF3dlDYFxDQ--.28013S8 X-Coremail-Antispam: 1UD129KBjvJXoW3Jw1DtryDWw17CF45XFyrZwb_yoW7Aw18pa y3Ca95Aw4UKrn8urs7Xwn8Zr12g3sFqa1Uuay7C3yakFyfXryIkas7ta45tFyrKry8AFWk XF4DAr4rXF40grJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPa14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Wrv_Gr1UMI IYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E 14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r 1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjfU OBTYUUUUU X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai On the one hand covert to use folio while reading bdev inode, on the other hand prevent to access bd_inode directly. Signed-off-by: Yu Kuai --- drivers/mtd/devices/block2mtd.c | 81 +++++++++++++++------------------ 1 file changed, 36 insertions(+), 45 deletions(-) diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c index aa44a23ec045..cf201bf73184 100644 --- a/drivers/mtd/devices/block2mtd.c +++ b/drivers/mtd/devices/block2mtd.c @@ -46,40 +46,34 @@ struct block2mtd_dev { /* Static info about the MTD, used in cleanup_module */ static LIST_HEAD(blkmtd_device_list); - -static struct page *page_read(struct address_space *mapping, pgoff_t index) -{ - return read_mapping_page(mapping, index, NULL); -} - /* erase a specified part of the device */ static int _block2mtd_erase(struct block2mtd_dev *dev, loff_t to, size_t len) { - struct address_space *mapping = - dev->bdev_handle->bdev->bd_inode->i_mapping; - struct page *page; + struct block_device *bdev = dev->bdev_handle->bdev; + struct folio *folio; pgoff_t index = to >> PAGE_SHIFT; // page index int pages = len >> PAGE_SHIFT; u_long *p; u_long *max; while (pages) { - page = page_read(mapping, index); - if (IS_ERR(page)) - return PTR_ERR(page); + folio = bdev_read_folio(bdev, index << PAGE_SHIFT); + if (IS_ERR(folio)) + return PTR_ERR(folio); - max = page_address(page) + PAGE_SIZE; - for (p=page_address(page); ppriv; - struct address_space *mapping = - dev->bdev_handle->bdev->bd_inode->i_mapping; - struct page *page; + struct folio *folio; pgoff_t index = from >> PAGE_SHIFT; int offset = from & (PAGE_SIZE-1); int cpylen; @@ -120,12 +112,13 @@ static int block2mtd_read(struct mtd_info *mtd, loff_t from, size_t len, cpylen = len; // this page len = len - cpylen; - page = page_read(mapping, index); - if (IS_ERR(page)) - return PTR_ERR(page); + folio = bdev_read_folio(dev->bdev_handle->bdev, + index << PAGE_SHIFT); + if (IS_ERR(folio)) + return PTR_ERR(folio); - memcpy(buf, page_address(page) + offset, cpylen); - put_page(page); + memcpy(buf, folio_address(folio) + offset, cpylen); + folio_put(folio); if (retlen) *retlen += cpylen; @@ -141,9 +134,8 @@ static int block2mtd_read(struct mtd_info *mtd, loff_t from, size_t len, static int _block2mtd_write(struct block2mtd_dev *dev, const u_char *buf, loff_t to, size_t len, size_t *retlen) { - struct page *page; - struct address_space *mapping = - dev->bdev_handle->bdev->bd_inode->i_mapping; + struct block_device *bdev = dev->bdev_handle->bdev; + struct folio *folio; pgoff_t index = to >> PAGE_SHIFT; // page index int offset = to & ~PAGE_MASK; // page offset int cpylen; @@ -155,18 +147,18 @@ static int _block2mtd_write(struct block2mtd_dev *dev, const u_char *buf, cpylen = len; // this page len = len - cpylen; - page = page_read(mapping, index); - if (IS_ERR(page)) - return PTR_ERR(page); + folio = bdev_read_folio(bdev, index << PAGE_SHIFT); + if (IS_ERR(folio)) + return PTR_ERR(folio); - if (memcmp(page_address(page)+offset, buf, cpylen)) { - lock_page(page); - memcpy(page_address(page) + offset, buf, cpylen); - set_page_dirty(page); - unlock_page(page); - balance_dirty_pages_ratelimited(mapping); + if (memcmp(folio_address(folio) + offset, buf, cpylen)) { + folio_lock(folio); + memcpy(folio_address(folio) + offset, buf, cpylen); + folio_mark_dirty(folio); + folio_unlock(folio); + bdev_balance_dirty_pages_ratelimited(bdev); } - put_page(page); + folio_put(folio); if (retlen) *retlen += cpylen; @@ -211,8 +203,7 @@ static void block2mtd_free_device(struct block2mtd_dev *dev) kfree(dev->mtd.name); if (dev->bdev_handle) { - invalidate_mapping_pages( - dev->bdev_handle->bdev->bd_inode->i_mapping, 0, -1); + invalidate_bdev(dev->bdev_handle->bdev); bdev_release(dev->bdev_handle); } @@ -295,7 +286,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size, goto err_free_block2mtd; } - if ((long)bdev->bd_inode->i_size % erase_size) { + if (bdev_nr_bytes(bdev) % erase_size) { pr_err("erasesize must be a divisor of device size\n"); goto err_free_block2mtd; } @@ -313,7 +304,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size, dev->mtd.name = name; - dev->mtd.size = bdev->bd_inode->i_size & PAGE_MASK; + dev->mtd.size = bdev_nr_bytes(bdev) & PAGE_MASK; dev->mtd.erasesize = erase_size; dev->mtd.writesize = 1; dev->mtd.writebufsize = PAGE_SIZE; -- 2.39.2