tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: openat/fstatat functions implementation

> ZFS uses openat/fstatat[1] function as a thread-safe version of a
> open/fstat calls.

As Thor said, the names suck; fstatat sounds like an -at version of
fstat, which it isn't.  (Thor's implicit suggestion of following the
paradigm implicit in fchroot won't work, though; that would lead to
fopen and fstat, each of which already exists with other semantics.)

I disagree that it's reasonable to call them thread-safe versions of
open and stat/lstat (*not*, incidentally, fstat; fstat does not need an
-at version, since it does not take a pathname).  Those functions are
already thread-safe in the usual sense.  What these are doing,
basically, is moving the "current directory" piece of per-process state
out of the kernel into userland.  This is not really related to
threading; the two facilities are often wanted together, but each is
plenty useful without the other.  You might as well convert UIDs into
some sort of userland-holdable capabilities and have "openwithuid"
which takes that rather than using the process's UID - these are about
moving per-process state out of the kernel into userland.

If you want to do this for the sake of threading, then make separate
threads have separate cwds (or UIDs or whatever).

But if you want to do it more generally, you could do much better than
this.  This way leads, ultimately, to an -at version of each syscall
that takes, or can take, a pathname, which is just silly.  The right
thing would be to replace pathnames with something more general, and in
particular with something which can include representations for things
like "start at the directory at fd N", akin to the current "start at my
cwd" (spelled "") or "start at my current rootdir" (spelled "/").
There currently is no room for this kind of thing, which is one reason
this would involve replacing pathnames - pathname strings are
insufficiently general to do this right.

I'm not sure what would be best.  But I'd much prefer to see this done
right than kludged.  (Of course, POSIX is a sufficiently holy document
that it will probably be followed even when it's wrong, rendering that
point moot, but that doesn't mean we can't do better _also_.)

/~\ The ASCII                             Mouse
\ / Ribbon Campaign
 X  Against HTML      
/ \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B

Home | Main Index | Thread Index | Old Index