From: Tejun Heo <tj@kernel.org>
To: jeff@garzik.org, linux-ide@vger.kernel.org,
jens.axboe@oracle.com, linux-scsi@vger.kernel.org,
James.Bottomley@suse.de, linux-kernel@vger.kernel.org,
ben@decadent.org.uk, davem@davemloft.net, bzolnier@gmail.com
Cc: Tejun Heo <tj@kernel.org>
Subject: [PATCH 5/8] block: improve automatic native capacity unlocking
Date: Sat, 15 May 2010 20:09:31 +0200 [thread overview]
Message-ID: <1273946974-29131-6-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1273946974-29131-1-git-send-email-tj@kernel.org>
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.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Ben Hutchings <ben@decadent.org.uk>
---
fs/partitions/check.c | 69 +++++++++++++++++++++++++++++++++++++++----------
fs/partitions/check.h | 5 +++
2 files changed, 60 insertions(+), 14 deletions(-)
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index a19995c..5dcd4b0 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -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;
}
}
diff --git a/fs/partitions/check.h b/fs/partitions/check.h
index 4b31a97..52f8bd3 100644
--- a/fs/partitions/check.h
+++ b/fs/partitions/check.h
@@ -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);
}
--
1.6.4.2
next prev parent reply other threads:[~2010-05-15 18:10 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-15 18:09 [PATCHSET] block,libata: implement ->unlock_native_capacity() Tejun Heo
2010-05-15 18:09 ` [PATCH 1/8] buffer: make invalidate_bdev() drain all percpu LRU add caches Tejun Heo
2010-05-16 7:11 ` David Miller
2010-05-15 18:09 ` [PATCH 2/8] block: restart partition scan after resizing a device Tejun Heo
2010-05-16 7:15 ` David Miller
2010-05-15 18:09 ` [PATCH 3/8] block,ide: simplify bdops->set_capacity() to ->unlock_native_capacity() Tejun Heo
2010-05-15 18:48 ` Bartlomiej Zolnierkiewicz
2010-05-15 18:58 ` Tejun Heo
2010-05-16 7:15 ` David Miller
2010-05-15 18:09 ` [PATCH 4/8] block: use struct parsed_partitions *state universally in partition check code Tejun Heo
2010-05-16 7:16 ` David Miller
2010-05-15 18:09 ` Tejun Heo [this message]
2010-05-16 7:17 ` [PATCH 5/8] block: improve automatic native capacity unlocking David Miller
2010-05-15 18:09 ` [PATCH 6/8] SCSI: implement sd_unlock_native_capacity() Tejun Heo
2010-05-16 7:18 ` David Miller
2010-05-16 13:39 ` James Bottomley
2010-05-16 15:07 ` Ben Hutchings
2010-05-16 16:00 ` James Bottomley
2010-05-16 17:00 ` Tejun Heo
2010-05-16 19:23 ` James Bottomley
2010-05-17 5:30 ` Tejun Heo
2010-06-02 17:50 ` Jeff Garzik
2010-05-15 18:09 ` [PATCH 7/8] libata: use the enlarged capacity after late HPA unlock Tejun Heo
2010-05-15 19:22 ` Jeff Garzik
2010-05-16 7:18 ` David Miller
2010-05-15 18:09 ` [PATCH 8/8] libata: implement on-demand HPA unlocking Tejun Heo
2010-05-15 19:22 ` Jeff Garzik
2010-05-16 7:19 ` David Miller
2010-05-19 7:05 ` [PATCHSET] block,libata: implement ->unlock_native_capacity() Tejun Heo
2010-05-19 7:08 ` Jens Axboe
2010-06-02 16:37 ` Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1273946974-29131-6-git-send-email-tj@kernel.org \
--to=tj@kernel.org \
--cc=James.Bottomley@suse.de \
--cc=ben@decadent.org.uk \
--cc=bzolnier@gmail.com \
--cc=davem@davemloft.net \
--cc=jeff@garzik.org \
--cc=jens.axboe@oracle.com \
--cc=linux-ide@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).