[PATCH v8 09/18] dax, dm: allow device-mapper to operate without dax support

2018-03-30 Thread Dan Williams
Change device-mapper's DAX dependency to require the presence of at
least one DAX_DRIVER. This allows device-mapper to be built without
bringing the DAX core along which is especially wasteful when there are
no DAX drivers, like BLK_DEV_PMEM, configured.

Cc: Alasdair Kergon 
Reported-by: Bart Van Assche 
Reported-by: kbuild test robot 
Reviewed-by: Mike Snitzer 
Signed-off-by: Dan Williams 
---
 drivers/md/Kconfig |1 
 drivers/md/dm-linear.c |6 +++
 drivers/md/dm-log-writes.c |   95 +++-
 drivers/md/dm-stripe.c |6 +++
 drivers/md/dm.c|   10 +++--
 include/linux/dax.h|   30 +++---
 6 files changed, 92 insertions(+), 56 deletions(-)

diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig
index 2c8ac3688815..6dfc328b8f99 100644
--- a/drivers/md/Kconfig
+++ b/drivers/md/Kconfig
@@ -201,7 +201,6 @@ config BLK_DEV_DM_BUILTIN
 config BLK_DEV_DM
tristate "Device mapper support"
select BLK_DEV_DM_BUILTIN
-   select DAX
---help---
  Device-mapper is a low level volume manager.  It works by allowing
  people to specify mappings for ranges of logical sectors.  Various
diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c
index d5f8eff7c11d..89443e0ededa 100644
--- a/drivers/md/dm-linear.c
+++ b/drivers/md/dm-linear.c
@@ -154,6 +154,7 @@ static int linear_iterate_devices(struct dm_target *ti,
return fn(ti, lc->dev, lc->start, ti->len, data);
 }
 
