Whamcloud - gitweb
LU-1302 llog: pass lu_env as parametr in llog functions
[fs/lustre-release.git] / lustre / mgc / mgc_request.c
index a628354..6364022 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -29,8 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011 Whamcloud, Inc.
- *
+ * Copyright (c) 2011, Whamcloud, Inc.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -41,9 +38,6 @@
  * Author: Nathan Rutman <nathan@clusterfs.com>
  */
 
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
 #define DEBUG_SUBSYSTEM S_MGC
 #define D_MGC D_CONFIG /*|D_WARNING*/
 
@@ -123,7 +117,7 @@ int mgc_logname2resid(char *logname, struct ldlm_res_id *res_id, int type)
 
 /********************** config llog list **********************/
 static CFS_LIST_HEAD(config_llog_list);
-static cfs_spinlock_t config_list_lock = CFS_SPIN_LOCK_UNLOCKED;
+static DEFINE_SPINLOCK(config_list_lock);
 
 /* Take a reference to a config log */
 static int config_log_get(struct config_llog_data *cld)
@@ -351,7 +345,7 @@ static int config_log_add(struct obd_device *obd, char *logname,
         RETURN(0);
 }
 
-CFS_DECLARE_MUTEX(llog_process_lock);
+CFS_DEFINE_MUTEX(llog_process_lock);
 
 /** Stop watching for updates on this log.
  */
@@ -424,7 +418,7 @@ int lprocfs_mgc_rd_ir_state(char *page, char **start, off_t off,
         ENTRY;
 
         rc = snprintf(page, count, "imperative_recovery: %s\n",
-                      OCD_HAS_FLAG(ocd, IMP_RECOV) ? "ON" : "OFF");
+                     OCD_HAS_FLAG(ocd, IMP_RECOV) ? "ENABLED" : "DISABLED");
         rc += snprintf(page + rc, count - rc, "client_state:\n");
 
         cfs_spin_lock(&config_list_lock);
@@ -634,7 +628,9 @@ static int mgc_fs_setup(struct obd_device *obd, struct super_block *sb,
         }
 
         cli->cl_mgc_vfsmnt = mnt;
-        fsfilt_setup(obd, mnt->mnt_sb);
+        err = fsfilt_setup(obd, mnt->mnt_sb);
+        if (err)
+                GOTO(err_ops, err);
 
         OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
         obd->obd_lvfs_ctxt.pwdmnt = mnt;
@@ -1004,9 +1000,9 @@ static int mgc_target_register(struct obd_export *exp,
         RETURN(rc);
 }
 
