Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933343Ab1ESWtQ (ORCPT ); Thu, 19 May 2011 18:49:16 -0400 Received: from e35.co.us.ibm.com ([32.97.110.153]:60568 "EHLO e35.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932829Ab1ESWtK (ORCPT ); Thu, 19 May 2011 18:49:10 -0400 Subject: [PATCH 3/3] mm: Provide stub page_mkwrite functionality to stabilize pages during writes To: Alexander Viro , "Darrick J. Wong" From: "Darrick J. Wong" Cc: Jens Axboe , Theodore Tso , "Martin K. Petersen" , Jeff Layton , Dave Chinner , linux-kernel , Dave Hansen , Christoph Hellwig , linux-mm@kvack.org, Chris Mason , Joel Becker , linux-scsi , linux-fsdevel , Jan Kara , linux-ext4@vger.kernel.org, Mingming Cao Date: Thu, 19 May 2011 15:49:03 -0700 Message-ID: <20110519224903.28755.2703.stgit@elm3c44.beaverton.ibm.com> In-Reply-To: <20110519224841.28755.80650.stgit@elm3c44.beaverton.ibm.com> References: <20110519224841.28755.80650.stgit@elm3c44.beaverton.ibm.com> User-Agent: StGit/0.15 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1540 Lines: 49 For filesystems that do not provide any page_mkwrite handler, provide a stub page_mkwrite function that locks the page and waits for pending writeback to complete. This is needed to stabilize pages during writes for a large variety of filesystem drivers (ext2, ext3, vfat, hfs...). Signed-off-by: Darrick J. Wong --- mm/filemap.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index fd0e7f2..2a922b4 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1713,8 +1713,27 @@ page_not_uptodate: } EXPORT_SYMBOL(filemap_fault); +static int stub_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) +{ + struct page *page = vmf->page; + struct inode *inode = vma->vm_file->f_path.dentry->d_inode; + loff_t size; + + lock_page(page); + size = i_size_read(inode); + if ((page->mapping != inode->i_mapping) || + (page_offset(page) > size)) { + /* page got truncated out from underneath us */ + unlock_page(page); + return VM_FAULT_NOPAGE; + } + wait_on_page_writeback(page); + return VM_FAULT_LOCKED; +} + const struct vm_operations_struct generic_file_vm_ops = { .fault = filemap_fault, + .page_mkwrite = stub_page_mkwrite, }; /* This is used for a general mmap of a disk file */ -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/