Whamcloud - gitweb
LU-5823 clio: add coo_obd_info_get and coo_data_version
[fs/lustre-release.git] / lustre / obdclass / cl_object.c
index de52f90..b003952 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2013, Intel Corporation.
+ * Copyright (c) 2011, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -58,6 +58,7 @@
 #include <libcfs/list.h>
 #include <libcfs/libcfs_hash.h> /* for cfs_hash stuff */
 #include <cl_object.h>
+#include <lu_object.h>
 #include "cl_internal.h"
 
 static struct kmem_cache *cl_env_kmem;
@@ -65,8 +66,6 @@ static struct kmem_cache *cl_env_kmem;
 /** Lock class of cl_object_header::coh_attr_guard */
 static struct lock_class_key cl_attr_guard_class;
 
-extern __u32 lu_context_tags_default;
-extern __u32 lu_session_tags_default;
 /**
  * Initialize cl_object_header.
  */
@@ -92,7 +91,6 @@ void cl_object_header_fini(struct cl_object_header *h)
 {
         lu_object_header_fini(&h->coh_lu);
 }
-EXPORT_SYMBOL(cl_object_header_fini);
 
 /**
  * Returns a cl_object with a given \a fid.
@@ -177,7 +175,7 @@ static spinlock_t *cl_object_attr_guard(struct cl_object *o)
  *
  * Prevents data-attributes from changing, until lock is released by
  * cl_object_attr_unlock(). This has to be called before calls to
- * cl_object_attr_get(), cl_object_attr_set().
+ * cl_object_attr_get(), cl_object_attr_update().
  */
 void cl_object_attr_lock(struct cl_object *o)
 __acquires(cl_object_attr_guard(o))
@@ -204,7 +202,7 @@ EXPORT_SYMBOL(cl_object_attr_unlock);
  * for.
  */
 int cl_object_attr_get(const struct lu_env *env, struct cl_object *obj,
-                       struct cl_attr *attr)
+                       struct cl_attr *attr)
 {
        struct lu_object_header *top;
        int result;
@@ -212,19 +210,19 @@ int cl_object_attr_get(const struct lu_env *env, struct cl_object *obj,
        assert_spin_locked(cl_object_attr_guard(obj));
        ENTRY;
 
-        top = obj->co_lu.lo_header;
-        result = 0;
+       top = obj->co_lu.lo_header;
+       result = 0;
        list_for_each_entry(obj, &top->loh_layers, co_lu.lo_linkage) {
-                if (obj->co_ops->coo_attr_get != NULL) {
-                        result = obj->co_ops->coo_attr_get(env, obj, attr);
-                        if (result != 0) {
-                                if (result > 0)
-                                        result = 0;
-                                break;
-                        }
-                }
-        }
-        RETURN(result);
+               if (obj->co_ops->coo_attr_get != NULL) {
+                       result = obj->co_ops->coo_attr_get(env, obj, attr);
+                       if (result != 0) {
+                               if (result > 0)
+                                       result = 0;
+                               break;
+                       }
+               }
+       }
+       RETURN(result);
 }
 EXPORT_SYMBOL(cl_object_attr_get);
 
@@ -232,11 +230,11 @@ EXPORT_SYMBOL(cl_object_attr_get);
  * Updates data-attributes of an object \a obj.
  *
  * Only attributes, mentioned in a validness bit-mask \a v are
- * updated. Calls cl_object_operations::coo_attr_set() on every layer, bottom
+ * updated. Calls cl_object_operations::coo_upd_attr() on every layer, bottom
  * to top.
  */
