From patchwork Mon Mar 30 06:01:16 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 15103 Received: from lists.samba.org (mail.samba.org [66.70.73.150]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n2U8oBWm010856 for ; Mon, 30 Mar 2009 08:50:11 GMT Received: from dp.samba.org (localhost [127.0.0.1]) by lists.samba.org (Postfix) with ESMTP id 3F8B4163D05 for ; Mon, 30 Mar 2009 08:49:54 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on dp.samba.org X-Spam-Level: X-Spam-Status: No, score=-1.2 required=3.8 tests=AWL,BAYES_00, FORGED_RCVD_HELO,RCVD_IN_SORBS_WEB autolearn=no version=3.1.7 X-Original-To: linux-cifs-client@lists.samba.org Delivered-To: linux-cifs-client@lists.samba.org Received: from mail.etersoft.ru (mail.etersoft.ru [87.249.47.46]) by lists.samba.org (Postfix) with ESMTP id 3A268163BCF for ; Mon, 30 Mar 2009 08:49:35 +0000 (GMT) Received: from localhost (as.office.etersoft.ru [192.168.0.10]) by mail.etersoft.ru (Postfix) with ESMTP id 1562320DF5A for ; Mon, 30 Mar 2009 12:49:50 +0400 (MSD) X-Virus-Scanned: amavisd-new at office.etersoft.ru Received: from mail.etersoft.ru ([192.168.0.1]) by localhost (as.office.etersoft.ru [192.168.0.10]) (amavisd-new, port 10024) with LMTP id m4Xmk84tlInk for ; Mon, 30 Mar 2009 12:49:45 +0400 (MSD) Received: from homestation.localnet (pppoe-88-147-209-216.san.ru [88.147.209.216]) by mail.etersoft.ru (Postfix) with ESMTP id 641EB303A0D for ; Mon, 30 Mar 2009 10:01:23 +0400 (MSD) From: Pavel Shilovsky To: linux-cifs-client@lists.samba.org Subject: Re: [linux-cifs-client] [PATCH] F_GETLK request - returning value Date: Mon, 30 Mar 2009 10:01:16 +0400 User-Agent: KMail/1.10.3 (Linux/2.6.26-1-686; KDE/4.1.3; i686; ; ) References: <200903292204.02755.piastry@etersoft.ru> <200903292208.10943.piastry@etersoft.ru> In-Reply-To: <200903292208.10943.piastry@etersoft.ru> MIME-Version: 1.0 Content-Disposition: inline Message-Id: <200903301001.17229.piastry@etersoft.ru> X-BeenThere: linux-cifs-client@lists.samba.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: The Linux CIFS VFS client List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-cifs-client-bounces+patchwork-cifs-client=patchwork.kernel.org@lists.samba.org Errors-To: linux-cifs-client-bounces+patchwork-cifs-client=patchwork.kernel.org@lists.samba.org I have found very stupid bug in my code that I couldn't catch later because I use version of cifs without forcemand option for testing. Signed-off-by: Pavel Shilovsky Acked-by: Jeff Layton diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index 8f0f86d..54a6a7f 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -1880,8 +1880,21 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon, } parm_data = (struct cifs_posix_lock *) ((char *)&pSMBr->hdr.Protocol + data_offset); - if (parm_data->lock_type == cpu_to_le16(CIFS_UNLCK)) + if (parm_data->lock_type == __constant_cpu_to_le16(CIFS_UNLCK)) pLockData->fl_type = F_UNLCK; + else { + if (parm_data->lock_type == + __constant_cpu_to_le16(CIFS_RDLCK)) + pLockData->fl_type = F_RDLCK; + else if (parm_data->lock_type == + __constant_cpu_to_le16(CIFS_WRLCK)) + pLockData->fl_type = F_WRLCK; + + pLockData->fl_start = parm_data->start; + pLockData->fl_end = parm_data->start + + parm_data->length - 1; + pLockData->fl_pid = parm_data->pid; + } } plk_err_exit: diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 6851043..855937e 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -896,8 +896,32 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock) } else { /* if rc == ERR_SHARING_VIOLATION ? */ - rc = 0; /* do not change lock type to unlock - since range in use */ + rc = 0; + + if (lockType & LOCKING_ANDX_SHARED_LOCK) { + pfLock->fl_type = F_WRLCK; + } else { + rc = CIFSSMBLock(xid, pTcon, netfid, length, + pfLock->fl_start, 0, 1, + lockType | LOCKING_ANDX_SHARED_LOCK, + 0 /* wait flag */ ); + if (rc == 0) { + rc = CIFSSMBLock(xid, pTcon, netfid, + length, pfLock->fl_start, 1, 0, + lockType | + LOCKING_ANDX_SHARED_LOCK, + 0 /* wait flag */ ); + pfLock->fl_type = F_RDLCK; + if (rc != 0) + cERROR(1, ("Error unlocking " + "previously locked range %d " + "during test of lock", rc)); + rc = 0; + } else { + pfLock->fl_type = F_WRLCK; + rc = 0; + } + } } FreeXid(xid);