Skip to content

Commit fbbbad4

Browse files
Matthew Wilcoxtorvalds
authored andcommitted
vfs,ext2: introduce IS_DAX(inode)
Use an inode flag to tag inodes which should avoid using the page cache. Convert ext2 to use it instead of mapping_is_xip(). Prevent I/Os to files tagged with the DAX flag from falling back to buffered I/O. Signed-off-by: Matthew Wilcox <[email protected]> Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Mathieu Desnoyers <[email protected]> Cc: Andreas Dilger <[email protected]> Cc: Boaz Harrosh <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Dave Chinner <[email protected]> Cc: Jens Axboe <[email protected]> Cc: Kirill A. Shutemov <[email protected]> Cc: Randy Dunlap <[email protected]> Cc: Ross Zwisler <[email protected]> Cc: Theodore Ts'o <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 2e4cdab commit fbbbad4

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

fs/ext2/inode.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ static int ext2_get_blocks(struct inode *inode,
731731
goto cleanup;
732732
}
733733

734-
if (ext2_use_xip(inode->i_sb)) {
734+
if (IS_DAX(inode)) {
735735
/*
736736
* we need to clear the block
737737
*/
@@ -1201,7 +1201,7 @@ static int ext2_setsize(struct inode *inode, loff_t newsize)
12011201

12021202
inode_dio_wait(inode);
12031203

1204-
if (mapping_is_xip(inode->i_mapping))
1204+
if (IS_DAX(inode))
12051205
error = xip_truncate_page(inode->i_mapping, newsize);
12061206
else if (test_opt(inode->i_sb, NOBH))
12071207
error = nobh_truncate_page(inode->i_mapping,
@@ -1273,7 +1273,8 @@ void ext2_set_inode_flags(struct inode *inode)
12731273
{
12741274
unsigned int flags = EXT2_I(inode)->i_flags;
12751275

1276-
inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1276+
inode->i_flags &= ~(S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME |
1277+
S_DIRSYNC | S_DAX);
12771278
if (flags & EXT2_SYNC_FL)
12781279
inode->i_flags |= S_SYNC;
12791280
if (flags & EXT2_APPEND_FL)
@@ -1284,6 +1285,8 @@ void ext2_set_inode_flags(struct inode *inode)
12841285
inode->i_flags |= S_NOATIME;
12851286
if (flags & EXT2_DIRSYNC_FL)
12861287
inode->i_flags |= S_DIRSYNC;
1288+
if (test_opt(inode->i_sb, XIP))
1289+
inode->i_flags |= S_DAX;
12871290
}
12881291

12891292
/* Propagate flags from i_flags to EXT2_I(inode)->i_flags */

fs/ext2/xip.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ static inline int ext2_use_xip (struct super_block *sb)
1616
}
1717
int ext2_get_xip_mem(struct address_space *, pgoff_t, int,
1818
void **, unsigned long *);
19-
#define mapping_is_xip(map) unlikely(map->a_ops->get_xip_mem)
2019
#else
21-
#define mapping_is_xip(map) 0
2220
#define ext2_xip_verify_sb(sb) do { } while (0)
2321
#define ext2_use_xip(sb) 0
2422
#define ext2_clear_xip_target(inode, chain) 0

include/linux/fs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,11 @@ struct super_operations {
16771677
#define S_IMA 1024 /* Inode has an associated IMA struct */
16781678
#define S_AUTOMOUNT 2048 /* Automount/referral quasi-directory */
16791679
#define S_NOSEC 4096 /* no suid or xattr security attributes */
1680+
#ifdef CONFIG_FS_XIP
1681+
#define S_DAX 8192 /* Direct Access, avoiding the page cache */
1682+
#else
1683+
#define S_DAX 0 /* Make all the DAX code disappear */
1684+
#endif
16801685

16811686
/*
16821687
* Note that nosuid etc flags are inode-specific: setting some file-system
@@ -1714,6 +1719,7 @@ struct super_operations {
17141719
#define IS_IMA(inode) ((inode)->i_flags & S_IMA)
17151720
#define IS_AUTOMOUNT(inode) ((inode)->i_flags & S_AUTOMOUNT)
17161721
#define IS_NOSEC(inode) ((inode)->i_flags & S_NOSEC)
1722+
#define IS_DAX(inode) ((inode)->i_flags & S_DAX)
17171723

17181724
#define IS_WHITEOUT(inode) (S_ISCHR(inode->i_mode) && \
17191725
(inode)->i_rdev == WHITEOUT_DEV)

mm/filemap.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,9 +1723,11 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
17231723
* we've already read everything we wanted to, or if
17241724
* there was a short read because we hit EOF, go ahead
17251725
* and return. Otherwise fallthrough to buffered io for
1726-
* the rest of the read.
1726+
* the rest of the read. Buffered reads will not work for
1727+
* DAX files, so don't bother trying.
17271728
*/
1728-
if (retval < 0 || !iov_iter_count(iter) || *ppos >= size) {
1729+
if (retval < 0 || !iov_iter_count(iter) || *ppos >= size ||
1730+
IS_DAX(inode)) {
17291731
file_accessed(file);
17301732
goto out;
17311733
}
@@ -2587,13 +2589,16 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
25872589
loff_t endbyte;
25882590

25892591
written = generic_file_direct_write(iocb, from, pos);
2590-
if (written < 0 || written == count)
2591-
goto out;
2592-
25932592
/*
2594-
* direct-io write to a hole: fall through to buffered I/O
2595-
* for completing the rest of the request.
2593+
* If the write stopped short of completing, fall back to
2594+
* buffered writes. Some filesystems do this for writes to
2595+
* holes, for example. For DAX files, a buffered write will
2596+
* not succeed (even if it did, DAX does not handle dirty
2597+
* page-cache pages correctly).
25962598
*/
2599+
if (written < 0 || written == count || IS_DAX(inode))
2600+
goto out;
2601+
25972602
pos += written;
25982603
count -= written;
25992604

0 commit comments

Comments
 (0)