13 #include <linux/module.h>
15 #include <linux/slab.h>
17 #include <linux/ctype.h>
19 #include <linux/blktrace_api.h>
23 #ifdef CONFIG_BLK_DEV_MD
70 struct hd_struct *
p = dev_to_part(dev);
72 return sprintf(buf,
"%d\n", p->partno);
78 struct hd_struct *
p = dev_to_part(dev);
80 return sprintf(buf,
"%llu\n",(
unsigned long long)p->start_sect);
86 struct hd_struct *p = dev_to_part(dev);
87 return sprintf(buf,
"%llu\n",(
unsigned long long)part_nr_sects_read(p));
93 struct hd_struct *p = dev_to_part(dev);
94 return sprintf(buf,
"%d\n", p->policy ? 1 : 0);
100 struct hd_struct *p = dev_to_part(dev);
101 return sprintf(buf,
"%llu\n", (
unsigned long long)p->alignment_offset);
104 static ssize_t part_discard_alignment_show(
struct device *dev,
107 struct hd_struct *p = dev_to_part(dev);
108 return sprintf(buf,
"%u\n", p->discard_alignment);
114 struct hd_struct *p = dev_to_part(dev);
117 cpu = part_stat_lock();
121 "%8lu %8lu %8llu %8u "
122 "%8lu %8lu %8llu %8u "
125 part_stat_read(p, ios[
READ]),
126 part_stat_read(p, merges[READ]),
127 (
unsigned long long)part_stat_read(p,
sectors[READ]),
129 part_stat_read(p, ios[
WRITE]),
130 part_stat_read(p, merges[WRITE]),
131 (
unsigned long long)part_stat_read(p,
sectors[WRITE]),
141 struct hd_struct *p = dev_to_part(dev);
147 #ifdef CONFIG_FAIL_MAKE_REQUEST
151 struct hd_struct *p = dev_to_part(dev);
153 return sprintf(buf,
"%d\n", p->make_it_fail);
158 const char *buf,
size_t count)
160 struct hd_struct *p = dev_to_part(dev);
163 if (count > 0 &&
sscanf(buf,
"%d", &i) > 0)
164 p->make_it_fail = (i == 0) ? 0 : 1;
179 #ifdef CONFIG_FAIL_MAKE_REQUEST
184 static struct attribute *part_attrs[] = {
185 &dev_attr_partition.attr,
186 &dev_attr_start.attr,
189 &dev_attr_alignment_offset.attr,
190 &dev_attr_discard_alignment.attr,
192 &dev_attr_inflight.attr,
193 #ifdef CONFIG_FAIL_MAKE_REQUEST
205 #ifdef CONFIG_BLK_DEV_IO_TRACE
206 &blk_trace_attr_group,
211 static void part_release(
struct device *dev)
213 struct hd_struct *p = dev_to_part(dev);
221 .groups = part_attr_groups,
222 .release = part_release,
225 static void delete_partition_rcu_cb(
struct rcu_head *
head)
229 part->start_sect = 0;
231 part_stat_set_all(part, 0);
237 call_rcu(&part->rcu_head, delete_partition_rcu_cb);
242 struct disk_part_tbl *ptbl = disk->part_tbl;
243 struct hd_struct *
part;
245 if (partno >= ptbl->len)
248 part = ptbl->part[partno];
267 whole_disk_show,
NULL);
271 struct partition_meta_info *
info)
275 struct device *ddev = disk_to_dev(disk);
277 struct disk_part_tbl *ptbl;
284 ptbl = disk->part_tbl;
286 if (ptbl->part[partno])
287 return ERR_PTR(-
EBUSY);
291 return ERR_PTR(-
EBUSY);
293 if (!init_part_stats(p)) {
299 pdev = part_to_dev(p);
301 p->start_sect =
start;
302 p->alignment_offset =
303 queue_limit_alignment_offset(&disk->queue->limits, start);
304 p->discard_alignment =
305 queue_limit_discard_alignment(&disk->queue->limits, start);
308 p->policy = get_disk_ro(disk);
311 struct partition_meta_info *
pinfo = alloc_part_info(disk);
314 memcpy(pinfo, info,
sizeof(*info));
318 dname = dev_name(ddev);
335 dev_set_uevent_suppress(pdev, 1);
345 dev_set_uevent_suppress(pdev, 0);
346 if (flags & ADDPART_FLAG_WHOLEDISK) {
356 if (!dev_get_uevent_suppress(ddev))
378 static bool disk_unlock_native_capacity(
struct gendisk *disk)
380 const struct block_device_operations *bdops = disk->fops;
382 if (bdops->unlock_native_capacity &&
383 !(disk->flags & GENHD_FL_NATIVE_CAPACITY)) {
385 bdops->unlock_native_capacity(disk);
386 disk->flags |= GENHD_FL_NATIVE_CAPACITY;
394 static int drop_partitions(
struct gendisk *disk,
struct block_device *bdev)
396 struct disk_part_iter piter;
397 struct hd_struct *
part;
417 struct hd_struct *
part;
420 if (state && !IS_ERR(state)) {
425 res = drop_partitions(disk, bdev);
429 if (disk->fops->revalidate_disk)
430 disk->fops->revalidate_disk(disk);
441 if (PTR_ERR(state) == -
ENOSPC) {
444 if (disk_unlock_native_capacity(disk))
456 "%s: partition table partially beyond EOD, ",
458 if (disk_unlock_native_capacity(disk))
469 for (p = 1, highest = 0; p < state->
limit; p++)
470 if (state->
parts[p].size)
476 for (p = 1; p < state->
limit; p++) {
478 struct partition_meta_info *
info =
NULL;
480 size = state->
parts[
p].size;
484 from = state->
parts[
p].from;
485 if (from >= get_capacity(disk)) {
487 "%s: p%d start %llu is beyond EOD, ",
488 disk->disk_name, p, (
unsigned long long) from);
489 if (disk_unlock_native_capacity(disk))
494 if (from + size > get_capacity(disk)) {
496 "%s: p%d size %llu extends beyond EOD, ",
497 disk->disk_name, p, (
unsigned long long) size);
499 if (disk_unlock_native_capacity(disk)) {
509 size = get_capacity(disk) -
from;
513 if (state->
parts[p].has_info)
514 info = &state->
parts[
p].info;
516 state->
parts[p].flags,
517 &state->
parts[p].info);
520 disk->disk_name, p, -PTR_ERR(part));
523 #ifdef CONFIG_BLK_DEV_MD
524 if (state->
parts[p].flags & ADDPART_FLAG_RAID)
539 res = drop_partitions(disk, bdev);
543 set_capacity(disk, 0);