Skip to content

Commit 5b0fab5

Browse files
lostjefflesnitm
authored andcommitted
dm table: fix DAX iterate_devices based device capability checks
Fix dm_table_supports_dax() and invert logic of both iterate_devices_callout_fn so that all devices' DAX capabilities are properly checked. Fixes: 545ed20 ("dm: add infrastructure for DAX support") Cc: [email protected] Signed-off-by: Jeffle Xu <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent a4c8dd9 commit 5b0fab5

3 files changed

Lines changed: 12 additions & 29 deletions

File tree

drivers/md/dm-table.c

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -820,24 +820,24 @@ void dm_table_set_type(struct dm_table *t, enum dm_queue_mode type)
820820
EXPORT_SYMBOL_GPL(dm_table_set_type);
821821

822822
/* validate the dax capability of the target device span */
823-
int device_supports_dax(struct dm_target *ti, struct dm_dev *dev,
823+
int device_not_dax_capable(struct dm_target *ti, struct dm_dev *dev,
824824
sector_t start, sector_t len, void *data)
825825
{
826826
int blocksize = *(int *) data, id;
827827
bool rc;
828828

829829
id = dax_read_lock();
830-
rc = dax_supported(dev->dax_dev, dev->bdev, blocksize, start, len);
830+
rc = !dax_supported(dev->dax_dev, dev->bdev, blocksize, start, len);
831831
dax_read_unlock(id);
832832

833833
return rc;
834834
}
835835

836836
/* Check devices support synchronous DAX */
837-
static int device_dax_synchronous(struct dm_target *ti, struct dm_dev *dev,
838-
sector_t start, sector_t len, void *data)
837+
static int device_not_dax_synchronous_capable(struct dm_target *ti, struct dm_dev *dev,
838+
sector_t start, sector_t len, void *data)
839839
{
840-
return dev->dax_dev && dax_synchronous(dev->dax_dev);
840+
return !dev->dax_dev || !dax_synchronous(dev->dax_dev);
841841
}
842842

843843
bool dm_table_supports_dax(struct dm_table *t,
@@ -854,7 +854,7 @@ bool dm_table_supports_dax(struct dm_table *t,
854854
return false;
855855

856856
if (!ti->type->iterate_devices ||
857-
!ti->type->iterate_devices(ti, iterate_fn, blocksize))
857+
ti->type->iterate_devices(ti, iterate_fn, blocksize))
858858
return false;
859859
}
860860

@@ -925,7 +925,7 @@ static int dm_table_determine_type(struct dm_table *t)
925925
verify_bio_based:
926926
/* We must use this table as bio-based */
927927
t->type = DM_TYPE_BIO_BASED;
928-
if (dm_table_supports_dax(t, device_supports_dax, &page_size) ||
928+
if (dm_table_supports_dax(t, device_not_dax_capable, &page_size) ||
929929
(list_empty(devices) && live_md_type == DM_TYPE_DAX_BIO_BASED)) {
930930
t->type = DM_TYPE_DAX_BIO_BASED;
931931
}
@@ -1618,23 +1618,6 @@ static int device_dax_write_cache_enabled(struct dm_target *ti,
16181618
return false;
16191619
}
16201620

1621-
static int dm_table_supports_dax_write_cache(struct dm_table *t)
1622-
{
1623-
struct dm_target *ti;
1624-
unsigned i;
1625-
1626-
for (i = 0; i < dm_table_get_num_targets(t); i++) {
1627-
ti = dm_table_get_target(t, i);
1628-
1629-
if (ti->type->iterate_devices &&
1630-
ti->type->iterate_devices(ti,
1631-
device_dax_write_cache_enabled, NULL))
1632-
return true;
1633-
}
1634-
1635-
return false;
1636-
}
1637-
16381621
static int device_is_rotational(struct dm_target *ti, struct dm_dev *dev,
16391622
sector_t start, sector_t len, void *data)
16401623
{
@@ -1839,15 +1822,15 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
18391822
}
18401823
blk_queue_write_cache(q, wc, fua);
18411824

1842-
if (dm_table_supports_dax(t, device_supports_dax, &page_size)) {
1825+
if (dm_table_supports_dax(t, device_not_dax_capable, &page_size)) {
18431826
blk_queue_flag_set(QUEUE_FLAG_DAX, q);
1844-
if (dm_table_supports_dax(t, device_dax_synchronous, NULL))
1827+
if (dm_table_supports_dax(t, device_not_dax_synchronous_capable, NULL))
18451828
set_dax_synchronous(t->md->dax_dev);
18461829
}
18471830
else
18481831
blk_queue_flag_clear(QUEUE_FLAG_DAX, q);
18491832

1850-
if (dm_table_supports_dax_write_cache(t))
1833+
if (dm_table_any_dev_attr(t, device_dax_write_cache_enabled))
18511834
dax_write_cache(t->md->dax_dev, true);
18521835

18531836
/* Ensure that all underlying devices are non-rotational. */

drivers/md/dm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ static bool dm_dax_supported(struct dax_device *dax_dev, struct block_device *bd
11331133
if (!map)
11341134
goto out;
11351135

1136-
ret = dm_table_supports_dax(map, device_supports_dax, &blocksize);
1136+
ret = dm_table_supports_dax(map, device_not_dax_capable, &blocksize);
11371137

11381138
out:
11391139
dm_put_live_table(md, srcu_idx);

drivers/md/dm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void dm_table_free_md_mempools(struct dm_table *t);
7373
struct dm_md_mempools *dm_table_get_md_mempools(struct dm_table *t);
7474
bool dm_table_supports_dax(struct dm_table *t, iterate_devices_callout_fn fn,
7575
int *blocksize);
76-
int device_supports_dax(struct dm_target *ti, struct dm_dev *dev,
76+
int device_not_dax_capable(struct dm_target *ti, struct dm_dev *dev,
7777
sector_t start, sector_t len, void *data);
7878

7979
void dm_lock_md_type(struct mapped_device *md);

0 commit comments

Comments
 (0)