All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] SGI 901086: NFSv2 SETATTR current server time support
@ 2003-10-20 10:05 Greg Banks
  2003-10-21  6:40 ` Neil Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Greg Banks @ 2003-10-20 10:05 UTC (permalink / raw)
  To: Neil Brown, Trond Myklebust; +Cc: Linux NFS Mailing List

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] SGI 901086: NFSv2 SETATTR current server time support
  2003-10-20 10:05 [PATCH] SGI 901086: NFSv2 SETATTR current server time support Greg Banks
@ 2003-10-21  6:40 ` Neil Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Neil Brown @ 2003-10-21  6:40 UTC (permalink / raw)
  To: Greg Banks; +Cc: Trond Myklebust, Linux NFS Mailing List

On Monday October 20, gnb@melbourne.sgi.com wrote:
> G'day,
> 
> SGI bug 901086.
...
> 
> 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).
> 

Hmmm... how delightful :-(

But, it seems not unreasonable.  I will forward nfsd patches to Linus and
Marcelo.

Thanks.

NeilBrown


-------------------------------------------------------
This SF.net email is sponsored by OSDN developer relations
Here's your chance to show off your extensive product knowledge
We want to know what you know. Tell us and you have a chance to win $100
http://www.zoomerang.com/survey.zgi?HRPT1X3RYQNC5V4MLNSV3E54
_______________________________________________
NFS maillist  -  NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-10-21  8:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-20 10:05 [PATCH] SGI 901086: NFSv2 SETATTR current server time support Greg Banks
2003-10-21  6:40 ` Neil Brown

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.