From bc47cfc93d250f97b6c46d726b077e7fc113bd78 Mon Sep 17 00:00:00 2001 From: Sohei Koyama Date: Wed, 30 Oct 2024 18:28:08 +0900 Subject: [PATCH] mfu: copy much more xattrs When copying files using dcp or dsync, extended attributes such as project id are also copied. Resolves #553. Signed-off-by: Sohei Koyama --- src/common/mfu_flist_copy.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/common/mfu_flist_copy.c b/src/common/mfu_flist_copy.c index 0775116f..11476b00 100644 --- a/src/common/mfu_flist_copy.c +++ b/src/common/mfu_flist_copy.c @@ -18,6 +18,10 @@ #include /* asctime / localtime */ #include +#if DCOPY_USE_XATTRS +#include +#endif + #ifdef HAVE_LIBATTR #include #endif /* HAVE_LIBATTR */ @@ -443,6 +447,37 @@ static int mfu_copy_xattrs( mfu_free(&list); list_bufsize = 0; + /* open the src */ + int src_fd = open(src_path, O_RDONLY); + if (src_fd >= 0) { + /* open the dest */ + int dest_fd = open(dest_path, O_RDONLY); + if (dest_fd >= 0) { + struct fsxattr attr; + /* get src's xattr */ + rc = ioctl(src_fd, FS_IOC_FSGETXATTR, &attr); + if (rc == 0) { + /* set dest's xattr */ + rc = ioctl(dest_fd, FS_IOC_FSSETXATTR, &attr); + if (rc != 0) { + MFU_LOG(MFU_LOG_ERR, "ioctl failed: `%s' errno=%d (%s)", dest_path, errno, strerror(errno)); + } + } else { + MFU_LOG(MFU_LOG_ERR, "ioctl failed: `%s' errno=%d (%s)", src_path, errno, strerror(errno)); + } + /* close dest */ + close(dest_fd); + } else { + MFU_LOG(MFU_LOG_ERR, "open failed: `%s' errno=%d (%s)", dest_path, errno, strerror(errno)); + rc = -1; + } + /* close src */ + close(src_fd); + } else { + MFU_LOG(MFU_LOG_ERR, "open failed: `%s' errno=%d (%s)", src_path, errno, strerror(errno)); + rc = -1; + } + #endif /* DCOPY_USE_XATTR */ return rc;