Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1489038
  • 博文数量: 230
  • 博客积分: 474
  • 博客等级: 下士
  • 技术积分: 1955
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-19 18:40
文章分类

全部博文(230)

文章存档

2020年(3)

2019年(3)

2018年(12)

2017年(13)

2016年(11)

2015年(55)

2014年(74)

2013年(39)

2012年(2)

2011年(18)

我的朋友

分类: 云计算

2014-05-30 14:58:50

查看更多,请猛点向glusterfs中增加xlator(一)
前面已经介绍过,glusterfs中主线为xlator,几乎每一个大的功能点,或者性能,都可以以xlator形式参与进glusterfs中,那么xlator的开发就必不可少,所以,这里介绍一下简单的向glusterfs中增加xlator的方法,首先创建一个卷testvol

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
[root@CM addxlator]# mkdir /opt/test
[root@CM addxlator]# gluster volume create testvol 192.168.0.194:/opt/test force
volume create: testvol: success: please start the volume to access data
[root@CM addxlator]# gluster volume info all
  
Volume Name: testvol
Type: Distribute
Volume ID: f0ef2a09-09c0-4a84-aeb6-3f2e0aebf4c2
Status: Created
Number of Bricks: 1
Transport-type: tcp
Bricks:
Brick1: 192.168.0.194:/opt/test
[root@CM addxlator]#
[root@CM addxlator]# gluster volume start testvol force
volume start: testvol: success
[root@CM addxlator]#
创建成功后,可以查看volume file中的内容
 cat /var/lib/glusterd/vols/testvol/testvol-fuse.vol 
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
volume testvol-client-0
    type protocol/client
    option transport-type tcp
    option remote-subvolume /opt/test
    option remote-host 192.168.0.194
end-volume
 
volume testvol-dht
    type cluster/distribute
    subvolumes testvol-client-0
end-volume
 
volume testvol-write-behind
    type performance/write-behind
    subvolumes testvol-dht
end-volume
 
volume testvol-read-ahead
    type performance/read-ahead
    subvolumes testvol-write-behind
end-volume
 
volume testvol-io-cache
    type performance/io-cache
    subvolumes testvol-read-ahead
end-volume
 
volume testvol-quick-read
    type performance/quick-read
    subvolumes testvol-io-cache
end-volume
 
volume testvol-open-behind
    type performance/open-behind
    subvolumes testvol-quick-read
end-volume
 
volume testvol-md-cache
    type performance/md-cache
    subvolumes testvol-open-behind
end-volume
 
volume testvol
    type debug/io-stats
    option count-fop-hits off
    option latency-measurement off
    subvolumes testvol-md-cache
end-volume
这个配置为默认的配置,接下来需要将自己的xlator增加入该配置中,根据之前所提到过的xlator_dyload的过程,需要修改这个volume file,来增加xlator,修改配置如下:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
volume testvol-client-0
    type protocol/client
    option transport-type tcp
    option remote-subvolume /opt/test
    option remote-host 192.168.0.194
end-volume
 
volume testvol-dht
    type cluster/distribute
    subvolumes testvol-client-0
end-volume
 
volume testvol-write-behind
    type performance/write-behind
    subvolumes testvol-dht
end-volume
 
volume testvol-read-ahead
    type performance/read-ahead
    subvolumes testvol-write-behind
end-volume
 
volume testvol-io-cache
    type performance/io-cache
    subvolumes testvol-read-ahead
end-volume
 
volume testvol-quick-read
    type performance/quick-read
    subvolumes testvol-io-cache
end-volume
 
volume testvol-open-behind
    type performance/open-behind
    subvolumes testvol-quick-read
end-volume
 
volume testvol-md-cache
    type performance/md-cache
    subvolumes testvol-open-behind
end-volume volume testvol-test
    type debug/test
    subvolumes testvol-md-cache
end-volume volume testvol
    type debug/io-stats
    option count-fop-hits off
    option latency-measurement off
    subvolumes testvol-test
