Bug 7630 - Can not copy new files to a mounted share with oplock enabled
Can not copy new files to a mounted share with oplock enabled
Product: CifsVFS
Classification: Unclassified
Component: kernel fs
x86 Linux
: P3 normal
: ---
Assigned To: Suresh Jayaraman (mail address is dead)
Depends on:
  Show dependency treegraph
Reported: 2010-08-19 00:27 UTC by Zhang Nan
Modified: 2010-10-05 06:18 UTC (History)
1 user (show)

See Also:

Proposed patch (3.39 KB, patch)
2010-09-17 08:29 UTC, Suresh Jayaraman (mail address is dead)
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zhang Nan 2010-08-19 00:27:46 UTC
I run 2.6.35 linux kernel on Fedora 13. When I copy new files to a mounted CIFS share (either WinXP or Samba server), oplock is always disabled on these files.

    1. sudo mount -t cifs //ip/share /mnt
    2. sudo cp new_files /mnt

Oplock status can be observed by adding the following code in cifs_file_aio_write():

        cFYI(1, "zn: cifs_file_aio_write(): clientCanCacheAll = %d",
        cFYI(1, "zn: cifs_file_aio_write(): clientCanCacheRead = %d",

In my test both clientCanCacheAll and clientCanCacheRead are set to 0 and filemap_fdatawrite() is always called.

I found that before cifs_create() calls cifs_new_fileinfo(), the value of "oplock" variable in cifs_create() is 0x20001 (CIFS_CREATE_ACTION | OPLOCK_EXCLUSIVE). But this value is not used in cifs_new_fileinfo(). Instead, a local "oplock" variable (set to REQ_OPLOCK) is used by cifs_new_fileinfo() to compare with OPLOCK_EXCLUSIVE/OPLOCK_READ. When the comparison fails, clientCanCacheAll/clientCanCacheRead are not set to "true".

cifs_new_fileinfo() is called by cifs_create(), cifs_open() and cifs_lookup(). Maybe it should accept oplock as a function parameter.

Sorry a patch is not provided because I'm new to Samba/CIFS code.

Comment 1 Suresh Jayaraman (mail address is dead) 2010-09-17 08:29:52 UTC
Created attachment 5967 [details]
Proposed patch

Thanks for the bug report. Indeed, you're correct! The oplock handling seems broken. 

Could you please test the attached fix and report?
Comment 2 Zhang Nan 2010-09-29 00:27:35 UTC
I manually applied the patch to tree, and it works fine.
The debug statements I added now print:

    fs/cifs/cifsfs.c: zn: cifs_file_aio_write(): clientCanCacheAll = 1
    fs/cifs/cifsfs.c: zn: cifs_file_aio_write(): clientCanCacheRead = 1
Comment 3 Suresh Jayaraman (mail address is dead) 2010-10-01 00:54:46 UTC
Patch committed to cifs-2.6 git via commit 23ec47c2ad8115c70a2d5fd1cb3f46b1bf30246a

Can be marked as FIXED (I'm unable to do so..).
Comment 4 Jeff Layton 2010-10-05 06:18:40 UTC
Marking FIXED as requested...