Skip to contentSkip to conversation

unfsd: fix invalid argument error for setattr request

PATCH New Ryusuke Konishi 1 participant 1 message Aug 16, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 unfsd: fix invalid argument error for setattr request

Hi folks,

I found that the Linux user-space NFS server (unfsd) fails for setattr requests against the kernel 2.6.22 and later. For instance, it returns an invalid argument error when overwriting an existing file by dd command as follows.

 # mount -t nfs server:/pub /nfs
 # dd if=/dev/zero of=/nfs/aaa bs=4k count=1
 1+0 records in
 1+0 records out
 4096 bytes (4.1 kB) copied, 0.000462054 seconds, 8.9 MB/s
 # dd if=/dev/zero of=/nfs/aaa bs=4k count=1
 dd: opening `/nfs/aaa': Invalid argument

I found out this is caused by the following two reasons.

(1) Since kernel 2.6.22, range checks of utimes() system call got more strict by an utimensat related patch (1c710c896eb461895d3c399e15bb5f20b39c9073)

(2) Linux NFS client uses a Sun convention for "set to current sever time" in which an invalid value useconds=1000000 is passed to server. However, unfsd tries to use it as-is for changing timestamp of requested files through the utimes() system call.

This patch fixes the problem by adding the Sun convention support to unfsd.

Best regards,
---
Ryusuke Konishi <[email protected]>

setattr.c +29 -6
Index: nfs-user-server-2.2beta47/setattr.c
===================================================================
@@ -16,6 +16,7 @@
 #include "nfsd.h"
 
 #define IGNORE_TIME	((unsigned int) -1)
+#define SET_SERVER_TIME	1000000		/* Sun convention for "set to current server time" */
 
 /*
  * Set file attributes based on file handle
@@ -70,6 +71,17 @@
 	if (flags & SATTR_UTIMES) {
 		unsigned int	a_secs = attr->atime.seconds;
 		unsigned int	m_secs = attr->mtime.seconds;
+		unsigned int	a_usecs = attr->atime.useconds;
+		unsigned int	m_usecs = attr->mtime.useconds;
+		struct timeval	server_time;
+
+		if (a_usecs == SET_SERVER_TIME || m_usecs == SET_SERVER_TIME) {
+			gettimeofday(&server_time, NULL);
+			if (a_usecs == SET_SERVER_TIME)
+				a_secs = server_time.tv_sec;
+			if (m_usecs == SET_SERVER_TIME)
+				m_secs = server_time.tv_sec;
+		}
 
 		if ((a_secs != IGNORE_TIME && a_secs != s->st_atime)
 		 || (m_secs != IGNORE_TIME && m_secs != s->st_mtime)) {
@@ -78,19 +90,30 @@
 			/*
 			 * Cover for partial utime setting
 			 * Alan Cox <[email protected]>
+			 *
+			 * Handle Sun convention for "set to current server time"
+			 * Ryusuke Konishi <[email protected]>
 			 */
 			if (a_secs != IGNORE_TIME) {
-				tvp[0].tv_sec  = attr->atime.seconds;
-				tvp[0].tv_usec = attr->atime.useconds;
-				s->st_atime    = attr->atime.seconds;
+				if (a_usecs != SET_SERVER_TIME) {
+					tvp[0].tv_sec  = attr->atime.seconds;
+					tvp[0].tv_usec = attr->atime.useconds;
+				} else
+					tvp[0] = server_time;
+
+				s->st_atime    = a_secs;
 			} else {
 				tvp[0].tv_sec  = s->st_atime;
 				tvp[0].tv_usec = 0;
 			}
 			if (m_secs != IGNORE_TIME) {
-				tvp[1].tv_sec  = attr->mtime.seconds;
-				tvp[1].tv_usec = attr->mtime.useconds;
-				s->st_mtime    = attr->mtime.seconds;
+				if (m_usecs != SET_SERVER_TIME) {
+					tvp[1].tv_sec  = attr->mtime.seconds;
+					tvp[1].tv_usec = attr->mtime.useconds;
+				} else
+					tvp[1] = server_time;
+
+				s->st_mtime    = m_secs;
 			} else {
 				tvp[1].tv_sec  = s->st_mtime;
 				tvp[1].tv_usec = 0;

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs