|
| 1 | +# FUSE on PFS |
| 2 | + |
| 3 | +Filesystem in USErspace (FUSE) is a software interface for Unix and Unix-like computer operating systems that lets non-privileged users create their own file systems without editing kernel code. This is achieved by running file system code in user space while the FUSE module provides only a bridge to the actual kernel interfaces. |
| 4 | + |
| 5 | +To allow users to use PFS with kernel interfaces like any other kernel built-in filesystems, we implement a FUSE on PFS handler program, which is linked to the supplied LibFUSE library. This program defines the request-respond mapping of kernal interfaces to pfs operations, which means it specify how PFS is to respond to read/write/stat requests. The program is also used to mount PFS. At the time PFS is mounted, the handler is registered with the kernel. If a user now issues read/write/stat requests for PFS, the kernel forwards these IO-requests to the handler and then sends the handler's response back to the user. |
| 6 | + |
| 7 | +# Main FUSE Modules |
| 8 | + |
| 9 | +#### FUSE kernel module (kernel state) |
| 10 | + |
| 11 | +The FUSE kernel module implements the VFS interface (which implements the registration of the fuse file driver, the fuse device driver, and provides maintenance of super blocks, inode, etc.) It receives requests from VFS and passes them to LibFUSE, and then LibFUSE passes requests to PFS handler program; |
| 12 | + |
| 13 | +#### LibFUSE module (user state) |
| 14 | + |
| 15 | +LibFUSE implements the main framework of the file system, the encapsulation of PFS operations, mount management and communication with the kernel module via /dev/fuse device; |
| 16 | + |
| 17 | +#### User program module (user state) |
| 18 | + |
| 19 | +User programs implement PFS operations encapsulated by the LibFUSE library in user space. |
| 20 | + |
| 21 | +# Interfaces |
| 22 | + |
| 23 | +FUSE interfaces are defined in`fusepfs_operations`, mainly divided into the following categories : |
| 24 | + |
| 25 | +1. FUSE environment building: init, destroy |
| 26 | + |
| 27 | +2. file operations: create, mknod, open, rename, truncate, ftruncate |
| 28 | + |
| 29 | +3. directory operations: mkdir, opendir, readdir, rmdir |
| 30 | + |
| 31 | +4. link: symlink, readlink, unlink |
| 32 | + |
| 33 | +5. file attribute: statfs, access, getattr, fgetattr |
| 34 | + |
| 35 | +6. extended attribute: getxattr, setxattr, listxattr, removexattr |
| 36 | + |
| 37 | +7. R/W: read, write, read_buf, write_buf, fallocate |
| 38 | + |
| 39 | +8. Sync I/O: fsync, fsyncdir |
| 40 | + |
| 41 | +9. multiplexing: poll |
| 42 | + |
| 43 | +10. release: release, releasedir |
| 44 | + |
| 45 | +11. other: ioctl, lock, bmap |
| 46 | + |
| 47 | + |
| 48 | +# Use FUSE on PFS |
| 49 | + |
| 50 | +#### 1. Install PFS Dependencies |
| 51 | + |
| 52 | +Refer to 【Install Dependencies】part in document [Readme.md](./Readme.md) for installation steps |
| 53 | + |
| 54 | +#### 2. Load FUSE Module |
| 55 | + |
| 56 | +##### I. Download FUSE resource package and decompress |
| 57 | + |
| 58 | +``` bash |
| 59 | +tar -zxvf fuse.tar.gz |
| 60 | +``` |
| 61 | +Recommended FUSE version: 2.9.2 |
| 62 | + |
| 63 | +##### II. Install FUSE (fuse 3.2 or above needs Meson or Ninj) |
| 64 | + |
| 65 | +```bash |
| 66 | +./configure && sudo make install |
| 67 | +``` |
| 68 | + |
| 69 | +##### III. Check |
| 70 | + |
| 71 | +````bash |
| 72 | +# check if FUSE is mounted successfully |
| 73 | +lsmod | grep fuse |
| 74 | +# If not, you can use `modprobe fuse` to mount FUSE. |
| 75 | +modprobe fuse |
| 76 | +# Look up version information |
| 77 | +fusermount --version |
| 78 | +```` |
| 79 | + |
| 80 | +#### 3. Complie and Install |
| 81 | + |
| 82 | +After the dependencies are installed, go to the root directory of PFS source code and run the script to compile and install PFS. |
| 83 | + |
| 84 | +```bash |
| 85 | +./autobuild.sh && sudo ./install.sh |
| 86 | +``` |
| 87 | + |
| 88 | +#### 4. Usage |
| 89 | + |
| 90 | +##### I. mount FUSE on PFS |
| 91 | + |
| 92 | +Before mounting, you need to configure /etc/fuse.conf: |
| 93 | +add `user_allow_other` to the file |
| 94 | + |
| 95 | +```bash |
| 96 | +/usr/local/polarstore/pfsd/bin/mount_pfs_fuse.sh [-p diskname] [-c rw/ro] mount_dir |
| 97 | +# example |
| 98 | +/usr/local/polarstore/pfsd/bin/mount_pfs_fuse.sh -p nvme1n1 -c rw ./fuse_mntdir |
| 99 | +``` |
| 100 | + |
| 101 | +`diskname` block device. you can get the information of all your available block devices with shell command `lsblk`; |
| 102 | + |
| 103 | +`rw/ro` startup a read&write or read-only instance; |
| 104 | + |
| 105 | +`mount_dir` fuse mount directory. |
| 106 | + |
| 107 | +p.s. Mounting FUSE on PFS will first start pfsdaemon in the background, then start pfs-fuse process, pfs-fuse will mount PFS to the specified directory. |
| 108 | + |
| 109 | +##### II. Visit PFS by FUSE |
| 110 | + |
| 111 | +After starting a pfsdfuse instance in background, now you can `cd` into the mount directory to operate PFS like a kernel built-in file system as usual. The results of all operations will be sent into the disk mounted via PFS. Here is an example : |
| 112 | + |
| 113 | +```bash |
| 114 | +# enter mount directory |
| 115 | +$cd path/to/fuse_mount_dir |
| 116 | +# create file and write |
| 117 | +$echo "hello pfs fuse">test_file.txt |
| 118 | +# show new file |
| 119 | +$cat test_file.txt |
| 120 | +hello pfs fuse |
| 121 | +``` |
| 122 | + |
| 123 | +##### III. Stop using FUSE on PFS |
| 124 | + |
| 125 | +1. Umount FUSE on pfs |
| 126 | + |
| 127 | + |
| 128 | +```bash |
| 129 | +/usr/local/polarstore/pfsd/bin/umount_pfs_fuse.sh [mount_dir/all] |
| 130 | +# example |
| 131 | +/usr/local/polarstore/pfsd/bin/umount_pfs_fuse.sh /fuse_mntdir |
| 132 | +/usr/local/polarstore/pfsd/bin/umount_pfs_fuse.sh all |
| 133 | +``` |
| 134 | + |
| 135 | +your can appoint a `mount_dir` to umount the selected instance, `mount dir` should be pointed as absolute path; |
| 136 | +your can also choose `all` to umount all mounted pfsdfuse instance. |
| 137 | + |
| 138 | +2. Stop pfsdaemon |
| 139 | + |
| 140 | +You can stop single pfsdaemon by pointing a diskname of the pfsdaemon, or you can kill all pfsdaemons by running stop_pfsd.sh without any parameter. |
| 141 | + |
| 142 | +```bash |
| 143 | +sudo /usr/local/polarstore/pfsd/bin/stop_pfsd.sh [diskname] |
| 144 | +sudo /usr/local/polarstore/pfsd/bin/stop_pfsd.sh |
| 145 | + |
| 146 | +example: |
| 147 | +sudo /usr/local/polarstore/pfsd/bin/stop_pfsd.sh nvme1n1 |
| 148 | +sudo /usr/local/polarstore/pfsd/bin/stop_pfsd.sh |
| 149 | +``` |
| 150 | + |
| 151 | +##### IV. Run the uninstall.sh script to uninstall pfsdaemon |
| 152 | + |
| 153 | +``` |
| 154 | +sudo ./uninstall.sh |
| 155 | +``` |
0 commit comments