end-volume
可以看到,配置中多了个testvol-test这么一层,接下来将glusterfs挂载至挂载点查看输出log
1
2
3
[root@CM addxlator]#
[root@CM addxlator]# mount -t glusterfs 192.168.0.194:testvol /media
[root@CM addxlator]#
查看gluster挂载到的挂载点对应的log输出信息
cat /usr/local/var/log/glusterfs/media.log
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
[2013-06-10 11:00:29.899440] I [glusterfsd.c:1878:main] 0-/usr/local/sbin/glusterfs: Started running /usr/local/sbin/glusterfs version 3git (/usr/local/sbin/glusterfs --volfile-id=testvol --volfile-server=192.168.0.194 /media)
[2013-06-10 11:00:29.903627] I [socket.c:3515:socket_init] 0-glusterfs: SSL support is NOT enabled
[2013-06-10 11:00:29.903823] I [socket.c:3530:socket_init] 0-glusterfs: using system polling thread
[2013-06-10 11:00:29.909423] E [test.c:54:init] 0-testvol-test: test translator loaded
[2013-06-10 11:00:29.909718] I [dht-shared.c:311:dht_init_regex] 0-testvol-dht: using regex rsync-hash-regex = ^\.(.+)\.[^.]+$
[2013-06-10 11:00:29.911047] I [socket.c:3515:socket_init] 0-testvol-client-0: SSL support is NOT enabled
[2013-06-10 11:00:29.911173] I [socket.c:3530:socket_init] 0-testvol-client-0: using system polling thread
[2013-06-10 11:00:29.911218] I [client.c:2236:notify] 0-testvol-client-0: parent translators are ready, attempting connect on transport
Final graph:
+------------------------------------------------------------------------------+
  1: volume testvol-client-0
  2:     type protocol/client
  3:     option remote-host 192.168.0.194
  4:     option remote-subvolume /opt/test
  5:     option transport-type socket
  6: end-volume
  7:
  8: volume testvol-dht
  9:     type cluster/distribute
 10:     subvolumes testvol-client-0
 11: end-volume
 12:
 13: volume testvol-write-behind
 14:     type performance/write-behind
 15:     subvolumes testvol-dht
 16: end-volume
 17:
 18: volume testvol-read-ahead
 19:     type performance/read-ahead
 20:     subvolumes testvol-write-behind
 21: end-volume
 22:
 23: volume testvol-io-cache
 24:     type performance/io-cache
 25:     subvolumes testvol-read-ahead
 26: end-volume
 27:
 28: volume testvol-quick-read
 29:     type performance/quick-read
 30:     subvolumes testvol-io-cache
 31: end-volume
 32:
 33: volume testvol-open-behind
 34:     type performance/open-behind
 35:     subvolumes testvol-quick-read
 36: end-volume
 37:
 38: volume testvol-md-cache
 39:     type performance/md-cache
 40:     subvolumes testvol-open-behind
 41: end-volume
 42:
 43: volume testvol-test
 44:     type debug/test
 45:     subvolumes testvol-md-cache
 46: end-volume
 47:
 48: volume testvol
 49:     type debug/io-stats
 50:     option latency-measurement off
 51:     option count-fop-hits off
 52:     subvolumes testvol-test
 53: end-volume
 54:
+------------------------------------------------------------------------------+
[2013-06-10 11:00:29.914847] I [rpc-clnt.c:1675:rpc_clnt_reconfig] 0-testvol-client-0: changing port to 49152 (from 0)
[2013-06-10 11:00:29.918227] I [client-handshake.c:1658:select_server_supported_programs] 0-testvol-client-0: Using Program GlusterFS 3.3, Num (1298437), Version (330)
[2013-06-10 11:00:29.918482] I [client-handshake.c:1456:client_setvolume_cbk] 0-testvol-client-0: Connected to 192.168.0.194:49152, attached to remote volume '/opt/test'.
[2013-06-10 11:00:29.918548] I [client-handshake.c:1468:client_setvolume_cbk] 0-testvol-client-0: Server and Client lk-version numbers are not same, reopening the fds
[2013-06-10 11:00:29.923683] I [fuse-bridge.c:4767:fuse_graph_setup] 0-fuse: switched to graph 0
[2013-06-10 11:00:29.923986] I [client-handshake.c:450:client_set_lk_version_cbk] 0-testvol-client-0: Server lk version = 1
[2013-06-10 11:00:29.924164] I [fuse-bridge.c:3724:fuse_init] 0-glusterfs-fuse: FUSE inited with protocol versions: glusterfs 7.13 kernel 7.13
[2013-06-10 11:00:29.924225] E [test.c:28:test_lookup] 0-testvol-test: in test translator lookup
[2013-06-10 11:00:29.925153] E [test.c:28:test_lookup] 0-testvol-test: in test translator lookup
经过查看log,可以看到test模块中的打印输出, in test translator lookup
接下来查看描述一下外挂xlator的方式
首先现在glusterfs的源代码,编译以后,在本地也就存在了glusterfs的开发环境,为了开发调试方便,可暂不将xlator存于glusterfs工程中,这时可以编写一个Makefile
首先建立一个目录
1
2
mkdir addxlator_sample
cd  addxlator_sample
Makefile中内容可如下:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#Add translator into glusterfs volume file
#Author Steven Liu
#E-mail lingjiujianke@gmail.com
 
TARGET  = test.so
OBJECTS = test.o
 
GLUSTERFS_SRC   = /opt/glusterfs
GLUSTERFS_LIB   = /usr/local/lib
HOST_OS = HF_LINUX_HOST_OS
 
CFLAGS  = -fPIC -Wall -O0 -g \
          -DHAVE_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D$(HOST_OS) \
          -I$(GLUSTERFS_SRC) -I$(GLUSTERFS_SRC)/libglusterfs/src \
          -I$(GLUSTERFS_SRC)/contrib/uuid
 
LDFLAGS = -shared -nostartfiles -L$(GLUSTERFS_LIB) -lglusterfs -lpthread
 
$(TARGET): $(OBJECTS)
    $(CC) $(OBJECTS) $(LDFLAGS) -o $(TARGET)
 
 
clean:
    rm -rf $(TARGET) $(OBJECTS)
Makefile编写完成之后,需要OBJECTS,这时需要编写test.c来保证编译通过,当然,test这个xlator也需要在这里生成
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#include "xlator.h"
#endif
 
#include
#include
#include "glusterfs.h"
#include "xlator.h"
#include
#include "defaults.h"
#include "logging.h"
 
int test_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
                     int32_t op_ret, int32_t op_errno,
                     inode_t *inode, struct iatt *buf,
                     dict_t *xdata, struct iatt *postparent)
{
        STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, inode, buf, xdata,
                             postparent);
        return 0;
}
 
 
static int test_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
    gf_log(this->name, GF_LOG_ERROR, "in test translator lookup");
    STACK_WIND (frame, test_lookup_cbk,
            FIRST_CHILD(this), FIRST_CHILD(this)->fops->lookup,
            loc, xdata);
    return 0;
}
 
static int test_stat (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
    gf_log(this->name, GF_LOG_ERROR, "in test translator stat");
    return 0;
}
 
int
reconfigure (xlator_t *this, dict_t *options)
{
        return 0;
}
 
 
int
init (xlator_t *this)
{
        struct ios_conf    *conf = NULL;
        int                 ret = -1;
 
    gf_log (this->name, GF_LOG_ERROR, "test translator loaded");
        if (!this)
                return -1;
 
        if (!this->children) {
                gf_log (this->name, GF_LOG_ERROR,
                        "test translator requires atleast one subvolume");
                return -1;
        }
 
        if (!this->parents) {
              gf_log (this->name, GF_LOG_ERROR, "dangling volume. check volfile ");
        }
 
        conf = this->private;
 
        this->private = conf;
        ret = 0;
        return ret;
}
 
 
void
fini (xlator_t *this)
{
        struct ios_conf *conf = NULL;
 
        if (!this)
                return;
 
        conf = this->private;
 
        if (!conf)
                return;
        this->private = NULL;
 
        GF_FREE(conf);
        gf_log (this->name, GF_LOG_ERROR, "test translator unloaded");
        return;
}
 
int
notify (xlator_t *this, int32_t event, void *data, ...)
{
    default_notify (this, event, data);
        return 0;
}
 
struct xlator_fops fops = {
        .stat        = test_stat,
        .lookup      = test_lookup,
};
 
struct xlator_cbks cbks = {
};
 
struct volume_options options[] = {
 };
目前仅用于测试的xlator而已,所以自己定义了lookup与stat,还有lookup_cbk,其他的并未定义,全部走default,这个原理在之前已经提到过。
然后执行make既可生成对应的xlator文件
1
Makefile  test.c  test.o  test.so
将test.so复制至/usr/local/lib/glusterfs/3git/xlator/debug中
然后执行glusterfs的客户端,mount至挂载节点,如果成功,可以查看log,整个过程成功矣~~!
阅读(1660) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~