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.

246 lines
10 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. #### readdir ####
  74. [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`.
  75. 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.
  76. #### statvfs ####
  77. [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.
  78. **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.
  79. # BUILDING
  80. * Need to install FUSE development libraries (libfuse-dev).
  81. * Optionally need libattr1 (libattr1-dev).
  82. ```
  83. [trapexit:~/dev/mergerfs] $ make help
  84. usage: make
  85. make XATTR_AVAILABLE=0 - to build program without xattrs functionality (auto discovered otherwise)
  86. ```
  87. # Runtime Settings
  88. #### /.mergerfs pseudo file ####
  89. ```
  90. <mountpoint>/.mergerfs
  91. ```
  92. 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.
  93. Even if xattrs are disabled the [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr) calls will still work.
  94. ##### Keys #####
  95. * user.mergerfs.srcmounts
  96. * user.mergerfs.category.action
  97. * user.mergerfs.category.create
  98. * user.mergerfs.category.search
  99. * user.mergerfs.func.access
  100. * user.mergerfs.func.chmod
  101. * user.mergerfs.func.chown
  102. * user.mergerfs.func.create
  103. * user.mergerfs.func.getattr
  104. * user.mergerfs.func.getxattr
  105. * user.mergerfs.func.link
  106. * user.mergerfs.func.listxattr
  107. * user.mergerfs.func.mkdir
  108. * user.mergerfs.func.mknod
  109. * user.mergerfs.func.open
  110. * user.mergerfs.func.readlink
  111. * user.mergerfs.func.removexattr
  112. * user.mergerfs.func.rename
  113. * user.mergerfs.func.rmdir
  114. * user.mergerfs.func.setxattr
  115. * user.mergerfs.func.symlink
  116. * user.mergerfs.func.truncate
  117. * user.mergerfs.func.unlink
  118. * user.mergerfs.func.utimens
  119. ##### Example #####
  120. ```
  121. [trapexit:/tmp/mount] $ xattr -l .mergerfs
  122. user.mergerfs.srcmounts: /tmp/a:/tmp/b
  123. user.mergerfs.category.action: all
  124. user.mergerfs.category.create: epmfs
  125. user.mergerfs.category.search: ff
  126. user.mergerfs.func.access: ff
  127. user.mergerfs.func.chmod: all
  128. user.mergerfs.func.chown: all
  129. user.mergerfs.func.create: epmfs
  130. user.mergerfs.func.getattr: ff
  131. user.mergerfs.func.getxattr: ff
  132. user.mergerfs.func.link: all
  133. user.mergerfs.func.listxattr: ff
  134. user.mergerfs.func.mkdir: epmfs
  135. user.mergerfs.func.mknod: epmfs
  136. user.mergerfs.func.open: ff
  137. user.mergerfs.func.readlink: ff
  138. user.mergerfs.func.removexattr: all
  139. user.mergerfs.func.rename: all
  140. user.mergerfs.func.rmdir: all
  141. user.mergerfs.func.setxattr: all
  142. user.mergerfs.func.symlink: epmfs
  143. user.mergerfs.func.truncate: all
  144. user.mergerfs.func.unlink: all
  145. user.mergerfs.func.utimens: all
  146. [trapexit:/tmp/mount] $ xattr -p user.mergerfs.category.search .mergerfs
  147. ff
  148. [trapexit:/tmp/mount] $ xattr -w user.mergerfs.category.search ffwp .mergerfs
  149. [trapexit:/tmp/mount] $ xattr -p user.mergerfs.category.search .mergerfs
  150. ffwp
  151. [trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts +/tmp/c .mergerfs
  152. [trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
  153. /tmp/a:/tmp/b:/tmp/c
  154. [trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts =/tmp/c .mergerfs
  155. [trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
  156. /tmp/c
  157. [trapexit:/tmp/mount] $ xattr -w user.mergerfs.srcmounts '+</tmp/a:/tmp/b' .mergerfs
  158. [trapexit:/tmp/mount] $ xattr -p user.mergerfs.srcmounts .mergerfs
  159. /tmp/a:/tmp/b:/tmp/c
  160. ```
  161. ##### Extra Details #####
  162. 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.
  163. | Instruction | Description |
  164. |--------------|-------------|
  165. | +[list] | append |
  166. | +<[list] | prepend |
  167. | +>[list] | append |
  168. | -[list] | remove all values provided |
  169. | -< | remove first in list |
  170. | -> | remove last in list |
  171. | =[list] | set |
  172. | [list] | set |
  173. 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`.
  174. #### mergerfs file xattrs ####
  175. 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:
  176. * user.mergerfs.basepath: the base mount point for the file given the current search policy
  177. * user.mergerfs.relpath: the relative path of the file from the perspective of the mount point
  178. * user.mergerfs.fullpath: the full path of the original file given the search policy
  179. * user.mergerfs.allpaths: a NUL ('\0') separated list of full paths to all files found
  180. ```
  181. [trapexit:/tmp/mount] $ ls
  182. A B C
  183. [trapexit:/tmp/mount] $ xattr -p user.mergerfs.fullpath A
  184. /mnt/a/full/path/to/A
  185. [trapexit:/tmp/mount] $ xattr -p user.mergerfs.basepath A
  186. /mnt/a
  187. [trapexit:/tmp/mount] $ xattr -p user.mergerfs.relpath A
  188. /full/path/to/A
  189. [trapexit:/tmp/mount] $ xattr -p user.mergerfs.allpaths A | tr '\0' '\n'
  190. /mnt/a/full/path/to/A
  191. /mnt/b/full/path/to/A
  192. ```