summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2021-09-01 11:25:43 -0700
committerDarrick J. Wong <djwong@kernel.org>2021-09-17 18:55:30 -0700
commit07b7328f66eb82d292d7686fb534a5c313b23f34 (patch)
treefa0316dc136acc4b8d8e3fd749c7817688373344
parentb8d21abec50754dd717428dd1fed9957f181abf2 (diff)
xfs: implement FALLOC_FL_ZEROINIT_RANGE
Implement this new fallocate mode so that persistent memory users can, upon receipt of a pmem poison notification, cause the pmem to be reinitialized to a known value (zero) and clear any hardware poison state that might be lurking. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
-rw-r--r--fs/xfs/xfs_bmap_util.c22
-rw-r--r--fs/xfs/xfs_bmap_util.h2
-rw-r--r--fs/xfs/xfs_file.c9
-rw-r--r--fs/xfs/xfs_trace.h1
4 files changed, 32 insertions, 2 deletions
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index f7804d3bba73..b1678a051e48 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -1004,6 +1004,28 @@ xfs_flush_unmap_range(
}
int
+xfs_file_zeroinit_space(
+ struct xfs_inode *ip,
+ xfs_off_t offset,
+ xfs_off_t len)
+{
+ struct inode *inode = VFS_I(ip);
+ int error;
+
+ trace_xfs_zeroinit_file_space(ip, offset, len);
+
+ if (IS_DAX(inode))
+ error = dax_zeroinit_range(inode, offset, len,
+ &xfs_read_iomap_ops);
+ else
+ error = iomap_zeroout_range(inode, offset, len,
+ &xfs_read_iomap_ops);
+ if (error == -ECANCELED)
+ return -EOPNOTSUPP;
+ return error;
+}
+
+int
xfs_free_file_space(
struct xfs_inode *ip,
xfs_off_t offset,
diff --git a/fs/xfs/xfs_bmap_util.h b/fs/xfs/xfs_bmap_util.h
index ff7dc1d9298a..6435c1ef8a92 100644
--- a/fs/xfs/xfs_bmap_util.h
+++ b/fs/xfs/xfs_bmap_util.h
@@ -61,6 +61,8 @@ int xfs_collapse_file_space(struct xfs_inode *, xfs_off_t offset,
xfs_off_t len);
int xfs_insert_file_space(struct xfs_inode *, xfs_off_t offset,
xfs_off_t len);
+int xfs_file_zeroinit_space(struct xfs_inode *ip, xfs_off_t offset,
+ xfs_off_t length);
/* EOF block manipulation functions */
bool xfs_can_free_eofblocks(struct xfs_inode *ip, bool force);
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 959a3bed1dcd..a1f92395a5f0 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -987,6 +987,7 @@ xfs_break_layouts(
#define XFS_FALLOC_FL_SUPPORTED \
(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | \
FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE | \
+ FALLOC_FL_ZEROINIT_RANGE | \
FALLOC_FL_INSERT_RANGE | FALLOC_FL_UNSHARE_RANGE | \
FALLOC_FL_MAP_FREE_SPACE)
@@ -1039,13 +1040,17 @@ xfs_file_fallocate(
* handled at the right time by xfs_prepare_shift().
*/
if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE |
- FALLOC_FL_COLLAPSE_RANGE)) {
+ FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZEROINIT_RANGE)) {
error = xfs_flush_unmap_range(ip, offset, len);
if (error)
goto out_unlock;
}
- if (mode & FALLOC_FL_PUNCH_HOLE) {
+ if (mode & FALLOC_FL_ZEROINIT_RANGE) {
+ error = xfs_file_zeroinit_space(ip, offset, len);
+ if (error)
+ goto out_unlock;
+ } else if (mode & FALLOC_FL_PUNCH_HOLE) {
/* Unshare around the region to punch, if needed. */
if (xfs_inode_needs_cow_around(ip)) {
error = xfs_file_cow_around(ip, offset, len);
diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h
index e66e0282c96c..0d44b873f813 100644
--- a/fs/xfs/xfs_trace.h
+++ b/fs/xfs/xfs_trace.h
@@ -1557,6 +1557,7 @@ DEFINE_SIMPLE_IO_EVENT(xfs_end_io_direct_write_append);
DEFINE_SIMPLE_IO_EVENT(xfs_alloc_file_space);
DEFINE_SIMPLE_IO_EVENT(xfs_free_file_space);
DEFINE_SIMPLE_IO_EVENT(xfs_zero_file_space);
+DEFINE_SIMPLE_IO_EVENT(xfs_zeroinit_file_space);
DEFINE_SIMPLE_IO_EVENT(xfs_collapse_file_space);
DEFINE_SIMPLE_IO_EVENT(xfs_insert_file_space);
DEFINE_SIMPLE_IO_EVENT(xfs_map_free_rt_space);