From patchwork Wed Dec 26 15:53:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 1911191 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 219173FC66 for ; Wed, 26 Dec 2012 15:53:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753050Ab2LZPxM (ORCPT ); Wed, 26 Dec 2012 10:53:12 -0500 Received: from mail-la0-f44.google.com ([209.85.215.44]:34422 "EHLO mail-la0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751538Ab2LZPxM (ORCPT ); Wed, 26 Dec 2012 10:53:12 -0500 Received: by mail-la0-f44.google.com with SMTP id d3so10973850lah.31 for ; Wed, 26 Dec 2012 07:53:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:subject:date:message-id:x-mailer :in-reply-to:references; bh=5Y7lnc+EiF9/2fUqVGlfb7Fb8DiqqPWbvg8FheJqjE4=; b=tVgrsYrL1osI30nXFaI1R6N3YI6r7e7mj6IHs/7vtktENsRf0zhGucep2ejpWW7TtW 2PTslz4K2UL71liZcjrCSWCD9qBfUVY4LKM9j1rNWbqNrL5BtOESREwhzA0lh85swLUw NqSljZaG16xKZKEVRwsR3tJtD0hnTJMkxVsjxejyHGMf7PZm86G8drveCA/kh/6zs2CE 8B69e7M0ppRdsL37y7fsRvHb82c0/rrvf5dxA3jSOqK8r2Ua0fkjCPBwo2YgmWow8dmo ijqxUGQ/Ee4fXeP4yHrR9qnzEz41TSqeRR5qi15WPN14wHrJAtv8u0QY7qyegR7EL94m hKPw== X-Received: by 10.152.162.1 with SMTP id xw1mr26087100lab.3.1356537190994; Wed, 26 Dec 2012 07:53:10 -0800 (PST) Received: from workstation.localdomain (PPPoE-78-29-79-97.san.ru. [78.29.79.97]) by mx.google.com with ESMTPS id ee5sm9627016lbb.14.2012.12.26.07.53.09 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 26 Dec 2012 07:53:10 -0800 (PST) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 2/3] CIFS: Fix write after setting a read lock for read oplock files Date: Wed, 26 Dec 2012 19:53:53 +0400 Message-Id: <1356537234-11507-3-git-send-email-piastry@etersoft.ru> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1356537234-11507-1-git-send-email-piastry@etersoft.ru> References: <1356537234-11507-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 have a read oplock and set a read lock in it, we can't write to the locked area - so, filemap_fdatawrite may fail with a no information for a userspace application even if we request a write to non-locked area. Fix this by writing directly to the server and then breaking oplock level from level2 to None. Also remove CONFIG_CIFS_SMB2 ifdefs because it's suitable for both CIFS and SMB2 protocols. Signed-off-by: Pavel Shilovsky Reviewed-by: Jeff Layton --- fs/cifs/file.c | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 1b322d0..22c3725 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -2505,42 +2505,34 @@ cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov, struct cifsFileInfo *cfile = (struct cifsFileInfo *) iocb->ki_filp->private_data; struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); + ssize_t written; -#ifdef CONFIG_CIFS_SMB2 - /* - * If we have an oplock for read and want to write a data to the file - * we need to store it in the page cache and then push it to the server - * to be sure the next read will get a valid data. - */ - if (!cinode->clientCanCacheAll && cinode->clientCanCacheRead) { - ssize_t written; - int rc; - - written = generic_file_aio_write(iocb, iov, nr_segs, pos); - rc = filemap_fdatawrite(inode->i_mapping); - if (rc) - return (ssize_t)rc; - - return written; + if (cinode->clientCanCacheAll) { + if (cap_unix(tcon->ses) && + (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) + && ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) + return generic_file_aio_write(iocb, iov, nr_segs, pos); + return cifs_writev(iocb, iov, nr_segs, pos); } -#endif - /* * For non-oplocked files in strict cache mode we need to write the data * to the server exactly from the pos to pos+len-1 rather than flush all * affected pages because it may cause a error with mandatory locks on * these pages but not on the region from pos to ppos+len-1. */ - - if (!cinode->clientCanCacheAll) - return cifs_user_writev(iocb, iov, nr_segs, pos); - - if (cap_unix(tcon->ses) && - (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) && - ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) - return generic_file_aio_write(iocb, iov, nr_segs, pos); - - return cifs_writev(iocb, iov, nr_segs, pos); + written = cifs_user_writev(iocb, iov, nr_segs, pos); + if (written > 0 && cinode->clientCanCacheRead) { + /* + * Windows 7 server can delay breaking level2 oplock if a write + * request comes - break it on the client to prevent reading + * an old data. + */ + cifs_invalidate_mapping(inode); + cFYI(1, "Set no oplock for inode=%p after a write operation", + inode); + cinode->clientCanCacheRead = false; + } + return written; } static struct cifs_readdata *