Whamcloud - gitweb
LU-1302 llog: pass lu_env as parametr in llog functions
[fs/lustre-release.git] / lustre / mgc / mgc_request.c
index 295b6c7..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*/
 
@@ -88,6 +82,9 @@ static int mgc_name2resid(char *name, int len, struct ldlm_res_id *res_id,
         case CONFIG_T_SPTLRPC:
                 resname = 0;
                 break;
+        case CONFIG_T_RECOVER:
+                resname = type;
+                break;
         default:
                 LBUG();
         }
@@ -120,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)
@@ -149,6 +146,8 @@ static void config_log_put(struct config_llog_data *cld)
 
                 CDEBUG(D_MGC, "dropping config log %s\n", cld->cld_logname);
 
+                if (cld->cld_recover)
+                        config_log_put(cld->cld_recover);
                 if (cld->cld_sptlrpc)
                         config_log_put(cld->cld_sptlrpc);
                 if (cld_is_sptlrpc(cld))
@@ -250,6 +249,37 @@ struct config_llog_data *do_config_log_add(struct obd_device *obd,
         RETURN(cld);
 }
 
+static struct config_llog_data *config_recover_log_add(struct obd_device *obd,
+        char *fsname,
+        struct config_llog_instance *cfg,
+        struct super_block *sb)
+{
+        struct config_llog_instance lcfg = *cfg;
+        struct lustre_sb_info *lsi = s2lsi(sb);
+        struct config_llog_data *cld;
+        char logname[32];
+
+        if ((lsi->lsi_flags & LSI_SERVER) && IS_OST(lsi->lsi_ldd))
+                return NULL;
+
+        /* we have to use different llog for clients and mdts for cmd
+         * where only clients are notified if one of cmd server restarts */
+        LASSERT(strlen(fsname) < sizeof(logname) / 2);
+        strcpy(logname, fsname);
+        if (lsi->lsi_flags & LSI_SERVER) { /* mdt */
+                LASSERT(lcfg.cfg_instance == NULL);
+                lcfg.cfg_instance = sb;
+                strcat(logname, "-mdtir");
+        } else {
+                LASSERT(lcfg.cfg_instance != NULL);
+                strcat(logname, "-cliir");
+        }
+
+        cld = do_config_log_add(obd, logname, CONFIG_T_RECOVER, &lcfg, sb);
+        return cld;
+}
+
+
 /** Add this log to the list of active logs watched by an MGC.
  * Active means we're watching for updates.
  * We have one active log per "mount" - client instance or servername.
@@ -259,6 +289,7 @@ static int config_log_add(struct obd_device *obd, char *logname,
                           struct config_llog_instance *cfg,
                           struct super_block *sb)
 {
+        struct lustre_sb_info *lsi = s2lsi(sb);
         struct config_llog_data *cld;
         struct config_llog_data *sptlrpc_cld;
         char                     seclogname[32];
@@ -299,16 +330,30 @@ static int config_log_add(struct obd_device *obd, char *logname,
 
         cld->cld_sptlrpc = sptlrpc_cld;
 
+        LASSERT(lsi->lsi_lmd);
+        if (!(lsi->lsi_lmd->lmd_flags & LMD_FLG_NOIR)) {
+                struct config_llog_data *recover_cld;
+                *strrchr(seclogname, '-') = 0;
+                recover_cld = config_recover_log_add(obd, seclogname, cfg, sb);
+                if (IS_ERR(recover_cld)) {
+                        config_log_put(cld);
+                        RETURN(PTR_ERR(recover_cld));
+                }
+                cld->cld_recover = recover_cld;
+        }
+
         RETURN(0);
 }
 
-CFS_DECLARE_MUTEX(llog_process_lock);
+CFS_DEFINE_MUTEX(llog_process_lock);
 
 /** Stop watching for updates on this log.
  */
 static int config_log_end(char *logname, struct config_llog_instance *cfg)
 {
-        struct config_llog_data *cld, *cld_sptlrpc = NULL;
+        struct config_llog_data *cld;
+        struct config_llog_data *cld_sptlrpc = NULL;
+        struct config_llog_data *cld_recover = NULL;
         int rc = 0;
         ENTRY;
 
@@ -332,8 +377,18 @@ static int config_log_end(char *logname, struct config_llog_instance *cfg)
         }
 
         cld->cld_stopping = 1;
