Whamcloud - gitweb
LU-11154 llite: use proper flags for FS_IOC_{FSSET,FSGET}XATTR 28/32828/6
authorWang Shilong <wshilong@ddn.com>
Wed, 18 Jul 2018 08:30:28 +0000 (16:30 +0800)
committerOleg Drokin <green@whamcloud.com>
Thu, 23 Aug 2018 07:17:52 +0000 (07:17 +0000)
Two problems addressed by this patch:

1)struct fsxattr fsx_xflags has its own flags definition
like FS_XFLAG_XXX, we should use proper convert macro for
it, here we used wrong constant flag for project inherit flag.

2)FS_XFLAG_PROJINHERIT is not a valid vfs inode flag, looking
at current linux codes, local filesystem set project inherit
flag on its private flags, we should do similar thing to Lustre

Test-Parameters: trivial testlist=sanity-quota,sanity-quota,sanity-quota
Change-Id: I453db8ed074e8008f0ec145c726d7577121422e6
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-on: https://review.whamcloud.com/32828
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Olaf Weber <olaf.weber@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/uapi/linux/lustre/lustre_idl.h
lustre/include/uapi/linux/lustre/lustre_user.h
lustre/llite/file.c
lustre/llite/llite_internal.h
lustre/llite/llite_lib.c
lustre/utils/lfs_project.c

index d97732b..ba34185 100644 (file)
@@ -1729,6 +1729,18 @@ enum {
        LUSTRE_LMA_FL_MASKS = LUSTRE_ORPHAN_FL,
 };
 
+#ifndef FS_XFLAG_SYNC
+#define FS_XFLAG_SYNC          0x00000020      /* all writes synchronous */
+#endif
+#ifndef FS_XFLAG_NOATIME
+#define FS_XFLAG_NOATIME       0x00000040      /* do not update access time */
+#endif
+#ifndef FS_XFLAG_IMMUTABLE
+#define FS_XFLAG_IMMUTABLE     0x00000008      /* file cannot be modified */
+#endif
+#ifndef FS_XFLAG_APPEND
+#define FS_XFLAG_APPEND                0x00000010      /* all writes append */
+#endif
 #ifndef FS_XFLAG_PROJINHERIT
 #define FS_XFLAG_PROJINHERIT   0x00000200      /* create with parents projid */
 #endif
@@ -1748,8 +1760,7 @@ static inline int ll_ext_to_inode_flags(int flags)
 #if defined(S_DIRSYNC)
                 ((flags & LUSTRE_DIRSYNC_FL)   ? S_DIRSYNC   : 0) |
 #endif
-               ((flags & LUSTRE_IMMUTABLE_FL) ? S_IMMUTABLE : 0) |
-               ((flags & LUSTRE_PROJINHERIT_FL) ? FS_XFLAG_PROJINHERIT : 0));
+               ((flags & LUSTRE_IMMUTABLE_FL) ? S_IMMUTABLE : 0));
 }
 
 static inline int ll_inode_to_ext_flags(int iflags)
@@ -1760,8 +1771,23 @@ static inline int ll_inode_to_ext_flags(int iflags)
 #if defined(S_DIRSYNC)
                 ((iflags & S_DIRSYNC)   ? LUSTRE_DIRSYNC_FL   : 0) |
 #endif
-               ((iflags & S_IMMUTABLE) ? LUSTRE_IMMUTABLE_FL : 0) |
-               ((iflags & FS_XFLAG_PROJINHERIT) ? LUSTRE_PROJINHERIT_FL : 0));
+               ((iflags & S_IMMUTABLE) ? LUSTRE_IMMUTABLE_FL : 0));
+}
+
+static inline int ll_xflags_to_inode_flags(int xflags)
+{
+       return  ((xflags & FS_XFLAG_SYNC) ? S_SYNC : 0) |
+               ((xflags & FS_XFLAG_NOATIME) ? S_NOATIME : 0) |
+               ((xflags & FS_XFLAG_APPEND) ? S_APPEND : 0) |
+               ((xflags & FS_XFLAG_IMMUTABLE) ? S_IMMUTABLE : 0);
+}
+
+static inline int ll_inode_flags_to_xflags(int flags)
+{
+       return  ((flags & S_SYNC) ? FS_XFLAG_SYNC : 0) |
+               ((flags & S_NOATIME) ? FS_XFLAG_NOATIME : 0) |
+               ((flags & S_APPEND) ? FS_XFLAG_APPEND : 0) |
+               ((flags & S_IMMUTABLE) ? FS_XFLAG_IMMUTABLE : 0);
 }
 #endif
 
