From patchwork Thu Feb 22 12:45:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13567252 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 01DB812DDBA; Thu, 22 Feb 2024 12:51:41 +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=1708606305; cv=none; b=jOqbedanQQ5sZz7kNtpfq6eeQPTxr8P35oPnBkf8HJC0cWRw0XF/58jm89gbKWtPUrX8JyX3QTkMFDhKsC5fbIVcqqFrb7W0XpjxpYDL2stOTsHSZLXpsQjK8kfDOe7AmokZ0U/oYBlUfhOttHmjw/RIDxpS8XzN08oI8E8JKa4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708606305; c=relaxed/simple; bh=zunERTv3W4LcU7+CFI6zdD2a6SGNkJeQA1vdXJ7+4BI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dU7zVPjX84kUtX/ylmdBFyTPL5FuUINL0QoEOvKwkCDXMFz10D05A35N+8HaV0OvP1s3sX5XnnEtb8SzAAaI/mMCK8fgWhUMbrL274bp/dJ+/woWd1A1gXEukEK1JYt88LwvrIqFKznO+WfSeeiJ9USBnSFLED9z8wQmpdlYuzc= 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 4TgY1L0fHWz4f3jsc; Thu, 22 Feb 2024 20:51:34 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 2045E1A0172; Thu, 22 Feb 2024 20:51:39 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgBHGBFSQ9dlQ382Ew--.47909S19; Thu, 22 Feb 2024 20:51:38 +0800 (CST) From: Yu Kuai To: jack@suse.cz, hch@lst.de, brauner@kernel.org, axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [RFC v4 linux-next 15/19] bcache: prevent direct access of bd_inode Date: Thu, 22 Feb 2024 20:45:51 +0800 Message-Id: <20240222124555.2049140-16-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240222124555.2049140-1-yukuai1@huaweicloud.com> References: <20240222124555.2049140-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgBHGBFSQ9dlQ382Ew--.47909S19 X-Coremail-Antispam: 1UD129KBjvJXoW7uFWrJF4rCw4kZFW3JFyUGFg_yoW8Gw17pF ZxCa90qrW8Ww4093yDXr4DuFyrt3sIyayIk34xu34ava9Fqr9Y9FW5GFyUuryFqry8Wwsr XF47Kry7Cr1kC3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUQ SdkUUUUU= 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: Jan Kara Reviewed-by: Christoph Hellwig --- 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 4153c9ddbe0b..ec9efa79d5a8 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"; @@ -2564,7 +2565,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;