Skip to contentSkip to conversation

block,libata: implement ->unlock_native_capacity()

PATCH In review Tejun Heo 8 participants 31 messages May 15, 2010 – Jun 2, 2010

Subsystems (4)
lore
Share & tools
lore

Tejun Heo

author
#0 lore raw

PATCH 1/1 block,libata: implement ->unlock_native_capacity()

Hello, all.

This is the evolved version of the implement-set_capacity patchset[L] and contains the following patches.

0001-buffer-make-invalidate_bdev-drain-all-percpu-LRU-add.patch 0002-block-restart-partition-scan-after-resizing-a-device.patch 0003-block-ide-simplify-bdops-set_capacity-to-unlock_nati.patch 0004-block-use-struct-parsed_partitions-state-universally.patch 0005-block-improve-automatic-native-capacity-unlocking.patch 0006-SCSI-implement-sd_unlock_native_capacity.patch 0007-libata-use-the-enlarged-capacity-after-late-HPA-unlo.patch 0008-libata-implement-on-demand-HPA-unlocking.patch

0001-0005 fix and update partition check related code and make the existing automatic native capacity unlocking mechanism simpler and more robust.

0001 fixes invalidate_bdev() which seems to have been somewhat broken for quite some time since percpu LRU add cache was introduced.

0002 makes partition code to restart from beginning after native capacity is locked so that resize and all other stuff can be dealt with in the usual revalidation path.

0003 renames ->set_capacity() to ->unlock_native_capacity() and drops the spurious new capacity parameter and return value.

0004 updates partition check API for the next patch.

0005 improves automatic native capacity unlocking code so that it covers all partition misdetection cases which can be caused by limited disk capacity.

0006-0008 add ->unlock_native_capacity() support to libata. 0001-0005 are probably best routed through block tree if David is okay with it (0003 modifies ide), and 0006-0008 through libata if James is okay with the SCSI part. What do you guys think?

This patchset is available in the following git branch.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata-dev.git unlock-native-capa

diffstat follows.

 drivers/ata/libata-core.c |    6 +--
 drivers/ata/libata-scsi.c |   29 ++++++++++++++
 drivers/ide/ide-disk.c    |   40 ++++++++------------
 drivers/ide/ide-gd.c      |   11 ++---
 drivers/scsi/sd.c         |   22 +++++++++++
 fs/buffer.c               |    1 
 fs/partitions/acorn.c     |   68 ++++++++++++++++------------------
 fs/partitions/acorn.h     |   10 ++---
 fs/partitions/amiga.c     |   13 +++---
 fs/partitions/amiga.h     |    2 -
 fs/partitions/atari.c     |    8 ++--
 fs/partitions/atari.h     |    2 -
 fs/partitions/check.c     |   84 ++++++++++++++++++++++++++++++------------
 fs/partitions/check.h     |   12 ++++++
 fs/partitions/efi.c       |   91 +++++++++++++++++++++-------------------------
 fs/partitions/efi.h       |    2 -
 fs/partitions/ibm.c       |   21 +++++-----
 fs/partitions/ibm.h       |    2 -
 fs/partitions/karma.c     |    4 +-
 fs/partitions/karma.h     |    2 -
 fs/partitions/ldm.c       |   89 ++++++++++++++++++++++----------------------
 fs/partitions/ldm.h       |    2 -
 fs/partitions/mac.c       |   11 +++--
 fs/partitions/mac.h       |    2 -
 fs/partitions/msdos.c     |   85 ++++++++++++++++++------------------------
 fs/partitions/msdos.h     |    2 -
 fs/partitions/osf.c       |    4 +-
 fs/partitions/osf.h       |    2 -
 fs/partitions/sgi.c       |    6 +--
 fs/partitions/sgi.h       |    2 -
 fs/partitions/sun.c       |    6 +--
 fs/partitions/sun.h       |    2 -
 fs/partitions/sysv68.c    |    6 +--
 fs/partitions/sysv68.h    |    2 -
 fs/partitions/ultrix.c    |    4 +-
 fs/partitions/ultrix.h    |    2 -
 include/linux/blkdev.h    |    3 -
 include/linux/ide.h       |    2 -
 include/linux/libata.h    |    2 +
 include/scsi/scsi_host.h  |    8 ++++
 40 files changed, 375 insertions(+), 297 deletions(-)

Thanks.

--
tejun

[L] http://thread.gmane.org/gmane.linux.scsi/58925

author
#1 lore raw

PATCH 1/8 buffer: make invalidate_bdev() drain all percpu LRU add caches

invalidate_bdev() should release all page cache pages which are clean and not being used; however, if some pages are still in the percpu LRU add caches on other cpus, those pages are considered in used and don't get released. Fix it by calling lru_add_drain_all() before trying to invalidate pages.

This problem was discovered while testing block automatic native capacity unlocking. Null pages which were read before automatic unlocking didn't get released by invalidate_bdev() and ended up interfering with partition scan after unlocking.

---
 fs/buffer.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
fs/buffer.c +1 -0
index c9c266d..08e422d 100644
@@ -275,6 +275,7 @@ void invalidate_bdev(struct block_device *bdev)
 		return;
 
 	invalidate_bh_lrus();
+	lru_add_drain_all();	/* make sure all lru add caches are flushed */
 	invalidate_mapping_pages(mapping, 0, -1);
 }
 EXPORT_SYMBOL(invalidate_bdev);
Signature · 1 line
1.6.4.2
Acked-by on v1 1/8
#2 lore raw

Re: [PATCH 1/8] buffer: make invalidate_bdev() drain all percpu LRU add caches

From: Tejun Heo <[email protected]>
Date: Sat, 15 May 2010 20:09:27 +0200

Quoted 6 lines

invalidate_bdev() should release all page cache pages which are clean and not being used; however, if some pages are still in the percpu LRU add caches on other cpus, those pages are considered in used and don't get released. Fix it by calling lru_add_drain_all() before trying to invalidate pages.

Quoted 6 lines

This problem was discovered while testing block automatic native capacity unlocking. Null pages which were read before automatic unlocking didn't get released by invalidate_bdev() and ended up interfering with partition scan after unlocking.

author
#3 lore raw

PATCH 2/8 block: restart partition scan after resizing a device

In reply to Tejun Heo

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.

---
 fs/partitions/check.c |   16 ++++++----------
 1 files changed, 6 insertions(+), 10 deletions(-)
fs/partitions/check.c +6 -10
index e238ab2..8f01df3 100644
@@ -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
Signature · 1 line
1.6.4.2
Acked-by on v1 2/8
#4 lore raw

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

From: Tejun Heo <[email protected]>
Date: Sat, 15 May 2010 20:09:28 +0200

Quoted 9 lines

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.

author
#5 lore raw

PATCH 3/8 block,ide: simplify bdops->set_capacity() to ->unlock_native_capacity()

In reply to Tejun Heo

bdops->set_capacity() is unnecessarily generic. All that's required is a simple one way notification to lower level driver telling it to try to unlock native capacity. There's no reason to pass in target capacity or return the new capacity. The former is always the inherent native capacity and the latter can be handled via the usual device resize / revalidation path. In fact, the current API is always used that way.

Replace ->set_capacity() with ->unlock_native_capacity() which take only @disk and doesn't return anything. IDE which is the only current user of the API is converted accordingly.

Cc Ben Hutchings <[email protected]>
Cc Jens Axboe <[email protected]>
Cc David Miller <[email protected]>
Cc Bartlomiej Zolnierkiewicz <[email protected]>
---
 drivers/ide/ide-disk.c |   40 ++++++++++++++++------------------------
 drivers/ide/ide-gd.c   |   11 ++++-------
 fs/partitions/check.c  |    4 ++--
 include/linux/blkdev.h |    3 +--
 include/linux/ide.h    |    2 +-
 5 files changed, 24 insertions(+), 36 deletions(-)
drivers/ide/ide-disk.c +16 -24
index 3b128dc..33d6503 100644
@@ -407,32 +407,24 @@ static int ide_disk_get_capacity(ide_drive_t *drive)
 	return 0;
 }
 
-static u64 ide_disk_set_capacity(ide_drive_t *drive, u64 capacity)
+static void ide_disk_unlock_native_capacity(ide_drive_t *drive)
 {
-	u64 set = min(capacity, drive->probed_capacity);
 	u16 *id = drive->id;
 	int lba48 = ata_id_lba48_enabled(id);
 
 	if ((drive->dev_flags & IDE_DFLAG_LBA) == 0 ||
 	    ata_id_hpa_enabled(id) == 0)
-		goto out;
+		return;
 
 	/*
 	 * according to the spec the SET MAX ADDRESS command shall be
 	 * immediately preceded by a READ NATIVE MAX ADDRESS command
 	 */
-	capacity = ide_disk_hpa_get_native_capacity(drive, lba48);
-	if (capacity == 0)
-		goto out;
-
-	set = ide_disk_hpa_set_capacity(drive, set, lba48);
-	if (set) {
-		/* needed for ->resume to disable HPA */
-		drive->dev_flags |= IDE_DFLAG_NOHPA;
-		return set;
-	}
-out:
-	return drive->capacity64;
+	if (!ide_disk_hpa_get_native_capacity(drive, lba48))
+		return;
+
+	if (ide_disk_hpa_set_capacity(drive, drive->probed_capacity, lba48))
+		drive->dev_flags |= IDE_DFLAG_NOHPA; /* disable HPA on resume */
 }
 
 static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
@@ -783,13 +775,13 @@ static int ide_disk_set_doorlock(ide_drive_t *drive, struct gendisk *disk,
 }
 
 const struct ide_disk_ops ide_ata_disk_ops = {
-	.check		= ide_disk_check,
-	.set_capacity	= ide_disk_set_capacity,
-	.get_capacity	= ide_disk_get_capacity,
-	.setup		= ide_disk_setup,
-	.flush		= ide_disk_flush,
-	.init_media	= ide_disk_init_media,
-	.set_doorlock	= ide_disk_set_doorlock,
-	.do_request	= ide_do_rw_disk,
-	.ioctl		= ide_disk_ioctl,
+	.check			= ide_disk_check,
+	.unlock_native_capacity	= ide_disk_unlock_native_capacity,
+	.get_capacity		= ide_disk_get_capacity,
+	.setup			= ide_disk_setup,
+	.flush			= ide_disk_flush,
+	.init_media		= ide_disk_init_media,
+	.set_doorlock		= ide_disk_set_doorlock,
+	.do_request		= ide_do_rw_disk,
+	.ioctl			= ide_disk_ioctl,
 };
drivers/ide/ide-gd.c +4 -7
index c32d839..c102d23 100644
@@ -288,17 +288,14 @@ static int ide_gd_media_changed(struct gendisk *disk)
 	return ret;
 }
 
-static unsigned long long ide_gd_set_capacity(struct gendisk *disk,
-					      unsigned long long capacity)
+static void ide_gd_unlock_native_capacity(struct gendisk *disk)
 {
 	struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
 	ide_drive_t *drive = idkp->drive;
 	const struct ide_disk_ops *disk_ops = drive->disk_ops;
 
-	if (disk_ops->set_capacity)
-		return disk_ops->set_capacity(drive, capacity);
-
-	return drive->capacity64;
+	if (disk_ops->unlock_native_capacity)
+		disk_ops->unlock_native_capacity(drive);
 }
 
 static int ide_gd_revalidate_disk(struct gendisk *disk)
@@ -329,7 +326,7 @@ static const struct block_device_operations ide_gd_ops = {
 	.locked_ioctl		= ide_gd_ioctl,
 	.getgeo			= ide_gd_getgeo,
 	.media_changed		= ide_gd_media_changed,
-	.set_capacity		= ide_gd_set_capacity,
+	.unlock_native_capacity	= ide_gd_unlock_native_capacity,
 	.revalidate_disk	= ide_gd_revalidate_disk
 };
 
