From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FCEDC432C3 for ; Thu, 21 Nov 2019 17:13:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E5993206D7 for ; Thu, 21 Nov 2019 17:13:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727237AbfKURNr (ORCPT ); Thu, 21 Nov 2019 12:13:47 -0500 Received: from mx2.suse.de ([195.135.220.15]:54298 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727165AbfKURNo (ORCPT ); Thu, 21 Nov 2019 12:13:44 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2B3A0B27A; Thu, 21 Nov 2019 17:13:41 +0000 (UTC) From: Michal Suchanek To: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org Cc: Michal Suchanek , Jonathan Corbet , Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Eric Biggers , "J. Bruce Fields" , Mauro Carvalho Chehab , Benjamin Coddington , Ming Lei , Chaitanya Kulkarni , Bart Van Assche , Damien Le Moal , Hou Tao , Pavel Begunkov , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jan Kara , Hannes Reinecke , "Ewan D. Milne" , Christoph Hellwig , Matthew Wilcox Subject: [PATCH v4 07/10] bdev: separate parts of __blkdev_get as helper functions Date: Thu, 21 Nov 2019 18:13:14 +0100 Message-Id: <49c843f88373d9ad4f6e607f704f51ca84c1747d.1574355709.git.msuchanek@suse.de> X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This code will be reused in later patch. Hopefully putting it aside rather than cut&pasting another copy will make the function more readable. Signed-off-by: Michal Suchanek --- fs/block_dev.c | 52 +++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/fs/block_dev.c b/fs/block_dev.c index a3083fbada8b..10c9e0ae2bdc 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1512,6 +1512,28 @@ EXPORT_SYMBOL(bd_set_size); static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part); +static void blkdev_init_size(struct block_device *bdev, struct gendisk *disk) +{ + bd_set_size(bdev, (loff_t)get_capacity(disk) << 9); + set_init_blocksize(bdev); +} + +static void blkdev_do_partitions(struct block_device *bdev, + struct gendisk *disk, int ret) +{ + /* + * If the device is invalidated, rescan partition if open succeeded or + * failed with -ENOMEDIUM. The latter is necessary to prevent ghost + * partitions on a removed medium. + */ + if (bdev->bd_invalidated) { + if (!ret) + rescan_partitions(disk, bdev); + else if (ret == -ENOMEDIUM) + invalidate_partitions(disk, bdev); + } +} + /* * bd_mutex locking: * @@ -1584,23 +1606,9 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) } } - if (!ret) { - bd_set_size(bdev,(loff_t)get_capacity(disk)<<9); - set_init_blocksize(bdev); - } - - /* - * If the device is invalidated, rescan partition - * if open succeeded or failed with -ENOMEDIUM. - * The latter is necessary to prevent ghost - * partitions on a removed medium. - */ - if (bdev->bd_invalidated) { - if (!ret) - rescan_partitions(disk, bdev); - else if (ret == -ENOMEDIUM) - invalidate_partitions(disk, bdev); - } + if (!ret) + blkdev_init_size(bdev, disk); + blkdev_do_partitions(bdev, disk, ret); if (ret) goto out_clear; @@ -1632,13 +1640,9 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) ret = 0; if (bdev->bd_disk->fops->open) ret = bdev->bd_disk->fops->open(bdev, mode); - /* the same as first opener case, read comment there */ - if (bdev->bd_invalidated) { - if (!ret) - rescan_partitions(bdev->bd_disk, bdev); - else if (ret == -ENOMEDIUM) - invalidate_partitions(bdev->bd_disk, bdev); - } + + blkdev_do_partitions(bdev, disk, ret); + if (ret) goto out_unlock_bdev; } -- 2.23.0