MGC(management client)
、MDC(metadata client)
、若干个OSC(object storage client)
。客户端中每个osc对应后端lustre的ost.MGC
管理客户端是作为整个lustre vfs和MGS(lustre management server)之间的接口.lustre通过MGT后端设备注册MGS,后续客户端请求MGS来获取文件系统信息[ ~/lustre-2.14.52/lustre/mgc]$ ls -l -1h
Makefile.in
autoMakefile.am
lproc_mgc.c
mgc_internal.h
mgc_request.c
// MGC的数据操作的函数定义表
static const struct obd_ops mgc_obd_ops = {
.o_owner = THIS_MODULE,
.o_setup = mgc_setup,
.o_precleanup = mgc_precleanup,
.o_cleanup = mgc_cleanup,
.o_add_conn = client_import_add_conn,
.o_del_conn = client_import_del_conn,
.o_connect = client_connect_import,
.o_disconnect = client_disconnect_export,
.o_set_info_async = mgc_set_info_async,
.o_get_info = mgc_get_info,
.o_import_event = mgc_import_event,
.o_process_config = mgc_process_config,
};
// MGC的内核模块初始化函数
static int __init mgc_init(void)
{
return class_register_type(&mgc_obd_ops, NULL, false,
LUSTRE_MGC_NAME, NULL);
}
// MGC内核模块退出的函数
static void __exit mgc_exit(void)
{
class_unregister_type(LUSTRE_MGC_NAME);
}
MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
MODULE_DESCRIPTION("Lustre Management Client");
MODULE_VERSION(LUSTRE_VERSION_STRING);
MODULE_LICENSE("GPL");
module_init(mgc_init);
module_exit(mgc_exit);
mgc_obd_ops
函数操作表来操作MGC的涉及到的操作。1.lustre_init :lustre客户端进行mount时候初始化函数,这里涉及到的是lustre文件系统的注册(lustre_fs_type)
2.lustre_mount:当用户态执行mount时候,会调用lustre_mount来做
mount的过程
3.lustre_fill_super:客户端挂载点的mount执行
4.lustre_start_mgc:设置MGC的OBD设备处理启动的日志
5.lustre_start_simple:启动MDC的OBD,通过调用do_lcfg根据不同的命令操作MDC OBD
6.class_process_config:根据cmd初始化lustre_cfg配置MDC OBD.分别调用class_attach(),class_setup()注册和设置MDC OBD.class_attch函数调用class_register_device来注册lustre的MDC OBD.class_setup函数来设置MDC的OBD.这里class_setup实际调用的是mgc_setup.
// 启动lustre client 中的mgc
int lustre_start_mgc(struct super_block *sb)
{
// 注册mdc obd和设置mdc obd
rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME,
(char *)uuid->uuid, LUSTRE_MGS_OBDNAME,
niduuid, NULL, NULL);
// 设置完成连接到mgs
rc = obd_connect(NULL, &exp, obd, uuid, data, NULL);
}
int class_process_config(struct lustre_cfg *lcfg)
{
struct obd_device *obd;
int err;
LASSERT(lcfg && !IS_ERR(lcfg));
CDEBUG(D_IOCTL, "processing cmd: %x\n", lcfg->lcfg_command);
// 根据lcfg_commond注册MDC OBD
switch (lcfg->lcfg_command) {
case LCFG_ATTACH: {
err = class_attach(lcfg);
GOTO(out, err);
}
}
// 根据MDC设置的数据操作参数表,调用mgc_setup设置
switch(lcfg->lcfg_command) {
case LCFG_SETUP: {
err = class_setup(obd, lcfg);
GOTO(out, err);
}
}
}
// 根据配置进行处理
static int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
char *s1, char *s2, char *s3, char *s4)
{
rc = class_process_config(lcfg);
OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
return rc;
}
// 启动mgc的核心函数
int lustre_start_simple(char *obdname, char *type, char *uuid,
char *s1, char *s2, char *s3, char *s4)
{
int rc;
CDEBUG(D_MOUNT, "Starting OBD %s (typ=%s)\n", obdname, type);
// mdc OBD分为2个阶段处理,LCFG_ATTACH命令是进行注册
rc = do_lcfg(obdname, 0, LCFG_ATTACH, type, uuid, NULL, NULL);
if (rc) {
CERROR("%s attach error %d\n", obdname, rc);
return rc;
}
// LCFG_SETUP是调用具体的mgc模块的mgc_setup进行设置
rc = do_lcfg(obdname, 0, LCFG_SETUP, s1, s2, s3, s4);
if (rc) {
CERROR("%s setup error %d\n", obdname, rc);
do_lcfg(obdname, 0, LCFG_DETACH, NULL, NULL, NULL, NULL);
}
return rc;
}
static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
{
struct task_struct *task;
int rc;
ENTRY;
// 初始化一个rpc
rc = ptlrpcd_addref();
if (rc < 0)
RETURN(rc);
// mdc设置rpc
rc = client_obd_setup(obd, lcfg);
if (rc)
GOTO(err_decref, rc);
// mdc处理MGS发过来的log
rc = mgc_llog_init(NULL, obd);
if (rc) {
CERROR("failed to setup llogging subsystems\n");
GOTO(err_cleanup, rc);
}
// 默认参数的初始化
rc = mgc_tunables_init(obd);
if (rc)
GOTO(err_sysfs, rc);
if (atomic_inc_return(&mgc_count) == 1) {
rq_state = 0;
init_waitqueue_head(&rq_waitq);
// 启动内核线程来运行mgc_requeue_thread
task = kthread_run(mgc_requeue_thread, NULL, "ll_cfg_requeue");
if (IS_ERR(task)) {
rc = PTR_ERR(task);
CERROR("%s: cannot start requeue thread: rc = %d; "
"no more log updates\n",
obd->obd_name, rc);
GOTO(err_sysfs, rc);
}
/* rc is the task_struct pointer of mgc_requeue_thread. */
rc = 0;
wait_for_completion(&rq_start);
}
RETURN(rc);
err_sysfs:
lprocfs_obd_cleanup(obd);
err_cleanup:
client_obd_cleanup(obd);
err_decref:
ptlrpcd_decref();
RETURN(rc);
}
static int mgc_requeue_thread(void *data)
{
rq_state |= RQ_RUNNING;
while (!(rq_state & RQ_STOP)) {
struct config_llog_data *cld, *cld_prev;
// 休眠每次循环时间间隔
to = cfs_time_seconds(MGC_TIMEOUT_MIN_SECONDS * 100 + rand);
/* rand is centi-seconds */
wait_event_idle_timeout(rq_waitq,
rq_state & (RQ_STOP | RQ_PRECLEANUP),
to/100);
// 处理当前来自mgs的log
do_requeue(cld) {
mgc_process_log(...)
}
}
}
obd_import_event
定义 enum obd_import_event {
IMP_EVENT_DISCON = 0x808001,
IMP_EVENT_INACTIVE = 0x808002,
IMP_EVENT_INVALIDATE = 0x808003,
IMP_EVENT_ACTIVE = 0x808004,
IMP_EVENT_OCD = 0x808005,
IMP_EVENT_DEACTIVATE = 0x808006,
IMP_EVENT_ACTIVATE = 0x808007,
};