fs/partitions/check.c +2 -2
index 8f01df3..4f1fee0 100644
@@ -601,10 +601,10 @@ rescan:
 			       "%s: p%d size %llu exceeds device capacity, ",
 			       disk->disk_name, p, (unsigned long long) size);
 
-			if (bdops->set_capacity &&
+			if (bdops->unlock_native_capacity &&
 			    (disk->flags & GENHD_FL_NATIVE_CAPACITY) == 0) {
 				printk(KERN_CONT "enabling native capacity\n");
-				bdops->set_capacity(disk, ~0ULL);
+				bdops->unlock_native_capacity(disk);
 				disk->flags |= GENHD_FL_NATIVE_CAPACITY;
 				/* free state and restart */
 				kfree(state);
include/linux/blkdev.h +1 -2
index 6690e8b..f2a0c33 100644
@@ -1283,8 +1283,7 @@ struct block_device_operations {
 	int (*direct_access) (struct block_device *, sector_t,
 						void **, unsigned long *);
 	int (*media_changed) (struct gendisk *);
-	unsigned long long (*set_capacity) (struct gendisk *,
-						unsigned long long);
+	void (*unlock_native_capacity) (struct gendisk *);
 	int (*revalidate_disk) (struct gendisk *);
 	int (*getgeo)(struct block_device *, struct hd_geometry *);
 	struct module *owner;
include/linux/ide.h +1 -1
index 3239d1c..b6d4480 100644
@@ -362,7 +362,7 @@ struct ide_drive_s;
 struct ide_disk_ops {
 	int		(*check)(struct ide_drive_s *, const char *);
 	int		(*get_capacity)(struct ide_drive_s *);
-	u64		(*set_capacity)(struct ide_drive_s *, u64);
+	void		(*unlock_native_capacity)(struct ide_drive_s *);
 	void		(*setup)(struct ide_drive_s *);
 	void		(*flush)(struct ide_drive_s *);
 	int		(*init_media)(struct ide_drive_s *, struct gendisk *);
Signature · 1 line
1.6.4.2
#6 lore raw

Re: [PATCH 3/8] block,ide: simplify bdops->set_capacity() to ->unlock_native_capacity()

Hi Tejun,

Quoted 4 lines · Tejun Heo

bdops->set_capacity() is unnecessarily generic. All that's required is a simple one way notification to lower level driver telling it to try to unlock native capacity. There's no reason to pass in target capacity or return the new capacity. The former is always the

This seems to rely on an optimistic assumption that command execution will always be successful and that no errors on disk or host level can ever happen..

[ The assumption in question was introduced in the previous patch:

@@ -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;

originally if the command execution failed the 'capacity' would be 0 ]

It also seems that the original code could be improved a lot to handle (very unlikely but not impossible) error situations better..

Quoted 166 lines

inherent native capacity and the latter can be handled via the usual device resize / revalidation path. In fact, the current API is always used that way.

Replace ->set_capacity() with ->unlock_native_capacity() which take only @disk and doesn't return anything. IDE which is the only current user of the API is converted accordingly.

Cc Ben Hutchings <[email protected]>
Cc Jens Axboe <[email protected]>
Cc David Miller <[email protected]>
Cc Bartlomiej Zolnierkiewicz <[email protected]>
---
 drivers/ide/ide-disk.c |   40 ++++++++++++++++------------------------
 drivers/ide/ide-gd.c   |   11 ++++-------
 fs/partitions/check.c  |    4 ++--
 include/linux/blkdev.h |    3 +--
 include/linux/ide.h    |    2 +-
 5 files changed, 24 insertions(+), 36 deletions(-)
drivers/ide/ide-disk.c +16 -24
index 3b128dc..33d6503 100644
@@ -407,32 +407,24 @@ static int ide_disk_get_capacity(ide_drive_t *drive)
 	return 0;
 }
 
-static u64 ide_disk_set_capacity(ide_drive_t *drive, u64 capacity)
+static void ide_disk_unlock_native_capacity(ide_drive_t *drive)
 {
-	u64 set = min(capacity, drive->probed_capacity);
 	u16 *id = drive->id;
 	int lba48 = ata_id_lba48_enabled(id);
 
 	if ((drive->dev_flags & IDE_DFLAG_LBA) == 0 ||
 	    ata_id_hpa_enabled(id) == 0)
-		goto out;
+		return;
 
 	/*
 	 * according to the spec the SET MAX ADDRESS command shall be
 	 * immediately preceded by a READ NATIVE MAX ADDRESS command
 	 */
-	capacity = ide_disk_hpa_get_native_capacity(drive, lba48);
-	if (capacity == 0)
-		goto out;
-
-	set = ide_disk_hpa_set_capacity(drive, set, lba48);
-	if (set) {
-		/* needed for ->resume to disable HPA */
-		drive->dev_flags |= IDE_DFLAG_NOHPA;
-		return set;
-	}
-out:
-	return drive->capacity64;
+	if (!ide_disk_hpa_get_native_capacity(drive, lba48))
+		return;
+
+	if (ide_disk_hpa_set_capacity(drive, drive->probed_capacity, lba48))
+		drive->dev_flags |= IDE_DFLAG_NOHPA; /* disable HPA on resume */
 }
 
 static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
@@ -783,13 +775,13 @@ static int ide_disk_set_doorlock(ide_drive_t *drive, struct gendisk *disk,
 }
 
 const struct ide_disk_ops ide_ata_disk_ops = {
-	.check		= ide_disk_check,
-	.set_capacity	= ide_disk_set_capacity,
-	.get_capacity	= ide_disk_get_capacity,
-	.setup		= ide_disk_setup,
-	.flush		= ide_disk_flush,
-	.init_media	= ide_disk_init_media,
-	.set_doorlock	= ide_disk_set_doorlock,
-	.do_request	= ide_do_rw_disk,
-	.ioctl		= ide_disk_ioctl,
+	.check			= ide_disk_check,
+	.unlock_native_capacity	= ide_disk_unlock_native_capacity,
+	.get_capacity		= ide_disk_get_capacity,
+	.setup			= ide_disk_setup,
+	.flush			= ide_disk_flush,
+	.init_media		= ide_disk_init_media,
+	.set_doorlock		= ide_disk_set_doorlock,
+	.do_request		= ide_do_rw_disk,
+	.ioctl			= ide_disk_ioctl,
 };
drivers/ide/ide-gd.c +4 -7
index c32d839..c102d23 100644
@@ -288,17 +288,14 @@ static int ide_gd_media_changed(struct gendisk *disk)
 	return ret;
 }
 
-static unsigned long long ide_gd_set_capacity(struct gendisk *disk,
-					      unsigned long long capacity)
+static void ide_gd_unlock_native_capacity(struct gendisk *disk)
 {
 	struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
 	ide_drive_t *drive = idkp->drive;
 	const struct ide_disk_ops *disk_ops = drive->disk_ops;
 
-	if (disk_ops->set_capacity)
-		return disk_ops->set_capacity(drive, capacity);
-
-	return drive->capacity64;
+	if (disk_ops->unlock_native_capacity)
+		disk_ops->unlock_native_capacity(drive);
 }
 
 static int ide_gd_revalidate_disk(struct gendisk *disk)
@@ -329,7 +326,7 @@ static const struct block_device_operations ide_gd_ops = {
 	.locked_ioctl		= ide_gd_ioctl,
 	.getgeo			= ide_gd_getgeo,
 	.media_changed		= ide_gd_media_changed,
-	.set_capacity		= ide_gd_set_capacity,
+	.unlock_native_capacity	= ide_gd_unlock_native_capacity,
 	.revalidate_disk	= ide_gd_revalidate_disk
 };
 
fs/partitions/check.c +2 -2
index 8f01df3..4f1fee0 100644
@@ -601,10 +601,10 @@ rescan:
 			       "%s: p%d size %llu exceeds device capacity, ",
 			       disk->disk_name, p, (unsigned long long) size);
 
-			if (bdops->set_capacity &&
+			if (bdops->unlock_native_capacity &&
 			    (disk->flags & GENHD_FL_NATIVE_CAPACITY) == 0) {
 				printk(KERN_CONT "enabling native capacity\n");
-				bdops->set_capacity(disk, ~0ULL);
+				bdops->unlock_native_capacity(disk);
 				disk->flags |= GENHD_FL_NATIVE_CAPACITY;
 				/* free state and restart */
 				kfree(state);
include/linux/blkdev.h +1 -2
index 6690e8b..f2a0c33 100644
@@ -1283,8 +1283,7 @@ struct block_device_operations {
 	int (*direct_access) (struct block_device *, sector_t,
 						void **, unsigned long *);
 	int (*media_changed) (struct gendisk *);
-	unsigned long long (*set_capacity) (struct gendisk *,
-						unsigned long long);
+	void (*unlock_native_capacity) (struct gendisk *);
 	int (*revalidate_disk) (struct gendisk *);
 	int (*getgeo)(struct block_device *, struct hd_geometry *);
 	struct module *owner;
include/linux/ide.h +1 -1
index 3239d1c..b6d4480 100644
@@ -362,7 +362,7 @@ struct ide_drive_s;
 struct ide_disk_ops {
 	int		(*check)(struct ide_drive_s *, const char *);
 	int		(*get_capacity)(struct ide_drive_s *);
-	u64		(*set_capacity)(struct ide_drive_s *, u64);
+	void		(*unlock_native_capacity)(struct ide_drive_s *);
 	void		(*setup)(struct ide_drive_s *);
 	void		(*flush)(struct ide_drive_s *);
 	int		(*init_media)(struct ide_drive_s *, struct gendisk *);
author
#7 lore raw

Re: [PATCH 3/8] block,ide: simplify bdops->set_capacity() to ->unlock_native_capacity()

Hello, Bartlomiej.

Quoted 5 lines · Bartlomiej Zolnierkiewicz

This seems to rely on an optimistic assumption that command execution will always be successful and that no errors on disk or host level can ever happen..

[ The assumption in question was introduced in the previous patch:

...

Quoted 1 line

originally if the command execution failed the 'capacity' would be 0 ]

Hmm... nothing really changes by this tho. Whether unlocking succeeds or not, the block layer will revalidate the disk and the state at that point will be taken as the configuration to use. There really is nothing much else to do. You try unlocking, if it unlocks, use new capacity. If unlocking fails, revalidation will report the limited size and block layer will have to use that. If the device dies due to the unlocking attempt, well, the device is dead all the same.

Quoted 2 lines

It also seems that the original code could be improved a lot to handle (very unlikely but not impossible) error situations better..

If retry is deemed necessary, it's best handled inside the per-driver unlock handler. I don't think pushing EH logic upto block layer in this case would be a good idea. Block layer is basically telling the driver "do whatever you can do to unlock the native capacity, when you're done, I'll restart from the beginning".

Thanks.

Signature · 1 line
tejun
Acked-by on v1 3/8
#8 lore raw

Re: [PATCH 3/8] block,ide: simplify bdops->set_capacity() to ->unlock_native_capacity()

In reply to Tejun Heo

From: Tejun Heo <[email protected]>
Date: Sat, 15 May 2010 20:09:29 +0200

Quoted 8 lines

bdops->set_capacity() is unnecessarily generic. All that's required is a simple one way notification to lower level driver telling it to try to unlock native capacity. There's no reason to pass in target capacity or return the new capacity. The former is always the inherent native capacity and the latter can be handled via the usual device resize / revalidation path. In fact, the current API is always used that way.

Quoted 5 lines

Replace ->set_capacity() with ->unlock_native_capacity() which take only @disk and doesn't return anything. IDE which is the only current user of the API is converted accordingly.

author
#9 lore raw

PATCH 4/8 block: use struct parsed_partitions *state universally in partition check code

In reply to Tejun Heo

Make the following changes to partition check code.

* Add ->bdev to struct parsed_partitions.

* Introduce read_part_sector() which is a simple wrapper around read_dev_sector() which takes struct parsed_partitions *state instead of @bdev.

* For functions which used to take @state and @bdev, drop @bdev. For functions which used to take @bdev, replace it with @state.

* While updating, drop superflous checks on NULL state/bdev in ldm.c.

This cleans up the API a bit and enables better handling of IO errors during partition check as the generic partition check code now has much better visibility into what went wrong in the low level code paths.

Cc Ben Hutchings <[email protected]>
---
 fs/partitions/acorn.c  |   68 +++++++++++++++++-------------------
 fs/partitions/acorn.h  |   10 +++---
 fs/partitions/amiga.c  |   13 +++----
 fs/partitions/amiga.h  |    2 +-
 fs/partitions/atari.c  |    8 ++--
 fs/partitions/atari.h  |    2 +-
 fs/partitions/check.c  |    5 ++-
 fs/partitions/check.h  |    7 ++++
 fs/partitions/efi.c    |   91 ++++++++++++++++++++++-------------------------
 fs/partitions/efi.h    |    2 +-
 fs/partitions/ibm.c    |   21 +++++------
 fs/partitions/ibm.h    |    2 +-
 fs/partitions/karma.c  |    4 +-
 fs/partitions/karma.h  |    2 +-
 fs/partitions/ldm.c    |   89 +++++++++++++++++++++++-----------------------
 fs/partitions/ldm.h    |    2 +-
 fs/partitions/mac.c    |   11 +++---
 fs/partitions/mac.h    |    2 +-
 fs/partitions/msdos.c  |   85 +++++++++++++++++++-------------------------
 fs/partitions/msdos.h  |    2 +-
 fs/partitions/osf.c    |    4 +-
 fs/partitions/osf.h    |    2 +-
 fs/partitions/sgi.c    |    6 ++--
 fs/partitions/sgi.h    |    2 +-
 fs/partitions/sun.c    |    6 ++--
 fs/partitions/sun.h    |    2 +-
 fs/partitions/sysv68.c |    6 ++--
 fs/partitions/sysv68.h |    2 +-
 fs/partitions/ultrix.c |    4 +-
 fs/partitions/ultrix.h |    2 +-
 30 files changed, 225 insertions(+), 239 deletions(-)
fs/partitions/acorn.c +32 -36
index a97b477..6921e78 100644
@@ -70,14 +70,14 @@ struct riscix_record {
 
 #if defined(CONFIG_ACORN_PARTITION_CUMANA) || \
 	defined(CONFIG_ACORN_PARTITION_ADFS)
-static int
-riscix_partition(struct parsed_partitions *state, struct block_device *bdev,
-		unsigned long first_sect, int slot, unsigned long nr_sects)
+static int riscix_partition(struct parsed_partitions *state,
+			    unsigned long first_sect, int slot,
+			    unsigned long nr_sects)
 {
 	Sector sect;
 	struct riscix_record *rr;
 	
-	rr = (struct riscix_record *)read_dev_sector(bdev, first_sect, &sect);
+	rr = read_part_sector(state, first_sect, &sect);
 	if (!rr)
 		return -1;
 
@@ -123,9 +123,9 @@ struct linux_part {
 
 #if defined(CONFIG_ACORN_PARTITION_CUMANA) || \
 	defined(CONFIG_ACORN_PARTITION_ADFS)
-static int
-linux_partition(struct parsed_partitions *state, struct block_device *bdev,
-		unsigned long first_sect, int slot, unsigned long nr_sects)
+static int linux_partition(struct parsed_partitions *state,
+			   unsigned long first_sect, int slot,
+			   unsigned long nr_sects)
 {
 	Sector sect;
 	struct linux_part *linuxp;
@@ -135,7 +135,7 @@ linux_partition(struct parsed_partitions *state, struct block_device *bdev,
 
 	put_partition(state, slot++, first_sect, size);
 
-	linuxp = (struct linux_part *)read_dev_sector(bdev, first_sect, &sect);
+	linuxp = read_part_sector(state, first_sect, &sect);
 	if (!linuxp)
 		return -1;
 
@@ -157,8 +157,7 @@ linux_partition(struct parsed_partitions *state, struct block_device *bdev,
 #endif
 
 #ifdef CONFIG_ACORN_PARTITION_CUMANA
-int
-adfspart_check_CUMANA(struct parsed_partitions *state, struct block_device *bdev)
+int adfspart_check_CUMANA(struct parsed_partitions *state)
 {
 	unsigned long first_sector = 0;
 	unsigned int start_blk = 0;
@@ -185,7 +184,7 @@ adfspart_check_CUMANA(struct parsed_partitions *state, struct block_device *bdev
 		struct adfs_discrecord *dr;
 		unsigned int nr_sects;
 
-		data = read_dev_sector(bdev, start_blk * 2 + 6, &sect);
+		data = read_part_sector(state, start_blk * 2 + 6, &sect);
 		if (!data)
 			return -1;
 
@@ -217,14 +216,14 @@ adfspart_check_CUMANA(struct parsed_partitions *state, struct block_device *bdev
 #ifdef CONFIG_ACORN_PARTITION_RISCIX
 		case PARTITION_RISCIX_SCSI:
 			/* RISCiX - we don't know how to find the next one. */
-			slot = riscix_partition(state, bdev, first_sector,
-						 slot, nr_sects);
+			slot = riscix_partition(state, first_sector, slot,
+						nr_sects);
 			break;
 #endif
 
 		case PARTITION_LINUX:
-			slot = linux_partition(state, bdev, first_sector,
-						slot, nr_sects);
+			slot = linux_partition(state, first_sector, slot,
+					       nr_sects);
 			break;
 		}
 		put_dev_sector(sect);
@@ -249,8 +248,7 @@ adfspart_check_CUMANA(struct parsed_partitions *state, struct block_device *bdev
  *	    hda1 = ADFS partition on first drive.
  *	    hda2 = non-ADFS partition.
  */
-int
-adfspart_check_ADFS(struct parsed_partitions *state, struct block_device *bdev)
+int adfspart_check_ADFS(struct parsed_partitions *state)
 {
 	unsigned long start_sect, nr_sects, sectscyl, heads;
 	Sector sect;
@@ -259,7 +257,7 @@ adfspart_check_ADFS(struct parsed_partitions *state, struct block_device *bdev)
 	unsigned char id;
 	int slot = 1;
 
-	data = read_dev_sector(bdev, 6, &sect);
+	data = read_part_sector(state, 6, &sect);
 	if (!data)
 		return -1;
 
@@ -278,21 +276,21 @@ adfspart_check_ADFS(struct parsed_partitions *state, struct block_device *bdev)
 	/*
 	 * Work out start of non-adfs partition.
 	 */
-	nr_sects = (bdev->bd_inode->i_size >> 9) - start_sect;
+	nr_sects = (state->bdev->bd_inode->i_size >> 9) - start_sect;
 
 	if (start_sect) {
 		switch (id) {
 #ifdef CONFIG_ACORN_PARTITION_RISCIX
 		case PARTITION_RISCIX_SCSI:
 		case PARTITION_RISCIX_MFM:
-			slot = riscix_partition(state, bdev, start_sect,
-						 slot, nr_sects);
+			slot = riscix_partition(state, start_sect, slot,
+						nr_sects);
 			break;
 #endif
 
 		case PARTITION_LINUX:
-			slot = linux_partition(state, bdev, start_sect,
-						slot, nr_sects);
+			slot = linux_partition(state, start_sect, slot,
+					       nr_sects);
 			break;
 		}
 	}
@@ -308,10 +306,11 @@ struct ics_part {
 	__le32 size;
 };
 
-static int adfspart_check_ICSLinux(struct block_device *bdev, unsigned long block)
+static int adfspart_check_ICSLinux(struct parsed_partitions *state,
+				   unsigned long block)
 {
 	Sector sect;
-	unsigned char *data = read_dev_sector(bdev, block, &sect);
+	unsigned char *data = read_part_sector(state, block, &sect);
 	int result = 0;
 
 	if (data) {
@@ -349,8 +348,7 @@ static inline int valid_ics_sector(const unsigned char *data)
  *	    hda2 = ADFS partition 1 on first drive.
  *		..etc..
  */
-int
-adfspart_check_ICS(struct parsed_partitions *state, struct block_device *bdev)
+int adfspart_check_ICS(struct parsed_partitions *state)
 {
 	const unsigned char *data;
 	const struct ics_part *p;
@@ -360,7 +358,7 @@ adfspart_check_ICS(struct parsed_partitions *state, struct block_device *bdev)
 	/*
 	 * Try ICS style partitions - sector 0 contains partition info.
 	 */
-	data = read_dev_sector(bdev, 0, &sect);
+	data = read_part_sector(state, 0, &sect);
 	if (!data)
 	    	return -1;
 
@@ -392,7 +390,7 @@ adfspart_check_ICS(struct parsed_partitions *state, struct block_device *bdev)
 			 * partition is.  We must not make this visible
 			 * to the filesystem.
 			 */
-			if (size > 1 && adfspart_check_ICSLinux(bdev, start)) {
+			if (size > 1 && adfspart_check_ICSLinux(state, start)) {
 				start += 1;
 				size -= 1;
 			}
@@ -446,8 +444,7 @@ static inline int valid_ptec_sector(const unsigned char *data)
  *	    hda2 = ADFS partition 1 on first drive.
  *		..etc..
  */
-int
-adfspart_check_POWERTEC(struct parsed_partitions *state, struct block_device *bdev)
+int adfspart_check_POWERTEC(struct parsed_partitions *state)
 {
 	Sector sect;
 	const unsigned char *data;
@@ -455,7 +452,7 @@ adfspart_check_POWERTEC(struct parsed_partitions *state, struct block_device *bd
 	int slot = 1;
 	int i;
 
-	data = read_dev_sector(bdev, 0, &sect);
+	data = read_part_sector(state, 0, &sect);
 	if (!data)
 		return -1;
 
@@ -508,8 +505,7 @@ static const char eesox_name[] = {
  *  1. The individual ADFS boot block entries that are placed on the disk.
  *  2. The start address of the next entry.
  */
-int
-adfspart_check_EESOX(struct parsed_partitions *state, struct block_device *bdev)
+int adfspart_check_EESOX(struct parsed_partitions *state)
 {
 	Sector sect;
 	const unsigned char *data;
@@ -518,7 +514,7 @@ adfspart_check_EESOX(struct parsed_partitions *state, struct block_device *bdev)
 	sector_t start = 0;
 	int i, slot = 1;
 
-	data = read_dev_sector(bdev, 7, &sect);
+	data = read_part_sector(state, 7, &sect);
 	if (!data)
 		return -1;
 
@@ -545,7 +541,7 @@ adfspart_check_EESOX(struct parsed_partitions *state, struct block_device *bdev)
 	if (i != 0) {
 		sector_t size;
 
-		size = get_capacity(bdev->bd_disk);
+		size = get_capacity(state->bdev->bd_disk);
 		put_partition(state, slot++, start, size - start);
 		printk("\n");
 	}
fs/partitions/acorn.h +5 -5
index 81fd50e..ede8285 100644
@@ -7,8 +7,8 @@
  *  format, and everyone stick to it?
  */
 
-int adfspart_check_CUMANA(struct parsed_partitions *state, struct block_device *bdev);
-int adfspart_check_ADFS(struct parsed_partitions *state, struct block_device *bdev);
-int adfspart_check_ICS(struct parsed_partitions *state, struct block_device *bdev);
-int adfspart_check_POWERTEC(struct parsed_partitions *state, struct block_device *bdev);
-int adfspart_check_EESOX(struct parsed_partitions *state, struct block_device *bdev);
+int adfspart_check_CUMANA(struct parsed_partitions *state);
+int adfspart_check_ADFS(struct parsed_partitions *state);
+int adfspart_check_ICS(struct parsed_partitions *state);
+int adfspart_check_POWERTEC(struct parsed_partitions *state);
+int adfspart_check_EESOX(struct parsed_partitions *state);
fs/partitions/amiga.c +6 -7
index 9917a8c..ba443d4 100644
@@ -23,8 +23,7 @@ checksum_block(__be32 *m, int size)
 	return sum;
 }
 
-int
-amiga_partition(struct parsed_partitions *state, struct block_device *bdev)
+int amiga_partition(struct parsed_partitions *state)
 {
 	Sector sect;
 	unsigned char *data;
@@ -38,11 +37,11 @@ amiga_partition(struct parsed_partitions *state, struct block_device *bdev)
 	for (blk = 0; ; blk++, put_dev_sector(sect)) {
 		if (blk == RDB_ALLOCATION_LIMIT)
 			goto rdb_done;
-		data = read_dev_sector(bdev, blk, &sect);
+		data = read_part_sector(state, blk, &sect);
 		if (!data) {
 			if (warn_no_part)
 				printk("Dev %s: unable to read RDB block %d\n",
-				       bdevname(bdev, b), blk);
+				       bdevname(state->bdev, b), blk);
 			res = -1;
 			goto rdb_done;
 		}
@@ -64,7 +63,7 @@ amiga_partition(struct parsed_partitions *state, struct block_device *bdev)
 		}
 
 		printk("Dev %s: RDB in block %d has bad checksum\n",
-			       bdevname(bdev, b), blk);
+		       bdevname(state->bdev, b), blk);
 	}
 
 	/* blksize is blocks per 512 byte standard block */
@@ -75,11 +74,11 @@ amiga_partition(struct parsed_partitions *state, struct block_device *bdev)
 	put_dev_sector(sect);
 	for (part = 1; blk>0 && part<=16; part++, put_dev_sector(sect)) {
 		blk *= blksize;	/* Read in terms partition table understands */
-		data = read_dev_sector(bdev, blk, &sect);
+		data = read_part_sector(state, blk, &sect);
 		if (!data) {
 			if (warn_no_part)
 				printk("Dev %s: unable to read partition block %d\n",
-				       bdevname(bdev, b), blk);
+				       bdevname(state->bdev, b), blk);
 			res = -1;
 			goto rdb_done;
 		}
fs/partitions/amiga.h +1 -1
index 2f3e9ce..d094585 100644
@@ -2,5 +2,5 @@
  *  fs/partitions/amiga.h
  */
 
-int amiga_partition(struct parsed_partitions *state, struct block_device *bdev);
+int amiga_partition(struct parsed_partitions *state);
 
fs/partitions/atari.c +4 -4
index 1f3572d..4439ff1 100644
@@ -30,7 +30,7 @@ static inline int OK_id(char *s)
 		memcmp (s, "RAW", 3) == 0 ;
 }
 
-int atari_partition(struct parsed_partitions *state, struct block_device *bdev)
+int atari_partition(struct parsed_partitions *state)
 {
 	Sector sect;
 	struct rootsector *rs;
@@ -42,12 +42,12 @@ int atari_partition(struct parsed_partitions *state, struct block_device *bdev)
 	int part_fmt = 0; /* 0:unknown, 1:AHDI, 2:ICD/Supra */
 #endif
 
-	rs = (struct rootsector *) read_dev_sector(bdev, 0, &sect);
+	rs = read_part_sector(state, 0, &sect);
 	if (!rs)
 		return -1;
 
 	/* Verify this is an Atari rootsector: */
-	hd_size = bdev->bd_inode->i_size >> 9;
+	hd_size = state->bdev->bd_inode->i_size >> 9;
 	if (!VALID_PARTITION(&rs->part[0], hd_size) &&
 	    !VALID_PARTITION(&rs->part[1], hd_size) &&
 	    !VALID_PARTITION(&rs->part[2], hd_size) &&
@@ -84,7 +84,7 @@ int atari_partition(struct parsed_partitions *state, struct block_device *bdev)
 		printk(" XGM<");
 		partsect = extensect = be32_to_cpu(pi->st);
 		while (1) {
-			xrs = (struct rootsector *)read_dev_sector(bdev, partsect, &sect2);
+			xrs = read_part_sector(state, partsect, &sect2);
 			if (!xrs) {
 				printk (" block %ld read failed\n", partsect);
 				put_dev_sector(sect);
fs/partitions/atari.h +1 -1
index 63186b0..fe2d32a 100644
@@ -31,4 +31,4 @@ struct rootsector
   u16 checksum;			/* checksum for bootable disks */
 } __attribute__((__packed__));
 
-int atari_partition(struct parsed_partitions *state, struct block_device *bdev);
+int atari_partition(struct parsed_partitions *state);
fs/partitions/check.c +3 -2
index 4f1fee0..a19995c 100644
@@ -45,7 +45,7 @@ extern void md_autodetect_dev(dev_t dev);
 
 int warn_no_part = 1; /*This is ugly: should make genhd removable media aware*/
 
-static int (*check_part[])(struct parsed_partitions *, struct block_device *) = {
+static int (*check_part[])(struct parsed_partitions *) = {
 	/*
 	 * Probe partition formats with tables at disk address 0
 	 * that also have an ADFS boot block at 0xdc0.
@@ -165,6 +165,7 @@ check_partition(struct gendisk *hd, struct block_device *bdev)
 	if (!state)
 		return NULL;
 
+	state->bdev = bdev;
 	disk_name(hd, 0, state->name);
 	printk(KERN_INFO " %s:", state->name);
 	if (isdigit(state->name[strlen(state->name)-1]))
@@ -174,7 +175,7 @@ check_partition(struct gendisk *hd, struct block_device *bdev)
 	i = res = err = 0;
 	while (!res && check_part[i]) {
 		memset(&state->parts, 0, sizeof(state->parts));
-		res = check_part[i++](state, bdev);
+		res = check_part[i++](state);
 		if (res < 0) {
 			/* We have hit an I/O error which we don't report now.
 		 	* But record it, and let the others do their job.
fs/partitions/check.h +7 -0
index 98dbe1a..4b31a97 100644
@@ -6,6 +6,7 @@
  * description.
  */
 struct parsed_partitions {
+	struct block_device *bdev;
 	char name[BDEVNAME_SIZE];
 	struct {
 		sector_t from;
@@ -16,6 +17,12 @@ struct parsed_partitions {
 	int limit;
 };
 
+static inline void *read_part_sector(struct parsed_partitions *state,
+				     sector_t n, Sector *p)
+{
+	return read_dev_sector(state->bdev, n, p);
+}
+
 static inline void
 put_partition(struct parsed_partitions *p, int n, sector_t from, sector_t size)
 {
fs/partitions/efi.c +43 -48

245 lines not on this page · raw message

fs/partitions/efi.h +1 -1
index 6998b58..b69ab72 100644
@@ -110,7 +110,7 @@ typedef struct _legacy_mbr {
 } __attribute__ ((packed)) legacy_mbr;
 
 /* Functions */
-extern int efi_partition(struct parsed_partitions *state, struct block_device *bdev);
+extern int efi_partition(struct parsed_partitions *state);
 
 #endif
 
fs/partitions/ibm.c +10 -11
index fc71aab..3e73de5 100644
@@ -58,9 +58,9 @@ cchhb2blk (struct vtoc_cchhb *ptr, struct hd_geometry *geo) {
 
 /*
  */
-int
-ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
+int ibm_partition(struct parsed_partitions *state)
 {
+	struct block_device *bdev = state->bdev;
 	int blocksize, res;
 	loff_t i_size, offset, size, fmt_size;
 	dasd_information2_t *info;
@@ -100,7 +100,8 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
 	/*
 	 * Get volume label, extract name and type.
 	 */
-	data = read_dev_sector(bdev, info->label_block*(blocksize/512), &sect);
+	data = read_part_sector(state, info->label_block*(blocksize/512),
+				&sect);
 	if (data == NULL)
 		goto out_readerr;
 
@@ -193,8 +194,8 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
 			 */
 			blk = cchhb2blk(&label->vol.vtoc, geo) + 1;
 			counter = 0;
-			data = read_dev_sector(bdev, blk * (blocksize/512),
-					       &sect);
+			data = read_part_sector(state, blk * (blocksize/512),
+						&sect);
 			while (data != NULL) {
 				struct vtoc_format1_label f1;
 
@@ -208,9 +209,8 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
 				    || f1.DS1FMTID == _ascebc['7']
 				    || f1.DS1FMTID == _ascebc['9']) {
 					blk++;
-					data = read_dev_sector(bdev, blk *
-							       (blocksize/512),
-								&sect);
+					data = read_part_sector(state,
+						blk * (blocksize/512), &sect);
 					continue;
 				}
 
@@ -230,9 +230,8 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
 					      size * (blocksize >> 9));
 				counter++;
 				blk++;
-				data = read_dev_sector(bdev,
-						       blk * (blocksize/512),
-						       &sect);
+				data = read_part_sector(state,
+						blk * (blocksize/512), &sect);
 			}
 
 			if (!data)
fs/partitions/ibm.h +1 -1
index 31f85a6..08fb080 100644
@@ -1 +1 @@
-int ibm_partition(struct parsed_partitions *, struct block_device *);
+int ibm_partition(struct parsed_partitions *);
fs/partitions/karma.c +2 -2
index 176d89b..1cc928b 100644
@@ -9,7 +9,7 @@
 #include "check.h"
 #include "karma.h"
 
-int karma_partition(struct parsed_partitions *state, struct block_device *bdev)
+int karma_partition(struct parsed_partitions *state)
 {
 	int i;
 	int slot = 1;
@@ -29,7 +29,7 @@ int karma_partition(struct parsed_partitions *state, struct block_device *bdev)
 	} __attribute__((packed)) *label;
 	struct d_partition *p;
 
-	data = read_dev_sector(bdev, 0, &sect);
+	data = read_part_sector(state, 0, &sect);
 	if (!data)
 		return -1;
 
fs/partitions/karma.h +1 -1
index ecf7d3f..c764b2e 100644
@@ -4,5 +4,5 @@
 
 #define KARMA_LABEL_MAGIC		0xAB56
 
-int karma_partition(struct parsed_partitions *state, struct block_device *bdev);
+int karma_partition(struct parsed_partitions *state);
 
fs/partitions/ldm.c +44 -45

259 lines not on this page · raw message

fs/partitions/ldm.h +1 -1
index 30e08e8..d1fb50b 100644
@@ -209,7 +209,7 @@ struct ldmdb {				/* Cache of the database */
 	struct list_head v_part;
 };
 
-int ldm_partition (struct parsed_partitions *state, struct block_device *bdev);
+int ldm_partition(struct parsed_partitions *state);
 
 #endif /* _FS_PT_LDM_H_ */
 
fs/partitions/mac.c +6 -5
index d4a0fad..13e27b0 100644
@@ -27,7 +27,7 @@ static inline void mac_fix_string(char *stg, int len)
 		stg[i] = 0;
 }
 
-int mac_partition(struct parsed_partitions *state, struct block_device *bdev)
+int mac_partition(struct parsed_partitions *state)
 {
 	int slot = 1;
 	Sector sect;
@@ -42,7 +42,7 @@ int mac_partition(struct parsed_partitions *state, struct block_device *bdev)
 	struct mac_driver_desc *md;
 
 	/* Get 0th block and look at the first partition map entry. */
-	md = (struct mac_driver_desc *) read_dev_sector(bdev, 0, &sect);
+	md = read_part_sector(state, 0, &sect);
 	if (!md)
 		return -1;
 	if (be16_to_cpu(md->signature) != MAC_DRIVER_MAGIC) {
@@ -51,7 +51,7 @@ int mac_partition(struct parsed_partitions *state, struct block_device *bdev)
 	}
 	secsize = be16_to_cpu(md->block_size);
 	put_dev_sector(sect);
-	data = read_dev_sector(bdev, secsize/512, &sect);
+	data = read_part_sector(state, secsize/512, &sect);
 	if (!data)
 		return -1;
 	part = (struct mac_partition *) (data + secsize%512);
@@ -64,7 +64,7 @@ int mac_partition(struct parsed_partitions *state, struct block_device *bdev)
 	for (blk = 1; blk <= blocks_in_map; ++blk) {
 		int pos = blk * secsize;
 		put_dev_sector(sect);
-		data = read_dev_sector(bdev, pos/512, &sect);
+		data = read_part_sector(state, pos/512, &sect);
 		if (!data)
 			return -1;
 		part = (struct mac_partition *) (data + pos%512);
@@ -123,7 +123,8 @@ int mac_partition(struct parsed_partitions *state, struct block_device *bdev)
 	}
 #ifdef CONFIG_PPC_PMAC
 	if (found_root_goodness)
-		note_bootable_part(bdev->bd_dev, found_root, found_root_goodness);
+		note_bootable_part(state->bdev->bd_dev, found_root,
+				   found_root_goodness);
 #endif
 
 	put_dev_sector(sect);
fs/partitions/mac.h +1 -1
index bbf26e1..3c7d984 100644
@@ -41,4 +41,4 @@ struct mac_driver_desc {
     /* ... more stuff */
 };
 
-int mac_partition(struct parsed_partitions *state, struct block_device *bdev);
+int mac_partition(struct parsed_partitions *state);
fs/partitions/msdos.c +37 -48

216 lines not on this page · raw message

fs/partitions/msdos.h +1 -1
index 01e5e0b..38c781c 100644
@@ -4,5 +4,5 @@
 
 #define MSDOS_LABEL_MAGIC		0xAA55
 
-int msdos_partition(struct parsed_partitions *state, struct block_device *bdev);
+int msdos_partition(struct parsed_partitions *state);
 
fs/partitions/osf.c +2 -2
index c05c17b..fc22b85 100644
@@ -10,7 +10,7 @@
 #include "check.h"
 #include "osf.h"
 
-int osf_partition(struct parsed_partitions *state, struct block_device *bdev)
+int osf_partition(struct parsed_partitions *state)
 {
 	int i;
 	int slot = 1;
@@ -49,7 +49,7 @@ int osf_partition(struct parsed_partitions *state, struct block_device *bdev)
 	} * label;
 	struct d_partition * partition;
 
-	data = read_dev_sector(bdev, 0, &sect);
+	data = read_part_sector(state, 0, &sect);
 	if (!data)
 		return -1;
 
fs/partitions/osf.h +1 -1
index 427b8ea..20ed231 100644
@@ -4,4 +4,4 @@
 
 #define DISKLABELMAGIC (0x82564557UL)
 
-int osf_partition(struct parsed_partitions *state, struct block_device *bdev);
+int osf_partition(struct parsed_partitions *state);
fs/partitions/sgi.c +3 -3
index ed5ac83..43b1df9 100644
@@ -27,7 +27,7 @@ struct sgi_disklabel {
 	__be32 _unused1;			/* Padding */
 };
 
-int sgi_partition(struct parsed_partitions *state, struct block_device *bdev)
+int sgi_partition(struct parsed_partitions *state)
 {
 	int i, csum;
 	__be32 magic;
@@ -39,7 +39,7 @@ int sgi_partition(struct parsed_partitions *state, struct block_device *bdev)
 	struct sgi_partition *p;
 	char b[BDEVNAME_SIZE];
 
-	label = (struct sgi_disklabel *) read_dev_sector(bdev, 0, &sect);
+	label = read_part_sector(state, 0, &sect);
 	if (!label)
 		return -1;
 	p = &label->partitions[0];
@@ -57,7 +57,7 @@ int sgi_partition(struct parsed_partitions *state, struct block_device *bdev)
 	}
 	if(csum) {
 		printk(KERN_WARNING "Dev %s SGI disklabel: csum bad, label corrupted\n",
-		       bdevname(bdev, b));
+		       bdevname(state->bdev, b));
 		put_dev_sector(sect);
 		return 0;
 	}
fs/partitions/sgi.h +1 -1
index 5d5595c..b9553eb 100644
@@ -2,7 +2,7 @@
  *  fs/partitions/sgi.h
  */
 
-extern int sgi_partition(struct parsed_partitions *state, struct block_device *bdev);
+extern int sgi_partition(struct parsed_partitions *state);
 
 #define SGI_LABEL_MAGIC 0x0be5a941
 
fs/partitions/sun.c +3 -3
index c95e6a6..a32660e 100644
@@ -10,7 +10,7 @@
 #include "check.h"
 #include "sun.h"
 
-int sun_partition(struct parsed_partitions *state, struct block_device *bdev)
+int sun_partition(struct parsed_partitions *state)
 {
 	int i;
 	__be16 csum;
@@ -61,7 +61,7 @@ int sun_partition(struct parsed_partitions *state, struct block_device *bdev)
 	int use_vtoc;
 	int nparts;
 
-	label = (struct sun_disklabel *)read_dev_sector(bdev, 0, &sect);
+	label = read_part_sector(state, 0, &sect);
 	if (!label)
 		return -1;
 
@@ -78,7 +78,7 @@ int sun_partition(struct parsed_partitions *state, struct block_device *bdev)
 		csum ^= *ush--;
 	if (csum) {
 		printk("Dev %s Sun disklabel: Csum bad, label corrupted\n",
-		       bdevname(bdev, b));
+		       bdevname(state->bdev, b));
 		put_dev_sector(sect);
 		return 0;
 	}
fs/partitions/sun.h +1 -1
index 7f864d1..2424baa 100644
@@ -5,4 +5,4 @@
 #define SUN_LABEL_MAGIC          0xDABE
 #define SUN_VTOC_SANITY          0x600DDEEE
 
-int sun_partition(struct parsed_partitions *state, struct block_device *bdev);
+int sun_partition(struct parsed_partitions *state);
fs/partitions/sysv68.c +3 -3
index 4eba27b..9030c86 100644
@@ -46,7 +46,7 @@ struct slice {
 };
 
 
-int sysv68_partition(struct parsed_partitions *state, struct block_device *bdev)
+int sysv68_partition(struct parsed_partitions *state)
 {
 	int i, slices;
 	int slot = 1;
@@ -55,7 +55,7 @@ int sysv68_partition(struct parsed_partitions *state, struct block_device *bdev)
 	struct dkblk0 *b;
 	struct slice *slice;
 
-	data = read_dev_sector(bdev, 0, &sect);
+	data = read_part_sector(state, 0, &sect);
 	if (!data)
 		return -1;
 
@@ -68,7 +68,7 @@ int sysv68_partition(struct parsed_partitions *state, struct block_device *bdev)
 	i = be32_to_cpu(b->dk_ios.ios_slcblk);
 	put_dev_sector(sect);
 
-	data = read_dev_sector(bdev, i, &sect);
+	data = read_part_sector(state, i, &sect);
 	if (!data)
 		return -1;
 
fs/partitions/sysv68.h +1 -1
index fa733f6..bf2f5ff 100644
@@ -1 +1 @@
-extern int sysv68_partition(struct parsed_partitions *state, struct block_device *bdev);
+extern int sysv68_partition(struct parsed_partitions *state);
fs/partitions/ultrix.c +2 -2
index ec852c1..db9eef2 100644
@@ -9,7 +9,7 @@
 #include "check.h"
 #include "ultrix.h"
 
-int ultrix_partition(struct parsed_partitions *state, struct block_device *bdev)
+int ultrix_partition(struct parsed_partitions *state)
 {
 	int i;
 	Sector sect;
@@ -26,7 +26,7 @@ int ultrix_partition(struct parsed_partitions *state, struct block_device *bdev)
 #define PT_MAGIC	0x032957	/* Partition magic number */
 #define PT_VALID	1		/* Indicates if struct is valid */
 
-	data = read_dev_sector(bdev, (16384 - sizeof(*label))/512, &sect);
+	data = read_part_sector(state, (16384 - sizeof(*label))/512, &sect);
 	if (!data)
 		return -1;
 	
fs/partitions/ultrix.h +1 -1
index a74bf8e..a3cc00b 100644
@@ -2,4 +2,4 @@
  *  fs/partitions/ultrix.h
  */
 
-int ultrix_partition(struct parsed_partitions *state, struct block_device *bdev);
+int ultrix_partition(struct parsed_partitions *state);
Signature · 1 line
1.6.4.2
Acked-by on v1 4/8
#10 lore raw

Re: [PATCH 4/8] block: use struct parsed_partitions *state universally in partition check code

From: Tejun Heo <[email protected]>
Date: Sat, 15 May 2010 20:09:30 +0200

Quoted 11 lines

Make the following changes to partition check code.

* Add ->bdev to struct parsed_partitions.

* Introduce read_part_sector() which is a simple wrapper around read_dev_sector() which takes struct parsed_partitions *state instead of @bdev.

* For functions which used to take @state and @bdev, drop @bdev. For functions which used to take @bdev, replace it with @state.

Quoted 8 lines

* While updating, drop superflous checks on NULL state/bdev in ldm.c.

This cleans up the API a bit and enables better handling of IO errors during partition check as the generic partition check code now has much better visibility into what went wrong in the low level code paths.

author
#11 lore raw

PATCH 5/8 block: improve automatic native capacity unlocking

In reply to Tejun Heo

Currently, native capacity unlocking is initiated only when a recognized partition extends beyond the end of the disk. However, there are several other unhandled cases where truncated capacity can lead to misdetection of partitions.

* Partition table is fully beyond EOD.

* Partition table is partially beyond EOD (daisy chained ones).

* Recognized partition starts beyond EOD.

This patch updates generic partition check code such that all the above three cases are handled too. For the first two, @state tracks whether low level partition check code tried to read beyond EOD during partition scan and triggers native capacity unlocking accordingly. The third is now handled similarly to the original unlocking case.

Cc Ben Hutchings <[email protected]>
---
 fs/partitions/check.c |   69 +++++++++++++++++++++++++++++++++++++++----------
 fs/partitions/check.h |    5 +++
 2 files changed, 60 insertions(+), 14 deletions(-)
fs/partitions/check.c +55 -14
index a19995c..5dcd4b0 100644
@@ -161,7 +161,7 @@ check_partition(struct gendisk *hd, struct block_device *bdev)
 	struct parsed_partitions *state;
 	int i, res, err;
 
-	state = kmalloc(sizeof(struct parsed_partitions), GFP_KERNEL);
+	state = kzalloc(sizeof(struct parsed_partitions), GFP_KERNEL);
 	if (!state)
 		return NULL;
 
@@ -187,6 +187,8 @@ check_partition(struct gendisk *hd, struct block_device *bdev)
 	}
 	if (res > 0)
 		return state;
+	if (state->access_beyond_eod)
+		err = -ENOSPC;
 	if (err)
 	/* The partition is unrecognized. So report I/O errors if there were any */
 		res = err;
@@ -539,13 +541,34 @@ exit:
 	disk_part_iter_exit(&piter);
 }
 
+static bool disk_unlock_native_capacity(struct gendisk *disk)
+{
+	const struct block_device_operations *bdops = disk->fops;
+
+	if (bdops->unlock_native_capacity &&
+	    !(disk->flags & GENHD_FL_NATIVE_CAPACITY)) {
+		printk(KERN_CONT "enabling native capacity\n");
+		bdops->unlock_native_capacity(disk);
+		disk->flags |= GENHD_FL_NATIVE_CAPACITY;
+		return true;
+	} else {
+		printk(KERN_CONT "truncated\n");
+		return false;
+	}
+}
+
 int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
 {
+	struct parsed_partitions *state = NULL;
 	struct disk_part_iter piter;
 	struct hd_struct *part;
-	struct parsed_partitions *state;
 	int p, highest, res;
 rescan:
+	if (state && !IS_ERR(state)) {
+		kfree(state);
+		state = NULL;
+	}
+
 	if (bdev->bd_part_count)
 		return -EBUSY;
 	res = invalidate_partition(disk, 0);
@@ -563,8 +586,32 @@ rescan:
 	bdev->bd_invalidated = 0;
 	if (!get_capacity(disk) || !(state = check_partition(disk, bdev)))
 		return 0;
-	if (IS_ERR(state))	/* I/O error reading the partition table */
+	if (IS_ERR(state)) {
+		/*
+		 * I/O error reading the partition table.  If any
+		 * partition code tried to read beyond EOD, retry
+		 * after unlocking native capacity.
+		 */
+		if (PTR_ERR(state) == -ENOSPC) {
+			printk(KERN_WARNING "%s: partition table beyond EOD, ",
+			       disk->disk_name);
+			if (disk_unlock_native_capacity(disk))
+				goto rescan;
+		}
 		return -EIO;
+	}
+	/*
+	 * If any partition code tried to read beyond EOD, try
+	 * unlocking native capacity even if partition table is
+	 * sucessfully read as we could be missing some partitions.
+	 */
+	if (state->access_beyond_eod) {
+		printk(KERN_WARNING
+		       "%s: partition table partially beyond EOD, ",
+		       disk->disk_name);
+		if (disk_unlock_native_capacity(disk))
+			goto rescan;
+	}
 
 	/* tell userspace that the media / partition table may have changed */
 	kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
@@ -590,25 +637,20 @@ rescan:
 		from = state->parts[p].from;
 		if (from >= get_capacity(disk)) {
 			printk(KERN_WARNING
-			       "%s: p%d ignored, start %llu is behind the end of the disk\n",
+			       "%s: p%d start %llu is beyond EOD, ",
 			       disk->disk_name, p, (unsigned long long) from);
+			if (disk_unlock_native_capacity(disk))
+				goto rescan;
 			continue;
 		}
 
 		if (from + size > get_capacity(disk)) {
-			const struct block_device_operations *bdops = disk->fops;
-
 			printk(KERN_WARNING
-			       "%s: p%d size %llu exceeds device capacity, ",
+			       "%s: p%d size %llu extends beyond EOD, ",
 			       disk->disk_name, p, (unsigned long long) size);
 
-			if (bdops->unlock_native_capacity &&
-			    (disk->flags & GENHD_FL_NATIVE_CAPACITY) == 0) {
-				printk(KERN_CONT "enabling native capacity\n");
-				bdops->unlock_native_capacity(disk);
-				disk->flags |= GENHD_FL_NATIVE_CAPACITY;
+			if (disk_unlock_native_capacity(disk)) {
 				/* free state and restart */
-				kfree(state);
 				goto rescan;
 			} else {
 				/*
@@ -617,7 +659,6 @@ rescan:
 				 * we limit them to the end of the disk to avoid
 				 * creating invalid block devices
 				 */
-				printk(KERN_CONT "limited to end of disk\n");
 				size = get_capacity(disk) - from;
 			}
 		}
fs/partitions/check.h +5 -0
index 4b31a97..52f8bd3 100644
@@ -15,11 +15,16 @@ struct parsed_partitions {
 	} parts[DISK_MAX_PARTS];
 	int next;
 	int limit;
+	bool access_beyond_eod;
 };
 
 static inline void *read_part_sector(struct parsed_partitions *state,
 				     sector_t n, Sector *p)
 {
+	if (n >= get_capacity(state->bdev->bd_disk)) {
+		state->access_beyond_eod = true;
+		return NULL;
+	}
 	return read_dev_sector(state->bdev, n, p);
 }
 
Signature · 1 line
1.6.4.2
Acked-by on v1 5/8
#12 lore raw

Re: [PATCH 5/8] block: improve automatic native capacity unlocking

From: Tejun Heo <[email protected]>
Date: Sat, 15 May 2010 20:09:31 +0200

Quoted 11 lines

Currently, native capacity unlocking is initiated only when a recognized partition extends beyond the end of the disk. However, there are several other unhandled cases where truncated capacity can lead to misdetection of partitions.

* Partition table is fully beyond EOD.

* Partition table is partially beyond EOD (daisy chained ones).

* Recognized partition starts beyond EOD.

Quoted 7 lines

This patch updates generic partition check code such that all the above three cases are handled too. For the first two, @state tracks whether low level partition check code tried to read beyond EOD during partition scan and triggers native capacity unlocking accordingly. The third is now handled similarly to the original unlocking case.

author
#13 lore raw

PATCH 6/8 SCSI: implement sd_unlock_native_capacity()

In reply to Tejun Heo

Implement sd_unlock_native_capacity() method which calls into hostt->unlock_native_capacity() if implemented. This will be invoked by block layer if partitions extend beyond the end of the device and can be used to implement, for example, on-demand ATA host protected area unlocking.

Cc Ben Hutchings <[email protected]>
---
 drivers/scsi/sd.c        |   22 ++++++++++++++++++++++
 include/scsi/scsi_host.h |    8 ++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)
drivers/scsi/sd.c +22 -0
index 8b827f3..b85906e 100644
@@ -97,6 +97,7 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_RBC);
 #endif
 
 static int  sd_revalidate_disk(struct gendisk *);
+static void sd_unlock_native_capacity(struct gendisk *disk);
 static int  sd_probe(struct device *);
 static int  sd_remove(struct device *);
 static void sd_shutdown(struct device *);
@@ -1100,6 +1101,7 @@ static const struct block_device_operations sd_fops = {
 #endif
 	.media_changed		= sd_media_changed,
 	.revalidate_disk	= sd_revalidate_disk,
+	.unlock_native_capacity	= sd_unlock_native_capacity,
 };
 
 static unsigned int sd_completed_bytes(struct scsi_cmnd *scmd)
@@ -2101,6 +2103,26 @@ static int sd_revalidate_disk(struct gendisk *disk)
 }
 
 /**
+ *	sd_unlock_native_capacity - unlock native capacity
+ *	@disk: struct gendisk to set capacity for
+ *
+ *	Block layer calls this function if it detects that partitions
+ *	on @disk reach beyond the end of the device.  If the SCSI host
+ *	implements ->unlock_native_capacity() method, it's invoked to
+ *	give it a chance to adjust the device capacity.
+ *
+ *	CONTEXT:
+ *	Defined by block layer.  Might sleep.
+ */
+static void sd_unlock_native_capacity(struct gendisk *disk)
+{
+	struct scsi_device *sdev = scsi_disk(disk)->device;
+
+	if (sdev->host->hostt->unlock_native_capacity)
+		sdev->host->hostt->unlock_native_capacity(sdev);
+}
+
+/**
  *	sd_format_disk_name - format disk name
  *	@prefix: name prefix - ie. "sd" for SCSI disks
  *	@index: index of the disk to format name for
include/scsi/scsi_host.h +8 -0
index c50a97f..b7bdecb 100644
@@ -327,6 +327,14 @@ struct scsi_host_template {
 			sector_t, int []);
 
 	/*
+	 * This function is called when one or more partitions on the
+	 * device reach beyond the end of the device.
+	 *
+	 * Status: OPTIONAL
+	 */
+	void (*unlock_native_capacity)(struct scsi_device *);
+
+	/*
 	 * Can be used to export driver statistics and other infos to the
 	 * world outside the kernel ie. userspace and it also provides an
 	 * interface to feed the driver with information.
Signature · 1 line
1.6.4.2
Acked-by on v1 6/8
#14 lore raw

Re: [PATCH 6/8] SCSI: implement sd_unlock_native_capacity()

From: Tejun Heo <[email protected]>
Date: Sat, 15 May 2010 20:09:32 +0200

Quoted 7 lines

Implement sd_unlock_native_capacity() method which calls into hostt->unlock_native_capacity() if implemented. This will be invoked by block layer if partitions extend beyond the end of the device and can be used to implement, for example, on-demand ATA host protected area unlocking.

#15 lore raw

Re: [PATCH 6/8] SCSI: implement sd_unlock_native_capacity()

In reply to Tejun Heo
Quoted 66 lines · Tejun Heo

Implement sd_unlock_native_capacity() method which calls into hostt->unlock_native_capacity() if implemented. This will be invoked by block layer if partitions extend beyond the end of the device and can be used to implement, for example, on-demand ATA host protected area unlocking.

Cc Ben Hutchings <[email protected]>
---
 drivers/scsi/sd.c        |   22 ++++++++++++++++++++++
 include/scsi/scsi_host.h |    8 ++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)
drivers/scsi/sd.c +22 -0
index 8b827f3..b85906e 100644
@@ -97,6 +97,7 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_RBC);
 #endif
 
 static int  sd_revalidate_disk(struct gendisk *);
+static void sd_unlock_native_capacity(struct gendisk *disk);
 static int  sd_probe(struct device *);
 static int  sd_remove(struct device *);
 static void sd_shutdown(struct device *);
@@ -1100,6 +1101,7 @@ static const struct block_device_operations sd_fops = {
 #endif
 	.media_changed		= sd_media_changed,
 	.revalidate_disk	= sd_revalidate_disk,
+	.unlock_native_capacity	= sd_unlock_native_capacity,
 };
 
 static unsigned int sd_completed_bytes(struct scsi_cmnd *scmd)
@@ -2101,6 +2103,26 @@ static int sd_revalidate_disk(struct gendisk *disk)
 }
 
 /**
+ *	sd_unlock_native_capacity - unlock native capacity
+ *	@disk: struct gendisk to set capacity for
+ *
+ *	Block layer calls this function if it detects that partitions
+ *	on @disk reach beyond the end of the device.  If the SCSI host
+ *	implements ->unlock_native_capacity() method, it's invoked to
+ *	give it a chance to adjust the device capacity.
+ *
+ *	CONTEXT:
+ *	Defined by block layer.  Might sleep.
+ */
+static void sd_unlock_native_capacity(struct gendisk *disk)
+{
+	struct scsi_device *sdev = scsi_disk(disk)->device;
+
+	if (sdev->host->hostt->unlock_native_capacity)
+		sdev->host->hostt->unlock_native_capacity(sdev);
+}
+
+/**
  *	sd_format_disk_name - format disk name
  *	@prefix: name prefix - ie. "sd" for SCSI disks
  *	@index: index of the disk to format name for
include/scsi/scsi_host.h +0 -0
index c50a97f..b7bdecb 100644
@@ -327,6 +327,14 @@ struct scsi_host_template {
 			sector_t, int []);

include/scsi/scsi_host.h struct scsi_host_template { · line 337

Quoted 10 lines
include/scsi/scsi_host.h +8 -0
 
 	/*
+	 * This function is called when one or more partitions on the
+	 * device reach beyond the end of the device.
+	 *
+	 * Status: OPTIONAL
+	 */
+	void (*unlock_native_capacity)(struct scsi_device *);
+
+	/*

I still principally dislike this threading of the operation up and down the stack. Although we've done it before, we're trying to get away from the paradigm of driver conditions to scsi and scsi conditions to block for all stuff where driver could condition straight to block (alignment is a classic example of the new way of doing things).

The reason you need the threading is because the block ops gets hidden at the top of the stack in the upper layers (this was a design choice to try to prevent the lower layers mucking with it). The way we get around this is to use a queue operation instead. As far as I can tell, there's no logical reason for the unlock to be a block op, so lets make it a queue op instead. The consumer in

static bool disk_unlock_native_capacity(struct gendisk *disk)

then becomes

	blk_unlock_native_capacity(disk->queue)

Block's implementation of this would probably call directly through the queue.

You place the usual function in the queue template so the ata slave configure can say

blk_queue_unlock_native_function(rq, <unlock_function>)

Then there's no need for anything at all in SCSI ... and it becomes a whole lot more obvious how to do legacy ide (if we ever get problems there).

James

#16 lore raw

Re: [PATCH 6/8] SCSI: implement sd_unlock_native_capacity()

On Sun, 2010-05-16 at 08:39 -0500, James Bottomley wrote:
[...]

Quoted 3 lines

Then there's no need for anything at all in SCSI ... and it becomes a whole lot more obvious how to do legacy ide (if we ever get problems there).

The block device set_capacity() interface is already defined and was implemented for the IDE disk driver some time ago. The purpose of Tejun's work on sd and libata is to implement this existing interface and so avoid a regression when users switch from IDE to libata-based drivers. I don't see why he should have to replace the interface as well.

Ben.

Signature · 2 lines
Ben Hutchings
Once a job is fouled up, anything done to improve it makes it worse.
#17 lore raw

Re: [PATCH 6/8] SCSI: implement sd_unlock_native_capacity()

Quoted 6 lines · Ben Hutchings

On Sun, 2010-05-16 at 08:39 -0500, James Bottomley wrote:
[...]

Quoted 3 lines

Then there's no need for anything at all in SCSI ... and it becomes a whole lot more obvious how to do legacy ide (if we ever get problems there).

Quoted 6 lines

The block device set_capacity() interface is already defined and was implemented for the IDE disk driver some time ago. The purpose of Tejun's work on sd and libata is to implement this existing interface and so avoid a regression when users switch from IDE to libata-based drivers. I don't see why he should have to replace the interface as well.

I thought we already reached the conclusion that set_capacity wasn't the right interface, hence the redo as a binary lock/unlock of native capacity ... which is revoking the set_capacity interface in this patch.

The point I was making is that bdops just works for ide because it's completely monolithic. It gives us a layering problem in SCSI because you have to hook it into the lower layers which don't have access to bdops (since they're an upper layer thing in SCSI).

This layering problem is partly the fault of libata ... if we had an ATA native disk driver, it would be able to unlock the capacity on its own. It's just we're using SCSI which has no SAT command it can issue for this, so the functional request has to be pushed down to libata ... leading to the need to thread it through the host template.

I was just pointing out that the whole thing is simplified if we use a block queue function approach instead. ide_disk_t has access to the queue, as does gendisk, so it would all "just work" with a simple call site change if we used queue ops instead of block dev ops. The plus side of doing it this way is that the SCSI threading becomes
unnecessary: libata gets directly hooked into the unlock function instead of having to do it via an intermediary.

James

author
#18 lore raw

Re: [PATCH 6/8] SCSI: implement sd_unlock_native_capacity()

Hello, James.

Quoted 2 lines · James Bottomley

This layering problem is partly the fault of libata ... if we had an ATA native disk driver, it would be able to unlock the capacity on its own.

Yeap.

Quoted 11 lines

It's just we're using SCSI which has no SAT command it can issue for this, so the functional request has to be pushed down to libata ... leading to the need to thread it through the host template.

I was just pointing out that the whole thing is simplified if we use a block queue function approach instead. ide_disk_t has access to the queue, as does gendisk, so it would all "just work" with a simple call site change if we used queue ops instead of block dev ops. The plus side of doing it this way is that the SCSI threading becomes
unnecessary: libata gets directly hooked into the unlock function instead of having to do it via an intermediary.

Yeah, it can be made to work via a queue callback but I'm afraid that would be a genuine layering violation (although going through SCSI is extra layering, it isn't really a layering violation).

These are request_queue methods.

	request_fn_proc		*request_fn;
	make_request_fn		*make_request_fn;
	prep_rq_fn		*prep_rq_fn;
	unplug_fn		*unplug_fn;
	merge_bvec_fn		*merge_bvec_fn;
	prepare_flush_fn	*prepare_flush_fn;
	softirq_done_fn		*softirq_done_fn;
	rq_timed_out_fn		*rq_timed_out_fn;
	dma_drain_needed_fn	*dma_drain_needed;
	lld_busy_fn		*lld_busy_fn;

These are gendisk methods.

	int (*open) (struct block_device *, fmode_t);
	int (*release) (struct gendisk *, fmode_t);
	int (*locked_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
	int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
	int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
	int (*direct_access) (struct block_device *, sector_t,
						void **, unsigned long *);
	int (*media_changed) (struct gendisk *);
	void (*unlock_native_capacity) (struct gendisk *);
	int (*revalidate_disk) (struct gendisk *);
	int (*getgeo)(struct block_device *, struct hd_geometry *);

request_queue is (or at least supposed to be) oblivious about genhd and its attributes including capacity. After all, request_queue can exist w/o genhd associated, so it would be quite odd to have capacity related method living in request_queue.

Another thing is that there is no generic way to reach the associated genhd from request_queue and I can't think of a clean way to map request_queue to the associated ata device w/o in-flight requests (can you even do that from SCSI?).

Unfortunately, libata is still properly layered below SCSI, so I'm afraid threading through sd is clumsy yet the cleanest way to do it.

Thanks.

Signature · 1 line
tejun
#19 lore raw

Re: [PATCH 6/8] SCSI: implement sd_unlock_native_capacity()

Quoted 51 lines · Tejun Heo

Hello, James.

Quoted 2 lines · James Bottomley

This layering problem is partly the fault of libata ... if we had an ATA native disk driver, it would be able to unlock the capacity on its own.

Yeap.

Quoted 11 lines

It's just we're using SCSI which has no SAT command it can issue for this, so the functional request has to be pushed down to libata ... leading to the need to thread it through the host template.

I was just pointing out that the whole thing is simplified if we use a block queue function approach instead. ide_disk_t has access to the queue, as does gendisk, so it would all "just work" with a simple call site change if we used queue ops instead of block dev ops. The plus side of doing it this way is that the SCSI threading becomes
unnecessary: libata gets directly hooked into the unlock function instead of having to do it via an intermediary.

Yeah, it can be made to work via a queue callback but I'm afraid that would be a genuine layering violation (although going through SCSI is extra layering, it isn't really a layering violation).

These are request_queue methods.

	request_fn_proc		*request_fn;
	make_request_fn		*make_request_fn;
	prep_rq_fn		*prep_rq_fn;
	unplug_fn		*unplug_fn;
	merge_bvec_fn		*merge_bvec_fn;
	prepare_flush_fn	*prepare_flush_fn;
	softirq_done_fn		*softirq_done_fn;
	rq_timed_out_fn		*rq_timed_out_fn;
	dma_drain_needed_fn	*dma_drain_needed;
	lld_busy_fn		*lld_busy_fn;

These are gendisk methods.

	int (*open) (struct block_device *, fmode_t);
	int (*release) (struct gendisk *, fmode_t);
	int (*locked_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
	int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
	int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
	int (*direct_access) (struct block_device *, sector_t,
						void **, unsigned long *);
	int (*media_changed) (struct gendisk *);
	void (*unlock_native_capacity) (struct gendisk *);
	int (*revalidate_disk) (struct gendisk *);
	int (*getgeo)(struct block_device *, struct hd_geometry *);
Quoted 4 lines

request_queue is (or at least supposed to be) oblivious about genhd and its attributes including capacity. After all, request_queue can exist w/o genhd associated, so it would be quite odd to have capacity related method living in request_queue.

Yes, I'll sort of buy this ... although it's not quite that clean:
barrier methods, which are only used for filesystem above block devices also live in the queue.

Quoted 4 lines

Another thing is that there is no generic way to reach the associated genhd from request_queue and I can't think of a clean way to map request_queue to the associated ata device w/o in-flight requests (can you even do that from SCSI?).

No ... that's by design ... but you don't need it if all you're doing is unlocking the native capacity (whether on behalf of block dev ops or queue ops).

Quoted 2 lines

Unfortunately, libata is still properly layered below SCSI, so I'm afraid threading through sd is clumsy yet the cleanest way to do it.

s/properly/im\&/

but yes,

James

author
#20 lore raw

Re: [PATCH 6/8] SCSI: implement sd_unlock_native_capacity()

Hello,

Quoted 8 lines · James Bottomley
Quoted 4 lines

request_queue is (or at least supposed to be) oblivious about genhd and its attributes including capacity. After all, request_queue can exist w/o genhd associated, so it would be quite odd to have capacity related method living in request_queue.

Yes, I'll sort of buy this ... although it's not quite that clean:
barrier methods, which are only used for filesystem above block devices also live in the queue.

You mean prepare_flush_fn()? Hmmm...

Quoted 8 lines
Quoted 4 lines

Another thing is that there is no generic way to reach the associated genhd from request_queue and I can't think of a clean way to map request_queue to the associated ata device w/o in-flight requests (can you even do that from SCSI?).

No ... that's by design ... but you don't need it if all you're doing is unlocking the native capacity (whether on behalf of block dev ops or queue ops).

libata defers all those managements stuff to EH and the ata device needs to be accessible to invoke EH. It can be worked around by issuing a pseudo command which is trapped and deferred to EH during command processing but it's much better to be able to access the device directly.

Quoted 4 lines
Quoted 2 lines

Unfortunately, libata is still properly layered below SCSI, so I'm afraid threading through sd is clumsy yet the cleanest way to do it.

s/properly/im\&/

Heh, yeah. :-)

Quoted 3 lines

but yes,

Thanks. Much appreciated.

Signature · 1 line
tejun
#21 lore raw

Re: [PATCH 6/8] SCSI: implement sd_unlock_native_capacity()

In reply to Tejun Heo
Quoted 66 lines · Tejun Heo

Implement sd_unlock_native_capacity() method which calls into hostt->unlock_native_capacity() if implemented. This will be invoked by block layer if partitions extend beyond the end of the device and can be used to implement, for example, on-demand ATA host protected area unlocking.

Cc Ben Hutchings<[email protected]>
---
  drivers/scsi/sd.c        |   22 ++++++++++++++++++++++
  include/scsi/scsi_host.h |    8 ++++++++
  2 files changed, 30 insertions(+), 0 deletions(-)
drivers/scsi/sd.c +22 -0
index 8b827f3..b85906e 100644
@@ -97,6 +97,7 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_RBC);
  #endif
 
  static int  sd_revalidate_disk(struct gendisk *);
+static void sd_unlock_native_capacity(struct gendisk *disk);
  static int  sd_probe(struct device *);
  static int  sd_remove(struct device *);
  static void sd_shutdown(struct device *);
@@ -1100,6 +1101,7 @@ static const struct block_device_operations sd_fops = {
  #endif
  	.media_changed		= sd_media_changed,
  	.revalidate_disk	= sd_revalidate_disk,
+	.unlock_native_capacity	= sd_unlock_native_capacity,
  };
 
  static unsigned int sd_completed_bytes(struct scsi_cmnd *scmd)
@@ -2101,6 +2103,26 @@ static int sd_revalidate_disk(struct gendisk *disk)
  }
 
  /**
+ *	sd_unlock_native_capacity - unlock native capacity
+ *	@disk: struct gendisk to set capacity for
+ *
+ *	Block layer calls this function if it detects that partitions
+ *	on @disk reach beyond the end of the device.  If the SCSI host
+ *	implements ->unlock_native_capacity() method, it's invoked to
+ *	give it a chance to adjust the device capacity.
+ *
+ *	CONTEXT:
+ *	Defined by block layer.  Might sleep.
+ */
+static void sd_unlock_native_capacity(struct gendisk *disk)
+{
+	struct scsi_device *sdev = scsi_disk(disk)->device;
+
+	if (sdev->host->hostt->unlock_native_capacity)
+		sdev->host->hostt->unlock_native_capacity(sdev);
+}
+
+/**
   *	sd_format_disk_name - format disk name
   *	@prefix: name prefix - ie. "sd" for SCSI disks
   *	@index: index of the disk to format name for
include/scsi/scsi_host.h +0 -0
index c50a97f..b7bdecb 100644
@@ -327,6 +327,14 @@ struct scsi_host_template {
  			sector_t, int []);

include/scsi/scsi_host.h struct scsi_host_template { · line 337

Quoted 10 lines
include/scsi/scsi_host.h +8 -0
 
  	/*
+	 * This function is called when one or more partitions on the
+	 * device reach beyond the end of the device.
+	 *
+	 * Status: OPTIONAL
+	 */
+	void (*unlock_native_capacity)(struct scsi_device *);
+
+	/*

applied 6-8, including this SCSI patch

author
#22 lore raw

PATCH 7/8 libata: use the enlarged capacity after late HPA unlock

In reply to Tejun Heo

After late HPA unlock, libata kept using the original capacity ignoring the new larger native capacity. Enlarging device on the fly doesn't cause any harm. Use the larger native capacity instead. This will enable on-demand HPA unlocking.

Cc Ben Hutchings <[email protected]>
---
 drivers/ata/libata-core.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
drivers/ata/libata-core.c +2 -3
index 86f405b..9d6e92d 100644
@@ -4212,9 +4212,8 @@ int ata_dev_revalidate(struct ata_device *dev, unsigned int new_class,
 	    dev->n_sectors > n_sectors && dev->n_sectors == n_native_sectors) {
 		ata_dev_printk(dev, KERN_WARNING,
 			       "new n_sectors matches native, probably "
-			       "late HPA unlock, continuing\n");
-		/* keep using the old n_sectors */
-		dev->n_sectors = n_sectors;
+			       "late HPA unlock, n_sectors updated\n");
+		/* use the larger n_sectors */
 		return 0;
 	}
 
Signature · 1 line
1.6.4.2
Acked-by on v1 7/8
#23 lore raw

Re: [PATCH 7/8] libata: use the enlarged capacity after late HPA unlock

Quoted 7 lines · Tejun Heo

After late HPA unlock, libata kept using the original capacity ignoring the new larger native capacity. Enlarging device on the fly doesn't cause any harm. Use the larger native capacity instead. This will enable on-demand HPA unlocking.

Cc Ben Hutchings<[email protected]>
Acked-by on v1 7/8
#24 lore raw

Re: [PATCH 7/8] libata: use the enlarged capacity after late HPA unlock

In reply to Tejun Heo

From: Tejun Heo <[email protected]>
Date: Sat, 15 May 2010 20:09:33 +0200

Quoted 6 lines

After late HPA unlock, libata kept using the original capacity ignoring the new larger native capacity. Enlarging device on the fly doesn't cause any harm. Use the larger native capacity instead. This will enable on-demand HPA unlocking.

author
#25 lore raw

PATCH 8/8 libata: implement on-demand HPA unlocking

In reply to Tejun Heo

Implement ata_scsi_unlock_native_capacity() which will be called through SCSI layer when block layer notices that partitions on a device extend beyond the end of the device. It requests EH to unlock HPA, waits for completion and returns the current device capacity.

This allows libata to unlock HPA on demand instead of having to decide whether to unlock upfront. Unlocking on demand is safer than unlocking by upfront because some BIOSes write private data to the area beyond HPA limit. This was suggested by Ben Hutchings.

---
 drivers/ata/libata-core.c |    1 +
 drivers/ata/libata-scsi.c |   29 +++++++++++++++++++++++++++++
 include/linux/libata.h    |    2 ++
 3 files changed, 32 insertions(+), 0 deletions(-)
drivers/ata/libata-core.c +1 -0
index 9d6e92d..b0e379d 100644
@@ -6797,6 +6797,7 @@ EXPORT_SYMBOL_GPL(ata_dummy_port_info);
 EXPORT_SYMBOL_GPL(ata_link_next);
 EXPORT_SYMBOL_GPL(ata_dev_next);
 EXPORT_SYMBOL_GPL(ata_std_bios_param);
+EXPORT_SYMBOL_GPL(ata_scsi_unlock_native_capacity);
 EXPORT_SYMBOL_GPL(ata_host_init);
 EXPORT_SYMBOL_GPL(ata_host_alloc);
 EXPORT_SYMBOL_GPL(ata_host_alloc_pinfo);
drivers/ata/libata-scsi.c +29 -0
index 0088cde..fc51531 100644
@@ -415,6 +415,35 @@ int ata_std_bios_param(struct scsi_device *sdev, struct block_device *bdev,
 }
 
 /**
+ *	ata_scsi_unlock_native_capacity - unlock native capacity
+ *	@sdev: SCSI device to adjust device capacity for
+ *
+ *	This function is called if a partition on @sdev extends beyond
+ *	the end of the device.  It requests EH to unlock HPA.
+ *
+ *	LOCKING:
+ *	Defined by the SCSI layer.  Might sleep.
+ */
+void ata_scsi_unlock_native_capacity(struct scsi_device *sdev)
+{
+	struct ata_port *ap = ata_shost_to_port(sdev->host);
+	struct ata_device *dev;
+	unsigned long flags;
+
+	spin_lock_irqsave(ap->lock, flags);
+
+	dev = ata_scsi_find_dev(ap, sdev);
+	if (dev && dev->n_sectors < dev->n_native_sectors) {
+		dev->flags |= ATA_DFLAG_UNLOCK_HPA;
+		dev->link->eh_info.action |= ATA_EH_RESET;
+		ata_port_schedule_eh(ap);
+	}
+
+	spin_unlock_irqrestore(ap->lock, flags);
+	ata_port_wait_eh(ap);
+}
+
+/**
  *	ata_get_identity - Handler for HDIO_GET_IDENTITY ioctl
  *	@ap: target port
  *	@sdev: SCSI device to get identify data for
include/linux/libata.h +2 -0
index 242eb26..ab7d6de 100644
@@ -1027,6 +1027,7 @@ extern void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd,
 extern int ata_std_bios_param(struct scsi_device *sdev,
 			      struct block_device *bdev,
 			      sector_t capacity, int geom[]);
+extern void ata_scsi_unlock_native_capacity(struct scsi_device *sdev);
 extern int ata_scsi_slave_config(struct scsi_device *sdev);
 extern void ata_scsi_slave_destroy(struct scsi_device *sdev);
 extern int ata_scsi_change_queue_depth(struct scsi_device *sdev,
@@ -1181,6 +1182,7 @@ extern struct device_attribute *ata_common_sdev_attrs[];
 	.slave_configure	= ata_scsi_slave_config,	\
 	.slave_destroy		= ata_scsi_slave_destroy,	\
 	.bios_param		= ata_std_bios_param,		\
+	.unlock_native_capacity	= ata_scsi_unlock_native_capacity, \
 	.sdev_attrs		= ata_common_sdev_attrs
 
 #define ATA_NCQ_SHT(drv_name)					\
Signature · 1 line
1.6.4.2
Acked-by on v1 8/8
#26 lore raw

Re: [PATCH 8/8] libata: implement on-demand HPA unlocking

Quoted 5 lines · Tejun Heo

Implement ata_scsi_unlock_native_capacity() which will be called through SCSI layer when block layer notices that partitions on a device extend beyond the end of the device. It requests EH to unlock HPA, waits for completion and returns the current device capacity.

Quoted 7 lines

This allows libata to unlock HPA on demand instead of having to decide whether to unlock upfront. Unlocking on demand is safer than unlocking by upfront because some BIOSes write private data to the area beyond HPA limit. This was suggested by Ben Hutchings.

Acked-by on v1 8/8
#27 lore raw

Re: [PATCH 8/8] libata: implement on-demand HPA unlocking

In reply to Tejun Heo

From: Tejun Heo <[email protected]>
Date: Sat, 15 May 2010 20:09:34 +0200

Quoted 5 lines

Implement ata_scsi_unlock_native_capacity() which will be called through SCSI layer when block layer notices that partitions on a device extend beyond the end of the device. It requests EH to unlock HPA, waits for completion and returns the current device capacity.

Quoted 7 lines

This allows libata to unlock HPA on demand instead of having to decide whether to unlock upfront. Unlocking on demand is safer than unlocking by upfront because some BIOSes write private data to the area beyond HPA limit. This was suggested by Ben Hutchings.

#28 lore raw
In reply to Tejun Heo
Quoted 5 lines · Tejun Heo

Hello, all.

This is the evolved version of the implement-set_capacity patchset[L] and contains the following patches.

Quoted 8 lines

0001-buffer-make-invalidate_bdev-drain-all-percpu-LRU-add.patch 0002-block-restart-partition-scan-after-resizing-a-device.patch 0003-block-ide-simplify-bdops-set_capacity-to-unlock_nati.patch 0004-block-use-struct-parsed_partitions-state-universally.patch 0005-block-improve-automatic-native-capacity-unlocking.patch 0006-SCSI-implement-sd_unlock_native_capacity.patch 0007-libata-use-the-enlarged-capacity-after-late-HPA-unlo.patch 0008-libata-implement-on-demand-HPA-unlocking.patch

Other than block part, everything is acked, so how do we route this? 0001-0005 through block tree and 0006-0008 through libata tree seem the easiest unless someone objects. Jens, can you please review 0001-0005 and take them into block tree if it seems okay?

Thanks.

Signature · 1 line
tejun
#29 lore raw
Quoted 15 lines · Tejun Heo
Quoted 5 lines · Tejun Heo

Hello, all.

This is the evolved version of the implement-set_capacity patchset[L] and contains the following patches.

Quoted 8 lines

0001-buffer-make-invalidate_bdev-drain-all-percpu-LRU-add.patch 0002-block-restart-partition-scan-after-resizing-a-device.patch 0003-block-ide-simplify-bdops-set_capacity-to-unlock_nati.patch 0004-block-use-struct-parsed_partitions-state-universally.patch 0005-block-improve-automatic-native-capacity-unlocking.patch 0006-SCSI-implement-sd_unlock_native_capacity.patch 0007-libata-use-the-enlarged-capacity-after-late-HPA-unlo.patch 0008-libata-implement-on-demand-HPA-unlocking.patch

Quoted 4 lines

Other than block part, everything is acked, so how do we route this? 0001-0005 through block tree and 0006-0008 through libata tree seem the easiest unless someone objects. Jens, can you please review 0001-0005 and take them into block tree if it seems okay?

Yeah will do.

Signature · 1 line
Jens Axboe
#30 lore raw
In reply to Tejun Heo
Quoted 8 lines · Tejun Heo

0001-buffer-make-invalidate_bdev-drain-all-percpu-LRU-add.patch 0002-block-restart-partition-scan-after-resizing-a-device.patch 0003-block-ide-simplify-bdops-set_capacity-to-unlock_nati.patch 0004-block-use-struct-parsed_partitions-state-universally.patch 0005-block-improve-automatic-native-capacity-unlocking.patch 0006-SCSI-implement-sd_unlock_native_capacity.patch 0007-libata-use-the-enlarged-capacity-after-late-HPA-unlo.patch 0008-libata-implement-on-demand-HPA-unlocking.patch

Jeff, now 0001-0005 are in mainline. Can you please apply 0006-0008?

Thanks.

Signature · 1 line
tejun