Whamcloud - gitweb
LU-3365 lmv: support DNE with HSM.
[fs/lustre-release.git] / lustre / fld / fld_handler.c
index 4e4404f..9d6d138 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Whamcloud, Inc.
+ * Copyright (c) 2011, 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 
 #define DEBUG_SUBSYSTEM S_FLD
 
-#ifdef __KERNEL__
-# include <libcfs/libcfs.h>
-# include <linux/module.h>
-# include <linux/jbd.h>
-# include <asm/div64.h>
-#else /* __KERNEL__ */
-# include <liblustre.h>
-# include <libcfs/list.h>
-#endif
+#include <libcfs/libcfs.h>
+#include <linux/module.h>
 
 #include <obd.h>
-#include <obd_class.h>
-#include <lustre_ver.h>
 #include <obd_support.h>
-#include <lprocfs_status.h>
-
-#include <md_object.h>
 #include <lustre_fid.h>
+#include <lustre_fld.h>
+#include <lustre_mdt.h> /* err_serious() */
 #include <lustre_req_layout.h>
+#include <lprocfs_status.h>
 #include "fld_internal.h"
-#include <lustre_fid.h>
-
-#ifdef __KERNEL__
 
 /* context key constructor/destructor: fld_key_init, fld_key_fini */
 LU_KEY_INIT_FINI(fld, struct fld_thread_info);
 
 /* context key: fld_thread_key */
-LU_CONTEXT_KEY_DEFINE(fld, LCT_MD_THREAD|LCT_DT_THREAD);
-
-cfs_proc_dir_entry_t *fld_type_proc_dir = NULL;
+LU_CONTEXT_KEY_DEFINE(fld, LCT_MD_THREAD | LCT_DT_THREAD | LCT_MG_THREAD);
 
-static int __init fld_mod_init(void)
+int fld_server_mod_init(void)
 {
-        fld_type_proc_dir = lprocfs_register(LUSTRE_FLD_NAME,
-                                             proc_lustre_root,
-                                             NULL, NULL);
-        if (IS_ERR(fld_type_proc_dir))
-                return PTR_ERR(fld_type_proc_dir);
-
-        LU_CONTEXT_KEY_INIT(&fld_thread_key);
-        lu_context_key_register(&fld_thread_key);
-        return 0;
+       LU_CONTEXT_KEY_INIT(&fld_thread_key);
+       return lu_context_key_register(&fld_thread_key);
 }
 
