diff mbox series

xfs_io: use FICLONE/FICLONERANGE/FIDEDUPERANGE for reflink/dedupe IO commands

Message ID 20240817064826.14177-1-liuhuan01@kylinos.cn (mailing list archive)
State Accepted, archived
Headers show
Series xfs_io: use FICLONE/FICLONERANGE/FIDEDUPERANGE for reflink/dedupe IO commands | expand

Commit Message

liuh Aug. 17, 2024, 6:48 a.m. UTC
From: liuh <liuhuan01@kylinos.cn>

Use FICLONE/FICLONERANGE/FIDEDUPERANGE instead of XFS_IOC_CLONE/XFS_IOC_CLONE_RANGE/XFS_IOC_FILE_EXTENT_SAME.
And the declaration becomes useless, delete it.

Signed-off-by: liuh <liuhuan01@kylinos.cn>
---
 include/xfs_fs_compat.h | 54 -----------------------------------------
 io/reflink.c            | 52 +++++++++++++++++++--------------------
 2 files changed, 26 insertions(+), 80 deletions(-)
diff mbox series

Patch

diff --git a/include/xfs_fs_compat.h b/include/xfs_fs_compat.h
index 0077f00c..e53dcc6e 100644
--- a/include/xfs_fs_compat.h
+++ b/include/xfs_fs_compat.h
@@ -31,60 +31,6 @@ 
 #define	XFS_XFLAG_FILESTREAM	FS_XFLAG_FILESTREAM
 #define	XFS_XFLAG_HASATTR	FS_XFLAG_HASATTR
 
-/*
- * Don't use this.
- * Use struct file_clone_range
- */
-struct xfs_clone_args {
-	__s64 src_fd;
-	__u64 src_offset;
-	__u64 src_length;
-	__u64 dest_offset;
-};
-
-/*
- * Don't use these.
- * Use FILE_DEDUPE_RANGE_SAME / FILE_DEDUPE_RANGE_DIFFERS
- */
-#define XFS_EXTENT_DATA_SAME	0
-#define XFS_EXTENT_DATA_DIFFERS	1
-
-/* Don't use this. Use file_dedupe_range_info */
-struct xfs_extent_data_info {
-	__s64 fd;		/* in - destination file */
-	__u64 logical_offset;	/* in - start of extent in destination */
-	__u64 bytes_deduped;	/* out - total # of bytes we were able
-				 * to dedupe from this file */
-	/* status of this dedupe operation:
-	 * < 0 for error
-	 * == XFS_EXTENT_DATA_SAME if dedupe succeeds
-	 * == XFS_EXTENT_DATA_DIFFERS if data differs
-	 */
-	__s32 status;		/* out - see above description */
-	__u32 reserved;
-};
-
-/*
- * Don't use this.
- * Use struct file_dedupe_range
- */
-struct xfs_extent_data {
-	__u64 logical_offset;	/* in - start of extent in source */
-	__u64 length;		/* in - length of extent */
-	__u16 dest_count;	/* in - total elements in info array */
-	__u16 reserved1;
-	__u32 reserved2;
-	struct xfs_extent_data_info info[0];
-};
-
-/*
- * Don't use these.
- * Use FICLONE/FICLONERANGE/FIDEDUPERANGE
- */
-#define XFS_IOC_CLONE		 _IOW (0x94, 9, int)
-#define XFS_IOC_CLONE_RANGE	 _IOW (0x94, 13, struct xfs_clone_args)
-#define XFS_IOC_FILE_EXTENT_SAME _IOWR(0x94, 54, struct xfs_extent_data)
-
 /* 64-bit seconds counter that works independently of the C library time_t. */
 typedef long long int time64_t;
 
