From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jason Baron Subject: (unknown) Date: Tue, 13 Jun 2006 15:01:46 -0400 (EDT) Message-ID: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Cc: linux-fsdevel@vger.kernel.org, jlayton@redhat.com Return-path: Received: from mx1.redhat.com ([66.187.233.31]:58840 "EHLO mx1.redhat.com") by vger.kernel.org with ESMTP id S1750909AbWFMTGn (ORCPT ); Tue, 13 Jun 2006 15:06:43 -0400 To: matthew@wil.cx Sender: linux-fsdevel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org Hi, If one tries to do a fcntl(fd, F_SETLEASE, F_RDLCK) on a file that is open for writing, the error returned is always -EAGAIN. This seems like the wrong error return for the case where 'fd' points to a file_struct that has FMODE_WRITE set. No matter how many times one calls the fcntl on that 'fd' it will fail. Therefore, i think the return value should be -EINVAL in this case. The patch below implements this behavior. Some more context for this issue can be found at: http://lkml.org/lkml/2005/5/2/20. Patch is based on a suggestion from Jeff Layton. thanks, -Jason Signed-off-by: Jason Baron --- linux-2.6/fs/locks.c.bak 2006-06-13 10:36:58.000000000 -0400 +++ linux-2.6/fs/locks.c 2006-06-13 10:41:19.000000000 -0400 @@ -1338,8 +1338,11 @@ lease = *flp; error = -EAGAIN; - if ((arg == F_RDLCK) && (atomic_read(&inode->i_writecount) > 0)) + if ((arg == F_RDLCK) && (atomic_read(&inode->i_writecount) > 0)) { + if (filp->f_mode & FMODE_WRITE) + error = -EINVAL; goto out; + } if ((arg == F_WRLCK) && ((atomic_read(&dentry->d_count) > 1) || (atomic_read(&inode->i_count) > 1)))