5. 编译新Xlator
设计并编码实现新Xlator后,我们需要将其编译成SO形式的动态库,提供给Glusterfs使用。编译过程中,需要使用到glusterfs其他部分的相关代码,要求设置较为复杂的编译环境。这里我们编写了Makefile文件设置环境并进行编译,内容如下:
# Change these to match your source code.
TARGET = null.so
OBJECTS = null.o null_fops.o
# Change these to match your environment.
GLFS_SRC = /home/liuag/glusterfs-3.2.5
GLFS_VERS = 3.2.5
GLFS_LIB = /opt/glusterfs/3.2.5/lib64/
HOST_OS = GF_LINUX_HOST_OS
# You shouldn't need to change anything below here.
CFLAGS = -fPIC -Wall -O2 \
-DHAVE_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D$(HOST_OS) \
-I$(GLFS_SRC) -I$(GLFS_SRC)/libglusterfs/src \
-I$(GLFS_SRC)/contrib/uuid -I.
LDFLAGS = -shared -nostartfiles -L$(GLFS_LIB) -lglusterfs -lpthread
$(TARGET): $(OBJECTS)
$(CC) $(CFLAGS) $(OBJECTS) $(LDFLAGS) -o $(TARGET)
install: $(TARGET)
cp $(TARGET) $(GLFS_LIB)/glusterfs/$(GLFS_VERS)/xlator/null
clean:
rm -f $(TARGET) $(OBJECTS)
将Makefile设置成与自己相匹配的编译环境,然后直接make即可生成null.so动态库,make install安装null新xlator。至此,一个新xlator就构造成功了,之后我们就可以使用它了。
6. 测试新Xlator
最激动人心的时刻终于到来了,现在我们可以通过修改volume配置文件来添加并测试新构造的null xlator。这个xlator可以工作在客户端或服务器端,可以修改相应卷配置文件或fuse卷配置文件来实现。下面以服务器端加载为例,局部卷配置修改如下:
volume test-posix
type storage/posix
option directory /data/test-1
end-volume
volume test-null
type null/null
subvolumes test-posix
end-volume
volume test-access-control
type features/access-control
subvolumes test-null
end-volume
… …
OK,现在重启glusterd服务,然后mount这个卷,就可以测试null xlator功能了。当然,你可能什么功能都测试不出来,因为我们什么功能都没实现。
