From patchwork Sat Apr 6 09:09:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619739 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBB07EEBB; Sat, 6 Apr 2024 09:17:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395069; cv=none; b=mYjzEGhRSEMWl1qjtDiN4loFUmnvgFvchKxm3Lk4x/Y9k3uaaqgWL6LakUMbqRJJj2uOxDKzAkfVbQ+VaIdplnek2C6der411yiRQo3PgzZ88waybk1HwNTuhJ6mWmpEMN1yISR1vD4XeOxUsb0HGCoDrlG9Y0+iCrX7RjhUrKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395069; c=relaxed/simple; bh=dNBqjZwjTaP+9WqGKegPiWuES3qTPoMZqb7CTuS6A4c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=akKtkwIvScaHBWUc1RVLTwVXdXVXBVflLm+SROOHHb8KXCQmqOnbMenfSqck9X21iLDYgxzgnX+iYEvzays2yf3QVxWSXc92DR4CARazqLFpnM8in590Fp0t2+xI+TKXTySf9sV6GKn9c9RYaHH4LUkiRECpx3NS+hmuxgcQK30= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVB61DVqz4f3lVn; Sat, 6 Apr 2024 17:17:34 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id A1F1A1A016E; Sat, 6 Apr 2024 17:17:42 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S5; Sat, 06 Apr 2024 17:17:42 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 01/26] block: move two helpers into bdev.c Date: Sat, 6 Apr 2024 17:09:05 +0800 Message-Id: <20240406090930.2252838-2-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S5 X-Coremail-Antispam: 1UD129KBjvJXoW7WF45CFy3KF1ruryxJr17trb_yoW5Jr1UpF ZxGFW8G3yUCFyjgF40va1fZr1agw1kK34xJa4a934rKFyDtr4IgF1kJry8ZrWSqrZ7uFsx ZF43Ary0kryjk3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBYb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGw A2048vs2IY020Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I 0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7IU1M7K7UUUUU== X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai disk_live() and block_size() access bd_inode directly, prepare to remove the field bd_inode from block_device, and only access bd_inode in block layer. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- block/bdev.c | 12 ++++++++++++ include/linux/blkdev.h | 12 ++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index dd26d37356aa..621b9163c0f6 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -1251,6 +1251,18 @@ void bdev_statx_dioalign(struct inode *inode, struct kstat *stat) blkdev_put_no_open(bdev); } +bool disk_live(struct gendisk *disk) +{ + return !inode_unhashed(disk->part0->bd_inode); +} +EXPORT_SYMBOL_GPL(disk_live); + +unsigned int block_size(struct block_device *bdev) +{ + return 1 << bdev->bd_inode->i_blkbits; +} +EXPORT_SYMBOL_GPL(block_size); + static int __init setup_bdev_allow_write_mounted(char *str) { if (kstrtobool(str, &bdev_allow_write_mounted)) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 172c91879999..2c0d3a89002c 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -211,11 +211,6 @@ struct gendisk { struct blk_independent_access_ranges *ia_ranges; }; -static inline bool disk_live(struct gendisk *disk) -{ - return !inode_unhashed(disk->part0->bd_inode); -} - /** * disk_openers - returns how many openers are there for a disk * @disk: disk to check @@ -1364,11 +1359,6 @@ static inline unsigned int blksize_bits(unsigned int size) return order_base_2(size >> SECTOR_SHIFT) + SECTOR_SHIFT; } -static inline unsigned int block_size(struct block_device *bdev) -{ - return 1 << bdev->bd_inode->i_blkbits; -} - int kblockd_schedule_work(struct work_struct *work); int kblockd_mod_delayed_work_on(int cpu, struct delayed_work *dwork, unsigned long delay); @@ -1536,6 +1526,8 @@ void blkdev_put_no_open(struct block_device *bdev); struct block_device *I_BDEV(struct inode *inode); struct block_device *file_bdev(struct file *bdev_file); +bool disk_live(struct gendisk *disk); +unsigned int block_size(struct block_device *bdev); #ifdef CONFIG_BLOCK void invalidate_bdev(struct block_device *bdev); From patchwork Sat Apr 6 09:09:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619738 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51E4A1862A; Sat, 6 Apr 2024 09:17:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395068; cv=none; b=uTLCxkxYhPVon+5JR/qp2iC2qlm+bU+SgGm0HZiNsbaXRh4AR8O3ApkrNC3XWN73IwIWv/JfykYZIFHYySBjKCl3RVv/9OLEFyV3Hqw0R068S+LQBKv6A0wSTzs4qb9k1vIleInJ/vGz8W6fMAMdppy493rKVU/MQDSBFm3wOpE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395068; c=relaxed/simple; bh=YaUJHyGS36XvrDajQBrXYYb4F/pVSj/DeaXUDCcINNg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HWn44NNAxaAq1JwYI0qsOAekTKzkaCnPzMThr0qZXJNRcdSaTKJbsW1grD/QrVjyj5PDy9taeM3JT/zdptPoHebIuhBjAHVgddqH302WQomWNW+vXraxs/FL++kxjjZDXZbB6koWnpMripvQDKBtwbEhR9cz+rPizVjw56dfP34= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VBVB82s1Wz4f3kGJ; Sat, 6 Apr 2024 17:17:36 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 0FC4D1A0C75; Sat, 6 Apr 2024 17:17:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S6; Sat, 06 Apr 2024 17:17:42 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 02/26] block: remove sync_blockdev_nowait() Date: Sat, 6 Apr 2024 17:09:06 +0800 Message-Id: <20240406090930.2252838-3-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S6 X-Coremail-Antispam: 1UD129KBjvJXoWxuryfJr17WF13ury5CF47twb_yoW5ZFy3pF nxAFZ7GrW8WF18WFs2vw4DZrySg3Wqk3yxCFyFvw1YvFWqqrs2gF9YyFyrAFW0vrZ7ArW2 qFWxury5uFy5C3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBYb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I 0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7IU8fcTPUUUUU== X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai Now that all filesystems stash the bdev file, it's ok to flush the file mapping directly. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- block/bdev.c | 8 -------- fs/fat/inode.c | 2 +- fs/ntfs3/inode.c | 2 +- fs/sync.c | 9 ++++++--- include/linux/blkdev.h | 5 ----- 5 files changed, 8 insertions(+), 18 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index 621b9163c0f6..c9b056782c96 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -188,14 +188,6 @@ int sb_min_blocksize(struct super_block *sb, int size) EXPORT_SYMBOL(sb_min_blocksize); -int sync_blockdev_nowait(struct block_device *bdev) -{ - if (!bdev) - return 0; - return filemap_flush(bdev->bd_inode->i_mapping); -} -EXPORT_SYMBOL_GPL(sync_blockdev_nowait); - /* * Write out and wait upon all the dirty data associated with a block * device via its mapping. Does not take the superblock lock. diff --git a/fs/fat/inode.c b/fs/fat/inode.c index d9e6fbb6f246..ef2ac3e7c3a8 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c @@ -1945,7 +1945,7 @@ int fat_flush_inodes(struct super_block *sb, struct inode *i1, struct inode *i2) if (!ret && i2) ret = writeback_inode(i2); if (!ret) - ret = sync_blockdev_nowait(sb->s_bdev); + ret = filemap_flush(sb->s_bdev_file->f_mapping); return ret; } EXPORT_SYMBOL_GPL(fat_flush_inodes); diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index eb7a8c9fba01..3c4c878f6d77 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -1081,7 +1081,7 @@ int ntfs_flush_inodes(struct super_block *sb, struct inode *i1, if (!ret && i2) ret = writeback_inode(i2); if (!ret) - ret = sync_blockdev_nowait(sb->s_bdev); + ret = filemap_flush(sb->s_bdev_file->f_mapping); return ret; } diff --git a/fs/sync.c b/fs/sync.c index dc725914e1ed..3a43062790d9 100644 --- a/fs/sync.c +++ b/fs/sync.c @@ -57,9 +57,12 @@ int sync_filesystem(struct super_block *sb) if (ret) return ret; } - ret = sync_blockdev_nowait(sb->s_bdev); - if (ret) - return ret; + + if (sb->s_bdev_file) { + ret = filemap_flush(sb->s_bdev_file->f_mapping); + if (ret) + return ret; + } sync_inodes_sb(sb); if (sb->s_op->sync_fs) { diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 2c0d3a89002c..433c880299a6 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1533,7 +1533,6 @@ unsigned int block_size(struct block_device *bdev); void invalidate_bdev(struct block_device *bdev); int sync_blockdev(struct block_device *bdev); int sync_blockdev_range(struct block_device *bdev, loff_t lstart, loff_t lend); -int sync_blockdev_nowait(struct block_device *bdev); void sync_bdevs(bool wait); void bdev_statx_dioalign(struct inode *inode, struct kstat *stat); void printk_all_partitions(void); @@ -1546,10 +1545,6 @@ static inline int sync_blockdev(struct block_device *bdev) { return 0; } -static inline int sync_blockdev_nowait(struct block_device *bdev) -{ - return 0; -} static inline void sync_bdevs(bool wait) { } From patchwork Sat Apr 6 09:09:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619737 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51E0213ACC; Sat, 6 Apr 2024 09:17:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395068; cv=none; b=gObCR1ksnmoUokaVh/pBspLfpjogOOUM1xjp2E4JQ/LC+roeBrqiUrUs0oRuu66imCWPydsrIxvY8JnagHwoVh6+kEczbp3qDpg66ACmL6o+e9iILe01Rpax2hAg9AbFX4QcHUMhwMlVY+tqFOI+fny3FaJLL7FbxZkv8MWeAFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395068; c=relaxed/simple; bh=H82D58NOgy0o7/74tqwrG1s/n91s+R+aCwnBgkogdlU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=prHEo+ozUuKnbt3COZ1OgwESnRuCKxpVVp3IQFJlEfnFfpxSMF4/TxsyZprISxKAKuU4xlkWp+94JIHdApbrhklBXc5HqDRAAqLImpRiBJ8GBSLLlEc8qpAGfdV0uXYR6pmK3v/OlafXXDS4ZcRQLoWiwst68ShnTVXKsCW8Dvg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVBC13jKz4f3jkT; Sat, 6 Apr 2024 17:17:39 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 725EC1A016E; Sat, 6 Apr 2024 17:17:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S7; Sat, 06 Apr 2024 17:17:43 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 03/26] block: remove sync_blockdev_range() Date: Sat, 6 Apr 2024 17:09:07 +0800 Message-Id: <20240406090930.2252838-4-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S7 X-Coremail-Antispam: 1UD129KBjvJXoWxuryfJr17WryxJr15ZrW3trb_yoWrXr17pF 9xCF93GrW8Gr4DWF4UCa1xAw1FgwnFk34xAr9xZ3yFq3yDtr9xKryktr1YyayUtrZ3JrWD XFy29a4SgF1xCaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBYb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I 0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7IU1c4S7UUUUU== X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai Now that all filesystems stash the bdev file, it's ok to flush the file mapping directly. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- block/bdev.c | 7 ------- fs/btrfs/volumes.c | 12 +++++++----- fs/exfat/fatent.c | 2 +- include/linux/blkdev.h | 1 - 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index c9b056782c96..d53bf2f46b43 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -200,13 +200,6 @@ int sync_blockdev(struct block_device *bdev) } EXPORT_SYMBOL(sync_blockdev); -int sync_blockdev_range(struct block_device *bdev, loff_t lstart, loff_t lend) -{ - return filemap_write_and_wait_range(bdev->bd_inode->i_mapping, - lstart, lend); -} -EXPORT_SYMBOL(sync_blockdev_range); - /** * bdev_freeze - lock a filesystem and force it into a consistent state * @bdev: blockdevice to lock diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 1dc1f1946ae0..6f130c749dbc 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2050,14 +2050,14 @@ static u64 btrfs_num_devices(struct btrfs_fs_info *fs_info) } static void btrfs_scratch_superblock(struct btrfs_fs_info *fs_info, - struct block_device *bdev, int copy_num) + struct file *bdev_file, int copy_num) { struct btrfs_super_block *disk_super; const size_t len = sizeof(disk_super->magic); const u64 bytenr = btrfs_sb_offset(copy_num); int ret; - disk_super = btrfs_read_disk_super(bdev, bytenr, bytenr); + disk_super = btrfs_read_disk_super(file_bdev(bdev_file), bytenr, bytenr); if (IS_ERR(disk_super)) return; @@ -2065,7 +2065,8 @@ static void btrfs_scratch_superblock(struct btrfs_fs_info *fs_info, folio_mark_dirty(virt_to_folio(disk_super)); btrfs_release_disk_super(disk_super); - ret = sync_blockdev_range(bdev, bytenr, bytenr + len - 1); + ret = filemap_write_and_wait_range(bdev_file->f_mapping, + bytenr, bytenr + len - 1); if (ret) btrfs_warn(fs_info, "error clearing superblock number %d (%d)", copy_num, ret); @@ -2075,15 +2076,16 @@ void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info, struct btrfs_devic { int copy_num; struct block_device *bdev = device->bdev; + struct file *bdev_file = device->bdev_file; - if (!bdev) + if (!bdev || !bdev_file) return; for (copy_num = 0; copy_num < BTRFS_SUPER_MIRROR_MAX; copy_num++) { if (bdev_is_zoned(bdev)) btrfs_reset_sb_log_zones(bdev, copy_num); else - btrfs_scratch_superblock(fs_info, bdev, copy_num); + btrfs_scratch_superblock(fs_info, bdev_file, copy_num); } /* Notify udev that device has changed */ diff --git a/fs/exfat/fatent.c b/fs/exfat/fatent.c index 56b870d9cc0d..1c86ec2465b7 100644 --- a/fs/exfat/fatent.c +++ b/fs/exfat/fatent.c @@ -296,7 +296,7 @@ int exfat_zeroed_cluster(struct inode *dir, unsigned int clu) } if (IS_DIRSYNC(dir)) - return sync_blockdev_range(sb->s_bdev, + return filemap_write_and_wait_range(sb->s_bdev_file->f_mapping, EXFAT_BLK_TO_B(blknr, sb), EXFAT_BLK_TO_B(last_blknr, sb) - 1); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 433c880299a6..08d4e6a0940c 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1532,7 +1532,6 @@ unsigned int block_size(struct block_device *bdev); #ifdef CONFIG_BLOCK void invalidate_bdev(struct block_device *bdev); int sync_blockdev(struct block_device *bdev); -int sync_blockdev_range(struct block_device *bdev, loff_t lstart, loff_t lend); void sync_bdevs(bool wait); void bdev_statx_dioalign(struct inode *inode, struct kstat *stat); void printk_all_partitions(void); From patchwork Sat Apr 6 09:09:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619742 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5DCF1EB48; Sat, 6 Apr 2024 09:17:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395069; cv=none; b=feRkUrBH2ybStQ0h7oMsk0U8CIy4OVYZUVw+szmIU5mUvKSwC0yCaj2MumUhCcWta3A04vYEXVYbPVJ/Q56/VnZSLPNKxmsZ8No8lHqlbCOJ3w54y5ZtP+1fzyNA83Oa7eyDn4aEtnUFXagUYv9T3zmxpjzJgAGimT5jPJUIwv8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395069; c=relaxed/simple; bh=WyMUYItZQMIEqD1988qNBPb2DZ7ZwiQAtYkhpZgr4Nc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lBW5t/Kaol3yOrou6Jvdf1O2QM8ZGxeFQZ1cuTo5a4PgHqo/B0viFS80uGESXrPudPGitK4LtBbT6ypJ44Jqb1/ag6X3lWV1Pp8lkD0CGjXMi6KSWH9uRwUWTUv4MPsiq/jH3/aXXJRRLoKzhHovsK6DgyHkxyu78MAnckpoeUM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVB72nG3z4f3l20; Sat, 6 Apr 2024 17:17:35 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id D95411A0B8A; Sat, 6 Apr 2024 17:17:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S8; Sat, 06 Apr 2024 17:17:43 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 04/26] block: prevent direct access of bd_inode Date: Sat, 6 Apr 2024 17:09:08 +0800 Message-Id: <20240406090930.2252838-5-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S8 X-Coremail-Antispam: 1UD129KBjvAXoWfXr15ZF13Cw4rtw4DAFy5urg_yoW8JF1xZo W3Jr13Xr4rJrW5W3yxGas7AFyjq39rCws5CFn8Zr1Dua1rtw1jkw17Ga15AFyru3WrKr1I vryxJFyrJFW5CFs3n29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjp_UUUYC7kC6x804xWl14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK 8VAvwI8IcIk0rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF 0E3s1l82xGYIkIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vE j48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxV AFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x02 67AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I 80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCj c4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4IIrI8v6xkF7I0E8cxan2IY04v7MxAIw28Icx kI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2Iq xVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42 IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY 6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aV CY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07UZo7tUUUUU= X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai Add helpers to access bd_inode, prepare to remove the field 'bd_inode' after removing all the access from filesystems and drivers. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- block/bdev.c | 58 +++++++++++++++++++++++++++-------------- block/blk-zoned.c | 4 +-- block/blk.h | 2 ++ block/fops.c | 2 +- block/genhd.c | 9 ++++--- block/ioctl.c | 8 +++--- block/partitions/core.c | 8 +++--- 7 files changed, 56 insertions(+), 35 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index d53bf2f46b43..c0b30392563a 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -43,6 +43,21 @@ static inline struct bdev_inode *BDEV_I(struct inode *inode) return container_of(inode, struct bdev_inode, vfs_inode); } +static inline struct bdev_inode *BDEV_B(struct block_device *bdev) +{ + return container_of(bdev, struct bdev_inode, bdev); +} + +struct inode *bdev_inode(struct block_device *bdev) +{ + return &BDEV_B(bdev)->vfs_inode; +} + +struct address_space *bdev_mapping(struct block_device *bdev) +{ + return BDEV_B(bdev)->vfs_inode.i_mapping; +} + struct block_device *I_BDEV(struct inode *inode) { return &BDEV_I(inode)->bdev; @@ -57,7 +72,7 @@ EXPORT_SYMBOL(file_bdev); static void bdev_write_inode(struct block_device *bdev) { - struct inode *inode = bdev->bd_inode; + struct inode *inode = bdev_inode(bdev); int ret; spin_lock(&inode->i_lock); @@ -76,7 +91,7 @@ static void bdev_write_inode(struct block_device *bdev) /* Kill _all_ buffers and pagecache , dirty or not.. */ static void kill_bdev(struct block_device *bdev) { - struct address_space *mapping = bdev->bd_inode->i_mapping; + struct address_space *mapping = bdev_mapping(bdev); if (mapping_empty(mapping)) return; @@ -88,7 +103,7 @@ static void kill_bdev(struct block_device *bdev) /* Invalidate clean unused buffers and pagecache. */ void invalidate_bdev(struct block_device *bdev) { - struct address_space *mapping = bdev->bd_inode->i_mapping; + struct address_space *mapping = bdev_mapping(bdev); if (mapping->nrpages) { invalidate_bh_lrus(); @@ -116,7 +131,7 @@ int truncate_bdev_range(struct block_device *bdev, blk_mode_t mode, goto invalidate; } - truncate_inode_pages_range(bdev->bd_inode->i_mapping, lstart, lend); + truncate_inode_pages_range(bdev_mapping(bdev), lstart, lend); if (!(mode & BLK_OPEN_EXCL)) bd_abort_claiming(bdev, truncate_bdev_range); return 0; @@ -126,7 +141,7 @@ int truncate_bdev_range(struct block_device *bdev, blk_mode_t mode, * Someone else has handle exclusively open. Try invalidating instead. * The 'end' argument is inclusive so the rounding is safe. */ - return invalidate_inode_pages2_range(bdev->bd_inode->i_mapping, + return invalidate_inode_pages2_range(bdev_mapping(bdev), lstart >> PAGE_SHIFT, lend >> PAGE_SHIFT); } @@ -134,14 +149,14 @@ int truncate_bdev_range(struct block_device *bdev, blk_mode_t mode, static void set_init_blocksize(struct block_device *bdev) { unsigned int bsize = bdev_logical_block_size(bdev); - loff_t size = i_size_read(bdev->bd_inode); + loff_t size = i_size_read(bdev_inode(bdev)); while (bsize < PAGE_SIZE) { if (size & bsize) break; bsize <<= 1; } - bdev->bd_inode->i_blkbits = blksize_bits(bsize); + bdev_inode(bdev)->i_blkbits = blksize_bits(bsize); } int set_blocksize(struct block_device *bdev, int size) @@ -155,9 +170,9 @@ int set_blocksize(struct block_device *bdev, int size) return -EINVAL; /* Don't change the size if it is same as current */ - if (bdev->bd_inode->i_blkbits != blksize_bits(size)) { + if (bdev_inode(bdev)->i_blkbits != blksize_bits(size)) { sync_blockdev(bdev); - bdev->bd_inode->i_blkbits = blksize_bits(size); + bdev_inode(bdev)->i_blkbits = blksize_bits(size); kill_bdev(bdev); } return 0; @@ -196,7 +211,7 @@ int sync_blockdev(struct block_device *bdev) { if (!bdev) return 0; - return filemap_write_and_wait(bdev->bd_inode->i_mapping); + return filemap_write_and_wait(bdev_mapping(bdev)); } EXPORT_SYMBOL(sync_blockdev); @@ -415,19 +430,22 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno) void bdev_set_nr_sectors(struct block_device *bdev, sector_t sectors) { spin_lock(&bdev->bd_size_lock); - i_size_write(bdev->bd_inode, (loff_t)sectors << SECTOR_SHIFT); + i_size_write(bdev_inode(bdev), (loff_t)sectors << SECTOR_SHIFT); bdev->bd_nr_sectors = sectors; spin_unlock(&bdev->bd_size_lock); } void bdev_add(struct block_device *bdev, dev_t dev) { + struct inode *inode; + if (bdev_stable_writes(bdev)) - mapping_set_stable_writes(bdev->bd_inode->i_mapping); + mapping_set_stable_writes(bdev_mapping(bdev)); bdev->bd_dev = dev; - bdev->bd_inode->i_rdev = dev; - bdev->bd_inode->i_ino = dev; - insert_inode_hash(bdev->bd_inode); + inode = bdev_inode(bdev); + inode->i_rdev = dev; + inode->i_ino = dev; + insert_inode_hash(inode); } long nr_blockdev_pages(void) @@ -893,7 +911,7 @@ int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder, bdev_file->f_mode |= FMODE_NOWAIT; if (mode & BLK_OPEN_RESTRICT_WRITES) bdev_file->f_mode |= FMODE_WRITE_RESTRICTED; - bdev_file->f_mapping = bdev->bd_inode->i_mapping; + bdev_file->f_mapping = bdev_mapping(bdev); bdev_file->f_wb_err = filemap_sample_wb_err(bdev_file->f_mapping); bdev_file->private_data = holder; @@ -955,13 +973,13 @@ struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, return ERR_PTR(-ENXIO); flags = blk_to_file_flags(mode); - bdev_file = alloc_file_pseudo_noaccount(bdev->bd_inode, + bdev_file = alloc_file_pseudo_noaccount(bdev_inode(bdev), blockdev_mnt, "", flags | O_LARGEFILE, &def_blk_fops); if (IS_ERR(bdev_file)) { blkdev_put_no_open(bdev); return bdev_file; } - ihold(bdev->bd_inode); + ihold(bdev_inode(bdev)); ret = bdev_open(bdev, mode, holder, hops, bdev_file); if (ret) { @@ -1238,13 +1256,13 @@ void bdev_statx_dioalign(struct inode *inode, struct kstat *stat) bool disk_live(struct gendisk *disk) { - return !inode_unhashed(disk->part0->bd_inode); + return !inode_unhashed(bdev_inode(disk->part0)); } EXPORT_SYMBOL_GPL(disk_live); unsigned int block_size(struct block_device *bdev) { - return 1 << bdev->bd_inode->i_blkbits; + return 1 << bdev_inode(bdev)->i_blkbits; } EXPORT_SYMBOL_GPL(block_size); diff --git a/block/blk-zoned.c b/block/blk-zoned.c index da0f4b2a8fa0..7e6805250317 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -398,7 +398,7 @@ int blkdev_zone_mgmt_ioctl(struct block_device *bdev, blk_mode_t mode, op = REQ_OP_ZONE_RESET; /* Invalidate the page cache, including dirty pages. */ - filemap_invalidate_lock(bdev->bd_inode->i_mapping); + filemap_invalidate_lock(bdev_mapping(bdev)); ret = blkdev_truncate_zone_range(bdev, mode, &zrange); if (ret) goto fail; @@ -420,7 +420,7 @@ int blkdev_zone_mgmt_ioctl(struct block_device *bdev, blk_mode_t mode, fail: if (cmd == BLKRESETZONE) - filemap_invalidate_unlock(bdev->bd_inode->i_mapping); + filemap_invalidate_unlock(bdev_mapping(bdev)); return ret; } diff --git a/block/blk.h b/block/blk.h index 5cac4e29ae17..a34bb590cce6 100644 --- a/block/blk.h +++ b/block/blk.h @@ -427,6 +427,8 @@ static inline int blkdev_zone_mgmt_ioctl(struct block_device *bdev, } #endif /* CONFIG_BLK_DEV_ZONED */ +struct inode *bdev_inode(struct block_device *bdev); +struct address_space *bdev_mapping(struct block_device *bdev); struct block_device *bdev_alloc(struct gendisk *disk, u8 partno); void bdev_add(struct block_device *bdev, dev_t dev); diff --git a/block/fops.c b/block/fops.c index af6c244314af..58b427051c0d 100644 --- a/block/fops.c +++ b/block/fops.c @@ -669,7 +669,7 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) { struct file *file = iocb->ki_filp; struct block_device *bdev = I_BDEV(file->f_mapping->host); - struct inode *bd_inode = bdev->bd_inode; + struct inode *bd_inode = bdev_inode(bdev); loff_t size = bdev_nr_bytes(bdev); size_t shorted = 0; ssize_t ret; diff --git a/block/genhd.c b/block/genhd.c index bb29a68e1d67..9a7d1b7e9e95 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -656,7 +656,7 @@ void del_gendisk(struct gendisk *disk) */ mutex_lock(&disk->open_mutex); xa_for_each(&disk->part_tbl, idx, part) - remove_inode_hash(part->bd_inode); + remove_inode_hash(bdev_inode(part)); mutex_unlock(&disk->open_mutex); /* @@ -745,7 +745,7 @@ void invalidate_disk(struct gendisk *disk) struct block_device *bdev = disk->part0; invalidate_bdev(bdev); - bdev->bd_inode->i_mapping->wb_err = 0; + bdev_mapping(bdev)->wb_err = 0; set_capacity(disk, 0); } EXPORT_SYMBOL(invalidate_disk); @@ -1191,7 +1191,8 @@ static void disk_release(struct device *dev) if (test_bit(GD_ADDED, &disk->state) && disk->fops->free_disk) disk->fops->free_disk(disk); - iput(disk->part0->bd_inode); /* frees the disk */ + /* frees the disk */ + iput(bdev_inode(disk->part0)); } static int block_uevent(const struct device *dev, struct kobj_uevent_env *env) @@ -1381,7 +1382,7 @@ struct gendisk *__alloc_disk_node(struct request_queue *q, int node_id, out_destroy_part_tbl: xa_destroy(&disk->part_tbl); disk->part0->bd_disk = NULL; - iput(disk->part0->bd_inode); + iput(bdev_inode(disk->part0)); out_free_bdi: bdi_put(disk->bdi); out_free_bioset: diff --git a/block/ioctl.c b/block/ioctl.c index 0c76137adcaa..0f78806abb62 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -97,7 +97,7 @@ static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode, { uint64_t range[2]; uint64_t start, len; - struct inode *inode = bdev->bd_inode; + struct inode *inode = bdev_inode(bdev); int err; if (!(mode & BLK_OPEN_WRITE)) @@ -151,12 +151,12 @@ static int blk_ioctl_secure_erase(struct block_device *bdev, blk_mode_t mode, if (start + len > bdev_nr_bytes(bdev)) return -EINVAL; - filemap_invalidate_lock(bdev->bd_inode->i_mapping); + filemap_invalidate_lock(bdev_mapping(bdev)); err = truncate_bdev_range(bdev, mode, start, start + len - 1); if (!err) err = blkdev_issue_secure_erase(bdev, start >> 9, len >> 9, GFP_KERNEL); - filemap_invalidate_unlock(bdev->bd_inode->i_mapping); + filemap_invalidate_unlock(bdev_mapping(bdev)); return err; } @@ -166,7 +166,7 @@ static int blk_ioctl_zeroout(struct block_device *bdev, blk_mode_t mode, { uint64_t range[2]; uint64_t start, end, len; - struct inode *inode = bdev->bd_inode; + struct inode *inode = bdev_inode(bdev); int err; if (!(mode & BLK_OPEN_WRITE)) diff --git a/block/partitions/core.c b/block/partitions/core.c index b11e88c82c8c..ddd418758fa4 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -243,7 +243,7 @@ static const struct attribute_group *part_attr_groups[] = { static void part_release(struct device *dev) { put_disk(dev_to_bdev(dev)->bd_disk); - iput(dev_to_bdev(dev)->bd_inode); + iput(bdev_inode(dev_to_bdev(dev))); } static int part_uevent(const struct device *dev, struct kobj_uevent_env *env) @@ -469,7 +469,7 @@ int bdev_del_partition(struct gendisk *disk, int partno) * Just delete the partition and invalidate it. */ - remove_inode_hash(part->bd_inode); + remove_inode_hash(bdev_inode(part)); invalidate_bdev(part); drop_partition(part); ret = 0; @@ -655,7 +655,7 @@ int bdev_disk_changed(struct gendisk *disk, bool invalidate) * it cannot be looked up any more even when openers * still hold references. */ - remove_inode_hash(part->bd_inode); + remove_inode_hash(bdev_inode(part)); /* * If @disk->open_partitions isn't elevated but there's @@ -704,7 +704,7 @@ EXPORT_SYMBOL_GPL(bdev_disk_changed); void *read_part_sector(struct parsed_partitions *state, sector_t n, Sector *p) { - struct address_space *mapping = state->disk->part0->bd_inode->i_mapping; + struct address_space *mapping = bdev_mapping(state->disk->part0); struct folio *folio; if (n >= get_capacity(state->disk)) { From patchwork Sat Apr 6 09:09:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619741 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78E54225CF; Sat, 6 Apr 2024 09:17:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395069; cv=none; b=cmK+oZVeAJ+hKzt4sJW/jXiH1pQHJNM0mm7oNsoCcH4DeNYNcHbBk9G1d+JS29mpA8Kof/DGLXveRsU8PO6EWx30xI5UBmQKU9PETHN2f52j+C5LU955nt9EIHJOyE9o6ryVsblyYyKC3+p+DDj7SrgQURNtPiXUU3VutCT2p9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395069; c=relaxed/simple; bh=cqaJwJ89c1NnHHCX2IeUwDZs+ZSvdbogTUh2DBgyGXk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hWf+6Hk9hzNpivq29ndyo8HHDq7TIO3RK//9r95RuuZ2wig516ErSTw230tAXCC8GPsa7LCwAK8CVsd+1XqQs/rhb/bhDToVcuYVkyxwiwrJonQCC07HaOuW4YkobBWNAzhFKN0KvL5EPL27/xp1iYGYwp0TmtpKF9st4AF7n2A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVBC6wzqz4f3k69; Sat, 6 Apr 2024 17:17:39 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 4A5D51A0BF8; Sat, 6 Apr 2024 17:17:44 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S9; Sat, 06 Apr 2024 17:17:44 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 05/26] block: add a helper bdev_read_folio() Date: Sat, 6 Apr 2024 17:09:09 +0800 Message-Id: <20240406090930.2252838-6-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S9 X-Coremail-Antispam: 1UD129KBjvJXoW7Cr17XF1UXFWfKrW5Wr1xKrg_yoW8uFW3pF 9rGay5CrW8GFnrWF47Z3W7Xw1fK3y0kw1fCFWa9r1SkrWUtrZ7uFyvyr1UAryjkws7JF4v qFy7ury0gryjkrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBab4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY 6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aV CY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07UZo7tUUUUU= X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai Currently scsi driver is reading without opening disk as file( scsi_bios_ptable()), factor out a helper to read into block device page cache to prevent access bd_inode directly from scsi. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- block/bdev.c | 19 +++++++++++++++++++ include/linux/blkdev.h | 1 + 2 files changed, 20 insertions(+) diff --git a/block/bdev.c b/block/bdev.c index c0b30392563a..4335df6d1266 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -1266,6 +1266,25 @@ unsigned int block_size(struct block_device *bdev) } EXPORT_SYMBOL_GPL(block_size); +/** + * bdev_read_folio - Read into block device page cache. + * @bdev: the block device which holds the cache to read. + * @pos: the offset that allocated folio will contain. + * + * Read one page into the block device page cache. If it succeeds, the folio + * returned will contain @pos; + * + * This is only used for scsi_bios_ptable(), the bdev is not opened as files. + * + * Return: Uptodate folio on success, ERR_PTR() on failure. + */ +struct folio *bdev_read_folio(struct block_device *bdev, loff_t pos) +{ + return mapping_read_folio_gfp(bdev_mapping(bdev), + pos >> PAGE_SHIFT, GFP_KERNEL); +} +EXPORT_SYMBOL_GPL(bdev_read_folio); + static int __init setup_bdev_allow_write_mounted(char *str) { if (kstrtobool(str, &bdev_allow_write_mounted)) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 08d4e6a0940c..bc840e0fb6e5 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1519,6 +1519,7 @@ struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode, int bd_prepare_to_claim(struct block_device *bdev, void *holder, const struct blk_holder_ops *hops); void bd_abort_claiming(struct block_device *bdev, void *holder); +struct folio *bdev_read_folio(struct block_device *bdev, loff_t pos); /* just for blk-cgroup, don't use elsewhere */ struct block_device *blkdev_get_no_open(dev_t dev); From patchwork Sat Apr 6 09:09:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619740 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E44B122EEF; Sat, 6 Apr 2024 09:17:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395069; cv=none; b=ui8QJO1IANe8QUXv7513ajbxA4KtyUA0F4wZB22i2jGs2qcrJ6OTfrJlrqj+3jrbdv9UMDwBi0nzPCKjzF9VIv53M4ALYY9591DR1w4L6NWBnyHp4aJPTh6oBaP4aHUHjqhIIPMz8OAWaKeiR8QzeIxGpIZfqZjxmV49JO+WgSw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395069; c=relaxed/simple; bh=hoYLFcyt/54sHLbfIn1CPiTJleIS23+rpBc2pLFqVDg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uAk3pQjkrOLCQGjOeCr9AdbPqwLUUm0ovRfJMfwD3p05kPKhpF4gL9vwYaI2x4Xmcm+iGDRy6mzQ79ZHl99UkaoRqw5vn/4L146Ej7BGd/sf8gCXLvONhxVt7Berrj0fshZKcSy/4VXD6cCs7VRJSgicE+yhtyGg6zazQNNEngo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVBD2dL6z4f3k6C; Sat, 6 Apr 2024 17:17:40 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id AAE801A0C0A; Sat, 6 Apr 2024 17:17:44 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S10; Sat, 06 Apr 2024 17:17:44 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 06/26] bcachefs: remove dead function bdev_sectors() Date: Sat, 6 Apr 2024 17:09:10 +0800 Message-Id: <20240406090930.2252838-7-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S10 X-Coremail-Antispam: 1UD129KBjvdXoWrZFyrKrWkur47uFWrJryxXwb_yoWfJFb_KF 9avF17uw4IqF1F93ZxXrnYvr40v34jqry29Fs0q3WxJ3WDJrZ3XFZ5GrZ8Zrs7W397ua42 qayxJrZF9ryS9jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbSkYFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r126s 0DM28IrcIa0xkI8VCY1x0267AKxVW5JVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4AK67xG Y2AK021l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14 v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAF wI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2 WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkE bVWUJVW8JwACjcxG0xvY0x0EwIxGrwACI402YVCY1x02628vn2kIc2xKxwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6x kF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7IU13l1DUUUUU== X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai bdev_sectors() is not used hence remove it. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- fs/bcachefs/util.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h index 175aee3074c7..960827eddff1 100644 --- a/fs/bcachefs/util.h +++ b/fs/bcachefs/util.h @@ -445,11 +445,6 @@ static inline unsigned fract_exp_two(unsigned x, unsigned fract_bits) void bch2_bio_map(struct bio *bio, void *base, size_t); int bch2_bio_alloc_pages(struct bio *, size_t, gfp_t); -static inline sector_t bdev_sectors(struct block_device *bdev) -{ - return bdev->bd_inode->i_size >> 9; -} - #define closure_bio_submit(bio, cl) \ do { \ closure_get(cl); \ From patchwork Sat Apr 6 09:09:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619743 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2E8922EED; Sat, 6 Apr 2024 09:17:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395069; cv=none; b=LnAu2Vl2gHboOt7IVsbhQx4zo7bL/330VF2rfKNrnsqsoZO3+N3YzX1dPsUWWMBHn5k91ZGrF0sQ6EJjy0xWbFGp+hGQ6gfAW3tC1/ELlfbJA0lGjn071Jftd6/RNaoEd8truxrHQeTdfST6WdOS6I69u++pK0hOhiYIForSiF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395069; c=relaxed/simple; bh=VeY/gOgLFypQc0FglGRPZyMAihZTyTp1W5didLMJ+bk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=J4/GoovWe3uGX7zmI8yeK26QueDVrAIKu2nTr/ptK7FBS73kWhN2isNfn9BKSSV/zP3Wx/Za9Yg187pFDP29xM9XgKL8WtxBAH6R6zhKKrvYGBz0f2KuoB/y8mXr+b0i3r5U8wUVUURt8+vNCs7OA4ZPnlWGicPo42o9+Bgp1jI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVB84Kd1z4f3lfY; Sat, 6 Apr 2024 17:17:36 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 1ACCB1A0572; Sat, 6 Apr 2024 17:17:45 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S11; Sat, 06 Apr 2024 17:17:44 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 07/26] cramfs: prevent direct access of bd_inode Date: Sat, 6 Apr 2024 17:09:11 +0800 Message-Id: <20240406090930.2252838-8-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S11 X-Coremail-Antispam: 1UD129KBjvdXoW7XFW8CrWUWr45tr1xWry7trb_yoWfArX_Aa 40kr1rWw1fXwn3uws8Wwn8Zr409w45Krs7uFZxKr9xJryrJF93Crs7Xr18Wr4DJr4UXFZ8 GFn7XF48Jr9F9jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbSkYFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r126s 0DM28IrcIa0xkI8VCY1x0267AKxVW5JVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4AK67xG Y2AK021l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14 v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAF wI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2 WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkE bVWUJVW8JwACjcxG0xvY0x0EwIxGrwACI402YVCY1x02628vn2kIc2xKxwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6x kF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7IU13l1DUUUUU== X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai Now that all filesystems stash the bdev file, it's ok to get bdev mapping from the file directly. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- fs/cramfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c index 9901057a15ba..38416c245ced 100644 --- a/fs/cramfs/inode.c +++ b/fs/cramfs/inode.c @@ -183,7 +183,7 @@ static int next_buffer; static void *cramfs_blkdev_read(struct super_block *sb, unsigned int offset, unsigned int len) { - struct address_space *mapping = sb->s_bdev->bd_inode->i_mapping; + struct address_space *mapping = sb->s_bdev_file->f_mapping; struct file_ra_state ra = {}; struct page *pages[BLKS_PER_BUF]; unsigned i, blocknr, buffer; From patchwork Sat Apr 6 09:09:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619744 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97D7E23767; Sat, 6 Apr 2024 09:17:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395070; cv=none; b=Bc18Qz8IUmlEd7jaYjdA6gL81917h+a9soH/orsgK3xPbs3ym9HBhC752pJSAyj++uDVhJ9uyZT+HzRZD72G5yRuJtpcBmXzmQlF+85M9Y+FYoZUAEiN/uIpIvHmMLn6KL0WpD7sAPXqqK2JTSAhr+pq1SiJbq5J1YhIhRihP/0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395070; c=relaxed/simple; bh=f/0h0prYtUZuwCmQrVaP5W+SeMu7SBeETNVjpeCDMuw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eC4m/Gx9jz9S6gGEyQF81lI4/agpgol3cvKcFzgckN0miZYt+FXJaKs3pZo3QrDr1F7opma5CFkRV3RRk3na/fPN6uEN7T8kPGyzbYafH+EIuIfyDtPFjz5lJmisfhNw4mINIwKg1tc9r9EMLETI8fsl0p1bPCKavtI7agL71w8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVBF1RZWz4f3k6X; Sat, 6 Apr 2024 17:17:41 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 800151A0572; Sat, 6 Apr 2024 17:17:45 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S12; Sat, 06 Apr 2024 17:17:45 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 08/26] erofs: prevent direct access of bd_inode Date: Sat, 6 Apr 2024 17:09:12 +0800 Message-Id: <20240406090930.2252838-9-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S12 X-Coremail-Antispam: 1UD129KBjvdXoW7XFW8CryfJry3Aw4UZr43Wrg_yoWfWwc_ZF yIyr48W3y7X34ftFZ5C3W5Zr4v9a1FkFsY9F43JrZxWF1UJrykZrWDJw4rJrsrWw4kKFZ8 AFs3WF47tryYqjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbSkYFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r126s 0DM28IrcIa0xkI8VCY1x0267AKxVW5JVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4AK67xG Y2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14 v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAF wI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2 WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkE bVWUJVW8JwACjcxG0xvY0x0EwIxGrwACI402YVCY1x02628vn2kIc2xKxwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6x kF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7IU13l1DUUUUU== X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai Now that all filesystems stash the bdev file, it's ok to get inode for the file. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara Reviewed-by: Gao Xiang --- fs/erofs/data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index 52524bd9698b..b0a55b4d8c30 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -70,7 +70,7 @@ void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb) if (erofs_is_fscache_mode(sb)) buf->inode = EROFS_SB(sb)->s_fscache->inode; else - buf->inode = sb->s_bdev->bd_inode; + buf->inode = file_inode(sb->s_bdev_file); } void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb, From patchwork Sat Apr 6 09:09:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619745 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF8C225763; Sat, 6 Apr 2024 09:17:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395070; cv=none; b=VROq+m7R90jpyycgnPFb8785uWXX3JqGCeg9jJSDqywITRtiFOUBw3USphKIhmt1GDKz9Ft1HUugacFQDMGuCg4TcVphWl6zViD+ckJGkqJyf2jxvvQXDprnMGpZ4G66hH/Dxnkdv4CwT+KyNLMNLq1BBu6+/Z5nlgwQr6NwnxY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395070; c=relaxed/simple; bh=6vvdk+m0o/gxsdQdLbxhN1AmOBQxitEqsibAbJfs3zs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Gn3FV6N7GEyhWSD+8PWkRVywz3z4TNxwz5OpCXddz15n5dZVemcJR4yWlbrctT4QUmJDYytD+/EhfM9cxlgFiQDdtcBQY+38+jtlFTgQ13curCqxjZ7VFlyOh8UkARLvVB4odyphBSibOMEchBiGR9vpHJQLPr5JQ2AWsrOVMBU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVB936sJz4f3lfn; Sat, 6 Apr 2024 17:17:37 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id E44481A0175; Sat, 6 Apr 2024 17:17:45 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S13; Sat, 06 Apr 2024 17:17:45 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 09/26] nilfs2: prevent direct access of bd_inode Date: Sat, 6 Apr 2024 17:09:13 +0800 Message-Id: <20240406090930.2252838-10-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S13 X-Coremail-Antispam: 1UD129KBjvdXoW7XFW8Cry3Kw4kGF1ruF47XFb_yoWfGFXEvF yrAr1kX3yYqFWfua1DurWYvr9Yy3W0k3WrZrWfGFy5Kr18Z395Cr1DXr4UAayUury2q3Zx J3ZrXr98t34UWjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbSkYFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r126s 0DM28IrcIa0xkI8VCY1x0267AKxVW5JVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4AK67xG Y2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14 v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAF wI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2 WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkE bVWUJVW8JwACjcxG0xvY0x0EwIxGrwACI402YVCY1x02628vn2kIc2xKxwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6x kF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7IU13l1DUUUUU== X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai Now that all filesystems stash the bdev file, it's ok to get inode from the file. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- fs/nilfs2/segment.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c index aa5290cb7467..2940e8ef88f4 100644 --- a/fs/nilfs2/segment.c +++ b/fs/nilfs2/segment.c @@ -2790,7 +2790,7 @@ int nilfs_attach_log_writer(struct super_block *sb, struct nilfs_root *root) if (!nilfs->ns_writer) return -ENOMEM; - inode_attach_wb(nilfs->ns_bdev->bd_inode, NULL); + inode_attach_wb(file_inode(nilfs->ns_sb->s_bdev_file), NULL); err = nilfs_segctor_start_thread(nilfs->ns_writer); if (unlikely(err)) From patchwork Sat Apr 6 09:09:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619746 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6534932C96; Sat, 6 Apr 2024 09:17:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395071; cv=none; b=Bex5Wc2JpROnz18qAvq4HxU5ddDxjPJrLX8AACafDCOG852gwQuGdBePAw5fkc49HtYEeK+d/HLuoP4dqW55AF6NkfCybEn454gDFyyQVXDN/XT0TuqRYvRkGsXcNF+G1ZRfjQHqeBaEm7ZLcrSEl/1VYe+MD/+yMdB2OdjT+UQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395071; c=relaxed/simple; bh=yQzU2QHnCpMIuA4/zDVO/ONCg4v2ItF7Sta4U2/L2nk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SGyQKpzX/lEPpvme5IvxgoILzYUTi3p5QRIhVolTax4GPJ/E2E7czbpnmXswJGEQQRkrIUHzGGHnrPMOJKvT7SpLjzfLhH3Obz+DCOoYLFsN655gcqIIHA4KUWh1O3MalqoMR+KAAJhRz4W+R5vrucvUKdWedXqXhuOmQOqmLJw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVB967G7z4f3lft; Sat, 6 Apr 2024 17:17:37 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 5759B1A016E; Sat, 6 Apr 2024 17:17:46 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S14; Sat, 06 Apr 2024 17:17:46 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 10/26] gfs2: prevent direct access of bd_inode Date: Sat, 6 Apr 2024 17:09:14 +0800 Message-Id: <20240406090930.2252838-11-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S14 X-Coremail-Antispam: 1UD129KBjvJXoW7uryfury8KrW3tF45Wr1DAwb_yoW8GFy8pF 9xJF1UuF4kWFnIgaykZF4ft3WUuaykG3y0v34kZw1YvrsrKw13KrZFkF4DGa15Ja9rJws0 ga1ak3yavr1aqrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBSb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAI cVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2js IEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai Now that all filesystems stash the bdev file, it's ok to get inode from the file. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- fs/gfs2/glock.c | 2 +- fs/gfs2/ops_fstype.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 34540f9d011c..95ade8979f6b 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -1227,7 +1227,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, mapping = gfs2_glock2aspace(gl); if (mapping) { mapping->a_ops = &gfs2_meta_aops; - mapping->host = s->s_bdev->bd_inode; + mapping->host = file_inode(s->s_bdev_file); mapping->flags = 0; mapping_set_gfp_mask(mapping, GFP_NOFS); mapping->i_private_data = NULL; diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index 572d58e86296..4384cb39b06c 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -114,7 +114,7 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb) address_space_init_once(mapping); mapping->a_ops = &gfs2_rgrp_aops; - mapping->host = sb->s_bdev->bd_inode; + mapping->host = file_inode(sb->s_bdev_file); mapping->flags = 0; mapping_set_gfp_mask(mapping, GFP_NOFS); mapping->i_private_data = NULL; From patchwork Sat Apr 6 09:09:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619751 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43DC636B09; Sat, 6 Apr 2024 09:17:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395073; cv=none; b=Y8x8Fl9E++iguOG1j6hDsrbYnPu3SlHdve8J+B46WvQ9kPt9OaxCPIAcNMBIpgfvxD39hjkCGK1jHcz19lNetpa1ijvKWFshaTpe9jz319eZJ4NHKrjbvNNbHOKi9HPr5BvgqsnuklAY/AsIEod2TuXIPJR/398wmSm0CvhxaIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395073; c=relaxed/simple; bh=sBI5IP7HEIeGWKPvU1m2LBx55GGf+8Pouw7yjWnEM6Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Fgm99dmbE5RmIV9AeZcuuqYypv1t+LI2UgGH0iKDRuw3XxiPyxKNcKlvw19r+RKVtTG4BtlvEInWLmrESx88SlSzY6YcHKa0q5YbAUKgQzD5OgDiEIpvbEkTTb6RwuRMxaLnZau7m5RIWN80GScSauQUpPUZ1QkodPLFioZjWs4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVBB1m0nz4f3lg0; Sat, 6 Apr 2024 17:17:38 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id B76B51A0175; Sat, 6 Apr 2024 17:17:46 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S15; Sat, 06 Apr 2024 17:17:46 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 11/26] btrfs: prevent direct access of bd_inode Date: Sat, 6 Apr 2024 17:09:15 +0800 Message-Id: <20240406090930.2252838-12-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S15 X-Coremail-Antispam: 1UD129KBjvJXoW3CrW7JrWDZw1DurWkJFykAFb_yoWktr4Upr 98Aas5JrWUJr1DWayDWa1kAw1Sgw1vkayxCF93J3ySg39rtr90qFyqyr12yryrtrWkJr17 ZF4UK347Cr1IkF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBSb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAI cVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2js IEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai Now that all filesystems stash the bdev file, it's ok to get inode or mapping from the file. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- fs/btrfs/disk-io.c | 17 +++++++++-------- fs/btrfs/disk-io.h | 4 ++-- fs/btrfs/super.c | 2 +- fs/btrfs/volumes.c | 15 +++++++-------- fs/btrfs/zoned.c | 20 +++++++++++--------- fs/btrfs/zoned.h | 4 ++-- 6 files changed, 32 insertions(+), 30 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 3df5477d48a8..b565eef527a4 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3233,7 +3233,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device /* * Read super block and check the signature bytes only */ - disk_super = btrfs_read_dev_super(fs_devices->latest_dev->bdev); + disk_super = btrfs_read_dev_super(fs_devices->latest_dev->bdev_file); if (IS_ERR(disk_super)) { ret = PTR_ERR(disk_super); goto fail_alloc; @@ -3645,17 +3645,18 @@ static void btrfs_end_super_write(struct bio *bio) bio_put(bio); } -struct btrfs_super_block *btrfs_read_dev_one_super(struct block_device *bdev, +struct btrfs_super_block *btrfs_read_dev_one_super(struct file *bdev_file, int copy_num, bool drop_cache) { struct btrfs_super_block *super; struct page *page; u64 bytenr, bytenr_orig; - struct address_space *mapping = bdev->bd_inode->i_mapping; + struct block_device *bdev = file_bdev(bdev_file); + struct address_space *mapping = bdev_file->f_mapping; int ret; bytenr_orig = btrfs_sb_offset(copy_num); - ret = btrfs_sb_log_location_bdev(bdev, copy_num, READ, &bytenr); + ret = btrfs_sb_log_location_bdev(bdev_file, copy_num, READ, &bytenr); if (ret == -ENOENT) return ERR_PTR(-EINVAL); else if (ret) @@ -3696,7 +3697,7 @@ struct btrfs_super_block *btrfs_read_dev_one_super(struct block_device *bdev, } -struct btrfs_super_block *btrfs_read_dev_super(struct block_device *bdev) +struct btrfs_super_block *btrfs_read_dev_super(struct file *bdev_file) { struct btrfs_super_block *super, *latest = NULL; int i; @@ -3708,7 +3709,7 @@ struct btrfs_super_block *btrfs_read_dev_super(struct block_device *bdev) * later supers, using BTRFS_SUPER_MIRROR_MAX instead */ for (i = 0; i < 1; i++) { - super = btrfs_read_dev_one_super(bdev, i, false); + super = btrfs_read_dev_one_super(bdev_file, i, false); if (IS_ERR(super)) continue; @@ -3738,7 +3739,7 @@ static int write_dev_supers(struct btrfs_device *device, struct btrfs_super_block *sb, int max_mirrors) { struct btrfs_fs_info *fs_info = device->fs_info; - struct address_space *mapping = device->bdev->bd_inode->i_mapping; + struct address_space *mapping = device->bdev_file->f_mapping; SHASH_DESC_ON_STACK(shash, fs_info->csum_shash); int i; int errors = 0; @@ -3855,7 +3856,7 @@ static int wait_dev_supers(struct btrfs_device *device, int max_mirrors) device->commit_total_bytes) break; - page = find_get_page(device->bdev->bd_inode->i_mapping, + page = find_get_page(device->bdev_file->f_mapping, bytenr >> PAGE_SHIFT); if (!page) { errors++; diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index 76eb53fe7a11..8470426cd8e8 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -60,8 +60,8 @@ int btrfs_validate_super(struct btrfs_fs_info *fs_info, struct btrfs_super_block *sb, int mirror_num); int btrfs_check_features(struct btrfs_fs_info *fs_info, bool is_rw_mount); int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors); -struct btrfs_super_block *btrfs_read_dev_super(struct block_device *bdev); -struct btrfs_super_block *btrfs_read_dev_one_super(struct block_device *bdev, +struct btrfs_super_block *btrfs_read_dev_super(struct file *bdev_file); +struct btrfs_super_block *btrfs_read_dev_one_super(struct file *bdev_file, int copy_num, bool drop_cache); int btrfs_commit_super(struct btrfs_fs_info *fs_info); struct btrfs_root *btrfs_read_tree_root(struct btrfs_root *tree_root, diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 7e44ccaf348f..cbe64e9e22a8 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2289,7 +2289,7 @@ static int check_dev_super(struct btrfs_device *dev) return 0; /* Only need to check the primary super block. */ - sb = btrfs_read_dev_one_super(dev->bdev, 0, true); + sb = btrfs_read_dev_one_super(dev->bdev_file, 0, true); if (IS_ERR(sb)) return PTR_ERR(sb); diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 6f130c749dbc..e6c8b3a40ef7 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -488,7 +488,7 @@ btrfs_get_bdev_and_sb(const char *device_path, blk_mode_t flags, void *holder, goto error; } invalidate_bdev(bdev); - *disk_super = btrfs_read_dev_super(bdev); + *disk_super = btrfs_read_dev_super(*bdev_file); if (IS_ERR(*disk_super)) { ret = PTR_ERR(*disk_super); fput(*bdev_file); @@ -1248,7 +1248,7 @@ void btrfs_release_disk_super(struct btrfs_super_block *super) put_page(page); } -static struct btrfs_super_block *btrfs_read_disk_super(struct block_device *bdev, +static struct btrfs_super_block *btrfs_read_disk_super(struct file *bdev_file, u64 bytenr, u64 bytenr_orig) { struct btrfs_super_block *disk_super; @@ -1257,7 +1257,7 @@ static struct btrfs_super_block *btrfs_read_disk_super(struct block_device *bdev pgoff_t index; /* make sure our super fits in the device */ - if (bytenr + PAGE_SIZE >= bdev_nr_bytes(bdev)) + if (bytenr + PAGE_SIZE >= bdev_nr_bytes(file_bdev(bdev_file))) return ERR_PTR(-EINVAL); /* make sure our super fits in the page */ @@ -1270,7 +1270,7 @@ static struct btrfs_super_block *btrfs_read_disk_super(struct block_device *bdev return ERR_PTR(-EINVAL); /* pull in the page with our super */ - page = read_cache_page_gfp(bdev->bd_inode->i_mapping, index, GFP_KERNEL); + page = read_cache_page_gfp(bdev_file->f_mapping, index, GFP_KERNEL); if (IS_ERR(page)) return ERR_CAST(page); @@ -1388,14 +1388,13 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags, return ERR_CAST(bdev_file); bytenr_orig = btrfs_sb_offset(0); - ret = btrfs_sb_log_location_bdev(file_bdev(bdev_file), 0, READ, &bytenr); + ret = btrfs_sb_log_location_bdev(bdev_file, 0, READ, &bytenr); if (ret) { device = ERR_PTR(ret); goto error_bdev_put; } - disk_super = btrfs_read_disk_super(file_bdev(bdev_file), bytenr, - bytenr_orig); + disk_super = btrfs_read_disk_super(bdev_file, bytenr, bytenr_orig); if (IS_ERR(disk_super)) { device = ERR_CAST(disk_super); goto error_bdev_put; @@ -2057,7 +2056,7 @@ static void btrfs_scratch_superblock(struct btrfs_fs_info *fs_info, const u64 bytenr = btrfs_sb_offset(copy_num); int ret; - disk_super = btrfs_read_disk_super(file_bdev(bdev_file), bytenr, bytenr); + disk_super = btrfs_read_disk_super(bdev_file, bytenr, bytenr); if (IS_ERR(disk_super)) return; diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 5a3d5ec75c5a..b9b78374a612 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -81,7 +81,7 @@ static int copy_zone_info_cb(struct blk_zone *zone, unsigned int idx, void *data return 0; } -static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones, +static int sb_write_pointer(struct file *bdev_file, struct blk_zone *zones, u64 *wp_ret) { bool empty[BTRFS_NR_SB_LOG_ZONES]; @@ -118,7 +118,7 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones, return -ENOENT; } else if (full[0] && full[1]) { /* Compare two super blocks */ - struct address_space *mapping = bdev->bd_inode->i_mapping; + struct address_space *mapping = bdev_file->f_mapping; struct page *page[BTRFS_NR_SB_LOG_ZONES]; struct btrfs_super_block *super[BTRFS_NR_SB_LOG_ZONES]; int i; @@ -562,7 +562,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) BLK_ZONE_TYPE_CONVENTIONAL) continue; - ret = sb_write_pointer(device->bdev, + ret = sb_write_pointer(device->bdev_file, &zone_info->sb_zones[sb_pos], &sb_wp); if (ret != -ENOENT && ret) { btrfs_err_in_rcu(device->fs_info, @@ -798,7 +798,7 @@ int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info, unsigned long *mount return 0; } -static int sb_log_location(struct block_device *bdev, struct blk_zone *zones, +static int sb_log_location(struct file *bdev_file, struct blk_zone *zones, int rw, u64 *bytenr_ret) { u64 wp; @@ -809,7 +809,7 @@ static int sb_log_location(struct block_device *bdev, struct blk_zone *zones, return 0; } - ret = sb_write_pointer(bdev, zones, &wp); + ret = sb_write_pointer(bdev_file, zones, &wp); if (ret != -ENOENT && ret < 0) return ret; @@ -827,7 +827,8 @@ static int sb_log_location(struct block_device *bdev, struct blk_zone *zones, ASSERT(sb_zone_is_full(reset)); nofs_flags = memalloc_nofs_save(); - ret = blkdev_zone_mgmt(bdev, REQ_OP_ZONE_RESET, + ret = blkdev_zone_mgmt(file_bdev(bdev_file), + REQ_OP_ZONE_RESET, reset->start, reset->len); memalloc_nofs_restore(nofs_flags); if (ret) @@ -859,10 +860,11 @@ static int sb_log_location(struct block_device *bdev, struct blk_zone *zones, } -int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, +int btrfs_sb_log_location_bdev(struct file *bdev_file, int mirror, int rw, u64 *bytenr_ret) { struct blk_zone zones[BTRFS_NR_SB_LOG_ZONES]; + struct block_device *bdev = file_bdev(bdev_file); sector_t zone_sectors; u32 sb_zone; int ret; @@ -896,7 +898,7 @@ int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, if (ret != BTRFS_NR_SB_LOG_ZONES) return -EIO; - return sb_log_location(bdev, zones, rw, bytenr_ret); + return sb_log_location(bdev_file, zones, rw, bytenr_ret); } int btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw, @@ -920,7 +922,7 @@ int btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw, if (zone_num + 1 >= zinfo->nr_zones) return -ENOENT; - return sb_log_location(device->bdev, + return sb_log_location(device->bdev_file, &zinfo->sb_zones[BTRFS_NR_SB_LOG_ZONES * mirror], rw, bytenr_ret); } diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index 77c4321e331f..32680a04aa1f 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -61,7 +61,7 @@ void btrfs_destroy_dev_zone_info(struct btrfs_device *device); struct btrfs_zoned_device_info *btrfs_clone_dev_zone_info(struct btrfs_device *orig_dev); int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info); int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info, unsigned long *mount_opt); -int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, +int btrfs_sb_log_location_bdev(struct file *bdev_file, int mirror, int rw, u64 *bytenr_ret); int btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw, u64 *bytenr_ret); @@ -142,7 +142,7 @@ static inline int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info, return 0; } -static inline int btrfs_sb_log_location_bdev(struct block_device *bdev, +static inline int btrfs_sb_log_location_bdev(struct file *bdev_file, int mirror, int rw, u64 *bytenr_ret) { *bytenr_ret = btrfs_sb_offset(mirror); From patchwork Sat Apr 6 09:09:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619749 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE75E2C868; Sat, 6 Apr 2024 09:17:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395072; cv=none; b=q8egXkNuWy9O8WAg30VHo6cnX2psNdHgBsITil9vuiVd6BcXNjKrF79y4JzP/23fziEFiBXH4LUxGWSNWazUYLiELTJhLAq/Mr5BIJspLmDCV23ElPP3eji6WgjQP1IQWUym7+L7Ccb0qc8cT82glZmRe4tsueBFLcAz0PE70UM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395072; c=relaxed/simple; bh=zUIO1SUiCKW2XfTdRsFxc2S0V/jDhjXrjWEbfQuXH5E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NDLGy7VXIrG6oIa2hLXDiX+5v6BGbxnS/TIzbWh7hokZGMbJwMVFlu5u9JyHNzvIXtLkOs/ipAENhQHWS+T+AUj8lwC6emwMyed/EN9XXEx053EXYutORc+UDZKshEywK0Mc4Az2in1O/FnHJ7GKFSSVYh3MvEgA2+5l4GIq3f4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VBVBD3ZqZz4f3khj; Sat, 6 Apr 2024 17:17:40 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 29EF51A0C9B; Sat, 6 Apr 2024 17:17:47 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S16; Sat, 06 Apr 2024 17:17:46 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 12/26] ext4: remove block_device_ejected() Date: Sat, 6 Apr 2024 17:09:16 +0800 Message-Id: <20240406090930.2252838-13-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S16 X-Coremail-Antispam: 1UD129KBjvJXoW7Kr4UGw1xJF1fWr48KFy3urg_yoW8tF1Up3 y3uw1fJrW8urn29ayxJr4xWry0qa92yay0gFyxur1Fgrn7JryIqF4ktr1Iya40vrZ3uw4F qF1UCrWxur1UCrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBSb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAI cVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2js IEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai block_device_ejected() is added by commit bdfe0cbd746a ("Revert "ext4: remove block_device_ejected"") in 2015. At that time 'bdi->wb' is destroyed synchronized from del_gendisk(), hence if ext4 is still mounted, and then mark_buffer_dirty() will reference destroyed 'wb'. However, such problem doesn't exist anymore: - commit d03f6cdc1fc4 ("block: Dynamically allocate and refcount backing_dev_info") switch bdi to use refcounting; - commit 13eec2363ef0 ("fs: Get proper reference for s_bdi"), will grab additional reference of bdi while mounting, so that 'bdi->wb' will not be destroyed until generic_shutdown_super(). Hence remove this dead function block_device_ejected(). Signed-off-by: Yu Kuai Reviewed-by: Jan Kara Reviewed-by: Christoph Hellwig --- fs/ext4/super.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 3fce1b80c419..cf4666b04d2e 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -492,22 +492,6 @@ static void ext4_maybe_update_superblock(struct super_block *sb) schedule_work(&EXT4_SB(sb)->s_sb_upd_work); } -/* - * The del_gendisk() function uninitializes the disk-specific data - * structures, including the bdi structure, without telling anyone - * else. Once this happens, any attempt to call mark_buffer_dirty() - * (for example, by ext4_commit_super), will cause a kernel OOPS. - * This is a kludge to prevent these oops until we can put in a proper - * hook in del_gendisk() to inform the VFS and file system layers. - */ -static int block_device_ejected(struct super_block *sb) -{ - struct inode *bd_inode = sb->s_bdev->bd_inode; - struct backing_dev_info *bdi = inode_to_bdi(bd_inode); - - return bdi->dev == NULL; -} - static void ext4_journal_commit_callback(journal_t *journal, transaction_t *txn) { struct super_block *sb = journal->j_private; @@ -6168,8 +6152,6 @@ static int ext4_commit_super(struct super_block *sb) if (!sbh) return -EINVAL; - if (block_device_ejected(sb)) - return -ENODEV; ext4_update_super(sb); From patchwork Sat Apr 6 09:09:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619747 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3EB962E652; Sat, 6 Apr 2024 09:17:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395072; cv=none; b=k7cpQ7W5gKQYQ5zows6F8YozHqr/Hs3BrecZy4Hgtz96QOa8W+KN47m9zHWyBJ2KJfbetscEPyqNeZ8DmNEQMhOf4v6GLx0bLHTtyhxw64JocD0yaWn/mlQPkgTPoutCT32yOnfBydA5t7rrCF9Lew1U0ZT0dU8a7Td0wnjLtuk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395072; c=relaxed/simple; bh=g8gx/vP7JXR9bQcNllNLkqVOlxmyZfK7k0VNv7WlN94=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LC+X4X4DTaOBBpcD/oxDs+HObX1D5zLz7eolbqJMI7FcjfcXa/AIQmqBHeHi2iGcMHkdJTUddWZsFSeGlM+OcaRZgxRjEdO9GP88oHSYrvBjR/ClL/c5Y5qBG795LP+3e2DOEc5yR9JtXG1LjUycfvGMJcGk47UpgxjC2S7SVfA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVBH1vVBz4f3kJv; Sat, 6 Apr 2024 17:17:43 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 9017B1A0175; Sat, 6 Apr 2024 17:17:47 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S17; Sat, 06 Apr 2024 17:17:47 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 13/26] ext4: prevent direct access of bd_inode Date: Sat, 6 Apr 2024 17:09:17 +0800 Message-Id: <20240406090930.2252838-14-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S17 X-Coremail-Antispam: 1UD129KBjvJXoWxWFW7WrW8ZF4DWFyDAF1DJrb_yoW5Ww48pa s8AF15Cr4UZFyj9a9xGFZrta47uw18Kayxuryxu34a9rZIqrySvFy8KF1jvFWjqrW8Zr97 XF1jkryrCr1FkrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBSb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAI cVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2js IEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai Now that all filesystems stash the bdev file, it's ok to get mapping from the file. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- fs/ext4/dir.c | 2 +- fs/ext4/ext4_jbd2.c | 2 +- fs/ext4/super.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c index 3985f8c33f95..0733bc1eec7a 100644 --- a/fs/ext4/dir.c +++ b/fs/ext4/dir.c @@ -192,7 +192,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx) (PAGE_SHIFT - inode->i_blkbits); if (!ra_has_index(&file->f_ra, index)) page_cache_sync_readahead( - sb->s_bdev->bd_inode->i_mapping, + sb->s_bdev_file->f_mapping, &file->f_ra, file, index, 1); file->f_ra.prev_pos = (loff_t)index << PAGE_SHIFT; diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c index 5d8055161acd..dbb9aff07ac1 100644 --- a/fs/ext4/ext4_jbd2.c +++ b/fs/ext4/ext4_jbd2.c @@ -206,7 +206,7 @@ static void ext4_journal_abort_handle(const char *caller, unsigned int line, static void ext4_check_bdev_write_error(struct super_block *sb) { - struct address_space *mapping = sb->s_bdev->bd_inode->i_mapping; + struct address_space *mapping = sb->s_bdev_file->f_mapping; struct ext4_sb_info *sbi = EXT4_SB(sb); int err; diff --git a/fs/ext4/super.c b/fs/ext4/super.c index cf4666b04d2e..2a1afe6c77f2 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -244,7 +244,7 @@ static struct buffer_head *__ext4_sb_bread_gfp(struct super_block *sb, struct buffer_head *ext4_sb_bread(struct super_block *sb, sector_t block, blk_opf_t op_flags) { - gfp_t gfp = mapping_gfp_constraint(sb->s_bdev->bd_inode->i_mapping, + gfp_t gfp = mapping_gfp_constraint(sb->s_bdev_file->f_mapping, ~__GFP_FS) | __GFP_MOVABLE; return __ext4_sb_bread_gfp(sb, block, op_flags, gfp); @@ -253,7 +253,7 @@ struct buffer_head *ext4_sb_bread(struct super_block *sb, sector_t block, struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb, sector_t block) { - gfp_t gfp = mapping_gfp_constraint(sb->s_bdev->bd_inode->i_mapping, + gfp_t gfp = mapping_gfp_constraint(sb->s_bdev_file->f_mapping, ~__GFP_FS); return __ext4_sb_bread_gfp(sb, block, 0, gfp); @@ -5552,7 +5552,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) * used to detect the metadata async write error. */ spin_lock_init(&sbi->s_bdev_wb_lock); - errseq_check_and_advance(&sb->s_bdev->bd_inode->i_mapping->wb_err, + errseq_check_and_advance(&sb->s_bdev_file->f_mapping->wb_err, &sbi->s_bdev_wb_err); EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS; ext4_orphan_cleanup(sb, es); From patchwork Sat Apr 6 09:09:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619748 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A33A36AF6; Sat, 6 Apr 2024 09:17:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395072; cv=none; b=btklzGXmtLdi38KpIJRpVAkt6IEWcncxUP9lwyC7gVU+OItXBH4OeTDa1irmrgCiYK5FjaH3zFV2M3xTsqs+k6SWYxz44FID8yl2lvRtWHL5t65kxUJFGIbYtjREfLHmxZInuBsg/46PFz/+KfR6n1pRMwKhaUhfHx4rslsG3yA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395072; c=relaxed/simple; bh=8vZlYcXDwbM//A79Dk/T06AReJmn5bA6v/csx8/5VJw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=D2gGd1/3U/KveRy2jWDv+dBnQjwkjCovAocJL42rifCCvrU4LUYBb+Rn6y+ZVAQWMgTVGzkvrzKw8nEfLKBTHzgVPY1rENmj96+8OP94m6AqAMccrhtA398Kqj5Bsc8rz/2jq5VHrOZ0dnZ5d7c/VLI6Vm+MotJVW4coWmvXQog= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVBC3bPbz4f3lg9; Sat, 6 Apr 2024 17:17:39 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 013F91A0175; Sat, 6 Apr 2024 17:17:48 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S18; Sat, 06 Apr 2024 17:17:47 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 14/26] jbd2: prevent direct access of bd_inode Date: Sat, 6 Apr 2024 17:09:18 +0800 Message-Id: <20240406090930.2252838-15-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S18 X-Coremail-Antispam: 1UD129KBjvJXoW3GF1rJw4fAF1fJw1rKF4fuFg_yoWxXFW3pF 98Ga45ZrWUZryjgrWxXrWUJrWYqa40ka4UWr9ru3sYy3yqyr97KF1kKr1UJFWUtFWrGan5 XF1DC3y7Gw1UK3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBSb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAI cVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2js IEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai Now that all filesystems stash the bdev file, it's ok to get mapping from the file. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- fs/ext4/super.c | 2 +- fs/jbd2/journal.c | 26 +++++++++++++++----------- include/linux/jbd2.h | 18 ++++++++++++++---- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 2a1afe6c77f2..d47c1e7e8798 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5910,7 +5910,7 @@ static journal_t *ext4_open_dev_journal(struct super_block *sb, if (IS_ERR(bdev_file)) return ERR_CAST(bdev_file); - journal = jbd2_journal_init_dev(file_bdev(bdev_file), sb->s_bdev, j_start, + journal = jbd2_journal_init_dev(bdev_file, sb->s_bdev_file, j_start, j_len, sb->s_blocksize); if (IS_ERR(journal)) { ext4_msg(sb, KERN_ERR, "failed to create device journal"); diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index b6c114c11b97..abd42a6ccd0e 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -1516,11 +1516,12 @@ static int journal_load_superblock(journal_t *journal) * very few fields yet: that has to wait until we have created the * journal structures from from scratch, or loaded them from disk. */ -static journal_t *journal_init_common(struct block_device *bdev, - struct block_device *fs_dev, +static journal_t *journal_init_common(struct file *bdev_file, + struct file *fs_dev_file, unsigned long long start, int len, int blocksize) { static struct lock_class_key jbd2_trans_commit_key; + struct block_device *bdev = file_bdev(bdev_file); journal_t *journal; int err; int n; @@ -1531,7 +1532,9 @@ static journal_t *journal_init_common(struct block_device *bdev, journal->j_blocksize = blocksize; journal->j_dev = bdev; - journal->j_fs_dev = fs_dev; + journal->j_dev_file = bdev_file; + journal->j_fs_dev = file_bdev(fs_dev_file); + journal->j_fs_dev_file = fs_dev_file; journal->j_blk_offset = start; journal->j_total_len = len; jbd2_init_fs_dev_write_error(journal); @@ -1628,8 +1631,8 @@ static journal_t *journal_init_common(struct block_device *bdev, /** * journal_t * jbd2_journal_init_dev() - creates and initialises a journal structure - * @bdev: Block device on which to create the journal - * @fs_dev: Device which hold journalled filesystem for this journal. + * @bdev_file: Opened block device on which to create the journal + * @fs_dev_file: Opened device which hold journalled filesystem for this journal. * @start: Block nr Start of journal. * @len: Length of the journal in blocks. * @blocksize: blocksize of journalling device @@ -1640,13 +1643,13 @@ static journal_t *journal_init_common(struct block_device *bdev, * range of blocks on an arbitrary block device. * */ -journal_t *jbd2_journal_init_dev(struct block_device *bdev, - struct block_device *fs_dev, +journal_t *jbd2_journal_init_dev(struct file *bdev_file, + struct file *fs_dev_file, unsigned long long start, int len, int blocksize) { journal_t *journal; - journal = journal_init_common(bdev, fs_dev, start, len, blocksize); + journal = journal_init_common(bdev_file, fs_dev_file, start, len, blocksize); if (IS_ERR(journal)) return ERR_CAST(journal); @@ -1683,8 +1686,9 @@ journal_t *jbd2_journal_init_inode(struct inode *inode) inode->i_sb->s_id, inode->i_ino, (long long) inode->i_size, inode->i_sb->s_blocksize_bits, inode->i_sb->s_blocksize); - journal = journal_init_common(inode->i_sb->s_bdev, inode->i_sb->s_bdev, - blocknr, inode->i_size >> inode->i_sb->s_blocksize_bits, + journal = journal_init_common(inode->i_sb->s_bdev_file, + inode->i_sb->s_bdev_file, blocknr, + inode->i_size >> inode->i_sb->s_blocksize_bits, inode->i_sb->s_blocksize); if (IS_ERR(journal)) return ERR_CAST(journal); @@ -2009,7 +2013,7 @@ static int __jbd2_journal_erase(journal_t *journal, unsigned int flags) byte_count = (block_stop - block_start + 1) * journal->j_blocksize; - truncate_inode_pages_range(journal->j_dev->bd_inode->i_mapping, + truncate_inode_pages_range(journal->j_dev_file->f_mapping, byte_start, byte_stop); if (flags & JBD2_JOURNAL_FLUSH_DISCARD) { diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h index 971f3e826e15..fc26730ae8ef 100644 --- a/include/linux/jbd2.h +++ b/include/linux/jbd2.h @@ -968,6 +968,11 @@ struct journal_s */ struct block_device *j_dev; + /** + * @j_dev_file: Opended device @j_dev. + */ + struct file *j_dev_file; + /** * @j_blocksize: Block size for the location where we store the journal. */ @@ -993,6 +998,11 @@ struct journal_s */ struct block_device *j_fs_dev; + /** + * @j_fs_dev_file: Opened device @j_fs_dev. + */ + struct file *j_fs_dev_file; + /** * @j_fs_dev_wb_err: * @@ -1533,8 +1543,8 @@ extern void jbd2_journal_unlock_updates (journal_t *); void jbd2_journal_wait_updates(journal_t *); -extern journal_t * jbd2_journal_init_dev(struct block_device *bdev, - struct block_device *fs_dev, +extern journal_t *jbd2_journal_init_dev(struct file *bdev_file, + struct file *fs_dev_file, unsigned long long start, int len, int bsize); extern journal_t * jbd2_journal_init_inode (struct inode *); extern int jbd2_journal_update_format (journal_t *); @@ -1696,7 +1706,7 @@ static inline void jbd2_journal_abort_handle(handle_t *handle) static inline void jbd2_init_fs_dev_write_error(journal_t *journal) { - struct address_space *mapping = journal->j_fs_dev->bd_inode->i_mapping; + struct address_space *mapping = journal->j_fs_dev_file->f_mapping; /* * Save the original wb_err value of client fs's bdev mapping which @@ -1707,7 +1717,7 @@ static inline void jbd2_init_fs_dev_write_error(journal_t *journal) static inline int jbd2_check_fs_dev_write_error(journal_t *journal) { - struct address_space *mapping = journal->j_fs_dev->bd_inode->i_mapping; + struct address_space *mapping = journal->j_fs_dev_file->f_mapping; return errseq_check(&mapping->wb_err, READ_ONCE(journal->j_fs_dev_wb_err)); From patchwork Sat Apr 6 09:09:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619754 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B67636B0E; Sat, 6 Apr 2024 09:17:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395074; cv=none; b=GKcK/BhF7BdN1gd5QOdmZg/Y1XAK+61k7AYzYJDCjD3GfQB8RglIvghLcaVYU9xJWJl+E/f3ILO4HhklaY3t8cYSUS98Oio56ZuenMV9Lott5IOheXV3Ae9x6Q9MBcMiMJSkF+RKeDUlz+xk4GI4MMkSpHrOUCoSezrx5wwZXDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395074; c=relaxed/simple; bh=bCFy/k/FvtAgI9RRhfoHH1YorOQQiJPbNFphSp0CF/c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=e2XnWv7hUspn+CuMmzDlrfLpHcQ0sKpjs3UGX45R2IA++jh24e6Hwhk6i51Re3sFBi0QcQlEPDZwapvZdfzGmc7Q1sl5wusJ6S2uoT3a5RXpcC31NrbM2omqI5zz+d1K9Kl1mYmjXZVxgkAplCyd2azJfNVtaPF5Qg5M3dP9gHw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VBVBF5Jqnz4f3khX; Sat, 6 Apr 2024 17:17:41 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 650241A0C9A; Sat, 6 Apr 2024 17:17:48 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S19; Sat, 06 Apr 2024 17:17:48 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 15/26] s390/dasd: use bdev api in dasd_format() Date: Sat, 6 Apr 2024 17:09:19 +0800 Message-Id: <20240406090930.2252838-16-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S19 X-Coremail-Antispam: 1UD129KBjvdXoW7XFWrWFWfWw45CFyfZw1xGrg_yoWDJFc_ZF 1fKryftr18Cr93Cr1YvF15Zr9Ykr1vgF1fZr9xtr1fWrnrXFsxX3ykurs8JrWkAayUC3s5 JFnrXr1Iyr15WjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbSAYFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r126s 0DM28IrcIa0xkI8VCY1x0267AKxVW5JVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4AK67xG Y2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14 v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAF wI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2 WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkE bVWUJVW8JwACjcxG0xvY0x0EwIxGrwACI402YVCY1x02628vn2kIc2xKxwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY 6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aV CY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07UZo7tUUUUU= X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai Avoid to access bd_inode directly, prepare to remove bd_inode from block_devcie. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- drivers/s390/block/dasd_ioctl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/s390/block/dasd_ioctl.c b/drivers/s390/block/dasd_ioctl.c index 7e0ed7032f76..c1201590f343 100644 --- a/drivers/s390/block/dasd_ioctl.c +++ b/drivers/s390/block/dasd_ioctl.c @@ -215,8 +215,9 @@ dasd_format(struct dasd_block *block, struct format_data_t *fdata) * enabling the device later. */ if (fdata->start_unit == 0) { - block->gdp->part0->bd_inode->i_blkbits = - blksize_bits(fdata->blksize); + rc = set_blocksize(block->gdp->part0, fdata->blksize); + if (rc) + return rc; } rc = base->discipline->format_device(base, fdata, 1); From patchwork Sat Apr 6 09:09:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619750 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E93236B17; Sat, 6 Apr 2024 09:17:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395073; cv=none; b=jczoEjb31rCAgtCBjcjl7Br2jJDmQ+knv/E0ygl99PMSi6GL+GqHdCewSOK9+fRyCUc6DEKcqoq60TNVZnvVHpeVMJKiYOGX//xIUVNIDzYSzu3jeBanJvmzmGW+b8P52LYCvuN03X03CEDVxnrg8Q7Azz0ARXb3Wk7niW+JcOQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395073; c=relaxed/simple; bh=NbjIZxMOKnTQPzGEJd3Cu63LI5ii2Hm3loSg5zcCzpk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jUR0j3yBiLVU9NuD0nmxEXDLDZB9jHT4w4MGbXr+0uZhXA/axY8uBqwtsES1NmOfu4ilU9SaQveh2gGEY/DuvecTDvqJ8lziram7kx/3vaJytjW6aYCNJOt//eSgZkQslPDhnrX3vSmDeCZ5WXSalbhmYSCfZpCi7nKRFQhFcBc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVBJ3WXKz4f3jkC; Sat, 6 Apr 2024 17:17:44 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id C64981A058D; Sat, 6 Apr 2024 17:17:48 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S20; Sat, 06 Apr 2024 17:17:48 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 16/26] bcache: prevent direct access of bd_inode Date: Sat, 6 Apr 2024 17:09:20 +0800 Message-Id: <20240406090930.2252838-17-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S20 X-Coremail-Antispam: 1UD129KBjvJXoW7uFWrJF4rCw4kZw43KFWUXFb_yoW8XF4fpF 9xCayjqrW8Ww48u3yUXr4DuFyrKwnIyayIk34xu34ava9Fqr9Y9FW5GryUuryFqry8Gwsr XF17Kry7Cr1kC3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBSb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAI cVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2js IEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai Now that all bcache stash the file of opened bdev, it's ok to get mapping from the file. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- drivers/md/bcache/super.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index 330bcd9ea4a9..be8565691abe 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -163,15 +163,16 @@ static const char *read_super_common(struct cache_sb *sb, struct block_device * } -static const char *read_super(struct cache_sb *sb, struct block_device *bdev, +static const char *read_super(struct cache_sb *sb, struct file *bdev_file, struct cache_sb_disk **res) { const char *err; + struct block_device *bdev = file_bdev(bdev_file); struct cache_sb_disk *s; struct page *page; unsigned int i; - page = read_cache_page_gfp(bdev->bd_inode->i_mapping, + page = read_cache_page_gfp(bdev_file->f_mapping, SB_OFFSET >> PAGE_SHIFT, GFP_KERNEL); if (IS_ERR(page)) return "IO error"; @@ -2558,7 +2559,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, if (set_blocksize(file_bdev(bdev_file), 4096)) goto out_blkdev_put; - err = read_super(sb, file_bdev(bdev_file), &sb_disk); + err = read_super(sb, bdev_file, &sb_disk); if (err) goto out_blkdev_put; From patchwork Sat Apr 6 09:09:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619753 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17F2937142; Sat, 6 Apr 2024 09:17:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395073; cv=none; b=oS0WVoXHYIxd/MMR/EkVYsJCitek9sOgCXhr2PRHrlkwT5q/WaqUKdXm4u05M/+hhNW6O5K3kqHkgcDB4pLokXENbHy8PFLyMjNpuk1g6tg1kNOEfMw2fRYXoIp7Rp5e6VK47cvYsU32pAkZDvkTXqcT3duZeTPcdpMsNasBhWs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395073; c=relaxed/simple; bh=Yy2Aw+6/50D+yEfctlUSXmAe2PKqrekApIQwCQffqrY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bf4+C51gbtSUlCqfuoBSQnIemPaBz0CMIL9w6c7cucwSAKXanOFgIN7F0tCl59yrMDKKexKuKbPKfUZ0K0xXx/cygjOx+rfVqphg4HTR6p3LNNcNdLAgkqBDxh5kkoeWO3P7kVGBBcG3mBEwhd7sMUIWDHzGw5Jt0XHoyyJKeB8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VBVBG46V9z4f3khn; Sat, 6 Apr 2024 17:17:42 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 39D911A0172; Sat, 6 Apr 2024 17:17:49 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S21; Sat, 06 Apr 2024 17:17:49 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 17/26] block2mtd: prevent direct access of bd_inode Date: Sat, 6 Apr 2024 17:09:21 +0800 Message-Id: <20240406090930.2252838-18-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S21 X-Coremail-Antispam: 1UD129KBjvJXoW7ur15Ww1DJw1kJFy3Zry7Jrb_yoW8XryUpa sxuFWUJryjkr1UWay8XF1DXry0q3Wqya1xuryUA34SgryfXrW2ka9xtas8J34rtFZrC3y5 ZF1qkrW8Cr48urJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBSb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAI cVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2js IEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai Now that block2mtd stash the file of opened bdev, it's ok to get inode from the file. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- drivers/mtd/devices/block2mtd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c index caacdc0a3819..1834692790a6 100644 --- a/drivers/mtd/devices/block2mtd.c +++ b/drivers/mtd/devices/block2mtd.c @@ -265,6 +265,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size, struct file *bdev_file; struct block_device *bdev; struct block2mtd_dev *dev; + loff_t size; char *name; if (!devname) @@ -291,7 +292,8 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size, goto err_free_block2mtd; } - if ((long)bdev->bd_inode->i_size % erase_size) { + size = i_size_read(file_inode(bdev_file)); + if ((long)size % erase_size) { pr_err("erasesize must be a divisor of device size\n"); goto err_free_block2mtd; } @@ -309,7 +311,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 = size & PAGE_MASK; dev->mtd.erasesize = erase_size; dev->mtd.writesize = 1; dev->mtd.writebufsize = PAGE_SIZE; From patchwork Sat Apr 6 09:09:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619752 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DE9A37163; Sat, 6 Apr 2024 09:17:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395073; cv=none; b=TZRKppq0rkdF+ei9V10HkzDmT/1jv4vO7FKPBD6afAyT1tkuQeAcr0kssOGyMxxnlt78GXSqv1mgfW9fwTuzvinaAvBm769jCROvK2MgiFftvAg0IEIZXMz+P17BkaAvjgtV2ITRusS8M/oanaM8Vs4dYqzuKBaWOFnw6zi0+FU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395073; c=relaxed/simple; bh=jTqQFKQ6Hwm8j3owKWdmo2+A5Arsz1b5/slXYeVdVUA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GlOZxvgtJ+YUGjjEfy+b5iLtzfX6yb8Bdn7NsReUGB5ekS0AAEDSuOxwjItrUNV4HHRhbJzMjybka5NxlOVn2ds1XqN/jrcpxTPLj8bb8W0PLTXqCSUQvwqwkMeFviL1+ttowHdIKucPFOfQl+2JQzeL4LsokhequDyJo0qLVBQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVBF0v3tz4f3lVn; Sat, 6 Apr 2024 17:17:41 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 97EA51A058D; Sat, 6 Apr 2024 17:17:49 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S22; Sat, 06 Apr 2024 17:17:49 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 18/26] scsi: use bdev helper in scsi_bios_ptable() Date: Sat, 6 Apr 2024 17:09:22 +0800 Message-Id: <20240406090930.2252838-19-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S22 X-Coremail-Antispam: 1UD129KBjvdXoWrKw1UZw13ur4xJF1UGw47CFg_yoWfKFX_CF WS9w17Wr4xAan2qr15tF4avryvva1qgF109F4Sqasavw1UXr95Jryvqr13Aw47Gr4UAw1r C3W7XrWayrsFgjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbSAYFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r126s 0DM28IrcIa0xkI8VCY1x0267AKxVW5JVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4AK67xG Y2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14 v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAF wI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2 WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkE bVWUJVW8JwACjcxG0xvY0x0EwIxGrwACI402YVCY1x02628vn2kIc2xKxwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY 6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aV CY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07UZo7tUUUUU= X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai scsi_bios_ptable() is reading without opening disk as file, use the new helper to read into block device page cache to prevent access bd_inode directly from scsi. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- drivers/scsi/scsicam.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/scsi/scsicam.c b/drivers/scsi/scsicam.c index e2c7d8ef205f..1c99b964a0eb 100644 --- a/drivers/scsi/scsicam.c +++ b/drivers/scsi/scsicam.c @@ -32,11 +32,10 @@ */ unsigned char *scsi_bios_ptable(struct block_device *dev) { - struct address_space *mapping = bdev_whole(dev)->bd_inode->i_mapping; unsigned char *res = NULL; struct folio *folio; - folio = read_mapping_folio(mapping, 0, NULL); + folio = bdev_read_folio(bdev_whole(dev), 0); if (IS_ERR(folio)) return NULL; From patchwork Sat Apr 6 09:09:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619757 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAA6F376EB; Sat, 6 Apr 2024 09:17:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395075; cv=none; b=R3IMJgO774jamWvP78bcnlfo8UMPCmjlef9YVz2Ii5DMKzT5mfANGFgmY7z89hzsu4WV4tB2VZPzF21uwsWXQeYqXm0U9xmlUTyFZ5ZE7UolkfcQysD7e7v+eCTz1+9EgBC7e7+SzyiKc+gm/lLJT3Ee29vkMgsirVwSns8GGfY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395075; c=relaxed/simple; bh=hNZfFgjhdajKdGO70rq9XI6mg40YgL8p68a393SI864=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=D7PIDYlMzOtxsrF/WkMGlfZOxg/ZuLuNwfXUIw6kDkZcj5Zym9M9Ret/kNwIhs+NAz7dvOnNoafvvTq1f1Zs68cmc4Px6s8cjCEzaGzIJ8nhKjtaL532G+btx7MfZ/R3uEkLlZ/hfwp76VkecXasP90kKGyDKPCfkdF600tUbDU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVBK5Cv8z4f3k69; Sat, 6 Apr 2024 17:17:45 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 0D5921A0C0C; Sat, 6 Apr 2024 17:17:50 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S23; Sat, 06 Apr 2024 17:17:49 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 19/26] dm-vdo: convert to use bdev_file Date: Sat, 6 Apr 2024 17:09:23 +0800 Message-Id: <20240406090930.2252838-20-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S23 X-Coremail-Antispam: 1UD129KBjvAXoW3uFyfuFyfuryDWFW3WrWxWFg_yoW8WF48Wo WaqrZxWa18Jw4xJFWrJF97JF9xZa1DCw4rC3WrZFZ8Wa15ta15JFW7Jw15XF13tr10qFn8 ZryxW3srtFWUJF4Dn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjp_UUUYu7kC6x804xWl14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK 8VAvwI8IcIk0rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF 0E3s1l82xGYIkIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vE j48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxV AFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x02 67AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I 80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCj c4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4IIrI8v6xkF7I0E8cxan2IY04v7MxAIw28Icx kI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2Iq xVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42 IY6xIIjxv20xvE14v26r4j6ryUMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UMIIF 0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87 Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7IU13l1DUUUUU== X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai Now that dm upper layer already statsh the file of opened device in 'dm_dev->bdev_file', it's ok to get inode from the file. There are no functional changes, prepare to remove 'bd_inode' from block_device. Suggested-by: Jan Kara Signed-off-by: Yu Kuai Reviewed-by: Jan Kara Signed-off-by: Al Viro Reviewed-by: Matthew Sakai --- drivers/md/dm-vdo/dedupe.c | 7 ++++--- drivers/md/dm-vdo/dm-vdo-target.c | 9 +++++++-- drivers/md/dm-vdo/indexer/config.c | 2 +- drivers/md/dm-vdo/indexer/config.h | 4 ++-- drivers/md/dm-vdo/indexer/index-layout.c | 6 +++--- drivers/md/dm-vdo/indexer/index-layout.h | 2 +- drivers/md/dm-vdo/indexer/index-session.c | 18 ++++++++++-------- drivers/md/dm-vdo/indexer/index.c | 4 ++-- drivers/md/dm-vdo/indexer/index.h | 2 +- drivers/md/dm-vdo/indexer/indexer.h | 6 +++--- drivers/md/dm-vdo/indexer/io-factory.c | 17 +++++++++-------- drivers/md/dm-vdo/indexer/io-factory.h | 4 ++-- drivers/md/dm-vdo/indexer/volume.c | 4 ++-- drivers/md/dm-vdo/indexer/volume.h | 2 +- drivers/md/dm-vdo/vdo.c | 2 +- 15 files changed, 49 insertions(+), 40 deletions(-) diff --git a/drivers/md/dm-vdo/dedupe.c b/drivers/md/dm-vdo/dedupe.c index 117266e1b3ae..0e311989247e 100644 --- a/drivers/md/dm-vdo/dedupe.c +++ b/drivers/md/dm-vdo/dedupe.c @@ -2191,7 +2191,7 @@ static int initialize_index(struct vdo *vdo, struct hash_zones *zones) uds_offset = ((vdo_get_index_region_start(geometry) - geometry.bio_offset) * VDO_BLOCK_SIZE); zones->parameters = (struct uds_parameters) { - .bdev = vdo->device_config->owned_device->bdev, + .bdev_file = vdo->device_config->owned_device->bdev_file, .offset = uds_offset, .size = (vdo_get_index_region_size(geometry) * VDO_BLOCK_SIZE), .memory_size = geometry.index_config.mem, @@ -2582,8 +2582,9 @@ static void resume_index(void *context, struct vdo_completion *parent) struct device_config *config = parent->vdo->device_config; int result; - zones->parameters.bdev = config->owned_device->bdev; - result = uds_resume_index_session(zones->index_session, zones->parameters.bdev); + zones->parameters.bdev_file = config->owned_device->bdev_file; + result = uds_resume_index_session(zones->index_session, + zones->parameters.bdev_file); if (result != UDS_SUCCESS) vdo_log_error_strerror(result, "Error resuming dedupe index"); diff --git a/drivers/md/dm-vdo/dm-vdo-target.c b/drivers/md/dm-vdo/dm-vdo-target.c index 5a4b0a927f56..79e861c2887c 100644 --- a/drivers/md/dm-vdo/dm-vdo-target.c +++ b/drivers/md/dm-vdo/dm-vdo-target.c @@ -696,6 +696,11 @@ static void handle_parse_error(struct device_config *config, char **error_ptr, *error_ptr = error_str; } +static loff_t vdo_get_device_size(const struct device_config *config) +{ + return i_size_read(file_inode(config->owned_device->bdev_file)); +} + /** * parse_device_config() - Convert the dmsetup table into a struct device_config. * @argc: The number of table values. @@ -878,7 +883,7 @@ static int parse_device_config(int argc, char **argv, struct dm_target *ti, } if (config->version == 0) { - u64 device_size = i_size_read(config->owned_device->bdev->bd_inode); + u64 device_size = vdo_get_device_size(config); config->physical_blocks = device_size / VDO_BLOCK_SIZE; } @@ -1011,7 +1016,7 @@ static void vdo_status(struct dm_target *ti, status_type_t status_type, static block_count_t __must_check get_underlying_device_block_count(const struct vdo *vdo) { - return i_size_read(vdo_get_backing_device(vdo)->bd_inode) / VDO_BLOCK_SIZE; + return vdo_get_device_size(vdo->device_config) / VDO_BLOCK_SIZE; } static int __must_check process_vdo_message_locked(struct vdo *vdo, unsigned int argc, diff --git a/drivers/md/dm-vdo/indexer/config.c b/drivers/md/dm-vdo/indexer/config.c index 5532371b952f..dcf0742a6145 100644 --- a/drivers/md/dm-vdo/indexer/config.c +++ b/drivers/md/dm-vdo/indexer/config.c @@ -344,7 +344,7 @@ int uds_make_configuration(const struct uds_parameters *params, config->volume_index_mean_delta = DEFAULT_VOLUME_INDEX_MEAN_DELTA; config->sparse_sample_rate = (params->sparse ? DEFAULT_SPARSE_SAMPLE_RATE : 0); config->nonce = params->nonce; - config->bdev = params->bdev; + config->bdev_file = params->bdev_file; config->offset = params->offset; config->size = params->size; diff --git a/drivers/md/dm-vdo/indexer/config.h b/drivers/md/dm-vdo/indexer/config.h index 08507dc2f7a1..8ba0cf72dec9 100644 --- a/drivers/md/dm-vdo/indexer/config.h +++ b/drivers/md/dm-vdo/indexer/config.h @@ -25,8 +25,8 @@ enum { /* A set of configuration parameters for the indexer. */ struct uds_configuration { - /* Storage device for the index */ - struct block_device *bdev; + /* File of opened storage device for the index */ + struct file *bdev_file; /* The maximum allowable size of the index */ size_t size; diff --git a/drivers/md/dm-vdo/indexer/index-layout.c b/drivers/md/dm-vdo/indexer/index-layout.c index 627adc24af3b..32eee76bc246 100644 --- a/drivers/md/dm-vdo/indexer/index-layout.c +++ b/drivers/md/dm-vdo/indexer/index-layout.c @@ -1668,7 +1668,7 @@ static int create_layout_factory(struct index_layout *layout, size_t writable_size; struct io_factory *factory = NULL; - result = uds_make_io_factory(config->bdev, &factory); + result = uds_make_io_factory(config->bdev_file, &factory); if (result != UDS_SUCCESS) return result; @@ -1741,9 +1741,9 @@ void uds_free_index_layout(struct index_layout *layout) } int uds_replace_index_layout_storage(struct index_layout *layout, - struct block_device *bdev) + struct file *bdev_file) { - return uds_replace_storage(layout->factory, bdev); + return uds_replace_storage(layout->factory, bdev_file); } /* Obtain a dm_bufio_client for the volume region. */ diff --git a/drivers/md/dm-vdo/indexer/index-layout.h b/drivers/md/dm-vdo/indexer/index-layout.h index e9ac6f4302d6..28f9be577631 100644 --- a/drivers/md/dm-vdo/indexer/index-layout.h +++ b/drivers/md/dm-vdo/indexer/index-layout.h @@ -24,7 +24,7 @@ int __must_check uds_make_index_layout(struct uds_configuration *config, bool ne void uds_free_index_layout(struct index_layout *layout); int __must_check uds_replace_index_layout_storage(struct index_layout *layout, - struct block_device *bdev); + struct file *bdev_file); int __must_check uds_load_index_state(struct index_layout *layout, struct uds_index *index); diff --git a/drivers/md/dm-vdo/indexer/index-session.c b/drivers/md/dm-vdo/indexer/index-session.c index aee0914d604a..914abf5e006b 100644 --- a/drivers/md/dm-vdo/indexer/index-session.c +++ b/drivers/md/dm-vdo/indexer/index-session.c @@ -335,7 +335,7 @@ int uds_open_index(enum uds_open_index_type open_type, vdo_log_error("missing required parameters"); return -EINVAL; } - if (parameters->bdev == NULL) { + if (parameters->bdev_file == NULL) { vdo_log_error("missing required block device"); return -EINVAL; } @@ -349,7 +349,7 @@ int uds_open_index(enum uds_open_index_type open_type, return uds_status_to_errno(result); session->parameters = *parameters; - format_dev_t(name, parameters->bdev->bd_dev); + format_dev_t(name, file_bdev(parameters->bdev_file)->bd_dev); vdo_log_info("%s: %s", get_open_type_string(open_type), name); result = initialize_index_session(session, open_type); @@ -460,15 +460,16 @@ int uds_suspend_index_session(struct uds_index_session *session, bool save) return uds_status_to_errno(result); } -static int replace_device(struct uds_index_session *session, struct block_device *bdev) +static int replace_device(struct uds_index_session *session, + struct file *bdev_file) { int result; - result = uds_replace_index_storage(session->index, bdev); + result = uds_replace_index_storage(session->index, bdev_file); if (result != UDS_SUCCESS) return result; - session->parameters.bdev = bdev; + session->parameters.bdev_file = bdev_file; return UDS_SUCCESS; } @@ -477,7 +478,7 @@ static int replace_device(struct uds_index_session *session, struct block_device * device differs from the current backing store, the index will start using the new backing store. */ int uds_resume_index_session(struct uds_index_session *session, - struct block_device *bdev) + struct file *bdev_file) { int result = UDS_SUCCESS; bool no_work = false; @@ -502,8 +503,9 @@ int uds_resume_index_session(struct uds_index_session *session, if (no_work) return result; - if ((session->index != NULL) && (bdev != session->parameters.bdev)) { - result = replace_device(session, bdev); + if (session->index != NULL && + bdev_file != session->parameters.bdev_file) { + result = replace_device(session, bdev_file); if (result != UDS_SUCCESS) { mutex_lock(&session->request_mutex); session->state &= ~IS_FLAG_WAITING; diff --git a/drivers/md/dm-vdo/indexer/index.c b/drivers/md/dm-vdo/indexer/index.c index 1ba767144426..48b16275a067 100644 --- a/drivers/md/dm-vdo/indexer/index.c +++ b/drivers/md/dm-vdo/indexer/index.c @@ -1336,9 +1336,9 @@ int uds_save_index(struct uds_index *index) return result; } -int uds_replace_index_storage(struct uds_index *index, struct block_device *bdev) +int uds_replace_index_storage(struct uds_index *index, struct file *bdev_file) { - return uds_replace_volume_storage(index->volume, index->layout, bdev); + return uds_replace_volume_storage(index->volume, index->layout, bdev_file); } /* Accessing statistics should be safe from any thread. */ diff --git a/drivers/md/dm-vdo/indexer/index.h b/drivers/md/dm-vdo/indexer/index.h index edabb239548e..6e2e203f43f7 100644 --- a/drivers/md/dm-vdo/indexer/index.h +++ b/drivers/md/dm-vdo/indexer/index.h @@ -72,7 +72,7 @@ int __must_check uds_save_index(struct uds_index *index); void uds_free_index(struct uds_index *index); int __must_check uds_replace_index_storage(struct uds_index *index, - struct block_device *bdev); + struct file *bdev_file); void uds_get_index_stats(struct uds_index *index, struct uds_index_stats *counters); diff --git a/drivers/md/dm-vdo/indexer/indexer.h b/drivers/md/dm-vdo/indexer/indexer.h index 3744aaf625b0..246ff2810e01 100644 --- a/drivers/md/dm-vdo/indexer/indexer.h +++ b/drivers/md/dm-vdo/indexer/indexer.h @@ -128,8 +128,8 @@ struct uds_volume_record { }; struct uds_parameters { - /* The block_device used for storage */ - struct block_device *bdev; + /* The bdev_file used for storage */ + struct file *bdev_file; /* The maximum allowable size of the index on storage */ size_t size; /* The offset where the index should start */ @@ -314,7 +314,7 @@ int __must_check uds_suspend_index_session(struct uds_index_session *session, bo * start using the new backing store instead. */ int __must_check uds_resume_index_session(struct uds_index_session *session, - struct block_device *bdev); + struct file *bdev_file); /* Wait until all outstanding index operations are complete. */ int __must_check uds_flush_index_session(struct uds_index_session *session); diff --git a/drivers/md/dm-vdo/indexer/io-factory.c b/drivers/md/dm-vdo/indexer/io-factory.c index 515765d35794..f4dedb7b7f40 100644 --- a/drivers/md/dm-vdo/indexer/io-factory.c +++ b/drivers/md/dm-vdo/indexer/io-factory.c @@ -22,7 +22,7 @@ * make helper structures that can be used to access sections of the index. */ struct io_factory { - struct block_device *bdev; + struct file *bdev_file; atomic_t ref_count; }; @@ -59,7 +59,7 @@ static void uds_get_io_factory(struct io_factory *factory) atomic_inc(&factory->ref_count); } -int uds_make_io_factory(struct block_device *bdev, struct io_factory **factory_ptr) +int uds_make_io_factory(struct file *bdev_file, struct io_factory **factory_ptr) { int result; struct io_factory *factory; @@ -68,16 +68,16 @@ int uds_make_io_factory(struct block_device *bdev, struct io_factory **factory_p if (result != VDO_SUCCESS) return result; - factory->bdev = bdev; + factory->bdev_file = bdev_file; atomic_set_release(&factory->ref_count, 1); *factory_ptr = factory; return UDS_SUCCESS; } -int uds_replace_storage(struct io_factory *factory, struct block_device *bdev) +int uds_replace_storage(struct io_factory *factory, struct file *bdev_file) { - factory->bdev = bdev; + factory->bdev_file = bdev_file; return UDS_SUCCESS; } @@ -90,7 +90,7 @@ void uds_put_io_factory(struct io_factory *factory) size_t uds_get_writable_size(struct io_factory *factory) { - return i_size_read(factory->bdev->bd_inode); + return i_size_read(file_inode(factory->bdev_file)); } /* Create a struct dm_bufio_client for an index region starting at offset. */ @@ -99,8 +99,9 @@ int uds_make_bufio(struct io_factory *factory, off_t block_offset, size_t block_ { struct dm_bufio_client *client; - client = dm_bufio_client_create(factory->bdev, block_size, reserved_buffers, 0, - NULL, NULL, 0); + client = dm_bufio_client_create(file_bdev(factory->bdev_file), + block_size, reserved_buffers, + 0, NULL, NULL, 0); if (IS_ERR(client)) return -PTR_ERR(client); diff --git a/drivers/md/dm-vdo/indexer/io-factory.h b/drivers/md/dm-vdo/indexer/io-factory.h index 7fb5a0616a79..a3ca84d62f2d 100644 --- a/drivers/md/dm-vdo/indexer/io-factory.h +++ b/drivers/md/dm-vdo/indexer/io-factory.h @@ -24,11 +24,11 @@ enum { SECTORS_PER_BLOCK = UDS_BLOCK_SIZE >> SECTOR_SHIFT, }; -int __must_check uds_make_io_factory(struct block_device *bdev, +int __must_check uds_make_io_factory(struct file *bdev_file, struct io_factory **factory_ptr); int __must_check uds_replace_storage(struct io_factory *factory, - struct block_device *bdev); + struct file *bdev_file); void uds_put_io_factory(struct io_factory *factory); diff --git a/drivers/md/dm-vdo/indexer/volume.c b/drivers/md/dm-vdo/indexer/volume.c index 655453bb276b..edbe46252657 100644 --- a/drivers/md/dm-vdo/indexer/volume.c +++ b/drivers/md/dm-vdo/indexer/volume.c @@ -1465,12 +1465,12 @@ int uds_find_volume_chapter_boundaries(struct volume *volume, u64 *lowest_vcn, int __must_check uds_replace_volume_storage(struct volume *volume, struct index_layout *layout, - struct block_device *bdev) + struct file *bdev_file) { int result; u32 i; - result = uds_replace_index_layout_storage(layout, bdev); + result = uds_replace_index_layout_storage(layout, bdev_file); if (result != UDS_SUCCESS) return result; diff --git a/drivers/md/dm-vdo/indexer/volume.h b/drivers/md/dm-vdo/indexer/volume.h index 8679a5e55347..1dc3561b8b43 100644 --- a/drivers/md/dm-vdo/indexer/volume.h +++ b/drivers/md/dm-vdo/indexer/volume.h @@ -130,7 +130,7 @@ void uds_free_volume(struct volume *volume); int __must_check uds_replace_volume_storage(struct volume *volume, struct index_layout *layout, - struct block_device *bdev); + struct file *bdev_file); int __must_check uds_find_volume_chapter_boundaries(struct volume *volume, u64 *lowest_vcn, u64 *highest_vcn, diff --git a/drivers/md/dm-vdo/vdo.c b/drivers/md/dm-vdo/vdo.c index fff847767755..eca9f8b51535 100644 --- a/drivers/md/dm-vdo/vdo.c +++ b/drivers/md/dm-vdo/vdo.c @@ -809,7 +809,7 @@ void vdo_load_super_block(struct vdo *vdo, struct vdo_completion *parent) */ struct block_device *vdo_get_backing_device(const struct vdo *vdo) { - return vdo->device_config->owned_device->bdev; + return file_bdev(vdo->device_config->owned_device->bdev_file); } /** From patchwork Sat Apr 6 09:09:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619756 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 697B0383A3; Sat, 6 Apr 2024 09:17:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395075; cv=none; b=m7THCg10YAjFObJwfqH/F7Fe9DQm/X4XIYa74sRK1TrhLaRHACFT8lzCALURknOBaYu9zZVZIBfFr01gux/gwKLBonL9EKwFMlSd5FpfdAkCfKqWFox0SbpJCYEaPrEYksegIoy3twkANdXPiN5a75HTZDgkTL3aujlUhqbTMVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395075; c=relaxed/simple; bh=IVNvL7M+0fIXRVg8xk89r3IChLHlduOXWlBxUNT4Nvk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eEdWjZxg4Dmj+1WGiXt2YOTiZ+jw0JKVuVDyQUACnE1jR7G81MkKM0F5Wjm8Fxqbw0RvrHxD9eA0bD1jnYbQDcMlGtyfOwBGPQ5B3qszK2CtvwW3YWQ7up2ndN74P2VW5Rorl5/ppoCba3uIKE5SzbGIfjjaoeODRIWaQzMGDQs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VBVBH5rdKz4f3kFR; Sat, 6 Apr 2024 17:17:43 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 74DDD1A0568; Sat, 6 Apr 2024 17:17:50 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S24; Sat, 06 Apr 2024 17:17:50 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 20/26] block: factor out a helper init_bdev_file() Date: Sat, 6 Apr 2024 17:09:24 +0800 Message-Id: <20240406090930.2252838-21-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S24 X-Coremail-Antispam: 1UD129KBjvJXoW7Kr47Kr4xtry7uF47WFWUCFg_yoW8Aw1fpr 9xWFZ0gr1UGw1DWay7Xa42qF90vw18Aa48Zr12qa4ayFZrJrZ29F1rKr1UuFWUt34kJw1D XF4UuryUWFySk37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBSb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Xr0_Ar1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAI cVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2js IEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai There are no functional changes, the helper will be used in later patches to initialize stashed bdev_file as well. Signed-off-by: Yu Kuai --- block/bdev.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index 4335df6d1266..82fb1688f4c9 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -832,6 +832,20 @@ static void bdev_yield_write_access(struct file *bdev_file) bdev->bd_writers--; } +static void init_bdev_file(struct file *bdev_file, struct block_device *bdev, + blk_mode_t mode, void *holder) +{ + bdev_file->f_flags |= O_LARGEFILE; + bdev_file->f_mode |= FMODE_CAN_ODIRECT; + if (bdev_nowait(bdev)) + bdev_file->f_mode |= FMODE_NOWAIT; + if (mode & BLK_OPEN_RESTRICT_WRITES) + bdev_file->f_mode |= FMODE_WRITE_RESTRICTED; + bdev_file->f_mapping = bdev_mapping(bdev); + bdev_file->f_wb_err = filemap_sample_wb_err(bdev_file->f_mapping); + bdev_file->private_data = holder; +} + /** * bdev_open - open a block device * @bdev: block device to open @@ -905,15 +919,7 @@ int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder, if (unblock_events) disk_unblock_events(disk); - bdev_file->f_flags |= O_LARGEFILE; - bdev_file->f_mode |= FMODE_CAN_ODIRECT; - if (bdev_nowait(bdev)) - bdev_file->f_mode |= FMODE_NOWAIT; - if (mode & BLK_OPEN_RESTRICT_WRITES) - bdev_file->f_mode |= FMODE_WRITE_RESTRICTED; - bdev_file->f_mapping = bdev_mapping(bdev); - bdev_file->f_wb_err = filemap_sample_wb_err(bdev_file->f_mapping); - bdev_file->private_data = holder; + init_bdev_file(bdev_file, bdev, mode, holder); return 0; put_module: From patchwork Sat Apr 6 09:09:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619755 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B050383A6; Sat, 6 Apr 2024 09:17:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395075; cv=none; b=YhOODVPhTcRPIOGwmMZdruF9Nro2sneiO/8DgqL63U7jcgpWgAM3krph8Gi7b8Z1pPwLnoDljMTxsgCofSzSr8akcD8Ddurcqv9baiXNtsTFnZDawmWds4QBC6IgjcY/B9bhxg1Nmvrv+OnbbXoCK+zXTO2quxtpbZFjIoBhKPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395075; c=relaxed/simple; bh=oITzHCczE+PR9WvzwFwNQD/O6vI0Xdj/12ViSedP+jo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Y+UuGJeyh6xgjSGZCT53+CwOqgAtURAS5j7k1tqGeDnmFvN0kybCUfFAOzgXCkBs9zDaoAEUUeBZjH9feFl6E1hbLEqmsMxYNXkuPnizUffVhjB4oHpOKhVFa3wVzuHlRwvuSTzuxPduXGabAZIr/ZatDR9JdZssXCCfC1i5uAM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVBG2lB7z4f3lgK; Sat, 6 Apr 2024 17:17:42 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id D8DE91A0572; Sat, 6 Apr 2024 17:17:50 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S25; Sat, 06 Apr 2024 17:17:50 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 21/26] block: fix module reference leakage from bdev_open_by_dev error path Date: Sat, 6 Apr 2024 17:09:25 +0800 Message-Id: <20240406090930.2252838-22-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S25 X-Coremail-Antispam: 1UD129KBjvdXoW7Gr1xurykXrW7uw48ZF17GFg_yoWfGFb_u3 WrCry8ur4rA34fCw4ayFyrXrs5t3W8JrWFyayxJF97CFy7Jas7uanxXr95ZF43XayDGw45 C3WYqrs8Zr1IgjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbSAYFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r126s 0DM28IrcIa0xkI8VCY1x0267AKxVW5JVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4AK67xG Y2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14 v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAF wI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2 WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkE bVWUJVW8JwACjcxG0xvY0x0EwIxGrwACI402YVCY1x02628vn2kIc2xKxwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVW5JVW7JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY 6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aV CY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07UZo7tUUUUU= X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai At the time bdev_may_open() is called, module reference is grabbed already, hence module reference should be released if bdev_may_open() failed. This problem is found by code review. Fixes: ed5cc702d311 ("block: Add config option to not allow writing to mounted devices") Signed-off-by: Yu Kuai --- block/bdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/bdev.c b/block/bdev.c index 82fb1688f4c9..86db97b0709e 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -890,7 +890,7 @@ int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder, goto abort_claiming; ret = -EBUSY; if (!bdev_may_open(bdev, mode)) - goto abort_claiming; + goto put_module; if (bdev_is_partition(bdev)) ret = blkdev_get_part(bdev, mode); else From patchwork Sat Apr 6 09:09:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619758 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D864D39FE5; Sat, 6 Apr 2024 09:17:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395075; cv=none; b=qhDrcRwU08iow2hK/KG08exWAy45h9YcpJ7iNW4TubKjMxIUD0PTyTJmLBSgZA5NWYiuJCiIhAk3pH3sg7keo9fzcTQxLiBYqHNkDfxdINMiWrq8i/oVCHiOh/n3VL1SH2kMIQytSQ3WaHPF7Fu2I0b9M+Z3lDVpORfttPyd+L4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395075; c=relaxed/simple; bh=pcjMvX4iWAJQ9J9m7Y1CdP7psXkpgzQlz5ovJqA3F8E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=a3adgCiQj3HEKuoKrPRiguIty/YtIJaW3FnLK8KKlaBsABOOJRKFyx/ix5R11RERJjDv96qHdqD9al4EML2o9RZ+2+I7eUCgHKM+IjFh41KjZDCwnT8Qua0BwThbMDsopBpbGwvDbQVsng2gHOaYMtWlSOrIEPmzMRXx/ritBLk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVBL6xfcz4f3jMM; Sat, 6 Apr 2024 17:17:46 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 47F721A058D; Sat, 6 Apr 2024 17:17:51 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S26; Sat, 06 Apr 2024 17:17:51 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 22/26] block: stash a bdev_file to read/write raw blcok_device Date: Sat, 6 Apr 2024 17:09:26 +0800 Message-Id: <20240406090930.2252838-23-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S26 X-Coremail-Antispam: 1UD129KBjvJXoW3Jr4kZF4rKw4DCr4xGF13XFb_yoW7CF48pr Z5GFZ8tryqgas7WFWIqanrur1agw48Jw1UZasxWr9ay3yDtrna9a48KrW5uFy8t34kAF1Y qFW5WryUCFy3CaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBSb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Xr0_Ar1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAI cVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2js IEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai So that iomap and bffer_head can convert to use bdev_file in following patches. Signed-off-by: Yu Kuai --- block/bdev.c | 137 +++++++++++++++++++++++++++++--------- include/linux/blk_types.h | 1 + 2 files changed, 107 insertions(+), 31 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index 86db97b0709e..3d300823da6b 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -846,6 +846,101 @@ static void init_bdev_file(struct file *bdev_file, struct block_device *bdev, bdev_file->private_data = holder; } +/* + * If BLK_OPEN_WRITE_IOCTL is set then this is a historical quirk + * associated with the floppy driver where it has allowed ioctls if the + * file was opened for writing, but does not allow reads or writes. + * Make sure that this quirk is reflected in @f_flags. + * + * It can also happen if a block device is opened as O_RDWR | O_WRONLY. + */ +static unsigned blk_to_file_flags(blk_mode_t mode) +{ + unsigned int flags = 0; + + if ((mode & (BLK_OPEN_READ | BLK_OPEN_WRITE)) == + (BLK_OPEN_READ | BLK_OPEN_WRITE)) + flags |= O_RDWR; + else if (mode & BLK_OPEN_WRITE_IOCTL) + flags |= O_RDWR | O_WRONLY; + else if (mode & BLK_OPEN_WRITE) + flags |= O_WRONLY; + else if (mode & BLK_OPEN_READ) + flags |= O_RDONLY; /* homeopathic, because O_RDONLY is 0 */ + else + WARN_ON_ONCE(true); + + if (mode & BLK_OPEN_NDELAY) + flags |= O_NDELAY; + + return flags; +} + +static int __stash_bdev_file(struct block_device *bdev) +{ + struct inode *inode = bdev_inode(bdev); + unsigned int flags = blk_to_file_flags(BLK_OPEN_READ | BLK_OPEN_WRITE); + struct file *file; + static struct file_operations stash_fops; + + file = inode->i_private; + if (!file) { + /* + * This file is used for iomap/buffer_head for raw block_device + * read/write operations to access block_device. + */ + file = alloc_file_pseudo_noaccount(bdev_inode(bdev), + blockdev_mnt, "", flags | O_LARGEFILE, + &stash_fops); + + if (IS_ERR(file)) + return PTR_ERR(file); + + ihold(inode); + init_bdev_file(file, bdev, 0, NULL); + + inode->i_private = file; + WARN_ON_ONCE(bdev->stash_count != 0); + } + + bdev->stash_count++; + return 0; +} + +static void __unstash_bdev_file(struct block_device *bdev) +{ + + WARN_ON_ONCE(bdev->stash_count <= 0); + if (--bdev->stash_count == 0) { + struct inode *inode = bdev_inode(bdev); + struct file *file = inode->i_private; + + inode->i_private = NULL; + fput(file); + } +} + +static int stash_bdev_file(struct block_device *bdev) +{ + int ret = __stash_bdev_file(bdev); + + if (ret || !bdev_is_partition(bdev)) + return ret; + + ret = __stash_bdev_file(bdev_whole(bdev)); + if (ret) + __unstash_bdev_file(bdev); + + return ret; +} + +static void unstash_bdev_file(struct block_device *bdev) +{ + __unstash_bdev_file(bdev); + if (bdev_is_partition(bdev)) + __unstash_bdev_file(bdev_whole(bdev)); +} + /** * bdev_open - open a block device * @bdev: block device to open @@ -891,12 +986,17 @@ int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder, ret = -EBUSY; if (!bdev_may_open(bdev, mode)) goto put_module; + + ret = stash_bdev_file(bdev); + if (ret) + goto put_module; + if (bdev_is_partition(bdev)) ret = blkdev_get_part(bdev, mode); else ret = blkdev_get_whole(bdev, mode); if (ret) - goto put_module; + goto unstash_bdev_file; bdev_claim_write_access(bdev, mode); if (holder) { bd_finish_claiming(bdev, holder, hops); @@ -922,6 +1022,9 @@ int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder, init_bdev_file(bdev_file, bdev, mode, holder); return 0; + +unstash_bdev_file: + unstash_bdev_file(bdev); put_module: module_put(disk->fops->owner); abort_claiming: @@ -932,36 +1035,6 @@ int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder, return ret; } -/* - * If BLK_OPEN_WRITE_IOCTL is set then this is a historical quirk - * associated with the floppy driver where it has allowed ioctls if the - * file was opened for writing, but does not allow reads or writes. - * Make sure that this quirk is reflected in @f_flags. - * - * It can also happen if a block device is opened as O_RDWR | O_WRONLY. - */ -static unsigned blk_to_file_flags(blk_mode_t mode) -{ - unsigned int flags = 0; - - if ((mode & (BLK_OPEN_READ | BLK_OPEN_WRITE)) == - (BLK_OPEN_READ | BLK_OPEN_WRITE)) - flags |= O_RDWR; - else if (mode & BLK_OPEN_WRITE_IOCTL) - flags |= O_RDWR | O_WRONLY; - else if (mode & BLK_OPEN_WRITE) - flags |= O_WRONLY; - else if (mode & BLK_OPEN_READ) - flags |= O_RDONLY; /* homeopathic, because O_RDONLY is 0 */ - else - WARN_ON_ONCE(true); - - if (mode & BLK_OPEN_NDELAY) - flags |= O_NDELAY; - - return flags; -} - struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, const struct blk_holder_ops *hops) { @@ -1073,6 +1146,8 @@ void bdev_release(struct file *bdev_file) blkdev_put_part(bdev); else blkdev_put_whole(bdev); + + unstash_bdev_file(bdev); mutex_unlock(&disk->open_mutex); module_put(disk->fops->owner); diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index cb1526ec44b5..22f736908cbe 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -70,6 +70,7 @@ struct block_device { #endif bool bd_ro_warned; int bd_writers; + int stash_count; /* * keep this out-of-line as it's both big and not needed in the fast * path From patchwork Sat Apr 6 09:09:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619760 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67ED73BBCE; Sat, 6 Apr 2024 09:17:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395076; cv=none; b=okpmqc8lMpMyrhuljCPO/S6ZPYD7XpJ1gKR+6y+cy8g92cj9GWDfK4EhaPkipUE64X0ieWP2GyZSOQnYScrvB7GGQ1U8vsh7GhHhGnWPi3uX7kxMSkWMR/oCU/8Qp/w6IQh49Gizsaje6FI9rN//udBoua6ypx+A0Vew70+ScPI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395076; c=relaxed/simple; bh=sPl5OvusNK1tKYCPnrwI3ydu+x8lrDSjoRqJ2OSjP9M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=r48t4DsImJKtylWoaH1JI26dH4mxE8VL5oHnR+Wl2680BFneWpFTlox4zGFQBbEi3qOxOeN4gQeDpk/1dhLTkKHMdxfmHvYVvfdiaeQMGKqGAnttVNTuqvbwGkOCioj57iKTg5+6vkcFRpmH8AfBelQhlYKL1Isv3x69Aakpiq8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVBM2mltz4f3k6Z; Sat, 6 Apr 2024 17:17:47 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id ACC8B1A0176; Sat, 6 Apr 2024 17:17:51 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S27; Sat, 06 Apr 2024 17:17:51 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 23/26] iomap: add helpers helpers to get and set bdev Date: Sat, 6 Apr 2024 17:09:27 +0800 Message-Id: <20240406090930.2252838-24-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S27 X-Coremail-Antispam: 1UD129KBjvAXoW3Zr43XFW8Cr4kJFW7Xw1DZFb_yoW8Ww45uo WYqw47Jr48KryUJayrCr4rGFW7X3Zxtw4kAFyUWrZ8Xryftw1Uuw47GanrXa47W3s5KFW7 A343t3y5JF4kWFs5n29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjp_UUUYu7kC6x804xWl14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK 8VAvwI8IcIk0rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF 0E3s1l82xGYIkIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vE j48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxV AFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x02 67AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I 80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCj c4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4IIrI8v6xkF7I0E8cxan2IY04v7MxAIw28Icx kI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2Iq xVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42 IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UMIIF 0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87 Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7IU13l1DUUUUU== X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai So that we have unified APIs, there are no functional changes and prepare to convert iomap to use bdev_file. Signed-off-by: Yu Kuai --- block/fops.c | 2 +- fs/btrfs/inode.c | 2 +- fs/buffer.c | 2 +- fs/erofs/data.c | 20 ++++++++++++++++---- fs/erofs/internal.h | 1 + fs/erofs/zmap.c | 2 +- fs/ext2/inode.c | 2 +- fs/ext4/inode.c | 2 +- fs/f2fs/data.c | 10 ++++++++-- fs/f2fs/f2fs.h | 1 + fs/fuse/dax.c | 2 +- fs/gfs2/bmap.c | 2 +- fs/hpfs/file.c | 2 +- fs/iomap/buffered-io.c | 8 ++++---- fs/iomap/direct-io.c | 11 ++++++----- fs/iomap/swapfile.c | 2 +- fs/iomap/trace.h | 6 ++++-- fs/xfs/xfs_iomap.c | 4 ++-- fs/zonefs/file.c | 4 ++-- include/linux/iomap.h | 11 +++++++++++ 20 files changed, 65 insertions(+), 31 deletions(-) diff --git a/block/fops.c b/block/fops.c index 58b427051c0d..7d177be788cd 100644 --- a/block/fops.c +++ b/block/fops.c @@ -388,7 +388,7 @@ static int blkdev_iomap_begin(struct inode *inode, loff_t offset, loff_t length, struct block_device *bdev = I_BDEV(inode); loff_t isize = i_size_read(inode); - iomap->bdev = bdev; + iomap_set_bdev_file(iomap, inode->i_private); iomap->offset = ALIGN_DOWN(offset, bdev_logical_block_size(bdev)); if (iomap->offset >= isize) return -EIO; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 8cf692c708d7..e7495581bc58 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7709,7 +7709,7 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start, iomap->type = IOMAP_MAPPED; } iomap->offset = start; - iomap->bdev = fs_info->fs_devices->latest_dev->bdev; + iomap_set_bdev_file(iomap, fs_info->fs_devices->latest_dev->bdev_file); iomap->length = len; free_extent_map(em); diff --git a/fs/buffer.c b/fs/buffer.c index 4f73d23c2c46..7900720fc54b 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2005,7 +2005,7 @@ iomap_to_bh(struct inode *inode, sector_t block, struct buffer_head *bh, { loff_t offset = (loff_t)block << inode->i_blkbits; - bh->b_bdev = iomap->bdev; + bh->b_bdev = iomap_bdev(iomap); /* * Block points to offset in file we need to map, iomap contains diff --git a/fs/erofs/data.c b/fs/erofs/data.c index b0a55b4d8c30..ea149cfef88e 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -204,6 +204,7 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map) int id; map->m_bdev = sb->s_bdev; + map->m_bdev_file = sb->s_bdev_file; map->m_daxdev = EROFS_SB(sb)->dax_dev; map->m_dax_part_off = EROFS_SB(sb)->dax_part_off; map->m_fscache = EROFS_SB(sb)->s_fscache; @@ -220,7 +221,13 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map) up_read(&devs->rwsem); return 0; } - map->m_bdev = dif->bdev_file ? file_bdev(dif->bdev_file) : NULL; + if (dif->bdev_file) { + map->m_bdev = file_bdev(dif->bdev_file); + map->m_bdev_file = dif->bdev_file; + } else { + map->m_bdev = NULL; + map->m_bdev_file = NULL; + } map->m_daxdev = dif->dax_dev; map->m_dax_part_off = dif->dax_part_off; map->m_fscache = dif->fscache; @@ -238,8 +245,13 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map) if (map->m_pa >= startoff && map->m_pa < startoff + length) { map->m_pa -= startoff; - map->m_bdev = dif->bdev_file ? - file_bdev(dif->bdev_file) : NULL; + if (dif->bdev_file) { + map->m_bdev = file_bdev(dif->bdev_file); + map->m_bdev_file = dif->bdev_file; + } else { + map->m_bdev = NULL; + map->m_bdev_file = NULL; + } map->m_daxdev = dif->dax_dev; map->m_dax_part_off = dif->dax_part_off; map->m_fscache = dif->fscache; @@ -278,7 +290,7 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, if (flags & IOMAP_DAX) iomap->dax_dev = mdev.m_daxdev; else - iomap->bdev = mdev.m_bdev; + iomap_set_bdev_file(iomap, mdev.m_bdev_file); iomap->length = map.m_llen; iomap->flags = 0; iomap->private = NULL; diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 39c67119f43b..a91481178876 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -378,6 +378,7 @@ enum { struct erofs_map_dev { struct erofs_fscache *m_fscache; struct block_device *m_bdev; + struct file *m_bdev_file; struct dax_device *m_daxdev; u64 m_dax_part_off; diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c index e313c936351d..71e6c5342d72 100644 --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -739,7 +739,7 @@ static int z_erofs_iomap_begin_report(struct inode *inode, loff_t offset, if (ret < 0) return ret; - iomap->bdev = inode->i_sb->s_bdev; + iomap_set_bdev_file(iomap, inode->i_sb->s_bdev_file); iomap->offset = map.m_la; iomap->length = map.m_llen; if (map.m_flags & EROFS_MAP_MAPPED) { diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index f3d570a9302b..6286d1578426 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c @@ -842,7 +842,7 @@ static int ext2_iomap_begin(struct inode *inode, loff_t offset, loff_t length, if (flags & IOMAP_DAX) iomap->dax_dev = sbi->s_daxdev; else - iomap->bdev = inode->i_sb->s_bdev; + iomap_set_bdev_file(iomap, inode->i_sb->s_bdev_file); if (ret == 0) { /* diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 537803250ca9..588af2604bb8 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3235,7 +3235,7 @@ static void ext4_set_iomap(struct inode *inode, struct iomap *iomap, if (flags & IOMAP_DAX) iomap->dax_dev = EXT4_SB(inode->i_sb)->s_daxdev; else - iomap->bdev = inode->i_sb->s_bdev; + iomap_set_bdev_file(iomap, inode->i_sb->s_bdev_file); iomap->offset = (u64) map->m_lblk << blkbits; iomap->length = (u64) map->m_len << blkbits; diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index d9494b5fc7c1..8002a5b511d9 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1499,10 +1499,12 @@ static bool f2fs_map_blocks_cached(struct inode *inode, struct f2fs_dev_info *dev = &sbi->devs[bidx]; map->m_bdev = dev->bdev; + map->m_bdev_file = dev->bdev_file; map->m_pblk -= dev->start_blk; map->m_len = min(map->m_len, dev->end_blk + 1 - map->m_pblk); } else { map->m_bdev = inode->i_sb->s_bdev; + map->m_bdev_file = inode->i_sb->s_bdev_file; } return true; } @@ -1534,6 +1536,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag) goto out; map->m_bdev = inode->i_sb->s_bdev; + map->m_bdev_file = inode->i_sb->s_bdev_file; map->m_multidev_dio = f2fs_allow_multi_device_dio(F2FS_I_SB(inode), flag); @@ -1651,8 +1654,10 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag) map->m_pblk = blkaddr; map->m_len = 1; - if (map->m_multidev_dio) + if (map->m_multidev_dio) { map->m_bdev = FDEV(bidx).bdev; + map->m_bdev_file = FDEV(bidx).bdev_file; + } } else if ((map->m_pblk != NEW_ADDR && blkaddr == (map->m_pblk + ofs)) || (map->m_pblk == NEW_ADDR && blkaddr == NEW_ADDR) || @@ -1725,6 +1730,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag) bidx = f2fs_target_device_index(sbi, map->m_pblk); map->m_bdev = FDEV(bidx).bdev; + map->m_bdev_file = FDEV(bidx).bdev_file; map->m_pblk -= FDEV(bidx).start_blk; if (map->m_may_create) @@ -4189,7 +4195,7 @@ static int f2fs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, iomap->length = blks_to_bytes(inode, map.m_len); iomap->type = IOMAP_MAPPED; iomap->flags |= IOMAP_F_MERGED; - iomap->bdev = map.m_bdev; + iomap_set_bdev_file(iomap, map.m_bdev_file); iomap->addr = blks_to_bytes(inode, map.m_pblk); } else { if (flags & IOMAP_WRITE) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index fced2b7652f4..49894ac4f7ff 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -699,6 +699,7 @@ struct extent_tree_info { struct f2fs_map_blocks { struct block_device *m_bdev; /* for multi-device dio */ + struct file *m_bdev_file; /* for multi-device dio */ block_t m_pblk; block_t m_lblk; unsigned int m_len; diff --git a/fs/fuse/dax.c b/fs/fuse/dax.c index 12ef91d170bb..1fbc1c5688ca 100644 --- a/fs/fuse/dax.c +++ b/fs/fuse/dax.c @@ -575,7 +575,7 @@ static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t length, iomap->offset = pos; iomap->flags = 0; - iomap->bdev = NULL; + iomap_set_bdev_file(iomap, NULL); iomap->dax_dev = fc->dax->dev; /* diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 789af5c8fade..20eb2db774b0 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -926,7 +926,7 @@ static int __gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length, iomap->flags |= IOMAP_F_GFS2_BOUNDARY; out: - iomap->bdev = inode->i_sb->s_bdev; + iomap_set_bdev_file(iomap, inode->i_sb->s_bdev_file); unlock: up_read(&ip->i_rw_mutex); return ret; diff --git a/fs/hpfs/file.c b/fs/hpfs/file.c index 1bb8d97cd9ae..77c01a9252c7 100644 --- a/fs/hpfs/file.c +++ b/fs/hpfs/file.c @@ -128,7 +128,7 @@ static int hpfs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, if (WARN_ON_ONCE(flags & (IOMAP_WRITE | IOMAP_ZERO))) return -EINVAL; - iomap->bdev = inode->i_sb->s_bdev; + iomap_set_bdev_file(iomap, inode->i_sb->s_bdev_file); iomap->offset = offset; hpfs_lock(sb); diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 4e8e41c8b3c0..66a83c84d11d 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -415,7 +415,7 @@ static loff_t iomap_readpage_iter(const struct iomap_iter *iter, if (ctx->rac) /* same as readahead_gfp_mask */ gfp |= __GFP_NORETRY | __GFP_NOWARN; - ctx->bio = bio_alloc(iomap->bdev, bio_max_segs(nr_vecs), + ctx->bio = bio_alloc(iomap_bdev(iomap), bio_max_segs(nr_vecs), REQ_OP_READ, gfp); /* * If the bio_alloc fails, try it again for a single page to @@ -423,7 +423,7 @@ static loff_t iomap_readpage_iter(const struct iomap_iter *iter, * what do_mpage_read_folio does. */ if (!ctx->bio) { - ctx->bio = bio_alloc(iomap->bdev, 1, REQ_OP_READ, + ctx->bio = bio_alloc(iomap_bdev(iomap), 1, REQ_OP_READ, orig_gfp); } if (ctx->rac) @@ -662,7 +662,7 @@ static int iomap_read_folio_sync(loff_t block_start, struct folio *folio, struct bio_vec bvec; struct bio bio; - bio_init(&bio, iomap->bdev, &bvec, 1, REQ_OP_READ); + bio_init(&bio, iomap_bdev(iomap), &bvec, 1, REQ_OP_READ); bio.bi_iter.bi_sector = iomap_sector(iomap, block_start); bio_add_folio_nofail(&bio, folio, plen, poff); return submit_bio_wait(&bio); @@ -1684,7 +1684,7 @@ static struct iomap_ioend *iomap_alloc_ioend(struct iomap_writepage_ctx *wpc, struct iomap_ioend *ioend; struct bio *bio; - bio = bio_alloc_bioset(wpc->iomap.bdev, BIO_MAX_VECS, + bio = bio_alloc_bioset(iomap_bdev(&wpc->iomap), BIO_MAX_VECS, REQ_OP_WRITE | wbc_to_write_flags(wbc), GFP_NOFS, &iomap_ioend_bioset); bio->bi_iter.bi_sector = iomap_sector(&wpc->iomap, pos); diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index f3b43d223a46..3e9f54727326 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -56,9 +56,9 @@ static struct bio *iomap_dio_alloc_bio(const struct iomap_iter *iter, struct iomap_dio *dio, unsigned short nr_vecs, blk_opf_t opf) { if (dio->dops && dio->dops->bio_set) - return bio_alloc_bioset(iter->iomap.bdev, nr_vecs, opf, + return bio_alloc_bioset(iomap_bdev(&iter->iomap), nr_vecs, opf, GFP_KERNEL, dio->dops->bio_set); - return bio_alloc(iter->iomap.bdev, nr_vecs, opf, GFP_KERNEL); + return bio_alloc(iomap_bdev(&iter->iomap), nr_vecs, opf, GFP_KERNEL); } static void iomap_dio_submit_bio(const struct iomap_iter *iter, @@ -288,8 +288,8 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, size_t copied = 0; size_t orig_count; - if ((pos | length) & (bdev_logical_block_size(iomap->bdev) - 1) || - !bdev_iter_is_aligned(iomap->bdev, dio->submit.iter)) + if ((pos | length) & (bdev_logical_block_size(iomap_bdev(iomap)) - 1) || + !bdev_iter_is_aligned(iomap_bdev(iomap), dio->submit.iter)) return -EINVAL; if (iomap->type == IOMAP_UNWRITTEN) { @@ -316,7 +316,8 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, */ if (!(iomap->flags & (IOMAP_F_SHARED|IOMAP_F_DIRTY)) && (dio->flags & IOMAP_DIO_WRITE_THROUGH) && - (bdev_fua(iomap->bdev) || !bdev_write_cache(iomap->bdev))) + (bdev_fua(iomap_bdev(iomap)) || + !bdev_write_cache(iomap_bdev(iomap)))) use_fua = true; else if (dio->flags & IOMAP_DIO_NEED_SYNC) dio->flags &= ~IOMAP_DIO_CALLER_COMP; diff --git a/fs/iomap/swapfile.c b/fs/iomap/swapfile.c index 5fc0ac36dee3..20bd67e85d15 100644 --- a/fs/iomap/swapfile.c +++ b/fs/iomap/swapfile.c @@ -116,7 +116,7 @@ static loff_t iomap_swapfile_iter(const struct iomap_iter *iter, return iomap_swapfile_fail(isi, "has shared extents"); /* Only one bdev per swap file. */ - if (iomap->bdev != isi->sis->bdev) + if (iomap_bdev(iomap) != isi->sis->bdev) return iomap_swapfile_fail(isi, "outside the main device"); if (isi->iomap.length == 0) { diff --git a/fs/iomap/trace.h b/fs/iomap/trace.h index 0a991c4ce87d..39ac91fd4a50 100644 --- a/fs/iomap/trace.h +++ b/fs/iomap/trace.h @@ -134,7 +134,8 @@ DECLARE_EVENT_CLASS(iomap_class, __entry->length = iomap->length; __entry->type = iomap->type; __entry->flags = iomap->flags; - __entry->bdev = iomap->bdev ? iomap->bdev->bd_dev : 0; + __entry->bdev = iomap_bdev(iomap) ? + iomap_bdev(iomap)->bd_dev : 0; ), TP_printk("dev %d:%d ino 0x%llx bdev %d:%d addr 0x%llx offset 0x%llx " "length 0x%llx type %s flags %s", @@ -181,7 +182,8 @@ TRACE_EVENT(iomap_writepage_map, __entry->length = iomap->length; __entry->type = iomap->type; __entry->flags = iomap->flags; - __entry->bdev = iomap->bdev ? iomap->bdev->bd_dev : 0; + __entry->bdev = iomap_bdev(iomap) ? + iomap_bdev(iomap)->bd_dev : 0; ), TP_printk("dev %d:%d ino 0x%llx bdev %d:%d pos 0x%llx dirty len 0x%llx " "addr 0x%llx offset 0x%llx length 0x%llx type %s flags %s", diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 4087af7f3c9f..cb4ac7129bce 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -129,7 +129,7 @@ xfs_bmbt_to_iomap( if (mapping_flags & IOMAP_DAX) iomap->dax_dev = target->bt_daxdev; else - iomap->bdev = target->bt_bdev; + iomap_set_bdev_file(iomap, target->bt_bdev_file); iomap->flags = iomap_flags; if (xfs_ipincount(ip) && @@ -154,7 +154,7 @@ xfs_hole_to_iomap( iomap->type = IOMAP_HOLE; iomap->offset = XFS_FSB_TO_B(ip->i_mount, offset_fsb); iomap->length = XFS_FSB_TO_B(ip->i_mount, end_fsb - offset_fsb); - iomap->bdev = target->bt_bdev; + iomap_set_bdev_file(iomap, target->bt_bdev_file); iomap->dax_dev = target->bt_daxdev; } diff --git a/fs/zonefs/file.c b/fs/zonefs/file.c index 3b103715acc9..34100c6e008d 100644 --- a/fs/zonefs/file.c +++ b/fs/zonefs/file.c @@ -38,7 +38,7 @@ static int zonefs_read_iomap_begin(struct inode *inode, loff_t offset, * act as if there is a hole up to the file maximum size. */ mutex_lock(&zi->i_truncate_mutex); - iomap->bdev = inode->i_sb->s_bdev; + iomap_set_bdev_file(iomap, inode->i_sb->s_bdev_file); iomap->offset = ALIGN_DOWN(offset, sb->s_blocksize); isize = i_size_read(inode); if (iomap->offset >= isize) { @@ -88,7 +88,7 @@ static int zonefs_write_iomap_begin(struct inode *inode, loff_t offset, * write pointer) and unwriten beyond. */ mutex_lock(&zi->i_truncate_mutex); - iomap->bdev = inode->i_sb->s_bdev; + iomap_set_bdev_file(iomap, inode->i_sb->s_bdev_file); iomap->offset = ALIGN_DOWN(offset, sb->s_blocksize); iomap->addr = (z->z_sector << SECTOR_SHIFT) + iomap->offset; isize = i_size_read(inode); diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 6fc1c858013d..8ae384f0eeb1 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -105,6 +105,17 @@ struct iomap { u64 validity_cookie; /* used with .iomap_valid() */ }; +static inline struct block_device *iomap_bdev(const struct iomap *iomap) +{ + return iomap->bdev; +} + +static inline void iomap_set_bdev_file(struct iomap *iomap, + struct file *bdev_file) +{ + iomap->bdev = bdev_file ? file_bdev(bdev_file) : NULL; +} + static inline sector_t iomap_sector(const struct iomap *iomap, loff_t pos) { return (iomap->addr + pos - iomap->offset) >> SECTOR_SHIFT; From patchwork Sat Apr 6 09:09:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619759 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95A863BBE5; Sat, 6 Apr 2024 09:17:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395076; cv=none; b=M3+WZoVeefJgAA60vUOqboq6VVOtXpstB5Xb89U7Llt89IKkm83e9BLIRwAcOs0XYHig4ABNAXYNHP3KaBpcTKbGmL1jcKQGF5wnQMO0kJjRgnsEMl4527UZjsi8p1vzZQuJIIANBMqm89t0ZGK7FZNPT4NKyzKkZgs3TOliHSI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395076; c=relaxed/simple; bh=Kh1zow+pxK8H/NTVbdXq3rJd+HWiY01On+hqvTU1d5E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DaNzT0c6apNxg1LZr3J1dOOvRFVvYEQYA9peLWOLZxAme65QAcXT70cqxKoZKhWoqEyKAbFH8SQL9SSINT7Oju4qtmxqgwgRe5C0s3NsOp/LPZ8iDw3muUMCalD2RjohxgvNc8Rj9gzxKl22aooU87v8iyL066My5+uSSza9Etg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVBH4SN0z4f3lfn; Sat, 6 Apr 2024 17:17:43 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 1E2131A0568; Sat, 6 Apr 2024 17:17:52 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S28; Sat, 06 Apr 2024 17:17:51 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 24/26] iomap: convert to use bdev_file Date: Sat, 6 Apr 2024 17:09:28 +0800 Message-Id: <20240406090930.2252838-25-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S28 X-Coremail-Antispam: 1UD129KBjvJXoW7AF4UJw1fXFy3Jw4rGFyrCrg_yoW8Gw4kpF n0kFyUKFW8Gr1UuFZrJ3yxZryYywn8G34UZry5W3y5GrWUtr92gFn5CF1jva48XrWvyan8 XFyqgry8Cr1rC3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBSb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Xr0_Ar1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAI cVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2js IEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai With previous commit both filesystems and raw block device provide bdev_file while initializing iomap, it's safe to convert to use bdev_file. Prepare to remove bd_inode from block_device after convert buffer_head to use bdev_file as well. Signed-off-by: Yu Kuai --- include/linux/iomap.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 8ae384f0eeb1..1386f3a618fe 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -97,7 +97,7 @@ struct iomap { u64 length; /* length of mapping, bytes */ u16 type; /* type of mapping */ u16 flags; /* flags for mapping */ - struct block_device *bdev; /* block device for I/O */ + struct file *bdev_file; /* block device for I/O */ struct dax_device *dax_dev; /* dax_dev for dax operations */ void *inline_data; void *private; /* filesystem private */ @@ -107,13 +107,13 @@ struct iomap { static inline struct block_device *iomap_bdev(const struct iomap *iomap) { - return iomap->bdev; + return iomap->bdev_file ? file_bdev(iomap->bdev_file) : NULL; } static inline void iomap_set_bdev_file(struct iomap *iomap, struct file *bdev_file) { - iomap->bdev = bdev_file ? file_bdev(bdev_file) : NULL; + iomap->bdev_file = bdev_file; } static inline sector_t iomap_sector(const struct iomap *iomap, loff_t pos) From patchwork Sat Apr 6 09:09:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619761 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BF8522EF4; Sat, 6 Apr 2024 09:17:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395077; cv=none; b=JxnvO5PiQ6kzVxdikMzz1GNwI0si+A/j4L1ui/g3RfYKhwH834BMHW6SXcFc3Ywdh3caYNgxJT9snCEr8ZTJaYOGjUbjic+afanqOKPYC+QjpzIXB1Rt9Eri7TxJuf4iwZStkzUNafDBR3SNSVNyOtj/edpn/1Df4rc48yP7yNw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395077; c=relaxed/simple; bh=uuwI0ExCc5LHc3HCq/LUZaJS3kD1vKo2Qex/s185n0c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=T6fu3aoXN/K0Uvd1W/0JL9/Q0Oc/9LV4+25OtNRd6XVFfNg/c279cMX5Vm2PW7nSbORbcHVQyMfEaUFtC5gt73Q2HWylze/QTOqr1e0fd4cFVLpXMlm1wCnDHHfXs9fHOu6OBsAiDinYT6Cy2zN7LbCxn6DxNI3R0iUCloaXguA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVBJ0JTQz4f3lfx; Sat, 6 Apr 2024 17:17:44 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 861671A058D; Sat, 6 Apr 2024 17:17:52 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S29; Sat, 06 Apr 2024 17:17:52 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 25/26] buffer: add helpers to get and set bdev Date: Sat, 6 Apr 2024 17:09:29 +0800 Message-Id: <20240406090930.2252838-26-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S29 X-Coremail-Antispam: 1UD129KBjvAXoW3KF17XF18uw4ktw15Gr47CFg_yoW8ZrW7Ao Wavw4xXr48t3sFy3yIkryFqFyUJasxtrZ5JF48WFZ8ua4ftr1q9ry3Kw12ya4xGw1FkryY grW5Jw45XF4Uu3ykn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjp_UUUYu7kC6x804xWl14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK 8VAvwI8IcIk0rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF 0E3s1l82xGYIkIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vE j48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxV AFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x02 67AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I 80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCj c4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4IIrI8v6xkF7I0E8cxan2IY04v7MxAIw28Icx kI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2Iq xVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42 IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UMIIF 0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87 Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7IU13l1DUUUUU== X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai So that we have unified APIs, there are no functional changes and prepare to convert buffer_head to use bdev_file. Signed-off-by: Yu Kuai --- block/fops.c | 2 +- drivers/md/md-bitmap.c | 2 +- fs/affs/file.c | 2 +- fs/buffer.c | 10 +++++----- fs/direct-io.c | 4 ++-- fs/ext2/xattr.c | 2 +- fs/ext4/mmp.c | 2 +- fs/ext4/page-io.c | 5 ++--- fs/ext4/xattr.c | 2 +- fs/gfs2/aops.c | 2 +- fs/gfs2/meta_io.c | 2 +- fs/jbd2/commit.c | 2 +- fs/jbd2/journal.c | 2 +- fs/jbd2/transaction.c | 8 ++++---- fs/mpage.c | 10 +++++----- fs/nilfs2/btnode.c | 4 ++-- fs/nilfs2/gcinode.c | 2 +- fs/nilfs2/mdt.c | 2 +- fs/nilfs2/page.c | 4 ++-- fs/ntfs3/inode.c | 2 +- fs/reiserfs/fix_node.c | 2 +- fs/reiserfs/journal.c | 2 +- fs/reiserfs/prints.c | 4 ++-- fs/reiserfs/stree.c | 2 +- fs/reiserfs/tail_conversion.c | 2 +- include/linux/buffer_head.h | 20 +++++++++++++++++++- include/trace/events/block.h | 2 +- 27 files changed, 61 insertions(+), 44 deletions(-) diff --git a/block/fops.c b/block/fops.c index 7d177be788cd..edae216e31dd 100644 --- a/block/fops.c +++ b/block/fops.c @@ -407,7 +407,7 @@ static const struct iomap_ops blkdev_iomap_ops = { static int blkdev_get_block(struct inode *inode, sector_t iblock, struct buffer_head *bh, int create) { - bh->b_bdev = I_BDEV(inode); + bh_set_bdev_file(bh, inode->i_private); bh->b_blocknr = iblock; set_buffer_mapped(bh); return 0; diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c index 059afc24c08b..fd6c95e0c625 100644 --- a/drivers/md/md-bitmap.c +++ b/drivers/md/md-bitmap.c @@ -381,7 +381,7 @@ static int read_file_page(struct file *file, unsigned long index, } bh->b_blocknr = block; - bh->b_bdev = inode->i_sb->s_bdev; + bh_set_bdev_file(bh, inode->i_sb->s_bdev_file); if (count < blocksize) count = 0; else diff --git a/fs/affs/file.c b/fs/affs/file.c index 04c018e19602..f15b24202aab 100644 --- a/fs/affs/file.c +++ b/fs/affs/file.c @@ -365,7 +365,7 @@ affs_get_block(struct inode *inode, sector_t block, struct buffer_head *bh_resul err_alloc: brelse(ext_bh); clear_buffer_mapped(bh_result); - bh_result->b_bdev = NULL; + bh_set_bdev_file(bh_result, NULL); // unlock cache affs_unlock_ext(inode); return -ENOSPC; diff --git a/fs/buffer.c b/fs/buffer.c index 7900720fc54b..e4d74eb63265 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -129,7 +129,7 @@ static void buffer_io_error(struct buffer_head *bh, char *msg) if (!test_bit(BH_Quiet, &bh->b_state)) printk_ratelimited(KERN_ERR "Buffer I/O error on dev %pg, logical block %llu%s\n", - bh->b_bdev, (unsigned long long)bh->b_blocknr, msg); + bh_bdev(bh), (unsigned long long)bh->b_blocknr, msg); } /* @@ -1367,7 +1367,7 @@ lookup_bh_lru(struct block_device *bdev, sector_t block, unsigned size) for (i = 0; i < BH_LRU_SIZE; i++) { struct buffer_head *bh = __this_cpu_read(bh_lrus.bhs[i]); - if (bh && bh->b_blocknr == block && bh->b_bdev == bdev && + if (bh && bh->b_blocknr == block && bh_bdev(bh) == bdev && bh->b_size == size) { if (i) { while (i) { @@ -1564,7 +1564,7 @@ static void discard_buffer(struct buffer_head * bh) lock_buffer(bh); clear_buffer_dirty(bh); - bh->b_bdev = NULL; + bh_set_bdev_file(bh, NULL); b_state = READ_ONCE(bh->b_state); do { } while (!try_cmpxchg(&bh->b_state, &b_state, @@ -2005,7 +2005,7 @@ iomap_to_bh(struct inode *inode, sector_t block, struct buffer_head *bh, { loff_t offset = (loff_t)block << inode->i_blkbits; - bh->b_bdev = iomap_bdev(iomap); + bh_set_bdev_file(bh, iomap->bdev_file); /* * Block points to offset in file we need to map, iomap contains @@ -2781,7 +2781,7 @@ static void submit_bh_wbc(blk_opf_t opf, struct buffer_head *bh, if (buffer_prio(bh)) opf |= REQ_PRIO; - bio = bio_alloc(bh->b_bdev, 1, opf, GFP_NOIO); + bio = bio_alloc(bh_bdev(bh), 1, opf, GFP_NOIO); fscrypt_set_bio_crypt_ctx_bh(bio, bh, GFP_NOIO); diff --git a/fs/direct-io.c b/fs/direct-io.c index 62c97ff9e852..49475f530e0f 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -673,7 +673,7 @@ static inline int dio_new_bio(struct dio *dio, struct dio_submit *sdio, sector = start_sector << (sdio->blkbits - 9); nr_pages = bio_max_segs(sdio->pages_in_io); BUG_ON(nr_pages <= 0); - dio_bio_alloc(dio, sdio, map_bh->b_bdev, sector, nr_pages); + dio_bio_alloc(dio, sdio, bh_bdev(map_bh), sector, nr_pages); sdio->boundary = 0; out: return ret; @@ -948,7 +948,7 @@ static int do_direct_IO(struct dio *dio, struct dio_submit *sdio, map_bh->b_blocknr << sdio->blkfactor; if (buffer_new(map_bh)) { clean_bdev_aliases( - map_bh->b_bdev, + bh_bdev(map_bh), map_bh->b_blocknr, map_bh->b_size >> i_blkbits); } diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c index c885dcc3bd0d..42e595e87a74 100644 --- a/fs/ext2/xattr.c +++ b/fs/ext2/xattr.c @@ -80,7 +80,7 @@ } while (0) # define ea_bdebug(bh, f...) do { \ printk(KERN_DEBUG "block %pg:%lu: ", \ - bh->b_bdev, (unsigned long) bh->b_blocknr); \ + bh_bdev(bh), (unsigned long) bh->b_blocknr); \ printk(f); \ printk("\n"); \ } while (0) diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c index bd946d0c71b7..5641bd34d021 100644 --- a/fs/ext4/mmp.c +++ b/fs/ext4/mmp.c @@ -384,7 +384,7 @@ int ext4_multi_mount_protect(struct super_block *sb, BUILD_BUG_ON(sizeof(mmp->mmp_bdevname) < BDEVNAME_SIZE); snprintf(mmp->mmp_bdevname, sizeof(mmp->mmp_bdevname), - "%pg", bh->b_bdev); + "%pg", bh_bdev(bh)); /* * Start a kernel thread to update the MMP block periodically. diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c index 312bc6813357..1b02b6a28eca 100644 --- a/fs/ext4/page-io.c +++ b/fs/ext4/page-io.c @@ -93,8 +93,7 @@ struct ext4_io_end_vec *ext4_last_io_end_vec(ext4_io_end_t *io_end) static void buffer_io_error(struct buffer_head *bh) { printk_ratelimited(KERN_ERR "Buffer I/O error on device %pg, logical block %llu\n", - bh->b_bdev, - (unsigned long long)bh->b_blocknr); + bh_bdev(bh), (unsigned long long)bh->b_blocknr); } static void ext4_finish_bio(struct bio *bio) @@ -397,7 +396,7 @@ static void io_submit_init_bio(struct ext4_io_submit *io, * bio_alloc will _always_ be able to allocate a bio if * __GFP_DIRECT_RECLAIM is set, see comments for bio_alloc_bioset(). */ - bio = bio_alloc(bh->b_bdev, BIO_MAX_VECS, REQ_OP_WRITE, GFP_NOIO); + bio = bio_alloc(bh_bdev(bh), BIO_MAX_VECS, REQ_OP_WRITE, GFP_NOIO); fscrypt_set_bio_crypt_ctx_bh(bio, bh, GFP_NOIO); bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9); bio->bi_end_io = ext4_end_bio; diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index b67a176bfcf9..005af215e24a 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -68,7 +68,7 @@ inode->i_sb->s_id, inode->i_ino, ##__VA_ARGS__) # define ea_bdebug(bh, fmt, ...) \ printk(KERN_DEBUG "block %pg:%lu: " fmt "\n", \ - bh->b_bdev, (unsigned long)bh->b_blocknr, ##__VA_ARGS__) + bh_bdev(bh), (unsigned long)bh->b_blocknr, ##__VA_ARGS__) #else # define ea_idebug(inode, fmt, ...) no_printk(fmt, ##__VA_ARGS__) # define ea_bdebug(bh, fmt, ...) no_printk(fmt, ##__VA_ARGS__) diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c index 974aca9c8ea8..24b6cf9021ca 100644 --- a/fs/gfs2/aops.c +++ b/fs/gfs2/aops.c @@ -622,7 +622,7 @@ static void gfs2_discard(struct gfs2_sbd *sdp, struct buffer_head *bh) spin_unlock(&sdp->sd_ail_lock); } } - bh->b_bdev = NULL; + bh_set_bdev_file(bh, NULL); clear_buffer_mapped(bh); clear_buffer_req(bh); clear_buffer_new(bh); diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index f814054c8cd0..2052d3fc2c24 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c @@ -218,7 +218,7 @@ static void gfs2_submit_bhs(blk_opf_t opf, struct buffer_head *bhs[], int num) struct buffer_head *bh = *bhs; struct bio *bio; - bio = bio_alloc(bh->b_bdev, num, opf, GFP_NOIO); + bio = bio_alloc(bh_bdev(bh), num, opf, GFP_NOIO); bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9); while (num > 0) { bh = *bhs; diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c index 5e122586e06e..413f32b2f308 100644 --- a/fs/jbd2/commit.c +++ b/fs/jbd2/commit.c @@ -1014,7 +1014,7 @@ void jbd2_journal_commit_transaction(journal_t *journal) clear_buffer_mapped(bh); clear_buffer_new(bh); clear_buffer_req(bh); - bh->b_bdev = NULL; + bh_set_bdev_file(bh, NULL); } } diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index abd42a6ccd0e..c1ce32d99267 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -434,7 +434,7 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction, folio_set_bh(new_bh, new_folio, new_offset); new_bh->b_size = bh_in->b_size; - new_bh->b_bdev = journal->j_dev; + bh_set_bdev_file(new_bh, journal->j_dev_file); new_bh->b_blocknr = blocknr; new_bh->b_private = bh_in; set_buffer_mapped(new_bh); diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c index cb0b8d6fc0c6..04021f54ca97 100644 --- a/fs/jbd2/transaction.c +++ b/fs/jbd2/transaction.c @@ -929,7 +929,7 @@ static void warn_dirty_buffer(struct buffer_head *bh) "JBD2: Spotted dirty metadata buffer (dev = %pg, blocknr = %llu). " "There's a risk of filesystem corruption in case of system " "crash.\n", - bh->b_bdev, (unsigned long long)bh->b_blocknr); + bh_bdev(bh), (unsigned long long)bh->b_blocknr); } /* Call t_frozen trigger and copy buffer data into jh->b_frozen_data. */ @@ -990,7 +990,7 @@ do_get_write_access(handle_t *handle, struct journal_head *jh, /* If it takes too long to lock the buffer, trace it */ time_lock = jbd2_time_diff(start_lock, jiffies); if (time_lock > HZ/10) - trace_jbd2_lock_buffer_stall(bh->b_bdev->bd_dev, + trace_jbd2_lock_buffer_stall(bh_bdev(bh)->bd_dev, jiffies_to_msecs(time_lock)); /* We now hold the buffer lock so it is safe to query the buffer @@ -2374,7 +2374,7 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh, write_unlock(&journal->j_state_lock); jbd2_journal_put_journal_head(jh); /* Already zapped buffer? Nothing to do... */ - if (!bh->b_bdev) + if (!bh_bdev(bh)) return 0; return -EBUSY; } @@ -2428,7 +2428,7 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh, clear_buffer_new(bh); clear_buffer_delay(bh); clear_buffer_unwritten(bh); - bh->b_bdev = NULL; + bh_set_bdev_file(bh, NULL); return may_free; } diff --git a/fs/mpage.c b/fs/mpage.c index fa8b99a199fa..40594afa63cb 100644 --- a/fs/mpage.c +++ b/fs/mpage.c @@ -126,7 +126,7 @@ static void map_buffer_to_folio(struct folio *folio, struct buffer_head *bh, do { if (block == page_block) { page_bh->b_state = bh->b_state; - page_bh->b_bdev = bh->b_bdev; + bh_copy_bdev_file(page_bh, bh); page_bh->b_blocknr = bh->b_blocknr; break; } @@ -216,7 +216,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) page_block++; block_in_file++; } - bdev = map_bh->b_bdev; + bdev = bh_bdev(map_bh); } /* @@ -272,7 +272,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) page_block++; block_in_file++; } - bdev = map_bh->b_bdev; + bdev = bh_bdev(map_bh); } if (first_hole != blocks_per_page) { @@ -515,7 +515,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, boundary_block = bh->b_blocknr; boundary_bdev = bh->b_bdev; } - bdev = bh->b_bdev; + bdev = bh_bdev(bh); } while ((bh = bh->b_this_page) != head); if (first_unmapped) @@ -565,7 +565,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, } page_block++; boundary = buffer_boundary(&map_bh); - bdev = map_bh.b_bdev; + bdev = bh_bdev(&map_bh); if (block_in_file == last_block) break; block_in_file++; diff --git a/fs/nilfs2/btnode.c b/fs/nilfs2/btnode.c index 0131d83b912d..3f81d00fc031 100644 --- a/fs/nilfs2/btnode.c +++ b/fs/nilfs2/btnode.c @@ -59,7 +59,7 @@ nilfs_btnode_create_block(struct address_space *btnc, __u64 blocknr) BUG(); } memset(bh->b_data, 0, i_blocksize(inode)); - bh->b_bdev = inode->i_sb->s_bdev; + bh_set_bdev_file(bh, inode->i_sb->s_bdev_file); bh->b_blocknr = blocknr; set_buffer_mapped(bh); set_buffer_uptodate(bh); @@ -118,7 +118,7 @@ int nilfs_btnode_submit_block(struct address_space *btnc, __u64 blocknr, goto found; } set_buffer_mapped(bh); - bh->b_bdev = inode->i_sb->s_bdev; + bh_set_bdev_file(bh, inode->i_sb->s_bdev_file); bh->b_blocknr = pblocknr; /* set block address for read */ bh->b_end_io = end_buffer_read_sync; get_bh(bh); diff --git a/fs/nilfs2/gcinode.c b/fs/nilfs2/gcinode.c index bf9a11d58817..83d2b5e034ad 100644 --- a/fs/nilfs2/gcinode.c +++ b/fs/nilfs2/gcinode.c @@ -84,7 +84,7 @@ int nilfs_gccache_submit_read_data(struct inode *inode, sector_t blkoff, } if (!buffer_mapped(bh)) { - bh->b_bdev = inode->i_sb->s_bdev; + bh_set_bdev_file(bh, inode->i_sb->s_bdev_file); set_buffer_mapped(bh); } bh->b_blocknr = pbn; diff --git a/fs/nilfs2/mdt.c b/fs/nilfs2/mdt.c index 4f792a0ad0f0..10f33017a1c9 100644 --- a/fs/nilfs2/mdt.c +++ b/fs/nilfs2/mdt.c @@ -89,7 +89,7 @@ static int nilfs_mdt_create_block(struct inode *inode, unsigned long block, if (buffer_uptodate(bh)) goto failed_bh; - bh->b_bdev = sb->s_bdev; + bh_set_bdev_file(bh, sb->s_bdev_file); err = nilfs_mdt_insert_new_block(inode, block, bh, init_block); if (likely(!err)) { get_bh(bh); diff --git a/fs/nilfs2/page.c b/fs/nilfs2/page.c index 14e470fb8870..b6cc95dd13c0 100644 --- a/fs/nilfs2/page.c +++ b/fs/nilfs2/page.c @@ -111,7 +111,7 @@ void nilfs_copy_buffer(struct buffer_head *dbh, struct buffer_head *sbh) dbh->b_state = sbh->b_state & NILFS_BUFFER_INHERENT_BITS; dbh->b_blocknr = sbh->b_blocknr; - dbh->b_bdev = sbh->b_bdev; + bh_copy_bdev_file(dbh, sbh); bh = dbh; bits = sbh->b_state & (BIT(BH_Uptodate) | BIT(BH_Mapped)); @@ -216,7 +216,7 @@ static void nilfs_copy_folio(struct folio *dst, struct folio *src, lock_buffer(dbh); dbh->b_state = sbh->b_state & mask; dbh->b_blocknr = sbh->b_blocknr; - dbh->b_bdev = sbh->b_bdev; + bh_copy_bdev_file(dbh, sbh); sbh = sbh->b_this_page; dbh = dbh->b_this_page; } while (dbh != dbufs); diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index 3c4c878f6d77..c795fd2000ee 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -609,7 +609,7 @@ static noinline int ntfs_get_block_vbo(struct inode *inode, u64 vbo, lbo = ((u64)lcn << cluster_bits) + off; set_buffer_mapped(bh); - bh->b_bdev = sb->s_bdev; + bh_set_bdev_file(bh, sb->s_bdev_file); bh->b_blocknr = lbo >> sb->s_blocksize_bits; valid = ni->i_valid; diff --git a/fs/reiserfs/fix_node.c b/fs/reiserfs/fix_node.c index 6c13a8d9a73c..2b288b1539d9 100644 --- a/fs/reiserfs/fix_node.c +++ b/fs/reiserfs/fix_node.c @@ -2332,7 +2332,7 @@ static void tb_buffer_sanity_check(struct super_block *sb, "in tree %s[%d] (%b)", descr, level, bh); - if (bh->b_bdev != sb->s_bdev) + if (bh_bdev(bh) != sb->s_bdev) reiserfs_panic(sb, "jmacd-4", "buffer has wrong " "device %s[%d] (%b)", descr, level, bh); diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c index e539ccd39e1e..724113cb79d3 100644 --- a/fs/reiserfs/journal.c +++ b/fs/reiserfs/journal.c @@ -618,7 +618,7 @@ static void reiserfs_end_buffer_io_sync(struct buffer_head *bh, int uptodate) if (buffer_journaled(bh)) { reiserfs_warning(NULL, "clm-2084", "pinned buffer %lu:%pg sent to disk", - bh->b_blocknr, bh->b_bdev); + bh->b_blocknr, bh_bdev(bh)); } if (uptodate) set_buffer_uptodate(bh); diff --git a/fs/reiserfs/prints.c b/fs/reiserfs/prints.c index 84a194b77f19..249a458b6e28 100644 --- a/fs/reiserfs/prints.c +++ b/fs/reiserfs/prints.c @@ -156,7 +156,7 @@ static int scnprintf_buffer_head(char *buf, size_t size, struct buffer_head *bh) { return scnprintf(buf, size, "dev %pg, size %zd, blocknr %llu, count %d, state 0x%lx, page %p, (%s, %s, %s)", - bh->b_bdev, bh->b_size, + bh_bdev(bh), bh->b_size, (unsigned long long)bh->b_blocknr, atomic_read(&(bh->b_count)), bh->b_state, bh->b_page, @@ -561,7 +561,7 @@ static int print_super_block(struct buffer_head *bh) return 1; } - printk("%pg\'s super block is in block %llu\n", bh->b_bdev, + printk("%pg\'s super block is in block %llu\n", bh_bdev(bh), (unsigned long long)bh->b_blocknr); printk("Reiserfs version %s\n", version); printk("Block count %u\n", sb_block_count(rs)); diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c index 5faf702f8d15..23998f071d9c 100644 --- a/fs/reiserfs/stree.c +++ b/fs/reiserfs/stree.c @@ -331,7 +331,7 @@ static inline int key_in_buffer( || chk_path->path_length > MAX_HEIGHT, "PAP-5050: pointer to the key(%p) is NULL or invalid path length(%d)", key, chk_path->path_length); - RFALSE(!PATH_PLAST_BUFFER(chk_path)->b_bdev, + RFALSE(!bh_bdev(PATH_PLAST_BUFFER(chk_path)), "PAP-5060: device must not be NODEV"); if (comp_keys(get_lkey(chk_path, sb), key) == 1) diff --git a/fs/reiserfs/tail_conversion.c b/fs/reiserfs/tail_conversion.c index 2cec61af2a9e..300e6737a0db 100644 --- a/fs/reiserfs/tail_conversion.c +++ b/fs/reiserfs/tail_conversion.c @@ -187,7 +187,7 @@ void reiserfs_unmap_buffer(struct buffer_head *bh) clear_buffer_mapped(bh); clear_buffer_req(bh); clear_buffer_new(bh); - bh->b_bdev = NULL; + bh_set_bdev_file(bh, NULL); unlock_buffer(bh); } diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h index d78454a4dd1f..4c6f0d0332c8 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -136,6 +137,23 @@ BUFFER_FNS(Meta, meta) BUFFER_FNS(Prio, prio) BUFFER_FNS(Defer_Completion, defer_completion) +static __always_inline void bh_set_bdev_file(struct buffer_head *bh, + struct file *bdev_file) +{ + bh->b_bdev = bdev_file ? file_bdev(bdev_file) : NULL; +} + +static __always_inline void bh_copy_bdev_file(struct buffer_head *dbh, + struct buffer_head *sbh) +{ + dbh->b_bdev = sbh->b_bdev; +} + +static __always_inline struct block_device *bh_bdev(struct buffer_head *bh) +{ + return bh->b_bdev; +} + static __always_inline void set_buffer_uptodate(struct buffer_head *bh) { /* @@ -377,7 +395,7 @@ static inline void map_bh(struct buffer_head *bh, struct super_block *sb, sector_t block) { set_buffer_mapped(bh); - bh->b_bdev = sb->s_bdev; + bh_set_bdev_file(bh, sb->s_bdev_file); bh->b_blocknr = block; bh->b_size = sb->s_blocksize; } diff --git a/include/trace/events/block.h b/include/trace/events/block.h index 0e128ad51460..95d3ed978864 100644 --- a/include/trace/events/block.h +++ b/include/trace/events/block.h @@ -26,7 +26,7 @@ DECLARE_EVENT_CLASS(block_buffer, ), TP_fast_assign( - __entry->dev = bh->b_bdev->bd_dev; + __entry->dev = bh_bdev(bh)->bd_dev; __entry->sector = bh->b_blocknr; __entry->size = bh->b_size; ), From patchwork Sat Apr 6 09:09:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13619762 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A30D03C092; Sat, 6 Apr 2024 09:17:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395078; cv=none; b=S19tmRAADlGl2CFkE1BLsLu5f3IZwPqrXooFfcPn7XdSMqA38hyJhVKznF/7UcWm6WQqctTZvLR4QKIg85LGtQB6ItxhR6xCNkJ1VLYbW1amY8sFHC+fAPTlw8FHDiVl6Kz2o1gEzQAefDuBrBVuJ8Vg7330bt0u/76DI0kE6lM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712395078; c=relaxed/simple; bh=saNPSwf7+Kc5VskVq4X9Yf9v8StZ+QKsIgEh1fzfkGE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bCpwoNeSS9Rhjs+6XPX1tiXH/2rzIZPcMbKB0MclGOHAnrCTN/DXNSg0aXxmzA1tXi1dy/hGEBzsWSgvznTAAaH52ThcYPUrVRyBs5XKD9+i4pQSAt1evB3WNkDpzTfpM5aRZXWCJ3HZoi/rfmNMUtt3pqoCQJJ6yIemyCN5F1I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VBVBJ3kJCz4f3lg7; Sat, 6 Apr 2024 17:17:44 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 026F61A0568; Sat, 6 Apr 2024 17:17:53 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REyExFm0JDpJA--.50223S30; Sat, 06 Apr 2024 17:17:52 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, viro@zeniv.linux.org.uk, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: [PATCH vfs.all 26/26] buffer: convert to use bdev_file Date: Sat, 6 Apr 2024 17:09:30 +0800 Message-Id: <20240406090930.2252838-27-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240406090930.2252838-1-yukuai1@huaweicloud.com> References: <20240406090930.2252838-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+REyExFm0JDpJA--.50223S30 X-Coremail-Antispam: 1UD129KBjvAXoWfAryxJFyUJFy8WF4kXr13Arb_yoW5Kw4Uto Waqw4fZF4rt3yUJ34IyryvqryUZayDKw13Jr4rGFZ0v3Z5tw1jk343KF45J34fG3WFkryY gryfJw4ruF4UCr48n29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjp_UUUYu7kC6x804xWl14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK 8VAvwI8IcIk0rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF 0E3s1l82xGYIkIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vE j48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxV AFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x02 67AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I 80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCj c4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4IIrI8v6xkF7I0E8cxan2IY04v7MxAIw28Icx kI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2Iq xVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42 IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UMIIF 0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87 Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7IU13l1DUUUUU== X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai With previous commit both filesystems and raw block device provide bdev_file, it's safe to convert to use bdev_file. Now that there are no users of bd_inode anymore, remove bd_inode from block_device as well. Signed-off-by: Yu Kuai --- block/bdev.c | 1 - fs/buffer.c | 96 +++++++++++++++++++------------------ fs/direct-io.c | 2 +- fs/ext2/inode.c | 2 +- fs/ext4/super.c | 4 +- fs/jbd2/journal.c | 6 +-- fs/jbd2/recovery.c | 9 ++-- fs/jbd2/revoke.c | 14 +++--- fs/mpage.c | 8 ++-- fs/nilfs2/recovery.c | 27 +++++++---- fs/ntfs3/fsntfs.c | 10 ++-- fs/ntfs3/super.c | 6 +-- fs/ocfs2/journal.c | 2 +- fs/reiserfs/journal.c | 8 ++-- fs/reiserfs/reiserfs.h | 6 +-- include/linux/blk_types.h | 1 - include/linux/buffer_head.h | 67 +++++++++++++------------- 17 files changed, 141 insertions(+), 128 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index 3d300823da6b..31972a7bd358 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -412,7 +412,6 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno) spin_lock_init(&bdev->bd_size_lock); mutex_init(&bdev->bd_holder_lock); bdev->bd_partno = partno; - bdev->bd_inode = inode; bdev->bd_queue = disk->queue; if (partno) bdev->bd_has_submit_bio = disk->part0->bd_has_submit_bio; diff --git a/fs/buffer.c b/fs/buffer.c index e4d74eb63265..a84e9878b52f 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -187,9 +187,9 @@ EXPORT_SYMBOL(end_buffer_write_sync); * succeeds, there is no need to take i_private_lock. */ static struct buffer_head * -__find_get_block_slow(struct block_device *bdev, sector_t block) +__find_get_block_slow(struct file *bdev_file, sector_t block) { - struct inode *bd_inode = bdev->bd_inode; + struct inode *bd_inode = file_inode(bdev_file); struct address_space *bd_mapping = bd_inode->i_mapping; struct buffer_head *ret = NULL; pgoff_t index; @@ -232,7 +232,7 @@ __find_get_block_slow(struct block_device *bdev, sector_t block) "device %pg blocksize: %d\n", (unsigned long long)block, (unsigned long long)bh->b_blocknr, - bh->b_state, bh->b_size, bdev, + bh->b_state, bh->b_size, file_bdev(bdev_file), 1 << bd_inode->i_blkbits); } out_unlock: @@ -655,10 +655,12 @@ EXPORT_SYMBOL(generic_buffers_fsync); * `bblock + 1' is probably a dirty indirect block. Hunt it down and, if it's * dirty, schedule it for IO. So that indirects merge nicely with their data. */ -void write_boundary_block(struct block_device *bdev, - sector_t bblock, unsigned blocksize) +void write_boundary_block(struct file *bdev_file, sector_t bblock, + unsigned int blocksize) { - struct buffer_head *bh = __find_get_block(bdev, bblock + 1, blocksize); + struct buffer_head *bh = __find_get_block(bdev_file, bblock + 1, + blocksize); + if (bh) { if (buffer_dirty(bh)) write_dirty_buffer(bh, 0); @@ -992,21 +994,21 @@ static sector_t blkdev_max_block(struct block_device *bdev, unsigned int size) /* * Initialise the state of a blockdev folio's buffers. - */ -static sector_t folio_init_buffers(struct folio *folio, - struct block_device *bdev, unsigned size) + */ +static sector_t folio_init_buffers(struct folio *folio, struct file *bdev_file, + unsigned int size) { struct buffer_head *head = folio_buffers(folio); struct buffer_head *bh = head; bool uptodate = folio_test_uptodate(folio); sector_t block = div_u64(folio_pos(folio), size); - sector_t end_block = blkdev_max_block(bdev, size); + sector_t end_block = blkdev_max_block(file_bdev(bdev_file), size); do { if (!buffer_mapped(bh)) { bh->b_end_io = NULL; bh->b_private = NULL; - bh->b_bdev = bdev; + bh->b_bdev_file = bdev_file; bh->b_blocknr = block; if (uptodate) set_buffer_uptodate(bh); @@ -1031,10 +1033,10 @@ static sector_t folio_init_buffers(struct folio *folio, * Returns false if we have a failure which cannot be cured by retrying * without sleeping. Returns true if we succeeded, or the caller should retry. */ -static bool grow_dev_folio(struct block_device *bdev, sector_t block, - pgoff_t index, unsigned size, gfp_t gfp) +static bool grow_dev_folio(struct file *bdev_file, sector_t block, + pgoff_t index, unsigned int size, gfp_t gfp) { - struct inode *inode = bdev->bd_inode; + struct inode *inode = file_inode(bdev_file); struct folio *folio; struct buffer_head *bh; sector_t end_block = 0; @@ -1047,7 +1049,7 @@ static bool grow_dev_folio(struct block_device *bdev, sector_t block, bh = folio_buffers(folio); if (bh) { if (bh->b_size == size) { - end_block = folio_init_buffers(folio, bdev, size); + end_block = folio_init_buffers(folio, bdev_file, size); goto unlock; } @@ -1075,7 +1077,7 @@ static bool grow_dev_folio(struct block_device *bdev, sector_t block, */ spin_lock(&inode->i_mapping->i_private_lock); link_dev_buffers(folio, bh); - end_block = folio_init_buffers(folio, bdev, size); + end_block = folio_init_buffers(folio, bdev_file, size); spin_unlock(&inode->i_mapping->i_private_lock); unlock: folio_unlock(folio); @@ -1088,8 +1090,8 @@ static bool grow_dev_folio(struct block_device *bdev, sector_t block, * that folio was dirty, the buffers are set dirty also. Returns false * if we've hit a permanent error. */ -static bool grow_buffers(struct block_device *bdev, sector_t block, - unsigned size, gfp_t gfp) +static bool grow_buffers(struct file *bdev_file, sector_t block, + unsigned int size, gfp_t gfp) { loff_t pos; @@ -1100,18 +1102,20 @@ static bool grow_buffers(struct block_device *bdev, sector_t block, if (check_mul_overflow(block, (sector_t)size, &pos) || pos > MAX_LFS_FILESIZE) { printk(KERN_ERR "%s: requested out-of-range block %llu for device %pg\n", __func__, (unsigned long long)block, - bdev); + file_bdev(bdev_file)); return false; } /* Create a folio with the proper size buffers */ - return grow_dev_folio(bdev, block, pos / PAGE_SIZE, size, gfp); + return grow_dev_folio(bdev_file, block, pos / PAGE_SIZE, size, gfp); } static struct buffer_head * -__getblk_slow(struct block_device *bdev, sector_t block, - unsigned size, gfp_t gfp) +__getblk_slow(struct file *bdev_file, sector_t block, unsigned int size, + gfp_t gfp) { + struct block_device *bdev = file_bdev(bdev_file); + /* Size must be multiple of hard sectorsize */ if (unlikely(size & (bdev_logical_block_size(bdev)-1) || (size < 512 || size > PAGE_SIZE))) { @@ -1127,11 +1131,11 @@ __getblk_slow(struct block_device *bdev, sector_t block, for (;;) { struct buffer_head *bh; - bh = __find_get_block(bdev, block, size); + bh = __find_get_block(bdev_file, block, size); if (bh) return bh; - if (!grow_buffers(bdev, block, size, gfp)) + if (!grow_buffers(bdev_file, block, size, gfp)) return NULL; } } @@ -1353,7 +1357,7 @@ static void bh_lru_install(struct buffer_head *bh) * Look up the bh in this cpu's LRU. If it's there, move it to the head. */ static struct buffer_head * -lookup_bh_lru(struct block_device *bdev, sector_t block, unsigned size) +lookup_bh_lru(struct file *bdev_file, sector_t block, unsigned int size) { struct buffer_head *ret = NULL; unsigned int i; @@ -1367,8 +1371,8 @@ lookup_bh_lru(struct block_device *bdev, sector_t block, unsigned size) for (i = 0; i < BH_LRU_SIZE; i++) { struct buffer_head *bh = __this_cpu_read(bh_lrus.bhs[i]); - if (bh && bh->b_blocknr == block && bh_bdev(bh) == bdev && - bh->b_size == size) { + if (bh && bh->b_blocknr == block && + bh_bdev(bh) == file_bdev(bdev_file) && bh->b_size == size) { if (i) { while (i) { __this_cpu_write(bh_lrus.bhs[i], @@ -1392,13 +1396,13 @@ lookup_bh_lru(struct block_device *bdev, sector_t block, unsigned size) * NULL */ struct buffer_head * -__find_get_block(struct block_device *bdev, sector_t block, unsigned size) +__find_get_block(struct file *bdev_file, sector_t block, unsigned int size) { - struct buffer_head *bh = lookup_bh_lru(bdev, block, size); + struct buffer_head *bh = lookup_bh_lru(bdev_file, block, size); if (bh == NULL) { /* __find_get_block_slow will mark the page accessed */ - bh = __find_get_block_slow(bdev, block); + bh = __find_get_block_slow(bdev_file, block); if (bh) bh_lru_install(bh); } else @@ -1410,32 +1414,32 @@ EXPORT_SYMBOL(__find_get_block); /** * bdev_getblk - Get a buffer_head in a block device's buffer cache. - * @bdev: The block device. + * @bdev_file: The opened block device. * @block: The block number. - * @size: The size of buffer_heads for this @bdev. + * @size: The size of buffer_heads for this @bdev_file. * @gfp: The memory allocation flags to use. * * Return: The buffer head, or NULL if memory could not be allocated. */ -struct buffer_head *bdev_getblk(struct block_device *bdev, sector_t block, - unsigned size, gfp_t gfp) +struct buffer_head *bdev_getblk(struct file *bdev_file, sector_t block, + unsigned int size, gfp_t gfp) { - struct buffer_head *bh = __find_get_block(bdev, block, size); + struct buffer_head *bh = __find_get_block(bdev_file, block, size); might_alloc(gfp); if (bh) return bh; - return __getblk_slow(bdev, block, size, gfp); + return __getblk_slow(bdev_file, block, size, gfp); } EXPORT_SYMBOL(bdev_getblk); /* * Do async read-ahead on a buffer.. */ -void __breadahead(struct block_device *bdev, sector_t block, unsigned size) +void __breadahead(struct file *bdev_file, sector_t block, unsigned int size) { - struct buffer_head *bh = bdev_getblk(bdev, block, size, + struct buffer_head *bh = bdev_getblk(bdev_file, block, size, GFP_NOWAIT | __GFP_MOVABLE); if (likely(bh)) { @@ -1447,7 +1451,7 @@ EXPORT_SYMBOL(__breadahead); /** * __bread_gfp() - reads a specified block and returns the bh - * @bdev: the block_device to read from + * @bdev_file: the opened block_device to read from * @block: number of block * @size: size (in bytes) to read * @gfp: page allocation flag @@ -1458,12 +1462,12 @@ EXPORT_SYMBOL(__breadahead); * It returns NULL if the block was unreadable. */ struct buffer_head * -__bread_gfp(struct block_device *bdev, sector_t block, - unsigned size, gfp_t gfp) +__bread_gfp(struct file *bdev_file, sector_t block, unsigned int size, + gfp_t gfp) { struct buffer_head *bh; - gfp |= mapping_gfp_constraint(bdev->bd_inode->i_mapping, ~__GFP_FS); + gfp |= mapping_gfp_constraint(bdev_file->f_mapping, ~__GFP_FS); /* * Prefer looping in the allocator rather than here, at least that @@ -1471,7 +1475,7 @@ __bread_gfp(struct block_device *bdev, sector_t block, */ gfp |= __GFP_NOFAIL; - bh = bdev_getblk(bdev, block, size, gfp); + bh = bdev_getblk(bdev_file, block, size, gfp); if (likely(bh) && !buffer_uptodate(bh)) bh = __bread_slow(bh); @@ -1676,7 +1680,7 @@ EXPORT_SYMBOL(create_empty_buffers); /** * clean_bdev_aliases: clean a range of buffers in block device - * @bdev: Block device to clean buffers in + * @bdev_file: Opened block device to clean buffers in * @block: Start of a range of blocks to clean * @len: Number of blocks to clean * @@ -1694,9 +1698,9 @@ EXPORT_SYMBOL(create_empty_buffers); * I/O in bforget() - it's more efficient to wait on the I/O only if we really * need to. That happens here. */ -void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len) +void clean_bdev_aliases(struct file *bdev_file, sector_t block, sector_t len) { - struct inode *bd_inode = bdev->bd_inode; + struct inode *bd_inode = file_inode(bdev_file); struct address_space *bd_mapping = bd_inode->i_mapping; struct folio_batch fbatch; pgoff_t index = ((loff_t)block << bd_inode->i_blkbits) / PAGE_SIZE; diff --git a/fs/direct-io.c b/fs/direct-io.c index 49475f530e0f..dade4cea754b 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -948,7 +948,7 @@ static int do_direct_IO(struct dio *dio, struct dio_submit *sdio, map_bh->b_blocknr << sdio->blkfactor; if (buffer_new(map_bh)) { clean_bdev_aliases( - bh_bdev(map_bh), + map_bh->b_bdev_file, map_bh->b_blocknr, map_bh->b_size >> i_blkbits); } diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index 6286d1578426..c8f59a61c95b 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c @@ -744,7 +744,7 @@ static int ext2_get_blocks(struct inode *inode, * We must unmap blocks before zeroing so that writeback cannot * overwrite zeros with stale data from block device page cache. */ - clean_bdev_aliases(inode->i_sb->s_bdev, + clean_bdev_aliases(inode->i_sb->s_bdev_file, le32_to_cpu(chain[depth-1].key), count); /* diff --git a/fs/ext4/super.c b/fs/ext4/super.c index d47c1e7e8798..1516d58a16ec 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -261,7 +261,7 @@ struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb, void ext4_sb_breadahead_unmovable(struct super_block *sb, sector_t block) { - struct buffer_head *bh = bdev_getblk(sb->s_bdev, block, + struct buffer_head *bh = bdev_getblk(sb->s_bdev_file, block, sb->s_blocksize, GFP_NOWAIT | __GFP_NOWARN); if (likely(bh)) { @@ -5854,7 +5854,7 @@ static struct file *ext4_get_journal_blkdev(struct super_block *sb, sb_block = EXT4_MIN_BLOCK_SIZE / blocksize; offset = EXT4_MIN_BLOCK_SIZE % blocksize; set_blocksize(bdev, blocksize); - bh = __bread(bdev, sb_block, blocksize); + bh = __bread(bdev_file, sb_block, blocksize); if (!bh) { ext4_msg(sb, KERN_ERR, "couldn't read superblock of " "external journal"); diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index c1ce32d99267..6157496deec2 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -880,7 +880,7 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out) if (ret) return ret; - bh = __getblk(journal->j_dev, pblock, journal->j_blocksize); + bh = __getblk(journal->j_dev_file, pblock, journal->j_blocksize); if (!bh) return -ENOMEM; @@ -1007,7 +1007,7 @@ jbd2_journal_get_descriptor_buffer(transaction_t *transaction, int type) if (err) return NULL; - bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize); + bh = __getblk(journal->j_dev_file, blocknr, journal->j_blocksize); if (!bh) return NULL; atomic_dec(&transaction->t_outstanding_credits); @@ -1461,7 +1461,7 @@ static int journal_load_superblock(journal_t *journal) struct buffer_head *bh; journal_superblock_t *sb; - bh = getblk_unmovable(journal->j_dev, journal->j_blk_offset, + bh = getblk_unmovable(journal->j_dev_file, journal->j_blk_offset, journal->j_blocksize); if (bh) err = bh_read(bh, 0); diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c index 1f7664984d6e..1685a139467a 100644 --- a/fs/jbd2/recovery.c +++ b/fs/jbd2/recovery.c @@ -92,7 +92,8 @@ static int do_readahead(journal_t *journal, unsigned int start) goto failed; } - bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize); + bh = __getblk(journal->j_dev_file, blocknr, + journal->j_blocksize); if (!bh) { err = -ENOMEM; goto failed; @@ -148,7 +149,7 @@ static int jread(struct buffer_head **bhp, journal_t *journal, return err; } - bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize); + bh = __getblk(journal->j_dev_file, blocknr, journal->j_blocksize); if (!bh) return -ENOMEM; @@ -370,7 +371,7 @@ int jbd2_journal_skip_recovery(journal_t *journal) journal->j_head = journal->j_first; } else { #ifdef CONFIG_JBD2_DEBUG - int dropped = info.end_transaction - + int dropped = info.end_transaction - be32_to_cpu(journal->j_superblock->s_sequence); jbd2_debug(1, "JBD2: ignoring %d transaction%s from the journal.\n", @@ -672,7 +673,7 @@ static int do_one_pass(journal_t *journal, /* Find a buffer for the new * data being restored */ - nbh = __getblk(journal->j_fs_dev, + nbh = __getblk(journal->j_fs_dev_file, blocknr, journal->j_blocksize); if (nbh == NULL) { diff --git a/fs/jbd2/revoke.c b/fs/jbd2/revoke.c index 4556e4689024..f464f84d08e6 100644 --- a/fs/jbd2/revoke.c +++ b/fs/jbd2/revoke.c @@ -328,7 +328,7 @@ int jbd2_journal_revoke(handle_t *handle, unsigned long long blocknr, { struct buffer_head *bh = NULL; journal_t *journal; - struct block_device *bdev; + struct file *bdev_file; int err; might_sleep(); @@ -341,11 +341,11 @@ int jbd2_journal_revoke(handle_t *handle, unsigned long long blocknr, return -EINVAL; } - bdev = journal->j_fs_dev; + bdev_file = journal->j_fs_dev_file; bh = bh_in; if (!bh) { - bh = __find_get_block(bdev, blocknr, journal->j_blocksize); + bh = __find_get_block(bdev_file, blocknr, journal->j_blocksize); if (bh) BUFFER_TRACE(bh, "found on hash"); } @@ -355,7 +355,7 @@ int jbd2_journal_revoke(handle_t *handle, unsigned long long blocknr, /* If there is a different buffer_head lying around in * memory anywhere... */ - bh2 = __find_get_block(bdev, blocknr, journal->j_blocksize); + bh2 = __find_get_block(bdev_file, blocknr, journal->j_blocksize); if (bh2) { /* ... and it has RevokeValid status... */ if (bh2 != bh && buffer_revokevalid(bh2)) @@ -466,7 +466,9 @@ int jbd2_journal_cancel_revoke(handle_t *handle, struct journal_head *jh) * state machine will get very upset later on. */ if (need_cancel) { struct buffer_head *bh2; - bh2 = __find_get_block(bh->b_bdev, bh->b_blocknr, bh->b_size); + + bh2 = __find_get_block(bh->b_bdev_file, bh->b_blocknr, + bh->b_size); if (bh2) { if (bh2 != bh) clear_buffer_revoked(bh2); @@ -495,7 +497,7 @@ void jbd2_clear_buffer_revoked_flags(journal_t *journal) struct jbd2_revoke_record_s *record; struct buffer_head *bh; record = (struct jbd2_revoke_record_s *)list_entry; - bh = __find_get_block(journal->j_fs_dev, + bh = __find_get_block(journal->j_fs_dev_file, record->blocknr, journal->j_blocksize); if (bh) { diff --git a/fs/mpage.c b/fs/mpage.c index 40594afa63cb..f01f06f20585 100644 --- a/fs/mpage.c +++ b/fs/mpage.c @@ -472,7 +472,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, struct block_device *bdev = NULL; int boundary = 0; sector_t boundary_block = 0; - struct block_device *boundary_bdev = NULL; + struct file *boundary_bdev_file = NULL; size_t length; struct buffer_head map_bh; loff_t i_size = i_size_read(inode); @@ -513,7 +513,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, boundary = buffer_boundary(bh); if (boundary) { boundary_block = bh->b_blocknr; - boundary_bdev = bh->b_bdev; + boundary_bdev_file = bh->b_bdev_file; } bdev = bh_bdev(bh); } while ((bh = bh->b_this_page) != head); @@ -555,7 +555,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, clean_bdev_bh_alias(&map_bh); if (buffer_boundary(&map_bh)) { boundary_block = map_bh.b_blocknr; - boundary_bdev = map_bh.b_bdev; + boundary_bdev_file = map_bh.b_bdev_file; } if (page_block) { if (map_bh.b_blocknr != first_block + page_block) @@ -628,7 +628,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, if (boundary || (first_unmapped != blocks_per_page)) { bio = mpage_bio_submit_write(bio); if (boundary_block) { - write_boundary_block(boundary_bdev, + write_boundary_block(boundary_bdev_file, boundary_block, 1 << blkbits); } } else { diff --git a/fs/nilfs2/recovery.c b/fs/nilfs2/recovery.c index 49a70c68bf3c..88e4f130c932 100644 --- a/fs/nilfs2/recovery.c +++ b/fs/nilfs2/recovery.c @@ -107,7 +107,8 @@ static int nilfs_compute_checksum(struct the_nilfs *nilfs, do { struct buffer_head *bh; - bh = __bread(nilfs->ns_bdev, ++start, blocksize); + bh = __bread(nilfs->ns_sb->s_bdev_file, ++start, + blocksize); if (!bh) return -EIO; check_bytes -= size; @@ -136,7 +137,8 @@ int nilfs_read_super_root_block(struct the_nilfs *nilfs, sector_t sr_block, int ret; *pbh = NULL; - bh_sr = __bread(nilfs->ns_bdev, sr_block, nilfs->ns_blocksize); + bh_sr = __bread(nilfs->ns_sb->s_bdev_file, sr_block, + nilfs->ns_blocksize); if (unlikely(!bh_sr)) { ret = NILFS_SEG_FAIL_IO; goto failed; @@ -183,7 +185,8 @@ nilfs_read_log_header(struct the_nilfs *nilfs, sector_t start_blocknr, { struct buffer_head *bh_sum; - bh_sum = __bread(nilfs->ns_bdev, start_blocknr, nilfs->ns_blocksize); + bh_sum = __bread(nilfs->ns_sb->s_bdev_file, start_blocknr, + nilfs->ns_blocksize); if (bh_sum) *sum = (struct nilfs_segment_summary *)bh_sum->b_data; return bh_sum; @@ -250,7 +253,7 @@ static void *nilfs_read_summary_info(struct the_nilfs *nilfs, if (bytes > (*pbh)->b_size - *offset) { blocknr = (*pbh)->b_blocknr; brelse(*pbh); - *pbh = __bread(nilfs->ns_bdev, blocknr + 1, + *pbh = __bread(nilfs->ns_sb->s_bdev_file, blocknr + 1, nilfs->ns_blocksize); if (unlikely(!*pbh)) return NULL; @@ -289,7 +292,7 @@ static void nilfs_skip_summary_info(struct the_nilfs *nilfs, *offset = bytes * (count - (bcnt - 1) * nitem_per_block); brelse(*pbh); - *pbh = __bread(nilfs->ns_bdev, blocknr + bcnt, + *pbh = __bread(nilfs->ns_sb->s_bdev_file, blocknr + bcnt, nilfs->ns_blocksize); } } @@ -318,7 +321,8 @@ static int nilfs_scan_dsync_log(struct the_nilfs *nilfs, sector_t start_blocknr, sumbytes = le32_to_cpu(sum->ss_sumbytes); blocknr = start_blocknr + DIV_ROUND_UP(sumbytes, nilfs->ns_blocksize); - bh = __bread(nilfs->ns_bdev, start_blocknr, nilfs->ns_blocksize); + bh = __bread(nilfs->ns_sb->s_bdev_file, start_blocknr, + nilfs->ns_blocksize); if (unlikely(!bh)) goto out; @@ -478,7 +482,8 @@ static int nilfs_recovery_copy_block(struct the_nilfs *nilfs, size_t from = pos & ~PAGE_MASK; void *kaddr; - bh_org = __bread(nilfs->ns_bdev, rb->blocknr, nilfs->ns_blocksize); + bh_org = __bread(nilfs->ns_sb->s_bdev_file, rb->blocknr, + nilfs->ns_blocksize); if (unlikely(!bh_org)) return -EIO; @@ -697,7 +702,8 @@ static void nilfs_finish_roll_forward(struct the_nilfs *nilfs, nilfs_get_segnum_of_block(nilfs, ri->ri_super_root)) return; - bh = __getblk(nilfs->ns_bdev, ri->ri_lsegs_start, nilfs->ns_blocksize); + bh = __getblk(nilfs->ns_sb->s_bdev_file, ri->ri_lsegs_start, + nilfs->ns_blocksize); BUG_ON(!bh); memset(bh->b_data, 0, bh->b_size); set_buffer_dirty(bh); @@ -823,7 +829,8 @@ int nilfs_search_super_root(struct the_nilfs *nilfs, /* Read ahead segment */ b = seg_start; while (b <= seg_end) - __breadahead(nilfs->ns_bdev, b++, nilfs->ns_blocksize); + __breadahead(nilfs->ns_sb->s_bdev_file, b++, + nilfs->ns_blocksize); for (;;) { brelse(bh_sum); @@ -869,7 +876,7 @@ int nilfs_search_super_root(struct the_nilfs *nilfs, if (pseg_start == seg_start) { nilfs_get_segment_range(nilfs, nextnum, &b, &end); while (b <= end) - __breadahead(nilfs->ns_bdev, b++, + __breadahead(nilfs->ns_sb->s_bdev_file, b++, nilfs->ns_blocksize); } if (!(flags & NILFS_SS_SR)) { diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c index ae2ef5c11868..32085ede15ea 100644 --- a/fs/ntfs3/fsntfs.c +++ b/fs/ntfs3/fsntfs.c @@ -1033,14 +1033,14 @@ struct buffer_head *ntfs_bread(struct super_block *sb, sector_t block) int ntfs_sb_read(struct super_block *sb, u64 lbo, size_t bytes, void *buffer) { - struct block_device *bdev = sb->s_bdev; u32 blocksize = sb->s_blocksize; u64 block = lbo >> sb->s_blocksize_bits; u32 off = lbo & (blocksize - 1); u32 op = blocksize - off; for (; bytes; block += 1, off = 0, op = blocksize) { - struct buffer_head *bh = __bread(bdev, block, blocksize); + struct buffer_head *bh = __bread(sb->s_bdev_file, block, + blocksize); if (!bh) return -EIO; @@ -1063,7 +1063,7 @@ int ntfs_sb_write(struct super_block *sb, u64 lbo, size_t bytes, const void *buf, int wait) { u32 blocksize = sb->s_blocksize; - struct block_device *bdev = sb->s_bdev; + struct file *bdev_file = sb->s_bdev_file; sector_t block = lbo >> sb->s_blocksize_bits; u32 off = lbo & (blocksize - 1); u32 op = blocksize - off; @@ -1077,14 +1077,14 @@ int ntfs_sb_write(struct super_block *sb, u64 lbo, size_t bytes, op = bytes; if (op < blocksize) { - bh = __bread(bdev, block, blocksize); + bh = __bread(bdev_file, block, blocksize); if (!bh) { ntfs_err(sb, "failed to read block %llx", (u64)block); return -EIO; } } else { - bh = __getblk(bdev, block, blocksize); + bh = __getblk(bdev_file, block, blocksize); if (!bh) return -ENOMEM; } diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index 9df7c20d066f..d67becf7302e 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -1627,7 +1627,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc) void ntfs_unmap_meta(struct super_block *sb, CLST lcn, CLST len) { struct ntfs_sb_info *sbi = sb->s_fs_info; - struct block_device *bdev = sb->s_bdev; + struct file *bdev_file = sb->s_bdev_file; sector_t devblock = (u64)lcn * sbi->blocks_per_cluster; unsigned long blocks = (u64)len * sbi->blocks_per_cluster; unsigned long cnt = 0; @@ -1642,9 +1642,9 @@ void ntfs_unmap_meta(struct super_block *sb, CLST lcn, CLST len) limit >>= 1; while (blocks--) { - clean_bdev_aliases(bdev, devblock++, 1); + clean_bdev_aliases(bdev_file, devblock++, 1); if (cnt++ >= limit) { - sync_blockdev(bdev); + filemap_write_and_wait(bdev_file->f_mapping); cnt = 0; } } diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c index 604fea3a26ff..4ad64997f3c7 100644 --- a/fs/ocfs2/journal.c +++ b/fs/ocfs2/journal.c @@ -1209,7 +1209,7 @@ static int ocfs2_force_read_journal(struct inode *inode) } for (i = 0; i < p_blocks; i++, p_blkno++) { - bh = __find_get_block(osb->sb->s_bdev, p_blkno, + bh = __find_get_block(osb->sb->s_bdev_file, p_blkno, osb->sb->s_blocksize); /* block not cached. */ if (!bh) diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c index 724113cb79d3..3961f406ee7e 100644 --- a/fs/reiserfs/journal.c +++ b/fs/reiserfs/journal.c @@ -2315,7 +2315,7 @@ static int journal_read_transaction(struct super_block *sb, * from other places. * Note: Do not use journal_getblk/sb_getblk functions here! */ -static struct buffer_head *reiserfs_breada(struct block_device *dev, +static struct buffer_head *reiserfs_breada(struct file *bdev_file, b_blocknr_t block, int bufsize, b_blocknr_t max_block) { @@ -2324,7 +2324,7 @@ static struct buffer_head *reiserfs_breada(struct block_device *dev, struct buffer_head *bh; int i, j; - bh = __getblk(dev, block, bufsize); + bh = __getblk(bdev_file, block, bufsize); if (!bh || buffer_uptodate(bh)) return (bh); @@ -2334,7 +2334,7 @@ static struct buffer_head *reiserfs_breada(struct block_device *dev, bhlist[0] = bh; j = 1; for (i = 1; i < blocks; i++) { - bh = __getblk(dev, block + i, bufsize); + bh = __getblk(bdev_file, block + i, bufsize); if (!bh) break; if (buffer_uptodate(bh)) { @@ -2447,7 +2447,7 @@ static int journal_read(struct super_block *sb) * device and journal device to be the same */ d_bh = - reiserfs_breada(file_bdev(journal->j_bdev_file), cur_dblock, + reiserfs_breada(journal->j_bdev_file, cur_dblock, sb->s_blocksize, SB_ONDISK_JOURNAL_1st_BLOCK(sb) + SB_ONDISK_JOURNAL_SIZE(sb)); diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h index f0e1f29f20ee..49caa7c42fb7 100644 --- a/fs/reiserfs/reiserfs.h +++ b/fs/reiserfs/reiserfs.h @@ -2810,10 +2810,10 @@ struct reiserfs_journal_header { /* We need these to make journal.c code more readable */ #define journal_find_get_block(s, block) __find_get_block(\ - file_bdev(SB_JOURNAL(s)->j_bdev_file), block, s->s_blocksize) -#define journal_getblk(s, block) __getblk(file_bdev(SB_JOURNAL(s)->j_bdev_file),\ + SB_JOURNAL(s)->j_bdev_file, block, s->s_blocksize) +#define journal_getblk(s, block) __getblk(SB_JOURNAL(s)->j_bdev_file,\ block, s->s_blocksize) -#define journal_bread(s, block) __bread(file_bdev(SB_JOURNAL(s)->j_bdev_file),\ +#define journal_bread(s, block) __bread(SB_JOURNAL(s)->j_bdev_file,\ block, s->s_blocksize) enum reiserfs_bh_state_bits { diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 22f736908cbe..d0907c079779 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -50,7 +50,6 @@ struct block_device { bool bd_write_holder; bool bd_has_submit_bio; dev_t bd_dev; - struct inode *bd_inode; /* will die */ atomic_t bd_openers; spinlock_t bd_size_lock; /* for bd_inode->i_size updates */ diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h index 4c6f0d0332c8..cebff2645d59 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -69,7 +69,7 @@ struct buffer_head { size_t b_size; /* size of mapping */ char *b_data; /* pointer to data within the page */ - struct block_device *b_bdev; + struct file *b_bdev_file; bh_end_io_t *b_end_io; /* I/O completion */ void *b_private; /* reserved for b_end_io */ struct list_head b_assoc_buffers; /* associated with another mapping */ @@ -140,18 +140,18 @@ BUFFER_FNS(Defer_Completion, defer_completion) static __always_inline void bh_set_bdev_file(struct buffer_head *bh, struct file *bdev_file) { - bh->b_bdev = bdev_file ? file_bdev(bdev_file) : NULL; + bh->b_bdev_file = bdev_file; } static __always_inline void bh_copy_bdev_file(struct buffer_head *dbh, struct buffer_head *sbh) { - dbh->b_bdev = sbh->b_bdev; + dbh->b_bdev_file = sbh->b_bdev_file; } static __always_inline struct block_device *bh_bdev(struct buffer_head *bh) { - return bh->b_bdev; + return bh->b_bdev_file ? file_bdev(bh->b_bdev_file) : NULL; } static __always_inline void set_buffer_uptodate(struct buffer_head *bh) @@ -230,25 +230,24 @@ int generic_buffers_fsync_noflush(struct file *file, loff_t start, loff_t end, bool datasync); int generic_buffers_fsync(struct file *file, loff_t start, loff_t end, bool datasync); -void clean_bdev_aliases(struct block_device *bdev, sector_t block, - sector_t len); +void clean_bdev_aliases(struct file *bdev_file, sector_t block, sector_t len); static inline void clean_bdev_bh_alias(struct buffer_head *bh) { - clean_bdev_aliases(bh->b_bdev, bh->b_blocknr, 1); + clean_bdev_aliases(bh->b_bdev_file, bh->b_blocknr, 1); } void mark_buffer_async_write(struct buffer_head *bh); void __wait_on_buffer(struct buffer_head *); wait_queue_head_t *bh_waitq_head(struct buffer_head *bh); -struct buffer_head *__find_get_block(struct block_device *bdev, sector_t block, - unsigned size); -struct buffer_head *bdev_getblk(struct block_device *bdev, sector_t block, - unsigned size, gfp_t gfp); +struct buffer_head *__find_get_block(struct file *bdev_file, sector_t block, + unsigned int size); +struct buffer_head *bdev_getblk(struct file *bdev_file, sector_t block, + unsigned int size, gfp_t gfp); void __brelse(struct buffer_head *); void __bforget(struct buffer_head *); -void __breadahead(struct block_device *, sector_t block, unsigned int size); -struct buffer_head *__bread_gfp(struct block_device *, - sector_t block, unsigned size, gfp_t gfp); +void __breadahead(struct file *bdev_file, sector_t block, unsigned int size); +struct buffer_head *__bread_gfp(struct file *bdev_file, sector_t block, + unsigned int size, gfp_t gfp); struct buffer_head *alloc_buffer_head(gfp_t gfp_flags); void free_buffer_head(struct buffer_head * bh); void unlock_buffer(struct buffer_head *bh); @@ -257,8 +256,8 @@ int sync_dirty_buffer(struct buffer_head *bh); int __sync_dirty_buffer(struct buffer_head *bh, blk_opf_t op_flags); void write_dirty_buffer(struct buffer_head *bh, blk_opf_t op_flags); void submit_bh(blk_opf_t, struct buffer_head *); -void write_boundary_block(struct block_device *bdev, - sector_t bblock, unsigned blocksize); +void write_boundary_block(struct file *bdev_file, sector_t bblock, + unsigned int blocksize); int bh_uptodate_or_lock(struct buffer_head *bh); int __bh_read(struct buffer_head *bh, blk_opf_t op_flags, bool wait); void __bh_read_batch(int nr, struct buffer_head *bhs[], @@ -336,59 +335,61 @@ static inline void bforget(struct buffer_head *bh) static inline struct buffer_head * sb_bread(struct super_block *sb, sector_t block) { - return __bread_gfp(sb->s_bdev, block, sb->s_blocksize, __GFP_MOVABLE); + return __bread_gfp(sb->s_bdev_file, block, sb->s_blocksize, + __GFP_MOVABLE); } static inline struct buffer_head * sb_bread_unmovable(struct super_block *sb, sector_t block) { - return __bread_gfp(sb->s_bdev, block, sb->s_blocksize, 0); + return __bread_gfp(sb->s_bdev_file, block, sb->s_blocksize, 0); } static inline void sb_breadahead(struct super_block *sb, sector_t block) { - __breadahead(sb->s_bdev, block, sb->s_blocksize); + __breadahead(sb->s_bdev_file, block, sb->s_blocksize); } -static inline struct buffer_head *getblk_unmovable(struct block_device *bdev, - sector_t block, unsigned size) +static inline struct buffer_head *getblk_unmovable(struct file *bdev_file, + sector_t block, + unsigned int size) { gfp_t gfp; - gfp = mapping_gfp_constraint(bdev->bd_inode->i_mapping, ~__GFP_FS); + gfp = mapping_gfp_constraint(bdev_file->f_mapping, ~__GFP_FS); gfp |= __GFP_NOFAIL; - return bdev_getblk(bdev, block, size, gfp); + return bdev_getblk(bdev_file, block, size, gfp); } -static inline struct buffer_head *__getblk(struct block_device *bdev, - sector_t block, unsigned size) +static inline struct buffer_head *__getblk(struct file *bdev_file, + sector_t block, unsigned int size) { gfp_t gfp; - gfp = mapping_gfp_constraint(bdev->bd_inode->i_mapping, ~__GFP_FS); + gfp = mapping_gfp_constraint(bdev_file->f_mapping, ~__GFP_FS); gfp |= __GFP_MOVABLE | __GFP_NOFAIL; - return bdev_getblk(bdev, block, size, gfp); + return bdev_getblk(bdev_file, block, size, gfp); } static inline struct buffer_head *sb_getblk(struct super_block *sb, sector_t block) { - return __getblk(sb->s_bdev, block, sb->s_blocksize); + return __getblk(sb->s_bdev_file, block, sb->s_blocksize); } static inline struct buffer_head *sb_getblk_gfp(struct super_block *sb, sector_t block, gfp_t gfp) { - return bdev_getblk(sb->s_bdev, block, sb->s_blocksize, gfp); + return bdev_getblk(sb->s_bdev_file, block, sb->s_blocksize, gfp); } static inline struct buffer_head * sb_find_get_block(struct super_block *sb, sector_t block) { - return __find_get_block(sb->s_bdev, block, sb->s_blocksize); + return __find_get_block(sb->s_bdev_file, block, sb->s_blocksize); } static inline void @@ -456,7 +457,7 @@ static inline void bh_readahead_batch(int nr, struct buffer_head *bhs[], /** * __bread() - reads a specified block and returns the bh - * @bdev: the block_device to read from + * @bdev_file: the opened block_device to read from * @block: number of block * @size: size (in bytes) to read * @@ -465,9 +466,9 @@ static inline void bh_readahead_batch(int nr, struct buffer_head *bhs[], * It returns NULL if the block was unreadable. */ static inline struct buffer_head * -__bread(struct block_device *bdev, sector_t block, unsigned size) +__bread(struct file *bdev_file, sector_t block, unsigned int size) { - return __bread_gfp(bdev, block, size, __GFP_MOVABLE); + return __bread_gfp(bdev_file, block, size, __GFP_MOVABLE); } /**