2019-05-28 09:57:16 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-09-09 13:04:18 -07: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 09:15:34 -05:00
|
|
|
#include <linux/filelock.h>
|
2006-10-18 13:55:46 -04:00
|
|
|
#include <linux/sched.h>
|
2005-09-09 13:04:18 -07:00
|
|
|
#include <linux/file.h>
|
|
|
|
#include <linux/stat.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/list.h>
|
2009-09-22 11:34:05 -05: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 11:34:24 +05:30
|
|
|
#include <linux/utsname.h>
|
2016-12-24 11:46:01 -08:00
|
|
|
#include <linux/uaccess.h>
|
2015-04-01 20:17:51 -04:00
|
|
|
#include <linux/uio.h>
|
2015-04-02 12:02:03 -04:00
|
|
|
#include <linux/slab.h>
|
2007-07-10 17:57:28 -05:00
|
|
|
#include <net/9p/9p.h>
|
|
|
|
#include <net/9p/client.h>
|
2005-09-09 13:04:18 -07:00
|
|
|
|
|
|
|
#include "v9fs.h"
|
|
|
|
#include "v9fs_vfs.h"
|
|
|
|
#include "fid.h"
|
2009-09-23 13:00:27 -05:00
|
|
|
#include "cache.h"
|
2005-09-09 13:04:18 -07:00
|
|
|
|
2014-01-10 13:44:09 +01:00
|
|
|
static const struct vm_operations_struct v9fs_mmap_file_vm_ops;
|
2011-02-28 17:03:58 +05:30
|
|
|
|
2005-09-09 13: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 02:54:30 -08:00
|
|
|
int err;
|
2007-07-10 17:57:28 -05:00
|
|
|
struct v9fs_session_info *v9ses;
|
2023-03-27 02:06:37 +00:00
|
|
|
struct p9_fid *fid;
|
2007-07-10 17:57:28 -05:00
|
|
|
int omode;
|
2005-09-09 13:04:18 -07:00
|
|
|
|
2011-11-28 10:40:46 -08:00
|
|
|
p9_debug(P9_DEBUG_VFS, "inode: %p file: %p\n", inode, file);
|
2007-07-10 17:57:28 -05:00
|
|
|
v9ses = v9fs_inode2v9ses(inode);
|
2010-06-22 19:47:50 +05:30
|
|
|
if (v9fs_proto_dotl(v9ses))
|
2011-08-03 19:55:32 +05:30
|
|
|
omode = v9fs_open_to_dotl_flags(file->f_flags);
|
2010-06-22 19:47:50 +05:30
|
|
|
else
|
|
|
|
omode = v9fs_uflags2omode(file->f_flags,
|
|
|
|
v9fs_proto_dotu(v9ses));
|
2007-07-10 17:57:28 -05:00
|
|
|
fid = file->private_data;
|
|
|
|
if (!fid) {
|
2016-06-29 10:54:23 +02:00
|
|
|
fid = v9fs_fid_clone(file_dentry(file));
|
2007-07-10 17:57:28 -05: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 13:01:27 -05:00
|
|
|
if (err < 0) {
|
2022-06-12 13:42:32 +09:00
|
|
|
p9_fid_put(fid);
|
2007-07-10 17:57:28 -05:00
|
|
|
return err;
|
|
|
|
}
|
2010-06-22 19:47:50 +05:30
|
|
|
if ((file->f_flags & O_APPEND) &&
|
|
|
|
(!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)))
|
2008-06-24 17:39:39 -05:00
|
|
|
generic_file_llseek(file, 0, SEEK_END);
|
2022-06-12 16:05:39 +09:00
|
|
|
|
|
|
|
file->private_data = fid;
|
2006-03-02 02:54:30 -08:00
|
|
|
}
|
2005-09-09 13:04:18 -07: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 16:05:39 +09:00
|
|
|
v9fs_open_fid_add(inode, &fid);
|
2006-03-02 02:54:30 -08:00
|
|
|
return 0;
|
2005-09-09 13:04:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* v9fs_file_lock - lock a file (or directory)
|
2008-03-05 07:08:09 -06:00
|
|
|
* @filp: file to be locked
|
|
|
|
* @cmd: lock command
|
|
|
|
* @fl: file lock structure
|
2005-09-09 13:04:18 -07:00
|
|
|
*
|
2008-03-05 07:08:09 -06:00
|
|
|
* Bugs: this looks like a local only lock, we should extend into 9P
|
2005-09-09 13:04:18 -07:00
|
|
|
* by using open exclusive
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl)
|
|
|
|
{
|
2013-01-23 17:07:38 -05:00
|
|
|
struct inode *inode = file_inode(filp);
|
2005-09-09 13:04:18 -07:00
|
|
|
|
2011-11-28 10:40:46 -08:00
|
|
|
p9_debug(P9_DEBUG_VFS, "filp: %p lock: %p\n", filp, fl);
|
2005-09-09 13:04:18 -07:00
|
|
|
|
2024-01-31 18:02:15 -05: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 01:02:14 -08:00
|
|
|
filemap_write_and_wait(inode->i_mapping);
|
2007-02-10 01:45:39 -08:00
|
|
|
invalidate_mapping_pages(&inode->i_data, 0, -1);
|
2005-09-09 13:04:18 -07:00
|
|
|
}
|
|
|
|
|
2021-11-09 11:43:43 +00:00
|
|
|
return 0;
|
2005-09-09 13:04:18 -07: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 11:34:24 +05:30
|
|
|
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 12:56:07 +01: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 11:34:24 +05:30
|
|
|
int res = 0;
|
2018-09-05 16:44:12 +09: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 11:34:24 +05:30
|
|
|
|
|
|
|
fid = filp->private_data;
|
|
|
|
BUG_ON(fid == NULL);
|
|
|
|
|
2024-01-31 18:02:15 -05: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 11:34:24 +05:30
|
|
|
|
2015-10-22 13:38:14 -04: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 11:34:24 +05:30
|
|
|
if (res < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* convert posix lock to p9 tlock args */
|
|
|
|
memset(&flock, 0, sizeof(flock));
|
2011-08-21 00:21:18 +05:30
|
|
|
/* map the lock type */
|
2024-01-31 18:02:15 -05:00
|
|
|
switch (fl->c.flc_type) {
|
2011-08-21 00:21:18 +05:30
|
|
|
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 11:34:24 +05:30
|
|
|
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 18:02:15 -05:00
|
|
|
flock.proc_id = fl->c.flc_pid;
|
2013-08-21 18:24:47 +01: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 11:34:24 +05:30
|
|
|
if (IS_SETLKW(cmd))
|
|
|
|
flock.flags = P9_LOCK_FLAGS_BLOCK;
|
|
|
|
|
2018-09-05 16:44:12 +09: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 11:34:24 +05:30
|
|
|
/*
|
|
|
|
* 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 15:00:18 +02: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 11:34:24 +05:30
|
|
|
|
|
|
|
if (status != P9_LOCK_BLOCKED)
|
|
|
|
break;
|
|
|
|
if (status == P9_LOCK_BLOCKED && !IS_SETLKW(cmd))
|
|
|
|
break;
|
2018-09-05 16:44:12 +09:00
|
|
|
if (schedule_timeout_interruptible(v9ses->session_lock_timeout)
|
|
|
|
!= 0)
|
2012-01-03 15:27:50 -06:00
|
|
|
break;
|
2018-09-08 01:18:43 +09: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 11:34:24 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 15:00:19 +02:00
|
|
|
default:
|
|
|
|
WARN_ONCE(1, "unknown lock status code: %d\n", status);
|
2020-08-23 17:36:59 -05: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 11:34:24 +05:30
|
|
|
case P9_LOCK_ERROR:
|
|
|
|
case P9_LOCK_GRACE:
|
|
|
|
res = -ENOLCK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-12-29 15:00:18 +02: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 11:34:24 +05:30
|
|
|
/*
|
|
|
|
* incase server returned error for lock request, revert
|
|
|
|
* it locally
|
|
|
|
*/
|
2024-01-31 18:02:15 -05:00
|
|
|
if (res < 0 && fl->c.flc_type != F_UNLCK) {
|
|
|
|
unsigned char type = fl->c.flc_type;
|
2024-01-31 18:01:46 -05:00
|
|
|
|
2024-01-31 18:02:15 -05:00
|
|
|
fl->c.flc_type = F_UNLCK;
|
2015-11-05 18:44:21 -08:00
|
|
|
/* Even if this fails we want to return the remote error */
|
2015-11-05 23:10:54 -08:00
|
|
|
locks_lock_file_wait(filp, fl);
|
2024-01-31 18:02:15 -05: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 11:34:24 +05:30
|
|
|
}
|
2018-09-08 01:18:43 +09: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 11:34:24 +05:30
|
|
|
out:
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-09-27 12:22:13 +05:30
|
|
|
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 18:02:15 -05:00
|
|
|
if (fl->c.flc_type != F_UNLCK)
|
2010-09-27 12:22:13 +05:30
|
|
|
return res;
|
|
|
|
|
|
|
|
/* convert posix lock to p9 tgetlock args */
|
|
|
|
memset(&glock, 0, sizeof(glock));
|
2011-08-21 00:21:18 +05:30
|
|
|
glock.type = P9_LOCK_TYPE_UNLCK;
|
2010-09-27 12:22:13 +05:30
|
|
|
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 18:02:15 -05:00
|
|
|
glock.proc_id = fl->c.flc_pid;
|
2013-08-21 18:24:47 +01:00
|
|
|
glock.client_id = fid->clnt->name;
|
2010-09-27 12:22:13 +05:30
|
|
|
|
|
|
|
res = p9_client_getlock_dotl(fid, &glock);
|
|
|
|
if (res < 0)
|
2018-09-08 01:18:43 +09:00
|
|
|
goto out;
|
2011-08-21 00:21:18 +05:30
|
|
|
/* map 9p lock type to os lock type */
|
|
|
|
switch (glock.type) {
|
|
|
|
case P9_LOCK_TYPE_RDLCK:
|
2024-01-31 18:02:15 -05:00
|
|
|
fl->c.flc_type = F_RDLCK;
|
2011-08-21 00:21:18 +05:30
|
|
|
break;
|
|
|
|
case P9_LOCK_TYPE_WRLCK:
|
2024-01-31 18:02:15 -05:00
|
|
|
fl->c.flc_type = F_WRLCK;
|
2011-08-21 00:21:18 +05:30
|
|
|
break;
|
|
|
|
case P9_LOCK_TYPE_UNLCK:
|
2024-01-31 18:02:15 -05:00
|
|
|
fl->c.flc_type = F_UNLCK;
|
2011-08-21 00:21:18 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (glock.type != P9_LOCK_TYPE_UNLCK) {
|
2010-09-27 12:22:13 +05:30
|
|
|
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 18:02:15 -05:00
|
|
|
fl->c.flc_pid = -glock.proc_id;
|
2011-08-21 00:21:18 +05:30
|
|
|
}
|
2018-09-08 01:18:43 +09:00
|
|
|
out:
|
|
|
|
if (glock.client_id != fid->clnt->name)
|
|
|
|
kfree(glock.client_id);
|
2010-09-27 12:22:13 +05:30
|
|
|
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 11:34:24 +05:30
|
|
|
/**
|
|
|
|
* 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 17:07:38 -05: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 11:34:24 +05:30
|
|
|
int ret = -ENOLCK;
|
|
|
|
|
2014-08-19 20:17:38 -04: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 11:34:24 +05:30
|
|
|
|
2024-01-31 18:02:15 -05: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 11:34:24 +05:30
|
|
|
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 12:22:13 +05:30
|
|
|
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 11:34:24 +05:30
|
|
|
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 17:07:38 -05: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 11:34:24 +05:30
|
|
|
int ret = -ENOLCK;
|
|
|
|
|
2014-08-19 20:17:38 -04: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 11:34:24 +05:30
|
|
|
|
2024-01-31 18:02:15 -05: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 11:34:24 +05:30
|
|
|
goto out_err;
|
|
|
|
|
2024-01-31 18:02:15 -05: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 11:34:24 +05:30
|
|
|
filemap_write_and_wait(inode->i_mapping);
|
|
|
|
invalidate_mapping_pages(&inode->i_data, 0, -1);
|
|
|
|
}
|
|
|
|
/* Convert flock to posix lock */
|
2024-01-31 18:02:15 -05: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 11:34:24 +05:30
|
|
|
|
|
|
|
if (IS_SETLK(cmd) | IS_SETLKW(cmd))
|
|
|
|
ret = v9fs_file_do_lock(filp, cmd, fl);
|
|
|
|
else
|
|
|
|
ret = -EINVAL;
|
|
|
|
out_err:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-10-13 20:36:16 -05:00
|
|
|
/**
|
2021-10-04 22:07:22 +01:00
|
|
|
* v9fs_file_read_iter - read from a file
|
|
|
|
* @iocb: The operation parameters
|
|
|
|
* @to: The buffer to read into
|
2008-10-13 20:36:16 -05:00
|
|
|
*
|
|
|
|
*/
|
2005-09-09 13:04:18 -07:00
|
|
|
static ssize_t
|
2015-04-01 23:59:57 -04:00
|
|
|
v9fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
|
2005-09-09 13:04:18 -07:00
|
|
|
{
|
2015-04-01 23:59:57 -04:00
|
|
|
struct p9_fid *fid = iocb->ki_filp->private_data;
|
2005-09-09 13:04:18 -07: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-13 20:36:16 -05:00
|
|
|
|
2023-12-06 12:48:56 +00:00
|
|
|
if (fid->mode & P9L_DIRECT)
|
|
|
|
return netfs_unbuffered_read_iter(iocb, to);
|
2005-09-09 13:04:18 -07: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 13:04:18 -07:00
|
|
|
}
|
|
|
|
|
2023-05-22 14:50:01 +01: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 17:03:56 +05:30
|
|
|
/**
|
2021-10-04 22:07:22 +01:00
|
|
|
* v9fs_file_write_iter - write to a file
|
|
|
|
* @iocb: The operation parameters
|
|
|
|
* @from: The data to write
|
2011-02-28 17:03:56 +05:30
|
|
|
*
|
|
|
|
*/
|
|
|
|
static ssize_t
|
2015-04-01 23:59:57 -04:00
|
|
|
v9fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
|
2011-02-28 17:03:56 +05:30
|
|
|
{
|
2015-04-01 23:59:57 -04: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 17:03:56 +05:30
|
|
|
|
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 13:04:18 -07:00
|
|
|
}
|
|
|
|
|
2011-07-16 20:44:56 -04:00
|
|
|
static int v9fs_file_fsync(struct file *filp, loff_t start, loff_t end,
|
|
|
|
int datasync)
|
2010-02-08 15:36:48 -06:00
|
|
|
{
|
|
|
|
struct p9_fid *fid;
|
2011-07-16 20:44:56 -04:00
|
|
|
struct inode *inode = filp->f_mapping->host;
|
2010-02-08 15:36:48 -06:00
|
|
|
struct p9_wstat wstat;
|
|
|
|
int retval;
|
|
|
|
|
2017-07-07 15:20:52 -04:00
|
|
|
retval = file_write_and_wait_range(filp, start, end);
|
2011-07-16 20:44:56 -04:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
2016-01-22 15:40:57 -05:00
|
|
|
inode_lock(inode);
|
2011-11-28 10:40:46 -08:00
|
|
|
p9_debug(P9_DEBUG_VFS, "filp %p datasync %x\n", filp, datasync);
|
2010-02-08 15:36:48 -06:00
|
|
|
|
|
|
|
fid = filp->private_data;
|
|
|
|
v9fs_blank_wstat(&wstat);
|
|
|
|
|
|
|
|
retval = p9_client_wstat(fid, &wstat);
|
2016-01-22 15:40:57 -05:00
|
|
|
inode_unlock(inode);
|
2011-07-16 20:44:56 -04:00
|
|
|
|
2010-02-08 15:36:48 -06:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2011-07-16 20:44:56 -04:00
|
|
|
int v9fs_file_fsync_dotl(struct file *filp, loff_t start, loff_t end,
|
|
|
|
int datasync)
|
2010-09-22 17:19:19 -07:00
|
|
|
{
|
|
|
|
struct p9_fid *fid;
|
2011-07-16 20:44:56 -04:00
|
|
|
struct inode *inode = filp->f_mapping->host;
|
2010-09-22 17:19:19 -07:00
|
|
|
int retval;
|
|
|
|
|
2017-07-07 15:20:52 -04:00
|
|
|
retval = file_write_and_wait_range(filp, start, end);
|
2011-07-16 20:44:56 -04:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
2016-01-22 15:40:57 -05:00
|
|
|
inode_lock(inode);
|
2011-11-28 10:40:46 -08:00
|
|
|
p9_debug(P9_DEBUG_VFS, "filp %p datasync %x\n", filp, datasync);
|
2010-09-22 17:19:19 -07:00
|
|
|
|
|
|
|
fid = filp->private_data;
|
|
|
|
|
2010-10-22 10:13:12 -07:00
|
|
|
retval = p9_client_fsync(fid, datasync);
|
2016-01-22 15:40:57 -05:00
|
|
|
inode_unlock(inode);
|
2011-07-16 20:44:56 -04:00
|
|
|
|
2010-09-22 17:19:19 -07:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2011-02-28 17:03:58 +05:30
|
|
|
static int
|
fs: convert most other generic_file_*mmap() users to .mmap_prepare()
Update nearly all generic_file_mmap() and generic_file_readonly_mmap()
callers to use generic_file_mmap_prepare() and
generic_file_readonly_mmap_prepare() respectively.
We update blkdev, 9p, afs, erofs, ext2, nfs, ntfs3, smb, ubifs and vboxsf
file systems this way.
Remaining users we cannot yet update are ecryptfs, fuse and cramfs. The
former two are nested file systems that must support any underlying file
ssytem, and cramfs inserts a mixed mapping which currently requires a VMA.
Once all file systems have been converted to mmap_prepare(), we can then
update nested file systems.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Link: https://lore.kernel.org/08db85970d89b17a995d2cffae96fb4cc462377f.1750099179.git.lorenzo.stoakes@oracle.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
2025-06-16 20:33:28 +01:00
|
|
|
v9fs_file_mmap_prepare(struct vm_area_desc *desc)
|
2011-02-28 17:03:58 +05:30
|
|
|
{
|
|
|
|
int retval;
|
fs: convert most other generic_file_*mmap() users to .mmap_prepare()
Update nearly all generic_file_mmap() and generic_file_readonly_mmap()
callers to use generic_file_mmap_prepare() and
generic_file_readonly_mmap_prepare() respectively.
We update blkdev, 9p, afs, erofs, ext2, nfs, ntfs3, smb, ubifs and vboxsf
file systems this way.
Remaining users we cannot yet update are ecryptfs, fuse and cramfs. The
former two are nested file systems that must support any underlying file
ssytem, and cramfs inserts a mixed mapping which currently requires a VMA.
Once all file systems have been converted to mmap_prepare(), we can then
update nested file systems.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Link: https://lore.kernel.org/08db85970d89b17a995d2cffae96fb4cc462377f.1750099179.git.lorenzo.stoakes@oracle.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
2025-06-16 20:33:28 +01:00
|
|
|
struct file *filp = desc->file;
|
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 13:44:09 +01: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)");
|
fs: convert most other generic_file_*mmap() users to .mmap_prepare()
Update nearly all generic_file_mmap() and generic_file_readonly_mmap()
callers to use generic_file_mmap_prepare() and
generic_file_readonly_mmap_prepare() respectively.
We update blkdev, 9p, afs, erofs, ext2, nfs, ntfs3, smb, ubifs and vboxsf
file systems this way.
Remaining users we cannot yet update are ecryptfs, fuse and cramfs. The
former two are nested file systems that must support any underlying file
ssytem, and cramfs inserts a mixed mapping which currently requires a VMA.
Once all file systems have been converted to mmap_prepare(), we can then
update nested file systems.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Link: https://lore.kernel.org/08db85970d89b17a995d2cffae96fb4cc462377f.1750099179.git.lorenzo.stoakes@oracle.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
2025-06-16 20:33:28 +01:00
|
|
|
return generic_file_readonly_mmap_prepare(desc);
|
2022-12-08 02:40:37 +00:00
|
|
|
}
|
|
|
|
|
fs: convert most other generic_file_*mmap() users to .mmap_prepare()
Update nearly all generic_file_mmap() and generic_file_readonly_mmap()
callers to use generic_file_mmap_prepare() and
generic_file_readonly_mmap_prepare() respectively.
We update blkdev, 9p, afs, erofs, ext2, nfs, ntfs3, smb, ubifs and vboxsf
file systems this way.
Remaining users we cannot yet update are ecryptfs, fuse and cramfs. The
former two are nested file systems that must support any underlying file
ssytem, and cramfs inserts a mixed mapping which currently requires a VMA.
Once all file systems have been converted to mmap_prepare(), we can then
update nested file systems.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Link: https://lore.kernel.org/08db85970d89b17a995d2cffae96fb4cc462377f.1750099179.git.lorenzo.stoakes@oracle.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
2025-06-16 20:33:28 +01:00
|
|
|
retval = generic_file_mmap_prepare(desc);
|
2014-01-10 13:44:09 +01:00
|
|
|
if (!retval)
|
fs: convert most other generic_file_*mmap() users to .mmap_prepare()
Update nearly all generic_file_mmap() and generic_file_readonly_mmap()
callers to use generic_file_mmap_prepare() and
generic_file_readonly_mmap_prepare() respectively.
We update blkdev, 9p, afs, erofs, ext2, nfs, ntfs3, smb, ubifs and vboxsf
file systems this way.
Remaining users we cannot yet update are ecryptfs, fuse and cramfs. The
former two are nested file systems that must support any underlying file
ssytem, and cramfs inserts a mixed mapping which currently requires a VMA.
Once all file systems have been converted to mmap_prepare(), we can then
update nested file systems.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Link: https://lore.kernel.org/08db85970d89b17a995d2cffae96fb4cc462377f.1750099179.git.lorenzo.stoakes@oracle.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
2025-06-16 20:33:28 +01:00
|
|
|
desc->vm_ops = &v9fs_mmap_file_vm_ops;
|
2014-01-10 13:44:09 +01:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2018-07-17 19:14:35 -07:00
|
|
|
static vm_fault_t
|
2017-02-24 14:56:41 -08:00
|
|
|
v9fs_vm_page_mkwrite(struct vm_fault *vmf)
|
2011-02-28 17:03:58 +05:30
|
|
|
{
|
2023-12-06 12:48:56 +00:00
|
|
|
return netfs_page_mkwrite(vmf, NULL);
|
2011-02-28 17:03:58 +05:30
|
|
|
}
|
|
|
|
|
2014-01-10 13:44:09 +01: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 19:04:22 +01:00
|
|
|
.range_start = (loff_t)vma->vm_pgoff * PAGE_SIZE,
|
2014-01-10 13:44:09 +01:00
|
|
|
/* absolute end, byte at end included */
|
2020-10-04 19:04:22 +01:00
|
|
|
.range_end = (loff_t)vma->vm_pgoff * PAGE_SIZE +
|
2014-01-10 13:44:09 +01:00
|
|
|
(vma->vm_end - vma->vm_start - 1),
|
|
|
|
};
|
|
|
|
|
2019-08-20 18:03:25 +08:00
|
|
|
if (!(vma->vm_flags & VM_SHARED))
|
|
|
|
return;
|
2014-01-10 13:44:09 +01:00
|
|
|
|
|
|
|
p9_debug(P9_DEBUG_VFS, "9p VMA close, %p, flushing", vma);
|
|
|
|
|
|
|
|
inode = file_inode(vma->vm_file);
|
2021-07-14 14:47:24 -04:00
|
|
|
filemap_fdatawrite_wbc(inode->i_mapping, &wbc);
|
2014-01-10 13:44:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct vm_operations_struct v9fs_mmap_file_vm_ops = {
|
|
|
|
.close = v9fs_mmap_vm_close,
|
|
|
|
.fault = filemap_fault,
|
2014-04-07 15:37:19 -07:00
|
|
|
.map_pages = filemap_map_pages,
|
2014-01-10 13:44:09 +01:00
|
|
|
.page_mkwrite = v9fs_vm_page_mkwrite,
|
|
|
|
};
|
|
|
|
|
2006-03-28 01:56:42 -08:00
|
|
|
const struct file_operations v9fs_file_operations = {
|
2005-09-09 13:04:18 -07:00
|
|
|
.llseek = generic_file_llseek,
|
2015-04-01 23:59:57 -04:00
|
|
|
.read_iter = v9fs_file_read_iter,
|
|
|
|
.write_iter = v9fs_file_write_iter,
|
2005-09-09 13:04:18 -07:00
|
|
|
.open = v9fs_file_open,
|
|
|
|
.release = v9fs_dir_release,
|
|
|
|
.lock = v9fs_file_lock,
|
fs: convert simple use of generic_file_*_mmap() to .mmap_prepare()
Since commit c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file
callback"), the f_op->mmap() hook has been deprecated in favour of
f_op->mmap_prepare().
We have provided generic .mmap_prepare() equivalents, so update all file
systems that specify these directly in their file_operations structures.
This updates 9p, adfs, affs, bfs, fat, hfs, hfsplus, hostfs, hpfs, jffs2,
jfs, minix, omfs, ramfs and ufs file systems directly.
It updates generic_ro_fops which impacts qnx4, cramfs, befs, squashfs,
frebxfs, qnx6, efs, romfs, erofs and isofs file systems.
There are remaining file systems which use generic hooks in a less direct
way which we address in a subsequent commit.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Link: https://lore.kernel.org/c7dc90e44a9e75e750939ea369290d6e441a18e6.1750099179.git.lorenzo.stoakes@oracle.com
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2025-06-16 20:33:27 +01:00
|
|
|
.mmap_prepare = generic_file_readonly_mmap_prepare,
|
2023-05-22 14:50:01 +01:00
|
|
|
.splice_read = v9fs_file_splice_read,
|
2020-12-01 16:09:37 +01:00
|
|
|
.splice_write = iter_file_splice_write,
|
2010-02-08 15:36:48 -06:00
|
|
|
.fsync = v9fs_file_fsync,
|
2024-03-19 12:34:45 -04:00
|
|
|
.setlease = simple_nosetlease,
|
2005-09-09 13:04:18 -07:00
|
|
|
};
|
2010-03-25 12:41:54 +00:00
|
|
|
|
|
|
|
const struct file_operations v9fs_file_operations_dotl = {
|
|
|
|
.llseek = generic_file_llseek,
|
2015-04-01 23:59:57 -04: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 11:34:24 +05:30
|
|
|
.lock = v9fs_file_lock_dotl,
|
|
|
|
.flock = v9fs_file_flock_dotl,
|
fs: convert most other generic_file_*mmap() users to .mmap_prepare()
Update nearly all generic_file_mmap() and generic_file_readonly_mmap()
callers to use generic_file_mmap_prepare() and
generic_file_readonly_mmap_prepare() respectively.
We update blkdev, 9p, afs, erofs, ext2, nfs, ntfs3, smb, ubifs and vboxsf
file systems this way.
Remaining users we cannot yet update are ecryptfs, fuse and cramfs. The
former two are nested file systems that must support any underlying file
ssytem, and cramfs inserts a mixed mapping which currently requires a VMA.
Once all file systems have been converted to mmap_prepare(), we can then
update nested file systems.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Link: https://lore.kernel.org/08db85970d89b17a995d2cffae96fb4cc462377f.1750099179.git.lorenzo.stoakes@oracle.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
2025-06-16 20:33:28 +01:00
|
|
|
.mmap_prepare = v9fs_file_mmap_prepare,
|
2023-05-22 14:50:01 +01:00
|
|
|
.splice_read = v9fs_file_splice_read,
|
2020-12-01 16:09:37 +01:00
|
|
|
.splice_write = iter_file_splice_write,
|
2014-01-10 13:44:09 +01:00
|
|
|
.fsync = v9fs_file_fsync_dotl,
|
2024-03-19 12:34:45 -04:00
|
|
|
.setlease = simple_nosetlease,
|
2014-01-10 13:44:09 +01:00
|
|
|
};
|