From patchwork Wed Nov 10 15:41:48 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 314532 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 oAAFgYqY031219 for ; Wed, 10 Nov 2010 15:42:38 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756725Ab0KJPmi (ORCPT ); Wed, 10 Nov 2010 10:42:38 -0500 Received: from mail-ey0-f174.google.com ([209.85.215.174]:59893 "EHLO mail-ey0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756595Ab0KJPmh (ORCPT ); Wed, 10 Nov 2010 10:42:37 -0500 Received: by eye27 with SMTP id 27so381132eye.19 for ; Wed, 10 Nov 2010 07:42:36 -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=M2383k3XXIxJfo5SmgfzrtQnxsdwUJAwrJLNIh9P10E=; b=eJyaL6hk4X20BCr3Y16X9FVdj0vyPXdwEQQWOertaHIqYA8MSfmh9HrTuSKp6VUofL jIQtRkqYmhKdS7Ei6RBY1BZ+vgLDxybw1b9wdK1Y2yUTjugzPdlwUrRxwaXZNcrYprwj OHoLGI1gAqT3KBT6SrIlao+cCa0tNtbre7ruc= 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=nueoZyM+exr4WwHU8jVArLWeDovWAsSvfvEUQL3CHR78dQBF8qoA8tkvS/+TZY1rgg WjwcDl8D3maMsteNOoQ/jwrQoFRa0uw0B86Lfwr0y36pSk3BFgukg2G9SHFGsR5IKBOQ C6d4V1C2IekNCMftBDGOIErge9+PjgkgOkmDQ= Received: by 10.213.113.211 with SMTP id b19mr620709ebq.94.1289403755216; Wed, 10 Nov 2010 07:42:35 -0800 (PST) Received: from localhost.localdomain ([79.126.90.150]) by mx.google.com with ESMTPS id w20sm815303eeh.0.2010.11.10.07.42.33 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 10 Nov 2010 07:42:33 -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:41:48 +0300 Message-Id: <1289403711-12965-4-git-send-email-piastryyy@gmail.com> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1289403711-12965-1-git-send-email-piastryyy@gmail.com> References: <1289403711-12965-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]); Wed, 10 Nov 2010 15:42:38 +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..568e93f 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -1545,7 +1545,11 @@ 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; + struct cifs_sb_info *cifs_sb; + + inode = mapping->host; + cifs_sb = CIFS_SB(inode->i_sb); cFYI(1, "write_end for page %p from pos %lld with %d bytes", page, pos, copied); @@ -1578,7 +1582,13 @@ static int cifs_write_end(struct file *file, struct address_space *mapping, } else { rc = copied; pos += copied; - set_page_dirty(page); + /* if we have strict cache switched on and don't have Exclusive + oplock for the inode, we don't have to set_page_dirty + because we flushed the data to the server in + cifs_file_aio_write before */ + if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) == 0 || + CIFS_I(inode)->clientCanCacheAll) + set_page_dirty(page); } if (rc > 0) {