Skip to content

Commit 2d96afc

Browse files
toshikanistellarhopper
authored andcommitted
block: Add bdev_dax_supported() for dax mount checks
DAX imposes additional requirements to a device. Add bdev_dax_supported() which performs all the precondition checks necessary for filesystem to mount the device with dax option. Also add a new check to verify if a partition is aligned by 4KB. When a partition is unaligned, any dax read/write access fails, except for metadata update. Signed-off-by: Toshi Kani <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Cc: Alexander Viro <[email protected]> Cc: Jens Axboe <[email protected]> Cc: "Theodore Ts'o" <[email protected]> Cc: Andreas Dilger <[email protected]> Cc: Jan Kara <[email protected]> Cc: Dave Chinner <[email protected]> Cc: Dan Williams <[email protected]> Cc: Ross Zwisler <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Boaz Harrosh <[email protected]> Signed-off-by: Vishal Verma <[email protected]>
1 parent 2af3a81 commit 2d96afc

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

fs/block_dev.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,51 @@ long bdev_direct_access(struct block_device *bdev, struct blk_dax_ctl *dax)
509509
}
510510
EXPORT_SYMBOL_GPL(bdev_direct_access);
511511

512+
/**
513+
* bdev_dax_supported() - Check if the device supports dax for filesystem
514+
* @sb: The superblock of the device
515+
* @blocksize: The block size of the device
516+
*
517+
* This is a library function for filesystems to check if the block device
518+
* can be mounted with dax option.
519+
*
520+
* Return: negative errno if unsupported, 0 if supported.
521+
*/
522+
int bdev_dax_supported(struct super_block *sb, int blocksize)
523+
{
524+
struct blk_dax_ctl dax = {
525+
.sector = 0,
526+
.size = PAGE_SIZE,
527+
};
528+
int err;
529+
530+
if (blocksize != PAGE_SIZE) {
531+
vfs_msg(sb, KERN_ERR, "error: unsupported blocksize for dax");
532+
return -EINVAL;
533+
}
534+
535+
err = bdev_direct_access(sb->s_bdev, &dax);
536+
if (err < 0) {
537+
switch (err) {
538+
case -EOPNOTSUPP:
539+
vfs_msg(sb, KERN_ERR,
540+
"error: device does not support dax");
541+
break;
542+
case -EINVAL:
543+
vfs_msg(sb, KERN_ERR,
544+
"error: unaligned partition for dax");
545+
break;
546+
default:
547+
vfs_msg(sb, KERN_ERR,
548+
"error: dax access failed (%d)", err);
549+
}
550+
return err;
551+
}
552+
553+
return 0;
554+
}
555+
EXPORT_SYMBOL_GPL(bdev_dax_supported);
556+
512557
/*
513558
* pseudo-fs
514559
*/

include/linux/blkdev.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,7 @@ extern int bdev_read_page(struct block_device *, sector_t, struct page *);
16881688
extern int bdev_write_page(struct block_device *, sector_t, struct page *,
16891689
struct writeback_control *);
16901690
extern long bdev_direct_access(struct block_device *, struct blk_dax_ctl *);
1691+
extern int bdev_dax_supported(struct super_block *, int);
16911692
#else /* CONFIG_BLOCK */
16921693

16931694
struct block_device;

0 commit comments

Comments
 (0)