KFS[CloudStore] 使用fuse挂载方法

1, 下载fuse-2.8.4.tar.gz
2,  tar -xzvf fuse-2.8.4.tar.gz
3,  ./configure && make && make install
注:需要root权限
4,  echo “/usr/local/lib” >> /etc/ld.so.conf
/sbin/ldconfig
5,  /sbin/modprobe fuse

6,  修改kfs-0.5中CMakeLists.txt中的
SET(Fuse_LIBRARY_DIR “/usr/local/lib”)
SET(Fuse_INCLUDE_DIR “/usr/local/include”)
7,  重新编译kfs-0.5 会在bin目录下生成kfs_fuse二进制文件

8,  启动kfs

9,  编写kfs.prp
metaServer.name=10.60.1.125
metaServer.port=20000
注:kfs.prp这个配置的路径是在kfs_fuse_main.cc中写的,
注意启动时kfs.prp与kfs_fuse是在同一个目录下

10, ./kfs_fuse /tmp/kfs-fuse -f  启动

cd /tmp/kfs-fuse 就可以看到当前kfs下的所有数据了

注:kfs-0.5版本中存在bug以及可优化的地方

1, 在fuse_read 和fuse_write 中调用Seek, 判断返回值status应该是大于等于0 而不是等于0
因为status 的值应该是seek后的文件偏移


2, 可以优化的地方,在每次fuse_read 和 fuse_write 时,都会进行open 和close 操作,这样会导致效率上的问题,加入读取很大的数据,导致进行多次open 和 close操作。
优化方法:使用client->Fileno(path) 来获得已经打开的fd ,如果fd不存在的话,再进行Open 操作,在函数结束时不进行

Close 操作,而是将close操作放到fuse_flush函数中(新增的函数),具体作用请参考fuse手册

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Fuse(Filesystem in Userspace)是一个允许非特权用户在用户空间中实现自己的文件系统的框架。Fuse可以允许用户创建虚拟文件系统,将不同的物理文件夹组合为单个文件夹等等。 在Linux系统中,Fuse可以通过Fuse API实现自定义文件系统。Fuse API提供了一组C语言函数,可以实现文件系统的挂载、卸载、读写、文件创建和删除等基本操作。用户可以通过Fuse API编写自己的文件系统模块,然后将其挂载到本地文件系统中。 创建一个Fuse文件系统的基本步骤是: 1. 安装Fuse库和相关的开发工具。 2. 编写Fuse文件系统程序并通过gcc进行编译。 3. 执行Fuse文件系统程序,将其挂载到Linux本地文件系统中。 4. 通过系统的标准文件操作接口来使用Fuse文件系统。 下面是一个示例程序,它可以创建一个简单的Fuse文件系统: 1. 首先,安装Fuse应用程序和开发包。这里以Ubuntu为例: sudo apt-get install fuse libfuse-dev 2. 编写Fuse文件系统程序。下面的程序实现了一个简单的只读文件系统,它将远程的文件读取并映射到本地的文件系统中: ``` #include <fuse.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <fcntl.h> static const char *hello_str = "Hello World!\n"; static const char *hello_path = "/hello"; static int hello_getattr(const char *path, struct stat *stbuf) { int res = 0; memset(stbuf, 0, sizeof(struct stat)); if (strcmp(path, "/") == 0) { stbuf->st_mode = S_IFDIR | 0755; stbuf->st_nlink = 2; } else if (strcmp(path, hello_path) == 0) { stbuf->st_mode = S_IFREG | 0444; stbuf->st_nlink = 1; stbuf->st_size = strlen(hello_str); } else res = -ENOENT; return res; } static int hello_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { (void) offset; (void) fi; if (strcmp(path, "/") != 0) return -ENOENT; filler(buf, ".", NULL, 0); filler(buf, "..", NULL, 0); filler(buf, hello_path + 1, NULL, 0); return 0; } static int hello_open(const char *path, struct fuse_file_info *fi) { if (strcmp(path, hello_path) != 0) return -ENOENT; if ((fi->flags & 3) != O_RDONLY) return -EACCES; return 0; } static int hello_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { size_t len; (void) fi; if(strcmp(path, hello_path) != 0) return -ENOENT; len = strlen(hello_str); if (offset < len) { if (offset + size > len) size = len - offset; memcpy(buf, hello_str + offset, size); } else size = 0; return size; } static struct fuse_operations hello_oper = { .getattr = hello_getattr, .readdir = hello_readdir, .open = hello_open, .read = hello_read, }; int main(int argc, char *argv[]) { return fuse_main(argc, argv, &hello_oper, NULL); } ``` 3. 编译程序: gcc -Wall hello.c -o hello `pkg-config fuse --cflags --libs` 4. 在本地文件系统中创建一个挂载点: mkdir /tmp/myfuse 5. 运行Fuse文件系统程序: ./hello /tmp/myfuse 6. 使用cat或其他标准文件操作接口,读取`/hello`文件: cat /tmp/myfuse/hello 输出:Hello World! Fuse文件系统提供了一种强大而灵活的方法来扩展和定制Linux文件系统,通过定制Fuse文件系统可以实现各种场景下的文件读写、解压缩、加密解密等操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值