2019-05-28 16:57:16 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-09-09 20:04:18 +00:00
|
|
|
/*
|
|
|
|
* 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>
|
2022-11-20 14:15:34 +00:00
|
|
|
#include <linux/filelock.h>
|
2006-10-18 17:55:46 +00:00
|
|
|
#include <linux/sched.h>
|
2005-09-09 20:04:18 +00:00
|
|
|
#include <linux/file.h>
|
|
|
|
#include <linux/stat.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/list.h>
|
2009-09-22 16:34:05 +00: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 06:04:24 +00:00
|
|
|
#include <linux/utsname.h>
|
2016-12-24 19:46:01 +00:00
|
|
|
#include <linux/uaccess.h>
|
2015-04-02 00:17:51 +00:00
|
|
|
#include <linux/uio.h>
|
2015-04-02 16:02:03 +00:00
|
|
|
#include <linux/slab.h>
|
2007-07-10 22:57:28 +00:00
|
|
|
#include <net/9p/9p.h>
|
|
|
|
#include <net/9p/client.h>
|
2005-09-09 20:04:18 +00:00
|
|
|
|
|
|
|
#include "v9fs.h"
|
|
|
|
#include "v9fs_vfs.h"
|
|
|
|
#include "fid.h"
|
2009-09-23 18:00:27 +00:00
|
|
|
#include "cache.h"
|
2005-09-09 20:04:18 +00:00
|
|
|
|
2014-01-10 12:44:09 +00:00
|
|
|
static const struct vm_operations_struct v9fs_mmap_file_vm_ops;
|
2011-02-28 11:33:58 +00:00
|
|
|
|
2005-09-09 20:04:18 +00: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 10:54:30 +00:00
|
|
|
int err;
|
2007-07-10 22:57:28 +00:00
|
|
|
struct v9fs_session_info *v9ses;
|
2023-03-27 02:06:37 +00:00
|
|
|
struct p9_fid *fid;
|
2007-07-10 22:57:28 +00:00
|
|
|
int omode;
|
2005-09-09 20:04:18 +00:00
|
|
|
|
2011-11-28 18:40:46 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "inode: %p file: %p\n", inode, file);
|
2007-07-10 22:57:28 +00:00
|
|
|
v9ses = v9fs_inode2v9ses(inode);
|
2010-06-22 14:17:50 +00:00
|
|
|
if (v9fs_proto_dotl(v9ses))
|
2011-08-03 14:25:32 +00:00
|
|
|
omode = v9fs_open_to_dotl_flags(file->f_flags);
|
2010-06-22 14:17:50 +00:00
|
|
|
else
|
|
|
|
omode = v9fs_uflags2omode(file->f_flags,
|
|
|
|
v9fs_proto_dotu(v9ses));
|
2007-07-10 22:57:28 +00:00
|
|
|
fid = file->private_data;
|
|
|
|
if (!fid) {
|
2016-06-29 08:54:23 +00:00
|
|
|
fid = v9fs_fid_clone(file_dentry(file));
|
2007-07-10 22:57:28 +00:00
|
|
|
if (IS_ERR(fid))
|
|
|
|
return PTR_ERR(fid);
|
|
|
|
|
2023-03-27 01:53:10 +00:00
|
|
|
if ((v9ses->cache & CACHE_WRITEBACK) && (omode & P9_OWRITE)) {
|
2023-03-27 02:06:37 +00:00
|
|
|
int writeback_omode = (omode & ~P9_OWRITE) | P9_ORDWR;
|
|
|
|
|
|
|
|
p9_debug(P9_DEBUG_CACHE, "write-only file with writeback enabled, try opening O_RDWR\n");
|
|
|
|
err = p9_client_open(fid, writeback_omode);
|
|
|
|
if (err < 0) {
|
|
|
|
p9_debug(P9_DEBUG_CACHE, "could not open O_RDWR, disabling caches\n");
|
|
|
|
err = p9_client_open(fid, omode);
|
|
|
|
fid->mode |= P9L_DIRECT;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
err = p9_client_open(fid, omode);
|
|
|
|
}
|
2007-07-13 18:01:27 +00:00
|
|
|
if (err < 0) {
|
2022-06-12 04:42:32 +00:00
|
|
|
p9_fid_put(fid);
|
2007-07-10 22:57:28 +00:00
|
|
|
return err;
|
|
|
|
}
|
2010-06-22 14:17:50 +00:00
|
|
|
if ((file->f_flags & O_APPEND) &&
|
|
|
|
(!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)))
|
2008-06-24 22:39:39 +00:00
|
|
|
generic_file_llseek(file, 0, SEEK_END);
|
2022-06-12 07:05:39 +00:00
|
|
|
|
|
|
|
file->private_data = fid;
|
2006-03-02 10:54:30 +00:00
|
|
|
}
|
2005-09-09 20:04:18 +00:00
|
|
|
|
2022-12-08 02:03:32 +00:00
|
|
|
#ifdef CONFIG_9P_FSCACHE
|
2023-03-27 01:53:10 +00:00
|
|
|
if (v9ses->cache & CACHE_FSCACHE)
|
|
|
|
fscache_use_cookie(v9fs_inode_cookie(V9FS_I(inode)),
|
2020-11-18 09:06:42 +00:00
|
|
|
file->f_mode & FMODE_WRITE);
|
2022-12-08 02:03:32 +00:00
|
|
|
#endif
|
2023-03-27 02:06:37 +00:00
|
|
|
v9fs_fid_add_modes(fid, v9ses->flags, v9ses->cache, file->f_flags);
|
2022-06-12 07:05:39 +00:00
|
|
|
v9fs_open_fid_add(inode, &fid);
|
2006-03-02 10:54:30 +00:00
|
|
|
return 0;
|
2005-09-09 20:04:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* v9fs_file_lock - lock a file (or directory)
|
2008-03-05 13:08:09 +00:00
|
|
|
* @filp: file to be locked
|
|
|
|
* @cmd: lock command
|
|
|
|
* @fl: file lock structure
|
2005-09-09 20:04:18 +00:00
|
|
|
*
|
2008-03-05 13:08:09 +00:00
|
|
|
* Bugs: this looks like a local only lock, we should extend into 9P
|
2005-09-09 20:04:18 +00:00
|
|
|
* by using open exclusive
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl)
|
|
|
|
{
|
2013-01-23 22:07:38 +00:00
|
|
|
struct inode *inode = file_inode(filp);
|
2005-09-09 20:04:18 +00:00
|
|
|
|
2011-11-28 18:40:46 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "filp: %p lock: %p\n", filp, fl);
|
2005-09-09 20:04:18 +00:00
|
|
|
|
2024-01-31 23:02:15 +00:00
|
|
|
if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->c.flc_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 09:02:14 +00:00
|
|
|
filemap_write_and_wait(inode->i_mapping);
|
2007-02-10 09:45:39 +00:00
|
|
|
invalidate_mapping_pages(&inode->i_data, 0, -1);
|
2005-09-09 20:04:18 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 11:43:43 +00:00
|
|
|
return 0;
|
2005-09-09 20:04:18 +00:00
|
|
|
}
|
|
|
|
|
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 06:04:24 +00: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 11:56:07 +00: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 06:04:24 +00:00
|
|
|
int res = 0;
|
2018-09-05 07:44:12 +00: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 06:04:24 +00:00
|
|
|
|
|
|
|
fid = filp->private_data;
|
|
|
|
BUG_ON(fid == NULL);
|
|
|
|
|
2024-01-31 23:02:15 +00:00
|
|
|
BUG_ON((fl->c.flc_flags & FL_POSIX) != FL_POSIX);
|
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 06:04:24 +00:00
|
|
|
|
2015-10-22 17:38:14 +00: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 06:04:24 +00:00
|
|
|
if (res < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* convert posix lock to p9 tlock args */
|
|
|
|
memset(&flock, 0, sizeof(flock));
|
2011-08-20 18:51:18 +00:00
|
|
|
/* map the lock type */
|
2024-01-31 23:02:15 +00:00
|
|
|
switch (fl->c.flc_type) {
|
2011-08-20 18:51:18 +00:00
|
|
|
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 06:04:24 +00: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;
|
2024-01-31 23:02:15 +00:00
|
|
|
flock.proc_id = fl->c.flc_pid;
|
2013-08-21 17:24:47 +00: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 06:04:24 +00:00
|
|
|
if (IS_SETLKW(cmd))
|
|
|
|
flock.flags = P9_LOCK_FLAGS_BLOCK;
|
|
|
|
|
2018-09-05 07:44:12 +00: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 06:04:24 +00: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 13:00:18 +00: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 06:04:24 +00:00
|
|
|
|
|
|
|
if (status != P9_LOCK_BLOCKED)
|
|
|
|
break;
|
|
|
|
if (status == P9_LOCK_BLOCKED && !IS_SETLKW(cmd))
|
|
|
|
break;
|
2018-09-05 07:44:12 +00:00
|
|
|
if (schedule_timeout_interruptible(v9ses->session_lock_timeout)
|
|
|
|
!= 0)
|
2012-01-03 21:27:50 +00:00
|
|
|
break;
|
2018-09-07 16:18:43 +00: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 06:04:24 +00: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 13:00:19 +00:00
|
|
|
default:
|
|
|
|
WARN_ONCE(1, "unknown lock status code: %d\n", status);
|
2020-08-23 22:36:59 +00:00
|
|
|
fallthrough;
|
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 06:04:24 +00:00
|
|
|
case P9_LOCK_ERROR:
|
|
|
|
case P9_LOCK_GRACE:
|
|
|
|
res = -ENOLCK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-12-29 13:00:18 +00: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 06:04:24 +00:00
|
|
|
/*
|
|
|
|
* incase server returned error for lock request, revert
|
|
|
|
* it locally
|
|
|
|
*/
|
2024-01-31 23:02:15 +00:00
|
|
|
if (res < 0 && fl->c.flc_type != F_UNLCK) {
|
|
|
|
unsigned char type = fl->c.flc_type;
|
2024-01-31 23:01:46 +00:00
|
|
|
|
2024-01-31 23:02:15 +00:00
|
|
|
fl->c.flc_type = F_UNLCK;
|
2015-11-06 02:44:21 +00:00
|
|
|
/* Even if this fails we want to return the remote error */
|
2015-11-06 07:10:54 +00:00
|
|
|
locks_lock_file_wait(filp, fl);
|
2024-01-31 23:02:15 +00:00
|
|
|
fl->c.flc_type = type;
|
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 06:04:24 +00:00
|
|
|
}
|
2018-09-07 16:18:43 +00: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 06:04:24 +00:00
|
|
|
out:
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-09-27 06:52:13 +00: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
|
|
|
|
*/
|
2024-01-31 23:02:15 +00:00
|
|
|
if (fl->c.flc_type != F_UNLCK)
|
2010-09-27 06:52:13 +00:00
|
|
|
return res;
|
|
|
|
|
|
|
|
/* convert posix lock to p9 tgetlock args */
|
|
|
|
memset(&glock, 0, sizeof(glock));
|
2011-08-20 18:51:18 +00:00
|
|
|
glock.type = P9_LOCK_TYPE_UNLCK;
|
2010-09-27 06:52:13 +00: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;
|
2024-01-31 23:02:15 +00:00
|
|
|
glock.proc_id = fl->c.flc_pid;
|
2013-08-21 17:24:47 +00:00
|
|
|
glock.client_id = fid->clnt->name;
|
2010-09-27 06:52:13 +00:00
|
|
|
|
|
|
|
res = p9_client_getlock_dotl(fid, &glock);
|
|
|
|
if (res < 0)
|
2018-09-07 16:18:43 +00:00
|
|
|
goto out;
|
2011-08-20 18:51:18 +00:00
|
|
|
/* map 9p lock type to os lock type */
|
|
|
|
switch (glock.type) {
|
|
|
|
case P9_LOCK_TYPE_RDLCK:
|
2024-01-31 23:02:15 +00:00
|
|
|
fl->c.flc_type = F_RDLCK;
|
2011-08-20 18:51:18 +00:00
|
|
|
break;
|
|
|
|
case P9_LOCK_TYPE_WRLCK:
|
2024-01-31 23:02:15 +00:00
|
|
|
fl->c.flc_type = F_WRLCK;
|
2011-08-20 18:51:18 +00:00
|
|
|
break;
|
|
|
|
case P9_LOCK_TYPE_UNLCK:
|
2024-01-31 23:02:15 +00:00
|
|
|
fl->c.flc_type = F_UNLCK;
|
2011-08-20 18:51:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (glock.type != P9_LOCK_TYPE_UNLCK) {
|
2010-09-27 06:52:13 +00:00
|
|
|
fl->fl_start = glock.start;
|
|
|
|
if (glock.length == 0)
|
|
|
|
fl->fl_end = OFFSET_MAX;
|
|
|
|
else
|
|
|
|
fl->fl_end = glock.start + glock.length - 1;
|
2024-01-31 23:02:15 +00:00
|
|
|
fl->c.flc_pid = -glock.proc_id;
|
2011-08-20 18:51:18 +00:00
|
|
|
}
|
2018-09-07 16:18:43 +00:00
|
|
|
out:
|
|
|
|
if (glock.client_id != fid->clnt->name)
|
|
|
|
kfree(glock.client_id);
|
2010-09-27 06:52:13 +00: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 06:04:24 +00: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-23 22:07:38 +00: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 06:04:24 +00:00
|
|
|
int ret = -ENOLCK;
|
|
|
|
|
2014-08-20 00:17:38 +00: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 06:04:24 +00:00
|
|
|
|
2024-01-31 23:02:15 +00:00
|
|
|
if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->c.flc_type != F_UNLCK) {
|
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 06:04:24 +00:00
|
|
|
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 06:52:13 +00: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 06:04:24 +00:00
|
|
|
else
|
|
|
|
ret = -EINVAL;
|
|
|
|
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-23 22:07:38 +00: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 06:04:24 +00:00
|
|
|
int ret = -ENOLCK;
|
|
|
|
|
2014-08-20 00:17:38 +00: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 06:04:24 +00:00
|
|
|
|
2024-01-31 23:02:15 +00:00
|
|
|
if (!(fl->c.flc_flags & FL_FLOCK))
|
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 06:04:24 +00:00
|
|
|
goto out_err;
|
|
|
|
|
2024-01-31 23:02:15 +00:00
|
|
|
if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->c.flc_type != F_UNLCK) {
|
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 06:04:24 +00:00
|
|
|
filemap_write_and_wait(inode->i_mapping);
|
|
|
|
invalidate_mapping_pages(&inode->i_data, 0, -1);
|
|
|
|
}
|
|
|
|
/* Convert flock to posix lock */
|
2024-01-31 23:02:15 +00:00
|
|
|
fl->c.flc_flags |= FL_POSIX;
|
|
|
|
fl->c.flc_flags ^= FL_FLOCK;
|
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 06:04:24 +00:00
|
|
|
|
|
|
|
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 01:36:16 +00:00
|
|
|
/**
|
2021-10-04 21:07:22 +00:00
|
|
|
* v9fs_file_read_iter - read from a file
|
|
|
|
* @iocb: The operation parameters
|
|
|
|
* @to: The buffer to read into
|
2008-10-14 01:36:16 +00:00
|
|
|
*
|
|
|
|
*/
|
2005-09-09 20:04:18 +00:00
|
|
|
static ssize_t
|
2015-04-02 03:59:57 +00:00
|
|
|
v9fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
|
2005-09-09 20:04:18 +00:00
|
|
|
{
|
2015-04-02 03:59:57 +00:00
|
|
|
struct p9_fid *fid = iocb->ki_filp->private_data;
|
2005-09-09 20:04:18 +00:00
|
|
|
|
2023-03-27 02:06:37 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "fid %d count %zu offset %lld\n",
|
|
|
|
fid->fid, iov_iter_count(to), iocb->ki_pos);
|
2008-10-14 01:36:16 +00:00
|
|
|
|
2023-12-06 12:48:56 +00:00
|
|
|
if (fid->mode & P9L_DIRECT)
|
|
|
|
return netfs_unbuffered_read_iter(iocb, to);
|
2005-09-09 20:04:18 +00:00
|
|
|
|
2023-12-06 12:48:56 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "(cached)\n");
|
|
|
|
return netfs_file_read_iter(iocb, to);
|
2005-09-09 20:04:18 +00:00
|
|
|
}
|
|
|
|
|
2023-05-22 13:50:01 +00:00
|
|
|
/*
|
|
|
|
* v9fs_file_splice_read - splice-read from a file
|
|
|
|
* @in: The 9p file to read from
|
|
|
|
* @ppos: Where to find/update the file position
|
|
|
|
* @pipe: The pipe to splice into
|
|
|
|
* @len: The maximum amount of data to splice
|
|
|
|
* @flags: SPLICE_F_* flags
|
|
|
|
*/
|
|
|
|
static ssize_t v9fs_file_splice_read(struct file *in, loff_t *ppos,
|
|
|
|
struct pipe_inode_info *pipe,
|
|
|
|
size_t len, unsigned int flags)
|
|
|
|
{
|
|
|
|
struct p9_fid *fid = in->private_data;
|
|
|
|
|
|
|
|
p9_debug(P9_DEBUG_VFS, "fid %d count %zu offset %lld\n",
|
|
|
|
fid->fid, len, *ppos);
|
|
|
|
|
|
|
|
if (fid->mode & P9L_DIRECT)
|
|
|
|
return copy_splice_read(in, ppos, pipe, len, flags);
|
|
|
|
return filemap_splice_read(in, ppos, pipe, len, flags);
|
|
|
|
}
|
|
|
|
|
2011-02-28 11:33:56 +00:00
|
|
|
/**
|
2021-10-04 21:07:22 +00:00
|
|
|
* v9fs_file_write_iter - write to a file
|
|
|
|
* @iocb: The operation parameters
|
|
|
|
* @from: The data to write
|
2011-02-28 11:33:56 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
static ssize_t
|
2015-04-02 03:59:57 +00:00
|
|
|
v9fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
|
2011-02-28 11:33:56 +00:00
|
|
|
{
|
2015-04-02 03:59:57 +00:00
|
|
|
struct file *file = iocb->ki_filp;
|
2023-03-27 02:06:37 +00:00
|
|
|
struct p9_fid *fid = file->private_data;
|
2022-12-08 02:40:37 +00:00
|
|
|
|
2023-03-27 02:06:37 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "fid %d\n", fid->fid);
|
|
|
|
|
2023-12-06 12:48:56 +00:00
|
|
|
if (fid->mode & (P9L_DIRECT | P9L_NOWRITECACHE))
|
|
|
|
return netfs_unbuffered_write_iter(iocb, from);
|
2011-02-28 11:33:56 +00:00
|
|
|
|
2023-12-06 12:48:56 +00:00
|
|
|
p9_debug(P9_DEBUG_CACHE, "(cached)\n");
|
|
|
|
return netfs_file_write_iter(iocb, from);
|
2005-09-09 20:04:18 +00:00
|
|
|
}
|
|
|
|
|
2011-07-17 00:44:56 +00:00
|
|
|
static int v9fs_file_fsync(struct file *filp, loff_t start, loff_t end,
|
|
|
|
int datasync)
|
2010-02-08 21:36:48 +00:00
|
|
|
{
|
|
|
|
struct p9_fid *fid;
|
2011-07-17 00:44:56 +00:00
|
|
|
struct inode *inode = filp->f_mapping->host;
|
2010-02-08 21:36:48 +00:00
|
|
|
struct p9_wstat wstat;
|
|
|
|
int retval;
|
|
|
|
|
2017-07-07 19:20:52 +00:00
|
|
|
retval = file_write_and_wait_range(filp, start, end);
|
2011-07-17 00:44:56 +00:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
2016-01-22 20:40:57 +00:00
|
|
|
inode_lock(inode);
|
2011-11-28 18:40:46 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "filp %p datasync %x\n", filp, datasync);
|
2010-02-08 21:36:48 +00:00
|
|
|
|
|
|
|
fid = filp->private_data;
|
|
|
|
v9fs_blank_wstat(&wstat);
|
|
|
|
|
|
|
|
retval = p9_client_wstat(fid, &wstat);
|
2016-01-22 20:40:57 +00:00
|
|
|
inode_unlock(inode);
|
2011-07-17 00:44:56 +00:00
|
|
|
|
2010-02-08 21:36:48 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2011-07-17 00:44:56 +00:00
|
|
|
int v9fs_file_fsync_dotl(struct file *filp, loff_t start, loff_t end,
|
|
|
|
int datasync)
|
2010-09-23 00:19:19 +00:00
|
|
|
{
|
|
|
|
struct p9_fid *fid;
|
2011-07-17 00:44:56 +00:00
|
|
|
struct inode *inode = filp->f_mapping->host;
|
2010-09-23 00:19:19 +00:00
|
|
|
int retval;
|
|
|
|
|
2017-07-07 19:20:52 +00:00
|
|
|
retval = file_write_and_wait_range(filp, start, end);
|
2011-07-17 00:44:56 +00:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
2016-01-22 20:40:57 +00:00
|
|
|
inode_lock(inode);
|
2011-11-28 18:40:46 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "filp %p datasync %x\n", filp, datasync);
|
2010-09-23 00:19:19 +00:00
|
|
|
|
|
|
|
fid = filp->private_data;
|
|
|
|
|
2010-10-22 17:13:12 +00:00
|
|
|
retval = p9_client_fsync(fid, datasync);
|
2016-01-22 20:40:57 +00:00
|
|
|
inode_unlock(inode);
|
2011-07-17 00:44:56 +00:00
|
|
|
|
2010-09-23 00:19:19 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2011-02-28 11:33:58 +00:00
|
|
|
static int
|
2014-01-10 12:44:09 +00:00
|
|
|
v9fs_file_mmap(struct file *filp, struct vm_area_struct *vma)
|
2011-02-28 11:33:58 +00:00
|
|
|
{
|
|
|
|
int retval;
|
2022-12-08 02:40:37 +00:00
|
|
|
struct inode *inode = file_inode(filp);
|
|
|
|
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
|
2023-03-27 02:06:37 +00:00
|
|
|
|
|
|
|
p9_debug(P9_DEBUG_MMAP, "filp :%p\n", filp);
|
2014-01-10 12:44:09 +00:00
|
|
|
|
2023-03-27 01:53:10 +00:00
|
|
|
if (!(v9ses->cache & CACHE_WRITEBACK)) {
|
2023-07-19 16:22:30 +00:00
|
|
|
p9_debug(P9_DEBUG_CACHE, "(read-only mmap mode)");
|
2022-12-08 02:40:37 +00:00
|
|
|
return generic_file_readonly_mmap(filp, vma);
|
|
|
|
}
|
|
|
|
|
2014-01-10 12:44:09 +00:00
|
|
|
retval = generic_file_mmap(filp, vma);
|
|
|
|
if (!retval)
|
|
|
|
vma->vm_ops = &v9fs_mmap_file_vm_ops;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2018-07-18 02:14:35 +00:00
|
|
|
static vm_fault_t
|
2017-02-24 22:56:41 +00:00
|
|
|
v9fs_vm_page_mkwrite(struct vm_fault *vmf)
|
2011-02-28 11:33:58 +00:00
|
|
|
{
|
2023-12-06 12:48:56 +00:00
|
|
|
return netfs_page_mkwrite(vmf, NULL);
|
2011-02-28 11:33:58 +00:00
|
|
|
}
|
|
|
|
|
2014-01-10 12:44:09 +00: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,
|
2020-10-04 18:04:22 +00:00
|
|
|
.range_start = (loff_t)vma->vm_pgoff * PAGE_SIZE,
|
2014-01-10 12:44:09 +00:00
|
|
|
/* absolute end, byte at end included */
|
2020-10-04 18:04:22 +00:00
|
|
|
.range_end = (loff_t)vma->vm_pgoff * PAGE_SIZE +
|
2014-01-10 12:44:09 +00:00
|
|
|
(vma->vm_end - vma->vm_start - 1),
|
|
|
|
};
|
|
|
|
|
2019-08-20 10:03:25 +00:00
|
|
|
if (!(vma->vm_flags & VM_SHARED))
|
|
|
|
return;
|
2014-01-10 12:44:09 +00:00
|
|
|
|
|
|
|
p9_debug(P9_DEBUG_VFS, "9p VMA close, %p, flushing", vma);
|
|
|
|
|
|
|
|
inode = file_inode(vma->vm_file);
|
2021-07-14 18:47:24 +00:00
|
|
|
filemap_fdatawrite_wbc(inode->i_mapping, &wbc);
|
2014-01-10 12:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct vm_operations_struct v9fs_mmap_file_vm_ops = {
|
|
|
|
.close = v9fs_mmap_vm_close,
|
|
|
|
.fault = filemap_fault,
|
2014-04-07 22:37:19 +00:00
|
|
|
.map_pages = filemap_map_pages,
|
2014-01-10 12:44:09 +00:00
|
|
|
.page_mkwrite = v9fs_vm_page_mkwrite,
|
|
|
|
};
|
|
|
|
|
2006-03-28 09:56:42 +00:00
|
|
|
const struct file_operations v9fs_file_operations = {
|
2005-09-09 20:04:18 +00:00
|
|
|
.llseek = generic_file_llseek,
|
2015-04-02 03:59:57 +00:00
|
|
|
.read_iter = v9fs_file_read_iter,
|
|
|
|
.write_iter = v9fs_file_write_iter,
|
2005-09-09 20:04:18 +00:00
|
|
|
.open = v9fs_file_open,
|
|
|
|
.release = v9fs_dir_release,
|
|
|
|
.lock = v9fs_file_lock,
|
2008-02-07 01:25:05 +00:00
|
|
|
.mmap = generic_file_readonly_mmap,
|
2023-05-22 13:50:01 +00:00
|
|
|
.splice_read = v9fs_file_splice_read,
|
2020-12-01 15:09:37 +00:00
|
|
|
.splice_write = iter_file_splice_write,
|
2010-02-08 21:36:48 +00:00
|
|
|
.fsync = v9fs_file_fsync,
|
2005-09-09 20:04:18 +00:00
|
|
|
};
|
2010-03-25 12:41:54 +00:00
|
|
|
|
|
|
|
const struct file_operations v9fs_file_operations_dotl = {
|
|
|
|
.llseek = generic_file_llseek,
|
2015-04-02 03:59:57 +00:00
|
|
|
.read_iter = v9fs_file_read_iter,
|
|
|
|
.write_iter = v9fs_file_write_iter,
|
2010-03-25 12:41:54 +00: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 06:04:24 +00:00
|
|
|
.lock = v9fs_file_lock_dotl,
|
|
|
|
.flock = v9fs_file_flock_dotl,
|
2022-12-08 02:40:37 +00:00
|
|
|
.mmap = v9fs_file_mmap,
|
2023-05-22 13:50:01 +00:00
|
|
|
.splice_read = v9fs_file_splice_read,
|
2020-12-01 15:09:37 +00:00
|
|
|
.splice_write = iter_file_splice_write,
|
2014-01-10 12:44:09 +00:00
|
|
|
.fsync = v9fs_file_fsync_dotl,
|
|
|
|
};
|