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 <skoyama@ddn.com>
  • Loading branch information
KoyamaSohei committed Oct 30, 2024
1 parent d56910b commit bc47cfc
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 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,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;
Expand Down

0 comments on commit bc47cfc

Please sign in to comment.