@@ -940,9 +940,6 @@ ext2_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
940
940
loff_t offset = iocb -> ki_pos ;
941
941
ssize_t ret ;
942
942
943
- if (WARN_ON_ONCE (IS_DAX (inode )))
944
- return - EIO ;
945
-
946
943
ret = blockdev_direct_IO (iocb , inode , iter , ext2_get_block );
947
944
if (ret < 0 && iov_iter_rw (iter ) == WRITE )
948
945
ext2_write_failed (mapping , offset + count );
@@ -952,17 +949,16 @@ ext2_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
952
949
static int
953
950
ext2_writepages (struct address_space * mapping , struct writeback_control * wbc )
954
951
{
955
- #ifdef CONFIG_FS_DAX
956
- if (dax_mapping (mapping )) {
957
- return dax_writeback_mapping_range (mapping ,
958
- mapping -> host -> i_sb -> s_bdev ,
959
- wbc );
960
- }
961
- #endif
962
-
963
952
return mpage_writepages (mapping , wbc , ext2_get_block );
964
953
}
965
954
955
+ static int
956
+ ext2_dax_writepages (struct address_space * mapping , struct writeback_control * wbc )
957
+ {
958
+ return dax_writeback_mapping_range (mapping ,
959
+ mapping -> host -> i_sb -> s_bdev , wbc );
960
+ }
961
+
966
962
const struct address_space_operations ext2_aops = {
967
963
.readpage = ext2_readpage ,
968
964
.readpages = ext2_readpages ,
@@ -990,6 +986,13 @@ const struct address_space_operations ext2_nobh_aops = {
990
986
.error_remove_page = generic_error_remove_page ,
991
987
};
992
988
989
+ static const struct address_space_operations ext2_dax_aops = {
990
+ .writepages = ext2_dax_writepages ,
991
+ .direct_IO = noop_direct_IO ,
992
+ .set_page_dirty = noop_set_page_dirty ,
993
+ .invalidatepage = noop_invalidatepage ,
994
+ };
995
+
993
996
/*
994
997
* Probably it should be a library function... search for first non-zero word
995
998
* or memcmp with zero_page, whatever is better for particular architecture.
@@ -1388,6 +1391,18 @@ void ext2_set_inode_flags(struct inode *inode)
1388
1391
inode -> i_flags |= S_DAX ;
1389
1392
}
1390
1393
1394
+ void ext2_set_file_ops (struct inode * inode )
1395
+ {
1396
+ inode -> i_op = & ext2_file_inode_operations ;
1397
+ inode -> i_fop = & ext2_file_operations ;
1398
+ if (IS_DAX (inode ))
1399
+ inode -> i_mapping -> a_ops = & ext2_dax_aops ;
1400
+ else if (test_opt (inode -> i_sb , NOBH ))
1401
+ inode -> i_mapping -> a_ops = & ext2_nobh_aops ;
1402
+ else
1403
+ inode -> i_mapping -> a_ops = & ext2_aops ;
1404
+ }
1405
+
1391
1406
struct inode * ext2_iget (struct super_block * sb , unsigned long ino )
1392
1407
{
1393
1408
struct ext2_inode_info * ei ;
@@ -1480,14 +1495,7 @@ struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
1480
1495
ei -> i_data [n ] = raw_inode -> i_block [n ];
1481
1496
1482
1497
if (S_ISREG (inode -> i_mode )) {
1483
- inode -> i_op = & ext2_file_inode_operations ;
1484
- if (test_opt (inode -> i_sb , NOBH )) {
1485
- inode -> i_mapping -> a_ops = & ext2_nobh_aops ;
1486
- inode -> i_fop = & ext2_file_operations ;
1487
- } else {
1488
- inode -> i_mapping -> a_ops = & ext2_aops ;
1489
- inode -> i_fop = & ext2_file_operations ;
1490
- }
1498
+ ext2_set_file_ops (inode );
1491
1499
} else if (S_ISDIR (inode -> i_mode )) {
1492
1500
inode -> i_op = & ext2_dir_inode_operations ;
1493
1501
inode -> i_fop = & ext2_dir_operations ;
0 commit comments