+
+        cld_recover = cld->cld_recover;
+        cld->cld_recover = NULL;
         cfs_mutex_unlock(&cld->cld_lock);
 
+        if (cld_recover) {
+                cfs_mutex_lock(&cld_recover->cld_lock);
+                cld_recover->cld_stopping = 1;
+                cfs_mutex_unlock(&cld_recover->cld_lock);
+                config_log_put(cld_recover);
+        }
+
         cfs_spin_lock(&config_list_lock);
         cld_sptlrpc = cld->cld_sptlrpc;
         cld->cld_sptlrpc = NULL;
@@ -352,6 +407,34 @@ static int config_log_end(char *logname, struct config_llog_instance *cfg)
         RETURN(rc);
 }
 
+int lprocfs_mgc_rd_ir_state(char *page, char **start, off_t off,
+                            int count, int *eof, void *data)
+{
+        struct obd_device       *obd = data;
+        struct obd_import       *imp = obd->u.cli.cl_import;
+        struct obd_connect_data *ocd = &imp->imp_connect_data;
+        struct config_llog_data *cld;
+        int rc = 0;
+        ENTRY;
+
+        rc = snprintf(page, count, "imperative_recovery: %s\n",
+                     OCD_HAS_FLAG(ocd, IMP_RECOV) ? "ENABLED" : "DISABLED");
+        rc += snprintf(page + rc, count - rc, "client_state:\n");
+
+        cfs_spin_lock(&config_list_lock);
+        cfs_list_for_each_entry(cld, &config_llog_list, cld_list_chain) {
+                if (cld->cld_recover == NULL)
+                        continue;
+                rc += snprintf(page + rc, count - rc,
+                               "    - { client: %s, nidtbl_version: %u }\n",
+                               cld->cld_logname,
+                               cld->cld_recover->cld_cfg.cfg_last_idx);
+        }
+        cfs_spin_unlock(&config_list_lock);
+
+        RETURN(rc);
+}
+
 /* reenqueue any lost locks */
 #define RQ_RUNNING 0x1
 #define RQ_NOW     0x2
@@ -545,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;
@@ -915,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;
@@ -1026,6 +1111,25 @@ int mgc_set_info_async(struct obd_export *exp, obd_count keylen,
         RETURN(rc);
 }
 
+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;
+
+        if (KEY_IS(KEY_CONN_DATA)) {
+                struct obd_import *imp = class_exp2cliimp(exp);
+                struct obd_connect_data *data = val;
+
+                if (*vallen == sizeof(*data)) {
+                        *data = imp->imp_connect_data;
+                        rc = 0;
+                }
+        }
+
+        return rc;
+}
+
 static int mgc_import_event(struct obd_device *obd,
                             struct obd_import *imp,
                             enum obd_import_event event)
@@ -1119,28 +1223,361 @@ static int mgc_llog_finish(struct obd_device *obd, int count)
         RETURN(rc);
 }
 
-/* identical to mgs_log_is_empty */
-static int mgc_llog_is_empty(struct obd_device *obd, struct llog_ctxt *ctxt,
-                            char *name)
+enum {
+        CONFIG_READ_NRPAGES_INIT = 1 << (20 - CFS_PAGE_SHIFT),
+        CONFIG_READ_NRPAGES      = 4
+};
+
+static int mgc_apply_recover_logs(struct obd_device *mgc,
+                                 struct config_llog_data *cld,
+                                 __u64 max_version,
+                                 void *data, int datalen, bool mne_swab)
 {
-        struct lvfs_run_ctxt saved;
-        struct llog_handle *llh;
-        int rc = 0;
+        struct config_llog_instance *cfg = &cld->cld_cfg;
+        struct lustre_sb_info       *lsi = s2lsi(cfg->cfg_sb);
+        struct mgs_nidtbl_entry *entry;
+        struct lustre_cfg       *lcfg;
+        struct lustre_cfg_bufs   bufs;
+        u64   prev_version = 0;
+        char *inst;
+        char *buf;
+        int   bufsz;
+        int   pos;
+        int   rc  = 0;
+        int   off = 0;
+        ENTRY;
 
-        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);
+        LASSERT(cfg->cfg_instance != NULL);
+        LASSERT(cfg->cfg_sb == cfg->cfg_instance);
+
+        OBD_ALLOC(inst, CFS_PAGE_SIZE);
+        if (inst == NULL)
+                RETURN(-ENOMEM);
+
+        if (!(lsi->lsi_flags & LSI_SERVER)) {
+                pos = sprintf(inst, "%p", cfg->cfg_instance);
+        } else {
+                LASSERT(IS_MDT(lsi->lsi_ldd));
+                pos = sprintf(inst, "MDT%04x", lsi->lsi_ldd->ldd_svindex);
         }
