Starting LBA is a 64bit number, so use htole64 instead of htole32. The
latter casts the LBA to a 32-bit number before assigning it to the 64 bit structure entity. This works fine on the first 2TB of TRIMs, but terrible beyond that due to trucation. Also, add an assert to make sure we don't end too many DSM TRIM entries in one request. Sponsored by: Netflix
This commit is contained in:
parent
fa46a47c04
commit
8d536b9f2e
@ -164,7 +164,7 @@ static void ndasuspend(void *arg);
|
||||
#define NDA_DEFAULT_RETRY 4
|
||||
#endif
|
||||
#ifndef NDA_MAX_TRIM_ENTRIES
|
||||
#define NDA_MAX_TRIM_ENTRIES 256 /* Number of DSM trims to use, max 256 */
|
||||
#define NDA_MAX_TRIM_ENTRIES (NVME_MAX_DSM_TRIM / sizeof(struct nvme_dsm_range))/* Number of DSM trims to use, max 256 */
|
||||
#endif
|
||||
|
||||
static SYSCTL_NODE(_kern_cam, OID_AUTO, nda, CTLFLAG_RD, 0,
|
||||
@ -218,6 +218,8 @@ static void
|
||||
nda_nvme_trim(struct nda_softc *softc, struct ccb_nvmeio *nvmeio,
|
||||
void *payload, uint32_t num_ranges)
|
||||
{
|
||||
KASSERT(num_ranges * sizeof(struct nvme_dsm_range) < NVME_MAX_DSM_TRIM);
|
||||
|
||||
cam_fill_nvmeio(nvmeio,
|
||||
0, /* retries */
|
||||
ndadone, /* cbfcnp */
|
||||
@ -957,7 +959,7 @@ ndastart(struct cam_periph *periph, union ccb *start_ccb)
|
||||
dsm_range->length =
|
||||
htole32(bp1->bio_bcount / softc->disk->d_sectorsize);
|
||||
dsm_range->starting_lba =
|
||||
htole32(bp1->bio_offset / softc->disk->d_sectorsize);
|
||||
htole64(bp1->bio_offset / softc->disk->d_sectorsize);
|
||||
dsm_range++;
|
||||
if (dsm_range >= dsm_end)
|
||||
break;
|
||||
|
@ -478,7 +478,6 @@ struct nvme_completion {
|
||||
_Static_assert(sizeof(struct nvme_completion) == 4 * 4, "bad size for nvme_completion");
|
||||
|
||||
struct nvme_dsm_range {
|
||||
|
||||
uint32_t attributes;
|
||||
uint32_t length;
|
||||
uint64_t starting_lba;
|
||||
|
Loading…
Reference in New Issue
Block a user