From patchwork Wed Nov 10 15:50:51 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 314572 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 oAAFpNLR032006 for ; Wed, 10 Nov 2010 15:51:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756751Ab0KJPvL (ORCPT ); Wed, 10 Nov 2010 10:51:11 -0500 Received: from mail-ew0-f46.google.com ([209.85.215.46]:63526 "EHLO mail-ew0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756744Ab0KJPvK (ORCPT ); Wed, 10 Nov 2010 10:51:10 -0500 Received: by ewy7 with SMTP id 7so377414ewy.19 for ; Wed, 10 Nov 2010 07:51:09 -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=nKqktd2MWTCGHReDyypA2cQPXzHaZeSvhY1ndzSC7Bc=; b=OLTCUinf0bvIJgdmFEvSeXb/hf29wX2Le80YMWB2iQZiGl2lVimMPU9GWj0A3lxwoU Oc+z2svz8lwPTpv9zjyBf31sPdQbRJaca4bwzncZt2SBen8BZ4V0T2nEmuCLBA6F1fJG yYf0/K6vkdOP5JD6rrQqx21vCvg5tNEgzHwew= 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=smfVXTgKCVG01nRqUL2wpXMwrJ20G768qkFkpKjtXd2aZcOUpYMbHl0X3X/ymojstf yZxsKUqx/mkTfA8ZDfb1pdbYzta0QmXC9jdxQpEIhfN0xjO4WFa0AdK2PY0CDT2jfiAX T70TV45h5xErqdMh3EjEevm64Pc3aWREJTLwc= Received: by 10.213.36.14 with SMTP id r14mr4356105ebd.75.1289404269316; Wed, 10 Nov 2010 07:51:09 -0800 (PST) Received: from localhost.localdomain ([79.126.90.150]) by mx.google.com with ESMTPS id q58sm821223eeh.3.2010.11.10.07.51.08 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 10 Nov 2010 07:51:08 -0800 (PST) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 3/6] CIFS: Make write call work with strict cache mode Date: Wed, 10 Nov 2010 18:50:51 +0300 Message-Id: <1289404251-13066-1-git-send-email-piastryyy@gmail.com> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1289403711-12965-4-git-send-email-piastryyy@gmail.com> References: <1289403711-12965-4-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]); Wed, 10 Nov 2010 15:51:25 +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; } diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 88bb366..9a30557 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -1545,7 +1545,7 @@ static int cifs_write_end(struct file *file, struct address_space *mapping, struct page *page, void *fsdata) { int rc; - struct inode *inode = mapping->host; + struct inode *inode = mapping->host cFYI(1, "write_end for page %p from pos %lld with %d bytes", page, pos, copied);