[2.2] bdev_discard_supported: understand discard_granularity=0 #16111
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation and Context
OpenZFS does not consider the
discard_granularity
property when enabling discard (TRIM), leading to the kernel rejecting discard requests with confusing warnings in the logs.Backporting #16082 for 2.2.4, which i promised I would do in #16056.
Description
Kernel documentation for the
discard_granularity
property says:Some older kernels had drivers (notably loop, but also some USB-SATA adapters) that would set the
QUEUE_FLAG_DISCARD
capability flag, but havediscard_granularity=0
. Since 5.10 (torvalds/linux@b35fd7422c2f) the discard entry pointblkdev_issue_discard()
has had a check for this, which would immediately reject the call withEOPNOTSUPP
, and throw a scary diagnostic message into the log. See #16068.Since 6.8, the block layer sets a non-zero default for discard_granularity (torvalds/linux@3c407dc723bb), and a future kernel will remove the check entirely.
As such, there's no good reason for us to enable discard when
discard_granularity=0
. The kernel will never let the request go in anyway; better that we just disable it so we can report it properly to the user.How Has This Been Tested?
Checked on 5.10.214, where loop devices have
QUEUE_FLAG_DISCARD
anddiscard_granularity=0
:Testing on #16082 should hold here.
Types of changes
Checklist:
Signed-off-by
.