+#if IS_ENABLED(CONFIG_DAX_DRIVER)
 static long linear_dax_direct_access(struct dm_target *ti, pgoff_t pgoff,
long nr_pages, void **kaddr, pfn_t *pfn)
 {
@@ -184,6 +185,11 @@ static size_t linear_dax_copy_from_iter(struct dm_target 
*ti, pgoff_t pgoff,
return dax_copy_from_iter(dax_dev, pgoff, addr, bytes, i);
 }
 
+#else
+#define linear_dax_direct_access NULL
+#define linear_dax_copy_from_iter NULL
+#endif
+
 static struct target_type linear_target = {
.name   = "linear",
.version = {1, 4, 0},
diff --git a/drivers/md/dm-log-writes.c b/drivers/md/dm-log-writes.c
index 3362d866793b..7fcb4216973f 100644
--- a/drivers/md/dm-log-writes.c
+++ b/drivers/md/dm-log-writes.c
@@ -610,51 +610,6 @@ static int log_mark(struct log_writes_c *lc, char *data)
return 0;
 }
 
-static int log_dax(struct log_writes_c *lc, sector_t sector, size_t bytes,
-  struct iov_iter *i)
-{
-   struct pending_block *block;
-
-   if (!bytes)
-   return 0;
-
-   block = kzalloc(sizeof(struct pending_block), GFP_KERNEL);
-   if (!block) {
-   DMERR("Error allocating dax pending block");
-   return -ENOMEM;
-   }
-
-   block->data = kzalloc(bytes, GFP_KERNEL);
-   if (!block->data) {
-   DMERR("Error allocating dax data space");
-   kfree(block);
-   return -ENOMEM;
-   }
-
-   /* write data provided via the iterator */
-   if (!copy_from_iter(block->data, bytes, i)) {
-   DMERR("Error copying dax data");
-   kfree(block->data);
-   kfree(block);
-   return -EIO;
-   }
-
-   /* rewind the iterator so that the block driver can use it */
-   iov_iter_revert(i, bytes);
-
-   block->datalen = bytes;
-   block->sector = bio_to_dev_sectors(lc, sector);
-   block->nr_sectors = ALIGN(bytes, lc->sectorsize) >> lc->sectorshift;
-
-   atomic_inc(>pending_blocks);
-   spin_lock_irq(>blocks_lock);
-   list_add_tail(>list, >unflushed_blocks);
-   spin_unlock_irq(>blocks_lock);
-   wake_up_process(lc->log_kthread);
-
-   return 0;
-}
-
 static void log_writes_dtr(struct dm_target *ti)
 {
struct log_writes_c *lc = ti->private;
@@ -920,6 +875,52 @@ static void log_writes_io_hints(struct dm_target *ti, 
struct queue_limits *limit
limits->io_min = limits->physical_block_size;
 }
 
+#if IS_ENABLED(CONFIG_DAX_DRIVER)
+static int log_dax(struct log_writes_c *lc, sector_t sector, size_t bytes,
+  struct iov_iter *i)
+{
+   struct pending_block *block;
+
+   if (!bytes)
+   return 0;
+
+   block = kzalloc(sizeof(struct pending_block), GFP_KERNEL);
+   if (!block) {
+   DMERR("Error allocating dax pending block");
+   return -ENOMEM;
+   }
+
+   block->data = kzalloc(bytes, GFP_KERNEL);
+   if (!block->data) {
+   DMERR("Error allocating dax data space");
+   kfree(block);
+   return -ENOMEM;
+   }
+
+   /* write data provided via the iterator */
+   if (!copy_from_iter(block->data, bytes, i)) {
+   DMERR("Error copying dax data");
+   kfree(block->data);
+   kfree(block);
+   return -EIO;
+   }
+
+   /* rewind the 

[PATCH v8 09/18] dax, dm: allow device-mapper to operate without dax support

2018-03-30 Thread Dan Williams
Change device-mapper's DAX dependency to require the presence of at
least one DAX_DRIVER. This allows device-mapper to be built without
bringing the DAX core along which is especially wasteful when there are
no DAX drivers, like BLK_DEV_PMEM, configured.

Cc: Alasdair Kergon 
Reported-by: Bart Van Assche 
Reported-by: kbuild test robot 
Reviewed-by: Mike Snitzer 
Signed-off-by: Dan Williams 
---
 drivers/md/Kconfig |1 
 drivers/md/dm-linear.c |6 +++
 drivers/md/dm-log-writes.c |   95 +++-
 drivers/md/dm-stripe.c |6 +++
 drivers/md/dm.c|   10 +++--
 include/linux/dax.h|   30 +++---
 6 files changed, 92 insertions(+), 56 deletions(-)

diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig
index 2c8ac3688815..6dfc328b8f99 100644
--- a/drivers/md/Kconfig
+++ b/drivers/md/Kconfig
@@ -201,7 +201,6 @@ config BLK_DEV_DM_BUILTIN
 config BLK_DEV_DM
tristate "Device mapper support"
select BLK_DEV_DM_BUILTIN
-   select DAX
---help---
  Device-mapper is a low level volume manager.  It works by allowing
  people to specify mappings for ranges of logical sectors.  Various
diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c
index d5f8eff7c11d..89443e0ededa 100644
--- a/drivers/md/dm-linear.c
+++ b/drivers/md/dm-linear.c
@@ -154,6 +154,7 @@ static int linear_iterate_devices(struct dm_target *ti,
return fn(ti, lc->dev, lc->start, ti->len, data);
 }
 
+#if IS_ENABLED(CONFIG_DAX_DRIVER)
 static long linear_dax_direct_access(struct dm_target *ti, pgoff_t pgoff,
long nr_pages, void **kaddr, pfn_t *pfn)
 {
@@ -184,6 +185,11 @@ static size_t linear_dax_copy_from_iter(struct dm_target 
*ti, pgoff_t pgoff,
return dax_copy_from_iter(dax_dev, pgoff, addr, bytes, i);
 }
 
+#else
+#define linear_dax_direct_access NULL
+#define linear_dax_copy_from_iter NULL
+#endif
+
 static struct target_type linear_target = {
.name   = "linear",
.version = {1, 4, 0},
diff --git a/drivers/md/dm-log-writes.c b/drivers/md/dm-log-writes.c
index 3362d866793b..7fcb4216973f 100644
--- a/drivers/md/dm-log-writes.c
+++ b/drivers/md/dm-log-writes.c
@@ -610,51 +610,6 @@ static int log_mark(struct log_writes_c *lc, char *data)
return 0;
 }
 
-static int log_dax(struct log_writes_c *lc, sector_t sector, size_t bytes,
-  struct iov_iter *i)
-{
-   struct pending_block *block;
-
-   if (!bytes)
-   return 0;
-
-   block = kzalloc(sizeof(struct pending_block), GFP_KERNEL);
-   if (!block) {
-   DMERR("Error allocating dax pending block");
-   return -ENOMEM;
-   }
-
-   block->data = kzalloc(bytes, GFP_KERNEL);
-   if (!block->data) {
-   DMERR("Error allocating dax data space");
-   kfree(block);
-   return -ENOMEM;
-   }
-
-   /* write data provided via the iterator */
-   if (!copy_from_iter(block->data, bytes, i)) {
-   DMERR("Error copying dax data");
-   kfree(block->data);
-   kfree(block);
-   return -EIO;
-   }
-
-   /* rewind the iterator so that the block driver can use it */
-   iov_iter_revert(i, bytes);
-
-   block->datalen = bytes;
-   block->sector = bio_to_dev_sectors(lc, sector);
-   block->nr_sectors = ALIGN(bytes, lc->sectorsize) >> lc->sectorshift;
-
-   atomic_inc(>pending_blocks);
-   spin_lock_irq(>blocks_lock);
-   list_add_tail(>list, >unflushed_blocks);
-   spin_unlock_irq(>blocks_lock);
-   wake_up_process(lc->log_kthread);
-
-   return 0;
-}
-
 static void log_writes_dtr(struct dm_target *ti)
 {
struct log_writes_c *lc = ti->private;
@@ -920,6 +875,52 @@ static void log_writes_io_hints(struct dm_target *ti, 
struct queue_limits *limit
limits->io_min = limits->physical_block_size;
 }
 
+#if IS_ENABLED(CONFIG_DAX_DRIVER)
+static int log_dax(struct log_writes_c *lc, sector_t sector, size_t bytes,
+  struct iov_iter *i)
+{
+   struct pending_block *block;
+
+   if (!bytes)
+   return 0;
+
+   block = kzalloc(sizeof(struct pending_block), GFP_KERNEL);
+   if (!block) {
+   DMERR("Error allocating dax pending block");
+   return -ENOMEM;
+   }
+
+   block->data = kzalloc(bytes, GFP_KERNEL);
+   if (!block->data) {
+   DMERR("Error allocating dax data space");
+   kfree(block);
+   return -ENOMEM;
+   }
+
+   /* write data provided via the iterator */
+   if (!copy_from_iter(block->data, bytes, i)) {
+   DMERR("Error copying dax data");
+   kfree(block->data);
+   kfree(block);
+   return -EIO;
+   }
+
+   /* rewind the iterator so that the block driver can use it */
+   iov_iter_revert(i, bytes);
+
+   block->datalen =