-        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-        /* header is record 1 */
-        return(rc <= 1);
+
+        ++pos;
+        buf   = inst + pos;
+        bufsz = CFS_PAGE_SIZE - pos;
+
+        while (datalen > 0) {
+                int   entry_len = sizeof(*entry);
+                int   is_ost;
+                struct obd_device *obd;
+                char *obdname;
+                char *cname;
+                char *params;
+                char *uuid;
+
+                rc = -EINVAL;
+                if (datalen < sizeof(*entry))
+                        break;
+
+                entry = (typeof(entry))(data + off);
+
+                /* sanity check */
+                if (entry->mne_nid_type != 0) /* only support type 0 for ipv4 */
+                        break;
+                if (entry->mne_nid_count == 0) /* at least one nid entry */
+                        break;
+                if (entry->mne_nid_size != sizeof(lnet_nid_t))
+                        break;
+
+                entry_len += entry->mne_nid_count * entry->mne_nid_size;
+                if (datalen < entry_len) /* must have entry_len at least */
+                        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;
+                if (datalen < 0)
+                        break;
+
+                if (entry->mne_version > max_version) {
+                        CERROR("entry index(%lld) is over max_index(%lld)\n",
+                               entry->mne_version, max_version);
+                        break;
+                }
+
+                if (prev_version >= entry->mne_version) {
+                        CERROR("index unsorted, prev %lld, now %lld\n",
+                               prev_version, entry->mne_version);
+                        break;
+                }
+                prev_version = entry->mne_version;
+
+                /*
+                 * Write a string with format "nid::instance" to
+                 * lustre/<osc|mdc>/<target>-<osc|mdc>-<instance>/import.
+                 */
+
+                is_ost = entry->mne_type == LDD_F_SV_TYPE_OST;
+                memset(buf, 0, bufsz);
+                obdname = buf;
+                pos = 0;
+
+                /* lustre-OST0001-osc-<instance #> */
+                strcpy(obdname, cld->cld_logname);
+                cname = strrchr(obdname, '-');
+                if (cname == NULL) {
+                        CERROR("mgc %s: invalid logname %s\n",
+                               mgc->obd_name, obdname);
+                        break;
+                }
+
+                pos = cname - obdname;
+                obdname[pos] = 0;
+                pos += sprintf(obdname + pos, "-%s%04x",
+                                  is_ost ? "OST" : "MDT", entry->mne_index);
+
+                cname = is_ost ? "osc" : "mdc",
+                pos += sprintf(obdname + pos, "-%s-%s", cname, inst);
+                lustre_cfg_bufs_reset(&bufs, obdname);
+
+                /* find the obd by obdname */
+                obd = class_name2obd(obdname);
+                if (obd == NULL) {
+                        CDEBUG(D_INFO, "mgc %s: cannot find obdname %s\n",
+                               mgc->obd_name, obdname);
+
+                        /* this is a safe race, when the ost is starting up...*/
+                        continue;
+                }
+
+                /* osc.import = "connection=<Conn UUID>::<target instance>" */
+                ++pos;
+                params = buf + pos;
+                pos += sprintf(params, "%s.import=%s", cname, "connection=");
+                uuid = buf + pos;
+
+                /* TODO: iterate all nids to find one */
+                /* find uuid by nid */
+                rc = client_import_find_conn(obd->u.cli.cl_import,
+                                             entry->u.nids[0],
+                                             (struct obd_uuid *)uuid);
+                if (rc < 0) {
+                        CERROR("mgc: cannot find uuid by nid %s\n",
+                               libcfs_nid2str(entry->u.nids[0]));
+                        break;
+                }
+
+                CDEBUG(D_INFO, "Find uuid %s by nid %s\n",
+                       uuid, libcfs_nid2str(entry->u.nids[0]));
+
+                pos += strlen(uuid);
+                pos += sprintf(buf + pos, "::%u", entry->mne_instance);
+                LASSERT(pos < bufsz);
+
+                lustre_cfg_bufs_set_string(&bufs, 1, params);
+
+                rc = -ENOMEM;
+                lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
+                if (lcfg == NULL) {
+                        CERROR("mgc: cannot allocate memory\n");
+                        break;
+                }
+
+                CDEBUG(D_INFO, "ir apply logs "LPD64"/"LPD64" for %s -> %s\n",
+                       prev_version, max_version, obdname, params);
+
+                rc = class_process_config(lcfg);
+                lustre_cfg_free(lcfg);
+                if (rc)
+                        CDEBUG(D_INFO, "process config for %s error %d\n",
+                               obdname, rc);
+
+                /* continue, even one with error */
+        }
+
+        OBD_FREE(inst, CFS_PAGE_SIZE);
+        RETURN(rc);
 }
 
