[linux-cifs-client] fcntl(): file unlocking failure

Steve French smfltc at us.ibm.com
Tue Nov 14 14:56:32 GMT 2006


> I need to open a file and to lock it for both read and write access.
>
> The file is in a network directory on a Windows server. To access it
> from Linux (Debian), I use CIFS with mandatory locks activated:
>
> mount -t cifs -o mand \\\\server\\share MountFolder
>
> I test it with a C program using fcntl(). It behaves well if I mount the
> share with SMBFS. But with CIFS, unlocking operation fails: I get Error
> 5: Input / Output Error.
>
> Test program:
>
>     fd = open("MountFolder/b.txt", O_RDWR | O_EXCL | O_APPEND);
>
>     if (fd == -1) 
>     {
>          // erreur ...
>     }
>
>     fl.l_type = F_WRLCK;
>     fl.l_whence = SEEK_SET;
>     fl.l_start = 0;
>     fl.l_len = 0;
>
>     if (fcntl(fd, F_SETLK, &fl) == -1)
>     {
> 	// Error...
>     } 
>
>     else 
>     {
>         printf("Lock granted.\n");
>
>         // Unlock the locked bytes 
>         fl.l_type = F_UNLCK;
>
>         if (fcntl(fd, F_SETLK, &fl) == -1) 
>         {
>            printf("Unlocking operation failed.\nError: %i \n", errno);
>            perror(s);
>         }
>         else
>         {
>             printf("File unlocked.\n");
>         }
>     }
>
> Why does unlock fail?
>
> Thanks
>
>
>   
Which kernel?  You can type "cat /proc/version" to check the version.

There was a bug introduced in 2.6.18 (fixed in 2.6.19) for posix byte 
range unlock to Windows servers.

To work around it you can mount with the mount option "nobrl" (which 
makes cifs like smbfs not
send byte range lock requests to the server, and just check them 
locally).   This may get updated
in a 2.6.18 point release but is fixed in 2.6.19


More information about the linux-cifs-client mailing list