The system call posix_fallocate
is not supported on some filesystems.
- catches the result of posix_allocate and fall back to the default behaviour if the return value is different from 0 (success)
Fixes #15624
Do you think we can consider the Linux part in the fallback? I don’t know if posix_allocate can be called on every platform. It will become something like:
0#if defined(WIN32)
1...
2#elif defined(MAC_OSX)
3...
4#endif
5 // Linux and fallback version
6 (this calls posix_fallocate for every other platform)
This way the system call posix_fallocate
would be called for every fallback platform. I don’t know if this is a good idea.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
Just tested on an affected filesystem (unionf on Debian stable), using strace to check the system calls sent to the system. The success return value of posix_fallocate is obviously zero. Somehow in a previous version I had the ‘!’, but then I pushed the wrong one, without it. I’ve just force-pushed the good version, I’ve just tested with strace.
Affected filesystem (fallocate result is EOPNOTSUPP, and the fallback code is activated):
0$ strace test/test_bitcoin -t flatfile_tests 2>&1 | grep -A 5 fallocate | tail -6
1fallocate(3, 0, 0, 100) = -1 EOPNOTSUPP (Operation not supported)
2fcntl(3, F_GETFL) = 0x8002 (flags O_RDWR|O_LARGEFILE)
3fstat(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
4fstatfs(3, {f_type=FUSE_SUPER_MAGIC, f_bsize=4096, f_blocks=2047598, f_bfree=712591, f_bavail=603651, f_files=524288, f_ffree=411273, f_fsid={val=[0, 0]}, f_namelen=255, f_frsize=4096, f_flags=ST_VALID|ST_NOSUID|ST_NODEV|ST_RELATIME}) = 0
5pwrite64(3, "\0", 1, 99) = 1
6close(3) = 0
Ext4 filesystem (fallocate result is zero, that means success, and no other code is activated):
0$ strace test/test_bitcoin -t flatfile_tests 2>&1 | grep -A 1 fallocate | tail -2
1fallocate(3, 0, 0, 100) = 0
2close(3) = 0
1094+ #if defined(__linux__)
1095 // Version using posix_fallocate
1096 off_t nEndPos = (off_t)offset + length;
1097- posix_fallocate(fileno(file), 0, nEndPos);
1098-#else
1099+ if (!posix_fallocate(fileno(file), 0, nEndPos)) return;
0 == posix_fallocate(...
Gitian builds for commit 7b13c646457980f44599412f243694fa682a1abf (master):
4f78895ec6af482e4f2076d902d79aba...
bitcoin-0.18.99-aarch64-linux-gnu-debug.tar.gzf6e1b636a1f14b7b74dafeca7b288aad...
bitcoin-0.18.99-aarch64-linux-gnu.tar.gzbdd396e51fd211e7ae6978081fd80534...
bitcoin-0.18.99-arm-linux-gnueabihf-debug.tar.gz6bda652fb95d1dbc0a7de0fb5bca25ca...
bitcoin-0.18.99-arm-linux-gnueabihf.tar.gz4ac97f744c2cb8e30a7c51f03a9cd399...
bitcoin-0.18.99-i686-pc-linux-gnu-debug.tar.gzdc8aad2b49d5af8a5bbd55954d51f675...
bitcoin-0.18.99-i686-pc-linux-gnu.tar.gzf007fca585745aae6106f242c657715d...
bitcoin-0.18.99-osx-unsigned.dmg7761ef2852707751c1bb2d94ca42136d...
bitcoin-0.18.99-osx64.tar.gz45c5877a4e8253fc3d9c7e52b0d26aa7...
bitcoin-0.18.99-riscv64-linux-gnu-debug.tar.gz0bb71a7848f96eaa3c20ad4178f27e11...
bitcoin-0.18.99-riscv64-linux-gnu.tar.gz33972e602f6c68f2d97795a71c7b1626...
bitcoin-0.18.99-win32-debug.zip657642242318697dc7db55d7e2db7c00...
bitcoin-0.18.99-win32-setup-unsigned.exe0848f56e7983961e93c1ab26a8923eeb...
bitcoin-0.18.99-win32.zip8b9b03eec62fba194784347510efed2b...
bitcoin-0.18.99-win64-debug.zipfa6d55bd44c047796f4622d584afa71b...
bitcoin-0.18.99-win64-setup-unsigned.execf4437f868cde361df90164787a3b98e...
bitcoin-0.18.99-win64.zip63ae828070c1e3bd8aedceadb2d427de...
bitcoin-0.18.99-x86_64-linux-gnu-debug.tar.gz622159fc615d8bfe04f22cc6b9cffcc1...
bitcoin-0.18.99-x86_64-linux-gnu.tar.gzd21f4a40ace15642c04ea3698171675e...
bitcoin-0.18.99.tar.gz78231cf6502926e213d5ee7be15674f0...
bitcoin-core-linux-0.19-res.ymld2107f5b5b1afcf6c1235cc72ae38e3c...
bitcoin-core-osx-0.19-res.yml218b5cfc88ec9dc9d2ca4305f7b63f48...
bitcoin-core-win-0.19-res.ymla5982dd6614e7a0d888309a64c524aff...
bitcoin-linux-build.log765929be5af185f6876284129cdf2dca...
bitcoin-osx-build.logae3a68c79127f9e1f9d0110344421044...
bitcoin-win-build.logGitian builds for commit a48eb1ba7e1c72b46d38d53dd8ef180678975255 (master and this pull):
d6b086cb5da8596f910b73ce5868a7b8...
bitcoin-0.18.99-aarch64-linux-gnu-debug.tar.gzc2ef048622ff906708f921e9f32651d7...
bitcoin-0.18.99-aarch64-linux-gnu.tar.gz844ef68b84e801fe735b299d4b0a3a2a...
bitcoin-0.18.99-arm-linux-gnueabihf-debug.tar.gzd24c95a67af925a62e59adcd93253f52...
bitcoin-0.18.99-arm-linux-gnueabihf.tar.gzadda32f96408277b11fa157005c1d93e...
bitcoin-0.18.99-i686-pc-linux-gnu-debug.tar.gz7c279a770f6a99ace5d216211313f304...
bitcoin-0.18.99-i686-pc-linux-gnu.tar.gz9ca6ad745af66066e6020365458e8cd7...
bitcoin-0.18.99-osx-unsigned.dmg6c0c35c3f43a7c7cb14ca11ee8df4c02...
bitcoin-0.18.99-osx64.tar.gz5fad65923e795fb1cddb9ef05722ca29...
bitcoin-0.18.99-riscv64-linux-gnu-debug.tar.gz222084db1367f8641337381893f92db1...
bitcoin-0.18.99-riscv64-linux-gnu.tar.gz67ea5e99b6cfd4fab44fbab87f5efc1e...
bitcoin-0.18.99-win32-debug.zip1340d4dd53f678ab930403cbb27ca54d...
bitcoin-0.18.99-win32-setup-unsigned.exe10ef864ed1ff6d9d2dd9207cdedc3a37...
bitcoin-0.18.99-win32.zipce62fca6ab1db16bb2899328967b8a0e...
bitcoin-0.18.99-win64-debug.zipc2aec6a79e882cd28d6c18cc706b4b57...
bitcoin-0.18.99-win64-setup-unsigned.exe12d5856e6a433bcd8950e1f4576f5f8c...
bitcoin-0.18.99-win64.zipcb2c3bff3982ecc48937b9433645cf45...
bitcoin-0.18.99-x86_64-linux-gnu-debug.tar.gz444a690e3a6ba95285462dc780856eb3...
bitcoin-0.18.99-x86_64-linux-gnu.tar.gz0f2a531b1840ea9b1f2fd83ece18a4e4...
bitcoin-0.18.99.tar.gz859ce9fccd48b3bf87bcbb2cdf67c0aa...
bitcoin-core-linux-0.19-res.yml3a6e9c511a1981f031af0445c8f57e73...
bitcoin-core-osx-0.19-res.ymlbb4b27eec3a2146379f668b9c7ea9e65...
bitcoin-core-win-0.19-res.yml07f28a3bbc8b993fabe866b0ed32fc48...
bitcoin-linux-build.loga917e92952a001f9b606a7ae69522aaf...
bitcoin-osx-build.log68868884fdbaee4c0a3b97e888cb621e...
bitcoin-win-build.logProbably would be better to have configure check for posix_fallocate
availability instead of using __linux__
, but since it’s already that way, this is strictly an improvement.
utACK
lucayepa
gmaxwell
DrahtBot
MarcoFalke
sipa
luke-jr
hebasto
practicalswift
Labels
Utils/log/libs
Milestone
0.19.0