Skip to content

Commit e2c8147

Browse files
committed
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 <[email protected]>
1 parent d56910b commit e2c8147

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/common/mfu_flist_copy.c

+35
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#include <time.h> /* asctime / localtime */
1919
#include <regex.h>
2020

21+
#if DCOPY_USE_XATTRS
22+
#include <linux/fs.h>
23+
#endif
24+
2125
#ifdef HAVE_LIBATTR
2226
#include <attr/libattr.h>
2327
#endif /* HAVE_LIBATTR */
@@ -443,6 +447,37 @@ static int mfu_copy_xattrs(
443447
mfu_free(&list);
444448
list_bufsize = 0;
445449

450+
/* open the src */
451+
int src_fd = open(src_path, O_RDONLY);
452+
if (src_fd >= 0) {
453+
/* open the dest */
454+
int dest_fd = open(dest_path, O_RDONLY);
455+
if (dest_fd >= 0) {
456+
struct fsxattr attr;
457+
/* get src's xattr */
458+
rc = ioctl(src_fd, FS_IOC_FSGETXATTR, &attr);
459+
if (rc == 0) {
460+
/* set dest's xattr */
461+
rc = ioctl(dest_fd, FS_IOC_FSSETXATTR, &attr);
462+
if (rc != 0) {
463+
MFU_LOG(MFU_LOG_ERR, "ioctl failed: `%s' errno=%d (%s)", dest_path, errno, strerror(errno));
464+
}
465+
} else {
466+
MFU_LOG(MFU_LOG_ERR, "ioctl failed: `%s' errno=%d (%s)", src_path, errno, strerror(errno));
467+
}
468+
/* close dest */
469+
close(dest_fd);
470+
} else {
471+
MFU_LOG(MFU_LOG_ERR, "open failed: `%s' errno=%d (%s)", dest_path, errno, strerror(errno));
472+
rc = -1;
473+
}
474+
/* close src */
475+
close(src_fd);
476+
} else {
477+
MFU_LOG(MFU_LOG_ERR, "open failed: `%s' errno=%d (%s)", src_path, errno, strerror(errno));
478+
rc = -1;
479+
}
480+
446481
#endif /* DCOPY_USE_XATTR */
447482

448483
return rc;

0 commit comments

Comments
 (0)