On Mon, 2015-10-05 at 17:39 +0200, Mark Wielaard wrote:
When not using mmap it is enough the just ftruncate the file to the
right
size. pwrite will report an error if there is no disk space left. And on
file systems that don't support fallocate it might duplicate writes. When
using posix_fallocate do ignore errors indicating the file system doesn't
support fallocate. These will never happen with glibc, but might on some
other implementations. That is pretty nasty since we might get a SIGBUS
in that case when writing to the mmapped memory. But the chance of that
happening is very small and people using such a libc implementation are
on their own.
Sigh. Another issue with posix_fallocate was pointed out, this time in
the glibc fallback code, which introduces yet another failure mode/errno
to consider... I am starting to be a little less enthusiastic about this
function... If the original fd underlying the ELF file is opened
O_WRONLY then posix_fallocate might fail with EBADF if the glibc
fallback code is triggered. This doesn't actually happen right now in
our code, since if elf_begin is called with ELF_C_WRITE_MMAP (and not
ELF_C_RDWR_MMAP) we don't actually mmap the underlying file (yes, I was
surprised too, but ELF_C_WRITE and ELF_C_WRITE_MMAP both go through
write_file, which doesn't do mmap). But in case we ever change that for
some reason then having to handle yet another errno/failure case in some
obscure situations will be a pain.
So I changed the code again, now we just ignore all errors, except for
ENOSPC since that is the only real thing we are interested in.
Cheers,
Mark