2019-05-28 23:57:16 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-09-10 03:04:18 +07:00
|
|
|
/*
|
|
|
|
* linux/fs/9p/vfs_file.c
|
|
|
|
*
|
|
|
|
* This file contians vfs file ops for 9P2000.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 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>
|
2006-10-19 00:55:46 +07:00
|
|
|
#include <linux/sched.h>
|
2005-09-10 03:04:18 +07:00
|
|
|
#include <linux/file.h>
|
|
|
|
#include <linux/stat.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/inet.h>
|
|
|
|
#include <linux/list.h>
|
2009-09-22 23:34:05 +07:00
|
|
|
#include <linux/pagemap.h>
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
#include <linux/utsname.h>
|
2016-12-25 02:46:01 +07:00
|
|
|
#include <linux/uaccess.h>
|
2005-09-10 03:04:18 +07:00
|
|
|
#include <linux/idr.h>
|
2015-04-02 07:17:51 +07:00
|
|
|
#include <linux/uio.h>
|
2015-04-02 23:02:03 +07:00
|
|
|
#include <linux/slab.h>
|
2007-07-11 05:57:28 +07:00
|
|
|
#include <net/9p/9p.h>
|
|
|
|
#include <net/9p/client.h>
|
2005-09-10 03:04:18 +07:00
|
|
|
|
|
|
|
#include "v9fs.h"
|
|
|
|
#include "v9fs_vfs.h"
|
|
|
|
#include "fid.h"
|
2009-09-24 01:00:27 +07:00
|
|
|
#include "cache.h"
|
2005-09-10 03:04:18 +07:00
|
|
|
|
2011-02-28 18:33:58 +07:00
|
|
|
static const struct vm_operations_struct v9fs_file_vm_ops;
|
2014-01-10 19:44:09 +07:00
|
|
|
static const struct vm_operations_struct v9fs_mmap_file_vm_ops;
|
2011-02-28 18:33:58 +07:00
|
|
|
|
2005-09-10 03:04:18 +07:00
|
|
|
/**
|
|
|
|
* v9fs_file_open - open a file (or directory)
|
|
|
|
* @inode: inode to be opened
|
|
|
|
* @file: file being opened
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
int v9fs_file_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2006-03-02 17:54:30 +07:00
|
|
|
int err;
|
2011-02-28 18:34:03 +07:00
|
|
|
struct v9fs_inode *v9inode;
|
2007-07-11 05:57:28 +07:00
|
|
|
struct v9fs_session_info *v9ses;
|
|
|
|
struct p9_fid *fid;
|
|
|
|
int omode;
|
2005-09-10 03:04:18 +07:00
|
|
|
|
2011-11-29 01:40:46 +07:00
|
|
|
p9_debug(P9_DEBUG_VFS, "inode: %p file: %p\n", inode, file);
|
2011-02-28 18:34:03 +07:00
|
|
|
v9inode = V9FS_I(inode);
|
2007-07-11 05:57:28 +07:00
|
|
|
v9ses = v9fs_inode2v9ses(inode);
|
2010-06-22 21:17:50 +07:00
|
|
|
if (v9fs_proto_dotl(v9ses))
|
2011-08-03 21:25:32 +07:00
|
|
|
omode = v9fs_open_to_dotl_flags(file->f_flags);
|
2010-06-22 21:17:50 +07:00
|
|
|
else
|
|
|
|
omode = v9fs_uflags2omode(file->f_flags,
|
|
|
|
v9fs_proto_dotu(v9ses));
|
2007-07-11 05:57:28 +07:00
|
|
|
fid = file->private_data;
|
|
|
|
if (!fid) {
|
2016-06-29 15:54:23 +07:00
|
|
|
fid = v9fs_fid_clone(file_dentry(file));
|
2007-07-11 05:57:28 +07:00
|
|
|
if (IS_ERR(fid))
|
|
|
|
return PTR_ERR(fid);
|
|
|
|
|
|
|
|
err = p9_client_open(fid, omode);
|
2007-07-14 01:01:27 +07:00
|
|
|
if (err < 0) {
|
2007-07-11 05:57:28 +07:00
|
|
|
p9_client_clunk(fid);
|
|
|
|
return err;
|
|
|
|
}
|
2010-06-22 21:17:50 +07:00
|
|
|
if ((file->f_flags & O_APPEND) &&
|
|
|
|
(!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)))
|
2008-06-25 05:39:39 +07:00
|
|
|
generic_file_llseek(file, 0, SEEK_END);
|
2006-03-02 17:54:30 +07:00
|
|
|
}
|
2005-09-10 03:04:18 +07:00
|
|
|
|
2007-07-11 05:57:28 +07:00
|
|
|
file->private_data = fid;
|
2011-03-08 18:09:46 +07:00
|
|
|
mutex_lock(&v9inode->v_mutex);
|
2014-01-10 19:44:09 +07:00
|
|
|
if ((v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) &&
|
|
|
|
!v9inode->writeback_fid &&
|
2011-03-08 18:09:49 +07:00
|
|
|
((file->f_flags & O_ACCMODE) != O_RDONLY)) {
|
2011-02-28 18:33:57 +07:00
|
|
|
/*
|
2011-02-28 18:34:03 +07:00
|
|
|
* clone a fid and add it to writeback_fid
|
2011-02-28 18:33:57 +07:00
|
|
|
* we do it during open time instead of
|
|
|
|
* page dirty time via write_begin/page_mkwrite
|
|
|
|
* because we want write after unlink usecase
|
|
|
|
* to work.
|
|
|
|
*/
|
2016-06-29 15:54:23 +07:00
|
|
|
fid = v9fs_writeback_fid(file_dentry(file));
|
2011-02-28 18:33:57 +07:00
|
|
|
if (IS_ERR(fid)) {
|
|
|
|
err = PTR_ERR(fid);
|
2011-03-08 18:09:46 +07:00
|
|
|
mutex_unlock(&v9inode->v_mutex);
|
2011-02-28 18:33:57 +07:00
|
|
|
goto out_error;
|
|
|
|
}
|
2011-02-28 18:34:03 +07:00
|
|
|
v9inode->writeback_fid = (void *) fid;
|
2011-02-28 18:33:57 +07:00
|
|
|
}
|
2011-03-08 18:09:46 +07:00
|
|
|
mutex_unlock(&v9inode->v_mutex);
|
2014-01-10 19:44:09 +07:00
|
|
|
if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
|
2009-09-24 01:00:27 +07:00
|
|
|
v9fs_cache_inode_set_cookie(inode, file);
|
2006-03-02 17:54:30 +07:00
|
|
|
return 0;
|
2011-02-28 18:33:57 +07:00
|
|
|
out_error:
|
|
|
|
p9_client_clunk(file->private_data);
|
|
|
|
file->private_data = NULL;
|
|
|
|
return err;
|
2005-09-10 03:04:18 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* v9fs_file_lock - lock a file (or directory)
|
2008-03-05 20:08:09 +07:00
|
|
|
* @filp: file to be locked
|
|
|
|
* @cmd: lock command
|
|
|
|
* @fl: file lock structure
|
2005-09-10 03:04:18 +07:00
|
|
|
*
|
2008-03-05 20:08:09 +07:00
|
|
|
* Bugs: this looks like a local only lock, we should extend into 9P
|
2005-09-10 03:04:18 +07:00
|
|
|
* by using open exclusive
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl)
|
|
|
|
{
|
|
|
|
int res = 0;
|
2013-01-24 05:07:38 +07:00
|
|
|
struct inode *inode = file_inode(filp);
|
2005-09-10 03:04:18 +07:00
|
|
|
|
2011-11-29 01:40:46 +07:00
|
|
|
p9_debug(P9_DEBUG_VFS, "filp: %p lock: %p\n", filp, fl);
|
2005-09-10 03:04:18 +07:00
|
|
|
|
|
|
|
/* No mandatory locks */
|
2010-03-13 22:03:55 +07:00
|
|
|
if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
|
2005-09-10 03:04:18 +07:00
|
|
|
return -ENOLCK;
|
|
|
|
|
|
|
|
if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->fl_type != F_UNLCK) {
|
[PATCH] Fix and add EXPORT_SYMBOL(filemap_write_and_wait)
This patch add EXPORT_SYMBOL(filemap_write_and_wait) and use it.
See mm/filemap.c:
And changes the filemap_write_and_wait() and filemap_write_and_wait_range().
Current filemap_write_and_wait() doesn't wait if filemap_fdatawrite()
returns error. However, even if filemap_fdatawrite() returned an
error, it may have submitted the partially data pages to the device.
(e.g. in the case of -ENOSPC)
<quotation>
Andrew Morton writes,
If filemap_fdatawrite() returns an error, this might be due to some
I/O problem: dead disk, unplugged cable, etc. Given the generally
crappy quality of the kernel's handling of such exceptions, there's a
good chance that the filemap_fdatawait() will get stuck in D state
forever.
</quotation>
So, this patch doesn't wait if filemap_fdatawrite() returns the -EIO.
Trond, could you please review the nfs part? Especially I'm not sure,
nfs must use the "filemap_fdatawrite(inode->i_mapping) == 0", or not.
Acked-by: Trond Myklebust <trond.myklebust@fys.uio.no>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-08 16:02:14 +07:00
|
|
|
filemap_write_and_wait(inode->i_mapping);
|
2007-02-10 16:45:39 +07:00
|
|
|
invalidate_mapping_pages(&inode->i_data, 0, -1);
|
2005-09-10 03:04:18 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
static int v9fs_file_do_lock(struct file *filp, int cmd, struct file_lock *fl)
|
|
|
|
{
|
|
|
|
struct p9_flock flock;
|
|
|
|
struct p9_fid *fid;
|
2015-01-09 18:56:07 +07:00
|
|
|
uint8_t status = P9_LOCK_ERROR;
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
int res = 0;
|
|
|
|
unsigned char fl_type;
|
2018-09-05 14:44:12 +07:00
|
|
|
struct v9fs_session_info *v9ses;
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
|
|
|
|
fid = filp->private_data;
|
|
|
|
BUG_ON(fid == NULL);
|
|
|
|
|
|
|
|
if ((fl->fl_flags & FL_POSIX) != FL_POSIX)
|
|
|
|
BUG();
|
|
|
|
|
2015-10-23 00:38:14 +07:00
|
|
|
res = locks_lock_file_wait(filp, fl);
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
if (res < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* convert posix lock to p9 tlock args */
|
|
|
|
memset(&flock, 0, sizeof(flock));
|
2011-08-21 01:51:18 +07:00
|
|
|
/* map the lock type */
|
|
|
|
switch (fl->fl_type) {
|
|
|
|
case F_RDLCK:
|
|
|
|
flock.type = P9_LOCK_TYPE_RDLCK;
|
|
|
|
break;
|
|
|
|
case F_WRLCK:
|
|
|
|
flock.type = P9_LOCK_TYPE_WRLCK;
|
|
|
|
break;
|
|
|
|
case F_UNLCK:
|
|
|
|
flock.type = P9_LOCK_TYPE_UNLCK;
|
|
|
|
break;
|
|
|
|
}
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
flock.start = fl->fl_start;
|
|
|
|
if (fl->fl_end == OFFSET_MAX)
|
|
|
|
flock.length = 0;
|
|
|
|
else
|
|
|
|
flock.length = fl->fl_end - fl->fl_start + 1;
|
|
|
|
flock.proc_id = fl->fl_pid;
|
2013-08-22 00:24:47 +07:00
|
|
|
flock.client_id = fid->clnt->name;
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
if (IS_SETLKW(cmd))
|
|
|
|
flock.flags = P9_LOCK_FLAGS_BLOCK;
|
|
|
|
|
2018-09-05 14:44:12 +07:00
|
|
|
v9ses = v9fs_inode2v9ses(file_inode(filp));
|
|
|
|
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
/*
|
|
|
|
* if its a blocked request and we get P9_LOCK_BLOCKED as the status
|
|
|
|
* for lock request, keep on trying
|
|
|
|
*/
|
|
|
|
for (;;) {
|
|
|
|
res = p9_client_lock_dotl(fid, &flock, &status);
|
|
|
|
if (res < 0)
|
2014-12-29 20:00:18 +07:00
|
|
|
goto out_unlock;
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
|
|
|
|
if (status != P9_LOCK_BLOCKED)
|
|
|
|
break;
|
|
|
|
if (status == P9_LOCK_BLOCKED && !IS_SETLKW(cmd))
|
|
|
|
break;
|
2018-09-05 14:44:12 +07:00
|
|
|
if (schedule_timeout_interruptible(v9ses->session_lock_timeout)
|
|
|
|
!= 0)
|
2012-01-04 04:27:50 +07:00
|
|
|
break;
|
2018-09-07 23:18:43 +07:00
|
|
|
/*
|
|
|
|
* p9_client_lock_dotl overwrites flock.client_id with the
|
|
|
|
* server message, free and reuse the client name
|
|
|
|
*/
|
|
|
|
if (flock.client_id != fid->clnt->name) {
|
|
|
|
kfree(flock.client_id);
|
|
|
|
flock.client_id = fid->clnt->name;
|
|
|
|
}
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* map 9p status to VFS status */
|
|
|
|
switch (status) {
|
|
|
|
case P9_LOCK_SUCCESS:
|
|
|
|
res = 0;
|
|
|
|
break;
|
|
|
|
case P9_LOCK_BLOCKED:
|
|
|
|
res = -EAGAIN;
|
|
|
|
break;
|
2014-12-29 20:00:19 +07:00
|
|
|
default:
|
|
|
|
WARN_ONCE(1, "unknown lock status code: %d\n", status);
|
2018-09-04 02:38:06 +07:00
|
|
|
/* fall through */
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
case P9_LOCK_ERROR:
|
|
|
|
case P9_LOCK_GRACE:
|
|
|
|
res = -ENOLCK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-12-29 20:00:18 +07:00
|
|
|
out_unlock:
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
/*
|
|
|
|
* incase server returned error for lock request, revert
|
|
|
|
* it locally
|
|
|
|
*/
|
|
|
|
if (res < 0 && fl->fl_type != F_UNLCK) {
|
|
|
|
fl_type = fl->fl_type;
|
|
|
|
fl->fl_type = F_UNLCK;
|
2015-11-06 09:44:21 +07:00
|
|
|
/* Even if this fails we want to return the remote error */
|
2015-11-06 14:10:54 +07:00
|
|
|
locks_lock_file_wait(filp, fl);
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
fl->fl_type = fl_type;
|
|
|
|
}
|
2018-09-07 23:18:43 +07:00
|
|
|
if (flock.client_id != fid->clnt->name)
|
|
|
|
kfree(flock.client_id);
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
out:
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-09-27 13:52:13 +07:00
|
|
|
static int v9fs_file_getlock(struct file *filp, struct file_lock *fl)
|
|
|
|
{
|
|
|
|
struct p9_getlock glock;
|
|
|
|
struct p9_fid *fid;
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
fid = filp->private_data;
|
|
|
|
BUG_ON(fid == NULL);
|
|
|
|
|
|
|
|
posix_test_lock(filp, fl);
|
|
|
|
/*
|
|
|
|
* if we have a conflicting lock locally, no need to validate
|
|
|
|
* with server
|
|
|
|
*/
|
|
|
|
if (fl->fl_type != F_UNLCK)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
/* convert posix lock to p9 tgetlock args */
|
|
|
|
memset(&glock, 0, sizeof(glock));
|
2011-08-21 01:51:18 +07:00
|
|
|
glock.type = P9_LOCK_TYPE_UNLCK;
|
2010-09-27 13:52:13 +07:00
|
|
|
glock.start = fl->fl_start;
|
|
|
|
if (fl->fl_end == OFFSET_MAX)
|
|
|
|
glock.length = 0;
|
|
|
|
else
|
|
|
|
glock.length = fl->fl_end - fl->fl_start + 1;
|
|
|
|
glock.proc_id = fl->fl_pid;
|
2013-08-22 00:24:47 +07:00
|
|
|
glock.client_id = fid->clnt->name;
|
2010-09-27 13:52:13 +07:00
|
|
|
|
|
|
|
res = p9_client_getlock_dotl(fid, &glock);
|
|
|
|
if (res < 0)
|
2018-09-07 23:18:43 +07:00
|
|
|
goto out;
|
2011-08-21 01:51:18 +07:00
|
|
|
/* map 9p lock type to os lock type */
|
|
|
|
switch (glock.type) {
|
|
|
|
case P9_LOCK_TYPE_RDLCK:
|
|
|
|
fl->fl_type = F_RDLCK;
|
|
|
|
break;
|
|
|
|
case P9_LOCK_TYPE_WRLCK:
|
|
|
|
fl->fl_type = F_WRLCK;
|
|
|
|
break;
|
|
|
|
case P9_LOCK_TYPE_UNLCK:
|
|
|
|
fl->fl_type = F_UNLCK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (glock.type != P9_LOCK_TYPE_UNLCK) {
|
2010-09-27 13:52:13 +07:00
|
|
|
fl->fl_start = glock.start;
|
|
|
|
if (glock.length == 0)
|
|
|
|
fl->fl_end = OFFSET_MAX;
|
|
|
|
else
|
|
|
|
fl->fl_end = glock.start + glock.length - 1;
|
fs/locks: Remove fl_nspid and use fs-specific l_pid for remote locks
Since commit c69899a17ca4 "NFSv4: Update of VFS byte range lock must be
atomic with the stateid update", NFSv4 has been inserting locks in rpciod
worker context. The result is that the file_lock's fl_nspid is the
kworker's pid instead of the original userspace pid.
The fl_nspid is only used to represent the namespaced virtual pid number
when displaying locks or returning from F_GETLK. There's no reason to set
it for every inserted lock, since we can usually just look it up from
fl_pid. So, instead of looking up and holding struct pid for every lock,
let's just look up the virtual pid number from fl_pid when it is needed.
That means we can remove fl_nspid entirely.
The translaton and presentation of fl_pid should handle the following four
cases:
1 - F_GETLK on a remote file with a remote lock:
In this case, the filesystem should determine the l_pid to return here.
Filesystems should indicate that the fl_pid represents a non-local pid
value that should not be translated by returning an fl_pid <= 0.
2 - F_GETLK on a local file with a remote lock:
This should be the l_pid of the lock manager process, and translated.
3 - F_GETLK on a remote file with a local lock, and
4 - F_GETLK on a local file with a local lock:
These should be the translated l_pid of the local locking process.
Fuse was already doing the correct thing by translating the pid into the
caller's namespace. With this change we must update fuse to translate
to init's pid namespace, so that the locks API can then translate from
init's pid namespace into the pid namespace of the caller.
With this change, the locks API will expect that if a filesystem returns
a remote pid as opposed to a local pid for F_GETLK, that remote pid will
be <= 0. This signifies that the pid is remote, and the locks API will
forego translating that pid into the pid namespace of the local calling
process.
Finally, we convert remote filesystems to present remote pids using
negative numbers. Have lustre, 9p, ceph, cifs, and dlm negate the remote
pid returned for F_GETLK lock requests.
Since local pids will never be larger than PID_MAX_LIMIT (which is
currently defined as <= 4 million), but pid_t is an unsigned int, we
should have plenty of room to represent remote pids with negative
numbers if we assume that remote pid numbers are similarly limited.
If this is not the case, then we run the risk of having a remote pid
returned for which there is also a corresponding local pid. This is a
problem we have now, but this patch should reduce the chances of that
occurring, while also returning those remote pid numbers, for whatever
that may be worth.
Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
Signed-off-by: Jeff Layton <jlayton@redhat.com>
2017-07-16 21:28:22 +07:00
|
|
|
fl->fl_pid = -glock.proc_id;
|
2011-08-21 01:51:18 +07:00
|
|
|
}
|
2018-09-07 23:18:43 +07:00
|
|
|
out:
|
|
|
|
if (glock.client_id != fid->clnt->name)
|
|
|
|
kfree(glock.client_id);
|
2010-09-27 13:52:13 +07:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
/**
|
|
|
|
* v9fs_file_lock_dotl - lock a file (or directory)
|
|
|
|
* @filp: file to be locked
|
|
|
|
* @cmd: lock command
|
|
|
|
* @fl: file lock structure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int v9fs_file_lock_dotl(struct file *filp, int cmd, struct file_lock *fl)
|
|
|
|
{
|
2013-01-24 05:07:38 +07:00
|
|
|
struct inode *inode = file_inode(filp);
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
int ret = -ENOLCK;
|
|
|
|
|
2014-08-20 07:17:38 +07:00
|
|
|
p9_debug(P9_DEBUG_VFS, "filp: %p cmd:%d lock: %p name: %pD\n",
|
|
|
|
filp, cmd, fl, filp);
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
|
|
|
|
/* No mandatory locks */
|
|
|
|
if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->fl_type != F_UNLCK) {
|
|
|
|
filemap_write_and_wait(inode->i_mapping);
|
|
|
|
invalidate_mapping_pages(&inode->i_data, 0, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_SETLK(cmd) || IS_SETLKW(cmd))
|
|
|
|
ret = v9fs_file_do_lock(filp, cmd, fl);
|
2010-09-27 13:52:13 +07:00
|
|
|
else if (IS_GETLK(cmd))
|
|
|
|
ret = v9fs_file_getlock(filp, fl);
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
else
|
|
|
|
ret = -EINVAL;
|
|
|
|
out_err:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* v9fs_file_flock_dotl - lock a file
|
|
|
|
* @filp: file to be locked
|
|
|
|
* @cmd: lock command
|
|
|
|
* @fl: file lock structure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int v9fs_file_flock_dotl(struct file *filp, int cmd,
|
|
|
|
struct file_lock *fl)
|
|
|
|
{
|
2013-01-24 05:07:38 +07:00
|
|
|
struct inode *inode = file_inode(filp);
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
int ret = -ENOLCK;
|
|
|
|
|
2014-08-20 07:17:38 +07:00
|
|
|
p9_debug(P9_DEBUG_VFS, "filp: %p cmd:%d lock: %p name: %pD\n",
|
|
|
|
filp, cmd, fl, filp);
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
|
|
|
|
/* No mandatory locks */
|
|
|
|
if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
if (!(fl->fl_flags & FL_FLOCK))
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->fl_type != F_UNLCK) {
|
|
|
|
filemap_write_and_wait(inode->i_mapping);
|
|
|
|
invalidate_mapping_pages(&inode->i_data, 0, -1);
|
|
|
|
}
|
|
|
|
/* Convert flock to posix lock */
|
|
|
|
fl->fl_flags |= FL_POSIX;
|
|
|
|
fl->fl_flags ^= FL_FLOCK;
|
|
|
|
|
|
|
|
if (IS_SETLK(cmd) | IS_SETLKW(cmd))
|
|
|
|
ret = v9fs_file_do_lock(filp, cmd, fl);
|
|
|
|
else
|
|
|
|
ret = -EINVAL;
|
|
|
|
out_err:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-10-14 08:36:16 +07:00
|
|
|
/**
|
|
|
|
* v9fs_file_read - read from a file
|
|
|
|
* @filp: file pointer to read
|
|
|
|
* @udata: user data buffer to read data into
|
|
|
|
* @count: size of buffer
|
|
|
|
* @offset: offset at which to read data
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-09-10 03:04:18 +07:00
|
|
|
static ssize_t
|
2015-04-02 10:59:57 +07:00
|
|
|
v9fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
|
2005-09-10 03:04:18 +07:00
|
|
|
{
|
2015-04-02 10:59:57 +07:00
|
|
|
struct p9_fid *fid = iocb->ki_filp->private_data;
|
2015-08-15 19:07:44 +07:00
|
|
|
int ret, err = 0;
|
2005-09-10 03:04:18 +07:00
|
|
|
|
2015-04-02 10:59:57 +07:00
|
|
|
p9_debug(P9_DEBUG_VFS, "count %zu offset %lld\n",
|
|
|
|
iov_iter_count(to), iocb->ki_pos);
|
2008-10-14 08:36:16 +07:00
|
|
|
|
2015-04-02 10:59:57 +07:00
|
|
|
ret = p9_client_read(fid, iocb->ki_pos, to, &err);
|
2015-04-02 10:42:28 +07:00
|
|
|
if (!ret)
|
|
|
|
return err;
|
2005-09-10 03:04:18 +07:00
|
|
|
|
2015-04-02 10:59:57 +07:00
|
|
|
iocb->ki_pos += ret;
|
2007-07-11 05:57:28 +07:00
|
|
|
return ret;
|
2005-09-10 03:04:18 +07:00
|
|
|
}
|
|
|
|
|
2011-02-28 18:33:56 +07:00
|
|
|
/**
|
|
|
|
* v9fs_file_write - write to a file
|
|
|
|
* @filp: file pointer to write
|
|
|
|
* @data: data buffer to write data from
|
|
|
|
* @count: size of buffer
|
|
|
|
* @offset: offset at which to write data
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static ssize_t
|
2015-04-02 10:59:57 +07:00
|
|
|
v9fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
|
2011-02-28 18:33:56 +07:00
|
|
|
{
|
2015-04-02 10:59:57 +07:00
|
|
|
struct file *file = iocb->ki_filp;
|
2015-04-09 23:55:47 +07:00
|
|
|
ssize_t retval;
|
|
|
|
loff_t origin;
|
2015-04-02 09:04:46 +07:00
|
|
|
int err = 0;
|
2011-02-28 18:33:56 +07:00
|
|
|
|
2015-04-09 23:55:47 +07:00
|
|
|
retval = generic_write_checks(iocb, from);
|
|
|
|
if (retval <= 0)
|
2015-04-02 09:04:46 +07:00
|
|
|
return retval;
|
|
|
|
|
2015-04-09 23:55:47 +07:00
|
|
|
origin = iocb->ki_pos;
|
|
|
|
retval = p9_client_write(file->private_data, iocb->ki_pos, from, &err);
|
2015-04-02 09:04:46 +07:00
|
|
|
if (retval > 0) {
|
2015-04-02 10:59:57 +07:00
|
|
|
struct inode *inode = file_inode(file);
|
2015-04-02 09:04:46 +07:00
|
|
|
loff_t i_size;
|
|
|
|
unsigned long pg_start, pg_end;
|
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 19:29:47 +07:00
|
|
|
pg_start = origin >> PAGE_SHIFT;
|
|
|
|
pg_end = (origin + retval - 1) >> PAGE_SHIFT;
|
2015-04-02 09:04:46 +07:00
|
|
|
if (inode->i_mapping && inode->i_mapping->nrpages)
|
|
|
|
invalidate_inode_pages2_range(inode->i_mapping,
|
|
|
|
pg_start, pg_end);
|
2015-04-09 23:55:47 +07:00
|
|
|
iocb->ki_pos += retval;
|
2015-04-02 09:04:46 +07:00
|
|
|
i_size = i_size_read(inode);
|
2015-04-09 23:55:47 +07:00
|
|
|
if (iocb->ki_pos > i_size) {
|
|
|
|
inode_add_bytes(inode, iocb->ki_pos - i_size);
|
2019-01-24 13:35:13 +07:00
|
|
|
/*
|
|
|
|
* Need to serialize against i_size_write() in
|
|
|
|
* v9fs_stat2inode()
|
|
|
|
*/
|
|
|
|
v9fs_i_size_write(inode, iocb->ki_pos);
|
2015-04-02 09:04:46 +07:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
return err;
|
2005-09-10 03:04:18 +07:00
|
|
|
}
|
|
|
|
|
2011-07-17 07:44:56 +07:00
|
|
|
static int v9fs_file_fsync(struct file *filp, loff_t start, loff_t end,
|
|
|
|
int datasync)
|
2010-02-09 04:36:48 +07:00
|
|
|
{
|
|
|
|
struct p9_fid *fid;
|
2011-07-17 07:44:56 +07:00
|
|
|
struct inode *inode = filp->f_mapping->host;
|
2010-02-09 04:36:48 +07:00
|
|
|
struct p9_wstat wstat;
|
|
|
|
int retval;
|
|
|
|
|
2017-07-08 02:20:52 +07:00
|
|
|
retval = file_write_and_wait_range(filp, start, end);
|
2011-07-17 07:44:56 +07:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
2016-01-23 03:40:57 +07:00
|
|
|
inode_lock(inode);
|
2011-11-29 01:40:46 +07:00
|
|
|
p9_debug(P9_DEBUG_VFS, "filp %p datasync %x\n", filp, datasync);
|
2010-02-09 04:36:48 +07:00
|
|
|
|
|
|
|
fid = filp->private_data;
|
|
|
|
v9fs_blank_wstat(&wstat);
|
|
|
|
|
|
|
|
retval = p9_client_wstat(fid, &wstat);
|
2016-01-23 03:40:57 +07:00
|
|
|
inode_unlock(inode);
|
2011-07-17 07:44:56 +07:00
|
|
|
|
2010-02-09 04:36:48 +07:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2011-07-17 07:44:56 +07:00
|
|
|
int v9fs_file_fsync_dotl(struct file *filp, loff_t start, loff_t end,
|
|
|
|
int datasync)
|
2010-09-23 07:19:19 +07:00
|
|
|
{
|
|
|
|
struct p9_fid *fid;
|
2011-07-17 07:44:56 +07:00
|
|
|
struct inode *inode = filp->f_mapping->host;
|
2010-09-23 07:19:19 +07:00
|
|
|
int retval;
|
|
|
|
|
2017-07-08 02:20:52 +07:00
|
|
|
retval = file_write_and_wait_range(filp, start, end);
|
2011-07-17 07:44:56 +07:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
2016-01-23 03:40:57 +07:00
|
|
|
inode_lock(inode);
|
2011-11-29 01:40:46 +07:00
|
|
|
p9_debug(P9_DEBUG_VFS, "filp %p datasync %x\n", filp, datasync);
|
2010-09-23 07:19:19 +07:00
|
|
|
|
|
|
|
fid = filp->private_data;
|
|
|
|
|
2010-10-23 00:13:12 +07:00
|
|
|
retval = p9_client_fsync(fid, datasync);
|
2016-01-23 03:40:57 +07:00
|
|
|
inode_unlock(inode);
|
2011-07-17 07:44:56 +07:00
|
|
|
|
2010-09-23 07:19:19 +07:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2011-02-28 18:33:58 +07:00
|
|
|
static int
|
2014-01-10 19:44:09 +07:00
|
|
|
v9fs_file_mmap(struct file *filp, struct vm_area_struct *vma)
|
2011-02-28 18:33:58 +07:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
2014-01-10 19:44:09 +07:00
|
|
|
|
|
|
|
retval = generic_file_mmap(filp, vma);
|
2011-02-28 18:33:58 +07:00
|
|
|
if (!retval)
|
|
|
|
vma->vm_ops = &v9fs_file_vm_ops;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2014-01-10 19:44:09 +07:00
|
|
|
static int
|
|
|
|
v9fs_mmap_file_mmap(struct file *filp, struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
struct inode *inode;
|
|
|
|
struct v9fs_inode *v9inode;
|
|
|
|
struct p9_fid *fid;
|
|
|
|
|
|
|
|
inode = file_inode(filp);
|
|
|
|
v9inode = V9FS_I(inode);
|
|
|
|
mutex_lock(&v9inode->v_mutex);
|
|
|
|
if (!v9inode->writeback_fid &&
|
|
|
|
(vma->vm_flags & VM_WRITE)) {
|
|
|
|
/*
|
|
|
|
* clone a fid and add it to writeback_fid
|
|
|
|
* we do it during mmap instead of
|
|
|
|
* page dirty time via write_begin/page_mkwrite
|
|
|
|
* because we want write after unlink usecase
|
|
|
|
* to work.
|
|
|
|
*/
|
2016-06-29 15:54:23 +07:00
|
|
|
fid = v9fs_writeback_fid(file_dentry(filp));
|
2014-01-10 19:44:09 +07:00
|
|
|
if (IS_ERR(fid)) {
|
|
|
|
retval = PTR_ERR(fid);
|
|
|
|
mutex_unlock(&v9inode->v_mutex);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
v9inode->writeback_fid = (void *) fid;
|
|
|
|
}
|
|
|
|
mutex_unlock(&v9inode->v_mutex);
|
|
|
|
|
|
|
|
retval = generic_file_mmap(filp, vma);
|
|
|
|
if (!retval)
|
|
|
|
vma->vm_ops = &v9fs_mmap_file_vm_ops;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2018-07-18 09:14:35 +07:00
|
|
|
static vm_fault_t
|
2017-02-25 05:56:41 +07:00
|
|
|
v9fs_vm_page_mkwrite(struct vm_fault *vmf)
|
2011-02-28 18:33:58 +07:00
|
|
|
{
|
2011-02-28 18:34:03 +07:00
|
|
|
struct v9fs_inode *v9inode;
|
2011-02-28 18:33:58 +07:00
|
|
|
struct page *page = vmf->page;
|
2017-02-25 05:56:41 +07:00
|
|
|
struct file *filp = vmf->vma->vm_file;
|
2013-01-24 05:07:38 +07:00
|
|
|
struct inode *inode = file_inode(filp);
|
2011-02-28 18:33:58 +07:00
|
|
|
|
|
|
|
|
2011-11-29 01:40:46 +07:00
|
|
|
p9_debug(P9_DEBUG_VFS, "page %p fid %lx\n",
|
|
|
|
page, (unsigned long)filp->private_data);
|
2011-02-28 18:33:58 +07:00
|
|
|
|
2012-06-12 21:20:25 +07:00
|
|
|
/* Update file times before taking page lock */
|
|
|
|
file_update_time(filp);
|
|
|
|
|
2011-02-28 18:34:03 +07:00
|
|
|
v9inode = V9FS_I(inode);
|
2011-02-28 18:33:58 +07:00
|
|
|
/* make sure the cache has finished storing the page */
|
|
|
|
v9fs_fscache_wait_on_page_write(inode, page);
|
2011-02-28 18:34:03 +07:00
|
|
|
BUG_ON(!v9inode->writeback_fid);
|
2011-02-28 18:33:58 +07:00
|
|
|
lock_page(page);
|
|
|
|
if (page->mapping != inode->i_mapping)
|
|
|
|
goto out_unlock;
|
2013-02-22 07:42:53 +07:00
|
|
|
wait_for_stable_page(page);
|
2011-02-28 18:33:58 +07:00
|
|
|
|
|
|
|
return VM_FAULT_LOCKED;
|
|
|
|
out_unlock:
|
|
|
|
unlock_page(page);
|
|
|
|
return VM_FAULT_NOPAGE;
|
|
|
|
}
|
|
|
|
|
2014-01-10 19:44:09 +07:00
|
|
|
/**
|
|
|
|
* v9fs_mmap_file_read - read from a file
|
|
|
|
* @filp: file pointer to read
|
2014-06-05 06:06:26 +07:00
|
|
|
* @data: user data buffer to read data into
|
2014-01-10 19:44:09 +07:00
|
|
|
* @count: size of buffer
|
|
|
|
* @offset: offset at which to read data
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static ssize_t
|
2015-04-02 10:59:57 +07:00
|
|
|
v9fs_mmap_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
|
2014-01-10 19:44:09 +07:00
|
|
|
{
|
|
|
|
/* TODO: Check if there are dirty pages */
|
2015-04-02 10:59:57 +07:00
|
|
|
return v9fs_file_read_iter(iocb, to);
|
2014-01-10 19:44:09 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* v9fs_mmap_file_write - write to a file
|
|
|
|
* @filp: file pointer to write
|
|
|
|
* @data: data buffer to write data from
|
|
|
|
* @count: size of buffer
|
|
|
|
* @offset: offset at which to write data
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static ssize_t
|
2015-04-02 10:59:57 +07:00
|
|
|
v9fs_mmap_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
|
2014-01-10 19:44:09 +07:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* TODO: invalidate mmaps on filp's inode between
|
|
|
|
* offset and offset+count
|
|
|
|
*/
|
2015-04-02 10:59:57 +07:00
|
|
|
return v9fs_file_write_iter(iocb, from);
|
2014-01-10 19:44:09 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void v9fs_mmap_vm_close(struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
struct inode *inode;
|
|
|
|
|
|
|
|
struct writeback_control wbc = {
|
|
|
|
.nr_to_write = LONG_MAX,
|
|
|
|
.sync_mode = WB_SYNC_ALL,
|
|
|
|
.range_start = vma->vm_pgoff * PAGE_SIZE,
|
|
|
|
/* absolute end, byte at end included */
|
|
|
|
.range_end = vma->vm_pgoff * PAGE_SIZE +
|
|
|
|
(vma->vm_end - vma->vm_start - 1),
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
p9_debug(P9_DEBUG_VFS, "9p VMA close, %p, flushing", vma);
|
|
|
|
|
|
|
|
inode = file_inode(vma->vm_file);
|
|
|
|
|
|
|
|
if (!mapping_cap_writeback_dirty(inode->i_mapping))
|
|
|
|
wbc.nr_to_write = 0;
|
|
|
|
|
|
|
|
might_sleep();
|
|
|
|
sync_inode(inode, &wbc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-28 18:33:58 +07:00
|
|
|
static const struct vm_operations_struct v9fs_file_vm_ops = {
|
|
|
|
.fault = filemap_fault,
|
2014-04-08 05:37:19 +07:00
|
|
|
.map_pages = filemap_map_pages,
|
2011-02-28 18:33:58 +07:00
|
|
|
.page_mkwrite = v9fs_vm_page_mkwrite,
|
|
|
|
};
|
|
|
|
|
2014-01-10 19:44:09 +07:00
|
|
|
static const struct vm_operations_struct v9fs_mmap_file_vm_ops = {
|
|
|
|
.close = v9fs_mmap_vm_close,
|
|
|
|
.fault = filemap_fault,
|
2014-04-08 05:37:19 +07:00
|
|
|
.map_pages = filemap_map_pages,
|
2014-01-10 19:44:09 +07:00
|
|
|
.page_mkwrite = v9fs_vm_page_mkwrite,
|
|
|
|
};
|
|
|
|
|
2011-02-28 18:34:04 +07:00
|
|
|
|
2011-02-28 18:33:54 +07:00
|
|
|
const struct file_operations v9fs_cached_file_operations = {
|
2007-02-12 02:21:39 +07:00
|
|
|
.llseek = generic_file_llseek,
|
2014-04-03 01:33:16 +07:00
|
|
|
.read_iter = generic_file_read_iter,
|
2014-04-03 14:17:43 +07:00
|
|
|
.write_iter = generic_file_write_iter,
|
2007-02-12 02:21:39 +07:00
|
|
|
.open = v9fs_file_open,
|
|
|
|
.release = v9fs_dir_release,
|
|
|
|
.lock = v9fs_file_lock,
|
2011-02-28 18:33:58 +07:00
|
|
|
.mmap = v9fs_file_mmap,
|
2010-02-09 04:36:48 +07:00
|
|
|
.fsync = v9fs_file_fsync,
|
2007-02-12 02:21:39 +07:00
|
|
|
};
|
|
|
|
|
2011-02-28 18:33:54 +07:00
|
|
|
const struct file_operations v9fs_cached_file_operations_dotl = {
|
2010-09-23 06:30:52 +07:00
|
|
|
.llseek = generic_file_llseek,
|
2014-04-03 01:33:16 +07:00
|
|
|
.read_iter = generic_file_read_iter,
|
2014-04-03 14:17:43 +07:00
|
|
|
.write_iter = generic_file_write_iter,
|
2010-09-23 06:30:52 +07:00
|
|
|
.open = v9fs_file_open,
|
|
|
|
.release = v9fs_dir_release,
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
.lock = v9fs_file_lock_dotl,
|
|
|
|
.flock = v9fs_file_flock_dotl,
|
2011-02-28 18:33:58 +07:00
|
|
|
.mmap = v9fs_file_mmap,
|
2010-09-23 07:19:19 +07:00
|
|
|
.fsync = v9fs_file_fsync_dotl,
|
2010-09-23 06:30:52 +07:00
|
|
|
};
|
|
|
|
|
2006-03-28 16:56:42 +07:00
|
|
|
const struct file_operations v9fs_file_operations = {
|
2005-09-10 03:04:18 +07:00
|
|
|
.llseek = generic_file_llseek,
|
2015-04-02 10:59:57 +07:00
|
|
|
.read_iter = v9fs_file_read_iter,
|
|
|
|
.write_iter = v9fs_file_write_iter,
|
2005-09-10 03:04:18 +07:00
|
|
|
.open = v9fs_file_open,
|
|
|
|
.release = v9fs_dir_release,
|
|
|
|
.lock = v9fs_file_lock,
|
2008-02-07 08:25:05 +07:00
|
|
|
.mmap = generic_file_readonly_mmap,
|
2010-02-09 04:36:48 +07:00
|
|
|
.fsync = v9fs_file_fsync,
|
2005-09-10 03:04:18 +07:00
|
|
|
};
|
2010-03-25 19:41:54 +07:00
|
|
|
|
|
|
|
const struct file_operations v9fs_file_operations_dotl = {
|
|
|
|
.llseek = generic_file_llseek,
|
2015-04-02 10:59:57 +07:00
|
|
|
.read_iter = v9fs_file_read_iter,
|
|
|
|
.write_iter = v9fs_file_write_iter,
|
2010-03-25 19:41:54 +07:00
|
|
|
.open = v9fs_file_open,
|
|
|
|
.release = v9fs_dir_release,
|
9p: Implement TLOCK
Synopsis
size[4] TLock tag[2] fid[4] flock[n]
size[4] RLock tag[2] status[1]
Description
Tlock is used to acquire/release byte range posix locks on a file
identified by given fid. The reply contains status of the lock request
flock structure:
type[1] - Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
flags[4] - Flags could be either of
P9_LOCK_FLAGS_BLOCK - Blocked lock request, if there is a
conflicting lock exists, wait for that lock to be released.
P9_LOCK_FLAGS_RECLAIM - Reclaim lock request, used when client is
trying to reclaim a lock after a server restrart (due to crash)
start[8] - Starting offset for lock
length[8] - Number of bytes to lock
If length is 0, lock all bytes starting at the location 'start'
through to the end of file
pid[4] - PID of the process that wants to take lock
client_id[4] - Unique client id
status[1] - Status of the lock request, can be
P9_LOCK_SUCCESS(0), P9_LOCK_BLOCKED(1), P9_LOCK_ERROR(2) or
P9_LOCK_GRACE(3)
P9_LOCK_SUCCESS - Request was successful
P9_LOCK_BLOCKED - A conflicting lock is held by another process
P9_LOCK_ERROR - Error while processing the lock request
P9_LOCK_GRACE - Server is in grace period, it can't accept new lock
requests in this period (except locks with
P9_LOCK_FLAGS_RECLAIM flag set)
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
2010-09-27 13:04:24 +07:00
|
|
|
.lock = v9fs_file_lock_dotl,
|
|
|
|
.flock = v9fs_file_flock_dotl,
|
2010-03-25 19:41:54 +07:00
|
|
|
.mmap = generic_file_readonly_mmap,
|
2010-09-23 07:19:19 +07:00
|
|
|
.fsync = v9fs_file_fsync_dotl,
|
2010-03-25 19:41:54 +07:00
|
|
|
};
|
2014-01-10 19:44:09 +07:00
|
|
|
|
|
|
|
const struct file_operations v9fs_mmap_file_operations = {
|
|
|
|
.llseek = generic_file_llseek,
|
2015-04-02 10:59:57 +07:00
|
|
|
.read_iter = v9fs_mmap_file_read_iter,
|
|
|
|
.write_iter = v9fs_mmap_file_write_iter,
|
2014-01-10 19:44:09 +07:00
|
|
|
.open = v9fs_file_open,
|
|
|
|
.release = v9fs_dir_release,
|
|
|
|
.lock = v9fs_file_lock,
|
|
|
|
.mmap = v9fs_mmap_file_mmap,
|
|
|
|
.fsync = v9fs_file_fsync,
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct file_operations v9fs_mmap_file_operations_dotl = {
|
|
|
|
.llseek = generic_file_llseek,
|
2015-04-02 10:59:57 +07:00
|
|
|
.read_iter = v9fs_mmap_file_read_iter,
|
|
|
|
.write_iter = v9fs_mmap_file_write_iter,
|
2014-01-10 19:44:09 +07:00
|
|
|
.open = v9fs_file_open,
|
|
|
|
.release = v9fs_dir_release,
|
|
|
|
.lock = v9fs_file_lock_dotl,
|
|
|
|
.flock = v9fs_file_flock_dotl,
|
|
|
|
.mmap = v9fs_mmap_file_mmap,
|
|
|
|
.fsync = v9fs_file_fsync_dotl,
|
|
|
|
};
|