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.

863 lines
28 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. .\"t
  2. .TH "mergerfs" "1" "2016\-02\-21" "mergerfs user manual" ""
  3. .SH NAME
  4. .PP
  5. mergerfs \- another (FUSE based) union filesystem
  6. .SH SYNOPSIS
  7. .PP
  8. mergerfs \-o<options> <srcmounts> <mountpoint>
  9. .SH DESCRIPTION
  10. .PP
  11. \f[B]mergerfs\f[] is a union filesystem geared towards simplifing
  12. storage and management of files across numerous commodity storage
  13. devices.
  14. It is similar to \f[B]mhddfs\f[], \f[B]unionfs\f[], and \f[B]aufs\f[].
  15. .SH FEATURES
  16. .IP \[bu] 2
  17. Runs in userspace (FUSE)
  18. .IP \[bu] 2
  19. Configurable behaviors
  20. .IP \[bu] 2
  21. Support for extended attributes (xattrs)
  22. .IP \[bu] 2
  23. Support for file attributes (chattr)
  24. .IP \[bu] 2
  25. Runtime configurable (via xattrs)
  26. .IP \[bu] 2
  27. Safe to run as root
  28. .IP \[bu] 2
  29. Opportunistic credential caching
  30. .IP \[bu] 2
  31. Works with heterogeneous filesystem types
  32. .IP \[bu] 2
  33. Handling of writes to full drives
  34. .IP \[bu] 2
  35. Handles pool of readonly and read/write drives
  36. .SH OPTIONS
  37. .SS options
  38. .IP \[bu] 2
  39. \f[B]defaults\f[]: a shortcut for FUSE\[aq]s \f[B]atomic_o_trunc\f[],
  40. \f[B]auto_cache\f[], \f[B]big_writes\f[], \f[B]default_permissions\f[],
  41. \f[B]splice_move\f[], \f[B]splice_read\f[], and \f[B]splice_write\f[].
  42. These options seem to provide the best performance.
  43. .IP \[bu] 2
  44. \f[B]direct_io\f[]: causes FUSE to bypass an addition caching step which
  45. can increase write speeds at the detriment of read speed.
  46. .IP \[bu] 2
  47. \f[B]minfreespace\f[]: the minimum space value used for the
  48. \f[B]lfs\f[], \f[B]fwfs\f[], \f[B]eplfs\f[], & \f[B]epmfs\f[] policies.
  49. Understands \[aq]K\[aq], \[aq]M\[aq], and \[aq]G\[aq] to represent
  50. kilobyte, megabyte, and gigabyte respectively.
  51. (default: 4G)
  52. .IP \[bu] 2
  53. \f[B]moveonenospc\f[]: when enabled (set to \f[B]true\f[]) if a
  54. \f[B]write\f[] fails with \f[B]ENOSPC\f[] a scan of all drives will be
  55. done looking for the drive with most free space which is at least the
  56. size of the file plus the amount which failed to write.
  57. An attempt to move the file to that drive will occur (keeping all
  58. metadata possible) and if successful the original is unlinked and the
  59. write retried.
  60. (default: false)
  61. .IP \[bu] 2
  62. \f[B]func.<func>=<policy>\f[]: sets the specific FUSE function\[aq]s
  63. policy.
  64. See below for the list of value types.
  65. Example: \f[B]func.getattr=newest\f[]
  66. .IP \[bu] 2
  67. \f[B]category.<category>=<policy>\f[]: Sets policy of all FUSE functions
  68. in the provided category.
  69. Example: \f[B]category.create=mfs\f[]
  70. .PP
  71. \f[B]NOTE:\f[] Options are evaluated in the order listed so if the
  72. options are \f[B]func.rmdir=rand,category.action=ff\f[] the
  73. \f[B]action\f[] category setting will override the \f[B]rmdir\f[]
  74. setting.
  75. .SS srcmounts
  76. .PP
  77. The source mounts argument is a colon (\[aq]:\[aq]) delimited list of
  78. paths.
  79. To make it simpler to include multiple source mounts without having to
  80. modify your fstab (http://linux.die.net/man/5/fstab) we also support
  81. globbing (http://linux.die.net/man/7/glob).
  82. \f[B]The globbing tokens MUST be escaped when using via the shell else
  83. the shell itself will probably expand it.\f[]
  84. .IP
  85. .nf
  86. \f[C]
  87. $\ mergerfs\ /mnt/disk\\*:/mnt/cdrom\ /media/drives
  88. \f[]
  89. .fi
  90. .PP
  91. The above line will use all mount points in /mnt prefixed with
  92. \f[I]disk\f[] and the directory \f[I]cdrom\f[].
  93. .PP
  94. In /etc/fstab it\[aq]d look like the following:
  95. .IP
  96. .nf
  97. \f[C]
  98. #\ <file\ system>\ \ \ \ \ \ \ \ <mount\ point>\ \ <type>\ \ \ \ \ \ \ \ \ <options>\ \ \ \ \ \ \ \ \ \ \ \ \ <dump>\ \ <pass>
  99. /mnt/disk*:/mnt/cdrom\ \ /media/drives\ \ fuse.mergerfs\ \ defaults,allow_other\ \ 0\ \ \ \ \ \ \ 0
  100. \f[]
  101. .fi
  102. .PP
  103. \f[B]NOTE:\f[] the globbing is done at mount or xattr update time.
  104. If a new directory is added matching the glob after the fact it will not
  105. be included.
  106. .SH FUNCTIONS / POLICIES / CATEGORIES
  107. .PP
  108. The filesystem has a number of functions.
  109. Those functions are grouped into 3 categories: \f[B]action\f[],
  110. \f[B]create\f[], \f[B]search\f[].
  111. These functions and categories can be assigned a policy which dictates
  112. how \f[B]mergerfs\f[] behaves.
  113. Any policy can be assigned to a function or category though some are not
  114. very practical.
  115. For instance: \f[B]rand\f[] (Random) may be useful for file creation
  116. (create) but could lead to very odd behavior if used for \f[C]chmod\f[].
  117. .PP
  118. All policies when used to create will ignore drives which are mounted
  119. readonly.
  120. This allows for read/write and readonly drives to be mixed together.
  121. .SS Function / Category classifications
  122. .PP
  123. .TS
  124. tab(@);
  125. l l.
  126. T{
  127. Category
  128. T}@T{
  129. FUSE Functions
  130. T}
  131. _
  132. T{
  133. action
  134. T}@T{
  135. chmod, chown, link, removexattr, rename, rmdir, setxattr, truncate,
  136. unlink, utimens
  137. T}
  138. T{
  139. create
  140. T}@T{
  141. create, mkdir, mknod, symlink
  142. T}
  143. T{
  144. search
  145. T}@T{
  146. access, getattr, getxattr, ioctl, listxattr, open, readlink
  147. T}
  148. T{
  149. N/A
  150. T}@T{
  151. fallocate, fgetattr, fsync, ftruncate, ioctl, read, readdir, release,
  152. statfs, write
  153. T}
  154. .TE
  155. .PP
  156. Due to FUSE limitations \f[B]ioctl\f[] behaves differently if its acting
  157. on a directory.
  158. It\[aq]ll use the \f[B]getattr\f[] policy to find and open the directory
  159. before issuing the \f[B]ioctl\f[].
  160. In other cases where something may be searched (to confirm a directory
  161. exists across all source mounts) then \f[B]getattr\f[] will be used.
  162. .SS Policy descriptions
  163. .PP
  164. Generally speaking most policies when called to create will filter out
  165. drives which are readonly or have less than \f[C]minfreespace\f[].
  166. .PP
  167. .TS
  168. tab(@);
  169. l l.
  170. T{
  171. Policy
  172. T}@T{
  173. Description
  174. T}
  175. _
  176. T{
  177. all
  178. T}@T{
  179. Search category: acts like \f[B]ff\f[].
  180. Action category: apply to all found.
  181. Create category: for \f[B]mkdir\f[], \f[B]mknod\f[], and
  182. \f[B]symlink\f[] perform on all read/write drives with
  183. \f[B]minfreespace\f[].
  184. \f[B]create\f[] filters the same way but acts like \f[B]ff\f[].
  185. T}
  186. T{
  187. eplfs (existing path, least free space)
  188. T}@T{
  189. If the path exists on multiple drives use the one with the least free
  190. space.
  191. Falls back to \f[B]lfs\f[].
  192. T}
  193. T{
  194. epmfs (existing path, most free space)
  195. T}@T{
  196. If the path exists on multiple drives use the one with the most free
  197. space.
  198. Falls back to \f[B]mfs\f[].
  199. T}
  200. T{
  201. erofs
  202. T}@T{
  203. Exclusively return \f[B]\-1\f[] with \f[B]errno\f[] set to
  204. \f[B]EROFS\f[].
  205. By setting \f[B]create\f[] functions to this you can in effect turn the
  206. filesystem readonly.
  207. T}
  208. T{
  209. ff (first found)
  210. T}@T{
  211. Given the order of the drives, as defined at mount time or when
  212. configured via xattr interface, act on the first one found.
  213. T}
  214. T{
  215. fwfs (first with free space)
  216. T}@T{
  217. Pick the first drive which has at least \f[B]minfreespace\f[].
  218. Falls back to \f[B]mfs\f[].
  219. T}
  220. T{
  221. lfs (least free space)
  222. T}@T{
  223. Pick the drive with the least available free space but more than
  224. \f[B]minfreespace\f[].
  225. Falls back to \f[B]mfs\f[].
  226. T}
  227. T{
  228. mfs (most free space)
  229. T}@T{
  230. Use the drive with the most available free space.
  231. Falls back to \f[B]ff\f[].
  232. T}
  233. T{
  234. newest (newest file)
  235. T}@T{
  236. Pick the file / directory with the largest mtime.
  237. T}
  238. T{
  239. rand (random)
  240. T}@T{
  241. Calls \f[B]all\f[] and then randomizes.
  242. T}
  243. .TE
  244. .SS Defaults
  245. .PP
  246. .TS
  247. tab(@);
  248. l l.
  249. T{
  250. Category
  251. T}@T{
  252. Policy
  253. T}
  254. _
  255. T{
  256. action
  257. T}@T{
  258. all
  259. T}
  260. T{
  261. create
  262. T}@T{
  263. epmfs
  264. T}
  265. T{
  266. search
  267. T}@T{
  268. ff
  269. T}
  270. .TE
  271. .SS rename & link
  272. .PP
  273. rename (http://man7.org/linux/man-pages/man2/rename.2.html) is a tricky
  274. function in a merged system.
  275. Normally if a rename can\[aq]t be done atomically due to the source and
  276. destination paths existing on different mount points it will return
  277. \f[C]\-1\f[] with \f[C]errno\ =\ EXDEV\f[].
  278. The atomic rename is most critical for replacing files in place
  279. atomically (such as securing writing to a temp file and then replacing a
  280. target).
  281. The problem is that by merging multiple paths you can have N instances
  282. of the source and destinations on different drives.
  283. This can lead to several undesirable situtations with or without errors
  284. and it\[aq]s not entirely obvious what to do when an error occurs.
  285. .PP
  286. Originally mergerfs would return EXDEV whenever a rename was requested
  287. which was cross directory in any way.
  288. This made the code simple and was technically complient with POSIX
  289. requirements.
  290. However, many applications fail to handle EXDEV at all and treat it as a
  291. normal error or they only partially support EXDEV (don\[aq]t respond the
  292. same as \f[C]mv\f[] would).
  293. Such apps include: gvfsd\-fuse v1.20.3 and prior, Finder / CIFS/SMB
  294. client in Apple OSX 10.9+, NZBGet, Samba\[aq]s recycling bin feature.
  295. .IP \[bu] 2
  296. If using a policy which tries to preserve directories (epmfs,eplfs)
  297. .IP \[bu] 2
  298. Using the \f[C]rename\f[] policy get the list of files to rename
  299. .IP \[bu] 2
  300. For each file attempt rename:
  301. .RS 2
  302. .IP \[bu] 2
  303. If failure with ENOENT run \f[C]create\f[] policy
  304. .IP \[bu] 2
  305. If create policy returns the same drive as currently evaluating then
  306. clone the path
  307. .IP \[bu] 2
  308. Re\-attempt rename
  309. .RE
  310. .IP \[bu] 2
  311. If \f[B]any\f[] of the renames succeed the higher level rename is
  312. considered a success
  313. .IP \[bu] 2
  314. If \f[B]no\f[] renames succeed the first error encountered will be
  315. returned
  316. .IP \[bu] 2
  317. On success:
  318. .RS 2
  319. .IP \[bu] 2
  320. Remove the target from all drives with no source file
  321. .IP \[bu] 2
  322. Remove the source from all drives which failed to rename
  323. .RE
  324. .IP \[bu] 2
  325. If using a policy which does \f[B]not\f[] try to preserve directories
  326. .IP \[bu] 2
  327. Using the \f[C]rename\f[] policy get the list of files to rename
  328. .IP \[bu] 2
  329. Using the \f[C]getattr\f[] policy get the target path
  330. .IP \[bu] 2
  331. For each file attempt rename:
  332. .RS 2
  333. .IP \[bu] 2
  334. If the source drive != target drive:
  335. .IP \[bu] 2
  336. Clone target path from target drive to source drive
  337. .IP \[bu] 2
  338. Rename
  339. .RE
  340. .IP \[bu] 2
  341. If \f[B]any\f[] of the renames succeed the higher level rename is
  342. considered a success
  343. .IP \[bu] 2
  344. If \f[B]no\f[] renames succeed the first error encountered will be
  345. returned
  346. .IP \[bu] 2
  347. On success:
  348. .RS 2
  349. .IP \[bu] 2
  350. Remove the target from all drives with no source file
  351. .IP \[bu] 2
  352. Remove the source from all drives which failed to rename
  353. .RE
  354. .PP
  355. The the removals are subject to normal entitlement checks.
  356. .PP
  357. The above behavior will help minimize the likelihood of EXDEV being
  358. returned but it will still be possible.
  359. To remove the possibility all together mergerfs would need to perform
  360. the as \f[C]mv\f[] does when it receives EXDEV normally.
  361. .PP
  362. \f[C]link\f[] uses the same basic strategy.
  363. .SS readdir
  364. .PP
  365. readdir (http://linux.die.net/man/3/readdir) is different from all other
  366. filesystem functions.
  367. It certainly could have it\[aq]s own set of policies to tweak its
  368. behavior.
  369. At this time it provides a simple \f[B]first found\f[] merging of
  370. directories and files found.
  371. That is: only the first file or directory found for a directory is
  372. returned.
  373. Given how FUSE works though the data representing the returned entry
  374. comes from \f[B]getattr\f[].
  375. .PP
  376. It could be extended to offer the ability to see all files found.
  377. Perhaps concatenating \f[B]#\f[] and a number to the name.
  378. But to really be useful you\[aq]d need to be able to access them which
  379. would complicate file lookup.
  380. .SS statvfs
  381. .PP
  382. statvfs (http://linux.die.net/man/2/statvfs) normalizes the source
  383. drives based on the fragment size and sums the number of adjusted blocks
  384. and inodes.
  385. This means you will see the combined space of all sources.
  386. Total, used, and free.
  387. The sources however are dedupped based on the drive so multiple sources
  388. on the same drive will not result in double counting it\[aq]s space.
  389. .SH BUILDING
  390. .PP
  391. \f[B]NOTE:\f[] Prebuilt packages can be found at:
  392. https://github.com/trapexit/mergerfs/releases
  393. .PP
  394. First get the code from github (http://github.com/trapexit/mergerfs).
  395. .IP
  396. .nf
  397. \f[C]
  398. $\ git\ clone\ https://github.com/trapexit/mergerfs.git
  399. $\ #\ or
  400. $\ wget\ https://github.com/trapexit/mergerfs/archive/master.zip
  401. \f[]
  402. .fi
  403. .SS Debian / Ubuntu
  404. .IP
  405. .nf
  406. \f[C]
  407. $\ sudo\ apt\-get\ install\ g++\ pkg\-config\ git\ git\-buildpackage\ pandoc\ debhelper\ libfuse\-dev\ libattr1\-dev\ python
  408. $\ cd\ mergerfs
  409. $\ make\ deb
  410. $\ sudo\ dpkg\ \-i\ ../mergerfs_version_arch.deb
  411. \f[]
  412. .fi
  413. .SS Fedora
  414. .IP
  415. .nf
  416. \f[C]
  417. $\ su\ \-
  418. #\ dnf\ install\ rpm\-build\ fuse\-devel\ libattr\-devel\ pandoc\ gcc\-c++\ git\ make\ which\ python
  419. #\ cd\ mergerfs
  420. #\ make\ rpm
  421. #\ rpm\ \-i\ rpmbuild/RPMS/<arch>/mergerfs\-<verion>.<arch>.rpm
  422. \f[]
  423. .fi
  424. .SS Generically
  425. .PP
  426. Have git, python, pkg\-config, pandoc, libfuse, libattr1 installed.
  427. .IP
  428. .nf
  429. \f[C]
  430. $\ cd\ mergerfs
  431. $\ make
  432. $\ make\ man
  433. $\ sudo\ make\ install
  434. \f[]
  435. .fi
  436. .SH RUNTIME
  437. .SS \&.mergerfs pseudo file
  438. .IP
  439. .nf
  440. \f[C]
  441. <mountpoint>/.mergerfs
  442. \f[]
  443. .fi
  444. .PP
  445. There is a pseudo file available at the mount point which allows for the
  446. runtime modification of certain \f[B]mergerfs\f[] options.
  447. The file will not show up in \f[B]readdir\f[] but can be
  448. \f[B]stat\f[]\[aq]ed and manipulated via
  449. {list,get,set}xattrs (http://linux.die.net/man/2/listxattr) calls.
  450. .PP
  451. Even if xattrs are disabled the
  452. {list,get,set}xattrs (http://linux.die.net/man/2/listxattr) calls will
  453. still work.
  454. .SS Keys
  455. .PP
  456. Use \f[C]xattr\ \-l\ /mount/point/.mergerfs\f[] to see all supported
  457. keys.
  458. .SS user.mergerfs.srcmounts
  459. .PP
  460. For \f[B]user.mergerfs.srcmounts\f[] there are several instructions
  461. available for manipulating the list.
  462. The value provided is just as the value used at mount time.
  463. A colon (\[aq]:\[aq]) delimited list of full path globs.
  464. .PP
  465. .TS
  466. tab(@);
  467. l l.
  468. T{
  469. Instruction
  470. T}@T{
  471. Description
  472. T}
  473. _
  474. T{
  475. [list]
  476. T}@T{
  477. set
  478. T}
  479. T{
  480. +<[list]
  481. T}@T{
  482. prepend
  483. T}
  484. T{
  485. +>[list]
  486. T}@T{
  487. append
  488. T}
  489. T{
  490. \-[list]
  491. T}@T{
  492. remove all values provided
  493. T}
  494. T{
  495. \-<
  496. T}@T{
  497. remove first in list
  498. T}
  499. T{
  500. \->
  501. T}@T{
  502. remove last in list
  503. T}
  504. .TE
  505. .SS minfreespace
  506. .PP
  507. Input: interger with an optional multiplier suffix.
  508. \f[B]K\f[], \f[B]M\f[], or \f[B]G\f[].
  509. .PP
  510. Output: value in bytes
  511. .SS moveonenospc
  512. .PP
  513. Input: \f[B]true\f[] and \f[B]false\f[]
  514. .PP
  515. Ouput: \f[B]true\f[] or \f[B]false\f[]
  516. .SS categories / funcs
  517. .PP
  518. Input: short policy string as described elsewhere in this document
  519. .PP
  520. Output: the policy string except for categories where its funcs have
  521. multiple types.
  522. In that case it will be a comma separated list
  523. .SS Example
  524. .IP
  525. .nf
  526. \f[C]
  527. [trapexit:/tmp/mount]\ $\ xattr\ \-l\ .mergerfs
  528. user.mergerfs.srcmounts:\ /tmp/a:/tmp/b
  529. user.mergerfs.minfreespace:\ 4294967295
  530. user.mergerfs.moveonenospc:\ false
  531. \&...
  532. [trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.category.search\ .mergerfs
  533. ff
  534. [trapexit:/tmp/mount]\ $\ xattr\ \-w\ user.mergerfs.category.search\ fwfs\ .mergerfs
  535. [trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.category.search\ .mergerfs
  536. fwfs
  537. [trapexit:/tmp/mount]\ $\ xattr\ \-w\ user.mergerfs.srcmounts\ +/tmp/c\ .mergerfs
  538. [trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.srcmounts\ .mergerfs
  539. /tmp/a:/tmp/b:/tmp/c
  540. [trapexit:/tmp/mount]\ $\ xattr\ \-w\ user.mergerfs.srcmounts\ =/tmp/c\ .mergerfs
  541. [trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.srcmounts\ .mergerfs
  542. /tmp/c
  543. [trapexit:/tmp/mount]\ $\ xattr\ \-w\ user.mergerfs.srcmounts\ \[aq]+</tmp/a:/tmp/b\[aq]\ .mergerfs
  544. [trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.srcmounts\ .mergerfs
  545. /tmp/a:/tmp/b:/tmp/c
  546. \f[]
  547. .fi
  548. .SS mergerfs file xattrs
  549. .PP
  550. While they won\[aq]t show up when using
  551. listxattr (http://linux.die.net/man/2/listxattr) \f[B]mergerfs\f[]
  552. offers a number of special xattrs to query information about the files
  553. served.
  554. To access the values you will need to issue a
  555. getxattr (http://linux.die.net/man/2/getxattr) for one of the following:
  556. .IP \[bu] 2
  557. \f[B]user.mergerfs.basepath:\f[] the base mount point for the file given
  558. the current getattr policy
  559. .IP \[bu] 2
  560. \f[B]user.mergerfs.relpath:\f[] the relative path of the file from the
  561. perspective of the mount point
  562. .IP \[bu] 2
  563. \f[B]user.mergerfs.fullpath:\f[] the full path of the original file
  564. given the getattr policy
  565. .IP \[bu] 2
  566. \f[B]user.mergerfs.allpaths:\f[] a NUL (\[aq]\[aq]) separated list of
  567. full paths to all files found
  568. .IP
  569. .nf
  570. \f[C]
  571. [trapexit:/tmp/mount]\ $\ ls
  572. A\ B\ C
  573. [trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.fullpath\ A
  574. /mnt/a/full/path/to/A
  575. [trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.basepath\ A
  576. /mnt/a
  577. [trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.relpath\ A
  578. /full/path/to/A
  579. [trapexit:/tmp/mount]\ $\ xattr\ \-p\ user.mergerfs.allpaths\ A\ |\ tr\ \[aq]\\0\[aq]\ \[aq]\\n\[aq]
  580. /mnt/a/full/path/to/A
  581. /mnt/b/full/path/to/A
  582. \f[]
  583. .fi
  584. .SH TOOLING
  585. .PP
  586. Find tooling to help with managing \f[C]mergerfs\f[] at:
  587. https://github.com/trapexit/mergerfs\-tools
  588. .IP \[bu] 2
  589. fsck.mergerfs: Provides permissions and ownership auditing and the
  590. ability to fix them
  591. .IP \[bu] 2
  592. mergerfs.mktrash: Creates FreeDesktop.org Trash specification compatible
  593. directories on a mergerfs mount
  594. .SH TIPS / NOTES
  595. .IP \[bu] 2
  596. If you don\[aq]t see some directories / files you expect in a merged
  597. point be sure the user has permission to all the underlying directories.
  598. If \f[C]/drive0/a\f[] has is owned by \f[C]root:root\f[] with ACLs set
  599. to \f[C]0700\f[] and \f[C]/drive1/a\f[] is \f[C]root:root\f[] and
  600. \f[C]0755\f[] you\[aq]ll see only \f[C]/drive1/a\f[].
  601. Use \f[C]fsck.mergerfs\f[] to audit the drive for out of sync
  602. permissions.
  603. .IP \[bu] 2
  604. Since POSIX gives you only error or success on calls its difficult to
  605. determine the proper behavior when applying the behavior to multiple
  606. targets.
  607. \f[B]mergerfs\f[] will return an error only if all attempts of an action
  608. fail.
  609. Any success will lead to a success returned.
  610. .IP \[bu] 2
  611. The recommended options are \f[B]defaults,allow_other\f[].
  612. The \f[B]allow_other\f[] is to allow users who are not the one which
  613. executed mergerfs access to the mountpoint.
  614. \f[B]defaults\f[] is described above and should offer the best
  615. performance.
  616. It\[aq]s possible that if you\[aq]re running on an older platform the
  617. \f[B]splice\f[] features aren\[aq]t available and could error.
  618. In that case simply use the other options manually.
  619. .IP \[bu] 2
  620. If write performance is valued more than read it may be useful to enable
  621. \f[B]direct_io\f[].
  622. Best to benchmark with and without and choose appropriately.
  623. .IP \[bu] 2
  624. Remember: some policies mixed with some functions may result in strange
  625. behaviors.
  626. Not that some of these behaviors and race conditions couldn\[aq]t happen
  627. outside \f[B]mergerfs\f[] but that they are far more likely to occur on
  628. account of attempt to merge together multiple sources of data which
  629. could be out of sync due to the different policies.
  630. .IP \[bu] 2
  631. An example: Kodi (http://kodi.tv) and Plex (http://plex.tv) can use
  632. directory mtime (http://linux.die.net/man/2/stat) to more efficiently
  633. determine whether to scan for new content rather than simply performing
  634. a full scan.
  635. If using the current default \f[B]getattr\f[] policy of \f[B]ff\f[] its
  636. possible \f[B]Kodi\f[] will miss an update on account of it returning
  637. the first directory found\[aq]s \f[B]stat\f[] info and its a later
  638. directory on another mount which had the \f[B]mtime\f[] recently
  639. updated.
  640. To fix this you will want to set \f[B]func.getattr=newest\f[].
  641. Remember though that this is just \f[B]stat\f[].
  642. If the file is later \f[B]open\f[]\[aq]ed or \f[B]unlink\f[]\[aq]ed and
  643. the policy is different for those then a completely different file or
  644. directory could be acted on.
  645. .IP \[bu] 2
  646. Due to previously mentioned issues its generally best to set
  647. \f[B]category\f[] wide policies rather than individual
  648. \f[B]func\f[]\[aq]s.
  649. This will help limit the confusion of tools such as
  650. rsync (http://linux.die.net/man/1/rsync).
  651. .SH KNOWN ISSUES / BUGS
  652. .SS Trashing files occasionally fails
  653. .PP
  654. This is the same issue as with Samba.
  655. \f[C]rename\f[] returns \f[C]EXDEV\f[] (in our case that will really
  656. only happen with path preserving policies like \f[C]epmfs\f[]) and the
  657. software doesn\[aq]t handle the situtation well.
  658. This is unfortunately a common failure of software which moves files
  659. around.
  660. The standard indicates that an implementation \f[C]MAY\f[] choose to
  661. support non\-user home directory trashing of files (which is a
  662. \f[C]MUST\f[]).
  663. The implementation \f[C]MAY\f[] also support "top directory trashes"
  664. which many probably do.
  665. .PP
  666. To create a \f[C]$topdir/.Trash\f[] directory as defined in the standard
  667. use the mergerfs\-tools (https://github.com/trapexit/mergerfs-tools)
  668. tool \f[C]mergerfs.mktrash\f[].
  669. .SS Samba: Moving files / directories fails
  670. .PP
  671. Workaround: Copy the file/directory and then remove the original rather
  672. than move.
  673. .PP
  674. This isn\[aq]t an issue with Samba but some SMB clients.
  675. GVFS\-fuse v1.20.3 and prior (found in Ubuntu 14.04 among others) failed
  676. to handle certain error codes correctly.
  677. Particularly \f[B]STATUS_NOT_SAME_DEVICE\f[] which comes from the
  678. \f[B]EXDEV\f[] which is returned by \f[B]rename\f[] when the call is
  679. crossing mount points.
  680. When a program gets an \f[B]EXDEV\f[] it needs to explicitly take an
  681. alternate action to accomplish it\[aq]s goal.
  682. In the case of \f[B]mv\f[] or similar it tries \f[B]rename\f[] and on
  683. \f[B]EXDEV\f[] falls back to a manual copying of data between the two
  684. locations and unlinking the source.
  685. In these older versions of GVFS\-fuse if it received \f[B]EXDEV\f[] it
  686. would translate that into \f[B]EIO\f[].
  687. This would cause \f[B]mv\f[] or most any application attempting to move
  688. files around on that SMB share to fail with a IO error.
  689. .PP
  690. GVFS\-fuse v1.22.0 (https://bugzilla.gnome.org/show_bug.cgi?id=734568)
  691. and above fixed this issue but a large number of systems use the older
  692. release.
  693. On Ubuntu the version can be checked by issuing
  694. \f[C]apt\-cache\ showpkg\ gvfs\-fuse\f[].
  695. Most distros released in 2015 seem to have the updated release and will
  696. work fine but older systems may not.
  697. Upgrading gvfs\-fuse or the distro in general will address the problem.
  698. .PP
  699. In Apple\[aq]s MacOSX 10.9 they replaced Samba (client and server) with
  700. their own product.
  701. It appears their new client does not handle \f[B]EXDEV\f[] either and
  702. responds similar to older release of gvfs on Linux.
  703. .SS Supplemental user groups
  704. .PP
  705. Due to the overhead of
  706. getgroups/setgroups (http://linux.die.net/man/2/setgroups) mergerfs
  707. utilizes a cache.
  708. This cache is opportunistic and per thread.
  709. Each thread will query the supplemental groups for a user when that
  710. particular thread needs to change credentials and will keep that data
  711. for the lifetime of the thread.
  712. This means that if a user is added to a group it may not be picked up
  713. without the restart of mergerfs.
  714. However, since the high level FUSE API\[aq]s (at least the standard
  715. version) thread pool dynamically grows and shrinks it\[aq]s possible
  716. that over time a thread will be killed and later a new thread with no
  717. cache will start and query the new data.
  718. .PP
  719. The gid cache uses fixed storage to simplify the design and be
  720. compatible with older systems which may not have C++11 compilers.
  721. There is enough storage for 256 users\[aq] supplemental groups.
  722. Each user is allowed upto 32 supplemental groups.
  723. Linux >= 2.6.3 allows upto 65535 groups per user but most other *nixs
  724. allow far less.
  725. NFS allowing only 16.
  726. The system does handle overflow gracefully.
  727. If the user has more than 32 supplemental groups only the first 32 will
  728. be used.
  729. If more than 256 users are using the system when an uncached user is
  730. found it will evict an existing user\[aq]s cache at random.
  731. So long as there aren\[aq]t more than 256 active users this should be
  732. fine.
  733. If either value is too low for your needs you will have to modify
  734. \f[C]gidcache.hpp\f[] to increase the values.
  735. Note that doing so will increase the memory needed by each thread.
  736. .SS mergerfs or libfuse crashing
  737. .PP
  738. If suddenly the mergerfs mount point disappears and
  739. \f[C]Transport\ endpoint\ is\ not\ connected\f[] is returned when
  740. attempting to perform actions within the mount directory \f[B]and\f[]
  741. the version of libfuse (use \f[C]mergerfs\ \-v\f[] to find the version)
  742. is older than \f[C]2.9.4\f[] its likely due to a bug in libfuse.
  743. Affected versions of libfuse can be found in Debian Wheezy, Ubuntu
  744. Precise and others.
  745. .PP
  746. In order to fix this please install newer versions of libfuse.
  747. If using a Debian based distro (Debian,Ubuntu,Mint) you can likely just
  748. install newer versions of
  749. libfuse (https://packages.debian.org/unstable/libfuse2) and
  750. fuse (https://packages.debian.org/unstable/fuse) from the repo of a
  751. newer release.
  752. .SH FAQ
  753. .SS Why use mergerfs over mhddfs?
  754. .PP
  755. mhddfs is no longer maintained and has some known stability and security
  756. issues (see below).
  757. .SS Why use mergerfs over aufs?
  758. .PP
  759. While aufs can offer better peak performance mergerfs offers more
  760. configurability and is generally easier to use.
  761. mergerfs however doesn\[aq]t offer the overlay features which tends to
  762. result in whiteout files being left around the underlying filesystems.
  763. .SS Why use mergerfs over LVM/ZFS/BTRFS/RAID0 drive concatenation /
  764. striping?
  765. .PP
  766. A single drive failure will lead to full pool failure without additional
  767. redundancy.
  768. mergerfs performs a similar behavior without the catastrophic failure
  769. and lack of recovery.
  770. Drives can fail and all other data will continue to be accessable.
  771. .SS It\[aq]s mentioned that there are some security issues with mhddfs.
  772. What are they? How does mergerfs address them?
  773. .PP
  774. mhddfs (https://github.com/trapexit/mhddfs) tries to handle being run as
  775. \f[B]root\f[] by calling
  776. getuid() (https://github.com/trapexit/mhddfs/blob/cae96e6251dd91e2bdc24800b4a18a74044f6672/src/main.c#L319)
  777. and if it returns \f[B]0\f[] then it will
  778. chown (http://linux.die.net/man/1/chown) the file.
  779. Not only is that a race condition but it doesn\[aq]t handle many other
  780. situations.
  781. Rather than attempting to simulate POSIX ACL behaviors the proper
  782. behavior is to use seteuid (http://linux.die.net/man/2/seteuid) and
  783. setegid (http://linux.die.net/man/2/setegid), become the user making the
  784. original call and perform the action as them.
  785. This is how mergerfs (https://github.com/trapexit/mergerfs) handles
  786. things.
  787. .PP
  788. If you are familiar with POSIX standards you\[aq]ll know that this
  789. behavior poses a problem.
  790. \f[B]seteuid\f[] and \f[B]setegid\f[] affect the whole process and
  791. \f[B]libfuse\f[] is multithreaded by default.
  792. We\[aq]d need to lock access to \f[B]seteuid\f[] and \f[B]setegid\f[]
  793. with a mutex so that the several threads aren\[aq]t stepping on one
  794. another and files end up with weird permissions and ownership.
  795. This however wouldn\[aq]t scale well.
  796. With lots of calls the contention on that mutex would be extremely high.
  797. Thankfully on Linux and OSX we have a better solution.
  798. .PP
  799. OSX has a non\-portable pthread
  800. extension (https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/pthread_setugid_np.2.html)
  801. for per\-thread user and group impersonation.
  802. .PP
  803. Linux does not support
  804. pthread_setugid_np (https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/pthread_setugid_np.2.html)
  805. but user and group IDs are a per\-thread attribute though documentation
  806. on that fact or how to manipulate them is not well distributed.
  807. From the \f[B]4.00\f[] release of the Linux man\-pages project for
  808. setuid (http://man7.org/linux/man-pages/man2/setuid.2.html).
  809. .RS
  810. .PP
  811. At the kernel level, user IDs and group IDs are a per\-thread attribute.
  812. However, POSIX requires that all threads in a process share the same
  813. credentials.
  814. The NPTL threading implementation handles the POSIX requirements by
  815. providing wrapper functions for the various system calls that change
  816. process UIDs and GIDs.
  817. These wrapper functions (including the one for setuid()) employ a
  818. signal\-based technique to ensure that when one thread changes
  819. credentials, all of the other threads in the process also change their
  820. credentials.
  821. For details, see nptl(7).
  822. .RE
  823. .PP
  824. Turns out the setreuid syscalls apply only to the thread.
  825. GLIBC hides this away using RT signals to inform all threads to change
  826. credentials.
  827. Taking after \f[B]Samba\f[] mergerfs uses
  828. \f[B]syscall(SYS_setreuid,...)\f[] to set the callers credentials for
  829. that thread only.
  830. Jumping back to \f[B]root\f[] as necessary should escalated privileges
  831. be needed (for instance: to clone paths).
  832. .PP
  833. For non\-Linux systems mergerfs uses a read\-write lock and changes
  834. credentials only when necessary.
  835. If multiple threads are to be user X then only the first one will need
  836. to change the processes credentials.
  837. So long as the other threads need to be user X they will take a readlock
  838. allow multiple threads to share the credentials.
  839. Once a request comes in to run as user Y that thread will attempt a
  840. write lock and change to Y\[aq]s credentials when it can.
  841. If the ability to give writers priority is supported then that flag will
  842. be used so threads trying to change credentials don\[aq]t starve.
  843. This isn\[aq]t the best solution but should work reasonably well.
  844. As new platforms are supported if they offer per thread credentials
  845. those APIs will be adopted.
  846. .SH SUPPORT
  847. .SS Issues with the software
  848. .IP \[bu] 2
  849. github.com: https://github.com/trapexit/mergerfs/issues
  850. .IP \[bu] 2
  851. email: trapexit\@spawn.link
  852. .SS Support development
  853. .IP \[bu] 2
  854. Gratipay: https://gratipay.com/~trapexit
  855. .IP \[bu] 2
  856. BitCoin: 12CdMhEPQVmjz3SSynkAEuD5q9JmhTDCZA
  857. .SH AUTHORS
  858. Antonio SJ Musumeci <trapexit@spawn.link>.