You are not logged in.

#1 2014-07-08 01:01:20

azzido
Member
Registered: 2014-05-01
Posts: 18

NFS file locking issue

I started experiencing this strange issue a couple of weeks ago, but I did not have time to look into it until now. That makes it difficult to identify which package update caused it.

Whenever I try to save a new or existing text file to the NFS share using Kate or KWrite I get a message "The document could not be saved, as it was not possible to write to /mnt/nfsshare.". Similar things happen with Gedit as well. Nothing has changed on the NFS server (Solaris 11) and I made sure that I have all necessary permissions.

Using strace (strace -p <pid> -e trace=file,close) I was able to observe file system syscalls that Kate is making:

open("/mnt/nfsshare/testkwrite2br4238.new", O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0600) = 17
open("/mnt/nfsshare/testkwrite2br4238.new", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666) = 19
close(17)                               = 0
close(19)                               = 0
rename("/mnt/nfsshare/testkwrite2br4238.new", "/mnt/nfsshare/testkwrite2") = -1 EBUSY (Device or resource busy)
unlink("/mnt/nfsshare/testkwrite2br4238.new") = -1 EBUSY (Device or resource busy)

Kate is able to create the temp file, but then receives an error "Device or resource busy" when trying to rename it to permanent name. If I try to delete the temp file in the command line I get error "rm: cannot remove ‘testkwrite2br4238.new’: Device or resource busy". Neither lsof nor lslocks list this file as being in use or locked. I am also able to unmount the file system, but still get the same error when trying to delete the file after re-mounting it.

To eliminate Kate as a possible cause of this I created a simple C program that performs same steps as Kate and was able to reproduce the issue:

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>

int
main (void)
{
  int fd1, fd2;
  char fName1[] = "/mnt/nfsshare/test.txt";
  char fName2[] = "/mnt/nfsshare/test_renamed.txt";

  fd1 = open(fName1, O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0600);

  if (-1 == fd1) {
    printf("\nopen() 1 failed with error [%s]",strerror(errno));
    return 1;
  } else {
    printf("\nopen() 1 successful");
  }

  fd2 = open(fName1, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666);

  if (-1 == fd2) {
    printf("\nopen() 2 failed with error [%s]",strerror(errno));
    return 1;
  } else {
    printf("\nopen() 2 successful");
  }

  if (-1 == close(fd1)) {
    printf("\nclose() 1 failed with error [%s]",strerror(errno));
  } else {
    printf("\nclose() 1 successful");
  }

  if (-1 == close(fd2)) {
    printf("\nclose() 2 failed with error [%s]",strerror(errno));
  } else {
    printf("\nclose() 2 successful");
  }
  
  if (-1 == rename(fName1, fName2)) {
    printf("\rrename() failed with error [%s]",strerror(errno));
  } else {
    printf("\rrename() successful");
  }
   
  return 0;
}

output when program is executed:

open() 1 successful
open() 2 successful
close() 1 successful
rename() failed with error [Device or resource busy]

The issue is caused by the fact that file is opened twice before both file descriptors are closed. If I perform open, close, open, close file does not stay in the locked state and I am able to rename it.

I ran this program on the CentOS box that connects to the same NFS server and it did not run into any issues. At this point I think this might be a kernel or nfs-utils package bug. I really don't know enough about NFS to be able to accurately determine it.

I hope someone can try to reproduce it or help me find out additional details

Thanks for reading and sorry for the long post.

Offline

#2 2014-07-12 22:30:25

azzido
Member
Registered: 2014-05-01
Posts: 18

Re: NFS file locking issue

Today I installed LTS kernel 3.14.12-1 and could not reproduce the issue, so I am pretty sure this issue has something to do with kernel 3.15

Offline

Board footer

Powered by FluxBB