Whamcloud - gitweb
LU-5560 llite: basic support of SELinux in CLIO
[fs/lustre-release.git] / lustre / llite / xattr_cache.c
index de5d8e2..031a470 100644 (file)
@@ -24,6 +24,8 @@
 /*
  * Copyright 2012 Xyratex Technology Limited
  *
+ * Copyright (c) 2013, 2014, Intel Corporation.
+ *
  * Author: Andrew Perepechko <Andrew_Perepechko@xyratex.com>
  *
  */
@@ -34,7 +36,6 @@
 #include <linux/sched.h>
 #include <linux/mm.h>
 #include <obd_support.h>
-#include <lustre_lite.h>
 #include <lustre_dlm.h>
 #include <lustre_ver.h>
 #include "llite_internal.h"
@@ -84,8 +85,8 @@ static void ll_xattr_cache_init(struct ll_inode_info *lli)
 
        LASSERT(lli != NULL);
 
-       CFS_INIT_LIST_HEAD(&lli->lli_xattrs);
-       lli->lli_flags |= LLIF_XATTR_CACHE;
+       INIT_LIST_HEAD(&lli->lli_xattrs);
+       ll_file_set_flag(lli, LLIF_XATTR_CACHE);
 }
 
 /**
@@ -143,7 +144,7 @@ static int ll_xattr_cache_add(struct list_head *cache,
                RETURN(-EPROTO);
        }
 
-       OBD_SLAB_ALLOC_PTR_GFP(xattr, xattr_kmem, __GFP_IO);
+       OBD_SLAB_ALLOC_PTR_GFP(xattr, xattr_kmem, GFP_NOFS);
        if (xattr == NULL) {
                CDEBUG(D_CACHE, "failed to allocate xattr\n");
                RETURN(-ENOMEM);
@@ -255,9 +256,9 @@ static int ll_xattr_cache_list(struct list_head *cache,
  * \retval 0 @cache is not initialized
  * \retval 1 @cache is initialized
  */
-int ll_xattr_cache_valid(struct ll_inode_info *lli)
+static int ll_xattr_cache_valid(struct ll_inode_info *lli)
 {
-       return !!(lli->lli_flags & LLIF_XATTR_CACHE);
+       return ll_file_test_flag(lli, LLIF_XATTR_CACHE);
 }
 
 /**
@@ -276,7 +277,8 @@ static int ll_xattr_cache_destroy_locked(struct ll_inode_info *lli)
 
        while (ll_xattr_cache_del(&lli->lli_xattrs, NULL) == 0)
                /* empty loop */ ;
-       lli->lli_flags &= ~LLIF_XATTR_CACHE;
+
+       ll_file_clear_flag(lli, LLIF_XATTR_CACHE);
 
        RETURN(0);
 }
