gdfs开源代码中基于Fuse的GoogleDrive客户端如何实现优化?
摘要:背景 在学习fuse的过程中,首先从libfuse中的demo开始学习,以了解用户态与内核态通信的框架。而此处的demo只聚焦于最基本的通信,用户态文件系统的实现只是一个最简单的read only文件系统,其他操作都是假接口。 要继续深入学
背景
在学习fuse的过程中,首先从libfuse中的demo开始学习,以了解用户态与内核态通信的框架。而此处的demo只聚焦于最基本的通信,用户态文件系统的实现只是一个最简单的read only文件系统,其他操作都是假接口。
要继续深入学习,直接看cephfs等高集成、高完善的代码容易被细节淹没,最好能够循序渐进,同时也可以横向对比,看各个实现解决了什么问题,如何在用户态组织文件索引,缓存如何实现,客户端与服务端的缓存一致性如何解决,分布式锁如何实现,实现方式是否优雅,哪里有需要完善的地方等。
找到一个基于fuse开发的google drive文件系统,翻了一下代码结构比较简单,适合入门学习。因此本文以该项目来做说明。
项目地址:
GitHub - robin-thomas/GDFS: Google Drive File System
注:该代码涉及到通过api与google drive进行交互,因此也需要了解google api:
gdrive api:
https://developers.google.com/drive/api/guides/about-sdk?hl=zh-cn
google drive go sdk quickstart(此处以go sdk为例。官方不提供c++ sdk,因此作者是通过libcurl手搓的api调用):
https://developers.google.com/drive/api/quickstart/go?hl=zh-cn
google cloud console:
https://console.cloud.google.com/apis/credentials?hl=zh-cn&inv=1&invt=AbpcxA&project=wangxz-proj00049
环境搭建
# 拉起centos8容器:
IMAGE_ID='5d0da3dc9764'
NAME=centos8_demo
docker run --privileged -idt \
--name $NAME \
-v /data:/data \
--net host \
${IMAGE_ID} \
/usr/sbin/init
docker exec -it $NAME /bin/bash
# 配置源:
mkdir /etc/yum.repos.d/orig && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/orig && curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
# 安装编译工具:
yum install automake gcc-c++ cmake libfuse-devel libfuse3-devel curl libcurl -y -q
# 编译:
# 按照具体按照的automake版本重新配置,否则会报错找不到automake-1.15:
autoreconf -f -i
./configure
make
make install
# 配置:
vim /opt/gdfs/gdfs.conf
# 日志位置:
tail -f /opt/gdfs/gdfs.log
# 启动:
/opt/gdfs/gdfs.sh start
# 或
/usr/local/bin/mount.gdfs -m /tmp/robin -f -s --log_path /opt/gdfs --log_level DEBUG -o allow_other -o allow_root -o direct_io
b mount_fs
b get_node
b gdfs_read
b fuse_ll_process_buf
b LRUCache::get
b File::get
b File::read_file
#--
cat /tmp/robin/_opt_gdfs_/haha
架构分析
google auth
该项目使用google OAuth2.0进行鉴权。
