Whamcloud - gitweb
LU-5100 llite: set dir LOV xattr length variable
[fs/lustre-release.git] / lustre / llite / xattr.c
index 1b5b821..effdd01 100644 (file)
@@ -123,6 +123,15 @@ int ll_setxattr_common(struct inode *inode, const char *name,
         if (rc)
                 RETURN(rc);
 
+       if ((xattr_type == XATTR_ACL_ACCESS_T ||
+            xattr_type == XATTR_ACL_DEFAULT_T) &&
+#ifdef HAVE_INODE_OWNER_OR_CAPABLE
+           !inode_owner_or_capable(inode))
+#else
+           !is_owner_or_cap(inode))
+#endif
+               return -EPERM;
+
         /* b10667: ignore lustre special xattr for now */
         if ((xattr_type == XATTR_TRUSTED_T && strcmp(name, "trusted.lov") == 0) ||
             (xattr_type == XATTR_LUSTRE_T && strcmp(name, "lustre.lov") == 0))
@@ -139,21 +148,21 @@ int ll_setxattr_common(struct inode *inode, const char *name,
                 RETURN(-EOPNOTSUPP);
 
 #ifdef CONFIG_FS_POSIX_ACL
-        if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
-            (xattr_type == XATTR_ACL_ACCESS_T ||
-            xattr_type == XATTR_ACL_DEFAULT_T)) {
-                rce = rct_search(&sbi->ll_rct, cfs_curproc_pid());
-                if (rce == NULL ||
-                    (rce->rce_ops != RMT_LSETFACL &&
-                    rce->rce_ops != RMT_RSETFACL))
-                        RETURN(-EOPNOTSUPP);
-
-                if (rce->rce_ops == RMT_LSETFACL) {
-                        struct eacl_entry *ee;
-
-                        ee = et_search_del(&sbi->ll_et, cfs_curproc_pid(),
-                                           ll_inode2fid(inode), xattr_type);
-                        LASSERT(ee != NULL);
+       if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
+           (xattr_type == XATTR_ACL_ACCESS_T ||
+           xattr_type == XATTR_ACL_DEFAULT_T)) {
+               rce = rct_search(&sbi->ll_rct, current_pid());
+               if (rce == NULL ||
+                   (rce->rce_ops != RMT_LSETFACL &&
+                   rce->rce_ops != RMT_RSETFACL))
+                       RETURN(-EOPNOTSUPP);
+
+               if (rce->rce_ops == RMT_LSETFACL) {
+                       struct eacl_entry *ee;
+
+                       ee = et_search_del(&sbi->ll_et, current_pid(),
+                                          ll_inode2fid(inode), xattr_type);
+                       LASSERT(ee != NULL);
                         if (valid & OBD_MD_FLXATTR) {
                                 acl = lustre_acl_xattr_merge2ext(
                                                 (posix_acl_xattr_header *)value,
@@ -183,17 +192,11 @@ int ll_setxattr_common(struct inode *inode, const char *name,
                 valid |= rce_ops2valid(rce->rce_ops);
         }
 #endif
-       if (sbi->ll_xattr_cache_enabled &&
-           (rce == NULL || rce->rce_ops == RMT_LSETFACL)) {
-               rc = ll_xattr_cache_update(inode, name, pv, size, valid, flags);
-       } else {
-               oc = ll_mdscapa_get(inode);
-               rc = md_setxattr(sbi->ll_md_exp, ll_inode2fid(inode), oc,
-                               valid, name, pv, size, 0, flags,
-                               ll_i2suppgid(inode), &req);
-               capa_put(oc);
-       }
-
+       oc = ll_mdscapa_get(inode);
+       rc = md_setxattr(sbi->ll_md_exp, ll_inode2fid(inode), oc,
+                       valid, name, pv, size, 0, flags,
+                       ll_i2suppgid(inode), &req);
+       capa_put(oc);
 #ifdef CONFIG_FS_POSIX_ACL
         if (new_value != NULL)
                 lustre_posix_acl_xattr_free(new_value, size);
@@ -221,8 +224,8 @@ int ll_setxattr(struct dentry *dentry, const char *name,
         LASSERT(inode);
         LASSERT(name);
 
-        CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p), xattr %s\n",
-               inode->i_ino, inode->i_generation, inode, name);
+       CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), xattr %s\n",
+              PFID(ll_inode2fid(inode)), inode, name);
 
         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_SETXATTR, 1);
 
@@ -273,8 +276,8 @@ int ll_removexattr(struct dentry *dentry, const char *name)
         LASSERT(inode);
         LASSERT(name);
 
-        CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p), xattr %s\n",
-               inode->i_ino, inode->i_generation, inode, name);
+       CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), xattr %s\n",
+              PFID(ll_inode2fid(inode)), inode, name);
 
         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_REMOVEXATTR, 1);
         return ll_setxattr_common(inode, name, NULL, 0, 0,
@@ -292,10 +295,11 @@ int ll_getxattr_common(struct inode *inode, const char *name,
         void *xdata;
         struct obd_capa *oc;
         struct rmtacl_ctl_entry *rce = NULL;
+       struct ll_inode_info *lli = ll_i2info(inode);
         ENTRY;
 
-        CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n",
-               inode->i_ino, inode->i_generation, inode);
+       CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
+              PFID(ll_inode2fid(inode)), inode);
 
         /* listxattr have slightly different behavior from of ext3:
          * without 'user_xattr' ext3 will list all xattr names but
@@ -322,17 +326,17 @@ int ll_getxattr_common(struct inode *inode, const char *name,
                 RETURN(-EOPNOTSUPP);
 
 #ifdef CONFIG_FS_POSIX_ACL
-        if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
-            (xattr_type == XATTR_ACL_ACCESS_T ||
-            xattr_type == XATTR_ACL_DEFAULT_T)) {
-                rce = rct_search(&sbi->ll_rct, cfs_curproc_pid());
-                if (rce == NULL ||
-                    (rce->rce_ops != RMT_LSETFACL &&
-                    rce->rce_ops != RMT_LGETFACL &&
-                    rce->rce_ops != RMT_RSETFACL &&
-                    rce->rce_ops != RMT_RGETFACL))
-                        RETURN(-EOPNOTSUPP);
-        }
+       if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
+           (xattr_type == XATTR_ACL_ACCESS_T ||
+           xattr_type == XATTR_ACL_DEFAULT_T)) {
+               rce = rct_search(&sbi->ll_rct, current_pid());
+               if (rce == NULL ||
+                   (rce->rce_ops != RMT_LSETFACL &&
+                   rce->rce_ops != RMT_LGETFACL &&
+                   rce->rce_ops != RMT_RSETFACL &&
+                   rce->rce_ops != RMT_RGETFACL))
+                       RETURN(-EOPNOTSUPP);
+       }
 
         /* posix acl is under protection of LOOKUP lock. when calling to this,
          * we just have path resolution to the target inode, so we have great
@@ -340,7 +344,7 @@ int ll_getxattr_common(struct inode *inode, const char *name,
          */
         if (xattr_type == XATTR_ACL_ACCESS_T &&
             !(sbi->ll_flags & LL_SBI_RMT_CLIENT)) {
-                struct ll_inode_info *lli = ll_i2info(inode);
+
                 struct posix_acl *acl;
 
                spin_lock(&lli->lli_lock);
@@ -359,13 +363,27 @@ int ll_getxattr_common(struct inode *inode, const char *name,
 #endif
 
 do_getxattr:
-       if (sbi->ll_xattr_cache_enabled && (rce == NULL ||
-                                           rce->rce_ops == RMT_LGETFACL ||
-                                           rce->rce_ops == RMT_LSETFACL)) {
+       if (sbi->ll_xattr_cache_enabled && xattr_type != XATTR_ACL_ACCESS_T) {
                rc = ll_xattr_cache_get(inode, name, buffer, size, valid);
+               if (rc == -EAGAIN)
+                       goto getxattr_nocache;
                if (rc < 0)
                        GOTO(out_xattr, rc);
+
+               /* Add "system.posix_acl_access" to the list */
+               if (lli->lli_posix_acl != NULL && valid & OBD_MD_FLXATTRLS) {
+                       if (size == 0) {
+                               rc += sizeof(XATTR_NAME_ACL_ACCESS);
+                       } else if (size - rc >= sizeof(XATTR_NAME_ACL_ACCESS)) {
+                               memcpy(buffer + rc, XATTR_NAME_ACL_ACCESS,
+                                      sizeof(XATTR_NAME_ACL_ACCESS));
+                               rc += sizeof(XATTR_NAME_ACL_ACCESS);
+                       } else {
+                               GOTO(out_xattr, rc = -ERANGE);
+                       }
+               }
        } else {
+getxattr_nocache:
                oc = ll_mdscapa_get(inode);
                rc = md_getxattr(sbi->ll_md_exp, ll_inode2fid(inode), oc,
                                valid | (rce ? rce_ops2valid(rce->rce_ops) : 0),
@@ -402,21 +420,20 @@ do_getxattr:
        }
 
 #ifdef CONFIG_FS_POSIX_ACL
-       if (rce && rce->rce_ops == RMT_LSETFACL) {
+       if (rce != NULL && rce->rce_ops == RMT_LSETFACL) {
                ext_acl_xattr_header *acl;
 
-               acl = lustre_posix_acl_xattr_2ext((posix_acl_xattr_header *)buffer,
-                                               rc);
-                if (IS_ERR(acl))
-                        GOTO(out, rc = PTR_ERR(acl));
+               acl = lustre_posix_acl_xattr_2ext(buffer, rc);
+               if (IS_ERR(acl))
+                       GOTO(out, rc = PTR_ERR(acl));
 
-                rc = ee_add(&sbi->ll_et, cfs_curproc_pid(), ll_inode2fid(inode),
-                            xattr_type, acl);
-                if (unlikely(rc < 0)) {
-                        lustre_ext_acl_xattr_free(acl);
-                        GOTO(out, rc);
-                }
-        }
+               rc = ee_add(&sbi->ll_et, current_pid(), ll_inode2fid(inode),
+                           xattr_type, acl);
+               if (unlikely(rc < 0)) {
+                       lustre_ext_acl_xattr_free(acl);
+                       GOTO(out, rc);
+               }
+       }
 #endif
        EXIT;
 
@@ -440,8 +457,8 @@ ssize_t ll_getxattr(struct dentry *dentry, const char *name,
         LASSERT(inode);
         LASSERT(name);
 
-        CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p), xattr %s\n",
-               inode->i_ino, inode->i_generation, inode, name);
+       CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), xattr %s\n",
+              PFID(ll_inode2fid(inode)), inode, name);
 
         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_GETXATTR, 1);
 