-int mgc_set_info_async(struct obd_export *exp, obd_count keylen,
-                       void *key, obd_count vallen, void *val,
-                       struct ptlrpc_request_set *set)
+int mgc_set_info_async(const struct lu_env *env, struct obd_export *exp,
+                       obd_count keylen, void *key, obd_count vallen,
+                       void *val, struct ptlrpc_request_set *set)
 {
         int rc = -EINVAL;
         ENTRY;
@@ -1115,8 +1111,9 @@ int mgc_set_info_async(struct obd_export *exp, obd_count keylen,
         RETURN(rc);
 }
 
-static int mgc_get_info(struct obd_export *exp, __u32 keylen, void *key,
-                        __u32 *vallen, void *val, struct lov_stripe_md *unused)
+static int mgc_get_info(const struct lu_env *env, struct obd_export *exp,
+                        __u32 keylen, void *key, __u32 *vallen, void *val,
+                        struct lov_stripe_md *unused)
 {
         int rc = -EINVAL;
 
@@ -1232,9 +1229,9 @@ enum {
 };
 
 static int mgc_apply_recover_logs(struct obd_device *mgc,
-                                  struct config_llog_data *cld,
-                                  __u64 max_version,
-                                  void *data, int datalen)
+                                 struct config_llog_data *cld,
+                                 __u64 max_version,
+                                 void *data, int datalen, bool mne_swab)
 {
         struct config_llog_instance *cfg = &cld->cld_cfg;
         struct lustre_sb_info       *lsi = s2lsi(cfg->cfg_sb);
@@ -1295,10 +1292,16 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
                 if (datalen < entry_len) /* must have entry_len at least */
                         break;
 
-                lustre_swab_mgs_nidtbl_entry(entry);
-                LASSERT(entry->mne_length <= CFS_PAGE_SIZE);
-                if (entry->mne_length < entry_len)
-                        break;
+               /* Keep this swab for normal mixed endian handling. LU-1644 */
+               if (mne_swab)
+                       lustre_swab_mgs_nidtbl_entry(entry);
+               if (entry->mne_length > CFS_PAGE_SIZE) {
+                       CERROR("MNE too large (%u)\n", entry->mne_length);
+                       break;
+               }
+
+               if (entry->mne_length < entry_len)
+                       break;
 
                 off     += entry->mne_length;
                 datalen -= entry->mne_length;
@@ -1420,6 +1423,7 @@ static int mgc_process_recover_log(struct obd_device *obd,
         cfs_page_t **pages;
         int nrpages;
         bool eof = true;
+       bool mne_swab = false;
         int i;
         int ealen;
         int rc;
@@ -1506,13 +1510,24 @@ again:
                 GOTO(out, rc);
         }
 
+       mne_swab = !!ptlrpc_rep_need_swab(req);
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 6, 50, 0)
+       /* This import flag means the server did an extra swab of IR MNE
+        * records (fixed in LU-1252), reverse it here if needed. LU-1644 */
+       if (unlikely(req->rq_import->imp_need_mne_swab))
+               mne_swab = !mne_swab;
+#else
+#warning "LU-1644: Remove old OBD_CONNECT_MNE_SWAB fixup and exp_need_mne_swab"
+#endif
+
         for (i = 0; i < nrpages && ealen > 0; i++) {
                 int rc2;
                 void *ptr;
 
                 ptr = cfs_kmap(pages[i]);
                 rc2 = mgc_apply_recover_logs(obd, cld, res->mcr_offset, ptr,
-                                             min_t(int, ealen, CFS_PAGE_SIZE));
+                                            min_t(int, ealen, CFS_PAGE_SIZE),
+                                            mne_swab);
                 cfs_kunmap(pages[i]);
                 if (rc2 < 0) {
                         CWARN("Process recover log %s error %d\n",
@@ -1543,26 +1558,26 @@ out:
 
 /* identical to mgs_log_is_empty */
 static int mgc_llog_is_empty(struct obd_device *obd, struct llog_ctxt *ctxt,
-                            char *name)
+                            char *name)
 {
-        struct lvfs_run_ctxt saved;
-        struct llog_handle *llh;
-        int rc = 0;
-
-        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-        rc = llog_create(ctxt, &llh, NULL, name);
-        if (rc == 0) {
-                llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
-                rc = llog_get_size(llh);
-                llog_close(llh);
-        }
-        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-        /* header is record 1 */
-        return(rc <= 1);
+       struct lvfs_run_ctxt     saved;
+       struct llog_handle      *llh;
+       int                      rc = 0;
+
+       push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+       rc = llog_create(NULL, ctxt, &llh, NULL, name);
+       if (rc == 0) {
+               llog_init_handle(NULL, llh, LLOG_F_IS_PLAIN, NULL);
+               rc = llog_get_size(llh);
+               llog_close(NULL, llh);
+       }
+       pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+       /* header is record 1 */
+       return (rc <= 1);
 }
 
-static int mgc_copy_handler(struct llog_handle *llh, struct llog_rec_hdr *rec,
-                            void *data)
+static int mgc_copy_handler(const struct lu_env *env, struct llog_handle *llh,
+                           struct llog_rec_hdr *rec, void *data)
 {
         struct llog_rec_hdr local_rec = *rec;
         struct llog_handle *local_llh = (struct llog_handle *)data;
@@ -1573,7 +1588,7 @@ static int mgc_copy_handler(struct llog_handle *llh, struct llog_rec_hdr *rec,
 
         /* Append all records */
         local_rec.lrh_len -= sizeof(*rec) + sizeof(struct llog_rec_tail);
-        rc = llog_write_rec(local_llh, &local_rec, NULL, 0,
+       rc = llog_write_rec(env, local_llh, &local_rec, NULL, 0,
                             (void *)cfg_buf, -1);
 
         lcfg = (struct lustre_cfg *)cfg_buf;
@@ -1603,47 +1618,48 @@ static int mgc_copy_llog(struct obd_device *obd, struct llog_ctxt *rctxt,
         sprintf(temp_log, "%sT", logname);
 
         /* Make sure there's no old temp log */
-        rc = llog_create(lctxt, &local_llh, NULL, temp_log);
-        if (rc)
-                GOTO(out, rc);
-        rc = llog_init_handle(local_llh, LLOG_F_IS_PLAIN, NULL);
-        if (rc)
-                GOTO(out, rc);
-        rc = llog_destroy(local_llh);
+       rc = llog_create(NULL, lctxt, &local_llh, NULL, temp_log);
+       if (rc)
+               GOTO(out, rc);
+       rc = llog_init_handle(NULL, local_llh, LLOG_F_IS_PLAIN, NULL);
+       if (rc)
+               GOTO(out, rc);
+       rc = llog_destroy(NULL, local_llh);
         llog_free_handle(local_llh);
         if (rc)
                 GOTO(out, rc);
 
         /* open local log */
-        rc = llog_create(lctxt, &local_llh, NULL, temp_log);
+       rc = llog_create(NULL, lctxt, &local_llh, NULL, temp_log);
         if (rc)
                 GOTO(out, rc);
 
         /* set the log header uuid for fun */
         OBD_ALLOC_PTR(uuid);
         obd_str2uuid(uuid, logname);
-        rc = llog_init_handle(local_llh, LLOG_F_IS_PLAIN, uuid);
+       rc = llog_init_handle(NULL, local_llh, LLOG_F_IS_PLAIN, uuid);
         OBD_FREE_PTR(uuid);
         if (rc)
                 GOTO(out_closel, rc);
 
         /* open remote log */
-        rc = llog_create(rctxt, &remote_llh, NULL, logname);
-        if (rc)
-                GOTO(out_closel, rc);
-        rc = llog_init_handle(remote_llh, LLOG_F_IS_PLAIN, NULL);
+       rc = llog_create(NULL, rctxt, &remote_llh, NULL, logname);
+       if (rc)
+               GOTO(out_closel, rc);
+       rc = llog_init_handle(NULL, remote_llh, LLOG_F_IS_PLAIN, NULL);
         if (rc)
                 GOTO(out_closer, rc);
 
         /* Copy remote log */
-        rc = llog_process(remote_llh, mgc_copy_handler,(void *)local_llh, NULL);
+       rc = llog_process(NULL, remote_llh, mgc_copy_handler,
+                         (void *)local_llh, NULL);
 
 out_closer:
-        rc2 = llog_close(remote_llh);
-        if (!rc)
-                rc = rc2;
+       rc2 = llog_close(NULL, remote_llh);
+       if (!rc)
+               rc = rc2;
 out_closel:
-        rc2 = llog_close(local_llh);
+       rc2 = llog_close(NULL, local_llh);
         if (!rc)
                 rc = rc2;
 
@@ -1707,7 +1723,7 @@ static int mgc_process_cfg_log(struct obd_device *mgc,
            running an MGS though (logs are already local). */
         if (lctxt && lsi && (lsi->lsi_flags & LSI_SERVER) &&
             (lsi->lsi_srv_mnt == cli->cl_mgc_vfsmnt) &&
-            !IS_MGS(lsi->lsi_ldd)) {
+           !IS_MGS(lsi->lsi_ldd) && lsi->lsi_lmd->lmd_osd_type == NULL) {
                 push_ctxt(saved_ctxt, &mgc->obd_lvfs_ctxt, NULL);
                 must_pop++;
                 if (!local_only)
@@ -1905,8 +1921,15 @@ static int mgc_process_config(struct obd_device *obd, obd_count len, void *buf)
                 cld->cld_cfg.cfg_flags |= CFG_F_COMPAT146;
 
                 rc = mgc_process_log(obd, cld);
-                if (rc == 0 && cld->cld_recover) {
-                        rc = mgc_process_log(obd, cld->cld_recover);
+                if (rc == 0 && cld->cld_recover != NULL) {
+                        if (OCD_HAS_FLAG(&obd->u.cli.cl_import->
+                                         imp_connect_data, IMP_RECOV)) {
+                                rc = mgc_process_log(obd, cld->cld_recover);
+                        } else {
+                                struct config_llog_data *cir = cld->cld_recover;
+                                cld->cld_recover = NULL;
+                                config_log_put(cir);
+                        }
                         if (rc)
                                 CERROR("Cannot process recover llog %d\n", rc);
                 }