Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block,ide: simplify bdops->set_capacity() to ->unlock_native_capacity()

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.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Ben Hutchings <ben@decadent.org.uk>
Cc: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>

authored by

Tejun Heo and committed by
Jens Axboe
c3e33e04 56bca017

+23 -35
+15 -23
drivers/ide/ide-disk.c
··· 407 407 return 0; 408 408 } 409 409 410 - static u64 ide_disk_set_capacity(ide_drive_t *drive, u64 capacity) 410 + static void ide_disk_unlock_native_capacity(ide_drive_t *drive) 411 411 { 412 - u64 set = min(capacity, drive->probed_capacity); 413 412 u16 *id = drive->id; 414 413 int lba48 = ata_id_lba48_enabled(id); 415 414 416 415 if ((drive->dev_flags & IDE_DFLAG_LBA) == 0 || 417 416 ata_id_hpa_enabled(id) == 0) 418 - goto out; 417 + return; 419 418 420 419 /* 421 420 * according to the spec the SET MAX ADDRESS command shall be 422 421 * immediately preceded by a READ NATIVE MAX ADDRESS command 423 422 */ 424 - capacity = ide_disk_hpa_get_native_capacity(drive, lba48); 425 - if (capacity == 0) 426 - goto out; 423 + if (!ide_disk_hpa_get_native_capacity(drive, lba48)) 424 + return; 427 425 428 - set = ide_disk_hpa_set_capacity(drive, set, lba48); 429 - if (set) { 430 - /* needed for ->resume to disable HPA */ 431 - drive->dev_flags |= IDE_DFLAG_NOHPA; 432 - return set; 433 - } 434 - out: 435 - return drive->capacity64; 426 + if (ide_disk_hpa_set_capacity(drive, drive->probed_capacity, lba48)) 427 + drive->dev_flags |= IDE_DFLAG_NOHPA; /* disable HPA on resume */ 436 428 } 437 429 438 430 static void idedisk_prepare_flush(struct request_queue *q, struct request *rq) ··· 775 783 } 776 784 777 785 const struct ide_disk_ops ide_ata_disk_ops = { 778 - .check = ide_disk_check, 779 - .set_capacity = ide_disk_set_capacity, 780 - .get_capacity = ide_disk_get_capacity, 781 - .setup = ide_disk_setup, 782 - .flush = ide_disk_flush, 783 - .init_media = ide_disk_init_media, 784 - .set_doorlock = ide_disk_set_doorlock, 785 - .do_request = ide_do_rw_disk, 786 - .ioctl = ide_disk_ioctl, 786 + .check = ide_disk_check, 787 + .unlock_native_capacity = ide_disk_unlock_native_capacity, 788 + .get_capacity = ide_disk_get_capacity, 789 + .setup = ide_disk_setup, 790 + .flush = ide_disk_flush, 791 + .init_media = ide_disk_init_media, 792 + .set_doorlock = ide_disk_set_doorlock, 793 + .do_request = ide_do_rw_disk, 794 + .ioctl = ide_disk_ioctl, 787 795 };
+4 -7
drivers/ide/ide-gd.c
··· 288 288 return ret; 289 289 } 290 290 291 - static unsigned long long ide_gd_set_capacity(struct gendisk *disk, 292 - unsigned long long capacity) 291 + static void ide_gd_unlock_native_capacity(struct gendisk *disk) 293 292 { 294 293 struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj); 295 294 ide_drive_t *drive = idkp->drive; 296 295 const struct ide_disk_ops *disk_ops = drive->disk_ops; 297 296 298 - if (disk_ops->set_capacity) 299 - return disk_ops->set_capacity(drive, capacity); 300 - 301 - return drive->capacity64; 297 + if (disk_ops->unlock_native_capacity) 298 + disk_ops->unlock_native_capacity(drive); 302 299 } 303 300 304 301 static int ide_gd_revalidate_disk(struct gendisk *disk) ··· 326 329 .locked_ioctl = ide_gd_ioctl, 327 330 .getgeo = ide_gd_getgeo, 328 331 .media_changed = ide_gd_media_changed, 329 - .set_capacity = ide_gd_set_capacity, 332 + .unlock_native_capacity = ide_gd_unlock_native_capacity, 330 333 .revalidate_disk = ide_gd_revalidate_disk 331 334 }; 332 335
+2 -2
fs/partitions/check.c
··· 601 601 "%s: p%d size %llu exceeds device capacity, ", 602 602 disk->disk_name, p, (unsigned long long) size); 603 603 604 - if (bdops->set_capacity && 604 + if (bdops->unlock_native_capacity && 605 605 (disk->flags & GENHD_FL_NATIVE_CAPACITY) == 0) { 606 606 printk(KERN_CONT "enabling native capacity\n"); 607 - bdops->set_capacity(disk, ~0ULL); 607 + bdops->unlock_native_capacity(disk); 608 608 disk->flags |= GENHD_FL_NATIVE_CAPACITY; 609 609 /* free state and restart */ 610 610 kfree(state);
+1 -2
include/linux/blkdev.h
··· 1330 1330 int (*direct_access) (struct block_device *, sector_t, 1331 1331 void **, unsigned long *); 1332 1332 int (*media_changed) (struct gendisk *); 1333 - unsigned long long (*set_capacity) (struct gendisk *, 1334 - unsigned long long); 1333 + void (*unlock_native_capacity) (struct gendisk *); 1335 1334 int (*revalidate_disk) (struct gendisk *); 1336 1335 int (*getgeo)(struct block_device *, struct hd_geometry *); 1337 1336 struct module *owner;
+1 -1
include/linux/ide.h
··· 362 362 struct ide_disk_ops { 363 363 int (*check)(struct ide_drive_s *, const char *); 364 364 int (*get_capacity)(struct ide_drive_s *); 365 - u64 (*set_capacity)(struct ide_drive_s *, u64); 365 + void (*unlock_native_capacity)(struct ide_drive_s *); 366 366 void (*setup)(struct ide_drive_s *); 367 367 void (*flush)(struct ide_drive_s *); 368 368 int (*init_media)(struct ide_drive_s *, struct gendisk *);