Whamcloud - gitweb
LU-12296 llite: improve ll_dom_lock_cancel
[fs/lustre-release.git] / lustre / obdclass / cl_object.c
index 333486b..5aa59de 100644 (file)
@@ -23,7 +23,7 @@
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2015, Intel Corporation.
+ * Copyright (c) 2011, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -339,7 +339,7 @@ EXPORT_SYMBOL(cl_object_prune);
  * Get stripe information of this object.
  */
 int cl_object_getstripe(const struct lu_env *env, struct cl_object *obj,
-                       struct lov_user_md __user *uarg)
+                       struct lov_user_md __user *uarg, size_t size)
 {
        struct lu_object_header *top;
        int                     result = 0;
@@ -348,7 +348,8 @@ int cl_object_getstripe(const struct lu_env *env, struct cl_object *obj,
        top = obj->co_lu.lo_header;
        list_for_each_entry(obj, &top->loh_layers, co_lu.lo_linkage) {
                if (obj->co_ops->coo_getstripe != NULL) {
-                       result = obj->co_ops->coo_getstripe(env, obj, uarg);
+                       result = obj->co_ops->coo_getstripe(env, obj, uarg,
+                                                           size);
                        if (result != 0)
                                break;
                }
@@ -421,6 +422,24 @@ loff_t cl_object_maxbytes(struct cl_object *obj)
 }
 EXPORT_SYMBOL(cl_object_maxbytes);
 
+int cl_object_flush(const struct lu_env *env, struct cl_object *obj,
+                        struct ldlm_lock *lock)
+{
+       struct lu_object_header *top = obj->co_lu.lo_header;
+       int rc = 0;
+       ENTRY;
+
+       list_for_each_entry(obj, &top->loh_layers, co_lu.lo_linkage) {
+               if (obj->co_ops->coo_object_flush) {
+                       rc = obj->co_ops->coo_object_flush(env, obj, lock);
+                       if (rc)
+                               break;
+               }
+       }
+       RETURN(rc);
+}
+EXPORT_SYMBOL(cl_object_flush);
+
 /**
  * Helper function removing all object locks, and marking object for
  * deletion. All object pages must have been deleted at this point.
@@ -549,19 +568,16 @@ EXPORT_SYMBOL(cl_site_stats_print);
 
 /**
  * The most efficient way is to store cl_env pointer in task specific
- * structures. On Linux, it wont' be easy to use task_struct->journal_info
- * because Lustre code may call into other fs which has certain assumptions
- * about journal_info. Currently following fields in task_struct are identified
- * can be used for this purpose:
- *  - cl_env: for liblustre.
- *  - tux_info: ony on RedHat kernel.
- *  - ...
+ * structures. On Linux, it isn't easy to use task_struct->journal_info
+ * because Lustre code may call into other fs during memory reclaim, which
+ * has certain assumptions about journal_info. There are not currently any
+ * fields in task_struct that can be used for this purpose.
  * \note As long as we use task_struct to store cl_env, we assume that once
  * called into Lustre, we'll never call into the other part of the kernel
  * which will use those fields in task_struct without explicitly exiting
  * Lustre.
  *
- * If there's no space in task_struct is available, hash will be used.
+ * Since there's no space in task_struct is available, hash will be used.
  * bz20044, bz22683.
  */
 
@@ -594,17 +610,20 @@ struct cl_env {
         void             *ce_debug;
 };
 
+static void cl_env_inc(enum cache_stats_item item)
+{
 #ifdef CONFIG_DEBUG_PAGESTATE_TRACKING
-#define CL_ENV_INC(counter) atomic_inc(&cl_env_stats.cs_stats[CS_##counter])
-
-#define CL_ENV_DEC(counter) do {                                              \
-       LASSERT(atomic_read(&cl_env_stats.cs_stats[CS_##counter]) > 0);   \
-       atomic_dec(&cl_env_stats.cs_stats[CS_##counter]);                 \
-} while (0)
-#else
-#define CL_ENV_INC(counter)
-#define CL_ENV_DEC(counter)
+       atomic_inc(&cl_env_stats.cs_stats[item]);
 #endif
+}
+
+static void cl_env_dec(enum cache_stats_item item)
+{
+#ifdef CONFIG_DEBUG_PAGESTATE_TRACKING
+       LASSERT(atomic_read(&cl_env_stats.cs_stats[item]) > 0);
+       atomic_dec(&cl_env_stats.cs_stats[item]);
+#endif
+}
 
 static void cl_env_init0(struct cl_env *cle, void *debug)
 {
@@ -614,7 +633,7 @@ static void cl_env_init0(struct cl_env *cle, void *debug)
 
        cle->ce_ref = 1;
        cle->ce_debug = debug;
-       CL_ENV_INC(busy);
+       cl_env_inc(CS_busy);
 }
 
 static struct lu_env *cl_env_new(__u32 ctx_tags, __u32 ses_tags, void *debug)
@@ -644,8 +663,8 @@ static struct lu_env *cl_env_new(__u32 ctx_tags, __u32 ses_tags, void *debug)
                        OBD_SLAB_FREE_PTR(cle, cl_env_kmem);
                        env = ERR_PTR(rc);
                } else {
-                       CL_ENV_INC(create);
-                       CL_ENV_INC(total);
+                       cl_env_inc(CS_create);
+                       cl_env_inc(CS_total);
                }
        } else
                env = ERR_PTR(-ENOMEM);
@@ -654,10 +673,10 @@ static struct lu_env *cl_env_new(__u32 ctx_tags, __u32 ses_tags, void *debug)
 
 static void cl_env_fini(struct cl_env *cle)
 {
-        CL_ENV_DEC(total);
-        lu_context_fini(&cle->ce_lu.le_ctx);
-        lu_context_fini(&cle->ce_ses);
-        OBD_SLAB_FREE_PTR(cle, cl_env_kmem);
+       cl_env_dec(CS_total);
+       lu_context_fini(&cle->ce_lu.le_ctx);
+       lu_context_fini(&cle->ce_ses);
+       OBD_SLAB_FREE_PTR(cle, cl_env_kmem);
 }
 
 static struct lu_env *cl_env_obtain(void *debug)
@@ -813,15 +832,15 @@ void cl_env_put(struct lu_env *env, __u16 *refcheck)
         if (--cle->ce_ref == 0) {
                int cpu = get_cpu();
 
-                CL_ENV_DEC(busy);
-                cle->ce_debug = NULL;
-                cl_env_exit(cle);
-                /*
-                 * Don't bother to take a lock here.
-                 *
-                 * Return environment to the cache only when it was allocated
-                 * with the standard tags.
-                 */
+               cl_env_dec(CS_busy);
+               cle->ce_debug = NULL;
+               cl_env_exit(cle);
+               /*
+                * Don't bother to take a lock here.
+                *
+                * Return environment to the cache only when it was allocated
+                * with the standard tags.
+                */
                if (cl_envs[cpu].cec_count < cl_envs_cached_max &&
                    (env->le_ctx.lc_tags & ~LCT_HAS_EXIT) == LCT_CL_THREAD &&
                    (env->le_ses->lc_tags & ~LCT_HAS_EXIT) == LCT_SESSION) {
@@ -843,13 +862,11 @@ EXPORT_SYMBOL(cl_env_put);
  */
 void cl_attr2lvb(struct ost_lvb *lvb, const struct cl_attr *attr)
 {
-        ENTRY;
         lvb->lvb_size   = attr->cat_size;
         lvb->lvb_mtime  = attr->cat_mtime;
         lvb->lvb_atime  = attr->cat_atime;
         lvb->lvb_ctime  = attr->cat_ctime;
         lvb->lvb_blocks = attr->cat_blocks;
-        EXIT;
 }
 
 /**
@@ -859,13 +876,11 @@ void cl_attr2lvb(struct ost_lvb *lvb, const struct cl_attr *attr)
  */
 void cl_lvb2attr(struct cl_attr *attr, const struct ost_lvb *lvb)
 {
-        ENTRY;
         attr->cat_size   = lvb->lvb_size;
         attr->cat_mtime  = lvb->lvb_mtime;
         attr->cat_atime  = lvb->lvb_atime;
         attr->cat_ctime  = lvb->lvb_ctime;
         attr->cat_blocks = lvb->lvb_blocks;
-        EXIT;
 }
 EXPORT_SYMBOL(cl_lvb2attr);
 
@@ -950,7 +965,7 @@ void cl_env_percpu_put(struct lu_env *env)
        cle->ce_ref--;
        LASSERT(cle->ce_ref == 0);
 
-       CL_ENV_DEC(busy);
+       cl_env_dec(CS_busy);
        cle->ce_debug = NULL;
 
        put_cpu();
@@ -1022,20 +1037,8 @@ struct cl_thread_info *cl_env_info(const struct lu_env *env)
         return lu_context_key_get(&env->le_ctx, &cl_key);
 }
 
-/* defines cl0_key_{init,fini}() */
-LU_KEY_INIT_FINI(cl0, struct cl_thread_info);
-
-static void *cl_key_init(const struct lu_context *ctx,
-                         struct lu_context_key *key)
-{
-       return cl0_key_init(ctx, key);
-}
-
-static void cl_key_fini(const struct lu_context *ctx,
-                        struct lu_context_key *key, void *data)
-{
-       cl0_key_fini(ctx, key, data);
-}
+/* defines cl_key_{init,fini}() */
+LU_KEY_INIT_FINI(cl, struct cl_thread_info);
 
 static struct lu_context_key cl_key = {
         .lct_tags = LCT_CL_THREAD,