Currently there is no convenient way how to get the information from userspace whether or not the block device supports discard other than try to call BLKDISCARD ioctl and check the result, which is not really good way to do it. We already have BLKDISCARDZEROES ioctl and /sys/block/sda/queue/discard_zeroes_data to tell whether subsequent reads after discard returns all zeroes. This commit adds at least sysfs interface /sys/block/sda/queue/discard_support to tell whether device support discard. Signed-off-by: Lukas Czerner <lczerner@xxxxxxxxxx> Cc: Jens Axboe <jaxboe@xxxxxxxxxxxx> Cc: Jeff Moyer <jmoyer@xxxxxxxxxx> --- block/blk-sysfs.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index bd23631..96f1cca 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -160,6 +160,11 @@ static ssize_t queue_discard_zeroes_data_show(struct request_queue *q, char *pag return queue_var_show(queue_discard_zeroes_data(q), page); } +static ssize_t queue_discard_support_show(struct request_queue *q, char *page) +{ + return queue_var_show(blk_queue_discard(q), page); +} + static ssize_t queue_max_sectors_store(struct request_queue *q, const char *page, size_t count) { @@ -349,6 +354,11 @@ static struct queue_sysfs_entry queue_discard_zeroes_data_entry = { .show = queue_discard_zeroes_data_show, }; +static struct queue_sysfs_entry queue_discard_support_entry = { + .attr = {.name = "discard_support", .mode = S_IRUGO }, + .show = queue_discard_support_show, +}; + static struct queue_sysfs_entry queue_nonrot_entry = { .attr = {.name = "rotational", .mode = S_IRUGO | S_IWUSR }, .show = queue_show_nonrot, @@ -396,6 +406,7 @@ static struct attribute *default_attrs[] = { &queue_discard_granularity_entry.attr, &queue_discard_max_entry.attr, &queue_discard_zeroes_data_entry.attr, + &queue_discard_support_entry.attr, &queue_nonrot_entry.attr, &queue_nomerges_entry.attr, &queue_rq_affinity_entry.attr, -- 1.7.4.4 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html