Skip to content

Commit f4f8458

Browse files
damien-lemoalaxboe
authored andcommitted
null_blk: Introduce fua attribute
Add the fua configfs attribute and module parameter to allow configuring if the device supports FUA or not. Using this attribute has an effect on the null_blk device only if memory backing is enabled together with a write cache (cache_size option). This new attribute allows configuring a null_blk device with a write cache but without FUA support. This is convenient to test the block layer flush machinery. Signed-off-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Tested-by: Hans Holmberg <hans.holmberg@wdc.com> Tested-by: Dennis Maisenbacher <dennis.maisenbacher@wdc.com> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Link: https://lore.kernel.org/r/20240408014128.205141-18-dlemoal@kernel.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 997a1f0 commit f4f8458

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

drivers/block/null_blk/main.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ static unsigned long g_cache_size;
225225
module_param_named(cache_size, g_cache_size, ulong, 0444);
226226
MODULE_PARM_DESC(mbps, "Cache size in MiB for memory-backed device. Default: 0 (none)");
227227

228+
static bool g_fua = true;
229+
module_param_named(fua, g_fua, bool, 0444);
230+
MODULE_PARM_DESC(zoned, "Enable/disable FUA support when cache_size is used. Default: true");
231+
228232
static unsigned int g_mbps;
229233
module_param_named(mbps, g_mbps, uint, 0444);
230234
MODULE_PARM_DESC(mbps, "Limit maximum bandwidth (in MiB/s). Default: 0 (no limit)");
@@ -446,6 +450,7 @@ NULLB_DEVICE_ATTR(virt_boundary, bool, NULL);
446450
NULLB_DEVICE_ATTR(no_sched, bool, NULL);
447451
NULLB_DEVICE_ATTR(shared_tags, bool, NULL);
448452
NULLB_DEVICE_ATTR(shared_tag_bitmap, bool, NULL);
453+
NULLB_DEVICE_ATTR(fua, bool, NULL);
449454

450455
static ssize_t nullb_device_power_show(struct config_item *item, char *page)
451456
{
@@ -593,6 +598,7 @@ static struct configfs_attribute *nullb_device_attrs[] = {
593598
&nullb_device_attr_no_sched,
594599
&nullb_device_attr_shared_tags,
595600
&nullb_device_attr_shared_tag_bitmap,
601+
&nullb_device_attr_fua,
596602
NULL,
597603
};
598604

@@ -671,7 +677,7 @@ nullb_group_drop_item(struct config_group *group, struct config_item *item)
671677
static ssize_t memb_group_features_show(struct config_item *item, char *page)
672678
{
673679
return snprintf(page, PAGE_SIZE,
674-
"badblocks,blocking,blocksize,cache_size,"
680+
"badblocks,blocking,blocksize,cache_size,fua,"
675681
"completion_nsec,discard,home_node,hw_queue_depth,"
676682
"irqmode,max_sectors,mbps,memory_backed,no_sched,"
677683
"poll_queues,power,queue_mode,shared_tag_bitmap,"
@@ -763,6 +769,8 @@ static struct nullb_device *null_alloc_dev(void)
763769
dev->no_sched = g_no_sched;
764770
dev->shared_tags = g_shared_tags;
765771
dev->shared_tag_bitmap = g_shared_tag_bitmap;
772+
dev->fua = g_fua;
773+
766774
return dev;
767775
}
768776

@@ -1920,7 +1928,7 @@ static int null_add_dev(struct nullb_device *dev)
19201928

19211929
if (dev->cache_size > 0) {
19221930
set_bit(NULLB_DEV_FL_CACHE, &nullb->dev->flags);
1923-
blk_queue_write_cache(nullb->q, true, true);
1931+
blk_queue_write_cache(nullb->q, true, dev->fua);
19241932
}
19251933

19261934
nullb->q->queuedata = nullb;

drivers/block/null_blk/null_blk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ struct nullb_device {
105105
bool no_sched; /* no IO scheduler for the device */
106106
bool shared_tags; /* share tag set between devices for blk-mq */
107107
bool shared_tag_bitmap; /* use hostwide shared tags */
108+
bool fua; /* Support FUA */
108109
};
109110

110111
struct nullb {

0 commit comments

Comments
 (0)