On Thu, Jul 2, 2009 at 9:21 AM, Joerg
Schilling<joerg.schill...@fokus.fraunhofer.de> wrote:
> Peter Tribble <peter.trib...@gmail.com> wrote:
>
>> We've just stumbled across an interesting problem in one of our
>> applications that fails when run on a ZFS filesystem.
>>
>> I don't have the code, so I can't fix it at source, but it's relying
>> on the fact that if you do readdir() on a directory, the files come
>> back in the order they were added to the directory. This appears
>> to be true (within certain limitations) on UFS, but certainly isn't
>> true on ZFS.
>
> It seems that you found a software that is not POSIX compliant as it expects a
> behavior that is not granted by POSIX.
>
>> Is there any way to force readdir() to return files in a specific order?
>> (On UFS, we have a scipt that creates symlinks in the correct order.
>> Ugly, but seems to have worked for many years.)
>
> You could write a readdir() replacement that calls
>
> struct dirent * (*readdir_real)() = dlsym(RTLD_NEXT, "readdir");

I don't think this part is necessary - it seems as though readdir
needs to be replaced, not wrapped.  As such, readdir_real would never
be called.

>
> and enforce it via LDPRELOAD=
>
> ...but how would you retrieve the creation order?

Sort on crtime?

$ ls -l -% all .bashrc
-rw-r--r--   1 mgerdts  other       4674 Jul  2 06:18 .bashrc
         timestamp: atime         Jul  2 09:51:44 2009
         timestamp: ctime         Jul  2 06:18:06 2009
         timestamp: mtime         Jul  2 06:18:06 2009
         timestamp: crtime         May 14 09:24:35 2009

getattrat(3C) seems to be the man page to look at for this value.  My
guess is that this is going to be extremely slow on the first call to
readdir with the need to read the entire directory contents, call
getattrat on every entry, then sort.  However, slow is often better
than broke.

> Also note that you would need to read in the whole directory into allocated
> storage first.

It seems as though readdir will already do this for smallish (8KB) directories.

>
>
> BTW: If you like to fix the software, you should know that Linux has at least
> one filesystem that returns the entries for "." and ".." out of order.


-- 
Mike Gerdts
http://mgerdts.blogspot.com/
_______________________________________________
zfs-discuss mailing list
zfs-discuss@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/zfs-discuss

Reply via email to