SCSI: implement sd_unlock_native_capacity()

Implement sd_unlock_native_capacity() method which calls into
hostt->unlock_native_capacity() if implemented. This will be invoked
by block layer if partitions extend beyond the end of the device and
can be used to implement, for example, on-demand ATA host protected
area unlocking.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Jeff Garzik <jgarzik@redhat.com>

authored by Tejun Heo and committed by Jeff Garzik 72ec24bd ed4e2f80

+30
+22
drivers/scsi/sd.c
··· 97 #endif 98 99 static int sd_revalidate_disk(struct gendisk *); 100 static int sd_probe(struct device *); 101 static int sd_remove(struct device *); 102 static void sd_shutdown(struct device *); ··· 1102 #endif 1103 .media_changed = sd_media_changed, 1104 .revalidate_disk = sd_revalidate_disk, 1105 }; 1106 1107 static unsigned int sd_completed_bytes(struct scsi_cmnd *scmd) ··· 2120 2121 out: 2122 return 0; 2123 } 2124 2125 /**
··· 97 #endif 98 99 static int sd_revalidate_disk(struct gendisk *); 100 + static void sd_unlock_native_capacity(struct gendisk *disk); 101 static int sd_probe(struct device *); 102 static int sd_remove(struct device *); 103 static void sd_shutdown(struct device *); ··· 1101 #endif 1102 .media_changed = sd_media_changed, 1103 .revalidate_disk = sd_revalidate_disk, 1104 + .unlock_native_capacity = sd_unlock_native_capacity, 1105 }; 1106 1107 static unsigned int sd_completed_bytes(struct scsi_cmnd *scmd) ··· 2118 2119 out: 2120 return 0; 2121 + } 2122 + 2123 + /** 2124 + * sd_unlock_native_capacity - unlock native capacity 2125 + * @disk: struct gendisk to set capacity for 2126 + * 2127 + * Block layer calls this function if it detects that partitions 2128 + * on @disk reach beyond the end of the device. If the SCSI host 2129 + * implements ->unlock_native_capacity() method, it's invoked to 2130 + * give it a chance to adjust the device capacity. 2131 + * 2132 + * CONTEXT: 2133 + * Defined by block layer. Might sleep. 2134 + */ 2135 + static void sd_unlock_native_capacity(struct gendisk *disk) 2136 + { 2137 + struct scsi_device *sdev = scsi_disk(disk)->device; 2138 + 2139 + if (sdev->host->hostt->unlock_native_capacity) 2140 + sdev->host->hostt->unlock_native_capacity(sdev); 2141 } 2142 2143 /**
+8
include/scsi/scsi_host.h
··· 327 sector_t, int []); 328 329 /* 330 * Can be used to export driver statistics and other infos to the 331 * world outside the kernel ie. userspace and it also provides an 332 * interface to feed the driver with information.
··· 327 sector_t, int []); 328 329 /* 330 + * This function is called when one or more partitions on the 331 + * device reach beyond the end of the device. 332 + * 333 + * Status: OPTIONAL 334 + */ 335 + void (*unlock_native_capacity)(struct scsi_device *); 336 + 337 + /* 338 * Can be used to export driver statistics and other infos to the 339 * world outside the kernel ie. userspace and it also provides an 340 * interface to feed the driver with information.