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.

107 lines
3.9 KiB

  1. # TOOLING
  2. ## preload.so
  3. EXPERIMENTAL
  4. For some time there has been work to enable passthrough IO in
  5. FUSE. Passthrough IO would allow for near native performance with
  6. regards to reads and writes (at the expense of certain mergerfs
  7. features.) However, there have been several complications which have
  8. kept the feature from making it into the mainline Linux kernel. Until
  9. that feature is available there are two methods to provide similar
  10. functionality. One method is using the LD_PRELOAD feature of the
  11. dynamic linker. The other leveraging ptrace to intercept
  12. syscalls. Each has their disadvantages. At the moment only a preload
  13. based tool is available. A ptrace based tool may be developed later if
  14. there is a need.
  15. `/usr/lib/mergerfs/preload.so`
  16. This [preloadable
  17. library](https://man7.org/linux/man-pages/man8/ld.so.8.html#ENVIRONMENT)
  18. overrides the creation and opening of files in order to simulate
  19. passthrough file IO. It catches the open/creat/fopen calls, has
  20. mergerfs do the call, queries mergerfs for the branch the file exists
  21. on, reopens the file on the underlying filesystem and returns that
  22. instead. Meaning that you will get native read/write performance
  23. because mergerfs is no longer part of the workflow. Keep in mind that
  24. this also means certain mergerfs features that work by interrupting
  25. the read/write workflow, such as `moveonenospc`, will no longer work.
  26. Also, understand that this will only work on dynamically linked
  27. software. Anything statically compiled will not work. Many GoLang and
  28. Rust apps are statically compiled.
  29. The library will not interfere with non-mergerfs filesystems. The
  30. library is written to always fallback to returning the mergerfs opened
  31. file on error.
  32. While the library was written to account for a number of edgecases
  33. there could be some yet accounted for so please report any oddities.
  34. Thank you to
  35. [nohajc](https://github.com/nohajc/mergerfs-io-passthrough) for
  36. prototyping the idea.
  37. ### general usage
  38. ```sh
  39. LD_PRELOAD=/usr/lib/mergerfs/preload.so touch /mnt/mergerfs/filename
  40. ```
  41. ### Docker usage
  42. Assume `/mnt/fs0` and `/mnt/fs1` are pooled with mergerfs at `/media`.
  43. All mergerfs branch paths _must_ be bind mounted into the container at
  44. the same path as found on the host so the preload library can see them.
  45. ```sh
  46. docker run \
  47. -e LD_PRELOAD=/usr/lib/mergerfs/preload.so \
  48. -v /usr/lib/mergerfs/preload.so:/usr/lib/mergerfs/preload.so:ro \
  49. -v /media:/data \
  50. -v /mnt:/mnt \
  51. ubuntu:latest \
  52. bash
  53. ```
  54. or more explicitly
  55. ```sh
  56. docker run \
  57. -e LD_PRELOAD=/usr/lib/mergerfs/preload.so \
  58. -v /usr/lib/mergerfs/preload.so:/usr/lib/mergerfs/preload.so:ro \
  59. -v /media:/data \
  60. -v /mnt/fs0:/mnt/fs0 \
  61. -v /mnt/fs1:/mnt/fs1 \
  62. ubuntu:latest \
  63. bash
  64. ```
  65. ### systemd unit
  66. Use the `Environment` option to set the LD_PRELOAD variable.
  67. - https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#Command%20lines
  68. - https://serverfault.com/questions/413397/how-to-set-environment-variable-in-systemd-service
  69. ```
  70. [Service]
  71. Environment=LD_PRELOAD=/usr/lib/mergerfs/preload.so
  72. ```
  73. ## Misc
  74. - https://github.com/trapexit/mergerfs-tools
  75. - mergerfs.ctl: A tool to make it easier to query and configure mergerfs at runtime
  76. - mergerfs.fsck: Provides permissions and ownership auditing and the ability to fix them
  77. - mergerfs.dedup: Will help identify and optionally remove duplicate files
  78. - mergerfs.dup: Ensure there are at least N copies of a file across the pool
  79. - mergerfs.balance: Rebalance files across filesystems by moving them from the most filled to the least filled
  80. - mergerfs.consolidate: move files within a single mergerfs directory to the filesystem with most free space
  81. - https://github.com/trapexit/scorch
  82. - scorch: A tool to help discover silent corruption of files and keep track of files
  83. - https://github.com/trapexit/bbf
  84. - bbf (bad block finder): a tool to scan for and 'fix' hard drive bad blocks and find the files using those blocks