Gluster添加自定义简单xlator的步骤

来源:互联网 发布:淘宝评价推荐排序 编辑:程序博客网 时间:2024/06/05 06:21

1、状况说明:

已有的gluster集群由三台机器组成,分别为:     gfsmaster 172.29.41.205     gfsslave1  172.29.41.204   gfsslave2  172.29.41.203 用于测试gluster挂载的客户端     gfsclient     172.29.41.206       挂载目录为 /opt/gfsmount      glusterfs源码目录:/root/Gluster/gluster  

gluster volume信息:

2、编写自定义代码和Makefile文件

test.c:

#ifndef _CONFIG_H#define _CONFIG_H#include "config.h"#include "xlator.h"#endif#include <fnmatch.h>#include <errno.h>#include "glusterfs.h"#include "xlator.h"#include <stdarg.h>#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;}intreconfigure (xlator_t *this, dict_t *options){        return 0;}intinit (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;}voidfini (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;}intnotify (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[] = { };

MakeFile:

Add translator into glusterfs volume file#Author Steven Liu#E-mail lingjiujianke@gmail.com#Blog: http://blog.fs-linux.orgTARGET  = test.soOBJECTS = test.oGLUSTERFS_SRC   = /root/Gluster/glusterfsGLUSTERFS_LIB   = /usr/local/libHOST_OS = HF_LINUX_HOST_OSCFLAGS  = -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/uuidLDFLAGS = -shared -nostartfiles -L$(GLUSTERFS_LIB) -lglusterfs -lpthread$(TARGET): $(OBJECTS)    $(CC) $(OBJECTS) $(LDFLAGS) -o $(TARGET)clean:    rm -rf $(TARGET) $(OBJECTS)

3、编译出so文件 并放在所有机器的/usr/local/lib/glusterfs/xlator/debug/(具体根据不同版本路径有所不同)下面

4、修改volfile

vi /var/lib/glusterd/vols/testvol/testvol-fuse.vol

在结尾处修改如下:

volume testvol-test    type debug/test    subvolumes testvol-md-cacheend-volumevolume testvol    type debug/io-stats    option count-fop-hits off    option latency-measurement off    subvolumes testvol-testend-volume

然后在每个服务器中都更新这个文件

5、在三台gluster服务器中重启glusterfsd进程

ps -ef | grep glusterfsd
kill -9 ****

6、客户端挂载测试

可以看出test xlator成功生效!