All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Banks <gnb@melbourne.sgi.com>
To: Neil Brown <neilb@cse.unsw.edu.au>,
	Trond Myklebust <trond.myklebust@fys.uio.no>
Cc: Linux NFS Mailing List <nfs@lists.sourceforge.net>
Subject: [PATCH] SGI 901086: NFSv2 SETATTR current server time support
Date: Mon, 20 Oct 2003 20:05:19 +1000	[thread overview]
Message-ID: <3F93B35F.EAFC7028@melbourne.sgi.com> (raw)

G'day,

SGI bug 901086.

In the NFSv3 RFC, the sattr3 structure passed in the SETATTR call allows
for the client to request that the mtime and/or atime of an inode be set
to the current server time, the given (client) time, or not changed.  The
set-to-current-server value is used when you run "touch file" on the client.

This is significant for two reasons.  First, if there is clock skew between
the client and server there are times when you want the server time.  Secondly, 
the filesystem permissions checks for the two cases are actually different:
setting to an explicit time requires the setting process to own the file (or
be root), but setting to the current time requires only that the file be
writable to the process (or the process be root).

The NFSv2 RFC defines no such encoding for the sattr structure.  However
Solaris and Irix machine obey a convention where passing the invalid value
mtime.useconds=1000000 means "set both mtime and atime to the current
server time".  The convention is documented in the book "NFS Illustrated"
by Brent Callaghan.  The patch below implements this convention for the
Linux client and server (hence multiple To:s).

Tested between ia64 Linux 2.4.21, Irix & Solaris.



===========================================================================
linux/linux/fs/nfs/nfs2xdr.c
===========================================================================

--- /usr/tmp/TmpDir.14185-0/linux/linux/fs/nfs/nfs2xdr.c_1.11	Mon Oct 20 19:30:02
2003
+++ linux/linux/fs/nfs/nfs2xdr.c	Mon Oct 20 19:08:49 2003
@@ -139,9 +139,21 @@
 		*p++ = ~(u32) 0;
 	}
 
-	if (attr->ia_valid & (ATTR_MTIME|ATTR_MTIME_SET)) {
+	if (attr->ia_valid & ATTR_MTIME_SET) {
 		*p++ = htonl(attr->ia_mtime);
 		*p++ = 0;
+	} else if (attr->ia_valid & ATTR_MTIME) {
+	    	/*
+		 * Passing the invalid value useconds=1000000 for mtime
+		 * is a Sun convention for "set both mtime and atime to
+		 * current server time".  It's needed to make permissions
+		 * checks for the "touch" program across v2 mounts to
+		 * Solaris and Irix boxes work correctly. See description of
+		 * sattr in section 6.1 of "NFS Illustrated" by
+		 * Brent Callaghan, Addison-Wesley, ISBN 0-201-32750-5
+		 */
+		*p++ = htonl(attr->ia_mtime);
+		*p++ = __constant_htonl(1000000);
 	} else {
 		*p++ = ~(u32) 0;	
 		*p++ = ~(u32) 0;

===========================================================================
linux/linux/fs/nfsd/nfsxdr.c
===========================================================================

--- /usr/tmp/TmpDir.14185-0/linux/linux/fs/nfsd/nfsxdr.c_1.12	Mon Oct 20 19:30:02
2003
+++ linux/linux/fs/nfsd/nfsxdr.c	Mon Oct 20 18:27:02 2003
@@ -126,6 +126,17 @@
 	tmp  = ntohl(*p++); tmp1 = ntohl(*p++);
 	if (tmp != (u32)-1 && tmp1 != (u32)-1) {
 		iap->ia_valid |= ATTR_MTIME | ATTR_MTIME_SET;
+	    	/*
+		 * Passing the invalid value useconds=1000000 for mtime
+		 * is a Sun convention for "set both mtime and atime to
+		 * current server time".  It's needed to make permissions
+		 * checks for the "touch" program across v2 mounts to
+		 * Solaris and Irix boxes work correctly. See description of
+		 * sattr in section 6.1 of "NFS Illustrated" by
+		 * Brent Callaghan, Addison-Wesley, ISBN 0-201-32750-5
+		 */
+		if (tmp1 == 1000000)
+			iap->ia_valid &= ~(ATTR_ATIME_SET|ATTR_MTIME_SET);
 		iap->ia_mtime = tmp;
 	}
 	return p;

Greg.
-- 
Greg Banks, R&D Software Engineer, SGI Australian Software Group.
I don't speak for SGI.


-------------------------------------------------------
This SF.net email sponsored by: Enterprise Linux Forum Conference & Expo
The Event For Linux Datacenter Solutions & Strategies in The Enterprise 
Linux in the Boardroom; in the Front Office; & in the Server Room 
http://www.enterpriselinuxforum.com
_______________________________________________
NFS maillist  -  NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs

             reply	other threads:[~2003-10-20 11:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-20 10:05 Greg Banks [this message]
2003-10-21  6:40 ` [PATCH] SGI 901086: NFSv2 SETATTR current server time support Neil Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3F93B35F.EAFC7028@melbourne.sgi.com \
    --to=gnb@melbourne.sgi.com \
    --cc=neilb@cse.unsw.edu.au \
    --cc=nfs@lists.sourceforge.net \
    --cc=trond.myklebust@fys.uio.no \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.