diff --git a/io/reflink.c b/io/reflink.c
index b6a3c05a..154ca65b 100644
--- a/io/reflink.c
+++ b/io/reflink.c
@@ -43,49 +43,49 @@  dedupe_ioctl(
 	uint64_t	len,
 	int		*ops)
 {
-	struct xfs_extent_data		*args;
-	struct xfs_extent_data_info	*info;
+	struct file_dedupe_range	*args;
+	struct file_dedupe_range_info	*info;
 	int				error;
 	uint64_t			deduped = 0;
 
-	args = calloc(1, sizeof(struct xfs_extent_data) +
-			 sizeof(struct xfs_extent_data_info));
+	args = calloc(1, sizeof(struct file_dedupe_range) +
+			 sizeof(struct file_dedupe_range_info));
 	if (!args)
 		goto done;
-	info = (struct xfs_extent_data_info *)(args + 1);
-	args->logical_offset = soffset;
-	args->length = len;
+	info = (struct file_dedupe_range_info *)(args + 1);
+	args->src_offset = soffset;
+	args->src_length = len;
 	args->dest_count = 1;
-	info->fd = file->fd;
-	info->logical_offset = doffset;
+	info->dest_fd = file->fd;
+	info->dest_offset = doffset;
 
-	while (args->length > 0 || !*ops) {
-		error = ioctl(fd, XFS_IOC_FILE_EXTENT_SAME, args);
+	while (args->src_length > 0 || !*ops) {
+		error = ioctl(fd, FIDEDUPERANGE, args);
 		if (error) {
-			perror("XFS_IOC_FILE_EXTENT_SAME");
+			perror("FIDEDUPERANGE");
 			exitcode = 1;
 			goto done;
 		}
 		if (info->status < 0) {
-			fprintf(stderr, "XFS_IOC_FILE_EXTENT_SAME: %s\n",
+			fprintf(stderr, "FIDEDUPERANGE: %s\n",
 					_(strerror(-info->status)));
 			goto done;
 		}
-		if (info->status == XFS_EXTENT_DATA_DIFFERS) {
-			fprintf(stderr, "XFS_IOC_FILE_EXTENT_SAME: %s\n",
+		if (info->status == FILE_DEDUPE_RANGE_DIFFERS) {
+			fprintf(stderr, "FIDEDUPERANGE: %s\n",
 					_("Extents did not match."));
 			goto done;
 		}
-		if (args->length != 0 &&
+		if (args->src_length != 0 &&
 		    (info->bytes_deduped == 0 ||
-		     info->bytes_deduped > args->length))
+		     info->bytes_deduped > args->src_length))
 			break;
 
 		(*ops)++;
-		args->logical_offset += info->bytes_deduped;
-		info->logical_offset += info->bytes_deduped;
-		if (args->length >= info->bytes_deduped)
-			args->length -= info->bytes_deduped;
+		args->src_offset += info->bytes_deduped;
+		info->dest_offset += info->bytes_deduped;
+		if (args->src_length >= info->bytes_deduped)
+			args->src_length -= info->bytes_deduped;
 		deduped += info->bytes_deduped;
 	}
 done:
@@ -200,21 +200,21 @@  reflink_ioctl(
 	uint64_t		len,
 	int			*ops)
 {
-	struct xfs_clone_args	args;
+	struct file_clone_range	args;
 	int			error;
 
 	if (soffset == 0 && doffset == 0 && len == 0) {
-		error = ioctl(file->fd, XFS_IOC_CLONE, fd);
+		error = ioctl(file->fd, FICLONE, fd);
 		if (error)
-			perror("XFS_IOC_CLONE");
+			perror("FICLONE");
 	} else {
 		args.src_fd = fd;
 		args.src_offset = soffset;
 		args.src_length = len;
 		args.dest_offset = doffset;
-		error = ioctl(file->fd, XFS_IOC_CLONE_RANGE, &args);
+		error = ioctl(file->fd, FICLONERANGE, &args);
 		if (error)
-			perror("XFS_IOC_CLONE_RANGE");
+			perror("FICLONERANGE");
 	}
 	if (!error)
 		(*ops)++;