From patchwork Tue Nov 26 19:54:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Suchanek X-Patchwork-Id: 11262975 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A128D930 for ; Tue, 26 Nov 2019 19:54:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8946B2086A for ; Tue, 26 Nov 2019 19:54:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727116AbfKZTyu (ORCPT ); Tue, 26 Nov 2019 14:54:50 -0500 Received: from mx2.suse.de ([195.135.220.15]:40276 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726033AbfKZTyp (ORCPT ); Tue, 26 Nov 2019 14:54:45 -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 69271B11E; Tue, 26 Nov 2019 19:54:44 +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 rebase 07/10] bdev: separate parts of __blkdev_get as helper functions Date: Tue, 26 Nov 2019 20:54:26 +0100 Message-Id: <1bf484f0003874d8bc6935ed4653e40ba597afd4.1574797504.git.msuchanek@suse.de> X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@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 | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/fs/block_dev.c b/fs/block_dev.c index 545bb6c8848a..a386ebd997fb 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1547,6 +1547,24 @@ int bdev_disk_changed(struct block_device *bdev, bool invalidate) */ EXPORT_SYMBOL_GPL(bdev_disk_changed); +static void blkdev_init_size(struct block_device *bdev) +{ + bd_set_size(bdev, (loff_t)get_capacity(bdev->bd_disk) << 9); + set_init_blocksize(bdev); +} + +static void blkdev_do_partitions(struct block_device *bdev, 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 && + (!ret || ret == -ENOMEDIUM)) + bdev_disk_changed(bdev, ret == -ENOMEDIUM); +} + /* * bd_mutex locking: * @@ -1619,20 +1637,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 && - (!ret || ret == -ENOMEDIUM)) - bdev_disk_changed(bdev, ret == -ENOMEDIUM); + if (!ret) + blkdev_init_size(bdev); + blkdev_do_partitions(bdev, ret); if (ret) goto out_clear; @@ -1664,10 +1671,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 && - (!ret || ret == -ENOMEDIUM)) - bdev_disk_changed(bdev, ret == -ENOMEDIUM); + + blkdev_do_partitions(bdev, ret); + if (ret) goto out_unlock_bdev; }