Patchwork [2/8] block: restart partition scan after resizing a device

login
register
mail settings
Submitter Tejun Heo
Date May 15, 2010, 6:09 p.m.
Message ID <1273946974-29131-3-git-send-email-tj@kernel.org>
Download mbox | patch
Permalink /patch/52714/
State Not Applicable
Delegated to: David Miller
Headers show

Comments

Tejun Heo - May 15, 2010, 6:09 p.m.
Device resize via ->set_capacity() can reveal new partitions (e.g. in
chained partition table formats such as dos extended parts).  Restart
partition scan from the beginning after resizing a device.  This
change also makes libata always revalidate the disk after resize which
makes lower layer native capacity unlocking implementation simpler and
more robust as resize can be handled in the usual path.

Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Ben Hutchings <ben@decadent.org.uk>
---
 fs/partitions/check.c |   16 ++++++----------
 1 files changed, 6 insertions(+), 10 deletions(-)
David Miller - May 16, 2010, 7:15 a.m.
From: Tejun Heo <tj@kernel.org>
Date: Sat, 15 May 2010 20:09:28 +0200

> Device resize via ->set_capacity() can reveal new partitions (e.g. in
> chained partition table formats such as dos extended parts).  Restart
> partition scan from the beginning after resizing a device.  This
> change also makes libata always revalidate the disk after resize which
> makes lower layer native capacity unlocking implementation simpler and
> more robust as resize can be handled in the usual path.
> 
> Signed-off-by: Tejun Heo <tj@kernel.org>
> Reported-by: Ben Hutchings <ben@decadent.org.uk>

Acked-by: David S. Miller <davem@davemloft.net>
--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index e238ab2..8f01df3 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -544,7 +544,7 @@  int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
 	struct hd_struct *part;
 	struct parsed_partitions *state;
 	int p, highest, res;
-
+rescan:
 	if (bdev->bd_part_count)
 		return -EBUSY;
 	res = invalidate_partition(disk, 0);
@@ -581,7 +581,7 @@  int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
 	/* add partitions */
 	for (p = 1; p < state->limit; p++) {
 		sector_t size, from;
-try_scan:
+
 		size = state->parts[p].size;
 		if (!size)
 			continue;
@@ -596,7 +596,6 @@  try_scan:
 
 		if (from + size > get_capacity(disk)) {
 			const struct block_device_operations *bdops = disk->fops;
-			unsigned long long capacity;
 
 			printk(KERN_WARNING
 			       "%s: p%d size %llu exceeds device capacity, ",
@@ -605,14 +604,11 @@  try_scan:
 			if (bdops->set_capacity &&
 			    (disk->flags & GENHD_FL_NATIVE_CAPACITY) == 0) {
 				printk(KERN_CONT "enabling native capacity\n");
-				capacity = bdops->set_capacity(disk, ~0ULL);
+				bdops->set_capacity(disk, ~0ULL);
 				disk->flags |= GENHD_FL_NATIVE_CAPACITY;
-				if (capacity > get_capacity(disk)) {
-					set_capacity(disk, capacity);
-					check_disk_size_change(disk, bdev);
-					bdev->bd_invalidated = 0;
-				}
-				goto try_scan;
+				/* free state and restart */
+				kfree(state);
+				goto rescan;
 			} else {
 				/*
 				 * we can not ignore partitions of broken tables