@@ -652,6 +652,8 @@ _xfs_dic2xflags(
if (di_flags2 & XFS_DIFLAG2_ANY) {
if (di_flags2 & XFS_DIFLAG2_DAX)
flags |= FS_XFLAG_DAX;
+ if (di_flags2 & XFS_DIFLAG2_REFLINK)
+ flags |= FS_XFLAG_REFLINK;
}
if (has_attr)
@@ -41,6 +41,7 @@
#include "xfs_trans.h"
#include "xfs_pnfs.h"
#include "xfs_acl.h"
+#include "xfs_reflink.h"
#include <linux/capability.h>
#include <linux/dcache.h>
@@ -1261,6 +1262,10 @@ xfs_ioctl_setattr(
trace_xfs_ioctl_setattr(ip);
+ code = xfs_reflink_check_flag_adjust(ip, &fa->fsx_xflags);
+ if (code)
+ return code;
+
code = xfs_ioctl_setattr_check_projid(ip, fa);
if (code)
return code;
@@ -1743,3 +1743,29 @@ out_unlock:
trace_xfs_reflink_cow_eof_block_error(ip, error, _RET_IP_);
return error;
}
+
+/*
+ * Ensure that the only change we allow to the inode reflink flag is to clear
+ * it when the fs supports reflink and the size is zero.
+ */
+int
+xfs_reflink_check_flag_adjust(
+ struct xfs_inode *ip,
+ unsigned int *xflags)
+{
+ unsigned int chg;
+
+ chg = !!(*xflags & FS_XFLAG_REFLINK) ^ !!xfs_is_reflink_inode(ip);
+
+ if (!chg)
+ return 0;
+ if (!xfs_sb_version_hasreflink(&ip->i_mount->m_sb))
+ return -EOPNOTSUPP;
+ if (i_size_read(VFS_I(ip)) != 0)
+ return -EINVAL;
+ if (*xflags & FS_XFLAG_REFLINK) {
+ *xflags &= ~FS_XFLAG_REFLINK;
+ return 0;
+ }
+ return 0;
+}
@@ -53,4 +53,8 @@ extern int xfs_reflink_unshare(struct xfs_inode *ip, xfs_off_t offset,
xfs_off_t len);
extern int xfs_reflink_cow_eof_block(struct xfs_inode *ip, xfs_off_t newsize);
+extern void xfs_reflink_get_lxflags(struct xfs_inode *ip, unsigned int *flags);
+extern int xfs_reflink_check_flag_adjust(struct xfs_inode *ip,
+ unsigned int *xflags);
+
#endif /* __XFS_REFLINK_H */
Add support for reporting the "reflink" inode flag in the XFS-specific getxflags ioctl, and allow the user to clear the flag if file size is zero. v2: Move the reflink flag out of the way of the DAX flag, and add the new cowextsize flag. v3: do not report (or allow changes to) FL_NOCOW_FL, since we don't support a flag to prevent CoWing and the reflink flag is a poor proxy. We'll try to design away the need for the NOCOW flag. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> --- fs/xfs/xfs_inode.c | 2 ++ fs/xfs/xfs_ioctl.c | 5 +++++ fs/xfs/xfs_reflink.c | 26 ++++++++++++++++++++++++++ fs/xfs/xfs_reflink.h | 4 ++++ 4 files changed, 37 insertions(+)