Skip to contentSkip to conversation

fstests: atomic file content commits

PATCH In review Darrick J. Wong 4 participants 15 messages Oct 1, 2024 – Oct 12, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 fstests: atomic file content commits

Hi all,

This series creates XFS_IOC_START_COMMIT and XFS_IOC_COMMIT_RANGE ioctls to perform the exchange only if the target file has not been changed since a given sampling point.

This new functionality uses the mechanism underlying EXCHANGE_RANGE to stage and commit file updates such that reader programs will see either the old contents or the new contents in their entirety, with no chance of torn writes. A successful call completion guarantees that the new contents will be seen even if the system fails. The pair of ioctls allows userspace to perform what amounts to a compare and exchange operation on entire file contents.

Note that there are ongoing arguments in the community about how best to implement some sort of file data write counter that nfsd could also use to signal invalidations to clients. Until such a thing is implemented, this patch will rely on ctime/mtime updates.

If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.

This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=atomic-file-commits

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=atomic-file-commits

fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=atomic-file-commits
---
Commits in this patchset:
* src/fiexchange.h: add the start-commit/commit-range ioctls
* xfs/122: add tests for commitrange structures

---
 m4/package_xfslibs.m4 |    2 ++
 src/fiexchange.h      |   26 ++++++++++++++++++++++++++
 src/global.h          |    4 ++++
 tests/xfs/122.out     |    1 +
 4 files changed, 33 insertions(+)
#1 lore raw

PATCH 1/2 src/fiexchange.h: add the start-commit/commit-range ioctls

From: Darrick J. Wong <[email protected]>

Add these two ioctls as well, since they're a part of the file content exchange functionality.

---
 m4/package_xfslibs.m4 |    2 ++
 src/fiexchange.h      |   26 ++++++++++++++++++++++++++
 src/global.h          |    4 ++++
 3 files changed, 32 insertions(+)
m4/package_xfslibs.m4 +2 -0
index 5604989e34..ec7b91986c 100644
@@ -100,7 +100,9 @@ AC_DEFUN([AC_NEED_INTERNAL_XFS_IOC_EXCHANGE_RANGE],
 #include <xfs/xfs.h>
     ]], [[
          struct xfs_exchange_range obj;
+         struct xfs_commit_range obj2;
          ioctl(-1, XFS_IOC_EXCHANGE_RANGE, &obj);
+         ioctl(-1, XFS_IOC_COMMIT_RANGE, &obj2);
     ]])],[AC_MSG_RESULT(yes)],
          [need_internal_xfs_ioc_exchange_range=yes
           AC_MSG_RESULT(no)])
src/fiexchange.h +26 -0
index 02eb0027d1..b9eb2a7e26 100644
@@ -26,6 +26,30 @@ struct xfs_exchange_range {
 	__u64		flags;		/* see XFS_EXCHANGE_RANGE_* below */
 };
 
+/*
+ * Using the same definition of file2 as struct xfs_exchange_range, commit the
+ * contents of file1 into file2 if file2 has the same inode number, mtime, and
+ * ctime as the arguments provided to the call.  The old contents of file2 will
+ * be moved to file1.
+ *
+ * Returns -EBUSY if there isn't an exact match for the file2 fields.
+ *
+ * Filesystems must be able to restart and complete the operation even after
+ * the system goes down.
+ */
+struct xfs_commit_range {
+	__s32		file1_fd;
+	__u32		pad;		/* must be zeroes */
+	__u64		file1_offset;	/* file1 offset, bytes */
+	__u64		file2_offset;	/* file2 offset, bytes */
+	__u64		length;		/* bytes to exchange */
+
+	__u64		flags;		/* see XFS_EXCHANGE_RANGE_* below */
+
+	/* opaque file2 metadata for freshness checks */
+	__u64		file2_freshness[5];
+};
+
 /*
  * Exchange file data all the way to the ends of both files, and then exchange
  * the file sizes.  This flag can be used to replace a file's contents with a
@@ -53,5 +77,7 @@ struct xfs_exchange_range {
 					 XFS_EXCHANGE_RANGE_FILE1_WRITTEN)
 
 #define XFS_IOC_EXCHANGE_RANGE	     _IOW ('X', 129, struct xfs_exchange_range)
+#define XFS_IOC_START_COMMIT	     _IOR ('X', 130, struct xfs_commit_range)
+#define XFS_IOC_COMMIT_RANGE	     _IOW ('X', 131, struct xfs_commit_range)
 
 #endif /* _LINUX_FIEXCHANGE_H */
