Skip to contentSkip to conversation

Linux 2.6.10: locks are leaked

DISCUSSION Peter Karl Müller 2 participants 2 messages Mar 29, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Dear experts,

my home directories are exported from server to client (both vanilla 2.6.10). When I start the famous "skype" program from my home directory in a console, enter my account/password, and then terminate the skype process by ctrl-\ some file locks remain on the server. These file locks prevent a successfull re-login after a re-launch of "skype" (you get "Logging in failed").

I performed some tests with multiple running/stopped instances of

      1 #include <stdio.h>
      2 #include <sys/types.h>
      3 #include <sys/stat.h>
      4 #include <fcntl.h>
      5 #include <signal.h>
      6
      7 int main ()
      8 {
      9    int fd = open ("DATAFILE", O_RDWR, 0600);
     10    if (fd == -1)
     11       perror ("open"), exit (1);
     12    printf ("file opened\n");
     13    int rc = lockf (fd, F_LOCK, 0);
     14    if (rc)
     15       perror ("lockf"), exit (2);
     16    printf ("lock acquired\n");
     17    pid_t mypid = getpid ();
     18    printf ("pid = %d\n", mypid);
     19    sleep (10);
     20    kill (mypid, 9);
     21    return 0;
     22 }

and eventually ran into a well known kernel panic on the client. In two cases the server became fully inaccessible.

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#1 lore raw

ty den 29.03.2005 Klokka 02:25 (+0200) skreiv Peter Karl Müller:

Quoted 34 lines

Dear experts,

my home directories are exported from server to client (both vanilla 2.6.10). When I start the famous "skype" program from my home directory in a console, enter my account/password, and then terminate the skype process by ctrl-\ some file locks remain on the server. These file locks prevent a successfull re-login after a re-launch of "skype" (you get "Logging in failed").

I performed some tests with multiple running/stopped instances of

      1 #include <stdio.h>
      2 #include <sys/types.h>
      3 #include <sys/stat.h>
      4 #include <fcntl.h>
      5 #include <signal.h>
      6
      7 int main ()
      8 {
      9    int fd = open ("DATAFILE", O_RDWR, 0600);
     10    if (fd == -1)
     11       perror ("open"), exit (1);
     12    printf ("file opened\n");
     13    int rc = lockf (fd, F_LOCK, 0);
     14    if (rc)
     15       perror ("lockf"), exit (2);
     16    printf ("lock acquired\n");
     17    pid_t mypid = getpid ();
     18    printf ("pid = %d\n", mypid);
     19    sleep (10);
     20    kill (mypid, 9);
     21    return 0;
     22 }
Quoted 3 lines

and eventually ran into a well known kernel panic on the client. In two cases the server became fully inaccessible.

Please could you try to reproduce with 2.6.11? The latter contains the well-known fix (i.e. the attached patch).

Cheers,
Trond

Signature · 1 line
Trond Myklebust <[email protected]>

# This is a BitKeeper generated diff -Nru style patch. #
# ChangeSet
# 2005/01/16 19:53:47-08:00 [email protected]
# [PATCH] Fix an Oopsable condition in the NFS locking
#
# Signed-off-by: Trond Myklebust <[email protected]>
# Signed-off-by: Linus Torvalds <[email protected]>
#

# fs/nfs/file.c
#   2005/01/16 16:00:00-08:00 [email protected] +8 -4
#   Fix an Oopsable condition in the NFS locking
# 
diff -Nru a/fs/nfs/file.c b/fs/nfs/file.c
--- a/fs/nfs/file.c	2005-03-28 19:33:22 -05:00
+++ b/fs/nfs/file.c	2005-03-28 19:33:22 -05:00
@@ -347,8 +347,10 @@
 static int do_setlk(struct file *filp, int cmd, struct file_lock *fl)
 {
 	struct inode *inode = filp->f_mapping->host;
+	sigset_t oldset;
 	int status;

+ rpc_clnt_sigmask(NFS_CLIENT(inode), &oldset);
/*
* Flush all pending writes before doing anything
* with locks..
@@ -362,7 +364,7 @@
status = filemap_fdatawait(filp->f_mapping);
}
if (status < 0)
- return status;
+ goto out;

lock_kernel();
/* Use local locking if mounted with "-onolock" */
@@ -375,12 +377,12 @@
* the process exits.
*/
if (status == -EINTR || status == -ERESTARTSYS)
- posix_lock_file(filp, fl);
+ posix_lock_file_wait(filp, fl);
} else
status = posix_lock_file_wait(filp, fl);
unlock_kernel();
if (status < 0)
- return status;
+ goto out;
/*
* Make sure we clear the cache whenever we try to get the lock.
* This makes locking act as a cache coherency point.
@@ -391,7 +393,9 @@
up(&inode->i_sem); filemap_fdatawait(filp->f_mapping); nfs_zap_caches(inode);
- return 0;
+out:
+ rpc_clnt_sigunmask(NFS_CLIENT(inode), &oldset);
+ return status;
}

/*