gluster 添加xlator新节点

来源:互联网 发布:公司网络布局 编辑:程序博客网 时间:2024/06/04 19:26

                                                                   添加xlator过程步骤分析


1.执行命令A机器:mkdir/home/test

任意机器:glustervolume create testvol A机器IP/home/test

如果你指定的brick位于根分区,在创建卷命令后加force

2.vim /var/lib/glusterd/vols/testvol/testvol-fuse.vol,这个是默认生成的配置文件,我们修改这个文件加入我们自己的xlator

例子如下:

原文件内容:

volumetestvol-client-0

    typeprotocol/client

    optiontransport-typetcp

    optionremote-subvolume /home/test

    optionremote-host A机器IP

end-volume

 

volumetestvol-dht

    typecluster/distribute

    subvolumestestvol-client-0

end-volume

 

volumetestvol-write-behind

    typeperformance/write-behind

    subvolumestestvol-dht

end-volume

 

volumetestvol-read-ahead

    typeperformance/read-ahead

    subvolumestestvol-write-behind

end-volume

 

volumetestvol-io-cache

    typeperformance/io-cache

    subvolumestestvol-read-ahead

end-volume

 

volumetestvol-quick-read

    typeperformance/quick-read

    subvolumestestvol-io-cache

end-volume

 

volumetestvol-open-behind

    typeperformance/open-behind

    subvolumestestvol-quick-read

end-volume

 

volumetestvol-md-cache

    typeperformance/md-cache

    subvolumestestvol-open-behind

end-volume

 

volumetestvol

    typedebug/io-stats

    optioncount-fop-hits off

    optionlatency-measurement off

    subvolumestestvol-md-cache

end-volume


修改后文件的内容如下:

volumetestvol-client-0

    typeprotocol/client

    optiontransport-typetcp

    optionremote-subvolume /home/test

    optionremote-host A机器IP

end-volume

 

volumetestvol-dht

    typecluster/distribute

    subvolumestestvol-client-0

end-volume

 

volumetestvol-write-behind

    typeperformance/write-behind

    subvolumestestvol-dht

end-volume

 

volumetestvol-read-ahead

    typeperformance/read-ahead

    subvolumestestvol-write-behind

end-volume

 

volumetestvol-io-cache

    typeperformance/io-cache

    subvolumestestvol-read-ahead

end-volume

 

volumetestvol-quick-read

    typeperformance/quick-read

    subvolumestestvol-io-cache

end-volume

 

volumetestvol-open-behind

    typeperformance/open-behind

    subvolumestestvol-quick-read

end-volume

 

volumetestvol-md-cache

    typeperformance/md-cache

    subvolumestestvol-open-behind

end-volume


volumetestvol-test

    typedebug/test

    subvolumestestvol-md-cache

end-volume


volumetestvol

    typedebug/io-stats

    optioncount-fop-hits off

    optionlatency-measurement off

    subvolumestestvol-test

end-volume

注意:黑体部分为变动的地方


3.创建任意目录,编写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"

 

inttest_lookup_cbk(call_frame_t *frame, void*cookie,xlator_t *this,

                     int32_top_ret, int32_t op_errno,

                     inode_t*inode, structiatt*buf,

                     dict_t*xdata, structiatt*postparent)

{

        STACK_UNWIND_STRICT(lookup, frame, op_ret, op_errno, inode, buf, xdata,

                             postparent);

        return0;

}

 

 

staticinttest_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);

    return0;

}

 

staticinttest_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");

    return0;

}

 

int

reconfigure(xlator_t *this, dict_t *options)

{

        return0;

}

 

 

int

init(xlator_t *this)

{

        structios_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,

                        "testtranslator 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;

        returnret;

}

 

 

void

fini(xlator_t *this)

{

        structios_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);

        return0;

}

 

structxlator_fopsfops = {

        .stat       = test_stat,

        .lookup     = test_lookup,

};

 

structxlator_cbkscbks = {

};

 

structvolume_optionsoptions[] = {

 };


此文件摘自http://blog.chinaunix.net/uid-11344913-id-3795965.html


4.test.c同目录下,编辑Makefile文件

内容如下:


TARGET =test.so

OBJECTS=test.o

 

GLUSTERFS_SRC  = /...../glusterfs #自己的gluster源码路径

GLUSTERFS_LIB  = /usr/local/lib

HOST_OS= GF_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)

此源码文件注意调整需要tab键格式的地方

执行命令make

将产生的test.so文件拷贝到/usr/local/lib/glusterfs/3.4.3/xlator/debug

4.重启glusterd服务,客户端挂载此卷

mount-t glusterfs A机器IPtestvol/media

查看日志文件输出是否含有testxlator的信息。


附上指定日志输出位置和指定卷配置的命令:

/glusterfsd-l ../../g.log -f /home/li/...../test.vol

(-l指定日志存储位置,-f指定配置文件的位置)

glusterfsd的位置可以用whereisglusterfsd查看

0 0
原创粉丝点击