src/global.h +4 -0
index fc48d82e03..fbc0a0b5e1 100644
@@ -12,6 +12,7 @@
 #ifdef NEED_INTERNAL_XFS_IOC_EXCHANGE_RANGE
 /* Override struct xfs_exchange_range in xfslibs */
 # define xfs_exchange_range		sys_xfs_exchange_range
+# define xfs_commit_range		sys_xfs_commit_range
 #endif
 
 #ifdef HAVE_XFS_XFS_H
@@ -20,7 +21,10 @@
 
 #ifdef NEED_INTERNAL_XFS_IOC_EXCHANGE_RANGE
 # undef xfs_exchange_range
+# undef xfs_commit_range
 # undef XFS_IOC_EXCHANGE_RANGE
+# undef XFS_IOC_START_COMMIT
+# undef XFS_IOC_COMMIT_RANGE
 #endif
 
 #ifdef HAVE_XFS_LIBXFS_H
#3 lore raw

PATCH 2/2 xfs/122: add tests for commitrange structures

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Update this test to check the ioctl structure for XFS_IOC_COMMIT_RANGE.

---
 tests/xfs/122.out |    1 +
 1 file changed, 1 insertion(+)
tests/xfs/122.out +1 -0
index 60d8294551..4dc7d7d0a3 100644
@@ -76,6 +76,7 @@ sizeof(struct xfs_bulk_ireq) = 64
 sizeof(struct xfs_bulkstat) = 192
 sizeof(struct xfs_bulkstat_req) = 64
 sizeof(struct xfs_clone_args) = 32
+sizeof(struct xfs_commit_range) = 88
 sizeof(struct xfs_cud_log_format) = 16
 sizeof(struct xfs_cui_log_format) = 16
 sizeof(struct xfs_da3_blkinfo) = 56
#4 lore raw

Re: [PATCH 2/2] xfs/122: add tests for commitrange structures

Quoted 3 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Update this test to check the ioctl structure for XFS_IOC_COMMIT_RANGE.

Meh. Can we please not add more to xfs/122, as that's alway just a pain? We can just static_assert the size in xfsprogs (or the xfstests code using it) instead of this mess.

#5 lore raw

Re: [PATCH 2/2] xfs/122: add tests for commitrange structures

Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Update this test to check the ioctl structure for XFS_IOC_COMMIT_RANGE.

Meh. Can we please not add more to xfs/122, as that's alway just a pain? We can just static_assert the size in xfsprogs (or the xfstests code using it) instead of this mess.

Oh right, we had a plan to autotranslate the xfs/122 stuff to xfs_ondisk.h didn't we... I'll put that back on my list.

--D

#6 lore raw

Re: [PATCH 2/2] xfs/122: add tests for commitrange structures

Quoted 2 lines · Darrick J. Wong

Oh right, we had a plan to autotranslate the xfs/122 stuff to xfs_ondisk.h didn't we... I'll put that back on my list.

xfs_ondisk.h should be fully covered. You pointed out that were are missing ioctls, though. Let me find some time to add those as well.

#7 lore raw

Re: [PATCH 2/2] xfs/122: add tests for commitrange structures

In reply to Darrick J. Wong
Quoted 4 lines · Darrick J. Wong
Quoted 3 lines · Christoph Hellwig
Quoted 2 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Update this test to check the ioctl structure for XFS_IOC_COMMIT_RANGE.

Meh. Can we please not add more to xfs/122, as that's alway just a pain? We can just static_assert the size in xfsprogs (or the xfstests code using it) instead of this mess.

Oh right, we had a plan to autotranslate the xfs/122 stuff to xfs_ondisk.h didn't we... I'll put that back on my list.

Hi Darrick,

Do you want to have this patch at first, or just wait for your next version which does the "autotranslate"?

Thanks,
Zorro

Quoted 3 lines

--D

#8 lore raw

Re: [PATCH 2/2] xfs/122: add tests for commitrange structures

Quoted 11 lines · Zorro Lang
Quoted 10 lines · Darrick J. Wong
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Update this test to check the ioctl structure for XFS_IOC_COMMIT_RANGE.

Meh. Can we please not add more to xfs/122, as that's alway just a pain? We can just static_assert the size in xfsprogs (or the xfstests code using it) instead of this mess.

Quoted 7 lines
Quoted 2 lines