@@ -460,23 +477,17 @@ ssize_t ll_getxattr(struct dentry *dentry, const char *name,
                 if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode))
                         return -ENODATA;
 
-                if (size == 0 && S_ISDIR(inode->i_mode)) {
-                        /* XXX directory EA is fix for now, optimize to save
-                         * RPC transfer */
-                        GOTO(out, rc = sizeof(struct lov_user_md));
-                }
-
                lsm = ccc_inode_lsm_get(inode);
                if (lsm == NULL) {
-                        if (S_ISDIR(inode->i_mode)) {
-                                rc = ll_dir_getstripe(inode, &lmm,
-                                                      &lmmsize, &request);
-                        } else {
-                                rc = -ENODATA;
-                        }
-                } else {
-                        /* LSM is present already after lookup/getattr call.
-                         * we need to grab layout lock once it is implemented */
+                       if (S_ISDIR(inode->i_mode)) {
+                               rc = ll_dir_getstripe(inode, (void **)&lmm,
+                                                     &lmmsize, &request, 0);
+                       } else {
+                               rc = -ENODATA;
+                       }
+               } else {
+                       /* LSM is present already after lookup/getattr call.
+                        * we need to grab layout lock once it is implemented */
                        rc = obd_packmd(ll_i2dtexp(inode), &lmm, lsm);
                        lmmsize = rc;
                }
@@ -529,8 +540,8 @@ ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size)
 
         LASSERT(inode);
 
-        CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n",
-               inode->i_ino, inode->i_generation, inode);
+       CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
+              PFID(ll_inode2fid(inode)), inode);
 
         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_LISTXATTR, 1);
 
@@ -563,10 +574,11 @@ ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size)
        }
        if (S_ISREG(inode->i_mode)) {
                if (!ll_i2info(inode)->lli_has_smd)
-                        rc2 = -1;
-        } else if (S_ISDIR(inode->i_mode)) {
-                rc2 = ll_dir_getstripe(inode, &lmm, &lmmsize, &request);
-        }
+                       rc2 = -1;
+       } else if (S_ISDIR(inode->i_mode)) {
+               rc2 = ll_dir_getstripe(inode, (void **)&lmm, &lmmsize, &request,
+                                      0);
+       }
 
         if (rc2 < 0) {
                 GOTO(out, rc2 = 0);