Skip to content

Commit

Permalink
mfu: copy much more xattrs
Browse files Browse the repository at this point in the history
When copying files using dcp or dsync, extended attributes
such as project id are also copied.

Resolves hpc#553.

Signed-off-by: Sohei Koyama <[email protected]>
  • Loading branch information
KoyamaSohei committed Oct 30, 2024
1 parent d56910b commit 0eca578
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/common/mfu_flist_copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include <time.h> /* asctime / localtime */
#include <regex.h>

#if DCOPY_USE_XATTRS
#include <linux/fs.h>
#endif

#ifdef HAVE_LIBATTR
#include <attr/libattr.h>
#endif /* HAVE_LIBATTR */
Expand Down Expand Up @@ -443,6 +447,31 @@ static int mfu_copy_xattrs(
mfu_free(&list);
list_bufsize = 0;

int src_fd = open(src_path, O_RDONLY);
if (src_fd >= 0) {
int dest_fd = open(dest_path, O_RDONLY);
if (dest_fd >= 0) {
struct fsxattr attr;
rc = ioctl(src_fd, FS_IOC_FSGETXATTR, &attr);
if (rc == 0) {
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_fd);
} else {
MFU_LOG(MFU_LOG_ERR, "open failed: `%s' errno=%d (%s)", dest_path, errno, strerror(errno));
rc = -1;
}
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;
Expand Down

0 comments on commit 0eca578

Please sign in to comment.