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 #553.

Signed-off-by: Sohei Koyama <[email protected]>
  • Loading branch information
KoyamaSohei committed Nov 26, 2024
1 parent d56910b commit a0a85dc
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 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,50 @@ 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) {
MFU_LOG(MFU_LOG_ERR, "open failed: `%s' errno=%d (%s)", src_path, errno, strerror(errno));
rc = -1;
goto xattr_fin;
}
/* open the dest */
int dest_fd = open(dest_path, O_RDONLY);
if (dest_fd < 0) {
MFU_LOG(MFU_LOG_ERR, "open failed: `%s' errno=%d (%s)", dest_path, errno, strerror(errno));
rc = -1;
goto xattr_close_src;
}
struct fsxattr src_attr;
/* get src's xattr */
rc = ioctl(src_fd, FS_IOC_FSGETXATTR, &src_attr);
if (rc != 0) {
MFU_LOG(MFU_LOG_ERR, "ioctl(FS_IOC_FSGETXATTR) failed: `%s' errno=%d (%s)", src_path, errno, strerror(errno));
goto xattr_close_dest;
}
struct fsxattr dest_attr;
/* get dest's xattr */
rc = ioctl(dest_fd, FS_IOC_FSGETXATTR, &dest_attr);
if (rc != 0) {
MFU_LOG(MFU_LOG_ERR, "ioctl(FS_IOC_FSGETXATTR) failed: `%s' errno=%d (%s)", dest_path, errno, strerror(errno));
goto xattr_close_dest;
}
dest_attr.fsx_projid = src_attr.fsx_projid;
dest_attr.fsx_xflags = (dest_attr.fsx_xflags & ~FS_XFLAG_PROJINHERIT) |
(src_attr.fsx_xflags & FS_XFLAG_PROJINHERIT);
/* set dest's xattr */
rc = ioctl(dest_fd, FS_IOC_FSSETXATTR, &dest_attr);
if (rc != 0) {
MFU_LOG(MFU_LOG_ERR, "ioctl(FS_IOC_FSSETXATTR) failed: `%s' errno=%d (%s)", dest_path, errno, strerror(errno));
}
xattr_close_dest:
/* close dest */
close(dest_fd);
xattr_close_src:
/* close src */
close(src_fd);
xattr_fin:

#endif /* DCOPY_USE_XATTR */

return rc;
Expand Down

0 comments on commit a0a85dc

Please sign in to comment.