Skip to content

Commit ef51042

Browse files
committed
block, dax: move "select DAX" from BLOCK to FS_DAX
For configurations that do not enable DAX filesystems or drivers, do not require the DAX core to be built. Given that the 'direct_access' method has been removed from 'block_device_operations', we can also go ahead and remove the block-related dax helper functions from fs/block_dev.c to drivers/dax/super.c. This keeps dax details out of the block layer and lets the DAX core be built as a module in the FS_DAX=n case. Filesystems need to include dax.h to call bdev_dax_supported(). Cc: linux-xfs@vger.kernel.org Cc: Jens Axboe <axboe@kernel.dk> Cc: "Theodore Ts'o" <tytso@mit.edu> Cc: Matthew Wilcox <mawilcox@microsoft.com> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: "Darrick J. Wong" <darrick.wong@oracle.com> Cc: Ross Zwisler <ross.zwisler@linux.intel.com> Reviewed-by: Jan Kara <jack@suse.com> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 74d71a0 commit ef51042

9 files changed

Lines changed: 102 additions & 71 deletions

File tree

‎block/Kconfig‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ menuconfig BLOCK
66
default y
77
select SBITMAP
88
select SRCU
9-
select DAX
109
help
1110
Provide block layer support for the kernel.
1211

‎drivers/dax/super.c‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/module.h>
1515
#include <linux/mount.h>
1616
#include <linux/magic.h>
17+
#include <linux/genhd.h>
1718
#include <linux/cdev.h>
1819
#include <linux/hash.h>
1920
#include <linux/slab.h>
@@ -47,6 +48,75 @@ void dax_read_unlock(int id)
4748
}
4849
EXPORT_SYMBOL_GPL(dax_read_unlock);
4950

51+
int bdev_dax_pgoff(struct block_device *bdev, sector_t sector, size_t size,
52+
pgoff_t *pgoff)
53+
{
54+
phys_addr_t phys_off = (get_start_sect(bdev) + sector) * 512;
55+
56+
if (pgoff)
57+
*pgoff = PHYS_PFN(phys_off);
58+
if (phys_off % PAGE_SIZE || size % PAGE_SIZE)
59+
return -EINVAL;
60+
return 0;
61+
}
62+
EXPORT_SYMBOL(bdev_dax_pgoff);
63+
64+
/**
65+
* __bdev_dax_supported() - Check if the device supports dax for filesystem
66+
* @sb: The superblock of the device
67+
* @blocksize: The block size of the device
68+
*
69+
* This is a library function for filesystems to check if the block device
70+
* can be mounted with dax option.
71+
*
72+
* Return: negative errno if unsupported, 0 if supported.
73+
*/
74+
int __bdev_dax_supported(struct super_block *sb, int blocksize)
75+
{
76+
struct block_device *bdev = sb->s_bdev;
77+
struct dax_device *dax_dev;
78+
pgoff_t pgoff;
79+
int err, id;
80+
void *kaddr;
81+
pfn_t pfn;
82+
long len;
83+
84+
if (blocksize != PAGE_SIZE) {
85+
pr_err("VFS (%s): error: unsupported blocksize for dax\n",
86+
sb->s_id);
87+
return -EINVAL;
88+
}
89+
90+
err = bdev_dax_pgoff(bdev, 0, PAGE_SIZE, &pgoff);
91+
if (err) {
92+
pr_err("VFS (%s): error: unaligned partition for dax\n",
93+
sb->s_id);
94+
return err;
95+
}
96+
97+
dax_dev = dax_get_by_host(bdev->bd_disk->disk_name);
98+
if (!dax_dev) {
99+
pr_err("VFS (%s): error: device does not support dax\n",
100+
sb->s_id);
101+
return -EOPNOTSUPP;
102+
}
103+
104+
id = dax_read_lock();
105+
len = dax_direct_access(dax_dev, pgoff, 1, &kaddr, &pfn);
106+
dax_read_unlock(id);
107+
108+
put_dax(dax_dev);
109+
110+
if (len < 1) {
111+
pr_err("VFS (%s): error: dax access failed (%ld)",
112+
sb->s_id, len);
113+
return len < 0 ? len : -EIO;
114+
}
115+
116+
return 0;
117+
}
118+
EXPORT_SYMBOL_GPL(__bdev_dax_supported);
119+
50120
/**
51121
* struct dax_device - anchor object for dax services
52122
* @inode: core vfs

‎fs/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ config FS_DAX
3939
depends on MMU
4040
depends on !(ARM || MIPS || SPARC)
4141
select FS_IOMAP
42+
select DAX
4243
help
4344
Direct Access (DAX) can be used on memory-backed block devices.
4445
If the block device supports DAX and the filesystem supports DAX,

‎fs/block_dev.c‎

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -718,72 +718,6 @@ int bdev_write_page(struct block_device *bdev, sector_t sector,
718718
}
719719
EXPORT_SYMBOL_GPL(bdev_write_page);
720720

721-
int bdev_dax_pgoff(struct block_device *bdev, sector_t sector, size_t size,
722-
pgoff_t *pgoff)
723-
{
724-
phys_addr_t phys_off = (get_start_sect(bdev) + sector) * 512;
725-
726-
if (pgoff)
727-
*pgoff = PHYS_PFN(phys_off);
728-
if (phys_off % PAGE_SIZE || size % PAGE_SIZE)
729-
return -EINVAL;
730-
return 0;
731-
}
732-
EXPORT_SYMBOL(bdev_dax_pgoff);
733-
734-
/**
735-
* bdev_dax_supported() - Check if the device supports dax for filesystem
736-
* @sb: The superblock of the device
737-
* @blocksize: The block size of the device
738-
*
739-
* This is a library function for filesystems to check if the block device
740-
* can be mounted with dax option.
741-
*
742-
* Return: negative errno if unsupported, 0 if supported.
743-
*/
744-
int bdev_dax_supported(struct super_block *sb, int blocksize)
745-
{
746-
struct block_device *bdev = sb->s_bdev;
747-
struct dax_device *dax_dev;
748-
pgoff_t pgoff;
749-
int err, id;
750-
void *kaddr;
751-
pfn_t pfn;
752-
long len;
753-
754-
if (blocksize != PAGE_SIZE) {
755-
vfs_msg(sb, KERN_ERR, "error: unsupported blocksize for dax");
756-
return -EINVAL;
757-
}
758-
759-
err = bdev_dax_pgoff(bdev, 0, PAGE_SIZE, &pgoff);
760-
if (err) {
761-
vfs_msg(sb, KERN_ERR, "error: unaligned partition for dax");
762-
return err;
763-
}
764-
765-
dax_dev = dax_get_by_host(bdev->bd_disk->disk_name);
766-
if (!dax_dev) {
767-
vfs_msg(sb, KERN_ERR, "error: device does not support dax");
768-
return -EOPNOTSUPP;
769-
}
770-
771-
id = dax_read_lock();
772-
len = dax_direct_access(dax_dev, pgoff, 1, &kaddr, &pfn);
773-
dax_read_unlock(id);
774-
775-
put_dax(dax_dev);
776-
777-
if (len < 1) {
778-
vfs_msg(sb, KERN_ERR,
779-
"error: dax access failed (%ld)", len);
780-
return len < 0 ? len : -EIO;
781-
}
782-
783-
return 0;
784-
}
785-
EXPORT_SYMBOL_GPL(bdev_dax_supported);
786-
787721
/*
788722
* pseudo-fs
789723
*/

