Hi all,<br><br>I am building an experimental device mapper target which is supposed to receive<br>all TRIM requests (REQ_DISCARD).  Irrespective of whether underlying actual<br>physical block device supports discards or not, my device mapper target should<br>
receive REQ_DISCARD bios.<br><br>
In my target, I set:<br><br>ti->num_discard_requests = 1;<br>ti->discards_supported = 1;<br><br>It looks like setting above 2 parameters did not get me any REQ_DISCARD<br>requests when "fstrim" utility is used.  The operations fails with "Operation not<br>
supported" from kernel funcion:<br><br>blkdev_issue_discard<br><br>because max_discard_sectors for device queue is set to 0.<br><br>max_discard_sectors = min(q->limits.max_discard_sectors, UINT_MAX >> 9);<br>
if (unlikely(!max_discard_sectors))<br>       return -EOPNOTSUPP;<br><br>When I further digged into the device mapper code, I found that<br>dm_calculate_queue_limits function sets the queue limits to default values<br>of 0 for both limits as well as ti_limits and thus blk_stack_limits eventually<br>
sets max_discard_sectors to 0 for the device mapper target.<br><br>So, if my device mapper target does not implement iterate_devices function<br>(used to set max_discard_sectors based on underlying physical device's discard<br>
support) or underlying physical device does not support discards, then there<br>is no way for device mapper target to set max_discard_sectors more than 0<br>to receive REQ_DISCARD commands.<br><br>Is this analysis correct? Or I am missing something?<br>
<br>Appreciate the help / advice.<br><br>Thanks and Regards,<br>Amar<br><br><br><br>