nfs-workarounds.c revision 4f49b5cbfa6b9e6e4a213009ea6bb84337cb106a
4f49b5cbfa6b9e6e4a213009ea6bb84337cb106aTimo Sirainen/* Copyright (c) 2006-2007 Timo Sirainen */
4f49b5cbfa6b9e6e4a213009ea6bb84337cb106aTimo Sirainen These tests were done with various Linux 2.6 kernels, FreeBSD 6.2 and
4f49b5cbfa6b9e6e4a213009ea6bb84337cb106aTimo Sirainen Solaris 8 and 10.
4f49b5cbfa6b9e6e4a213009ea6bb84337cb106aTimo Sirainen Attribute cache is usually flushed with chown()ing or fchown()ing the file.
4f49b5cbfa6b9e6e4a213009ea6bb84337cb106aTimo Sirainen The safest way would be to use uid=-1 gid=-1, but this doesn't work with
4f49b5cbfa6b9e6e4a213009ea6bb84337cb106aTimo Sirainen Linux (it does with FreeBSD 6.2 and Solaris). So we'll first get the
4f49b5cbfa6b9e6e4a213009ea6bb84337cb106aTimo Sirainen file's owner and use it. As long as we're not root the file's owner can't
4f49b5cbfa6b9e6e4a213009ea6bb84337cb106aTimo Sirainen change accidentally. If would be possible to also use chmod()/fchmod(), but
4f49b5cbfa6b9e6e4a213009ea6bb84337cb106aTimo Sirainen that's riskier since it could actually cause an unwanted change.
4f49b5cbfa6b9e6e4a213009ea6bb84337cb106aTimo Sirainen Write cache can be flushed with fdatasync(). It's all we need, but other
4f49b5cbfa6b9e6e4a213009ea6bb84337cb106aTimo Sirainen tested alternatives are: fcntl locking (Linux 2.6, Solaris),
4f49b5cbfa6b9e6e4a213009ea6bb84337cb106aTimo Sirainen fchown() (Solaris) and dup()+close() (Linux 2.6, Solaris).
4f49b5cbfa6b9e6e4a213009ea6bb84337cb106aTimo Sirainen Read cache flushing is more problematic. There's no universal way to do it.
4f49b5cbfa6b9e6e4a213009ea6bb84337cb106aTimo Sirainen The working methods are:
4f49b5cbfa6b9e6e4a213009ea6bb84337cb106aTimo Sirainen Linux 2.6: fcntl(), O_DIRECT
4f49b5cbfa6b9e6e4a213009ea6bb84337cb106aTimo Sirainen Solaris: fchown(), fcntl(), dup()+close()
4f49b5cbfa6b9e6e4a213009ea6bb84337cb106aTimo Sirainen FreeBSD 6.2: fchown()