Whamcloud - gitweb
LU-1301 mgs: lu device for mgs
[fs/lustre-release.git] / lustre / mgs / mgs_nids.c
index 794ee9e..b23748f 100644 (file)
 #define D_MGS D_CONFIG
 
 #ifdef __KERNEL__
-#include <linux/module.h>
 #include <linux/pagemap.h>
-#include <linux/fs.h>
 #endif
 
 #include <obd.h>
-#include <obd_lov.h>
 #include <obd_class.h>
-#include <lustre_log.h>
-#include <obd_ost.h>
-#include <libcfs/list.h>
-#include <linux/lvfs.h>
 #include <lustre_fsfilt.h>
 #include <lustre_disk.h>
-#include <lustre_param.h>
+
 #include "mgs_internal.h"
 
 static unsigned int ir_timeout;
@@ -86,7 +79,7 @@ static int nidtbl_is_sane(struct mgs_nidtbl *tbl)
  * nidtbl entries will be packed in @pages by @unit_size units - entries
  * shouldn't cross unit boundaries.
  */
-static int mgs_nidtbl_read(struct obd_device *unused, struct mgs_nidtbl *tbl,
+static int mgs_nidtbl_read(struct obd_export *exp, struct mgs_nidtbl *tbl,
                            struct mgs_config_res *res, cfs_page_t **pages,
                            int nrpages, int units_total, int unit_size)
 {
@@ -146,10 +139,16 @@ static int mgs_nidtbl_read(struct obd_device *unused, struct mgs_nidtbl *tbl,
 
                         /* check if we need to consume remaining bytes. */
                         if (last_in_unit != NULL && bytes_in_unit) {
-                                /* entry has been swapped. */
-                                __swab32s(&last_in_unit->mne_length);
-                                last_in_unit->mne_length += bytes_in_unit;
-                                __swab32s(&last_in_unit->mne_length);
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 6, 50, 0)
+                               /* May need to swab back to update the length.*/
+                               if (exp->exp_need_mne_swab)
+                                       lustre_swab_mgs_nidtbl_entry(last_in_unit);
+#endif
+                               last_in_unit->mne_length += bytes_in_unit;
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 6, 50, 0)
+                               if (exp->exp_need_mne_swab)
+                                       lustre_swab_mgs_nidtbl_entry(last_in_unit);
+#endif
                                 rc  += bytes_in_unit;
                                 buf += bytes_in_unit;
                                 last_in_unit = NULL;
@@ -195,7 +194,12 @@ static int mgs_nidtbl_read(struct obd_device *unused, struct mgs_nidtbl *tbl,
                 entry->mne_nid_count = mti->mti_nid_count;
                 memcpy(entry->u.nids, mti->mti_nids,
                        mti->mti_nid_count * sizeof(lnet_nid_t));
-                lustre_swab_mgs_nidtbl_entry(entry);
+
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 6, 50, 0)
+               /* For LU-1644, swab entry for 2.2 clients. */
+               if (exp->exp_need_mne_swab)
+                       lustre_swab_mgs_nidtbl_entry(entry);
+#endif
 
                 version = tgt->mnt_version;
                 rc     += entry_len;
@@ -222,7 +226,9 @@ out:
         RETURN(rc);
 }
 
-static int nidtbl_update_version(struct obd_device *obd, struct mgs_nidtbl *tbl)
+static int nidtbl_update_version(const struct lu_env *env,
+                                struct mgs_device *mgs,
+                                struct mgs_nidtbl *tbl)
 {
         struct lvfs_run_ctxt saved;
         struct file         *file = NULL;
@@ -230,6 +236,7 @@ static int nidtbl_update_version(struct obd_device *obd, struct mgs_nidtbl *tbl)
         u64                  version;
         loff_t               off = 0;
         int                  rc;
+       struct obd_device   *obd = tbl->mn_fsdb->fsdb_obd;
         ENTRY;
 
         LASSERT(cfs_mutex_is_locked(&tbl->mn_lock));
@@ -247,7 +254,7 @@ static int nidtbl_update_version(struct obd_device *obd, struct mgs_nidtbl *tbl)
                 if (rc == sizeof(version))
                         rc = 0;
                 filp_close(file, 0);
-                fsfilt_sync(obd, obd->u.mgs.mgs_sb);
+               dt_sync(env, mgs->mgs_bottom);
         } else {
                 rc = PTR_ERR(file);
         }
@@ -258,7 +265,8 @@ static int nidtbl_update_version(struct obd_device *obd, struct mgs_nidtbl *tbl)
 
 #define MGS_NIDTBL_VERSION_INIT 2
 
-static int nidtbl_read_version(struct obd_device *obd, struct mgs_nidtbl *tbl)
+static int nidtbl_read_version(const struct lu_env *env,
+                              struct mgs_device *mgs, struct mgs_nidtbl *tbl)
 {
         struct lvfs_run_ctxt saved;
         struct file         *file = NULL;
@@ -266,6 +274,7 @@ static int nidtbl_read_version(struct obd_device *obd, struct mgs_nidtbl *tbl)
         u64                  version;
         loff_t               off = 0;
         int                  rc;
+       struct obd_device   *obd = tbl->mn_fsdb->fsdb_obd;
         ENTRY;
 
         LASSERT(cfs_mutex_is_locked(&tbl->mn_lock));
@@ -296,7 +305,8 @@ static int nidtbl_read_version(struct obd_device *obd, struct mgs_nidtbl *tbl)
         RETURN(rc);
 }
 
-static int mgs_nidtbl_write(struct fs_db *fsdb, struct mgs_target_info *mti)
+static int mgs_nidtbl_write(const struct lu_env *env, struct fs_db *fsdb,
+                           struct mgs_target_info *mti)
 {
         struct mgs_nidtbl        *tbl;
         struct mgs_nidtbl_target *tgt;
@@ -336,7 +346,7 @@ static int mgs_nidtbl_write(struct fs_db *fsdb, struct mgs_target_info *mti)
 
         cfs_list_move_tail(&tgt->mnt_list, &tbl->mn_targets);
 
-        rc = nidtbl_update_version(fsdb->fsdb_obd, tbl);
+       rc = nidtbl_update_version(env, fsdb->fsdb_mgs, tbl);
         EXIT;
 
 out:
@@ -365,7 +375,7 @@ static void mgs_nidtbl_fini_fs(struct fs_db *fsdb)
         }
 }
 
