From patchwork Tue Sep 4 16:24:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 1403321 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 801B63FC71 for ; Tue, 4 Sep 2012 16:24:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757135Ab2IDQYS (ORCPT ); Tue, 4 Sep 2012 12:24:18 -0400 Received: from mail-lb0-f174.google.com ([209.85.217.174]:36684 "EHLO mail-lb0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757280Ab2IDQYR (ORCPT ); Tue, 4 Sep 2012 12:24:17 -0400 Received: by lbbgj3 with SMTP id gj3so3227016lbb.19 for ; Tue, 04 Sep 2012 09:24:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=RrHz3rznXui5JtCFTTl5xllWDXZF9bASkL2/6HlDxhI=; b=DM1EsnP5ffRSCaR4hk1pm8ar3aXxzPK/I6Hugzkl/TF7ohmjXNNspqL7zcDHDDXSFs ONDQA3zQ7FAoWPd6zmFhsn+TOjaOQ6e23qbPr0Fg3bcFJzk05ch1VYRRA+7jU7DfDRUE y2kGHVt5sM1Bauwkf0iz3265sAKsKncl5vIbqfFThrZ4gXjS0d6JYx4TN379ofS0a+Tb iLRKNHuVTUqUNRhk3KvwIWGabmnCJOmF3GOYZHgk7D670QhkhpUk1Ip9xUuy/04/qRPm hRwELvlB/GL/iGliYz6zWpW5LFGhWyaqV7QJvx/w4hKP92ehjBK3Pzf2Bwob5eEpr7SS 56jQ== Received: by 10.152.112.37 with SMTP id in5mr1296617lab.44.1346775856333; Tue, 04 Sep 2012 09:24:16 -0700 (PDT) Received: from localhost.localdomain ([95.84.59.238]) by mx.google.com with ESMTPS id c6sm4169662lbn.1.2012.09.04.09.24.15 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 04 Sep 2012 09:24:15 -0700 (PDT) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Cc: Pavel Shilovsky Subject: [PATCH 2/4] CIFS: Fix cache coherency for read oplock case Date: Tue, 4 Sep 2012 20:24:05 +0400 Message-Id: <1346775847-7894-3-git-send-email-pshilovsky@etersoft.ru> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1346775847-7894-1-git-send-email-pshilovsky@etersoft.ru> References: <1346775847-7894-1-git-send-email-pshilovsky@etersoft.ru> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org From: Pavel Shilovsky When we have a file opened with read oplock and we are writing a data to this file, we need to store the data in the cache and then send to the server to ensure that the next read operation will get a coherent data. Also mark it as CONFIG_CIFS_SMB2 because it's more suitable for SMB2 code but can fix some CIFS problems too (when server delays sending an oplock break after a write request). We can drop this ifdefs dependence in future. Signed-off-by: Pavel Shilovsky --- fs/cifs/file.c | 26 ++++++++++++++++++++++---- 1 files changed, 22 insertions(+), 4 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index f15c30c..da7e3d4 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -2421,11 +2421,29 @@ cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov, struct TCP_Server_Info *server = tcon->ses->server; int rc = -EACCES; +#ifdef CONFIG_CIFS_SMB2 /* - * 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 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; + + written = generic_file_aio_write(iocb, iov, nr_segs, pos); + rc = filemap_fdatawrite(inode->i_mapping); + if (rc) + return (ssize_t)rc; + + return written; + } +#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)