Skip to content

Commit 0fbeb02

Browse files
zhangyi089kawasaki
authored andcommitted
nvme: set BLK_FEAT_WRITE_ZEROES_UNMAP if device supports DEAC bit
When the device supports the Write Zeroes command and the DEAC bit, it indicates that the deallocate bit in the Write Zeroes command is supported, and the bytes read from a deallocated logical block are zeroes. This means the device supports unmap Write Zeroes, so set the BLK_FEAT_WRITE_ZEROES_UNMAP feature to the device's queue limit. Signed-off-by: Zhang Yi <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent c70dcfe commit 0fbeb02

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

drivers/nvme/host/core.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,22 +2420,25 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
24202420
else
24212421
lim.write_stream_granularity = 0;
24222422

2423-
ret = queue_limits_commit_update(ns->disk->queue, &lim);
2424-
if (ret) {
2425-
blk_mq_unfreeze_queue(ns->disk->queue, memflags);
2426-
goto out;
2427-
}
2428-
2429-
set_capacity_and_notify(ns->disk, capacity);
2430-
24312423
/*
24322424
* Only set the DEAC bit if the device guarantees that reads from
24332425
* deallocated data return zeroes. While the DEAC bit does not
24342426
* require that, it must be a no-op if reads from deallocated data
24352427
* do not return zeroes.
24362428
*/
2437-
if ((id->dlfeat & 0x7) == 0x1 && (id->dlfeat & (1 << 3)))
2429+
if ((id->dlfeat & 0x7) == 0x1 && (id->dlfeat & (1 << 3))) {
24382430
ns->head->features |= NVME_NS_DEAC;
2431+
if (lim.max_write_zeroes_sectors)
2432+
lim.features |= BLK_FEAT_WRITE_ZEROES_UNMAP;
2433+
}
2434+
2435+
ret = queue_limits_commit_update(ns->disk->queue, &lim);
2436+
if (ret) {
2437+
blk_mq_unfreeze_queue(ns->disk->queue, memflags);
2438+
goto out;
2439+
}
2440+
2441+
set_capacity_and_notify(ns->disk, capacity);
24392442
set_disk_ro(ns->disk, nvme_ns_is_readonly(ns, info));
24402443
set_bit(NVME_NS_READY, &ns->flags);
24412444
blk_mq_unfreeze_queue(ns->disk->queue, memflags);

0 commit comments

Comments
 (0)