staging: lustre: mgc: expand the GOTO macro
[firefly-linux-kernel-4.4.55.git] / drivers / staging / lustre / lustre / mgc / mgc_request.c
index a806aeffe026188962db81911f4ee39d442273a4..b21a1359d2802363ed06d10d47d6d0bc23353165 100644 (file)
 #define D_MGC D_CONFIG /*|D_WARNING*/
 
 #include <linux/module.h>
-#include <obd_class.h>
-#include <lustre_dlm.h>
-#include <lprocfs_status.h>
-#include <lustre_log.h>
-#include <lustre_disk.h>
-#include <dt_object.h>
+#include "../include/obd_class.h"
+#include "../include/lustre_dlm.h"
+#include "../include/lprocfs_status.h"
+#include "../include/lustre_log.h"
+#include "../include/lustre_disk.h"
+#include "../include/dt_object.h"
 
 #include "mgc_internal.h"
 
@@ -83,7 +83,7 @@ static int mgc_name2resid(char *name, int len, struct ldlm_res_id *res_id,
                LBUG();
        }
        res_id->name[1] = cpu_to_le64(resname);
-       CDEBUG(D_MGC, "log %s to resid "LPX64"/"LPX64" (%.8s)\n", name,
+       CDEBUG(D_MGC, "log %s to resid %#llx/%#llx (%.8s)\n", name,
               res_id->name[0], res_id->name[1], (char *)&res_id->name[0]);
        return 0;
 }
@@ -197,7 +197,7 @@ struct config_llog_data *do_config_log_add(struct obd_device *obd,
        int                   rc;
 
        CDEBUG(D_MGC, "do adding config log %s:%p\n", logname,
-              cfg ? cfg->cfg_instance : 0);
+              cfg ? cfg->cfg_instance : NULL);
 
        OBD_ALLOC(cld, sizeof(*cld) + strlen(logname) + 1);
        if (!cld)
@@ -329,7 +329,8 @@ static int config_log_add(struct obd_device *obd, char *logname,
                                                CONFIG_T_SPTLRPC, NULL, NULL);
                if (IS_ERR(sptlrpc_cld)) {
                        CERROR("can't create sptlrpc log: %s\n", seclogname);
-                       GOTO(out_err, rc = PTR_ERR(sptlrpc_cld));
+                       rc = PTR_ERR(sptlrpc_cld);
+                       goto out_err;
                }
        }
        params_cld = config_params_log_add(obd, cfg, sb);
@@ -337,13 +338,14 @@ static int config_log_add(struct obd_device *obd, char *logname,
                rc = PTR_ERR(params_cld);
                CERROR("%s: can't create params log: rc = %d\n",
                       obd->obd_name, rc);
-               GOTO(out_err1, rc);
+               goto out_err1;
        }
 
        cld = do_config_log_add(obd, logname, CONFIG_T_CONFIG, cfg, sb);
        if (IS_ERR(cld)) {
                CERROR("can't create log: %s\n", logname);
-               GOTO(out_err2, rc = PTR_ERR(cld));
+               rc = PTR_ERR(cld);
+               goto out_err2;
        }
 
        cld->cld_sptlrpc = sptlrpc_cld;
@@ -354,8 +356,10 @@ static int config_log_add(struct obd_device *obd, char *logname,
                struct config_llog_data *recover_cld;
                *strrchr(seclogname, '-') = 0;
                recover_cld = config_recover_log_add(obd, seclogname, cfg, sb);
-               if (IS_ERR(recover_cld))
-                       GOTO(out_err3, rc = PTR_ERR(recover_cld));
+               if (IS_ERR(recover_cld)) {
+                       rc = PTR_ERR(recover_cld);
+                       goto out_err3;
+               }
                cld->cld_recover = recover_cld;
        }
 
@@ -445,7 +449,7 @@ static int config_log_end(char *logname, struct config_llog_instance *cfg)
        return rc;
 }
 
