Enable per-file/directory DAX operations V2
Subsystems (10)
v2 cover Enable per-file/directory DAX operations V2
From: Ira Weiny <[email protected]>
At LSF/MM'19 [1] [2] we discussed applications that overestimate memory consumption due to their inability to detect whether the kernel will instantiate page cache for a file, and cases where a global dax enable via a mount option is too coarse.
The following patch series enables selecting the use of DAX on individual files and/or directories on xfs, and lays some groundwork to do so in ext4. In this scheme the dax mount option can be omitted to allow the per-file property to take effect.
The insight at LSF/MM was to separate the per-mount or per-file "physical" capability switch from an "effective" attribute for the file.
At LSF/MM we discussed the difficulties of switching the mode of a file with active mappings / page cache. It was thought the races could be avoided by limiting mode flips to 0-length files.
However, this turns out to not be true.[3] This is because address space operations (a_ops) may be in use at any time the inode is referenced and users have expressed a desire to be able to change the mode on a file with data in it. For those reasons this patch set allows changing the mode flag on a file as long as it is not current mapped.
Furthermore, DAX is a property of the inode and as such, many operations other than address space operations need to be protected during a mode change.
Therefore callbacks are placed within the inode operations and used to lock the inode as appropriate.
As in V1, Users are able to query the effective and physical flags separately at any time. Specifically the addition of the statx attribute bit allows them to ensure the file is operating in the mode they intend. This 'effective flag' and physical flags could differ when the filesystem is mounted with the dax flag for example.
It should be noted that the physical DAX flag inheritance is not shown in this patch set as it was maintained from previous work on XFS. The physical DAX flag and it's inheritance will need to be added to other file systems for user control.
Finally, extensive testing was performed which resulted in a couple of bug fix and clean up patches. Specifically:
fs: remove unneeded IS_DAX() check
fs/xfs: Fix truncate up
'Fix truncate up' deserves specific attention because I'm not 100% sure it is the correct fix. Without that patch fsx testing failed within a few minutes with this error.
Mapped Write: non-zero data past EOF (0x3b0da) page offset 0xdb is 0x3711
With 'Fix truncate up' running fsx while changing modes can run for hours but I have seen 2 other errors in the same genre after many hours of continuous testing.
They are:
READ BAD DATA: offset = 0x22dc, size = 0xcc7e, fname = /mnt/pmem/dax-file Mapped Read: non-zero data past EOF (0x3309e) page offset 0x9f is 0x6ab4
After seeing the patches to fix stale data exposure problems[4] I'm more confident now that all 3 of these errors are a latent bug rather than a bug in this series itself.
However, because of these failures I'm only submitting this set RFC.
[1] https://lwn.net/Articles/787973/
[2] https://lwn.net/Articles/787233/
[3] https://lkml.org/lkml/2019/10/20/96
[4] https://patchwork.kernel.org/patch/11310511/
To: [email protected]
Cc: Alexander Viro <[email protected]>
Cc: "Darrick J. Wong" <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Dave Chinner <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: "Theodore Y. Ts'o" <[email protected]>
Cc: Jan Kara <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
RFC PATCH v2 1/12 fs/stat: Define DAX statx attribute
From: Ira Weiny <[email protected]>
In order for users to determine if a file is currently operating in DAX mode (effective DAX). Define a statx attribute value and set that attribute if the effective DAX flag is set.
To go along with this we propose the following addition to the statx man page:
STATX_ATTR_DAX
DAX (cpu direct access) is a file mode that attempts to minimize software cache effects for both I/O and memory mappings of this file. It requires a capable device, a compatible filesystem block size, and filesystem opt-in. It generally assumes all accesses are via cpu load / store instructions which can minimize overhead for small accesses, but adversely affect cpu utilization for large transfers. File I/O is done directly to/from user-space buffers. While the DAX property tends to result in data being transferred synchronously it does not give the guarantees of synchronous I/O that data and necessary metadata are transferred. Memory mapped I/O may be performed with direct mappings that bypass system memory buffering. Again while memory-mapped I/O tends to result in data being transferred synchronously it does not guarantee synchronous metadata updates. A dax file may optionally support being mapped with the MAP_SYNC flag which does allow cpu store operations to be considered synchronous modulo cpu cache effects.
--- fs/stat.c | 3 +++ include/uapi/linux/stat.h | 1 + 2 files changed, 4 insertions(+)
fs/stat.c +3 -0
@@ -79,6 +79,9 @@ int vfs_getattr_nosec(const struct path *path, struct kstat *stat,if (IS_AUTOMOUNT (inode)) stat->attributes |=STATX_ATTR_AUTOMOUNT ; +if (IS_DAX (inode)) + stat->attributes |=STATX_ATTR_DAX ; +if (inode->i_op->getattr)return inode->i_op->getattr (path, stat, request_mask, query_flags);
include/uapi/linux/stat.h +1 -0
@@ -169,6 +169,7 @@ struct statx {#define STATX_ATTR_ENCRYPTED 0x00000800/* [I] File requires key to decrypt in fs */ #define STATX_ATTR_AUTOMOUNT 0x00001000/* Dir: Automount trigger */ #define STATX_ATTR_VERITY 0x00100000/* [I] Verity protected file */ +#define STATX_ATTR_DAX 0x00002000/* [I] File is DAX */ #endif /* _UAPI_LINUX_STAT_H */
Signature · 1 line
2.21.0
Re: [RFC PATCH V2 01/12] fs/stat: Define DAX statx attribute
Quoted 29 lines · On Fri 10-01-20 11:29:31, [email protected] wrote:
From: Ira Weiny <[email protected]>
In order for users to determine if a file is currently operating in DAX mode (effective DAX). Define a statx attribute value and set that attribute if the effective DAX flag is set.
To go along with this we propose the following addition to the statx man page:
STATX_ATTR_DAXDAX (cpu direct access) is a file mode that attempts to minimize software cache effects for both I/O and memory mappings of this file. It requires a capable device, a compatible filesystem block size, and filesystem opt-in. It generally assumes all accesses are via cpu load / store instructions which can minimize overhead for small accesses, but adversely affect cpu utilization for large transfers. File I/O is done directly to/from user-space buffers. While the DAX property tends to result in data being transferred synchronously it does not give the guarantees of synchronous I/O that data and necessary metadata are transferred. Memory mapped I/O may be performed with direct mappings that bypass system memory buffering. Again while memory-mapped I/O tends to result in data being transferred synchronously it does not guarantee synchronous metadata updates. A dax file may optionally support being mapped with the
MAP_SYNCflag which does allow cpu store operations to be considered synchronous modulo cpu cache effects.
Quoted 1 line
Signed-off-by Ira Weiny <[email protected]>
This looks good to me. You can add:
Honza
Quoted 34 lines
--- fs/stat.c | 3 +++ include/uapi/linux/stat.h | 1 + 2 files changed, 4 insertions(+)fs/stat.c +3
-0@@ -79,6 +79,9 @@ int vfs_getattr_nosec(const struct path *path, struct kstat *stat,if (IS_AUTOMOUNT (inode)) stat->attributes |=STATX_ATTR_AUTOMOUNT ; +if (IS_DAX (inode)) + stat->attributes |=STATX_ATTR_DAX ; +if (inode->i_op->getattr)return inode->i_op->getattr (path, stat, request_mask, query_flags);include/uapi/linux/stat.h +1
-0@@ -169,6 +169,7 @@ struct statx {#define STATX_ATTR_ENCRYPTED 0x00000800/* [I] File requires key to decrypt in fs */ #define STATX_ATTR_AUTOMOUNT 0x00001000/* Dir: Automount trigger */ #define STATX_ATTR_VERITY 0x00100000/* [I] Verity protected file */ +#define STATX_ATTR_DAX 0x00002000/* [I] File is DAX */ #endif /* _UAPI_LINUX_STAT_H */ Signature · 1 line
2.21.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [RFC PATCH V2 01/12] fs/stat: Define DAX statx attribute
Quoted 7 lines · Jan Kara
Quoted 6 lines · On Fri 10-01-20 11:29:31, [email protected] wrote:
From: Ira Weiny <[email protected]>
In order for users to determine if a file is currently operating in DAX mode (effective DAX). Define a statx attribute value and set that attribute if the effective DAX flag is set.
Quoted 6 lines
Quoted 6 lines
To go along with this we propose the following addition to the statx man page:
STATX_ATTR_DAXDAX (cpu direct access) is a file mode that attempts to minimize
"..is a file I/O mode"?
Quoted 3 lines
Quoted 3 lines
software cache effects for both I/O and memory mappings of this file. It requires a capable device, a compatible filesystem block size, and filesystem opt-in.
"...a capable storage device..."
What does "compatible fs block size" mean? How does the user figure out if their fs blocksize is compatible? Do we tell users to refer their filesystem's documentation here?
Quoted 4 lines
Quoted 4 lines
It generally assumes all
accesses are via cpu load / store instructions which can minimize overhead for small accesses, but adversely affect cpu utilization for large transfers.
Will this always be true for persistent memory?
I wasn't even aware that large transfers adversely affected CPU utilization. ;)
Quoted 3 lines
Quoted 3 lines
File I/O is done directly
to/from user-space buffers. While the DAX property tends to result in data being transferred synchronously it does not give
"...transferred synchronously, it does not..."
Quoted 1 line
Quoted 1 line
the guarantees of synchronous I/O that data and necessary
"...it does not guarantee that I/O or file metadata have been flushed to the storage device."
Quoted 2 lines
Quoted 2 lines
metadata are transferred. Memory mapped I/O may be performed with direct mappings that bypass system memory buffering.
"...with direct memory mappings that bypass kernel page cache."
Quoted 2 lines
Quoted 2 lines
Again
while memory-mapped I/O tends to result in data being
I would move the sentence about "Memory mapped I/O..." to directly after the sentence about file I/O being done directly to and from userspace so that you don't need to repeat this statement.
Quoted 4 lines
Quoted 4 lines
transferred synchronously it does not guarantee synchronous metadata updates. A dax file may optionally support being mapped with the
MAP_SYNCflag which does allow cpu store operations to be considered synchronous modulo cpu cache effects.
How does one detect or work around or deal with "cpu cache effects"? I assume some sort of CPU cache flush instruction is what is meant here, but I think we could mention the basics of what has to be done here:
"A DAX file may support being mapped with the MAP_SYNC flag, which enables a program to use CPU cache flush operations to persist CPU store operations without an explicit fsync(2). See mmap(2) for more information."?
Oof, a paragraph break would be nice. :)
--D
Quoted 46 lines
Quoted 2 lines
Signed-off-by Ira Weiny <[email protected]>This looks good to me. You can add:
Reviewed-by Jan Kara <[email protected]>Honza
Quoted 34 lines
--- fs/stat.c | 3 +++ include/uapi/linux/stat.h | 1 + 2 files changed, 4 insertions(+)fs/stat.c +3
-0@@ -79,6 +79,9 @@ int vfs_getattr_nosec(const struct path *path, struct kstat *stat,if (IS_AUTOMOUNT (inode)) stat->attributes |=STATX_ATTR_AUTOMOUNT ; +if (IS_DAX (inode)) + stat->attributes |=STATX_ATTR_DAX ; +if (inode->i_op->getattr)return inode->i_op->getattr (path, stat, request_mask, query_flags);include/uapi/linux/stat.h +1
-0@@ -169,6 +169,7 @@ struct statx {#define STATX_ATTR_ENCRYPTED 0x00000800/* [I] File requires key to decrypt in fs */ #define STATX_ATTR_AUTOMOUNT 0x00001000/* Dir: Automount trigger */ #define STATX_ATTR_VERITY 0x00100000/* [I] Verity protected file */ +#define STATX_ATTR_DAX 0x00002000/* [I] File is DAX */ #endif /* _UAPI_LINUX_STAT_H */ Signature · 1 line
2.21.0Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [RFC PATCH V2 01/12] fs/stat: Define DAX statx attribute
Quoted 8 lines · Darrick J. Wong
Quoted 7 lines · Jan Kara
Quoted 6 lines · On Fri 10-01-20 11:29:31, [email protected] wrote:
From: Ira Weiny <[email protected]>
In order for users to determine if a file is currently operating in DAX mode (effective DAX). Define a statx attribute value and set that attribute if the effective DAX flag is set.
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
To go along with this we propose the following addition to the statx man page:
STATX_ATTR_DAXDAX (cpu direct access) is a file mode that attempts to minimize
"..is a file I/O mode"?
or "... is a file state ..."?
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
software cache effects for both I/O and memory mappings of this file. It requires a capable device, a compatible filesystem block size, and filesystem opt-in.
"...a capable storage device..."
Done
Quoted 4 lines
What does "compatible fs block size" mean? How does the user figure out if their fs blocksize is compatible? Do we tell users to refer their filesystem's documentation here?
Perhaps it is wrong for this to be in the man page at all? Would it be better to assume the file system and block device are already configured properly by the admin?
For which the blocksize restrictions are already well documented. ie:
https://www.kernel.org/doc/Documentation/filesystems/dax.txt
?
How about changing the text to:
It requires a block device and file system which have been configured to support DAX.
?
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
It generally assumes all
accesses are via cpu load / store instructions which can minimize overhead for small accesses, but adversely affect cpu utilization for large transfers.Will this always be true for persistent memory?
I'm not clear. Did you mean; "this" == adverse utilization for large transfers?
Quoted 3 lines
I wasn't even aware that large transfers adversely affected CPU utilization. ;)
Sure vs using a DMA engine for example.
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
File I/O is done directly
to/from user-space buffers. While the DAX property tends to result in data being transferred synchronously it does not give"...transferred synchronously, it does not..."
done.
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
the guarantees of synchronous I/O that data and necessary
"...it does not guarantee that I/O or file metadata have been flushed to the storage device."
The lack of guarantee here is mainly regarding metadata.
How about:
While the DAX property tends to result in data being transferred synchronously, it does not give the same guarantees of synchronous I/O where data and the necessary metadata are transferred together.
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
metadata are transferred. Memory mapped I/O may be performed with direct mappings that bypass system memory buffering.
"...with direct memory mappings that bypass kernel page cache."
Done.
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Again
while memory-mapped I/O tends to result in data beingI would move the sentence about "Memory mapped I/O..." to directly after the sentence about file I/O being done directly to and from userspace so that you don't need to repeat this statement.
Done.
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
transferred synchronously it does not guarantee synchronous metadata updates. A dax file may optionally support being mapped with the
MAP_SYNCflag which does allow cpu store operations to be considered synchronous modulo cpu cache effects.
Quoted 8 lines
How does one detect or work around or deal with "cpu cache effects"? I assume some sort of CPU cache flush instruction is what is meant here, but I think we could mention the basics of what has to be done here:
"A DAX file may support being mapped with the
MAP_SYNCflag, which enables a program to use CPU cache flush operations to persist CPU store operations without an explicit fsync(2). See mmap(2) for more information."?
That sounds better. I like the reference to mmap as well.
Ok I changed a couple of things as well. How does this sound?
STATX_ATTR_DAX
DAX (cpu direct access) is a file mode that attempts to minimize software cache effects for both I/O and memory mappings of this file. It requires a block device and file system which have been configured to support DAX.
DAX generally assumes all accesses are via cpu load / store instructions which can minimize overhead for small accesses, but may adversely affect cpu utilization for large transfers.
File I/O is done directly to/from user-space buffers and memory mapped I/O may be performed with direct memory mappings that bypass kernel page cache.
While the DAX property tends to result in data being transferred synchronously, it does not give the same guarantees of synchronous I/O where data and the necessary metadata are transferred together.
A DAX file may support being mapped with the MAP_SYNC flag, which enables a program to use CPU cache flush operations to persist CPU store operations without an explicit fsync(2). See mmap(2) for more information.
Ira
Quoted 51 lines
Oof, a paragraph break would be nice. :)
--D
Quoted 46 lines
Quoted 2 lines
Signed-off-by Ira Weiny <[email protected]>This looks good to me. You can add:
Reviewed-by Jan Kara <[email protected]>Honza
Quoted 34 lines
--- fs/stat.c | 3 +++ include/uapi/linux/stat.h | 1 + 2 files changed, 4 insertions(+)fs/stat.c +3
-0@@ -79,6 +79,9 @@ int vfs_getattr_nosec(const struct path *path, struct kstat *stat,if (IS_AUTOMOUNT (inode)) stat->attributes |=STATX_ATTR_AUTOMOUNT ; +if (IS_DAX (inode)) + stat->attributes |=STATX_ATTR_DAX ; +if (inode->i_op->getattr)return inode->i_op->getattr (path, stat, request_mask, query_flags);include/uapi/linux/stat.h +1
-0@@ -169,6 +169,7 @@ struct statx {#define STATX_ATTR_ENCRYPTED 0x00000800/* [I] File requires key to decrypt in fs */ #define STATX_ATTR_AUTOMOUNT 0x00001000/* Dir: Automount trigger */ #define STATX_ATTR_VERITY 0x00100000/* [I] Verity protected file */ +#define STATX_ATTR_DAX 0x00002000/* [I] File is DAX */ #endif /* _UAPI_LINUX_STAT_H */ Signature · 1 line
2.21.0Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [RFC PATCH V2 01/12] fs/stat: Define DAX statx attribute
Quoted 42 lines · Ira Weiny
Quoted 8 lines · Darrick J. Wong
Quoted 7 lines · Jan Kara
Quoted 6 lines · On Fri 10-01-20 11:29:31, [email protected] wrote:
From: Ira Weiny <[email protected]>
In order for users to determine if a file is currently operating in DAX mode (effective DAX). Define a statx attribute value and set that attribute if the effective DAX flag is set.
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
To go along with this we propose the following addition to the statx man page:
STATX_ATTR_DAXDAX (cpu direct access) is a file mode that attempts to minimize
"..is a file I/O mode"?
or "... is a file state ..."?
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
software cache effects for both I/O and memory mappings of this file. It requires a capable device, a compatible filesystem block size, and filesystem opt-in.
"...a capable storage device..."
Done
Quoted 4 lines
What does "compatible fs block size" mean? How does the user figure out if their fs blocksize is compatible? Do we tell users to refer their filesystem's documentation here?
Perhaps it is wrong for this to be in the man page at all? Would it be better to assume the file system and block device are already configured properly by the admin?
For which the blocksize restrictions are already well documented. ie:
https://www.kernel.org/doc/Documentation/filesystems/dax.txt
Quoted 8 lines
?
How about changing the text to:
It requires a block device and file system which have been configured to support DAX.
?
The goal was to document the gauntlet of checks that __generic_fsdax_supported() performs so someone could debug "why am I not able to get dax operation?"
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
It generally assumes all
accesses are via cpu load / store instructions which can minimize overhead for small accesses, but adversely affect cpu utilization for large transfers.Will this always be true for persistent memory?
For direct-mapped pmem there is no opportunity to do dma offload so it will always be true that application dax access consumes cpu to do I/O where something like NVMe does not. There has been unfruitful to date experiments with the driver using an offload engine for kernel internal I/O, but if you're use case is kernel internal I/O bound then you don't need dax.
Quoted 8 lines
I'm not clear. Did you mean; "this" == adverse utilization for large transfers?
Quoted 3 lines
I wasn't even aware that large transfers adversely affected CPU utilization. ;)
Sure vs using a DMA engine for example.
Right, this is purely a statement about cpu memcpy vs device-dma.
Quoted 58 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
File I/O is done directly
to/from user-space buffers. While the DAX property tends to result in data being transferred synchronously it does not give"...transferred synchronously, it does not..."
done.
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
the guarantees of synchronous I/O that data and necessary
"...it does not guarantee that I/O or file metadata have been flushed to the storage device."
The lack of guarantee here is mainly regarding metadata.
How about:
While the DAX property tends to result in data being transferred synchronously, it does not give the same guarantees of synchronous I/O where data and the necessary metadata are transferred together.
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
metadata are transferred. Memory mapped I/O may be performed with direct mappings that bypass system memory buffering.
"...with direct memory mappings that bypass kernel page cache."
Done.
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Again
while memory-mapped I/O tends to result in data beingI would move the sentence about "Memory mapped I/O..." to directly after the sentence about file I/O being done directly to and from userspace so that you don't need to repeat this statement.
Done.
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
transferred synchronously it does not guarantee synchronous metadata updates. A dax file may optionally support being mapped with the
MAP_SYNCflag which does allow cpu store operations to be considered synchronous modulo cpu cache effects.Quoted 8 lines
How does one detect or work around or deal with "cpu cache effects"? I assume some sort of CPU cache flush instruction is what is meant here, but I think we could mention the basics of what has to be done here:
"A DAX file may support being mapped with the
MAP_SYNCflag, which enables a program to use CPU cache flush operations to persist CPU store operations without an explicit fsync(2). See mmap(2) for more information."?
Quoted 8 lines
That sounds better. I like the reference to mmap as well.
Ok I changed a couple of things as well. How does this sound?
STATX_ATTR_DAXDAX (cpu direct access) is a file mode that attempts to minimize
s/mode/state/?
Quoted 3 lines
software cache effects for both I/O and memory mappings of this file. It requires a block device and file system which have been configured to support DAX.
It may not require a block device in the future.
Quoted 5 lines
DAX generally assumes all accesses are via cpu load / store instructions which can minimize overhead for small accesses, but may adversely affect cpu utilization for large transfers.
Quoted 7 lines
File I/O is done directly to/from user-space buffers and memory mapped I/O may be performed with direct memory mappings that bypass kernel page cache.
While the DAX property tends to result in data being transferred synchronously, it does not give the same guarantees of synchronous I/O where data and the necessary metadata are
Maybe use "O_SYNC I/O" explicitly to further differentiate the 2 meanings of "synchronous" in this sentence?
Quoted 4 lines
transferred together.
A DAX file may support being mapped with the
MAP_SYNCflag, which enables a program to use CPU cache flush operations to
s/operations/instructions/
Quoted 2 lines
persist CPU store operations without an explicit fsync(2). See mmap(2) for more information.
I think this also wants a reference to the Linux interpretation of platform "persistence domains" we were discussing that here [1], but maybe it should be part of a "pmem" manpage that can be referenced from this man page.
Re: [RFC PATCH V2 01/12] fs/stat: Define DAX statx attribute
Quoted 7 lines · Dan Williams
Quoted 6 lines · Ira Weiny
Quoted 4 lines · Darrick J. Wong
Quoted 3 lines · Jan Kara
Quoted 2 lines · On Fri 10-01-20 11:29:31, [email protected] wrote:
From: Ira Weiny <[email protected]>
[snip]
Quoted 8 lines
Quoted 6 lines
Ok I changed a couple of things as well. How does this sound?
STATX_ATTR_DAXDAX (cpu direct access) is a file mode that attempts to minimize
s/mode/state/?
DOH! yes state... ;-)
Quoted 6 lines
Quoted 4 lines
software cache effects for both I/O and memory mappings of this file. It requires a block device and file system which have been configured to support DAX.
It may not require a block device in the future.
Ok:
"It requires a file system which has been configured to support DAX." ?
I'm trying to separate the user of the individual STATX DAX flag from the Admin details of configuring the file system and/or devices which supports it.
Also, I just realized that we should follow the format of the other STATX_* attributes. They all read something like "the file is..."
So I'm adding that text as well.
Quoted 10 lines
Quoted 10 lines
DAX generally assumes all accesses are via cpu load / store instructions which can minimize overhead for small accesses, but may adversely affect cpu utilization for large transfers.
File I/O is done directly to/from user-space buffers and memory mapped I/O may be performed with direct memory mappings that bypass kernel page cache.
Quoted 6 lines
Quoted 3 lines
While the DAX property tends to result in data being transferred synchronously, it does not give the same guarantees of synchronous I/O where data and the necessary metadata are
Maybe use "
O_SYNCI/O" explicitly to further differentiate the 2 meanings of "synchronous" in this sentence?
Done.
Quoted 7 lines
Quoted 5 lines
transferred together.
A DAX file may support being mapped with the
MAP_SYNCflag, which enables a program to use CPU cache flush operations tos/operations/instructions/
Done.
Quoted 8 lines
Quoted 3 lines
persist CPU store operations without an explicit fsync(2). See mmap(2) for more information.
I think this also wants a reference to the Linux interpretation of platform "persistence domains" we were discussing that here [1], but maybe it should be part of a "pmem" manpage that can be referenced from this man page.
Sure, but for now I think referencing mmap for details on MAP_SYNC works.
I suspect that we may have some word smithing once I get this series in and we submit a change to the statx man page itself. Can I move forward with the following for this patch?
<quote>STATX_ATTR_DAX
The file is in the DAX (cpu direct access) state. DAX state attempts to minimize software cache effects for both I/O and memory mappings of this file. It requires a file system which has been configured to support DAX.
DAX generally assumes all accesses are via cpu load / store instructions which can minimize overhead for small accesses, but may adversely affect cpu utilization for large transfers.
File I/O is done directly to/from user-space buffers and memory mapped I/O may be performed with direct memory mappings that bypass kernel page cache.
While the DAX property tends to result in data being transferred synchronously, it does not give the same guarantees of synchronous I/O where data and the necessary metadata are transferred together.
A DAX file may support being mapped with the MAP_SYNC flag, which enables a program to use CPU cache flush instructions to persist CPU store operations without an explicit fsync(2). See mmap(2) for more information.
</quote>
Ira
Quoted 2 lines
Re: [RFC PATCH V2 01/12] fs/stat: Define DAX statx attribute
Quoted 81 lines · Ira Weiny
Quoted 7 lines · Dan Williams
Quoted 6 lines · Ira Weiny
Quoted 4 lines · Darrick J. Wong
Quoted 3 lines · Jan Kara
Quoted 2 lines · On Fri 10-01-20 11:29:31, [email protected] wrote:
From: Ira Weiny <[email protected]>
[snip]
Quoted 8 lines
Quoted 6 lines
Ok I changed a couple of things as well. How does this sound?
STATX_ATTR_DAXDAX (cpu direct access) is a file mode that attempts to minimize
s/mode/state/?
DOH! yes state... ;-)
Quoted 6 lines
Quoted 4 lines
software cache effects for both I/O and memory mappings of this file. It requires a block device and file system which have been configured to support DAX.
It may not require a block device in the future.
Ok:
"It requires a file system which has been configured to support DAX." ?
I'm trying to separate the user of the individual STATX DAX flag from the Admin details of configuring the file system and/or devices which supports it.
Also, I just realized that we should follow the format of the other STATX_* attributes. They all read something like "the file is..."
So I'm adding that text as well.
Quoted 10 lines
Quoted 10 lines
DAX generally assumes all accesses are via cpu load / store instructions which can minimize overhead for small accesses, but may adversely affect cpu utilization for large transfers.
File I/O is done directly to/from user-space buffers and memory mapped I/O may be performed with direct memory mappings that bypass kernel page cache.
Quoted 6 lines
Quoted 3 lines
While the DAX property tends to result in data being transferred synchronously, it does not give the same guarantees of synchronous I/O where data and the necessary metadata are
Maybe use "
O_SYNCI/O" explicitly to further differentiate the 2 meanings of "synchronous" in this sentence?Done.
Quoted 7 lines
Quoted 5 lines
transferred together.
A DAX file may support being mapped with the
MAP_SYNCflag, which enables a program to use CPU cache flush operations tos/operations/instructions/
Done.
Quoted 8 lines
Quoted 3 lines
persist CPU store operations without an explicit fsync(2). See mmap(2) for more information.
I think this also wants a reference to the Linux interpretation of platform "persistence domains" we were discussing that here [1], but maybe it should be part of a "pmem" manpage that can be referenced from this man page.
Sure, but for now I think referencing mmap for details on
MAP_SYNCworks.
Quoted 8 lines
I suspect that we may have some word smithing once I get this series in and we submit a change to the statx man page itself. Can I move forward with the following for this patch?
<quote>
STATX_ATTR_DAXThe file is in the DAX (cpu direct access) state. DAX state
Hmm, now that I see it written out, I <cough> kind of like "DAX mode" better now. :/
"The file is in DAX (CPU direct access) mode. DAX mode attempts..."
Quoted 8 lines
attempts to minimize software cache effects for both I/O and memory mappings of this file. It requires a file system which has been configured to support DAX.
DAX generally assumes all accesses are via cpu load / store instructions which can minimize overhead for small accesses, but may adversely affect cpu utilization for large transfers.
Quoted 8 lines
File I/O is done directly to/from user-space buffers and memory mapped I/O may be performed with direct memory mappings that bypass kernel page cache.
While the DAX property tends to result in data being transferred synchronously, it does not give the same guarantees of synchronous I/O where data and the necessary metadata are transferred together.
(I'm frankly not sure that synchronous I/O actually guarantees that the metadata has hit stable storage...)
--D
Quoted 10 lines
A DAX file may support being mapped with the
MAP_SYNCflag, which enables a program to use CPU cache flush instructions to persist CPU store operations without an explicit fsync(2). See mmap(2) for more information.
</quote>Ira
Quoted 2 lines
Re: [RFC PATCH V2 01/12] fs/stat: Define DAX statx attribute
On Wed, Jan 15, 2020 at 9:39 PM Darrick J. Wong <[email protected]> wrote:
[..]
Quoted 12 lines
Quoted 12 lines
attempts to minimize software cache effects for both I/O and memory mappings of this file. It requires a file system which has been configured to support DAX.
DAX generally assumes all accesses are via cpu load / store instructions which can minimize overhead for small accesses, but may adversely affect cpu utilization for large transfers.
File I/O is done directly to/from user-space buffers and memory mapped I/O may be performed with direct memory mappings that bypass kernel page cache.
Quoted 7 lines
Quoted 4 lines
While the DAX property tends to result in data being transferred synchronously, it does not give the same guarantees of synchronous I/O where data and the necessary metadata are transferred together.
(I'm frankly not sure that synchronous I/O actually guarantees that the metadata has hit stable storage...)
Oh? That text was motivated by the open(2) man page description of O_SYNC.
Re: [RFC PATCH V2 01/12] fs/stat: Define DAX statx attribute
Quoted 19 lines · Dan Williams
On Wed, Jan 15, 2020 at 9:39 PM Darrick J. Wong <[email protected]> wrote:
[..]Quoted 17 lines
Quoted 16 lines
attempts to minimize software cache effects for both I/O and memory mappings of this file. It requires a file system which has been configured to support DAX.
DAX generally assumes all accesses are via cpu load / store instructions which can minimize overhead for small accesses, but may adversely affect cpu utilization for large transfers.
File I/O is done directly to/from user-space buffers and memory mapped I/O may be performed with direct memory mappings that bypass kernel page cache.
While the DAX property tends to result in data being transferred synchronously, it does not give the same guarantees of synchronous I/O where data and the necessary metadata are transferred together.
Quoted 4 lines
Quoted 2 lines
(I'm frankly not sure that synchronous I/O actually guarantees that the metadata has hit stable storage...)
Oh? That text was motivated by the open(2) man page description of
O_SYNC.
Eh, that's just me being cynical about software. Yes, the O_SYNC docs say that data+metadata are supposed to happen; that's good enough for another section in the man pages. :)
--D
Re: [RFC PATCH V2 01/12] fs/stat: Define DAX statx attribute
Quoted 21 lines · Darrick J. Wong
Quoted 19 lines · Dan Williams
On Wed, Jan 15, 2020 at 9:39 PM Darrick J. Wong <[email protected]> wrote:
[..]Quoted 17 lines
Quoted 16 lines
attempts to minimize software cache effects for both I/O and memory mappings of this file. It requires a file system which has been configured to support DAX.
DAX generally assumes all accesses are via cpu load / store instructions which can minimize overhead for small accesses, but may adversely affect cpu utilization for large transfers.
File I/O is done directly to/from user-space buffers and memory mapped I/O may be performed with direct memory mappings that bypass kernel page cache.
While the DAX property tends to result in data being transferred synchronously, it does not give the same guarantees of synchronous I/O where data and the necessary metadata are transferred together.
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
(I'm frankly not sure that synchronous I/O actually guarantees that the metadata has hit stable storage...)
Oh? That text was motivated by the open(2) man page description of
O_SYNC.Eh, that's just me being cynical about software. Yes, the
O_SYNCdocs say that data+metadata are supposed to happen; that's good enough for another section in the man pages. :)
Ah ok, yes, "all storage is a lie".
Re: [RFC PATCH V2 01/12] fs/stat: Define DAX statx attribute
In reply to Dan WilliamsQuoted 19 lines · Dan Williams
On Wed, Jan 15, 2020 at 9:39 PM Darrick J. Wong <[email protected]> wrote:
[..]Quoted 17 lines
Quoted 16 lines
attempts to minimize software cache effects for both I/O and memory mappings of this file. It requires a file system which has been configured to support DAX.
DAX generally assumes all accesses are via cpu load / store instructions which can minimize overhead for small accesses, but may adversely affect cpu utilization for large transfers.
File I/O is done directly to/from user-space buffers and memory mapped I/O may be performed with direct memory mappings that bypass kernel page cache.
While the DAX property tends to result in data being transferred synchronously, it does not give the same guarantees of synchronous I/O where data and the necessary metadata are transferred together.
Quoted 4 lines
Quoted 2 lines
(I'm frankly not sure that synchronous I/O actually guarantees that the metadata has hit stable storage...)
Oh? That text was motivated by the open(2) man page description of
O_SYNC.
Ugh. "synchronous I/O" means two different things, depending on context. In the AIO context, it means "process context waits for operation completion direct", but in the O_SYNC context, it means "we guarantee data integrity for each I/O submitted".
Indeed, O_SYNC AIO is a thing. i.e. we can do an "async sync write" to guarantee data integrity without directly waiting for it. Now try describing that only using the words "synchronous write" to describe both behaviours. :)
IOWs, if you are talking about data integrity, you need to explicitly say "O_SYNC semantics", not "synchronous write", because "synchronous write" is totally ambiguous without the O_SYNC context of the open(2) man page...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [RFC PATCH V2 01/12] fs/stat: Define DAX statx attribute
In reply to Darrick J. WongQuoted 10 lines · Darrick J. Wong
Quoted 9 lines · Ira Weiny
Quoted 7 lines · Dan Williams
Quoted 6 lines · Ira Weiny
Quoted 4 lines · Darrick J. Wong
Quoted 3 lines · Jan Kara
Quoted 2 lines · On Fri 10-01-20 11:29:31, [email protected] wrote:
From: Ira Weiny <[email protected]>
[snip]
Quoted 10 lines
Quoted 10 lines
Sure, but for now I think referencing mmap for details on
MAP_SYNCworks.I suspect that we may have some word smithing once I get this series in and we submit a change to the statx man page itself. Can I move forward with the following for this patch?
<quote>
STATX_ATTR_DAX
Quoted 6 lines
Quoted 1 line
The file is in the DAX (cpu direct access) state. DAX state
Hmm, now that I see it written out, I <cough> kind of like "DAX mode" better now. :/
"The file is in DAX (CPU direct access) mode. DAX mode attempts..."
Sure... now you tell me... ;-)
Seriously, we could use mode here in the man page as this is less confusing to say "DAX mode".
But I think the code should still use 'state' because mode is just too overloaded. You were not the only one who was thrown by my use of mode and I don't want that confusion when we look at this code 2 weeks from now...
https://www.reddit.com/r/ProgrammerHumor/comments/852og2/only_god_knows/
;-)
Quoted 13 lines
Quoted 13 lines
attempts to minimize software cache effects for both I/O and memory mappings of this file. It requires a file system which has been configured to support DAX.
DAX generally assumes all accesses are via cpu load / store instructions which can minimize overhead for small accesses, but may adversely affect cpu utilization for large transfers.
File I/O is done directly to/from user-space buffers and memory mapped I/O may be performed with direct memory mappings that bypass kernel page cache.
Quoted 7 lines
Quoted 4 lines
While the DAX property tends to result in data being transferred synchronously, it does not give the same guarantees of synchronous I/O where data and the necessary metadata are transferred together.
(I'm frankly not sure that synchronous I/O actually guarantees that the metadata has hit stable storage...)
I'll let you and Dan work this one out... ;-)
Ira
Re: [RFC PATCH V2 01/12] fs/stat: Define DAX statx attribute
Quoted 36 lines · Ira Weiny
Quoted 10 lines · Darrick J. Wong
Quoted 9 lines · Ira Weiny
Quoted 7 lines · Dan Williams
Quoted 6 lines · Ira Weiny
Quoted 4 lines · Darrick J. Wong
Quoted 3 lines · Jan Kara
Quoted 2 lines · On Fri 10-01-20 11:29:31, [email protected] wrote:
From: Ira Weiny <[email protected]>
[snip]
Quoted 10 lines
Quoted 10 lines
Sure, but for now I think referencing mmap for details on
MAP_SYNCworks.I suspect that we may have some word smithing once I get this series in and we submit a change to the statx man page itself. Can I move forward with the following for this patch?
<quote>
STATX_ATTR_DAXQuoted 6 lines
Quoted 1 line
The file is in the DAX (cpu direct access) state. DAX state
Hmm, now that I see it written out, I <cough> kind of like "DAX mode" better now. :/
"The file is in DAX (CPU direct access) mode. DAX mode attempts..."
Sure... now you tell me... ;-)
Seriously, we could use mode here in the man page as this is less confusing to say "DAX mode".
Quoted 7 lines
But I think the code should still use 'state' because mode is just too overloaded. You were not the only one who was thrown by my use of mode and I don't want that confusion when we look at this code 2 weeks from now...
https://www.reddit.com/r/ProgrammerHumor/comments/852og2/only_god_knows/
;-)
Ok, let's leave it alone for now then.
I'm not even sure what 'DAX' stands for. Direct Access to ... Professor Xavier? 8-)
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
attempts to minimize software cache effects for both I/O and memory mappings of this file. It requires a file system which has been configured to support DAX.
DAX generally assumes all accesses are via cpu load / store instructions which can minimize overhead for small accesses, but may adversely affect cpu utilization for large transfers.
File I/O is done directly to/from user-space buffers and memory mapped I/O may be performed with direct memory mappings that bypass kernel page cache.
While the DAX property tends to result in data being transferred synchronously, it does not give the same guarantees of synchronous I/O where data and the necessary metadata are transferred together.
Quoted 4 lines
Quoted 2 lines
(I'm frankly not sure that synchronous I/O actually guarantees that the metadata has hit stable storage...)
I'll let you and Dan work this one out... ;-)
Hehe. I think the wording here is fine.
--D
Quoted 2 lines
Ira
Re: [RFC PATCH V2 01/12] fs/stat: Define DAX statx attribute
Quoted 41 lines · Darrick J. Wong
Quoted 40 lines · Ira Weiny
Quoted 10 lines · Darrick J. Wong
Quoted 9 lines · Ira Weiny
Quoted 7 lines · Dan Williams
Quoted 6 lines · Ira Weiny
Quoted 4 lines · Darrick J. Wong
Quoted 3 lines · Jan Kara
Quoted 2 lines · On Fri 10-01-20 11:29:31, [email protected] wrote:
From: Ira Weiny <[email protected]>
[snip]
Quoted 10 lines
Quoted 10 lines
Sure, but for now I think referencing mmap for details on
MAP_SYNCworks.I suspect that we may have some word smithing once I get this series in and we submit a change to the statx man page itself. Can I move forward with the following for this patch?
<quote>
STATX_ATTR_DAXQuoted 6 lines
Quoted 1 line
The file is in the DAX (cpu direct access) state. DAX state
Hmm, now that I see it written out, I <cough> kind of like "DAX mode" better now. :/
"The file is in DAX (CPU direct access) mode. DAX mode attempts..."
Sure... now you tell me... ;-)
Seriously, we could use mode here in the man page as this is less confusing to say "DAX mode".
But I think the code should still use 'state' because mode is just too overloaded. You were not the only one who was thrown by my use of mode and I don't want that confusion when we look at this code 2 weeks from now...
Quoted 5 lines
Ok, let's leave it alone for now then.
Cool could I get a reviewed by?
And Jan is this reword of the man page/commit ok to keep your reviewed by?
Quoted 3 lines
I'm not even sure what 'DAX' stands for. Direct Access to ... Professor Xavier? 8-)
That is pronounced 'Direct A'Xes' you know, for chopping wood!
Thanks everyone,
Ira
Quoted 30 lines
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
attempts to minimize software cache effects for both I/O and memory mappings of this file. It requires a file system which has been configured to support DAX.
DAX generally assumes all accesses are via cpu load / store instructions which can minimize overhead for small accesses, but may adversely affect cpu utilization for large transfers.
File I/O is done directly to/from user-space buffers and memory mapped I/O may be performed with direct memory mappings that bypass kernel page cache.
While the DAX property tends to result in data being transferred synchronously, it does not give the same guarantees of synchronous I/O where data and the necessary metadata are transferred together.
Quoted 4 lines
Quoted 2 lines
(I'm frankly not sure that synchronous I/O actually guarantees that the metadata has hit stable storage...)
I'll let you and Dan work this one out... ;-)
Hehe. I think the wording here is fine.
--D
Quoted 2 lines
Ira
Darrick J. Wong
Reviewed-byRe: [RFC PATCH V2 01/12] fs/stat: Define DAX statx attribute
Quoted 42 lines · Ira Weiny
Quoted 41 lines · Darrick J. Wong
Quoted 40 lines · Ira Weiny
Quoted 10 lines · Darrick J. Wong
Quoted 9 lines · Ira Weiny
Quoted 7 lines · Dan Williams
Quoted 6 lines · Ira Weiny
Quoted 4 lines · Darrick J. Wong
Quoted 3 lines · Jan Kara
Quoted 2 lines · On Fri 10-01-20 11:29:31, [email protected] wrote:
From: Ira Weiny <[email protected]>
[snip]
Quoted 10 lines
Quoted 10 lines
Sure, but for now I think referencing mmap for details on
MAP_SYNCworks.I suspect that we may have some word smithing once I get this series in and we submit a change to the statx man page itself. Can I move forward with the following for this patch?
<quote>
STATX_ATTR_DAXQuoted 6 lines
Quoted 1 line
The file is in the DAX (cpu direct access) state. DAX state
Hmm, now that I see it written out, I <cough> kind of like "DAX mode" better now. :/
"The file is in DAX (CPU direct access) mode. DAX mode attempts..."
Sure... now you tell me... ;-)
Seriously, we could use mode here in the man page as this is less confusing to say "DAX mode".
But I think the code should still use 'state' because mode is just too overloaded. You were not the only one who was thrown by my use of mode and I don't want that confusion when we look at this code 2 weeks from now...
Quoted 7 lines
Quoted 5 lines
Ok, let's leave it alone for now then.
Cool could I get a reviewed by?
My bike shed is painted green with purple polka dots,
--D
Quoted 41 lines
And Jan is this reword of the man page/commit ok to keep your reviewed by?
Quoted 3 lines
I'm not even sure what 'DAX' stands for. Direct Access to ... Professor Xavier? 8-)
That is pronounced 'Direct A'Xes' you know, for chopping wood!
Thanks everyone,
IraQuoted 30 lines
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
attempts to minimize software cache effects for both I/O and memory mappings of this file. It requires a file system which has been configured to support DAX.
DAX generally assumes all accesses are via cpu load / store instructions which can minimize overhead for small accesses, but may adversely affect cpu utilization for large transfers.
File I/O is done directly to/from user-space buffers and memory mapped I/O may be performed with direct memory mappings that bypass kernel page cache.
While the DAX property tends to result in data being transferred synchronously, it does not give the same guarantees of synchronous I/O where data and the necessary metadata are transferred together.
Quoted 4 lines
Quoted 2 lines
(I'm frankly not sure that synchronous I/O actually guarantees that the metadata has hit stable storage...)
I'll let you and Dan work this one out... ;-)
Hehe. I think the wording here is fine.
--D
Quoted 2 lines
Ira
Jan Kara
maintainerRe: [RFC PATCH V2 01/12] fs/stat: Define DAX statx attribute
In reply to Ira WeinyQuoted 1 line · Ira Weiny
And Jan is this reword of the man page/commit ok to keep your reviewed by?
Yes.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
RFC PATCH v2 2/12 fs/xfs: Isolate the physical DAX flag from effective
In reply to [email protected]From: Ira Weiny <[email protected]>
xfs_ioctl_setattr_dax_invalidate() currently checks if the DAX flag is changing as a quick check.
But the implementation mixes the physical (XFS_DIFLAG2_DAX) and effective (S_DAX) DAX flags.
Remove the use of the effective flag when determining if a change of the physical flag is required.
--- fs/xfs/xfs_ioctl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/xfs/xfs_ioctl.c +4 -2
@@ -1195,9 +1195,11 @@ xfs_ioctl_setattr_dax_invalidate( }/* If the DAX state is not changing, we have nothing to do here. */ -if ((fa->fsx_xflags &FS_XFLAG_DAX ) &&IS_DAX (inode)) +if ((fa->fsx_xflags &FS_XFLAG_DAX ) && + (ip->i_d.di_flags2 &XFS_DIFLAG2_DAX ))return 0 ; -if (!(fa->fsx_xflags &FS_XFLAG_DAX ) && !IS_DAX (inode)) +if (!(fa->fsx_xflags &FS_XFLAG_DAX ) && + !(ip->i_d.di_flags2 &XFS_DIFLAG2_DAX ))return 0 ;if (S_ISDIR (inode->i_mode))
Signature · 1 line
2.21.0
RFC PATCH v2 3/12 fs/xfs: Separate functionality of xfs_inode_supports_dax()
In reply to [email protected]From: Ira Weiny <[email protected]>
xfs_inode_supports_dax() should reflect if the inode can support DAX not that it is enabled for DAX. Leave that to other helper functions.
Change the caller of xfs_inode_supports_dax() to call xfs_inode_use_dax() which reflects new logic to override the effective DAX flag with either the mount option or the physical DAX flag.
To make the logic clear create 2 helper functions for the mount and physical flag.
--- fs/xfs/xfs_iops.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-)
fs/xfs/xfs_iops.c +26 -6
@@ -1234,6 +1234,15 @@ static const struct inode_operations xfs_inline_symlink_inode_operations = { .update_time = xfs_vn_update_time, }; +static bool +xfs_inode_mount_is_dax ( +struct xfs_inode *ip) +{ +struct xfs_mount *mp = ip->i_mount; + +return (mp->m_flags &XFS_MOUNT_DAX ) ==XFS_MOUNT_DAX ; +} +/* Figure out if this file actually supports DAX. */ static bool xfs_inode_supports_dax(
@@ -1245,11 +1254,6 @@ xfs_inode_supports_dax(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;
@@ -1258,6 +1262,22 @@ xfs_inode_supports_dax(return xfs_inode_buftarg (ip)->bt_daxdev !=NULL ; } +static bool +xfs_inode_is_dax ( +struct xfs_inode *ip) +{ +return (ip->i_d.di_flags2 &XFS_DIFLAG2_DAX ) ==XFS_DIFLAG2_DAX ; +} + +static bool +xfs_inode_use_dax ( +struct xfs_inode *ip) +{ +return xfs_inode_supports_dax (ip) && + (xfs_inode_mount_is_dax (ip) || +xfs_inode_is_dax (ip)); +} + STATIC void xfs_diflags_to_iflags( struct inode *inode,
@@ -1276,7 +1296,7 @@ xfs_diflags_to_iflags( inode->i_flags |=S_SYNC ;if (flags &XFS_DIFLAG_NOATIME ) inode->i_flags |=S_NOATIME ; -if (xfs_inode_supports_dax (ip)) +if (xfs_inode_use_dax (ip)) inode->i_flags |=S_DAX ; }
Signature · 1 line
2.21.0
RFC PATCH v2 4/12 fs/xfs: Clean up DAX support check
In reply to [email protected]From: Ira Weiny <[email protected]>
Rather than open coding xfs_inode_supports_dax() in xfs_ioctl_setattr_dax_invalidate() export xfs_inode_supports_dax() and call it in preparation for swapping dax flags.
This also means updating xfs_inode_supports_dax() to return true for a directory.
--- fs/xfs/xfs_ioctl.c | 16 +++------------- fs/xfs/xfs_iops.c | 8 ++++++-- fs/xfs/xfs_iops.h | 2 ++ 3 files changed, 11 insertions(+), 15 deletions(-)
fs/xfs/xfs_ioctl.c +3 -13
@@ -1176,23 +1176,13 @@ xfs_ioctl_setattr_dax_invalidate( int *join_flags) {struct inode *inode =VFS_I (ip); -struct super_block *sb = inode->i_sb;int error; *join_flags =0 ; -/* -* It is only valid to set the DAX flag on regular files and -* directories on filesystems where the block size is equal to the page -* size. On directories it serves as an inherited hint so we don't -* have to check the device for dax support or flush pagecache. -*/ -if (fa->fsx_xflags &FS_XFLAG_DAX ) { -struct xfs_buftarg *target =xfs_inode_buftarg (ip); - -if (!bdev_dax_supported (target->bt_bdev, sb->s_blocksize)) -return -EINVAL ; - } +if ((fa->fsx_xflags &FS_XFLAG_DAX ) ==FS_XFLAG_DAX && + !xfs_inode_supports_dax (ip)) +return -EINVAL ;/* If the DAX state is not changing, we have nothing to do here. */ if ((fa->fsx_xflags & FS_XFLAG_DAX) &&
fs/xfs/xfs_iops.c +6 -2
@@ -1244,14 +1244,18 @@ xfs_inode_mount_is_dax( }/* Figure out if this file actually supports DAX. */ -static bool +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)) +if (xfs_is_reflink_inode (ip)) +return false; + +/* Only supported on regular files and directories. */ +if (!(S_ISREG (VFS_I (ip)->i_mode) ||S_ISDIR (VFS_I (ip)->i_mode)))return false;/* Block size must match page size */
fs/xfs/xfs_iops.h +2 -0
@@ -24,4 +24,6 @@ extern int xfs_setattr_nonsize(struct xfs_inode *ip, struct iattr *vap,extern int xfs_vn_setattr_nonsize (struct dentry *dentry,struct iattr *vap);extern int xfs_vn_setattr_size (struct dentry *dentry,struct iattr *vap); +extern bool xfs_inode_supports_dax (struct xfs_inode *ip); +#endif /* __XFS_IOPS_H__ */
Signature · 1 line
2.21.0
RFC PATCH v2 5/12 fs: remove unneeded IS_DAX() check
In reply to [email protected]From: Ira Weiny <[email protected]>
The IS_DAX() check in io_is_direct() causes a race between changing the DAX mode and creating the iocb flags.
Remove the check because DAX now emulates the page cache API and therefore it does not matter if the file mode is DAX or not when the iocb flags are created.
--- include/linux/fs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/fs.h +1 -1
@@ -3365,7 +3365,7 @@ extern int file_update_time(struct file *file);static inline bool io_is_direct (struct file *filp) { -return (filp->f_flags &O_DIRECT ) ||IS_DAX (filp->f_mapping->host); +return (filp->f_flags &O_DIRECT ); }static inline bool vma_is_dax (struct vm_area_struct *vma)
Signature · 1 line
2.21.0
Re: [RFC PATCH V2 05/12] fs: remove unneeded IS_DAX() check
Quoted 10 lines · On Fri 10-01-20 11:29:35, [email protected] wrote:
From: Ira Weiny <[email protected]>
The
IS_DAX()check inio_is_direct()causes a race between changing the DAX mode and creating the iocb flags.Remove the check because DAX now emulates the page cache API and therefore it does not matter if the file mode is DAX or not when the iocb flags are created.
Signed-off-by Ira Weiny <[email protected]>
The patch looks good to me. You can add:
Honza
Quoted 20 lines
--- include/linux/fs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/fs.h +1
-1@@ -3365,7 +3365,7 @@ extern int file_update_time(struct file *file);static inline bool io_is_direct (struct file *filp) { -return (filp->f_flags &O_DIRECT ) ||IS_DAX (filp->f_mapping->host); +return (filp->f_flags &O_DIRECT ); }static inline bool vma_is_dax (struct vm_area_struct *vma)Signature · 1 line
2.21.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [RFC PATCH V2 05/12] fs: remove unneeded IS_DAX() check
Quoted 10 lines · Jan Kara
Quoted 9 lines · On Fri 10-01-20 11:29:35, [email protected] wrote:
From: Ira Weiny <[email protected]>
The
IS_DAX()check inio_is_direct()causes a race between changing the DAX mode and creating the iocb flags.Remove the check because DAX now emulates the page cache API and therefore it does not matter if the file mode is DAX or not when the iocb flags are created.
Quoted 5 lines
Quoted 1 line
Signed-off-by Ira Weiny <[email protected]>The patch looks good to me. You can add:
Reviewed-by Jan Kara <[email protected]>
Thanks,
Ira
Quoted 26 lines
Honza
Quoted 20 lines
--- include/linux/fs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/fs.h +1
-1@@ -3365,7 +3365,7 @@ extern int file_update_time(struct file *file);static inline bool io_is_direct (struct file *filp) { -return (filp->f_flags &O_DIRECT ) ||IS_DAX (filp->f_mapping->host); +return (filp->f_flags &O_DIRECT ); }static inline bool vma_is_dax (struct vm_area_struct *vma)Signature · 1 line
2.21.0Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
RFC PATCH v2 6/12 fs/xfs: Check if the inode supports DAX under lock
In reply to [email protected]From: Ira Weiny <[email protected]>
One of the checks for an inode supporting DAX is if the inode is reflinked. During a non-DAX to DAX mode change we could race with the file being reflinked and end up with a reflinked file being in DAX mode.
Prevent this race by checking for DAX support under the MMAP_LOCK.
--- fs/xfs/xfs_ioctl.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
fs/xfs/xfs_ioctl.c +7 -4
@@ -1180,10 +1180,6 @@ xfs_ioctl_setattr_dax_invalidate( *join_flags =0 ; -if ((fa->fsx_xflags &FS_XFLAG_DAX ) ==FS_XFLAG_DAX && - !xfs_inode_supports_dax (ip)) -return -EINVAL ; -/* If the DAX state is not changing, we have nothing to do here. */ if ((fa->fsx_xflags &FS_XFLAG_DAX ) && (ip->i_d.di_flags2 &XFS_DIFLAG2_DAX ))
@@ -1197,6 +1193,13 @@ xfs_ioctl_setattr_dax_invalidate(/* lock, flush and invalidate mapping in preparation for flag change */ xfs_ilock (ip,XFS_MMAPLOCK_EXCL |XFS_IOLOCK_EXCL ); + +if ((fa->fsx_xflags &FS_XFLAG_DAX ) ==FS_XFLAG_DAX && + !xfs_inode_supports_dax (ip)) { + error = -EINVAL ; + goto out_unlock; + } + error =filemap_write_and_wait (inode->i_mapping);if (error) goto out_unlock;
Signature · 1 line
2.21.0
RFC PATCH v2 7/12 fs: Add locking for a dynamic inode 'mode'
In reply to [email protected]From: Ira Weiny <[email protected]>
DAX requires special address space operations but many other functions check the IS_DAX() mode.
DAX is a property of the inode thus we define an inode mode lock as an inode operation which file systems can optionally define.
This patch defines the core function callbacks as well as puts the locking calls in place.
--- Documentation/filesystems/vfs.rst | 30 ++++++++++++++++ fs/ioctl.c | 23 +++++++++---- fs/open.c | 4 +++ include/linux/fs.h | 57 +++++++++++++++++++++++++++++-- mm/fadvise.c | 10 ++++-- mm/khugepaged.c | 2 ++ mm/mmap.c | 7 ++++ 7 files changed, 123 insertions(+), 10 deletions(-)
Documentation/filesystems/vfs.rst +30 -0
@@ -59,6 +59,28 @@ like open(2) the file, or stat(2) it to peek at the inode data. The stat(2) operation is fairly simple: once the VFS has the dentry, it peeks at the inode data and passes some of it back to userspace. +Changing inode 'modes' dynamically +---------------------------------- + +Some file systems may have different modes for their inodes which require +dyanic changing. A specific example of this is DAX enabled files in XFS and +ext4. To switch the mode safely we lock the inode mode in all "normal" file +system operations and restrict mode changes to those operations. The specific +rules are. + +To do this a file system must follow the following rules. + + 1) the direct_IO address_space_operation must be supported in all + potential a_ops vectors for any mode suported by the inode. + 2) Filesystems must define the lock_mode() and unlock_mode() operations + in struct inode_operations. These functions are used by the core + vfs layers to ensure that the mode is stable before allowing the + core operations to proceed. + 3) Mode changes shall not be allowed while the file is mmap'ed + 4) While changing modes filesystems should take exclusive locks which + prevent the core vfs layer from proceeding. + + The File Object ---------------
@@ -437,6 +459,8 @@ As of kernel 2.6.22, the following members are defined: int (*atomic_open)(struct inode *, struct dentry *, struct file *, unsigned open_flag, umode_t create_mode); int (*tmpfile) (struct inode *, struct dentry *, umode_t); + void (*lock_mode)(struct inode *); + void (*unlock_mode)(struct inode *); }; Again, all methods are called without any locks being held, unless
@@ -584,6 +608,12 @@ otherwise noted. atomically creating, opening and unlinking a file in given directory. +``lock_mode`` + called to prevent operations which depend on the inode's mode from + proceeding should a mode change be in progress + +``unlock_mode`` + called when critical mode dependent operation is complete The Address Space Object ========================
fs/ioctl.c +17 -6
@@ -55,18 +55,29 @@ EXPORT_SYMBOL(vfs_ioctl);static int ioctl_fibmap (struct file *filp,int __user *p) {struct address_space *mapping = filp->f_mapping; +struct inode *inode = filp->f_inode;int res, block; +lock_inode_mode (inode); +/* do we support this mess? */ -if (!mapping->a_ops->bmap) -return -EINVAL ; -if (!capable (CAP_SYS_RAWIO )) -return -EPERM ; +if (!mapping->a_ops->bmap) { + res = -EINVAL ; + goto out; + } +if (!capable (CAP_SYS_RAWIO )) { + res = -EPERM ; + goto out; + } res =get_user (block, p);if (res) -return res; + goto out; res = mapping->a_ops->bmap (mapping, block); -return put_user (res, p); + res =put_user (res, p); + +out: +unlock_inode_mode (inode); +return res; }/**
fs/open.c +4 -0
@@ -59,10 +59,12 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,if (ret) newattrs.ia_valid |= ret |ATTR_FORCE ; +lock_inode_mode (dentry->d_inode);inode_lock (dentry->d_inode);/* Note any delegations or leases have already been broken: */ ret =notify_change (dentry, &newattrs,NULL );inode_unlock (dentry->d_inode); +unlock_inode_mode (dentry->d_inode);return ret; }
@@ -306,7 +308,9 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)return -EOPNOTSUPP ;file_start_write (file); +lock_inode_mode (inode); ret = file->f_op->fallocate (file, mode, offset, len); +unlock_inode_mode (inode);/* * Create inotify and fanotify events.
include/linux/fs.h +55 -2
91 lines not on this page · raw message
mm/fadvise.c +8 -2
@@ -47,7 +47,10 @@ int generic_fadvise(struct file *file, loff_t offset, loff_t len, int advice) bdi =inode_to_bdi (mapping->host); +lock_inode_mode (inode);if (IS_DAX (inode) || (bdi == &noop_backing_dev_info)) { +int ret =0 ; +switch (advice) {case POSIX_FADV_NORMAL :case POSIX_FADV_RANDOM :
@@ -58,10 +61,13 @@ int generic_fadvise(struct file *file, loff_t offset, loff_t len, int advice)/* no bad return value, but ignore advice */ break ;default : -return -EINVAL ; + ret = -EINVAL ; } -return 0 ; + +unlock_inode_mode (inode); +return ret; } +unlock_inode_mode (inode);/* * Careful about overflows. Len == 0 means "as much as possible". Use
mm/khugepaged.c +2 -0
@@ -1592,9 +1592,11 @@ static void collapse_file(struct mm_struct *mm, }else {/* !is_shmem */ if (!page ||xa_is_value (page)) {xas_unlock_irq (&xas); +lock_inode_mode (file->f_inode);page_cache_sync_readahead (mapping, &file->f_ra, file, index,PAGE_SIZE ); +unlock_inode_mode (file->f_inode);/* drain pagevecs to help isolate_lru_page() */ lru_add_drain (); page =find_lock_page (mapping, index);
mm/mmap.c +7 -0
@@ -1542,11 +1542,18 @@ unsigned long do_mmap(struct file *file, unsigned long addr, vm_flags |=VM_NORESERVE ; } +if (file) +lock_inode_mode (file_inode (file)); + addr =mmap_region (file, addr, len, vm_flags, pgoff, uf);if (!IS_ERR_VALUE (addr) && ((vm_flags &VM_LOCKED ) || (flags & (MAP_POPULATE |MAP_NONBLOCK )) ==MAP_POPULATE )) *populate = len; + +if (file) +unlock_inode_mode (file_inode (file)); +return addr; }
Signature · 1 line
2.21.0
Re: [RFC PATCH V2 07/12] fs: Add locking for a dynamic inode 'mode'
Quoted 56 lines · On Fri, Jan 10, 2020 at 11:29:37AM -0800, [email protected] wrote:
From: Ira Weiny <[email protected]>
DAX requires special address space operations but many other functions check the
IS_DAX()mode.DAX is a property of the inode thus we define an inode mode lock as an inode operation which file systems can optionally define.
This patch defines the core function callbacks as well as puts the locking calls in place.
Signed-off-by Ira Weiny <[email protected]>--- Documentation/filesystems/vfs.rst | 30 ++++++++++++++++ fs/ioctl.c | 23 +++++++++---- fs/open.c | 4 +++ include/linux/fs.h | 57 +++++++++++++++++++++++++++++-- mm/fadvise.c | 10 ++++-- mm/khugepaged.c | 2 ++ mm/mmap.c | 7 ++++ 7 files changed, 123 insertions(+), 10 deletions(-)Documentation/filesystems/vfs.rst +22
-0@@ -59,6 +59,28 @@ like open(2) the file, or stat(2) it to peek at the inode data. The stat(2) operation is fairly simple: once the VFS has the dentry, it peeks at the inode data and passes some of it back to userspace. +Changing inode 'modes' dynamically +---------------------------------- + +Some file systems may have different modes for their inodes which require +dyanic changing. A specific example of this is DAX enabled files in XFS and +ext4. To switch the mode safely we lock the inode mode in all "normal" file +system operations and restrict mode changes to those operations. The specific +rules are. + +To do this a file system must follow the following rules. + + 1) the direct_IO address_space_operation must be supported in all + potential a_ops vectors for any mode suported by the inode. + 2) Filesystems must define the lock_mode() and unlock_mode() operations + in struct inode_operations. These functions are used by the core + vfs layers to ensure that the mode is stable before allowing the + core operations to proceed. + 3) Mode changes shall not be allowed while the file is mmap'ed + 4) While changing modes filesystems should take exclusive locks which + prevent the core vfs layer from proceeding. + + The File Object ---------------
Documentation/filesystems/vfs.rst As of kernel 2.6.22, the following members are defined: · line 463
Quoted 5 lines
Documentation/filesystems/vfs.rst +2
-0@@ -437,6 +459,8 @@ As of kernel 2.6.22, the following members are defined: int (*atomic_open)(struct inode *, struct dentry *, struct file *, unsigned open_flag, umode_t create_mode); int (*tmpfile) (struct inode *, struct dentry *, umode_t); + void (*lock_mode)(struct inode *); + void (*unlock_mode)(struct inode *);
Yikes. "mode" has a specific meaning for inodes, and this lock isn't related to i_mode. This lock protects aops from changing while an address space operation is in use.
Documentation/filesystems/vfs.rst otherwise noted. · line 613
Quoted 10 lines
Documentation/filesystems/vfs.rst +3
-0}; Again, all methods are called without any locks being held, unless@@ -584,6 +608,12 @@ otherwise noted. atomically creating, opening and unlinking a file in given directory. +``lock_mode`` + called to prevent operations which depend on the inode's mode from + proceeding should a mode change be in progress
"Inodes can't change mode, because files do not suddenly become directories". ;)
Oh, you meant "lock_XXXX is called to prevent a change in the pagecache mode from proceeding while there are address space operations in progress". So these are really more aops get and put functions...
Quoted 20 lines
Documentation/filesystems/vfs.rst +2
-0+``unlock_mode`` + called when critical mode dependent operation is complete The Address Space Object ========================fs/ioctl.c +3
-1@@ -55,18 +55,29 @@ EXPORT_SYMBOL(vfs_ioctl);static int ioctl_fibmap (struct file *filp,int __user *p) {struct address_space *mapping = filp->f_mapping; +struct inode *inode = filp->f_inode;int res, block; +lock_inode_mode (inode); +/* do we support this mess? */ -if (!mapping->a_ops->bmap)
fs/ioctl.c EXPORT_SYMBOL(vfs_ioctl); · line 70
Quoted 10 lines
fs/ioctl.c +7
-3-return -EINVAL ; -if (!capable (CAP_SYS_RAWIO )) -return -EPERM ; +if (!mapping->a_ops->bmap) { + res = -EINVAL ; + goto out; + } +if (!capable (CAP_SYS_RAWIO )) { + res = -EPERM ; + goto out;
Why does the order of these checks change here?
Quoted 92 lines
fs/ioctl.c +7
-2+ } res =get_user (block, p);if (res) -return res; + goto out; res = mapping->a_ops->bmap (mapping, block); -return put_user (res, p); + res =put_user (res, p); + +out: +unlock_inode_mode (inode); +return res; }/** fs/open.c +4
-0@@ -59,10 +59,12 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,if (ret) newattrs.ia_valid |= ret |ATTR_FORCE ; +lock_inode_mode (dentry->d_inode);inode_lock (dentry->d_inode);/* Note any delegations or leases have already been broken: */ ret =notify_change (dentry, &newattrs,NULL );inode_unlock (dentry->d_inode); +unlock_inode_mode (dentry->d_inode);return ret; }@@ -306,7 +308,9 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)return -EOPNOTSUPP ;file_start_write (file); +lock_inode_mode (inode); ret = file->f_op->fallocate (file, mode, offset, len); +unlock_inode_mode (inode);/* * Create inotify and fanotify events. include/linux/fs.h +24
-0@@ -359,6 +359,11 @@ typedef struct {typedef int (*read_actor_t )(read_descriptor_t *,struct page *,unsigned long ,unsigned long ); +/** +* NOTE: DO NOT define new functions in address_space_operations without first +* considering how dynamic inode modes can be supported. See the comment in +* struct inode_operations for the lock_mode() and unlock_mode() callbacks. +*/ struct address_space_operations {int (*writepage)(struct page *page,struct writeback_control *wbc);int (*readpage)(struct file *,struct page *);@@ -1817,6 +1822,11 @@ struct block_device_operations;struct iov_iter ; +/** +* NOTE: DO NOT define new functions in file_operations without first +* considering how dynamic inode modes can be supported. See the comment in +* struct inode_operations for the lock_mode() and unlock_mode() callbacks. +*/ struct file_operations {struct module *owner;loff_t (*llseek) (struct file *,loff_t ,int );@@ -1859,6 +1869,20 @@ struct file_operations {int (*fadvise)(struct file *,loff_t ,loff_t ,int ); } __randomize_layout; +/* +* Filesystems wishing to support dynamic inode modes must do the following. +* +* 1) the direct_IO address_space_operation must be supported in all +* potential a_ops vectors for any mode suported by the inode. +* 2) Filesystems must define the lock_mode() and unlock_mode() operations +* in struct inode_operations. These functions are used by the core +* vfs layers to ensure that the mode is stable before allowing the +* core operations to proceed. +* 3) Mode changes shall not be allowed while the file is mmap'ed +* 4) While changing modes filesystems should take exclusive locks which +* prevent the core vfs layer from proceeding. +* +*/ struct inode_operations {struct dentry * (*lookup) (struct inode *,struct dentry *,unsigned int );const char * (*get_link) (struct dentry *,struct inode *,struct delayed_call *);
include/linux/fs.h struct inode_operations { · line 1918
Quoted 8 lines
include/linux/fs.h +3
-0@@ -1887,18 +1911,47 @@ struct inode_operations { umode_t create_mode);int (*tmpfile) (struct inode *,struct dentry *,umode_t );int (*set_acl)(struct inode *,struct posix_acl *,int ); +void (*lock_mode)(struct inode *); +void (*unlock_mode)(struct inode *); }____cacheline_aligned ; +static inline void lock_inode_mode (struct inode *inode)
inode_aops_get()?
Quoted 6 lines
include/linux/fs.h +6
-0+{ +WARN_ON_ONCE (inode->i_op->lock_mode && + !inode->i_op->unlock_mode); +if (inode->i_op->lock_mode) + inode->i_op->lock_mode (inode); +}
include/linux/fs.h struct inode_operations { · line 1934
Quoted 10 lines
include/linux/fs.h +8
-0+static inline void unlock_inode_mode (struct inode *inode) +{ +WARN_ON_ONCE (inode->i_op->unlock_mode && + !inode->i_op->lock_mode); +if (inode->i_op->unlock_mode) + inode->i_op->unlock_mode (inode); +} +static inline ssize_t call_read_iter (struct file *file,struct kiocb *kio,struct iov_iter *iter)
inode_aops_put()?
--D
Quoted 98 lines
include/linux/fs.h +14
-2{ -return file->f_op->read_iter (kio, iter); +struct inode *inode =file_inode (kio->ki_filp); +ssize_t ret; + +lock_inode_mode (inode); + ret = file->f_op->read_iter (kio, iter); +unlock_inode_mode (inode); +return ret; }static inline ssize_t call_write_iter (struct file *file,struct kiocb *kio,struct iov_iter *iter) { -return file->f_op->write_iter (kio, iter); +struct inode *inode =file_inode (kio->ki_filp); +ssize_t ret; + +lock_inode_mode (inode); + ret = file->f_op->write_iter (kio, iter); +unlock_inode_mode (inode); +return ret; }static inline int call_mmap (struct file *file,struct vm_area_struct *vma)mm/fadvise.c +8
-2@@ -47,7 +47,10 @@ int generic_fadvise(struct file *file, loff_t offset, loff_t len, int advice) bdi =inode_to_bdi (mapping->host); +lock_inode_mode (inode);if (IS_DAX (inode) || (bdi == &noop_backing_dev_info)) { +int ret =0 ; +switch (advice) {case POSIX_FADV_NORMAL :case POSIX_FADV_RANDOM :@@ -58,10 +61,13 @@ int generic_fadvise(struct file *file, loff_t offset, loff_t len, int advice)/* no bad return value, but ignore advice */ break ;default : -return -EINVAL ; + ret = -EINVAL ; } -return 0 ; + +unlock_inode_mode (inode); +return ret; } +unlock_inode_mode (inode);/* * Careful about overflows. Len == 0 means "as much as possible". Use mm/khugepaged.c +2
-0@@ -1592,9 +1592,11 @@ static void collapse_file(struct mm_struct *mm, }else {/* !is_shmem */ if (!page ||xa_is_value (page)) {xas_unlock_irq (&xas); +lock_inode_mode (file->f_inode);page_cache_sync_readahead (mapping, &file->f_ra, file, index,PAGE_SIZE ); +unlock_inode_mode (file->f_inode);/* drain pagevecs to help isolate_lru_page() */ lru_add_drain (); page =find_lock_page (mapping, index);mm/mmap.c +7
-0@@ -1542,11 +1542,18 @@ unsigned long do_mmap(struct file *file, unsigned long addr, vm_flags |=VM_NORESERVE ; } +if (file) +lock_inode_mode (file_inode (file)); + addr =mmap_region (file, addr, len, vm_flags, pgoff, uf);if (!IS_ERR_VALUE (addr) && ((vm_flags &VM_LOCKED ) || (flags & (MAP_POPULATE |MAP_NONBLOCK )) ==MAP_POPULATE )) *populate = len; + +if (file) +unlock_inode_mode (file_inode (file)); +return addr; }Signature · 1 line
2.21.0
Re: [RFC PATCH V2 07/12] fs: Add locking for a dynamic inode 'mode'
Quoted 2 lines · Darrick J. Wong
Quoted 1 line · On Fri, Jan 10, 2020 at 11:29:37AM -0800, [email protected] wrote:
From: Ira Weiny <[email protected]>
[snip]
Quoted 13 lines
Documentation/filesystems/vfs.rst As of kernel 2.6.22, the following members are defined: · line 463
Quoted 9 lines
The File Object
---------------Documentation/filesystems/vfs.rst +2
-0@@ -437,6 +459,8 @@ As of kernel 2.6.22, the following members are defined: int (*atomic_open)(struct inode *, struct dentry *, struct file *, unsigned open_flag, umode_t create_mode); int (*tmpfile) (struct inode *, struct dentry *, umode_t); + void (*lock_mode)(struct inode *); + void (*unlock_mode)(struct inode *);Yikes. "mode" has a specific meaning for inodes, and this lock isn't related to
i_mode. This lock protects aops from changing while an address space operation is in use.
Ah... yea ok mode is a bad name.
Quoted 8 lines
Quoted 8 lines
Documentation/filesystems/vfs.rst +0
-0}; Again, all methods are called without any locks being held, unless@@ -584,6 +608,12 @@ otherwise noted. atomically creating, opening and unlinking a file in given directory.
Quoted 6 lines
Documentation/filesystems/vfs.rst otherwise noted. · line 613
Quoted 3 lines
Documentation/filesystems/vfs.rst +3
-0+``lock_mode`` + called to prevent operations which depend on the inode's mode from + proceeding should a mode change be in progress"Inodes can't change mode, because files do not suddenly become directories". ;)
Yea sorry.
Quoted 4 lines
Oh, you meant "
lock_XXXXis called to prevent a change in the pagecache mode from proceeding while there are address space operations in progress". So these are really more aops get and put functions...
At first I actually did have aops get/put functions but this is really protecting more than the aops vector because as Christoph said there are file operations which need to be protected not just address space operations.
But I agree "mode" is a bad name... Sorry...
Quoted 17 lines
Quoted 17 lines
Documentation/filesystems/vfs.rst +2
-0+``unlock_mode`` + called when critical mode dependent operation is complete The Address Space Object ========================fs/ioctl.c +1
-0@@ -55,18 +55,29 @@ EXPORT_SYMBOL(vfs_ioctl);static int ioctl_fibmap (struct file *filp,int __user *p) {struct address_space *mapping = filp->f_mapping; +struct inode *inode = filp->f_inode;int res, block;
Quoted 16 lines
Quoted 4 lines
fs/ioctl.c +2
-1+lock_inode_mode (inode); +/* do we support this mess? */ -if (!mapping->a_ops->bmap)fs/ioctl.c EXPORT_SYMBOL(vfs_ioctl); · line 70
Quoted 10 lines
fs/ioctl.c +7
-3-return -EINVAL ; -if (!capable (CAP_SYS_RAWIO )) -return -EPERM ; +if (!mapping->a_ops->bmap) { + res = -EINVAL ; + goto out; + } +if (!capable (CAP_SYS_RAWIO )) { + res = -EPERM ; + goto out;Why does the order of these checks change here?
I don't understand? The order does not change we just can't return without releasing the lock. And to protect against bmap changing the lock needs to be taken first.
[snip]
Quoted 4 lines
fs/ioctl.c EXPORT_SYMBOL(vfs_ioctl); · line 71
Quoted 2 lines
fs/ioctl.c +1
-0+static inline void lock_inode_mode (struct inode *inode)
inode_aops_get()?
Let me think on this. This is not just getting a reference to the aops vector. It is more than that... and inode_get is not right either! ;-P
Quoted 11 lines
Quoted 11 lines
fs/ioctl.c +10
-0+{ +WARN_ON_ONCE (inode->i_op->lock_mode && + !inode->i_op->unlock_mode); +if (inode->i_op->lock_mode) + inode->i_op->lock_mode (inode); +} +static inline void unlock_inode_mode (struct inode *inode) +{ +WARN_ON_ONCE (inode->i_op->unlock_mode && + !inode->i_op->lock_mode);
Quoted 8 lines
fs/ioctl.c EXPORT_SYMBOL(vfs_ioctl);
Quoted 6 lines
fs/ioctl.c +4
-0+if (inode->i_op->unlock_mode) + inode->i_op->unlock_mode (inode); +} +static inline ssize_t call_read_iter (struct file *file,struct kiocb *kio,struct iov_iter *iter)
inode_aops_put()?
... something like that but not 'aops'...
Ira
Quoted 3 lines
--D
Re: [RFC PATCH V2 07/12] fs: Add locking for a dynamic inode 'mode'
Quoted 44 lines · Ira Weiny
Quoted 2 lines · Darrick J. Wong
Quoted 1 line · On Fri, Jan 10, 2020 at 11:29:37AM -0800, [email protected] wrote:
From: Ira Weiny <[email protected]>
[snip]
Quoted 13 lines
Documentation/filesystems/vfs.rst As of kernel 2.6.22, the following members are defined: · line 463
Quoted 9 lines
The File Object
---------------Documentation/filesystems/vfs.rst +2
-0@@ -437,6 +459,8 @@ As of kernel 2.6.22, the following members are defined: int (*atomic_open)(struct inode *, struct dentry *, struct file *, unsigned open_flag, umode_t create_mode); int (*tmpfile) (struct inode *, struct dentry *, umode_t); + void (*lock_mode)(struct inode *); + void (*unlock_mode)(struct inode *);Yikes. "mode" has a specific meaning for inodes, and this lock isn't related to
i_mode. This lock protects aops from changing while an address space operation is in use.Ah... yea ok mode is a bad name.
Quoted 8 lines
Quoted 8 lines
Documentation/filesystems/vfs.rst +0
-0}; Again, all methods are called without any locks being held, unless@@ -584,6 +608,12 @@ otherwise noted. atomically creating, opening and unlinking a file in given directory.Quoted 6 lines
Documentation/filesystems/vfs.rst otherwise noted. · line 613
Quoted 3 lines
Documentation/filesystems/vfs.rst +3
-0+``lock_mode`` + called to prevent operations which depend on the inode's mode from + proceeding should a mode change be in progress"Inodes can't change mode, because files do not suddenly become directories". ;)
Yea sorry.
Quoted 4 lines
Oh, you meant "
lock_XXXXis called to prevent a change in the pagecache mode from proceeding while there are address space operations in progress". So these are really more aops get and put functions...
Quoted 5 lines
At first I actually did have aops get/put functions but this is really protecting more than the aops vector because as Christoph said there are file operations which need to be protected not just address space operations.
But I agree "mode" is a bad name... Sorry...
inode_fops_{get,set}(), then?
inode_start_fileop()inode_end_fileop() ?
Trying to avoid sounding foppish <COUGH>
Quoted 34 lines
Quoted 17 lines
Quoted 17 lines
Documentation/filesystems/vfs.rst +2
-0+``unlock_mode`` + called when critical mode dependent operation is complete The Address Space Object ========================fs/ioctl.c +1
-0@@ -55,18 +55,29 @@ EXPORT_SYMBOL(vfs_ioctl);static int ioctl_fibmap (struct file *filp,int __user *p) {struct address_space *mapping = filp->f_mapping; +struct inode *inode = filp->f_inode;int res, block;Quoted 16 lines
Quoted 4 lines
fs/ioctl.c +2
-1+lock_inode_mode (inode); +/* do we support this mess? */ -if (!mapping->a_ops->bmap)fs/ioctl.c EXPORT_SYMBOL(vfs_ioctl); · line 70
Quoted 10 lines
fs/ioctl.c +7
-3-return -EINVAL ; -if (!capable (CAP_SYS_RAWIO )) -return -EPERM ; +if (!mapping->a_ops->bmap) { + res = -EINVAL ; + goto out; + } +if (!capable (CAP_SYS_RAWIO )) { + res = -EPERM ; + goto out;Why does the order of these checks change here?
Quoted 3 lines
I don't understand? The order does not change we just can't return without releasing the lock. And to protect against bmap changing the lock needs to be taken first.
Doh. -ENOCOFFEE, I plead.
--D
Quoted 37 lines
[snip]
Quoted 4 lines
Quoted 2 lines
+static inline void
lock_inode_mode(struct inode *inode)
inode_aops_get()?Let me think on this. This is not just getting a reference to the aops vector. It is more than that... and
inode_getis not right either! ;-PQuoted 11 lines
Quoted 11 lines
fs/ioctl.c +10
-0+{ +WARN_ON_ONCE (inode->i_op->lock_mode && + !inode->i_op->unlock_mode); +if (inode->i_op->lock_mode) + inode->i_op->lock_mode (inode); +} +static inline void unlock_inode_mode (struct inode *inode) +{ +WARN_ON_ONCE (inode->i_op->unlock_mode && + !inode->i_op->lock_mode);Quoted 8 lines
fs/ioctl.c
Quoted 6 lines
fs/ioctl.c +4
-0+if (inode->i_op->unlock_mode) + inode->i_op->unlock_mode (inode); +} +static inline ssize_t call_read_iter (struct file *file,struct kiocb *kio,struct iov_iter *iter)
inode_aops_put()?... something like that but not 'aops'...
Ira
Quoted 3 lines
--D
Re: [RFC PATCH V2 07/12] fs: Add locking for a dynamic inode 'mode'
Quoted 4 lines · Darrick J. Wong
Quoted 3 lines · Ira Weiny
Quoted 2 lines · Darrick J. Wong
Quoted 1 line · On Fri, Jan 10, 2020 at 11:29:37AM -0800, [email protected] wrote:
From: Ira Weiny <[email protected]>
[snip]
Quoted 18 lines
Quoted 18 lines
Quoted 6 lines
Documentation/filesystems/vfs.rst otherwise noted. · line 613
Quoted 3 lines
+``lock_mode``
Documentation/filesystems/vfs.rst +2
-0+ called to prevent operations which depend on the inode's mode from + proceeding should a mode change be in progress"Inodes can't change mode, because files do not suddenly become directories". ;)
Yea sorry.
Quoted 4 lines
Oh, you meant "
lock_XXXXis called to prevent a change in the pagecache mode from proceeding while there are address space operations in progress". So these are really more aops get and put functions...At first I actually did have aops get/put functions but this is really protecting more than the aops vector because as Christoph said there are file operations which need to be protected not just address space operations.
Quoted 8 lines
Quoted 1 line
But I agree "mode" is a bad name... Sorry...
inode_fops_{get,set}(), then?
inode_start_fileop()inode_end_fileop()?Trying to avoid sounding foppish <COUGH>
What about?
inode_[un]lock_state()?
Ira
Re: [RFC PATCH V2 07/12] fs: Add locking for a dynamic inode 'mode'
Quoted 30 lines · Ira Weiny
Quoted 4 lines · Darrick J. Wong
Quoted 3 lines · Ira Weiny
Quoted 2 lines · Darrick J. Wong
Quoted 1 line · On Fri, Jan 10, 2020 at 11:29:37AM -0800, [email protected] wrote:
From: Ira Weiny <[email protected]>
[snip]
Quoted 22 lines
Quoted 14 lines
Quoted 6 lines
Documentation/filesystems/vfs.rst otherwise noted. · line 613
Quoted 3 lines
+``lock_mode``
Documentation/filesystems/vfs.rst +2
-0+ called to prevent operations which depend on the inode's mode from + proceeding should a mode change be in progress"Inodes can't change mode, because files do not suddenly become directories". ;)
Yea sorry.
Quoted 4 lines
Oh, you meant "
lock_XXXXis called to prevent a change in the pagecache mode from proceeding while there are address space operations in progress". So these are really more aops get and put functions...Quoted 5 lines
At first I actually did have aops get/put functions but this is really protecting more than the aops vector because as Christoph said there are file operations which need to be protected not just address space operations.
But I agree "mode" is a bad name... Sorry...
inode_fops_{get,set}(), then?
Quoted 8 lines
Quoted 4 lines
inode_start_fileop()inode_end_fileop()?Trying to avoid sounding foppish <COUGH>
What about?
inode_[un]lock_state()?
Kinda vague -- which state? inodes retain a lot of different state.
This locking primitive ensures that file operations pointers can't change while any operations are ongoing, right?
--D
Quoted 2 lines
Ira
Re: [RFC PATCH V2 07/12] fs: Add locking for a dynamic inode 'mode'
Quoted 36 lines · Darrick J. Wong
Quoted 35 lines · Ira Weiny
Quoted 4 lines · Darrick J. Wong
Quoted 3 lines · Ira Weiny
Quoted 2 lines · Darrick J. Wong
Quoted 1 line · On Fri, Jan 10, 2020 at 11:29:37AM -0800, [email protected] wrote:
From: Ira Weiny <[email protected]>
[snip]
Quoted 26 lines
Quoted 14 lines
Quoted 6 lines
Documentation/filesystems/vfs.rst otherwise noted. · line 613
Quoted 3 lines
+``lock_mode``
Documentation/filesystems/vfs.rst +2
-0+ called to prevent operations which depend on the inode's mode from + proceeding should a mode change be in progress"Inodes can't change mode, because files do not suddenly become directories". ;)
Yea sorry.
Quoted 4 lines
Oh, you meant "
lock_XXXXis called to prevent a change in the pagecache mode from proceeding while there are address space operations in progress". So these are really more aops get and put functions...Quoted 5 lines
At first I actually did have aops get/put functions but this is really protecting more than the aops vector because as Christoph said there are file operations which need to be protected not just address space operations.
But I agree "mode" is a bad name... Sorry...
inode_fops_{get,set}(), then?
inode_start_fileop()inode_end_fileop()?Trying to avoid sounding foppish <COUGH>
Quoted 8 lines
Quoted 3 lines
What about?
inode_[un]lock_state()?
Kinda vague -- which state? inodes retain a lot of different state.
This locking primitive ensures that file operations pointers can't change while any operations are ongoing, right?
file ops
Address space ops
...
Whatever it needs...
With the current patch set we could be more specific and call it.
inode_[un]lock_dax_state()
Ira
Quoted 5 lines
--D
Quoted 2 lines
Ira
RFC PATCH v2 8/12 fs/xfs: Add lock/unlock mode to xfs
In reply to [email protected]From: Ira Weiny <[email protected]>
XFS requires regular files to be locked while changing to/from DAX mode.
Define a new DAX lock type and implement the [un]lock_mode() inode operation callbacks.
We define a new XFS_DAX_* lock type to carry the lock through the transaction because we don't want to use IOLOCK as that would cause performance issues with locking of the inode itself.
--- fs/xfs/xfs_icache.c | 2 ++ fs/xfs/xfs_inode.c | 37 +++++++++++++++++++++++++++++++++++-- fs/xfs/xfs_inode.h | 12 ++++++++++-- fs/xfs/xfs_iops.c | 24 +++++++++++++++++++++++- 4 files changed, 70 insertions(+), 5 deletions(-)
fs/xfs/xfs_icache.c +2 -0
@@ -74,6 +74,8 @@ xfs_inode_alloc(INIT_LIST_HEAD (&ip->i_ioend_list);spin_lock_init (&ip->i_ioend_lock); +percpu_init_rwsem (&ip->i_dax_sem); +return ip; }
fs/xfs/xfs_inode.c +35 -2
@@ -142,12 +142,12 @@ xfs_ilock_attr_map_shared(* * Basic locking order: * -* i_rwsem -> i_mmap_lock -> page_lock -> i_ilock +* i_rwsem -> i_dax_sem -> i_mmap_lock -> page_lock -> i_ilock * * mmap_sem locking order: * * i_rwsem -> page lock -> mmap_sem -* mmap_sem -> i_mmap_lock -> page_lock +* mmap_sem -> i_dax_sem -> i_mmap_lock -> page_lock * * The difference in mmap_sem locking order mean that we cannot hold the * i_mmap_lock over syscall based read(2)/write(2) based IO. These IO paths can
@@ -181,6 +181,13 @@ xfs_ilock(ASSERT ((lock_flags & (XFS_ILOCK_SHARED |XFS_ILOCK_EXCL )) != (XFS_ILOCK_SHARED |XFS_ILOCK_EXCL ));ASSERT ((lock_flags & ~(XFS_LOCK_MASK |XFS_LOCK_SUBCLASS_MASK )) ==0 ); +ASSERT ((lock_flags & (XFS_DAX_SHARED |XFS_DAX_EXCL )) != + (XFS_DAX_SHARED |XFS_DAX_EXCL )); + +if (lock_flags &XFS_DAX_EXCL ) +percpu_down_write (&ip->i_dax_sem); +else if (lock_flags &XFS_DAX_SHARED ) +percpu_down_read (&ip->i_dax_sem);if (lock_flags &XFS_IOLOCK_EXCL ) { down_write_nested(&VFS_I(ip)->i_rwsem,
@@ -224,6 +231,8 @@ xfs_ilock_nowait(* You can't set both SHARED and EXCL for the same lock, * and only XFS_IOLOCK_SHARED, XFS_IOLOCK_EXCL, XFS_ILOCK_SHARED, * and XFS_ILOCK_EXCL are valid values to set in lock_flags. +* +* XFS_DAX_* is not allowed */ ASSERT ((lock_flags & (XFS_IOLOCK_SHARED |XFS_IOLOCK_EXCL )) != (XFS_IOLOCK_SHARED |XFS_IOLOCK_EXCL ));
@@ -232,6 +241,7 @@ xfs_ilock_nowait(ASSERT ((lock_flags & (XFS_ILOCK_SHARED |XFS_ILOCK_EXCL )) != (XFS_ILOCK_SHARED |XFS_ILOCK_EXCL ));ASSERT ((lock_flags & ~(XFS_LOCK_MASK |XFS_LOCK_SUBCLASS_MASK )) ==0 ); +ASSERT ((lock_flags & (XFS_DAX_SHARED |XFS_DAX_EXCL )) ==0 );if (lock_flags &XFS_IOLOCK_EXCL ) {if (!down_write_trylock (&VFS_I (ip)->i_rwsem))
@@ -302,6 +312,8 @@ xfs_iunlock( (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL));ASSERT ((lock_flags & ~(XFS_LOCK_MASK |XFS_LOCK_SUBCLASS_MASK )) ==0 );ASSERT (lock_flags !=0 ); +ASSERT ((lock_flags & (XFS_DAX_SHARED |XFS_DAX_EXCL )) != + (XFS_DAX_SHARED |XFS_DAX_EXCL ));if (lock_flags &XFS_IOLOCK_EXCL )up_write (&VFS_I (ip)->i_rwsem);
@@ -318,6 +330,11 @@ xfs_iunlock(else if (lock_flags &XFS_ILOCK_SHARED )mrunlock_shared (&ip->i_lock); +if (lock_flags &XFS_DAX_EXCL ) +percpu_up_write (&ip->i_dax_sem); +else if (lock_flags &XFS_DAX_SHARED ) +percpu_up_read (&ip->i_dax_sem); +trace_xfs_iunlock (ip, lock_flags, _RET_IP_); }
@@ -333,6 +350,8 @@ xfs_ilock_demote(ASSERT (lock_flags & (XFS_IOLOCK_EXCL |XFS_MMAPLOCK_EXCL |XFS_ILOCK_EXCL ));ASSERT ((lock_flags & ~(XFS_IOLOCK_EXCL |XFS_MMAPLOCK_EXCL |XFS_ILOCK_EXCL )) ==0 ); +/* XFS_DAX_* is not allowed */ +ASSERT ((lock_flags & (XFS_DAX_SHARED |XFS_DAX_EXCL )) ==0 );if (lock_flags &XFS_ILOCK_EXCL )mrdemote (&ip->i_lock);
@@ -369,6 +388,13 @@ xfs_isilocked(return rwsem_is_locked (&VFS_I (ip)->i_rwsem); } +if (lock_flags & (XFS_DAX_EXCL |XFS_DAX_SHARED )) { +if (!(lock_flags &XFS_DAX_SHARED )) +return !debug_locks || +percpu_rwsem_is_held (&ip->i_dax_sem,0 ); +return rwsem_is_locked (&ip->i_dax_sem); + } +ASSERT (0 );return 0 ; }
@@ -465,6 +491,9 @@ xfs_lock_inodes(ASSERT (!(lock_mode &XFS_ILOCK_EXCL ) || inodes <=XFS_ILOCK_MAX_SUBCLASS +1 ); +/* XFS_DAX_* is not allowed */ +ASSERT ((lock_mode & (XFS_DAX_SHARED |XFS_DAX_EXCL )) ==0 ); +if (lock_mode &XFS_IOLOCK_EXCL ) {ASSERT (!(lock_mode & (XFS_MMAPLOCK_EXCL |XFS_ILOCK_EXCL ))); }else if (lock_mode &XFS_MMAPLOCK_EXCL )
@@ -566,6 +595,10 @@ xfs_lock_two_inodes(ASSERT (!(ip0_mode & (XFS_MMAPLOCK_SHARED |XFS_MMAPLOCK_EXCL )) || !(ip1_mode & (XFS_ILOCK_SHARED |XFS_ILOCK_EXCL ))); +/* XFS_DAX_* is not allowed */ +ASSERT ((ip0_mode & (XFS_DAX_SHARED |XFS_DAX_EXCL )) ==0 ); +ASSERT ((ip1_mode & (XFS_DAX_SHARED |XFS_DAX_EXCL )) ==0 ); +ASSERT (ip0->i_ino != ip1->i_ino);if (ip0->i_ino > ip1->i_ino) {
fs/xfs/xfs_inode.h +10 -2
@@ -67,6 +67,9 @@ typedef struct xfs_inode {spinlock_t i_ioend_lock;struct work_struct i_ioend_work;struct list_head i_ioend_list; + +/* protect changing the mode to/from DAX */ +struct percpu_rw_semaphore i_dax_sem; } xfs_inode_t;/* Convert from vfs inode to xfs inode */
@@ -278,10 +281,13 @@ static inline void xfs_ifunlock(struct xfs_inode *ip)#define XFS_ILOCK_SHARED (1<<3)#define XFS_MMAPLOCK_EXCL (1<<4)#define XFS_MMAPLOCK_SHARED (1<<5) +#define XFS_DAX_EXCL (1<<6) +#define XFS_DAX_SHARED (1<<7)#define XFS_LOCK_MASK (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED \ | XFS_ILOCK_EXCL | XFS_ILOCK_SHARED \ - | XFS_MMAPLOCK_EXCL | XFS_MMAPLOCK_SHARED) + | XFS_MMAPLOCK_EXCL | XFS_MMAPLOCK_SHARED \ + | XFS_DAX_EXCL | XFS_DAX_SHARED)#define XFS_LOCK_FLAGS \ { XFS_IOLOCK_EXCL, "IOLOCK_EXCL" }, \
@@ -289,7 +295,9 @@ static inline void xfs_ifunlock(struct xfs_inode *ip) { XFS_ILOCK_EXCL, "ILOCK_EXCL" }, \ { XFS_ILOCK_SHARED, "ILOCK_SHARED" }, \ { XFS_MMAPLOCK_EXCL, "MMAPLOCK_EXCL" }, \ - { XFS_MMAPLOCK_SHARED, "MMAPLOCK_SHARED" } + { XFS_MMAPLOCK_SHARED, "MMAPLOCK_SHARED" }, \ + { XFS_DAX_EXCL, "DAX_EXCL" }, \ + { XFS_DAX_SHARED, "DAX_SHARED" }/*
fs/xfs/xfs_iops.c +23 -1
@@ -1158,6 +1158,16 @@ xfs_vn_tmpfile(return xfs_generic_create (dir, dentry, mode,0 , true); } +static void xfs_lock_mode (struct inode *inode) +{ +xfs_ilock (XFS_I (inode),XFS_DAX_SHARED ); +} + +static void xfs_unlock_mode (struct inode *inode) +{ +xfs_iunlock (XFS_I (inode),XFS_DAX_SHARED ); +} +static const struct inode_operations xfs_inode_operations = { .get_acl = xfs_get_acl, .set_acl = xfs_set_acl,
@@ -1168,6 +1178,18 @@ static const struct inode_operations xfs_inode_operations = { .update_time = xfs_vn_update_time, }; +static const struct inode_operations xfs_reg_inode_operations = { + .get_acl = xfs_get_acl, + .set_acl = xfs_set_acl, + .getattr = xfs_vn_getattr, + .setattr = xfs_vn_setattr, + .listxattr = xfs_vn_listxattr, + .fiemap = xfs_vn_fiemap, + .update_time = xfs_vn_update_time, + .lock_mode = xfs_lock_mode, + .unlock_mode = xfs_unlock_mode, +}; +static const struct inode_operations xfs_dir_inode_operations = { .create = xfs_vn_create, .lookup = xfs_vn_lookup,
@@ -1372,7 +1394,7 @@ xfs_setup_iops(switch (inode->i_mode &S_IFMT ) {case S_IFREG : - inode->i_op = &xfs_inode_operations; + inode->i_op = &xfs_reg_inode_operations; inode->i_fop = &xfs_file_operations;if (IS_DAX (inode)) inode->i_mapping->a_ops = &xfs_dax_aops;
Signature · 1 line
2.21.0
kbuild test robot
build botRe: [RFC PATCH V2 08/12] fs/xfs: Add lock/unlock mode to xfs
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…
Hi,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on xfs-linux/for-next]
[also build test ERROR on linux/master linus/master v5.5-rc5] [cannot apply to djwong-xfs/djwong-devel next-20200110]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/ira-weiny-intel-com/Enable-per-file-directory-DAX-operations-V2/20200111-095526 base: https://git.kernel.org/pub/scm/fs/xfs/xfs-linux.git for-next config: x86_64-lkp (attached as .config) compiler: gcc-7 (Debian 7.5.0-3) 7.5.0 reproduce: # save the attached .config to linux build tree make ARCH=x86_64
If you fix the issue, kindly add following tag
All errors (new ones prefixed by >>):
fs/xfs/xfs_inode.c: In function 'xfs_isilocked':
>> fs/xfs/xfs_inode.c:394:43: error: macro "percpu_rwsem_is_held" passed 2 arguments, but takes just 1
percpu_rwsem_is_held(&ip->i_dax_sem, 0);
^
>> fs/xfs/xfs_inode.c:394:5: error: 'percpu_rwsem_is_held' undeclared (first use in this function); did you mean 'percpu_ref_is_zero'?
percpu_rwsem_is_held(&ip->i_dax_sem, 0);
^~~~~~~~~~~~~~~~~~~~
percpu_ref_is_zero
fs/xfs/xfs_inode.c:394:5: note: each undeclared identifier is reported only once for each function it appears in
>> fs/xfs/xfs_inode.c:395:26: error: passing argument 1 of 'rwsem_is_locked' from incompatible pointer type [-Werror=incompatible-pointer-types]
return rwsem_is_locked(&ip->i_dax_sem);
^
In file included from include/linux/mm_types.h:11:0,
from include/linux/mmzone.h:21,
from include/linux/gfp.h:6,
from include/linux/xarray.h:14,
from include/linux/radix-tree.h:18,
from include/linux/fs.h:15,
from include/linux/iversion.h:5,
from fs/xfs/xfs_inode.c:6: include/linux/rwsem.h:63:19: note: expected 'struct rw_semaphore *' but argument is of type 'struct percpu_rw_semaphore *'
static inline int rwsem_is_locked(struct rw_semaphore *sem)
^~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
vim +/percpu_rwsem_is_held +394 fs/xfs/xfs_inode.c
365
366 #if defined(DEBUG) || defined(XFS_WARN)
367 int
368 xfs_isilocked(
369 xfs_inode_t *ip,
370 uint lock_flags)
371 {
372 if (lock_flags & (XFS_ILOCK_EXCL|XFS_ILOCK_SHARED)) {
373 if (!(lock_flags & XFS_ILOCK_SHARED))
374 return !!ip->i_lock.mr_writer;
375 return rwsem_is_locked(&ip->i_lock.mr_lock);
376 }
377
378 if (lock_flags & (XFS_MMAPLOCK_EXCL|XFS_MMAPLOCK_SHARED)) {
379 if (!(lock_flags & XFS_MMAPLOCK_SHARED))
380 return !!ip->i_mmaplock.mr_writer;
381 return rwsem_is_locked(&ip->i_mmaplock.mr_lock);
382 }
383
384 if (lock_flags & (XFS_IOLOCK_EXCL|XFS_IOLOCK_SHARED)) {
385 if (!(lock_flags & XFS_IOLOCK_SHARED))
386 return !debug_locks ||
387 lockdep_is_held_type(&VFS_I(ip)->i_rwsem, 0);
388 return rwsem_is_locked(&VFS_I(ip)->i_rwsem);
389 }
390
391 if (lock_flags & (XFS_DAX_EXCL|XFS_DAX_SHARED)) {
392 if (!(lock_flags & XFS_DAX_SHARED))
393 return !debug_locks ||
> 394 percpu_rwsem_is_held(&ip->i_dax_sem, 0); > 395 return rwsem_is_locked(&ip->i_dax_sem);
396 }
397
398 ASSERT(0);
399 return 0;
400 }
401 #endif
402
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corporation
Re: [RFC PATCH V2 08/12] fs/xfs: Add lock/unlock mode to xfs
In reply to [email protected]Quoted 37 lines · On Fri, Jan 10, 2020 at 11:29:38AM -0800, [email protected] wrote:
From: Ira Weiny <[email protected]>
XFS requires regular files to be locked while changing to/from DAX mode.
Define a new DAX lock type and implement the [un]lock_mode() inode operation callbacks.
We define a new XFS_DAX_* lock type to carry the lock through the transaction because we don't want to use IOLOCK as that would cause performance issues with locking of the inode itself.
Signed-off-by Ira Weiny <[email protected]>--- fs/xfs/xfs_icache.c | 2 ++ fs/xfs/xfs_inode.c | 37 +++++++++++++++++++++++++++++++++++-- fs/xfs/xfs_inode.h | 12 ++++++++++-- fs/xfs/xfs_iops.c | 24 +++++++++++++++++++++++- 4 files changed, 70 insertions(+), 5 deletions(-)fs/xfs/xfs_icache.c +2
-0@@ -74,6 +74,8 @@ xfs_inode_alloc(INIT_LIST_HEAD (&ip->i_ioend_list);spin_lock_init (&ip->i_ioend_lock); +percpu_init_rwsem (&ip->i_dax_sem); +return ip; }fs/xfs/xfs_inode.c +0
-0
fs/xfs/xfs_inode.c xfs_ilock_attr_map_shared( · line 145
Quoted 5 lines
fs/xfs/xfs_inode.c +1
-1@@ -142,12 +142,12 @@ xfs_ilock_attr_map_shared(* * Basic locking order: * -* i_rwsem -> i_mmap_lock -> page_lock -> i_ilock +* i_rwsem -> i_dax_sem -> i_mmap_lock -> page_lock -> i_ilock
Mmmmmm, more locks. Can we skip the extra lock if CONFIG_FSDAX=n or if the filesystem devices don't support DAX at all?
Also, I don't think we're actually following the i_rwsem -> i_daxsem order in fallocate, and possibly elsewhere too?
Does the vfs have to take the i_dax_sem to do remapping things like reflink? (Pretend that reflink and dax are compatible for the moment)
Quoted 134 lines
fs/xfs/xfs_inode.c +34
-1* mmap_sem locking order: * * i_rwsem -> page lock -> mmap_sem -* mmap_sem -> i_mmap_lock -> page_lock +* mmap_sem -> i_dax_sem -> i_mmap_lock -> page_lock * * The difference in mmap_sem locking order mean that we cannot hold the * i_mmap_lock over syscall based read(2)/write(2) based IO. These IO paths can @@ -181,6 +181,13 @@ xfs_ilock(ASSERT ((lock_flags & (XFS_ILOCK_SHARED |XFS_ILOCK_EXCL )) != (XFS_ILOCK_SHARED |XFS_ILOCK_EXCL ));ASSERT ((lock_flags & ~(XFS_LOCK_MASK |XFS_LOCK_SUBCLASS_MASK )) ==0 ); +ASSERT ((lock_flags & (XFS_DAX_SHARED |XFS_DAX_EXCL )) != + (XFS_DAX_SHARED |XFS_DAX_EXCL )); + +if (lock_flags &XFS_DAX_EXCL ) +percpu_down_write (&ip->i_dax_sem); +else if (lock_flags &XFS_DAX_SHARED ) +percpu_down_read (&ip->i_dax_sem);if (lock_flags &XFS_IOLOCK_EXCL ) { down_write_nested(&VFS_I(ip)->i_rwsem,@@ -224,6 +231,8 @@ xfs_ilock_nowait(* You can't set both SHARED and EXCL for the same lock, * and only XFS_IOLOCK_SHARED, XFS_IOLOCK_EXCL, XFS_ILOCK_SHARED, * and XFS_ILOCK_EXCL are valid values to set in lock_flags. +* +* XFS_DAX_* is not allowed */ ASSERT ((lock_flags & (XFS_IOLOCK_SHARED |XFS_IOLOCK_EXCL )) != (XFS_IOLOCK_SHARED |XFS_IOLOCK_EXCL ));@@ -232,6 +241,7 @@ xfs_ilock_nowait(ASSERT ((lock_flags & (XFS_ILOCK_SHARED |XFS_ILOCK_EXCL )) != (XFS_ILOCK_SHARED |XFS_ILOCK_EXCL ));ASSERT ((lock_flags & ~(XFS_LOCK_MASK |XFS_LOCK_SUBCLASS_MASK )) ==0 ); +ASSERT ((lock_flags & (XFS_DAX_SHARED |XFS_DAX_EXCL )) ==0 );if (lock_flags &XFS_IOLOCK_EXCL ) {if (!down_write_trylock (&VFS_I (ip)->i_rwsem))@@ -302,6 +312,8 @@ xfs_iunlock( (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL));ASSERT ((lock_flags & ~(XFS_LOCK_MASK |XFS_LOCK_SUBCLASS_MASK )) ==0 );ASSERT (lock_flags !=0 ); +ASSERT ((lock_flags & (XFS_DAX_SHARED |XFS_DAX_EXCL )) != + (XFS_DAX_SHARED |XFS_DAX_EXCL ));if (lock_flags &XFS_IOLOCK_EXCL )up_write (&VFS_I (ip)->i_rwsem);@@ -318,6 +330,11 @@ xfs_iunlock(else if (lock_flags &XFS_ILOCK_SHARED )mrunlock_shared (&ip->i_lock); +if (lock_flags &XFS_DAX_EXCL ) +percpu_up_write (&ip->i_dax_sem); +else if (lock_flags &XFS_DAX_SHARED ) +percpu_up_read (&ip->i_dax_sem); +trace_xfs_iunlock (ip, lock_flags, _RET_IP_); }@@ -333,6 +350,8 @@ xfs_ilock_demote(ASSERT (lock_flags & (XFS_IOLOCK_EXCL |XFS_MMAPLOCK_EXCL |XFS_ILOCK_EXCL ));ASSERT ((lock_flags & ~(XFS_IOLOCK_EXCL |XFS_MMAPLOCK_EXCL |XFS_ILOCK_EXCL )) ==0 ); +/* XFS_DAX_* is not allowed */ +ASSERT ((lock_flags & (XFS_DAX_SHARED |XFS_DAX_EXCL )) ==0 );if (lock_flags &XFS_ILOCK_EXCL )mrdemote (&ip->i_lock);@@ -369,6 +388,13 @@ xfs_isilocked(return rwsem_is_locked (&VFS_I (ip)->i_rwsem); } +if (lock_flags & (XFS_DAX_EXCL |XFS_DAX_SHARED )) { +if (!(lock_flags &XFS_DAX_SHARED )) +return !debug_locks || +percpu_rwsem_is_held (&ip->i_dax_sem,0 ); +return rwsem_is_locked (&ip->i_dax_sem); + } +ASSERT (0 );return 0 ; }@@ -465,6 +491,9 @@ xfs_lock_inodes(ASSERT (!(lock_mode &XFS_ILOCK_EXCL ) || inodes <=XFS_ILOCK_MAX_SUBCLASS +1 ); +/* XFS_DAX_* is not allowed */ +ASSERT ((lock_mode & (XFS_DAX_SHARED |XFS_DAX_EXCL )) ==0 ); +if (lock_mode &XFS_IOLOCK_EXCL ) {ASSERT (!(lock_mode & (XFS_MMAPLOCK_EXCL |XFS_ILOCK_EXCL ))); }else if (lock_mode &XFS_MMAPLOCK_EXCL )@@ -566,6 +595,10 @@ xfs_lock_two_inodes(ASSERT (!(ip0_mode & (XFS_MMAPLOCK_SHARED |XFS_MMAPLOCK_EXCL )) || !(ip1_mode & (XFS_ILOCK_SHARED |XFS_ILOCK_EXCL ))); +/* XFS_DAX_* is not allowed */ +ASSERT ((ip0_mode & (XFS_DAX_SHARED |XFS_DAX_EXCL )) ==0 ); +ASSERT ((ip1_mode & (XFS_DAX_SHARED |XFS_DAX_EXCL )) ==0 ); +ASSERT (ip0->i_ino != ip1->i_ino);if (ip0->i_ino > ip1->i_ino) {fs/xfs/xfs_inode.h +7
-1@@ -67,6 +67,9 @@ typedef struct xfs_inode {spinlock_t i_ioend_lock;struct work_struct i_ioend_work;struct list_head i_ioend_list; + +/* protect changing the mode to/from DAX */ +struct percpu_rw_semaphore i_dax_sem; } xfs_inode_t;/* Convert from vfs inode to xfs inode */ @@ -278,10 +281,13 @@ static inline void xfs_ifunlock(struct xfs_inode *ip)#define XFS_ILOCK_SHARED (1<<3)#define XFS_MMAPLOCK_EXCL (1<<4)#define XFS_MMAPLOCK_SHARED (1<<5) +#define XFS_DAX_EXCL (1<<6) +#define XFS_DAX_SHARED (1<<7)#define XFS_LOCK_MASK (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED \ | XFS_ILOCK_EXCL | XFS_ILOCK_SHARED \ - | XFS_MMAPLOCK_EXCL | XFS_MMAPLOCK_SHARED) + | XFS_MMAPLOCK_EXCL | XFS_MMAPLOCK_SHARED \ + | XFS_DAX_EXCL | XFS_DAX_SHARED)#define XFS_LOCK_FLAGS \ { XFS_IOLOCK_EXCL, "IOLOCK_EXCL" }, \
fs/xfs/xfs_inode.h static inline void xfs_ifunlock(struct xfs_inode *ip) · line 299
Quoted 6 lines
fs/xfs/xfs_inode.h +2
-1@@ -289,7 +295,9 @@ static inline void xfs_ifunlock(struct xfs_inode *ip) { XFS_ILOCK_EXCL, "ILOCK_EXCL" }, \ { XFS_ILOCK_SHARED, "ILOCK_SHARED" }, \ { XFS_MMAPLOCK_EXCL, "MMAPLOCK_EXCL" }, \ - { XFS_MMAPLOCK_SHARED, "MMAPLOCK_SHARED" } + { XFS_MMAPLOCK_SHARED, "MMAPLOCK_SHARED" }, \ + { XFS_DAX_EXCL, "DAX_EXCL" }, \
Whitespace between the comma & string.
Quoted 45 lines
fs/xfs/xfs_inode.h +1
-0+ { XFS_DAX_SHARED, "DAX_SHARED" }/* fs/xfs/xfs_iops.c +22
-0@@ -1158,6 +1158,16 @@ xfs_vn_tmpfile(return xfs_generic_create (dir, dentry, mode,0 , true); } +static void xfs_lock_mode (struct inode *inode) +{ +xfs_ilock (XFS_I (inode),XFS_DAX_SHARED ); +} + +static void xfs_unlock_mode (struct inode *inode) +{ +xfs_iunlock (XFS_I (inode),XFS_DAX_SHARED ); +} +static const struct inode_operations xfs_inode_operations = { .get_acl = xfs_get_acl, .set_acl = xfs_set_acl,@@ -1168,6 +1178,18 @@ static const struct inode_operations xfs_inode_operations = { .update_time = xfs_vn_update_time, }; +static const struct inode_operations xfs_reg_inode_operations = { + .get_acl = xfs_get_acl, + .set_acl = xfs_set_acl, + .getattr = xfs_vn_getattr, + .setattr = xfs_vn_setattr, + .listxattr = xfs_vn_listxattr, + .fiemap = xfs_vn_fiemap, + .update_time = xfs_vn_update_time, + .lock_mode = xfs_lock_mode, + .unlock_mode = xfs_unlock_mode, +}; +static const struct inode_operations xfs_dir_inode_operations = { .create = xfs_vn_create, .lookup = xfs_vn_lookup,
fs/xfs/xfs_iops.c xfs_setup_iops( · line 1397
Quoted 5 lines
fs/xfs/xfs_iops.c +1
-1@@ -1372,7 +1394,7 @@ xfs_setup_iops(switch (inode->i_mode &S_IFMT ) {case S_IFREG : - inode->i_op = &xfs_inode_operations; + inode->i_op = &xfs_reg_inode_operations;
xfs_file_inode_operations?
--D
Quoted 6 lines
fs/xfs/xfs_iops.c +0
-0inode->i_fop = &xfs_file_operations;if (IS_DAX (inode)) inode->i_mapping->a_ops = &xfs_dax_aops;Signature · 1 line
2.21.0
Re: [RFC PATCH V2 08/12] fs/xfs: Add lock/unlock mode to xfs
Quoted 2 lines · Darrick J. Wong
Quoted 1 line · On Fri, Jan 10, 2020 at 11:29:38AM -0800, [email protected] wrote:
From: Ira Weiny <[email protected]>
[snip]
Quoted 14 lines
fs/xfs/xfs_inode.c xfs_ilock_attr_map_shared( · line 145
Quoted 11 lines
fs/xfs/xfs_inode.c +1
-1@@ -142,12 +142,12 @@ xfs_ilock_attr_map_shared(* * Basic locking order: * -* i_rwsem -> i_mmap_lock -> page_lock -> i_ilock +* i_rwsem -> i_dax_sem -> i_mmap_lock -> page_lock -> i_ilock Mmmmmm, more locks. Can we skip the extra lock if
CONFIG_FSDAX=nor if the filesystem devices don't support DAX at all?
I'll look into it.
Quoted 3 lines
Also, I don't think we're actually following the
i_rwsem->i_daxsemorder in fallocate, and possibly elsewhere too?
I'll have to verify. It took a lot of iterations to get the order working so I'm not going to claim perfection.
Quoted 3 lines
Does the vfs have to take the
i_dax_semto do remapping things like reflink? (Pretend that reflink and dax are compatible for the moment)
Honestly I can't say for sure. For this series I was careful to exclude reflink from the locking requirement.
[snip]
Quoted 12 lines
fs/xfs/xfs_inode.c static inline void xfs_ifunlock(struct xfs_inode *ip) · line 299
Quoted 10 lines
fs/xfs/xfs_inode.c +2
-1#define XFS_LOCK_FLAGS \ { XFS_IOLOCK_EXCL, "IOLOCK_EXCL" }, \@@ -289,7 +295,9 @@ static inline void xfs_ifunlock(struct xfs_inode *ip) { XFS_ILOCK_EXCL, "ILOCK_EXCL" }, \ { XFS_ILOCK_SHARED, "ILOCK_SHARED" }, \ { XFS_MMAPLOCK_EXCL, "MMAPLOCK_EXCL" }, \ - { XFS_MMAPLOCK_SHARED, "MMAPLOCK_SHARED" } + { XFS_MMAPLOCK_SHARED, "MMAPLOCK_SHARED" }, \ + { XFS_DAX_EXCL, "DAX_EXCL" }, \Whitespace between the comma & string.
Fixed.
[snip]
Quoted 6 lines
Quoted 6 lines
fs/xfs/xfs_inode.c +1
-0+static const struct inode_operations xfs_dir_inode_operations = { .create = xfs_vn_create, .lookup = xfs_vn_lookup,@@ -1372,7 +1394,7 @@ xfs_setup_iops(
Quoted 6 lines
fs/xfs/xfs_inode.c xfs_setup_iops( · line 1397
Quoted 4 lines
fs/xfs/xfs_inode.c +1
-1switch (inode->i_mode &S_IFMT ) {case S_IFREG : - inode->i_op = &xfs_inode_operations; + inode->i_op = &xfs_reg_inode_operations;
xfs_file_inode_operations?
Sounds better. Fixed.
Ira
Re: [RFC PATCH V2 08/12] fs/xfs: Add lock/unlock mode to xfs
Quoted 21 lines · Ira Weiny
Quoted 2 lines · Darrick J. Wong
Quoted 1 line · On Fri, Jan 10, 2020 at 11:29:38AM -0800, [email protected] wrote:
From: Ira Weiny <[email protected]>
[snip]
Quoted 14 lines
fs/xfs/xfs_inode.c xfs_ilock_attr_map_shared( · line 145
Quoted 11 lines
fs/xfs/xfs_inode.c +1
-1@@ -142,12 +142,12 @@ xfs_ilock_attr_map_shared(* * Basic locking order: * -* i_rwsem -> i_mmap_lock -> page_lock -> i_ilock +* i_rwsem -> i_dax_sem -> i_mmap_lock -> page_lock -> i_ilock Mmmmmm, more locks. Can we skip the extra lock if
CONFIG_FSDAX=nor if the filesystem devices don't support DAX at all?
Quoted 8 lines
I'll look into it.
Quoted 3 lines
Also, I don't think we're actually following the
i_rwsem->i_daxsemorder in fallocate, and possibly elsewhere too?I'll have to verify. It took a lot of iterations to get the order working so I'm not going to claim perfection.
Yes this was inconsistent. The code was right WRT i_rwsem.
mmap_sem may have issues:
What about this?
fs/xfs/xfs_inode.c +2 -2
@@ -142,12 +142,12 @@ xfs_ilock_attr_map_shared(* * Basic locking order: * -* i_rwsem -> i_dax_sem -> i_mmap_lock -> page_lock -> i_ilock +* i_dax_sem -> i_rwsem -> i_mmap_lock -> page_lock -> i_ilock * * mmap_sem locking order: * * i_rwsem -> page lock -> mmap_sem -* mmap_sem -> i_dax_sem -> i_mmap_lock -> page_lock +* i_dax_sem -> mmap_sem -> i_mmap_lock -> page_lock * * The difference in mmap_sem locking order mean that we cannot hold the * i_mmap_lock over syscall based read(2)/write(2) based IO. These IO paths can
mm/mmap.c +0 -6
@@ -1547,18 +1547,12 @@ unsigned long do_mmap(struct file *file, unsigned long addr, vm_flags |=VM_NORESERVE ; } -if (file) -lock_inode_mode (file_inode (file)); - addr =mmap_region (file, addr, len, vm_flags, pgoff, uf);if (!IS_ERR_VALUE (addr) && ((vm_flags &VM_LOCKED ) || (flags & (MAP_POPULATE |MAP_NONBLOCK )) ==MAP_POPULATE )) *populate = len; -if (file) -unlock_inode_mode (file_inode (file)); -return addr; }
mm/util.c +8 -1
@@ -501,11 +501,18 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr, ret =security_mmap_file (file, prot, flag);if (!ret) { -if (down_write_killable (&mm->mmap_sem)) +if (file) +lock_inode_mode (file_inode (file)); +if (down_write_killable (&mm->mmap_sem)) { +if (file) +unlock_inode_mode (file_inode (file));return -EINTR ; + } ret =do_mmap_pgoff (file, addr, len, prot, flag, pgoff, &populate, &uf);up_write (&mm->mmap_sem); +if (file) +unlock_inode_mode (file_inode (file));userfaultfd_unmap_complete (mm, &uf);if (populate)mm_populate (ret, populate);
Re: [RFC PATCH V2 08/12] fs/xfs: Add lock/unlock mode to xfs
In reply to Darrick J. WongQuoted 3 lines · Darrick J. Wong
Quoted 2 lines · On Fri, Jan 10, 2020 at 11:29:38AM -0800, [email protected] wrote:
From: Ira Weiny <[email protected]>
[snip]
Quoted 14 lines
fs/xfs/xfs_inode.c xfs_ilock_attr_map_shared( · line 145
Quoted 11 lines
fs/xfs/xfs_inode.c +1
-1@@ -142,12 +142,12 @@ xfs_ilock_attr_map_shared(* * Basic locking order: * -* i_rwsem -> i_mmap_lock -> page_lock -> i_ilock +* i_rwsem -> i_dax_sem -> i_mmap_lock -> page_lock -> i_ilock Mmmmmm, more locks. Can we skip the extra lock if
CONFIG_FSDAX=nor if the filesystem devices don't support DAX at all?
I've looked into this a bit more and I think skipping on CONFIG_FSDAX=n is ok but doing so on individual devices is not going to be possible because we don't have that information at the vfs layer.
I'll continue to think about how to mitigate this more while I add CONFIG_FSDAX checks before rolling out a new patch set.
Quoted 7 lines
Also, I don't think we're actually following the
i_rwsem->i_daxsemorder in fallocate, and possibly elsewhere too?Does the vfs have to take the
i_dax_semto do remapping things like reflink? (Pretend that reflink and dax are compatible for the moment)
I spoke with Dan today about this and we believe the answer is going to be yes. However, not until the code is added to support DAX in reflink. Because currently this is only required for places which use "IS_DAX()" to see the state of the inode.
Currently the vfs layer does not have any IS_DAX() checks in the reflink path. But when they are added they will be required to take this sem.
Ira
Jan Kara
maintainerRe: [RFC PATCH V2 08/12] fs/xfs: Add lock/unlock mode to xfs
In reply to [email protected]Quoted 12 lines · On Fri 10-01-20 11:29:38, [email protected] wrote:
From: Ira Weiny <[email protected]>
XFS requires regular files to be locked while changing to/from DAX mode.
Define a new DAX lock type and implement the [un]lock_mode() inode operation callbacks.
We define a new XFS_DAX_* lock type to carry the lock through the transaction because we don't want to use IOLOCK as that would cause performance issues with locking of the inode itself.
Signed-off-by Ira Weiny <[email protected]>
...
fs/xfs/xfs_inode.h typedef struct xfs_inode { · line 73
Quoted 12 lines
fs/xfs/xfs_inode.h +3
-0@@ -67,6 +67,9 @@ typedef struct xfs_inode {spinlock_t i_ioend_lock;struct work_struct i_ioend_work;struct list_head i_ioend_list; + +/* protect changing the mode to/from DAX */ +struct percpu_rw_semaphore i_dax_sem; } xfs_inode_t;
This adds overhead of ~32k per inode for typical distro kernel. That's not going to fly. That's why ext4 has similar kind of lock in the superblock shared by all inodes. For read side it does not matter because that's per-cpu and shared lock. For write side we don't care as changing inode access mode should be rare.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [RFC PATCH V2 08/12] fs/xfs: Add lock/unlock mode to xfs
Quoted 14 lines · Jan Kara
Quoted 12 lines · On Fri 10-01-20 11:29:38, [email protected] wrote:
From: Ira Weiny <[email protected]>
XFS requires regular files to be locked while changing to/from DAX mode.
Define a new DAX lock type and implement the [un]lock_mode() inode operation callbacks.
We define a new XFS_DAX_* lock type to carry the lock through the transaction because we don't want to use IOLOCK as that would cause performance issues with locking of the inode itself.
Signed-off-by Ira Weiny <[email protected]>...
Quoted 14 lines
fs/xfs/xfs_inode.h typedef struct xfs_inode { · line 73
Quoted 12 lines
fs/xfs/xfs_inode.h +3
-0@@ -67,6 +67,9 @@ typedef struct xfs_inode {spinlock_t i_ioend_lock;struct work_struct i_ioend_work;struct list_head i_ioend_list; + +/* protect changing the mode to/from DAX */ +struct percpu_rw_semaphore i_dax_sem; } xfs_inode_t;This adds overhead of ~32k per inode for typical distro kernel.
Wow!
Quoted 2 lines
That's not
going to fly.
Probably not...
Quoted 4 lines
That's why ext4 has similar kind of lock in the superblock shared by all inodes. For read side it does not matter because that's per-cpu and shared lock. For write side we don't care as changing inode access mode should be rare.
Sounds reasonable to me. I'll convert it.
Thanks for pointing this out, that would have been bad indeed. Ira
RFC PATCH v2 9/12 fs: Prevent mode change if file is mmap'ed
In reply to [email protected]From: Ira Weiny <[email protected]>
Page faults need to ensure the inode mode is correct and consistent with the vmf information at the time of the fault. There is no easy way to ensure the vmf information is correct if a mode change is in progress. Furthermore, there is no good use case to require a mode change while the file is mmap'ed.
Track mmap's of the file and fail the mode change if the file is mmap'ed.
--- fs/inode.c | 2 ++ fs/xfs/xfs_ioctl.c | 8 ++++++++ include/linux/fs.h | 1 + mm/mmap.c | 19 +++++++++++++++++-- 4 files changed, 28 insertions(+), 2 deletions(-)
fs/inode.c +2 -0
@@ -245,6 +245,8 @@ static struct inode *alloc_inode(struct super_block *sb)return NULL ; } +atomic64_set (&inode->i_mapped,0 ); +return inode; }
fs/xfs/xfs_ioctl.c +8 -0
@@ -1200,6 +1200,14 @@ xfs_ioctl_setattr_dax_invalidate( goto out_unlock; } +/* +* If there is a mapping in place we must remain in our current mode. +*/ +if (atomic64_read (&inode->i_mapped)) { + error = -EBUSY ; + goto out_unlock; + } + error =filemap_write_and_wait (inode->i_mapping);if (error) goto out_unlock;
include/linux/fs.h +1 -0
@@ -740,6 +740,7 @@ struct inode {#endif void *i_private;/* fs or device private pointer */ +atomic64_t i_mapped; } __randomize_layout;struct timespec64 timestamp_truncate (struct timespec64 t,struct inode *inode);
mm/mmap.c +17 -2
@@ -171,12 +171,17 @@ void unlink_file_vma(struct vm_area_struct *vma)static struct vm_area_struct *remove_vma (struct vm_area_struct *vma) {struct vm_area_struct *next = vma->vm_next; +struct file *f = vma->vm_file;might_sleep ();if (vma->vm_ops && vma->vm_ops->close) vma->vm_ops->close (vma); -if (vma->vm_file) -fput (vma->vm_file); +if (f) { +struct inode *inode =file_inode (f); +if (inode) +atomic64_dec (&inode->i_mapped); +fput (f); + }mpol_put (vma_policy (vma));vm_area_free (vma);return next;
@@ -1837,6 +1842,16 @@ unsigned long mmap_region(struct file *file, unsigned long addr,vma_set_page_prot (vma); +/* +* Track if there is mapping in place such that a mode change +* does not occur on a file which is mapped +*/ +if (file) { +struct inode *inode =file_inode (file); + +atomic64_inc (&inode->i_mapped); + } +return addr; unmap_and_free_vma:
Signature · 1 line
2.21.0
Re: [RFC PATCH V2 09/12] fs: Prevent mode change if file is mmap'ed
Quoted 37 lines · On Fri, Jan 10, 2020 at 11:29:39AM -0800, [email protected] wrote:
From: Ira Weiny <[email protected]>
Page faults need to ensure the inode mode is correct and consistent with the vmf information at the time of the fault. There is no easy way to ensure the vmf information is correct if a mode change is in progress. Furthermore, there is no good use case to require a mode change while the file is mmap'ed.
Track mmap's of the file and fail the mode change if the file is mmap'ed.
Signed-off-by Ira Weiny <[email protected]>--- fs/inode.c | 2 ++ fs/xfs/xfs_ioctl.c | 8 ++++++++ include/linux/fs.h | 1 + mm/mmap.c | 19 +++++++++++++++++-- 4 files changed, 28 insertions(+), 2 deletions(-)fs/inode.c +2
-0@@ -245,6 +245,8 @@ static struct inode *alloc_inode(struct super_block *sb)return NULL ; } +atomic64_set (&inode->i_mapped,0 ); +return inode; }fs/xfs/xfs_ioctl.c +0
-0
fs/xfs/xfs_ioctl.c xfs_ioctl_setattr_dax_invalidate( · line 1206
Quoted 7 lines
fs/xfs/xfs_ioctl.c +4
-0@@ -1200,6 +1200,14 @@ xfs_ioctl_setattr_dax_invalidate( goto out_unlock; } +/* +* If there is a mapping in place we must remain in our current mode. +*/ +if (atomic64_read (&inode->i_mapped)) {
Urk, should we really be messing around with the address space internals?
Quoted 12 lines
fs/xfs/xfs_ioctl.c +4
-0+ error = -EBUSY ; + goto out_unlock; + } + error =filemap_write_and_wait (inode->i_mapping);if (error) goto out_unlock;include/linux/fs.h +0
-0
include/linux/fs.h struct inode { · line 743
Quoted 4 lines
include/linux/fs.h +1
-0@@ -740,6 +740,7 @@ struct inode {#endif void *i_private;/* fs or device private pointer */ +atomic64_t i_mapped;
I would have expected to find this in struct address_space since the mapping count is a function of the address space, right?
--D
Quoted 47 lines
include/linux/fs.h +0
-0} __randomize_layout;struct timespec64 timestamp_truncate (struct timespec64 t,struct inode *inode);mm/mmap.c +17
-2@@ -171,12 +171,17 @@ void unlink_file_vma(struct vm_area_struct *vma)static struct vm_area_struct *remove_vma (struct vm_area_struct *vma) {struct vm_area_struct *next = vma->vm_next; +struct file *f = vma->vm_file;might_sleep ();if (vma->vm_ops && vma->vm_ops->close) vma->vm_ops->close (vma); -if (vma->vm_file) -fput (vma->vm_file); +if (f) { +struct inode *inode =file_inode (f); +if (inode) +atomic64_dec (&inode->i_mapped); +fput (f); + }mpol_put (vma_policy (vma));vm_area_free (vma);return next;@@ -1837,6 +1842,16 @@ unsigned long mmap_region(struct file *file, unsigned long addr,vma_set_page_prot (vma); +/* +* Track if there is mapping in place such that a mode change +* does not occur on a file which is mapped +*/ +if (file) { +struct inode *inode =file_inode (file); + +atomic64_inc (&inode->i_mapped); + } +return addr; unmap_and_free_vma:Signature · 1 line
2.21.0
Re: [RFC PATCH V2 09/12] fs: Prevent mode change if file is mmap'ed
Quoted 3 lines · Darrick J. Wong
Quoted 2 lines · On Fri, Jan 10, 2020 at 11:29:39AM -0800, [email protected] wrote:
From: Ira Weiny <[email protected]>
[snip]
Quoted 9 lines
Quoted 9 lines
fs/xfs/xfs_ioctl.c +0
-0@@ -1200,6 +1200,14 @@ xfs_ioctl_setattr_dax_invalidate( goto out_unlock; }
Quoted 7 lines
fs/xfs/xfs_ioctl.c xfs_ioctl_setattr_dax_invalidate( · line 1206
Quoted 4 lines
fs/xfs/xfs_ioctl.c +4
-0+/* +* If there is a mapping in place we must remain in our current mode. +*/ +if (atomic64_read (&inode->i_mapped)) {Urk, should we really be messing around with the address space internals?
I contemplated a function call instead of checking i_mapped directly? Is that what you mean?
Quoted 15 lines
Quoted 15 lines
fs/xfs/xfs_ioctl.c +4
-0+ error = -EBUSY ; + goto out_unlock; + } + error =filemap_write_and_wait (inode->i_mapping);if (error) goto out_unlock;include/linux/fs.h +0
-0@@ -740,6 +740,7 @@ struct inode {#endif
Quoted 5 lines
include/linux/fs.h struct inode { · line 743
Quoted 2 lines
include/linux/fs.h +1
-0void *i_private;/* fs or device private pointer */ +atomic64_t i_mapped;I would have expected to find this in struct
address_spacesince the mapping count is a function of the address space, right?
I suppose but the only external call (above) would be passing an inode. So to me it seemed better here.
Ira
Quoted 3 lines
--D
Re: [RFC PATCH V2 09/12] fs: Prevent mode change if file is mmap'ed
Quoted 24 lines · Ira Weiny
Quoted 3 lines · Darrick J. Wong
Quoted 2 lines · On Fri, Jan 10, 2020 at 11:29:39AM -0800, [email protected] wrote:
From: Ira Weiny <[email protected]>
[snip]
Quoted 9 lines
Quoted 9 lines
fs/xfs/xfs_ioctl.c +0
-0@@ -1200,6 +1200,14 @@ xfs_ioctl_setattr_dax_invalidate( goto out_unlock; }Quoted 7 lines
fs/xfs/xfs_ioctl.c xfs_ioctl_setattr_dax_invalidate( · line 1206
Quoted 4 lines
fs/xfs/xfs_ioctl.c +4
-0+/* +* If there is a mapping in place we must remain in our current mode. +*/ +if (atomic64_read (&inode->i_mapped)) {Urk, should we really be messing around with the address space internals?
Quoted 2 lines
I contemplated a function call instead of checking
i_mappeddirectly? Is that what you mean?
Yeah. Abstracting the details just enough that filesystems don't have to know that i_mapped is atomic64 etc.
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
fs/xfs/xfs_ioctl.c +4
-0+ error = -EBUSY ; + goto out_unlock; + } + error =filemap_write_and_wait (inode->i_mapping);if (error) goto out_unlock;include/linux/fs.h +0
-0@@ -740,6 +740,7 @@ struct inode {#endif
Quoted 8 lines
Quoted 5 lines
include/linux/fs.h struct inode { · line 743
Quoted 2 lines
include/linux/fs.h +1
-0void *i_private;/* fs or device private pointer */ +atomic64_t i_mapped;I would have expected to find this in struct
address_spacesince the mapping count is a function of the address space, right?I suppose but the only external call (above) would be passing an inode. So to me it seemed better here.
But the number of memory mappings reflects the state of the address space, not the inode. Or maybe put another way, if I were an mm developer I would not expect to look in struct inode for mm state.
static inline bool inode_has_mappings(struct inode *inode)
{
return atomic64_read(&inode->i_mapping->mapcount) > 0;
}OTOH if there exist other mm developers who /do/ find that storing the mmap count in struct inode is more logical, please let me know. :)
--D
Quoted 5 lines
Ira
Quoted 3 lines
--D
Re: [RFC PATCH V2 09/12] fs: Prevent mode change if file is mmap'ed
Quoted 25 lines · Darrick J. Wong
Quoted 24 lines · Ira Weiny
Quoted 3 lines · Darrick J. Wong
Quoted 2 lines · On Fri, Jan 10, 2020 at 11:29:39AM -0800, [email protected] wrote:
From: Ira Weiny <[email protected]>
[snip]
Quoted 16 lines
fs/xfs/xfs_ioctl.c xfs_ioctl_setattr_dax_invalidate( · line 1206
Quoted 13 lines
fs/xfs/xfs_ioctl.c +4
-0@@ -1200,6 +1200,14 @@ xfs_ioctl_setattr_dax_invalidate( goto out_unlock; } +/* +* If there is a mapping in place we must remain in our current mode. +*/ +if (atomic64_read (&inode->i_mapped)) {Urk, should we really be messing around with the address space internals?
Quoted 5 lines
Quoted 2 lines
I contemplated a function call instead of checking
i_mappeddirectly? Is that what you mean?Yeah. Abstracting the details just enough that filesystems don't have to know that
i_mappedis atomic64 etc.
Done.
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 15 lines
fs/xfs/xfs_ioctl.c +4
-0+ error = -EBUSY ; + goto out_unlock; + } + error =filemap_write_and_wait (inode->i_mapping);if (error) goto out_unlock;include/linux/fs.h +0
-0include/linux/fs.h struct inode { · line 743
Quoted 4 lines
include/linux/fs.h +1
-0@@ -740,6 +740,7 @@ struct inode {#endif void *i_private;/* fs or device private pointer */ +atomic64_t i_mapped;I would have expected to find this in struct
address_spacesince the mapping count is a function of the address space, right?
Quoted 6 lines
Quoted 2 lines
I suppose but the only external call (above) would be passing an inode. So to me it seemed better here.
But the number of memory mappings reflects the state of the address space, not the inode. Or maybe put another way, if I were an mm developer I would not expect to look in struct inode for mm state.
This is a good point...
Quoted 8 lines
static inline bool
inode_has_mappings(struct inode *inode){ return atomic64_read(&inode->i_mapping->mapcount) > 0; }OTOH if there exist other mm developers who /do/ find that storing the mmap count in struct inode is more logical, please let me know. :)
... My thinking was that the number of mappings does not matters to the mm system... However, I'm starting to think you are correct... ;-)
I've made a note of it and we will see what others think.
Ira
Quoted 8 lines
--D
Quoted 5 lines
Ira
Quoted 3 lines
--D
Jan Kara
maintainerRe: [RFC PATCH V2 09/12] fs: Prevent mode change if file is mmap'ed
Quoted 36 lines · Ira Weiny
Quoted 20 lines · Darrick J. Wong
Quoted 20 lines
Quoted 19 lines
Quoted 12 lines
fs/xfs/xfs_ioctl.c +4
-0+ error = -EBUSY ; + goto out_unlock; + } + error =filemap_write_and_wait (inode->i_mapping);if (error) goto out_unlock;include/linux/fs.h +0
-0include/linux/fs.h struct inode { · line 743
Quoted 4 lines
include/linux/fs.h +1
-0@@ -740,6 +740,7 @@ struct inode {#endif void *i_private;/* fs or device private pointer */ +atomic64_t i_mapped;I would have expected to find this in struct
address_spacesince the mapping count is a function of the address space, right?Quoted 6 lines
Quoted 2 lines
I suppose but the only external call (above) would be passing an inode. So to me it seemed better here.
But the number of memory mappings reflects the state of the address space, not the inode. Or maybe put another way, if I were an mm developer I would not expect to look in struct inode for mm state.
This is a good point...
Quoted 6 lines
static inline bool
inode_has_mappings(struct inode *inode){ return atomic64_read(&inode->i_mapping->mapcount) > 0; }
Quoted 7 lines
Quoted 2 lines
OTOH if there exist other mm developers who /do/ find that storing the mmap count in struct inode is more logical, please let me know. :)
... My thinking was that the number of mappings does not matters to the mm system... However, I'm starting to think you are correct... ;-)
I've made a note of it and we will see what others think.
Well, more importantly mapping != inode. There can be multiple inodes pointing to the same mapping (struct address_space) as is the case for example for block devices. So this counter definitely belongs into struct address_space.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [RFC PATCH V2 09/12] fs: Prevent mode change if file is mmap'ed
Quoted 43 lines · Jan Kara
Quoted 42 lines · Ira Weiny
Quoted 20 lines · Darrick J. Wong
Quoted 20 lines
Quoted 19 lines
Quoted 12 lines
fs/xfs/xfs_ioctl.c +4
-0+ error = -EBUSY ; + goto out_unlock; + } + error =filemap_write_and_wait (inode->i_mapping);if (error) goto out_unlock;include/linux/fs.h +0
-0include/linux/fs.h struct inode { · line 743
Quoted 4 lines
include/linux/fs.h +1
-0@@ -740,6 +740,7 @@ struct inode {#endif void *i_private;/* fs or device private pointer */ +atomic64_t i_mapped;I would have expected to find this in struct
address_spacesince the mapping count is a function of the address space, right?Quoted 6 lines
Quoted 2 lines
I suppose but the only external call (above) would be passing an inode. So to me it seemed better here.
But the number of memory mappings reflects the state of the address space, not the inode. Or maybe put another way, if I were an mm developer I would not expect to look in struct inode for mm state.
This is a good point...
Quoted 8 lines
static inline bool
inode_has_mappings(struct inode *inode){ return atomic64_read(&inode->i_mapping->mapcount) > 0; }OTOH if there exist other mm developers who /do/ find that storing the mmap count in struct inode is more logical, please let me know. :)
... My thinking was that the number of mappings does not matters to the mm system... However, I'm starting to think you are correct... ;-)
Quoted 6 lines
Quoted 1 line
I've made a note of it and we will see what others think.
Well, more importantly mapping != inode. There can be multiple inodes pointing to the same mapping (struct
address_space) as is the case for example for block devices. So this counter definitely belongs into structaddress_space.
Ah Yes, great point. Done.
Ira
RE: [RFC PATCH V2 09/12] fs: Prevent mode change if file is mmap'ed
In reply to [email protected]From [email protected]
Quoted 10 lines
Sent: 10 January 2020 19:30
Page faults need to ensure the inode mode is correct and consistent with the vmf information at the time of the fault. There is no easy way to ensure the vmf information is correct if a mode change is in progress. Furthermore, there is no good use case to require a mode change while the file is mmap'ed.
Track mmap's of the file and fail the mode change if the file is mmap'ed.
This seems wrong to me.
I presume the 'mode changes' are from things like 'chmod -w ...'. mmap() should be no different to open().
Only the permissions set when the file is opened count.
Next you'll be stopping unlink() when a file is open :-)
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Re: [RFC PATCH V2 09/12] fs: Prevent mode change if file is mmap'ed
Quoted 9 lines · David Laight
From [email protected]
Quoted 8 lines
Sent: 10 January 2020 19:30
Page faults need to ensure the inode mode is correct and consistent with the vmf information at the time of the fault. There is no easy way to ensure the vmf information is correct if a mode change is in progress. Furthermore, there is no good use case to require a mode change while the file is mmap'ed.
Quoted 5 lines
Quoted 2 lines
Track mmap's of the file and fail the mode change if the file is mmap'ed.
This seems wrong to me.
I presume the 'mode changes' are from things like 'chmod -w ...'.
No... Sorry... "mode" was a _very_ bad name. In this context "mode" was the "DAX mode" not the file mode.
Quoted 4 lines
mmap()should be no different toopen().
Only the permissions set when the file is opened count.Next you'll be stopping
unlink()when a file is open :-)
hehehe :-D no ... sorry that was not the meaning.
To be clear what this is preventing is a change from non-DAX to DAX or vice versa while a file is mmap'ed.
I'm looking at a better name for this. For this commit message is this more clear?
<commit>
fs: Prevent DAX change if file is mmap'ed
Page faults need to ensure the inode DAX configuration is correct and consistent with the vmf information at the time of the fault. There is no easy way to ensure the vmf information is correct if a DAX change is in progress. Furthermore, there is no good use case to require changing DAX configs while the file is mmap'ed.
Track mmap's of the file and fail the DAX change if the file is mmap'ed. </commit>
Sorry for the confusion,
Ira
Quoted 7 lines
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
RFC PATCH v2 10/12 fs/xfs: Fix truncate up
In reply to [email protected]From: Ira Weiny <[email protected]>
When zeroing the end of a file we must account for bytes contained in the final page which are past EOF.
Extend the range passed to iomap_zero_range() to reach LLONG_MAX which will include all bytes of the final page.
--- fs/xfs/xfs_iops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_iops.c +1 -1
@@ -910,7 +910,7 @@ xfs_setattr_size(*/ if (newsize > oldsize) {trace_xfs_zero_eof (ip, oldsize, newsize - oldsize); - error =iomap_zero_range (inode, oldsize, newsize - oldsize, + error =iomap_zero_range (inode, oldsize,LLONG_MAX - oldsize, &did_zeroing, &xfs_buffered_write_iomap_ops); }else { error = iomap_truncate_page(inode, newsize, &did_zeroing,
Signature · 1 line
2.21.0
Re: [RFC PATCH V2 10/12] fs/xfs: Fix truncate up
Quoted 18 lines · On Fri, Jan 10, 2020 at 11:29:40AM -0800, [email protected] wrote:
From: Ira Weiny <[email protected]>
When zeroing the end of a file we must account for bytes contained in the final page which are past EOF.
Extend the range passed to
iomap_zero_range()to reachLLONG_MAXwhich will include all bytes of the final page.Signed-off-by Ira Weiny <[email protected]>--- fs/xfs/xfs_iops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/xfs/xfs_iops.c +0
-0
fs/xfs/xfs_iops.c xfs_setattr_size( · line 913
Quoted 5 lines
fs/xfs/xfs_iops.c +1
-1@@ -910,7 +910,7 @@ xfs_setattr_size(*/ if (newsize > oldsize) {trace_xfs_zero_eof (ip, oldsize, newsize - oldsize); - error = iomap_zero_range(inode, oldsize, newsize - oldsize, + error = iomap_zero_range(inode, oldsize, LLONG_MAX - oldsize,
Huh? Won't this cause the file size to be set to LLONG_MAX?
--D
Quoted 6 lines
fs/xfs/xfs_iops.c +0
-0&did_zeroing, &xfs_buffered_write_iomap_ops); }else { error = iomap_truncate_page(inode, newsize, &did_zeroing,Signature · 1 line
2.21.0
Re: [RFC PATCH V2 10/12] fs/xfs: Fix truncate up
Quoted 14 lines · Darrick J. Wong
Quoted 13 lines · On Fri, Jan 10, 2020 at 11:29:40AM -0800, [email protected] wrote:
From: Ira Weiny <[email protected]>
When zeroing the end of a file we must account for bytes contained in the final page which are past EOF.
Extend the range passed to
iomap_zero_range()to reachLLONG_MAXwhich will include all bytes of the final page.Signed-off-by Ira Weiny <[email protected]>--- fs/xfs/xfs_iops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines
fs/xfs/xfs_iops.c xfs_setattr_size( · line 913
Quoted 10 lines
fs/xfs/xfs_iops.c +1
-1@@ -910,7 +910,7 @@ xfs_setattr_size(*/ if (newsize > oldsize) {trace_xfs_zero_eof (ip, oldsize, newsize - oldsize); - error = iomap_zero_range(inode, oldsize, newsize - oldsize, + error = iomap_zero_range(inode, oldsize, LLONG_MAX - oldsize,Huh? Won't this cause the file size to be set to
LLONG_MAX?
Not as I understand the code. But as I said in the cover I am not 100% sure of this fix.
From what I can tell xfs_ioctl_setattr_dax_invalidate() should invalidate the mappings and the page cache and the traces I have indicate that the DAX mode is not changing or was properly held off.
Any other suggestions as to the problem are welcome.
Ira
Quoted 9 lines
--D
Quoted 6 lines
fs/xfs/xfs_iops.c +0
-0&did_zeroing, &xfs_buffered_write_iomap_ops); }else { error = iomap_truncate_page(inode, newsize, &did_zeroing,Signature · 1 line
2.21.0
Re: [RFC PATCH V2 10/12] fs/xfs: Fix truncate up
Quoted 28 lines · Ira Weiny
Quoted 14 lines · Darrick J. Wong
Quoted 13 lines · On Fri, Jan 10, 2020 at 11:29:40AM -0800, [email protected] wrote:
From: Ira Weiny <[email protected]>
When zeroing the end of a file we must account for bytes contained in the final page which are past EOF.
Extend the range passed to
iomap_zero_range()to reachLLONG_MAXwhich will include all bytes of the final page.Signed-off-by Ira Weiny <[email protected]>--- fs/xfs/xfs_iops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 12 lines
fs/xfs/xfs_iops.c xfs_setattr_size( · line 913
Quoted 10 lines
fs/xfs/xfs_iops.c +1
-1@@ -910,7 +910,7 @@ xfs_setattr_size(*/ if (newsize > oldsize) {trace_xfs_zero_eof (ip, oldsize, newsize - oldsize); - error = iomap_zero_range(inode, oldsize, newsize - oldsize, + error = iomap_zero_range(inode, oldsize, LLONG_MAX - oldsize,Huh? Won't this cause the file size to be set to
LLONG_MAX?
Quoted 1 line
Not as I understand the code.
iomap_zero_range uses the standard iomap_write_{begin,end} functions, which means that if you pass it an (offset, length) that extend beyond EOF it will change isize to offset+length.
Quoted 6 lines
But as I said in the cover I am not 100% sure of
this fix.From what I can tell
xfs_ioctl_setattr_dax_invalidate()should invalidate the mappings and the page cache and the traces I have indicate that the DAX mode is not changing or was properly held off.
Hmm, that implies the invalidation didn't work. Can you find a way to report the contents of the page cache after the dax mode change invalidation fails? I wonder if this is something dorky like rounding down such that the EOF page doesn't actually get invalidated?
Hmm, no, xfs_ioctl_setattr_dax_invalidate should be nuking all the pages... do you have a quick reproducer?
--D
Quoted 14 lines
Any other suggestions as to the problem are welcome.
Ira
Quoted 9 lines
--D
Quoted 6 lines
fs/xfs/xfs_iops.c +0
-0&did_zeroing, &xfs_buffered_write_iomap_ops); }else { error = iomap_truncate_page(inode, newsize, &did_zeroing,Signature · 1 line
2.21.0
Re: [RFC PATCH V2 10/12] fs/xfs: Fix truncate up
Quoted 29 lines · Darrick J. Wong
Quoted 28 lines · Ira Weiny
Quoted 26 lines · Darrick J. Wong
Quoted 18 lines · On Fri, Jan 10, 2020 at 11:29:40AM -0800, [email protected] wrote:
From: Ira Weiny <[email protected]>
When zeroing the end of a file we must account for bytes contained in the final page which are past EOF.
Extend the range passed to
iomap_zero_range()to reachLLONG_MAXwhich will include all bytes of the final page.Signed-off-by Ira Weiny <[email protected]>--- fs/xfs/xfs_iops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/xfs/xfs_iops.c +0
-0fs/xfs/xfs_iops.c xfs_setattr_size( · line 913
Quoted 5 lines
fs/xfs/xfs_iops.c +1
-1@@ -910,7 +910,7 @@ xfs_setattr_size(*/ if (newsize > oldsize) {trace_xfs_zero_eof (ip, oldsize, newsize - oldsize); - error = iomap_zero_range(inode, oldsize, newsize - oldsize, + error = iomap_zero_range(inode, oldsize, LLONG_MAX - oldsize,Huh? Won't this cause the file size to be set to
LLONG_MAX?
Quoted 5 lines
Quoted 1 line
Not as I understand the code.
iomap_zero_rangeuses the standard iomap_write_{begin,end} functions, which means that if you pass it an (offset, length) that extend beyond EOF it will change isize to offset+length.
I don't see that but I'll take your word for it... That is unfortunate because I would have thought that the full page would have been zero'ed by something already.
I found code in xfs_free_file_space() with this comment:
/*
* If we zeroed right up to EOF and EOF straddles a page boundary we
* must make sure that the post-EOF area is also zeroed because the
* page could be mmap'd and iomap_zero_range doesn't do that for us.
* Writeback of the eof page will do this, albeit clumsily. */
But that just calls filemap_write_and_wait_range()... :-/
Quoted 8 lines
Quoted 7 lines
But as I said in the cover I am not 100% sure of
this fix.From what I can tell
xfs_ioctl_setattr_dax_invalidate()should invalidate the mappings and the page cache and the traces I have indicate that the DAX mode is not changing or was properly held off.
Quoted 7 lines
Hmm, that implies the invalidation didn't work. Can you find a way to report the contents of the page cache after the dax mode change invalidation fails? I wonder if this is something dorky like rounding down such that the EOF page doesn't actually get invalidated?
Hmm, no,
xfs_ioctl_setattr_dax_invalidateshould be nuking all the pages... do you have a quick reproducer?
I thought I did...
What I have done is take this patch:
https://www.spinics.net/lists/fstests/msg13313.html
and put [run_fsx ""] in a loop... (diff below) And without this truncate fix patch it was failing in about 5 - 10 iterations. But I'm running it right now and it has gone for 30+... :-(
I am 90% confident that this series works for 100% of the use cases we have. I think this is an existing bug which I've just managed to find. And again I'm not comfortable with this patch either. So I'm not trying to argue for it but I just don't know what could be wrong...
Ira
tests/generic/999 +3 -1
@@ -274,7 +274,9 @@ function run_fsx { pid="" } -run_fsx "" +while [ 1 ]; do + run_fsx "" +done run_fsx "-A" run_fsx "-Z -r 4096 -w 4096"
Re: [RFC PATCH V2 10/12] fs/xfs: Fix truncate up
Quoted 5 lines · Ira Weiny
Quoted 4 lines · Darrick J. Wong
Quoted 3 lines · Ira Weiny
Quoted 2 lines · Darrick J. Wong
Quoted 1 line · On Fri, Jan 10, 2020 at 11:29:40AM -0800, [email protected] wrote:
From: Ira Weiny <[email protected]>
[snip]
Quoted 19 lines
Quoted 9 lines
Quoted 8 lines
But as I said in the cover I am not 100% sure of
this fix.From what I can tell
xfs_ioctl_setattr_dax_invalidate()should invalidate the mappings and the page cache and the traces I have indicate that the DAX mode is not changing or was properly held off.Quoted 7 lines
Hmm, that implies the invalidation didn't work. Can you find a way to report the contents of the page cache after the dax mode change invalidation fails? I wonder if this is something dorky like rounding down such that the EOF page doesn't actually get invalidated?
Hmm, no,
xfs_ioctl_setattr_dax_invalidateshould be nuking all the pages... do you have a quick reproducer?I thought I did...
Quoted 7 lines
What I have done is take this patch:
https://www.spinics.net/lists/fstests/msg13313.html
and put [
run_fsx""] in a loop... (diff below) And without this truncate fix patch it was failing in about 5 - 10 iterations. But I'm running it right now and it has gone for 30+... :-(
Ok... perhaps this is a qemu problem? In qemu I had a slightly different script; 'test-suite.sh' (attached). This was copied to create the xfstest I sent. Without this 'fix truncate patch I get something like the following after in just a few iterations.
...
*** run 'fsx ' racing with setting/clearing the DAX flag *** run 'fsx ' racing with setting/clearing the DAX flag
FAILED: fsx exited with status : 205
see trace_outputzero_range to largest ever: 0x19867
truncating to largest ever: 0x3fb6dzero_range to largest ever: 0x40000
Mapped Write: non-zero data past EOF (0x3ab88) page offset 0xb89 is 0xe71c LOG DUMP (15817 total operations):
15818(202 mod 256): SKIPPED (no operation)
15819(203 mod 256): ZERO 0x2ae9f thru 0x3346c (0x85ce bytes) 15820(204 mod 256): READ 0x3637 thru 0x91e6 (0x5bb0 bytes) 15821(205 mod 256): MAPREAD 0x38a80 thru 0x3d014 (0x4595 bytes)
15822(206 mod 256): INSERT 0x28000 thru 0x29fff (0x2000 bytes)
Ira
Quoted 13 lines
I am 90% confident that this series works for 100% of the use cases we have. I think this is an existing bug which I've just managed to find. And again I'm not comfortable with this patch either. So I'm not trying to argue for it but I just don't know what could be wrong...
Ira
tests/generic/999 +0
-0
tests/generic/999 function run_fsx { · line 282
Quoted 10 lines
tests/generic/999 +3
-1@@ -274,7 +274,9 @@ function run_fsx { pid="" } -run_fsx "" +while [ 1 ]; do + run_fsx "" +done run_fsx "-A" run_fsx "-Z -r 4096 -w 4096"
#!/bin/bash
#
# Run suite of tests for feature
#
mnt_pt=/mnt/pmem
function mount_no_dax {
umount $mnt_pt
mount /dev/pmem0 $mnt_pt
}
function mount_dax {
umount $mnt_pt
mount -o dax /dev/pmem0 $mnt_pt
}
# test set up if [ ! -d /mnt/pmem ]; then echo "" echo " Setting up FS DAX" echo ""
ndctl create-namespace -e namespace0.0 -f --mode=fsdax #mkfs.ext4 /dev/pmem0 mkfs.xfs -f /dev/pmem0 mkdir -p /mnt/pmem mount_no_dax
fi
#if [ ! -c /dev/dax1.0 ]; then
# echo ""
# echo " Setting up DEV DAX"
# echo ""
#
# ndctl create-namespace -f --mode=devdax --align=4096 -e namespace1.0
#fi
if [ "$1" == "--create-fs-only" ]; then
exit 0
fi
test_file=/mnt/pmem/foo
function start_test {
rm -f $test_file
echo ""
echo " ***** START ${FUNCNAME[1]} *****"
}function end_test {
echo " ***** END ${FUNCNAME[1]} *****"
echo ""
killall -9 rdma-fsdax
}function expect_pass {
echo -n " ***** $2 : "
if [ "$1" == "0" ]; then
echo "PASSED"
else
echo "FAILED"
exit 255
fi
}function expect_fail {
echo -n " ***** $2 : "
if [ "$1" == "0" ]; then
echo "FAILED"
exit 255
else
echo "PASSED"
fi
}# test below here are not fully written yet. Just ideas of what we should test # for.
function check_phys_dax {
xfs_io -c 'lsattr' $1 | awk -e '{ print $1 }' | grep 'x' &> /dev/null
if [ "$?" != "0" ]; then
echo "FAILED: Did NOT find DAX flag on $1"
exit 255
fi
}function check_effective_dax {
attr=`xfs_io -c 'statx -r' $1 | grep 'stat.attributes' | awk -e '{ print $3 }'`
masked=$(( $attr & 0x2000 ))
if [ "$masked" != "8192" ]; then
echo "FAILED: Did NOT find VFS DAX flag on $1"
exit 255
fi
}function check_phys_no_dax {
xfs_io -c 'lsattr' $1 | awk -e '{ print $1 }' | grep 'x' &> /dev/null
if [ "$?" == "0" ]; then
echo "FAILED: Found DAX flag on $1"
exit 255
fi
}function check_effective_no_dax {
attr=`xfs_io -c 'statx -r' $1 | grep 'stat.attributes' | awk -e '{ print $3 }'`
masked=$(( $attr & 0x2000 ))
if [ "$masked" == "8192" ]; then
echo "FAILED: Found VFS DAX flag on $1"
exit 255
fi
}XFS_IO_PROG=xfs_io
TEST_DIR=/mnt/pmem
dax_dir=$TEST_DIR/dax-dir
dax_sub_dir=$TEST_DIR/dax-dir/dax-sub-dir
dax_inh_file=$dax_dir/dax-inh-file
dax_non_inh_file=$dax_dir/dax-non-inh-file
non_dax=$TEST_DIR/non-dax
dax_file=$TEST_DIR/dax-file
dax_file_copy=$TEST_DIR/dax-file-copy
dax_file_move=$TEST_DIR/dax-file-move
data_file=$TEST_DIR/data-file
function clean_up {
echo "cleaning up..."
rm -rf $TEST_DIR/*
}clean_up
# Do double mount to have these special options.mount_no_dax
touch $dax_file
if [ "$1" == "--chattr-only" ]; then
for i in seq 1 10000; do
xfs_io -c 'chattr +x' $dax_file
xfs_io -c 'chattr -x' $dax_file
done
exit 0
fi
if [ "$1" == "--fsx-only" ]; then
./fsx -R -W -N 100000 $dax_file head $dax_file.fsxlog exit 0
fi
if [ "$1" == "--fsx-aio-only" ]; then
./fsx -R -W -A -N 100000 $dax_file head $dax_file.fsxlog exit 0
fi
# The below should be kept the same as xfstests
echo " *** mount w/o dax flag."mount_no_dax
echo " *** mark dax-dir as dax enabled"
mkdir $dax_dirxfs_io -c 'chattr +x' $dax_dircheck_phys_dax $dax_dircheck_effective_dax $dax_dir
echo " *** check file inheritance"
touch $dax_inh_filecheck_phys_dax $dax_inh_filecheck_effective_dax $dax_inh_file
echo " *** check directory inheritance"
mkdir $dax_sub_dircheck_phys_dax $dax_sub_dircheck_effective_dax $dax_sub_dir
echo " *** check changing directory"xfs_io -c 'chattr -x' $dax_dircheck_phys_no_dax $dax_dircheck_effective_no_dax $dax_dir
echo " *** check non file inheritance"
touch $dax_non_inh_filecheck_phys_no_dax $dax_non_inh_filecheck_effective_no_dax $dax_non_inh_file
echo " *** check that previous file stays enabled"check_phys_dax $dax_inh_filecheck_effective_dax $dax_inh_file
echo " *** Reset the directory"xfs_io -c 'chattr +x' $dax_dircheck_phys_dax $dax_dircheck_effective_dax $dax_dir
# check mount override # ====================
echo " *** Remount fs with mount flag"mount_dax
touch $non_daxcheck_phys_no_dax $non_daxcheck_effective_dax $non_dax
echo " *** Check for non-dax files to be dax with mount option"check_effective_dax $dax_non_inh_file
echo " *** check for file dax flag 'sticky-ness' after remount"
touch $dax_filexfs_io -c 'chattr +x' $dax_filecheck_phys_dax $dax_filecheck_effective_dax $dax_file
echo " *** remount w/o mount flag"mount_no_daxcheck_phys_dax $dax_filecheck_effective_dax $dax_file
check_phys_no_dax $non_daxcheck_effective_no_dax $non_dax
# Check non-zero file operations
# ==============================
echo " *** file should change effective but page cache should be empty"
$XFS_IO_PROG -f -c "pwrite 0 10000" $data_file > /dev/null xfs_io -c 'chattr +x' $data_filecheck_phys_dax $data_filecheck_effective_dax $data_file
# Check inheritance on cp, mv
# ===========================
echo " *** check inheritance on cp, mv"
cp $non_dax $dax_dir/conv-daxcheck_phys_dax $dax_dir/conv-daxcheck_effective_dax $dax_dir/conv-dax
echo " *** Moved files 'don't inherit'"
mv $non_dax $dax_dir/move-daxcheck_phys_no_dax $dax_dir/move-daxcheck_effective_no_dax $dax_dir/move-dax
# Check preservation of phys on cp, mv
# ====================================
mv $dax_file $dax_file_movecheck_phys_dax $dax_file_movecheck_effective_dax $dax_file_move
cp $dax_file_move $dax_file_copycheck_phys_no_dax $dax_file_copycheck_effective_no_dax $dax_file_copy
# Verify no mode changes on mmap
# ==============================
echo " *** check no mode change when mmaped"
dd if=/dev/zero of=$dax_file bs=4096 count=10 > $tmp.log 2>&1
# set known state. xfs_io -c 'chattr -x' $dax_file check_phys_no_dax $dax_file check_effective_no_dax $dax_file
python3 - << EOF > $tmp.log 2>&1 &
import mmap
import time
print ('mmaping "$dax_file"')
f=open("$dax_file", "r+b")
mm = mmap.mmap(f.fileno(), 0)
print ('mmaped "$dax_file"')
while True:
time.sleep(1)
EOF
pid=$!
sleep 1
# attempt to should fail xfs_io -c 'chattr +x' $dax_file > /dev/null 2>&1 check_phys_no_dax $dax_file check_effective_no_dax $dax_file
kill -TERM $pid > /dev/null 2>&1
wait $pid > /dev/null 2>&1
# after mmap released should work xfs_io -c 'chattr +x' $dax_file check_phys_dax $dax_file check_effective_dax $dax_file
# Finally run the test stolen from Christoph Hellwig to test changing the mode
# while performing a series of operations # =============================================================================
function run_fsx {
options=$1
echo " *** run 'fsx $options' racing with setting/clearing the DAX flag"
./fsx $options -N 20000 $dax_file > $tmp.log 2>&1 &
pid=$!
if [ ! -n "$pid" ]; then
echo "FAILED to start fsx"
exit 255
fi
# NOTE: for some
for i in `seq 1 500`; do
xfs_io -c 'chattr +x' $dax_file > /dev/null 2>&1
xfs_io -c 'chattr -x' $dax_file > /dev/null 2>&1
done
wait $pid
status=$?
if [ "$status" != "0" ]; then
cat /sys/kernel/debug/tracing/trace > trace_output
echo "FAILED: fsx exited with status : $status"
echo " see trace_output"
head $dax_file.fsxlog
exit $status
fi
pid=""
}while [ 1 ]; do
run_fsx "" done run_fsx "-A" run_fsx "-Z -r 4096 -w 4096"
echo " *** Check 'dump' and 'xfsdump'"
echo " TBD"
echo " *** PASSED! All tests PASSED ***"
exit 0
RFC PATCH v2 11/12 fs/xfs: Clean up locking in dax invalidate
In reply to [email protected]From: Ira Weiny <[email protected]>
Define a variable to hold the lock flags to ensure that the correct locks are returned or released on error.
--- fs/xfs/xfs_ioctl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
fs/xfs/xfs_ioctl.c +6 -4
@@ -1176,7 +1176,7 @@ xfs_ioctl_setattr_dax_invalidate( int *join_flags) {struct inode *inode =VFS_I (ip); -int error; +int error, flags; *join_flags =0 ;
@@ -1191,8 +1191,10 @@ xfs_ioctl_setattr_dax_invalidate(if (S_ISDIR (inode->i_mode))return 0 ; + flags =XFS_MMAPLOCK_EXCL |XFS_IOLOCK_EXCL ; +/* lock, flush and invalidate mapping in preparation for flag change */ -xfs_ilock (ip,XFS_MMAPLOCK_EXCL |XFS_IOLOCK_EXCL ); +xfs_ilock (ip, flags);if ((fa->fsx_xflags &FS_XFLAG_DAX ) ==FS_XFLAG_DAX && !xfs_inode_supports_dax (ip)) {
@@ -1215,11 +1217,11 @@ xfs_ioctl_setattr_dax_invalidate(if (error) goto out_unlock; - *join_flags =XFS_MMAPLOCK_EXCL |XFS_IOLOCK_EXCL ; + *join_flags = flags;return 0 ; out_unlock: -xfs_iunlock (ip,XFS_MMAPLOCK_EXCL |XFS_IOLOCK_EXCL ); +xfs_iunlock (ip, flags);return error; }
Signature · 1 line
2.21.0
RFC PATCH v2 12/12 fs/xfs: Allow toggle of effective DAX flag
In reply to [email protected]From: Ira Weiny <[email protected]>
Now that locking of the inode is in place we can allow a mode change while under the new lock.
--- fs/xfs/xfs_inode.h | 1 + fs/xfs/xfs_ioctl.c | 9 ++++++--- fs/xfs/xfs_iops.c | 15 +++++++++++---- 3 files changed, 18 insertions(+), 7 deletions(-)
fs/xfs/xfs_inode.h +1 -0
@@ -474,6 +474,7 @@ int xfs_break_layouts(struct inode *inode, uint *iolock,/* from xfs_iops.c */ extern void xfs_setup_inode (struct xfs_inode *ip);extern void xfs_setup_iops (struct xfs_inode *ip); +extern void xfs_setup_a_ops (struct xfs_inode *ip);/* * When setting up a newly allocated inode, we need to call
fs/xfs/xfs_ioctl.c +6 -3
@@ -1109,12 +1109,11 @@ xfs_diflags_to_linux( inode->i_flags |=S_NOATIME ; else inode->i_flags &= ~S_NOATIME; -#if 0 /* disabled until the flag switching races are sorted out */ if (xflags &FS_XFLAG_DAX ) inode->i_flags |=S_DAX ;else inode->i_flags &= ~S_DAX ; -#endif + } static int
@@ -1191,7 +1190,7 @@ xfs_ioctl_setattr_dax_invalidate(if (S_ISDIR (inode->i_mode))return 0 ; - flags =XFS_MMAPLOCK_EXCL |XFS_IOLOCK_EXCL ; + flags =XFS_MMAPLOCK_EXCL |XFS_IOLOCK_EXCL |XFS_DAX_EXCL ;/* lock, flush and invalidate mapping in preparation for flag change */ xfs_ilock (ip, flags);
@@ -1512,6 +1511,8 @@ xfs_ioctl_setattr(else ip->i_d.di_cowextsize =0 ; +xfs_setup_a_ops (ip); + code =xfs_trans_commit (tp);/*
@@ -1621,6 +1622,8 @@ xfs_ioc_setxflags( goto out_drop_write; } +xfs_setup_a_ops (ip); + error =xfs_trans_commit (tp); out_drop_write:mnt_drop_write_file (filp);
fs/xfs/xfs_iops.c +11 -4
@@ -1386,6 +1386,16 @@ xfs_setup_inode( } } +void xfs_setup_a_ops (struct xfs_inode *ip) +{ +struct inode *inode = &ip->i_vnode; + +if (IS_DAX (inode)) + inode->i_mapping->a_ops = &xfs_dax_aops; +else + inode->i_mapping->a_ops = &xfs_address_space_operations; +} +void xfs_setup_iops (struct xfs_inode *ip)
@@ -1396,10 +1406,7 @@ xfs_setup_iops(case S_IFREG : inode->i_op = &xfs_reg_inode_operations; inode->i_fop = &xfs_file_operations; -if (IS_DAX (inode)) - inode->i_mapping->a_ops = &xfs_dax_aops; -else - inode->i_mapping->a_ops = &xfs_address_space_operations; +xfs_setup_a_ops (ip);break ;case S_IFDIR :if (xfs_sb_version_hasasciici (&XFS_M (inode->i_sb)->m_sb))
Signature · 1 line
2.21.0