index 8b2a689..716ee16 100644 (file)
@@ -443,7 +443,9 @@ struct fsxattr {
 #endif
 #define LL_IOC_FSGETXATTR              FS_IOC_FSGETXATTR
 #define LL_IOC_FSSETXATTR              FS_IOC_FSSETXATTR
-#define LL_PROJINHERIT_FL              0x20000000
+#ifndef FS_XFLAG_PROJINHERIT
+#define FS_XFLAG_PROJINHERIT           0x00000200
+#endif
 
 
 #define LL_STATFS_LMV          1
index 719c744..8bfdf21 100644 (file)
@@ -104,6 +104,8 @@ static void ll_prepare_close(struct inode *inode, struct md_op_data *op_data,
                                     ATTR_CTIME | ATTR_CTIME_SET;
        op_data->op_attr_blocks = inode->i_blocks;
        op_data->op_attr_flags = ll_inode_to_ext_flags(inode->i_flags);
+       if (ll_file_test_flag(ll_i2info(inode), LLIF_PROJECT_INHERIT))
+               op_data->op_attr_flags |= LUSTRE_PROJINHERIT_FL;
        op_data->op_handle = och->och_fh;
 
        if (och->och_flags & FMODE_WRITE &&
@@ -3046,7 +3048,9 @@ int ll_ioctl_fsgetxattr(struct inode *inode, unsigned int cmd,
                           sizeof(fsxattr)))
                RETURN(-EFAULT);
 
-       fsxattr.fsx_xflags = ll_inode_to_ext_flags(inode->i_flags);
+       fsxattr.fsx_xflags = ll_inode_flags_to_xflags(inode->i_flags);
+       if (ll_file_test_flag(ll_i2info(inode), LLIF_PROJECT_INHERIT))
+               fsxattr.fsx_xflags |= FS_XFLAG_PROJINHERIT;
        fsxattr.fsx_projid = ll_i2info(inode)->lli_projid;
        if (copy_to_user((struct fsxattr __user *)arg,
                         &fsxattr, sizeof(fsxattr)))
@@ -3064,6 +3068,7 @@ int ll_ioctl_fssetxattr(struct inode *inode, unsigned int cmd,
        int rc = 0;
        struct fsxattr fsxattr;
        struct cl_object *obj;
+       int flags;
 
        /* only root could change project ID */
        if (!cfs_capable(CFS_CAP_SYS_ADMIN))
@@ -3079,7 +3084,10 @@ int ll_ioctl_fssetxattr(struct inode *inode, unsigned int cmd,
                           sizeof(fsxattr)))
                GOTO(out_fsxattr1, rc = -EFAULT);
 
-       op_data->op_attr_flags = fsxattr.fsx_xflags;
+       flags = ll_xflags_to_inode_flags(fsxattr.fsx_xflags);
+       op_data->op_attr_flags = ll_inode_to_ext_flags(flags);
+       if (fsxattr.fsx_xflags & FS_XFLAG_PROJINHERIT)
+               op_data->op_attr_flags |= LUSTRE_PROJINHERIT_FL;
        op_data->op_projid = fsxattr.fsx_projid;
        op_data->op_attr.ia_valid |= (MDS_ATTR_PROJID | ATTR_ATTR_FLAG);
        rc = md_setattr(ll_i2sbi(inode)->ll_md_exp, op_data, NULL,
@@ -3090,7 +3098,7 @@ int ll_ioctl_fssetxattr(struct inode *inode, unsigned int cmd,
        if (obj) {
                struct iattr *attr;
 
-               inode->i_flags = ll_ext_to_inode_flags(fsxattr.fsx_xflags);
+               ll_update_inode_flags(inode, op_data->op_attr_flags);
                OBD_ALLOC_PTR(attr);
                if (attr == NULL)
                        GOTO(out_fsxattr1, rc = -ENOMEM);
index 716263b..bca1084 100644 (file)
@@ -260,6 +260,8 @@ enum ll_file_flags {
        LLIF_FILE_RESTORING     = 1,
        /* Xattr cache is attached to the file */
        LLIF_XATTR_CACHE        = 2,
+       /* Project inherit */
+       LLIF_PROJECT_INHERIT    = 3,
 };
 
 static inline void ll_file_set_flag(struct ll_inode_info *lli,
@@ -927,6 +929,7 @@ int ll_statfs(struct dentry *de, struct kstatfs *sfs);
 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
                       u32 flags);
 int ll_update_inode(struct inode *inode, struct lustre_md *md);
+void ll_update_inode_flags(struct inode *inode, int ext_flags);
 int ll_read_inode2(struct inode *inode, void *opaque);
 void ll_delete_inode(struct inode *inode);
 int ll_iocontrol(struct inode *inode, struct file *file,
index 5665a5f..54a752f 100644 (file)
@@ -1900,6 +1900,15 @@ void ll_inode_size_unlock(struct inode *inode)
        mutex_unlock(&lli->lli_size_mutex);
 }
 
+void ll_update_inode_flags(struct inode *inode, int ext_flags)
+{
+       inode->i_flags = ll_ext_to_inode_flags(ext_flags);
+       if (ext_flags & LUSTRE_PROJINHERIT_FL)
+               ll_file_set_flag(ll_i2info(inode), LLIF_PROJECT_INHERIT);
+       else
+               ll_file_clear_flag(ll_i2info(inode), LLIF_PROJECT_INHERIT);
+}
+
 int ll_update_inode(struct inode *inode, struct lustre_md *md)
 {
        struct ll_inode_info *lli = ll_i2info(inode);
@@ -1956,7 +1965,7 @@ int ll_update_inode(struct inode *inode, struct lustre_md *md)
 
        /* Clear i_flags to remove S_NOSEC before permissions are updated */
        if (body->mbo_valid & OBD_MD_FLFLAGS)
-               inode->i_flags = ll_ext_to_inode_flags(body->mbo_flags);
+               ll_update_inode_flags(inode, body->mbo_flags);
        if (body->mbo_valid & OBD_MD_FLMODE)
                inode->i_mode = (inode->i_mode & S_IFMT) |
                                (body->mbo_mode & ~S_IFMT);
@@ -2158,7 +2167,7 @@ int ll_iocontrol(struct inode *inode, struct file *file,
                if (rc)
                        RETURN(rc);
 
-               inode->i_flags = ll_ext_to_inode_flags(flags);
+               ll_update_inode_flags(inode, flags);
 
                obj = ll_i2info(inode)->lli_clob;
                if (obj == NULL)
index 07eff3c..a2e9eb2 100644 (file)
@@ -119,7 +119,7 @@ project_check_one(const char *pathname, struct project_handle_control *phc)
                phc->projid = fsx.fsx_projid;
        }
 
-       if (!(fsx.fsx_xflags & LL_PROJINHERIT_FL)) {
+       if (!(fsx.fsx_xflags & FS_XFLAG_PROJINHERIT)) {
                if (!phc->newline) {
                        printf("%s%c", pathname, '\0');
                        goto out;
@@ -152,7 +152,7 @@ project_list_one(const char *pathname, struct project_handle_control *phc)
                return ret;
 
        printf("%5u %c %s\n", fsx.fsx_projid,
-              (fsx.fsx_xflags & LL_PROJINHERIT_FL) ?
+              (fsx.fsx_xflags & FS_XFLAG_PROJINHERIT) ?
                'P' : '-', pathname);
 
        close(ret);
@@ -170,11 +170,11 @@ project_set_one(const char *pathname, struct project_handle_control *phc)
                return fd;
 
        if ((!phc->set_projid || fsx.fsx_projid == phc->projid) &&
-           (!phc->set_inherit || (fsx.fsx_xflags & LL_PROJINHERIT_FL)))
+           (!phc->set_inherit || (fsx.fsx_xflags & FS_XFLAG_PROJINHERIT)))
                goto out;
 
        if (phc->set_inherit)
-               fsx.fsx_xflags |= LL_PROJINHERIT_FL;
+               fsx.fsx_xflags |= FS_XFLAG_PROJINHERIT;
        if (phc->set_projid)
                fsx.fsx_projid = phc->projid;
 
@@ -197,11 +197,11 @@ project_clear_one(const char *pathname, struct project_handle_control *phc)
        if (fd < 0)
                return fd;
 
-       if ((!(fsx.fsx_xflags & LL_PROJINHERIT_FL)) &&
+       if ((!(fsx.fsx_xflags & FS_XFLAG_PROJINHERIT)) &&
             (fsx.fsx_projid == 0 || phc->keep_projid))
                goto out;
 
-       fsx.fsx_xflags &= ~LL_PROJINHERIT_FL;
+       fsx.fsx_xflags &= ~FS_XFLAG_PROJINHERIT;
        if (!phc->keep_projid)
                fsx.fsx_projid = 0;