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.

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