Oh right, we had a plan to autotranslate the xfs/122 stuff to xfs_ondisk.h didn't we... I'll put that back on my list.

Hi Darrick,

Do you want to have this patch at first, or just wait for your next version which does the "autotranslate"?

Let's drop this for now, machine-converting xfs/122 to xfs_ondisk.h wasn't as hard as I thought it might be. Would you be ok with merging the fiexchange.h patch and the fsstress funshare patch this week?

--D

Quoted 8 lines

Thanks,
Zorro

Quoted 3 lines

--D

#9 lore raw

Re: [PATCH 2/2] xfs/122: add tests for commitrange structures

Quoted 15 lines · Darrick J. Wong
Quoted 14 lines · Zorro Lang
Quoted 12 lines · Darrick J. Wong
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Update this test to check the ioctl structure for XFS_IOC_COMMIT_RANGE.

Meh. Can we please not add more to xfs/122, as that's alway just a pain? We can just static_assert the size in xfsprogs (or the xfstests code using it) instead of this mess.

Oh right, we had a plan to autotranslate the xfs/122 stuff to xfs_ondisk.h didn't we... I'll put that back on my list.

Quoted 8 lines
Quoted 4 lines

Hi Darrick,

Do you want to have this patch at first, or just wait for your next version which does the "autotranslate"?

Let's drop this for now, machine-converting xfs/122 to xfs_ondisk.h wasn't as hard as I thought it might be. Would you be ok with merging the fiexchange.h patch and the fsstress funshare patch this week?

Sure, if you hope so :)

Quoted 12 lines

--D

Quoted 8 lines

Thanks,
Zorro

Quoted 3 lines

--D

#10 lore raw

PATCH 1/1 fsstress: add support for FALLOC_FL_UNSHARE_RANGE

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Teach fsstress to try to unshare file blocks on filesystems, seeing how the recent addition to fsx has uncovered a lot of bugs.

---
 ltp/fsstress.c |   14 ++++++++++++++
 1 file changed, 14 insertions(+)
