lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <49c843f88373d9ad4f6e607f704f51ca84c1747d.1574355709.git.msuchanek@suse.de>
Date:   Thu, 21 Nov 2019 18:13:14 +0100
From:   Michal Suchanek <msuchanek@...e.de>
To:     linux-scsi@...r.kernel.org, linux-block@...r.kernel.org
Cc:     Michal Suchanek <msuchanek@...e.de>,
        Jonathan Corbet <corbet@....net>, Jens Axboe <axboe@...nel.dk>,
        "James E.J. Bottomley" <jejb@...ux.ibm.com>,
        "Martin K. Petersen" <martin.petersen@...cle.com>,
        Alexander Viro <viro@...iv.linux.org.uk>,
        Eric Biggers <ebiggers@...gle.com>,
        "J. Bruce Fields" <bfields@...hat.com>,
        Mauro Carvalho Chehab <mchehab+samsung@...nel.org>,
        Benjamin Coddington <bcodding@...hat.com>,
        Ming Lei <ming.lei@...hat.com>,
        Chaitanya Kulkarni <chaitanya.kulkarni@....com>,
        Bart Van Assche <bvanassche@....org>,
        Damien Le Moal <damien.lemoal@....com>,
        Hou Tao <houtao1@...wei.com>,
        Pavel Begunkov <asml.silence@...il.com>,
        linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
        Jan Kara <jack@...e.cz>, Hannes Reinecke <hare@...e.com>,
        "Ewan D. Milne" <emilne@...hat.com>,
        Christoph Hellwig <hch@...radead.org>,
        Matthew Wilcox <willy@...radead.org>
Subject: [PATCH v4 07/10] bdev: separate parts of __blkdev_get as helper functions

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 <msuchanek@...e.de>
---
 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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