Description of problem : If an NFS client open a file over NFS, and then this file is modified on the server,when read the file on Client,the contents of file is wrong(Client can't get Server's modify). Version-Release number of selected component (if applicable) : RHEL4U5 (kernel-2.6.9-55.EL) nfs-utils-1.0.6-80.EL4 How reproducible : Use the following C program : ---------------------------------------------------------------- #include <stdio.h> #include <fcntl.h> int main() { int fd, ret; char readbuf[1024]=""; char *sfile = "/mnt/testfile"; printf("test start\n"); if ((fd = open(s, O_CREAT|O_TRUNC|O_RDWR ,0700)) < 0) { printf("can't open file\n"); exit(1); } printf("sleeping,please do echo operation on server.\n"); sleep(60); ret = read(fd, readbuf, 1024); printf("read: %s\n",readbuf); close(fd); printf("test end\n"); } ---------------------------------------------------------------- Reproduce Environment : Server: 192.168.1.2 showmount -e : /tmp * Client: 192.168.1.1 Steps to Reproduce : 1. On Client : mount -t nfs4 192.168.1.2:/ /mnt 2. On Client : run above C program 3. On Server : echo teststring >> /tmp/testfile (Do the echo operation while C program sleeping) 4. On Client : See the C program execute result Actual Results : read: (NULL) Expected Results : read: teststring Additional info : I have investigated the problem, and found the cause : In nfsv4 occasions,opening a file with write mode calls the function nfs4_proc_file_open(),and nfs4_proc_file_open() will call nfs_begin_data_update() to declare that a set of operations will update file data on the server. After modifying the file at server side, the Client will call nfs_update_inode () to update file properties, but nfs_begin_data_update() has been called while opening the file, which resulted in nfs_update_inode() to race with nfs_end_data_update() while updating file properties, so i_size of inode cannot be updated correctly (Please refer to nfs_update_inode function). If the i_size is not updated, nfs_readpages() will not be called for loading data at server side while the client is reading files (Please refer to __do_page_cache_readahead function) To resolve this problem, I have made the patch for the kernel. After the patch is applied, the problem can be resolved.
Created attachment 219141 [details] The patch for nfs4proc.c of the kernel.
*** This bug has been marked as a duplicate of 359651 ***