使用glusterfs3.3-release版本进行分析,ls命令执行后,抓取trace, 分析glusterfs的代码处理过程,用一台centos6.2虚拟机进行即可,创建卷及挂载过程步骤如下:
1. 官网下载release版本路径如下:http://www.gluster.org,下载后解压,然后我们先打入一个patch,使能glusterfs各个translator调用的trace,patch如下:
--- /root/stack.h 2013-06-13 00:57:40.244154611 -0700
+++ libglusterfs/src/stack.h 2013-06-07 01:10:59.752761043 -0700
@@ -248,6 +248,7 @@
} \
UNLOCK(&frame->root->stack_lock); \
old_THIS = THIS; \
+ gf_log(old_THIS->name, GF_LOG_TRACE, " enter stack"); \
THIS = obj; \
fn (_new, obj, params); \
THIS = old_THIS; \
@@ -287,6 +288,7 @@
UNLOCK(&frame->root->stack_lock); \
fn##_cbk = rfn; \
old_THIS = THIS; \
+ gf_log(old_THIS->name, GF_LOG_TRACE, " enter stack cookie"); \
THIS = obj; \
fn (_new, obj, params); \
THIS = old_THIS; \
@@ -311,6 +313,7 @@
} \
UNLOCK(&frame->root->stack_lock); \
old_THIS = THIS; \
+ gf_log(old_THIS->name, GF_LOG_TRACE, " exit stack"); \
THIS = _parent->this; \
frame->complete = _gf_true; \
frame->unwind_from = __FUNCTION__; \
@@ -338,6 +341,7 @@
} \
UNLOCK(&frame->root->stack_lock); \
old_THIS = THIS; \
+ gf_log(old_THIS->name, GF_LOG_TRACE, " exit stack strict"); \
THIS = _parent->this; \
frame->complete = _gf_true; \
frame->unwind_from = __FUNCTION__; \
从patch上可以看到,关键之处在STACK_WIND/UNWIND函数调用上加入trace信息,打入patch后,继续执行如下命令安装:
执行./autogen.sh && ./configure --enable-fusermount && make && make install
2. 启动glusterd
/etc/init.d/glusterd start
3.创建两个本地目录
mkdir /root/server-data1 /root/server-data2
4.创建客户端挂载的目录
mkdir /root/client-data
5.创建glusterfs卷(tcp+replictaion卷)
gluster volume create volume-rep replica 2 transport tcp localhost.localdomain:/root/server-data1 localhost.localdomain:/root/server-data2
6.启动卷
gluster volume start volume-rep
7.挂载卷(使用glusterfs-native 客户端协议)
mount -t glusterfs -o log-file=/var/log/gluster.log,log-level=TRACE localhost.localdomain:/volume-rep /root/client-data
[注意:log-level使用TRACE级别,或者默认方式,后面可以执行gluster volume set debug-gluster diagnostics.client-log-level TRACE 动态配置]
此后,我们所做的所有操作,都会记录在gluster.log文件中。
8.进入挂载目录/root/client-data中,执行touch test.txt文件,然后ls 执行后,我们可以打开gluster.log文件分析一下 ls命令在glusterfs文件系统协议中处理的全过程,日志及分析如下:
【注:】
通过下面的详细log分析,我们可以对应到代码函数进行细粒度分析,会发现虽然我们只建立了replication+tcp卷,实际内部默认配置了多个translator,总结如下,客户端translator的路径列举如下
fuse(client) -> io-stats(client)->md-cache(client)->quick-read(client)->io-cache(client)->defaults(client)->dht(client)->afr(client)->
rpc-clnt (client) .
P.S.: 后续我们再分析server端的处理路径
[2013-06-07 08:52:54.477283] T [fuse-bridge.c:597:fuse_getattr] 0-fuse: enter stack
[2013-06-07 08:52:54.477309] T [io-stats.c:1855:io_stats_lookup] 0-debug-gluster-rep: enter stack
[2013-06-07 08:52:54.477328] T [md-cache.c:733:mdc_lookup] 0-debug-gluster-rep-md-cache: enter stack
[2013-06-07 08:52:54.477341] T [quick-read.c:563:qr_lookup] 0-debug-gluster-rep-quick-read: enter stack
[2013-06-07 08:52:54.477351] T [io-cache.c:284:ioc_lookup] 0-debug-gluster-rep-io-cache: enter stack
[2013-06-07 08:52:54.477359] T [defaults.c:1241:default_lookup] 0-debug-gluster-rep-read-ahead: enter stack
[2013-06-07 08:52:54.477367] T [defaults.c:1241:default_lookup] 0-debug-gluster-rep-write-behind: enter stack
[2013-06-07 08:52:54.477382] T [dht-common.c:1414:dht_lookup] 0-debug-gluster-rep-dht: enter stack
[2013-06-07 08:52:54.477408] T [afr-common.c:2187:afr_lookup] 0-debug-gluster-rep-replicate-0: enter stack cookie
[2013-06-07 08:52:54.477473] T [rpc-clnt.c:1305:rpc_clnt_record] 0-debug-gluster-rep-client-0: Auth Info: pid: 3161, uid: 0, gid: 0, owner: 00000
00000000000
[2013-06-07 08:52:54.477491] T [rpc-clnt.c:1185:rpc_clnt_record_build_header] 0-rpc-clnt: Request fraglen 600, payload: 504, rpc hdr: 96
[2013-06-07 08:52:54.477538] T [rpc-clnt.c:1504:rpc_clnt_submit] 0-rpc-clnt: submitte