From patchwork Wed Nov 10 15:55:54 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 314632 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 oAAFuFh9032705 for ; Wed, 10 Nov 2010 15:56:16 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756519Ab0KJP4P (ORCPT ); Wed, 10 Nov 2010 10:56:15 -0500 Received: from mail-ey0-f174.google.com ([209.85.215.174]:37418 "EHLO mail-ey0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756459Ab0KJP4O (ORCPT ); Wed, 10 Nov 2010 10:56:14 -0500 Received: by eye27 with SMTP id 27so393441eye.19 for ; Wed, 10 Nov 2010 07:56:13 -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; bh=U973lqDEKjiERmZz7D8q73KstFgPi5IJoKjaLoWkChw=; b=vp0BYcHLGWXHR+G6/fD7crZcPHAg/tjFNlH3vG75BNM1JWskIUekv78l/OFNemBhvS UQ4HDjxfFYit6XUAdi6tiNGjofEAK2DLxJpeHGrNDah31OuDCMny6AVrKp2WUmBujOcB WhubosOM8f1mtPcHCZ1+eJ2AekKeuP8laQA2k= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:x-mailer; b=Hrcfsvblex4PCr54oszAAcwcWXjuI7V0IUWUBqhP9qiOT6fQy2EgWcEsqcvYZ524W/ R2jN8XqdOMRnHbG7kyWh0pSBZkUs5LtcTxqewxun38LgddfchOWijlU/Qe2/Exsj/WJP npigImBboH0W5y7AgkyL4YH4BDe1F1A//G18E= Received: by 10.213.4.203 with SMTP id 11mr676825ebs.9.1289404572338; Wed, 10 Nov 2010 07:56:12 -0800 (PST) Received: from localhost.localdomain ([79.126.90.150]) by mx.google.com with ESMTPS id x54sm817721eeh.23.2010.11.10.07.56.11 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 10 Nov 2010 07:56:11 -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:55:54 +0300 Message-Id: <1289404554-13748-1-git-send-email-piastryyy@gmail.com> X-Mailer: git-send-email 1.7.2.3 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:56:16 +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; }