2019-05-28 16:57:16 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2006-01-19 01:43:02 +00:00
|
|
|
/*
|
|
|
|
* 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>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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-20 21:22:52 +00:00
|
|
|
#include <linux/sched.h>
|
2015-02-22 16:58:50 +00:00
|
|
|
#include <linux/uio.h>
|
2021-11-02 08:29:55 +00:00
|
|
|
#include <linux/netfs.h>
|
2007-07-10 22:57:28 +00:00
|
|
|
#include <net/9p/9p.h>
|
|
|
|
#include <net/9p/client.h>
|
2006-01-19 01:43:02 +00:00
|
|
|
|
|
|
|
#include "v9fs.h"
|
|
|
|
#include "v9fs_vfs.h"
|
2009-09-23 18:00:27 +00:00
|
|
|
#include "cache.h"
|
2011-02-28 11:33:58 +00:00
|
|
|
#include "fid.h"
|
2006-01-19 01:43:02 +00:00
|
|
|
|
|
|
|
/**
|
2021-11-02 08:29:55 +00:00
|
|
|
* v9fs_req_issue_op - Issue a read from 9P
|
|
|
|
* @subreq: The read to make
|
2006-01-19 01:43:02 +00:00
|
|
|
*/
|
2021-11-02 08:29:55 +00:00
|
|
|
static void v9fs_req_issue_op(struct netfs_read_subrequest *subreq)
|
2006-01-19 01:43:02 +00:00
|
|
|
{
|
2021-11-02 08:29:55 +00:00
|
|
|
struct netfs_read_request *rreq = subreq->rreq;
|
|
|
|
struct p9_fid *fid = rreq->netfs_priv;
|
2015-04-02 03:42:28 +00:00
|
|
|
struct iov_iter to;
|
2021-11-02 08:29:55 +00:00
|
|
|
loff_t pos = subreq->start + subreq->transferred;
|
|
|
|
size_t len = subreq->len - subreq->transferred;
|
|
|
|
int total, err;
|
2007-02-11 19:21:39 +00:00
|
|
|
|
2021-11-02 08:29:55 +00:00
|
|
|
iov_iter_xarray(&to, READ, &rreq->mapping->i_pages, pos, len);
|
2009-09-23 18:00:27 +00:00
|
|
|
|
2021-11-02 08:29:55 +00:00
|
|
|
total = p9_client_read(fid, pos, &to, &err);
|
|
|
|
netfs_subreq_terminated(subreq, err ?: total, false);
|
|
|
|
}
|
2009-09-23 18:00:27 +00:00
|
|
|
|
2021-11-02 08:29:55 +00:00
|
|
|
/**
|
|
|
|
* v9fs_init_rreq - Initialise a read request
|
|
|
|
* @rreq: The read request
|
|
|
|
* @file: The file being read from
|
|
|
|
*/
|
|
|
|
static void v9fs_init_rreq(struct netfs_read_request *rreq, struct file *file)
|
|
|
|
{
|
|
|
|
struct p9_fid *fid = file->private_data;
|
2009-09-23 18:00:27 +00:00
|
|
|
|
2021-11-02 08:29:55 +00:00
|
|
|
refcount_inc(&fid->count);
|
|
|
|
rreq->netfs_priv = fid;
|
|
|
|
}
|
2006-01-19 01:43:02 +00:00
|
|
|
|
2021-11-02 08:29:55 +00:00
|
|
|
/**
|
|
|
|
* v9fs_req_cleanup - Cleanup request initialized by v9fs_init_rreq
|
|
|
|
* @mapping: unused mapping of request to cleanup
|
|
|
|
* @priv: private data to cleanup, a fid, guaranted non-null.
|
|
|
|
*/
|
|
|
|
static void v9fs_req_cleanup(struct address_space *mapping, void *priv)
|
|
|
|
{
|
|
|
|
struct p9_fid *fid = priv;
|
2006-01-19 01:43:02 +00:00
|
|
|
|
2021-11-02 08:29:55 +00:00
|
|
|
p9_client_clunk(fid);
|
|
|
|
}
|
2009-09-23 18:00:27 +00:00
|
|
|
|
2021-11-02 08:29:55 +00:00
|
|
|
/**
|
|
|
|
* v9fs_is_cache_enabled - Determine if caching is enabled for an inode
|
|
|
|
* @inode: The inode to check
|
|
|
|
*/
|
|
|
|
static bool v9fs_is_cache_enabled(struct inode *inode)
|
|
|
|
{
|
|
|
|
struct fscache_cookie *cookie = v9fs_inode_cookie(V9FS_I(inode));
|
2006-01-19 01:43:02 +00:00
|
|
|
|
2021-11-02 08:29:55 +00:00
|
|
|
return fscache_cookie_enabled(cookie) && !hlist_empty(&cookie->backing_objects);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* v9fs_begin_cache_operation - Begin a cache operation for a read
|
|
|
|
* @rreq: The read request
|
|
|
|
*/
|
|
|
|
static int v9fs_begin_cache_operation(struct netfs_read_request *rreq)
|
|
|
|
{
|
|
|
|
struct fscache_cookie *cookie = v9fs_inode_cookie(V9FS_I(rreq->inode));
|
|
|
|
|
|
|
|
return fscache_begin_read_operation(rreq, cookie);
|
2006-01-19 01:43:02 +00:00
|
|
|
}
|
|
|
|
|
2021-11-02 08:29:55 +00:00
|
|
|
static const struct netfs_read_request_ops v9fs_req_ops = {
|
|
|
|
.init_rreq = v9fs_init_rreq,
|
|
|
|
.is_cache_enabled = v9fs_is_cache_enabled,
|
|
|
|
.begin_cache_operation = v9fs_begin_cache_operation,
|
|
|
|
.issue_op = v9fs_req_issue_op,
|
|
|
|
.cleanup = v9fs_req_cleanup,
|
|
|
|
};
|
|
|
|
|
2011-02-28 11:33:58 +00:00
|
|
|
/**
|
|
|
|
* v9fs_vfs_readpage - read an entire page in from 9P
|
2021-11-02 08:29:55 +00:00
|
|
|
* @file: file being read
|
2011-02-28 11:33:58 +00:00
|
|
|
* @page: structure to page
|
|
|
|
*
|
|
|
|
*/
|
2021-11-02 08:29:55 +00:00
|
|
|
static int v9fs_vfs_readpage(struct file *file, struct page *page)
|
2011-02-28 11:33:58 +00:00
|
|
|
{
|
2021-11-02 08:29:55 +00:00
|
|
|
return netfs_readpage(file, page, &v9fs_req_ops, NULL);
|
2011-02-28 11:33:58 +00:00
|
|
|
}
|
|
|
|
|
2009-09-23 18:00:27 +00:00
|
|
|
/**
|
2021-11-02 08:29:55 +00:00
|
|
|
* v9fs_vfs_readahead - read a set of pages from 9P
|
|
|
|
* @ractl: The readahead parameters
|
2009-09-23 18:00:27 +00:00
|
|
|
*/
|
2021-11-02 08:29:55 +00:00
|
|
|
static void v9fs_vfs_readahead(struct readahead_control *ractl)
|
2009-09-23 18:00:27 +00:00
|
|
|
{
|
2021-11-02 08:29:55 +00:00
|
|
|
netfs_readahead(ractl, &v9fs_req_ops, NULL);
|
2009-09-23 18:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* v9fs_release_page - release the private state associated with a page
|
2021-10-04 21:07:22 +00:00
|
|
|
* @page: The page to be released
|
|
|
|
* @gfp: The caller's allocation restrictions
|
2009-09-23 18:00:27 +00:00
|
|
|
*
|
|
|
|
* 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;
|
2021-11-02 08:29:55 +00:00
|
|
|
#ifdef CONFIG_9P_FSCACHE
|
|
|
|
if (PageFsCache(page)) {
|
|
|
|
if (!(gfp & __GFP_DIRECT_RECLAIM) || !(gfp & __GFP_FS))
|
|
|
|
return 0;
|
|
|
|
wait_on_page_fscache(page);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 1;
|
2009-09-23 18:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* v9fs_invalidate_page - Invalidate a page completely or partially
|
2021-10-04 21:07:22 +00:00
|
|
|
* @page: The page to be invalidated
|
|
|
|
* @offset: offset of the invalidated region
|
|
|
|
* @length: length of the invalidated region
|
2009-09-23 18:00:27 +00:00
|
|
|
*/
|
|
|
|
|
2013-05-22 03:17:23 +00:00
|
|
|
static void v9fs_invalidate_page(struct page *page, unsigned int offset,
|
|
|
|
unsigned int length)
|
2009-09-23 18:00:27 +00:00
|
|
|
{
|
2021-11-02 08:29:55 +00:00
|
|
|
wait_on_page_fscache(page);
|
2009-09-23 18:00:27 +00:00
|
|
|
}
|
|
|
|
|
2011-02-28 11:33:58 +00:00
|
|
|
static int v9fs_vfs_writepage_locked(struct page *page)
|
|
|
|
{
|
|
|
|
struct inode *inode = page->mapping->host;
|
2015-04-02 01:54:42 +00:00
|
|
|
struct v9fs_inode *v9inode = V9FS_I(inode);
|
2021-11-02 08:29:55 +00:00
|
|
|
loff_t start = page_offset(page);
|
2015-04-02 01:54:42 +00:00
|
|
|
loff_t size = i_size_read(inode);
|
|
|
|
struct iov_iter from;
|
|
|
|
int err, len;
|
2011-02-28 11:33:58 +00:00
|
|
|
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 12:29:47 +00:00
|
|
|
if (page->index == size >> PAGE_SHIFT)
|
|
|
|
len = size & ~PAGE_MASK;
|
2011-02-28 11:33:58 +00:00
|
|
|
else
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 12:29:47 +00:00
|
|
|
len = PAGE_SIZE;
|
2011-02-28 11:33:58 +00:00
|
|
|
|
2021-11-02 08:29:55 +00:00
|
|
|
iov_iter_xarray(&from, WRITE, &page->mapping->i_pages, start, len);
|
2011-02-28 11:33:58 +00:00
|
|
|
|
2011-02-28 11:34:03 +00:00
|
|
|
/* We should have writeback_fid always set */
|
|
|
|
BUG_ON(!v9inode->writeback_fid);
|
2011-02-28 11:33:58 +00:00
|
|
|
|
2015-04-02 01:54:42 +00:00
|
|
|
set_page_writeback(page);
|
|
|
|
|
2021-11-02 08:29:55 +00:00
|
|
|
p9_client_write(v9inode->writeback_fid, start, &from, &err);
|
2011-02-28 11:33:58 +00:00
|
|
|
|
|
|
|
end_page_writeback(page);
|
2015-04-02 01:54:42 +00:00
|
|
|
return err;
|
2011-02-28 11:33:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int v9fs_vfs_writepage(struct page *page, struct writeback_control *wbc)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
2014-01-10 12:44:09 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "page %p\n", page);
|
|
|
|
|
2011-02-28 11:33:58 +00: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-23 18:00:27 +00:00
|
|
|
/**
|
|
|
|
* v9fs_launder_page - Writeback a dirty page
|
2021-10-04 21:07:22 +00:00
|
|
|
* @page: The page to be cleaned up
|
|
|
|
*
|
2009-09-23 18:00:27 +00:00
|
|
|
* Returns 0 on success.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int v9fs_launder_page(struct page *page)
|
|
|
|
{
|
2011-02-28 11:33:58 +00:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (clear_page_dirty_for_io(page)) {
|
|
|
|
retval = v9fs_vfs_writepage_locked(page);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
}
|
2021-11-02 08:29:55 +00:00
|
|
|
wait_on_page_fscache(page);
|
2009-09-23 18:00:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-24 15:43:28 +00:00
|
|
|
/**
|
|
|
|
* v9fs_direct_IO - 9P address space operation for direct I/O
|
|
|
|
* @iocb: target I/O control block
|
2021-10-04 21:07:22 +00:00
|
|
|
* @iter: The data/buffer to use
|
2010-08-24 15:43:28 +00:00
|
|
|
*
|
|
|
|
* 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 11:34:04 +00:00
|
|
|
static ssize_t
|
2016-04-07 15:51:58 +00:00
|
|
|
v9fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
|
2010-08-24 15:43:28 +00:00
|
|
|
{
|
2015-04-02 02:32:23 +00:00
|
|
|
struct file *file = iocb->ki_filp;
|
2016-04-07 15:51:58 +00:00
|
|
|
loff_t pos = iocb->ki_pos;
|
2015-04-02 03:49:24 +00:00
|
|
|
ssize_t n;
|
|
|
|
int err = 0;
|
2021-11-02 13:16:43 +00:00
|
|
|
|
2015-03-16 11:33:52 +00:00
|
|
|
if (iov_iter_rw(iter) == WRITE) {
|
2015-04-02 03:49:24 +00:00
|
|
|
n = p9_client_write(file->private_data, pos, iter, &err);
|
|
|
|
if (n) {
|
2015-04-02 02:32:23 +00:00
|
|
|
struct inode *inode = file_inode(file);
|
|
|
|
loff_t i_size = i_size_read(inode);
|
2021-11-02 13:16:43 +00:00
|
|
|
|
2015-04-02 03:49:24 +00:00
|
|
|
if (pos + n > i_size)
|
|
|
|
inode_add_bytes(inode, pos + n - i_size);
|
2015-04-02 02:32:23 +00:00
|
|
|
}
|
2015-04-02 03:49:24 +00:00
|
|
|
} else {
|
|
|
|
n = p9_client_read(file->private_data, pos, iter, &err);
|
2015-04-02 02:32:23 +00:00
|
|
|
}
|
2015-04-02 03:49:24 +00:00
|
|
|
return n ? n : err;
|
2010-08-24 15:43:28 +00:00
|
|
|
}
|
2011-02-28 11:33:58 +00:00
|
|
|
|
|
|
|
static int v9fs_write_begin(struct file *filp, struct address_space *mapping,
|
2021-11-02 13:16:43 +00:00
|
|
|
loff_t pos, unsigned int len, unsigned int flags,
|
2011-02-28 11:33:58 +00:00
|
|
|
struct page **pagep, void **fsdata)
|
|
|
|
{
|
2021-11-02 08:29:55 +00:00
|
|
|
int retval;
|
2011-02-28 11:33:58 +00:00
|
|
|
struct page *page;
|
2021-11-02 08:29:55 +00:00
|
|
|
struct v9fs_inode *v9inode = V9FS_I(mapping->host);
|
2014-01-10 12:44:09 +00:00
|
|
|
|
|
|
|
p9_debug(P9_DEBUG_VFS, "filp %p, mapping %p\n", filp, mapping);
|
|
|
|
|
2011-02-28 11:34:03 +00:00
|
|
|
BUG_ON(!v9inode->writeback_fid);
|
2011-02-28 11:33:58 +00:00
|
|
|
|
2021-11-02 08:29:55 +00:00
|
|
|
/* Prefetch area to be written into the cache if we're caching this
|
|
|
|
* file. We need to do this before we get a lock on the page in case
|
|
|
|
* there's more than one writer competing for the same cache block.
|
|
|
|
*/
|
|
|
|
retval = netfs_write_begin(filp, mapping, pos, len, flags, &page, fsdata,
|
|
|
|
&v9fs_req_ops, NULL);
|
|
|
|
if (retval < 0)
|
|
|
|
return retval;
|
2011-02-28 11:33:58 +00:00
|
|
|
|
2021-11-02 08:29:55 +00:00
|
|
|
*pagep = find_subpage(page, pos / PAGE_SIZE);
|
2011-02-28 11:33:58 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int v9fs_write_end(struct file *filp, struct address_space *mapping,
|
2021-11-02 13:16:43 +00:00
|
|
|
loff_t pos, unsigned int len, unsigned int copied,
|
2011-02-28 11:33:58 +00:00
|
|
|
struct page *page, void *fsdata)
|
|
|
|
{
|
|
|
|
loff_t last_pos = pos + copied;
|
|
|
|
struct inode *inode = page->mapping->host;
|
|
|
|
|
2014-01-10 12:44:09 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "filp %p, mapping %p\n", filp, mapping);
|
|
|
|
|
2017-04-10 18:46:51 +00:00
|
|
|
if (!PageUptodate(page)) {
|
|
|
|
if (unlikely(copied < len)) {
|
|
|
|
copied = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2021-11-02 08:29:55 +00:00
|
|
|
|
|
|
|
SetPageUptodate(page);
|
2011-02-28 11:33:58 +00:00
|
|
|
}
|
2021-11-02 08:29:55 +00:00
|
|
|
|
2011-02-28 11:33:58 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
2016-08-30 00:56:35 +00:00
|
|
|
out:
|
2011-02-28 11:33:58 +00:00
|
|
|
unlock_page(page);
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 12:29:47 +00:00
|
|
|
put_page(page);
|
2011-02-28 11:33:58 +00:00
|
|
|
|
|
|
|
return copied;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-28 11:26:44 +00:00
|
|
|
const struct address_space_operations v9fs_addr_operations = {
|
2011-02-28 11:33:58 +00:00
|
|
|
.readpage = v9fs_vfs_readpage,
|
2021-11-02 08:29:55 +00:00
|
|
|
.readahead = v9fs_vfs_readahead,
|
2011-02-28 11:33:58 +00:00
|
|
|
.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 01:43:02 +00:00
|
|
|
};
|