-int cl_object_attr_set(const struct lu_env *env, struct cl_object *obj,
-                       const struct cl_attr *attr, unsigned v)
+int cl_object_attr_update(const struct lu_env *env, struct cl_object *obj,
+                         const struct cl_attr *attr, unsigned v)
 {
        struct lu_object_header *top;
        int result;
@@ -247,8 +245,9 @@ int cl_object_attr_set(const struct lu_env *env, struct cl_object *obj,
        top = obj->co_lu.lo_header;
        result = 0;
        list_for_each_entry_reverse(obj, &top->loh_layers, co_lu.lo_linkage) {
-               if (obj->co_ops->coo_attr_set != NULL) {
-                       result = obj->co_ops->coo_attr_set(env, obj, attr, v);
+               if (obj->co_ops->coo_attr_update != NULL) {
+                       result = obj->co_ops->coo_attr_update(env, obj, attr,
+                                                             v);
                        if (result != 0) {
                                if (result > 0)
                                        result = 0;
@@ -258,7 +257,7 @@ int cl_object_attr_set(const struct lu_env *env, struct cl_object *obj,
        }
        RETURN(result);
 }
-EXPORT_SYMBOL(cl_object_attr_set);
+EXPORT_SYMBOL(cl_object_attr_update);
 
 /**
  * Notifies layers (bottom-to-top) that glimpse AST was received.
@@ -341,6 +340,126 @@ int cl_object_prune(const struct lu_env *env, struct cl_object *obj)
 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 lu_object_header *top;
+       int                     result = 0;
+       ENTRY;
+
+       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);
+                       if (result != 0)
+                               break;
+               }
+       }
+       RETURN(result);
+}
+EXPORT_SYMBOL(cl_object_getstripe);
+
+/**
+ * Find whether there is any callback data (ldlm lock) attached upon this
+ * object.
+ */
+int cl_object_find_cbdata(const struct lu_env *env, struct cl_object *obj,
+                          ldlm_iterator_t iter, void *data)
+{
+       struct lu_object_header *top;
+       int                     result = 0;
+       ENTRY;
+
+       top = obj->co_lu.lo_header;
+       list_for_each_entry(obj, &top->loh_layers, co_lu.lo_linkage) {
+               if (obj->co_ops->coo_find_cbdata != NULL) {
+                       result = obj->co_ops->coo_find_cbdata(env, obj, iter,
+                                                             data);
+                       if (result != 0)
+                               break;
+               }
+       }
+       RETURN(result);
+}
+EXPORT_SYMBOL(cl_object_find_cbdata);
+
+/**
+ * Get fiemap extents from file object.
+ *
+ * \param env [in]     lustre environment
+ * \param obj [in]     file object
+ * \param key [in]     fiemap request argument
+ * \param fiemap [out] fiemap extents mapping retrived
+ * \param buflen [in]  max buffer length of @fiemap
+ *
+ * \retval 0   success
+ * \retval < 0 error
+ */
+int cl_object_fiemap(const struct lu_env *env, struct cl_object *obj,
+                    struct ll_fiemap_info_key *key,
+                    struct fiemap *fiemap, size_t *buflen)
+{
+       struct lu_object_header *top;
+       int                     result = 0;
+       ENTRY;
+
+       top = obj->co_lu.lo_header;
+       list_for_each_entry(obj, &top->loh_layers, co_lu.lo_linkage) {
+               if (obj->co_ops->coo_fiemap != NULL) {
+                       result = obj->co_ops->coo_fiemap(env, obj, key, fiemap,
+                                                        buflen);
+                       if (result != 0)
+                               break;
+               }
+       }
+       RETURN(result);
+}
+EXPORT_SYMBOL(cl_object_fiemap);
+
+int cl_object_obd_info_get(const struct lu_env *env, struct cl_object *obj,
+                          struct obd_info *oinfo,
+                          struct ptlrpc_request_set *set)
+{
+       struct lu_object_header *top;
+       int                     result = 0;
+       ENTRY;
+
+       top = obj->co_lu.lo_header;
+       list_for_each_entry(obj, &top->loh_layers, co_lu.lo_linkage) {
+               if (obj->co_ops->coo_obd_info_get != NULL) {
+                       result = obj->co_ops->coo_obd_info_get(env, obj, oinfo,
+                                                              set);
+                       if (result != 0)
+                               break;
+               }
+       }
+       RETURN(result);
+}
+EXPORT_SYMBOL(cl_object_obd_info_get);
+
+int cl_object_data_version(const struct lu_env *env, struct cl_object *obj,
+                          __u64 *data_version, int flags)
+{
+       struct lu_object_header *top;
+       int                     result = 0;
+       ENTRY;
+
+       top = obj->co_lu.lo_header;
+       list_for_each_entry(obj, &top->loh_layers, co_lu.lo_linkage) {
+               if (obj->co_ops->coo_data_version != NULL) {
+                       result = obj->co_ops->coo_data_version(env, obj,
+                                                       data_version, flags);
+                       if (result != 0)
+                               break;
+               }
+       }
+       RETURN(result);
+}
+EXPORT_SYMBOL(cl_object_data_version);
+
+/**
  * Helper function removing all object locks, and marking object for
  * deletion. All object pages must have been deleted at this point.
  *
@@ -364,7 +483,8 @@ void cache_stats_init(struct cache_stats *cs, const char *name)
                atomic_set(&cs->cs_stats[i], 0);
 }
 
-int cache_stats_print(const struct cache_stats *cs, struct seq_file *m, int h)
+static int cache_stats_print(const struct cache_stats *cs,
+                            struct seq_file *m, int h)
 {
        int i;
 
@@ -397,7 +517,7 @@ static void cl_env_percpu_refill(void);
  */
 int cl_site_init(struct cl_site *s, struct cl_device *d)
 {
-        int i;
+       size_t i;
         int result;
 
         result = lu_site_init(&s->cs_lu, &d->cd_lu_dev);
@@ -438,7 +558,7 @@ int cl_site_stats_print(const struct cl_site *site, struct seq_file *m)
                [CPS_PAGEIN]    = "r",
                [CPS_FREEING]   = "f"
        };
-       int i;
+       size_t i;
 
 /*
        lookup    hit  total   busy create
@@ -803,7 +923,6 @@ struct lu_env *cl_env_peek(int *refcheck)
         CDEBUG(D_OTHER, "%d@%p\n", cle ? cle->ce_ref : 0, cle);
         return env;
 }
-EXPORT_SYMBOL(cl_env_peek);
 
 /**
  * Returns lu_env: if there already is an environment associated with the
@@ -1038,7 +1157,6 @@ void cl_attr2lvb(struct ost_lvb *lvb, const struct cl_attr *attr)
         lvb->lvb_blocks = attr->cat_blocks;
         EXIT;
 }
-EXPORT_SYMBOL(cl_attr2lvb);
 
 /**
  * Converts struct ost_lvb to struct cl_attr.
@@ -1218,7 +1336,7 @@ static void *cl_key_init(const struct lu_context *ctx,
 
         info = cl0_key_init(ctx, key);
         if (!IS_ERR(info)) {
-                int i;
+               size_t i;
 
                 for (i = 0; i < ARRAY_SIZE(info->clt_counters); ++i)
                         lu_ref_init(&info->clt_counters[i].ctc_locks_locked);
@@ -1229,8 +1347,8 @@ static void *cl_key_init(const struct lu_context *ctx,
 static void cl_key_fini(const struct lu_context *ctx,
                         struct lu_context_key *key, void *data)
 {
-        struct cl_thread_info *info;
-        int i;
+       struct cl_thread_info *info;
+       size_t i;
 
         info = data;
         for (i = 0; i < ARRAY_SIZE(info->clt_counters); ++i)
@@ -1241,8 +1359,8 @@ static void cl_key_fini(const struct lu_context *ctx,
 static void cl_key_exit(const struct lu_context *ctx,
                         struct lu_context_key *key, void *data)
 {
-        struct cl_thread_info *info = data;
-        int i;
+       struct cl_thread_info *info = data;
+       size_t i;
 
         for (i = 0; i < ARRAY_SIZE(info->clt_counters); ++i) {
                 LASSERT(info->clt_counters[i].ctc_nr_held == 0);