@@ -314,10 +316,12 @@ static int ll_xattr_find_get_lock(struct inode *inode,
        struct lustre_handle lockh = { 0 };
        struct md_op_data *op_data;
        struct ll_inode_info *lli = ll_i2info(inode);
-       struct ldlm_enqueue_info einfo = { .ei_type = LDLM_IBITS,
-                                          .ei_mode = it_to_lock_mode(oit),
-                                          .ei_cb_bl = ll_md_blocking_ast,
-                                          .ei_cb_cp = ldlm_completion_ast };
+       struct ldlm_enqueue_info einfo = {
+               .ei_type = LDLM_IBITS,
+               .ei_mode = it_to_lock_mode(oit),
+               .ei_cb_bl = &ll_md_blocking_ast,
+               .ei_cb_cp = &ldlm_completion_ast,
+       };
        struct ll_sb_info *sbi = ll_i2sbi(inode);
        struct obd_export *exp = sbi->ll_md_exp;
        int rc;
@@ -325,13 +329,18 @@ static int ll_xattr_find_get_lock(struct inode *inode,
        ENTRY;
 
        mutex_lock(&lli->lli_xattrs_enq_lock);
-       /* Try matching first. */
-       mode = ll_take_md_lock(inode, MDS_INODELOCK_XATTR, &lockh, 0, LCK_PR);
-       if (mode != 0) {
-               /* fake oit in mdc_revalidate_lock() manner */
-               oit->d.lustre.it_lock_handle = lockh.cookie;
-               oit->d.lustre.it_lock_mode = mode;
-               goto out;
+       /* inode may have been shrunk and recreated, so data is gone, match lock
+        * only when data exists. */
+       if (ll_xattr_cache_valid(lli)) {
+               /* Try matching first. */
+               mode = ll_take_md_lock(inode, MDS_INODELOCK_XATTR, &lockh, 0,
+                                       LCK_PR);
+               if (mode != 0) {
+                       /* fake oit in mdc_revalidate_lock() manner */
+                       oit->d.lustre.it_lock_handle = lockh.cookie;
+                       oit->d.lustre.it_lock_mode = mode;
+                       goto out;
+               }
        }
 
        /* Enqueue if the lock isn't cached locally. */
@@ -344,7 +353,7 @@ static int ll_xattr_find_get_lock(struct inode *inode,
 
        op_data->op_valid = OBD_MD_FLXATTR | OBD_MD_FLXATTRLS;
 
-       rc = md_enqueue(exp, &einfo, oit, op_data, &lockh, NULL, 0, NULL, 0);
+       rc = md_enqueue(exp, &einfo, NULL, oit, op_data, &lockh, 0);
        ll_finish_md_op_data(op_data);
 
        if (rc < 0) {
@@ -418,24 +427,25 @@ static int ll_xattr_cache_refill(struct inode *inode, struct lookup_intent *oit)
        }
        /* do not need swab xattr data */
        xdata = req_capsule_server_sized_get(&req->rq_pill, &RMF_EADATA,
-                                               body->eadatasize);
+                                               body->mbo_eadatasize);
        xval = req_capsule_server_sized_get(&req->rq_pill, &RMF_EAVALS,
-                                               body->aclsize);
+                                               body->mbo_aclsize);
        xsizes = req_capsule_server_sized_get(&req->rq_pill, &RMF_EAVALS_LENS,
-                                             body->max_mdsize * sizeof(__u32));
+                                             body->mbo_max_mdsize *
+                                             sizeof(__u32));
        if (xdata == NULL || xval == NULL || xsizes == NULL) {
                CERROR("wrong setxattr reply\n");
                GOTO(out_destroy, rc = -EPROTO);
        }
 
-       xtail = xdata + body->eadatasize;
-       xvtail = xval + body->aclsize;
+       xtail = xdata + body->mbo_eadatasize;
+       xvtail = xval + body->mbo_aclsize;
 
        CDEBUG(D_CACHE, "caching: xdata=%p xtail=%p\n", xdata, xtail);
 
        ll_xattr_cache_init(lli);
 
-       for (i = 0; i < body->max_mdsize; i++) {
+       for (i = 0; i < body->mbo_max_mdsize; i++) {
                CDEBUG(D_CACHE, "caching [%s]=%.*s\n", xdata, *xsizes, xval);
                /* Perform consistency checks: attr names and vals in pill */
                if (memchr(xdata, 0, xtail - xdata) == NULL) {
@@ -451,6 +461,10 @@ static int ll_xattr_cache_refill(struct inode *inode, struct lookup_intent *oit)
                        CDEBUG(D_CACHE, "not caching %s\n",
                               XATTR_NAME_ACL_ACCESS);
                        rc = 0;
+               } else if (!strcmp(xdata, "security.selinux")) {
+                       /* Filter out security.selinux, it is cached in slab */
+                       CDEBUG(D_CACHE, "not caching security.selinux\n");
+                       rc = 0;
                } else {
                        rc = ll_xattr_cache_add(&lli->lli_xattrs, xdata, xval,
                                                *xsizes);