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.

117 lines
4.3 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.) In Linux v6.9 that feature made its way into the kernel
  8. however in a somewhat limited form which is incompatible with aspects
  9. of how mergerfs currently functions. While work will continue to
  10. support passthrough IO in mergerfs this library was created to offer
  11. similar functionality in a more limited way.
  12. `/usr/lib/mergerfs/preload.so`
  13. This [preloadable
  14. library](https://man7.org/linux/man-pages/man8/ld.so.8.html#ENVIRONMENT)
  15. overrides the creation and opening of files in order to simulate
  16. passthrough file IO. It catches the open/creat/fopen calls, has
  17. mergerfs do the call, queries mergerfs for the branch the file exists
  18. on, reopens the file on the underlying filesystem and returns that
  19. instead. Meaning that you will get native read/write performance
  20. because mergerfs is no longer part of the workflow. Keep in mind that
  21. this also means certain mergerfs features that work by interrupting
  22. the read/write workflow, such as `moveonenospc`, will no longer work.
  23. Also, understand that this will only work on dynamically linked
  24. software. Anything statically compiled will not work. Many GoLang and
  25. Rust apps are statically compiled.
  26. The library will not interfere with non-mergerfs filesystems. The
  27. library is written to always fallback to returning the mergerfs opened
  28. file on error.
  29. While the library was written to account for a number of edgecases
  30. there could be some yet accounted for so please report any oddities.
  31. Thank you to
  32. [nohajc](https://github.com/nohajc/mergerfs-io-passthrough) for
  33. prototyping the idea.
  34. ### casual usage
  35. ```sh
  36. LD_PRELOAD=/usr/lib/mergerfs/preload.so touch /mnt/mergerfs/filename
  37. ```
  38. Or run `export LD_PRELOAD=/usr/lib/mergerfs/preload.so` in your shell
  39. or place it in your shell config file to have it be picked up by all
  40. software ran from your shell.
  41. ### Docker and Podman 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
  45. them.
  46. **NOTE:** Since a container can have its own OS setup there is no
  47. guarentee that `preload.so` from the host install will be compatible
  48. with the loader found in the container. If that is true it simply
  49. won't work and shouldn't cause any issues.
  50. ```sh
  51. docker run \
  52. -e LD_PRELOAD=/usr/lib/mergerfs/preload.so \
  53. -v /usr/lib/mergerfs/preload.so:/usr/lib/mergerfs/preload.so:ro \
  54. -v /media:/media \
  55. -v /mnt:/mnt \
  56. ubuntu:latest \
  57. bash
  58. ```
  59. or more explicitly
  60. ```sh
  61. docker run \
  62. -e LD_PRELOAD=/usr/lib/mergerfs/preload.so \
  63. -v /usr/lib/mergerfs/preload.so:/usr/lib/mergerfs/preload.so:ro \
  64. -v /media:/media \
  65. -v /mnt/fs0:/mnt/fs0 \
  66. -v /mnt/fs1:/mnt/fs1 \
  67. ubuntu:latest \
  68. bash
  69. ```
  70. ### systemd unit
  71. Use the `Environment` option to set the LD_PRELOAD variable.
  72. * [https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#Command%20lines](https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#Command%20lines)
  73. * [https://serverfault.com/questions/413397/how-to-set-environment-variable-in-systemd-service](https://serverfault.com/questions/413397/how-to-set-environment-variable-in-systemd-service)
  74. ```
  75. [Service]
  76. Environment=LD_PRELOAD=/usr/lib/mergerfs/preload.so
  77. ```
  78. ## Misc
  79. - https://github.com/trapexit/mergerfs-tools
  80. - mergerfs.ctl: A tool to make it easier to query and configure mergerfs at runtime
  81. - mergerfs.fsck: Provides permissions and ownership auditing and the ability to fix them
  82. - mergerfs.dedup: Will help identify and optionally remove duplicate files
  83. - mergerfs.dup: Ensure there are at least N copies of a file across the pool
  84. - mergerfs.balance: Rebalance files across filesystems by moving them from the most filled to the least filled
  85. - mergerfs.consolidate: move files within a single mergerfs directory to the filesystem with most free space
  86. - https://github.com/trapexit/scorch
  87. - scorch: A tool to help discover silent corruption of files and keep track of files
  88. - https://github.com/trapexit/bbf
  89. - bbf (bad block finder): a tool to scan for and 'fix' hard drive bad blocks and find the files using those blocks