aboutsummaryrefslogtreecommitdiffstats
path: root/fs/partitions
diff options
context:
space:
mode:
Diffstat (limited to 'fs/partitions')
-rw-r--r--fs/partitions/check.c79
1 files changed, 42 insertions, 37 deletions
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 0d4b7f28f13f..ac0df3acdcda 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -309,7 +309,7 @@ static inline void disk_sysfs_add_subdirs(struct gendisk *disk)
309{ 309{
310 struct kobject *k; 310 struct kobject *k;
311 311
312 k = kobject_get(&disk->dev.kobj); 312 k = kobject_get(&disk_to_dev(disk)->kobj);
313 disk->holder_dir = kobject_create_and_add("holders", k); 313 disk->holder_dir = kobject_create_and_add("holders", k);
314 disk->slave_dir = kobject_create_and_add("slaves", k); 314 disk->slave_dir = kobject_create_and_add("slaves", k);
315 kobject_put(k); 315 kobject_put(k);
@@ -322,7 +322,7 @@ static void delete_partition_rcu_cb(struct rcu_head *head)
322 part->start_sect = 0; 322 part->start_sect = 0;
323 part->nr_sects = 0; 323 part->nr_sects = 0;
324 part_stat_set_all(part, 0); 324 part_stat_set_all(part, 0);
325 put_device(&part->dev); 325 put_device(part_to_dev(part));
326} 326}
327 327
328void delete_partition(struct gendisk *disk, int partno) 328void delete_partition(struct gendisk *disk, int partno)
@@ -336,7 +336,7 @@ void delete_partition(struct gendisk *disk, int partno)
336 blk_free_devt(part_devt(part)); 336 blk_free_devt(part_devt(part));
337 rcu_assign_pointer(disk->__part[partno-1], NULL); 337 rcu_assign_pointer(disk->__part[partno-1], NULL);
338 kobject_put(part->holder_dir); 338 kobject_put(part->holder_dir);
339 device_del(&part->dev); 339 device_del(part_to_dev(part));
340 340
341 call_rcu(&part->rcu_head, delete_partition_rcu_cb); 341 call_rcu(&part->rcu_head, delete_partition_rcu_cb);
342} 342}
@@ -354,6 +354,9 @@ int add_partition(struct gendisk *disk, int partno,
354{ 354{
355 struct hd_struct *p; 355 struct hd_struct *p;
356 dev_t devt = MKDEV(0, 0); 356 dev_t devt = MKDEV(0, 0);
357 struct device *ddev = disk_to_dev(disk);
358 struct device *pdev;
359 const char *dname;
357 int err; 360 int err;
358 361
359 if (disk->__part[partno - 1]) 362 if (disk->__part[partno - 1])
@@ -367,42 +370,43 @@ int add_partition(struct gendisk *disk, int partno,
367 err = -ENOMEM; 370 err = -ENOMEM;
368 goto out_free; 371 goto out_free;
369 } 372 }
373 pdev = part_to_dev(p);
374
370 p->start_sect = start; 375 p->start_sect = start;
371 p->nr_sects = len; 376 p->nr_sects = len;
372 p->partno = partno; 377 p->partno = partno;
373 p->policy = disk->policy; 378 p->policy = disk->policy;
374 379
375 if (isdigit(disk->dev.bus_id[strlen(disk->dev.bus_id)-1])) 380 dname = dev_name(ddev);
376 snprintf(p->dev.bus_id, BUS_ID_SIZE, 381 if (isdigit(dname[strlen(dname) - 1]))
377 "%sp%d", disk->dev.bus_id, partno); 382 snprintf(pdev->bus_id, BUS_ID_SIZE, "%sp%d", dname, partno);
378 else 383 else
379 snprintf(p->dev.bus_id, BUS_ID_SIZE, 384 snprintf(pdev->bus_id, BUS_ID_SIZE, "%s%d", dname, partno);
380 "%s%d", disk->dev.bus_id, partno);
381 385
382 device_initialize(&p->dev); 386 device_initialize(pdev);
383 p->dev.class = &block_class; 387 pdev->class = &block_class;
384 p->dev.type = &part_type; 388 pdev->type = &part_type;
385 p->dev.parent = &disk->dev; 389 pdev->parent = ddev;
386 390
387 err = blk_alloc_devt(p, &devt); 391 err = blk_alloc_devt(p, &devt);
388 if (err) 392 if (err)
389 goto out_put; 393 goto out_free;
390 p->dev.devt = devt; 394 pdev->devt = devt;
391 395
392 /* delay uevent until 'holders' subdir is created */ 396 /* delay uevent until 'holders' subdir is created */
393 p->dev.uevent_suppress = 1; 397 pdev->uevent_suppress = 1;
394 err = device_add(&p->dev); 398 err = device_add(pdev);
395 if (err) 399 if (err)
396 goto out_put; 400 goto out_put;
397 401
398 err = -ENOMEM; 402 err = -ENOMEM;
399 p->holder_dir = kobject_create_and_add("holders", &p->dev.kobj); 403 p->holder_dir = kobject_create_and_add("holders", &pdev->kobj);
400 if (!p->holder_dir) 404 if (!p->holder_dir)
401 goto out_del; 405 goto out_del;
402 406
403 p->dev.uevent_suppress = 0; 407 pdev->uevent_suppress = 0;
404 if (flags & ADDPART_FLAG_WHOLEDISK) { 408 if (flags & ADDPART_FLAG_WHOLEDISK) {
405 err = device_create_file(&p->dev, &dev_attr_whole_disk); 409 err = device_create_file(pdev, &dev_attr_whole_disk);
406 if (err) 410 if (err)
407 goto out_del; 411 goto out_del;
408 } 412 }
@@ -412,8 +416,8 @@ int add_partition(struct gendisk *disk, int partno,
412 rcu_assign_pointer(disk->__part[partno - 1], p); 416 rcu_assign_pointer(disk->__part[partno - 1], p);
413 417
414 /* suppress uevent if the disk supresses it */ 418 /* suppress uevent if the disk supresses it */
415 if (!disk->dev.uevent_suppress) 419 if (!ddev->uevent_suppress)
416 kobject_uevent(&p->dev.kobj, KOBJ_ADD); 420 kobject_uevent(&pdev->kobj, KOBJ_ADD);
417 421
418 return 0; 422 return 0;
419 423
@@ -422,9 +426,9 @@ out_free:
422 return err; 426 return err;
423out_del: 427out_del:
424 kobject_put(p->holder_dir); 428 kobject_put(p->holder_dir);
425 device_del(&p->dev); 429 device_del(pdev);
426out_put: 430out_put:
427 put_device(&p->dev); 431 put_device(pdev);
428 blk_free_devt(devt); 432 blk_free_devt(devt);
429 return err; 433 return err;
430} 434}
@@ -432,30 +436,31 @@ out_put:
432/* Not exported, helper to add_disk(). */ 436/* Not exported, helper to add_disk(). */
433void register_disk(struct gendisk *disk) 437void register_disk(struct gendisk *disk)
434{ 438{
439 struct device *ddev = disk_to_dev(disk);
435 struct block_device *bdev; 440 struct block_device *bdev;
436 struct disk_part_iter piter; 441 struct disk_part_iter piter;
437 struct hd_struct *part; 442 struct hd_struct *part;
438 char *s; 443 char *s;
439 int err; 444 int err;
440 445
441 disk->dev.parent = disk->driverfs_dev; 446 ddev->parent = disk->driverfs_dev;
442 447
443 strlcpy(disk->dev.bus_id, disk->disk_name, BUS_ID_SIZE); 448 strlcpy(ddev->bus_id, disk->disk_name, BUS_ID_SIZE);
444 /* ewww... some of these buggers have / in the name... */ 449 /* ewww... some of these buggers have / in the name... */
445 s = strchr(disk->dev.bus_id, '/'); 450 s = strchr(ddev->bus_id, '/');
446 if (s) 451 if (s)
447 *s = '!'; 452 *s = '!';
448 453
449 /* delay uevents, until we scanned partition table */ 454 /* delay uevents, until we scanned partition table */
450 disk->dev.uevent_suppress = 1; 455 ddev->uevent_suppress = 1;
451 456
452 if (device_add(&disk->dev)) 457 if (device_add(ddev))
453 return; 458 return;
454#ifndef CONFIG_SYSFS_DEPRECATED 459#ifndef CONFIG_SYSFS_DEPRECATED
455 err = sysfs_create_link(block_depr, &disk->dev.kobj, 460 err = sysfs_create_link(block_depr, &ddev->kobj,
456 kobject_name(&disk->dev.kobj)); 461 kobject_name(&ddev->kobj));
457 if (err) { 462 if (err) {
458 device_del(&disk->dev); 463 device_del(ddev);
459 return; 464 return;
460 } 465 }
461#endif 466#endif
@@ -481,13 +486,13 @@ void register_disk(struct gendisk *disk)
481 486
482exit: 487exit:
483 /* announce disk after possible partitions are created */ 488 /* announce disk after possible partitions are created */
484 disk->dev.uevent_suppress = 0; 489 ddev->uevent_suppress = 0;
485 kobject_uevent(&disk->dev.kobj, KOBJ_ADD); 490 kobject_uevent(&ddev->kobj, KOBJ_ADD);
486 491
487 /* announce possible partitions */ 492 /* announce possible partitions */
488 disk_part_iter_init(&piter, disk, 0); 493 disk_part_iter_init(&piter, disk, 0);
489 while ((part = disk_part_iter_next(&piter))) 494 while ((part = disk_part_iter_next(&piter)))
490 kobject_uevent(&part->dev.kobj, KOBJ_ADD); 495 kobject_uevent(&part_to_dev(part)->kobj, KOBJ_ADD);
491 disk_part_iter_exit(&piter); 496 disk_part_iter_exit(&piter);
492} 497}
493 498
@@ -518,7 +523,7 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
518 return -EIO; 523 return -EIO;
519 524
520 /* tell userspace that the media / partition table may have changed */ 525 /* tell userspace that the media / partition table may have changed */
521 kobject_uevent(&disk->dev.kobj, KOBJ_CHANGE); 526 kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
522 527
523 for (p = 1; p < state->limit; p++) { 528 for (p = 1; p < state->limit; p++) {
524 sector_t size = state->parts[p].size; 529 sector_t size = state->parts[p].size;
@@ -591,7 +596,7 @@ void del_gendisk(struct gendisk *disk)
591 kobject_put(disk->slave_dir); 596 kobject_put(disk->slave_dir);
592 disk->driverfs_dev = NULL; 597 disk->driverfs_dev = NULL;
593#ifndef CONFIG_SYSFS_DEPRECATED 598#ifndef CONFIG_SYSFS_DEPRECATED
594 sysfs_remove_link(block_depr, disk->dev.bus_id); 599 sysfs_remove_link(block_depr, dev_name(disk_to_dev(disk)));
595#endif 600#endif
596 device_del(&disk->dev); 601 device_del(disk_to_dev(disk));
597} 602}