diff options
Diffstat (limited to 'drivers/staging/lustre/lustre/mgc/mgc_request.c')
-rw-r--r-- | drivers/staging/lustre/lustre/mgc/mgc_request.c | 360 |
1 files changed, 62 insertions, 298 deletions
diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c index f520591d5784..bc263adf09d4 100644 --- a/drivers/staging/lustre/lustre/mgc/mgc_request.c +++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c @@ -47,7 +47,6 @@ #include "../include/lprocfs_status.h" #include "../include/lustre_log.h" #include "../include/lustre_disk.h" -#include "../include/dt_object.h" #include "mgc_internal.h" @@ -329,7 +328,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 +337,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 +355,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; } @@ -624,146 +627,6 @@ static void mgc_requeue_add(struct config_llog_data *cld) } } -/********************** class fns **********************/ -static int mgc_local_llog_init(const struct lu_env *env, - struct obd_device *obd, - struct obd_device *disk) -{ - struct llog_ctxt *ctxt; - int rc; - - rc = llog_setup(env, obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, disk, - &llog_osd_ops); - if (rc) - return rc; - - ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT); - LASSERT(ctxt); - ctxt->loc_dir = obd->u.cli.cl_mgc_configs_dir; - llog_ctxt_put(ctxt); - - return 0; -} - -static int mgc_local_llog_fini(const struct lu_env *env, - struct obd_device *obd) -{ - struct llog_ctxt *ctxt; - - ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT); - llog_cleanup(env, ctxt); - - return 0; -} - -static int mgc_fs_setup(struct obd_device *obd, struct super_block *sb) -{ - struct lustre_sb_info *lsi = s2lsi(sb); - struct client_obd *cli = &obd->u.cli; - struct lu_fid rfid, fid; - struct dt_object *root, *dto; - struct lu_env *env; - int rc = 0; - - LASSERT(lsi); - LASSERT(lsi->lsi_dt_dev); - - OBD_ALLOC_PTR(env); - if (env == NULL) - return -ENOMEM; - - /* The mgc fs exclusion mutex. Only one fs can be setup at a time. */ - mutex_lock(&cli->cl_mgc_mutex); - - cfs_cleanup_group_info(); - - /* Setup the configs dir */ - rc = lu_env_init(env, LCT_MG_THREAD); - if (rc) - GOTO(out_err, rc); - - fid.f_seq = FID_SEQ_LOCAL_NAME; - fid.f_oid = 1; - fid.f_ver = 0; - rc = local_oid_storage_init(env, lsi->lsi_dt_dev, &fid, - &cli->cl_mgc_los); - if (rc) - GOTO(out_env, rc); - - rc = dt_root_get(env, lsi->lsi_dt_dev, &rfid); - if (rc) - GOTO(out_env, rc); - - 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)); - - 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)); - - 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); - - /* We take an obd ref to insure that we can't get to mgc_cleanup - * without calling mgc_fs_cleanup first. */ - class_incref(obd, "mgc_fs", obd); - - /* We keep the cl_mgc_sem until mgc_fs_cleanup */ -out_llog: - if (rc) { - lu_object_put(env, &cli->cl_mgc_configs_dir->do_lu); - cli->cl_mgc_configs_dir = NULL; - } -out_los: - if (rc < 0) { - local_oid_storage_fini(env, cli->cl_mgc_los); - cli->cl_mgc_los = NULL; - mutex_unlock(&cli->cl_mgc_mutex); - } -out_env: - lu_env_fini(env); -out_err: - OBD_FREE_PTR(env); - return rc; -} - -static int mgc_fs_cleanup(struct obd_device *obd) -{ - struct lu_env env; - struct client_obd *cli = &obd->u.cli; - int rc; - - LASSERT(cli->cl_mgc_los != NULL); - - rc = lu_env_init(&env, LCT_MG_THREAD); - if (rc) - GOTO(unlock, rc); - - mgc_local_llog_fini(&env, obd); - - lu_object_put_nocache(&env, &cli->cl_mgc_configs_dir->do_lu); - cli->cl_mgc_configs_dir = NULL; - - local_oid_storage_fini(&env, cli->cl_mgc_los); - cli->cl_mgc_los = NULL; - lu_env_fini(&env); - -unlock: - class_decref(obd, "mgc_fs", obd); - mutex_unlock(&cli->cl_mgc_mutex); - - return 0; -} - static int mgc_llog_init(const struct lu_env *env, struct obd_device *obd) { struct llog_ctxt *ctxt; @@ -853,12 +716,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 +739,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; @@ -1041,14 +904,6 @@ static int mgc_enqueue(struct obd_export *exp, struct lov_stripe_md *lsm, return rc; } -static int mgc_cancel(struct obd_export *exp, struct lov_stripe_md *md, - __u32 mode, struct lustre_handle *lockh) -{ - ldlm_lock_decref(lockh, mode); - - return 0; -} - static void mgc_notify_active(struct obd_device *unused) { /* wakeup mgc_requeue_thread to requeue mgc lock */ @@ -1100,7 +955,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; @@ -1123,38 +978,6 @@ int mgc_set_info_async(const struct lu_env *env, struct obd_export *exp, ptlrpc_reconnect_import(imp); return 0; } - /* FIXME move this to mgc_process_config */ - if (KEY_IS(KEY_REGISTER_TARGET)) { - struct mgs_target_info *mti; - if (vallen != sizeof(struct mgs_target_info)) - return -EINVAL; - mti = (struct mgs_target_info *)val; - CDEBUG(D_MGC, "register_target %s %#x\n", - mti->mti_svname, mti->mti_flags); - rc = mgc_target_register(exp, mti); - return rc; - } - if (KEY_IS(KEY_SET_FS)) { - struct super_block *sb = (struct super_block *)val; - - if (vallen != sizeof(struct super_block)) - return -EINVAL; - - rc = mgc_fs_setup(exp->exp_obd, sb); - if (rc) - CERROR("set_fs got %d\n", rc); - - return rc; - } - if (KEY_IS(KEY_CLEAR_FS)) { - if (vallen != 0) - return -EINVAL; - rc = mgc_fs_cleanup(exp->exp_obd); - if (rc) - CERROR("clear_fs got %d\n", rc); - - return rc; - } if (KEY_IS(KEY_SET_INFO)) { struct mgs_send_param *msp; @@ -1504,13 +1327,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: @@ -1518,20 +1345,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; @@ -1540,8 +1371,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); @@ -1549,11 +1382,13 @@ 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 */ @@ -1564,16 +1399,20 @@ again: 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); @@ -1622,54 +1461,11 @@ out: return rc; } -static int mgc_llog_local_copy(const struct lu_env *env, - struct obd_device *obd, - struct llog_ctxt *rctxt, - struct llog_ctxt *lctxt, char *logname) -{ - char *temp_log; - int rc; - - - - /* - * - copy it to backup using llog_backup() - * - copy remote llog to logname using llog_backup() - * - if failed then move backup to logname again - */ - - OBD_ALLOC(temp_log, strlen(logname) + 1); - if (!temp_log) - return -ENOMEM; - sprintf(temp_log, "%sT", logname); - - /* 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); - /* copy remote llog to the local copy */ - rc = llog_backup(env, obd, rctxt, lctxt, logname, logname); - if (rc == -ENOENT) { - /* no remote llog, delete local one too */ - llog_erase(env, lctxt, NULL, logname); - } else if (rc < 0) { - /* error during backup, get local one back from the copy */ - llog_backup(env, obd, lctxt, lctxt, temp_log, logname); -out: - CERROR("%s: failed to copy remote log %s: rc = %d\n", - obd->obd_name, logname, rc); - } - llog_erase(env, lctxt, NULL, temp_log); - OBD_FREE(temp_log, strlen(logname) + 1); - return rc; -} - /* local_only means it cannot get remote llogs */ static int mgc_process_cfg_log(struct obd_device *mgc, struct config_llog_data *cld, int local_only) { - struct llog_ctxt *ctxt, *lctxt = NULL; - struct dt_object *cl_mgc_dir = mgc->u.cli.cl_mgc_configs_dir; + struct llog_ctxt *ctxt; struct lustre_sb_info *lsi = NULL; int rc = 0; bool sptlrpc_started = false; @@ -1694,42 +1490,14 @@ 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); - lctxt = llog_get_context(mgc, LLOG_CONFIG_ORIG_CTXT); - - /* Copy the setup log locally if we can. Don't mess around if we're - * running an MGS though (logs are already local). */ - if (lctxt && lsi && IS_SERVER(lsi) && !IS_MGS(lsi) && - cl_mgc_dir != NULL && - lu2dt_dev(cl_mgc_dir->do_lu.lo_dev) == lsi->lsi_dt_dev) { - if (!local_only) - /* Only try to copy log if we have the lock. */ - rc = mgc_llog_local_copy(env, mgc, ctxt, lctxt, - cld->cld_logname); - if (local_only || rc) { - if (llog_is_empty(env, lctxt, cld->cld_logname)) { - LCONSOLE_ERROR_MSG(0x13a, - "Failed to get MGS log %s and no local copy.\n", - cld->cld_logname); - GOTO(out_pop, rc = -ENOENT); - } - CDEBUG(D_MGC, - "Failed to get MGS log %s, using local copy for now, will try to update later.\n", - cld->cld_logname); - } - /* Now, whether we copied or not, start using the local llog. - * If we failed to copy, we'll start using whatever the old - * log has. */ - llog_ctxt_put(ctxt); - 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)) { @@ -1745,8 +1513,6 @@ static int mgc_process_cfg_log(struct obd_device *mgc, out_pop: __llog_ctxt_put(env, ctxt); - if (lctxt) - __llog_ctxt_put(env, lctxt); /* * update settings on existing OBDs. doing it inside @@ -1829,12 +1595,8 @@ int mgc_process_log(struct obd_device *mgc, struct config_llog_data *cld) mutex_unlock(&cld->cld_lock); /* Now drop the lock so MGS can revoke it */ - if (!rcl) { - rcl = mgc_cancel(mgc->u.cli.cl_mgc_mgsexp, NULL, - LCK_CR, &lockh); - if (rcl) - CERROR("Can't drop cfg lock: %d\n", rcl); - } + if (!rcl) + ldlm_lock_decref(&lockh, LCK_CR); return rc; } @@ -1844,7 +1606,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; @@ -1857,8 +1619,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", @@ -1943,7 +1707,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; } } @@ -1961,7 +1726,6 @@ struct obd_ops mgc_obd_ops = { .o_connect = client_connect_import, .o_disconnect = client_disconnect_export, /* .o_enqueue = mgc_enqueue, */ - .o_cancel = mgc_cancel, /* .o_iocontrol = mgc_iocontrol, */ .o_set_info_async = mgc_set_info_async, .o_get_info = mgc_get_info, |