Bug 359651

Summary: [PATCH] nfsv4 fails to update content of files when open for write
Product: Red Hat Enterprise Linux 4 Reporter: jiangguiqing <jianggq>
Component: kernelAssignee: Jeff Layton <jlayton>
Status: CLOSED ERRATA QA Contact: Martin Jenner <mjenner>
Severity: high Docs Contact:
Priority: low    
Version: 4.5CC: chet.burgess, staubach, steved
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: RHSA-2008-0665 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2008-07-24 19:19:02 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 430698    
Attachments:
Description Flags
The patch for nfs4proc.c of the kernel.
none
Patch for rhel4.6 none

Description jiangguiqing 2007-10-31 05:29:21 UTC
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.

Comment 1 jiangguiqing 2007-10-31 05:29:21 UTC
Created attachment 244101 [details]
The patch for nfs4proc.c of the kernel.

Comment 2 Jeff Layton 2007-11-13 18:50:09 UTC
Thanks. Looks similar to a NFSv2/3 patch that we brought in late in the 4.5
update cycle. I'll have a closer look when I get a chance, but looks reasonable
at first glance.


Comment 3 Jeff Layton 2007-11-20 01:30:19 UTC
I've posted some test kernels with this patch on my people page:

http://people.redhat.com/jlayton

..could you test them and confirm that the problem is resolved?


Comment 4 jiangguiqing 2007-11-20 09:09:55 UTC
> ..could you test them and confirm that the problem is resolved?

I have tested 'kernel-2.6.9-68.EL.jtltest.24.i686.rpm/kernel-2.6.9-
68.EL.jtltest.24.ia64.rpm', 
and confirmed that the problem is resolved.

It is confirmed that the patched can really solve the problem. 


Comment 5 jiangguiqing 2007-12-10 03:47:41 UTC
Created attachment 282461 [details]
Patch for rhel4.6

Comment 6 jiangguiqing 2007-12-10 03:49:58 UTC
RHEL4.6 also have this problem.
I have make patch for rhel4.6,and confirmed that the patch can fix this problem.


Comment 8 RHEL Program Management 2008-01-02 16:05:56 UTC
This request was evaluated by Red Hat Product Management for inclusion in a Red
Hat Enterprise Linux maintenance release.  Product Management has requested
further review of this request by Red Hat Engineering, for potential
inclusion in a Red Hat Enterprise Linux Update release for currently deployed
products.  This request is not yet committed for inclusion in an Update
release.

Comment 10 Vivek Goyal 2008-03-27 23:22:59 UTC
Committed in 68.27.EL . RPMS are available at http://people.redhat.com/vgoyal/rhel4/

Comment 12 Jeff Layton 2008-04-29 13:10:44 UTC
*** Bug 322871 has been marked as a duplicate of this bug. ***

Comment 15 errata-xmlrpc 2008-07-24 19:19:02 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHSA-2008-0665.html