Skip to content

Commit

Permalink
SCSI: implement sd_unlock_native_capacity()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Tejun Heo authored and Jeff Garzik committed Jun 2, 2010
1 parent ed4e2f8 commit 72ec24b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
22 changes: 22 additions & 0 deletions drivers/scsi/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_RBC);
#endif

static int sd_revalidate_disk(struct gendisk *);
static void sd_unlock_native_capacity(struct gendisk *disk);
static int sd_probe(struct device *);
static int sd_remove(struct device *);
static void sd_shutdown(struct device *);
Expand Down Expand Up @@ -1101,6 +1102,7 @@ static const struct block_device_operations sd_fops = {
#endif
.media_changed = sd_media_changed,
.revalidate_disk = sd_revalidate_disk,
.unlock_native_capacity = sd_unlock_native_capacity,
};

static unsigned int sd_completed_bytes(struct scsi_cmnd *scmd)
Expand Down Expand Up @@ -2120,6 +2122,26 @@ static int sd_revalidate_disk(struct gendisk *disk)
return 0;
}

/**
* sd_unlock_native_capacity - unlock native capacity
* @disk: struct gendisk to set capacity for
*
* Block layer calls this function if it detects that partitions
* on @disk reach beyond the end of the device. If the SCSI host
* implements ->unlock_native_capacity() method, it's invoked to
* give it a chance to adjust the device capacity.
*
* CONTEXT:
* Defined by block layer. Might sleep.
*/
static void sd_unlock_native_capacity(struct gendisk *disk)
{
struct scsi_device *sdev = scsi_disk(disk)->device;

if (sdev->host->hostt->unlock_native_capacity)
sdev->host->hostt->unlock_native_capacity(sdev);
}

/**
* sd_format_disk_name - format disk name
* @prefix: name prefix - ie. "sd" for SCSI disks
Expand Down
8 changes: 8 additions & 0 deletions include/scsi/scsi_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,14 @@ struct scsi_host_template {
int (* bios_param)(struct scsi_device *, struct block_device *,
sector_t, int []);

/*
* This function is called when one or more partitions on the
* device reach beyond the end of the device.
*
* Status: OPTIONAL
*/
void (*unlock_native_capacity)(struct scsi_device *);

/*
* Can be used to export driver statistics and other infos to the
* world outside the kernel ie. userspace and it also provides an
Expand Down

0 comments on commit 72ec24b

Please sign in to comment.