‎fs/ext2/super.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <linux/log2.h>
3333
#include <linux/quotaops.h>
3434
#include <linux/uaccess.h>
35+
#include <linux/dax.h>
3536
#include "ext2.h"
3637
#include "xattr.h"
3738
#include "acl.h"

‎fs/ext4/super.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <linux/ctype.h>
3838
#include <linux/log2.h>
3939
#include <linux/crc16.h>
40+
#include <linux/dax.h>
4041
#include <linux/cleancache.h>
4142
#include <linux/uaccess.h>
4243

‎fs/xfs/xfs_super.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "xfs_reflink.h"
5353

5454
#include <linux/namei.h>
55+
#include <linux/dax.h>
5556
#include <linux/init.h>
5657
#include <linux/slab.h>
5758
#include <linux/mount.h>

‎include/linux/blkdev.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,8 +1940,6 @@ extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
19401940
extern int bdev_read_page(struct block_device *, sector_t, struct page *);
19411941
extern int bdev_write_page(struct block_device *, sector_t, struct page *,
19421942
struct writeback_control *);
1943-
extern int bdev_dax_supported(struct super_block *, int);
1944-
int bdev_dax_pgoff(struct block_device *, sector_t, size_t, pgoff_t *pgoff);
19451943
#else /* CONFIG_BLOCK */
19461944

19471945
struct block_device;

‎include/linux/dax.h‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,38 @@ struct dax_operations {
1818
void **, pfn_t *);
1919
};
2020

21+
int bdev_dax_pgoff(struct block_device *, sector_t, size_t, pgoff_t *pgoff);
22+
#if IS_ENABLED(CONFIG_FS_DAX)
23+
int __bdev_dax_supported(struct super_block *sb, int blocksize);
24+
static inline int bdev_dax_supported(struct super_block *sb, int blocksize)
25+
{
26+
return __bdev_dax_supported(sb, blocksize);
27+
}
28+
#else
29+
static inline int bdev_dax_supported(struct super_block *sb, int blocksize)
30+
{
31+
return -EOPNOTSUPP;
32+
}
33+
#endif
34+
35+
#if IS_ENABLED(CONFIG_DAX)
36+
struct dax_device *dax_get_by_host(const char *host);
37+
void put_dax(struct dax_device *dax_dev);
38+
#else
39+
static inline struct dax_device *dax_get_by_host(const char *host)
40+
{
41+
return NULL;
42+
}
43+
44+
static inline void put_dax(struct dax_device *dax_dev)
45+
{
46+
}
47+
#endif
48+
2149
int dax_read_lock(void);
2250
void dax_read_unlock(int id);
23-
struct dax_device *dax_get_by_host(const char *host);
2451
struct dax_device *alloc_dax(void *private, const char *host,
2552
const struct dax_operations *ops);
26-
void put_dax(struct dax_device *dax_dev);
2753
bool dax_alive(struct dax_device *dax_dev);
2854
void kill_dax(struct dax_device *dax_dev);
2955
void *dax_get_private(struct dax_device *dax_dev);

0 commit comments

Comments
 (0)