Skip to content

Commit a0a85dc

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 a0a85dc

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/common/mfu_flist_copy.c

Lines changed: 48 additions & 0 deletions
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,50 @@ 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+
MFU_LOG(MFU_LOG_ERR, "open failed: `%s' errno=%d (%s)", src_path, errno, strerror(errno));
454+
rc = -1;
455+
goto xattr_fin;
456+
}
457+
/* open the dest */
458+
int dest_fd = open(dest_path, O_RDONLY);
459+
if (dest_fd < 0) {
460+
MFU_LOG(MFU_LOG_ERR, "open failed: `%s' errno=%d (%s)", dest_path, errno, strerror(errno));
461+
rc = -1;
462+
goto xattr_close_src;
463+
}
464+
struct fsxattr src_attr;
465+
/* get src's xattr */
466+
rc = ioctl(src_fd, FS_IOC_FSGETXATTR, &src_attr);
467+
if (rc != 0) {
468+
MFU_LOG(MFU_LOG_ERR, "ioctl(FS_IOC_FSGETXATTR) failed: `%s' errno=%d (%s)", src_path, errno, strerror(errno));
469+
goto xattr_close_dest;
470+
}
471+
struct fsxattr dest_attr;
472+
/* get dest's xattr */
473+
rc = ioctl(dest_fd, FS_IOC_FSGETXATTR, &dest_attr);
474+
if (rc != 0) {
475+
MFU_LOG(MFU_LOG_ERR, "ioctl(FS_IOC_FSGETXATTR) failed: `%s' errno=%d (%s)", dest_path, errno, strerror(errno));
476+
goto xattr_close_dest;
477+
}
478+
dest_attr.fsx_projid = src_attr.fsx_projid;
479+
dest_attr.fsx_xflags = (dest_attr.fsx_xflags & ~FS_XFLAG_PROJINHERIT) |
480+
(src_attr.fsx_xflags & FS_XFLAG_PROJINHERIT);
481+
/* set dest's xattr */
482+
rc = ioctl(dest_fd, FS_IOC_FSSETXATTR, &dest_attr);
483+
if (rc != 0) {
484+
MFU_LOG(MFU_LOG_ERR, "ioctl(FS_IOC_FSSETXATTR) failed: `%s' errno=%d (%s)", dest_path, errno, strerror(errno));
485+
}
486+
xattr_close_dest:
487+
/* close dest */
488+
close(dest_fd);
489+
xattr_close_src:
490+
/* close src */
491+
close(src_fd);
492+
xattr_fin:
493+
446494
#endif /* DCOPY_USE_XATTR */
447495

448496
return rc;

0 commit comments

Comments
 (0)