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.

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