-static int mgs_nidtbl_init_fs(struct fs_db *fsdb)
+static int mgs_nidtbl_init_fs(const struct lu_env *env, struct fs_db *fsdb)
 {
         struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
 
@@ -374,7 +384,7 @@ static int mgs_nidtbl_init_fs(struct fs_db *fsdb)
         tbl->mn_nr_targets = 0;
         tbl->mn_fsdb = fsdb;
         cfs_mutex_lock(&tbl->mn_lock);
-        tbl->mn_version = nidtbl_read_version(fsdb->fsdb_obd, tbl);
+       tbl->mn_version = nidtbl_read_version(env, fsdb->fsdb_mgs, tbl);
         cfs_mutex_unlock(&tbl->mn_lock);
         CDEBUG(D_MGS, "IR: current version is %llu\n", tbl->mn_version);
 
@@ -431,16 +441,16 @@ static int mgs_ir_notify(void *arg)
                        name, cfs_atomic_read(&fsdb->fsdb_notify_phase));
 
                 fsdb->fsdb_notify_start = cfs_time_current();
-                mgs_revoke_lock(fsdb->fsdb_obd, fsdb, CONFIG_T_RECOVER);
+               mgs_revoke_lock(fsdb->fsdb_mgs, fsdb, CONFIG_T_RECOVER);
         }
 
         cfs_complete(&fsdb->fsdb_notify_comp);
         return 0;
 }
 
-int mgs_ir_init_fs(struct obd_device *obd, struct fs_db *fsdb)
+int mgs_ir_init_fs(const struct lu_env *env, struct mgs_device *mgs,
+                  struct fs_db *fsdb)
 {
-        struct mgs_obd *mgs = &obd->u.mgs;
         int rc;
 
         if (!ir_timeout)
@@ -454,7 +464,8 @@ int mgs_ir_init_fs(struct obd_device *obd, struct fs_db *fsdb)
         CFS_INIT_LIST_HEAD(&fsdb->fsdb_clients);
 
         /* start notify thread */
-        fsdb->fsdb_obd = obd;
+       fsdb->fsdb_obd = mgs->mgs_obd;
+       fsdb->fsdb_mgs = mgs;
         cfs_atomic_set(&fsdb->fsdb_notify_phase, 0);
         cfs_waitq_init(&fsdb->fsdb_notify_waitq);
         cfs_init_completion(&fsdb->fsdb_notify_comp);
@@ -464,11 +475,11 @@ int mgs_ir_init_fs(struct obd_device *obd, struct fs_db *fsdb)
         else
                 CERROR("Start notify thread error %d\n", rc);
 
-        mgs_nidtbl_init_fs(fsdb);
+       mgs_nidtbl_init_fs(env, fsdb);
         return 0;
 }
 
-void mgs_ir_fini_fs(struct obd_device *obd, struct fs_db *fsdb)
+void mgs_ir_fini_fs(struct mgs_device *mgs, struct fs_db *fsdb)
 {
         if (cfs_test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags))
                 return;
