file locking (fcntl) bug in 2.4.19
Subsystems (2)
Yep, 2.4 & 2.5 are broken. Here's a patch which both marcelo and alan refuse to apply, but fixes the problem.
fs/locks.c +9 -16
@@ -134,15 +134,9 @@static kmem_cache_t *filelock_cache;/* Allocate an empty lock structure. */ -static struct file_lock *locks_alloc_lock (int account) +static struct file_lock *locks_alloc_lock (void ) { -struct file_lock *fl; -if (account && current->locks >= current->rlim[RLIMIT_LOCKS ].rlim_cur) -return NULL ; - fl =kmem_cache_alloc (filelock_cache,SLAB_KERNEL ); -if (fl) - current->locks++; -return fl; +return kmem_cache_alloc (filelock_cache,SLAB_KERNEL ); }/* Free a lock which is not in use. */
@@ -152,7 +146,6 @@BUG ();return ; } - current->locks--;if (waitqueue_active (&fl->fl_wait))panic ("Attempting to free lock with active wait queue" );
@@ -219,7 +212,7 @@/* Fill in a file_lock structure with an appropriate FLOCK lock. */ static struct file_lock *flock_make_lock (struct file *filp,unsigned int type) { -struct file_lock *fl =locks_alloc_lock (1 ); +struct file_lock *fl =locks_alloc_lock ();if (fl ==NULL )return NULL ;
@@ -348,7 +341,7 @@/* Allocate a file_lock initialised to this type of lease */ static int lease_alloc (struct file *filp,int type,struct file_lock **flp) { -struct file_lock *fl =locks_alloc_lock (1 ); +struct file_lock *fl =locks_alloc_lock ();if (fl ==NULL )return -ENOMEM ;
@@ -712,7 +705,7 @@ size_t count) {struct file_lock *fl; -struct file_lock *new_fl =locks_alloc_lock (0 ); +struct file_lock *new_fl =locks_alloc_lock ();int error;if (new_fl ==NULL )
@@ -872,8 +865,8 @@* We may need two file_lock structures for this operation, * so we get them in advance to avoid races. */ - new_fl =locks_alloc_lock (0 ); - new_fl2 =locks_alloc_lock (0 ); + new_fl =locks_alloc_lock (); + new_fl2 =locks_alloc_lock (); error = -ENOLCK ;/* "no luck" */ if (!(new_fl && new_fl2)) goto out_nolock;
@@ -1426,7 +1419,7 @@int fcntl_setlk (unsigned int fd,unsigned int cmd,struct flock *l) {struct file *filp; -struct file_lock *file_lock =locks_alloc_lock (0 ); +struct file_lock *file_lock =locks_alloc_lock ();struct flock flock;struct inode *inode;int error;
@@ -1582,7 +1575,7 @@int fcntl_setlk64 (unsigned int fd,unsigned int cmd,struct flock64 *l) {struct file *filp; -struct file_lock *file_lock =locks_alloc_lock (0 ); +struct file_lock *file_lock =locks_alloc_lock ();struct flock64 flock;struct inode *inode;int error;
Signature · 1 line
Revolutions do not require corporate support.
Mr. Wilcox, thanks for the reply. I checked the source of the stock 2.4.19 kernel and it seems to have part of the patch incorporated. I checked to make sure the patch is fully applied and recompiled the kernel, and the bug still shows up (less frequently, but the test program lockbug.c can still trigger the bug). It seems the problem is not totally gone yet.
Thanks for any help.
Andy
Quoted 103 lines · --- Matthew Wilcox
Yep, 2.4 & 2.5 are broken. Here's a patch which
both marcelo and alan
refuse to apply, but fixes the problem.diff -urNX dontdiff
linux-2418/fs/locks.clinux-2418-acct/fs/locks.cfs/locks.c +0
-02002
fs/locks.c +2
-8@@ -134,15 +134,9 @@static kmem_cache_t *filelock_cache;/* Allocate an empty lock structure. */ -static struct file_lock *locks_alloc_lock (int account) +static struct file_lock *locks_alloc_lock(void) { -struct file_lock *fl; -if (account && current->locks >= current->rlim[RLIMIT_LOCKS].rlim_cur) -return NULL ; - fl =kmem_cache_alloc (filelock_cache, SLAB_KERNEL); -if (fl) - current->locks++; -return fl; + return kmem_cache_alloc(filelock_cache,
SLAB_KERNEL);
}/* Free a lock which is not in use. */
fs/locks.c +0
-1@@ -152,7 +146,6 @@BUG ();return ; } - current->locks--;if (waitqueue_active (&fl->fl_wait))panic ("Attempting to free lock with active wait queue");@@ -219,7 +212,7 @@/* Fill in a file_lock structure with an appropriate FLOCK lock. */
static structfile_lock*flock_make_lock(struct
file *filp, unsigned int type)
{fs/locks.c +1
-1-struct file_lock *fl =locks_alloc_lock (1 ); +struct file_lock *fl =locks_alloc_lock ();if (fl ==NULL )return NULL ;@@ -348,7 +341,7 @@/* Allocate a file_lock initialised to this type of lease */
static int lease_alloc(struct file *filp, int type,
structfile_lock**flp)
{fs/locks.c +4
-4-struct file_lock *fl =locks_alloc_lock (1 ); +struct file_lock *fl =locks_alloc_lock ();if (fl ==NULL )return -ENOMEM ;@@ -712,7 +705,7 @@ size_t count) {struct file_lock *fl; -struct file_lock *new_fl =locks_alloc_lock (0 ); +struct file_lock *new_fl =locks_alloc_lock ();int error;if (new_fl ==NULL )@@ -872,8 +865,8 @@* We may need two file_lock structures for this operation, * so we get them in advance to avoid races. */ - new_fl =locks_alloc_lock (0 ); - new_fl2 =locks_alloc_lock (0 ); + new_fl =locks_alloc_lock (); + new_fl2 =locks_alloc_lock (); error = -ENOLCK ;/* "no luck" */ if (!(new_fl && new_fl2))fs/locks.c +1
-1goto out_nolock;@@ -1426,7 +1419,7 @@int fcntl_setlk (unsigned int fd,unsigned int cmd,struct flock *l) {struct file *filp; -struct file_lock *file_lock =locks_alloc_lock (0 ); +struct file_lock *file_lock =locks_alloc_lock ();struct flock flock;struct inode *inode;fs/locks.c +1
-1int error;@@ -1582,7 +1575,7 @@int fcntl_setlk64 (unsigned int fd,unsigned int cmd,struct flock64 *l) {struct file *filp; -struct file_lock *file_lock =locks_alloc_lock (0 ); +struct file_lock *file_lock =locks_alloc_lock ();struct flock64 flock;struct inode *inode;
Quoted 4 lines
int error;
Signature · 1 line
Revolutions do not require corporate support.
__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com
Hi, I just figured out the problem is not with the locking code in the kernel, which works with your patch, but in the user space application setting the file permission in such a way as to use mandatory locks, that surely fails on a NFS volume...
The user space application in this case is Samba 2.2.5.
Thanks for your help.
Andy
Quoted 125 lines · --- Andy Tai
Mr. Wilcox, thanks for the reply. I checked the source of the stock 2.4.19 kernel and it seems to have
part of the patch incorporated. I checked to make sure the patch is fully applied and recompiled the kernel, and the bug still shows up (less frequently, but the test programlockbug.ccan still trigger the bug). It seems the problem is not totally gone yet.Thanks for any help.
Andy
Quoted 53 lines · --- Matthew Wilcox
Yep, 2.4 & 2.5 are broken. Here's a patch which
both marcelo and alan
refuse to apply, but fixes the problem.diff -urNX dontdiff
linux-2418/fs/locks.clinux-2418-acct/fs/locks.cfs/locks.c +0
-02002
fs/locks.c +2
-8@@ -134,15 +134,9 @@static kmem_cache_t *filelock_cache;/* Allocate an empty lock structure. */ -static struct file_lock *locks_alloc_lock (int account) +static struct file_lock *locks_alloc_lock(void) { -struct file_lock *fl; -if (account && current->locks >= current->rlim[RLIMIT_LOCKS].rlim_cur) -return NULL ; - fl =kmem_cache_alloc (filelock_cache, SLAB_KERNEL); -if (fl) - current->locks++; -return fl; + return kmem_cache_alloc(filelock_cache,
SLAB_KERNEL);
}/* Free a lock which is not in use. */
fs/locks.c +0
-1@@ -152,7 +146,6 @@BUG ();return ; } - current->locks--;if (waitqueue_active (&fl->fl_wait))panic ("Attempting to free lock with active wait queue");@@ -219,7 +212,7 @@/* Fill in a file_lock structure with an appropriate FLOCK lock. */
static structfile_lock*flock_make_lock(struct
file *filp, unsigned int type)
{fs/locks.c +1
-1-struct file_lock *fl =locks_alloc_lock (1 ); +struct file_lock *fl =locks_alloc_lock ();if (fl ==NULL )return NULL ;fs/locks.c line 341
Quoted 1 line
fs/locks.c +0
-0@@ -348,7 +341,7 @@/* Allocate a file_lock initialised to this type of
Quoted 2 lines
lease */
static int lease_alloc(struct file *filp, inttype,
Quoted 29 lines
struct
file_lock**flp)
{fs/locks.c +4
-4-struct file_lock *fl =locks_alloc_lock (1 ); +struct file_lock *fl =locks_alloc_lock ();if (fl ==NULL )return -ENOMEM ;@@ -712,7 +705,7 @@ size_t count) {struct file_lock *fl; -struct file_lock *new_fl =locks_alloc_lock (0 ); +struct file_lock *new_fl =locks_alloc_lock ();int error;if (new_fl ==NULL )@@ -872,8 +865,8 @@* We may need two file_lock structures for this operation, * so we get them in advance to avoid races. */ - new_fl =locks_alloc_lock (0 ); - new_fl2 =locks_alloc_lock (0 ); + new_fl =locks_alloc_lock (); + new_fl2 =locks_alloc_lock (); error = -ENOLCK ;/* "no luck" */ if (!(new_fl && new_fl2))fs/locks.c +0
-0goto out_nolock;fs/locks.c line 1419
Quoted 1 line
fs/locks.c +0
-0@@ -1426,7 +1419,7 @@ int fcntl_setlk(unsigned int fd, unsigned intcmd,
fs/locks.c
Quoted 4 lines
fs/locks.c +0
-1struct flock *l) {struct file *filp; - struct file_lock *file_lock =
locks_alloc_lock(0);fs/locks.c line 1423
Quoted 1 line
fs/locks.c +1
-0+ struct file_lock *file_lock =
locks_alloc_lock();fs/locks.c line 1586
Quoted 9 lines
fs/locks.c +0
-0struct flock flock;struct inode *inode;fs/locks.c +0
-1int error;@@ -1582,7 +1575,7 @@int fcntl_setlk64 (unsigned int fd,unsigned int cmd,struct flock64 *l) {struct file *filp; - struct file_lock *file_lock =
locks_alloc_lock(0);fs/locks.c line 1579
Quoted 1 line
fs/locks.c +1
-0+ struct file_lock *file_lock =
locks_alloc_lock();Quoted 4 lines
fs/locks.c +0
-0struct flock64 flock;struct inode *inode;int error;
Quoted 8 lines
Quoted 2 lines
Signature · 1 line
Revolutions do not require corporate support.__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com
__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com