From: Tejun Heo <tj@kernel.org> To: jeff@garzik.org, linux-ide@vger.kernel.org, jens.axboe@oracle.com, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, James.Bottomley@HansenPartnership.com, Mauelshagen@RedHat.c Cc: Tejun Heo <tj@kernel.org> Subject: [PATCH 1/3] block: add alt_size Date: Sat, 9 May 2009 09:13:20 +0900 [thread overview] Message-ID: <1241828002-12742-2-git-send-email-tj@kernel.org> (raw) In-Reply-To: <1241828002-12742-1-git-send-email-tj@kernel.org> ATA disks have two sizes - the user visible size and native size. The user visible size is usually used by the BIOS to hide certain area (e.g. recovery partition) or trim size for various reasons. IDE and libata can unlock these HPA areas and IDE does so by default and libata depending on kernel parameters (some distros default to unlock to maintain compatibility with IDE). This usually doesn't matter but certain tools need to know what BIOS wants the disk to look like. For example, certain BIOS RAID formats put the metadata at the end of the disk where the 'end' is the trimmed size, so without knowing the BIOS size, dmraid can't work reliably if HPA is unlocked. This patch adds alt_size to genhd and exports it via sysfs. alt_size is always smaller than the regular size. Being a hint, alt_size can also be set from userland by writing to the sysfs node mostly for debugging and testing. Because initialization order isn't enforced, the alt_size < size limitation is applied while getting the attribute. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Jens Axboe <jens.axboe@oracle.com> Cc: Dan Williams <dan.j.williams@gmail.com> Cc: Jeff Garzik <jeff@garzik.org> Cc: James Bottomley <James.Bottomley@HansenPartnership.com> --- block/genhd.c | 26 ++++++++++++++++++++++++++ include/linux/genhd.h | 13 ++++++++++++- 2 files changed, 38 insertions(+), 1 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index 1a4916e..e6a3fdb 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -844,6 +844,29 @@ static ssize_t disk_ro_show(struct device *dev, return sprintf(buf, "%d\n", get_disk_ro(disk) ? 1 : 0); } +static ssize_t disk_alt_size_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct gendisk *disk = dev_to_disk(dev); + + return sprintf(buf, "%llu\n", + (unsigned long long)get_alt_capacity(disk)); +} + +static ssize_t disk_alt_size_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct gendisk *disk = dev_to_disk(dev); + sector_t new_size = simple_strtoull(buf, NULL, 0); + + set_alt_capacity(disk, new_size); + + if (get_alt_capacity(disk) == new_size) + return count; + return -EINVAL; +} + static ssize_t disk_capability_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -857,6 +880,8 @@ static DEVICE_ATTR(ext_range, S_IRUGO, disk_ext_range_show, NULL); static DEVICE_ATTR(removable, S_IRUGO, disk_removable_show, NULL); static DEVICE_ATTR(ro, S_IRUGO, disk_ro_show, NULL); static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL); +static DEVICE_ATTR(alt_size, S_IRUGO | S_IWUSR, disk_alt_size_show, + disk_alt_size_store); static DEVICE_ATTR(capability, S_IRUGO, disk_capability_show, NULL); static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL); #ifdef CONFIG_FAIL_MAKE_REQUEST @@ -875,6 +900,7 @@ static struct attribute *disk_attrs[] = { &dev_attr_removable.attr, &dev_attr_ro.attr, &dev_attr_size.attr, + &dev_attr_alt_size.attr, &dev_attr_capability.attr, &dev_attr_stat.attr, #ifdef CONFIG_FAIL_MAKE_REQUEST diff --git a/include/linux/genhd.h b/include/linux/genhd.h index a1a28ca..a83e4e6 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -159,7 +159,8 @@ struct gendisk { struct timer_rand_state *random; - atomic_t sync_io; /* RAID */ + sector_t alt_nr_sects; /* alt sects, should be <= part0.sects */ + atomic_t sync_io; /* RAID */ struct work_struct async_notify; #ifdef CONFIG_BLK_DEV_INTEGRITY struct blk_integrity *integrity; @@ -364,10 +365,20 @@ static inline sector_t get_capacity(struct gendisk *disk) { return disk->part0.nr_sects; } +static inline sector_t get_alt_capacity(struct gendisk *disk) +{ + if (disk->alt_nr_sects && disk->alt_nr_sects < disk->part0.nr_sects) + return disk->alt_nr_sects; + return 0; +} static inline void set_capacity(struct gendisk *disk, sector_t size) { disk->part0.nr_sects = size; } +static inline void set_alt_capacity(struct gendisk *disk, sector_t size) +{ + disk->alt_nr_sects = size; +} #ifdef CONFIG_SOLARIS_X86_PARTITION -- 1.6.0.2
WARNING: multiple messages have this Message-ID (diff)
From: Tejun Heo <tj@kernel.org> To: jeff@garzik.org, linux-ide@vger.kernel.org, jens.axboe@oracle.com, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, James.Bottomley@HansenPartnership.com, Mauelshagen@RedHat.com, dm-devel@RedHat.com, dan.j.williams@gmail.com Cc: Tejun Heo <tj@kernel.org> Subject: [PATCH 1/3] block: add alt_size Date: Sat, 9 May 2009 09:13:20 +0900 [thread overview] Message-ID: <1241828002-12742-2-git-send-email-tj@kernel.org> (raw) In-Reply-To: <1241828002-12742-1-git-send-email-tj@kernel.org> ATA disks have two sizes - the user visible size and native size. The user visible size is usually used by the BIOS to hide certain area (e.g. recovery partition) or trim size for various reasons. IDE and libata can unlock these HPA areas and IDE does so by default and libata depending on kernel parameters (some distros default to unlock to maintain compatibility with IDE). This usually doesn't matter but certain tools need to know what BIOS wants the disk to look like. For example, certain BIOS RAID formats put the metadata at the end of the disk where the 'end' is the trimmed size, so without knowing the BIOS size, dmraid can't work reliably if HPA is unlocked. This patch adds alt_size to genhd and exports it via sysfs. alt_size is always smaller than the regular size. Being a hint, alt_size can also be set from userland by writing to the sysfs node mostly for debugging and testing. Because initialization order isn't enforced, the alt_size < size limitation is applied while getting the attribute. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Jens Axboe <jens.axboe@oracle.com> Cc: Dan Williams <dan.j.williams@gmail.com> Cc: Jeff Garzik <jeff@garzik.org> Cc: James Bottomley <James.Bottomley@HansenPartnership.com> --- block/genhd.c | 26 ++++++++++++++++++++++++++ include/linux/genhd.h | 13 ++++++++++++- 2 files changed, 38 insertions(+), 1 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index 1a4916e..e6a3fdb 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -844,6 +844,29 @@ static ssize_t disk_ro_show(struct device *dev, return sprintf(buf, "%d\n", get_disk_ro(disk) ? 1 : 0); } +static ssize_t disk_alt_size_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct gendisk *disk = dev_to_disk(dev); + + return sprintf(buf, "%llu\n", + (unsigned long long)get_alt_capacity(disk)); +} + +static ssize_t disk_alt_size_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct gendisk *disk = dev_to_disk(dev); + sector_t new_size = simple_strtoull(buf, NULL, 0); + + set_alt_capacity(disk, new_size); + + if (get_alt_capacity(disk) == new_size) + return count; + return -EINVAL; +} + static ssize_t disk_capability_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -857,6 +880,8 @@ static DEVICE_ATTR(ext_range, S_IRUGO, disk_ext_range_show, NULL); static DEVICE_ATTR(removable, S_IRUGO, disk_removable_show, NULL); static DEVICE_ATTR(ro, S_IRUGO, disk_ro_show, NULL); static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL); +static DEVICE_ATTR(alt_size, S_IRUGO | S_IWUSR, disk_alt_size_show, + disk_alt_size_store); static DEVICE_ATTR(capability, S_IRUGO, disk_capability_show, NULL); static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL); #ifdef CONFIG_FAIL_MAKE_REQUEST @@ -875,6 +900,7 @@ static struct attribute *disk_attrs[] = { &dev_attr_removable.attr, &dev_attr_ro.attr, &dev_attr_size.attr, + &dev_attr_alt_size.attr, &dev_attr_capability.attr, &dev_attr_stat.attr, #ifdef CONFIG_FAIL_MAKE_REQUEST diff --git a/include/linux/genhd.h b/include/linux/genhd.h index a1a28ca..a83e4e6 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -159,7 +159,8 @@ struct gendisk { struct timer_rand_state *random; - atomic_t sync_io; /* RAID */ + sector_t alt_nr_sects; /* alt sects, should be <= part0.sects */ + atomic_t sync_io; /* RAID */ struct work_struct async_notify; #ifdef CONFIG_BLK_DEV_INTEGRITY struct blk_integrity *integrity; @@ -364,10 +365,20 @@ static inline sector_t get_capacity(struct gendisk *disk) { return disk->part0.nr_sects; } +static inline sector_t get_alt_capacity(struct gendisk *disk) +{ + if (disk->alt_nr_sects && disk->alt_nr_sects < disk->part0.nr_sects) + return disk->alt_nr_sects; + return 0; +} static inline void set_capacity(struct gendisk *disk, sector_t size) { disk->part0.nr_sects = size; } +static inline void set_alt_capacity(struct gendisk *disk, sector_t size) +{ + disk->alt_nr_sects = size; +} #ifdef CONFIG_SOLARIS_X86_PARTITION -- 1.6.0.2
next prev parent reply other threads:[~2009-05-09 0:13 UTC|newest] Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top 2009-05-09 0:13 [GIT PATCH] block,scsi,libata: implement alt_size, take#2 Tejun Heo 2009-05-09 0:13 ` Tejun Heo 2009-05-09 0:13 ` Tejun Heo [this message] 2009-05-09 0:13 ` [PATCH 1/3] block: add alt_size Tejun Heo 2009-05-09 13:45 ` Kay Sievers 2009-05-09 13:45 ` Kay Sievers 2009-05-09 14:04 ` Tejun Heo 2009-05-09 14:04 ` Tejun Heo 2009-05-09 16:26 ` Kay Sievers 2009-05-11 13:45 ` [dm-devel] " Konrad Rzeszutek 2009-05-12 0:53 ` Tejun Heo 2009-05-12 0:53 ` [dm-devel] " Tejun Heo 2009-05-09 0:13 ` [PATCH 2/3] scsi: add scsi_device->alt_capacity Tejun Heo 2009-05-09 0:13 ` Tejun Heo 2009-05-09 4:23 ` James Bottomley 2009-05-09 16:09 ` Tejun Heo 2009-05-09 16:09 ` Tejun Heo 2009-05-09 16:23 ` James Bottomley 2009-05-10 1:26 ` Tejun Heo 2009-05-15 19:44 ` ATA ULD (was Re: [PATCH 2/3] scsi: add scsi_device->alt_capacity) Jeff Garzik 2009-05-09 0:13 ` [PATCH 3/3] libata: export HPA size as alt_size Tejun Heo 2009-05-09 0:13 ` Tejun Heo -- strict thread matches above, loose matches on Subject: below -- 2009-02-01 2:55 [PATCHSET] block,scsi,libata: implement alt_size Tejun Heo 2009-02-01 2:55 ` [PATCH 1/3] block: add alt_size Tejun Heo 2009-02-01 2:55 ` 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=1241828002-12742-2-git-send-email-tj@kernel.org \ --to=tj@kernel.org \ --cc=James.Bottomley@HansenPartnership.com \ --cc=Mauelshagen@RedHat.c \ --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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.