You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

254 lines
11 KiB

11 years ago
  1. % mergerfs(1) mergerfs user manual
  2. % Antonio SJ Musumeci <trapexit@spawn.link>
  3. % 2015-02-05
  4. # NAME
  5. mergerfs - another FUSE union filesystem
  6. # SYNOPSIS
  7. mergerfs -o&lt;options&gt; &lt;srcpoints&gt; &lt;mountpoint&gt;
  8. # DESCRIPTION
  9. mergerfs is similar to mhddfs, unionfs, and aufs. Like mhddfs in that it too uses FUSE. Like aufs in that it provides multiple policies for how to handle behavior.
  10. Why create mergerfs when those exist? mhddfs isn't really maintained or flexible. There are also issues with running as root. aufs is more flexible but contains some hard to debug inconsistencies in behavior. Neither support file attributes ([chattr](http://linux.die.net/man/1/chattr)).
  11. # OPTIONS
  12. ###options###
  13. All [FUSE](http://fuse.sourceforge.net) functions which have a category (see below) are option keys. The syntax being `func.<func>=<policy>`.
  14. To set all function policies in a category use `category.<category>=<policy>` such as `category.create=mfs`.
  15. They are evaluated in the order listed so if the options are `func.rmdir=rand,category.action=ff` the `action` category setting will override the `rmdir` setting.
  16. ###srcpoints###
  17. The source points argument is a colon (':') delimited list of paths. To make it simplier to include multiple source points without having to modify your [fstab](http://linux.die.net/man/5/fstab) we also support [globbing](http://linux.die.net/man/7/glob).
  18. ```
  19. $ mergerfs /mnt/disk*:/mnt/cdrom /media/drives
  20. ```
  21. The above line will use all points in /mnt prefixed with *disk* and the directory *cdrom*.
  22. In /etc/fstab it'd look like the following:
  23. ```
  24. # <file system> <mount point> <type> <options> <dump> <pass>
  25. /mnt/disk*:/mnt/cdrom /media/drives fuse.mergerfs allow_other 0 0
  26. ```
  27. **NOTE:** the globbing is done at mount time. If a new directory is added matching the glob after the fact it will not be included.
  28. # POLICIES
  29. Filesystem calls are broken up into 3 categories: action, create, search. There are also some calls which have no policy attached due to state being kept between calls. These categories can be assigned a policy which dictates how [mergerfs](http://github.com/trapexit/mergerfs) behaves. Any policy can be assigned to a category though some aren't terribly practical. For instance: rand (Random) may be useful for **create** but could lead to very odd behavior if used for **search**.
  30. #### Functional classifications ####
  31. | FUSE Function | Class |
  32. |-------------|---------|
  33. | access | search |
  34. | chmod | action |
  35. | chown | action |
  36. | create | create |
  37. | fallocate | N/A |
  38. | fgetattr | N/A |
  39. | fsync | N/A |
  40. | ftruncate | N/A |
  41. | getattr | search |
  42. | getxattr | search |
  43. | ioctl | N/A* |
  44. | link | action |
  45. | listxattr | search |
  46. | mkdir | create |
  47. | mknod | create |
  48. | open | search |
  49. | read | N/A |
  50. | readdir | N/A |
  51. | readlink | search |
  52. | release | N/A |
  53. | removexattr | action |
  54. | rename | action |
  55. | rmdir | action |
  56. | setxattr | action |
  57. | statfs | N/A |
  58. | symlink | create |
  59. | truncate | action |
  60. | unlink | action |
  61. | utimens | action |
  62. | write | N/A |
  63. `ioctl` behaves differently if its acting on a directory. It'll use the `getattr` policy to find and open the directory before issuing the `ioctl`. In other cases where something may be searched (to confirm a directory exists across all source mounts) then `getattr` will be used.
  64. #### Policy descriptions ####
  65. | Policy | Description |
  66. |--------------|-------------|
  67. | ff (first found) | Given the order of the paths act on the first one found (regardless if stat would return EACCES). |
  68. | ffwp (first found w/ permissions) | Given the order of the paths act on the first one found which you have access (stat does not error with EACCES). |
  69. | newest (newest file) | If multiple files exist return the one with the most recent mtime. |
  70. | mfs (most free space) | Assuming the path is found to exist (ENOENT would not be returned) use the drive with the most free space available. |
  71. | epmfs (existing path, most free space) | If the path exists in multiple locations use the one with the most free space. Otherwise fall back to mfs. |
  72. | rand (random) | Pick an existing destination at random. |
  73. | all | Applies action to all found. For searches it will behave like first found `ff`. |
  74. #### Defaults ####
  75. | Category | Policy |
  76. |----------|--------|
  77. | action | all |
  78. | create | epmfs |
  79. | search | ff |
  80. #### readdir ####
  81. [readdir](http://linux.die.net/man/3/readdir) is very different from most functions in this realm. It certainly could have it's own set of policies to tweak its behavior. At this time it provides a simple `first found` merging of directories and file found. That is: only the first file or directory found for a directory is returned. Given how FUSE works though the data representing the returned entry comes from `getattr`.
  82. It could be extended to offer the ability to see all files found. Perhaps concatinating `#` and a number to the name. But to really be useful you'd need to be able to access them which would complicate file lookup.
  83. #### statvfs ####
  84. [statvfs](http://linux.die.net/man/2/statvfs) normalizes the source drives based on the fragment size and sums the number of adjusted blocks and inodes. This means you will see the combined space of all sources. Total, used, and free. The sources however are dedupped based on the drive so multiple points on the same drive will not result in double counting it's space.
  85. **NOTE:** Since we can not (easily) replicate the atomicity of an `mkdir` or `mknod` without side effects those calls will first do a scan to see if the file exists and then attempts a create. This means there is a slight race condition. Worse case you'd end up with the directory or file on more than one mount.
  86. # BUILDING
  87. * Need to install FUSE development libraries (libfuse-dev).
  88. * Optionally need libattr1 (libattr1-dev).
  89. ```
  90. [trapexit:~/dev/mergerfs] $ make help
  91. usage: make
  92. make XATTR_AVAILABLE=0 - to build program without xattrs functionality (auto discovered otherwise)
  93. ```
  94. # Runtime Settings
  95. #### /.mergerfs pseudo file ####
  96. ```
  97. <mountpoint>/.mergerfs
  98. ```
  99. There is a pseudo file available at the mountpoint which allows for the runtime modification of certain mergerfs options. The file will not show up in readdirs but can be stat'ed and manipulated via [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls.
  100. Even if xattrs are disabled the [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls will still work.
  101. ##### Keys #####
  102. * user.mergerfs.srcmounts
  103. * user.mergerfs.category.action
  104. * user.mergerfs.category.create
  105. * user.mergerfs.category.search
  106. * user.mergerfs.func.access
  107. * user.mergerfs.func.chmod
  108. * user.mergerfs.func.chown
  109. * user.mergerfs.func.create
  110. * user.mergerfs.func.getattr
  111. * user.mergerfs.func.getxattr
  112. * user.mergerfs.func.link
  113. * user.mergerfs.func.listxattr
  114. * user.mergerfs.func.mkdir
  115. * user.mergerfs.func.mknod
  116. * user.mergerfs.func.open
  117. * user.mergerfs.func.readlink
  118. * user.mergerfs.func.removexattr
  119. * user.mergerfs.func.rename
  120. * user.mergerfs.func.rmdir
  121. * user.mergerfs.func.setxattr
  122. * user.mergerfs.func.symlink
  123. * user.mergerfs.func.truncate
  124. * user.mergerfs.func.unlink
  125. * user.mergerfs.func.utimens
  126. ##### Example #####
  127. ```
  128. [trapexit:/tmp/mount] $ xattr -l .mergerfs
  129. user.mergerfs.srcmounts: /tmp/a:/tmp/b
  130. user.mergerfs.category.action: all
  131. user.mergerfs.category.create: epmfs
  132. user.mergerfs.category.search: ff
  133. user.mergerfs.func.access: ff
  134. user.mergerfs.func.chmod: all
  135. user.mergerfs.func.chown: all
  136. user.mergerfs.func.create: epmfs
  137. user.mergerfs.func.getattr: ff
  138. user.mergerfs.func.getxattr: ff
  139. user.mergerfs.func.link: all
  140. user.mergerfs.func.listxattr: ff
  141. user.mergerfs.func.mkdir: epmfs
  142. user.mergerfs.func.mknod: epmfs
  143. user.mergerfs.func.open: ff
  144. user.mergerfs.func.readlink: ff
  145. user.mergerfs.func.removexattr: all
  146. user.mergerfs.func.rename: all
  147. user.mergerfs.func.rmdir: all
  148. user.mergerfs.func.setxattr: all
  149. user.mergerfs.func.symlink: epmfs
  150. user.mergerfs.func.truncate: all
  151. user.mergerfs.func.unlink: all
  152. user.mergerfs.func.utimens: all
  153. [trapexit:/tmp/mount] $ xattr -p user.mergerfs.category.search .mergerfs
  154. ff
  155. [trapexit:/tmp/mount] $ xattr -w user.mergerfs.category.search ffwp .mergerfs
  156. [trapexit:/tmp/mount] $ xattr -p user.mergerfs.category.search .mergerfs
  157. ffwp
  158. [trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts +/tmp/c .mergerfs
  159. [trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
  160. /tmp/a:/tmp/b:/tmp/c
  161. [trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts =/tmp/c .mergerfs
  162. [trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
  163. /tmp/c
  164. [trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts '+</tmp/a:/tmp/b' .mergerfs
  165. [trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
  166. /tmp/a:/tmp/b:/tmp/c
  167. ```
  168. ##### Extra Details #####
  169. For **user.mergerfs.srcmounts** there are several instructions available for manipulating the list. The value provided is just as the value used at mount time. A colon (':') delimited list of full path globs.
  170. | Instruction | Description |
  171. |--------------|-------------|
  172. | +[list] | append |
  173. | +<[list] | prepend |
  174. | +>[list] | append |
  175. | -[list] | remove all values provided |
  176. | -< | remove first in list |
  177. | -> | remove last in list |
  178. | =[list] | set |
  179. | [list] | set |
  180. Categories and funcs take a policy as described in the previous section. When reading funcs you'll get the policy string. However, with categories you'll get a coma separated list of policies for each type found. For example: if all search functions are `ff` except for `access` which is `ffwp` the value for `user.mergerfs.category.search` will be `ff,ffwp`.
  181. #### mergerfs file xattrs ####
  182. While they won't show up when using [listxattr](http://linux.die.net/man/2/listxattr) mergerfs offers a number of special xattrs to query information about the files served. To access the values you will need to issue a [getxattr](http://linux.die.net/man/2/getxattr) for one of the following:
  183. * user.mergerfs.basepath: the base mount point for the file given the current search policy
  184. * user.mergerfs.relpath: the relative path of the file from the perspective of the mount point
  185. * user.mergerfs.fullpath: the full path of the original file given the search policy
  186. * user.mergerfs.allpaths: a NUL ('\0') separated list of full paths to all files found
  187. ```
  188. [trapexit:/tmp/mount] $ ls
  189. A B C
  190. [trapexit:/tmp/mount] $ xattr -p user.mergerfs.fullpath A
  191. /mnt/a/full/path/to/A
  192. [trapexit:/tmp/mount] $ xattr -p user.mergerfs.basepath A
  193. /mnt/a
  194. [trapexit:/tmp/mount] $ xattr -p user.mergerfs.relpath A
  195. /full/path/to/A
  196. [trapexit:/tmp/mount] $ xattr -p user.mergerfs.allpaths A | tr '\0' '\n'
  197. /mnt/a/full/path/to/A
  198. /mnt/b/full/path/to/A
  199. ```