Bug 322871 - [PATCH] Fail to update content of file.
[PATCH] Fail to update content of file.
Status: CLOSED DUPLICATE of bug 359651
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: kernel (Show other bugs)
All Linux
low Severity high
: ---
: ---
Assigned To: Red Hat Kernel Manager
Martin Jenner
Depends On:
  Show dependency treegraph
Reported: 2007-10-08 04:53 EDT by jiangguiqing
Modified: 2008-04-29 09:10 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2008-04-29 09:10:43 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
The patch for nfs4proc.c of the kernel. (694 bytes, patch)
2007-10-08 04:53 EDT, jiangguiqing
no flags Details | Diff

  None (edit)
Description jiangguiqing 2007-10-08 04:53:53 EDT
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)

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");
    printf("sleeping,please do echo operation on server.\n");
    ret = read(fd, readbuf, 1024);
    printf("read: %s\n",readbuf);
    printf("test end\n");

Reproduce Environment :
        showmount -e : /tmp *

Steps to Reproduce :
1. On Client :
   mount -t nfs4 /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.
Comment 1 jiangguiqing 2007-10-08 04:53:53 EDT
Created attachment 219141 [details]
The patch for nfs4proc.c of the kernel.
Comment 2 Jeff Layton 2008-04-29 09:10:43 EDT

*** This bug has been marked as a duplicate of 359651 ***

Note You need to log in before you can comment on or make changes to this bug.