-static int mgc_copy_handler(struct llog_handle *llh, struct llog_rec_hdr *rec,
-                            void *data)
+/**
+ * This function is called if this client was notified for target restarting
+ * by the MGS. A CONFIG_READ RPC is going to send to fetch recovery logs.
+ */
+static int mgc_process_recover_log(struct obd_device *obd,
+                                   struct config_llog_data *cld)
+{
+        struct ptlrpc_request *req = NULL;
+        struct config_llog_instance *cfg = &cld->cld_cfg;
+        struct mgs_config_body *body;
+        struct mgs_config_res  *res;
+        struct ptlrpc_bulk_desc *desc;
+        cfs_page_t **pages;
+        int nrpages;
+        bool eof = true;
+       bool mne_swab = false;
+        int i;
+        int ealen;
+        int rc;
+        ENTRY;
+
+        /* allocate buffer for bulk transfer.
+         * if this is the first time for this mgs to read logs,
+         * CONFIG_READ_NRPAGES_INIT will be used since it will read all logs
+         * once; otherwise, it only reads increment of logs, this should be
+         * small and CONFIG_READ_NRPAGES will be used.
+         */
+        nrpages = CONFIG_READ_NRPAGES;
+        if (cfg->cfg_last_idx == 0) /* the first time */
+                nrpages = CONFIG_READ_NRPAGES_INIT;
+
+        OBD_ALLOC(pages, sizeof(*pages) * nrpages);
+        if (pages == NULL)
+                GOTO(out, rc = -ENOMEM);
+
+        for (i = 0; i < nrpages; i++) {
+                pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
+                if (pages[i] == NULL)
+                        GOTO(out, rc = -ENOMEM);
+        }
+
+again:
+        LASSERT(cld_is_recover(cld));
+        LASSERT(cfs_mutex_is_locked(&cld->cld_lock));
+        req = ptlrpc_request_alloc(class_exp2cliimp(cld->cld_mgcexp),
+                                   &RQF_MGS_CONFIG_READ);
+        if (req == NULL)
+                GOTO(out, rc = -ENOMEM);
+
+        rc = ptlrpc_request_pack(req, LUSTRE_MGS_VERSION, MGS_CONFIG_READ);
+        if (rc)
+                GOTO(out, rc);
+
+        /* pack request */
+        body = req_capsule_client_get(&req->rq_pill, &RMF_MGS_CONFIG_BODY);
+        LASSERT(body != NULL);
+        LASSERT(sizeof(body->mcb_name) > strlen(cld->cld_logname));
+        strncpy(body->mcb_name, cld->cld_logname, sizeof(body->mcb_name));
+        body->mcb_offset = cfg->cfg_last_idx + 1;
+        body->mcb_type   = cld->cld_type;
+        body->mcb_bits   = CFS_PAGE_SHIFT;
+        body->mcb_units  = nrpages;
+
+        /* allocate bulk transfer descriptor */
+        desc = ptlrpc_prep_bulk_imp(req, nrpages, BULK_PUT_SINK,
+                                    MGS_BULK_PORTAL);
+        if (desc == NULL)
+                GOTO(out, rc = -ENOMEM);
+
+        for (i = 0; i < nrpages; i++)
+                ptlrpc_prep_bulk_page(desc, pages[i], 0, CFS_PAGE_SIZE);
+
+        ptlrpc_request_set_replen(req);
+        rc = ptlrpc_queue_wait(req);
+        if (rc)
+                GOTO(out, rc);
+
+        res = req_capsule_server_get(&req->rq_pill, &RMF_MGS_CONFIG_RES);
+        if (res->mcr_size < res->mcr_offset)
+                GOTO(out, rc = -EINVAL);
+
+        /* always update the index even though it might have errors with
+         * handling the recover logs */
+        cfg->cfg_last_idx = res->mcr_offset;
+        eof = res->mcr_offset == res->mcr_size;
+
+        CDEBUG(D_INFO, "Latest version "LPD64", more %d.\n",
+               res->mcr_offset, eof == false);
+
+        ealen = sptlrpc_cli_unwrap_bulk_read(req, req->rq_bulk, 0);
+        if (ealen < 0)
+                GOTO(out, rc = ealen);
+
+        if (ealen > nrpages << CFS_PAGE_SHIFT)
+                GOTO(out, rc = -EINVAL);
+
+        if (ealen == 0) { /* no logs transferred */
+                if (!eof)
+                        rc = -EINVAL;
+                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),
+                                            mne_swab);
+                cfs_kunmap(pages[i]);
+                if (rc2 < 0) {
+                        CWARN("Process recover log %s error %d\n",
+                              cld->cld_logname, rc2);
+                        break;
+                }
+
+                ealen -= CFS_PAGE_SIZE;
+        }
+
+out:
+        if (req)
+                ptlrpc_req_finished(req);
+
+        if (rc == 0 && !eof)
+                goto again;
+
+        if (pages) {
+                for (i = 0; i < nrpages; i++) {
+                        if (pages[i] == NULL)
+                                break;
+                        cfs_free_page(pages[i]);
+                }
+                OBD_FREE(pages, sizeof(*pages) * nrpages);
+        }
+        return rc;
+}
+
+/* identical to mgs_log_is_empty */
+static int mgc_llog_is_empty(struct obd_device *obd, struct llog_ctxt *ctxt,
+                            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(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(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;
@@ -1151,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;
@@ -1181,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;
 
@@ -1285,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)
@@ -1355,7 +1793,7 @@ out_pop:
 int mgc_process_log(struct obd_device *mgc, struct config_llog_data *cld)
 {
         struct lustre_handle lockh = { 0 };
-        int rc = 0, rcl, flags = 0;
+        int rc = 0, rcl, flags = LDLM_FL_NO_LRU;
         ENTRY;
 
         LASSERT(cld);
@@ -1394,7 +1832,14 @@ int mgc_process_log(struct obd_device *mgc, struct config_llog_data *cld)
                 config_log_get(cld);
         }
 
-        rc = mgc_process_cfg_log(mgc, cld, rcl != 0);
+
+        if (cld_is_recover(cld)) {
+                rc = 0; /* this is not a fatal error for recover log */
+                if (rcl == 0)
+                        rc = mgc_process_recover_log(mgc, cld);
+        } else {
+                rc = mgc_process_cfg_log(mgc, cld, rcl != 0);
+        }
 
         CDEBUG(D_MGC, "%s: configuration from log '%s' %sed (%d).\n",
                mgc->obd_name, cld->cld_logname, rc ? "fail" : "succeed", rc);
@@ -1476,6 +1921,18 @@ 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 != 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);
+                }
                 config_log_put(cld);
 
                 break;
@@ -1512,6 +1969,7 @@ struct obd_ops mgc_obd_ops = {
         .o_cancel       = mgc_cancel,
         //.o_iocontrol    = mgc_iocontrol,
         .o_set_info_async = mgc_set_info_async,
+        .o_get_info       = mgc_get_info,
         .o_import_event = mgc_import_event,
         .o_llog_init    = mgc_llog_init,
         .o_llog_finish  = mgc_llog_finish,