vfs_addr.c 4.8 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*
 *  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
10 11
 *  it under the terms of the GNU General Public License version 2
 *  as published by the Free Software Foundation.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
 *
 *  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>
A
Alexey Dobriyan 已提交
35
#include <linux/sched.h>
36 37
#include <net/9p/9p.h>
#include <net/9p/client.h>
38 39 40

#include "v9fs.h"
#include "v9fs_vfs.h"
41
#include "cache.h"
42 43 44 45

/**
 * v9fs_vfs_readpage - read an entire page in from 9P
 *
E
Eric Van Hensbergen 已提交
46
 * @filp: file being read
47 48 49 50 51 52
 * @page: structure to page
 *
 */

static int v9fs_vfs_readpage(struct file *filp, struct page *page)
{
53 54 55
	int retval;
	loff_t offset;
	char *buffer;
56
	struct inode *inode;
57

58
	inode = page->mapping->host;
59
	P9_DPRINTK(P9_DEBUG_VFS, "\n");
60 61 62 63 64 65 66

	BUG_ON(!PageLocked(page));

	retval = v9fs_readpage_from_fscache(inode, page);
	if (retval == 0)
		return retval;

67
	buffer = kmap(page);
68
	offset = page_offset(page);
69

70
	retval = v9fs_file_readn(filp, buffer, NULL, PAGE_CACHE_SIZE, offset);
71 72
	if (retval < 0) {
		v9fs_uncache_page(inode, page);
73
		goto done;
74
	}
75

76
	memset(buffer + retval, 0, PAGE_CACHE_SIZE - retval);
77 78
	flush_dcache_page(page);
	SetPageUptodate(page);
79 80

	v9fs_readpage_to_fscache(inode, page);
81 82
	retval = 0;

83
done:
84 85 86 87 88
	kunmap(page);
	unlock_page(page);
	return retval;
}

89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
/**
 * 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;
	P9_DPRINTK(P9_DEBUG_VFS, "inode: %p file: %p\n", inode, filp);

	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);
	P9_DPRINTK(P9_DEBUG_VFS, "  = %d\n", ret);
	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
 */

static void v9fs_invalidate_page(struct page *page, unsigned long offset)
{
	if (offset == 0)
		v9fs_fscache_invalidate_page(page);
}

/**
 * v9fs_launder_page - Writeback a dirty page
 * Since the writes go directly to the server, we simply return a 0
 * here to indicate success.
 *
 * Returns 0 on success.
 */

static int v9fs_launder_page(struct page *page)
{
	return 0;
}

157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
/**
 * v9fs_direct_IO - 9P address space operation for direct I/O
 * @rw: direction (read or write)
 * @iocb: target I/O control block
 * @iov: array of vectors that define I/O buffer
 * @pos: offset in file to begin the operation
 * @nr_segs: size of iovec array
 *
 * 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.
 *
 */
ssize_t v9fs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
		loff_t pos, unsigned long nr_segs)
{
	P9_DPRINTK(P9_DEBUG_VFS, "v9fs_direct_IO: v9fs_direct_IO (%s) "
			"off/no(%lld/%lu) EINVAL\n",
			iocb->ki_filp->f_path.dentry->d_name.name,
			(long long) pos, nr_segs);

	return -EINVAL;
}
186
const struct address_space_operations v9fs_addr_operations = {
187
      .readpage = v9fs_vfs_readpage,
188 189 190 191
      .readpages = v9fs_vfs_readpages,
      .releasepage = v9fs_release_page,
      .invalidatepage = v9fs_invalidate_page,
      .launder_page = v9fs_launder_page,
192
      .direct_IO = v9fs_direct_IO,
193
};