-#ifdef LPROCFS
+#if defined (CONFIG_PROC_FS)
 int lprocfs_mgc_rd_ir_state(struct seq_file *m, void *data)
 {
        struct obd_device       *obd = data;
@@ -680,7 +684,7 @@ static int mgc_fs_setup(struct obd_device *obd, struct super_block *sb)
        /* Setup the configs dir */
        rc = lu_env_init(env, LCT_MG_THREAD);
        if (rc)
-               GOTO(out_err, rc);
+               goto out_err;
 
        fid.f_seq = FID_SEQ_LOCAL_NAME;
        fid.f_oid = 1;
@@ -688,30 +692,34 @@ static int mgc_fs_setup(struct obd_device *obd, struct super_block *sb)
        rc = local_oid_storage_init(env, lsi->lsi_dt_dev, &fid,
                                    &cli->cl_mgc_los);
        if (rc)
-               GOTO(out_env, rc);
+               goto out_env;
 
        rc = dt_root_get(env, lsi->lsi_dt_dev, &rfid);
        if (rc)
-               GOTO(out_env, rc);
+               goto out_env;
 
        root = dt_locate_at(env, lsi->lsi_dt_dev, &rfid,
                            &cli->cl_mgc_los->los_dev->dd_lu_dev);
-       if (unlikely(IS_ERR(root)))
-               GOTO(out_los, rc = PTR_ERR(root));
+       if (unlikely(IS_ERR(root))) {
+               rc = PTR_ERR(root);
+               goto out_los;
+       }
 
        dto = local_file_find_or_create(env, cli->cl_mgc_los, root,
                                        MOUNT_CONFIGS_DIR,
                                        S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO);
        lu_object_put_nocache(env, &root->do_lu);
-       if (IS_ERR(dto))
-               GOTO(out_los, rc = PTR_ERR(dto));
+       if (IS_ERR(dto)) {
+               rc = PTR_ERR(dto);
+               goto out_los;
+       }
 
        cli->cl_mgc_configs_dir = dto;
 
        LASSERT(lsi->lsi_osd_exp->exp_obd->obd_lvfs_ctxt.dt);
        rc = mgc_local_llog_init(env, obd, lsi->lsi_osd_exp->exp_obd);
        if (rc)
-               GOTO(out_llog, rc);
+               goto out_llog;
 
        /* We take an obd ref to insure that we can't get to mgc_cleanup
         * without calling mgc_fs_cleanup first. */
@@ -746,7 +754,7 @@ static int mgc_fs_cleanup(struct obd_device *obd)
 
        rc = lu_env_init(&env, LCT_MG_THREAD);
        if (rc)
-               GOTO(unlock, rc);
+               goto unlock;
 
        mgc_local_llog_fini(&env, obd);
 
@@ -853,12 +861,12 @@ static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
 
        rc = client_obd_setup(obd, lcfg);
        if (rc)
-               GOTO(err_decref, rc);
+               goto err_decref;
 
        rc = mgc_llog_init(NULL, obd);
        if (rc) {
                CERROR("failed to setup llogging subsystems\n");
-               GOTO(err_cleanup, rc);
+               goto err_cleanup;
        }
 
        lprocfs_mgc_init_vars(&lvars);
@@ -876,7 +884,7 @@ static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
                        CERROR("%s: Cannot start requeue thread (%d),"
                               "no more log updates!\n",
                               obd->obd_name, rc);
-                       GOTO(err_cleanup, rc);
+                       goto err_cleanup;
                }
                /* rc is the task_struct pointer of mgc_requeue_thread. */
                rc = 0;
@@ -950,7 +958,10 @@ static int mgc_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
 }
 
 /* Not sure where this should go... */
-#define  MGC_ENQUEUE_LIMIT 50
+/* This is the timeout value for MGS_CONNECT request plus a ping interval, such
+ * that we can have a chance to try the secondary MGS if any. */
+#define  MGC_ENQUEUE_LIMIT (INITIAL_CONNECT_TIMEOUT + (AT_OFF ? 0 : at_min) \
+                               + PING_INTERVAL)
 #define  MGC_TARGET_REG_LIMIT 10
 #define  MGC_SEND_PARAM_LIMIT 10
 
