Fix DM DAX handling
Subsystems (7)
cover Fix DM DAX handling
This is a v4.14-stable backport of my "Fix DM DAX handling" series which had backport collisions. This series also includes a few patches that were backport dependencies.
Changes from the v4.17-stable version:
* DAX on raw mode namespace is allowed in this baseline, so we allow it for DM devices as well. This meant dropping the patch "pmem: only set QUEUE_FLAG_DAX for fsdax mode".
* Pulled in one additional patch from Mike as a backport dependency.
Darrick J. Wong (1):
fs: allow per-device dax status checking for filesystems
Dave Jiang (1):
dax: change bdev_dax_supported() to support boolean returns
Mike Snitzer (1):
dm: set QUEUE_FLAG_DAX accordingly in dm_table_set_restrictions()
Ross Zwisler (2):
dax: check for QUEUE_FLAG_DAX in bdev_dax_supported()
dm: prevent DAX mounts if not supported
drivers/dax/super.c | 42 +++++++++++++++++++++++++----------------- drivers/md/dm-table.c | 9 ++++++--- drivers/md/dm.c | 6 +----- fs/ext2/super.c | 3 +-- fs/ext4/super.c | 3 +-- fs/xfs/xfs_ioctl.c | 3 ++- fs/xfs/xfs_iops.c | 30 +++++++++++++++++++++++++----- fs/xfs/xfs_super.c | 10 ++++++++-- include/linux/dax.h | 11 ++++++----- 9 files changed, 75 insertions(+), 42 deletions(-)
Signature · 1 line
2.14.4
PATCH 1/5 fs: allow per-device dax status checking for filesystems
From: "Darrick J. Wong" <[email protected]>
commit ba23cba9b3bdc967aabdc6ff1e3e9b11ce05bb4f upstream.
Change bdev_dax_supported so it takes a bdev parameter. This enables multi-device filesystems like xfs to check that a dax device can work for the particular filesystem. Once that's in place, actually fix all the parts of XFS where we need to be able to distinguish between datadev and rtdev.
This patch fixes the problem where we screw up the dax support checking in xfs if the datadev and rtdev have different dax capabilities.
--- drivers/dax/super.c | 22 +++++++++++----------- fs/ext2/super.c | 2 +- fs/ext4/super.c | 2 +- fs/xfs/xfs_ioctl.c | 3 ++- fs/xfs/xfs_iops.c | 30 +++++++++++++++++++++++++----- fs/xfs/xfs_super.c | 10 ++++++++-- include/linux/dax.h | 9 +++++---- 7 files changed, 53 insertions(+), 25 deletions(-)
drivers/dax/super.c +11 -11
@@ -73,7 +73,7 @@ EXPORT_SYMBOL_GPL(fs_dax_get_by_bdev);/** * __bdev_dax_supported() - Check if the device supports dax for filesystem -* @sb: The superblock of the device +* @bdev: block device to check * @blocksize: The block size of the device * * This is a library function for filesystems to check if the block device
@@ -81,33 +81,33 @@ EXPORT_SYMBOL_GPL(fs_dax_get_by_bdev);* * Return: negative errno if unsupported, 0 if supported. */ -int __bdev_dax_supported (struct super_block *sb,int blocksize) +int __bdev_dax_supported (struct block_device *bdev,int blocksize) { -struct block_device *bdev = sb->s_bdev;struct dax_device *dax_dev;pgoff_t pgoff;int err, id;void *kaddr;pfn_t pfn;long len; +char buf[BDEVNAME_SIZE ];if (blocksize !=PAGE_SIZE ) { -pr_err ("VFS (%s): error: unsupported blocksize for dax\n" , - sb->s_id); +pr_debug ("%s: error: unsupported blocksize for dax\n" , +bdevname (bdev, buf));return -EINVAL ; } err =bdev_dax_pgoff (bdev,0 ,PAGE_SIZE , &pgoff);if (err) { -pr_err ("VFS (%s): error: unaligned partition for dax\n" , - sb->s_id); +pr_debug ("%s: error: unaligned partition for dax\n" , +bdevname (bdev, buf));return err; } dax_dev =dax_get_by_host (bdev->bd_disk->disk_name);if (!dax_dev) { -pr_err ("VFS (%s): error: device does not support dax\n" , - sb->s_id); +pr_debug ("%s: error: device does not support dax\n" , +bdevname (bdev, buf));return -EOPNOTSUPP ; }
@@ -118,8 +118,8 @@ int __bdev_dax_supported(struct super_block *sb, int blocksize)put_dax (dax_dev);if (len <1 ) { -pr_err ("VFS (%s): error: dax access failed (%ld)" , - sb->s_id, len); +pr_debug ("%s: error: dax access failed (%ld)\n" , +bdevname (bdev, buf), len);return len <0 ? len : -EIO ; }
fs/ext2/super.c +1 -1
@@ -953,7 +953,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent) blocksize =BLOCK_SIZE <<le32_to_cpu (sbi->s_es->s_log_block_size);if (sbi->s_mount_opt &EXT2_MOUNT_DAX ) { - err =bdev_dax_supported (sb, blocksize); + err =bdev_dax_supported (sb->s_bdev, blocksize);if (err) goto failed_mount; }
fs/ext4/super.c +1 -1
@@ -3729,7 +3729,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) " that may contain inline data"); goto failed_mount; } - err =bdev_dax_supported (sb, blocksize); + err =bdev_dax_supported (sb->s_bdev, blocksize);if (err) goto failed_mount; }
fs/xfs/xfs_ioctl.c +2 -1
@@ -1101,7 +1101,8 @@ xfs_ioctl_setattr_dax_invalidate(if (fa->fsx_xflags &FS_XFLAG_DAX ) {if (!(S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode)))return -EINVAL ; -if (bdev_dax_supported (sb, sb->s_blocksize) <0 ) +if (bdev_dax_supported (xfs_find_bdev_for_inode (VFS_I (ip)), + sb->s_blocksize) <0 )return -EINVAL ; }
fs/xfs/xfs_iops.c +25 -5
@@ -1184,6 +1184,30 @@ static const struct inode_operations xfs_inline_symlink_inode_operations = { .update_time = xfs_vn_update_time, }; +/* Figure out if this file actually supports DAX. */ +static bool +xfs_inode_supports_dax ( +struct xfs_inode *ip) +{ +struct xfs_mount *mp = ip->i_mount; + +/* Only supported on non-reflinked files. */ +if (!S_ISREG (VFS_I (ip)->i_mode) ||xfs_is_reflink_inode (ip)) +return false; + +/* DAX mount option or DAX iflag must be set. */ +if (!(mp->m_flags &XFS_MOUNT_DAX ) && + !(ip->i_d.di_flags2 &XFS_DIFLAG2_DAX )) +return false; + +/* Block size must match page size */ +if (mp->m_sb.sb_blocksize !=PAGE_SIZE ) +return false; + +/* Device has to support DAX too. */ +return xfs_find_daxdev_for_inode (VFS_I (ip)) !=NULL ; +} + STATIC void xfs_diflags_to_iflags( struct inode *inode,
@@ -1202,11 +1226,7 @@ xfs_diflags_to_iflags( inode->i_flags |=S_SYNC ;if (flags &XFS_DIFLAG_NOATIME ) inode->i_flags |=S_NOATIME ; -if (S_ISREG (inode->i_mode) && - ip->i_mount->m_sb.sb_blocksize ==PAGE_SIZE && - !xfs_is_reflink_inode (ip) && - (ip->i_mount->m_flags &XFS_MOUNT_DAX || - ip->i_d.di_flags2 &XFS_DIFLAG2_DAX )) +if (xfs_inode_supports_dax (ip)) inode->i_flags |=S_DAX ; }
fs/xfs/xfs_super.c +8 -2
@@ -1640,11 +1640,17 @@ xfs_fs_fill_super( sb->s_flags |=SB_I_VERSION ;if (mp->m_flags &XFS_MOUNT_DAX ) { +int error2 =0 ; +xfs_warn (mp,"DAX enabled. Warning: EXPERIMENTAL, use at your own risk" ); - error =bdev_dax_supported (sb, sb->s_blocksize); -if (error) { + error =bdev_dax_supported (mp->m_ddev_targp->bt_bdev, + sb->s_blocksize); +if (mp->m_rtdev_targp) + error2 =bdev_dax_supported (mp->m_rtdev_targp->bt_bdev, + sb->s_blocksize); +if (error && error2) {xfs_alert (mp,"DAX unsupported by block device. Turning off DAX." ); mp->m_flags &= ~XFS_MOUNT_DAX ;
include/linux/dax.h +5 -4
@@ -40,10 +40,10 @@ static inline void put_dax(struct dax_device *dax_dev)int bdev_dax_pgoff (struct block_device *,sector_t ,size_t ,pgoff_t *pgoff);#if IS_ENABLED (CONFIG_FS_DAX ) -int __bdev_dax_supported (struct super_block *sb,int blocksize); -static inline int bdev_dax_supported (struct super_block *sb,int blocksize) +int __bdev_dax_supported (struct block_device *bdev,int blocksize); +static inline int bdev_dax_supported (struct block_device *bdev,int blocksize) { -return __bdev_dax_supported (sb, blocksize); +return __bdev_dax_supported (bdev, blocksize); }static inline struct dax_device *fs_dax_get_by_host (const char *host)
@@ -58,7 +58,8 @@ static inline void fs_put_dax(struct dax_device *dax_dev)struct dax_device *fs_dax_get_by_bdev (struct block_device *bdev);#else -static inline int bdev_dax_supported (struct super_block *sb,int blocksize) +static inline int bdev_dax_supported (struct block_device *bdev, +int blocksize) {return -EOPNOTSUPP ; }
Signature · 1 line
2.14.4
PATCH 2/5 dax: change bdev_dax_supported() to support boolean returns
In reply to Ross ZwislerFrom: Dave Jiang <[email protected]>
commit 80660f20252d6f76c9f203874ad7c7a4a8508cf8 upstream.
The function return values are confusing with the way the function is named. We expect a true or false return value but it actually returns 0/-errno. This makes the code very confusing. Changing the return values to return a bool where if DAX is supported then return true and no DAX support returns false.
--- drivers/dax/super.c | 14 +++++++------- fs/ext2/super.c | 3 +-- fs/ext4/super.c | 3 +-- fs/xfs/xfs_ioctl.c | 4 ++-- fs/xfs/xfs_super.c | 12 ++++++------ include/linux/dax.h | 8 ++++---- 6 files changed, 21 insertions(+), 23 deletions(-)
drivers/dax/super.c +7 -7
@@ -79,9 +79,9 @@ EXPORT_SYMBOL_GPL(fs_dax_get_by_bdev);* This is a library function for filesystems to check if the block device * can be mounted with dax option. * -* Return: negative errno if unsupported, 0 if supported. +* Return: true if supported, false if unsupported */ -int __bdev_dax_supported (struct block_device *bdev,int blocksize) +bool __bdev_dax_supported (struct block_device *bdev,int blocksize) {struct dax_device *dax_dev;pgoff_t pgoff;
@@ -94,21 +94,21 @@ int __bdev_dax_supported(struct block_device *bdev, int blocksize)if (blocksize !=PAGE_SIZE ) {pr_debug ("%s: error: unsupported blocksize for dax\n" ,bdevname (bdev, buf)); -return -EINVAL ; +return false; } err =bdev_dax_pgoff (bdev,0 ,PAGE_SIZE , &pgoff);if (err) {pr_debug ("%s: error: unaligned partition for dax\n" ,bdevname (bdev, buf)); -return err; +return false; } dax_dev =dax_get_by_host (bdev->bd_disk->disk_name);if (!dax_dev) {pr_debug ("%s: error: device does not support dax\n" ,bdevname (bdev, buf)); -return -EOPNOTSUPP ; +return false; } id =dax_read_lock ();
@@ -120,10 +120,10 @@ int __bdev_dax_supported(struct block_device *bdev, int blocksize)if (len <1 ) {pr_debug ("%s: error: dax access failed (%ld)\n" ,bdevname (bdev, buf), len); -return len <0 ? len : -EIO ; +return false; } - return 0; + return true; }EXPORT_SYMBOL_GPL (__bdev_dax_supported);#endif
fs/ext2/super.c +1 -2
@@ -953,8 +953,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent) blocksize =BLOCK_SIZE <<le32_to_cpu (sbi->s_es->s_log_block_size);if (sbi->s_mount_opt &EXT2_MOUNT_DAX ) { - err =bdev_dax_supported (sb->s_bdev, blocksize); -if (err) +if (!bdev_dax_supported (sb->s_bdev, blocksize)) goto failed_mount; }
fs/ext4/super.c +1 -2
@@ -3729,8 +3729,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) " that may contain inline data"); goto failed_mount; } - err =bdev_dax_supported (sb->s_bdev, blocksize); -if (err) +if (!bdev_dax_supported (sb->s_bdev, blocksize)) goto failed_mount; }
fs/xfs/xfs_ioctl.c +2 -2
@@ -1101,8 +1101,8 @@ xfs_ioctl_setattr_dax_invalidate(if (fa->fsx_xflags &FS_XFLAG_DAX ) {if (!(S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode)))return -EINVAL ; -if (bdev_dax_supported (xfs_find_bdev_for_inode (VFS_I (ip)), - sb->s_blocksize) <0 ) +if (!bdev_dax_supported (xfs_find_bdev_for_inode (VFS_I (ip)), + sb->s_blocksize))return -EINVAL ; }
fs/xfs/xfs_super.c +6 -6
@@ -1640,17 +1640,17 @@ xfs_fs_fill_super( sb->s_flags |=SB_I_VERSION ;if (mp->m_flags &XFS_MOUNT_DAX ) { -int error2 =0 ; +bool rtdev_is_dax = false, datadev_is_dax;xfs_warn (mp,"DAX enabled. Warning: EXPERIMENTAL, use at your own risk" ); - error =bdev_dax_supported (mp->m_ddev_targp->bt_bdev, - sb->s_blocksize); + datadev_is_dax =bdev_dax_supported (mp->m_ddev_targp->bt_bdev, + sb->s_blocksize);if (mp->m_rtdev_targp) - error2 =bdev_dax_supported (mp->m_rtdev_targp->bt_bdev, - sb->s_blocksize); -if (error && error2) { + rtdev_is_dax =bdev_dax_supported ( + mp->m_rtdev_targp->bt_bdev, sb->s_blocksize); +if (!rtdev_is_dax && !datadev_is_dax) {xfs_alert (mp,"DAX unsupported by block device. Turning off DAX." ); mp->m_flags &= ~XFS_MOUNT_DAX ;
include/linux/dax.h +4 -4
@@ -40,8 +40,8 @@ static inline void put_dax(struct dax_device *dax_dev)int bdev_dax_pgoff (struct block_device *,sector_t ,size_t ,pgoff_t *pgoff);#if IS_ENABLED (CONFIG_FS_DAX ) -int __bdev_dax_supported (struct block_device *bdev,int blocksize); -static inline int bdev_dax_supported (struct block_device *bdev,int blocksize) +bool __bdev_dax_supported (struct block_device *bdev,int blocksize); +static inline bool bdev_dax_supported (struct block_device *bdev,int blocksize) {return __bdev_dax_supported (bdev, blocksize); }
@@ -58,10 +58,10 @@ static inline void fs_put_dax(struct dax_device *dax_dev)struct dax_device *fs_dax_get_by_bdev (struct block_device *bdev);#else -static inline int bdev_dax_supported (struct block_device *bdev, +static inline bool bdev_dax_supported (struct block_device *bdev,int blocksize) { -return -EOPNOTSUPP ; +return false; }static inline struct dax_device *fs_dax_get_by_host (const char *host)
Signature · 1 line
2.14.4
PATCH 3/5 dax: check for QUEUE_FLAG_DAX in bdev_dax_supported()
In reply to Ross Zwislercommit 15256f6cc4b44f2e70503758150267fd2a53c0d6 upstream.
Add an explicit check for QUEUE_FLAG_DAX to __bdev_dax_supported(). This is needed for DM configurations where the first element in the dm-linear or dm-stripe target supports DAX, but other elements do not. Without this check __bdev_dax_supported() will pass for such devices, letting a filesystem on that device mount with the DAX option.
--- drivers/dax/super.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/dax/super.c +8 -0
@@ -84,6 +84,7 @@ EXPORT_SYMBOL_GPL(fs_dax_get_by_bdev);bool __bdev_dax_supported (struct block_device *bdev,int blocksize) {struct dax_device *dax_dev; +struct request_queue *q;pgoff_t pgoff;int err, id;void *kaddr;
@@ -97,6 +98,13 @@ bool __bdev_dax_supported(struct block_device *bdev, int blocksize)return false; } + q =bdev_get_queue (bdev); +if (!q || !blk_queue_dax (q)) { +pr_debug ("%s: error: request queue doesn't support dax\n" , +bdevname (bdev, buf)); +return false; + } + err =bdev_dax_pgoff (bdev,0 ,PAGE_SIZE , &pgoff);if (err) { pr_debug("%s: error: unaligned partition for dax\n",
Signature · 1 line
2.14.4
PATCH 4/5 dm: set QUEUE_FLAG_DAX accordingly in dm_table_set_restrictions()
In reply to Ross ZwislerFrom: Mike Snitzer <[email protected]>
commit ad3793fc3945173f64d82d05d3ecde41f6c0435c upstream.
Rather than having DAX support be unique by setting it based on table type in dm_setup_md_queue().
--- drivers/md/dm-table.c | 2 ++ drivers/md/dm.c | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/md/dm-table.c +2 -0
@@ -1813,6 +1813,8 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, }blk_queue_write_cache (q, wc, fua); +if (dm_table_supports_dax (t)) +queue_flag_set_unlocked (QUEUE_FLAG_DAX , q);if (dm_table_supports_dax_write_cache (t))dax_write_cache (t->md->dax_dev, true);
drivers/md/dm.c +0 -3
@@ -2050,9 +2050,6 @@ int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t)*/ bioset_free (md->queue->bio_split); md->queue->bio_split =NULL ; - -if (type ==DM_TYPE_DAX_BIO_BASED ) -queue_flag_set_unlocked (QUEUE_FLAG_DAX , md->queue);break ;case DM_TYPE_NONE :WARN_ON_ONCE (true);
Signature · 1 line
2.14.4
PATCH 5/5 dm: prevent DAX mounts if not supported
In reply to Ross Zwislercommit dbc626597c39b24cefce09fbd8e9dea85869a801 upstream.
Currently device_supports_dax() just checks to see if the QUEUE_FLAG_DAX flag is set on the device's request queue to decide whether or not the device supports filesystem DAX. Really we should be using bdev_dax_supported() like filesystems do at mount time. This performs other tests like checking to make sure the dax_direct_access() path works.
We also explicitly clear QUEUE_FLAG_DAX on the DM device's request queue if any of the underlying devices do not support DAX. This makes the handling of QUEUE_FLAG_DAX consistent with the setting/clearing of most other flags in dm_table_set_restrictions().
Now that bdev_dax_supported() explicitly checks for QUEUE_FLAG_DAX, this will ensure that filesystems built upon DM devices will only be able to mount with DAX if all underlying devices also support DAX.
--- drivers/md/dm-table.c | 7 ++++--- drivers/md/dm.c | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/md/dm-table.c +4 -3
@@ -883,9 +883,7 @@ EXPORT_SYMBOL_GPL(dm_table_set_type);static int device_supports_dax (struct dm_target *ti,struct dm_dev *dev,sector_t start,sector_t len,void *data) { -struct request_queue *q =bdev_get_queue (dev->bdev); - -return q &&blk_queue_dax (q); +return bdev_dax_supported (dev->bdev,PAGE_SIZE ); }static bool dm_table_supports_dax (struct dm_table *t)
@@ -1815,6 +1813,9 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,if (dm_table_supports_dax (t))queue_flag_set_unlocked (QUEUE_FLAG_DAX , q); +else +queue_flag_clear_unlocked (QUEUE_FLAG_DAX , q); +if (dm_table_supports_dax_write_cache (t))dax_write_cache (t->md->dax_dev, true);
drivers/md/dm.c +1 -2
@@ -961,8 +961,7 @@ static long dm_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff,if (len <1 ) goto out; nr_pages =min (len, nr_pages); -if (ti->type->direct_access) - ret = ti->type->direct_access (ti, pgoff, nr_pages, kaddr, pfn); + ret = ti->type->direct_access (ti, pgoff, nr_pages, kaddr, pfn); out:dm_put_live_table (md, srcu_idx);
Signature · 1 line
2.14.4
Greg KH
maintainerQuoted 3 lines · Ross Zwisler
This is a v4.14-stable backport of my "Fix DM DAX handling" series which had backport collisions. This series also includes a few patches that were backport dependencies.
All now applied, thanks.
greg k-h