ceph_mount流程
mount -t ceph $(hostname):6789:/ /mnt/ceph/ -o name=admin,secret=$(ceph auth get-key client.admin)
执行这条ceph挂载命令时会发生什么?
/var/log/messages
中只看到这两条相关日志,但远远不够,准备看看内核代码打开内核日志调试继续
Nov xx 11:03:56 node1 kernel: libceph: mon0 192.xxx.xxx.xxx:6789 session established
Nov xx 11:03:56 node1 kernel: libceph: client50981349 fsid ed69ef4c-63ed-436f-a733-c53c0037105d
日志级别可以通过/proc/sys/kernel/printk
文件来修改
先来看看这个文件初始是什么样子
[root@node1 ~]# cat /proc/sys/kernel/printk
4 4 1 7
这四个值的定义可以在kernel/printk.c
中找到
int console_printk[4] = {
DEFAULT_CONSOLE_LOGLEVEL, /* console_loglevel */
DEFAULT_MESSAGE_LOGLEVEL, /* default_message_loglevel */
MINIMUM_CONSOLE_LOGLEVEL, /* minimum_console_loglevel */
DEFAULT_CONSOLE_LOGLEVEL, /* default_console_loglevel */
};
而内核日志级别有以下七种
#define KERN_EMERG KERN_SOH "0" /* system is unusable */
#define KERN_ALERT KERN_SOH "1" /* action must be taken immediately */
#define KERN_CRIT KERN_SOH "2" /* critical conditions */
#define KERN_ERR KERN_SOH "3" /* error conditions */
#define KERN_WARNING KERN_SOH "4" /* warning conditions */
#define KERN_NOTICE KERN_SOH "5" /* normal but significant condition */
#define KERN_INFO KERN_SOH "6" /* informational */
#define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
#define KERN_DEFAULT KERN_SOH "d" /* the default kernel loglevel */
只需要调整对应数字就可以,比如
echo 7 7 1 7 > /proc/sys/kernel/printk
修改完成后,通过 sysctl -p 应用配置
方法二:
确保/etc/rsyslog.conf文件中 #kern.* 注释被取消!
systemctl restart rsyslog
这样内核产生的所有日志信息都会被记录到 后面文件中,包括 dout 产生的调试信息。
补充:
dmesg
的信息在环缓冲区中,只包含最新的内核日志;
/var/log/messages
是磁盘上的文件,保留较长时间的日志记录。
接下来看代码!!!
ceph mount
过程,主要在fs/ceph/super.c
文件中,从init_ceph
开始
static int __init init_ceph(void)
{
int ret = init_caches();
if (ret)
goto out;
ceph_flock_init();
ceph_xattr_init();
ret = register_filesystem(&ceph_fs_type);
if (ret)
goto out_xattr;
ret = ceph_register_sysctl();
if (ret < 0)
goto out_fs;
pr_info("loaded (mds proto %d)\n", CEPH_MDSC_PROTOCOL);
return 0;
out_fs:
unregister_filesystem(&ceph_fs_type);
out_xattr:
ceph_xattr_exit();
destroy_caches();
out:
return ret;
}
进入到register_filesystem(&ceph_fs_type)
,注册ceph文件系统
static struct file_system_type ceph_fs_type = {
.owner = THIS_MODULE,
.name = "ceph",
.mount = ceph_mount,
.kill_sb = ceph_kill_sb,
.fs_flags = FS_RENAME_DOES_D_MOVE,
};
ceph_mount
进行初始化挂载,会解析挂载选项,创建文件客户端,初始化mds客户端,然后进入到ceph_real_mount
static struct dentry *ceph_mount(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
{
struct super_block *sb;
struct ceph_fs_client *fsc;
struct dentry *res;
int err;
int (*compare_super)(struct super_block *, void *) = ceph_compare_super;
struct ceph_mount_options *fsopt = NULL;
struct ceph_options *opt = NULL;
dout("ceph_mount\n");
#ifdef CONFIG_CEPH_FS_POSIX_ACL
flags |= MS_POSIXACL;
#endif
err = parse_mount_options(&fsopt, &opt, flags, data, dev_name);
if (err < 0) {
res = ERR_PTR(err);
goto out_final;
}
/* create client (which we may/may not use) */
fsc = create_fs_client(fsopt, opt);
if (IS_ERR(fsc)) {
res = ERR_CAST(fsc);
destroy_mount_options(fsopt);
ceph_destroy_options(opt);
goto out_final;
}
err = ceph_mdsc_init(fsc);
if (err < 0) {
res = ERR_PTR(err);
goto out;
}
if (ceph_test_opt(fsc->client, NOSHARE))
compare_super = NULL;
sb = sget(fs_type, compare_super, ceph_set_super, flags, fsc);
if (IS_ERR(sb)) {
res = ERR_CAST(sb);
goto out;
}
if (ceph_sb_to_client(sb) != fsc) {
ceph_mdsc_destroy(fsc);
destroy_fs_client(fsc);
fsc = ceph_sb_to_client(sb);
dout("get_sb got existing client %p\n", fsc);
} else {
dout("get_sb using new client %p\n", fsc);
err = ceph_register_bdi(sb, fsc);
if (err < 0) {
res = ERR_PTR(err);
goto out_splat;
}
}
res = ceph_real_mount(fsc);
if (IS_ERR(res))
goto out_splat;
dout("root %p inode %p ino %llx.%llx\n", res,
res->d_inode, ceph_vinop(res->d_inode));
return res;
out_splat:
ceph_mdsc_close_sessions(fsc->mdsc);
deactivate_locked_super(sb);
goto out_final;
out:
ceph_mdsc_destroy(fsc);
destroy_fs_client(fsc);
out_final:
dout("ceph_mount fail %ld\n", PTR_ERR(res));
return res;
}
ceph_real_mount
标签:KERN,fsc,res,mount,ceph,out
From: https://www.cnblogs.com/itsfei/p/18560723