2010/08/27

ZKFuse 與 macfuse

zkfuse 可能會被歸在玩具類, 是網路控制中心 ZooKeeper 把資料暴露在 FUSE 下。但與 macfuse 不符(API 差異), 就游進去解決一下 ...

參考網誌 HowTo Mount ZooKeeper using FUSE 的做法。

zkfuse 需要 fuse(macfuse 2.0.3), boost, log4cxx ... 都用 macports 裝妥。

取得 zookeeper-3.3.1.tar.gz 解開到 <zookeeper3>。

按照 /src/c/README 編 zookeeper:
$ cd zookeeper3
$ ant compile_jute
$ cd src/c/
$ ./configure
$ make
$ sudo make install
(預設安裝到 /usr/local/include/ 與 /usr/local/lib/)

到 zkfuse/ 目錄下:
$ cd ../contrib/zkfuse/
$ autoreconf -if
$ export LDFLAGS="-L/usr/local/lib -L/opt/local/lib"
$ export CXXFLAGS="-I/opt/local/include -I/usr/local/include"
$ export LIBS="-lzookeeper_mt"
$ ./configure

由於 macfuse 與 fuse 差異, 修改 src/mutex.h:
--- mutex.h.original    2010-08-27 10:38:10.000000000 +0800
+++ mutex.h 2010-08-27 10:38:20.000000000 +0800
@@ -34,7 +34,7 @@
public:
Mutex() {
pthread_mutexattr_init( &m_mutexAttr );
- pthread_mutexattr_settype( &m_mutexAttr, PTHREAD_MUTEX_RECURSIVE_NP );
+ pthread_mutexattr_settype( &m_mutexAttr, PTHREAD_MUTEX_RECURSIVE );
pthread_mutex_init( &mutex, &m_mutexAttr );
}
~Mutex() {

修改 src/zkfuse.cc:
--- zkfuse.cc.original  2010-08-27 10:28:37.000000000 +0800
+++ zkfuse.cc 2010-08-27 10:30:01.000000000 +0800
@@ -27,7 +27,7 @@

extern "C" {
#include
-#include
+// #include
}
#include
#include
@@ -4171,16 +4171,17 @@
int zkfuse_lock(const char *path, struct fuse_file_info *fi, int cmd,
struct flock *lock)
{
- (void) path;
- return ulockmgr_op(fi->fh, cmd, lock, &fi->lock_owner,
- sizeof(fi->lock_owner));
+ return 0;
+// (void) path;
+// return ulockmgr_op(fi->fh, cmd, lock, &fi->lock_owner,
+// sizeof(fi->lock_owner));
}

static
void init_zkfuse_oper(fuse_operations & fo)
{
- memset(&fo, 0, sizeof(fuse_operations));
+// memset(&fo, 0, sizeof(fuse_operations));
fo.getattr = zkfuse_getattr;
fo.fgetattr = zkfuse_fgetattr;
// fo.access = zkfuse_access;
@@ -4204,7 +4205,7 @@
fo.open = zkfuse_open;
fo.read = zkfuse_read;
fo.write = zkfuse_write;
- fo.statfs = zkfuse_statfs;
+// fo.statfs = zkfuse_statfs;
fo.flush = zkfuse_flush;
fo.release = zkfuse_release;
fo.fsync = zkfuse_fsync;

改完繼續做出 zkfuse:
$ make

產生 src/zkfuse ... 然後繼續: (開始用 zkfuse 前要先啟動 zookeeper)
$ mkdir 123
(要 mount 的入口點)
$ src/zkfuse -z localhost:2181 -m 123 -d
(要加 -d, 否則不能用 ... 但終端機會被佔住)

開另一個終端機看 123/ 目錄內容:
$ ls zookeeper3/src/contrib/zkfuse/123
zookeeper

0 comments: