[PATCH] libc: add fallback for posix_fallocate() when not supported by underlying FS

Olivier Blin olivier.blin at softathome.com
Mon Sep 29 17:39:35 UTC 2014


On 09/29/14 18:42, Rich Felker wrote:
> On Mon, Sep 29, 2014 at 04:43:32PM +0200, Olivier Blin wrote:
> > EOPNOTSUPP is not a valid error code for posix_fallocate(), the
> > implementation should have a fallback when the underlying filesystem
> > does not support fallocate().
> >
> > This is especially useful when using posix_fallocate() on tmpfs with
> > kernels older than 3.5, for which there was no fallocate support.
> >
> > This copies the implementation of the internal fallback from glibc,
> > with a few adaptations for internals symbols.
>
> This code is dangerous (has race conditions that cause file
> corruption) and should not be added. See the bug report for the
> corresponding code in glibc:
>
> https://sourceware.org/bugzilla/show_bug.cgi?id=15661
>
> Rich
Indeed, this is dangerous.

According to the specification of posix_fallocate(), there does not seem 
to be an appropriate error code to return when the filesystem driver 
does not natively support fallocate().
In this case, the libc should probably provide a fallback implementation.

Users of posix_fallocate() do not expect it to fail if the FS does not 
support fallocate().
See for example the usage in wayland:
http://cgit.freedesktop.org/wayland/wayland/tree/cursor/os-compatibility.c?h=1.6&id=1.6.0#n79 


To have a better fallback, I don't see a way to avoid the extra child 
process either, since we can only do the atomic compare-and-swap through 
mmap.
Does anyone have a better suggestion to implement the fallback?

Thanks for bringing this up

-- 
Olivier Blin - SoftAtHome

-- This message and any attachments herein are confidential, intended solely for the addressees and are SoftAtHome.s ownership. Any unauthorized use or dissemination is prohibited. If you are not the intended addressee of this message, please cancel it immediately and inform the sender.
-- This message and any attachments herein are confidential, intended solely for the addressees and are SoftAtHome.s ownership. Any unauthorized use or dissemination is prohibited. If you are not the intended addressee of this message, please cancel it immediately and inform the sender.


More information about the uClibc mailing list