From patchwork Tue Nov 27 06:50:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 1808981 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 B9BDBDF254 for ; Tue, 27 Nov 2012 06:50:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758015Ab2K0Guw (ORCPT ); Tue, 27 Nov 2012 01:50:52 -0500 Received: from mail-la0-f46.google.com ([209.85.215.46]:54770 "EHLO mail-la0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757842Ab2K0Guw (ORCPT ); Tue, 27 Nov 2012 01:50:52 -0500 Received: by mail-la0-f46.google.com with SMTP id p5so6483184lag.19 for ; Mon, 26 Nov 2012 22:50:51 -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=LXfH3uwSImhNg4dqewhDFAdayrU+4hu6YiCWogPoSlg=; b=l1oaAXwHLl6sZ07B/Adt0YydDRt5yoPv3LAV6pZKWRI57/7qtU49QTO2TCilOfhP5p B4xrIyFfm0UaqYzWDp6G6AW5xmL8WCNmlj+sq9dCFPbbve3vD29hRqtlKm7lewY7HIyW VVAmbqbyGR54tO96/HuyEDJ7STjJkbBxWqewKl4LnUQCj2WURF7JeD1KnwK0Hq/aBB63 stxXQXRv0bHI48In/BMQan240Bi45B1doydfBmC9xhr8GtKinDMzOI4s6D72VjVy2jwg sUrINfLS4joOYRP2E1mOWxl4Eko6uwv8OqKYDcFIpBTLI2ackTeM0zUzkUhWWtlyHCq2 r5Bg== Received: by 10.152.162.1 with SMTP id xw1mr13706554lab.3.1353999051174; Mon, 26 Nov 2012 22:50:51 -0800 (PST) Received: from localhost.localdomain ([95.84.0.69]) by mx.google.com with ESMTPS id bf3sm6547215lbb.16.2012.11.26.22.50.49 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 26 Nov 2012 22:50:50 -0800 (PST) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 5/5] CIFS: Fix write after setting a read lock for read oplock files Date: Tue, 27 Nov 2012 10:50:28 +0400 Message-Id: <1353999029-3975-6-git-send-email-piastry@etersoft.ru> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1353999029-3975-1-git-send-email-piastry@etersoft.ru> References: <1353999029-3975-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 replacing it with filemap_write_and_wait call and sending non-page write in a error case. While this may end up with two write requests to the server, we can be sure that our data will be the same at the server and the page cache - the next read on this file gets the valid data. Signed-off-by: Pavel Shilovsky Acked-by: Jeff Layton --- fs/cifs/file.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index f8fe1bd..89efd85 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -2511,14 +2511,12 @@ cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov, */ 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; + /* try page write at first */ + if (!filemap_write_and_wait(inode->i_mapping)) + return written; + /* page write failed - try from pos to pos+len-1 */ } #endif