From patchwork Wed Nov 28 14:23:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 1816701 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id CF6D5DF26F for ; Wed, 28 Nov 2012 14:24:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754935Ab2K1OYF (ORCPT ); Wed, 28 Nov 2012 09:24:05 -0500 Received: from mail-lb0-f174.google.com ([209.85.217.174]:38988 "EHLO mail-lb0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754738Ab2K1OYE (ORCPT ); Wed, 28 Nov 2012 09:24:04 -0500 Received: by mail-lb0-f174.google.com with SMTP id gi11so7620337lbb.19 for ; Wed, 28 Nov 2012 06:24:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=uB16LyhgNfYZJwznsbIBI+uAWmtfLI+bSOMQ4sxpxCE=; b=CRUJeJX0hhx/okzOtRQIzb1pjCHW+Cb+7x8SYWIZe264v986zQnacXb9QI2Nn3iQ3s HfncIrZR8Q/FfAXxGVGJXl4bGCC7OGyeIghFui/bcMxFwsmg3kbUQ08drBEtgvE8Zusc xiA+iIDDQBpSIFp8+Kz2SRFVehbFyk1pEqpRJeUgfkU2viDveRFplPSfeb2b7OvmZrnL 4P+2vdOBr1T88ahVWGOYvwWFCjw0in0OLGH3ub8FnPix5xWCXczz3gjjh5G/4fZheL8T oNcIUIiFCHmz5dfNPRmXtv4w1rhlARe4Z3ZaA/4O7dbRQvkvChG/Q+Bu+Z2Gexf4XQq8 w4fA== Received: by 10.152.144.10 with SMTP id si10mr18173673lab.55.1354112643967; Wed, 28 Nov 2012 06:24:03 -0800 (PST) Received: from localhost.localdomain ([95.84.0.69]) by mx.google.com with ESMTPS id oj5sm8159019lab.8.2012.11.28.06.24.02 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 28 Nov 2012 06:24:03 -0800 (PST) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH v2 4/6] CIFS: Fix lock consistensy bug in cifs_setlk Date: Wed, 28 Nov 2012 18:23:43 +0400 Message-Id: <1354112625-30315-5-git-send-email-piastry@etersoft.ru> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1354112625-30315-1-git-send-email-piastry@etersoft.ru> References: <1354112625-30315-1-git-send-email-piastry@etersoft.ru> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org If we netogiate mandatory locking style, have a read lock and try to set a write lock we end up with a write lock in vfs cache and no lock in cifs lock cache - that's wrong. Fix it by returning from cifs_setlk immediately if a error occurs during setting a lock. Reviewed-by: Jeff Layton Signed-off-by: Pavel Shilovsky --- fs/cifs/file.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index a18c9eb..f8fe1bd 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -1449,16 +1449,18 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, return -ENOMEM; rc = cifs_lock_add_if(cfile, lock, wait_flag); - if (rc < 0) + if (rc < 0) { kfree(lock); - if (rc <= 0) + return rc; + } + if (!rc) goto out; rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, type, 1, 0, wait_flag); if (rc) { kfree(lock); - goto out; + return rc; } cifs_lock_add(cfile, lock);