mgs_handler.c
来自「lustre 1.6.5 source code」· C语言 代码 · 共 773 行 · 第 1/2 页
C
773 行
/* Log writing contention is handled by the fsdb_sem */ if (mti->mti_flags & LDD_F_WRITECONF) { if (mti->mti_flags & LDD_F_SV_TYPE_MDT) { rc = mgs_erase_logs(obd, mti->mti_fsname); LCONSOLE_WARN("%s: Logs for fs %s were removed by user " "request. All servers must be restarted " "in order to regenerate the logs." "\n", obd->obd_name, mti->mti_fsname); } else if (mti->mti_flags & LDD_F_SV_TYPE_OST) { rc = mgs_erase_log(obd, mti->mti_svname); LCONSOLE_WARN("%s: Regenerating %s log by user " "request.\n", obd->obd_name, mti->mti_svname); } mti->mti_flags |= LDD_F_UPDATE; /* Erased logs means start from scratch. */ mti->mti_flags &= ~LDD_F_UPGRADE14; } /* COMPAT_146 */ if (mti->mti_flags & LDD_F_UPGRADE14) { rc = mgs_upgrade_sv_14(obd, mti); if (rc) { CERROR("Can't upgrade from 1.4 (%d)\n", rc); GOTO(out, rc); } /* We're good to go */ mti->mti_flags |= LDD_F_UPDATE; } /* end COMPAT_146 */ if (mti->mti_flags & LDD_F_UPDATE) { CDEBUG(D_MGS, "updating %s, index=%d\n", mti->mti_svname, mti->mti_stripe_index); /* create or update the target log and update the client/mdt logs */ rc = mgs_write_log_target(obd, mti); if (rc) { CERROR("Failed to write %s log (%d)\n", mti->mti_svname, rc); GOTO(out, rc); } mti->mti_flags &= ~(LDD_F_VIRGIN | LDD_F_UPDATE | LDD_F_NEED_INDEX | LDD_F_WRITECONF | LDD_F_UPGRADE14); mti->mti_flags |= LDD_F_REWRITE_LDD; }out: /* done with log update */ if (lockrc == ELDLM_OK) mgs_put_cfg_lock(&lockh);out_nolock: CDEBUG(D_MGS, "replying with %s, index=%d, rc=%d\n", mti->mti_svname, mti->mti_stripe_index, rc); lustre_pack_reply(req, 2, rep_size, NULL); /* send back the whole mti in the reply */ rep_mti = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*rep_mti)); memcpy(rep_mti, mti, sizeof(*rep_mti)); /* Flush logs to disk */ fsfilt_sync(obd, obd->u.mgs.mgs_sb); RETURN(rc);}static int mgs_set_info_rpc(struct ptlrpc_request *req){ struct obd_device *obd = req->rq_export->exp_obd; struct mgs_send_param *msp, *rep_msp; struct lustre_handle lockh; int rep_size[] = { sizeof(struct ptlrpc_body), sizeof(*msp) }; int lockrc, rc; struct lustre_cfg_bufs bufs; struct lustre_cfg *lcfg; char fsname[MTI_NAME_MAXLEN]; ENTRY; msp = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*msp), NULL); /* Construct lustre_cfg structure to pass to function mgs_setparam */ lustre_cfg_bufs_reset(&bufs, NULL); lustre_cfg_bufs_set_string(&bufs, 1, msp->mgs_param); lcfg = lustre_cfg_new(LCFG_PARAM, &bufs); rc = mgs_setparam(obd, lcfg, fsname); if (rc) { CERROR("Error %d in setting the parameter %s for fs %s\n", rc, msp->mgs_param, fsname); RETURN(rc); } /* Revoke lock so everyone updates. Should be alright if * someone was already reading while we were updating the logs, * so we don't really need to hold the lock while we're * writing. */ if (fsname[0]) { lockrc = mgs_get_cfg_lock(obd, fsname, &lockh); if (lockrc != ELDLM_OK) CERROR("lock error %d for fs %s\n", lockrc, fsname); else mgs_put_cfg_lock(&lockh); } lustre_cfg_free(lcfg); lustre_pack_reply(req, 2, rep_size, NULL); rep_msp = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*rep_msp)); memcpy(rep_msp, msp, sizeof(*rep_msp)); RETURN(rc);}/* Called whenever a target cleans up. *//* XXX - Currently unused */static int mgs_handle_target_del(struct ptlrpc_request *req){ ENTRY; mgs_counter_incr(req->rq_export, LPROC_MGS_TARGET_DEL); RETURN(0);}/* XXX - Currently unused */static int mgs_handle_exception(struct ptlrpc_request *req){ ENTRY; mgs_counter_incr(req->rq_export, LPROC_MGS_EXCEPTION); RETURN(0);}int mgs_handle(struct ptlrpc_request *req){ int fail = OBD_FAIL_MGS_ALL_REPLY_NET; int opc, rc = 0; ENTRY; OBD_FAIL_TIMEOUT_MS(OBD_FAIL_MGS_PAUSE_REQ, obd_fail_val); OBD_FAIL_RETURN(OBD_FAIL_MGS_ALL_REQUEST_NET, 0); LASSERT(current->journal_info == NULL); opc = lustre_msg_get_opc(req->rq_reqmsg); if (opc != MGS_CONNECT) { if (req->rq_export == NULL) { CERROR("lustre_mgs: operation %d on unconnected MGS\n", opc); req->rq_status = -ENOTCONN; GOTO(out, rc = -ENOTCONN); } } switch (opc) { case MGS_CONNECT: DEBUG_REQ(D_MGS, req, "connect"); rc = target_handle_connect(req, mgs_handle); if (!rc && (lustre_msg_get_conn_cnt(req->rq_reqmsg) > 1)) /* Make clients trying to reconnect after a MGS restart happy; also requires obd_replayable */ lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECONNECT); break; case MGS_DISCONNECT: DEBUG_REQ(D_MGS, req, "disconnect"); rc = target_handle_disconnect(req); req->rq_status = rc; /* superfluous? */ break; case MGS_EXCEPTION: DEBUG_REQ(D_MGS, req, "exception"); rc = mgs_handle_exception(req); break; case MGS_TARGET_REG: DEBUG_REQ(D_MGS, req, "target add"); rc = mgs_handle_target_reg(req); break; case MGS_TARGET_DEL: DEBUG_REQ(D_MGS, req, "target del"); rc = mgs_handle_target_del(req); break; case MGS_SET_INFO: rc = mgs_set_info_rpc(req); break; case LDLM_ENQUEUE: DEBUG_REQ(D_MGS, req, "enqueue"); rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast, ldlm_server_blocking_ast, NULL); break; case LDLM_BL_CALLBACK: case LDLM_CP_CALLBACK: DEBUG_REQ(D_MGS, req, "callback"); CERROR("callbacks should not happen on MGS\n"); LBUG(); break; case OBD_PING: DEBUG_REQ(D_INFO, req, "ping"); rc = target_handle_ping(req); break; case OBD_LOG_CANCEL: DEBUG_REQ(D_MGS, req, "log cancel"); rc = -ENOTSUPP; /* la la la */ break; case LLOG_ORIGIN_HANDLE_CREATE: DEBUG_REQ(D_MGS, req, "llog_init"); rc = llog_origin_handle_create(req); break; case LLOG_ORIGIN_HANDLE_NEXT_BLOCK: DEBUG_REQ(D_MGS, req, "llog next block"); rc = llog_origin_handle_next_block(req); break; case LLOG_ORIGIN_HANDLE_READ_HEADER: DEBUG_REQ(D_MGS, req, "llog read header"); rc = llog_origin_handle_read_header(req); break; case LLOG_ORIGIN_HANDLE_CLOSE: DEBUG_REQ(D_MGS, req, "llog close"); rc = llog_origin_handle_close(req); break; case LLOG_CATINFO: DEBUG_REQ(D_MGS, req, "llog catinfo"); rc = llog_catinfo(req); break; default: req->rq_status = -ENOTSUPP; rc = ptlrpc_error(req); RETURN(rc); } LASSERT(current->journal_info == NULL); if (rc) CERROR("MGS handle cmd=%d rc=%d\n", opc, rc); out: target_send_reply(req, rc, fail); RETURN(0);}static inline int mgs_destroy_export(struct obd_export *exp){ ENTRY; target_destroy_export(exp); mgs_client_free(exp); RETURN(0);}/* from mdt_iocontrol */int mgs_iocontrol(unsigned int cmd, struct obd_export *exp, int len, void *karg, void *uarg){ struct obd_device *obd = exp->exp_obd; struct obd_ioctl_data *data = karg; struct lvfs_run_ctxt saved; int rc = 0; ENTRY; CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd); switch (cmd) { case OBD_IOC_PARAM: { struct lustre_handle lockh; struct lustre_cfg *lcfg; struct llog_rec_hdr rec; char fsname[MTI_NAME_MAXLEN]; int lockrc; rec.lrh_len = llog_data_len(data->ioc_plen1); if (data->ioc_type == LUSTRE_CFG_TYPE) { rec.lrh_type = OBD_CFG_REC; } else { CERROR("unknown cfg record type:%d \n", data->ioc_type); RETURN(-EINVAL); } OBD_ALLOC(lcfg, data->ioc_plen1); if (lcfg == NULL) RETURN(-ENOMEM); rc = copy_from_user(lcfg, data->ioc_pbuf1, data->ioc_plen1); if (rc) GOTO(out_free, rc); if (lcfg->lcfg_bufcount < 1) GOTO(out_free, rc = -EINVAL); rc = mgs_setparam(obd, lcfg, fsname); if (rc) { CERROR("setparam err %d\n", rc); GOTO(out_free, rc); } /* Revoke lock so everyone updates. Should be alright if someone was already reading while we were updating the logs, so we don't really need to hold the lock while we're writing (above). */ if (fsname[0]) { lockrc = mgs_get_cfg_lock(obd, fsname, &lockh); if (lockrc != ELDLM_OK) CERROR("lock error %d for fs %s\n", lockrc, fsname); else mgs_put_cfg_lock(&lockh); }out_free: OBD_FREE(lcfg, data->ioc_plen1); RETURN(rc); } case OBD_IOC_DUMP_LOG: { struct llog_ctxt *ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT); push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); rc = class_config_dump_llog(ctxt, data->ioc_inlbuf1, NULL); pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); llog_ctxt_put(ctxt); if (rc) RETURN(rc); RETURN(rc); } case OBD_IOC_LLOG_CHECK: case OBD_IOC_LLOG_INFO: case OBD_IOC_LLOG_PRINT: { struct llog_ctxt *ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT); push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL); rc = llog_ioctl(ctxt, cmd, data); pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL); llog_ctxt_put(ctxt); RETURN(rc); } default: CDEBUG(D_INFO, "unknown command %x\n", cmd); RETURN(-EINVAL); } RETURN(0);}/* use obd ops to offer management infrastructure */static struct obd_ops mgs_obd_ops = { .o_owner = THIS_MODULE, .o_connect = mgs_connect, .o_disconnect = mgs_disconnect, .o_setup = mgs_setup, .o_precleanup = mgs_precleanup, .o_cleanup = mgs_cleanup, .o_destroy_export = mgs_destroy_export, .o_iocontrol = mgs_iocontrol,};static int __init mgs_init(void){ struct lprocfs_static_vars lvars; lprocfs_mgs_init_vars(&lvars); class_register_type(&mgs_obd_ops, lvars.module_vars, LUSTRE_MGS_NAME); return 0;}static void /*__exit*/ mgs_exit(void){ class_unregister_type(LUSTRE_MGS_NAME);}MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");MODULE_DESCRIPTION("Lustre Management Server (MGS)");MODULE_LICENSE("GPL");module_init(mgs_init);module_exit(mgs_exit);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?