xfstests: add cifs.ko server-side copy helper
Subsystems (3)
cover xfstests: add cifs.ko server-side copy helper
In preparation for adding cifs.ko support to xfstests, this patch series extends the cloner binary to support SMB2 server-side copies via CIFS_IOC_COPYCHUNK_FILE, in addition to the existing Btrfs COW clone functionality.
This could be split into a separate binary if deemed necessary, but given the code overlap, I though it suitable to share the same source.
Feedback appreciated.
--
David Disseldorp (2):
src/cloner: check filesystem type src/cloner: add CIFS_IOC_COPYCHUNK_FILE support
configure.ac | 1 + src/cloner.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 114 insertions(+), 10 deletions(-)
PATCH 1/2 src/cloner: check filesystem type
Limit clone requests to Btrfs only for the moment.
--- src/cloner.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
src/cloner.c +47 -0
@@ -22,6 +22,7 @@#include <sys/types.h> #include <sys/stat.h> #include <sys/ioctl.h> +#include <sys/vfs.h> #include <stdint.h> #include <stdbool.h> #include <fcntl.h>
@@ -30,6 +31,7 @@#include <stdio.h> #include <string.h> #include <errno.h> +#include <linux/magic.h> #ifdef HAVE_BTRFS_IOCTL_H #include <btrfs/ioctl.h> #else
@@ -47,6 +49,10 @@ struct btrfs_ioctl_clone_range_args { struct btrfs_ioctl_clone_range_args)#endif +#ifndef BTRFS_SUPER_MAGIC +#define BTRFS_SUPER_MAGIC 0x9123683E +#endif +static void usage (char *name,const char *msg) {
@@ -89,6 +95,41 @@ clone_file_range(int src_fd, int dst_fd, uint64_t src_off, uint64_t dst_off,return ret; } +static int +cloner_check_fs_support (int src_fd,int dest_fd,unsigned int *fs_type) +{ +int ret; +struct statfs sfs; + + ret =fstatfs (src_fd, &sfs); +if (ret !=0 ) { +printf ("failed to stat source FS\n" ); +return errno; + } + +if (sfs.f_type !=BTRFS_SUPER_MAGIC ) { +printf ("unsupported source FS 0x%x\n" , + (unsigned int )sfs.f_type); +return ENOTSUP ; + } + + *fs_type = (unsigned int )sfs.f_type; + + ret =fstatfs (dest_fd, &sfs); +if (ret !=0 ) { +printf ("failed to stat destination FS\n" ); +return errno; + } + +if (sfs.f_type != *fs_type) { +printf ("dest FS type 0x%x does not match source 0x%x\n" , + (unsigned int )sfs.f_type, *fs_type); +return ENOTSUP ; + } + +return 0 ; +} +int main (int argc,char **argv) {
@@ -102,6 +143,7 @@ main(int argc, char **argv)int dst_fd;int ret;int opt; +unsigned int fs_type =0 ;while ((opt =getopt (argc, argv,"s:d:l:" )) !=-1 ) {char *sval_end;
@@ -162,6 +204,11 @@ main(int argc, char **argv) goto err_src_close; } + ret =cloner_check_fs_support (src_fd, dst_fd, &fs_type); +if (ret !=0 ) { + goto err_dst_close; + } +if (full_file) { ret =clone_file (src_fd, dst_fd); }else {
Signature · 1 line
1.8.4.5
PATCH 2/2 src/cloner: add CIFS_IOC_COPYCHUNK_FILE support
In reply to David Disseldorpcifs.ko supports server-side copy offloads via CIFS_IOC_COPYCHUNK_FILE. In handling the ioctl, the request is split into a series of SMB2 FSCTL_SRV_COPYCHUNK wire requests, which may be handled by the SMB server as a local read/write, or COW clone as is the case for Samba with vfs_btrfs.
--- configure.ac | 1 + src/cloner.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 68 insertions(+), 11 deletions(-)
configure.ac +1 -0
@@ -31,6 +31,7 @@ AC_HEADER_STDC sys/fs/xfs_itable.h \ xfs/platform_defs.h \ btrfs/ioctl.h \ + cifs/ioctl.h \ ]) AC_CHECK_HEADERS([xfs/xfs_log_format.h],,,[#include <xfs/libxfs.h>])
src/cloner.c +67 -11
129 lines not on this page · raw message
Signature · 1 line
1.8.4.5