From patchwork Wed Nov 28 14:23:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 1816721 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 DFC563FC54 for ; Wed, 28 Nov 2012 14:24:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754738Ab2K1OY0 (ORCPT ); Wed, 28 Nov 2012 09:24:26 -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 S1755277Ab2K1OYK (ORCPT ); Wed, 28 Nov 2012 09:24:10 -0500 Received: by mail-lb0-f174.google.com with SMTP id gi11so7620337lbb.19 for ; Wed, 28 Nov 2012 06:24:10 -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=JJzmyuETxhVtgcVbU+7LgH8c6+oMqKPtOuuaEp+ZFsw=; b=0TbpXzlqQ7OUvgwlZ1HbH5nGPgqeq1dubXieSssJX1slColifdcrwp1uPQXpK7h623 pmXysBiHxd4MIBFBufaWq8t25UVx7WCfdgm9q1Y7N2xkKQzsroohTtlH131qf073MHQt S41QLa8wZLYvXbjJ91qY9WHrcrNeK0M3B1jLaPvArm0pGi2wwbFNboebwkG8w8wQV0Ni W3hF+mMt/Z0k2GxPfc+luFvuisCxNU9XaNUqM6oqSkk1tVVzOLKYWSaUvt7ID1T7JsQ9 US6okCY/odjpqJGWsvsQ0tnTF9c3nzv7feLx2Rho1BAmUQgCHJlb7DhgOoOpgwfD60Qh EECg== Received: by 10.112.29.10 with SMTP id f10mr8106430lbh.4.1354112649930; Wed, 28 Nov 2012 06:24:09 -0800 (PST) Received: from localhost.localdomain ([95.84.0.69]) by mx.google.com with ESMTPS id oj5sm8159019lab.8.2012.11.28.06.24.05 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 28 Nov 2012 06:24:08 -0800 (PST) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH v2 6/6] CIFS: Fix write after setting a read lock for read oplock files Date: Wed, 28 Nov 2012 18:23:45 +0400 Message-Id: <1354112625-30315-7-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 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 checking for brlocks, populating the page cache without marking affected pages dirty and directly writing to the server. Also remove CONFIG_CIFS_SMB2 ifdefs because it's suitable for both CIFS and SMB2 protocols. Signed-off-by: Pavel Shilovsky Acked-by: Jeff Layton --- fs/cifs/file.c | 63 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index e7fc39c..5cfed9c 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -2109,7 +2109,14 @@ static int cifs_write_end(struct file *file, struct address_space *mapping, } else { rc = copied; pos += copied; - set_page_dirty(page); + /* + * If we don't have write oplock and use the strict cache mode, + * we can leave pages clean - cifs_strict_writev will send a + * data to the server itself. + */ + if (CIFS_I(inode)->clientCanCacheAll || + !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO)) + set_page_dirty(page); } if (rc > 0) { @@ -2460,8 +2467,8 @@ ssize_t cifs_user_writev(struct kiocb *iocb, const struct iovec *iov, } static ssize_t -cifs_writev(struct kiocb *iocb, const struct iovec *iov, - unsigned long nr_segs, loff_t pos) +cifs_pagecache_writev(struct kiocb *iocb, const struct iovec *iov, + unsigned long nr_segs, loff_t pos) { struct file *file = iocb->ki_filp; struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data; @@ -2511,25 +2518,26 @@ 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; + /* we have a read oplock - need to store a data in the page cache */ + if (cinode->clientCanCacheRead) { + if (cap_unix(tcon->ses) && + ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0) && + (CIFS_UNIX_FCNTL_CAP & le64_to_cpu( + tcon->fsUnixInfo.Capability))) + written = generic_file_aio_write(iocb, iov, nr_segs, + pos); + else + written = cifs_pagecache_writev(iocb, iov, nr_segs, + pos); + /* + * Errors occured during writing or we have read+write oplock - + * no need to flush to the server. + */ + if (written < 0 || cinode->clientCanCacheAll) + return written; } -#endif /* * For non-oplocked files in strict cache mode we need to write the data @@ -2537,16 +2545,11 @@ cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov, * 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); + /* need to restore pos if errors occured */ + if (written < 0) + iocb->ki_pos = pos; + return written; } static struct cifs_readdata *