@@ -1008,7 +1019,7 @@ static int mgc_enqueue(struct obd_export *exp, struct lov_stripe_md *lsm,
        int short_limit = cld_is_sptlrpc(cld);
        int rc;
 
-       CDEBUG(D_MGC, "Enqueue for %s (res "LPX64")\n", cld->cld_logname,
+       CDEBUG(D_MGC, "Enqueue for %s (res %#llx)\n", cld->cld_logname,
               cld->cld_resid.name[0]);
 
        /* We need a callback for every lockholder, so don't try to
@@ -1097,7 +1108,7 @@ static int mgc_target_register(struct obd_export *exp,
 }
 
 int mgc_set_info_async(const struct lu_env *env, struct obd_export *exp,
-                      obd_count keylen, void *key, obd_count vallen,
+                      u32 keylen, void *key, u32 vallen,
                       void *val, struct ptlrpc_request_set *set)
 {
        int rc = -EINVAL;
@@ -1454,7 +1465,7 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
                        break;
                }
 
-               CDEBUG(D_INFO, "ir apply logs "LPD64"/"LPD64" for %s -> %s\n",
+               CDEBUG(D_INFO, "ir apply logs %lld/%lld for %s -> %s\n",
                       prev_version, max_version, obdname, params);
 
                rc = class_process_config(lcfg);
@@ -1501,13 +1512,17 @@ static int mgc_process_recover_log(struct obd_device *obd,
                nrpages = CONFIG_READ_NRPAGES_INIT;
 
        OBD_ALLOC(pages, sizeof(*pages) * nrpages);
-       if (pages == NULL)
-               GOTO(out, rc = -ENOMEM);
+       if (pages == NULL) {
+               rc = -ENOMEM;
+               goto out;
+       }
 
        for (i = 0; i < nrpages; i++) {
                pages[i] = alloc_page(GFP_IOFS);
-               if (pages[i] == NULL)
-                       GOTO(out, rc = -ENOMEM);
+               if (pages[i] == NULL) {
+                       rc = -ENOMEM;
+                       goto out;
+               }
        }
 
 again:
@@ -1515,20 +1530,24 @@ again:
        LASSERT(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);
+       if (req == NULL) {
+               rc = -ENOMEM;
+               goto out;
+       }
 
        rc = ptlrpc_request_pack(req, LUSTRE_MGS_VERSION, MGS_CONFIG_READ);
        if (rc)
-               GOTO(out, rc);
+               goto out;
 
        /* 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));
        if (strlcpy(body->mcb_name, cld->cld_logname, sizeof(body->mcb_name))
-           >= sizeof(body->mcb_name))
-               GOTO(out, rc = -E2BIG);
+           >= sizeof(body->mcb_name)) {
+               rc = -E2BIG;
+               goto out;
+       }
        body->mcb_offset = cfg->cfg_last_idx + 1;
        body->mcb_type   = cld->cld_type;
        body->mcb_bits   = PAGE_CACHE_SHIFT;
@@ -1537,8 +1556,10 @@ again:
        /* allocate bulk transfer descriptor */
        desc = ptlrpc_prep_bulk_imp(req, nrpages, 1, BULK_PUT_SINK,
                                    MGS_BULK_PORTAL);
-       if (desc == NULL)
-               GOTO(out, rc = -ENOMEM);
+       if (desc == NULL) {
+               rc = -ENOMEM;
+               goto out;
+       }
 
        for (i = 0; i < nrpages; i++)
                ptlrpc_prep_bulk_page_pin(desc, pages[i], 0, PAGE_CACHE_SIZE);
@@ -1546,31 +1567,37 @@ again:
        ptlrpc_request_set_replen(req);
        rc = ptlrpc_queue_wait(req);
        if (rc)
-               GOTO(out, rc);
+               goto out;
 
        res = req_capsule_server_get(&req->rq_pill, &RMF_MGS_CONFIG_RES);
-       if (res->mcr_size < res->mcr_offset)
-               GOTO(out, rc = -EINVAL);
+       if (res->mcr_size < res->mcr_offset) {
+               rc = -EINVAL;
+               goto out;
+       }
 
        /* 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",
+       CDEBUG(D_INFO, "Latest version %lld, 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 < 0) {
+               rc = ealen;
+               goto out;
+       }
 
-       if (ealen > nrpages << PAGE_CACHE_SHIFT)
-               GOTO(out, rc = -EINVAL);
+       if (ealen > nrpages << PAGE_CACHE_SHIFT) {
+               rc = -EINVAL;
+               goto out;
+       }
 
        if (ealen == 0) { /* no logs transferred */
                if (!eof)
                        rc = -EINVAL;
-               GOTO(out, rc);
+               goto out;
        }
 
        mne_swab = !!ptlrpc_rep_need_swab(req);
@@ -1643,7 +1670,7 @@ static int mgc_llog_local_copy(const struct lu_env *env,
        /* make a copy of local llog at first */
        rc = llog_backup(env, obd, lctxt, lctxt, logname, temp_log);
        if (rc < 0 && rc != -ENOENT)
-               GOTO(out, rc);
+               goto out;
        /* copy remote llog to the local copy */
        rc = llog_backup(env, obd, rctxt, lctxt, logname, logname);
        if (rc == -ENOENT) {
@@ -1691,7 +1718,7 @@ static int mgc_process_cfg_log(struct obd_device *mgc,
 
        rc = lu_env_init(env, LCT_MG_THREAD);
        if (rc)
-               GOTO(out_free, rc);
+               goto out_free;
 
        ctxt = llog_get_context(mgc, LLOG_CONFIG_REPL_CTXT);
        LASSERT(ctxt);
@@ -1712,7 +1739,8 @@ static int mgc_process_cfg_log(struct obd_device *mgc,
                                LCONSOLE_ERROR_MSG(0x13a,
                                                   "Failed to get MGS log %s and no local copy.\n",
                                                   cld->cld_logname);
-                               GOTO(out_pop, rc = -ENOENT);
+                               rc = -ENOENT;
+                               goto out_pop;
                        }
                        CDEBUG(D_MGC,
                               "Failed to get MGS log %s, using local copy for now, will try to update later.\n",
@@ -1725,8 +1753,10 @@ static int mgc_process_cfg_log(struct obd_device *mgc,
                ctxt = lctxt;
                lctxt = NULL;
        } else {
-               if (local_only) /* no local log at client side */
-                       GOTO(out_pop, rc = -EIO);
+               if (local_only) /* no local log at client side */ {
+                       rc = -EIO;
+                       goto out_pop;
+               }
        }
 
        if (cld_is_sptlrpc(cld)) {
@@ -1841,7 +1871,7 @@ int mgc_process_log(struct obd_device *mgc, struct config_llog_data *cld)
  * LCFG_LOG_START gets the config log from the MGS, processes it to start
  * any services, and adds it to the list logs to watch (follow).
  */
-static int mgc_process_config(struct obd_device *obd, obd_count len, void *buf)
+static int mgc_process_config(struct obd_device *obd, u32 len, void *buf)
 {
        struct lustre_cfg *lcfg = buf;
        struct config_llog_instance *cfg = NULL;
@@ -1854,8 +1884,10 @@ static int mgc_process_config(struct obd_device *obd, obd_count len, void *buf)
                struct mgs_target_info *mti;
 
                if (LUSTRE_CFG_BUFLEN(lcfg, 1) !=
-                   sizeof(struct mgs_target_info))
-                       GOTO(out, rc = -EINVAL);
+                   sizeof(struct mgs_target_info)) {
+                       rc = -EINVAL;
+                       goto out;
+               }
 
                mti = (struct mgs_target_info *)lustre_cfg_buf(lcfg, 1);
                CDEBUG(D_MGC, "add_target %s %#x\n",
@@ -1940,7 +1972,8 @@ static int mgc_process_config(struct obd_device *obd, obd_count len, void *buf)
        }
        default: {
                CERROR("Unknown command: %d\n", lcfg->lcfg_command);
-               GOTO(out, rc = -EINVAL);
+               rc = -EINVAL;
+               goto out;
 
        }
        }