Skip to content

Commit a8078b1

Browse files
toshikanistellarhopper
authored andcommitted
block: Update blkdev_dax_capable() for consistency
blkdev_dax_capable() is similar to bdev_dax_supported(), but needs to remain as a separate interface for checking dax capability of a raw block device. Rename and relocate blkdev_dax_capable() to keep them maintained consistently, and call bdev_direct_access() for the dax capability check. There is no change in the behavior. Link: https://lkml.org/lkml/2016/5/9/950 Signed-off-by: Toshi Kani <[email protected]> Reviewed-by: Jan Kara <[email protected]> Cc: Alexander Viro <[email protected]> Cc: Jens Axboe <[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 1e937cd commit a8078b1

File tree

4 files changed

+38
-40
lines changed

4 files changed

+38
-40
lines changed

block/ioctl.c

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <linux/gfp.h>
55
#include <linux/blkpg.h>
66
#include <linux/hdreg.h>
7-
#include <linux/badblocks.h>
87
#include <linux/backing-dev.h>
98
#include <linux/fs.h>
109
#include <linux/blktrace_api.h>
@@ -407,35 +406,6 @@ static inline int is_unrecognized_ioctl(int ret)
407406
ret == -ENOIOCTLCMD;
408407
}
409408

410-
#ifdef CONFIG_FS_DAX
411-
bool blkdev_dax_capable(struct block_device *bdev)
412-
{
413-
struct gendisk *disk = bdev->bd_disk;
414-
415-
if (!disk->fops->direct_access)
416-
return false;
417-
418-
/*
419-
* If the partition is not aligned on a page boundary, we can't
420-
* do dax I/O to it.
421-
*/
422-
if ((bdev->bd_part->start_sect % (PAGE_SIZE / 512))
423-
|| (bdev->bd_part->nr_sects % (PAGE_SIZE / 512)))
424-
return false;
425-
426-
/*
427-
* If the device has known bad blocks, force all I/O through the
428-
* driver / page cache.
429-
*
430-
* TODO: support finer grained dax error handling
431-
*/
432-
if (disk->bb && disk->bb->count)
433-
return false;
434-
435-
return true;
436-
}
437-
#endif
438-
439409
static int blkdev_flushbuf(struct block_device *bdev, fmode_t mode,
440410
unsigned cmd, unsigned long arg)
441411
{

fs/block_dev.c

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/log2.h>
3030
#include <linux/cleancache.h>
3131
#include <linux/dax.h>
32+
#include <linux/badblocks.h>
3233
#include <asm/uaccess.h>
3334
#include "internal.h"
3435

@@ -554,6 +555,40 @@ int bdev_dax_supported(struct super_block *sb, int blocksize)
554555
}
555556
EXPORT_SYMBOL_GPL(bdev_dax_supported);
556557

558+
/**
559+
* bdev_dax_capable() - Return if the raw device is capable for dax
560+
* @bdev: The device for raw block device access
561+
*/
562+
bool bdev_dax_capable(struct block_device *bdev)
563+
{
564+
struct gendisk *disk = bdev->bd_disk;
565+
struct blk_dax_ctl dax = {
566+
.size = PAGE_SIZE,
567+
};
568+
569+
if (!IS_ENABLED(CONFIG_FS_DAX))
570+
return false;
571+
572+
dax.sector = 0;
573+
if (bdev_direct_access(bdev, &dax) < 0)
574+
return false;
575+
576+
dax.sector = bdev->bd_part->nr_sects - (PAGE_SIZE / 512);
577+
if (bdev_direct_access(bdev, &dax) < 0)
578+
return false;
579+
580+
/*
581+
* If the device has known bad blocks, force all I/O through the
582+
* driver / page cache.
583+
*
584+
* TODO: support finer grained dax error handling
585+
*/
586+
if (disk->bb && disk->bb->count)
587+
return false;
588+
589+
return true;
590+
}
591+
557592
/*
558593
* pseudo-fs
559594
*/
@@ -1295,7 +1330,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
12951330

12961331
if (!ret) {
12971332
bd_set_size(bdev,(loff_t)get_capacity(disk)<<9);
1298-
if (!blkdev_dax_capable(bdev))
1333+
if (!bdev_dax_capable(bdev))
12991334
bdev->bd_inode->i_flags &= ~S_DAX;
13001335
}
13011336

@@ -1332,7 +1367,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
13321367
goto out_clear;
13331368
}
13341369
bd_set_size(bdev, (loff_t)bdev->bd_part->nr_sects << 9);
1335-
if (!blkdev_dax_capable(bdev))
1370+
if (!bdev_dax_capable(bdev))
13361371
bdev->bd_inode->i_flags &= ~S_DAX;
13371372
}
13381373
} else {

include/linux/blkdev.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,7 @@ 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 *);
16911691
extern int bdev_dax_supported(struct super_block *, int);
1692+
extern bool bdev_dax_capable(struct block_device *);
16921693
#else /* CONFIG_BLOCK */
16931694

16941695
struct block_device;

include/linux/fs.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,14 +2319,6 @@ extern struct super_block *freeze_bdev(struct block_device *);
23192319
extern void emergency_thaw_all(void);
23202320
extern int thaw_bdev(struct block_device *bdev, struct super_block *sb);
23212321
extern int fsync_bdev(struct block_device *);
2322-
#ifdef CONFIG_FS_DAX
2323-
extern bool blkdev_dax_capable(struct block_device *bdev);
2324-
#else
2325-
static inline bool blkdev_dax_capable(struct block_device *bdev)
2326-
{
2327-
return false;
2328-
}
2329-
#endif
23302322

23312323
extern struct super_block *blockdev_superblock;
23322324

0 commit comments

Comments
 (0)