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.

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