From patchwork Sun Nov 28 08:12:49 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 361872 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oAS8BWvm023110 for ; Sun, 28 Nov 2010 08:14:56 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751764Ab0K1IO4 (ORCPT ); Sun, 28 Nov 2010 03:14:56 -0500 Received: from mail-ew0-f46.google.com ([209.85.215.46]:65049 "EHLO mail-ew0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751708Ab0K1IOz (ORCPT ); Sun, 28 Nov 2010 03:14:55 -0500 Received: by mail-ew0-f46.google.com with SMTP id 5so1493865ewy.19 for ; Sun, 28 Nov 2010 00:14:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:subject:date :message-id:x-mailer:in-reply-to:references; bh=RVecaqoqa0Ol6zib9XLORez8y5Ch0ve3Koxfv42LB6M=; b=F0wZQrpQ0qN5XHHFaE7647ZOz1BO7ZJqca9qO43sL1x+RN9oFPdFLbS2PTuvVAT8RV qrhVm2NMuHOJt1Qh5c5lDIFbaY/8vkDCmfcVUivxosphSXZcWqi67WXFy6EyG4eBiW1F fjtoltleHPCT+RqHB3TCgziVvEeTbflKxFBsw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:x-mailer:in-reply-to:references; b=vjGy4h75zvJoiFIKcrl4zZ35ssDt3o0uHuUeyWXn4xtbBCk4M+zca4j4kBLpqdJpIZ 2OiH/QemeFdHqSOH+yB/WCg4dycL8f+mHrA/ohNiPyYNPu+j9HWGwXLqx4EtE7BdEhpX 0orbdkTwp3ElCHwvvgZoLvPb4UdeOQRTv4tz0= Received: by 10.14.22.67 with SMTP id s43mr3095094ees.18.1290932095092; Sun, 28 Nov 2010 00:14:55 -0800 (PST) Received: from localhost.localdomain ([95.84.39.194]) by mx.google.com with ESMTPS id b52sm3724422eei.19.2010.11.28.00.14.54 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 28 Nov 2010 00:14:54 -0800 (PST) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 3/6] CIFS: Make write call work with strict cache mode (try #2) Date: Sun, 28 Nov 2010 11:12:49 +0300 Message-Id: <1290931972-2770-4-git-send-email-piastryyy@gmail.com> X-Mailer: git-send-email 1.7.3.2 In-Reply-To: <1290931972-2770-1-git-send-email-piastryyy@gmail.com> References: <1290931972-2770-1-git-send-email-piastryyy@gmail.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Sun, 28 Nov 2010 08:14:56 +0000 (UTC) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index bbb5294..901c82b 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -598,12 +598,44 @@ static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov, unsigned long nr_segs, loff_t pos) { - struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode; + struct inode *inode; + struct cifs_sb_info *cifs_sb; ssize_t written; - written = generic_file_aio_write(iocb, iov, nr_segs, pos); - if (!CIFS_I(inode)->clientCanCacheAll) - filemap_fdatawrite(inode->i_mapping); + inode = iocb->ki_filp->f_path.dentry->d_inode; + + if (CIFS_I(inode)->clientCanCacheAll) + return generic_file_aio_write(iocb, iov, nr_segs, pos); + + cifs_sb = CIFS_SB(iocb->ki_filp->f_path.dentry->d_sb); + + if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) == 0) { + int rc; + + written = generic_file_aio_write(iocb, iov, nr_segs, pos); + + rc = filemap_fdatawrite(inode->i_mapping); + if (rc) + cFYI(1, "cifs_file_aio_write: %d rc on %p inode", + rc, inode); + return written; + } + + /* 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 */ + written = cifs_user_write(iocb->ki_filp, iov->iov_base, + iov->iov_len, &pos); + + iocb->ki_pos = pos; + + /* if we were successful - invalidate inode pages the write affected */ + if (written > 0) + invalidate_mapping_pages(inode->i_mapping, + (pos-written) >> PAGE_CACHE_SHIFT, + (pos-1) >> PAGE_CACHE_SHIFT); + return written; }