From patchwork Fri Feb 14 09:31:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 3651531 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8CD22BF13A for ; Fri, 14 Feb 2014 09:31:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DB7822021B for ; Fri, 14 Feb 2014 09:31:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D95F32021C for ; Fri, 14 Feb 2014 09:31:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751337AbaBNJbQ (ORCPT ); Fri, 14 Feb 2014 04:31:16 -0500 Received: from mail-lb0-f171.google.com ([209.85.217.171]:58325 "EHLO mail-lb0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751374AbaBNJbO (ORCPT ); Fri, 14 Feb 2014 04:31:14 -0500 Received: by mail-lb0-f171.google.com with SMTP id c11so9332407lbj.30 for ; Fri, 14 Feb 2014 01:31:13 -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:in-reply-to:references; bh=7MKSq84LVQLvdna9xNSf1nAoL3+bD/X6xB6c1J7dTS4=; b=FggkUxADwOc7Jo4Hj/zfijBJNOurQmo6JlE+z4eJJQwu0fNTm0A2fkThMgoMllHEua 4KD8ftjmM2p5rvWEpxnLt1zl8Ea2BzacyVM3RuGjBOQ8OIHEenfsYNmaQz8k2iM/G6OH Nr8krfCC/6SdS7wRgGJr+zKSD2xQ3qvc/3HUK/VLWEFGUBwO6QFEXisEQyrgPjtr7P66 hc3tPUpOjTZ7UJe1vcIp+GLYlIk/hp0hpF8GAahS0ZbyEbbvTqIUP35Zukw9wAQscPB0 LsV9YBkYC7N0FUF6Lz9w7ZUEEKFGSp1fwSHtsxpfjcGA6RJLAO1OGeBptBmVjk2nGK+M g72g== X-Received: by 10.152.36.8 with SMTP id m8mr4656120laj.24.1392370273370; Fri, 14 Feb 2014 01:31:13 -0800 (PST) Received: from localhost.localdomain ([92.43.3.99]) by mx.google.com with ESMTPSA id cl5sm5212841lbb.14.2014.02.14.01.31.11 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 14 Feb 2014 01:31:12 -0800 (PST) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH] CIFS: Fix wrong pos argument of cifs_find_lock_conflict Date: Fri, 14 Feb 2014 13:31:03 +0400 Message-Id: <1392370263-10364-2-git-send-email-piastry@etersoft.ru> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1392370263-10364-1-git-send-email-piastry@etersoft.ru> References: <1392370263-10364-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 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP and use generic_file_aio_write rather than __generic_file_aio_write in cifs_writev. Signed-off-by: Pavel Shilovsky Reported-by: Al Viro --- fs/cifs/file.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index a7eda8e..d34dc3b 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -2539,31 +2539,19 @@ cifs_writev(struct kiocb *iocb, const struct iovec *iov, struct cifsInodeInfo *cinode = CIFS_I(inode); struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; ssize_t rc = -EACCES; + loff_t lock_pos = pos; - BUG_ON(iocb->ki_pos != pos); - + if (file->f_flags & O_APPEND) + lock_pos = i_size_read(inode); /* * We need to hold the sem to be sure nobody modifies lock list * with a brlock that prevents writing. */ down_read(&cinode->lock_sem); - if (!cifs_find_lock_conflict(cfile, pos, iov_length(iov, nr_segs), + if (!cifs_find_lock_conflict(cfile, lock_pos, iov_length(iov, nr_segs), server->vals->exclusive_lock_type, NULL, - CIFS_WRITE_OP)) { - mutex_lock(&inode->i_mutex); - rc = __generic_file_aio_write(iocb, iov, nr_segs, - &iocb->ki_pos); - mutex_unlock(&inode->i_mutex); - } - - if (rc > 0) { - ssize_t err; - - err = generic_write_sync(file, iocb->ki_pos - rc, rc); - if (err < 0) - rc = err; - } - + CIFS_WRITE_OP)) + rc = generic_file_aio_write(iocb, iov, nr_segs, pos); up_read(&cinode->lock_sem); return rc; }