-static void __exit fld_mod_exit(void)
+void fld_server_mod_exit(void)
 {
-        lu_context_key_degister(&fld_thread_key);
-        if (fld_type_proc_dir != NULL && !IS_ERR(fld_type_proc_dir)) {
-                lprocfs_remove(&fld_type_proc_dir);
-                fld_type_proc_dir = NULL;
-        }
+       lu_context_key_degister(&fld_thread_key);
 }
 
 int fld_declare_server_create(const struct lu_env *env,
                              struct lu_server_fld *fld,
-                             struct lu_seq_range *range,
+                             const struct lu_seq_range *range,
                              struct thandle *th)
 {
        int rc;
@@ -117,7 +92,7 @@ EXPORT_SYMBOL(fld_declare_server_create);
  * is granted to a server.
  */
 int fld_server_create(const struct lu_env *env, struct lu_server_fld *fld,
-                     struct lu_seq_range *range, struct thandle *th)
+                     const struct lu_seq_range *range, struct thandle *th)
 {
        int rc;
 
@@ -136,36 +111,37 @@ EXPORT_SYMBOL(fld_server_create);
  *  sequence controller node (MDT0). All other MDT[1...N] and client
  *  cache fld entries, but this cache is not persistent.
  */
-
 int fld_server_lookup(const struct lu_env *env, struct lu_server_fld *fld,
                      seqno_t seq, struct lu_seq_range *range)
 {
-        struct lu_seq_range *erange;
-        struct fld_thread_info *info;
-        int rc;
-        ENTRY;
+       struct lu_seq_range *erange;
+       struct fld_thread_info *info;
+       int rc;
+       ENTRY;
 
-        info = lu_context_key_get(&env->le_ctx, &fld_thread_key);
-        erange = &info->fti_lrange;
-
-        /* Lookup it in the cache. */
-        rc = fld_cache_lookup(fld->lsf_cache, seq, erange);
-        if (rc == 0) {
-                if (unlikely(erange->lsr_flags != range->lsr_flags)) {
-                        CERROR("FLD cache found a range "DRANGE" doesn't "
-                               "match the requested flag %x\n",
-                               PRANGE(erange), range->lsr_flags);
-                        RETURN(-EIO);
-                }
-                *range = *erange;
-                RETURN(0);
-        }
+       info = lu_context_key_get(&env->le_ctx, &fld_thread_key);
+       LASSERT(info != NULL);
+       erange = &info->fti_lrange;
+
+       /* Lookup it in the cache. */
+       rc = fld_cache_lookup(fld->lsf_cache, seq, erange);
+       if (rc == 0) {
+               if (unlikely(fld_range_type(erange) != fld_range_type(range) &&
+                            !fld_range_is_any(range))) {
+                       CERROR("%s: FLD cache range "DRANGE" does not match"
+                              "requested flag %x: rc = %d\n", fld->lsf_name,
+                              PRANGE(erange), range->lsr_flags, -EIO);
+                       RETURN(-EIO);
+               }
+               *range = *erange;
+               RETURN(0);
+       }
 
        if (fld->lsf_obj) {
                /* On server side, all entries should be in cache.
                 * If we can not find it in cache, just return error */
-               CERROR("%s: Can not found the seq "LPX64"\n",
-                       fld->lsf_name, seq);
+               CERROR("%s: Cannot find sequence "LPX64": rc = %d\n",
+                      fld->lsf_name, seq, -EIO);
                RETURN(-EIO);
        } else {
                LASSERT(fld->lsf_control_exp);
@@ -173,6 +149,7 @@ int fld_server_lookup(const struct lu_env *env, struct lu_server_fld *fld,
                 * This is temporary solution, long term solution is fld
                 * replication on all mdt servers.
                 */
+               range->lsr_start = seq;
                rc = fld_client_rpc(fld->lsf_control_exp,
                                    range, FLD_LOOKUP);
                if (rc == 0)
@@ -236,20 +213,22 @@ static int fld_req_handle(struct ptlrpc_request *req,
                         RETURN(err_serious(-EPROTO));
                 *out = *in;
 
-                /* For old 2.0 client, the 'lsr_flags' is uninitialized.
-                 * Set it as 'LU_SEQ_RANGE_MDT' by default.
-                 * Old 2.0 liblustre client cannot talk with new 2.1 server. */
-                if (!(exp->exp_connect_flags & OBD_CONNECT_64BITHASH) &&
-                    !exp->exp_libclient)
-                        out->lsr_flags = LU_SEQ_RANGE_MDT;
-
-                rc = fld_server_handle(lu_site2md(site)->ms_server_fld,
-                                       req->rq_svc_thread->t_env,
-                                       *opc, out, info);
-        } else
+               /* For old 2.0 client, the 'lsr_flags' is uninitialized.
+                * Set it as 'LU_SEQ_RANGE_MDT' by default. */
+               if (!(exp_connect_flags(exp) & OBD_CONNECT_64BITHASH) &&
+                   !(exp_connect_flags(exp) & OBD_CONNECT_MDS_MDS) &&
+                   !(exp_connect_flags(exp) & OBD_CONNECT_LIGHTWEIGHT) &&
+                   !exp->exp_libclient)
+                       fld_range_set_mdt(out);
+
+               rc = fld_server_handle(lu_site2seq(site)->ss_server_fld,
+                                      req->rq_svc_thread->t_env,
+                                      *opc, out, info);
+       } else {
                 rc = err_serious(-EPROTO);
+       }
 
-        RETURN(rc);
+       RETURN(rc);
 }
 
 static void fld_thread_info_init(struct ptlrpc_request *req,
@@ -305,26 +284,26 @@ EXPORT_SYMBOL(fld_query);
 int fid_is_local(const struct lu_env *env,
                  struct lu_site *site, const struct lu_fid *fid)
 {
-        int result;
-        struct md_site *msite;
-        struct lu_seq_range *range;
-        struct fld_thread_info *info;
-        ENTRY;
+       int result;
+       struct seq_server_site *ss_site;
+       struct lu_seq_range *range;
+       struct fld_thread_info *info;
+       ENTRY;
 
-        info = lu_context_key_get(&env->le_ctx, &fld_thread_key);
-        range = &info->fti_lrange;
+       info = lu_context_key_get(&env->le_ctx, &fld_thread_key);
+       range = &info->fti_lrange;
 
-        result = 1; /* conservatively assume fid is local */
-        msite = lu_site2md(site);
-        if (msite->ms_client_fld != NULL) {
-                int rc;
+       result = 1; /* conservatively assume fid is local */
+       ss_site = lu_site2seq(site);
+       if (ss_site->ss_client_fld != NULL) {
+               int rc;
 
-                rc = fld_cache_lookup(msite->ms_client_fld->lcf_cache,
-                                      fid_seq(fid), range);
-                if (rc == 0)
-                        result = (range->lsr_index == msite->ms_node_id);
-        }
-        return result;
+               rc = fld_cache_lookup(ss_site->ss_client_fld->lcf_cache,
+                                     fid_seq(fid), range);
+               if (rc == 0)
+                       result = (range->lsr_index == ss_site->ss_node_id);
+       }
+       return result;
 }
 EXPORT_SYMBOL(fid_is_local);
 
@@ -377,12 +356,12 @@ static void fld_server_proc_fini(struct lu_server_fld *fld)
 #endif
 
 int fld_server_init(const struct lu_env *env, struct lu_server_fld *fld,
-                   struct dt_device *dt, const char *prefix, int mds_node_id)
+                   struct dt_device *dt, const char *prefix, int mds_node_id,
+                   int type)
 {
-        int cache_size, cache_threshold;
-        struct lu_seq_range range;
-        int rc;
-        ENTRY;
+       int cache_size, cache_threshold;
+       int rc;
+       ENTRY;
 
         snprintf(fld->lsf_name, sizeof(fld->lsf_name),
                  "srv-%s", prefix);
@@ -402,12 +381,13 @@ int fld_server_init(const struct lu_env *env, struct lu_server_fld *fld,
                 GOTO(out, rc);
         }
 
-        if (!mds_node_id) {
+       if (!mds_node_id && type == LU_SEQ_RANGE_MDT) {
                rc = fld_index_init(env, fld, dt);
                 if (rc)
                         GOTO(out, rc);
-        } else
+        } else {
                 fld->lsf_obj = NULL;
+       }
 
         rc = fld_server_proc_init(fld);
         if (rc)
@@ -415,14 +395,8 @@ int fld_server_init(const struct lu_env *env, struct lu_server_fld *fld,
 
         fld->lsf_control_exp = NULL;
 
-        /* Insert reserved sequence number of ".lustre" into fld cache. */
-        range.lsr_start = FID_SEQ_DOT_LUSTRE;
-        range.lsr_end = FID_SEQ_DOT_LUSTRE + 1;
-        range.lsr_index = 0;
-        range.lsr_flags = LU_SEQ_RANGE_MDT;
-       fld_cache_insert(fld->lsf_cache, &range);
+       GOTO(out, rc);
 
-        EXIT;
 out:
        if (rc)
                fld_server_fini(env, fld);
@@ -446,10 +420,3 @@ void fld_server_fini(const struct lu_env *env, struct lu_server_fld *fld)
        EXIT;
 }
 EXPORT_SYMBOL(fld_server_fini);
-
-MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
-MODULE_DESCRIPTION("Lustre FLD");
-MODULE_LICENSE("GPL");
-
-cfs_module(mdd, "0.1.0", fld_mod_init, fld_mod_exit);
-#endif