mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-19 16:16:48 +00:00
Compare commits
131
Commits
2.35.0
...
latest-release
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b420e72c0 | ||
|
|
b63bb76bec | ||
|
|
5e584f246a | ||
|
|
7e964283b9 | ||
|
|
03dc17fff2 | ||
|
|
8cb68dce4a | ||
|
|
28260c434a | ||
|
|
fae9b993fe | ||
|
|
171eb9c7c0 | ||
|
|
174e703d2e | ||
|
|
efd0dfaa2f | ||
|
|
75d7a93724 | ||
|
|
50fa7ac694 | ||
|
|
7d64a47b88 | ||
|
|
5fba42f076 | ||
|
|
b0bb7ef38c | ||
|
|
85ce7d6178 | ||
|
|
40359df453 | ||
|
|
9b2a5a75ee | ||
|
|
b21172c609 | ||
|
|
f0444a1ca9 | ||
|
|
977d04229f | ||
|
|
757ae66327 | ||
|
|
42d0b5734c | ||
|
|
78050ed6b0 | ||
|
|
19ee44afe7 | ||
|
|
a234e9446c | ||
|
|
951eb9540d | ||
|
|
85a936c95e | ||
|
|
8210e63a66 | ||
|
|
facdb66746 | ||
|
|
1916e54a24 | ||
|
|
7fabe515f4 | ||
|
|
0ca5d6aad0 | ||
|
|
0c1aeb411d | ||
|
|
17fdbf7f42 | ||
|
|
27349e41ef | ||
|
|
b3ce95c422 | ||
|
|
cedc9f0f25 | ||
|
|
d68ad9ac01 | ||
|
|
ae6c4f7c25 | ||
|
|
87475098a1 | ||
|
|
d4dc0701d6 | ||
|
|
c1c2f075ee | ||
|
|
96d34f1eab | ||
|
|
f66fb7e2d4 | ||
|
|
edb3368078 | ||
|
|
bd70928268 | ||
|
|
337aade02d | ||
|
|
d6a2f06797 | ||
|
|
7890a4996c | ||
|
|
6aa6452d3e | ||
|
|
7d6c8e9333 | ||
|
|
a7069153bd | ||
|
|
5c71a75fdd | ||
|
|
fd33df04a3 | ||
|
|
a9ae36a3e4 | ||
|
|
569537df9e | ||
|
|
8534ee7ceb | ||
|
|
620cab2948 | ||
|
|
8635456818 | ||
|
|
0888f372aa | ||
|
|
e09b10c55b | ||
|
|
766b923116 | ||
|
|
dd7e9e2aa7 | ||
|
|
3fc0aa3809 | ||
|
|
b1dcc94e98 | ||
|
|
6d2c99e487 | ||
|
|
9d9eacfe7b | ||
|
|
b91cc1c191 | ||
|
|
6d2f26c60e | ||
|
|
0a94bd7cfc | ||
|
|
211e6c7115 | ||
|
|
335ca55a6e | ||
|
|
69de4de53f | ||
|
|
76c8d48dbd | ||
|
|
a927a15e9c | ||
|
|
0c555e71a0 | ||
|
|
82781b6ff8 | ||
|
|
b545352712 | ||
|
|
3d05999db0 | ||
|
|
f4a8105a42 | ||
|
|
004b616115 | ||
|
|
8d7017273f | ||
|
|
51b65cd126 | ||
|
|
0ed03a1535 | ||
|
|
b6d3c34d3f | ||
|
|
fdecabfaab | ||
|
|
3a1d8e03a1 | ||
|
|
e586d2fd1e | ||
|
|
e0087cd8a7 | ||
|
|
2377cb05b6 | ||
|
|
a8ffbc84f6 | ||
|
|
0aafdefc18 | ||
|
|
7221fded71 | ||
|
|
7a09f560f7 | ||
|
|
8b769dff7f | ||
|
|
6dcf6111af | ||
|
|
9849bcd3cf | ||
|
|
c92a10021e | ||
|
|
d817fa4e97 | ||
|
|
eb141c4c4e | ||
|
|
282ce08ddb | ||
|
|
51d97bb444 | ||
|
|
539f2221a3 | ||
|
|
2b1804d364 | ||
|
|
556c6522c0 | ||
|
|
543603bdfc | ||
|
|
7a86ed6508 | ||
|
|
707d298d7c | ||
|
|
36a4b7a23a | ||
|
|
22833bdfe2 | ||
|
|
775c3cad90 | ||
|
|
fa537961c5 | ||
|
|
ee13810f3b | ||
|
|
5d6c9cc56a | ||
|
|
832903378e | ||
|
|
2722f4f64d | ||
|
|
7cdd12bda4 | ||
|
|
5ab0fbcaee | ||
|
|
42836e0961 | ||
|
|
6a14a10e6c | ||
|
|
82430e1079 | ||
|
|
701f88de43 | ||
|
|
c72997f298 | ||
|
|
c681d6c2fe | ||
|
|
6bc3d77992 | ||
|
|
c266bae96d | ||
|
|
cdcfef2ceb | ||
|
|
7a62a629b9 | ||
|
|
0a64d74b4b |
+31
-393
@@ -1,128 +1,3 @@
|
||||
freebsd_task:
|
||||
name: "freebsd:11.4"
|
||||
freebsd_instance:
|
||||
image_family: freebsd-11-4
|
||||
env:
|
||||
ASSUME_ALWAYS_YES: yes
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- gmake -j4
|
||||
|
||||
freebsd_task:
|
||||
name: "freebsd:12.1"
|
||||
freebsd_instance:
|
||||
image_family: freebsd-12-1
|
||||
env:
|
||||
ASSUME_ALWAYS_YES: yes
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- gmake -j4
|
||||
|
||||
freebsd_task:
|
||||
name: "freebsd:12.2"
|
||||
freebsd_instance:
|
||||
image_family: freebsd-12-2
|
||||
env:
|
||||
ASSUME_ALWAYS_YES: yes
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- gmake -j4
|
||||
|
||||
freebsd_task:
|
||||
name: "freebsd:13.0"
|
||||
freebsd_instance:
|
||||
image_family: freebsd-13-0
|
||||
env:
|
||||
ASSUME_ALWAYS_YES: yes
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- gmake -j4
|
||||
|
||||
|
||||
#macos_task:
|
||||
# osx_instance:
|
||||
# image: catalina-base
|
||||
# script:
|
||||
# - tools/install-build-pkgs
|
||||
# - gmake -j4
|
||||
|
||||
linux_task:
|
||||
name: "alpine:3.11"
|
||||
container:
|
||||
image: alpine:3.11
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- make STATIC=1 LTO=1
|
||||
|
||||
linux_task:
|
||||
name: "alpine:3.12"
|
||||
container:
|
||||
image: alpine:3.12
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- make STATIC=1 LTO=1
|
||||
|
||||
linux_task:
|
||||
name: "alpine:3.13"
|
||||
container:
|
||||
image: alpine:3.13
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- make STATIC=1 LTO=1
|
||||
|
||||
linux_task:
|
||||
name: "alpine:3.14"
|
||||
container:
|
||||
image: alpine:3.14
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- make STATIC=1 LTO=1
|
||||
|
||||
linux_task:
|
||||
name: "alpine:3.15"
|
||||
container:
|
||||
image: alpine:3.15
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- make STATIC=1 LTO=1
|
||||
|
||||
linux_task:
|
||||
name: "alpine:3.16"
|
||||
container:
|
||||
image: alpine:3.16
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- make STATIC=1 LTO=1
|
||||
|
||||
linux_task:
|
||||
name: "alpine:3.17"
|
||||
container:
|
||||
image: alpine:3.17
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- make STATIC=1 LTO=1
|
||||
|
||||
linux_task:
|
||||
name: "alpine:latest"
|
||||
container:
|
||||
@@ -131,7 +6,7 @@ linux_task:
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- buildtools/install-build-pkgs
|
||||
- make STATIC=1 LTO=1
|
||||
|
||||
linux_task:
|
||||
@@ -142,225 +17,33 @@ linux_task:
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- buildtools/install-build-pkgs
|
||||
- make STATIC=1 LTO=1
|
||||
|
||||
linux_task:
|
||||
name: "centos:7"
|
||||
name: "fedora:41"
|
||||
container:
|
||||
image: centos:7
|
||||
image: fedora:41
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- buildtools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "rocky:8"
|
||||
container:
|
||||
image: rocky:8
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora:30"
|
||||
container:
|
||||
image: fedora:30
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora:31"
|
||||
container:
|
||||
image: fedora:31
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora:32"
|
||||
container:
|
||||
image: fedora:32
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora:33"
|
||||
container:
|
||||
image: fedora:33
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora:34"
|
||||
container:
|
||||
image: fedora:34
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora:35"
|
||||
container:
|
||||
image: fedora:35
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora:36"
|
||||
container:
|
||||
image: fedora:36
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora:37"
|
||||
container:
|
||||
image: fedora:37
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora:38"
|
||||
container:
|
||||
image: fedora:38
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora:latest"
|
||||
container:
|
||||
image: fedora:latest
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "fedora-arm:latest"
|
||||
name: "fedora-arm:41"
|
||||
arm_container:
|
||||
image: fedora:latest
|
||||
image: fedora:41
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- buildtools/install-build-pkgs
|
||||
- make
|
||||
- make rpm
|
||||
|
||||
linux_task:
|
||||
name: "ubuntu:14.04"
|
||||
container:
|
||||
image: ubuntu:14.04
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "ubuntu:16.04"
|
||||
container:
|
||||
image: ubuntu:16.04
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "ubuntu:18.04"
|
||||
container:
|
||||
image: ubuntu:18.04
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "ubuntu:20.04"
|
||||
container:
|
||||
image: ubuntu:20.04
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "ubuntu:22.04"
|
||||
container:
|
||||
@@ -369,7 +52,22 @@ linux_task:
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- buildtools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "ubuntu:24.04"
|
||||
container:
|
||||
image: ubuntu:24.04
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- buildtools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
@@ -384,7 +82,7 @@ linux_task:
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- buildtools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
@@ -399,7 +97,7 @@ linux_task:
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- buildtools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
@@ -407,74 +105,14 @@ linux_task:
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "debian:7"
|
||||
name: "debian:12"
|
||||
container:
|
||||
image: debian:8
|
||||
image: debian:12
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "debian:8"
|
||||
container:
|
||||
image: debian:8
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "debian:9"
|
||||
container:
|
||||
image: debian:9
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "debian:10"
|
||||
container:
|
||||
image: debian:10
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
- dpkg -i ../*.deb
|
||||
- mergerfs -v || true
|
||||
|
||||
linux_task:
|
||||
name: "debian:11"
|
||||
container:
|
||||
image: debian:11
|
||||
cpu: 4
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- buildtools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
@@ -489,7 +127,7 @@ linux_task:
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- buildtools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
@@ -504,7 +142,7 @@ linux_task:
|
||||
memory: 4G
|
||||
timeout_in: 15m
|
||||
script:
|
||||
- tools/install-build-pkgs
|
||||
- buildtools/install-build-pkgs
|
||||
- git fetch
|
||||
- make deb
|
||||
- apt-get -y install fuse
|
||||
|
||||
+1
-6
@@ -1,7 +1,2 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: [trapexit]
|
||||
patreon: trapexit
|
||||
custom: ['https://paypal.me/trapexit','https://buymeacoff.ee/trapexit']
|
||||
ko_fi: trapexit
|
||||
open_collective: trapexit
|
||||
custom: ['https://github.com/trapexit/support']
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
name: "mkdocs"
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
permissions:
|
||||
contents: write
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Configure Git Credentials
|
||||
run: |
|
||||
git config user.name github-actions[bot]
|
||||
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: 3.x
|
||||
- run: pip install --no-cache-dir mkdocs mkdocs-material pymdown-extensions
|
||||
working-directory: ./mkdocs
|
||||
- run: mkdocs gh-deploy --force
|
||||
working-directory: ./mkdocs
|
||||
@@ -23,3 +23,8 @@ debian/changelog
|
||||
|
||||
# RPM files
|
||||
rpmbuild/
|
||||
|
||||
# mkdocs files
|
||||
mkdocs/env
|
||||
mkdocs/.env
|
||||
__pycache__/
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
## Libraries
|
||||
|
||||
### included in repo
|
||||
|
||||
* libfuse: https://github.com/libfuse/libfuse (heavily modified fork of v2.x)
|
||||
* wyhash: https://github.com/wangyi-fudan/wyhash
|
||||
* ghc::filesystem: https://github.com/gulrak/filesystem
|
||||
* nonstd::optional: https://github.com/martinmoene/optional-lite
|
||||
* fmt: https://github.com/fmtlib/fmt
|
||||
* concurrentqueue: https://github.com/cameron314/concurrentqueue
|
||||
* scope_guard: https://github.com/Neargye/scope_guard
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2023, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
Copyright (c) 2024, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
# Copyright (c) 2024, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
#
|
||||
# Permission to use, copy, modify, and/or distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -26,7 +26,7 @@ STRIP = strip
|
||||
PANDOC = pandoc
|
||||
SED = sed
|
||||
RPMBUILD = rpmbuild
|
||||
GIT2DEBCL = ./tools/git2debcl
|
||||
GIT2DEBCL = ./buildtools/git2debcl
|
||||
PKGCONFIG = pkg-config
|
||||
|
||||
GIT_REPO = 0
|
||||
@@ -42,7 +42,7 @@ UGID_USE_RWLOCK = 0
|
||||
ifeq ($(DEBUG),1)
|
||||
OPT_FLAGS := -O0 -g -fsanitize=undefined
|
||||
else
|
||||
OPT_FLAGS := -O2
|
||||
OPT_FLAGS := -O2 -DNDEBUG
|
||||
endif
|
||||
|
||||
ifeq ($(STATIC),1)
|
||||
@@ -68,6 +68,10 @@ TESTS_DEPS = $(TESTS:tests/%.cpp=build/.tests/%.d)
|
||||
TESTS_DEPS += $(DEPS)
|
||||
|
||||
MANPAGE = mergerfs.1
|
||||
CFLAGS ?= ${OPT_FLAGS}
|
||||
CFLAGS := ${CFLAGS} \
|
||||
-Wall \
|
||||
-Wno-unused-result
|
||||
CXXFLAGS ?= ${OPT_FLAGS}
|
||||
CXXFLAGS := \
|
||||
${CXXFLAGS} \
|
||||
@@ -92,6 +96,7 @@ LDFLAGS := \
|
||||
-pthread \
|
||||
-lrt
|
||||
|
||||
# https://www.gnu.org/prep/standards/html_node/Directory-Variables.html
|
||||
DESTDIR =
|
||||
PREFIX = /usr/local
|
||||
EXEC_PREFIX = $(PREFIX)
|
||||
@@ -99,11 +104,13 @@ DATAROOTDIR = $(PREFIX)/share
|
||||
DATADIR = $(DATAROOTDIR)
|
||||
BINDIR = $(EXEC_PREFIX)/bin
|
||||
SBINDIR = $(EXEC_PREFIX)/sbin
|
||||
LIBDIR = $(EXEC_PREFIX)/lib
|
||||
MANDIR = $(DATAROOTDIR)/man
|
||||
MAN1DIR = $(MANDIR)/man1
|
||||
|
||||
INSTALLBINDIR = $(DESTDIR)$(BINDIR)
|
||||
INSTALLSBINDIR = $(DESTDIR)$(SBINDIR)
|
||||
INSTALLLIBDIR = $(DESTDIR)$(LIBDIR)/mergerfs
|
||||
INSTALLMAN1DIR = $(DESTDIR)$(MAN1DIR)
|
||||
|
||||
.PHONY: all
|
||||
@@ -141,7 +148,7 @@ endif
|
||||
|
||||
.PHONY: version
|
||||
version:
|
||||
tools/update-version
|
||||
./buildtools/update-version
|
||||
|
||||
build/stamp:
|
||||
$(MKDIR) -p build/.src build/.tests
|
||||
@@ -153,6 +160,10 @@ build/.src/%.o: src/%.cpp
|
||||
build/.tests/%.o: tests/%.cpp
|
||||
$(CXX) $(CXXFLAGS) $(TESTS_FLAGS) $(FUSE_FLAGS) $(MFS_FLAGS) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
build/preload.so: build/stamp tools/preload.c
|
||||
$(CC) -shared -fPIC $(CFLAGS) $(CPPFLAGS) -o $@ tools/preload.c
|
||||
|
||||
preload: build/preload.so
|
||||
|
||||
.PHONY: clean
|
||||
clean: rpm-clean
|
||||
@@ -166,7 +177,7 @@ ifeq ($(GIT_REPO),1)
|
||||
endif
|
||||
|
||||
.PHONY: install
|
||||
install: install-base install-mount-tools install-man
|
||||
install: install-base install-mount-tools install-preload install-man
|
||||
|
||||
install-base: build/mergerfs
|
||||
$(MKDIR) -p "$(INSTALLBINDIR)"
|
||||
@@ -180,6 +191,10 @@ install-man: $(MANPAGE)
|
||||
$(MKDIR) -p "$(INSTALLMAN1DIR)"
|
||||
$(INSTALL) -v -m 0644 "man/$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
|
||||
|
||||
install-preload: preload
|
||||
$(MKDIR) -p "$(INSTALLLIBDIR)"
|
||||
$(INSTALL) -v -m 444 "build/preload.so" "$(INSTALLLIBDIR)/preload.so"
|
||||
|
||||
install-strip: install-base
|
||||
$(STRIP) "$(INSTALLBINDIR)/mergerfs"
|
||||
|
||||
@@ -225,13 +240,13 @@ endif
|
||||
signed-deb:
|
||||
$(MAKE) distclean
|
||||
$(MAKE) debian-changelog
|
||||
dpkg-source -b .
|
||||
# dpkg-source -b .
|
||||
dpkg-buildpackage -nc
|
||||
|
||||
deb:
|
||||
$(MAKE) distclean
|
||||
$(MAKE) debian-changelog
|
||||
dpkg-source -b .
|
||||
# dpkg-source -b .
|
||||
dpkg-buildpackage -nc -uc -us
|
||||
|
||||
.PHONY: rpm-clean
|
||||
@@ -250,7 +265,7 @@ rpm: tarball
|
||||
|
||||
.PHONY: install-build-pkgs
|
||||
install-build-pkgs:
|
||||
tools/install-build-pkgs
|
||||
./buildtools/install-build-pkgs
|
||||
|
||||
.PHONY: libfuse
|
||||
libfuse:
|
||||
|
||||
+11
-2
@@ -15,6 +15,12 @@ else
|
||||
OPT_FLAGS := -O2
|
||||
endif
|
||||
|
||||
ifeq ($(LTO),1)
|
||||
LTO_FLAGS := -flto
|
||||
else
|
||||
LTO_FLAGS :=
|
||||
endif
|
||||
|
||||
DESTDIR =
|
||||
PREFIX = /usr/local
|
||||
EXEC_PREFIX = $(PREFIX)
|
||||
@@ -38,7 +44,7 @@ SRC_C = \
|
||||
lib/fuse.c \
|
||||
lib/fuse_dirents.c \
|
||||
lib/fuse_lowlevel.c \
|
||||
lib/fuse_mt.c \
|
||||
lib/node.c \
|
||||
lib/fuse_node.c \
|
||||
lib/fuse_opt.c \
|
||||
lib/fuse_session.c \
|
||||
@@ -49,7 +55,8 @@ SRC_CPP = \
|
||||
lib/format.cpp \
|
||||
lib/os.cpp \
|
||||
lib/cpu.cpp \
|
||||
lib/fuse_loop_mt.cpp \
|
||||
lib/fuse_config.cpp \
|
||||
lib/fuse_loop.cpp \
|
||||
lib/fuse_msgbuf.cpp
|
||||
OBJS_C = $(SRC_C:lib/%.c=build/%.o)
|
||||
OBJS_CPP = $(SRC_CPP:lib/%.cpp=build/%.o)
|
||||
@@ -59,12 +66,14 @@ CFLAGS ?= \
|
||||
$(OPT_FLAGS)
|
||||
CFLAGS := \
|
||||
${CFLAGS} \
|
||||
$(LTO_FLAGS) \
|
||||
-std=gnu99 \
|
||||
-Wall \
|
||||
-pipe \
|
||||
-MMD
|
||||
CXXFLAGS := \
|
||||
${CXXFLAGS} \
|
||||
$(LTO_FLAGS) \
|
||||
-std=c++11 \
|
||||
-Wall \
|
||||
-pipe \
|
||||
|
||||
@@ -539,6 +539,16 @@ struct fuse_operations
|
||||
off_t offset_out,
|
||||
size_t size,
|
||||
int flags);
|
||||
|
||||
ssize_t (*setupmapping)(uint64_t *fh_,
|
||||
uint64_t foffset_,
|
||||
uint64_t len_,
|
||||
uint64_t flags_,
|
||||
uint64_t moffset_);
|
||||
|
||||
int (*removemapping)();
|
||||
int (*syncfs)();
|
||||
int (*tmpfile)(const char *, mode_t, fuse_file_info_t *);
|
||||
};
|
||||
|
||||
/** Extra context that may be needed by some filesystems
|
||||
@@ -629,6 +639,7 @@ void fuse_exit(struct fuse *f);
|
||||
|
||||
int fuse_config_read_thread_count(const struct fuse *f);
|
||||
int fuse_config_process_thread_count(const struct fuse *f);
|
||||
int fuse_config_process_thread_queue_depth(const struct fuse *f);
|
||||
const char* fuse_config_pin_threads(const struct fuse *f);
|
||||
|
||||
/**
|
||||
@@ -764,6 +775,10 @@ void fuse_set_getcontext_func(struct fuse_context *(*func)(void));
|
||||
/** Get session from fuse object */
|
||||
struct fuse_session *fuse_get_session(struct fuse *f);
|
||||
|
||||
void fuse_gc1();
|
||||
void fuse_gc();
|
||||
void fuse_invalidate_all_nodes();
|
||||
|
||||
EXTERN_C_END
|
||||
|
||||
#endif /* _FUSE_H_ */
|
||||
|
||||
@@ -84,6 +84,10 @@ struct fuse_file_info_t
|
||||
|
||||
uint32_t auto_cache : 1;
|
||||
|
||||
uint32_t parallel_direct_writes:1;
|
||||
|
||||
uint32_t noflush:1;
|
||||
|
||||
/** File handle. May be filled in by filesystem in open().
|
||||
Available in all other file operations */
|
||||
uint64_t fh;
|
||||
@@ -104,23 +108,26 @@ struct fuse_file_info_t
|
||||
* FUSE_CAP_IOCTL_DIR: ioctl support on directories
|
||||
* FUSE_CAP_CACHE_SYMLINKS: cache READLINK responses
|
||||
*/
|
||||
#define FUSE_CAP_ASYNC_READ (1 << 0)
|
||||
#define FUSE_CAP_POSIX_LOCKS (1 << 1)
|
||||
#define FUSE_CAP_ATOMIC_O_TRUNC (1 << 3)
|
||||
#define FUSE_CAP_EXPORT_SUPPORT (1 << 4)
|
||||
#define FUSE_CAP_BIG_WRITES (1 << 5)
|
||||
#define FUSE_CAP_DONT_MASK (1 << 6)
|
||||
#define FUSE_CAP_FLOCK_LOCKS (1 << 10)
|
||||
#define FUSE_CAP_IOCTL_DIR (1 << 11)
|
||||
#define FUSE_CAP_READDIR_PLUS (1 << 13)
|
||||
#define FUSE_CAP_READDIR_PLUS_AUTO (1 << 14)
|
||||
#define FUSE_CAP_ASYNC_DIO (1 << 15)
|
||||
#define FUSE_CAP_WRITEBACK_CACHE (1 << 16)
|
||||
#define FUSE_CAP_PARALLEL_DIROPS (1 << 18)
|
||||
#define FUSE_CAP_POSIX_ACL (1 << 19)
|
||||
#define FUSE_CAP_CACHE_SYMLINKS (1 << 20)
|
||||
#define FUSE_CAP_MAX_PAGES (1 << 21)
|
||||
#define FUSE_CAP_SETXATTR_EXT (1 << 22)
|
||||
#define FUSE_CAP_ASYNC_READ (1ULL << 0)
|
||||
#define FUSE_CAP_POSIX_LOCKS (1ULL << 1)
|
||||
#define FUSE_CAP_ATOMIC_O_TRUNC (1ULL << 3)
|
||||
#define FUSE_CAP_EXPORT_SUPPORT (1ULL << 4)
|
||||
#define FUSE_CAP_BIG_WRITES (1ULL << 5)
|
||||
#define FUSE_CAP_DONT_MASK (1ULL << 6)
|
||||
#define FUSE_CAP_FLOCK_LOCKS (1ULL << 10)
|
||||
#define FUSE_CAP_IOCTL_DIR (1ULL << 11)
|
||||
#define FUSE_CAP_READDIR_PLUS (1ULL << 13)
|
||||
#define FUSE_CAP_READDIR_PLUS_AUTO (1ULL << 14)
|
||||
#define FUSE_CAP_ASYNC_DIO (1ULL << 15)
|
||||
#define FUSE_CAP_WRITEBACK_CACHE (1ULL << 16)
|
||||
#define FUSE_CAP_PARALLEL_DIROPS (1ULL << 18)
|
||||
#define FUSE_CAP_POSIX_ACL (1ULL << 19)
|
||||
#define FUSE_CAP_CACHE_SYMLINKS (1ULL << 20)
|
||||
#define FUSE_CAP_MAX_PAGES (1ULL << 21)
|
||||
#define FUSE_CAP_SETXATTR_EXT (1ULL << 22)
|
||||
#define FUSE_CAP_DIRECT_IO_ALLOW_MMAP (1ULL << 23)
|
||||
#define FUSE_CAP_CREATE_SUPP_GROUP (1ULL << 24)
|
||||
|
||||
|
||||
/**
|
||||
* Ioctl flags
|
||||
@@ -146,56 +153,17 @@ struct fuse_file_info_t
|
||||
* indicate the value requested by the filesystem. The requested
|
||||
* value must usually be smaller than the indicated value.
|
||||
*/
|
||||
struct fuse_conn_info {
|
||||
/**
|
||||
* Major version of the protocol (read-only)
|
||||
*/
|
||||
struct fuse_conn_info
|
||||
{
|
||||
unsigned proto_major;
|
||||
|
||||
/**
|
||||
* Minor version of the protocol (read-only)
|
||||
*/
|
||||
unsigned proto_minor;
|
||||
|
||||
/**
|
||||
* Maximum size of the write buffer
|
||||
*/
|
||||
unsigned max_write;
|
||||
|
||||
/**
|
||||
* Maximum readahead
|
||||
*/
|
||||
unsigned max_readahead;
|
||||
|
||||
/**
|
||||
* Capability flags, that the kernel supports
|
||||
*/
|
||||
unsigned capable;
|
||||
|
||||
/**
|
||||
* Capability flags, that the filesystem wants to enable
|
||||
*/
|
||||
unsigned want;
|
||||
|
||||
/**
|
||||
* Maximum number of backgrounded requests
|
||||
*/
|
||||
uint64_t capable;
|
||||
uint64_t want;
|
||||
unsigned max_background;
|
||||
|
||||
/**
|
||||
* Kernel congestion threshold parameter
|
||||
*/
|
||||
unsigned congestion_threshold;
|
||||
|
||||
/**
|
||||
* Max pages
|
||||
*/
|
||||
uint16_t max_pages;
|
||||
|
||||
/**
|
||||
* For future use.
|
||||
*/
|
||||
unsigned reserved[22];
|
||||
};
|
||||
|
||||
struct fuse_session;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2023, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
int fuse_config_get_read_thread_count();
|
||||
int fuse_config_get_process_thread_count();
|
||||
int fuse_config_get_process_thread_queue_depth();
|
||||
std::string fuse_config_get_pin_threads();
|
||||
|
||||
void fuse_config_set_read_thread_count(int const);
|
||||
void fuse_config_set_process_thread_count(int const);
|
||||
void fuse_config_set_process_thread_queue_depth(int const);
|
||||
void fuse_config_set_pin_threads(std::string const);
|
||||
@@ -63,14 +63,14 @@ int fuse_dirents_add_plus(fuse_dirents_t *d,
|
||||
const uint64_t namelen,
|
||||
const fuse_entry_t *entry,
|
||||
const struct stat *st);
|
||||
int fuse_dirents_add_linux(fuse_dirents_t *d,
|
||||
const struct linux_dirent64 *de,
|
||||
const uint64_t namelen);
|
||||
int fuse_dirents_add_linux_plus(fuse_dirents_t *d,
|
||||
const struct linux_dirent64 *de,
|
||||
const uint64_t namelen,
|
||||
const fuse_entry_t *entry,
|
||||
const struct stat *st);
|
||||
int fuse_dirents_add_linux(fuse_dirents_t *d,
|
||||
const linux_dirent64_t *de,
|
||||
const uint64_t namelen);
|
||||
int fuse_dirents_add_linux_plus(fuse_dirents_t *d,
|
||||
const linux_dirent64_t *de,
|
||||
const uint64_t namelen,
|
||||
const fuse_entry_t *entry,
|
||||
const struct stat *st);
|
||||
|
||||
void *fuse_dirents_find(fuse_dirents_t *d,
|
||||
const uint64_t ino);
|
||||
|
||||
+133
-15
@@ -197,6 +197,20 @@
|
||||
*
|
||||
* 7.37
|
||||
* - add FUSE_TMPFILE
|
||||
*
|
||||
* 7.38
|
||||
* - add FUSE_EXPIRE_ONLY flag to fuse_notify_inval_entry
|
||||
* - add FOPEN_PARALLEL_DIRECT_WRITES
|
||||
* - add total_extlen to fuse_in_header
|
||||
* - add FUSE_MAX_NR_SECCTX
|
||||
* - add extension header
|
||||
* - add FUSE_EXT_GROUPS
|
||||
* - add FUSE_CREATE_SUPP_GROUP
|
||||
* - add FUSE_HAS_EXPIRE_ONLY
|
||||
*
|
||||
* 7.39
|
||||
* - add FUSE_DIRECT_IO_ALLOW_MMAP
|
||||
* - add FUSE_STATX and related structures
|
||||
*/
|
||||
|
||||
#ifndef _LINUX_FUSE_H
|
||||
@@ -232,7 +246,7 @@
|
||||
#define FUSE_KERNEL_VERSION 7
|
||||
|
||||
/** Minor version number of this interface */
|
||||
#define FUSE_KERNEL_MINOR_VERSION 37
|
||||
#define FUSE_KERNEL_MINOR_VERSION 39
|
||||
|
||||
/** The node ID of the root inode */
|
||||
#define FUSE_ROOT_ID 1
|
||||
@@ -259,6 +273,40 @@ struct fuse_attr {
|
||||
uint32_t flags;
|
||||
};
|
||||
|
||||
/*
|
||||
* The following structures are bit-for-bit compatible with the statx(2) ABI in
|
||||
* Linux.
|
||||
*/
|
||||
struct fuse_sx_time {
|
||||
int64_t tv_sec;
|
||||
uint32_t tv_nsec;
|
||||
int32_t __reserved;
|
||||
};
|
||||
|
||||
struct fuse_statx {
|
||||
uint32_t mask;
|
||||
uint32_t blksize;
|
||||
uint64_t attributes;
|
||||
uint32_t nlink;
|
||||
uint32_t uid;
|
||||
uint32_t gid;
|
||||
uint16_t mode;
|
||||
uint16_t __spare0[1];
|
||||
uint64_t ino;
|
||||
uint64_t size;
|
||||
uint64_t blocks;
|
||||
uint64_t attributes_mask;
|
||||
struct fuse_sx_time atime;
|
||||
struct fuse_sx_time btime;
|
||||
struct fuse_sx_time ctime;
|
||||
struct fuse_sx_time mtime;
|
||||
uint32_t rdev_major;
|
||||
uint32_t rdev_minor;
|
||||
uint32_t dev_major;
|
||||
uint32_t dev_minor;
|
||||
uint64_t __spare2[14];
|
||||
};
|
||||
|
||||
struct fuse_kstatfs {
|
||||
uint64_t blocks;
|
||||
uint64_t bfree;
|
||||
@@ -282,18 +330,18 @@ struct fuse_file_lock {
|
||||
/**
|
||||
* Bitmasks for fuse_setattr_in.valid
|
||||
*/
|
||||
#define FATTR_MODE (1 << 0)
|
||||
#define FATTR_UID (1 << 1)
|
||||
#define FATTR_GID (1 << 2)
|
||||
#define FATTR_SIZE (1 << 3)
|
||||
#define FATTR_ATIME (1 << 4)
|
||||
#define FATTR_MTIME (1 << 5)
|
||||
#define FATTR_FH (1 << 6)
|
||||
#define FATTR_ATIME_NOW (1 << 7)
|
||||
#define FATTR_MTIME_NOW (1 << 8)
|
||||
#define FATTR_LOCKOWNER (1 << 9)
|
||||
#define FATTR_CTIME (1 << 10)
|
||||
#define FATTR_KILL_SUIDGID (1 << 11)
|
||||
#define FATTR_MODE (1 << 0)
|
||||
#define FATTR_UID (1 << 1)
|
||||
#define FATTR_GID (1 << 2)
|
||||
#define FATTR_SIZE (1 << 3)
|
||||
#define FATTR_ATIME (1 << 4)
|
||||
#define FATTR_MTIME (1 << 5)
|
||||
#define FATTR_FH (1 << 6)
|
||||
#define FATTR_ATIME_NOW (1 << 7)
|
||||
#define FATTR_MTIME_NOW (1 << 8)
|
||||
#define FATTR_LOCKOWNER (1 << 9)
|
||||
#define FATTR_CTIME (1 << 10)
|
||||
#define FATTR_KILL_SUIDGID (1 << 11)
|
||||
|
||||
/**
|
||||
* Flags returned by the OPEN request
|
||||
@@ -304,6 +352,7 @@ struct fuse_file_lock {
|
||||
* FOPEN_CACHE_DIR: allow caching this directory
|
||||
* FOPEN_STREAM: the file is stream-like (no file position at all)
|
||||
* FOPEN_NOFLUSH: don't flush data cache on close (unless FUSE_WRITEBACK_CACHE)
|
||||
* FOPEN_PARALLEL_DIRECT_WRITES: Allow concurrent direct writes on the same inode
|
||||
*/
|
||||
#define FOPEN_DIRECT_IO (1 << 0)
|
||||
#define FOPEN_KEEP_CACHE (1 << 1)
|
||||
@@ -311,6 +360,7 @@ struct fuse_file_lock {
|
||||
#define FOPEN_CACHE_DIR (1 << 3)
|
||||
#define FOPEN_STREAM (1 << 4)
|
||||
#define FOPEN_NOFLUSH (1 << 5)
|
||||
#define FOPEN_PARALLEL_DIRECT_WRITES (1 << 6)
|
||||
|
||||
/**
|
||||
* INIT request/reply flags
|
||||
@@ -356,6 +406,10 @@ struct fuse_file_lock {
|
||||
* FUSE_SECURITY_CTX: add security context to create, mkdir, symlink, and
|
||||
* mknod
|
||||
* FUSE_HAS_INODE_DAX: use per inode DAX
|
||||
* FUSE_CREATE_SUPP_GROUP: add supplementary group info to create, mkdir,
|
||||
* symlink and mknod (single group that matches parent)
|
||||
* FUSE_HAS_EXPIRE_ONLY: kernel supports expiry-only entry invalidation
|
||||
* FUSE_DIRECT_IO_ALLOW_MMAP: allow shared mmap in FOPEN_DIRECT_IO mode.
|
||||
*/
|
||||
#define FUSE_ASYNC_READ (1 << 0)
|
||||
#define FUSE_POSIX_LOCKS (1 << 1)
|
||||
@@ -392,6 +446,12 @@ struct fuse_file_lock {
|
||||
/* bits 32..63 get shifted down 32 bits into the flags2 field */
|
||||
#define FUSE_SECURITY_CTX (1ULL << 32)
|
||||
#define FUSE_HAS_INODE_DAX (1ULL << 33)
|
||||
#define FUSE_CREATE_SUPP_GROUP (1ULL << 34)
|
||||
#define FUSE_HAS_EXPIRE_ONLY (1ULL << 35)
|
||||
#define FUSE_DIRECT_IO_ALLOW_MMAP (1ULL << 36)
|
||||
|
||||
/* Obsolete alias for FUSE_DIRECT_IO_ALLOW_MMAP */
|
||||
#define FUSE_DIRECT_IO_RELAX FUSE_DIRECT_IO_ALLOW_MMAP
|
||||
|
||||
/**
|
||||
* CUSE INIT request/reply flags
|
||||
@@ -491,6 +551,23 @@ struct fuse_file_lock {
|
||||
*/
|
||||
#define FUSE_SETXATTR_ACL_KILL_SGID (1 << 0)
|
||||
|
||||
/**
|
||||
* notify_inval_entry flags
|
||||
* FUSE_EXPIRE_ONLY
|
||||
*/
|
||||
#define FUSE_EXPIRE_ONLY (1 << 0)
|
||||
|
||||
/**
|
||||
* extension type
|
||||
* FUSE_MAX_NR_SECCTX: maximum value of &fuse_secctx_header.nr_secctx
|
||||
* FUSE_EXT_GROUPS: &fuse_supp_groups extension
|
||||
*/
|
||||
enum fuse_ext_type {
|
||||
/* Types 0..31 are reserved for fuse_secctx_header */
|
||||
FUSE_MAX_NR_SECCTX = 31,
|
||||
FUSE_EXT_GROUPS = 32,
|
||||
};
|
||||
|
||||
enum fuse_opcode {
|
||||
FUSE_LOOKUP = 1,
|
||||
FUSE_FORGET = 2, /* no reply */
|
||||
@@ -541,6 +618,7 @@ enum fuse_opcode {
|
||||
FUSE_REMOVEMAPPING = 49,
|
||||
FUSE_SYNCFS = 50,
|
||||
FUSE_TMPFILE = 51,
|
||||
FUSE_STATX = 52,
|
||||
|
||||
/* CUSE specific operations */
|
||||
CUSE_INIT = 4096,
|
||||
@@ -605,6 +683,22 @@ struct fuse_attr_out {
|
||||
struct fuse_attr attr;
|
||||
};
|
||||
|
||||
struct fuse_statx_in {
|
||||
uint32_t getattr_flags;
|
||||
uint32_t reserved;
|
||||
uint64_t fh;
|
||||
uint32_t sx_flags;
|
||||
uint32_t sx_mask;
|
||||
};
|
||||
|
||||
struct fuse_statx_out {
|
||||
uint64_t attr_valid; /* Cache timeout for the attributes */
|
||||
uint32_t attr_valid_nsec;
|
||||
uint32_t flags;
|
||||
uint64_t spare[2];
|
||||
struct fuse_statx stat;
|
||||
};
|
||||
|
||||
#define FUSE_COMPAT_MKNOD_IN_SIZE 8
|
||||
|
||||
struct fuse_mknod_in {
|
||||
@@ -874,7 +968,8 @@ struct fuse_in_header {
|
||||
uint32_t uid;
|
||||
uint32_t gid;
|
||||
uint32_t pid;
|
||||
uint32_t padding;
|
||||
uint16_t total_extlen; /* length of extensions in 8byte units */
|
||||
uint16_t padding;
|
||||
};
|
||||
|
||||
struct fuse_out_header {
|
||||
@@ -919,7 +1014,7 @@ struct fuse_notify_inval_inode_out {
|
||||
struct fuse_notify_inval_entry_out {
|
||||
uint64_t parent;
|
||||
uint32_t namelen;
|
||||
uint32_t padding;
|
||||
uint32_t flags;
|
||||
};
|
||||
|
||||
struct fuse_notify_delete_out {
|
||||
@@ -1035,4 +1130,27 @@ struct fuse_secctx_header {
|
||||
uint32_t nr_secctx;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct fuse_ext_header - extension header
|
||||
* @size: total size of this extension including this header
|
||||
* @type: type of extension
|
||||
*
|
||||
* This is made compatible with fuse_secctx_header by using type values >
|
||||
* FUSE_MAX_NR_SECCTX
|
||||
*/
|
||||
struct fuse_ext_header {
|
||||
uint32_t size;
|
||||
uint32_t type;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct fuse_supp_groups - Supplementary group extension
|
||||
* @nr_groups: number of supplementary groups
|
||||
* @groups: flexible array of group IDs
|
||||
*/
|
||||
struct fuse_supp_groups {
|
||||
uint32_t nr_groups;
|
||||
uint32_t groups[];
|
||||
};
|
||||
|
||||
#endif /* _LINUX_FUSE_H */
|
||||
|
||||
@@ -1007,6 +1007,15 @@ struct fuse_lowlevel_ops
|
||||
*/
|
||||
void (*copy_file_range)(fuse_req_t req,
|
||||
const struct fuse_in_header *hdr);
|
||||
|
||||
void (*setupmapping)(fuse_req_t req,
|
||||
const struct fuse_in_header *hdr);
|
||||
void (*removemapping)(fuse_req_t req,
|
||||
const struct fuse_in_header *hdr);
|
||||
void (*syncfs)(fuse_req_t req,
|
||||
const struct fuse_in_header *hdr);
|
||||
void (*tmpfile)(fuse_req_t req,
|
||||
const struct fuse_in_header *hdr);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1460,6 +1469,7 @@ void fuse_session_process(struct fuse_session *se,
|
||||
int fuse_session_loop_mt(struct fuse_session *se,
|
||||
const int read_thread_count,
|
||||
const int process_thread_count,
|
||||
const int process_thread_queue_depth,
|
||||
const char *pin_threads_type);
|
||||
|
||||
/* ----------------------------------------------------------- *
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
typedef struct fuse_msgbuf_t fuse_msgbuf_t;
|
||||
struct fuse_msgbuf_t
|
||||
{
|
||||
char *mem;
|
||||
uint32_t size;
|
||||
uint32_t used;
|
||||
char *mem;
|
||||
};
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
struct linux_dirent64
|
||||
#define DIRENT_NAMELEN(X) (strlen((X)->name))
|
||||
|
||||
typedef struct linux_dirent64_t linux_dirent64_t;
|
||||
struct linux_dirent64_t
|
||||
{
|
||||
uint64_t ino;
|
||||
int64_t off;
|
||||
|
||||
@@ -0,0 +1,582 @@
|
||||
// Provides an efficient blocking version of moodycamel::ConcurrentQueue.
|
||||
// ©2015-2020 Cameron Desrochers. Distributed under the terms of the simplified
|
||||
// BSD license, available at the top of concurrentqueue.h.
|
||||
// Also dual-licensed under the Boost Software License (see LICENSE.md)
|
||||
// Uses Jeff Preshing's semaphore implementation (under the terms of its
|
||||
// separate zlib license, see lightweightsemaphore.h).
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "concurrentqueue.h"
|
||||
#include "lightweightsemaphore.h"
|
||||
|
||||
#include <type_traits>
|
||||
#include <cerrno>
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
|
||||
namespace moodycamel
|
||||
{
|
||||
// This is a blocking version of the queue. It has an almost identical interface to
|
||||
// the normal non-blocking version, with the addition of various wait_dequeue() methods
|
||||
// and the removal of producer-specific dequeue methods.
|
||||
template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
|
||||
class BlockingConcurrentQueue
|
||||
{
|
||||
private:
|
||||
typedef ::moodycamel::ConcurrentQueue<T, Traits> ConcurrentQueue;
|
||||
typedef ::moodycamel::LightweightSemaphore LightweightSemaphore;
|
||||
|
||||
public:
|
||||
typedef typename ConcurrentQueue::producer_token_t producer_token_t;
|
||||
typedef typename ConcurrentQueue::consumer_token_t consumer_token_t;
|
||||
|
||||
typedef typename ConcurrentQueue::index_t index_t;
|
||||
typedef typename ConcurrentQueue::size_t size_t;
|
||||
typedef typename std::make_signed<size_t>::type ssize_t;
|
||||
|
||||
static const size_t BLOCK_SIZE = ConcurrentQueue::BLOCK_SIZE;
|
||||
static const size_t EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD = ConcurrentQueue::EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD;
|
||||
static const size_t EXPLICIT_INITIAL_INDEX_SIZE = ConcurrentQueue::EXPLICIT_INITIAL_INDEX_SIZE;
|
||||
static const size_t IMPLICIT_INITIAL_INDEX_SIZE = ConcurrentQueue::IMPLICIT_INITIAL_INDEX_SIZE;
|
||||
static const size_t INITIAL_IMPLICIT_PRODUCER_HASH_SIZE = ConcurrentQueue::INITIAL_IMPLICIT_PRODUCER_HASH_SIZE;
|
||||
static const std::uint32_t EXPLICIT_CONSUMER_CONSUMPTION_QUOTA_BEFORE_ROTATE = ConcurrentQueue::EXPLICIT_CONSUMER_CONSUMPTION_QUOTA_BEFORE_ROTATE;
|
||||
static const size_t MAX_SUBQUEUE_SIZE = ConcurrentQueue::MAX_SUBQUEUE_SIZE;
|
||||
|
||||
public:
|
||||
// Creates a queue with at least `capacity` element slots; note that the
|
||||
// actual number of elements that can be inserted without additional memory
|
||||
// allocation depends on the number of producers and the block size (e.g. if
|
||||
// the block size is equal to `capacity`, only a single block will be allocated
|
||||
// up-front, which means only a single producer will be able to enqueue elements
|
||||
// without an extra allocation -- blocks aren't shared between producers).
|
||||
// This method is not thread safe -- it is up to the user to ensure that the
|
||||
// queue is fully constructed before it starts being used by other threads (this
|
||||
// includes making the memory effects of construction visible, possibly with a
|
||||
// memory barrier).
|
||||
explicit BlockingConcurrentQueue(size_t capacity = 6 * BLOCK_SIZE)
|
||||
: inner(capacity), sema(create<LightweightSemaphore, ssize_t, int>(0, (int)Traits::MAX_SEMA_SPINS), &BlockingConcurrentQueue::template destroy<LightweightSemaphore>)
|
||||
{
|
||||
assert(reinterpret_cast<ConcurrentQueue*>((BlockingConcurrentQueue*)1) == &((BlockingConcurrentQueue*)1)->inner && "BlockingConcurrentQueue must have ConcurrentQueue as its first member");
|
||||
if (!sema) {
|
||||
MOODYCAMEL_THROW(std::bad_alloc());
|
||||
}
|
||||
}
|
||||
|
||||
BlockingConcurrentQueue(size_t minCapacity, size_t maxExplicitProducers, size_t maxImplicitProducers)
|
||||
: inner(minCapacity, maxExplicitProducers, maxImplicitProducers), sema(create<LightweightSemaphore, ssize_t, int>(0, (int)Traits::MAX_SEMA_SPINS), &BlockingConcurrentQueue::template destroy<LightweightSemaphore>)
|
||||
{
|
||||
assert(reinterpret_cast<ConcurrentQueue*>((BlockingConcurrentQueue*)1) == &((BlockingConcurrentQueue*)1)->inner && "BlockingConcurrentQueue must have ConcurrentQueue as its first member");
|
||||
if (!sema) {
|
||||
MOODYCAMEL_THROW(std::bad_alloc());
|
||||
}
|
||||
}
|
||||
|
||||
// Disable copying and copy assignment
|
||||
BlockingConcurrentQueue(BlockingConcurrentQueue const&) MOODYCAMEL_DELETE_FUNCTION;
|
||||
BlockingConcurrentQueue& operator=(BlockingConcurrentQueue const&) MOODYCAMEL_DELETE_FUNCTION;
|
||||
|
||||
// Moving is supported, but note that it is *not* a thread-safe operation.
|
||||
// Nobody can use the queue while it's being moved, and the memory effects
|
||||
// of that move must be propagated to other threads before they can use it.
|
||||
// Note: When a queue is moved, its tokens are still valid but can only be
|
||||
// used with the destination queue (i.e. semantically they are moved along
|
||||
// with the queue itself).
|
||||
BlockingConcurrentQueue(BlockingConcurrentQueue&& other) MOODYCAMEL_NOEXCEPT
|
||||
: inner(std::move(other.inner)), sema(std::move(other.sema))
|
||||
{ }
|
||||
|
||||
inline BlockingConcurrentQueue& operator=(BlockingConcurrentQueue&& other) MOODYCAMEL_NOEXCEPT
|
||||
{
|
||||
return swap_internal(other);
|
||||
}
|
||||
|
||||
// Swaps this queue's state with the other's. Not thread-safe.
|
||||
// Swapping two queues does not invalidate their tokens, however
|
||||
// the tokens that were created for one queue must be used with
|
||||
// only the swapped queue (i.e. the tokens are tied to the
|
||||
// queue's movable state, not the object itself).
|
||||
inline void swap(BlockingConcurrentQueue& other) MOODYCAMEL_NOEXCEPT
|
||||
{
|
||||
swap_internal(other);
|
||||
}
|
||||
|
||||
private:
|
||||
BlockingConcurrentQueue& swap_internal(BlockingConcurrentQueue& other)
|
||||
{
|
||||
if (this == &other) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
inner.swap(other.inner);
|
||||
sema.swap(other.sema);
|
||||
return *this;
|
||||
}
|
||||
|
||||
public:
|
||||
// Enqueues a single item (by copying it).
|
||||
// Allocates memory if required. Only fails if memory allocation fails (or implicit
|
||||
// production is disabled because Traits::INITIAL_IMPLICIT_PRODUCER_HASH_SIZE is 0,
|
||||
// or Traits::MAX_SUBQUEUE_SIZE has been defined and would be surpassed).
|
||||
// Thread-safe.
|
||||
inline bool enqueue(T const& item)
|
||||
{
|
||||
if ((details::likely)(inner.enqueue(item))) {
|
||||
sema->signal();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enqueues a single item (by moving it, if possible).
|
||||
// Allocates memory if required. Only fails if memory allocation fails (or implicit
|
||||
// production is disabled because Traits::INITIAL_IMPLICIT_PRODUCER_HASH_SIZE is 0,
|
||||
// or Traits::MAX_SUBQUEUE_SIZE has been defined and would be surpassed).
|
||||
// Thread-safe.
|
||||
inline bool enqueue(T&& item)
|
||||
{
|
||||
if ((details::likely)(inner.enqueue(std::move(item)))) {
|
||||
sema->signal();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enqueues a single item (by copying it) using an explicit producer token.
|
||||
// Allocates memory if required. Only fails if memory allocation fails (or
|
||||
// Traits::MAX_SUBQUEUE_SIZE has been defined and would be surpassed).
|
||||
// Thread-safe.
|
||||
inline bool enqueue(producer_token_t const& token, T const& item)
|
||||
{
|
||||
if ((details::likely)(inner.enqueue(token, item))) {
|
||||
sema->signal();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enqueues a single item (by moving it, if possible) using an explicit producer token.
|
||||
// Allocates memory if required. Only fails if memory allocation fails (or
|
||||
// Traits::MAX_SUBQUEUE_SIZE has been defined and would be surpassed).
|
||||
// Thread-safe.
|
||||
inline bool enqueue(producer_token_t const& token, T&& item)
|
||||
{
|
||||
if ((details::likely)(inner.enqueue(token, std::move(item)))) {
|
||||
sema->signal();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enqueues several items.
|
||||
// Allocates memory if required. Only fails if memory allocation fails (or
|
||||
// implicit production is disabled because Traits::INITIAL_IMPLICIT_PRODUCER_HASH_SIZE
|
||||
// is 0, or Traits::MAX_SUBQUEUE_SIZE has been defined and would be surpassed).
|
||||
// Note: Use std::make_move_iterator if the elements should be moved instead of copied.
|
||||
// Thread-safe.
|
||||
template<typename It>
|
||||
inline bool enqueue_bulk(It itemFirst, size_t count)
|
||||
{
|
||||
if ((details::likely)(inner.enqueue_bulk(std::forward<It>(itemFirst), count))) {
|
||||
sema->signal((LightweightSemaphore::ssize_t)(ssize_t)count);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enqueues several items using an explicit producer token.
|
||||
// Allocates memory if required. Only fails if memory allocation fails
|
||||
// (or Traits::MAX_SUBQUEUE_SIZE has been defined and would be surpassed).
|
||||
// Note: Use std::make_move_iterator if the elements should be moved
|
||||
// instead of copied.
|
||||
// Thread-safe.
|
||||
template<typename It>
|
||||
inline bool enqueue_bulk(producer_token_t const& token, It itemFirst, size_t count)
|
||||
{
|
||||
if ((details::likely)(inner.enqueue_bulk(token, std::forward<It>(itemFirst), count))) {
|
||||
sema->signal((LightweightSemaphore::ssize_t)(ssize_t)count);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enqueues a single item (by copying it).
|
||||
// Does not allocate memory. Fails if not enough room to enqueue (or implicit
|
||||
// production is disabled because Traits::INITIAL_IMPLICIT_PRODUCER_HASH_SIZE
|
||||
// is 0).
|
||||
// Thread-safe.
|
||||
inline bool try_enqueue(T const& item)
|
||||
{
|
||||
if (inner.try_enqueue(item)) {
|
||||
sema->signal();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enqueues a single item (by moving it, if possible).
|
||||
// Does not allocate memory (except for one-time implicit producer).
|
||||
// Fails if not enough room to enqueue (or implicit production is
|
||||
// disabled because Traits::INITIAL_IMPLICIT_PRODUCER_HASH_SIZE is 0).
|
||||
// Thread-safe.
|
||||
inline bool try_enqueue(T&& item)
|
||||
{
|
||||
if (inner.try_enqueue(std::move(item))) {
|
||||
sema->signal();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enqueues a single item (by copying it) using an explicit producer token.
|
||||
// Does not allocate memory. Fails if not enough room to enqueue.
|
||||
// Thread-safe.
|
||||
inline bool try_enqueue(producer_token_t const& token, T const& item)
|
||||
{
|
||||
if (inner.try_enqueue(token, item)) {
|
||||
sema->signal();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enqueues a single item (by moving it, if possible) using an explicit producer token.
|
||||
// Does not allocate memory. Fails if not enough room to enqueue.
|
||||
// Thread-safe.
|
||||
inline bool try_enqueue(producer_token_t const& token, T&& item)
|
||||
{
|
||||
if (inner.try_enqueue(token, std::move(item))) {
|
||||
sema->signal();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enqueues several items.
|
||||
// Does not allocate memory (except for one-time implicit producer).
|
||||
// Fails if not enough room to enqueue (or implicit production is
|
||||
// disabled because Traits::INITIAL_IMPLICIT_PRODUCER_HASH_SIZE is 0).
|
||||
// Note: Use std::make_move_iterator if the elements should be moved
|
||||
// instead of copied.
|
||||
// Thread-safe.
|
||||
template<typename It>
|
||||
inline bool try_enqueue_bulk(It itemFirst, size_t count)
|
||||
{
|
||||
if (inner.try_enqueue_bulk(std::forward<It>(itemFirst), count)) {
|
||||
sema->signal((LightweightSemaphore::ssize_t)(ssize_t)count);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enqueues several items using an explicit producer token.
|
||||
// Does not allocate memory. Fails if not enough room to enqueue.
|
||||
// Note: Use std::make_move_iterator if the elements should be moved
|
||||
// instead of copied.
|
||||
// Thread-safe.
|
||||
template<typename It>
|
||||
inline bool try_enqueue_bulk(producer_token_t const& token, It itemFirst, size_t count)
|
||||
{
|
||||
if (inner.try_enqueue_bulk(token, std::forward<It>(itemFirst), count)) {
|
||||
sema->signal((LightweightSemaphore::ssize_t)(ssize_t)count);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Attempts to dequeue from the queue.
|
||||
// Returns false if all producer streams appeared empty at the time they
|
||||
// were checked (so, the queue is likely but not guaranteed to be empty).
|
||||
// Never allocates. Thread-safe.
|
||||
template<typename U>
|
||||
inline bool try_dequeue(U& item)
|
||||
{
|
||||
if (sema->tryWait()) {
|
||||
while (!inner.try_dequeue(item)) {
|
||||
continue;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Attempts to dequeue from the queue using an explicit consumer token.
|
||||
// Returns false if all producer streams appeared empty at the time they
|
||||
// were checked (so, the queue is likely but not guaranteed to be empty).
|
||||
// Never allocates. Thread-safe.
|
||||
template<typename U>
|
||||
inline bool try_dequeue(consumer_token_t& token, U& item)
|
||||
{
|
||||
if (sema->tryWait()) {
|
||||
while (!inner.try_dequeue(token, item)) {
|
||||
continue;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Attempts to dequeue several elements from the queue.
|
||||
// Returns the number of items actually dequeued.
|
||||
// Returns 0 if all producer streams appeared empty at the time they
|
||||
// were checked (so, the queue is likely but not guaranteed to be empty).
|
||||
// Never allocates. Thread-safe.
|
||||
template<typename It>
|
||||
inline size_t try_dequeue_bulk(It itemFirst, size_t max)
|
||||
{
|
||||
size_t count = 0;
|
||||
max = (size_t)sema->tryWaitMany((LightweightSemaphore::ssize_t)(ssize_t)max);
|
||||
while (count != max) {
|
||||
count += inner.template try_dequeue_bulk<It&>(itemFirst, max - count);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// Attempts to dequeue several elements from the queue using an explicit consumer token.
|
||||
// Returns the number of items actually dequeued.
|
||||
// Returns 0 if all producer streams appeared empty at the time they
|
||||
// were checked (so, the queue is likely but not guaranteed to be empty).
|
||||
// Never allocates. Thread-safe.
|
||||
template<typename It>
|
||||
inline size_t try_dequeue_bulk(consumer_token_t& token, It itemFirst, size_t max)
|
||||
{
|
||||
size_t count = 0;
|
||||
max = (size_t)sema->tryWaitMany((LightweightSemaphore::ssize_t)(ssize_t)max);
|
||||
while (count != max) {
|
||||
count += inner.template try_dequeue_bulk<It&>(token, itemFirst, max - count);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Blocks the current thread until there's something to dequeue, then
|
||||
// dequeues it.
|
||||
// Never allocates. Thread-safe.
|
||||
template<typename U>
|
||||
inline void wait_dequeue(U& item)
|
||||
{
|
||||
while (!sema->wait()) {
|
||||
continue;
|
||||
}
|
||||
while (!inner.try_dequeue(item)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Blocks the current thread until either there's something to dequeue
|
||||
// or the timeout (specified in microseconds) expires. Returns false
|
||||
// without setting `item` if the timeout expires, otherwise assigns
|
||||
// to `item` and returns true.
|
||||
// Using a negative timeout indicates an indefinite timeout,
|
||||
// and is thus functionally equivalent to calling wait_dequeue.
|
||||
// Never allocates. Thread-safe.
|
||||
template<typename U>
|
||||
inline bool wait_dequeue_timed(U& item, std::int64_t timeout_usecs)
|
||||
{
|
||||
if (!sema->wait(timeout_usecs)) {
|
||||
return false;
|
||||
}
|
||||
while (!inner.try_dequeue(item)) {
|
||||
continue;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Blocks the current thread until either there's something to dequeue
|
||||
// or the timeout expires. Returns false without setting `item` if the
|
||||
// timeout expires, otherwise assigns to `item` and returns true.
|
||||
// Never allocates. Thread-safe.
|
||||
template<typename U, typename Rep, typename Period>
|
||||
inline bool wait_dequeue_timed(U& item, std::chrono::duration<Rep, Period> const& timeout)
|
||||
{
|
||||
return wait_dequeue_timed(item, std::chrono::duration_cast<std::chrono::microseconds>(timeout).count());
|
||||
}
|
||||
|
||||
// Blocks the current thread until there's something to dequeue, then
|
||||
// dequeues it using an explicit consumer token.
|
||||
// Never allocates. Thread-safe.
|
||||
template<typename U>
|
||||
inline void wait_dequeue(consumer_token_t& token, U& item)
|
||||
{
|
||||
while (!sema->wait()) {
|
||||
continue;
|
||||
}
|
||||
while (!inner.try_dequeue(token, item)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Blocks the current thread until either there's something to dequeue
|
||||
// or the timeout (specified in microseconds) expires. Returns false
|
||||
// without setting `item` if the timeout expires, otherwise assigns
|
||||
// to `item` and returns true.
|
||||
// Using a negative timeout indicates an indefinite timeout,
|
||||
// and is thus functionally equivalent to calling wait_dequeue.
|
||||
// Never allocates. Thread-safe.
|
||||
template<typename U>
|
||||
inline bool wait_dequeue_timed(consumer_token_t& token, U& item, std::int64_t timeout_usecs)
|
||||
{
|
||||
if (!sema->wait(timeout_usecs)) {
|
||||
return false;
|
||||
}
|
||||
while (!inner.try_dequeue(token, item)) {
|
||||
continue;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Blocks the current thread until either there's something to dequeue
|
||||
// or the timeout expires. Returns false without setting `item` if the
|
||||
// timeout expires, otherwise assigns to `item` and returns true.
|
||||
// Never allocates. Thread-safe.
|
||||
template<typename U, typename Rep, typename Period>
|
||||
inline bool wait_dequeue_timed(consumer_token_t& token, U& item, std::chrono::duration<Rep, Period> const& timeout)
|
||||
{
|
||||
return wait_dequeue_timed(token, item, std::chrono::duration_cast<std::chrono::microseconds>(timeout).count());
|
||||
}
|
||||
|
||||
// Attempts to dequeue several elements from the queue.
|
||||
// Returns the number of items actually dequeued, which will
|
||||
// always be at least one (this method blocks until the queue
|
||||
// is non-empty) and at most max.
|
||||
// Never allocates. Thread-safe.
|
||||
template<typename It>
|
||||
inline size_t wait_dequeue_bulk(It itemFirst, size_t max)
|
||||
{
|
||||
size_t count = 0;
|
||||
max = (size_t)sema->waitMany((LightweightSemaphore::ssize_t)(ssize_t)max);
|
||||
while (count != max) {
|
||||
count += inner.template try_dequeue_bulk<It&>(itemFirst, max - count);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// Attempts to dequeue several elements from the queue.
|
||||
// Returns the number of items actually dequeued, which can
|
||||
// be 0 if the timeout expires while waiting for elements,
|
||||
// and at most max.
|
||||
// Using a negative timeout indicates an indefinite timeout,
|
||||
// and is thus functionally equivalent to calling wait_dequeue_bulk.
|
||||
// Never allocates. Thread-safe.
|
||||
template<typename It>
|
||||
inline size_t wait_dequeue_bulk_timed(It itemFirst, size_t max, std::int64_t timeout_usecs)
|
||||
{
|
||||
size_t count = 0;
|
||||
max = (size_t)sema->waitMany((LightweightSemaphore::ssize_t)(ssize_t)max, timeout_usecs);
|
||||
while (count != max) {
|
||||
count += inner.template try_dequeue_bulk<It&>(itemFirst, max - count);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// Attempts to dequeue several elements from the queue.
|
||||
// Returns the number of items actually dequeued, which can
|
||||
// be 0 if the timeout expires while waiting for elements,
|
||||
// and at most max.
|
||||
// Never allocates. Thread-safe.
|
||||
template<typename It, typename Rep, typename Period>
|
||||
inline size_t wait_dequeue_bulk_timed(It itemFirst, size_t max, std::chrono::duration<Rep, Period> const& timeout)
|
||||
{
|
||||
return wait_dequeue_bulk_timed<It&>(itemFirst, max, std::chrono::duration_cast<std::chrono::microseconds>(timeout).count());
|
||||
}
|
||||
|
||||
// Attempts to dequeue several elements from the queue using an explicit consumer token.
|
||||
// Returns the number of items actually dequeued, which will
|
||||
// always be at least one (this method blocks until the queue
|
||||
// is non-empty) and at most max.
|
||||
// Never allocates. Thread-safe.
|
||||
template<typename It>
|
||||
inline size_t wait_dequeue_bulk(consumer_token_t& token, It itemFirst, size_t max)
|
||||
{
|
||||
size_t count = 0;
|
||||
max = (size_t)sema->waitMany((LightweightSemaphore::ssize_t)(ssize_t)max);
|
||||
while (count != max) {
|
||||
count += inner.template try_dequeue_bulk<It&>(token, itemFirst, max - count);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// Attempts to dequeue several elements from the queue using an explicit consumer token.
|
||||
// Returns the number of items actually dequeued, which can
|
||||
// be 0 if the timeout expires while waiting for elements,
|
||||
// and at most max.
|
||||
// Using a negative timeout indicates an indefinite timeout,
|
||||
// and is thus functionally equivalent to calling wait_dequeue_bulk.
|
||||
// Never allocates. Thread-safe.
|
||||
template<typename It>
|
||||
inline size_t wait_dequeue_bulk_timed(consumer_token_t& token, It itemFirst, size_t max, std::int64_t timeout_usecs)
|
||||
{
|
||||
size_t count = 0;
|
||||
max = (size_t)sema->waitMany((LightweightSemaphore::ssize_t)(ssize_t)max, timeout_usecs);
|
||||
while (count != max) {
|
||||
count += inner.template try_dequeue_bulk<It&>(token, itemFirst, max - count);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// Attempts to dequeue several elements from the queue using an explicit consumer token.
|
||||
// Returns the number of items actually dequeued, which can
|
||||
// be 0 if the timeout expires while waiting for elements,
|
||||
// and at most max.
|
||||
// Never allocates. Thread-safe.
|
||||
template<typename It, typename Rep, typename Period>
|
||||
inline size_t wait_dequeue_bulk_timed(consumer_token_t& token, It itemFirst, size_t max, std::chrono::duration<Rep, Period> const& timeout)
|
||||
{
|
||||
return wait_dequeue_bulk_timed<It&>(token, itemFirst, max, std::chrono::duration_cast<std::chrono::microseconds>(timeout).count());
|
||||
}
|
||||
|
||||
|
||||
// Returns an estimate of the total number of elements currently in the queue. This
|
||||
// estimate is only accurate if the queue has completely stabilized before it is called
|
||||
// (i.e. all enqueue and dequeue operations have completed and their memory effects are
|
||||
// visible on the calling thread, and no further operations start while this method is
|
||||
// being called).
|
||||
// Thread-safe.
|
||||
inline size_t size_approx() const
|
||||
{
|
||||
return (size_t)sema->availableApprox();
|
||||
}
|
||||
|
||||
|
||||
// Returns true if the underlying atomic variables used by
|
||||
// the queue are lock-free (they should be on most platforms).
|
||||
// Thread-safe.
|
||||
static constexpr bool is_lock_free()
|
||||
{
|
||||
return ConcurrentQueue::is_lock_free();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
template<typename U, typename A1, typename A2>
|
||||
static inline U* create(A1&& a1, A2&& a2)
|
||||
{
|
||||
void* p = (Traits::malloc)(sizeof(U));
|
||||
return p != nullptr ? new (p) U(std::forward<A1>(a1), std::forward<A2>(a2)) : nullptr;
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
static inline void destroy(U* p)
|
||||
{
|
||||
if (p != nullptr) {
|
||||
p->~U();
|
||||
}
|
||||
(Traits::free)(p);
|
||||
}
|
||||
|
||||
private:
|
||||
ConcurrentQueue inner;
|
||||
std::unique_ptr<LightweightSemaphore, void (*)(LightweightSemaphore*)> sema;
|
||||
};
|
||||
|
||||
|
||||
template<typename T, typename Traits>
|
||||
inline void swap(BlockingConcurrentQueue<T, Traits>& a, BlockingConcurrentQueue<T, Traits>& b) MOODYCAMEL_NOEXCEPT
|
||||
{
|
||||
a.swap(b);
|
||||
}
|
||||
|
||||
} // end namespace moodycamel
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,427 @@
|
||||
// Provides an efficient implementation of a semaphore (LightweightSemaphore).
|
||||
// This is an extension of Jeff Preshing's sempahore implementation (licensed
|
||||
// under the terms of its separate zlib license) that has been adapted and
|
||||
// extended by Cameron Desrochers.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef> // For std::size_t
|
||||
#include <atomic>
|
||||
#include <type_traits> // For std::make_signed<T>
|
||||
|
||||
#if defined(_WIN32)
|
||||
// Avoid including windows.h in a header; we only need a handful of
|
||||
// items, so we'll redeclare them here (this is relatively safe since
|
||||
// the API generally has to remain stable between Windows versions).
|
||||
// I know this is an ugly hack but it still beats polluting the global
|
||||
// namespace with thousands of generic names or adding a .cpp for nothing.
|
||||
extern "C" {
|
||||
struct _SECURITY_ATTRIBUTES;
|
||||
__declspec(dllimport) void* __stdcall CreateSemaphoreW(_SECURITY_ATTRIBUTES* lpSemaphoreAttributes, long lInitialCount, long lMaximumCount, const wchar_t* lpName);
|
||||
__declspec(dllimport) int __stdcall CloseHandle(void* hObject);
|
||||
__declspec(dllimport) unsigned long __stdcall WaitForSingleObject(void* hHandle, unsigned long dwMilliseconds);
|
||||
__declspec(dllimport) int __stdcall ReleaseSemaphore(void* hSemaphore, long lReleaseCount, long* lpPreviousCount);
|
||||
}
|
||||
#elif defined(__MACH__)
|
||||
#include <mach/mach.h>
|
||||
#elif defined(__MVS__)
|
||||
#include <zos-semaphore.h>
|
||||
#elif defined(__unix__)
|
||||
#include <semaphore.h>
|
||||
|
||||
#if defined(__GLIBC_PREREQ) && defined(_GNU_SOURCE)
|
||||
#if __GLIBC_PREREQ(2,30)
|
||||
#define MOODYCAMEL_LIGHTWEIGHTSEMAPHORE_MONOTONIC
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace moodycamel
|
||||
{
|
||||
namespace details
|
||||
{
|
||||
|
||||
// Code in the mpmc_sema namespace below is an adaptation of Jeff Preshing's
|
||||
// portable + lightweight semaphore implementations, originally from
|
||||
// https://github.com/preshing/cpp11-on-multicore/blob/master/common/sema.h
|
||||
// LICENSE:
|
||||
// Copyright (c) 2015 Jeff Preshing
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgement in the product documentation would be
|
||||
// appreciated but is not required.
|
||||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
#if defined(_WIN32)
|
||||
class Semaphore
|
||||
{
|
||||
private:
|
||||
void* m_hSema;
|
||||
|
||||
Semaphore(const Semaphore& other) MOODYCAMEL_DELETE_FUNCTION;
|
||||
Semaphore& operator=(const Semaphore& other) MOODYCAMEL_DELETE_FUNCTION;
|
||||
|
||||
public:
|
||||
Semaphore(int initialCount = 0)
|
||||
{
|
||||
assert(initialCount >= 0);
|
||||
const long maxLong = 0x7fffffff;
|
||||
m_hSema = CreateSemaphoreW(nullptr, initialCount, maxLong, nullptr);
|
||||
assert(m_hSema);
|
||||
}
|
||||
|
||||
~Semaphore()
|
||||
{
|
||||
CloseHandle(m_hSema);
|
||||
}
|
||||
|
||||
bool wait()
|
||||
{
|
||||
const unsigned long infinite = 0xffffffff;
|
||||
return WaitForSingleObject(m_hSema, infinite) == 0;
|
||||
}
|
||||
|
||||
bool try_wait()
|
||||
{
|
||||
return WaitForSingleObject(m_hSema, 0) == 0;
|
||||
}
|
||||
|
||||
bool timed_wait(std::uint64_t usecs)
|
||||
{
|
||||
return WaitForSingleObject(m_hSema, (unsigned long)(usecs / 1000)) == 0;
|
||||
}
|
||||
|
||||
void signal(int count = 1)
|
||||
{
|
||||
while (!ReleaseSemaphore(m_hSema, count, nullptr));
|
||||
}
|
||||
};
|
||||
#elif defined(__MACH__)
|
||||
//---------------------------------------------------------
|
||||
// Semaphore (Apple iOS and OSX)
|
||||
// Can't use POSIX semaphores due to http://lists.apple.com/archives/darwin-kernel/2009/Apr/msg00010.html
|
||||
//---------------------------------------------------------
|
||||
class Semaphore
|
||||
{
|
||||
private:
|
||||
semaphore_t m_sema;
|
||||
|
||||
Semaphore(const Semaphore& other) MOODYCAMEL_DELETE_FUNCTION;
|
||||
Semaphore& operator=(const Semaphore& other) MOODYCAMEL_DELETE_FUNCTION;
|
||||
|
||||
public:
|
||||
Semaphore(int initialCount = 0)
|
||||
{
|
||||
assert(initialCount >= 0);
|
||||
kern_return_t rc = semaphore_create(mach_task_self(), &m_sema, SYNC_POLICY_FIFO, initialCount);
|
||||
assert(rc == KERN_SUCCESS);
|
||||
(void)rc;
|
||||
}
|
||||
|
||||
~Semaphore()
|
||||
{
|
||||
semaphore_destroy(mach_task_self(), m_sema);
|
||||
}
|
||||
|
||||
bool wait()
|
||||
{
|
||||
return semaphore_wait(m_sema) == KERN_SUCCESS;
|
||||
}
|
||||
|
||||
bool try_wait()
|
||||
{
|
||||
return timed_wait(0);
|
||||
}
|
||||
|
||||
bool timed_wait(std::uint64_t timeout_usecs)
|
||||
{
|
||||
mach_timespec_t ts;
|
||||
ts.tv_sec = static_cast<unsigned int>(timeout_usecs / 1000000);
|
||||
ts.tv_nsec = static_cast<int>((timeout_usecs % 1000000) * 1000);
|
||||
|
||||
// added in OSX 10.10: https://developer.apple.com/library/prerelease/mac/documentation/General/Reference/APIDiffsMacOSX10_10SeedDiff/modules/Darwin.html
|
||||
kern_return_t rc = semaphore_timedwait(m_sema, ts);
|
||||
return rc == KERN_SUCCESS;
|
||||
}
|
||||
|
||||
void signal()
|
||||
{
|
||||
while (semaphore_signal(m_sema) != KERN_SUCCESS);
|
||||
}
|
||||
|
||||
void signal(int count)
|
||||
{
|
||||
while (count-- > 0)
|
||||
{
|
||||
while (semaphore_signal(m_sema) != KERN_SUCCESS);
|
||||
}
|
||||
}
|
||||
};
|
||||
#elif defined(__unix__) || defined(__MVS__)
|
||||
//---------------------------------------------------------
|
||||
// Semaphore (POSIX, Linux, zOS)
|
||||
//---------------------------------------------------------
|
||||
class Semaphore
|
||||
{
|
||||
private:
|
||||
sem_t m_sema;
|
||||
|
||||
Semaphore(const Semaphore& other) MOODYCAMEL_DELETE_FUNCTION;
|
||||
Semaphore& operator=(const Semaphore& other) MOODYCAMEL_DELETE_FUNCTION;
|
||||
|
||||
public:
|
||||
Semaphore(int initialCount = 0)
|
||||
{
|
||||
assert(initialCount >= 0);
|
||||
int rc = sem_init(&m_sema, 0, static_cast<unsigned int>(initialCount));
|
||||
assert(rc == 0);
|
||||
(void)rc;
|
||||
}
|
||||
|
||||
~Semaphore()
|
||||
{
|
||||
sem_destroy(&m_sema);
|
||||
}
|
||||
|
||||
bool wait()
|
||||
{
|
||||
// http://stackoverflow.com/questions/2013181/gdb-causes-sem-wait-to-fail-with-eintr-error
|
||||
int rc;
|
||||
do {
|
||||
rc = sem_wait(&m_sema);
|
||||
} while (rc == -1 && errno == EINTR);
|
||||
return rc == 0;
|
||||
}
|
||||
|
||||
bool try_wait()
|
||||
{
|
||||
int rc;
|
||||
do {
|
||||
rc = sem_trywait(&m_sema);
|
||||
} while (rc == -1 && errno == EINTR);
|
||||
return rc == 0;
|
||||
}
|
||||
|
||||
bool timed_wait(std::uint64_t usecs)
|
||||
{
|
||||
struct timespec ts;
|
||||
const int usecs_in_1_sec = 1000000;
|
||||
const int nsecs_in_1_sec = 1000000000;
|
||||
#ifdef MOODYCAMEL_LIGHTWEIGHTSEMAPHORE_MONOTONIC
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
#else
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
#endif
|
||||
ts.tv_sec += (time_t)(usecs / usecs_in_1_sec);
|
||||
ts.tv_nsec += (long)(usecs % usecs_in_1_sec) * 1000;
|
||||
// sem_timedwait bombs if you have more than 1e9 in tv_nsec
|
||||
// so we have to clean things up before passing it in
|
||||
if (ts.tv_nsec >= nsecs_in_1_sec) {
|
||||
ts.tv_nsec -= nsecs_in_1_sec;
|
||||
++ts.tv_sec;
|
||||
}
|
||||
|
||||
int rc;
|
||||
do {
|
||||
#ifdef MOODYCAMEL_LIGHTWEIGHTSEMAPHORE_MONOTONIC
|
||||
rc = sem_clockwait(&m_sema, CLOCK_MONOTONIC, &ts);
|
||||
#else
|
||||
rc = sem_timedwait(&m_sema, &ts);
|
||||
#endif
|
||||
} while (rc == -1 && errno == EINTR);
|
||||
return rc == 0;
|
||||
}
|
||||
|
||||
void signal()
|
||||
{
|
||||
while (sem_post(&m_sema) == -1);
|
||||
}
|
||||
|
||||
void signal(int count)
|
||||
{
|
||||
while (count-- > 0)
|
||||
{
|
||||
while (sem_post(&m_sema) == -1);
|
||||
}
|
||||
}
|
||||
};
|
||||
#else
|
||||
#error Unsupported platform! (No semaphore wrapper available)
|
||||
#endif
|
||||
|
||||
} // end namespace details
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
// LightweightSemaphore
|
||||
//---------------------------------------------------------
|
||||
class LightweightSemaphore
|
||||
{
|
||||
public:
|
||||
typedef std::make_signed<std::size_t>::type ssize_t;
|
||||
|
||||
private:
|
||||
std::atomic<ssize_t> m_count;
|
||||
details::Semaphore m_sema;
|
||||
int m_maxSpins;
|
||||
|
||||
bool waitWithPartialSpinning(std::int64_t timeout_usecs = -1)
|
||||
{
|
||||
ssize_t oldCount;
|
||||
int spin = m_maxSpins;
|
||||
while (--spin >= 0)
|
||||
{
|
||||
oldCount = m_count.load(std::memory_order_relaxed);
|
||||
if ((oldCount > 0) && m_count.compare_exchange_strong(oldCount, oldCount - 1, std::memory_order_acquire, std::memory_order_relaxed))
|
||||
return true;
|
||||
std::atomic_signal_fence(std::memory_order_acquire); // Prevent the compiler from collapsing the loop.
|
||||
}
|
||||
oldCount = m_count.fetch_sub(1, std::memory_order_acquire);
|
||||
if (oldCount > 0)
|
||||
return true;
|
||||
if (timeout_usecs < 0)
|
||||
{
|
||||
if (m_sema.wait())
|
||||
return true;
|
||||
}
|
||||
if (timeout_usecs > 0 && m_sema.timed_wait((std::uint64_t)timeout_usecs))
|
||||
return true;
|
||||
// At this point, we've timed out waiting for the semaphore, but the
|
||||
// count is still decremented indicating we may still be waiting on
|
||||
// it. So we have to re-adjust the count, but only if the semaphore
|
||||
// wasn't signaled enough times for us too since then. If it was, we
|
||||
// need to release the semaphore too.
|
||||
while (true)
|
||||
{
|
||||
oldCount = m_count.load(std::memory_order_acquire);
|
||||
if (oldCount >= 0 && m_sema.try_wait())
|
||||
return true;
|
||||
if (oldCount < 0 && m_count.compare_exchange_strong(oldCount, oldCount + 1, std::memory_order_relaxed, std::memory_order_relaxed))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ssize_t waitManyWithPartialSpinning(ssize_t max, std::int64_t timeout_usecs = -1)
|
||||
{
|
||||
assert(max > 0);
|
||||
ssize_t oldCount;
|
||||
int spin = m_maxSpins;
|
||||
while (--spin >= 0)
|
||||
{
|
||||
oldCount = m_count.load(std::memory_order_relaxed);
|
||||
if (oldCount > 0)
|
||||
{
|
||||
ssize_t newCount = oldCount > max ? oldCount - max : 0;
|
||||
if (m_count.compare_exchange_strong(oldCount, newCount, std::memory_order_acquire, std::memory_order_relaxed))
|
||||
return oldCount - newCount;
|
||||
}
|
||||
std::atomic_signal_fence(std::memory_order_acquire);
|
||||
}
|
||||
oldCount = m_count.fetch_sub(1, std::memory_order_acquire);
|
||||
if (oldCount <= 0)
|
||||
{
|
||||
if ((timeout_usecs == 0) || (timeout_usecs < 0 && !m_sema.wait()) || (timeout_usecs > 0 && !m_sema.timed_wait((std::uint64_t)timeout_usecs)))
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
oldCount = m_count.load(std::memory_order_acquire);
|
||||
if (oldCount >= 0 && m_sema.try_wait())
|
||||
break;
|
||||
if (oldCount < 0 && m_count.compare_exchange_strong(oldCount, oldCount + 1, std::memory_order_relaxed, std::memory_order_relaxed))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (max > 1)
|
||||
return 1 + tryWaitMany(max - 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
public:
|
||||
LightweightSemaphore(ssize_t initialCount = 0, int maxSpins = 10000) : m_count(initialCount), m_maxSpins(maxSpins)
|
||||
{
|
||||
assert(initialCount >= 0);
|
||||
assert(maxSpins >= 0);
|
||||
}
|
||||
|
||||
bool tryWait()
|
||||
{
|
||||
ssize_t oldCount = m_count.load(std::memory_order_relaxed);
|
||||
while (oldCount > 0)
|
||||
{
|
||||
if (m_count.compare_exchange_weak(oldCount, oldCount - 1, std::memory_order_acquire, std::memory_order_relaxed))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wait()
|
||||
{
|
||||
return tryWait() || waitWithPartialSpinning();
|
||||
}
|
||||
|
||||
bool wait(std::int64_t timeout_usecs)
|
||||
{
|
||||
return tryWait() || waitWithPartialSpinning(timeout_usecs);
|
||||
}
|
||||
|
||||
// Acquires between 0 and (greedily) max, inclusive
|
||||
ssize_t tryWaitMany(ssize_t max)
|
||||
{
|
||||
assert(max >= 0);
|
||||
ssize_t oldCount = m_count.load(std::memory_order_relaxed);
|
||||
while (oldCount > 0)
|
||||
{
|
||||
ssize_t newCount = oldCount > max ? oldCount - max : 0;
|
||||
if (m_count.compare_exchange_weak(oldCount, newCount, std::memory_order_acquire, std::memory_order_relaxed))
|
||||
return oldCount - newCount;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Acquires at least one, and (greedily) at most max
|
||||
ssize_t waitMany(ssize_t max, std::int64_t timeout_usecs)
|
||||
{
|
||||
assert(max >= 0);
|
||||
ssize_t result = tryWaitMany(max);
|
||||
if (result == 0 && max > 0)
|
||||
result = waitManyWithPartialSpinning(max, timeout_usecs);
|
||||
return result;
|
||||
}
|
||||
|
||||
ssize_t waitMany(ssize_t max)
|
||||
{
|
||||
ssize_t result = waitMany(max, -1);
|
||||
assert(result > 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
void signal(ssize_t count = 1)
|
||||
{
|
||||
assert(count >= 0);
|
||||
ssize_t oldCount = m_count.fetch_add(count, std::memory_order_release);
|
||||
ssize_t toRelease = -oldCount < count ? -oldCount : count;
|
||||
if (toRelease > 0)
|
||||
{
|
||||
m_sema.signal((int)toRelease);
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t availableApprox() const
|
||||
{
|
||||
ssize_t count = m_count.load(std::memory_order_relaxed);
|
||||
return count > 0 ? static_cast<std::size_t>(count) : 0;
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace moodycamel
|
||||
@@ -0,0 +1,318 @@
|
||||
#pragma once
|
||||
|
||||
#include "moodycamel/blockingconcurrentqueue.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <csignal>
|
||||
#include <cstring>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include <syslog.h>
|
||||
|
||||
|
||||
struct ThreadPoolTraits : public moodycamel::ConcurrentQueueDefaultTraits
|
||||
{
|
||||
static const int MAX_SEMA_SPINS = 1;
|
||||
};
|
||||
|
||||
|
||||
class ThreadPool
|
||||
{
|
||||
private:
|
||||
using Func = std::function<void(void)>;
|
||||
using Queue = moodycamel::BlockingConcurrentQueue<Func,ThreadPoolTraits>;
|
||||
|
||||
public:
|
||||
explicit
|
||||
ThreadPool(unsigned const thread_count_ = std::thread::hardware_concurrency(),
|
||||
unsigned const max_queue_depth_ = std::thread::hardware_concurrency(),
|
||||
std::string const name_ = {})
|
||||
: _queue(),
|
||||
_queue_depth(0),
|
||||
_max_queue_depth(std::max(thread_count_,max_queue_depth_)),
|
||||
_name(name_)
|
||||
{
|
||||
syslog(LOG_DEBUG,
|
||||
"threadpool (%s): spawning %u threads w/ max queue depth %u%s",
|
||||
_name.c_str(),
|
||||
thread_count_,
|
||||
_max_queue_depth,
|
||||
((_max_queue_depth != max_queue_depth_) ? " (adjusted)" : ""));
|
||||
|
||||
sigset_t oldset;
|
||||
sigset_t newset;
|
||||
|
||||
sigfillset(&newset);
|
||||
pthread_sigmask(SIG_BLOCK,&newset,&oldset);
|
||||
|
||||
_threads.reserve(thread_count_);
|
||||
for(std::size_t i = 0; i < thread_count_; ++i)
|
||||
{
|
||||
int rv;
|
||||
pthread_t t;
|
||||
|
||||
rv = pthread_create(&t,NULL,ThreadPool::start_routine,this);
|
||||
if(rv != 0)
|
||||
{
|
||||
syslog(LOG_WARNING,
|
||||
"threadpool (%s): error spawning thread - %d (%s)",
|
||||
_name.c_str(),
|
||||
rv,
|
||||
strerror(rv));
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!_name.empty())
|
||||
pthread_setname_np(t,_name.c_str());
|
||||
|
||||
_threads.push_back(t);
|
||||
}
|
||||
|
||||
pthread_sigmask(SIG_SETMASK,&oldset,NULL);
|
||||
|
||||
if(_threads.empty())
|
||||
throw std::runtime_error("threadpool: failed to spawn any threads");
|
||||
}
|
||||
|
||||
~ThreadPool()
|
||||
{
|
||||
syslog(LOG_DEBUG,
|
||||
"threadpool (%s): destroying %lu threads",
|
||||
_name.c_str(),
|
||||
_threads.size());
|
||||
|
||||
auto func = []() { pthread_exit(NULL); };
|
||||
for(std::size_t i = 0; i < _threads.size(); i++)
|
||||
_queue.enqueue(func);
|
||||
|
||||
for(auto t : _threads)
|
||||
pthread_cancel(t);
|
||||
|
||||
for(auto t : _threads)
|
||||
pthread_join(t,NULL);
|
||||
}
|
||||
|
||||
private:
|
||||
static
|
||||
void*
|
||||
start_routine(void *arg_)
|
||||
{
|
||||
ThreadPool *btp = static_cast<ThreadPool*>(arg_);
|
||||
ThreadPool::Func func;
|
||||
ThreadPool::Queue &q = btp->_queue;
|
||||
std::atomic<unsigned> &queue_depth = btp->_queue_depth;
|
||||
moodycamel::ConsumerToken ctok(btp->_queue);
|
||||
|
||||
while(true)
|
||||
{
|
||||
q.wait_dequeue(ctok,func);
|
||||
|
||||
func();
|
||||
|
||||
queue_depth.fetch_sub(1,std::memory_order_release);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public:
|
||||
int
|
||||
add_thread(std::string const name_ = {})
|
||||
{
|
||||
int rv;
|
||||
pthread_t t;
|
||||
sigset_t oldset;
|
||||
sigset_t newset;
|
||||
std::string name;
|
||||
|
||||
name = (name_.empty() ? _name : name_);
|
||||
|
||||
sigfillset(&newset);
|
||||
pthread_sigmask(SIG_BLOCK,&newset,&oldset);
|
||||
rv = pthread_create(&t,NULL,ThreadPool::start_routine,this);
|
||||
pthread_sigmask(SIG_SETMASK,&oldset,NULL);
|
||||
|
||||
if(rv != 0)
|
||||
{
|
||||
syslog(LOG_WARNING,
|
||||
"threadpool (%s): error spawning thread - %d (%s)",
|
||||
_name.c_str(),
|
||||
rv,
|
||||
strerror(rv));
|
||||
return -rv;
|
||||
}
|
||||
|
||||
if(!name.empty())
|
||||
pthread_setname_np(t,name.c_str());
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lg(_threads_mutex);
|
||||
_threads.push_back(t);
|
||||
}
|
||||
|
||||
syslog(LOG_DEBUG,
|
||||
"threadpool (%s): 1 thread added named '%s'",
|
||||
_name.c_str(),
|
||||
name.c_str());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
remove_thread(void)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lg(_threads_mutex);
|
||||
if(_threads.size() <= 1)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
std::promise<pthread_t> promise;
|
||||
auto func = [&]()
|
||||
{
|
||||
pthread_t t;
|
||||
|
||||
t = pthread_self();
|
||||
promise.set_value(t);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lg(_threads_mutex);
|
||||
|
||||
for(auto i = _threads.begin(); i != _threads.end(); ++i)
|
||||
{
|
||||
if(*i != t)
|
||||
continue;
|
||||
|
||||
_threads.erase(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
syslog(LOG_DEBUG,
|
||||
"threadpool (%s): 1 thread removed",
|
||||
_name.c_str());
|
||||
|
||||
pthread_exit(NULL);
|
||||
};
|
||||
|
||||
enqueue_work(func);
|
||||
pthread_join(promise.get_future().get(),NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
set_threads(std::size_t const count_)
|
||||
{
|
||||
int diff;
|
||||
{
|
||||
std::lock_guard<std::mutex> lg(_threads_mutex);
|
||||
|
||||
diff = ((int)count_ - (int)_threads.size());
|
||||
}
|
||||
|
||||
for(auto i = diff; i > 0; --i)
|
||||
add_thread();
|
||||
for(auto i = diff; i < 0; ++i)
|
||||
remove_thread();
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
public:
|
||||
template<typename FuncType>
|
||||
void
|
||||
enqueue_work(moodycamel::ProducerToken &ptok_,
|
||||
FuncType &&f_)
|
||||
{
|
||||
timespec ts = {0,1000};
|
||||
for(unsigned i = 0; i < 1000000; i++)
|
||||
{
|
||||
if(_queue_depth.load(std::memory_order_acquire) < _max_queue_depth)
|
||||
break;
|
||||
::nanosleep(&ts,NULL);
|
||||
}
|
||||
|
||||
_queue.enqueue(ptok_,f_);
|
||||
_queue_depth.fetch_add(1,std::memory_order_release);
|
||||
}
|
||||
|
||||
template<typename FuncType>
|
||||
void
|
||||
enqueue_work(FuncType &&f_)
|
||||
{
|
||||
timespec ts = {0,1000};
|
||||
for(unsigned i = 0; i < 1000000; i++)
|
||||
{
|
||||
if(_queue_depth.load(std::memory_order_acquire) < _max_queue_depth)
|
||||
break;
|
||||
::nanosleep(&ts,NULL);
|
||||
}
|
||||
|
||||
_queue.enqueue(f_);
|
||||
_queue_depth.fetch_add(1,std::memory_order_release);
|
||||
}
|
||||
|
||||
template<typename FuncType>
|
||||
[[nodiscard]]
|
||||
std::future<typename std::result_of<FuncType()>::type>
|
||||
enqueue_task(FuncType&& f_)
|
||||
{
|
||||
using TaskReturnType = typename std::result_of<FuncType()>::type;
|
||||
using Promise = std::promise<TaskReturnType>;
|
||||
|
||||
auto promise = std::make_shared<Promise>();
|
||||
auto future = promise->get_future();
|
||||
|
||||
auto work = [=]()
|
||||
{
|
||||
auto rv = f_();
|
||||
promise->set_value(rv);
|
||||
};
|
||||
|
||||
timespec ts = {0,1000};
|
||||
for(unsigned i = 0; i < 1000000; i++)
|
||||
{
|
||||
if(_queue_depth.load(std::memory_order_acquire) < _max_queue_depth)
|
||||
break;
|
||||
::nanosleep(&ts,NULL);
|
||||
}
|
||||
|
||||
_queue.enqueue(work);
|
||||
_queue_depth.fetch_add(1,std::memory_order_release);
|
||||
|
||||
return future;
|
||||
}
|
||||
|
||||
public:
|
||||
std::vector<pthread_t>
|
||||
threads() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lg(_threads_mutex);
|
||||
|
||||
return _threads;
|
||||
}
|
||||
|
||||
moodycamel::ProducerToken
|
||||
ptoken()
|
||||
{
|
||||
return moodycamel::ProducerToken(_queue);
|
||||
}
|
||||
|
||||
private:
|
||||
Queue _queue;
|
||||
std::atomic<unsigned> _queue_depth;
|
||||
unsigned const _max_queue_depth;
|
||||
|
||||
private:
|
||||
std::string const _name;
|
||||
std::vector<pthread_t> _threads;
|
||||
mutable std::mutex _threads_mutex;
|
||||
};
|
||||
@@ -1,165 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <utility>
|
||||
|
||||
|
||||
template<typename T>
|
||||
class BoundedQueue
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
BoundedQueue(std::size_t max_size_,
|
||||
bool block_ = true)
|
||||
: _block(block),
|
||||
_max_size(max_size_)
|
||||
{
|
||||
if(_max_size == 0)
|
||||
_max_size = 1;
|
||||
}
|
||||
|
||||
bool
|
||||
push(const T& item_)
|
||||
{
|
||||
{
|
||||
std::unique_lock guard(_queue_lock);
|
||||
|
||||
_condition_push.wait(guard, [&]() { return _queue.size() < _max_size || !_block; });
|
||||
|
||||
if(_queue.size() == _max_size)
|
||||
return false;
|
||||
|
||||
_queue.push(item);
|
||||
}
|
||||
|
||||
_condition_pop.notify_one();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
push(T&& item_)
|
||||
{
|
||||
{
|
||||
std::unique_lock guard(_queue_lock);
|
||||
|
||||
_condition_push.wait(guard, [&]() { return _queue.size() < _max_size || !_block; });
|
||||
|
||||
if(_queue.size() == _max_size)
|
||||
return false;
|
||||
|
||||
_queue.push(std::move(item_));
|
||||
}
|
||||
_condition_pop.notify_one();
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
bool
|
||||
emplace(Args&&... args_)
|
||||
{
|
||||
{
|
||||
std::unique_lock guard(_queue_lock);
|
||||
|
||||
_condition_push.wait(guard, [&]() { return _queue.size() < _max_size || !_block; });
|
||||
|
||||
if(_queue.size() == _max_size)
|
||||
return false;
|
||||
|
||||
_queue.emplace(std::forward<Args>(args_)...);
|
||||
}
|
||||
|
||||
_condition_pop.notify_one();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
pop(T& item_)
|
||||
{
|
||||
{
|
||||
std::unique_lock guard(_queue_lock);
|
||||
|
||||
_condition_pop.wait(guard, [&]() { return !_queue.empty() || !_block; });
|
||||
if(_queue.empty())
|
||||
return false;
|
||||
|
||||
item_ = std::move(_queue.front());
|
||||
|
||||
_queue.pop();
|
||||
}
|
||||
|
||||
_condition_push.notify_one();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::size_t
|
||||
size() const
|
||||
{
|
||||
std::lock_guard guard(_queue_lock);
|
||||
|
||||
return _queue.size();
|
||||
}
|
||||
|
||||
std::size_t
|
||||
capacity() const
|
||||
{
|
||||
return _max_size;
|
||||
}
|
||||
|
||||
bool
|
||||
empty() const
|
||||
{
|
||||
std::lock_guard guard(_queue_lock);
|
||||
|
||||
return _queue.empty();
|
||||
}
|
||||
|
||||
bool
|
||||
full() const
|
||||
{
|
||||
std::lock_guard lock(_queue_lock);
|
||||
|
||||
return (_queue.size() == capacity());
|
||||
}
|
||||
|
||||
void
|
||||
block()
|
||||
{
|
||||
std::lock_guard guard(_queue_lock);
|
||||
_block = true;
|
||||
}
|
||||
|
||||
void
|
||||
unblock()
|
||||
{
|
||||
{
|
||||
std::lock_guard guard(_queue_lock);
|
||||
_block = false;
|
||||
}
|
||||
|
||||
_condition_push.notify_all();
|
||||
_condition_pop.notify_all();
|
||||
}
|
||||
|
||||
bool
|
||||
blocking() const
|
||||
{
|
||||
std::lock_guard guard(_queue_lock);
|
||||
|
||||
return _block;
|
||||
}
|
||||
|
||||
private:
|
||||
mutable std::mutex _queue_lock;
|
||||
|
||||
private:
|
||||
bool _block;
|
||||
std::queue<T> _queue;
|
||||
const std::size_t _max_size;
|
||||
std::condition_variable _condition_push;
|
||||
std::condition_variable _condition_pop;
|
||||
};
|
||||
+30
-14
@@ -158,9 +158,9 @@ open_flag_to_str(const uint64_t offset_)
|
||||
static
|
||||
const
|
||||
char*
|
||||
fuse_flag_to_str(const uint32_t offset_)
|
||||
fuse_flag_to_str(const uint64_t offset_)
|
||||
{
|
||||
switch(1 << offset_)
|
||||
switch(1ULL << offset_)
|
||||
{
|
||||
FUSE_INIT_FLAG_CASE(ASYNC_READ);
|
||||
FUSE_INIT_FLAG_CASE(POSIX_LOCKS);
|
||||
@@ -189,6 +189,16 @@ fuse_flag_to_str(const uint32_t offset_)
|
||||
FUSE_INIT_FLAG_CASE(NO_OPENDIR_SUPPORT);
|
||||
FUSE_INIT_FLAG_CASE(EXPLICIT_INVAL_DATA);
|
||||
FUSE_INIT_FLAG_CASE(MAP_ALIGNMENT);
|
||||
FUSE_INIT_FLAG_CASE(SUBMOUNTS);
|
||||
FUSE_INIT_FLAG_CASE(HANDLE_KILLPRIV_V2);
|
||||
FUSE_INIT_FLAG_CASE(SETXATTR_EXT);
|
||||
FUSE_INIT_FLAG_CASE(INIT_EXT);
|
||||
FUSE_INIT_FLAG_CASE(INIT_RESERVED);
|
||||
FUSE_INIT_FLAG_CASE(SECURITY_CTX);
|
||||
FUSE_INIT_FLAG_CASE(HAS_INODE_DAX);
|
||||
FUSE_INIT_FLAG_CASE(CREATE_SUPP_GROUP);
|
||||
FUSE_INIT_FLAG_CASE(HAS_EXPIRE_ONLY);
|
||||
FUSE_INIT_FLAG_CASE(DIRECT_IO_ALLOW_MMAP);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -200,7 +210,7 @@ static
|
||||
void
|
||||
debug_open_flags(const uint32_t flags_)
|
||||
{
|
||||
fprintf(stderr,"%s,",open_accmode_to_str(flags_));
|
||||
fprintf(stderr,"%s, ",open_accmode_to_str(flags_));
|
||||
for(int i = 0; i < (sizeof(flags_) * 8); i++)
|
||||
{
|
||||
const char *str;
|
||||
@@ -212,7 +222,7 @@ debug_open_flags(const uint32_t flags_)
|
||||
if(str == NULL)
|
||||
continue;
|
||||
|
||||
fprintf(stderr,"%s,",str);
|
||||
fprintf(stderr,"%s, ",str);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -717,28 +727,31 @@ debug_fuse_fallocate_in(const void *arg_)
|
||||
void
|
||||
debug_fuse_init_in(const struct fuse_init_in *arg_)
|
||||
{
|
||||
uint64_t flags;
|
||||
|
||||
flags = (((uint64_t)arg_->flags) | ((uint64_t)arg_->flags2) << 32);
|
||||
fprintf(g_OUTPUT,
|
||||
"FUSE_INIT_IN: "
|
||||
" major=%u;"
|
||||
" minor=%u;"
|
||||
" max_readahead=%u;"
|
||||
" flags=0x%08X (",
|
||||
" flags=0x%016lx (",
|
||||
arg_->major,
|
||||
arg_->minor,
|
||||
arg_->max_readahead,
|
||||
arg_->flags);
|
||||
for(uint64_t i = 0; i < (sizeof(arg_->flags)*8); i++)
|
||||
flags);
|
||||
for(uint64_t i = 0; i < (sizeof(flags)*8); i++)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
if(!(arg_->flags & (1ULL << i)))
|
||||
if(!(flags & (1ULL << i)))
|
||||
continue;
|
||||
|
||||
str = fuse_flag_to_str(i);
|
||||
if(str == NULL)
|
||||
continue;
|
||||
|
||||
fprintf(g_OUTPUT,"%s,",str);
|
||||
fprintf(g_OUTPUT,"%s, ",str);
|
||||
}
|
||||
fprintf(g_OUTPUT,")\n");
|
||||
}
|
||||
@@ -748,7 +761,10 @@ debug_fuse_init_out(const uint64_t unique_,
|
||||
const struct fuse_init_out *arg_,
|
||||
const uint64_t argsize_)
|
||||
{
|
||||
uint64_t flags;
|
||||
const struct fuse_init_out *arg = arg_;
|
||||
|
||||
flags = (((uint64_t)arg->flags) | ((uint64_t)arg->flags2) << 32);
|
||||
fprintf(g_OUTPUT,
|
||||
/* "unique=0x%016"PRIx64";" */
|
||||
/* " opcode=RESPONSE;" */
|
||||
@@ -758,27 +774,27 @@ debug_fuse_init_out(const uint64_t unique_,
|
||||
" major=%u;"
|
||||
" minor=%u;"
|
||||
" max_readahead=%u;"
|
||||
" flags=0x%08X ("
|
||||
" flags=0x%016lx ("
|
||||
,
|
||||
/* unique_, */
|
||||
/* sizeof(struct fuse_out_header) + argsize_, */
|
||||
arg->major,
|
||||
arg->minor,
|
||||
arg->max_readahead,
|
||||
arg->flags);
|
||||
flags);
|
||||
|
||||
for(uint64_t i = 0; i < (sizeof(arg->flags)*8); i++)
|
||||
for(uint64_t i = 0; i < (sizeof(flags)*8); i++)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
if(!(arg->flags & (1ULL << i)))
|
||||
if(!(flags & (1ULL << i)))
|
||||
continue;
|
||||
|
||||
str = fuse_flag_to_str(i);
|
||||
if(str == NULL)
|
||||
continue;
|
||||
|
||||
fprintf(g_OUTPUT,"%s,",str);
|
||||
fprintf(g_OUTPUT,"%s, ",str);
|
||||
}
|
||||
|
||||
fprintf(g_OUTPUT,
|
||||
|
||||
+354
-232
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2023, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
static int g_READ_THREAD_COUNT = -1;
|
||||
static int g_PROCESS_THREAD_COUNT = -1;
|
||||
static int g_PROCESS_THREAD_QUEUE_DEPTH = -1;
|
||||
static std::string g_PIN_THREADS = {};
|
||||
|
||||
|
||||
int
|
||||
fuse_config_get_read_thread_count()
|
||||
{
|
||||
return g_READ_THREAD_COUNT;
|
||||
}
|
||||
|
||||
void
|
||||
fuse_config_set_read_thread_count(int const v_)
|
||||
{
|
||||
g_READ_THREAD_COUNT = v_;
|
||||
}
|
||||
|
||||
int
|
||||
fuse_config_get_process_thread_count()
|
||||
{
|
||||
return g_PROCESS_THREAD_COUNT;
|
||||
}
|
||||
|
||||
void
|
||||
fuse_config_set_process_thread_count(int const v_)
|
||||
{
|
||||
g_PROCESS_THREAD_COUNT = v_;
|
||||
}
|
||||
|
||||
int
|
||||
fuse_config_get_process_thread_queue_depth()
|
||||
{
|
||||
return g_PROCESS_THREAD_QUEUE_DEPTH;
|
||||
}
|
||||
|
||||
void
|
||||
fuse_config_set_process_thread_queue_depth(int const v_)
|
||||
{
|
||||
g_PROCESS_THREAD_QUEUE_DEPTH = v_;
|
||||
}
|
||||
|
||||
std::string
|
||||
fuse_config_get_pin_threads()
|
||||
{
|
||||
return g_PIN_THREADS;
|
||||
}
|
||||
|
||||
void
|
||||
fuse_config_set_pin_threads(std::string const v_)
|
||||
{
|
||||
g_PIN_THREADS = v_;
|
||||
}
|
||||
@@ -304,9 +304,9 @@ fuse_dirents_add_plus(fuse_dirents_t *d_,
|
||||
}
|
||||
|
||||
int
|
||||
fuse_dirents_add_linux(fuse_dirents_t *d_,
|
||||
const struct linux_dirent64 *dirent_,
|
||||
const uint64_t namelen_)
|
||||
fuse_dirents_add_linux(fuse_dirents_t *d_,
|
||||
const linux_dirent64_t *dirent_,
|
||||
const uint64_t namelen_)
|
||||
{
|
||||
fuse_dirent_t *d;
|
||||
|
||||
@@ -336,11 +336,11 @@ fuse_dirents_add_linux(fuse_dirents_t *d_,
|
||||
}
|
||||
|
||||
int
|
||||
fuse_dirents_add_linux_plus(fuse_dirents_t *d_,
|
||||
const struct linux_dirent64 *dirent_,
|
||||
const uint64_t namelen_,
|
||||
const fuse_entry_t *entry_,
|
||||
const struct stat *st_)
|
||||
fuse_dirents_add_linux_plus(fuse_dirents_t *d_,
|
||||
const linux_dirent64_t *dirent_,
|
||||
const uint64_t namelen_,
|
||||
const fuse_entry_t *entry_,
|
||||
const struct stat *st_)
|
||||
{
|
||||
fuse_direntplus_t *d;
|
||||
|
||||
|
||||
@@ -2,15 +2,18 @@
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include "thread_pool.hpp"
|
||||
#include "cpu.hpp"
|
||||
#include "fmt/core.h"
|
||||
#include "make_unique.hpp"
|
||||
#include "scope_guard.hpp"
|
||||
#include "thread_pool.hpp"
|
||||
|
||||
#include "fuse_i.h"
|
||||
#include "fuse_kernel.h"
|
||||
#include "fuse_lowlevel.h"
|
||||
#include "fuse_misc.h"
|
||||
|
||||
#include "fuse_config.hpp"
|
||||
#include "fuse_msgbuf.hpp"
|
||||
#include "fuse_ll.hpp"
|
||||
|
||||
@@ -22,38 +25,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
|
||||
|
||||
struct fuse_worker_data_t
|
||||
{
|
||||
struct fuse_session *se;
|
||||
sem_t finished;
|
||||
std::function<void(fuse_worker_data_t*,fuse_msgbuf_t*)> msgbuf_processor;
|
||||
std::shared_ptr<ThreadPool> tp;
|
||||
};
|
||||
|
||||
class WorkerCleanup
|
||||
{
|
||||
public:
|
||||
WorkerCleanup(fuse_worker_data_t *wd_)
|
||||
: _wd(wd_)
|
||||
{
|
||||
}
|
||||
|
||||
~WorkerCleanup()
|
||||
{
|
||||
fuse_session_exit(_wd->se);
|
||||
sem_post(&_wd->finished);
|
||||
}
|
||||
|
||||
private:
|
||||
fuse_worker_data_t *_wd;
|
||||
};
|
||||
|
||||
static
|
||||
bool
|
||||
retriable_receive_error(const int err_)
|
||||
@@ -77,54 +54,117 @@ fatal_receive_error(const int err_)
|
||||
}
|
||||
|
||||
static
|
||||
void*
|
||||
void
|
||||
handle_receive_error(const int rv_,
|
||||
fuse_msgbuf_t *msgbuf_)
|
||||
{
|
||||
msgbuf_free(msgbuf_);
|
||||
|
||||
fprintf(stderr,
|
||||
"mergerfs: error reading from /dev/fuse - %s (%d)\n",
|
||||
strerror(-rv_),
|
||||
-rv_);
|
||||
|
||||
return NULL;
|
||||
fmt::print(stderr,
|
||||
"mergerfs: error reading from /dev/fuse - {} ({})\n",
|
||||
strerror(-rv_),
|
||||
-rv_);
|
||||
}
|
||||
|
||||
static
|
||||
void*
|
||||
fuse_do_work(void *data)
|
||||
struct AsyncWorker
|
||||
{
|
||||
fuse_worker_data_t *wd = (fuse_worker_data_t*)data;
|
||||
fuse_session *se = wd->se;
|
||||
auto &process_msgbuf = wd->msgbuf_processor;
|
||||
WorkerCleanup workercleanup(wd);
|
||||
fuse_session *_se;
|
||||
sem_t *_finished;
|
||||
std::shared_ptr<ThreadPool> _process_tp;
|
||||
|
||||
while(!fuse_session_exited(se))
|
||||
{
|
||||
int rv;
|
||||
fuse_msgbuf_t *msgbuf;
|
||||
AsyncWorker(fuse_session *se_,
|
||||
sem_t *finished_,
|
||||
std::shared_ptr<ThreadPool> process_tp_)
|
||||
: _se(se_),
|
||||
_finished(finished_),
|
||||
_process_tp(process_tp_)
|
||||
{
|
||||
}
|
||||
|
||||
msgbuf = msgbuf_alloc();
|
||||
inline
|
||||
void
|
||||
operator()() const
|
||||
{
|
||||
DEFER{ fuse_session_exit(_se); };
|
||||
DEFER{ sem_post(_finished); };
|
||||
|
||||
do
|
||||
moodycamel::ProducerToken ptok(_process_tp->ptoken());
|
||||
while(!fuse_session_exited(_se))
|
||||
{
|
||||
int rv;
|
||||
fuse_msgbuf_t *msgbuf;
|
||||
|
||||
msgbuf = msgbuf_alloc();
|
||||
|
||||
do
|
||||
{
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL);
|
||||
rv = _se->receive_buf(_se,msgbuf);
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL);
|
||||
if(rv == 0)
|
||||
return;
|
||||
if(retriable_receive_error(rv))
|
||||
continue;
|
||||
if(fatal_receive_error(rv))
|
||||
return handle_receive_error(rv,msgbuf);
|
||||
} while(false);
|
||||
|
||||
auto const func = [=]
|
||||
{
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL);
|
||||
rv = se->receive_buf(se,msgbuf);
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL);
|
||||
if(rv == 0)
|
||||
return NULL;
|
||||
if(retriable_receive_error(rv))
|
||||
continue;
|
||||
if(fatal_receive_error(rv))
|
||||
return handle_receive_error(rv,msgbuf);
|
||||
} while(false);
|
||||
_se->process_buf(_se,msgbuf);
|
||||
msgbuf_free(msgbuf);
|
||||
};
|
||||
|
||||
process_msgbuf(wd,msgbuf);
|
||||
}
|
||||
_process_tp->enqueue_work(ptok,func);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return NULL;
|
||||
}
|
||||
struct SyncWorker
|
||||
{
|
||||
fuse_session *_se;
|
||||
sem_t *_finished;
|
||||
|
||||
SyncWorker(fuse_session *se_,
|
||||
sem_t *finished_)
|
||||
|
||||
: _se(se_),
|
||||
_finished(finished_)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
void
|
||||
operator()() const
|
||||
{
|
||||
DEFER{ fuse_session_exit(_se); };
|
||||
DEFER{ sem_post(_finished); };
|
||||
|
||||
while(!fuse_session_exited(_se))
|
||||
{
|
||||
int rv;
|
||||
fuse_msgbuf_t *msgbuf;
|
||||
|
||||
msgbuf = msgbuf_alloc();
|
||||
|
||||
do
|
||||
{
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL);
|
||||
rv = _se->receive_buf(_se,msgbuf);
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL);
|
||||
if(rv == 0)
|
||||
return;
|
||||
if(retriable_receive_error(rv))
|
||||
continue;
|
||||
if(fatal_receive_error(rv))
|
||||
return handle_receive_error(rv,msgbuf);
|
||||
} while(false);
|
||||
|
||||
_se->process_buf(_se,msgbuf);
|
||||
msgbuf_free(msgbuf);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int
|
||||
fuse_start_thread(pthread_t *thread_id,
|
||||
@@ -174,7 +214,8 @@ calculate_thread_count(const int raw_thread_count_)
|
||||
static
|
||||
void
|
||||
calculate_thread_counts(int *read_thread_count_,
|
||||
int *process_thread_count_)
|
||||
int *process_thread_count_,
|
||||
int *process_thread_queue_depth_)
|
||||
{
|
||||
if((*read_thread_count_ == -1) && (*process_thread_count_ == -1))
|
||||
{
|
||||
@@ -190,27 +231,9 @@ calculate_thread_counts(int *read_thread_count_,
|
||||
if(*process_thread_count_ != -1)
|
||||
*process_thread_count_ = ::calculate_thread_count(*process_thread_count_);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
process_msgbuf_sync(fuse_worker_data_t *wd_,
|
||||
fuse_msgbuf_t *msgbuf_)
|
||||
{
|
||||
wd_->se->process_buf(wd_->se,msgbuf_);
|
||||
msgbuf_free(msgbuf_);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
process_msgbuf_async(fuse_worker_data_t *wd_,
|
||||
fuse_msgbuf_t *msgbuf_)
|
||||
{
|
||||
const auto func = [=] {
|
||||
process_msgbuf_sync(wd_,msgbuf_);
|
||||
};
|
||||
|
||||
wd_->tp->enqueue_work(func);
|
||||
if(*process_thread_queue_depth_ <= 0)
|
||||
*process_thread_queue_depth_ = *process_thread_count_;
|
||||
}
|
||||
|
||||
static
|
||||
@@ -401,10 +424,12 @@ pin_threads_R1PPSP(const std::vector<pthread_t> read_threads_,
|
||||
|
||||
static
|
||||
void
|
||||
pin_threads(const std::vector<pthread_t> read_threads_,
|
||||
const std::vector<pthread_t> process_threads_,
|
||||
const std::string type_)
|
||||
pin_threads(const std::vector<pthread_t> read_threads_,
|
||||
const std::vector<pthread_t> process_threads_,
|
||||
const std::string type_)
|
||||
{
|
||||
if(type_.empty() || (type_ == "false"))
|
||||
return;
|
||||
if(type_ == "R1L")
|
||||
return ::pin_threads_R1L(read_threads_);
|
||||
if(type_ == "R1P")
|
||||
@@ -423,65 +448,108 @@ pin_threads(const std::vector<pthread_t> read_threads_,
|
||||
return ::pin_threads_RPSP(read_threads_,process_threads_);
|
||||
if(type_ == "R1PPSP")
|
||||
return ::pin_threads_R1PPSP(read_threads_,process_threads_);
|
||||
|
||||
syslog(LOG_WARNING,
|
||||
"Invalid pin-threads value, ignoring: %s",
|
||||
type_.c_str());
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
wait(fuse_session *se_,
|
||||
sem_t *finished_sem_)
|
||||
{
|
||||
while(!fuse_session_exited(se_))
|
||||
sem_wait(finished_sem_);
|
||||
}
|
||||
|
||||
int
|
||||
fuse_session_loop_mt(struct fuse_session *se_,
|
||||
const int raw_read_thread_count_,
|
||||
const int raw_process_thread_count_,
|
||||
const char *pin_threads_type_)
|
||||
const int raw_process_thread_queue_depth_,
|
||||
const std::string pin_threads_type_)
|
||||
{
|
||||
int err;
|
||||
sem_t finished;
|
||||
int read_thread_count;
|
||||
int process_thread_count;
|
||||
fuse_worker_data_t wd = {0};
|
||||
int process_thread_queue_depth;
|
||||
std::vector<pthread_t> read_threads;
|
||||
std::vector<pthread_t> process_threads;
|
||||
std::unique_ptr<ThreadPool> read_tp;
|
||||
std::shared_ptr<ThreadPool> process_tp;
|
||||
|
||||
read_thread_count = raw_read_thread_count_;
|
||||
process_thread_count = raw_process_thread_count_;
|
||||
::calculate_thread_counts(&read_thread_count,&process_thread_count);
|
||||
sem_init(&finished,0,0);
|
||||
|
||||
read_thread_count = raw_read_thread_count_;
|
||||
process_thread_count = raw_process_thread_count_;
|
||||
process_thread_queue_depth = raw_process_thread_queue_depth_;
|
||||
::calculate_thread_counts(&read_thread_count,
|
||||
&process_thread_count,
|
||||
&process_thread_queue_depth);
|
||||
|
||||
if(process_thread_count > 0)
|
||||
process_tp = std::make_shared<ThreadPool>(process_thread_count,
|
||||
(process_thread_count *
|
||||
process_thread_queue_depth),
|
||||
"fuse.process");
|
||||
|
||||
read_tp = std::make_unique<ThreadPool>(read_thread_count,
|
||||
read_thread_count,
|
||||
"fuse.read");
|
||||
if(process_tp)
|
||||
{
|
||||
wd.tp = std::make_shared<ThreadPool>(process_thread_count);
|
||||
wd.msgbuf_processor = process_msgbuf_async;
|
||||
process_threads = wd.tp->threads();
|
||||
for(auto i = 0; i < read_thread_count; i++)
|
||||
read_tp->enqueue_work(AsyncWorker(se_,&finished,process_tp));
|
||||
}
|
||||
else
|
||||
{
|
||||
wd.msgbuf_processor = process_msgbuf_sync;
|
||||
for(auto i = 0; i < read_thread_count; i++)
|
||||
read_tp->enqueue_work(SyncWorker(se_,&finished));
|
||||
}
|
||||
|
||||
wd.se = se_;
|
||||
sem_init(&wd.finished,0,0);
|
||||
if(read_tp)
|
||||
read_threads = read_tp->threads();
|
||||
if(process_tp)
|
||||
process_threads = process_tp->threads();
|
||||
|
||||
err = 0;
|
||||
for(int i = 0; i < read_thread_count; i++)
|
||||
{
|
||||
pthread_t thread_id;
|
||||
err = fuse_start_thread(&thread_id,fuse_do_work,&wd);
|
||||
assert(err == 0);
|
||||
read_threads.push_back(thread_id);
|
||||
}
|
||||
::pin_threads(read_threads,process_threads,pin_threads_type_);
|
||||
|
||||
if(pin_threads_type_ != NULL)
|
||||
::pin_threads(read_threads,process_threads,pin_threads_type_);
|
||||
syslog(LOG_INFO,
|
||||
"read-thread-count=%d; "
|
||||
"process-thread-count=%d; "
|
||||
"process-thread-queue-depth=%d; "
|
||||
"pin-threads=%s;"
|
||||
,
|
||||
read_thread_count,
|
||||
process_thread_count,
|
||||
process_thread_queue_depth,
|
||||
pin_threads_type_.c_str());
|
||||
|
||||
if(!err)
|
||||
{
|
||||
/* sem_wait() is interruptible */
|
||||
while(!fuse_session_exited(se_))
|
||||
sem_wait(&wd.finished);
|
||||
::wait(se_,&finished);
|
||||
|
||||
for(const auto &thread_id : read_threads)
|
||||
pthread_cancel(thread_id);
|
||||
sem_destroy(&finished);
|
||||
|
||||
for(const auto &thread_id : read_threads)
|
||||
pthread_join(thread_id,NULL);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sem_destroy(&wd.finished);
|
||||
int
|
||||
fuse_loop_mt(struct fuse *f)
|
||||
{
|
||||
if(f == NULL)
|
||||
return -1;
|
||||
|
||||
return err;
|
||||
int res = fuse_start_maintenance_thread(f);
|
||||
if(res)
|
||||
return -1;
|
||||
|
||||
res = fuse_session_loop_mt(fuse_get_session(f),
|
||||
fuse_config_get_read_thread_count(),
|
||||
fuse_config_get_process_thread_count(),
|
||||
fuse_config_get_process_thread_queue_depth(),
|
||||
fuse_config_get_pin_threads());
|
||||
|
||||
fuse_stop_maintenance_thread(f);
|
||||
|
||||
return res;
|
||||
}
|
||||
+128
-46
@@ -261,18 +261,22 @@ fill_entry(struct fuse_entry_out *arg,
|
||||
|
||||
static
|
||||
void
|
||||
fill_open(struct fuse_open_out *arg,
|
||||
const fuse_file_info_t *f)
|
||||
fill_open(struct fuse_open_out *arg_,
|
||||
const fuse_file_info_t *ffi_)
|
||||
{
|
||||
arg->fh = f->fh;
|
||||
if(f->direct_io)
|
||||
arg->open_flags |= FOPEN_DIRECT_IO;
|
||||
if(f->keep_cache)
|
||||
arg->open_flags |= FOPEN_KEEP_CACHE;
|
||||
if(f->nonseekable)
|
||||
arg->open_flags |= FOPEN_NONSEEKABLE;
|
||||
if(f->cache_readdir)
|
||||
arg->open_flags |= FOPEN_CACHE_DIR;
|
||||
arg_->fh = ffi_->fh;
|
||||
if(ffi_->direct_io)
|
||||
arg_->open_flags |= FOPEN_DIRECT_IO;
|
||||
if(ffi_->keep_cache)
|
||||
arg_->open_flags |= FOPEN_KEEP_CACHE;
|
||||
if(ffi_->nonseekable)
|
||||
arg_->open_flags |= FOPEN_NONSEEKABLE;
|
||||
if(ffi_->cache_readdir)
|
||||
arg_->open_flags |= FOPEN_CACHE_DIR;
|
||||
if(ffi_->parallel_direct_writes)
|
||||
arg_->open_flags |= FOPEN_PARALLEL_DIRECT_WRITES;
|
||||
if(ffi_->noflush)
|
||||
arg_->open_flags |= FOPEN_NOFLUSH;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -290,6 +294,11 @@ fuse_reply_entry(fuse_req_t req,
|
||||
|
||||
fill_entry(&arg, e);
|
||||
|
||||
#ifdef NDEBUG
|
||||
// TODO: Add checks for cases where a node could be marked bad by
|
||||
// the kernel.
|
||||
#endif
|
||||
|
||||
return send_reply_ok(req, &arg, size);
|
||||
}
|
||||
|
||||
@@ -1088,6 +1097,11 @@ do_init(fuse_req_t req,
|
||||
struct fuse_init_in *arg = (struct fuse_init_in *) &hdr_[1];
|
||||
struct fuse_ll *f = req->f;
|
||||
size_t bufsize = fuse_chan_bufsize(req->ch);
|
||||
uint64_t inargflags;
|
||||
uint64_t outargflags;
|
||||
|
||||
inargflags = 0;
|
||||
outargflags = 0;
|
||||
|
||||
if(f->debug)
|
||||
debug_fuse_init_in(arg);
|
||||
@@ -1118,40 +1132,49 @@ do_init(fuse_req_t req,
|
||||
|
||||
if(arg->minor >= 6)
|
||||
{
|
||||
inargflags = arg->flags;
|
||||
if(inargflags & FUSE_INIT_EXT)
|
||||
inargflags |= (((uint64_t)arg->flags2) << 32);
|
||||
|
||||
if(arg->max_readahead < f->conn.max_readahead)
|
||||
f->conn.max_readahead = arg->max_readahead;
|
||||
if(arg->flags & FUSE_ASYNC_READ)
|
||||
|
||||
if(inargflags & FUSE_ASYNC_READ)
|
||||
f->conn.capable |= FUSE_CAP_ASYNC_READ;
|
||||
if(arg->flags & FUSE_POSIX_LOCKS)
|
||||
if(inargflags & FUSE_POSIX_LOCKS)
|
||||
f->conn.capable |= FUSE_CAP_POSIX_LOCKS;
|
||||
if(arg->flags & FUSE_ATOMIC_O_TRUNC)
|
||||
if(inargflags & FUSE_ATOMIC_O_TRUNC)
|
||||
f->conn.capable |= FUSE_CAP_ATOMIC_O_TRUNC;
|
||||
if(arg->flags & FUSE_EXPORT_SUPPORT)
|
||||
if(inargflags & FUSE_EXPORT_SUPPORT)
|
||||
f->conn.capable |= FUSE_CAP_EXPORT_SUPPORT;
|
||||
if(arg->flags & FUSE_BIG_WRITES)
|
||||
if(inargflags & FUSE_BIG_WRITES)
|
||||
f->conn.capable |= FUSE_CAP_BIG_WRITES;
|
||||
if(arg->flags & FUSE_DONT_MASK)
|
||||
if(inargflags & FUSE_DONT_MASK)
|
||||
f->conn.capable |= FUSE_CAP_DONT_MASK;
|
||||
if(arg->flags & FUSE_FLOCK_LOCKS)
|
||||
if(inargflags & FUSE_FLOCK_LOCKS)
|
||||
f->conn.capable |= FUSE_CAP_FLOCK_LOCKS;
|
||||
if(arg->flags & FUSE_POSIX_ACL)
|
||||
if(inargflags & FUSE_POSIX_ACL)
|
||||
f->conn.capable |= FUSE_CAP_POSIX_ACL;
|
||||
if(arg->flags & FUSE_CACHE_SYMLINKS)
|
||||
if(inargflags & FUSE_CACHE_SYMLINKS)
|
||||
f->conn.capable |= FUSE_CAP_CACHE_SYMLINKS;
|
||||
if(arg->flags & FUSE_ASYNC_DIO)
|
||||
if(inargflags & FUSE_ASYNC_DIO)
|
||||
f->conn.capable |= FUSE_CAP_ASYNC_DIO;
|
||||
if(arg->flags & FUSE_PARALLEL_DIROPS)
|
||||
if(inargflags & FUSE_PARALLEL_DIROPS)
|
||||
f->conn.capable |= FUSE_CAP_PARALLEL_DIROPS;
|
||||
if(arg->flags & FUSE_MAX_PAGES)
|
||||
if(inargflags & FUSE_MAX_PAGES)
|
||||
f->conn.capable |= FUSE_CAP_MAX_PAGES;
|
||||
if(arg->flags & FUSE_WRITEBACK_CACHE)
|
||||
if(inargflags & FUSE_WRITEBACK_CACHE)
|
||||
f->conn.capable |= FUSE_CAP_WRITEBACK_CACHE;
|
||||
if(arg->flags & FUSE_DO_READDIRPLUS)
|
||||
if(inargflags & FUSE_DO_READDIRPLUS)
|
||||
f->conn.capable |= FUSE_CAP_READDIR_PLUS;
|
||||
if(arg->flags & FUSE_READDIRPLUS_AUTO)
|
||||
if(inargflags & FUSE_READDIRPLUS_AUTO)
|
||||
f->conn.capable |= FUSE_CAP_READDIR_PLUS_AUTO;
|
||||
if(arg->flags & FUSE_SETXATTR_EXT)
|
||||
if(inargflags & FUSE_SETXATTR_EXT)
|
||||
f->conn.capable |= FUSE_CAP_SETXATTR_EXT;
|
||||
if(inargflags & FUSE_DIRECT_IO_ALLOW_MMAP)
|
||||
f->conn.capable |= FUSE_CAP_DIRECT_IO_ALLOW_MMAP;
|
||||
if(inargflags & FUSE_CREATE_SUPP_GROUP)
|
||||
f->conn.capable |= FUSE_CAP_CREATE_SUPP_GROUP;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1182,44 +1205,57 @@ do_init(fuse_req_t req,
|
||||
if(f->op.init)
|
||||
f->op.init(f->userdata, &f->conn);
|
||||
|
||||
if((arg->flags & FUSE_MAX_PAGES) && (f->conn.want & FUSE_CAP_MAX_PAGES))
|
||||
outargflags = outarg.flags;
|
||||
if((inargflags & FUSE_MAX_PAGES) && (f->conn.want & FUSE_CAP_MAX_PAGES))
|
||||
{
|
||||
outarg.flags |= FUSE_MAX_PAGES;
|
||||
outargflags |= FUSE_MAX_PAGES;
|
||||
outarg.max_pages = f->conn.max_pages;
|
||||
|
||||
msgbuf_set_bufsize(outarg.max_pages + 1);
|
||||
}
|
||||
|
||||
if(f->conn.want & FUSE_CAP_ASYNC_READ)
|
||||
outarg.flags |= FUSE_ASYNC_READ;
|
||||
outargflags |= FUSE_ASYNC_READ;
|
||||
if(f->conn.want & FUSE_CAP_POSIX_LOCKS)
|
||||
outarg.flags |= FUSE_POSIX_LOCKS;
|
||||
outargflags |= FUSE_POSIX_LOCKS;
|
||||
if(f->conn.want & FUSE_CAP_ATOMIC_O_TRUNC)
|
||||
outarg.flags |= FUSE_ATOMIC_O_TRUNC;
|
||||
outargflags |= FUSE_ATOMIC_O_TRUNC;
|
||||
if(f->conn.want & FUSE_CAP_EXPORT_SUPPORT)
|
||||
outarg.flags |= FUSE_EXPORT_SUPPORT;
|
||||
outargflags |= FUSE_EXPORT_SUPPORT;
|
||||
if(f->conn.want & FUSE_CAP_BIG_WRITES)
|
||||
outarg.flags |= FUSE_BIG_WRITES;
|
||||
outargflags |= FUSE_BIG_WRITES;
|
||||
if(f->conn.want & FUSE_CAP_DONT_MASK)
|
||||
outarg.flags |= FUSE_DONT_MASK;
|
||||
outargflags |= FUSE_DONT_MASK;
|
||||
if(f->conn.want & FUSE_CAP_FLOCK_LOCKS)
|
||||
outarg.flags |= FUSE_FLOCK_LOCKS;
|
||||
outargflags |= FUSE_FLOCK_LOCKS;
|
||||
if(f->conn.want & FUSE_CAP_POSIX_ACL)
|
||||
outarg.flags |= FUSE_POSIX_ACL;
|
||||
outargflags |= FUSE_POSIX_ACL;
|
||||
if(f->conn.want & FUSE_CAP_CACHE_SYMLINKS)
|
||||
outarg.flags |= FUSE_CACHE_SYMLINKS;
|
||||
outargflags |= FUSE_CACHE_SYMLINKS;
|
||||
if(f->conn.want & FUSE_CAP_ASYNC_DIO)
|
||||
outarg.flags |= FUSE_ASYNC_DIO;
|
||||
outargflags |= FUSE_ASYNC_DIO;
|
||||
if(f->conn.want & FUSE_CAP_PARALLEL_DIROPS)
|
||||
outarg.flags |= FUSE_PARALLEL_DIROPS;
|
||||
outargflags |= FUSE_PARALLEL_DIROPS;
|
||||
if(f->conn.want & FUSE_CAP_WRITEBACK_CACHE)
|
||||
outarg.flags |= FUSE_WRITEBACK_CACHE;
|
||||
outargflags |= FUSE_WRITEBACK_CACHE;
|
||||
if(f->conn.want & FUSE_CAP_READDIR_PLUS)
|
||||
outarg.flags |= FUSE_DO_READDIRPLUS;
|
||||
outargflags |= FUSE_DO_READDIRPLUS;
|
||||
if(f->conn.want & FUSE_CAP_READDIR_PLUS_AUTO)
|
||||
outarg.flags |= FUSE_READDIRPLUS_AUTO;
|
||||
outargflags |= FUSE_READDIRPLUS_AUTO;
|
||||
if(f->conn.want & FUSE_CAP_SETXATTR_EXT)
|
||||
outarg.flags |= FUSE_SETXATTR_EXT;
|
||||
outargflags |= FUSE_SETXATTR_EXT;
|
||||
if(f->conn.want & FUSE_CAP_CREATE_SUPP_GROUP)
|
||||
outargflags |= FUSE_CREATE_SUPP_GROUP;
|
||||
if(f->conn.want & FUSE_CAP_DIRECT_IO_ALLOW_MMAP)
|
||||
outargflags |= FUSE_DIRECT_IO_ALLOW_MMAP;
|
||||
|
||||
if(inargflags & FUSE_INIT_EXT)
|
||||
{
|
||||
outargflags |= FUSE_INIT_EXT;
|
||||
outarg.flags2 = (outargflags >> 32);
|
||||
}
|
||||
|
||||
outarg.flags = outargflags;
|
||||
|
||||
outarg.max_readahead = f->conn.max_readahead;
|
||||
outarg.max_write = f->conn.max_write;
|
||||
@@ -1238,6 +1274,9 @@ do_init(fuse_req_t req,
|
||||
outarg.congestion_threshold = f->conn.congestion_threshold;
|
||||
}
|
||||
|
||||
if(f->conn.proto_minor >= 23)
|
||||
outarg.time_gran = 1;
|
||||
|
||||
size_t outargsize;
|
||||
if(arg->minor < 5)
|
||||
outargsize = FUSE_COMPAT_INIT_OUT_SIZE;
|
||||
@@ -1328,6 +1367,42 @@ do_copy_file_range(fuse_req_t req_,
|
||||
req_->f->op.copy_file_range(req_,hdr_);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
do_setupmapping(fuse_req_t req_,
|
||||
struct fuse_in_header *hdr_)
|
||||
{
|
||||
printf("setupmapping\n");
|
||||
req_->f->op.setupmapping(req_,hdr_);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
do_removemapping(fuse_req_t req_,
|
||||
struct fuse_in_header *hdr_)
|
||||
{
|
||||
printf("removemapping\n");
|
||||
req_->f->op.removemapping(req_,hdr_);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
do_syncfs(fuse_req_t req_,
|
||||
struct fuse_in_header *hdr_)
|
||||
{
|
||||
printf("syncfs\n");
|
||||
req_->f->op.syncfs(req_,hdr_);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
do_tmpfile(fuse_req_t req_,
|
||||
struct fuse_in_header *hdr_)
|
||||
{
|
||||
printf("tmpfile\n");
|
||||
req_->f->op.tmpfile(req_,hdr_);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
send_notify_iov(struct fuse_ll *f,
|
||||
@@ -1414,9 +1489,10 @@ fuse_lowlevel_notify_inval_entry(struct fuse_chan *ch,
|
||||
if(!f)
|
||||
return -ENODEV;
|
||||
|
||||
outarg.parent = parent;
|
||||
outarg.parent = parent;
|
||||
outarg.namelen = namelen;
|
||||
outarg.padding = 0;
|
||||
// TODO: Add ability to set `flags`
|
||||
outarg.flags = 0;
|
||||
|
||||
iov[1].iov_base = &outarg;
|
||||
iov[1].iov_len = sizeof(outarg);
|
||||
@@ -1640,6 +1716,10 @@ static struct {
|
||||
[FUSE_NOTIFY_REPLY] = { do_notify_reply, "NOTIFY_REPLY" },
|
||||
[FUSE_BATCH_FORGET] = { do_batch_forget, "BATCH_FORGET" },
|
||||
[FUSE_COPY_FILE_RANGE] = { do_copy_file_range, "COPY_FILE_RANGE" },
|
||||
[FUSE_SETUPMAPPING] = { do_setupmapping, "SETUPMAPPING" },
|
||||
[FUSE_REMOVEMAPPING] = { do_removemapping, "REMOVEMAPPING" },
|
||||
[FUSE_SYNCFS] = { do_syncfs, "SYNCFS" },
|
||||
[FUSE_TMPFILE] = { do_tmpfile, "TMPFILE" }
|
||||
};
|
||||
|
||||
#define FUSE_MAXOP (sizeof(fuse_ll_ops) / sizeof(fuse_ll_ops[0]))
|
||||
@@ -1812,6 +1892,8 @@ fuse_ll_buf_process_read(struct fuse_session *se_,
|
||||
|
||||
in = (struct fuse_in_header*)msgbuf_->mem;
|
||||
|
||||
// printf("%d\n",in->opcode);
|
||||
|
||||
req = fuse_ll_alloc_req(se_->f);
|
||||
if(req == NULL)
|
||||
return fuse_send_enomem(se_->f,se_->ch,in->unique);
|
||||
|
||||
+141
-37
@@ -17,39 +17,26 @@
|
||||
|
||||
#include "fuse_msgbuf.hpp"
|
||||
#include "fuse.h"
|
||||
#include "fuse_kernel.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <mutex>
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
|
||||
|
||||
static std::uint32_t g_PAGESIZE = 0;
|
||||
static std::uint32_t g_BUFSIZE = 0;
|
||||
|
||||
static std::atomic<std::uint_fast64_t> g_MSGBUF_ALLOC_COUNT;
|
||||
|
||||
static std::mutex g_MUTEX;
|
||||
static std::stack<fuse_msgbuf_t*> g_MSGBUF_STACK;
|
||||
static std::vector<fuse_msgbuf_t*> g_MSGBUF_STACK;
|
||||
|
||||
static
|
||||
__attribute__((constructor))
|
||||
void
|
||||
msgbuf_constructor()
|
||||
{
|
||||
g_PAGESIZE = sysconf(_SC_PAGESIZE);
|
||||
g_BUFSIZE = (g_PAGESIZE * (FUSE_MAX_MAX_PAGES + 2));
|
||||
}
|
||||
|
||||
static
|
||||
__attribute__((destructor))
|
||||
void
|
||||
msgbuf_destroy()
|
||||
{
|
||||
// TODO: cleanup?
|
||||
}
|
||||
|
||||
uint32_t
|
||||
uint64_t
|
||||
msgbuf_get_bufsize()
|
||||
{
|
||||
return g_BUFSIZE;
|
||||
@@ -58,7 +45,43 @@ msgbuf_get_bufsize()
|
||||
void
|
||||
msgbuf_set_bufsize(const uint32_t size_in_pages_)
|
||||
{
|
||||
g_BUFSIZE = (size_in_pages_ * g_PAGESIZE);
|
||||
g_BUFSIZE = ((size_in_pages_ + 1) * g_PAGESIZE);
|
||||
}
|
||||
|
||||
void
|
||||
msgbuf_page_align(fuse_msgbuf_t *msgbuf_)
|
||||
{
|
||||
msgbuf_->mem = (char*)msgbuf_;
|
||||
msgbuf_->mem += g_PAGESIZE;
|
||||
msgbuf_->size = (g_BUFSIZE - g_PAGESIZE);
|
||||
}
|
||||
|
||||
void
|
||||
msgbuf_write_align(fuse_msgbuf_t *msgbuf_)
|
||||
{
|
||||
msgbuf_->mem = (char*)msgbuf_;
|
||||
msgbuf_->mem += g_PAGESIZE;
|
||||
msgbuf_->mem -= sizeof(struct fuse_in_header);
|
||||
msgbuf_->mem -= sizeof(struct fuse_write_in);
|
||||
msgbuf_->size = (g_BUFSIZE - g_PAGESIZE);
|
||||
}
|
||||
|
||||
static
|
||||
__attribute__((constructor))
|
||||
void
|
||||
msgbuf_constructor()
|
||||
{
|
||||
g_PAGESIZE = sysconf(_SC_PAGESIZE);
|
||||
// FUSE_MAX_MAX_PAGES for payload + 1 for message header
|
||||
msgbuf_set_bufsize(FUSE_MAX_MAX_PAGES + 1);
|
||||
}
|
||||
|
||||
static
|
||||
__attribute__((destructor))
|
||||
void
|
||||
msgbuf_destroy()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static
|
||||
@@ -75,8 +98,11 @@ page_aligned_malloc(const uint64_t size_)
|
||||
return buf;
|
||||
}
|
||||
|
||||
typedef void (*msgbuf_setup_func_t)(fuse_msgbuf_t*);
|
||||
|
||||
static
|
||||
fuse_msgbuf_t*
|
||||
msgbuf_alloc()
|
||||
_msgbuf_alloc(msgbuf_setup_func_t setup_func_)
|
||||
{
|
||||
fuse_msgbuf_t *msgbuf;
|
||||
|
||||
@@ -85,40 +111,118 @@ msgbuf_alloc()
|
||||
{
|
||||
g_MUTEX.unlock();
|
||||
|
||||
msgbuf = (fuse_msgbuf_t*)malloc(sizeof(fuse_msgbuf_t));
|
||||
msgbuf = (fuse_msgbuf_t*)page_aligned_malloc(g_BUFSIZE);
|
||||
if(msgbuf == NULL)
|
||||
return NULL;
|
||||
|
||||
msgbuf->mem = (char*)page_aligned_malloc(g_BUFSIZE);
|
||||
if(msgbuf->mem == NULL)
|
||||
{
|
||||
free(msgbuf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
msgbuf->size = g_BUFSIZE;
|
||||
g_MSGBUF_ALLOC_COUNT.fetch_add(1,std::memory_order_relaxed);
|
||||
}
|
||||
else
|
||||
{
|
||||
msgbuf = g_MSGBUF_STACK.top();
|
||||
g_MSGBUF_STACK.pop();
|
||||
msgbuf = g_MSGBUF_STACK.back();
|
||||
g_MSGBUF_STACK.pop_back();
|
||||
g_MUTEX.unlock();
|
||||
}
|
||||
|
||||
setup_func_(msgbuf);
|
||||
|
||||
return msgbuf;
|
||||
}
|
||||
|
||||
// Offset the memory so write request payload will be placed on page
|
||||
// boundry so O_DIRECT can work. No impact on other message types
|
||||
// except for `read` which will require using `msgbuf_page_align`.
|
||||
fuse_msgbuf_t*
|
||||
msgbuf_alloc()
|
||||
{
|
||||
return _msgbuf_alloc(msgbuf_write_align);
|
||||
}
|
||||
|
||||
fuse_msgbuf_t*
|
||||
msgbuf_alloc_page_aligned()
|
||||
{
|
||||
return _msgbuf_alloc(msgbuf_page_align);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
msgbuf_destroy(fuse_msgbuf_t *msgbuf_)
|
||||
{
|
||||
// free(msgbuf_->mem);
|
||||
free(msgbuf_);
|
||||
}
|
||||
|
||||
void
|
||||
msgbuf_free(fuse_msgbuf_t *msgbuf_)
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(g_MUTEX);
|
||||
|
||||
if(msgbuf_->size != g_BUFSIZE)
|
||||
if(msgbuf_->size != (g_BUFSIZE - g_PAGESIZE))
|
||||
{
|
||||
free(msgbuf_->mem);
|
||||
free(msgbuf_);
|
||||
msgbuf_destroy(msgbuf_);
|
||||
g_MSGBUF_ALLOC_COUNT.fetch_sub(1,std::memory_order_relaxed);
|
||||
return;
|
||||
}
|
||||
|
||||
g_MSGBUF_STACK.push(msgbuf_);
|
||||
g_MSGBUF_STACK.emplace_back(msgbuf_);
|
||||
|
||||
}
|
||||
|
||||
uint64_t
|
||||
msgbuf_alloc_count()
|
||||
{
|
||||
return g_MSGBUF_ALLOC_COUNT;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
msgbuf_avail_count()
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(g_MUTEX);
|
||||
|
||||
return g_MSGBUF_STACK.size();
|
||||
}
|
||||
|
||||
void
|
||||
msgbuf_gc_10percent()
|
||||
{
|
||||
std::vector<fuse_msgbuf_t*> togc;
|
||||
|
||||
{
|
||||
std::size_t size;
|
||||
std::size_t ten_percent;
|
||||
|
||||
std::lock_guard<std::mutex> lck(g_MUTEX);
|
||||
|
||||
size = g_MSGBUF_STACK.size();
|
||||
ten_percent = (size / 10);
|
||||
|
||||
for(std::size_t i = 0; i < ten_percent; i++)
|
||||
{
|
||||
togc.push_back(g_MSGBUF_STACK.back());
|
||||
g_MSGBUF_STACK.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
for(auto msgbuf : togc)
|
||||
{
|
||||
msgbuf_destroy(msgbuf);
|
||||
g_MSGBUF_ALLOC_COUNT.fetch_sub(1,std::memory_order_relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
msgbuf_gc()
|
||||
{
|
||||
std::vector<fuse_msgbuf_t*> oldstack;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(g_MUTEX);
|
||||
oldstack.swap(g_MSGBUF_STACK);
|
||||
}
|
||||
|
||||
for(auto msgbuf: oldstack)
|
||||
{
|
||||
msgbuf_destroy(msgbuf);
|
||||
g_MSGBUF_ALLOC_COUNT.fetch_sub(1,std::memory_order_relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +24,19 @@
|
||||
EXTERN_C_BEGIN
|
||||
|
||||
void msgbuf_set_bufsize(const uint32_t size);
|
||||
uint32_t msgbuf_get_bufsize();
|
||||
uint64_t msgbuf_get_bufsize();
|
||||
|
||||
fuse_msgbuf_t* msgbuf_alloc();
|
||||
fuse_msgbuf_t* msgbuf_alloc_memonly();
|
||||
fuse_msgbuf_t *msgbuf_alloc();
|
||||
fuse_msgbuf_t *msgbuf_alloc_page_aligned();
|
||||
void msgbuf_free(fuse_msgbuf_t *msgbuf);
|
||||
|
||||
void msgbuf_gc();
|
||||
void msgbuf_gc_10percent();
|
||||
|
||||
uint64_t msgbuf_alloc_count();
|
||||
uint64_t msgbuf_avail_count();
|
||||
|
||||
void msgbuf_page_align(fuse_msgbuf_t *msgbuf);
|
||||
void msgbuf_write_align(fuse_msgbuf_t *msgbuf);
|
||||
|
||||
EXTERN_C_END
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
FUSE: Filesystem in Userspace
|
||||
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
|
||||
|
||||
This program can be distributed under the terms of the GNU LGPLv2.
|
||||
See the file COPYING.LIB.
|
||||
*/
|
||||
|
||||
#include "fuse_i.h"
|
||||
#include "fuse_misc.h"
|
||||
#include "fuse_lowlevel.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <assert.h>
|
||||
|
||||
int
|
||||
fuse_loop_mt(struct fuse *f)
|
||||
{
|
||||
if (f == NULL)
|
||||
return -1;
|
||||
|
||||
int res = fuse_start_maintenance_thread(f);
|
||||
if (res)
|
||||
return -1;
|
||||
|
||||
res = fuse_session_loop_mt(fuse_get_session(f),
|
||||
fuse_config_read_thread_count(f),
|
||||
fuse_config_process_thread_count(f),
|
||||
fuse_config_pin_threads(f));
|
||||
|
||||
fuse_stop_maintenance_thread(f);
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -14,9 +14,11 @@
|
||||
|
||||
static struct fuse_session *fuse_instance;
|
||||
|
||||
static void exit_handler(int sig)
|
||||
static
|
||||
void
|
||||
exit_handler(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
(void)sig;
|
||||
if (fuse_instance)
|
||||
fuse_session_exit(fuse_instance);
|
||||
}
|
||||
@@ -46,10 +48,10 @@ static int set_one_signal_handler(int sig, void (*handler)(int), int remove)
|
||||
|
||||
int fuse_set_signal_handlers(struct fuse_session *se)
|
||||
{
|
||||
if (set_one_signal_handler(SIGHUP, exit_handler, 0) == -1 ||
|
||||
set_one_signal_handler(SIGINT, exit_handler, 0) == -1 ||
|
||||
set_one_signal_handler(SIGTERM, exit_handler, 0) == -1 ||
|
||||
set_one_signal_handler(SIGPIPE, SIG_IGN, 0) == -1)
|
||||
if((set_one_signal_handler(SIGINT, exit_handler, 0) == -1) ||
|
||||
(set_one_signal_handler(SIGTERM, exit_handler, 0) == -1) ||
|
||||
(set_one_signal_handler(SIGQUIT, exit_handler, 0) == -1) ||
|
||||
(set_one_signal_handler(SIGPIPE, SIG_IGN, 0) == -1))
|
||||
return -1;
|
||||
|
||||
fuse_instance = se;
|
||||
@@ -64,8 +66,8 @@ void fuse_remove_signal_handlers(struct fuse_session *se)
|
||||
else
|
||||
fuse_instance = NULL;
|
||||
|
||||
set_one_signal_handler(SIGHUP, exit_handler, 1);
|
||||
set_one_signal_handler(SIGINT, exit_handler, 1);
|
||||
set_one_signal_handler(SIGTERM, exit_handler, 1);
|
||||
set_one_signal_handler(SIGQUIT, exit_handler, 1);
|
||||
set_one_signal_handler(SIGPIPE, SIG_IGN, 1);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef struct lock_s lock_t;
|
||||
struct lock_s
|
||||
{
|
||||
int type;
|
||||
off_t start;
|
||||
off_t end;
|
||||
pid_t pid;
|
||||
uint64_t owner;
|
||||
lock_t *next;
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<class T> struct _Unique_if
|
||||
{
|
||||
typedef unique_ptr<T> _Single_object;
|
||||
};
|
||||
|
||||
template<class T> struct _Unique_if<T[]>
|
||||
{
|
||||
typedef unique_ptr<T[]> _Unknown_bound;
|
||||
};
|
||||
|
||||
template<class T, size_t N> struct _Unique_if<T[N]>
|
||||
{
|
||||
typedef void _Known_bound;
|
||||
};
|
||||
|
||||
template<class T, class... Args>
|
||||
typename _Unique_if<T>::_Single_object
|
||||
make_unique(Args&&... args)
|
||||
{
|
||||
return unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
typename _Unique_if<T>::_Unknown_bound
|
||||
make_unique(size_t n)
|
||||
{
|
||||
typedef typename remove_extent<T>::type U;
|
||||
return unique_ptr<T>(new U[n]());
|
||||
}
|
||||
|
||||
template<class T, class... Args>
|
||||
typename _Unique_if<T>::_Known_bound
|
||||
make_unique(Args&&...) = delete;
|
||||
}
|
||||
+11
-10
@@ -61,6 +61,7 @@ enum {
|
||||
};
|
||||
|
||||
struct mount_opts {
|
||||
int allow_other;
|
||||
int ishelp;
|
||||
int flags;
|
||||
int auto_unmount;
|
||||
@@ -76,13 +77,15 @@ struct mount_opts {
|
||||
#define FUSE_MOUNT_OPT(t, p) { t, offsetof(struct mount_opts, p), 1 }
|
||||
|
||||
static const struct fuse_opt fuse_mount_opts[] = {
|
||||
FUSE_MOUNT_OPT("allow_other", allow_other),
|
||||
FUSE_MOUNT_OPT("blkdev", blkdev),
|
||||
FUSE_MOUNT_OPT("auto_unmount", auto_unmount),
|
||||
FUSE_MOUNT_OPT("auto_unmount", auto_unmount),
|
||||
FUSE_MOUNT_OPT("fsname=%s", fsname),
|
||||
FUSE_MOUNT_OPT("subtype=%s", subtype),
|
||||
FUSE_OPT_KEY("allow_other", KEY_KERN_OPT),
|
||||
FUSE_OPT_KEY("auto_unmount", KEY_FUSERMOUNT_OPT),
|
||||
FUSE_OPT_KEY("blkdev", KEY_FUSERMOUNT_OPT),
|
||||
FUSE_OPT_KEY("fsname=", KEY_FUSERMOUNT_OPT),
|
||||
FUSE_OPT_KEY("blkdev", KEY_FUSERMOUNT_OPT),
|
||||
FUSE_OPT_KEY("fsname=", KEY_FUSERMOUNT_OPT),
|
||||
FUSE_OPT_KEY("subtype=", KEY_SUBTYPE_OPT),
|
||||
FUSE_OPT_KEY("large_read", KEY_KERN_OPT),
|
||||
FUSE_OPT_KEY("blksize=", KEY_KERN_OPT),
|
||||
@@ -98,18 +101,18 @@ static const struct fuse_opt fuse_mount_opts[] = {
|
||||
FUSE_OPT_KEY("ro", KEY_KERN_FLAG),
|
||||
FUSE_OPT_KEY("rw", KEY_KERN_FLAG),
|
||||
FUSE_OPT_KEY("suid", KEY_KERN_FLAG),
|
||||
FUSE_OPT_KEY("nosuid", KEY_KERN_FLAG),
|
||||
FUSE_OPT_KEY("nosuid", KEY_KERN_FLAG),
|
||||
FUSE_OPT_KEY("dev", KEY_KERN_FLAG),
|
||||
FUSE_OPT_KEY("nodev", KEY_KERN_FLAG),
|
||||
FUSE_OPT_KEY("exec", KEY_KERN_FLAG),
|
||||
FUSE_OPT_KEY("noexec", KEY_KERN_FLAG),
|
||||
FUSE_OPT_KEY("noexec", KEY_KERN_FLAG),
|
||||
FUSE_OPT_KEY("async", KEY_KERN_FLAG),
|
||||
FUSE_OPT_KEY("sync", KEY_KERN_FLAG),
|
||||
FUSE_OPT_KEY("dirsync", KEY_KERN_FLAG),
|
||||
FUSE_OPT_KEY("dirsync", KEY_KERN_FLAG),
|
||||
FUSE_OPT_KEY("atime", KEY_KERN_FLAG),
|
||||
FUSE_OPT_KEY("noatime", KEY_KERN_FLAG),
|
||||
FUSE_OPT_KEY("noatime", KEY_KERN_FLAG),
|
||||
FUSE_OPT_KEY("-h", KEY_HELP),
|
||||
FUSE_OPT_KEY("--help", KEY_HELP),
|
||||
FUSE_OPT_KEY("--help", KEY_HELP),
|
||||
FUSE_OPT_KEY("-V", KEY_VERSION),
|
||||
FUSE_OPT_KEY("--version", KEY_VERSION),
|
||||
FUSE_OPT_END
|
||||
@@ -549,8 +552,6 @@ int fuse_kern_mount(const char *mountpoint, struct fuse_args *args)
|
||||
fuse_opt_parse(args, &mo, fuse_mount_opts, fuse_mount_opt_proc) == -1)
|
||||
return -1;
|
||||
|
||||
fuse_opt_add_opt(&mo.kernel_opts,"allow_other");
|
||||
|
||||
res = 0;
|
||||
if (mo.ishelp)
|
||||
goto out;
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
#include "node.h"
|
||||
|
||||
#include "lfmp.h"
|
||||
|
||||
static lfmp_t g_NODE_FMP;
|
||||
|
||||
static
|
||||
__attribute__((constructor))
|
||||
void
|
||||
node_constructor()
|
||||
{
|
||||
lfmp_init(&g_NODE_FMP,sizeof(node_t),256);
|
||||
}
|
||||
|
||||
static
|
||||
__attribute__((destructor))
|
||||
void
|
||||
node_destructor()
|
||||
{
|
||||
lfmp_destroy(&g_NODE_FMP);
|
||||
}
|
||||
|
||||
node_t *
|
||||
node_alloc()
|
||||
{
|
||||
return lfmp_calloc(&g_NODE_FMP);
|
||||
}
|
||||
|
||||
void
|
||||
node_free(node_t *node_)
|
||||
{
|
||||
lfmp_free(&g_NODE_FMP,node_);
|
||||
}
|
||||
|
||||
int
|
||||
node_gc1()
|
||||
{
|
||||
return lfmp_gc(&g_NODE_FMP);
|
||||
}
|
||||
|
||||
void
|
||||
node_gc()
|
||||
{
|
||||
int rv;
|
||||
int fails;
|
||||
|
||||
fails = 0;
|
||||
do
|
||||
{
|
||||
rv = node_gc1();
|
||||
if(rv == 0)
|
||||
fails++;
|
||||
} while(rv || (fails < 3));
|
||||
}
|
||||
|
||||
lfmp_t*
|
||||
node_lfmp()
|
||||
{
|
||||
return &g_NODE_FMP;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "lock.h"
|
||||
#include "lfmp.h"
|
||||
|
||||
typedef struct node_s node_t;
|
||||
struct node_s
|
||||
{
|
||||
node_t *name_next;
|
||||
node_t *id_next;
|
||||
|
||||
uint64_t nodeid;
|
||||
char *name;
|
||||
node_t *parent;
|
||||
|
||||
uint64_t nlookup;
|
||||
uint32_t refctr;
|
||||
uint32_t open_count;
|
||||
uint64_t hidden_fh;
|
||||
|
||||
int32_t treelock;
|
||||
lock_t *locks;
|
||||
|
||||
uint32_t stat_crc32b;
|
||||
uint8_t is_stat_cache_valid:1;
|
||||
};
|
||||
|
||||
node_t *node_alloc();
|
||||
void node_free(node_t*);
|
||||
int node_gc1();
|
||||
void node_gc();
|
||||
lfmp_t *node_lfmp();
|
||||
@@ -0,0 +1,369 @@
|
||||
// _____ _____ _ _____
|
||||
// / ____| / ____| | | / ____|_ _
|
||||
// | (___ ___ ___ _ __ ___ | | __ _ _ __ _ _ __ __| | | | _| |_ _| |_
|
||||
// \___ \ / __/ _ \| '_ \ / _ \ | | |_ | | | |/ _` | '__/ _` | | | |_ _|_ _|
|
||||
// ____) | (_| (_) | |_) | __/ | |__| | |_| | (_| | | | (_| | | |____|_| |_|
|
||||
// |_____/ \___\___/| .__/ \___| \_____|\__,_|\__,_|_| \__,_| \_____|
|
||||
// | | https://github.com/Neargye/scope_guard
|
||||
// |_| version 0.9.1
|
||||
//
|
||||
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2018 - 2021 Daniil Goncharov <neargye@gmail.com>.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#ifndef NEARGYE_SCOPE_GUARD_HPP
|
||||
#define NEARGYE_SCOPE_GUARD_HPP
|
||||
|
||||
#define SCOPE_GUARD_VERSION_MAJOR 0
|
||||
#define SCOPE_GUARD_VERSION_MINOR 9
|
||||
#define SCOPE_GUARD_VERSION_PATCH 1
|
||||
|
||||
#include <type_traits>
|
||||
#if (defined(_MSC_VER) && _MSC_VER >= 1900) || ((defined(__clang__) || defined(__GNUC__)) && __cplusplus >= 201700L)
|
||||
#include <exception>
|
||||
#endif
|
||||
|
||||
// scope_guard throwable settings:
|
||||
// SCOPE_GUARD_NO_THROW_CONSTRUCTIBLE requires nothrow constructible action.
|
||||
// SCOPE_GUARD_MAY_THROW_ACTION action may throw exceptions.
|
||||
// SCOPE_GUARD_NO_THROW_ACTION requires noexcept action.
|
||||
// SCOPE_GUARD_SUPPRESS_THROW_ACTION exceptions during action will be suppressed.
|
||||
// SCOPE_GUARD_CATCH_HANDLER exceptions handler. If SCOPE_GUARD_SUPPRESS_THROW_ACTIONS is not defined, it will do nothing.
|
||||
|
||||
#if !defined(SCOPE_GUARD_MAY_THROW_ACTION) && !defined(SCOPE_GUARD_NO_THROW_ACTION) && !defined(SCOPE_GUARD_SUPPRESS_THROW_ACTION)
|
||||
# define SCOPE_GUARD_MAY_THROW_ACTION
|
||||
#elif (defined(SCOPE_GUARD_MAY_THROW_ACTION) + defined(SCOPE_GUARD_NO_THROW_ACTION) + defined(SCOPE_GUARD_SUPPRESS_THROW_ACTION)) > 1
|
||||
# error Only one of SCOPE_GUARD_MAY_THROW_ACTION and SCOPE_GUARD_NO_THROW_ACTION and SCOPE_GUARD_SUPPRESS_THROW_ACTION may be defined.
|
||||
#endif
|
||||
|
||||
#if !defined(SCOPE_GUARD_CATCH_HANDLER)
|
||||
# define SCOPE_GUARD_CATCH_HANDLER /* Suppress exception.*/
|
||||
#endif
|
||||
|
||||
namespace scope_guard {
|
||||
|
||||
namespace detail {
|
||||
|
||||
#if defined(SCOPE_GUARD_SUPPRESS_THROW_ACTION) && (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || (_HAS_EXCEPTIONS))
|
||||
# define NEARGYE_NOEXCEPT(...) noexcept
|
||||
# define NEARGYE_TRY try {
|
||||
# define NEARGYE_CATCH } catch (...) { SCOPE_GUARD_CATCH_HANDLER }
|
||||
#else
|
||||
# define NEARGYE_NOEXCEPT(...) noexcept(__VA_ARGS__)
|
||||
# define NEARGYE_TRY
|
||||
# define NEARGYE_CATCH
|
||||
#endif
|
||||
|
||||
#define NEARGYE_MOV(...) static_cast<typename std::remove_reference<decltype(__VA_ARGS__)>::type&&>(__VA_ARGS__)
|
||||
#define NEARGYE_FWD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)
|
||||
|
||||
// NEARGYE_NODISCARD encourages the compiler to issue a warning if the return value is discarded.
|
||||
#if !defined(NEARGYE_NODISCARD)
|
||||
# if defined(__clang__)
|
||||
# if (__clang_major__ * 10 + __clang_minor__) >= 39 && __cplusplus >= 201703L
|
||||
# define NEARGYE_NODISCARD [[nodiscard]]
|
||||
# else
|
||||
# define NEARGYE_NODISCARD __attribute__((__warn_unused_result__))
|
||||
# endif
|
||||
# elif defined(__GNUC__)
|
||||
# if __GNUC__ >= 7 && __cplusplus >= 201703L
|
||||
# define NEARGYE_NODISCARD [[nodiscard]]
|
||||
# else
|
||||
# define NEARGYE_NODISCARD __attribute__((__warn_unused_result__))
|
||||
# endif
|
||||
# elif defined(_MSC_VER)
|
||||
# if _MSC_VER >= 1911 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
|
||||
# define NEARGYE_NODISCARD [[nodiscard]]
|
||||
# elif defined(_Check_return_)
|
||||
# define NEARGYE_NODISCARD _Check_return_
|
||||
# else
|
||||
# define NEARGYE_NODISCARD
|
||||
# endif
|
||||
# else
|
||||
# define NEARGYE_NODISCARD
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
inline int uncaught_exceptions() noexcept {
|
||||
return *(reinterpret_cast<int*>(static_cast<char*>(static_cast<void*>(_getptd())) + (sizeof(void*) == 8 ? 0x100 : 0x90)));
|
||||
}
|
||||
#elif (defined(__clang__) || defined(__GNUC__)) && __cplusplus < 201700L
|
||||
struct __cxa_eh_globals;
|
||||
extern "C" __cxa_eh_globals* __cxa_get_globals() noexcept;
|
||||
inline int uncaught_exceptions() noexcept {
|
||||
return static_cast<int>(*(reinterpret_cast<unsigned int*>(static_cast<char*>(static_cast<void*>(__cxa_get_globals())) + sizeof(void*))));
|
||||
}
|
||||
#else
|
||||
inline int uncaught_exceptions() noexcept {
|
||||
return std::uncaught_exceptions();
|
||||
}
|
||||
#endif
|
||||
|
||||
class on_exit_policy {
|
||||
bool execute_;
|
||||
|
||||
public:
|
||||
explicit on_exit_policy(bool execute) noexcept : execute_{execute} {}
|
||||
|
||||
void dismiss() noexcept {
|
||||
execute_ = false;
|
||||
}
|
||||
|
||||
bool should_execute() const noexcept {
|
||||
return execute_;
|
||||
}
|
||||
};
|
||||
|
||||
class on_fail_policy {
|
||||
int ec_;
|
||||
|
||||
public:
|
||||
explicit on_fail_policy(bool execute) noexcept : ec_{execute ? uncaught_exceptions() : -1} {}
|
||||
|
||||
void dismiss() noexcept {
|
||||
ec_ = -1;
|
||||
}
|
||||
|
||||
bool should_execute() const noexcept {
|
||||
return ec_ != -1 && ec_ < uncaught_exceptions();
|
||||
}
|
||||
};
|
||||
|
||||
class on_success_policy {
|
||||
int ec_;
|
||||
|
||||
public:
|
||||
explicit on_success_policy(bool execute) noexcept : ec_{execute ? uncaught_exceptions() : -1} {}
|
||||
|
||||
void dismiss() noexcept {
|
||||
ec_ = -1;
|
||||
}
|
||||
|
||||
bool should_execute() const noexcept {
|
||||
return ec_ != -1 && ec_ >= uncaught_exceptions();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct is_noarg_returns_void_action
|
||||
: std::false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct is_noarg_returns_void_action<T, decltype((std::declval<T>())())>
|
||||
: std::true_type {};
|
||||
|
||||
template <typename T, bool = is_noarg_returns_void_action<T>::value>
|
||||
struct is_nothrow_invocable_action
|
||||
: std::false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct is_nothrow_invocable_action<T, true>
|
||||
: std::integral_constant<bool, noexcept((std::declval<T>())())> {};
|
||||
|
||||
template <typename F, typename P>
|
||||
class scope_guard {
|
||||
using A = typename std::decay<F>::type;
|
||||
|
||||
static_assert(is_noarg_returns_void_action<A>::value,
|
||||
"scope_guard requires no-argument action, that returns void.");
|
||||
static_assert(std::is_same<P, on_exit_policy>::value || std::is_same<P, on_fail_policy>::value || std::is_same<P, on_success_policy>::value,
|
||||
"scope_guard requires on_exit_policy, on_fail_policy or on_success_policy.");
|
||||
#if defined(SCOPE_GUARD_NO_THROW_ACTION)
|
||||
static_assert(is_nothrow_invocable_action<A>::value,
|
||||
"scope_guard requires noexcept invocable action.");
|
||||
#endif
|
||||
#if defined(SCOPE_GUARD_NO_THROW_CONSTRUCTIBLE)
|
||||
static_assert(std::is_nothrow_move_constructible<A>::value,
|
||||
"scope_guard requires nothrow constructible action.");
|
||||
#endif
|
||||
|
||||
P policy_;
|
||||
A action_;
|
||||
|
||||
void* operator new(std::size_t) = delete;
|
||||
void operator delete(void*) = delete;
|
||||
|
||||
public:
|
||||
scope_guard() = delete;
|
||||
scope_guard(const scope_guard&) = delete;
|
||||
scope_guard& operator=(const scope_guard&) = delete;
|
||||
scope_guard& operator=(scope_guard&&) = delete;
|
||||
|
||||
scope_guard(scope_guard&& other) noexcept(std::is_nothrow_move_constructible<A>::value)
|
||||
: policy_{false},
|
||||
action_{NEARGYE_MOV(other.action_)} {
|
||||
policy_ = NEARGYE_MOV(other.policy_);
|
||||
other.policy_.dismiss();
|
||||
}
|
||||
|
||||
scope_guard(const A& action) = delete;
|
||||
scope_guard(A& action) = delete;
|
||||
|
||||
explicit scope_guard(A&& action) noexcept(std::is_nothrow_move_constructible<A>::value)
|
||||
: policy_{true},
|
||||
action_{NEARGYE_MOV(action)} {}
|
||||
|
||||
void dismiss() noexcept {
|
||||
policy_.dismiss();
|
||||
}
|
||||
|
||||
~scope_guard() NEARGYE_NOEXCEPT(is_nothrow_invocable_action<A>::value) {
|
||||
if (policy_.should_execute()) {
|
||||
NEARGYE_TRY
|
||||
action_();
|
||||
NEARGYE_CATCH
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename F>
|
||||
using scope_exit = scope_guard<F, on_exit_policy>;
|
||||
|
||||
template <typename F, typename std::enable_if<is_noarg_returns_void_action<F>::value, int>::type = 0>
|
||||
NEARGYE_NODISCARD scope_exit<F> make_scope_exit(F&& action) noexcept(noexcept(scope_exit<F>{NEARGYE_FWD(action)})) {
|
||||
return scope_exit<F>{NEARGYE_FWD(action)};
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
using scope_fail = scope_guard<F, on_fail_policy>;
|
||||
|
||||
template <typename F, typename std::enable_if<is_noarg_returns_void_action<F>::value, int>::type = 0>
|
||||
NEARGYE_NODISCARD scope_fail<F> make_scope_fail(F&& action) noexcept(noexcept(scope_fail<F>{NEARGYE_FWD(action)})) {
|
||||
return scope_fail<F>{NEARGYE_FWD(action)};
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
using scope_success = scope_guard<F, on_success_policy>;
|
||||
|
||||
template <typename F, typename std::enable_if<is_noarg_returns_void_action<F>::value, int>::type = 0>
|
||||
NEARGYE_NODISCARD scope_success<F> make_scope_success(F&& action) noexcept(noexcept(scope_success<F>{NEARGYE_FWD(action)})) {
|
||||
return scope_success<F>{NEARGYE_FWD(action)};
|
||||
}
|
||||
|
||||
struct scope_exit_tag {};
|
||||
|
||||
template <typename F, typename std::enable_if<is_noarg_returns_void_action<F>::value, int>::type = 0>
|
||||
scope_exit<F> operator<<(scope_exit_tag, F&& action) noexcept(noexcept(scope_exit<F>{NEARGYE_FWD(action)})) {
|
||||
return scope_exit<F>{NEARGYE_FWD(action)};
|
||||
}
|
||||
|
||||
struct scope_fail_tag {};
|
||||
|
||||
template <typename F, typename std::enable_if<is_noarg_returns_void_action<F>::value, int>::type = 0>
|
||||
scope_fail<F> operator<<(scope_fail_tag, F&& action) noexcept(noexcept(scope_fail<F>{NEARGYE_FWD(action)})) {
|
||||
return scope_fail<F>{NEARGYE_FWD(action)};
|
||||
}
|
||||
|
||||
struct scope_success_tag {};
|
||||
|
||||
template <typename F, typename std::enable_if<is_noarg_returns_void_action<F>::value, int>::type = 0>
|
||||
scope_success<F> operator<<(scope_success_tag, F&& action) noexcept(noexcept(scope_success<F>{NEARGYE_FWD(action)})) {
|
||||
return scope_success<F>{NEARGYE_FWD(action)};
|
||||
}
|
||||
|
||||
#undef NEARGYE_MOV
|
||||
#undef NEARGYE_FWD
|
||||
#undef NEARGYE_NOEXCEPT
|
||||
#undef NEARGYE_TRY
|
||||
#undef NEARGYE_CATCH
|
||||
#undef NEARGYE_NODISCARD
|
||||
|
||||
} // namespace scope_guard::detail
|
||||
|
||||
using detail::make_scope_exit;
|
||||
using detail::make_scope_fail;
|
||||
using detail::make_scope_success;
|
||||
|
||||
} // namespace scope_guard
|
||||
|
||||
// NEARGYE_MAYBE_UNUSED suppresses compiler warnings on unused entities, if any.
|
||||
#if !defined(NEARGYE_MAYBE_UNUSED)
|
||||
# if defined(__clang__)
|
||||
# if (__clang_major__ * 10 + __clang_minor__) >= 39 && __cplusplus >= 201703L
|
||||
# define NEARGYE_MAYBE_UNUSED [[maybe_unused]]
|
||||
# else
|
||||
# define NEARGYE_MAYBE_UNUSED __attribute__((__unused__))
|
||||
# endif
|
||||
# elif defined(__GNUC__)
|
||||
# if __GNUC__ >= 7 && __cplusplus >= 201703L
|
||||
# define NEARGYE_MAYBE_UNUSED [[maybe_unused]]
|
||||
# else
|
||||
# define NEARGYE_MAYBE_UNUSED __attribute__((__unused__))
|
||||
# endif
|
||||
# elif defined(_MSC_VER)
|
||||
# if _MSC_VER >= 1911 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
|
||||
# define NEARGYE_MAYBE_UNUSED [[maybe_unused]]
|
||||
# else
|
||||
# define NEARGYE_MAYBE_UNUSED __pragma(warning(suppress : 4100 4101 4189))
|
||||
# endif
|
||||
# else
|
||||
# define NEARGYE_MAYBE_UNUSED
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(NEARGYE_STR_CONCAT)
|
||||
# define NEARGYE_STR_CONCAT_(s1, s2) s1##s2
|
||||
# define NEARGYE_STR_CONCAT(s1, s2) NEARGYE_STR_CONCAT_(s1, s2)
|
||||
#endif
|
||||
|
||||
#if !defined(NEARGYE_COUNTER)
|
||||
# if defined(__COUNTER__)
|
||||
# define NEARGYE_COUNTER __COUNTER__
|
||||
# elif defined(__LINE__)
|
||||
# define NEARGYE_COUNTER __LINE__
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(SCOPE_GUARD_NO_THROW_ACTION)
|
||||
# define NEARGYE_MAKE_SCOPE_GUARD_ACTION [&]() noexcept -> void
|
||||
#else
|
||||
# define NEARGYE_MAKE_SCOPE_GUARD_ACTION [&]() -> void
|
||||
#endif
|
||||
|
||||
#define NEARGYE_MAKE_SCOPE_EXIT ::scope_guard::detail::scope_exit_tag{} << NEARGYE_MAKE_SCOPE_GUARD_ACTION
|
||||
#define NEARGYE_MAKE_SCOPE_FAIL ::scope_guard::detail::scope_fail_tag{} << NEARGYE_MAKE_SCOPE_GUARD_ACTION
|
||||
#define NEARGYE_MAKE_SCOPE_SUCCESS ::scope_guard::detail::scope_success_tag{} << NEARGYE_MAKE_SCOPE_GUARD_ACTION
|
||||
|
||||
#define NEARGYE_SCOPE_GUARD_WITH_(g, i) for (int i = 1; i--; g)
|
||||
#define NEARGYE_SCOPE_GUARD_WITH(g) NEARGYE_SCOPE_GUARD_WITH_(g, NEARGYE_STR_CONCAT(NEARGYE_INTERNAL_OBJECT_, NEARGYE_COUNTER))
|
||||
|
||||
// SCOPE_EXIT executing action on scope exit.
|
||||
#define MAKE_SCOPE_EXIT(name) auto name = NEARGYE_MAKE_SCOPE_EXIT
|
||||
#define SCOPE_EXIT NEARGYE_MAYBE_UNUSED const MAKE_SCOPE_EXIT(NEARGYE_STR_CONCAT(NEARGYE_SCOPE_EXIT_, NEARGYE_COUNTER))
|
||||
#define WITH_SCOPE_EXIT(guard) NEARGYE_SCOPE_GUARD_WITH(NEARGYE_MAKE_SCOPE_EXIT{ guard })
|
||||
|
||||
// SCOPE_FAIL executing action on scope exit when an exception has been thrown before scope exit.
|
||||
#define MAKE_SCOPE_FAIL(name) auto name = NEARGYE_MAKE_SCOPE_FAIL
|
||||
#define SCOPE_FAIL NEARGYE_MAYBE_UNUSED const MAKE_SCOPE_FAIL(NEARGYE_STR_CONCAT(NEARGYE_SCOPE_FAIL_, NEARGYE_COUNTER))
|
||||
#define WITH_SCOPE_FAIL(guard) NEARGYE_SCOPE_GUARD_WITH(NEARGYE_MAKE_SCOPE_FAIL{ guard })
|
||||
|
||||
// SCOPE_SUCCESS executing action on scope exit when no exceptions have been thrown before scope exit.
|
||||
#define MAKE_SCOPE_SUCCESS(name) auto name = NEARGYE_MAKE_SCOPE_SUCCESS
|
||||
#define SCOPE_SUCCESS NEARGYE_MAYBE_UNUSED const MAKE_SCOPE_SUCCESS(NEARGYE_STR_CONCAT(NEARGYE_SCOPE_SUCCESS_, NEARGYE_COUNTER))
|
||||
#define WITH_SCOPE_SUCCESS(guard) NEARGYE_SCOPE_GUARD_WITH(NEARGYE_MAKE_SCOPE_SUCCESS{ guard })
|
||||
|
||||
// DEFER executing action on scope exit.
|
||||
#define MAKE_DEFER(name) MAKE_SCOPE_EXIT(name)
|
||||
#define DEFER SCOPE_EXIT
|
||||
#define WITH_DEFER(guard) WITH_SCOPE_EXIT(guard)
|
||||
|
||||
#endif // NEARGYE_SCOPE_GUARD_HPP
|
||||
@@ -1,124 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "unbounded_queue.hpp"
|
||||
|
||||
#include <tuple>
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <memory>
|
||||
#include <future>
|
||||
#include <utility>
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
|
||||
class ThreadPool
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
ThreadPool(const std::size_t thread_count_ = std::thread::hardware_concurrency())
|
||||
: _queues(thread_count_),
|
||||
_count(thread_count_)
|
||||
{
|
||||
auto worker = [this](std::size_t i)
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
Proc f;
|
||||
|
||||
for(std::size_t n = 0; n < (_count * K); ++n)
|
||||
{
|
||||
if(_queues[(i + n) % _count].try_pop(f))
|
||||
break;
|
||||
}
|
||||
|
||||
if(!f && !_queues[i].pop(f))
|
||||
break;
|
||||
|
||||
f();
|
||||
}
|
||||
};
|
||||
|
||||
_threads.reserve(thread_count_);
|
||||
for(std::size_t i = 0; i < thread_count_; ++i)
|
||||
_threads.emplace_back(worker, i);
|
||||
}
|
||||
|
||||
~ThreadPool()
|
||||
{
|
||||
for(auto& queue : _queues)
|
||||
queue.unblock();
|
||||
for(auto& thread : _threads)
|
||||
thread.join();
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
void
|
||||
enqueue_work(F&& f_)
|
||||
{
|
||||
auto i = _index++;
|
||||
|
||||
for(std::size_t n = 0; n < (_count * K); ++n)
|
||||
{
|
||||
if(_queues[(i + n) % _count].try_push(f_))
|
||||
return;
|
||||
}
|
||||
|
||||
_queues[i % _count].push(std::move(f_));
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
[[nodiscard]]
|
||||
std::future<typename std::result_of<F()>::type>
|
||||
enqueue_task(F&& f_)
|
||||
{
|
||||
using TaskReturnType = typename std::result_of<F()>::type;
|
||||
using Promise = std::promise<TaskReturnType>;
|
||||
|
||||
auto i = _index++;
|
||||
auto promise = std::make_shared<Promise>();
|
||||
auto future = promise->get_future();
|
||||
auto work = [=]() {
|
||||
auto rv = f_();
|
||||
promise->set_value(rv);
|
||||
};
|
||||
|
||||
for(std::size_t n = 0; n < (_count * K); ++n)
|
||||
{
|
||||
if(_queues[(i + n) % _count].try_push(work))
|
||||
return future;
|
||||
}
|
||||
|
||||
_queues[i % _count].push(std::move(work));
|
||||
|
||||
return future;
|
||||
}
|
||||
|
||||
public:
|
||||
std::vector<pthread_t>
|
||||
threads()
|
||||
{
|
||||
std::vector<pthread_t> rv;
|
||||
|
||||
for(auto &thread : _threads)
|
||||
rv.push_back(thread.native_handle());
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
private:
|
||||
using Proc = std::function<void(void)>;
|
||||
using Queue = UnboundedQueue<Proc>;
|
||||
using Queues = std::vector<Queue>;
|
||||
Queues _queues;
|
||||
|
||||
private:
|
||||
std::vector<std::thread> _threads;
|
||||
|
||||
private:
|
||||
const std::size_t _count;
|
||||
std::atomic_uint _index;
|
||||
|
||||
static const unsigned int K = 2;
|
||||
};
|
||||
@@ -1,161 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <utility>
|
||||
|
||||
|
||||
template<typename T>
|
||||
class UnboundedQueue
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
UnboundedQueue(bool block_ = true)
|
||||
: _block(block_)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
push(const T& item_)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(_queue_lock);
|
||||
_queue.push(item_);
|
||||
}
|
||||
_condition.notify_one();
|
||||
}
|
||||
|
||||
void
|
||||
push(T&& item_)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(_queue_lock);
|
||||
_queue.push(std::move(item_));
|
||||
}
|
||||
|
||||
_condition.notify_one();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void
|
||||
emplace(Args&&... args_)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(_queue_lock);
|
||||
_queue.emplace(std::forward<Args>(args_)...);
|
||||
}
|
||||
|
||||
_condition.notify_one();
|
||||
}
|
||||
|
||||
bool
|
||||
try_push(const T& item_)
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(_queue_lock, std::try_to_lock);
|
||||
if(!lock)
|
||||
return false;
|
||||
_queue.push(item_);
|
||||
}
|
||||
|
||||
_condition.notify_one();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
try_push(T&& item_)
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(_queue_lock, std::try_to_lock);
|
||||
if(!lock)
|
||||
return false;
|
||||
_queue.push(std::move(item_));
|
||||
}
|
||||
|
||||
_condition.notify_one();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//TODO: push multiple T at once
|
||||
|
||||
bool
|
||||
pop(T& item_)
|
||||
{
|
||||
std::unique_lock<std::mutex> guard(_queue_lock);
|
||||
|
||||
_condition.wait(guard, [&]() { return !_queue.empty() || !_block; });
|
||||
if(_queue.empty())
|
||||
return false;
|
||||
|
||||
item_ = std::move(_queue.front());
|
||||
_queue.pop();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
try_pop(T& item_)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(_queue_lock, std::try_to_lock);
|
||||
if(!lock || _queue.empty())
|
||||
return false;
|
||||
|
||||
item_ = std::move(_queue.front());
|
||||
_queue.pop();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::size_t
|
||||
size() const
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(_queue_lock);
|
||||
|
||||
return _queue.size();
|
||||
}
|
||||
|
||||
bool
|
||||
empty() const
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(_queue_lock);
|
||||
|
||||
return _queue.empty();
|
||||
}
|
||||
|
||||
void
|
||||
block()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(_queue_lock);
|
||||
_block = true;
|
||||
}
|
||||
|
||||
void
|
||||
unblock()
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(_queue_lock);
|
||||
_block = false;
|
||||
}
|
||||
|
||||
_condition.notify_all();
|
||||
}
|
||||
|
||||
bool
|
||||
blocking() const
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(_queue_lock);
|
||||
|
||||
return _block;
|
||||
}
|
||||
|
||||
private:
|
||||
mutable std::mutex _queue_lock;
|
||||
|
||||
private:
|
||||
bool _block;
|
||||
std::queue<T> _queue;
|
||||
std::condition_variable _condition;
|
||||
};
|
||||
+584
-170
@@ -106,16 +106,22 @@ If you don\[cq]t already know that you have a special use case then just
|
||||
start with one of the following option sets.
|
||||
.SS You need \f[C]mmap\f[R] (used by rtorrent and many sqlite3 base software)
|
||||
.PP
|
||||
\f[C]cache.files=partial,dropcacheonclose=true,category.create=mfs\f[R]
|
||||
\f[C]cache.files=auto-full,dropcacheonclose=true,category.create=mfs\f[R]
|
||||
.PP
|
||||
or if you are on a Linux kernel >= 6.6.x mergerfs will enable a mode
|
||||
that allows shared mmap when \f[C]cache.files=off\f[R].
|
||||
To be sure of the best performance between \f[C]cache.files=off\f[R] and
|
||||
\f[C]cache.files=auto-full\f[R] you\[cq]ll need to do your own
|
||||
benchmarking but often \f[C]off\f[R] is faster.
|
||||
.SS You don\[cq]t need \f[C]mmap\f[R]
|
||||
.PP
|
||||
\f[C]cache.files=off,dropcacheonclose=true,category.create=mfs\f[R]
|
||||
.SS Command Line
|
||||
.PP
|
||||
\f[C]mergerfs -o cache.files=partial,dropcacheonclose=true,category.create=mfs /mnt/hdd0:/mnt/hdd1 /media\f[R]
|
||||
\f[C]mergerfs -o cache.files=auto-full,dropcacheonclose=true,category.create=mfs /mnt/hdd0:/mnt/hdd1 /media\f[R]
|
||||
.SS /etc/fstab
|
||||
.PP
|
||||
\f[C]/mnt/hdd0:/mnt/hdd1 /media fuse.mergerfs cache.files=partial,dropcacheonclose=true,category.create=mfs 0 0\f[R]
|
||||
\f[C]/mnt/hdd0:/mnt/hdd1 /media mergerfs cache.files=auto-full,dropcacheonclose=true,category.create=mfs 0 0\f[R]
|
||||
.SS systemd mount
|
||||
.PP
|
||||
https://github.com/trapexit/mergerfs/wiki/systemd
|
||||
@@ -130,7 +136,7 @@ Type=simple
|
||||
KillMode=none
|
||||
ExecStart=/usr/bin/mergerfs \[rs]
|
||||
-f \[rs]
|
||||
-o cache.files=partial \[rs]
|
||||
-o cache.files=auto-full \[rs]
|
||||
-o dropcacheonclose=true \[rs]
|
||||
-o category.create=mfs \[rs]
|
||||
/mnt/hdd0:/mnt/hdd1 \[rs]
|
||||
@@ -185,6 +191,13 @@ Recommended when
|
||||
caching.
|
||||
(default: false)
|
||||
.IP \[bu] 2
|
||||
\f[B]direct-io-allow-mmap=BOOL\f[R]: On newer kernels (>= 6.6) it is
|
||||
possible to disable file page caching while still allowing for shared
|
||||
mmap support.
|
||||
mergerfs will enable this feature if available but an option is provided
|
||||
to turn it off for testing and debugging purposes.
|
||||
(default: true)
|
||||
.IP \[bu] 2
|
||||
\f[B]symlinkify=BOOL\f[R]: When enabled and a file is not writable and
|
||||
its mtime or ctime is older than \f[B]symlinkify_timeout\f[R] files will
|
||||
be reported as symlinks to the original files.
|
||||
@@ -214,6 +227,10 @@ This means files, when renamed or linked, will stay on the same
|
||||
filesystem.
|
||||
(default: false)
|
||||
.IP \[bu] 2
|
||||
\f[B]export-support=BOOL\f[R]: Sets a low-level FUSE feature intended to
|
||||
indicate the filesystem can support being exported via NFS.
|
||||
(default: true)
|
||||
.IP \[bu] 2
|
||||
\f[B]security_capability=BOOL\f[R]: If false return ENOATTR when xattr
|
||||
security.capability is queried.
|
||||
(default: true)
|
||||
@@ -311,9 +328,21 @@ reading FUSE messages which are dispatched to process threads.
|
||||
-1 means disabled otherwise acts like \f[C]read-thread-count\f[R].
|
||||
(default: -1)
|
||||
.IP \[bu] 2
|
||||
\f[B]process-thread-queue-depth=UINT\f[R]: Sets the number of requests
|
||||
any single process thread can have queued up at one time.
|
||||
Meaning the total memory usage of the queues is queue depth multiplied
|
||||
by the number of process threads plus read thread count.
|
||||
0 sets the depth to the same as the process thread count.
|
||||
(default: 0)
|
||||
.IP \[bu] 2
|
||||
\f[B]pin-threads=STR\f[R]: Selects a strategy to pin threads to CPUs
|
||||
(default: unset)
|
||||
.IP \[bu] 2
|
||||
\f[B]flush-on-close=never|always|opened-for-write\f[R]: Flush data cache
|
||||
on file close.
|
||||
Mostly for when writeback is enabled or merging network filesystems.
|
||||
(default: opened-for-write)
|
||||
.IP \[bu] 2
|
||||
\f[B]scheduling-priority=INT\f[R]: Set mergerfs\[cq] scheduling
|
||||
priority.
|
||||
Valid values range from -20 to 19.
|
||||
@@ -330,6 +359,11 @@ policy.
|
||||
See below for the list of value types.
|
||||
Example: \f[B]func.getattr=newest\f[R]
|
||||
.IP \[bu] 2
|
||||
\f[B]func.readdir=seq|cosr|cor|cosr:INT|cor:INT\f[R]: Sets
|
||||
\f[C]readdir\f[R] policy.
|
||||
INT value sets the number of threads to use for concurrency.
|
||||
(default: seq)
|
||||
.IP \[bu] 2
|
||||
\f[B]category.action=POLICY\f[R]: Sets policy of all FUSE functions in
|
||||
the action category.
|
||||
(default: epall)
|
||||
@@ -377,6 +411,12 @@ to enable page caching for when \f[C]cache.files=per-process\f[R].
|
||||
\f[B]cache.readdir=BOOL\f[R]: Cache readdir (if supported by kernel)
|
||||
(default: false)
|
||||
.IP \[bu] 2
|
||||
\f[B]parallel-direct-writes=BOOL\f[R]: Allow the kernel to dispatch
|
||||
multiple, parallel (non-extending) write requests for files opened with
|
||||
\f[C]cache.files=per-process\f[R] (if the process is not in
|
||||
\f[C]process-names\f[R]) or \f[C]cache.files=off\f[R].
|
||||
(This requires kernel support, and was added in v6.2)
|
||||
.IP \[bu] 2
|
||||
\f[B]direct_io\f[R]: deprecated - Bypass page cache.
|
||||
Use \f[C]cache.files=off\f[R] instead.
|
||||
(default: false)
|
||||
@@ -397,18 +437,14 @@ Use \f[C]async_read=true\f[R] instead.
|
||||
\f[B]sync_read\f[R]: deprecated - Perform reads synchronously.
|
||||
Use \f[C]async_read=false\f[R] instead.
|
||||
.IP \[bu] 2
|
||||
\f[B]use_ino\f[R]: deprecated - Always enabled.
|
||||
.IP \[bu] 2
|
||||
\f[B]allow_other\f[R]: deprecated - Always enabled.
|
||||
.IP \[bu] 2
|
||||
\f[B]splice_read\f[R]: deprecated - Does nothing.
|
||||
.IP \[bu] 2
|
||||
\f[B]splice_write\f[R]: deprecated - Does nothing.
|
||||
.IP \[bu] 2
|
||||
\f[B]splice_move\f[R]: deprecated - Does nothing.
|
||||
.IP \[bu] 2
|
||||
\f[B]allow_other\f[R]: deprecated - mergerfs always sets this FUSE
|
||||
option as normal permissions can be used to limit access.
|
||||
\f[B]allow_other\f[R]: deprecated - mergerfs v2.35.0 and newer sets this
|
||||
FUSE option automatically if running as root.
|
||||
.IP \[bu] 2
|
||||
\f[B]use_ino\f[R]: deprecated - mergerfs should always control inode
|
||||
calculation so this is enabled all the time.
|
||||
@@ -493,8 +529,8 @@ tools use \f[B]/etc/fstab\f[R].
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
/mnt/hdd*:/mnt/ssd /media fuse.mergerfs minfreespace=16G 0 0
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
/mnt/hdd*:/mnt/ssd /media mergerfs minfreespace=16G 0 0
|
||||
\f[R]
|
||||
.fi
|
||||
.PP
|
||||
@@ -528,7 +564,7 @@ Most software does not to care what the values are but those that do
|
||||
often break if a value changes unexpectedly.
|
||||
The tool \f[C]find\f[R] will abort a directory walk if it sees a
|
||||
directory inode change.
|
||||
NFS will return stale handle errors if the inode changes out of band.
|
||||
NFS can return stale handle errors if the inode changes out of band.
|
||||
File dedup tools will usually leverage device ids and inodes as a
|
||||
shortcut in searching for duplicate files and would resort to full file
|
||||
comparisons should it find different inode values.
|
||||
@@ -816,8 +852,20 @@ Even though it\[cq]s a more niche situation this hack breaks normal
|
||||
security and behavior and as such is \f[C]off\f[R] by default.
|
||||
If set to \f[C]git\f[R] it will only perform the hack when the path in
|
||||
question includes \f[C]/.git/\f[R].
|
||||
\f[C]all\f[R] will result it applying anytime a readonly file which is
|
||||
\f[C]all\f[R] will result it applying anytime a read-only file which is
|
||||
empty is opened for writing.
|
||||
.SS export-support
|
||||
.PP
|
||||
In theory this flag should not be exposed to the end user.
|
||||
It is a low-level FUSE flag which indicates whether or not the kernel
|
||||
can send certain kinds of messages to it for the purposes of using with
|
||||
NFS.
|
||||
mergerfs does support these messages but due bugs and quirks found in
|
||||
the kernel and mergerfs this option is provided just in case it is
|
||||
needed for debugging.
|
||||
.PP
|
||||
Given that this flag is set when the FUSE connection is first initiated
|
||||
it is not possible to change during run time.
|
||||
.SH FUNCTIONS, CATEGORIES and POLICIES
|
||||
.PP
|
||||
The POSIX filesystem API is made up of a number of functions.
|
||||
@@ -837,8 +885,6 @@ provide the file handle when a client calls \f[C]fgetattr\f[R],
|
||||
\f[C]fchown\f[R], \f[C]fchmod\f[R], \f[C]futimens\f[R],
|
||||
\f[C]ftruncate\f[R], etc.
|
||||
This means it will call the regular, path based, versions.
|
||||
\f[C]readdir\f[R] has no real need for a policy given the purpose is
|
||||
merely to return a list of entries in a directory.
|
||||
\f[C]statfs\f[R]\[cq]s behavior can be modified via other options.
|
||||
.PP
|
||||
When using policies which are based on a branch\[cq]s available space
|
||||
@@ -849,8 +895,8 @@ calculations.
|
||||
The reason is that it doesn\[cq]t really work for non-path preserving
|
||||
policies and can lead to non-obvious behaviors.
|
||||
.PP
|
||||
NOTE: While any policy can be assigned to a function or category though
|
||||
some may not be very useful in practice.
|
||||
NOTE: While any policy can be assigned to a function or category, some
|
||||
may not be very useful in practice.
|
||||
For instance: \f[B]rand\f[R] (random) may be useful for file creation
|
||||
(create) but could lead to very odd behavior if used for \f[C]chmod\f[R]
|
||||
if there were more than one copy of the file.
|
||||
@@ -895,8 +941,7 @@ In cases where something may be searched for (such as a path to clone)
|
||||
.SS Policies
|
||||
.PP
|
||||
A policy is the algorithm used to choose a branch or branches for a
|
||||
function to work on.
|
||||
Think of them as ways to filter and sort branches.
|
||||
function to work on or generally how the function behaves.
|
||||
.PP
|
||||
Any function in the \f[C]create\f[R] category will clone the relative
|
||||
path if needed.
|
||||
@@ -905,12 +950,12 @@ have special requirements or behaviors which you can read more about
|
||||
below.
|
||||
.SS Filtering
|
||||
.PP
|
||||
Policies basically search branches and create a list of files / paths
|
||||
for functions to work on.
|
||||
Most policies basically search branches and create a list of files /
|
||||
paths for functions to work on.
|
||||
The policy is responsible for filtering and sorting the branches.
|
||||
Filters include \f[B]minfreespace\f[R], whether or not a branch is
|
||||
mounted read-only, and the branch tagging (RO,NC,RW).
|
||||
These filters are applied across all policies unless otherwise noted.
|
||||
These filters are applied across most policies.
|
||||
.IP \[bu] 2
|
||||
No \f[B]search\f[R] function policies filter.
|
||||
.IP \[bu] 2
|
||||
@@ -930,6 +975,13 @@ Typically \f[B]EROFS\f[R] (read-only filesystem) or \f[B]ENOSPC\f[R] (no
|
||||
space left on device) depending on the most recent reason for filtering
|
||||
a branch.
|
||||
\f[B]ENOENT\f[R] will be returned if no eligible branch is found.
|
||||
.PP
|
||||
If \f[B]create\f[R], \f[B]mkdir\f[R], \f[B]mknod\f[R], or
|
||||
\f[B]symlink\f[R] fail with \f[C]EROFS\f[R] or other fundimental errors
|
||||
then mergerfs will mark any branch found to be read-only as such (IE
|
||||
will set the mode \f[C]RO\f[R]) and will rerun the policy and try again.
|
||||
This is mostly for \f[C]ext4\f[R] filesystems that can suddenly become
|
||||
read-only when it encounters an error.
|
||||
.SS Path Preservation
|
||||
.PP
|
||||
Policies, as described below, are of two basic classifications.
|
||||
@@ -1120,6 +1172,63 @@ T}@T{
|
||||
ff
|
||||
T}
|
||||
.TE
|
||||
.SS func.readdir
|
||||
.PP
|
||||
examples: \f[C]func.readdir=seq\f[R], \f[C]func.readdir=cor:4\f[R]
|
||||
.PP
|
||||
\f[C]readdir\f[R] has policies to control how it manages reading
|
||||
directory content.
|
||||
.PP
|
||||
.TS
|
||||
tab(@);
|
||||
lw(26.7n) lw(43.3n).
|
||||
T{
|
||||
Policy
|
||||
T}@T{
|
||||
Description
|
||||
T}
|
||||
_
|
||||
T{
|
||||
seq
|
||||
T}@T{
|
||||
\[lq]sequential\[rq] : Iterate over branches in the order defined.
|
||||
This is the default and traditional behavior found prior to the readdir
|
||||
policy introduction.
|
||||
T}
|
||||
T{
|
||||
cosr
|
||||
T}@T{
|
||||
\[lq]concurrent open, sequential read\[rq] : Concurrently open branch
|
||||
directories using a thread pool and process them in order of definition.
|
||||
This keeps memory and CPU usage low while also reducing the time spent
|
||||
waiting on branches to respond.
|
||||
Number of threads defaults to the number of logical cores.
|
||||
Can be overwritten via the syntax \f[C]func.readdir=cosr:N\f[R] where
|
||||
\f[C]N\f[R] is the number of threads.
|
||||
T}
|
||||
T{
|
||||
cor
|
||||
T}@T{
|
||||
\[lq]concurrent open and read\[rq] : Concurrently open branch
|
||||
directories and immediately start reading their contents using a thread
|
||||
pool.
|
||||
This will result in slightly higher memory and CPU usage but reduced
|
||||
latency.
|
||||
Particularly when using higher latency / slower speed network filesystem
|
||||
branches.
|
||||
Unlike \f[C]seq\f[R] and \f[C]cosr\f[R] the order of files could change
|
||||
due the async nature of the thread pool.
|
||||
Number of threads defaults to the number of logical cores.
|
||||
Can be overwritten via the syntax \f[C]func.readdir=cor:N\f[R] where
|
||||
\f[C]N\f[R] is the number of threads.
|
||||
T}
|
||||
.TE
|
||||
.PP
|
||||
Keep in mind that \f[C]readdir\f[R] mostly just provides a list of file
|
||||
names in a directory and possibly some basic metadata about said files.
|
||||
To know details about the files, as one would see from commands like
|
||||
\f[C]find\f[R] or \f[C]ls\f[R], it is required to call \f[C]stat\f[R] on
|
||||
the file which is controlled by \f[C]fuse.getattr\f[R].
|
||||
.SS ioctl
|
||||
.PP
|
||||
When \f[C]ioctl\f[R] is used with an open file then it will use the file
|
||||
@@ -1232,19 +1341,6 @@ The above behavior will help minimize the likelihood of EXDEV being
|
||||
returned but it will still be possible.
|
||||
.PP
|
||||
\f[B]link\f[R] uses the same strategy but without the removals.
|
||||
.SS readdir
|
||||
.PP
|
||||
readdir (http://linux.die.net/man/3/readdir) is different from all other
|
||||
filesystem functions.
|
||||
While it could have its own set of policies to tweak its behavior at
|
||||
this time it provides a simple union of files and directories found.
|
||||
Remember that any action or information queried about these files and
|
||||
directories come from the respective function.
|
||||
For instance: an \f[B]ls\f[R] is a \f[B]readdir\f[R] and for each
|
||||
file/directory returned \f[B]getattr\f[R] is called.
|
||||
Meaning the policy of \f[B]getattr\f[R] is responsible for choosing the
|
||||
file/directory which is the source of the metadata you see in an
|
||||
\f[B]ls\f[R].
|
||||
.SS statfs / statvfs
|
||||
.PP
|
||||
statvfs (http://linux.die.net/man/2/statvfs) normalizes the source
|
||||
@@ -1259,6 +1355,24 @@ be included when checking the mount\[cq]s stats.
|
||||
.PP
|
||||
The options \f[C]statfs\f[R] and \f[C]statfs_ignore\f[R] can be used to
|
||||
modify \f[C]statfs\f[R] behavior.
|
||||
.SS flush-on-close
|
||||
.PP
|
||||
https://lkml.kernel.org/linux-fsdevel/20211024132607.1636952-1-amir73il\[at]gmail.com/T/
|
||||
.PP
|
||||
By default FUSE would issue a flush before the release of a file
|
||||
descriptor.
|
||||
This was considered a bit aggressive and a feature added to give the
|
||||
FUSE server the ability to choose when that happens.
|
||||
.PP
|
||||
Options: * always * never * opened-for-write
|
||||
.PP
|
||||
For now it defaults to \[lq]opened-for-write\[rq] which is less
|
||||
aggressive than the behavior before this feature was added.
|
||||
It should not be a problem because the flush is really only relevant
|
||||
when a file is written to.
|
||||
Given flush is irrelevant for many filesystems in the future a branch
|
||||
specific flag may be added so only files opened on a specific branch
|
||||
would be flushed on close.
|
||||
.SH ERROR HANDLING
|
||||
.PP
|
||||
POSIX filesystem functions offer a single return code meaning that there
|
||||
@@ -1468,8 +1582,8 @@ apply those before mounting the new version.
|
||||
\f[C]
|
||||
$ sudo mount /mnt/mergerfs
|
||||
$ mount | grep mergerfs
|
||||
media on /mnt/mergerfs type fuse.mergerfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other)
|
||||
media on /mnt/mergerfs type fuse.mergerfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other)
|
||||
media on /mnt/mergerfs type mergerfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other)
|
||||
media on /mnt/mergerfs type mergerfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other)
|
||||
\f[R]
|
||||
.fi
|
||||
.PP
|
||||
@@ -1480,7 +1594,8 @@ Before mounting over top the mount point with the new instance of
|
||||
mergerfs issue: \f[C]umount -l <mergerfs_mountpoint>\f[R].
|
||||
Or you can let mergerfs do it by setting the option
|
||||
\f[C]lazy-umount-mountpoint=true\f[R].
|
||||
.SH RUNTIME CONFIG
|
||||
.SH RUNTIME INTERFACES
|
||||
.SS RUNTIME CONFIG
|
||||
.SS .mergerfs pseudo file
|
||||
.IP
|
||||
.nf
|
||||
@@ -1596,7 +1711,148 @@ given the getattr policy
|
||||
.IP \[bu] 2
|
||||
\f[B]user.mergerfs.allpaths\f[R]: a NUL (`\[rs]0') separated list of
|
||||
full paths to all files found
|
||||
.SS SIGNALS
|
||||
.IP \[bu] 2
|
||||
USR1: This will cause mergerfs to send invalidation notifications to the
|
||||
kernel for all files.
|
||||
This will cause all unused files to be released from memory.
|
||||
.IP \[bu] 2
|
||||
USR2: Trigger a general cleanup of currently unused memory.
|
||||
A more thorough version of what happens every \[ti]15 minutes.
|
||||
.SS IOCTLS
|
||||
.PP
|
||||
Found in \f[C]fuse_ioctl.cpp\f[R]:
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
typedef char IOCTL_BUF[4096];
|
||||
#define IOCTL_APP_TYPE 0xDF
|
||||
#define IOCTL_FILE_INFO _IOWR(IOCTL_APP_TYPE,0,IOCTL_BUF)
|
||||
#define IOCTL_GC _IO(IOCTL_APP_TYPE,1)
|
||||
#define IOCTL_GC1 _IO(IOCTL_APP_TYPE,2)
|
||||
#define IOCTL_INVALIDATE_ALL_NODES _IO(IOCTL_APP_TYPE,3)
|
||||
\f[R]
|
||||
.fi
|
||||
.IP \[bu] 2
|
||||
IOCTL_FILE_INFO: Same as the \[lq]file / directory xattrs\[rq] mentioned
|
||||
above.
|
||||
Use a buffer size of 4096 bytes.
|
||||
Pass in a string of \[lq]basepath\[rq], \[lq]relpath\[rq],
|
||||
\[lq]fullpath\[rq], or \[lq]allpaths\[rq].
|
||||
Receive details in same buffer.
|
||||
.IP \[bu] 2
|
||||
IOCTL_GC: Triggers a thorough garbage collection of excess memory.
|
||||
Same as SIGUSR2.
|
||||
.IP \[bu] 2
|
||||
IOCTL_GC1: Triggers a simple garbage collection of excess memory.
|
||||
Same as what happens every 15 minutes normally.
|
||||
.IP \[bu] 2
|
||||
IOCTL_INVALIDATE_ALL_NODES: Same as SIGUSR1.
|
||||
Send invalidation notifications to the kernel for all files causing
|
||||
unused files to be released from memory.
|
||||
.SH TOOLING
|
||||
.SS preload.so
|
||||
.PP
|
||||
EXPERIMENTAL
|
||||
.PP
|
||||
For some time there has been work to enable passthrough IO in FUSE.
|
||||
Passthrough IO would allow for near native performance with regards to
|
||||
reads and writes (at the expense of certain mergerfs features.) However,
|
||||
there have been several complications which have kept the feature from
|
||||
making it into the mainline Linux kernel.
|
||||
Until that feature is available there are two methods to provide similar
|
||||
functionality.
|
||||
One method is using the LD_PRELOAD feature of the dynamic linker.
|
||||
The other leveraging ptrace to intercept syscalls.
|
||||
Each has their disadvantages.
|
||||
At the moment only a preload based tool is available.
|
||||
A ptrace based tool may be developed later if there is a need.
|
||||
.PP
|
||||
\f[C]/usr/lib/mergerfs/preload.so\f[R]
|
||||
.PP
|
||||
This preloadable
|
||||
library (https://man7.org/linux/man-pages/man8/ld.so.8.html#ENVIRONMENT)
|
||||
overrides the creation and opening of files in order to simulate
|
||||
passthrough file IO.
|
||||
It catches the open/creat/fopen calls, has mergerfs do the call, queries
|
||||
mergerfs for the branch the file exists on, reopens the file on the
|
||||
underlying filesystem and returns that instead.
|
||||
Meaning that you will get native read/write performance because mergerfs
|
||||
is no longer part of the workflow.
|
||||
Keep in mind that this also means certain mergerfs features that work by
|
||||
interrupting the read/write workflow, such as \f[C]moveonenospc\f[R],
|
||||
will no longer work.
|
||||
.PP
|
||||
Also understand that this will only work on dynamically linked software.
|
||||
Anything statically compiled will not work.
|
||||
Many GoLang and Rust apps are statically compiled.
|
||||
.PP
|
||||
The library will not interfere with non-mergerfs filesystems.
|
||||
The library is written to always fallback to returning the mergerfs
|
||||
opened file on error.
|
||||
.PP
|
||||
While the library was written to account for a number of edgecases there
|
||||
could be some yet accounted for so please report any oddities.
|
||||
.PP
|
||||
Thank you to nohajc (https://github.com/nohajc/mergerfs-io-passthrough)
|
||||
for prototyping the idea.
|
||||
.SS general usage
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
LD_PRELOAD=/usr/lib/mergerfs/preload.so touch /mnt/mergerfs/filename
|
||||
\f[R]
|
||||
.fi
|
||||
.SS Docker usage
|
||||
.PP
|
||||
Assume \f[C]/mnt/fs0\f[R] and \f[C]/mnt/fs1\f[R] are pooled with
|
||||
mergerfs at \f[C]/media\f[R].
|
||||
.PP
|
||||
All mergerfs branch paths \f[I]must\f[R] be bind mounted into the
|
||||
container at the same path as found on the host so the preload library
|
||||
can see them.
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
docker run \[rs]
|
||||
-e LD_PRELOAD=/usr/lib/mergerfs/preload.so \[rs]
|
||||
-v /usr/lib/mergerfs/preload.so:/usr/lib/mergerfs/preload.so:ro \[rs]
|
||||
-v /media:/data \[rs]
|
||||
-v /mnt:/mnt \[rs]
|
||||
ubuntu:latest \[rs]
|
||||
bash
|
||||
\f[R]
|
||||
.fi
|
||||
.PP
|
||||
or more explicitly
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
docker run \[rs]
|
||||
-e LD_PRELOAD=/usr/lib/mergerfs/preload.so \[rs]
|
||||
-v /usr/lib/mergerfs/preload.so:/usr/lib/mergerfs/preload.so:ro \[rs]
|
||||
-v /media:/data \[rs]
|
||||
-v /mnt/fs0:/mnt/fs0 \[rs]
|
||||
-v /mnt/fs1:/mnt/fs1 \[rs]
|
||||
ubuntu:latest \[rs]
|
||||
bash
|
||||
\f[R]
|
||||
.fi
|
||||
.SS systemd unit
|
||||
.PP
|
||||
Use the \f[C]Environment\f[R] option to set the LD_PRELOAD variable.
|
||||
.IP \[bu] 2
|
||||
https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#Command%20lines
|
||||
.IP \[bu] 2
|
||||
https://serverfault.com/questions/413397/how-to-set-environment-variable-in-systemd-service
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
[Service]
|
||||
Environment=LD_PRELOAD=/usr/lib/mergerfs/preload.so
|
||||
\f[R]
|
||||
.fi
|
||||
.SS Misc
|
||||
.IP \[bu] 2
|
||||
https://github.com/trapexit/mergerfs-tools
|
||||
.RS 2
|
||||
@@ -1653,9 +1909,12 @@ size are unchanged since previous open.
|
||||
cache.files=libfuse: follow traditional libfuse \f[C]direct_io\f[R],
|
||||
\f[C]kernel_cache\f[R], and \f[C]auto_cache\f[R] arguments.
|
||||
.IP \[bu] 2
|
||||
cache.files=per-process: Enable page caching only for processes which
|
||||
`comm' name matches one of the values defined in
|
||||
cache.files=per-process: Enable page caching (equivalent to
|
||||
\f[C]cache.files=partial\f[R]) only for processes whose `comm' name
|
||||
matches one of the values defined in
|
||||
\f[C]cache.files.process-names\f[R].
|
||||
If the name does not match the file open is equivalent to
|
||||
\f[C]cache.files=off\f[R].
|
||||
.PP
|
||||
FUSE, which mergerfs uses, offers a number of page caching modes.
|
||||
mergerfs tries to simplify their use via the \f[C]cache.files\f[R]
|
||||
@@ -1794,7 +2053,7 @@ The placing of usually smaller, faster storage as a transparent cache to
|
||||
larger, slower storage.
|
||||
NVMe, SSD, Optane in front of traditional HDDs for instance.
|
||||
.PP
|
||||
MergerFS does not natively support any sort of tiered caching.
|
||||
mergerfs does not natively support any sort of tiered caching.
|
||||
Most users have no use for such a feature and its inclusion would
|
||||
complicate the code.
|
||||
However, there are a few situations where a cache filesystem could help
|
||||
@@ -1906,6 +2165,8 @@ increase cache timeouts \f[C]cache.attr\f[R], \f[C]cache.entry\f[R],
|
||||
.IP \[bu] 2
|
||||
enable (or disable) page caching (\f[C]cache.files\f[R])
|
||||
.IP \[bu] 2
|
||||
enable \f[C]parallel-direct-writes\f[R]
|
||||
.IP \[bu] 2
|
||||
enable \f[C]cache.writeback\f[R]
|
||||
.IP \[bu] 2
|
||||
enable \f[C]cache.statfs\f[R]
|
||||
@@ -2143,18 +2404,13 @@ Use \f[C]cache.files=off\f[R] and/or \f[C]dropcacheonclose=true\f[R].
|
||||
See the section on page caching.
|
||||
.SS NFS clients returning ESTALE / Stale file handle
|
||||
.PP
|
||||
NFS does not like out of band changes.
|
||||
That is especially true of inode values.
|
||||
.PP
|
||||
Be sure to use the following options:
|
||||
.IP \[bu] 2
|
||||
noforget
|
||||
.IP \[bu] 2
|
||||
inodecalc=path-hash
|
||||
NFS generally does not like out of band changes.
|
||||
Take a look at the section on NFS in the #remote-filesystems for more
|
||||
details.
|
||||
.SS rtorrent fails with ENODEV (No such device)
|
||||
.PP
|
||||
Be sure to set \f[C]cache.files=partial|full|auto-full|per-processe\f[R]
|
||||
or turn off \f[C]direct_io\f[R].
|
||||
Be sure to set
|
||||
\f[C]cache.files=partial|full|auto-full|per-processe\f[R].
|
||||
rtorrent and some other applications use
|
||||
mmap (http://linux.die.net/man/2/mmap) to read and write to files and
|
||||
offer no fallback to traditional methods.
|
||||
@@ -2307,6 +2563,123 @@ There might be a hack to work around this (make mergerfs read the
|
||||
would be limited to Linux and the /etc/group DB.
|
||||
Preferably users would mount in the host group file into the containers
|
||||
or use a standard shared user & groups technology like NIS or LDAP.
|
||||
.SH Remote Filesystems
|
||||
.PP
|
||||
Many users ask about compatibility with remote filesystems.
|
||||
This section is to describe any known issues or quirks when using
|
||||
mergerfs with common remote filesystems.
|
||||
.PP
|
||||
Keep in mind that, like with caching, it is not a good idea to change
|
||||
the contents of the remote filesystem
|
||||
out-of-band (https://en.wikipedia.org/wiki/Out-of-band).
|
||||
Meaning that you really shouldn\[cq]t change the contents of the
|
||||
underlying filesystems or mergerfs on the server hosting the remote
|
||||
filesystem.
|
||||
Doing so can lead to weird behavior, inconsistency, errors, and even
|
||||
data corruption should multiple programs try to write or read the same
|
||||
data at the same time.
|
||||
This isn\[cq]t to say you can\[cq]t do it or that data corruption is
|
||||
likely but it \f[I]could\f[R] happen.
|
||||
It is better to always use the remote filesystem.
|
||||
Even on the machine serving it.
|
||||
.SS NFS
|
||||
.PP
|
||||
NFS (https://en.wikipedia.org/wiki/Network_File_System) is a common
|
||||
remote filesystem on Unix/POSIX systems.
|
||||
Due to how NFS works there are some settings which need to be set in
|
||||
order for mergerfs to work with it.
|
||||
.PP
|
||||
It should be noted that NFS and FUSE (the technology mergerfs uses) do
|
||||
not work perfectly with one another due to certain design choices in
|
||||
FUSE (and mergerfs.) Due to these issues it is generally recommended to
|
||||
use SMB when possible till situations change.
|
||||
That said mergerfs should generally work as an export of NFS and issues
|
||||
discovered should still be reported.
|
||||
.PP
|
||||
To ensure compatibility between mergerfs and NFS use the following
|
||||
settings.
|
||||
.PP
|
||||
mergerfs settings: * noforget * inodecalc=path-hash
|
||||
.PP
|
||||
NFS export settings: * fsid=UUID * no_root_squash
|
||||
.PP
|
||||
\f[C]noforget\f[R] is needed because NFS uses the
|
||||
\f[C]name_to_handle_at\f[R] and \f[C]open_by_handle_at\f[R] functions
|
||||
which allow a program to keep a reference to a file without technically
|
||||
having it open in the typical sense.
|
||||
The problem is that FUSE has no way to know that NFS has a handle that
|
||||
it will later use to open the file again.
|
||||
As a result it is possible for the kernel to tell mergerfs to forget
|
||||
about the node and should NFS ever ask for that node\[cq]s details in
|
||||
the future it would have nothing to respond with.
|
||||
Keeping nodes around forever is not ideal but at the moment the only way
|
||||
to manage the situation.
|
||||
.PP
|
||||
\f[C]inodecalc=path-hash\f[R] is needed because NFS is sensitive to
|
||||
out-of-band changes.
|
||||
FUSE doesn\[cq]t care if a file\[cq]s inode value changes but NFS, being
|
||||
stateful, does.
|
||||
So if you used the default inode calculation algorithm then it is
|
||||
possible that if you changed a file or updated a directory the file
|
||||
mergerfs will use will be on a different branch and therefore the inode
|
||||
would change.
|
||||
This isn\[cq]t an ideal solution and others are being considered but it
|
||||
works for most situations.
|
||||
.PP
|
||||
\f[C]fsid=UUID\f[R] is needed because FUSE filesystems don\[cq]t have
|
||||
different \f[C]st_dev\f[R] values which can cause issues when exporting.
|
||||
The easiest thing to do is set each mergerfs export \f[C]fsid\f[R] to
|
||||
some random value.
|
||||
An easy way to generate a random value is to use the command line tool
|
||||
\f[C]uuid\f[R] or \f[C]uuidgen\f[R] or through a website such as
|
||||
uuidgenerator.net (https://www.uuidgenerator.net/).
|
||||
.PP
|
||||
\f[C]no_root_squash\f[R] is not strictly necessary but can lead to
|
||||
confusing permission and ownership issues if root squashing is enabled.
|
||||
.SS SMB / CIFS
|
||||
.PP
|
||||
SMB (https://en.wikipedia.org/wiki/Server_Message_Block) is a protocol
|
||||
most used by Microsoft Windows systems to share file shares, printers,
|
||||
etc.
|
||||
However, due to the popularity for Windows, it is also supported on many
|
||||
other platforms including Linux.
|
||||
The most popular way of supporting SMB on Linux is via the software
|
||||
Samba.
|
||||
.PP
|
||||
Samba (https://en.wikipedia.org/wiki/Samba_(software)), and other ways
|
||||
of serving Linux filesystems, via SMB should work fine with mergerfs.
|
||||
The services do not tend to use the same technologies which NFS uses and
|
||||
therefore don\[cq]t have the same issues.
|
||||
There should not be an special settings required to use mergerfs with
|
||||
Samba.
|
||||
However, CIFSD (https://en.wikipedia.org/wiki/CIFSD) and other programs
|
||||
have not been extensively tested.
|
||||
If you use mergerfs with CIFSD or other SMB servers please submit your
|
||||
experiences so these docs can be updated.
|
||||
.SS SSHFS
|
||||
.PP
|
||||
SSHFS (https://en.wikipedia.org/wiki/SSHFS) is a FUSE filesystem
|
||||
leveraging SSH as the connection and transport layer.
|
||||
While often simpler to setup when compared to NFS or Samba the
|
||||
performance can be lacking and the project is very much in maintenance
|
||||
mode.
|
||||
.PP
|
||||
There are no known issues using sshfs with mergerfs.
|
||||
You may want to use the following arguments to improve performance but
|
||||
your millage may vary.
|
||||
.IP \[bu] 2
|
||||
\f[C]-o Ciphers=arcfour\f[R]
|
||||
.IP \[bu] 2
|
||||
\f[C]-o Compression=no\f[R]
|
||||
.PP
|
||||
More info can be found
|
||||
here (https://ideatrash.net/2016/08/odds-and-ends-optimizing-sshfs-moving.html).
|
||||
.SS Other
|
||||
.PP
|
||||
There are other remote filesystems but none popularly used to serve
|
||||
mergerfs.
|
||||
If you use something not listed above feel free to reach out and I will
|
||||
add it to the list.
|
||||
.SH FAQ
|
||||
.SS How well does mergerfs scale? Is it \[lq]production ready?\[rq]
|
||||
.PP
|
||||
@@ -2326,17 +2699,50 @@ All of which are fixed in stable releases.
|
||||
.SS Can mergerfs be used with filesystems which already have data / are in use?
|
||||
.PP
|
||||
Yes.
|
||||
MergerFS is a proxy and does \f[B]NOT\f[R] interfere with the normal
|
||||
form or function of the filesystems / mounts / paths it manages.
|
||||
mergerfs is really just a proxy and does \f[B]NOT\f[R] interfere with
|
||||
the normal form or function of the filesystems / mounts / paths it
|
||||
manages.
|
||||
It is just another userland application that is acting as a
|
||||
man-in-the-middle.
|
||||
It can\[cq]t do anything that any other random piece of software
|
||||
can\[cq]t do.
|
||||
.PP
|
||||
MergerFS is \f[B]not\f[R] a traditional filesystem.
|
||||
MergerFS is \f[B]not\f[R] RAID.
|
||||
mergerfs is \f[B]not\f[R] a traditional filesystem that takes control
|
||||
over the underlying block device.
|
||||
mergerfs is \f[B]not\f[R] RAID.
|
||||
It does \f[B]not\f[R] manipulate the data that passes through it.
|
||||
It does \f[B]not\f[R] shard data across filesystems.
|
||||
It merely shards some \f[B]behavior\f[R] and aggregates others.
|
||||
.SS Can drives/filesystems be removed from the pool at will?
|
||||
.PP
|
||||
Yes.
|
||||
See previous question\[cq]s answer.
|
||||
.SS Can mergerfs be removed without affecting the data?
|
||||
.PP
|
||||
Yes.
|
||||
See the previous question\[cq]s answer.
|
||||
.SS Can drives/filesystems be moved to another pool?
|
||||
.PP
|
||||
Yes.
|
||||
See the previous question\[cq]s answer.
|
||||
.SS How do I migrate data into or out of the pool when adding/removing drives/filesystems?
|
||||
.PP
|
||||
You don\[cq]t need to.
|
||||
See the previous question\[cq]s answer.
|
||||
.SS How do I remove a drive/filesystem but keep the data in the pool?
|
||||
.PP
|
||||
Nothing special needs to be done.
|
||||
Remove the branch from mergerfs\[cq] config and copy (rsync) the data
|
||||
from the removed filesystem into the pool.
|
||||
Effectively the same as if it were you transfering data from one
|
||||
filesystem to another.
|
||||
.PP
|
||||
If you wish to continue using the pool while performing the transfer
|
||||
simply create another, temporary pool without the filesystem in question
|
||||
and then copy the data.
|
||||
It would probably be a good idea to set the branch to \f[C]RO\f[R] prior
|
||||
to doing this to ensure no new content is written to the filesystem
|
||||
while performing the copy.
|
||||
.SS What policies should I use?
|
||||
.PP
|
||||
Unless you\[cq]re doing something more niche the average user is
|
||||
@@ -2410,7 +2816,9 @@ Anything, files or directories, created in that first directory will be
|
||||
placed on the same branch because it is preserving paths.
|
||||
.PP
|
||||
This catches a lot of new users off guard but changing the default would
|
||||
break the setup for many existing users.
|
||||
break the setup for many existing users and this policy is the safest
|
||||
policy as it will not change the general layout of the existing
|
||||
filesystems.
|
||||
If you do not care about path preservation and wish your files to be
|
||||
spread across all your filesystems change to \f[C]mfs\f[R] or similar
|
||||
policy as described above.
|
||||
@@ -2440,6 +2848,16 @@ considered different devices.
|
||||
There is no way to link between them.
|
||||
You should mount in the highest directory in the mergerfs pool that
|
||||
includes all the paths you need if you want links to work.
|
||||
.SS Does FICLONE or FICLONERANGE work?
|
||||
.PP
|
||||
Unfortunately not.
|
||||
FUSE, the technology mergerfs is based on, does not support the
|
||||
\f[C]clone_file_range\f[R] feature needed for it to work.
|
||||
mergerfs won\[cq]t even know such a request is made.
|
||||
The kernel will simply return an error back to the application making
|
||||
the request.
|
||||
.PP
|
||||
Should FUSE gain the ability mergerfs will be updated to support it.
|
||||
.SS Can I use mergerfs without SnapRAID? SnapRAID without mergerfs?
|
||||
.PP
|
||||
Yes.
|
||||
@@ -2503,8 +2921,8 @@ executable bit set.
|
||||
A common mistake by users new to Linux is to \f[C]chmod -R 644\f[R] when
|
||||
they should have \f[C]chmod -R u=rwX,go=rX\f[R].
|
||||
.PP
|
||||
If using a network filesystem such as NFS, SMB, CIFS (Samba) be sure to
|
||||
pay close attention to anything regarding permissioning and users.
|
||||
If using a network filesystem such as NFS or SMB (Samba) be sure to pay
|
||||
close attention to anything regarding permissioning and users.
|
||||
Root squashing and user translation for instance has bitten a few
|
||||
mergerfs users.
|
||||
Some of these also affect the use of mergerfs from container platforms
|
||||
@@ -2563,93 +2981,6 @@ best provide equivalent performance and in cases worse performance.
|
||||
Splice is not supported on other platforms forcing a traditional
|
||||
read/write fallback to be provided.
|
||||
The splice code was removed to simplify the codebase.
|
||||
.SS Why use mergerfs over mhddfs?
|
||||
.PP
|
||||
mhddfs is no longer maintained and has some known stability and security
|
||||
issues (see below).
|
||||
MergerFS provides a superset of mhddfs\[cq] features and should offer
|
||||
the same or maybe better performance.
|
||||
.PP
|
||||
Below is an example of mhddfs and mergerfs setup to work similarly.
|
||||
.PP
|
||||
\f[C]mhddfs -o mlimit=4G,allow_other /mnt/drive1,/mnt/drive2 /mnt/pool\f[R]
|
||||
.PP
|
||||
\f[C]mergerfs -o minfreespace=4G,category.create=ff /mnt/drive1:/mnt/drive2 /mnt/pool\f[R]
|
||||
.SS Why use mergerfs over aufs?
|
||||
.PP
|
||||
aufs is mostly abandoned and no longer available in many distros.
|
||||
.PP
|
||||
While aufs can offer better peak performance mergerfs provides more
|
||||
configurability and is generally easier to use.
|
||||
mergerfs however does not offer the overlay / copy-on-write (CoW)
|
||||
features which aufs and overlayfs have.
|
||||
.SS Why use mergerfs over unionfs?
|
||||
.PP
|
||||
UnionFS is more like aufs than mergerfs in that it offers overlay / CoW
|
||||
features.
|
||||
If you\[cq]re just looking to create a union of filesystems and want
|
||||
flexibility in file/directory placement then mergerfs offers that
|
||||
whereas unionfs is more for overlaying RW filesystems over RO ones.
|
||||
.SS Why use mergerfs over overlayfs?
|
||||
.PP
|
||||
Same reasons as with unionfs.
|
||||
.SS Why use mergerfs over LVM/ZFS/BTRFS/RAID0 drive concatenation / striping?
|
||||
.PP
|
||||
With simple JBOD / drive concatenation / stripping / RAID0 a single
|
||||
drive failure will result in full pool failure.
|
||||
mergerfs performs a similar function without the possibility of
|
||||
catastrophic failure and the difficulties in recovery.
|
||||
Drives may fail, however, all other data will continue to be accessible.
|
||||
.PP
|
||||
When combined with something like SnapRaid (http://www.snapraid.it)
|
||||
and/or an offsite backup solution you can have the flexibility of JBOD
|
||||
without the single point of failure.
|
||||
.SS Why use mergerfs over ZFS?
|
||||
.PP
|
||||
MergerFS is not intended to be a replacement for ZFS.
|
||||
MergerFS is intended to provide flexible pooling of arbitrary
|
||||
filesystems (local or remote), of arbitrary sizes, and arbitrary
|
||||
filesystems.
|
||||
For \f[C]write once, read many\f[R] usecases such as bulk media storage.
|
||||
Where data integrity and backup is managed in other ways.
|
||||
In that situation ZFS can introduce a number of costs and limitations as
|
||||
described
|
||||
here (http://louwrentius.com/the-hidden-cost-of-using-zfs-for-your-home-nas.html),
|
||||
here (https://markmcb.com/2020/01/07/five-years-of-btrfs/), and
|
||||
here (https://utcc.utoronto.ca/~cks/space/blog/solaris/ZFSWhyNoRealReshaping).
|
||||
.SS Why use mergerfs over UnRAID?
|
||||
.PP
|
||||
UnRAID is a full OS and its storage layer, as I understand, is
|
||||
proprietary and closed source.
|
||||
Users who have experience with both have said they prefer the
|
||||
flexibility offered by mergerfs and for some the fact it is free and
|
||||
open source is important.
|
||||
.PP
|
||||
There are a number of UnRAID users who use mergerfs as well though
|
||||
I\[cq]m not entirely familiar with the use case.
|
||||
.SS Why use mergerfs over StableBit\[cq]s DrivePool?
|
||||
.PP
|
||||
DrivePool works only on Windows so not as common an alternative as other
|
||||
Linux solutions.
|
||||
If you want to use Windows then DrivePool is a good option.
|
||||
Functionally the two projects work a bit differently.
|
||||
DrivePool always writes to the filesystem with the most free space and
|
||||
later rebalances.
|
||||
mergerfs does not offer rebalance but chooses a branch at file/directory
|
||||
create time.
|
||||
DrivePool\[cq]s rebalancing can be done differently in any directory and
|
||||
has file pattern matching to further customize the behavior.
|
||||
mergerfs, not having rebalancing does not have these features, but
|
||||
similar features are planned for mergerfs v3.
|
||||
DrivePool has builtin file duplication which mergerfs does not natively
|
||||
support (but can be done via an external script.)
|
||||
.PP
|
||||
There are a lot of misc differences between the two projects but most
|
||||
features in DrivePool can be replicated with external tools in
|
||||
combination with mergerfs.
|
||||
.PP
|
||||
Additionally DrivePool is a closed source commercial product vs mergerfs
|
||||
a ISC licensed OSS project.
|
||||
.SS What should mergerfs NOT be used for?
|
||||
.IP \[bu] 2
|
||||
databases: Even if the database stored data in separate files (mergerfs
|
||||
@@ -2716,33 +3047,14 @@ mergerfs uses available space for statfs calculations.
|
||||
If you\[cq]ve reserved space for root then it won\[cq]t show up.
|
||||
.PP
|
||||
You can remove the reserve by running: \f[C]tune2fs -m 0 <device>\f[R]
|
||||
.SS Can mergerfs mounts be exported over NFS?
|
||||
.PP
|
||||
Yes, however if you do anything which may changes files out of band
|
||||
(including for example using the \f[C]newest\f[R] policy) it will result
|
||||
in \[lq]stale file handle\[rq] errors unless properly setup.
|
||||
.PP
|
||||
Be sure to use the following options:
|
||||
.IP \[bu] 2
|
||||
noforget
|
||||
.IP \[bu] 2
|
||||
inodecalc=path-hash
|
||||
.SS Can mergerfs mounts be exported over Samba / SMB?
|
||||
.PP
|
||||
Yes.
|
||||
While some users have reported problems it appears to always be related
|
||||
to how Samba is setup in relation to permissions.
|
||||
.SS Can mergerfs mounts be used over SSHFS?
|
||||
.PP
|
||||
Yes.
|
||||
.SS I notice massive slowdowns of writes when enabling cache.files.
|
||||
.PP
|
||||
When file caching is enabled in any form (\f[C]cache.files!=off\f[R] or
|
||||
\f[C]direct_io=false\f[R]) it will issue \f[C]getxattr\f[R] requests for
|
||||
\f[C]security.capability\f[R] prior to \f[I]every single write\f[R].
|
||||
When file caching is enabled in any form (\f[C]cache.files!=off\f[R]) it
|
||||
will issue \f[C]getxattr\f[R] requests for \f[C]security.capability\f[R]
|
||||
prior to \f[I]every single write\f[R].
|
||||
This will usually result in a performance degradation, especially when
|
||||
using a network filesystem (such as NFS or CIFS/SMB/Samba.)
|
||||
Unfortunately at this moment the kernel is not caching the response.
|
||||
using a network filesystem (such as NFS or SMB.) Unfortunately at this
|
||||
moment the kernel is not caching the response.
|
||||
.PP
|
||||
To work around this situation mergerfs offers a few solutions.
|
||||
.IP "1." 3
|
||||
@@ -2805,6 +3117,108 @@ If the ability to give writers priority is supported then that flag will
|
||||
be used so threads trying to change credentials don\[cq]t starve.
|
||||
This isn\[cq]t the best solution but should work reasonably well
|
||||
assuming there are few users.
|
||||
.SH mergerfs versus X
|
||||
.SS mhddfs
|
||||
.PP
|
||||
mhddfs had not been maintained for some time and has some known
|
||||
stability and security issues.
|
||||
mergerfs provides a superset of mhddfs\[cq] features and should offer
|
||||
the same or better performance.
|
||||
.PP
|
||||
Below is an example of mhddfs and mergerfs setup to work similarly.
|
||||
.PP
|
||||
\f[C]mhddfs -o mlimit=4G,allow_other /mnt/drive1,/mnt/drive2 /mnt/pool\f[R]
|
||||
.PP
|
||||
\f[C]mergerfs -o minfreespace=4G,category.create=ff /mnt/drive1:/mnt/drive2 /mnt/pool\f[R]
|
||||
.SS aufs
|
||||
.PP
|
||||
aufs is mostly abandoned and no longer available in most Linux distros.
|
||||
.PP
|
||||
While aufs can offer better peak performance mergerfs provides more
|
||||
configurability and is generally easier to use.
|
||||
mergerfs however does not offer the overlay / copy-on-write (CoW)
|
||||
features which aufs has.
|
||||
.SS unionfs-fuse
|
||||
.PP
|
||||
unionfs-fuse is more like aufs than mergerfs in that it offers overlay /
|
||||
copy-on-write (CoW) features.
|
||||
If you\[cq]re just looking to create a union of filesystems and want
|
||||
flexibility in file/directory placement then mergerfs offers that
|
||||
whereas unionfs is more for overlaying read/write filesystems over
|
||||
read-only ones.
|
||||
.SS overlayfs
|
||||
.PP
|
||||
overlayfs is similar to aufs and unionfs-fuse in that it also is
|
||||
primarily used to layer a read/write filesystem over one or more
|
||||
read-only filesystems.
|
||||
It does not have the ability to spread files/directories across numerous
|
||||
filesystems.
|
||||
.SS RAID0, JBOD, drive concatenation, striping
|
||||
.PP
|
||||
With simple JBOD / drive concatenation / stripping / RAID0 a single
|
||||
drive failure will result in full pool failure.
|
||||
mergerfs performs a similar function without the possibility of
|
||||
catastrophic failure and the difficulties in recovery.
|
||||
Drives may fail but all other filesystems and their data will continue
|
||||
to be accessible.
|
||||
.PP
|
||||
The main practical difference with mergerfs is the fact you don\[cq]t
|
||||
actually have contiguous space as large as if you used those other
|
||||
technologies.
|
||||
Meaning you can\[cq]t create a 2TB file on a pool of 2 1TB filesystems.
|
||||
.PP
|
||||
When combined with something like SnapRaid (http://www.snapraid.it)
|
||||
and/or an offsite backup solution you can have the flexibility of JBOD
|
||||
without the single point of failure.
|
||||
.SS UnRAID
|
||||
.PP
|
||||
UnRAID is a full OS and its storage layer, as I understand, is
|
||||
proprietary and closed source.
|
||||
Users who have experience with both have often said they prefer the
|
||||
flexibility offered by mergerfs and for some the fact it is open source
|
||||
is important.
|
||||
.PP
|
||||
There are a number of UnRAID users who use mergerfs as well though
|
||||
I\[cq]m not entirely familiar with the use case.
|
||||
.PP
|
||||
For semi-static data mergerfs + SnapRaid (http://www.snapraid.it)
|
||||
provides a similar solution.
|
||||
.SS ZFS
|
||||
.PP
|
||||
mergerfs is very different from ZFS.
|
||||
mergerfs is intended to provide flexible pooling of arbitrary
|
||||
filesystems (local or remote), of arbitrary sizes, and arbitrary
|
||||
filesystems.
|
||||
For \f[C]write once, read many\f[R] usecases such as bulk media storage.
|
||||
Where data integrity and backup is managed in other ways.
|
||||
In those usecases ZFS can introduce a number of costs and limitations as
|
||||
described
|
||||
here (http://louwrentius.com/the-hidden-cost-of-using-zfs-for-your-home-nas.html),
|
||||
here (https://markmcb.com/2020/01/07/five-years-of-btrfs/), and
|
||||
here (https://utcc.utoronto.ca/~cks/space/blog/solaris/ZFSWhyNoRealReshaping).
|
||||
.SS StableBit\[cq]s DrivePool
|
||||
.PP
|
||||
DrivePool works only on Windows so not as common an alternative as other
|
||||
Linux solutions.
|
||||
If you want to use Windows then DrivePool is a good option.
|
||||
Functionally the two projects work a bit differently.
|
||||
DrivePool always writes to the filesystem with the most free space and
|
||||
later rebalances.
|
||||
mergerfs does not offer rebalance but chooses a branch at file/directory
|
||||
create time.
|
||||
DrivePool\[cq]s rebalancing can be done differently in any directory and
|
||||
has file pattern matching to further customize the behavior.
|
||||
mergerfs, not having rebalancing does not have these features, but
|
||||
similar features are planned for mergerfs v3.
|
||||
DrivePool has builtin file duplication which mergerfs does not natively
|
||||
support (but can be done via an external script.)
|
||||
.PP
|
||||
There are a lot of misc differences between the two projects but most
|
||||
features in DrivePool can be replicated with external tools in
|
||||
combination with mergerfs.
|
||||
.PP
|
||||
Additionally DrivePool is a closed source commercial product vs mergerfs
|
||||
a ISC licensed OSS project.
|
||||
.SH SUPPORT
|
||||
.PP
|
||||
Filesystems are complex and difficult to debug.
|
||||
|
||||
@@ -35,6 +35,7 @@ make install PREFIX=%{_prefix} DESTDIR=%{buildroot}
|
||||
/usr/bin/mergerfs
|
||||
/usr/bin/mergerfs-fusermount
|
||||
/sbin/mount.mergerfs
|
||||
/usr/lib/mergerfs/preload.so
|
||||
%doc %{_mandir}/*
|
||||
|
||||
%changelog
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
# mkdocs
|
||||
|
||||
## Getting started
|
||||
|
||||
```bash
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate
|
||||
pip3 install --no-cache-dir mkdocs mkdocs-material pymdown-extensions
|
||||
mkdocs serve
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
* https://www.mkdocs.org/
|
||||
* https://squidfunk.github.io/mkdocs-material/
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
# Benchmarking
|
||||
|
||||
Filesystems are complicated. They do many things and many of those are
|
||||
interconnected. Additionally, the OS, drivers, hardware, etc. can all
|
||||
impact performance. Therefore, when benchmarking, it is **necessary**
|
||||
that the test focuses as narrowly as possible.
|
||||
|
||||
For most throughput is the key benchmark. To test throughput `dd` is
|
||||
useful but **must** be used with the correct settings in order to
|
||||
ensure the filesystem or device is actually being tested. The OS can
|
||||
and will cache data. Without forcing synchronous reads and writes
|
||||
and/or disabling caching the values returned will not be
|
||||
representative of the device's true performance.
|
||||
|
||||
When benchmarking through mergerfs ensure you only use 1 branch to
|
||||
remove any possibility of the policies complicating the
|
||||
situation. Benchmark the underlying filesystem first and then mount
|
||||
mergerfs over it and test again. If you're experiencing speeds below
|
||||
your expectation you will need to narrow down precisely which
|
||||
component is leading to the slowdown. Preferably test the following in
|
||||
the order listed (but not combined).
|
||||
|
||||
1. Enable `nullrw` mode with `nullrw=true`. This will effectively make
|
||||
reads and writes no-ops. Removing the underlying device /
|
||||
filesystem from the equation. This will give us the top theoretical
|
||||
speeds.
|
||||
2. Mount mergerfs over `tmpfs`. `tmpfs` is a RAM disk. Extremely high
|
||||
speed and very low latency. This is a more realistic best case
|
||||
scenario. Example: `mount -t tmpfs -o size=2G tmpfs /tmp/tmpfs`
|
||||
3. Mount mergerfs over a local device. NVMe, SSD, HDD, etc. If you
|
||||
have more than one I'd suggest testing each of them as drives
|
||||
and/or controllers (their drivers) could impact performance.
|
||||
4. Finally, if you intend to use mergerfs with a network filesystem,
|
||||
either as the source of data or to combine with another through
|
||||
mergerfs, test each of those alone as above.
|
||||
|
||||
Once you find the component which has the performance issue you can do
|
||||
further testing with different options to see if they impact
|
||||
performance. For reads and writes the most relevant would be:
|
||||
`cache.files`, `async_read`. Less likely but relevant when using NFS
|
||||
or with certain filesystems would be `security_capability`, `xattr`,
|
||||
and `posix_acl`. If you find a specific system, device, filesystem,
|
||||
controller, etc. that performs poorly contact trapexit so he may
|
||||
investigate further.
|
||||
|
||||
Sometimes the problem is really the application accessing or writing
|
||||
data through mergerfs. Some software use small buffer sizes which can
|
||||
lead to more requests and therefore greater overhead. You can test
|
||||
this out yourself by replacing `bs=1M` in the examples below with `ibs`
|
||||
or `obs` and using a size of `512` instead of `1M`. In one example
|
||||
test using `nullrw` the write speed dropped from 4.9GB/s to 69.7MB/s
|
||||
when moving from `1M` to `512`. Similar results were had when testing
|
||||
reads. Small writes overhead may be improved by leveraging a write
|
||||
cache but in casual tests little gain was found. More tests will need
|
||||
to be done before this feature would become available. If you have an
|
||||
app that appears slow with mergerfs it could be due to this. Contact
|
||||
trapexit so he may investigate further.
|
||||
|
||||
### write benchmark
|
||||
|
||||
```
|
||||
$ dd if=/dev/zero of=/mnt/mergerfs/1GB.file bs=1M count=1024 oflag=nocache conv=fdatasync status=progress
|
||||
```
|
||||
|
||||
### read benchmark
|
||||
|
||||
```
|
||||
$ dd if=/mnt/mergerfs/1GB.file of=/dev/null bs=1M count=1024 iflag=nocache conv=fdatasync status=progress
|
||||
```
|
||||
|
||||
### other benchmarks
|
||||
|
||||
If you are attempting to benchmark other behaviors you must ensure you
|
||||
clear kernel caches before runs. In fact it would be a good deal to
|
||||
run before the read and write benchmarks as well just in case.
|
||||
|
||||
```
|
||||
sync
|
||||
echo 3 | sudo tee /proc/sys/vm/drop_caches
|
||||
```
|
||||
@@ -0,0 +1,54 @@
|
||||
# branches
|
||||
|
||||
The 'branches' argument is a colon (':') delimited list of paths to be
|
||||
pooled together. It does not matter if the paths are on the same or
|
||||
different filesystems nor does it matter the filesystem type (within
|
||||
reason). Used and available space will not be duplicated for paths on
|
||||
the same filesystem and any features which aren't supported by the
|
||||
underlying filesystem (such as file attributes or extended attributes)
|
||||
will return the appropriate errors.
|
||||
|
||||
Branches currently have two options which can be set. A type which
|
||||
impacts whether or not the branch is included in a policy calculation
|
||||
and a individual minfreespace value. The values are set by prepending
|
||||
an `=` at the end of a branch designation and using commas as
|
||||
delimiters. Example: `/mnt/drive=RW,1234`
|
||||
|
||||
### branch mode
|
||||
|
||||
- RW: (read/write) - Default behavior. Will be eligible in all policy
|
||||
categories.
|
||||
- RO: (read-only) - Will be excluded from `create` and `action`
|
||||
policies. Same as a read-only mounted filesystem would be (though
|
||||
faster to process).
|
||||
- NC: (no-create) - Will be excluded from `create` policies. You can't
|
||||
create on that branch but you can change or delete.
|
||||
|
||||
### minfreespace
|
||||
|
||||
Same purpose and syntax as the global option but specific to the
|
||||
branch. If not set the global value is used.
|
||||
|
||||
### globbing
|
||||
|
||||
To make it easier to include multiple branches mergerfs supports
|
||||
[globbing](http://linux.die.net/man/7/glob). **The globbing tokens
|
||||
MUST be escaped when using via the shell else the shell itself will
|
||||
apply the glob itself.**
|
||||
|
||||
```
|
||||
# mergerfs /mnt/hdd\*:/mnt/ssd /media
|
||||
```
|
||||
|
||||
The above line will use all mount points in /mnt prefixed with **hdd**
|
||||
and **ssd**.
|
||||
|
||||
To have the pool mounted at boot or otherwise accessible from related
|
||||
tools use `/etc/fstab`.
|
||||
|
||||
```
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
/mnt/hdd*:/mnt/ssd /media mergerfs minfreespace=16G 0 0
|
||||
```
|
||||
|
||||
**NOTE:** The globbing is done at mount or when updated using the runtime API. If a new directory is added matching the glob after the fact it will not be automatically included.
|
||||
@@ -0,0 +1,187 @@
|
||||
# caching
|
||||
|
||||
## cache.files
|
||||
|
||||
Controls how [page caching](https://en.wikipedia.org/wiki/Page_cache)
|
||||
works for mergerfs itself. Not the underlying filesystems.
|
||||
|
||||
* `cache.files=off`: Disables page caching for mergerfs.
|
||||
* `cache.files=partial`: Enables page caching. Files are cached
|
||||
while open.
|
||||
* `cache.files=full`: Enables page caching. Files are cached across
|
||||
opens.
|
||||
* `cache.files=auto-full`: Enables page caching. Files are cached
|
||||
across opens if mtime and size are unchanged since previous open.
|
||||
* `cache.files=per-process`: Enable page caching (equivalent to
|
||||
`cache.files=partial`) only for processes whose 'comm' name matches
|
||||
one of the values defined in cache.files.process-names. If the name
|
||||
does not match the file open is equivalent to `cache.files=off`.
|
||||
|
||||
|
||||
Generally, enabling the page cache actually *harms*
|
||||
performance[^1]. In part because it can lead to buffer bloat due to
|
||||
the kernel caching both the underlying filesystem's file content as
|
||||
well as the file through mergerfs. However, if you want to confirm
|
||||
performance differences it is recommended that you perform some
|
||||
benchmark to confirm which option works best for your setup.
|
||||
|
||||
Why then would you want to enable page caching if it consumes ~2x the
|
||||
RAM as normal and is on average slower? Because it is the only way to
|
||||
support
|
||||
[mmap](https://man7.org/linux/man-pages/man2/mmap.2.html). `mmap` is a
|
||||
way for programs to treat a file as if it is a contiguous RAM buffer
|
||||
which is regularly used by a number of programs such as those that
|
||||
leverage **sqlite3**. Despite `mmap` not being supported by all
|
||||
filesystems it is unfortunately common for software to not have an
|
||||
option to use regular file IO instead of `mmap`.
|
||||
|
||||
The good thing is that in Linux v6.6[^2] and above FUSE can now
|
||||
transparently enable page caching when mmap is requested. This means
|
||||
it should be safe to set `cache.files=off`. However, on Linux v6.5 and
|
||||
below you will need to configure `cache.files` as you need.
|
||||
|
||||
|
||||
[^1]: This is not unique to mergerfs and affects all FUSE
|
||||
filesystems. It is something that the FUSE community hopes to
|
||||
investigate at some point but as of early 2025 there are a number
|
||||
of major reworking going on with FUSE which needs to be finished
|
||||
first.
|
||||
[^2]: [https://kernelnewbies.org/Linux_6.6#FUSE](https://kernelnewbies.org/Linux_6.6#FUSE)
|
||||
|
||||
|
||||
## cache.entry
|
||||
|
||||
* `cache.entry=UINT`: Sets the number of seconds to cache
|
||||
entry queries. Defaults to `1`.
|
||||
|
||||
The kernel must ask mergerfs about the existence of files. The entry
|
||||
cache caches that those details which limits the number of requests
|
||||
sent to mergerfs.
|
||||
|
||||
The risk of setting this value, as with most any cache, is related to
|
||||
[out-of-band](https://en.wikipedia.org/wiki/Out-of-band) changes. If
|
||||
the filesystems are changed outside mergerfs there is a risk of files
|
||||
which have been removed continuing to show as available. It will fail
|
||||
gracefully if a phantom file is actioned on in some way so there is
|
||||
little risk in setting the value much higher. Especially if there are
|
||||
no out-of-band changes.
|
||||
|
||||
|
||||
## cache.negative_entry
|
||||
|
||||
* `cache.negative_entry=UINT`: Sets the number of seconds to cache
|
||||
negative entry queries. Defaults to `1`.
|
||||
|
||||
This is a cache for negative entry query responses. Such as when a
|
||||
file which does not exist is referenced.
|
||||
|
||||
The risk of setting this value, as with most any cache, is related to
|
||||
[out-of-band](https://en.wikipedia.org/wiki/Out-of-band) changes. If
|
||||
the filesystems are changed outside mergerfs there is a risk of files
|
||||
which have been added outside mergerfs not appearing correctly till
|
||||
the cache entry times out if there had been a request for the same
|
||||
name within mergerfs which didn't exist. This is mostly an
|
||||
inconvenience.
|
||||
|
||||
|
||||
## cache.attr
|
||||
|
||||
* `cache.attr=UINT`: Sets the number of seconds to cache file
|
||||
attributes. Defaults to `1`.
|
||||
|
||||
This is a cache for file attributes and metadata such as that which is
|
||||
collected by the
|
||||
[stat](https://man7.org/linux/man-pages/man2/stat.2.html) system call
|
||||
which is used when you run commands such as `find` or `ls -lh`.
|
||||
|
||||
As with other caches the risk of enabling the attribute cache is if
|
||||
changes are made to the file out-of-band there could be
|
||||
inconsistencies between the actual file and the cached details which
|
||||
could result in different issues depending on how the data is used. If
|
||||
the simultaneous writing of a file from inside and outside is unlikely
|
||||
then you should be safe. That said any simultaneous, uncoordinated
|
||||
manipulation of a file can lead to unexpected results.
|
||||
|
||||
|
||||
## cache.statfs
|
||||
|
||||
* `cache.statfs=UINT`: Sets the number of seconds to cache `statfs`
|
||||
calls used by policies. Defaults to `0`.
|
||||
|
||||
A number of policies require looking up the available space of the
|
||||
branches being considered. This is accomplished by calling
|
||||
[statfs](https://man7.org/linux/man-pages/man2/statfs.2.html). This
|
||||
call however is a bit expensive so this cache reduces the overhead by
|
||||
limiting how often the calls are actually made.
|
||||
|
||||
This will mean that if the available space of branches changed
|
||||
somewhat rapidly there is a risk of `create` or `mkdir` calls made
|
||||
within the timeout period ending up on the same branch. This however
|
||||
should even itself out over time.
|
||||
|
||||
|
||||
## cache.symlinks
|
||||
|
||||
* `cache.symlinks=BOOL`: Enable kernel caching of symlink
|
||||
values. Defaults to `false`.
|
||||
|
||||
As of Linux v4.20 there is an ability to cache the value of symlinks
|
||||
so that the kernel does not need to make a request to mergerfs every
|
||||
single time a
|
||||
[readlink](https://man7.org/linux/man-pages/man2/readlink.2.html)
|
||||
request is made. While not a common usage pattern, if software very
|
||||
regularly queries symlink values, the use of this cache could
|
||||
significantly improve performance.
|
||||
|
||||
mergerfs will not error if the kernel used does not support symlink
|
||||
caching.
|
||||
|
||||
As with other caches the main risk in enabling it is if you are
|
||||
manipulating symlinks from both within and without the mergerfs
|
||||
mount. Should the value be changed outside of mergerfs then it will
|
||||
not be reflected in the mergerfs mount till the cached value is
|
||||
invalidated.
|
||||
|
||||
|
||||
## cache.readdir
|
||||
|
||||
* `cache.readdir=BOOL`: Enable kernel caching of readdir
|
||||
results. Defaults to `false`.
|
||||
|
||||
As of Linux v4.20 it supports readdir caching. This can have a
|
||||
significant impact on directory traversal. Especially when combined
|
||||
with entry (`cache.entry`) and attribute (`cache.attr`) caching. If
|
||||
the kernel doesn't support readdir caching setting the option to true
|
||||
has no effect. This option is configurable at runtime via xattr
|
||||
user.mergerfs.cache.readdir.
|
||||
|
||||
## cache.writeback
|
||||
|
||||
* `cache.writeback=BOOL`: Enable writeback cache. Defaults to `false`.
|
||||
|
||||
When `cache.files` is enabled the default is for it to perform
|
||||
writethrough caching. This behavior won't help improve performance as
|
||||
each write still goes one for one through the filesystem. By enabling
|
||||
the FUSE writeback cache small writes *may* be aggregated by the
|
||||
kernel and then sent to mergerfs as one larger request. This can
|
||||
greatly improve the throughput for apps which write to files
|
||||
inefficiently. The amount the kernel can aggregate is limited by the
|
||||
size of a FUSE message. Read the fuse_msg_size section for more
|
||||
details.
|
||||
|
||||
There is a side effect as a result of enabling writeback
|
||||
caching. Underlying files won't ever be opened with O_APPEND or
|
||||
O_WRONLY. The former because the kernel then manages append mode and
|
||||
the latter because the kernel may request file data from mergerfs to
|
||||
populate the write cache. The O_APPEND change means that if a file is
|
||||
changed outside of mergerfs it could lead to corruption as the kernel
|
||||
won't know the end of the file has changed. That said any time you use
|
||||
caching you should keep from writing to the same file outside of
|
||||
mergerfs at the same time.
|
||||
|
||||
Note that if an application is properly sizing writes then writeback
|
||||
caching will have little or no effect. It will only help with writes
|
||||
of sizes below the FUSE message size (128K on older kernels, 1M on
|
||||
newer). Even then its effectiveness might not be great. Given the side
|
||||
effects of enabling this feature it is recommended that its benefits
|
||||
be proved out with benchmarks.
|
||||
@@ -0,0 +1,21 @@
|
||||
# Deprecated Options
|
||||
|
||||
These are old, deprecated options which may no longer have any
|
||||
function or have been replaced.
|
||||
|
||||
* **direct_io**: Bypass page cache. Use `cache.files=off`
|
||||
instead.
|
||||
* **kernel_cache**: Do not invalidate data cache on file open. Use
|
||||
`cache.files=full` instead.
|
||||
* **auto_cache**: Invalidate data cache if file mtime or
|
||||
size change. Use `cache.files=auto-full` instead. (default: false)
|
||||
* **async_read**: Perform reads asynchronously. Use
|
||||
`async_read=true` instead.
|
||||
* **sync_read**: Perform reads synchronously. Use
|
||||
`async_read=false` instead.
|
||||
* **splice_read**: Does nothing.
|
||||
* **splice_write**: Does nothing.
|
||||
* **splice_move**: Does nothing.
|
||||
* **allow_other**: mergerfs v2.35.0 and above sets this FUSE option
|
||||
automatically if running as root.
|
||||
* **use_ino**: Effectively replaced with `inodecalc`.
|
||||
@@ -0,0 +1,14 @@
|
||||
# export-support
|
||||
|
||||
* `export-support=true|false`
|
||||
* Defaults to `true`.
|
||||
|
||||
In theory, this flag should not be exposed to the end user. It is a
|
||||
low-level FUSE flag which indicates whether or not the kernel can send
|
||||
certain kinds of messages to it for the purposes of using it with
|
||||
NFS. mergerfs does support these messages but due to bugs and quirks
|
||||
found in the kernel and mergerfs this option is provided just in case
|
||||
it is needed for debugging.
|
||||
|
||||
Given that this flag is set when the FUSE connection is first
|
||||
initiated it is not possible to change during run time.
|
||||
@@ -0,0 +1,21 @@
|
||||
# flush-on-close
|
||||
|
||||
By default, FUSE would issue a flush before the release of a file
|
||||
descriptor. This was considered a bit aggressive and a feature added
|
||||
to give the FUSE server the ability to choose when that happens.
|
||||
|
||||
* `flush-on-close=always`
|
||||
* `flush-on-close=never`
|
||||
* `flush-on-close=opened-for-write`
|
||||
* Defaults to `opened-for-write`.
|
||||
|
||||
For now it defaults to `opened-for-write` which is less aggressive
|
||||
than the behavior before this feature was added. It should not be a
|
||||
problem because the flush is really only relevant when a file is
|
||||
written to. Given flush is irrelevant for many filesystems in the
|
||||
future a branch specific flag may be added so only files opened on a
|
||||
specific branch would be flushed on close.
|
||||
|
||||
## References
|
||||
|
||||
* [https://lkml.kernel.org/linux-fsdevel/20211024132607.1636952-1-amir73il@gmail.com/T/](https://lkml.kernel.org/linux-fsdevel/20211024132607.1636952-1-amir73il@gmail.com/T/)
|
||||
@@ -0,0 +1,23 @@
|
||||
# follow-symlinks
|
||||
|
||||
This feature, when enabled, will cause symlinks to be interpreted by
|
||||
mergerfs as their target.
|
||||
|
||||
When there is a getattr/stat request for a file mergerfs will check if
|
||||
the file is a symlink and depending on the `follow-symlinks` setting
|
||||
will replace the information about the symlink with that of that which
|
||||
it points to.
|
||||
|
||||
When unlink'ing or rmdir'ing the followed symlink it will remove the
|
||||
symlink itself and not that which it points to.
|
||||
|
||||
* `follow-symlinks=never`: Behave as normal. Symlinks are treated as such.
|
||||
* `follow-symlinks=directory`: Resolve symlinks only which point to directories.
|
||||
* `follow-symlinks=regular`: Resolve symlinks only which point to regular files.
|
||||
* `follow-symlinks=all`: Resolve all symlinks to that which they point
|
||||
to. Symlinks which do not point to anything are left as is.
|
||||
* Defaults to `never`.
|
||||
|
||||
**WARNING:** This feature should be considered experimental. There
|
||||
might be edge cases yet found. If you find any odd behaviors please
|
||||
file a ticket on [github](https://github.com/trapexit/mergerfs/issues/new?assignees=&labels=bug%2C+investigating&projects=&template=bug_report.md&title=).
|
||||
@@ -0,0 +1,17 @@
|
||||
# func.readdir
|
||||
|
||||
examples: `func.readdir=seq`, `func.readdir=cor:4`
|
||||
|
||||
`readdir` has policies to control how it reads directory content.
|
||||
|
||||
| Policy | Description |
|
||||
| ------ | ----------- |
|
||||
| seq | "sequential" : Iterate sequentially over branches in the order defined in `branches`. This is the default and traditional behavior found prior to the readdir policy introduction. This will be increasingly slower as more branches are added to the pool. Especially if needing to wait for drives to spin up or network filesystems to respond. |
|
||||
| cosr | "concurrent open, sequential read" : Concurrently open branch directories using a thread pool and process them in the order defined in `branches`. This keeps memory and CPU usage low while also reducing the time spent waiting on branches to respond. Number of threads defaults to the number of logical cores. Can be overwritten via the syntax `func.readdir=cosr:N` where `N` is the number of threads. |
|
||||
| cor | "concurrent open and read" : Concurrently open branch directories and immediately start reading their contents using a thread pool. This will result in slightly higher memory and CPU usage but reduced latency. Particularly when using higher latency / slower speed network filesystem branches. Unlike `seq` and `cosr` the order of files could change due the async nature of the thread pool. This should not be a problem since the order of files listed in not guaranteed. Number of threads defaults to the number of logical cores. Can be overwritten via the syntax `func.readdir=cor:N` where `N` is the number of threads. |
|
||||
|
||||
Keep in mind that `readdir` mostly just provides a list of file names
|
||||
in a directory and possibly some basic metadata about said files. To
|
||||
know details about the files, as one would see from commands like
|
||||
`find` or `ls`, it is required to call `stat` on the file which is
|
||||
controlled by `fuse.getattr`.
|
||||
@@ -0,0 +1,139 @@
|
||||
# functions, categories and policies
|
||||
|
||||
The POSIX filesystem API is made up of a number of
|
||||
functions. **creat**, **stat**, **chown**, etc. For ease of
|
||||
configuration in mergerfs, most of the core functions are grouped into
|
||||
3 categories: **action**, **create**, and **search**. These functions
|
||||
and categories can be assigned a policy which dictates which branch is
|
||||
chosen when performing that function.
|
||||
|
||||
Some functions, listed in the category `N/A` below, can not be
|
||||
assigned the normal policies because they are directly related to a
|
||||
file which has already been opened.
|
||||
|
||||
When using policies which are based on a branch's available space the
|
||||
base path provided is used. Not the full path to the file in
|
||||
question. Meaning that mounts in the branch won't be considered in the
|
||||
space calculations. The reason is that it doesn't really work for
|
||||
non-path preserving policies and can lead to non-obvious behaviors.
|
||||
|
||||
NOTE: While any policy can be assigned to a function or category,
|
||||
some may not be very useful in practice. For instance: **rand**
|
||||
(random) may be useful for file creation (create) but could lead to
|
||||
very odd behavior if used for `chmod` if there were more than one copy
|
||||
of the file.
|
||||
|
||||
## Functions and their Category classifications
|
||||
|
||||
| Category | Functions |
|
||||
| -------- | --------- |
|
||||
| action | chmod, chown, link, removexattr, rename, rmdir, setxattr, truncate, unlink, utimens |
|
||||
| create | create, mkdir, mknod, symlink |
|
||||
| search | access, getattr, getxattr, ioctl (directories), listxattr, open, readlink |
|
||||
| N/A | fchmod, fchown, futimens, ftruncate, fallocate, fgetattr, fsync, ioctl (files), read, readdir, release, statfs, write, copy_file_range |
|
||||
|
||||
In cases where something may be searched for (such as a path to clone)
|
||||
**getattr** will usually be used.
|
||||
|
||||
## Policies
|
||||
|
||||
A policy is the algorithm used to choose a branch or branches for a
|
||||
function to work on or generally how the function behaves.
|
||||
|
||||
Any function in the `create` category will clone the relative path if
|
||||
needed. Some other functions (`rename`,`link`,`ioctl`) have special
|
||||
requirements or behaviors which you can read more about below.
|
||||
|
||||
## Filtering
|
||||
|
||||
Most policies basically search branches and create a list of files / paths
|
||||
for functions to work on. The policy is responsible for filtering and
|
||||
sorting the branches. Filters include **minfreespace**, whether or not
|
||||
a branch is mounted read-only, and the branch tagging
|
||||
(RO,NC,RW). These filters are applied across most policies.
|
||||
|
||||
- No **search** function policies filter.
|
||||
- All **action** function policies filter out branches which are
|
||||
mounted **read-only** or tagged as **RO (read-only)**.
|
||||
- All **create** function policies filter out branches which are
|
||||
mounted **read-only**, tagged **RO (read-only)** or **NC (no
|
||||
create)**, or has available space less than `minfreespace`.
|
||||
|
||||
Policies may have their own additional filtering such as those that
|
||||
require existing paths to be present.
|
||||
|
||||
If all branches are filtered an error will be returned. Typically
|
||||
**EROFS** (read-only filesystem) or **ENOSPC** (no space left on
|
||||
device) depending on the most recent reason for filtering a
|
||||
branch. **ENOENT** will be returned if no eligible branch is found.
|
||||
|
||||
If **create**, **mkdir**, **mknod**, or **symlink** fail with `EROFS`
|
||||
or other fundamental errors then mergerfs will mark any branch found
|
||||
to be read-only as such (IE will set the mode `RO`) and will rerun the
|
||||
policy and try again. This is mostly for `ext4` filesystems that can
|
||||
suddenly become read-only when it encounters an error.
|
||||
|
||||
## Path Preservation
|
||||
|
||||
Policies, as described below, are of two basic classifications. `path
|
||||
preserving` and `non-path preserving`.
|
||||
|
||||
All policies which start with `ep` (**epff**, **eplfs**, **eplus**,
|
||||
**epmfs**, **eprand**) are `path preserving`. `ep` stands for
|
||||
`existing path`.
|
||||
|
||||
A path preserving policy will only consider branches where the relative
|
||||
path being accessed already exists.
|
||||
|
||||
When using non-path preserving policies paths will be cloned to target
|
||||
branches as necessary.
|
||||
|
||||
With the `msp` or `most shared path` policies they are defined as
|
||||
`path preserving` for the purpose of controlling `link` and `rename`'s
|
||||
behaviors since `ignorepponrename` is available to disable that
|
||||
behavior.
|
||||
|
||||
## Policy descriptions
|
||||
|
||||
A policy's behavior differs, as mentioned above, based on the function
|
||||
it is used with. Sometimes it really might not make sense to even
|
||||
offer certain policies because they are literally the same as others
|
||||
but it makes things a bit more uniform.
|
||||
|
||||
| Policy | Description |
|
||||
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| all | Search: For **mkdir**, **mknod**, and **symlink** it will apply to all branches. **create** works like **ff**. |
|
||||
| epall (existing path, all) | For **mkdir**, **mknod**, and **symlink** it will apply to all found. **create** works like **epff** (but more expensive because it doesn't stop after finding a valid branch). |
|
||||
| epff (existing path, first found) | Given the order of the branches, as defined at mount time or configured at runtime, act on the first one found where the relative path exists. |
|
||||
| eplfs (existing path, least free space) | Of all the branches on which the relative path exists choose the branch with the least free space. |
|
||||
| eplus (existing path, least used space) | Of all the branches on which the relative path exists choose the branch with the least used space. |
|
||||
| epmfs (existing path, most free space) | Of all the branches on which the relative path exists choose the branch with the most free space. |
|
||||
| eppfrd (existing path, percentage free random distribution) | Like **pfrd** but limited to existing paths. |
|
||||
| eprand (existing path, random) | Calls **epall** and then randomizes. Returns 1. |
|
||||
| ff (first found) | Given the order of the branches, as defined at mount time or configured at runtime, act on the first one found. |
|
||||
| lfs (least free space) | Pick the branch with the least available free space. |
|
||||
| lus (least used space) | Pick the branch with the least used space. |
|
||||
| mfs (most free space) | Pick the branch with the most available free space. |
|
||||
| msplfs (most shared path, least free space) | Like **eplfs** but if it fails to find a branch it will try again with the parent directory. Continues this pattern till finding one. |
|
||||
| msplus (most shared path, least used space) | Like **eplus** but if it fails to find a branch it will try again with the parent directory. Continues this pattern till finding one. |
|
||||
| mspmfs (most shared path, most free space) | Like **epmfs** but if it fails to find a branch it will try again with the parent directory. Continues this pattern till finding one. |
|
||||
| msppfrd (most shared path, percentage free random distribution) | Like **eppfrd** but if it fails to find a branch it will try again with the parent directory. Continues this pattern till finding one. |
|
||||
| newest | Pick the file / directory with the largest mtime. |
|
||||
| pfrd (percentage free random distribution) | Chooses a branch at random with the likelihood of selection based on a branch's available space relative to the total. |
|
||||
| rand (random) | Calls **all** and then randomizes. Returns 1 branch. |
|
||||
|
||||
**NOTE:** If you are using an underlying filesystem that reserves
|
||||
blocks such as ext2, ext3, or ext4 be aware that mergerfs respects the
|
||||
reservation by using `f_bavail` (number of free blocks for
|
||||
unprivileged users) rather than `f_bfree` (number of free blocks) in
|
||||
policy calculations. **df** does NOT use `f_bavail`, it uses
|
||||
`f_bfree`, so direct comparisons between **df** output and mergerfs'
|
||||
policies is not appropriate.
|
||||
|
||||
## Defaults
|
||||
|
||||
| Category | Policy |
|
||||
| -------- | ------ |
|
||||
| action | epall |
|
||||
| create | epmfs |
|
||||
| search | ff |
|
||||
@@ -0,0 +1,29 @@
|
||||
# fuse_msg_size
|
||||
|
||||
* `fuse_msg_size=UINT`
|
||||
* Defaults to `256`
|
||||
|
||||
FUSE applications communicate with the kernel over a special character
|
||||
device: `/dev/fuse`. A large portion of the overhead associated with
|
||||
FUSE is the cost of going back and forth between user space and kernel
|
||||
space over that device. Generally speaking, the fewer trips needed the
|
||||
better the performance will be. Reducing the number of trips can be
|
||||
done a number of ways. Kernel level caching and increasing message
|
||||
sizes being two significant ones. When it comes to reads and writes if
|
||||
the message size is doubled the number of trips are approximately
|
||||
halved.
|
||||
|
||||
In Linux v4.20 a new feature was added allowing the negotiation of the
|
||||
max message size. Since the size is in multiples of
|
||||
[pages](https://en.wikipedia.org/wiki/Page_(computer_memory)) the
|
||||
feature is called `max_pages`. There is a maximum `max_pages` value of
|
||||
256 (1MiB) and minimum of 1 (4KiB). The default used by Linux >=4.20,
|
||||
and hardcoded value used before 4.20, is 32 (128KiB). In mergerfs it's
|
||||
referred to as fuse_msg_size to make it clear what it impacts and
|
||||
provide some abstraction.
|
||||
|
||||
Since there should be no downsides to increasing `fuse_msg_size`,
|
||||
outside a minor increase in RAM usage due to larger message buffers,
|
||||
mergerfs defaults the value to 256. On kernels before v4.20 the value
|
||||
has no effect. The reason the value is configurable is to enable
|
||||
experimentation and benchmarking.
|
||||
@@ -0,0 +1,75 @@
|
||||
# inodecalc
|
||||
|
||||
Inodes (`st_ino`) are unique identifiers within a filesystem. Each
|
||||
mounted filesystem has device ID (st_dev) as well and together they
|
||||
can uniquely identify a file on the whole of the system. Entries on
|
||||
the same device with the same inode are in fact references to the same
|
||||
underlying file. It is a many to one relationship between names and an
|
||||
inode. Directories, however, do not have multiple links on most
|
||||
systems due to the complexity they add.
|
||||
|
||||
FUSE allows the server (mergerfs) to set inode values but not device
|
||||
IDs. Creating an inode value is somewhat complex in mergerfs' case as
|
||||
files aren't really in its control. If a policy changes what directory
|
||||
or file is to be selected or something changes out of band it becomes
|
||||
unclear what value should be used. Most software does not to care what
|
||||
the values are but those that do often break if a value changes
|
||||
unexpectedly. The tool find will abort a directory walk if it sees a
|
||||
directory inode change. NFS can return stale handle errors if the
|
||||
inode changes out of band. File dedup tools will usually leverage
|
||||
device ids and inodes as a shortcut in searching for duplicate files
|
||||
and would resort to full file comparisons should it find different
|
||||
inode values.
|
||||
|
||||
mergerfs offers multiple ways to calculate the inode in hopes of
|
||||
covering different usecases.
|
||||
|
||||
* `passthrough`: Passes through the underlying inode value. Mostly
|
||||
intended for testing as using this does not address any of the
|
||||
problems mentioned above and could confuse file deduplication
|
||||
software as inodes from different filesystems can be the same.
|
||||
* `path-hash`: Hashes the relative path of the entry in question. The
|
||||
underlying file's values are completely ignored. This means the
|
||||
inode value will always be the same for that file path. This is
|
||||
useful when using NFS and you make changes out of band such as copy
|
||||
data between branches. This also means that entries that do point to
|
||||
the same file will not be recognizable via inodes. That does not
|
||||
mean hard links don't work. They will.
|
||||
* `path-hash32`: 32bit version of path-hash.
|
||||
* `devino-hash`: Hashes the device id and inode of the underlying
|
||||
entry. This won't prevent issues with NFS should the policy pick a
|
||||
different file or files move out of band but will present the same
|
||||
inode for underlying files that do too.
|
||||
* `devino-hash32`: 32bit version of devino-hash.
|
||||
* `hybrid-hash`: Performs path-hash on directories and devino-hash on
|
||||
other file types. Since directories can't have hard links the static
|
||||
value won't make a difference and the files will get values useful
|
||||
for finding duplicates. Probably the best to use if not using
|
||||
NFS. As such it is the default.
|
||||
* `hybrid-hash32`: 32bit version of hybrid-hash.
|
||||
|
||||
32bit versions are provided as there is some software which does not
|
||||
handle 64bit inodes well.
|
||||
|
||||
While there is a risk of hash collision in tests of a couple of
|
||||
million entries there were zero collisions. Unlike a typical
|
||||
filesystem FUSE filesystems can reuse inodes and not refer to the same
|
||||
entry. The internal identifier used to reference a file in FUSE is
|
||||
different from the inode value presented. The former is the nodeid and
|
||||
is actually a tuple of 2 64bit values: nodeid and generation. This
|
||||
tuple is not client facing. The inode that is presented to the client
|
||||
is passed through the kernel uninterpreted.
|
||||
|
||||
From FUSE docs for `use_ino`:
|
||||
|
||||
> Honor the st_ino field in the functions getattr() and
|
||||
> fill_dir(). This value is used to fill in the st_ino field
|
||||
> in the stat(2), lstat(2), fstat(2) functions and the d_ino
|
||||
> field in the readdir(2) function. The filesystem does not
|
||||
> have to guarantee uniqueness, however some applications
|
||||
> rely on this value being unique for the whole filesystem.
|
||||
> Note that this does *not* affect the inode that libfuse
|
||||
> and the kernel use internally (also called the "nodeid").
|
||||
|
||||
**NOTE:** As of version 2.35.0 the use_ino option has been
|
||||
removed. mergerfs should always be managing inode values.
|
||||
@@ -0,0 +1,17 @@
|
||||
# link-exdev
|
||||
|
||||
If using path preservation and a `link` fails with `EXDEV` make a call
|
||||
to `symlink` where the target is the `oldlink` and the `linkpath` is
|
||||
the newpath. The target value is determined by the value of
|
||||
`link-exdev`.
|
||||
|
||||
* `link-exdev=passthrough`: Return EXDEV as normal.
|
||||
* `link-exdev=rel-symlink`: A relative path from the newpath.
|
||||
* `link-exdev=abs-base-symlink`: An absolute value using the
|
||||
underlying branch.
|
||||
* `link-exdev=abs-pool-symlink`: An absolute value using the mergerfs
|
||||
mount point.
|
||||
* Defaults to `passthrough`.
|
||||
|
||||
**NOTE:** It is possible that some applications check the file they
|
||||
link. In those cases, it is possible it will error or complain.
|
||||
@@ -0,0 +1,13 @@
|
||||
# link_cow
|
||||
|
||||
* `link_cow=true|false`
|
||||
* Defaults to `false`
|
||||
|
||||
This feature offers similar functionality to what
|
||||
[cow-shell](https://manpages.ubuntu.com/manpages/noble/man1/cow-shell.1.html)
|
||||
offers.
|
||||
|
||||
When enabled if mergerfs is asked to open a file to write and the link
|
||||
count on the file is greater than 1 it will copy the file to a
|
||||
temporary new file and then rename it over the original. This will
|
||||
atomically "break" the link. After that it will open the new file.
|
||||
@@ -0,0 +1,26 @@
|
||||
# nfsopenhack
|
||||
|
||||
* `nfsopenhack=off`: No hack applied.
|
||||
* `nfsopenhack=git`: Apply hack if path includes `/.git/`.
|
||||
* `nfsopenhack=all`: Apply hack on all empty read-only files opened
|
||||
for writing.
|
||||
* Defaults to `off`.
|
||||
|
||||
NFS is not fully POSIX compliant and historically certain behaviors,
|
||||
such as opening files with `O_EXCL`, are not or not well
|
||||
supported. When mergerfs (or any FUSE filesystem) is exported over NFS
|
||||
some of these issues come up due to how NFS and FUSE interact.
|
||||
|
||||
This hack addresses the issue where the creation of a file with a
|
||||
read-only mode but with a read/write or write only flag. Normally this
|
||||
is perfectly valid but NFS chops the one open call into multiple
|
||||
calls. Exactly how it is translated depends on the configuration and
|
||||
versions of the NFS server and clients but it results in a permission
|
||||
error because a normal user is not allowed to open a read-only file as
|
||||
writable.
|
||||
|
||||
Even though it's a more niche situation this hack breaks normal
|
||||
security and behavior and as such is `off` by default. If set to `git`
|
||||
it will only perform the hack when the path in question includes
|
||||
`/.git/`. `all` will result in it applying anytime a read-only file
|
||||
which is empty is opened for writing.
|
||||
@@ -0,0 +1,20 @@
|
||||
# nullrw
|
||||
|
||||
* `nullrw=true|false`
|
||||
* Defaults to `false`.
|
||||
|
||||
Due to how FUSE works there is an overhead to all requests made to a
|
||||
FUSE filesystem that wouldn't exist for an in kernel one. Meaning that
|
||||
even a simple passthrough will have some slowdown. However, generally
|
||||
the overhead is minimal in comparison to the cost of the underlying
|
||||
I/O. By disabling the underlying I/O we can test the theoretical
|
||||
performance boundaries.
|
||||
|
||||
By enabling `nullrw` mergerfs will work as it always does **except**
|
||||
that all reads and writes will be no-ops. A write will succeed (the
|
||||
size of the write will be returned as if it were successful) but
|
||||
mergerfs does nothing with the data it was given. Similarly a read
|
||||
will return the size requested but won't touch the buffer.
|
||||
|
||||
See the [benchmarking](../benchmarking.md) section for suggestions on
|
||||
how to test.
|
||||
@@ -0,0 +1,184 @@
|
||||
# Options
|
||||
|
||||
These options are the same regardless of whether you use them with the
|
||||
`mergerfs` commandline program, in fstab, or in a config file.
|
||||
|
||||
### types
|
||||
|
||||
- BOOL = 'true' | 'false'
|
||||
- INT = [MIN_INT,MAX_INT]
|
||||
- UINT = [0,MAX_INT]
|
||||
- SIZE = 'NNM'; NN = INT, M = 'K' | 'M' | 'G' | 'T'
|
||||
- STR = string (may refer to an enumerated value, see details of
|
||||
argument)
|
||||
- FUNC = filesystem function
|
||||
- CATEGORY = function category
|
||||
- POLICY = mergerfs function policy
|
||||
|
||||
|
||||
### mount options
|
||||
|
||||
- **config**: Path to a config file. Same arguments as below in
|
||||
key=val / ini style format.
|
||||
- **branches**: Colon delimited list of branches.
|
||||
- **minfreespace=SIZE**: The minimum space value used for creation
|
||||
policies. Can be overridden by branch specific option. Understands
|
||||
'K', 'M', and 'G' to represent kilobyte, megabyte, and gigabyte
|
||||
respectively. (default: 4G)
|
||||
- **moveonenospc=BOOL|POLICY**: When enabled if a **write** fails with
|
||||
**ENOSPC** (no space left on device) or **EDQUOT** (disk quota
|
||||
exceeded) the policy selected will run to find a new location for
|
||||
the file. An attempt to move the file to that branch will occur
|
||||
(keeping all metadata possible) and if successful the original is
|
||||
unlinked and the write retried. (default: false, true = mfs)
|
||||
- **inodecalc=passthrough|path-hash|devino-hash|hybrid-hash**: Selects
|
||||
the inode calculation algorithm. (default: hybrid-hash)
|
||||
- **dropcacheonclose=BOOL**: When a file is requested to be closed
|
||||
call `posix_fadvise` on it first to instruct the kernel that we no
|
||||
longer need the data and it can drop its cache. Recommended when
|
||||
**cache.files=partial|full|auto-full|per-process** to limit double
|
||||
caching. (default: false)
|
||||
- **direct-io-allow-mmap=BOOL**: On newer kernels (>= 6.6) it is
|
||||
possible to disable file page caching while still allowing for
|
||||
shared mmap support. mergerfs will enable this feature if available
|
||||
but an option is provided to turn it off for testing and debugging
|
||||
purposes. (default: true)
|
||||
- **symlinkify=BOOL**: When enabled and a file is not writable and its
|
||||
mtime or ctime is older than **symlinkify_timeout** files will be
|
||||
reported as symlinks to the original files. Please read more below
|
||||
before using. (default: false)
|
||||
- **symlinkify_timeout=UINT**: Time to wait, in seconds, to activate
|
||||
the **symlinkify** behavior. (default: 3600)
|
||||
- **nullrw=BOOL**: Turns reads and writes into no-ops. The request
|
||||
will succeed but do nothing. Useful for benchmarking
|
||||
mergerfs. (default: false)
|
||||
- **lazy-umount-mountpoint=BOOL**: mergerfs will attempt to "lazy
|
||||
umount" the mountpoint before mounting itself. Useful when
|
||||
performing live upgrades of mergerfs. (default: false)
|
||||
- **ignorepponrename=BOOL**: Ignore path preserving on
|
||||
rename. Typically rename and link act differently depending on the
|
||||
policy of `create` (read below). Enabling this will cause rename and
|
||||
link to always use the non-path preserving behavior. This means
|
||||
files, when renamed or linked, will stay on the same
|
||||
filesystem. (default: false)
|
||||
- **export-support=BOOL**: Sets a low-level FUSE feature intended to
|
||||
indicate the filesystem can support being exported via
|
||||
NFS. (default: true)
|
||||
- **security_capability=BOOL**: If false return ENOATTR when xattr
|
||||
security.capability is queried. (default: true)
|
||||
- **xattr=passthrough|noattr|nosys**: Runtime control of
|
||||
xattrs. Default is to passthrough xattr requests. 'noattr' will
|
||||
short circuit as if nothing exists. 'nosys' will respond with ENOSYS
|
||||
as if xattrs are not supported or disabled. (default: passthrough)
|
||||
- **link_cow=BOOL**: When enabled if a regular file is opened which
|
||||
has a link count > 1 it will copy the file to a temporary file and
|
||||
rename over the original. Breaking the link and providing a basic
|
||||
copy-on-write function similar to cow-shell. (default: false)
|
||||
- **statfs=base|full**: Controls how statfs works. 'base' means it
|
||||
will always use all branches in statfs calculations. 'full' is in
|
||||
effect path preserving and only includes branches where the path
|
||||
exists. (default: base)
|
||||
- **statfs_ignore=none|ro|nc**: 'ro' will cause statfs calculations to
|
||||
ignore available space for branches mounted or tagged as 'read-only'
|
||||
or 'no create'. 'nc' will ignore available space for branches tagged
|
||||
as 'no create'. (default: none)
|
||||
- **nfsopenhack=off|git|all**: A workaround for exporting mergerfs
|
||||
over NFS where there are issues with creating files for write while
|
||||
setting the mode to read-only. (default: off)
|
||||
- **branches-mount-timeout=UINT**: Number of seconds to wait at
|
||||
startup for branches to be a mount other than the mountpoint's
|
||||
filesystem. (default: 0)
|
||||
- **follow-symlinks=never|directory|regular|all**: Turns symlinks into
|
||||
what they point to. (default: never)
|
||||
- **link-exdev=passthrough|rel-symlink|abs-base-symlink|abs-pool-symlink**:
|
||||
When a link fails with EXDEV optionally create a symlink to the file
|
||||
instead.
|
||||
- **rename-exdev=passthrough|rel-symlink|abs-symlink**: When a rename
|
||||
fails with EXDEV optionally move the file to a special directory and
|
||||
symlink to it.
|
||||
- **readahead=UINT**: Set readahead (in kilobytes) for mergerfs and
|
||||
branches if greater than 0. (default: 0)
|
||||
- **posix_acl=BOOL**: Enable POSIX ACL support (if supported by kernel
|
||||
and underlying filesystem). (default: false)
|
||||
- **async_read=BOOL**: Perform reads asynchronously. If disabled or
|
||||
unavailable the kernel will ensure there is at most one pending read
|
||||
request per file handle and will attempt to order requests by
|
||||
offset. (default: true)
|
||||
- **fuse_msg_size=UINT**: Set the max number of pages per FUSE
|
||||
message. Only available on Linux >= 4.20 and ignored
|
||||
otherwise. (min: 1; max: 256; default: 256)
|
||||
- **threads=INT**: Number of threads to use. When used alone
|
||||
(`process-thread-count=-1`) it sets the number of threads reading
|
||||
and processing FUSE messages. When used together it sets the number
|
||||
of threads reading from FUSE. When set to zero it will attempt to
|
||||
discover and use the number of logical cores. If the thread count is
|
||||
set negative it will look up the number of cores then divide by the
|
||||
absolute value. ie. threads=-2 on an 8 core machine will result in 8
|
||||
/ 2 = 4 threads. There will always be at least 1 thread. If set to
|
||||
-1 in combination with `process-thread-count` then it will try to
|
||||
pick reasonable values based on CPU thread count. NOTE: higher
|
||||
number of threads increases parallelism but usually decreases
|
||||
throughput. (default: 0)
|
||||
- **read-thread-count=INT**: Alias for `threads`.
|
||||
- **process-thread-count=INT**: Enables separate thread pool to
|
||||
asynchronously process FUSE requests. In this mode
|
||||
`read-thread-count` refers to the number of threads reading FUSE
|
||||
messages which are dispatched to process threads. -1 means disabled
|
||||
otherwise acts like `read-thread-count`. (default: -1)
|
||||
- **process-thread-queue-depth=UINT**: Sets the number of requests any
|
||||
single process thread can have queued up at one time. Meaning the
|
||||
total memory usage of the queues is queue depth multiplied by the
|
||||
number of process threads plus read thread count. 0 sets the depth
|
||||
to the same as the process thread count. (default: 0)
|
||||
- **pin-threads=STR**: Selects a strategy to pin threads to CPUs
|
||||
(default: unset)
|
||||
- **flush-on-close=never|always|opened-for-write**: Flush data cache
|
||||
on file close. Mostly for when writeback is enabled or merging
|
||||
network filesystems. (default: opened-for-write)
|
||||
- **scheduling-priority=INT**: Set mergerfs' scheduling
|
||||
priority. Valid values range from -20 to 19. See `setpriority` man
|
||||
page for more details. (default: -10)
|
||||
- **fsname=STR**: Sets the name of the filesystem as seen in
|
||||
**mount**, **df**, etc. Defaults to a list of the source paths
|
||||
concatenated together with the longest common prefix removed.
|
||||
- **func.FUNC=POLICY**: Sets the specific FUSE function's policy. See
|
||||
below for the list of value types. Example: **func.getattr=newest**
|
||||
- **func.readdir=seq|cosr|cor|cosr:INT|cor:INT**: Sets `readdir`
|
||||
policy. INT value sets the number of threads to use for
|
||||
concurrency. (default: seq)
|
||||
- **category.action=POLICY**: Sets policy of all FUSE functions in the
|
||||
action category. (default: epall)
|
||||
- **category.create=POLICY**: Sets policy of all FUSE functions in the
|
||||
create category. (default: epmfs)
|
||||
- **category.search=POLICY**: Sets policy of all FUSE functions in the
|
||||
search category. (default: ff)
|
||||
- **cache.statfs=UINT**: 'statfs' cache timeout in seconds. (default: 0)
|
||||
- **cache.attr=UINT**: File attribute cache timeout in
|
||||
seconds. (default: 1)
|
||||
- **cache.entry=UINT**: File name lookup cache timeout in
|
||||
seconds. (default: 1)
|
||||
- **cache.negative_entry=UINT**: Negative file name lookup cache
|
||||
timeout in seconds. (default: 0)
|
||||
- **cache.files=libfuse|off|partial|full|auto-full|per-process**: File
|
||||
page caching mode (default: libfuse)
|
||||
- **cache.files.process-names=LIST**: A pipe | delimited list of
|
||||
process [comm](https://man7.org/linux/man-pages/man5/proc.5.html)
|
||||
names to enable page caching for when
|
||||
`cache.files=per-process`. (default: "rtorrent|qbittorrent-nox")
|
||||
- **cache.writeback=BOOL**: Enable kernel writeback caching (default:
|
||||
false)
|
||||
- **cache.symlinks=BOOL**: Cache symlinks (if supported by kernel)
|
||||
(default: false)
|
||||
- **cache.readdir=BOOL**: Cache readdir (if supported by kernel)
|
||||
(default: false)
|
||||
- **parallel-direct-writes=BOOL**: Allow the kernel to dispatch
|
||||
multiple, parallel (non-extending) write requests for files opened
|
||||
with `cache.files=per-process` (if the process is not in `process-names`)
|
||||
or `cache.files=off`. (This requires kernel support, and was added in v6.2)
|
||||
|
||||
**NOTE:** Options are evaluated in the order listed so if the options
|
||||
are **func.rmdir=rand,category.action=ff** the **action** category
|
||||
setting will override the **rmdir** setting.
|
||||
|
||||
**NOTE:** Always look at the documentation for the version of mergerfs
|
||||
you're using. Not all features are available in older releases.
|
||||
@@ -0,0 +1,23 @@
|
||||
# pin-threads
|
||||
|
||||
Simple strategies for pinning read and/or process threads. If process
|
||||
threads are not enabled then the strategy simply works on the read
|
||||
threads. Invalid values are ignored.
|
||||
|
||||
* `pin-threads=R1L`: All read threads pinned to a single logical CPU.
|
||||
* `pin-threads=R1P`: All read threads pinned to a single physical CPU.
|
||||
* `pin-threads=RP1L`: All read and process threads pinned to a single logical CPU.
|
||||
* `pin-threads=RP1P`: All read and process threads pinned to a single physical CPU.
|
||||
* `pin-threads=R1LP1L`: All read threads pinned to a single logical
|
||||
CPU, all process threads pinned to a (if possible) different logical
|
||||
CPU.
|
||||
* `pin-threads=R1PP1P`: All read threads pinned to a single physical
|
||||
CPU, all process threads pinned to a (if possible) different logical
|
||||
CPU.
|
||||
* `pin-threads=RPSL`: All read and process threads are spread across
|
||||
all logical CPUs.
|
||||
* `pin-threads=RPSP`: All read and process threads are spread across
|
||||
all physical CPUs.
|
||||
* `pin-threads=R1PPSP`: All read threads are pinned to a single
|
||||
physical CPU while process threads are spread across all other
|
||||
physical CPUs.
|
||||
@@ -0,0 +1,38 @@
|
||||
# readahead
|
||||
|
||||
Sets the mergerfs and underlying filesystem `readahead` values. The
|
||||
value unit is in kibibytes.
|
||||
|
||||
* `readahead=1024`
|
||||
|
||||
While the max size of messages sent between the kernel and mergerfs is
|
||||
configurable via the [fuse_msg_size](fuse_msg_size.md) option that
|
||||
doesn't mean that is the size used by the kernel for read and
|
||||
writes.
|
||||
|
||||
Linux has a max read/write size of 2GB. Since the max FUSE message
|
||||
size is just over 1MB the kernel will break up read and write requests
|
||||
with buffers larger than that 1MB.
|
||||
|
||||
When page caching is disabled (`cache.files=off`), besides the kernel
|
||||
breaking up requests with larger buffers, requests are effectively one
|
||||
for one to mergerfs. A read or write request for X bytes is made to
|
||||
the kernel and a request for X bytes is made to mergerfs. No
|
||||
[readahead](https://en.wikipedia.org/wiki/Readahead) behavior will
|
||||
occur because there is no page cache available for it to store that
|
||||
data. In FUSE this is referred to as "direct IO". Note that "direct
|
||||
IO" is not the same as `O_DIRECT`.
|
||||
|
||||
When page caching is enabled the kernel can and will utilize
|
||||
`readahead`. However, there are two values which impact the size of
|
||||
the `readahead` requests. The filesystem's `readahead` value and the
|
||||
FUSE `max_readahead` value. Whichever is lowest is used. The default
|
||||
`max_readahead` in mergerfs is maxed out meaning only the filesystem
|
||||
`readahead` value is relevant.
|
||||
|
||||
Preferably this value would be set by the user externally since it is
|
||||
a generic feature but there is no standard way to do so mergerfs added
|
||||
this feature to make it easier to set.
|
||||
|
||||
There is currently no way to set separate values for different
|
||||
branches through mergerfs.
|
||||
@@ -0,0 +1,21 @@
|
||||
# rename-exdev
|
||||
|
||||
If using path preservation and a `rename` fails with `EXDEV`:
|
||||
|
||||
1. Move file from `/branch/a/b/c` to `/branch/.mergerfs_rename_exdev/a/b/c`.
|
||||
2. symlink the rename's `newpath` to the moved file.
|
||||
|
||||
The `target` value is determined by the value of `rename-exdev`.
|
||||
|
||||
* `rename-exdev=passthrough`: Return `EXDEV` as normal.
|
||||
* `rename-exdev=rel-symlink`: A relative path from the `newpath`.
|
||||
* `rename-exdev=abs-symlink`: An absolute value using the mergerfs
|
||||
mount point.
|
||||
* Defaults to `passthrough`.
|
||||
|
||||
**NOTE:** It is possible that some applications check the file they
|
||||
rename. In those cases it is possible it will error or complain.
|
||||
|
||||
**NOTE:** The reason `abs-symlink` is not split into two like
|
||||
`link-exdev` is due to the complexities in managing absolute base
|
||||
symlinks when multiple `oldpaths` exist.
|
||||
@@ -0,0 +1,59 @@
|
||||
# rename and link
|
||||
|
||||
**NOTE:** If you're receiving errors from software when files are
|
||||
moved / renamed / linked then you should consider changing the create
|
||||
policy to one which is **not** path preserving, enabling
|
||||
`ignorepponrename`, or contacting the author of the offending software
|
||||
and requesting that `EXDEV` (cross device / improper link) be properly
|
||||
handled.
|
||||
|
||||
`rename` and `link` are arguably the most complicated functions to
|
||||
create in a union filesystem. `rename` only works within a single
|
||||
filesystem or device. If a rename can't be done due to the source and
|
||||
destination paths existing on different mount points it will return
|
||||
**-1** with **errno = EXDEV** (cross device / improper link). So if a
|
||||
`rename`'s source and target are on different filesystems within the
|
||||
pool it creates an issue.
|
||||
|
||||
Originally mergerfs would return EXDEV whenever a rename was requested
|
||||
which was cross directory in any way. This made the code simple and
|
||||
was technically compliant with POSIX requirements. However, many
|
||||
applications fail to handle EXDEV at all and treat it as a normal
|
||||
error or otherwise handle it poorly. Such apps include: gvfsd-fuse
|
||||
v1.20.3 and prior, Finder / CIFS/SMB client in Apple OSX 10.9+,
|
||||
NZBGet, Samba's recycling bin feature.
|
||||
|
||||
As a result a compromise was made in order to get most software to
|
||||
work while still obeying mergerfs' policies. Below is the basic logic.
|
||||
|
||||
* If using a **create** policy which tries to preserve directory paths (epff,eplfs,eplus,epmfs)
|
||||
* Using the **rename** policy get the list of files to rename
|
||||
* For each file attempt rename:
|
||||
* If failure with ENOENT (no such file or directory) run **create** policy
|
||||
* If create policy returns the same branch as currently evaluating then clone the path
|
||||
* Re-attempt rename
|
||||
* If **any** of the renames succeed the higher level rename is considered a success
|
||||
* If **no** renames succeed the first error encountered will be returned
|
||||
* On success:
|
||||
* Remove the target from all branches with no source file
|
||||
* Remove the source from all branches which failed to rename
|
||||
* If using a **create** policy which does **not** try to preserve directory paths
|
||||
* Using the **rename** policy get the list of files to rename
|
||||
* Using the **getattr** policy get the target path
|
||||
* For each file attempt rename:
|
||||
* If the source branch != target branch:
|
||||
* Clone target path from target branch to source branch
|
||||
* Rename
|
||||
* If **any** of the renames succeed the higher level rename is considered a success
|
||||
* If **no** renames succeed the first error encountered will be returned
|
||||
* On success:
|
||||
* Remove the target from all branches with no source file
|
||||
* Remove the source from all branches which failed to rename
|
||||
|
||||
The removals are subject to normal entitlement checks. If the unlink
|
||||
fails it will fail silently.
|
||||
|
||||
The above behavior will help minimize the likelihood of EXDEV being
|
||||
returned but it will still be possible.
|
||||
|
||||
**link** uses the same strategy but without the removals.
|
||||
@@ -0,0 +1,26 @@
|
||||
# statfs / statvfs
|
||||
|
||||
* `statfs=base`: Aggregate details from all branches using their base directory.
|
||||
* `statfs=full`: Aggregate details using the full path of the file
|
||||
requested. Limiting it to only branches where the file exists.
|
||||
* Defaults to `base`.
|
||||
|
||||
[statvfs](http://linux.die.net/man/2/statvfs) normalizes the source
|
||||
filesystems based on the fragment size and sums the number of adjusted
|
||||
blocks and inodes. This means you will see the combined space of all
|
||||
sources. Total, used, and free. The sources however are dedupped based
|
||||
on the filesystem so multiple sources on the same drive will not result in
|
||||
double counting its space. Other filesystems mounted further down the tree
|
||||
of the branch will not be included when checking the mount's stats.
|
||||
|
||||
## statfs_ignore
|
||||
|
||||
Modifies how `statfs` works. Will cause it to ignore branches of a
|
||||
certain mode.
|
||||
|
||||
* `statfs_ignore=none`: Include all branches.
|
||||
* `statfs_ignore=ro`: Ignore available space for branches mounted as
|
||||
read-only or have a mode `RO` or `NC`.
|
||||
* `statfs_ignore=nc`: Ignore available space for branches with a mode
|
||||
of `NC`.
|
||||
* Defaults to `none`.
|
||||
@@ -0,0 +1,23 @@
|
||||
# symlinkify
|
||||
|
||||
* `symlinkify=true|false`
|
||||
* Defaults to `false`.
|
||||
|
||||
Due to the levels of indirection introduced by mergerfs and the
|
||||
underlying technology FUSE there can be varying levels of performance
|
||||
degradation. This feature will turn non-directories which are not
|
||||
writable into symlinks to the original file found by the `readlink`
|
||||
policy after the mtime and ctime are older than the timeout.
|
||||
|
||||
**WARNING:** The current implementation has a known issue in which if
|
||||
the file is open and being used when the file is converted to a
|
||||
symlink then the application which has that file open will receive an
|
||||
error when using it. This is unlikely to occur in practice but is
|
||||
something to keep in mind.
|
||||
|
||||
**WARNING:** Some backup solutions, such as CrashPlan, do not backup
|
||||
the target of a symlink. If using this feature it will be necessary to
|
||||
point any backup software to the original filesystems or configure the
|
||||
software to follow symlinks if such an option is
|
||||
available. Alternatively, create two mounts. One for backup and one
|
||||
for general consumption.
|
||||
@@ -0,0 +1,12 @@
|
||||
# Terminology
|
||||
|
||||
- `branch`: A base path used in the pool. Keep in mind that mergerfs
|
||||
does not work on devices or even filesystems but on paths. It can
|
||||
accomidate for multiple paths pointing to the same filesystem.
|
||||
- `pool`: The mergerfs mount. The union of the branches. The instance
|
||||
of mergerfs. You can have as many pools as you wish.
|
||||
- `relative path`: The path in the pool relative to the branch and mount.
|
||||
- `function`: A filesystem call (open, unlink, create, getattr, rmdir, etc.)
|
||||
- `category`: A collection of functions based on basic behavior (action, create, search).
|
||||
- `policy`: The algorithm used to select a file or files when performing a function.
|
||||
- `path preservation`: Aspect of some policies which includes checking the path for which a file would be created.
|
||||
@@ -0,0 +1,53 @@
|
||||
# threads
|
||||
|
||||
There are multiple thread pools used in mergerfs to provide
|
||||
parallel behaviors.
|
||||
|
||||
|
||||
## read-thread-count
|
||||
|
||||
The number of threads used to read (and possibly process) messages
|
||||
from the kernel.
|
||||
|
||||
* `read-thread-count=0`: Create a thread pool sized to the number of
|
||||
logical CPUs.
|
||||
* `read-thread-count=N` where `N>0`: Create a thread pool of `N` threads.
|
||||
* `read-thread-count=N` where `N<0`: Create a thread pool of `CPUCount /
|
||||
-N` threads.
|
||||
* `read-thread-count=-1` where `process-thread-count=-1`: Creates `2`
|
||||
read threads and `max(2,CPUCount-2)` process threads.
|
||||
* Defaults to `0`.
|
||||
|
||||
When `process-thread-count=-1` (the default) this option sets the
|
||||
number of threads which read and then process requests from the
|
||||
kernel.
|
||||
|
||||
When `process-thread-count` is set to anything else mergerfs will
|
||||
create two thread pools. A "read" thread pool which just reads from
|
||||
the kernel and hands off requests to the "process" thread pool.
|
||||
|
||||
Generally, only 1 or 2 "read" threads are necessary.
|
||||
|
||||
|
||||
## process-thread-count
|
||||
|
||||
When enabled this sets the number of threads in the message processing pool.
|
||||
|
||||
* `process-thread-count=-1`: Process thread pool is disabled.
|
||||
* `process-thread-count=0`: Create a thread pool sized to the number
|
||||
of logical CPUs.
|
||||
* `process-thread-count=N` where `N>0`: Create a thread pool of `N` threads.
|
||||
* `process-thread-count=N` where `N<-1`: Create a thread pool of `CPUCount /
|
||||
-N` threads.
|
||||
* Defaults to `-1`.
|
||||
|
||||
|
||||
## process-thread-queue-depth
|
||||
|
||||
* `process-thread-queue-depth=N` where `N>0`: Sets the number of outstanding
|
||||
requests that a process thread can have to N. If requests come in
|
||||
faster than can be processed and the max queue depth hit then
|
||||
queuing the request will block in order to limit memory growth.
|
||||
* `process-thread-queue-depth=0`: Sets the queue depth to the thread
|
||||
pool count.
|
||||
* Defaults to `0`.
|
||||
@@ -0,0 +1,27 @@
|
||||
# xattr
|
||||
|
||||
* `xattr=passthrough`: Passes through all requests to underlying file.
|
||||
* `xattr=noattr`: mergerfs receives the request but returns `NOATTR`.
|
||||
* `xattr=nosys`: Tells the kernel to reject all `xattr` requests.
|
||||
* Defaults to `passthrough`.
|
||||
|
||||
Runtime extended attribute support can be managed via the `xattr`
|
||||
option. By default it will passthrough any xattr calls. Given xattr
|
||||
support is rarely used and can have significant performance
|
||||
implications mergerfs allows it to be disabled at runtime. The
|
||||
performance problems mostly comes when file caching is enabled. The
|
||||
kernel will send a `getxattr` for `security.capability` *before every
|
||||
single write*. It doesn't cache the responses to any `getxattr`. This
|
||||
might be addressed in the future but for now mergerfs can really only
|
||||
offer the following workarounds.
|
||||
|
||||
`noattr` will cause mergerfs to short circuit all xattr calls and
|
||||
return ENOATTR where appropriate. mergerfs still gets all the requests
|
||||
but they will not be forwarded on to the underlying filesystems. The
|
||||
runtime control will still function in this mode.
|
||||
|
||||
`nosys` will cause mergerfs to return `ENOSYS` for any xattr call. The
|
||||
difference with `noattr` is that the kernel will cache this fact and
|
||||
itself short circuit future calls. This is more efficient than
|
||||
`noattr` but will cause mergerfs' runtime control via the hidden file
|
||||
to stop working.
|
||||
@@ -0,0 +1,37 @@
|
||||
# Error Handling
|
||||
|
||||
POSIX filesystem functions offer a single return code meaning that
|
||||
there is some complication regarding the handling of multiple branches
|
||||
as mergerfs does. It tries to handle errors in a way that would
|
||||
generally return meaningful values for that particular function.
|
||||
|
||||
### chmod, chown, removexattr, setxattr, truncate, utimens
|
||||
|
||||
1. if no error: return 0 (success)
|
||||
2. if no successes: return first error
|
||||
3. if one of the files acted on was the same as the related search function: return its value
|
||||
4. return 0 (success)
|
||||
|
||||
While doing this increases the complexity and cost of error handling,
|
||||
particularly step 3, this provides probably the most reasonable return
|
||||
value.
|
||||
|
||||
### unlink, rmdir
|
||||
|
||||
1. if no errors: return 0 (success)
|
||||
2. return first error
|
||||
|
||||
Older versions of mergerfs would return success if any success occurred
|
||||
but for unlink and rmdir there are downstream assumptions that, while
|
||||
not impossible to occur, can confuse some software.
|
||||
|
||||
### others
|
||||
|
||||
For search functions, there is always a single thing acted on and as
|
||||
such whatever return value that comes from the single function call is
|
||||
returned.
|
||||
|
||||
For create functions `mkdir`, `mknod`, and `symlink` which don't
|
||||
return a file descriptor and therefore can have `all` or `epall`
|
||||
policies it will return success if any of the calls succeed and an
|
||||
error otherwise.
|
||||
@@ -0,0 +1,42 @@
|
||||
# Compatibility and Integration
|
||||
|
||||
## Can I use mergerfs without SnapRAID? SnapRAID without mergerfs?
|
||||
|
||||
Yes. They are completely unrelated pieces of software that just happen
|
||||
to work well together.
|
||||
|
||||
|
||||
## Does mergerfs support CoW / copy-on-write / writes to read-only filesystems?
|
||||
|
||||
Not in the sense of a filesystem like BTRFS or ZFS nor in the
|
||||
overlayfs or aufs sense. It does offer a
|
||||
[cow-shell](http://manpages.ubuntu.com/manpages/bionic/man1/cow-shell.1.html)
|
||||
like hard link breaking (copy to temp file then rename over original)
|
||||
which can be useful when wanting to save space by hardlinking
|
||||
duplicate files but wish to treat each name as if it were a unique and
|
||||
separate file.
|
||||
|
||||
If you want to write to a read-only filesystem you should look at
|
||||
overlayfs. You can always include the overlayfs mount into a mergerfs
|
||||
pool.
|
||||
|
||||
|
||||
## Can mergerfs run via Docker, Podman, Kubernetes, etc.
|
||||
|
||||
Yes. With Docker you'll need to include `--cap-add=SYS_ADMIN
|
||||
--device=/dev/fuse --security-opt=apparmor:unconfined` or similar with
|
||||
other container runtimes. You should also be running it as root or
|
||||
given sufficient caps to change user and group identity as well as
|
||||
have root like filesystem permissions.
|
||||
|
||||
Keep in mind that you **MUST** consider identity when using
|
||||
containers. For example: supplemental groups will be picked up from
|
||||
the container unless you properly manage users and groups by sharing
|
||||
relevant /etc files or by using some other means to share identity
|
||||
across containers. Similarly, if you use "rootless" containers and user
|
||||
namespaces to do uid/gid translations you **MUST** consider that while
|
||||
managing shared files.
|
||||
|
||||
Also, as mentioned by [hotio](https://hotio.dev/containers/mergerfs),
|
||||
with Docker you should probably be mounting with `bind-propagation`
|
||||
set to `slave`.
|
||||
@@ -0,0 +1,81 @@
|
||||
# Configuration and Policies
|
||||
|
||||
## What policies should I use?
|
||||
|
||||
Unless you're doing something more niche the average user is probably
|
||||
best off using `mfs` for `category.create`. It will spread files out
|
||||
across your branches based on available space. Use `mspmfs` if you
|
||||
want to try to colocate the data a bit more. You may want to use `lus`
|
||||
if you prefer a slightly different distribution of data if you have a
|
||||
mix of smaller and larger filesystems. Generally though `mfs`, `lus`,
|
||||
or even `rand` are good for the general use case. If you are starting
|
||||
with an imbalanced pool you can use the tool **mergerfs.balance** to
|
||||
redistribute files across the pool. That said "balancing" really
|
||||
should not be needed. There is really no inherent issue with being
|
||||
unbalanced. "Optimal" layout is related to usage patterns and most
|
||||
people don't have patterns that are performance sensitive or specific
|
||||
enough to do anything about. Additionally, the balance tool is very
|
||||
simplistic and was not written to be as serious tool that accounts for
|
||||
edge cases.
|
||||
|
||||
If you really wish to try to colocate files based on directory you can
|
||||
set `func.create` to `epmfs` or similar and `func.mkdir` to `rand` or
|
||||
`eprand` depending on if you just want to colocate generally or on
|
||||
specific branches. Either way the _need_ to colocate is rare. For
|
||||
instance: if you wish to remove the device regularly and want the data
|
||||
to predictably be on that device or if you don't use backup at all and
|
||||
don't wish to replace that data piecemeal. In which case using path
|
||||
preservation can help but will require some manual
|
||||
attention. Colocating after the fact can be accomplished using the
|
||||
**mergerfs.consolidate** tool. If you don't need strict colocation
|
||||
which the `ep` policies provide then you can use the `msp` based
|
||||
policies which will walk back the path till finding a branch that
|
||||
works.
|
||||
|
||||
Ultimately there is no correct answer. It is a preference or based on
|
||||
some particular need. mergerfs is very easy to test and experiment
|
||||
with. I suggest creating a test setup and experimenting to get a sense
|
||||
of what you want.
|
||||
|
||||
`epmfs` is the default `category.create` policy because `ep` policies
|
||||
are not going to change the general layout of the branches. It won't
|
||||
place files/dirs on branches that don't already have the relative
|
||||
branch. So it keeps the system in a known state. It's much easier to
|
||||
stop using `epmfs` or redistribute files around the filesystem than it
|
||||
is to consolidate them back.
|
||||
|
||||
|
||||
## What settings should I use?
|
||||
|
||||
Depends on what features you want. Generally speaking, there are no
|
||||
"wrong" settings. All settings are feature related. The best bet is to
|
||||
read over the available options and choose what fits your
|
||||
situation. If something isn't clear from the documentation please
|
||||
reach out and the documentation will be improved.
|
||||
|
||||
For the average person the settings described in the [Quick
|
||||
Start](../quickstart.md) are sufficient.
|
||||
|
||||
|
||||
## Why are all my files ending up on 1 filesystem?!
|
||||
|
||||
Did you start with empty filesystems? Did you explicitly configure a
|
||||
`category.create` policy? Are you using an `existing path` / `path
|
||||
preserving` policy?
|
||||
|
||||
The default create policy is `epmfs`. That is a path preserving
|
||||
algorithm. With such a policy for `mkdir` and `create` with a set of
|
||||
empty filesystems it will select only 1 filesystem when the first
|
||||
directory is created. Anything, files or directories, created in that
|
||||
first directory will be placed on the same branch because it is
|
||||
preserving paths.
|
||||
|
||||
This may catch new users off guard but this policy is the safest
|
||||
policy to start with as it will not change the general layout of the
|
||||
underlying filesystems. If you do not care about path preservation
|
||||
(most shouldn't) and wish your files to be spread across all your
|
||||
filesystems change to `mfs` or similar
|
||||
[policy](../config/functions_categories_and_policies.md). If you do
|
||||
want path preservation you'll need to perform the manual act of
|
||||
creating paths on the filesystems you want the data to land on before
|
||||
transferring your data.
|
||||
@@ -0,0 +1,32 @@
|
||||
# Limiting drive spinup
|
||||
|
||||
## How can I setup my system to limit drive spinup?
|
||||
|
||||
TL;DR: You really can't. Not through mergerfs alone.
|
||||
|
||||
|
||||
mergerfs is a proxy. Not a cache. It proxies calls between client software and underlying filesystems. If a client does an `open`, `readdir`, `stat`, etc. it must translate that into something that makes sense across N filesystems. For `readdir` that means running the call against all branches and aggregating the output. For `open` that means finding the file to open and doing so. The only way to find the file to open is to scan across all branches and sort the results and pick one. There is no practical way to do otherwise. Especially given so many mergerfs users expect out of band changes to "just work."
|
||||
|
||||
The best way to limit spinup of drives is to limit their usage at the client level. Meaning keeping software from interacting with the filesystem all together.
|
||||
|
||||
### What if you assume no out of band changes and cache everything?
|
||||
|
||||
This would require a significant rewrite of mergerfs. Everything is done on the fly right now and all those calls to underlying filesystems can cause a spinup. To work around that a database of some sort would have to be used to store ALL metadata about the underlying filesystems and on startup everything scanned and stored. From then on it would have to carefully update all the same data the filesystems do. It couldn't be kept in RAM because it would take up too much space so it'd have to be on a SSD or other storage device. If anything changed out of band it would break things in weird ways. It could rescan on occasion but that would require spinning up everything. It could put file watches on every single directory but that probably won't scale (there are millions of directories in my system for example) and the open files might keep the drives from spinning down. Something as "simple" as keeping the current available free space on each filesystem isn't as easy as one might think given reflinks, snapshots, and other block level dedup technologies.
|
||||
|
||||
Even if all metadata (including xattrs) is cached some software will open files (media like videos and audio) to check their metadata. Granted a Plex or Jellyfin scan which may do that is different from a random directory listing but is still something to consider. Those "deep" scans can't be kept from waking drives.
|
||||
|
||||
### What if you only query already active drives?
|
||||
|
||||
Let's assume that is plausible (it isn't because some drives actually will spin up if you ask if they are spun down... yes... really) you would have to either cache all the metadata on the filesystem or treat it like the filesystem doesn't exist. The former has all the problems mentioned prior and the latter would break a lot of things.
|
||||
|
||||
### Is there anything that can be done where mergerfs is involved?
|
||||
|
||||
Yes, but whether it works for you depends on your tolerance for the complexity.
|
||||
|
||||
1. Cleanly separate writing, storing, and consuming the data.
|
||||
1. Use a SSD or dedicated and limited pool of drives for downloads / torrents.
|
||||
2. When downloaded move the files to the primary storage pool.
|
||||
3. When setting up software like Plex, Jellyfin, etc. point to the underlying filesystems. Not mergerfs.
|
||||
2. Add a bunch of bcache, lvmcache, or similar block level cache to your setup. After a bit of use, assuming sufficient storage space, you can limit the likelihood of the underlying spinning disks from needing to be hit.
|
||||
|
||||
Remember too that while it may be a tradeoff you're willing to live with there is decent evidence that spinning down drives puts increased wear on them and can lead to their death earlier than otherwise.
|
||||
@@ -0,0 +1,49 @@
|
||||
# Recommendations and Warnings
|
||||
|
||||
## What should mergerfs NOT be used for?
|
||||
|
||||
- databases: Even if the database stored data in separate files
|
||||
(mergerfs wouldn't offer much otherwise) the higher latency of the
|
||||
indirection will really harm performance. If it is a lightly used
|
||||
sqlite3 database then it should be fine.
|
||||
- VM images: For the same reasons as databases. VM images are accessed
|
||||
very aggressively and mergerfs will introduce a lot of extra latency.
|
||||
- As replacement for RAID: mergerfs is just for pooling branches. If
|
||||
you need that kind of device performance aggregation or high
|
||||
availability you should stick with RAID. However, it is fine to put
|
||||
a filesystem which is on a RAID setup in mergerfs.
|
||||
|
||||
|
||||
## It's mentioned that there are some security issues with mhddfs. What are they? How does mergerfs address them?
|
||||
|
||||
[mhddfs](https://github.com/trapexit/mhddfs) manages running as
|
||||
`root` by calling
|
||||
[getuid()](https://github.com/trapexit/mhddfs/blob/cae96e6251dd91e2bdc24800b4a18a74044f6672/src/main.c#L319)
|
||||
and if it returns `0` then it will
|
||||
[chown](http://linux.die.net/man/1/chown) the file. Not only is that a
|
||||
race condition but it doesn't handle other situations. Rather than
|
||||
attempting to simulate POSIX ACL behavior the proper way to manage
|
||||
this is to use [seteuid](http://linux.die.net/man/2/seteuid) and
|
||||
[setegid](http://linux.die.net/man/2/setegid), in effect, becoming the
|
||||
user making the original call, and perform the action as them. This is
|
||||
what mergerfs does and why mergerfs should always run as root.
|
||||
|
||||
In Linux setreuid syscalls apply only to the thread. glibc hides this
|
||||
away by using realtime signals to inform all threads to change
|
||||
credentials. Taking after Samba, mergerfs uses
|
||||
`syscall(SYS_setreuid,...)` to set the callers credentials for that
|
||||
thread only. Jumping back to `root` as necessary should escalated
|
||||
privileges be needed (for instance: to clone paths between
|
||||
filesystems).
|
||||
|
||||
For non-Linux systems, mergerfs uses a read-write lock and changes
|
||||
credentials only when necessary. If multiple threads are to be user X
|
||||
then only the first one will need to change the processes
|
||||
credentials. So long as the other threads need to be user X they will
|
||||
take a readlock allowing multiple threads to share the
|
||||
credentials. Once a request comes in to run as user Y that thread will
|
||||
attempt a write lock and change to Y's credentials when it can. If the
|
||||
ability to give writers priority is supported then that flag will be
|
||||
used so threads trying to change credentials don't starve. This isn't
|
||||
the best solution but should work reasonably well assuming there are
|
||||
few users.
|
||||
@@ -0,0 +1,31 @@
|
||||
# Reliability and Scalability
|
||||
|
||||
## Is mergerfs "production ready?"
|
||||
|
||||
Yes.
|
||||
|
||||
mergerfs has been around for over a decade and used by many users on
|
||||
their systems. Typically running 24/7 with constant load.
|
||||
|
||||
At least a few companies are believed to use mergerfs in production
|
||||
environments. A number of [NAS focused operating
|
||||
systems](../related_projects.md) includes mergerfs as a solution for
|
||||
pooling filesystems.
|
||||
|
||||
Most serious issues (crashes or data corruption) have been due to
|
||||
[kernel bugs](../known_issues_bugs.md#fuse-and-linux-kernel). All of
|
||||
which are fixed in stable releases.
|
||||
|
||||
|
||||
## How well does mergerfs scale?
|
||||
|
||||
Users have reported running mergerfs on everything from OpenWRT
|
||||
routers and Raspberry Pi SBCs to multi-socket Xeon enterprise servers.
|
||||
|
||||
Users have pooled everything from USB thumb drives to enterprise NVME
|
||||
SSDs to remote filesystems and rclone mounts.
|
||||
|
||||
The cost of many calls can be `O(n)` meaning adding more branches to
|
||||
the pool will increase the cost of certain functions but there are a
|
||||
number of caches and strategies in place to limit overhead where
|
||||
possible.
|
||||
@@ -0,0 +1,215 @@
|
||||
# Technical Behavior and Limitations
|
||||
|
||||
## Do hardlinks work?
|
||||
|
||||
Yes. See also the option `inodecalc` for how inode values are
|
||||
calculated.
|
||||
|
||||
What mergerfs does not do is fake hard links across branches. Read
|
||||
the section "rename & link" for how it works.
|
||||
|
||||
Remember that hardlinks will NOT work across devices. That includes
|
||||
between the original filesystem and a mergerfs pool, between two
|
||||
separate pools of the same underlying filesystems, or bind mounts of
|
||||
paths within the mergerfs pool. The latter is common when using Docker
|
||||
or Podman. Multiple volumes (bind mounts) to the same underlying
|
||||
filesystem are considered different devices. There is no way to link
|
||||
between them. You should mount in the highest directory in the
|
||||
mergerfs pool that includes all the paths you need if you want links
|
||||
to work.
|
||||
|
||||
## How does mergerfs handle moving and copying of files?
|
||||
|
||||
This is a _very_ common mistaken assumption regarding how filesystems
|
||||
work. There is no such thing as "move" or "copy." These concepts are
|
||||
high level behaviors made up of numerous independent steps and _not_
|
||||
individual filesystem functions.
|
||||
|
||||
A "move" can include a "copy" so lets describe copy first.
|
||||
|
||||
When an application copies a file from source to destination it can do
|
||||
so in a number of ways but the basics are the following.
|
||||
|
||||
1. `open` the source file.
|
||||
2. `create` the destination file.
|
||||
3. `read` a chunk of data from source and `write` to
|
||||
destination. Continue till it runs out of data to copy.
|
||||
4. Copy file metadata (`stat`) such as ownership (`chown`),
|
||||
permissions (`chmod`), timestamps (`utimes`), extended attributes
|
||||
(`getxattr`, `setxattr`), etc.
|
||||
5. `close` source and destination files.
|
||||
|
||||
"move" is typically a `rename(src,dst)` and if that errors with
|
||||
`EXDEV` (meaning the source and destination are on different
|
||||
filesystems) the application will "copy" the file as described above
|
||||
and then it removes (`unlink`) the source.
|
||||
|
||||
The `rename(src,dst)`, `open(src)`, `create(dst)`, data copying,
|
||||
metadata copying, `unlink(src)`, etc. are entirely distinct and
|
||||
separate events. There is really no practical way to know that what is
|
||||
ultimately occurring is the "copying" of a file or what the source
|
||||
file would be. Since the source is not known there is no way to know
|
||||
how large a created file is destined to become. This is why it is
|
||||
impossible for mergerfs to choose the branch for a `create` based on
|
||||
file size. The only context provided when a file is created, besides
|
||||
the name, is the permissions, if it is to be read and/or written, and
|
||||
some low level settings for the operating system.
|
||||
|
||||
All of this means that mergerfs can not make decisions when a file is
|
||||
created based on file size or the source of the data. That information
|
||||
is simply not available. At best mergerfs could respond to files
|
||||
reaching a certain size when writing data or when a file is closed.
|
||||
|
||||
Related: if a user wished to have mergerfs perform certain activities
|
||||
based on the name of a file it is common and even best practice for a
|
||||
program to write to a temporary file first and then rename to its
|
||||
final destination. That temporary file name will typically be random
|
||||
and have no indication of the type of file being written.
|
||||
|
||||
## Does FICLONE or FICLONERANGE work?
|
||||
|
||||
Unfortunately not. FUSE, the technology mergerfs is based on, does not
|
||||
support the `clone_file_range` feature needed for it to work. mergerfs
|
||||
won't even know such a request is made. The kernel will simply return
|
||||
an error back to the application making the request.
|
||||
|
||||
Should FUSE gain the ability mergerfs will be updated to support it.
|
||||
|
||||
## Why do I get an "out of space" / "no space left on device" / ENOSPC error even though there appears to be lots of space available?
|
||||
|
||||
First make sure you've read the sections above about policies, path
|
||||
preservation, branch filtering, and the options **minfreespace**,
|
||||
**moveonenospc**, **statfs**, and **statfs_ignore**.
|
||||
|
||||
mergerfs is simply presenting a union of the content within multiple
|
||||
branches. The reported free space is an aggregate of space available
|
||||
within the pool (behavior modified by **statfs** and
|
||||
**statfs_ignore**). It does not represent a contiguous space. In the
|
||||
same way that read-only filesystems, those with quotas, or reserved
|
||||
space report the full theoretical space available.
|
||||
|
||||
Due to path preservation, branch tagging, read-only status, and
|
||||
**minfreespace** settings it is perfectly valid that `ENOSPC` / "out
|
||||
of space" / "no space left on device" be returned. It is doing what
|
||||
was asked of it: filtering possible branches due to those
|
||||
settings. Only one error can be returned and if one of the reasons for
|
||||
filtering a branch was **minfreespace** then it will be returned as
|
||||
such. **moveonenospc** is only relevant to writing a file which is too
|
||||
large for the filesystem it's currently on.
|
||||
|
||||
It is also possible that the filesystem selected has run out of
|
||||
inodes. Use `df -i` to list the total and available inodes per
|
||||
filesystem.
|
||||
|
||||
If you don't care about path preservation then simply change the
|
||||
`create` policy to one which isn't. `mfs` is probably what most are
|
||||
looking for. The reason it's not default is because it was originally
|
||||
set to `epmfs` and changing it now would change people's setup. Such a
|
||||
setting change will likely occur in mergerfs 3.
|
||||
|
||||
## Why does the total available space in mergerfs not equal outside?
|
||||
|
||||
Are you using ext2/3/4? With reserve for root? mergerfs uses available
|
||||
space for statfs calculations. If you've reserved space for root then
|
||||
it won't show up.
|
||||
|
||||
You can remove the reserve by running: `tune2fs -m 0 <device>`
|
||||
|
||||
## I notice massive slowdowns of writes when enabling cache.files.
|
||||
|
||||
When file caching is enabled in any form (`cache.files!=off`) it will
|
||||
issue `getxattr` requests for `security.capability` prior to _every
|
||||
single write_. This will usually result in performance degradation,
|
||||
especially when using a network filesystem (such as NFS or SMB.)
|
||||
Unfortunately at this moment, the kernel is not caching the response.
|
||||
|
||||
To work around this situation mergerfs offers a few solutions.
|
||||
|
||||
1. Set `security_capability=false`. It will short circuit any call and
|
||||
return `ENOATTR`. This still means though that mergerfs will
|
||||
receive the request before every write but at least it doesn't get
|
||||
passed through to the underlying filesystem.
|
||||
2. Set `xattr=noattr`. Same as above but applies to _all_ calls to
|
||||
getxattr. Not just `security.capability`. This will not be cached
|
||||
by the kernel either but mergerfs' runtime config system will still
|
||||
function.
|
||||
3. Set `xattr=nosys`. Results in mergerfs returning `ENOSYS` which
|
||||
_will_ be cached by the kernel. No future xattr calls will be
|
||||
forwarded to mergerfs. The downside is that also means the xattr
|
||||
based config and query functionality won't work either.
|
||||
4. Disable file caching. If you aren't using applications which use
|
||||
`mmap` it's probably simpler to just disable it altogether. The
|
||||
kernel won't send the requests when caching is disabled.
|
||||
|
||||
## Why can't I see my files / directories?
|
||||
|
||||
It's almost always a permissions issue. Unlike mhddfs and
|
||||
unionfs-fuse, which runs as root and attempts to access content as
|
||||
such, mergerfs always changes its credentials to that of the
|
||||
caller. This means that if the user does not have access to a file or
|
||||
directory than neither will mergerfs. However, because mergerfs is
|
||||
creating a union of paths it may be able to read some files and
|
||||
directories on one filesystem but not another resulting in an
|
||||
incomplete set.
|
||||
|
||||
Whenever you run into a split permission issue (seeing some but not
|
||||
all files) try using
|
||||
[mergerfs.fsck](https://github.com/trapexit/mergerfs-tools) tool to
|
||||
check for and fix the mismatch. If you aren't seeing anything at all
|
||||
be sure that the basic permissions are correct. The user and group
|
||||
values are correct and that directories have their executable bit
|
||||
set. A common mistake by users new to Linux is to `chmod -R 644` when
|
||||
they should have `chmod -R u=rwX,go=rX`.
|
||||
|
||||
If using a network filesystem such as NFS or SMB (Samba) be sure to
|
||||
pay close attention to anything regarding permissioning and
|
||||
users. Root squashing and user translation for instance has bitten a
|
||||
few mergerfs users. Some of these also affect the use of mergerfs from
|
||||
container platforms such as Docker.
|
||||
|
||||
|
||||
## Why use FUSE? Why not a kernel based solution?
|
||||
|
||||
As with any solution to a problem, there are advantages and
|
||||
disadvantages to each one.
|
||||
|
||||
A FUSE based solution has all the downsides of FUSE:
|
||||
|
||||
- Higher IO latency due to the trips in and out of kernel space
|
||||
- Higher general overhead due to trips in and out of kernel space
|
||||
- Double caching when using page caching
|
||||
- Misc limitations due to FUSE's design
|
||||
|
||||
But FUSE also has a lot of upsides:
|
||||
|
||||
- Easier to offer a cross platform solution
|
||||
- Easier forward and backward compatibility
|
||||
- Easier updates for users
|
||||
- Easier and faster release cadence
|
||||
- Allows more flexibility in design and features
|
||||
- Overall easier to write, secure, and maintain
|
||||
- Much lower barrier to entry (getting code into the kernel takes a
|
||||
lot of time and effort initially)
|
||||
|
||||
|
||||
## Is my OS's libfuse needed for mergerfs to work?
|
||||
|
||||
No. Normally `mount.fuse` is needed to get mergerfs (or any FUSE
|
||||
filesystem to mount using the `mount` command but in vendoring the
|
||||
libfuse library the `mount.fuse` app has been renamed to
|
||||
`mount.mergerfs` meaning the filesystem type in `fstab` can simply be
|
||||
`mergerfs`. That said there should be no harm in having it installed
|
||||
and continuing to using `fuse.mergerfs` as the type in `/etc/fstab`.
|
||||
|
||||
If `mergerfs` doesn't work as a type it could be due to how the
|
||||
`mount.mergerfs` tool was installed. Must be in `/sbin/` with proper
|
||||
permissions.
|
||||
|
||||
|
||||
## Why was splice support removed?
|
||||
|
||||
After a lot of testing over the years, splicing always appeared to
|
||||
at best, provide equivalent performance, and in some cases, worse
|
||||
performance. Splice is not supported on other platforms forcing a
|
||||
traditional read/write fallback to be provided. The splice code was
|
||||
removed to simplify the codebase.
|
||||
@@ -0,0 +1,64 @@
|
||||
# Usage and Functionality
|
||||
|
||||
## Can mergerfs be used with filesystems which already have data / are in use?
|
||||
|
||||
Yes. mergerfs is really just a proxy and does **NOT** interfere with
|
||||
the normal form or function of the filesystems, mounts, paths it
|
||||
manages. A userland application that is acting as a
|
||||
man-in-the-middle. It can't do anything that any other random piece of
|
||||
software can't do.
|
||||
|
||||
mergerfs is **not** a traditional filesystem that takes control over
|
||||
the underlying block device. mergerfs is **not** RAID. It does **not**
|
||||
manipulate the data that passes through it. It does **not** shard data
|
||||
across filesystems. It merely shards some **behavior** and aggregates
|
||||
others.
|
||||
|
||||
|
||||
## Can filesystems be removed from the pool without affecting them?
|
||||
|
||||
Yes. See previous question's answer.
|
||||
|
||||
|
||||
## Can mergerfs be removed without affecting the data?
|
||||
|
||||
Yes. See the previous question's answer.
|
||||
|
||||
|
||||
## Can filesystems be moved to another pool?
|
||||
|
||||
Yes. See the previous question's answer.
|
||||
|
||||
|
||||
## Can filesystems be part of multiple pools?
|
||||
|
||||
Yes.
|
||||
|
||||
|
||||
## How do I migrate data into or out of the pool when adding/removing filesystems?
|
||||
|
||||
You don't need to. See the previous question's answer.
|
||||
|
||||
|
||||
## How do I remove a filesystem but keep the data in the pool?
|
||||
|
||||
Nothing special needs to be done. Remove the branch from mergerfs'
|
||||
config and copy (rsync) the data from the removed filesystem into the
|
||||
pool. The same as if it were you transfering data from one filesystem
|
||||
to another.
|
||||
|
||||
If you wish to continue using the pool while performing the transfer
|
||||
simply create a temporary pool without the filesystem in question and
|
||||
then copy the data. It would probably be a good idea to set the branch
|
||||
to `RO` prior to doing this to ensure no new content is written to the
|
||||
filesystem while performing the copy.
|
||||
|
||||
|
||||
## Can filesystems be written to directly? Outside of mergerfs while pooled?
|
||||
|
||||
Yes, however, it's not recommended to use the same file from within the
|
||||
pool and from without at the same time (particularly
|
||||
writing). Especially if using caching of any kind (cache.files,
|
||||
cache.entry, cache.attr, cache.negative_entry, cache.symlinks,
|
||||
cache.readdir, etc.) as there could be a conflict between cached data
|
||||
and not.
|
||||
@@ -0,0 +1,79 @@
|
||||
# mergerfs - a featureful union filesystem
|
||||
|
||||
**mergerfs** is a
|
||||
[FUSE](https://en.wikipedia.org/wiki/Filesystem_in_Userspace) based
|
||||
[union filesystem](https://en.wikipedia.org/wiki/Union_mount) geared
|
||||
towards simplifying storage and management of files across numerous
|
||||
commodity storage devices. It is similar to **mhddfs**, **unionfs**,
|
||||
and **aufs**.
|
||||
|
||||
## Features
|
||||
|
||||
* Logically combine numerous filesystems/paths into a single
|
||||
mount point
|
||||
* Combine paths of the same or different filesystems
|
||||
* Ability to add or remove filesystems/paths without impacting the
|
||||
rest of the data
|
||||
* Unaffected by individual filesystem failure
|
||||
* Configurable file selection and creation placement
|
||||
* Works with filesystems of any size
|
||||
* Works with filesystems of almost any type
|
||||
* Ignore read-only filesystems when creating files
|
||||
* Hard link copy-on-write / CoW
|
||||
* Runtime configurable
|
||||
* Support for extended attributes (xattrs)
|
||||
* Support for file attributes (chattr)
|
||||
* Support for POSIX ACLs
|
||||
|
||||
|
||||
## Non-features
|
||||
|
||||
* Read/write overlay on top of read-only filesystem like OverlayFS
|
||||
* File whiteout
|
||||
* RAID like parity calculation
|
||||
* Redundancy
|
||||
* Splitting of files across branches
|
||||
|
||||
|
||||
## How it works
|
||||
|
||||
mergerfs logically merges multiple filesystem paths together. It acts
|
||||
as a proxy to the underlying filesystem paths. Combining the behaviors
|
||||
of some functions and being a selector for others.
|
||||
|
||||
When the contents of a directory are requested mergerfs combines the
|
||||
list of files from each directory, deduplicating entries, and returns
|
||||
that list.
|
||||
|
||||
When a file or directory is created a policy is first run to determine
|
||||
which branch will be selected for the creation.
|
||||
|
||||
For functions which change attributes or remove the file the behavior
|
||||
may be applied to all instances found.
|
||||
|
||||
Read more about [policies
|
||||
here](config/functions_categories_and_policies.md).
|
||||
|
||||
|
||||
### Visualization
|
||||
|
||||
```
|
||||
A + B = C
|
||||
/disk1 /disk2 /merged
|
||||
| | |
|
||||
+-- /dir1 +-- /dir1 +-- /dir1
|
||||
| | | | | |
|
||||
| +-- file1 | +-- file2 | +-- file1
|
||||
| | +-- file3 | +-- file2
|
||||
+-- /dir2 | | +-- file3
|
||||
| | +-- /dir3 |
|
||||
| +-- file4 | +-- /dir2
|
||||
| +-- file5 | |
|
||||
+-- file6 | +-- file4
|
||||
|
|
||||
+-- /dir3
|
||||
| |
|
||||
| +-- file5
|
||||
|
|
||||
+-- file6
|
||||
```
|
||||
@@ -0,0 +1,271 @@
|
||||
# Known Issues and Bugs
|
||||
|
||||
## mergerfs
|
||||
|
||||
### Supplemental user groups
|
||||
|
||||
Due to the overhead of
|
||||
[getgroups/setgroups](http://linux.die.net/man/2/setgroups) mergerfs
|
||||
utilizes a cache. This cache is opportunistic and per thread. Each
|
||||
thread will query the supplemental groups for a user when that
|
||||
particular thread needs to change credentials and will keep that data
|
||||
for the lifetime of the thread. This means that if a user is added to
|
||||
a group it may not be picked up without the restart of
|
||||
mergerfs. In the future this may be improved to allow a periodic or
|
||||
manual clearing of the cache.
|
||||
|
||||
While not a bug some users have found when using containers that
|
||||
supplemental groups defined inside the container don't work as
|
||||
expected. Since mergerfs lives outside the container it is querying
|
||||
the host's group database. Effectively containers have their own user
|
||||
and group definitions unless setup otherwise just as different systems
|
||||
would.
|
||||
|
||||
Users should mount in the host group file into the containers or use a
|
||||
standard shared user & groups technology like NIS or LDAP.
|
||||
|
||||
|
||||
### directory mtime is not being updated
|
||||
|
||||
Remember that the default policy for `getattr` is `ff`. The
|
||||
information for the first directory found will be returned. If it
|
||||
wasn't the directory which had been updated then it will appear
|
||||
outdated.
|
||||
|
||||
The reason this is the default is because any other policy would be
|
||||
more expensive and for many applications it is unnecessary. To always
|
||||
return the directory with the most recent mtime or a faked value based
|
||||
on all found would require a scan of all filesystems.
|
||||
|
||||
If you always want the directory information from the one with the
|
||||
most recent mtime then use the `newest` policy for `getattr`.
|
||||
|
||||
|
||||
### 'mv /mnt/pool/foo /mnt/disk1/foo' removes 'foo'
|
||||
|
||||
This is not a bug.
|
||||
|
||||
Run in verbose mode to better understand what's happening:
|
||||
|
||||
```
|
||||
$ mv -v /mnt/pool/foo /mnt/disk1/foo
|
||||
copied '/mnt/pool/foo' -> '/mnt/disk1/foo'
|
||||
removed '/mnt/pool/foo'
|
||||
$ ls /mnt/pool/foo
|
||||
ls: cannot access '/mnt/pool/foo': No such file or directory
|
||||
```
|
||||
|
||||
`mv`, when working across devices, is copying the source to target and
|
||||
then removing the source. Since the source **is** the target in this
|
||||
case, depending on the unlink policy, it will remove the just copied
|
||||
file and other files across the branches.
|
||||
|
||||
If you want to move files to one filesystem just copy them there and
|
||||
use mergerfs.dedup to clean up the old paths or manually remove them
|
||||
from the branches directly.
|
||||
|
||||
|
||||
### cached memory appears greater than it should be
|
||||
|
||||
Use `cache.files=off` and/or `dropcacheonclose=true`. See the section
|
||||
on [page caching](config/cache.md).
|
||||
|
||||
|
||||
### NFS clients returning ESTALE / Stale file handle
|
||||
|
||||
NFS generally does not like out of band changes. Take a look at the
|
||||
section on NFS in the [remote-filesystems](remote_filesystems.md) for
|
||||
more details.
|
||||
|
||||
|
||||
### rtorrent fails with ENODEV (No such device)
|
||||
|
||||
Be sure to set
|
||||
[cache.files=partial|full|auto-full|per-process](config/cache.md)
|
||||
or use Linux kernel v6.6 or above. rtorrent and some other
|
||||
applications use [mmap](http://linux.die.net/man/2/mmap) to read and
|
||||
write to files and offer no fallback to traditional methods.
|
||||
|
||||
|
||||
### Plex / Jellyfin doesn't work with mergerfs
|
||||
|
||||
It does. If you're trying to put the software's config / metadata /
|
||||
database on mergerfs you can't set
|
||||
[cache.files=off](config/cache.md) (unless you use Linux v6.6 or
|
||||
above) because Plex is using **sqlite3** with **mmap** enabled.
|
||||
|
||||
That said it is recommended that config and runtime files be stored on
|
||||
SSDs on a regular filesystem for performance reasons and if you are
|
||||
using HDDs in your pool to help limit spinup.
|
||||
|
||||
Other software that leverages **sqlite3** which require **mmap**
|
||||
includes Radarr, Sonarr, Lidarr.
|
||||
|
||||
It is recommended that you reach out to the developers of the software
|
||||
you're having troubles with and asking them to add a fallback to
|
||||
regular file IO when **mmap** is unavailable. It is not only more
|
||||
compatible and resilient but also can be more performant in certain
|
||||
situations.
|
||||
|
||||
If the issue is that quick scanning doesn't seem to pick up media then
|
||||
be sure to set `func.getattr=newest`, though generally, a full scan
|
||||
will pick up all media anyway.
|
||||
|
||||
|
||||
### When a program tries to move or rename a file it fails
|
||||
|
||||
Please read the docs regarding [rename and
|
||||
link](config/rename_and_link.md).
|
||||
|
||||
The problem is that many applications do not properly handle `EXDEV`
|
||||
errors which `rename` and `link` may return even though they are
|
||||
perfectly valid situations which do not indicate actual device,
|
||||
filesystem, or OS errors. The error will only be returned by mergerfs
|
||||
if using a path preserving policy as described in the policy section
|
||||
above. If you do not care about path preservation simply change the
|
||||
mergerfs policy to the non-path preserving version. For example: `-o
|
||||
category.create=mfs` Ideally the offending software would be fixed and
|
||||
it is recommended that if you run into this problem you contact the
|
||||
software's author and request proper handling of `EXDEV` errors.
|
||||
|
||||
|
||||
### my 32bit software has problems
|
||||
|
||||
Some software have problems with 64bit inode values. The symptoms can
|
||||
include EOVERFLOW errors when trying to list files. You can address
|
||||
this by setting `inodecalc` to one of the 32bit based algos as
|
||||
described in the relevant section.
|
||||
|
||||
### Moving files and directories fails with Samba
|
||||
|
||||
Workaround: Copy the file/directory and then remove the original
|
||||
rather than move.
|
||||
|
||||
This isn't an issue with Samba but some SMB clients. GVFS-fuse v1.20.3
|
||||
and prior (found in Ubuntu 14.04 among others) failed to handle
|
||||
certain error codes correctly. Particularly `STATUS_NOT_SAME_DEVICE`
|
||||
which comes from the `EXDEV` that is returned by `rename` when the
|
||||
call is crossing mount points. When a program gets an `EXDEV` it needs
|
||||
to explicitly take an alternate action to accomplish its goal. In the
|
||||
case of `mv` or similar it tries `rename` and on `EXDEV` falls back to
|
||||
a copying the file to the destination and deleting the source. In
|
||||
these older versions of GVFS-fuse if it received `EXDEV` it would
|
||||
translate that into `EIO`. This would cause `mv` or most any
|
||||
application attempting to move files around on that SMB share to fail
|
||||
with a generic IO error.
|
||||
|
||||
[GVFS-fuse v1.22.0](https://bugzilla.gnome.org/show_bug.cgi?id=734568)
|
||||
and above fixed this issue but a large number of systems use the older
|
||||
release. On Ubuntu, the version can be checked by issuing `apt-cache
|
||||
showpkg gvfs-fuse`. Most distros released in 2015 seem to have the
|
||||
updated release and will work fine but older systems may
|
||||
not. Upgrading gvfs-fuse or the distro in general will address the
|
||||
problem.
|
||||
|
||||
In Apple's MacOSX 10.9 they replaced Samba (client and server) with
|
||||
their own product. It appears their new client does not handle
|
||||
`EXDEV` either and responds similarly to older releases of gvfs on
|
||||
Linux.
|
||||
|
||||
|
||||
### Trashing files occasionally fails
|
||||
|
||||
This is the same issue as with Samba. `rename` returns `EXDEV` (in our
|
||||
case that will really only happen with path preserving policies like
|
||||
`epmfs`) and the software doesn't handle the situation well. This is
|
||||
unfortunately a common failure of software which moves files
|
||||
around. The standard indicates that an implementation **MAY** choose
|
||||
to support non-user home directory trashing of files (which is a
|
||||
**MUST**). The implementation **MAY** also support "top directory
|
||||
trashes" which many probably do.
|
||||
|
||||
To create a `$topdir/.Trash` directory as defined in the standard use
|
||||
the [mergerfs-tools](https://github.com/trapexit/mergerfs-tools) tool
|
||||
`mergerfs.mktrash`.
|
||||
|
||||
|
||||
## FUSE and Linux kernel
|
||||
|
||||
There have been a number of kernel issues / bugs over the years which
|
||||
mergerfs has run into. Here is a list of them for reference and
|
||||
posterity.
|
||||
|
||||
|
||||
### NFS and EIO errors
|
||||
|
||||
[https://lore.kernel.org/linux-fsdevel/20240228160213.1988854-1-mszeredi@redhat.com/T/](https://lore.kernel.org/linux-fsdevel/20240228160213.1988854-1-mszeredi@redhat.com/T/)
|
||||
|
||||
Over the years some users have reported that while exporting mergerfs
|
||||
via NFS, after significant filesystem activity, not only will the NFS
|
||||
client start returning ESTALE and EIO errors but mergerfs itself would
|
||||
start returning EIO errors. The problem was that no one could
|
||||
reliability reproduce the issue. After a string of reports in late
|
||||
2023 and early 2024 more investigation was done.
|
||||
|
||||
In Linux 5.14 new validation was put into FUSE which caught a few
|
||||
invalid situations and would tag a FUSE node as invalid if a check
|
||||
failed. Such checks include invalid file type, changing of type from
|
||||
one request to another, a size greater than 63bit, and the generation
|
||||
of a inode changing while in use.
|
||||
|
||||
What happened was that mergerfs was using a different fixed, non-zero
|
||||
value for the generation of all nodes as it was suggested that unique
|
||||
inode + generation pairs are needed for proper integration with
|
||||
NFS. That non-zero value was being sent back to the kernel when a
|
||||
lookup request was made for root. The reason this was hard to track
|
||||
down was because NFS almost uniquely uses an API which can lead to a
|
||||
lookup of the root node that simply won't happen under normal
|
||||
workloads and usage. And that lookup will only happen if child nodes
|
||||
of the root were forgotten but NFS still had a handle to that node and
|
||||
later asked for details about it. It would trigger a set of requests
|
||||
to lookup info on those nodes.
|
||||
|
||||
This wasn't a bug in FUSE but mergerfs. However, the incorrect
|
||||
behavior of mergerfs lead to FUSE behave in an unexpected and
|
||||
incorrect manner. It would issue a lookup of the "parent of a child of
|
||||
the root" and mergerfs would send the invalid generation value. As a
|
||||
result the kernel would mark the root node as "bad" which would then
|
||||
trigger the kernel to issue a "forget root" message. In between those
|
||||
it would issue a request for the parent of the root... which doesn't
|
||||
exist.
|
||||
|
||||
So the kernel was doing two invalid things. Requesting the parent of
|
||||
the root and then when that failed issuing a forget for the
|
||||
root. These led to chasing after the wrong possible causes.
|
||||
|
||||
The change was for FUSE to revert the marking of root node bad if the
|
||||
generation is non-zero and warn about it. It will mark the node bad
|
||||
but not unhash/forget/remove it.
|
||||
|
||||
mergerfs in v2.40.1 ensures that generation for root is always 0 on
|
||||
lookup which should work across any kernel version.
|
||||
|
||||
|
||||
### Truncated files
|
||||
|
||||
This was a bug with `mmap` and `FUSE` on 32bit platforms. Should be fixed in all LTS releases.
|
||||
|
||||
* [https://marc.info/?l=linux-fsdevel&m=155550785230874&w=2](https://marc.info/?l=linux-fsdevel&m=155550785230874&w=2)
|
||||
|
||||
|
||||
### Crashing on OpenVZ
|
||||
|
||||
There was a bug in the OpenVZ kernel with regard to how it handles `ioctl` calls. It was making invalid requests which would lead to crashes due to mergerfs not expecting them.
|
||||
|
||||
* [https://bugs.openvz.org/browse/OVZ-7145](https://bugs.openvz.org/browse/OVZ-7145)
|
||||
* [https://www.mail-archive.com/devel@openvz.org/msg37096.html](https://www.mail-archive.com/devel@openvz.org/msg37096.html)
|
||||
|
||||
|
||||
### Really bad mmap performance
|
||||
|
||||
There was a bug in caching which affects overall performance of `mmap` through `FUSE` in Linux 4.x kernels. It is fixed in 4.4.10 and 4.5.4.
|
||||
|
||||
* [https://lkml.org/lkml/2016/3/16/260](https://lkml.org/lkml/2016/3/16/260)
|
||||
* [https://lkml.org/lkml/2016/5/11/59](https://lkml.org/lkml/2016/5/11/59)
|
||||
|
||||
|
||||
### Heavy load and memory pressure leads to kernel panic
|
||||
|
||||
* [https://lkml.org/lkml/2016/9/14/527](https://lkml.org/lkml/2016/9/14/527)
|
||||
* [https://lkml.org/lkml/2016/10/4/1](https://lkml.org/lkml/2016/10/4/1)
|
||||
* [https://www.theregister.com/2016/10/05/linus_torvalds_admits_buggy_crap_made_it_into_linux_48/](https://www.theregister.com/2016/10/05/linus_torvalds_admits_buggy_crap_made_it_into_linux_48/)
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 41 KiB |
@@ -0,0 +1,71 @@
|
||||
# Media and Publicity
|
||||
|
||||
## Tutorials / Articles
|
||||
|
||||
- 2016-02-02 - [Linuxserver.io: The Perfect Media Server 2016](https://blog.linuxserver.io/2016/02/02/the-perfect-media-server-2016/)
|
||||
- 2016-08-31 - [ZackReed.me: Mergerfs – another good option to pool your SnapRAID disks](https://zackreed.me/mergerfs-another-good-option-to-pool-your-snapraid-disks/)
|
||||
- 2016-11-06 - [Linuxserver.io: Revisiting the HP ProLiant Gen8 G1610T Microserver](https://blog.linuxserver.io/2016/11/06/revisiting-the-hp-proliant-gen8-g1610t-microserver/)
|
||||
- 2017-01-17 - [Setting up mergerfs on JBOD's (or a poor mans storage array)](http://corywestropp.com/develop/articles/setting-up-mergerfs/)
|
||||
- 2017-06-24 - [Linuxserver.io: The Perfect Media Server 2017](https://blog.linuxserver.io/2017/06/24/the-perfect-media-server-2017/)
|
||||
- 2018-02-19 - [Teknophiles: Disk Pooling in Linux with mergerFS](https://web.archive.org/web/20210324184857/https://www.teknophiles.com/2018/02/19/disk-pooling-in-linux-with-mergerfs/)
|
||||
- 2018-02-20 - [Fortes.com: Using Rclone and MergerFS together across drives](https://fortes.com/2018/rclone-and-mergerfs/)
|
||||
- 2019-02-10 - [Medium: Migrating from ZFS to MergerFS and SnapRAID at home](https://medium.com/@pascal.brokmeier/migrating-from-zfs-to-mergerfs-and-snapraid-at-home-89c45fd5db02)
|
||||
- 2019-04-24 - [MichaelXander.com: DIY NAS with OMV, SnapRAID, MergerFS, and Disk Encryption](https://michaelxander.com/diy-nas/)
|
||||
- 2019-07-16 - [Linuxserver.io: The Perfect Media Server - 2019 Edition](https://blog.linuxserver.io/2019/07/16/perfect-media-server-2019/)
|
||||
- 2019-09-10 - [Rclone VFS and MergerFS Setup](https://docs.usbx.me/books/rclone/page/rclone-vfs-and-mergerfs-setup)
|
||||
- 2019-12-20 - [NetworkShinobi.com: SnapRAID and MergerFS on OpenMediaVault](https://www.networkshinobi.com/snapraid-and-mergerfs-on-openmediavault/)
|
||||
- 2020-01-14 - [Brandon Rozek's Blog](https://brandonrozek.com/blog/mergerfs/)
|
||||
- 2020-02-14 - [SelfHostedHome.com: Combining Different Sized Drives with mergerfs and SnapRAID](https://selfhostedhome.com/combining-different-sized-drives-with-mergerfs-and-snapraid/)
|
||||
- 2020-05-01 - [FedoraMagazine.org: Using mergerfs to increase your virtual storage](https://fedoramagazine.org/using-mergerfs-to-increase-your-virtual-storage/)
|
||||
- 2020-08-20 - [Setting up Rclone, Mergerfs and Crontab for automated cloud storage](https://bytesized-hosting.com/pages/setting-up-rclone-mergerfs-and-crontab-for-automated-cloud-storage)
|
||||
- 2020-11-22 - [Introducing… MergerFS – My FREE UNRAID alternative](https://supertechfreaks.com/introducing-mergerfs-free-unraid-alternative/)
|
||||
- 2020-12-30 - [Perfect Media Server](https://perfectmediaserver.com) (a new site with docs fully fleshing out the 'Perfect Media Server' blog series)
|
||||
- 2021-10-31 - [Better Home Storage: MergerFS + SnapRAID on OpenMediaVault](https://blog.sakuragawa.moe/better-home-storage-mergerfs-snapraid-on-openmediavault/)
|
||||
- 2021-11-28 - [Linux Magazine: Come Together - Merging file systems for a simple NAS with MergerFS](https://www.linux-magazine.com/Issues/2022/254/MergerFS)
|
||||
- 2022-06-04 - [MergerFS + SnapRaid Study](https://crashlaker.github.io/2022/06/04/mergerfs_+_snapraid_study.html)
|
||||
- 2022-12-31 - [Merge Storages in CasaOS: A secret beta feature you know now](https://blog.casaos.io/blog/13.html)
|
||||
- 2023-02-03 - [(MergerFS + SnapRAID) is the new RAID 5](https://thenomadcode.tech/mergerfs-snapraid-is-the-new-raid-5)
|
||||
- 2024-02-07 - [Designing & Deploying MANS - A Hybrid NAS Approach with SnapRAID, MergerFS, and OpenZFS](https://blog.muffn.io/posts/part-3-mini-100tb-nas)
|
||||
|
||||
## Videos
|
||||
|
||||
- 2017-06-23 - [Alex Kretzschmar: Part 1 - Perfect Media Server 2017 - Introduction](https://www.youtube.com/watch?v=L5MH8q3lmmk)
|
||||
- 2017-06-24 - [Alex Kretzschmar: Part 2 - Perfect Media server 2017 - Installing Debian 9 Stretch](https://www.youtube.com/watch?v=YpVVYRN_L_A)
|
||||
- 2017-06-24 - [Alex Kretzschmar: Part 3 - Perfect Media Server 2017 - Install MergerFS and setting up your drives](https://www.youtube.com/watch?v=tbCMfm-jJ5Y)
|
||||
- 2017-06-24 - [Alex Kretzschmar: Part 4 - Perfect Media Server 2017 - Installing Docker](https://www.youtube.com/watch?v=WYI32kx4hPE)
|
||||
- 2017-06-24 - [Alex Kretzschmar: Part 5 - Perfect Media Server 2017 - Installing and Automating SnapRAID](https://www.youtube.com/watch?v=Ir5ZsUIbHXA)
|
||||
- 2017-06-24 - [Alex Kretzschmar: Part 6 - Perfect Media Server 2017 -Turning your server into a NAS with Samba and NFS](https://www.youtube.com/watch?v=1hVdWq758ZQ)
|
||||
- 2017-06-24 - [Alex Kretzschmar: Part 7 - Perfect Media Server 2017 - Managing your apps with docker-compose](https://www.youtube.com/watch?v=aI2rdw7_AmE)
|
||||
- 2017-06-24 - [Alex Kretzschmar: Part 8 - Perfect Media Server 2017 - Manging your server using a web UI (Cockpit and Portainer)](https://www.youtube.com/watch?v=aLyTWdzDiCg)
|
||||
- 2018-04-24 - [ElectronicsWizardy: How to setup a Linux Fileserver with Snapraid and Mergerfs Re-Export](https://www.youtube.com/watch?v=D2Klx-X7pFo)
|
||||
- 2019-03-01 - [Snapraid and Unionfs: Advanced Array Options on Openmediavault (Better than ZFS and Unraid)](https://www.youtube.com/watch?v=FYkdPyCt5FU)
|
||||
- 2019-03-22 - [Gamexplicit: The Perfect Plex Media Server 2019! Part 1 (Hardware)](https://www.youtube.com/watch?v=rJIRPhM2WcE)
|
||||
- 2019-05-13 - [Gamexplicit: The Perfect Plex Media Server 2019! Part 2 (Ubuntu Server 18.04.2 LTS)](https://www.youtube.com/watch?v=aLyTWdzDiCg)
|
||||
- 2019-05-20 - [Gamexplicit: The Perfect Plex Media Server 2019! Part 3 (SnapRaid, Samba, Plex)](https://www.youtube.com/watch?v=uW5y43XC-BI)
|
||||
- 2020-08-23 - [Installing OpenMediaVault and SnapRAID and UnionFS (mergerfs)](https://www.youtube.com/watch?v=nDvzXM8UjAI)
|
||||
- 2021-06-07 - [I ditched TrueNAS for MergerFS - Chia Plot Storage](https://www.youtube.com/watch?v=tpqFywkbZa4)
|
||||
- 2021-08-03 - [Install and configure mergerfs to merge more than one folder in the same place](https://www.youtube.com/watch?v=69zcqEy1674)
|
||||
- 2021-08-10 - [Instalando e configurando mergerfs para unir mais de uma pasta no mesmo lugar](https://www.youtube.com/watch?v=-RLxbBNBWhU)
|
||||
- 2021-08-13 - [Let's Convert an Old Laptop to a NAS - What you should do](https://www.youtube.com/watch?v=F1v-TSbOymI)
|
||||
- 2021-08-17 - [How to Combine Multiple Disks as One by using MergerFS | Ubuntu 20.04 LTS](https://www.youtube.com/watch?v=9e46pz5Seo4)
|
||||
- 2021-08-20 - [Vamos converter um Laptop antigo para um NAS – O que você deve fazer](https://www.youtube.com/watch?v=q8EK9vWCRTc)
|
||||
- 2021-10-29 - [Unlimited space for your Plex using Rclone to connect to your Cloud](https://www.youtube.com/watch?v=ghGconyrF3M)
|
||||
- 2022-12-01 - [Make Your Home Server Go FAST! SSD Caching, 10Gbit Networking, etc.](https://www.youtube.com/watch?v=eRfqC_q3lkM&t=784s)
|
||||
- 2022-12-07 - [Best RAID for mixed drive sizes. Unraid vs BTRFS vs Snapraid+Mergerfs vs Storage spaces.](https://www.youtube.com/watch?v=NQJkTiLXfgs)
|
||||
- 2023-02-21 - [MergerFS + SnapRAID : Forget about RAID 5 in your Home Server !](https://www.youtube.com/watch?v=tX5MA-c6Qq4)
|
||||
- 2023-06-26 - [How to install and setup MergerFS](https://www.youtube.com/watch?v=n7piuhTXeG4)
|
||||
- 2023-07-31 - [How to recover a dead drive using Snapraid](https://www.youtube.com/watch?v=fmuiRLPcuJE)
|
||||
- 2024-01-05 - [OpenMediaVault MergerFS Tutorial (Portuguese)](https://www.youtube.com/watch?v=V6Yw86dRUPQ)
|
||||
- 2024-11-15 - [Meu servidor NAS - Parte 18: Recuperando um HD, recuperando o MergerFS e os próximos passos do NAS!](https://www.youtube.com/watch?v=5fy98kPzE3s)
|
||||
|
||||
## Podcasts
|
||||
|
||||
- 2019-11-04 - [Jupiter Extras: A Chat with mergerfs Developer Antonio Musumeci | Jupiter Extras 28](https://www.youtube.com/watch?v=VmJUAyyhSPk)
|
||||
- 2019-11-07 - [Jupiter Broadcasting: ZFS Isn’t the Only Option | Self-Hosted 5](https://www.youtube.com/watch?v=JEW7UuKhMJ8)
|
||||
- 2023-10-08 - [Self Hosted Episode 105 - Sleeper Storage Technology](https://selfhosted.show/105)
|
||||
|
||||
## Social Media
|
||||
|
||||
- [Reddit](https://www.reddit.com/search/?q=mergerfs&sort=new)
|
||||
- [Twitter](https://twitter.com/search?q=mergerfs&src=spelling_expansion_revert_click&f=live)
|
||||
- [YouTube](https://www.youtube.com/results?search_query=mergerfs&sp=CAI%253D)
|
||||
@@ -0,0 +1,43 @@
|
||||
# Tweaking Performance
|
||||
|
||||
mergerfs is at its is a proxy and therefore its theoretical max
|
||||
performance is that of the underlying devices. However, given it is a
|
||||
FUSE based filesystem working from userspace there is an increase in
|
||||
overhead relative to kernel based solutions. That said the performance
|
||||
can match the theoretical max but it depends greatly on the system's
|
||||
configuration. Especially when adding network filesystems into the mix
|
||||
there are many variables which can impact performance. Device speeds
|
||||
and latency, network speeds and latency, concurrency and parallel
|
||||
limits of the hardware, read/write sizes, etc.
|
||||
|
||||
While some settings can impact performance they are all **functional**
|
||||
in nature. Meaning they change mergerfs' behavior in some way. As a
|
||||
result there is no such thing as a "performance mode".
|
||||
|
||||
If you're having performance issues please look over the suggestions
|
||||
below and the [benchmarking section.](benchmarking.md)
|
||||
|
||||
NOTE: Be sure to [read about these features](config/options.md) before
|
||||
changing them to understand how functionality will change.
|
||||
|
||||
* test theoretical performance using `nullrw` or mounting a ram disk
|
||||
* increase readahead: `readahead=1024`
|
||||
* disable `security_capability` and/or `xattr`
|
||||
* increase cache timeouts `cache.attr`, `cache.entry`, `cache.negative_entry`
|
||||
* enable (or disable) page caching (`cache.files`)
|
||||
* enable `parallel-direct-writes`
|
||||
* enable `cache.writeback`
|
||||
* enable `cache.statfs`
|
||||
* enable `cache.symlinks`
|
||||
* enable `cache.readdir`
|
||||
* change the number of threads available
|
||||
* disable `posix_acl`
|
||||
* disable `async_read`
|
||||
* use `symlinkify` if your data is largely static and read-only
|
||||
* use tiered cache devices
|
||||
* use LVM and LVM cache to place a SSD in front of your HDDs
|
||||
|
||||
If you come across a setting that significantly impacts performance
|
||||
please [contact trapexit](support.md) so he may investigate further. Please test
|
||||
both against your normal setup, a singular branch, and with
|
||||
`nullrw=true`
|
||||
@@ -0,0 +1,170 @@
|
||||
# Project Comparisons
|
||||
|
||||
## mhddfs
|
||||
|
||||
* [https://romanrm.net/mhddfs](https://romanrm.net/mhddfs)
|
||||
|
||||
mhddfs had not been updated in over a decade and has known stability
|
||||
and security issues. mergerfs provides a super set of mhddfs' features
|
||||
and offers better performance. In fact, as of 2020, the author of
|
||||
mhddfs has [moved to using
|
||||
mergerfs.](https://romanrm.net/mhddfs#update)
|
||||
|
||||
Below is an example of mhddfs and mergerfs setup to work similarly.
|
||||
|
||||
`mhddfs -o mlimit=4G,allow_other /mnt/drive1,/mnt/drive2 /mnt/pool`
|
||||
|
||||
`mergerfs -o minfreespace=4G,category.create=ff /mnt/drive1:/mnt/drive2 /mnt/pool`
|
||||
|
||||
|
||||
## aufs
|
||||
|
||||
* [https://aufs.sourceforge.net](https://aufs.sourceforge.net)
|
||||
* [https://en.wikipedia.org/wiki/Aufs](https://en.wikipedia.org/wiki/Aufs)
|
||||
|
||||
While aufs still is maintained it failed to be included in the
|
||||
mainline kernel and is no longer available in most Linux distros
|
||||
making it harder to get installed for the average user.
|
||||
|
||||
While aufs can often offer better peak performance due to being
|
||||
primarily kernel based, mergerfs provides more configurability and is
|
||||
generally easier to use. mergerfs however does not offer the overlay /
|
||||
copy-on-write (CoW) features which aufs has.
|
||||
|
||||
|
||||
## unionfs
|
||||
|
||||
* [https://unionfs.filesystems.org](https://unionfs.filesystems.org)
|
||||
|
||||
unionfs for Linux is a "stackable unification file system" which
|
||||
functions like many other union filesystems. unionfs has not been
|
||||
maintained and was last released for Linux v3.14 back in 2014.
|
||||
|
||||
Documentation is sparse so a comparison of features is not possible
|
||||
but given the lack of maintenance and support for modern kernels there
|
||||
is little reason to consider it as a solution.
|
||||
|
||||
|
||||
## unionfs-fuse
|
||||
|
||||
* [https://github.com/rpodgorny/unionfs-fuse](https://github.com/rpodgorny/unionfs-fuse)
|
||||
|
||||
unionfs-fuse is more like unionfs, aufs, and overlayfs than mergerfs
|
||||
in that it offers overlay / copy-on-write (CoW) features. If you're
|
||||
just looking to create a union of filesystems and want flexibility in
|
||||
file/directory placement then mergerfs offers that whereas
|
||||
unionfs-fuse is more for overlaying read/write filesystems over
|
||||
read-only ones.
|
||||
|
||||
Since unionfs-fuse, as the name suggests, is a FUSE based technology
|
||||
it can be used without elevated privileges that kernel solutions such
|
||||
as unionfs, aufs, and overlayfs require.
|
||||
|
||||
|
||||
## overlayfs
|
||||
|
||||
* [https://docs.kernel.org/filesystems/overlayfs.html](https://docs.kernel.org/filesystems/overlayfs.html)
|
||||
|
||||
overlayfs is effectively the successor to unionfs, unionfs-fuse, and
|
||||
aufs and is widely used by Linux container platforms such as Docker and
|
||||
Podman. It was developed and is maintained by the same developer who
|
||||
created FUSE.
|
||||
|
||||
If your use case is layering a writable filesystem on top of read-only
|
||||
filesystems then you should look first to overlayfs. Its feature set
|
||||
however is very different from mergerfs and solve different problems.
|
||||
|
||||
|
||||
## RAID0, JBOD, SPAN, drive concatenation, striping
|
||||
|
||||
* [RAID0](https://en.wikipedia.org/wiki/Standard_RAID_levels#RAID_0)
|
||||
* [JBOD](https://en.wikipedia.org/wiki/Non-RAID_drive_architectures#JBOD)
|
||||
* [SPAN](https://en.wikipedia.org/wiki/Non-RAID_drive_architectures#Concatenation_(SPAN,_BIG))
|
||||
* [striping](https://en.wikipedia.org/wiki/Data_striping)
|
||||
|
||||
These are block device technologies which in some form aggregate
|
||||
devices into what appears to be a singular device on which a
|
||||
traditional filesystem can be used. The filesystem has no
|
||||
understanding of the underlying block layout and should one of those
|
||||
underlying devices fail or be removed the filesystem will be missing
|
||||
that chunk which could contain critical information and the whole
|
||||
filesystem may become unrecoverable. Even if the data from the
|
||||
filesystem is recoverable it will take using specialized tooling to do
|
||||
so.
|
||||
|
||||
In contrast, with mergerfs you can format devices as one normally
|
||||
would or take existing filesystems and then combine them in a pool to
|
||||
aggregate their storage. The failure of any one device will have no
|
||||
impact on the other devices. The downside to mergerfs' technique is
|
||||
the fact you don't actually have contiguous space as large as if you
|
||||
used those other technologies. Meaning you can't create a file greater
|
||||
than 1TB on a pool of 2 1TB filesystems.
|
||||
|
||||
|
||||
## UnRAID
|
||||
|
||||
* [https://unraid.net](https://unraid.net)
|
||||
|
||||
UnRAID is a full OS and offers a (FUSE based?) filesystem which
|
||||
provides a union of filesystems like mergerfs but with the addition of
|
||||
live parity calculation and storage. Outside parity calculations
|
||||
mergerfs offers more features and due to the lack of real-time parity
|
||||
calculation can have higher peak performance. Some users also prefer
|
||||
an open source solution.
|
||||
|
||||
For semi-static data mergerfs + [SnapRaid](http://www.snapraid.it)
|
||||
provides a similar, but not real-time, solution.
|
||||
|
||||
|
||||
## ZFS
|
||||
|
||||
* [https://en.wikipedia.org/wiki/ZFS](https://en.wikipedia.org/wiki/ZFS)
|
||||
|
||||
mergerfs is very different from ZFS. mergerfs is intended to provide
|
||||
flexible pooling of arbitrary filesystems (local or remote), of
|
||||
arbitrary sizes, and arbitrary filesystems. Particularly in `write
|
||||
once, read many` use cases such as bulk media storage. Where data
|
||||
integrity and backup is managed in other ways. In those use cases ZFS
|
||||
can introduce a number of costs and limitations as described
|
||||
[here](http://louwrentius.com/the-hidden-cost-of-using-zfs-for-your-home-nas.html),
|
||||
[here](https://markmcb.com/2020/01/07/five-years-of-btrfs/), and
|
||||
[here](https://utcc.utoronto.ca/~cks/space/blog/solaris/ZFSWhyNoRealReshaping).
|
||||
|
||||
|
||||
## StableBit's DrivePool
|
||||
|
||||
* [https://stablebit.com](https://stablebit.com)
|
||||
|
||||
DrivePool works only on Windows so not as common an alternative as
|
||||
other Linux solutions. If you want to use Windows then DrivePool is a
|
||||
good option. Functionally the two projects work a bit
|
||||
differently. DrivePool always writes to the filesystem with the most
|
||||
free space and later rebalances. mergerfs does not currently offer
|
||||
rebalance but chooses a branch at file/directory create
|
||||
time. DrivePool's rebalancing can be done differently in any directory
|
||||
and has file pattern matching to further customize the
|
||||
behavior. mergerfs, not having rebalancing does not have these
|
||||
features, but similar features are planned for mergerfs v3. DrivePool
|
||||
has builtin file duplication which mergerfs does not natively support
|
||||
(but can be done via an external script.)
|
||||
|
||||
There are a lot of misc differences between the two projects but most
|
||||
features in DrivePool can be replicated with external tools in
|
||||
combination with mergerfs.
|
||||
|
||||
Additionally, DrivePool is a closed source commercial product vs
|
||||
mergerfs a ISC licensed open source project.
|
||||
|
||||
|
||||
## Plan9 binds
|
||||
|
||||
* [https://en.wikipedia.org/wiki/Plan_9_from_Bell_Labs#Union_directories_and_namespaces](https://en.wikipedia.org/wiki/Plan_9_from_Bell_Labs#Union_directories_and_namespaces)
|
||||
|
||||
Plan9 has the native ability to bind multiple paths/filesystems
|
||||
together to create a setup similar to simplified union
|
||||
filesystem. Such bind mounts choose files in a "first found" in the
|
||||
order they are listed similar to mergerfs' `ff` policy. Similar, when
|
||||
creating a file it will be created on the first directory in the
|
||||
union.
|
||||
|
||||
Plan 9 isn't a widely used OS so this comparison is mostly academic.
|
||||
@@ -0,0 +1,189 @@
|
||||
# QuickStart
|
||||
|
||||
## Install
|
||||
|
||||
First ensure you have the [latest version installed](setup/installation.md).
|
||||
|
||||
|
||||
## Configuration
|
||||
|
||||
mergerfs has many options and effectively all of them are functional
|
||||
in nature. What that means is that there is no "best" or "fastest"
|
||||
configuration. No "make faster" options. Everything changes
|
||||
behavior. Sometimes those changes in behavior affect performance.
|
||||
|
||||
That said: If you don't already know that you have a special use case
|
||||
then use one of the following option sets as it will cover most casual
|
||||
usecases.
|
||||
|
||||
### You use Linux v6.6 or above
|
||||
|
||||
* cache.files=off
|
||||
* category.create=mfs
|
||||
* dropcacheonclose=false
|
||||
|
||||
In previous versions of Linux it was unable to support `mmap` if page
|
||||
caching was disabled (ie: `cache.files=off`). However, it now will
|
||||
enable page caching if needed for a particular file if mmap is
|
||||
requested.
|
||||
|
||||
`mmap` is needed by certain software to read and write to a
|
||||
file. However, many software could work without it and fail to have
|
||||
proper error handling. Many programs that use sqlite3 will require
|
||||
`mmap` despite sqlite3 working perfectly fine without it (and in some
|
||||
cases can be more performant with regular file IO.)
|
||||
|
||||
|
||||
### You use Linux v6.5 or below
|
||||
|
||||
#### You need `mmap` (used by rtorrent and many sqlite3 base software)
|
||||
|
||||
* cache.files=auto-full
|
||||
* category.create=mfs
|
||||
* dropcacheonclose=true
|
||||
|
||||
|
||||
#### You don't need `mmap`
|
||||
|
||||
* cache.files=off
|
||||
* category.create=mfs
|
||||
* dropcacheonclose=false
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
### Command Line
|
||||
|
||||
```
|
||||
mergerfs -o cache.files=off,dropcacheonclose=false,category.create=mfs /mnt/hdd0:/mnt/hdd1 /media
|
||||
```
|
||||
|
||||
|
||||
### /etc/fstab
|
||||
|
||||
```
|
||||
/mnt/hdd0:/mnt/hdd1 /media mergerfs cache.files=off,dropcacheonclose=false,category.create=mfs 0 0
|
||||
```
|
||||
|
||||
### /etc/fstab w/ config file
|
||||
|
||||
For more complex setups it can be useful to separate out the config.
|
||||
|
||||
|
||||
#### /etc/fstab
|
||||
|
||||
```
|
||||
/etc/mergerfs/branches/media/* /media mergerfs config=/etc/mergerfs/config/media.ini
|
||||
```
|
||||
|
||||
|
||||
#### /etc/mergerfs/config/media.ini
|
||||
|
||||
```ini title="media.ini" linenums="1"
|
||||
cache.files=off
|
||||
category.create=mfs
|
||||
dropcacheonclose=false
|
||||
```
|
||||
|
||||
#### /etc/mergerfs/branches/media/
|
||||
|
||||
Create a bunch of symlinks to point to the branch. mergerfs will
|
||||
resolve the symlinks and use the real path.
|
||||
|
||||
`ls -lh /etc/mergerfs/branches/media/*`
|
||||
|
||||
```text
|
||||
lrwxrwxrwx 1 root root 21 Aug 4 2023 hdd00 -> /mnt/hdd/hdd00
|
||||
lrwxrwxrwx 1 root root 21 Aug 4 2023 hdd01 -> /mnt/hdd/hdd01
|
||||
lrwxrwxrwx 1 root root 21 Aug 4 2023 hdd02 -> /mnt/hdd/hdd02
|
||||
lrwxrwxrwx 1 root root 21 Aug 4 2023 hdd03 -> /mnt/hdd/hdd03
|
||||
```
|
||||
|
||||
### systemd (simple)
|
||||
|
||||
`/etc/systemd/system/mergerfs-media.service`
|
||||
|
||||
```systemd title="mergerfs-media.service" linenums="1"
|
||||
[Unit]
|
||||
Description=mergerfs /media service
|
||||
After=local-fs.target network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
KillMode=none
|
||||
ExecStart=/usr/bin/mergerfs \
|
||||
-f \
|
||||
-o cache.files=off \
|
||||
-o category.create=mfs \
|
||||
-o dropcacheonclose=false \
|
||||
/mnt/hdd0:/mnt/hdd1 \
|
||||
/media
|
||||
ExecStop=/bin/fusermount -uz /media
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
```
|
||||
|
||||
### systemd (w/ setup script)
|
||||
|
||||
Since it isn't well documented otherwise: if you wish to do some setup before
|
||||
you mount mergerfs follow this example.
|
||||
|
||||
#### setup-for-mergerfs
|
||||
|
||||
`/usr/local/bin/setup-for-mergerfs`
|
||||
|
||||
```shell title="setup-for-mergerfs" linenums="1"
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# Perform setup
|
||||
/bin/sleep 10
|
||||
|
||||
# Report back to systemd that things are ready
|
||||
/bin/systemd-notify --ready
|
||||
```
|
||||
|
||||
#### setup-for-mergerfs.service
|
||||
|
||||
`/etc/systemd/system/setup-for-mergerfs.service`
|
||||
|
||||
```systemd title="setup-for-mergerfs.service" linenums="1"
|
||||
[Unit]
|
||||
Description=mergerfs setup service
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/usr/local/bin/setup-for-mergerfs
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
```
|
||||
|
||||
#### mergerfs-media.service
|
||||
|
||||
`/etc/systemd/system/mergerfs-media.service`
|
||||
|
||||
```systemd title="mergerfs-media.service" linenums="1"
|
||||
[Unit]
|
||||
Description=mergerfs /media service
|
||||
Requires=setup-for-mergerfs.service
|
||||
After=local-fs.target network.target prepare-for-mergerfs.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
KillMode=none
|
||||
ExecStart=/usr/bin/mergerfs \
|
||||
-f \
|
||||
-o cache.files=off \
|
||||
-o category.create=mfs \
|
||||
-o dropcacheonclose=false \
|
||||
/mnt/hdd0:/mnt/hdd1 \
|
||||
/media
|
||||
ExecStop=/bin/fusermount -uz /media
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
```
|
||||
@@ -0,0 +1,56 @@
|
||||
# Related Projects
|
||||
|
||||
## Projects using mergerfs
|
||||
|
||||
* [Lakka.tv](https://lakka.tv/): A turnkey software emulation Linux
|
||||
distribution. Used to pool user and local storage. Also includes my
|
||||
other project [Opera](https://retroarch.com/). A 3DO emulator.
|
||||
* [OpenMediaVault](https://www.openmediavault.org): A network attached
|
||||
storage (NAS) solution based on Debian Linux. They provide plugins
|
||||
to manage mergerfs.
|
||||
* [CasaOS](https://casaos.io): "A simple, easy to use, elegant open
|
||||
source home cloud system." Has added initial integration with
|
||||
mergerfs to create pools from existing filesystems.
|
||||
* [ZimaOS](https://github.com/IceWhaleTech/zimaos-rauc): A more
|
||||
commercially focused NAS OS by the authors of CasaOS at [Ice
|
||||
Whale](https://www.zimaboard.com/).
|
||||
* [Cosmos Cloud](https://cosmos-cloud.io/): Cosmos "take the chore out
|
||||
of selfhosting, with automated maintenance and fully secured setup
|
||||
out of the box. It even integrates to your existing setup."
|
||||
|
||||
|
||||
## Software and services commonly used with mergerfs
|
||||
|
||||
* [snapraid](https://www.snapraid.it/)
|
||||
* [rclone](https://rclone.org/)
|
||||
* rclone's [union](https://rclone.org/union/) feature is based on
|
||||
mergerfs policies
|
||||
* [ZFS](https://openzfs.org/): Common to use ZFS w/ mergerfs
|
||||
* [UnRAID](https://unraid.net): While UnRAID has its own union
|
||||
filesystem it isn't uncommon to see UnRAID users leverage mergerfs
|
||||
given the differences in the technologies.
|
||||
* For a time there were a number of Chia miners recommending mergerfs
|
||||
* [cloudboxes.io](https://cloudboxes.io/wiki/how-to/apps/set-up-mergerfs-using-ssh)
|
||||
|
||||
|
||||
## Distributions including mergerfs
|
||||
|
||||
mergerfs can be found in the
|
||||
[repositories](https://pkgs.org/download/mergerfs) of [many
|
||||
Linux](https://repology.org/project/mergerfs/versions) (and maybe
|
||||
FreeBSD) distributions.
|
||||
|
||||
Note: Any non-rolling release based distro is likely to have
|
||||
out-of-date versions.
|
||||
|
||||
* [Debian](https://packages.debian.org/bullseye/mergerfs)
|
||||
* [Ubuntu](https://launchpad.net/ubuntu/+source/mergerfs)
|
||||
* [Fedora](https://rpmsphere.github.io/)
|
||||
* [T2](https://t2sde.org/packages/mergerfs)
|
||||
* [Alpine](https://pkgs.alpinelinux.org/packages?name=mergerfs&branch=edge&repo=&arch=&maintainer=)
|
||||
* [Gentoo](https://packages.gentoo.org/packages/sys-fs/mergerfs)
|
||||
* [Arch (AUR)](https://aur.archlinux.org/packages/mergerfs)
|
||||
* [Void](https://voidlinux.org/packages/?arch=x86_64&q=mergerfs)
|
||||
* [NixOS](https://search.nixos.org/packages?channel=22.11&show=mergerfs&from=0&size=50&sort=relevance&type=packages&query=mergerfs)
|
||||
* [Guix]()
|
||||
* [Slackware](https://slackbuilds.org/repository/15.0/system/mergerfs/?search=mergerfs)
|
||||
@@ -0,0 +1,117 @@
|
||||
# Remote Filesystems
|
||||
|
||||
Many users ask about compatibility with remote filesystems. This
|
||||
section is to describe any known issues or quirks when using mergerfs
|
||||
with common remote filesystems.
|
||||
|
||||
Keep in mind that, like with caching, it is **NOT** a good idea to
|
||||
change the contents of the remote filesystem
|
||||
[out-of-band](https://en.wikipedia.org/wiki/Out-of-band). Meaning that
|
||||
you should not change the contents of the underlying filesystems or
|
||||
mergerfs on the server hosting the remote filesystem. Doing so can
|
||||
lead to weird behavior, inconsistency, errors, and even data
|
||||
corruption should multiple programs try to write or read the same data
|
||||
at the same time. This isn't to say you can't do it or that data
|
||||
corruption is likely but it _could_ happen. It is better to always use
|
||||
the remote filesystem. Even on the machine serving it.
|
||||
|
||||
## NFS
|
||||
|
||||
[NFS](https://en.wikipedia.org/wiki/Network_File_System) is a common
|
||||
remote filesystem on Unix/POSIX systems. Due to how NFS works there
|
||||
are some settings which need to be set in order for mergerfs to work
|
||||
with it.
|
||||
|
||||
It should be noted that NFS and FUSE (the technology mergerfs uses) do
|
||||
not work perfectly with one another due to certain design choices in
|
||||
FUSE (and mergerfs.) Due to these issues, it is generally recommended
|
||||
to use SMB when possible. That said mergerfs should generally work as
|
||||
an export of NFS and issues discovered should still be reported.
|
||||
|
||||
To ensure compatibility between mergerfs and NFS use the following
|
||||
settings.
|
||||
|
||||
mergerfs settings:
|
||||
|
||||
* `noforget`
|
||||
* `inodecalc=path-hash`
|
||||
|
||||
NFS export settings:
|
||||
|
||||
* `fsid=UUID`
|
||||
* `no_root_squash`
|
||||
|
||||
`noforget` is needed because NFS uses the `name_to_handle_at` and
|
||||
`open_by_handle_at` functions which allow a program to keep a
|
||||
reference to a file without technically having it open in the typical
|
||||
sense. The problem is that FUSE has no way to know that NFS has a
|
||||
handle that it will later use to open the file again. As a result, it
|
||||
is possible for the kernel to tell mergerfs to forget about the node
|
||||
and should NFS ever ask for that node's details in the future it would
|
||||
have nothing to respond with. Keeping nodes around forever is not
|
||||
ideal but at the moment the only way to manage the situation.
|
||||
|
||||
`inodecalc=path-hash` is needed because NFS is sensitive to
|
||||
out-of-band changes. FUSE doesn't care if a file's inode value changes
|
||||
but NFS, being stateful, does. So if you used the default inode
|
||||
calculation algorithm then it is possible that if you changed a file
|
||||
or updated a directory the file mergerfs will use will be on a
|
||||
different branch and therefore the inode would change. This isn't an
|
||||
ideal solution and others are being considered but it works for most
|
||||
situations.
|
||||
|
||||
`fsid=UUID` is needed because FUSE filesystems don't have different
|
||||
`st_dev` values which can cause issues when exporting. The easiest
|
||||
thing to do is set each mergerfs export `fsid` to some random
|
||||
value. An easy way to generate a random value is to use the command
|
||||
line tool `uuid` or `uuidgen` or through a website such as
|
||||
[uuidgenerator.net](https://www.uuidgenerator.net/).
|
||||
|
||||
`no_root_squash` is not strictly necessary but can lead to confusing
|
||||
permission and ownership issues if root squashing is enabled. mergerfs
|
||||
needs to run certain commands as `root` and if root squash is enabled
|
||||
it NFS will tell mergerfs a non-root user is making certain calls.
|
||||
|
||||
|
||||
## SMB / CIFS
|
||||
|
||||
[SMB](https://en.wikipedia.org/wiki/Server_Message_Block) is a
|
||||
protocol most used by Microsoft Windows systems to share file shares,
|
||||
printers, etc. However, due to the popularity of Windows, it is also
|
||||
supported on many other platforms including Linux. The most popular
|
||||
way of supporting SMB on Linux is via the software Samba.
|
||||
|
||||
[Samba](<https://en.wikipedia.org/wiki/Samba_(software)>), and other
|
||||
ways of serving Linux filesystems, via SMB should work fine with
|
||||
mergerfs. The services do not tend to use the same technologies which
|
||||
NFS uses and therefore don't have the same issues. There should not be
|
||||
special settings required to use mergerfs with Samba. However,
|
||||
[CIFSD](https://en.wikipedia.org/wiki/CIFSD) and other programs have
|
||||
not been extensively tested. If you use mergerfs with CIFSD or other
|
||||
SMB servers please submit your experiences so these docs can be
|
||||
updated.
|
||||
|
||||
|
||||
## SSHFS
|
||||
|
||||
[SSHFS](https://en.wikipedia.org/wiki/SSHFS) is a FUSE filesystem
|
||||
leveraging SSH as the connection and transport layer. While often
|
||||
simpler to setup when compared to NFS or Samba the performance can be
|
||||
lacking and the project is very much in maintenance mode.
|
||||
|
||||
There are no known issues using sshfs with mergerfs. You may want to
|
||||
use the following arguments to improve performance but your millage
|
||||
may vary.
|
||||
|
||||
- `-o Ciphers=arcfour`
|
||||
- `-o Compression=no`
|
||||
|
||||
More info can be found
|
||||
[here](https://ideatrash.net/2016/08/odds-and-ends-optimizing-sshfs-moving.html).
|
||||
|
||||
|
||||
## Other
|
||||
|
||||
There are other remote filesystems but none popularly used to serve
|
||||
mergerfs. If you use something not listed above feel free to reach out
|
||||
and I will add it to the list.
|
||||
@@ -0,0 +1,114 @@
|
||||
# Runtime Interfaces
|
||||
|
||||
## Runtime Config
|
||||
|
||||
### .mergerfs pseudo file
|
||||
|
||||
```
|
||||
<mountpoint>/.mergerfs
|
||||
```
|
||||
|
||||
There is a pseudo file available at the mount point which allows for
|
||||
the runtime modification of certain **mergerfs** options. The file
|
||||
will not show up in **readdir** but can be **stat**'ed and manipulated
|
||||
via [{list,get,set}xattrs](http://linux.die.net/man/2/listxattr)
|
||||
calls.
|
||||
|
||||
Any changes made at runtime are **not** persisted. If you wish for
|
||||
values to persist they must be included as options wherever you
|
||||
configure the mounting of mergerfs (/etc/fstab).
|
||||
|
||||
|
||||
#### Keys
|
||||
|
||||
Use `getfattr -d /mountpoint/.mergerfs` or `xattr -l
|
||||
/mountpoint/.mergerfs` to see all supported keys. Some are
|
||||
informational and therefore read-only. `setxattr` will return EINVAL
|
||||
(invalid argument) on read-only keys.
|
||||
|
||||
|
||||
#### Values
|
||||
|
||||
Same as the command line.
|
||||
|
||||
|
||||
##### user.mergerfs.branches
|
||||
|
||||
Used to query or modify the list of branches. When modifying there are
|
||||
several shortcuts to easy manipulation of the list.
|
||||
|
||||
| Value | Description |
|
||||
| -------- | -------------------------- |
|
||||
| [list] | set |
|
||||
| +<[list] | prepend |
|
||||
| +>[list] | append |
|
||||
| -[list] | remove all values provided |
|
||||
| -< | remove first in list |
|
||||
| -> | remove last in list |
|
||||
|
||||
`xattr -w user.mergerfs.branches +</mnt/drive3 /mnt/pool/.mergerfs`
|
||||
|
||||
The `=NC`, `=RO`, `=RW` syntax works just as on the command line.
|
||||
|
||||
##### Example
|
||||
|
||||
```
|
||||
[trapexit:/mnt/mergerfs] $ getfattr -d .mergerfs
|
||||
user.mergerfs.branches="/mnt/a=RW:/mnt/b=RW"
|
||||
user.mergerfs.minfreespace="4294967295"
|
||||
user.mergerfs.moveonenospc="false"
|
||||
...
|
||||
|
||||
[trapexit:/mnt/mergerfs] $ getfattr -n user.mergerfs.category.search .mergerfs
|
||||
user.mergerfs.category.search="ff"
|
||||
|
||||
[trapexit:/mnt/mergerfs] $ setfattr -n user.mergerfs.category.search -v newest .mergerfs
|
||||
[trapexit:/mnt/mergerfs] $ getfattr -n user.mergerfs.category.search .mergerfs
|
||||
user.mergerfs.category.search="newest"
|
||||
```
|
||||
|
||||
### file / directory xattrs
|
||||
|
||||
While they won't show up when using `getfattr` **mergerfs** offers a
|
||||
number of special xattrs to query information about the files
|
||||
served. To access the values you will need to issue a
|
||||
[getxattr](http://linux.die.net/man/2/getxattr) for one of the
|
||||
following:
|
||||
|
||||
- **user.mergerfs.basepath**: the base mount point for the file given the current getattr policy
|
||||
- **user.mergerfs.relpath**: the relative path of the file from the perspective of the mount point
|
||||
- **user.mergerfs.fullpath**: the full path of the original file given the getattr policy
|
||||
- **user.mergerfs.allpaths**: a NUL ('\0') separated list of full paths to all files found
|
||||
|
||||
## Signals
|
||||
|
||||
- USR1: This will cause mergerfs to send invalidation notifications to
|
||||
the kernel for all files. This will cause all unused files to be
|
||||
released from memory.
|
||||
- USR2: Trigger a general cleanup of currently unused memory. A more
|
||||
thorough version of what happens every ~15 minutes.
|
||||
|
||||
## ioctl
|
||||
|
||||
Found in `fuse_ioctl.cpp`:
|
||||
|
||||
```C++
|
||||
typedef char IOCTL_BUF[4096];
|
||||
#define IOCTL_APP_TYPE 0xDF
|
||||
#define IOCTL_FILE_INFO _IOWR(IOCTL_APP_TYPE,0,IOCTL_BUF)
|
||||
#define IOCTL_GC _IO(IOCTL_APP_TYPE,1)
|
||||
#define IOCTL_GC1 _IO(IOCTL_APP_TYPE,2)
|
||||
#define IOCTL_INVALIDATE_ALL_NODES _IO(IOCTL_APP_TYPE,3)
|
||||
```
|
||||
|
||||
- IOCTL_FILE_INFO: Same as the "file / directory xattrs" mentioned
|
||||
above. Use a buffer size of 4096 bytes. Pass in a string of
|
||||
"basepath", "relpath", "fullpath", or "allpaths". Receive details in
|
||||
same buffer.
|
||||
- IOCTL_GC: Triggers a thorough garbage collection of excess
|
||||
memory. Same as SIGUSR2.
|
||||
- IOCTL_GC1: Triggers a simple garbage collection of excess
|
||||
memory. Same as what happens every 15 minutes normally.
|
||||
- IOCTL_INVALIDATE_ALL_NODES: Same as SIGUSR1. Send invalidation
|
||||
notifications to the kernel for all files causing unused files to be
|
||||
released from memory.
|
||||
@@ -0,0 +1,56 @@
|
||||
# Build
|
||||
|
||||
**NOTE:** Prebuilt packages can be found at and recommended for most
|
||||
users: https://github.com/trapexit/mergerfs/releases
|
||||
|
||||
**NOTE:** Only tagged releases are supported. `master` and other
|
||||
branches should be considered works in progress.
|
||||
|
||||
First, get the code from [github](https://github.com/trapexit/mergerfs).
|
||||
|
||||
```
|
||||
$ git clone https://github.com/trapexit/mergerfs.git
|
||||
$ # or
|
||||
$ wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs-<ver>.tar.gz
|
||||
```
|
||||
|
||||
## Debian / Ubuntu
|
||||
|
||||
```
|
||||
$ cd mergerfs
|
||||
$ sudo tools/install-build-pkgs
|
||||
$ make deb
|
||||
$ sudo dpkg -i ../mergerfs_<version>_<arch>.deb
|
||||
```
|
||||
|
||||
## RHEL / CentOS / Rocky / Fedora
|
||||
|
||||
```
|
||||
$ su -
|
||||
# cd mergerfs
|
||||
# tools/install-build-pkgs
|
||||
# make rpm
|
||||
# rpm -i rpmbuild/RPMS/<arch>/mergerfs-<version>.<arch>.rpm
|
||||
```
|
||||
|
||||
## Generic
|
||||
|
||||
Have git, g++, make, python installed.
|
||||
|
||||
|
||||
```
|
||||
$ cd mergerfs
|
||||
$ make
|
||||
$ sudo make install
|
||||
```
|
||||
|
||||
## Build options
|
||||
|
||||
```
|
||||
$ make help
|
||||
usage: make
|
||||
|
||||
make USE_XATTR=0 - build program without xattrs functionality
|
||||
make STATIC=1 - build static binary
|
||||
make LTO=1 - build with link time optimization
|
||||
```
|
||||
@@ -0,0 +1,101 @@
|
||||
# Installation
|
||||
|
||||
If you are using a non-rolling release Linux distro such as Debian or
|
||||
Ubuntu then you are almost certainly going to have an old version of
|
||||
mergerfs installed if you use the "official" package. For that reason
|
||||
we provide packages for major stable released distros.
|
||||
|
||||
Before reporting issues or bugs please be sure to upgrade to the
|
||||
latest release to confirm they still exist.
|
||||
|
||||
All provided packages can be found at [https://github.com/trapexit/mergerfs/releases](https://github.com/trapexit/mergerfs/releases)
|
||||
|
||||
|
||||
## Debian
|
||||
|
||||
Most Debian installs are of a stable branch and therefore do not have
|
||||
the most up to date software. While mergerfs is available via `apt` it
|
||||
is suggested that users install the most recent version available from
|
||||
the [releases page](https://github.com/trapexit/mergerfs/releases).
|
||||
|
||||
|
||||
### prebuilt deb
|
||||
|
||||
```
|
||||
wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs_<ver>.debian-<rel>_<arch>.deb
|
||||
sudo dpkg -i mergerfs_<ver>.debian-<rel>_<arch>.deb
|
||||
```
|
||||
|
||||
|
||||
### apt
|
||||
|
||||
```
|
||||
sudo apt install -y mergerfs
|
||||
```
|
||||
|
||||
|
||||
## Ubuntu
|
||||
|
||||
Most Ubuntu installs are of a stable branch and therefore do not have
|
||||
the most up to date software. While mergerfs is available via `apt` it
|
||||
is suggested that users install the most recent version available from
|
||||
the [releases page](https://github.com/trapexit/mergerfs/releases).
|
||||
|
||||
|
||||
### prebuilt deb
|
||||
|
||||
```
|
||||
wget https://github.com/trapexit/mergerfs/releases/download/<version>/mergerfs_<ver>.ubuntu-<rel>_<arch>.deb
|
||||
sudo dpkg -i mergerfs_<ver>.ubuntu-<rel>_<arch>.deb
|
||||
```
|
||||
|
||||
|
||||
### apt
|
||||
|
||||
```
|
||||
sudo apt install -y mergerfs
|
||||
```
|
||||
|
||||
|
||||
## Raspberry Pi OS
|
||||
|
||||
The same as Debian or Ubuntu.
|
||||
|
||||
|
||||
## Fedora
|
||||
|
||||
Get the RPM from the [releases page](https://github.com/trapexit/mergerfs/releases).
|
||||
|
||||
```
|
||||
wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs-<ver>.fc<rel>.<arch>.rpm
|
||||
sudo rpm -i mergerfs-<ver>.fc<rel>.<arch>.rpm
|
||||
```
|
||||
|
||||
|
||||
## CentOS / Rocky
|
||||
|
||||
Get the RPM from the [releases page](https://github.com/trapexit/mergerfs/releases).
|
||||
|
||||
```
|
||||
wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs-<ver>.el<rel>.<arch>.rpm
|
||||
sudo rpm -i mergerfs-<ver>.el<rel>.<arch>.rpm
|
||||
```
|
||||
|
||||
|
||||
## ArchLinux
|
||||
|
||||
1. Setup AUR
|
||||
2. `pacman -S mergerfs`
|
||||
|
||||
|
||||
## Other
|
||||
|
||||
Static binaries are provided for situations where native packages are
|
||||
unavailable.
|
||||
|
||||
Get the tarball from the [releases page](https://github.com/trapexit/mergerfs/releases).
|
||||
|
||||
```
|
||||
wget https://github.com/trapexit/mergerfs/releases/download/<ver>/mergerfs-static-linux_<arch>.tar.gz
|
||||
sudo tar xvf mergerfs-static-linux_<arch>.tar.gz -C /
|
||||
```
|
||||
@@ -0,0 +1,25 @@
|
||||
# Upgrade
|
||||
|
||||
mergerfs can be upgraded live by mounting on top of the previous
|
||||
instance. Simply install the new version of mergerfs and follow the
|
||||
instructions below.
|
||||
|
||||
Run mergerfs again or if using `/etc/fstab` call for it to mount
|
||||
again. Existing open files and such will continue to work fine though
|
||||
they won't see runtime changes since any such change would be the new
|
||||
mount. If you plan on changing settings with the new mount you should
|
||||
/ could apply those before mounting the new version.
|
||||
|
||||
```
|
||||
$ sudo mount /mnt/mergerfs
|
||||
$ mount | grep mergerfs
|
||||
media on /mnt/mergerfs type mergerfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other)
|
||||
media on /mnt/mergerfs type mergerfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other)
|
||||
```
|
||||
|
||||
A problem with this approach is that the underlying instance will
|
||||
continue to run even if the software using it stop or are
|
||||
restarted. To work around this you can use a "lazy umount". Before
|
||||
mounting over top the mount point with the new instance of mergerfs
|
||||
issue: `umount -l <mergerfs_mountpoint>`. Or you can let mergerfs do
|
||||
it by setting the option `lazy-umount-mountpoint=true`.
|
||||
@@ -0,0 +1,17 @@
|
||||
# Sponsorship and Donations
|
||||
|
||||
[https://github.com/trapexit/support](https://github.com/trapexit/support)
|
||||
|
||||
Development and support of a project like mergerfs requires a
|
||||
significant amount of time and effort. The software is released under
|
||||
the very liberal [ISC](https://opensource.org/license/isc-license-txt)
|
||||
license and is therefore free to use for personal or commercial uses.
|
||||
|
||||
If you are a non-commercial user and find mergerfs and its support valuable
|
||||
and would like to support the project financially it would be very
|
||||
much appreciated.
|
||||
|
||||
If you are using mergerfs commercially please consider sponsoring the
|
||||
project to ensure it continues to be maintained and receive
|
||||
updates. If custom features are needed feel free to [contact me
|
||||
directly](mailto:support@spawn.link).
|
||||
@@ -0,0 +1,45 @@
|
||||
# Support
|
||||
|
||||
Filesystems are complex, as are the interactions software have with
|
||||
them, and therefore difficult to debug. When reporting on a suspected
|
||||
issue **please** include as much of the below information as possible
|
||||
otherwise it will be difficult or impossible to diagnose. Also please
|
||||
read the documentation as it provides details on many previously
|
||||
encountered questions/issues.
|
||||
|
||||
**Please make sure you are using the [latest
|
||||
release](https://github.com/trapexit/mergerfs/releases) or have tried
|
||||
it in comparison. Old versions, which are often included in distros
|
||||
like Debian and Ubuntu, are not ever going to be updated and the issue
|
||||
you are encountering may have been addressed already.**
|
||||
|
||||
**For commercial support or feature requests please [contact me
|
||||
directly.](mailto:support@spawn.link)**
|
||||
|
||||
### Information to include in bug reports
|
||||
|
||||
* [Information about the broader problem along with any attempted
|
||||
solutions.](https://xyproblem.info)
|
||||
* Solution already ruled out and why.
|
||||
* Version of mergerfs: `mergerfs --version`
|
||||
* mergerfs settings / arguments: from fstab, systemd unit, command
|
||||
line, OMV plugin, etc.
|
||||
* Version of the OS: `uname -a` and `lsb_release -a`
|
||||
* List of branches, their filesystem types, sizes (before and after issue): `df -h`
|
||||
* **All** information about the relevant paths and files: permissions, ownership, etc.
|
||||
* **All** information about the client app making the requests: version, uid/gid
|
||||
* Runtime environment:
|
||||
* Is mergerfs running within a container?
|
||||
* Are the client apps using mergerfs running in a container?
|
||||
* A `strace` of the app having problems:
|
||||
* `strace -fvTtt -s 256 -o /tmp/app.strace.txt <cmd>`
|
||||
* A `strace` of mergerfs while the program is trying to do whatever it is failing to do:
|
||||
* `strace -fvTtt -s 256 -p <mergerfsPID> -o /tmp/mergerfs.strace.txt`
|
||||
* **Precise** directions on replicating the issue. Do not leave **anything** out.
|
||||
* Try to recreate the problem in the simplest way using standard programs: `ln`, `mv`, `cp`, `ls`, `dd`, etc.
|
||||
|
||||
### Contact / Issue submission
|
||||
|
||||
* github.com: [https://github.com/trapexit/mergerfs/issues](https://github.com/trapexit/mergerfs/issues)
|
||||
* discord: [https://discord.gg/MpAr69V](https://discord.gg/MpAr69V)
|
||||
* reddit: [https://www.reddit.com/r/mergerfs](https://www.reddit.com/r/mergerfs)
|
||||
@@ -0,0 +1,43 @@
|
||||
# Tips and Notes
|
||||
|
||||
* This document is literal and reasonably thorough. If a suspected
|
||||
feature isn't mentioned it doesn't exist. If certain `libfuse`
|
||||
arguments aren't listed they probably shouldn't be used.
|
||||
* Ensure you're using the latest version. Especially before submitting
|
||||
bug reports.
|
||||
* Run mergerfs as `root`. mergerfs is designed and intended to be run
|
||||
as `root` and may exhibit incorrect behavior if run otherwise.
|
||||
* If you do not see some directories and files you expect, policies
|
||||
seem to skip branches, you get strange permission errors, etc. be
|
||||
sure the underlying filesystems' permissions are all the same. Use
|
||||
`mergerfs.fsck` to audit the filesystem for out of sync permissions.
|
||||
* If you still have permission issues be sure you are using POSIX ACL
|
||||
compliant filesystems. mergerfs doesn't generally make exceptions
|
||||
for FAT, NTFS, or other non-POSIX filesystem.
|
||||
* Unless using Linux v6.6 or above do **not** use `cache.files=off` if
|
||||
you expect applications (such as rtorrent) to use
|
||||
[mmap](http://linux.die.net/man/2/mmap). Enabling `dropcacheonclose`
|
||||
is recommended when `cache.files=auto-full`.
|
||||
* [Kodi](http://kodi.tv), [Plex](http://plex.tv),
|
||||
[Subsonic](http://subsonic.org), etc. can use directory
|
||||
[mtime](http://linux.die.net/man/2/stat) to more efficiently
|
||||
determine whether to scan for new content rather than simply
|
||||
performing a full scan. If using the default `getattr` policy of
|
||||
`ff` it's possible those programs will miss an update on account of
|
||||
it returning the first directory found's `stat` info and it is a
|
||||
later directory on another mount which had the `mtime` recently
|
||||
updated. To fix this you will want to set
|
||||
`func.getattr=newest`. Remember though that this is just `stat`. If
|
||||
the file is later `open`'ed or `unlink`'ed and the policy is
|
||||
different for those then a completely different file or directory
|
||||
could be acted on.
|
||||
* Some policies mixed with some functions may result in strange
|
||||
behaviors. Not that some of these behaviors and race conditions
|
||||
couldn't happen outside mergerfs but that they are far more
|
||||
likely to occur on account of the attempt to merge multiple sources
|
||||
of data which could be out of sync due to the different policies.
|
||||
* For consistency it's generally best to set `category` wide policies
|
||||
rather than individual `func`'s. This will help limit the
|
||||
confusion of tools such as
|
||||
[rsync](http://linux.die.net/man/1/rsync). However, the flexibility
|
||||
is there if needed.
|
||||
@@ -0,0 +1,117 @@
|
||||
# Tooling
|
||||
|
||||
## preload.so
|
||||
|
||||
EXPERIMENTAL
|
||||
|
||||
For some time there has been work to enable passthrough IO in
|
||||
FUSE. Passthrough IO would allow for near native performance with
|
||||
regards to reads and writes (at the expense of certain mergerfs
|
||||
features.) In Linux v6.9 that feature made its way into the kernel
|
||||
however in a somewhat limited form which is incompatible with aspects
|
||||
of how mergerfs currently functions. While work will continue to
|
||||
support passthrough IO in mergerfs this library was created to offer
|
||||
similar functionality in a more limited way.
|
||||
|
||||
`/usr/lib/mergerfs/preload.so`
|
||||
|
||||
This [preloadable
|
||||
library](https://man7.org/linux/man-pages/man8/ld.so.8.html#ENVIRONMENT)
|
||||
overrides the creation and opening of files in order to simulate
|
||||
passthrough file IO. It catches the open/creat/fopen calls, has
|
||||
mergerfs do the call, queries mergerfs for the branch the file exists
|
||||
on, reopens the file on the underlying filesystem and returns that
|
||||
instead. Meaning that you will get native read/write performance
|
||||
because mergerfs is no longer part of the workflow. Keep in mind that
|
||||
this also means certain mergerfs features that work by interrupting
|
||||
the read/write workflow, such as `moveonenospc`, will no longer work.
|
||||
|
||||
Also, understand that this will only work on dynamically linked
|
||||
software. Anything statically compiled will not work. Many GoLang and
|
||||
Rust apps are statically compiled.
|
||||
|
||||
The library will not interfere with non-mergerfs filesystems. The
|
||||
library is written to always fallback to returning the mergerfs opened
|
||||
file on error.
|
||||
|
||||
While the library was written to account for a number of edgecases
|
||||
there could be some yet accounted for so please report any oddities.
|
||||
|
||||
Thank you to
|
||||
[nohajc](https://github.com/nohajc/mergerfs-io-passthrough) for
|
||||
prototyping the idea.
|
||||
|
||||
### casual usage
|
||||
|
||||
```sh
|
||||
LD_PRELOAD=/usr/lib/mergerfs/preload.so touch /mnt/mergerfs/filename
|
||||
```
|
||||
|
||||
Or run `export LD_PRELOAD=/usr/lib/mergerfs/preload.so` in your shell
|
||||
or place it in your shell config file to have it be picked up by all
|
||||
software ran from your shell.
|
||||
|
||||
|
||||
### Docker and Podman usage
|
||||
|
||||
Assume `/mnt/fs0` and `/mnt/fs1` are pooled with mergerfs at `/media`.
|
||||
|
||||
All mergerfs branch paths _must_ be bind mounted into the container at
|
||||
the same path as found on the host so the preload library can see
|
||||
them.
|
||||
|
||||
**NOTE:** Since a container can have its own OS setup there is no
|
||||
guarentee that `preload.so` from the host install will be compatible
|
||||
with the loader found in the container. If that is true it simply
|
||||
won't work and shouldn't cause any issues.
|
||||
|
||||
|
||||
```sh
|
||||
docker run \
|
||||
-e LD_PRELOAD=/usr/lib/mergerfs/preload.so \
|
||||
-v /usr/lib/mergerfs/preload.so:/usr/lib/mergerfs/preload.so:ro \
|
||||
-v /media:/media \
|
||||
-v /mnt:/mnt \
|
||||
ubuntu:latest \
|
||||
bash
|
||||
```
|
||||
|
||||
or more explicitly
|
||||
|
||||
```sh
|
||||
docker run \
|
||||
-e LD_PRELOAD=/usr/lib/mergerfs/preload.so \
|
||||
-v /usr/lib/mergerfs/preload.so:/usr/lib/mergerfs/preload.so:ro \
|
||||
-v /media:/media \
|
||||
-v /mnt/fs0:/mnt/fs0 \
|
||||
-v /mnt/fs1:/mnt/fs1 \
|
||||
ubuntu:latest \
|
||||
bash
|
||||
```
|
||||
|
||||
|
||||
### systemd unit
|
||||
|
||||
Use the `Environment` option to set the LD_PRELOAD variable.
|
||||
|
||||
* [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)
|
||||
* [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)
|
||||
|
||||
```
|
||||
[Service]
|
||||
Environment=LD_PRELOAD=/usr/lib/mergerfs/preload.so
|
||||
```
|
||||
|
||||
## Misc
|
||||
|
||||
- https://github.com/trapexit/mergerfs-tools
|
||||
- mergerfs.ctl: A tool to make it easier to query and configure mergerfs at runtime
|
||||
- mergerfs.fsck: Provides permissions and ownership auditing and the ability to fix them
|
||||
- mergerfs.dedup: Will help identify and optionally remove duplicate files
|
||||
- mergerfs.dup: Ensure there are at least N copies of a file across the pool
|
||||
- mergerfs.balance: Rebalance files across filesystems by moving them from the most filled to the least filled
|
||||
- mergerfs.consolidate: move files within a single mergerfs directory to the filesystem with most free space
|
||||
- https://github.com/trapexit/scorch
|
||||
- scorch: A tool to help discover silent corruption of files and keep track of files
|
||||
- https://github.com/trapexit/bbf
|
||||
- bbf (bad block finder): a tool to scan for and 'fix' hard drive bad blocks and find the files using those blocks
|
||||
@@ -0,0 +1,88 @@
|
||||
# Usage Patterns
|
||||
|
||||
## tiered cache
|
||||
|
||||
Some storage technologies support what is called "tiered" caching. The
|
||||
placing of smaller, faster storage as a transparent cache to larger,
|
||||
slower storage. NVMe, SSD, Optane in front of traditional HDDs for
|
||||
instance.
|
||||
|
||||
mergerfs does not natively support any sort of tiered caching. Most
|
||||
users have no use for such a feature and its inclusion would
|
||||
complicate the code as it exists today. However, there are a few
|
||||
situations where a cache filesystem could help with a typical mergerfs
|
||||
setup.
|
||||
|
||||
1. Fast network, slow filesystems, many readers: You've a 10+Gbps
|
||||
network with many readers and your regular filesystems can't keep
|
||||
up.
|
||||
2. Fast network, slow filesystems, small'ish bursty writes: You have
|
||||
a 10+Gbps network and wish to transfer amounts of data less than
|
||||
your cache filesystem but wish to do so quickly and the time
|
||||
between bursts is long enough to migrate data.
|
||||
|
||||
With #1 it's arguable if you should be using mergerfs at all. A RAID
|
||||
level that can aggregate performance or using higher performance
|
||||
storage would probably be the better solution. If you're going to use
|
||||
mergerfs there are other tactics that may help: spreading the data
|
||||
across filesystems (see the mergerfs.dup tool) and setting
|
||||
`func.open=rand`, using `symlinkify`, or using dm-cache or a similar
|
||||
technology to add tiered cache to the underlying device itself.
|
||||
|
||||
With #2 one could use dm-cache as well but there is another solution
|
||||
which requires only mergerfs and a cronjob.
|
||||
|
||||
1. Create 2 mergerfs pools. One which includes just the slow branches
|
||||
and one which has both the fast branches (SSD,NVME,etc.) and slow
|
||||
branches. The 'base' pool and the 'cache' pool.
|
||||
2. The 'cache' pool should have the cache branches listed first in
|
||||
the branch list.
|
||||
3. The best `create` policies to use for the 'cache' pool would
|
||||
probably be `ff`, `epff`, `lfs`, `msplfs`, or `eplfs`. The latter
|
||||
three under the assumption that the cache filesystem(s) are far
|
||||
smaller than the backing filesystems. If using path preserving
|
||||
policies remember that you'll need to manually create the core
|
||||
directories of those paths you wish to be cached. Be sure the
|
||||
permissions are in sync. Use `mergerfs.fsck` to check / correct
|
||||
them. You could also set the slow filesystems mode to `NC` though
|
||||
that'd mean if the cache filesystems fill you'd get "out of space"
|
||||
errors.
|
||||
4. Enable `moveonenospc` and set `minfreespace` appropriately. To
|
||||
make sure there is enough room on the "slow" pool you might want
|
||||
to set `minfreespace` to at least as large as the size of the
|
||||
largest cache filesystem if not larger. This way in the worst case
|
||||
the whole of the cache filesystem(s) can be moved to the other
|
||||
drives.
|
||||
5. Set your programs to use the 'cache' pool.
|
||||
6. Save one of the below scripts or create you're own. The script's
|
||||
responsibility is to move files from the cache filesystems (not
|
||||
pool) to the 'base' pool.
|
||||
7. Use `cron` (as root) to schedule the command at whatever frequency
|
||||
is appropriate for your workflow.
|
||||
|
||||
|
||||
### time based expiring
|
||||
|
||||
Move files from cache to base pool based only on the last time the
|
||||
file was accessed. Replace `-atime` with `-amin` if you want minutes
|
||||
rather than days. May want to use the `fadvise` / `--drop-cache`
|
||||
version of rsync or run rsync with the tool
|
||||
[nocache](https://github.com/Feh/nocache).
|
||||
|
||||
**NOTE:** The arguments to these scripts include the cache
|
||||
**filesystem** itself. Not the pool with the cache filesystem. You
|
||||
could have data loss if the source is the cache pool.
|
||||
|
||||
[mergerfs.time-based-mover](https://github.com/trapexit/mergerfs/blob/latest-release/tools/mergerfs.time-based-mover?raw=1)
|
||||
|
||||
|
||||
### percentage full expiring
|
||||
|
||||
Move the oldest file from the cache to the backing pool. Continue till
|
||||
below percentage threshold.
|
||||
|
||||
**NOTE:** The arguments to these scripts include the cache
|
||||
**filesystem** itself. Not the pool with the cache filesystem. You
|
||||
could have data loss if the source is the cache pool.
|
||||
|
||||
[mergerfs.percent-full-mover](https://github.com/trapexit/mergerfs/blob/latest-release/tools/mergerfs.percent-full-mover?raw=1)
|
||||
@@ -0,0 +1,104 @@
|
||||
site_name: mergerfs
|
||||
site_description: mergerfs - a featureful union filesystem
|
||||
site_url: https://trapexit.github.io/mergerfs/
|
||||
repo_name: mergerfs
|
||||
repo_url: https://github.com/trapexit/mergerfs
|
||||
edit_uri: tree/master/mkdocs/docs/
|
||||
docs_dir: docs
|
||||
theme:
|
||||
name: material
|
||||
logo: logo.jpeg
|
||||
features:
|
||||
- content.action.edit
|
||||
- content.action.view
|
||||
- content.code.copy
|
||||
- content.code.select
|
||||
- navigation.footer
|
||||
- navigation.instant
|
||||
- navigation.instant.prefetch
|
||||
- navigation.path
|
||||
- navigation.top
|
||||
- navigation.tracking
|
||||
- optimize
|
||||
- search.share
|
||||
- toc.follow
|
||||
palette:
|
||||
- media: "(prefers-color-scheme)"
|
||||
toggle:
|
||||
icon: material/brightness-auto
|
||||
name: Switch to light mode
|
||||
- media: "(prefers-color-scheme: light)"
|
||||
scheme: default
|
||||
toggle:
|
||||
icon: material/brightness-7
|
||||
name: Switch to dark mode
|
||||
- media: "(prefers-color-scheme: dark)"
|
||||
scheme: slate
|
||||
toggle:
|
||||
icon: material/brightness-4
|
||||
name: Switch to system preference
|
||||
markdown_extensions:
|
||||
- footnotes
|
||||
- pymdownx.highlight:
|
||||
auto_title: false
|
||||
linenums_style: pymdownx-inline
|
||||
anchor_linenums: true
|
||||
line_spans: __span
|
||||
pygments_lang_class: true
|
||||
- pymdownx.inlinehilite
|
||||
- pymdownx.snippets
|
||||
- pymdownx.superfences
|
||||
nav:
|
||||
- Home: index.md
|
||||
- QuickStart: quickstart.md
|
||||
- Installation:
|
||||
- setup/installation.md
|
||||
- setup/upgrade.md
|
||||
- setup/build.md
|
||||
- Config:
|
||||
- config/terminology.md
|
||||
- config/options.md
|
||||
- config/deprecated_options.md
|
||||
- config/branches.md
|
||||
- config/functions_categories_and_policies.md
|
||||
- config/func_readdir.md
|
||||
- config/rename_and_link.md
|
||||
- config/cache.md
|
||||
- config/readahead.md
|
||||
- config/inodecalc.md
|
||||
- config/threads.md
|
||||
- config/pin-threads.md
|
||||
- config/link_cow.md
|
||||
- config/fuse_msg_size.md
|
||||
- config/follow-symlinks.md
|
||||
- config/link-exdev.md
|
||||
- config/rename-exdev.md
|
||||
- config/symlinkify.md
|
||||
- config/nullrw.md
|
||||
- config/xattr.md
|
||||
- config/nfsopenhack.md
|
||||
- config/statfs.md
|
||||
- config/flush-on-close.md
|
||||
- config/export-support.md
|
||||
- error_handling.md
|
||||
- runtime_interfaces.md
|
||||
- remote_filesystems.md
|
||||
- tips_notes.md
|
||||
- known_issues_bugs.md
|
||||
- project_comparisons.md
|
||||
- performance.md
|
||||
- benchmarking.md
|
||||
- tooling.md
|
||||
- usage_patterns.md
|
||||
- FAQ:
|
||||
- faq/reliability_and_scalability.md
|
||||
- faq/usage_and_functionality.md
|
||||
- faq/configuration_and_policies.md
|
||||
- faq/compatibility_and_integration.md
|
||||
- faq/recommendations_and_warnings.md
|
||||
- faq/technical_behavior_and_limitations.md
|
||||
- faq/limit_drive_spinup.md
|
||||
- related_projects.md
|
||||
- media_and_publicity.md
|
||||
- support.md
|
||||
- sponsorship_and_donations.md
|
||||
+22
-1
@@ -21,10 +21,12 @@
|
||||
#include "errno.hpp"
|
||||
#include "from_string.hpp"
|
||||
#include "fs_glob.hpp"
|
||||
#include "fs_is_rofs.hpp"
|
||||
#include "fs_realpathize.hpp"
|
||||
#include "nonstd/optional.hpp"
|
||||
#include "num.hpp"
|
||||
#include "str.hpp"
|
||||
#include "syslog.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -415,6 +417,24 @@ Branches::to_string(void) const
|
||||
return _impl->to_string();
|
||||
}
|
||||
|
||||
void
|
||||
Branches::find_and_set_mode_ro()
|
||||
{
|
||||
for(auto &branch : *_impl)
|
||||
{
|
||||
if(branch.mode != Branch::Mode::RW)
|
||||
continue;
|
||||
|
||||
if(!fs::is_rofs_but_not_mounted_ro(branch.path))
|
||||
continue;
|
||||
|
||||
syslog_warning("Branch %s found to be readonly - setting its mode to RO",
|
||||
branch.path.c_str());
|
||||
|
||||
branch.mode = Branch::Mode::RO;
|
||||
}
|
||||
}
|
||||
|
||||
SrcMounts::SrcMounts(Branches &b_)
|
||||
: _branches(b_)
|
||||
{
|
||||
@@ -424,7 +444,8 @@ SrcMounts::SrcMounts(Branches &b_)
|
||||
int
|
||||
SrcMounts::from_string(const std::string &s_)
|
||||
{
|
||||
return _branches.from_string(s_);
|
||||
// return _branches.from_string(s_);
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user