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.

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