ltp/fsstress.c +14 -0
index b8d025d3a0..8cd45c7a85 100644
@@ -139,6 +139,7 @@ typedef enum {
 	OP_TRUNCATE,
 	OP_UNLINK,
 	OP_UNRESVSP,
+	OP_UNSHARE,
 	OP_URING_READ,
 	OP_URING_WRITE,
 	OP_WRITE,
@@ -246,6 +247,7 @@ void	punch_f(opnum_t, long);
 void	zero_f(opnum_t, long);
 void	collapse_f(opnum_t, long);
 void	insert_f(opnum_t, long);
+void	unshare_f(opnum_t, long);
 void	read_f(opnum_t, long);
 void	readlink_f(opnum_t, long);
 void	readv_f(opnum_t, long);
@@ -339,6 +341,7 @@ struct opdesc	ops[OP_LAST]	= {
 	[OP_TRUNCATE]	   = {"truncate",      truncate_f,	2, 1 },
 	[OP_UNLINK]	   = {"unlink",	       unlink_f,	1, 1 },
 	[OP_UNRESVSP]	   = {"unresvsp",      unresvsp_f,	1, 1 },
+	[OP_UNSHARE]	   = {"unshare",       unshare_f,	1, 1 },
 	[OP_URING_READ]	   = {"uring_read",    uring_read_f,	-1, 0 },
 	[OP_URING_WRITE]   = {"uring_write",   uring_write_f,	-1, 1 },
 	[OP_WRITE]	   = {"write",	       write_f,		4, 1 },
@@ -3767,6 +3770,7 @@ struct print_flags falloc_flags [] = {
 	{ FALLOC_FL_COLLAPSE_RANGE, "COLLAPSE_RANGE"},
 	{ FALLOC_FL_ZERO_RANGE, "ZERO_RANGE"},
 	{ FALLOC_FL_INSERT_RANGE, "INSERT_RANGE"},
+	{ FALLOC_FL_UNSHARE_RANGE, "UNSHARE_RANGE"},
 	{ -1, NULL}
 };
 
@@ -4469,6 +4473,16 @@ insert_f(opnum_t opno, long r)
 #endif
 }
 
+void
+unshare_f(opnum_t opno, long r)
+{
+#ifdef HAVE_LINUX_FALLOC_H
+# ifdef FALLOC_FL_UNSHARE_RANGE
+	do_fallocate(opno, r, FALLOC_FL_UNSHARE_RANGE);
+# endif
+#endif
+}
+
 void
 read_f(opnum_t opno, long r)
 {
Reviewed-by on v1 1/1
#11 lore raw

Re: [PATCH] fsstress: add support for FALLOC_FL_UNSHARE_RANGE

Quoted 7 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Teach fsstress to try to unshare file blocks on filesystems, seeing how the recent addition to fsx has uncovered a lot of bugs.

---

LGTM. Thanks for sending this:

Quoted 57 lines
 ltp/fsstress.c |   14 ++++++++++++++
 1 file changed, 14 insertions(+)
ltp/fsstress.c +14 -0
index b8d025d3a0..8cd45c7a85 100644
@@ -139,6 +139,7 @@ typedef enum {
 	OP_TRUNCATE,
 	OP_UNLINK,
 	OP_UNRESVSP,
+	OP_UNSHARE,
 	OP_URING_READ,
 	OP_URING_WRITE,
 	OP_WRITE,
@@ -246,6 +247,7 @@ void	punch_f(opnum_t, long);
 void	zero_f(opnum_t, long);
 void	collapse_f(opnum_t, long);
 void	insert_f(opnum_t, long);
+void	unshare_f(opnum_t, long);
 void	read_f(opnum_t, long);
 void	readlink_f(opnum_t, long);
 void	readv_f(opnum_t, long);
@@ -339,6 +341,7 @@ struct opdesc	ops[OP_LAST]	= {
 	[OP_TRUNCATE]	   = {"truncate",      truncate_f,	2, 1 },
 	[OP_UNLINK]	   = {"unlink",	       unlink_f,	1, 1 },
 	[OP_UNRESVSP]	   = {"unresvsp",      unresvsp_f,	1, 1 },
+	[OP_UNSHARE]	   = {"unshare",       unshare_f,	1, 1 },
 	[OP_URING_READ]	   = {"uring_read",    uring_read_f,	-1, 0 },
 	[OP_URING_WRITE]   = {"uring_write",   uring_write_f,	-1, 1 },
 	[OP_WRITE]	   = {"write",	       write_f,		4, 1 },
@@ -3767,6 +3770,7 @@ struct print_flags falloc_flags [] = {
 	{ FALLOC_FL_COLLAPSE_RANGE, "COLLAPSE_RANGE"},
 	{ FALLOC_FL_ZERO_RANGE, "ZERO_RANGE"},
 	{ FALLOC_FL_INSERT_RANGE, "INSERT_RANGE"},
+	{ FALLOC_FL_UNSHARE_RANGE, "UNSHARE_RANGE"},
 	{ -1, NULL}
 };
 
@@ -4469,6 +4473,16 @@ insert_f(opnum_t opno, long r)
 #endif
 }
 
+void
+unshare_f(opnum_t opno, long r)
+{
+#ifdef HAVE_LINUX_FALLOC_H
+# ifdef FALLOC_FL_UNSHARE_RANGE
+	do_fallocate(opno, r, FALLOC_FL_UNSHARE_RANGE);
+# endif
+#endif
+}
+
 void
 read_f(opnum_t opno, long r)
 {
Reviewed-by on v1 1/1
#12 lore raw

Re: [PATCH] fsstress: add support for FALLOC_FL_UNSHARE_RANGE

In reply to Darrick J. Wong
Quoted 7 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Teach fsstress to try to unshare file blocks on filesystems, seeing how the recent addition to fsx has uncovered a lot of bugs.

---

Thanks for this new test coverage on fsstress. Although it's conflict with current for-next branch, I've merged it manually, don't need one more version :)

Quoted 57 lines
 ltp/fsstress.c |   14 ++++++++++++++
 1 file changed, 14 insertions(+)
ltp/fsstress.c +14 -0
index b8d025d3a0..8cd45c7a85 100644
@@ -139,6 +139,7 @@ typedef enum {
 	OP_TRUNCATE,
 	OP_UNLINK,
 	OP_UNRESVSP,
+	OP_UNSHARE,
 	OP_URING_READ,
 	OP_URING_WRITE,
 	OP_WRITE,
@@ -246,6 +247,7 @@ void	punch_f(opnum_t, long);
 void	zero_f(opnum_t, long);
 void	collapse_f(opnum_t, long);
 void	insert_f(opnum_t, long);
+void	unshare_f(opnum_t, long);
 void	read_f(opnum_t, long);
 void	readlink_f(opnum_t, long);
 void	readv_f(opnum_t, long);
@@ -339,6 +341,7 @@ struct opdesc	ops[OP_LAST]	= {
 	[OP_TRUNCATE]	   = {"truncate",      truncate_f,	2, 1 },
 	[OP_UNLINK]	   = {"unlink",	       unlink_f,	1, 1 },
 	[OP_UNRESVSP]	   = {"unresvsp",      unresvsp_f,	1, 1 },
+	[OP_UNSHARE]	   = {"unshare",       unshare_f,	1, 1 },
 	[OP_URING_READ]	   = {"uring_read",    uring_read_f,	-1, 0 },
 	[OP_URING_WRITE]   = {"uring_write",   uring_write_f,	-1, 1 },
 	[OP_WRITE]	   = {"write",	       write_f,		4, 1 },
@@ -3767,6 +3770,7 @@ struct print_flags falloc_flags [] = {
 	{ FALLOC_FL_COLLAPSE_RANGE, "COLLAPSE_RANGE"},
 	{ FALLOC_FL_ZERO_RANGE, "ZERO_RANGE"},
 	{ FALLOC_FL_INSERT_RANGE, "INSERT_RANGE"},
+	{ FALLOC_FL_UNSHARE_RANGE, "UNSHARE_RANGE"},
 	{ -1, NULL}
 };
 
@@ -4469,6 +4473,16 @@ insert_f(opnum_t opno, long r)
 #endif
 }
 
+void
+unshare_f(opnum_t opno, long r)
+{
+#ifdef HAVE_LINUX_FALLOC_H
+# ifdef FALLOC_FL_UNSHARE_RANGE
+	do_fallocate(opno, r, FALLOC_FL_UNSHARE_RANGE);
+# endif
+#endif
+}
+
 void
 read_f(opnum_t opno, long r)
 {
#13 lore raw

Re: [PATCH] fsstress: add support for FALLOC_FL_UNSHARE_RANGE

Quoted 6 lines · Zorro Lang
Quoted 5 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Teach fsstress to try to unshare file blocks on filesystems, seeing how the recent addition to fsx has uncovered a lot of bugs.

Quoted 8 lines
Quoted 2 lines

---

Thanks for this new test coverage on fsstress. Although it's conflict with current for-next branch, I've merged it manually, don't need one more version :)

And...

I'm not sure why this patch is contained in this patchset:
[PATCHSET v31.1 2/2] fstests: atomic file content commits

As that patchset still need change, I'll merge this patch singly this week.

Thanks,
Zorro

Quoted 58 lines
Quoted 58 lines
 ltp/fsstress.c |   14 ++++++++++++++
 1 file changed, 14 insertions(+)
ltp/fsstress.c +14 -0
index b8d025d3a0..8cd45c7a85 100644
@@ -139,6 +139,7 @@ typedef enum {
 	OP_TRUNCATE,
 	OP_UNLINK,
 	OP_UNRESVSP,
+	OP_UNSHARE,
 	OP_URING_READ,
 	OP_URING_WRITE,
 	OP_WRITE,
@@ -246,6 +247,7 @@ void	punch_f(opnum_t, long);
 void	zero_f(opnum_t, long);
 void	collapse_f(opnum_t, long);
 void	insert_f(opnum_t, long);
+void	unshare_f(opnum_t, long);
 void	read_f(opnum_t, long);
 void	readlink_f(opnum_t, long);
 void	readv_f(opnum_t, long);
@@ -339,6 +341,7 @@ struct opdesc	ops[OP_LAST]	= {
 	[OP_TRUNCATE]	   = {"truncate",      truncate_f,	2, 1 },
 	[OP_UNLINK]	   = {"unlink",	       unlink_f,	1, 1 },
 	[OP_UNRESVSP]	   = {"unresvsp",      unresvsp_f,	1, 1 },
+	[OP_UNSHARE]	   = {"unshare",       unshare_f,	1, 1 },
 	[OP_URING_READ]	   = {"uring_read",    uring_read_f,	-1, 0 },
 	[OP_URING_WRITE]   = {"uring_write",   uring_write_f,	-1, 1 },
 	[OP_WRITE]	   = {"write",	       write_f,		4, 1 },
@@ -3767,6 +3770,7 @@ struct print_flags falloc_flags [] = {
 	{ FALLOC_FL_COLLAPSE_RANGE, "COLLAPSE_RANGE"},
 	{ FALLOC_FL_ZERO_RANGE, "ZERO_RANGE"},
 	{ FALLOC_FL_INSERT_RANGE, "INSERT_RANGE"},
+	{ FALLOC_FL_UNSHARE_RANGE, "UNSHARE_RANGE"},
 	{ -1, NULL}
 };
 
@@ -4469,6 +4473,16 @@ insert_f(opnum_t opno, long r)
 #endif
 }
 
+void
+unshare_f(opnum_t opno, long r)
+{
+#ifdef HAVE_LINUX_FALLOC_H
+# ifdef FALLOC_FL_UNSHARE_RANGE
+	do_fallocate(opno, r, FALLOC_FL_UNSHARE_RANGE);
+# endif
+#endif
+}
+
 void
 read_f(opnum_t opno, long r)
 {
#14 lore raw

Re: [PATCH] fsstress: add support for FALLOC_FL_UNSHARE_RANGE

Quoted 14 lines · Zorro Lang
Quoted 13 lines · Zorro Lang
Quoted 7 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Teach fsstress to try to unshare file blocks on filesystems, seeing how the recent addition to fsx has uncovered a lot of bugs.

---

Thanks for this new test coverage on fsstress. Although it's conflict with current for-next branch, I've merged it manually, don't need one more version :)

Quoted 6 lines
Quoted 1 line

And...

I'm not sure why this patch is contained in this patchset:
[PATCHSET v31.1 2/2] fstests: atomic file content commits

I hit reply-all to get the same to/cc list and forgot to strip out the in-reply-to header. :(

Quoted 1 line

As that patchset still need change, I'll merge this patch singly this week.

Thanks. :)

--D

Quoted 63 lines

Thanks,
Zorro

Quoted 58 lines
Quoted 58 lines
 ltp/fsstress.c |   14 ++++++++++++++
 1 file changed, 14 insertions(+)
ltp/fsstress.c +14 -0
index b8d025d3a0..8cd45c7a85 100644
@@ -139,6 +139,7 @@ typedef enum {
 	OP_TRUNCATE,
 	OP_UNLINK,
 	OP_UNRESVSP,
+	OP_UNSHARE,
 	OP_URING_READ,
 	OP_URING_WRITE,
 	OP_WRITE,
@@ -246,6 +247,7 @@ void	punch_f(opnum_t, long);
 void	zero_f(opnum_t, long);
 void	collapse_f(opnum_t, long);
 void	insert_f(opnum_t, long);
+void	unshare_f(opnum_t, long);
 void	read_f(opnum_t, long);
 void	readlink_f(opnum_t, long);
 void	readv_f(opnum_t, long);
@@ -339,6 +341,7 @@ struct opdesc	ops[OP_LAST]	= {
 	[OP_TRUNCATE]	   = {"truncate",      truncate_f,	2, 1 },
 	[OP_UNLINK]	   = {"unlink",	       unlink_f,	1, 1 },
 	[OP_UNRESVSP]	   = {"unresvsp",      unresvsp_f,	1, 1 },
+	[OP_UNSHARE]	   = {"unshare",       unshare_f,	1, 1 },
 	[OP_URING_READ]	   = {"uring_read",    uring_read_f,	-1, 0 },
 	[OP_URING_WRITE]   = {"uring_write",   uring_write_f,	-1, 1 },
 	[OP_WRITE]	   = {"write",	       write_f,		4, 1 },
@@ -3767,6 +3770,7 @@ struct print_flags falloc_flags [] = {
 	{ FALLOC_FL_COLLAPSE_RANGE, "COLLAPSE_RANGE"},
 	{ FALLOC_FL_ZERO_RANGE, "ZERO_RANGE"},
 	{ FALLOC_FL_INSERT_RANGE, "INSERT_RANGE"},
+	{ FALLOC_FL_UNSHARE_RANGE, "UNSHARE_RANGE"},
 	{ -1, NULL}
 };
 
@@ -4469,6 +4473,16 @@ insert_f(opnum_t opno, long r)
 #endif
 }
 
+void
+unshare_f(opnum_t opno, long r)
+{
+#ifdef HAVE_LINUX_FALLOC_H
+# ifdef FALLOC_FL_UNSHARE_RANGE
+	do_fallocate(opno, r, FALLOC_FL_UNSHARE_RANGE);
+# endif
+#endif
+}
+
 void
 read_f(opnum_t opno, long r)
 {