@@ -487,10 +498,8 @@ void mgs_ir_fini_fs(struct obd_device *obd, struct fs_db *fsdb)
 /* caller must have held fsdb_mutex */
 static inline void ir_state_graduate(struct fs_db *fsdb)
 {
-        struct mgs_obd *mgs = &fsdb->fsdb_obd->u.mgs;
-
         if (fsdb->fsdb_ir_state == IR_STARTUP) {
-                if (cfs_time_before(mgs->mgs_start_time + ir_timeout,
+               if (cfs_time_before(fsdb->fsdb_mgs->mgs_start_time + ir_timeout,
                                     cfs_time_current_sec())) {
                         fsdb->fsdb_ir_state = IR_FULL;
                         if (fsdb->fsdb_nonir_clients)
@@ -499,7 +508,8 @@ static inline void ir_state_graduate(struct fs_db *fsdb)
         }
 }
 
-int mgs_ir_update(struct obd_device *obd, struct mgs_target_info *mti)
+int mgs_ir_update(const struct lu_env *env, struct mgs_device *mgs,
+                 struct mgs_target_info *mti)
 {
         struct fs_db *fsdb;
         bool notify = true;
@@ -508,11 +518,11 @@ int mgs_ir_update(struct obd_device *obd, struct mgs_target_info *mti)
         if (mti->mti_instance == 0)
                 return -EINVAL;
 
-        rc = mgs_find_or_make_fsdb(obd, mti->mti_fsname, &fsdb);
+       rc = mgs_find_or_make_fsdb(env, mgs, mti->mti_fsname, &fsdb);
         if (rc)
                 return rc;
 
-        rc = mgs_nidtbl_write(fsdb, mti);
+       rc = mgs_nidtbl_write(env, fsdb, mti);
         if (rc)
                 return rc;
 
@@ -582,7 +592,8 @@ static int delogname(char *logname, char *fsname, int *typ)
 
 int mgs_get_ir_logs(struct ptlrpc_request *req)
 {
-        struct obd_device *obd = req->rq_export->exp_obd;
+       struct lu_env     *env = req->rq_svc_thread->t_env;
+       struct mgs_device *mgs = exp2mgs_dev(req->rq_export);
         struct fs_db      *fsdb;
         struct mgs_config_body  *body;
         struct mgs_config_res   *res;
@@ -591,7 +602,6 @@ int mgs_get_ir_logs(struct ptlrpc_request *req)
         char               fsname[16];
         long               bufsize;
         int                unit_size;
-
         int                type;
         int                rc = 0;
         int                i;
@@ -612,9 +622,9 @@ int mgs_get_ir_logs(struct ptlrpc_request *req)
         if (rc)
                 RETURN(rc);
 
-        rc = mgs_find_or_make_fsdb(obd, fsname, &fsdb);
+       rc = mgs_find_or_make_fsdb(env, mgs, fsname, &fsdb);
         if (rc)
-                GOTO(out, rc);
+               RETURN(rc);
 
         bufsize = body->mcb_units << body->mcb_bits;
         nrpages = (bufsize + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
@@ -638,8 +648,8 @@ int mgs_get_ir_logs(struct ptlrpc_request *req)
 
         res->mcr_offset = body->mcb_offset;
         unit_size = min_t(int, 1 << body->mcb_bits, CFS_PAGE_SIZE);
-        bytes = mgs_nidtbl_read(obd, &fsdb->fsdb_nidtbl, res, pages, nrpages,
-                                bufsize / unit_size, unit_size);
+       bytes = mgs_nidtbl_read(req->rq_export, &fsdb->fsdb_nidtbl, res,
+                               pages, nrpages, bufsize / unit_size, unit_size);
         if (bytes < 0)
                 GOTO(out, rc = bytes);
 
@@ -829,10 +839,11 @@ int lprocfs_wr_ir_timeout(struct file *file, const char *buffer,
 
 /* --------------- Handle non IR support clients --------------- */
 /* attach a lustre file system to an export */
-int mgs_fsc_attach(struct obd_export *exp, char *fsname)
+int mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
+                  char *fsname)
 {
         struct mgs_export_data *data = &exp->u.eu_mgs_data;
-        struct obd_device *obd       = exp->exp_obd;
+       struct mgs_device *mgs = exp2mgs_dev(exp);
         struct fs_db      *fsdb;
         struct mgs_fsc    *fsc     = NULL;
         struct mgs_fsc    *new_fsc = NULL;
@@ -840,7 +851,7 @@ int mgs_fsc_attach(struct obd_export *exp, char *fsname)
         int                rc;
         ENTRY;
 
-        rc = mgs_find_or_make_fsdb(obd, fsname, &fsdb);
+       rc = mgs_find_or_make_fsdb(env, mgs, fsname, &fsdb);
         if (rc)
                 RETURN(rc);