2006-01-19 09:43:02 +08:00
|
|
|
/*
|
|
|
|
* linux/fs/9p/vfs_addr.c
|
|
|
|
*
|
|
|
|
* This file contians vfs address (mmap) ops for 9P2000.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 by Eric Van Hensbergen <ericvh@gmail.com>
|
|
|
|
* Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2006-03-25 19:07:28 +08:00
|
|
|
* it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
2006-01-19 09:43:02 +08:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to:
|
|
|
|
* Free Software Foundation
|
|
|
|
* 51 Franklin Street, Fifth Floor
|
|
|
|
* Boston, MA 02111-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/file.h>
|
|
|
|
#include <linux/stat.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/inet.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/idr.h>
|
Detach sched.h from mm.h
First thing mm.h does is including sched.h solely for can_do_mlock() inline
function which has "current" dereference inside. By dealing with can_do_mlock()
mm.h can be detached from sched.h which is good. See below, why.
This patch
a) removes unconditional inclusion of sched.h from mm.h
b) makes can_do_mlock() normal function in mm/mlock.c
c) exports can_do_mlock() to not break compilation
d) adds sched.h inclusions back to files that were getting it indirectly.
e) adds less bloated headers to some files (asm/signal.h, jiffies.h) that were
getting them indirectly
Net result is:
a) mm.h users would get less code to open, read, preprocess, parse, ... if
they don't need sched.h
b) sched.h stops being dependency for significant number of files:
on x86_64 allmodconfig touching sched.h results in recompile of 4083 files,
after patch it's only 3744 (-8.3%).
Cross-compile tested on
all arm defconfigs, all mips defconfigs, all powerpc defconfigs,
alpha alpha-up
arm
i386 i386-up i386-defconfig i386-allnoconfig
ia64 ia64-up
m68k
mips
parisc parisc-up
powerpc powerpc-up
s390 s390-up
sparc sparc-up
sparc64 sparc64-up
um-x86_64
x86_64 x86_64-up x86_64-defconfig x86_64-allnoconfig
as well as my two usual configs.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-21 05:22:52 +08:00
|
|
|
#include <linux/sched.h>
|
2015-02-23 00:58:50 +08:00
|
|
|
#include <linux/uio.h>
|
2007-07-11 06:57:28 +08:00
|
|
|
#include <net/9p/9p.h>
|
|
|
|
#include <net/9p/client.h>
|
2006-01-19 09:43:02 +08:00
|
|
|
|
|
|
|
#include "v9fs.h"
|
|
|
|
#include "v9fs_vfs.h"
|
2009-09-24 02:00:27 +08:00
|
|
|
#include "cache.h"
|
2011-02-28 19:33:58 +08:00
|
|
|
#include "fid.h"
|
2006-01-19 09:43:02 +08:00
|
|
|
|
|
|
|
/**
|
2011-02-28 19:33:58 +08:00
|
|
|
* v9fs_fid_readpage - read an entire page in from 9P
|
2006-01-19 09:43:02 +08:00
|
|
|
*
|
2011-02-28 19:33:58 +08:00
|
|
|
* @fid: fid being read
|
2006-01-19 09:43:02 +08:00
|
|
|
* @page: structure to page
|
|
|
|
*
|
|
|
|
*/
|
2011-02-28 19:33:58 +08:00
|
|
|
static int v9fs_fid_readpage(struct p9_fid *fid, struct page *page)
|
2006-01-19 09:43:02 +08:00
|
|
|
{
|
2015-04-02 11:42:28 +08:00
|
|
|
struct inode *inode = page->mapping->host;
|
|
|
|
struct bio_vec bvec = {.bv_page = page, .bv_len = PAGE_SIZE};
|
|
|
|
struct iov_iter to;
|
|
|
|
int retval, err;
|
2007-02-12 03:21:39 +08:00
|
|
|
|
2011-11-29 02:40:46 +08:00
|
|
|
p9_debug(P9_DEBUG_VFS, "\n");
|
2009-09-24 02:00:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!PageLocked(page));
|
|
|
|
|
|
|
|
retval = v9fs_readpage_from_fscache(inode, page);
|
|
|
|
if (retval == 0)
|
|
|
|
return retval;
|
|
|
|
|
2015-04-02 11:42:28 +08:00
|
|
|
iov_iter_bvec(&to, ITER_BVEC | READ, &bvec, 1, PAGE_SIZE);
|
2006-01-19 09:43:02 +08:00
|
|
|
|
2015-04-02 11:42:28 +08:00
|
|
|
retval = p9_client_read(fid, page_offset(page), &to, &err);
|
|
|
|
if (err) {
|
2009-09-24 02:00:27 +08:00
|
|
|
v9fs_uncache_page(inode, page);
|
2015-04-02 11:42:28 +08:00
|
|
|
retval = err;
|
2007-07-11 06:57:28 +08:00
|
|
|
goto done;
|
2009-09-24 02:00:27 +08:00
|
|
|
}
|
2006-01-19 09:43:02 +08:00
|
|
|
|
2015-04-02 11:42:28 +08:00
|
|
|
zero_user(page, retval, PAGE_SIZE - retval);
|
2006-01-19 09:43:02 +08:00
|
|
|
flush_dcache_page(page);
|
|
|
|
SetPageUptodate(page);
|
2009-09-24 02:00:27 +08:00
|
|
|
|
|
|
|
v9fs_readpage_to_fscache(inode, page);
|
2006-01-19 09:43:02 +08:00
|
|
|
retval = 0;
|
|
|
|
|
2007-07-11 06:57:28 +08:00
|
|
|
done:
|
2006-01-19 09:43:02 +08:00
|
|
|
unlock_page(page);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2011-02-28 19:33:58 +08:00
|
|
|
/**
|
|
|
|
* v9fs_vfs_readpage - read an entire page in from 9P
|
|
|
|
*
|
|
|
|
* @filp: file being read
|
|
|
|
* @page: structure to page
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int v9fs_vfs_readpage(struct file *filp, struct page *page)
|
|
|
|
{
|
|
|
|
return v9fs_fid_readpage(filp->private_data, page);
|
|
|
|
}
|
|
|
|
|
2009-09-24 02:00:27 +08:00
|
|
|
/**
|
|
|
|
* v9fs_vfs_readpages - read a set of pages from 9P
|
|
|
|
*
|
|
|
|
* @filp: file being read
|
|
|
|
* @mapping: the address space
|
|
|
|
* @pages: list of pages to read
|
|
|
|
* @nr_pages: count of pages to read
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int v9fs_vfs_readpages(struct file *filp, struct address_space *mapping,
|
|
|
|
struct list_head *pages, unsigned nr_pages)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct inode *inode;
|
|
|
|
|
|
|
|
inode = mapping->host;
|
2011-11-29 02:40:46 +08:00
|
|
|
p9_debug(P9_DEBUG_VFS, "inode: %p file: %p\n", inode, filp);
|
2009-09-24 02:00:27 +08:00
|
|
|
|
|
|
|
ret = v9fs_readpages_from_fscache(inode, mapping, pages, &nr_pages);
|
|
|
|
if (ret == 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = read_cache_pages(mapping, pages, (void *)v9fs_vfs_readpage, filp);
|
2011-11-29 02:40:46 +08:00
|
|
|
p9_debug(P9_DEBUG_VFS, " = %d\n", ret);
|
2009-09-24 02:00:27 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* v9fs_release_page - release the private state associated with a page
|
|
|
|
*
|
|
|
|
* Returns 1 if the page can be released, false otherwise.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int v9fs_release_page(struct page *page, gfp_t gfp)
|
|
|
|
{
|
|
|
|
if (PagePrivate(page))
|
|
|
|
return 0;
|
|
|
|
return v9fs_fscache_release_page(page, gfp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* v9fs_invalidate_page - Invalidate a page completely or partially
|
|
|
|
*
|
|
|
|
* @page: structure to page
|
|
|
|
* @offset: offset in the page
|
|
|
|
*/
|
|
|
|
|
2013-05-22 11:17:23 +08:00
|
|
|
static void v9fs_invalidate_page(struct page *page, unsigned int offset,
|
|
|
|
unsigned int length)
|
2009-09-24 02:00:27 +08:00
|
|
|
{
|
2011-02-28 19:33:58 +08:00
|
|
|
/*
|
|
|
|
* If called with zero offset, we should release
|
|
|
|
* the private state assocated with the page
|
|
|
|
*/
|
2013-05-22 11:17:23 +08:00
|
|
|
if (offset == 0 && length == PAGE_CACHE_SIZE)
|
2009-09-24 02:00:27 +08:00
|
|
|
v9fs_fscache_invalidate_page(page);
|
|
|
|
}
|
|
|
|
|
2011-02-28 19:33:58 +08:00
|
|
|
static int v9fs_vfs_writepage_locked(struct page *page)
|
|
|
|
{
|
|
|
|
struct inode *inode = page->mapping->host;
|
2015-04-02 09:54:42 +08:00
|
|
|
struct v9fs_inode *v9inode = V9FS_I(inode);
|
|
|
|
loff_t size = i_size_read(inode);
|
|
|
|
struct iov_iter from;
|
|
|
|
struct bio_vec bvec;
|
|
|
|
int err, len;
|
2011-02-28 19:33:58 +08:00
|
|
|
|
|
|
|
if (page->index == size >> PAGE_CACHE_SHIFT)
|
|
|
|
len = size & ~PAGE_CACHE_MASK;
|
|
|
|
else
|
|
|
|
len = PAGE_CACHE_SIZE;
|
|
|
|
|
2015-04-02 09:54:42 +08:00
|
|
|
bvec.bv_page = page;
|
|
|
|
bvec.bv_offset = 0;
|
|
|
|
bvec.bv_len = len;
|
|
|
|
iov_iter_bvec(&from, ITER_BVEC | WRITE, &bvec, 1, len);
|
2011-02-28 19:33:58 +08:00
|
|
|
|
2011-02-28 19:34:03 +08:00
|
|
|
/* We should have writeback_fid always set */
|
|
|
|
BUG_ON(!v9inode->writeback_fid);
|
2011-02-28 19:33:58 +08:00
|
|
|
|
2015-04-02 09:54:42 +08:00
|
|
|
set_page_writeback(page);
|
|
|
|
|
|
|
|
p9_client_write(v9inode->writeback_fid, page_offset(page), &from, &err);
|
2011-02-28 19:33:58 +08:00
|
|
|
|
|
|
|
end_page_writeback(page);
|
2015-04-02 09:54:42 +08:00
|
|
|
return err;
|
2011-02-28 19:33:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int v9fs_vfs_writepage(struct page *page, struct writeback_control *wbc)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
2014-01-10 20:44:09 +08:00
|
|
|
p9_debug(P9_DEBUG_VFS, "page %p\n", page);
|
|
|
|
|
2011-02-28 19:33:58 +08:00
|
|
|
retval = v9fs_vfs_writepage_locked(page);
|
|
|
|
if (retval < 0) {
|
|
|
|
if (retval == -EAGAIN) {
|
|
|
|
redirty_page_for_writepage(wbc, page);
|
|
|
|
retval = 0;
|
|
|
|
} else {
|
|
|
|
SetPageError(page);
|
|
|
|
mapping_set_error(page->mapping, retval);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
retval = 0;
|
|
|
|
|
|
|
|
unlock_page(page);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2009-09-24 02:00:27 +08:00
|
|
|
/**
|
|
|
|
* v9fs_launder_page - Writeback a dirty page
|
|
|
|
* Returns 0 on success.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int v9fs_launder_page(struct page *page)
|
|
|
|
{
|
2011-02-28 19:33:58 +08:00
|
|
|
int retval;
|
2011-02-28 19:33:56 +08:00
|
|
|
struct inode *inode = page->mapping->host;
|
2011-02-28 19:33:58 +08:00
|
|
|
|
2011-02-28 19:33:56 +08:00
|
|
|
v9fs_fscache_wait_on_page_write(inode, page);
|
2011-02-28 19:33:58 +08:00
|
|
|
if (clear_page_dirty_for_io(page)) {
|
|
|
|
retval = v9fs_vfs_writepage_locked(page);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
}
|
2009-09-24 02:00:27 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-24 23:43:28 +08:00
|
|
|
/**
|
|
|
|
* v9fs_direct_IO - 9P address space operation for direct I/O
|
|
|
|
* @iocb: target I/O control block
|
|
|
|
* @pos: offset in file to begin the operation
|
|
|
|
*
|
|
|
|
* The presence of v9fs_direct_IO() in the address space ops vector
|
|
|
|
* allowes open() O_DIRECT flags which would have failed otherwise.
|
|
|
|
*
|
|
|
|
* In the non-cached mode, we shunt off direct read and write requests before
|
|
|
|
* the VFS gets them, so this method should never be called.
|
|
|
|
*
|
|
|
|
* Direct IO is not 'yet' supported in the cached mode. Hence when
|
|
|
|
* this routine is called through generic_file_aio_read(), the read/write fails
|
|
|
|
* with an error.
|
|
|
|
*
|
|
|
|
*/
|
2011-02-28 19:34:04 +08:00
|
|
|
static ssize_t
|
2015-03-16 19:33:53 +08:00
|
|
|
v9fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter, loff_t pos)
|
2010-08-24 23:43:28 +08:00
|
|
|
{
|
2015-04-02 10:32:23 +08:00
|
|
|
struct file *file = iocb->ki_filp;
|
2015-04-02 11:49:24 +08:00
|
|
|
ssize_t n;
|
|
|
|
int err = 0;
|
2015-03-16 19:33:52 +08:00
|
|
|
if (iov_iter_rw(iter) == WRITE) {
|
2015-04-02 11:49:24 +08:00
|
|
|
n = p9_client_write(file->private_data, pos, iter, &err);
|
|
|
|
if (n) {
|
2015-04-02 10:32:23 +08:00
|
|
|
struct inode *inode = file_inode(file);
|
|
|
|
loff_t i_size = i_size_read(inode);
|
2015-04-02 11:49:24 +08:00
|
|
|
if (pos + n > i_size)
|
|
|
|
inode_add_bytes(inode, pos + n - i_size);
|
2015-04-02 10:32:23 +08:00
|
|
|
}
|
2015-04-02 11:49:24 +08:00
|
|
|
} else {
|
|
|
|
n = p9_client_read(file->private_data, pos, iter, &err);
|
2015-04-02 10:32:23 +08:00
|
|
|
}
|
2015-04-02 11:49:24 +08:00
|
|
|
return n ? n : err;
|
2010-08-24 23:43:28 +08:00
|
|
|
}
|
2011-02-28 19:33:58 +08:00
|
|
|
|
|
|
|
static int v9fs_write_begin(struct file *filp, struct address_space *mapping,
|
|
|
|
loff_t pos, unsigned len, unsigned flags,
|
|
|
|
struct page **pagep, void **fsdata)
|
|
|
|
{
|
|
|
|
int retval = 0;
|
|
|
|
struct page *page;
|
2011-02-28 19:34:03 +08:00
|
|
|
struct v9fs_inode *v9inode;
|
2011-02-28 19:33:58 +08:00
|
|
|
pgoff_t index = pos >> PAGE_CACHE_SHIFT;
|
|
|
|
struct inode *inode = mapping->host;
|
|
|
|
|
2014-01-10 20:44:09 +08:00
|
|
|
|
|
|
|
p9_debug(P9_DEBUG_VFS, "filp %p, mapping %p\n", filp, mapping);
|
|
|
|
|
2011-02-28 19:34:03 +08:00
|
|
|
v9inode = V9FS_I(inode);
|
2011-02-28 19:33:58 +08:00
|
|
|
start:
|
|
|
|
page = grab_cache_page_write_begin(mapping, index, flags);
|
|
|
|
if (!page) {
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2011-02-28 19:34:03 +08:00
|
|
|
BUG_ON(!v9inode->writeback_fid);
|
2011-02-28 19:33:58 +08:00
|
|
|
if (PageUptodate(page))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (len == PAGE_CACHE_SIZE)
|
|
|
|
goto out;
|
|
|
|
|
2011-02-28 19:34:03 +08:00
|
|
|
retval = v9fs_fid_readpage(v9inode->writeback_fid, page);
|
2011-02-28 19:33:58 +08:00
|
|
|
page_cache_release(page);
|
|
|
|
if (!retval)
|
|
|
|
goto start;
|
|
|
|
out:
|
|
|
|
*pagep = page;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int v9fs_write_end(struct file *filp, struct address_space *mapping,
|
|
|
|
loff_t pos, unsigned len, unsigned copied,
|
|
|
|
struct page *page, void *fsdata)
|
|
|
|
{
|
|
|
|
loff_t last_pos = pos + copied;
|
|
|
|
struct inode *inode = page->mapping->host;
|
|
|
|
|
2014-01-10 20:44:09 +08:00
|
|
|
p9_debug(P9_DEBUG_VFS, "filp %p, mapping %p\n", filp, mapping);
|
|
|
|
|
2011-02-28 19:33:58 +08:00
|
|
|
if (unlikely(copied < len)) {
|
|
|
|
/*
|
|
|
|
* zero out the rest of the area
|
|
|
|
*/
|
|
|
|
unsigned from = pos & (PAGE_CACHE_SIZE - 1);
|
|
|
|
|
|
|
|
zero_user(page, from + copied, len - copied);
|
|
|
|
flush_dcache_page(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PageUptodate(page))
|
|
|
|
SetPageUptodate(page);
|
|
|
|
/*
|
|
|
|
* No need to use i_size_read() here, the i_size
|
|
|
|
* cannot change under us because we hold the i_mutex.
|
|
|
|
*/
|
|
|
|
if (last_pos > inode->i_size) {
|
|
|
|
inode_add_bytes(inode, last_pos - inode->i_size);
|
|
|
|
i_size_write(inode, last_pos);
|
|
|
|
}
|
|
|
|
set_page_dirty(page);
|
|
|
|
unlock_page(page);
|
|
|
|
page_cache_release(page);
|
|
|
|
|
|
|
|
return copied;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-28 19:26:44 +08:00
|
|
|
const struct address_space_operations v9fs_addr_operations = {
|
2011-02-28 19:33:58 +08:00
|
|
|
.readpage = v9fs_vfs_readpage,
|
|
|
|
.readpages = v9fs_vfs_readpages,
|
|
|
|
.set_page_dirty = __set_page_dirty_nobuffers,
|
|
|
|
.writepage = v9fs_vfs_writepage,
|
|
|
|
.write_begin = v9fs_write_begin,
|
|
|
|
.write_end = v9fs_write_end,
|
|
|
|
.releasepage = v9fs_release_page,
|
|
|
|
.invalidatepage = v9fs_invalidate_page,
|
|
|
|
.launder_page = v9fs_launder_page,
|
|
|
|
.direct_IO = v9fs_direct_IO,
|
2006-01-19 09:43:02 +08:00
|
|
|
};
|