Skip to content

Commit 273752c

Browse files
rhvgoyalsnitm
authored andcommitted
dm, dax: Make sure dm_dax_flush() is called if device supports it
Currently dm_dax_flush() is not being called, even if underlying dax device supports write cache, because DAXDEV_WRITE_CACHE is not being propagated up to the DM dax device. If the underlying dax device supports write cache, set DAXDEV_WRITE_CACHE on the DM dax device. This will cause dm_dax_flush() to be called. Fixes: abebfbe ("dm: add ->flush() dax operation support") Signed-off-by: Vivek Goyal <[email protected]> Acked-by: Dan Williams <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent 34c9650 commit 273752c

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

drivers/dax/super.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,12 @@ void dax_write_cache(struct dax_device *dax_dev, bool wc)
278278
}
279279
EXPORT_SYMBOL_GPL(dax_write_cache);
280280

281+
bool dax_write_cache_enabled(struct dax_device *dax_dev)
282+
{
283+
return test_bit(DAXDEV_WRITE_CACHE, &dax_dev->flags);
284+
}
285+
EXPORT_SYMBOL_GPL(dax_write_cache_enabled);
286+
281287
bool dax_alive(struct dax_device *dax_dev)
282288
{
283289
lockdep_assert_held(&dax_srcu);

drivers/md/dm-table.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/atomic.h>
2121
#include <linux/blk-mq.h>
2222
#include <linux/mount.h>
23+
#include <linux/dax.h>
2324

2425
#define DM_MSG_PREFIX "table"
2526

@@ -1630,6 +1631,37 @@ static bool dm_table_supports_flush(struct dm_table *t, unsigned long flush)
16301631
return false;
16311632
}
16321633

1634+
static int device_dax_write_cache_enabled(struct dm_target *ti,
1635+
struct dm_dev *dev, sector_t start,
1636+
sector_t len, void *data)
1637+
{
1638+
struct dax_device *dax_dev = dev->dax_dev;
1639+
1640+
if (!dax_dev)
1641+
return false;
1642+
1643+
if (dax_write_cache_enabled(dax_dev))
1644+
return true;
1645+
return false;
1646+
}
1647+
1648+
static int dm_table_supports_dax_write_cache(struct dm_table *t)
1649+
{
1650+
struct dm_target *ti;
1651+
unsigned i;
1652+
1653+
for (i = 0; i < dm_table_get_num_targets(t); i++) {
1654+
ti = dm_table_get_target(t, i);
1655+
1656+
if (ti->type->iterate_devices &&
1657+
ti->type->iterate_devices(ti,
1658+
device_dax_write_cache_enabled, NULL))
1659+
return true;
1660+
}
1661+
1662+
return false;
1663+
}
1664+
16331665
static int device_is_nonrot(struct dm_target *ti, struct dm_dev *dev,
16341666
sector_t start, sector_t len, void *data)
16351667
{
@@ -1785,6 +1817,9 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
17851817
}
17861818
blk_queue_write_cache(q, wc, fua);
17871819

1820+
if (dm_table_supports_dax_write_cache(t))
1821+
dax_write_cache(t->md->dax_dev, true);
1822+
17881823
/* Ensure that all underlying devices are non-rotational. */
17891824
if (dm_table_all_devices_attribute(t, device_is_nonrot))
17901825
queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q);

include/linux/dax.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
8787
void dax_flush(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
8888
size_t size);
8989
void dax_write_cache(struct dax_device *dax_dev, bool wc);
90+
bool dax_write_cache_enabled(struct dax_device *dax_dev);
9091

9192
/*
9293
* We use lowest available bit in exceptional entry for locking, one bit for

0 commit comments

Comments
 (0)