License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-09-26 17:58:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 Anna Schumaker <Anna.Schumaker@Netapp.com>
|
|
|
|
*/
|
|
|
|
#include <linux/fs.h>
|
2019-06-04 20:14:30 +00:00
|
|
|
#include <linux/sunrpc/addr.h>
|
2014-09-26 17:58:48 +00:00
|
|
|
#include <linux/sunrpc/sched.h>
|
|
|
|
#include <linux/nfs.h>
|
|
|
|
#include <linux/nfs3.h>
|
|
|
|
#include <linux/nfs4.h>
|
|
|
|
#include <linux/nfs_xdr.h>
|
|
|
|
#include <linux/nfs_fs.h>
|
|
|
|
#include "nfs4_fs.h"
|
|
|
|
#include "nfs42.h"
|
2015-06-23 11:51:56 +00:00
|
|
|
#include "iostat.h"
|
|
|
|
#include "pnfs.h"
|
2017-01-09 20:14:33 +00:00
|
|
|
#include "nfs4session.h"
|
2015-06-23 11:51:56 +00:00
|
|
|
#include "internal.h"
|
2019-06-04 20:14:30 +00:00
|
|
|
#include "delegation.h"
|
2020-08-04 15:02:44 +00:00
|
|
|
#include "nfs4trace.h"
|
2015-06-23 11:51:56 +00:00
|
|
|
|
2015-11-16 19:51:07 +00:00
|
|
|
#define NFSDBG_FACILITY NFSDBG_PROC
|
2018-07-09 19:13:34 +00:00
|
|
|
static int nfs42_do_offload_cancel_async(struct file *dst, nfs4_stateid *std);
|
2014-09-26 17:58:48 +00:00
|
|
|
|
2019-06-04 20:14:30 +00:00
|
|
|
static void nfs42_set_netaddr(struct file *filep, struct nfs42_netaddr *naddr)
|
|
|
|
{
|
|
|
|
struct nfs_client *clp = (NFS_SERVER(file_inode(filep)))->nfs_client;
|
|
|
|
unsigned short port = 2049;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
naddr->netid_len = scnprintf(naddr->netid,
|
|
|
|
sizeof(naddr->netid), "%s",
|
|
|
|
rpc_peeraddr2str(clp->cl_rpcclient,
|
|
|
|
RPC_DISPLAY_NETID));
|
|
|
|
naddr->addr_len = scnprintf(naddr->addr,
|
|
|
|
sizeof(naddr->addr),
|
|
|
|
"%s.%u.%u",
|
|
|
|
rpc_peeraddr2str(clp->cl_rpcclient,
|
|
|
|
RPC_DISPLAY_ADDR),
|
|
|
|
port >> 8, port & 255);
|
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
|
|
|
|
2014-11-25 18:18:15 +00:00
|
|
|
static int _nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep,
|
2016-02-17 14:48:28 +00:00
|
|
|
struct nfs_lock_context *lock, loff_t offset, loff_t len)
|
2014-11-25 18:18:15 +00:00
|
|
|
{
|
|
|
|
struct inode *inode = file_inode(filep);
|
2015-03-16 18:06:23 +00:00
|
|
|
struct nfs_server *server = NFS_SERVER(inode);
|
2021-12-27 19:40:52 +00:00
|
|
|
u32 bitmask[NFS_BITMASK_SZ];
|
2014-11-25 18:18:15 +00:00
|
|
|
struct nfs42_falloc_args args = {
|
|
|
|
.falloc_fh = NFS_FH(inode),
|
|
|
|
.falloc_offset = offset,
|
|
|
|
.falloc_length = len,
|
2021-03-28 22:12:03 +00:00
|
|
|
.falloc_bitmask = bitmask,
|
2015-03-16 18:06:23 +00:00
|
|
|
};
|
|
|
|
struct nfs42_falloc_res res = {
|
|
|
|
.falloc_server = server,
|
2014-11-25 18:18:15 +00:00
|
|
|
};
|
|
|
|
int status;
|
|
|
|
|
|
|
|
msg->rpc_argp = &args;
|
|
|
|
msg->rpc_resp = &res;
|
|
|
|
|
2016-02-17 14:48:28 +00:00
|
|
|
status = nfs4_set_rw_stateid(&args.falloc_stateid, lock->open_context,
|
|
|
|
lock, FMODE_WRITE);
|
2019-12-18 21:50:42 +00:00
|
|
|
if (status) {
|
|
|
|
if (status == -EAGAIN)
|
|
|
|
status = -NFS4ERR_BAD_STATEID;
|
2014-11-25 18:18:15 +00:00
|
|
|
return status;
|
2019-12-18 21:50:42 +00:00
|
|
|
}
|
2014-11-25 18:18:15 +00:00
|
|
|
|
2021-12-27 19:40:52 +00:00
|
|
|
nfs4_bitmask_set(bitmask, server->cache_consistency_bitmask, inode,
|
|
|
|
NFS_INO_INVALID_BLOCKS);
|
2021-03-28 22:12:03 +00:00
|
|
|
|
2015-03-16 18:06:23 +00:00
|
|
|
res.falloc_fattr = nfs_alloc_fattr();
|
|
|
|
if (!res.falloc_fattr)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
status = nfs4_call_sync(server->client, server, msg,
|
|
|
|
&args.seq_args, &res.seq_res, 0);
|
2022-09-07 20:34:21 +00:00
|
|
|
if (status == 0) {
|
|
|
|
if (nfs_should_remove_suid(inode)) {
|
|
|
|
spin_lock(&inode->i_lock);
|
2023-09-19 06:30:20 +00:00
|
|
|
nfs_set_cache_invalid(inode,
|
|
|
|
NFS_INO_REVAL_FORCED | NFS_INO_INVALID_MODE);
|
2022-09-07 20:34:21 +00:00
|
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
}
|
2021-03-28 22:12:03 +00:00
|
|
|
status = nfs_post_op_update_inode_force_wcc(inode,
|
|
|
|
res.falloc_fattr);
|
2022-09-07 20:34:21 +00:00
|
|
|
}
|
2021-11-04 14:57:09 +00:00
|
|
|
if (msg->rpc_proc == &nfs4_procedures[NFSPROC4_CLNT_ALLOCATE])
|
|
|
|
trace_nfs4_fallocate(inode, &args, status);
|
|
|
|
else
|
|
|
|
trace_nfs4_deallocate(inode, &args, status);
|
2015-03-16 18:06:23 +00:00
|
|
|
kfree(res.falloc_fattr);
|
|
|
|
return status;
|
2014-11-25 18:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep,
|
|
|
|
loff_t offset, loff_t len)
|
|
|
|
{
|
2021-03-28 22:17:14 +00:00
|
|
|
struct inode *inode = file_inode(filep);
|
|
|
|
struct nfs_server *server = NFS_SERVER(inode);
|
2014-11-25 18:18:15 +00:00
|
|
|
struct nfs4_exception exception = { };
|
2016-02-17 14:48:28 +00:00
|
|
|
struct nfs_lock_context *lock;
|
2014-11-25 18:18:15 +00:00
|
|
|
int err;
|
|
|
|
|
2016-02-17 14:48:28 +00:00
|
|
|
lock = nfs_get_lock_context(nfs_file_open_context(filep));
|
|
|
|
if (IS_ERR(lock))
|
|
|
|
return PTR_ERR(lock);
|
|
|
|
|
2021-03-28 22:17:14 +00:00
|
|
|
exception.inode = inode;
|
2016-02-17 14:48:28 +00:00
|
|
|
exception.state = lock->open_context->state;
|
|
|
|
|
2021-03-28 22:17:14 +00:00
|
|
|
err = nfs_sync_inode(inode);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
2014-11-25 18:18:15 +00:00
|
|
|
do {
|
2016-02-17 14:48:28 +00:00
|
|
|
err = _nfs42_proc_fallocate(msg, filep, lock, offset, len);
|
|
|
|
if (err == -ENOTSUPP) {
|
|
|
|
err = -EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
}
|
2014-11-25 18:18:15 +00:00
|
|
|
err = nfs4_handle_exception(server, err, &exception);
|
|
|
|
} while (exception.retry);
|
2021-03-28 22:17:14 +00:00
|
|
|
out:
|
2016-02-17 14:48:28 +00:00
|
|
|
nfs_put_lock_context(lock);
|
2014-11-25 18:18:15 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int nfs42_proc_allocate(struct file *filep, loff_t offset, loff_t len)
|
|
|
|
{
|
|
|
|
struct rpc_message msg = {
|
|
|
|
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ALLOCATE],
|
|
|
|
};
|
|
|
|
struct inode *inode = file_inode(filep);
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (!nfs_server_capable(inode, NFS_CAP_ALLOCATE))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2016-01-22 20:40:57 +00:00
|
|
|
inode_lock(inode);
|
2015-03-16 18:06:24 +00:00
|
|
|
|
2014-11-25 18:18:15 +00:00
|
|
|
err = nfs42_proc_fallocate(&msg, filep, offset, len);
|
|
|
|
if (err == -EOPNOTSUPP)
|
|
|
|
NFS_SERVER(inode)->caps &= ~NFS_CAP_ALLOCATE;
|
2015-03-16 18:06:24 +00:00
|
|
|
|
2016-01-22 20:40:57 +00:00
|
|
|
inode_unlock(inode);
|
2014-11-25 18:18:15 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-11-25 18:18:16 +00:00
|
|
|
int nfs42_proc_deallocate(struct file *filep, loff_t offset, loff_t len)
|
|
|
|
{
|
|
|
|
struct rpc_message msg = {
|
|
|
|
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DEALLOCATE],
|
|
|
|
};
|
|
|
|
struct inode *inode = file_inode(filep);
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (!nfs_server_capable(inode, NFS_CAP_DEALLOCATE))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2016-01-22 20:40:57 +00:00
|
|
|
inode_lock(inode);
|
2015-03-16 18:06:24 +00:00
|
|
|
|
2014-11-25 18:18:16 +00:00
|
|
|
err = nfs42_proc_fallocate(&msg, filep, offset, len);
|
2015-03-16 18:06:23 +00:00
|
|
|
if (err == 0)
|
|
|
|
truncate_pagecache_range(inode, offset, (offset + len) -1);
|
2014-11-25 18:18:16 +00:00
|
|
|
if (err == -EOPNOTSUPP)
|
|
|
|
NFS_SERVER(inode)->caps &= ~NFS_CAP_DEALLOCATE;
|
2021-03-28 22:17:14 +00:00
|
|
|
|
2016-01-22 20:40:57 +00:00
|
|
|
inode_unlock(inode);
|
2014-11-25 18:18:16 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-07-09 19:13:31 +00:00
|
|
|
static int handle_async_copy(struct nfs42_copy_res *res,
|
2019-06-14 18:38:40 +00:00
|
|
|
struct nfs_server *dst_server,
|
|
|
|
struct nfs_server *src_server,
|
2018-07-09 19:13:31 +00:00
|
|
|
struct file *src,
|
|
|
|
struct file *dst,
|
2019-06-14 18:38:40 +00:00
|
|
|
nfs4_stateid *src_stateid,
|
|
|
|
bool *restart)
|
2018-07-09 19:13:31 +00:00
|
|
|
{
|
2022-03-24 07:15:23 +00:00
|
|
|
struct nfs4_copy_state *copy, *tmp_copy = NULL, *iter;
|
2018-07-09 19:13:31 +00:00
|
|
|
int status = NFS4_OK;
|
2019-06-14 18:38:40 +00:00
|
|
|
struct nfs_open_context *dst_ctx = nfs_file_open_context(dst);
|
|
|
|
struct nfs_open_context *src_ctx = nfs_file_open_context(src);
|
2018-07-09 19:13:32 +00:00
|
|
|
|
2022-01-29 19:19:15 +00:00
|
|
|
copy = kzalloc(sizeof(struct nfs4_copy_state), GFP_KERNEL);
|
2018-11-21 16:24:22 +00:00
|
|
|
if (!copy)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2019-06-14 18:38:40 +00:00
|
|
|
spin_lock(&dst_server->nfs_client->cl_lock);
|
2022-03-24 07:15:23 +00:00
|
|
|
list_for_each_entry(iter,
|
2019-06-14 18:38:40 +00:00
|
|
|
&dst_server->nfs_client->pending_cb_stateids,
|
2018-07-09 19:13:32 +00:00
|
|
|
copies) {
|
2022-03-24 07:15:23 +00:00
|
|
|
if (memcmp(&res->write_res.stateid, &iter->stateid,
|
2018-07-09 19:13:32 +00:00
|
|
|
NFS4_STATEID_SIZE))
|
|
|
|
continue;
|
2022-03-24 07:15:23 +00:00
|
|
|
tmp_copy = iter;
|
|
|
|
list_del(&iter->copies);
|
2018-07-09 19:13:32 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-03-24 07:15:23 +00:00
|
|
|
if (tmp_copy) {
|
2019-06-14 18:38:40 +00:00
|
|
|
spin_unlock(&dst_server->nfs_client->cl_lock);
|
2018-11-21 16:24:22 +00:00
|
|
|
kfree(copy);
|
|
|
|
copy = tmp_copy;
|
2018-07-09 19:13:32 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2018-07-09 19:13:31 +00:00
|
|
|
|
|
|
|
memcpy(©->stateid, &res->write_res.stateid, NFS4_STATEID_SIZE);
|
|
|
|
init_completion(©->completion);
|
2019-06-14 18:38:40 +00:00
|
|
|
copy->parent_dst_state = dst_ctx->state;
|
|
|
|
copy->parent_src_state = src_ctx->state;
|
2018-07-09 19:13:31 +00:00
|
|
|
|
2019-06-14 18:38:40 +00:00
|
|
|
list_add_tail(©->copies, &dst_server->ss_copies);
|
|
|
|
spin_unlock(&dst_server->nfs_client->cl_lock);
|
|
|
|
|
|
|
|
if (dst_server != src_server) {
|
|
|
|
spin_lock(&src_server->nfs_client->cl_lock);
|
|
|
|
list_add_tail(©->src_copies, &src_server->ss_copies);
|
|
|
|
spin_unlock(&src_server->nfs_client->cl_lock);
|
|
|
|
}
|
2018-07-09 19:13:31 +00:00
|
|
|
|
2018-07-09 19:13:34 +00:00
|
|
|
status = wait_for_completion_interruptible(©->completion);
|
2019-06-14 18:38:40 +00:00
|
|
|
spin_lock(&dst_server->nfs_client->cl_lock);
|
2018-07-09 19:13:31 +00:00
|
|
|
list_del_init(©->copies);
|
2019-06-14 18:38:40 +00:00
|
|
|
spin_unlock(&dst_server->nfs_client->cl_lock);
|
|
|
|
if (dst_server != src_server) {
|
|
|
|
spin_lock(&src_server->nfs_client->cl_lock);
|
|
|
|
list_del_init(©->src_copies);
|
|
|
|
spin_unlock(&src_server->nfs_client->cl_lock);
|
|
|
|
}
|
2018-07-09 19:13:34 +00:00
|
|
|
if (status == -ERESTARTSYS) {
|
2018-08-13 19:33:01 +00:00
|
|
|
goto out_cancel;
|
2019-06-14 18:38:40 +00:00
|
|
|
} else if (copy->flags || copy->error == NFS4ERR_PARTNER_NO_AUTH) {
|
2018-08-13 19:33:01 +00:00
|
|
|
status = -EAGAIN;
|
2019-06-14 18:38:40 +00:00
|
|
|
*restart = true;
|
2018-08-13 19:33:01 +00:00
|
|
|
goto out_cancel;
|
2018-07-09 19:13:34 +00:00
|
|
|
}
|
2018-07-09 19:13:32 +00:00
|
|
|
out:
|
2018-07-09 19:13:31 +00:00
|
|
|
res->write_res.count = copy->count;
|
|
|
|
memcpy(&res->write_res.verifier, ©->verf, sizeof(copy->verf));
|
|
|
|
status = -copy->error;
|
|
|
|
|
2019-07-02 18:57:25 +00:00
|
|
|
out_free:
|
2018-08-13 19:33:01 +00:00
|
|
|
kfree(copy);
|
|
|
|
return status;
|
|
|
|
out_cancel:
|
|
|
|
nfs42_do_offload_cancel_async(dst, ©->stateid);
|
2019-07-02 18:57:25 +00:00
|
|
|
if (!nfs42_files_from_same_server(src, dst))
|
|
|
|
nfs42_do_offload_cancel_async(src, src_stateid);
|
|
|
|
goto out_free;
|
2018-07-09 19:13:31 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 19:13:36 +00:00
|
|
|
static int process_copy_commit(struct file *dst, loff_t pos_dst,
|
|
|
|
struct nfs42_copy_res *res)
|
|
|
|
{
|
|
|
|
struct nfs_commitres cres;
|
|
|
|
int status = -ENOMEM;
|
|
|
|
|
2022-01-29 19:19:15 +00:00
|
|
|
cres.verf = kzalloc(sizeof(struct nfs_writeverf), GFP_KERNEL);
|
2018-07-09 19:13:36 +00:00
|
|
|
if (!cres.verf)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
status = nfs4_proc_commit(dst, pos_dst, res->write_res.count, &cres);
|
|
|
|
if (status)
|
|
|
|
goto out_free;
|
|
|
|
if (nfs_write_verifier_cmp(&res->write_res.verifier.verifier,
|
|
|
|
&cres.verf->verifier)) {
|
|
|
|
dprintk("commit verf differs from copy verf\n");
|
|
|
|
status = -EAGAIN;
|
|
|
|
}
|
|
|
|
out_free:
|
|
|
|
kfree(cres.verf);
|
|
|
|
out:
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2021-04-14 14:10:09 +00:00
|
|
|
/**
|
|
|
|
* nfs42_copy_dest_done - perform inode cache updates after clone/copy offload
|
|
|
|
* @inode: pointer to destination inode
|
|
|
|
* @pos: destination offset
|
|
|
|
* @len: copy length
|
|
|
|
*
|
|
|
|
* Punch a hole in the inode page cache, so that the NFS client will
|
|
|
|
* know to retrieve new data.
|
|
|
|
* Update the file size if necessary, and then mark the inode as having
|
|
|
|
* invalid cached values for change attribute, ctime, mtime and space used.
|
|
|
|
*/
|
|
|
|
static void nfs42_copy_dest_done(struct inode *inode, loff_t pos, loff_t len)
|
|
|
|
{
|
|
|
|
loff_t newsize = pos + len;
|
|
|
|
loff_t end = newsize - 1;
|
|
|
|
|
2021-11-16 15:48:13 +00:00
|
|
|
WARN_ON_ONCE(invalidate_inode_pages2_range(inode->i_mapping,
|
|
|
|
pos >> PAGE_SHIFT, end >> PAGE_SHIFT));
|
|
|
|
|
2021-04-14 14:10:09 +00:00
|
|
|
spin_lock(&inode->i_lock);
|
|
|
|
if (newsize > i_size_read(inode))
|
|
|
|
i_size_write(inode, newsize);
|
|
|
|
nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE |
|
|
|
|
NFS_INO_INVALID_CTIME |
|
|
|
|
NFS_INO_INVALID_MTIME |
|
|
|
|
NFS_INO_INVALID_BLOCKS);
|
|
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
}
|
|
|
|
|
2017-02-17 23:42:32 +00:00
|
|
|
static ssize_t _nfs42_proc_copy(struct file *src,
|
2013-05-21 20:53:03 +00:00
|
|
|
struct nfs_lock_context *src_lock,
|
2017-02-17 23:42:32 +00:00
|
|
|
struct file *dst,
|
2013-05-21 20:53:03 +00:00
|
|
|
struct nfs_lock_context *dst_lock,
|
2017-02-17 23:42:32 +00:00
|
|
|
struct nfs42_copy_args *args,
|
2019-06-04 15:54:18 +00:00
|
|
|
struct nfs42_copy_res *res,
|
|
|
|
struct nl4_server *nss,
|
2019-06-14 18:38:40 +00:00
|
|
|
nfs4_stateid *cnr_stateid,
|
|
|
|
bool *restart)
|
2013-05-21 20:53:03 +00:00
|
|
|
{
|
|
|
|
struct rpc_message msg = {
|
|
|
|
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COPY],
|
2017-02-17 23:42:32 +00:00
|
|
|
.rpc_argp = args,
|
|
|
|
.rpc_resp = res,
|
2013-05-21 20:53:03 +00:00
|
|
|
};
|
|
|
|
struct inode *dst_inode = file_inode(dst);
|
2019-06-14 18:38:40 +00:00
|
|
|
struct inode *src_inode = file_inode(src);
|
|
|
|
struct nfs_server *dst_server = NFS_SERVER(dst_inode);
|
|
|
|
struct nfs_server *src_server = NFS_SERVER(src_inode);
|
2017-02-17 23:42:32 +00:00
|
|
|
loff_t pos_src = args->src_pos;
|
|
|
|
loff_t pos_dst = args->dst_pos;
|
|
|
|
size_t count = args->count;
|
2017-07-06 13:43:02 +00:00
|
|
|
ssize_t status;
|
2013-05-21 20:53:03 +00:00
|
|
|
|
2019-06-04 15:54:18 +00:00
|
|
|
if (nss) {
|
|
|
|
args->cp_src = nss;
|
|
|
|
nfs4_stateid_copy(&args->src_stateid, cnr_stateid);
|
|
|
|
} else {
|
|
|
|
status = nfs4_set_rw_stateid(&args->src_stateid,
|
|
|
|
src_lock->open_context, src_lock, FMODE_READ);
|
2019-12-18 21:50:42 +00:00
|
|
|
if (status) {
|
|
|
|
if (status == -EAGAIN)
|
|
|
|
status = -NFS4ERR_BAD_STATEID;
|
2019-06-04 15:54:18 +00:00
|
|
|
return status;
|
2019-12-18 21:50:42 +00:00
|
|
|
}
|
2019-06-04 15:54:18 +00:00
|
|
|
}
|
2022-08-20 17:12:02 +00:00
|
|
|
status = nfs_filemap_write_and_wait_range(src->f_mapping,
|
2016-06-25 22:12:03 +00:00
|
|
|
pos_src, pos_src + (loff_t)count - 1);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2017-02-17 23:42:32 +00:00
|
|
|
status = nfs4_set_rw_stateid(&args->dst_stateid, dst_lock->open_context,
|
2013-05-21 20:53:03 +00:00
|
|
|
dst_lock, FMODE_WRITE);
|
2019-12-18 21:50:42 +00:00
|
|
|
if (status) {
|
|
|
|
if (status == -EAGAIN)
|
|
|
|
status = -NFS4ERR_BAD_STATEID;
|
2013-05-21 20:53:03 +00:00
|
|
|
return status;
|
2019-12-18 21:50:42 +00:00
|
|
|
}
|
2016-06-25 22:12:03 +00:00
|
|
|
|
|
|
|
status = nfs_sync_inode(dst_inode);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2013-05-21 20:53:03 +00:00
|
|
|
|
2018-07-09 19:13:31 +00:00
|
|
|
res->commit_res.verf = NULL;
|
|
|
|
if (args->sync) {
|
|
|
|
res->commit_res.verf =
|
2022-01-29 19:19:15 +00:00
|
|
|
kzalloc(sizeof(struct nfs_writeverf), GFP_KERNEL);
|
2018-07-09 19:13:31 +00:00
|
|
|
if (!res->commit_res.verf)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2019-06-14 18:38:40 +00:00
|
|
|
set_bit(NFS_CLNT_SRC_SSC_COPY_STATE,
|
|
|
|
&src_lock->open_context->state->flags);
|
2018-08-13 19:33:01 +00:00
|
|
|
set_bit(NFS_CLNT_DST_SSC_COPY_STATE,
|
|
|
|
&dst_lock->open_context->state->flags);
|
|
|
|
|
2019-06-14 18:38:40 +00:00
|
|
|
status = nfs4_call_sync(dst_server->client, dst_server, &msg,
|
2017-02-17 23:42:32 +00:00
|
|
|
&args->seq_args, &res->seq_res, 0);
|
2021-11-04 14:57:10 +00:00
|
|
|
trace_nfs4_copy(src_inode, dst_inode, args, res, nss, status);
|
2013-05-21 20:53:03 +00:00
|
|
|
if (status == -ENOTSUPP)
|
2019-06-14 18:38:40 +00:00
|
|
|
dst_server->caps &= ~NFS_CAP_COPY;
|
2013-05-21 20:53:03 +00:00
|
|
|
if (status)
|
2017-05-08 22:02:24 +00:00
|
|
|
goto out;
|
2013-05-21 20:53:03 +00:00
|
|
|
|
2018-07-09 19:13:31 +00:00
|
|
|
if (args->sync &&
|
|
|
|
nfs_write_verifier_cmp(&res->write_res.verifier.verifier,
|
2017-05-08 22:02:24 +00:00
|
|
|
&res->commit_res.verf->verifier)) {
|
|
|
|
status = -EAGAIN;
|
|
|
|
goto out;
|
2013-05-21 20:53:03 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 19:13:31 +00:00
|
|
|
if (!res->synchronous) {
|
2019-06-14 18:38:40 +00:00
|
|
|
status = handle_async_copy(res, dst_server, src_server, src,
|
|
|
|
dst, &args->src_stateid, restart);
|
2018-07-09 19:13:31 +00:00
|
|
|
if (status)
|
2020-02-03 03:47:53 +00:00
|
|
|
goto out;
|
2018-07-09 19:13:31 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 19:13:36 +00:00
|
|
|
if ((!res->synchronous || !args->sync) &&
|
|
|
|
res->write_res.verifier.committed != NFS_FILE_SYNC) {
|
|
|
|
status = process_copy_commit(dst, pos_dst, res);
|
|
|
|
if (status)
|
2020-02-03 03:47:53 +00:00
|
|
|
goto out;
|
2018-07-09 19:13:36 +00:00
|
|
|
}
|
|
|
|
|
2021-04-14 14:10:09 +00:00
|
|
|
nfs42_copy_dest_done(dst_inode, pos_dst, res->write_res.count);
|
2021-04-14 14:27:39 +00:00
|
|
|
nfs_invalidate_atime(src_inode);
|
2017-05-08 22:02:24 +00:00
|
|
|
status = res->write_res.count;
|
|
|
|
out:
|
2018-07-09 19:13:31 +00:00
|
|
|
if (args->sync)
|
|
|
|
kfree(res->commit_res.verf);
|
2017-05-08 22:02:24 +00:00
|
|
|
return status;
|
2013-05-21 20:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t nfs42_proc_copy(struct file *src, loff_t pos_src,
|
2019-06-04 15:54:18 +00:00
|
|
|
struct file *dst, loff_t pos_dst, size_t count,
|
|
|
|
struct nl4_server *nss,
|
2019-07-03 14:38:02 +00:00
|
|
|
nfs4_stateid *cnr_stateid, bool sync)
|
2013-05-21 20:53:03 +00:00
|
|
|
{
|
|
|
|
struct nfs_server *server = NFS_SERVER(file_inode(dst));
|
|
|
|
struct nfs_lock_context *src_lock;
|
|
|
|
struct nfs_lock_context *dst_lock;
|
2017-02-17 23:42:32 +00:00
|
|
|
struct nfs42_copy_args args = {
|
|
|
|
.src_fh = NFS_FH(file_inode(src)),
|
|
|
|
.src_pos = pos_src,
|
|
|
|
.dst_fh = NFS_FH(file_inode(dst)),
|
|
|
|
.dst_pos = pos_dst,
|
|
|
|
.count = count,
|
2019-07-03 14:38:02 +00:00
|
|
|
.sync = sync,
|
2017-02-17 23:42:32 +00:00
|
|
|
};
|
|
|
|
struct nfs42_copy_res res;
|
|
|
|
struct nfs4_exception src_exception = {
|
|
|
|
.inode = file_inode(src),
|
|
|
|
.stateid = &args.src_stateid,
|
|
|
|
};
|
|
|
|
struct nfs4_exception dst_exception = {
|
|
|
|
.inode = file_inode(dst),
|
|
|
|
.stateid = &args.dst_stateid,
|
|
|
|
};
|
2013-05-21 20:53:03 +00:00
|
|
|
ssize_t err, err2;
|
2019-06-14 18:38:40 +00:00
|
|
|
bool restart = false;
|
2013-05-21 20:53:03 +00:00
|
|
|
|
|
|
|
src_lock = nfs_get_lock_context(nfs_file_open_context(src));
|
|
|
|
if (IS_ERR(src_lock))
|
|
|
|
return PTR_ERR(src_lock);
|
|
|
|
|
|
|
|
src_exception.state = src_lock->open_context->state;
|
|
|
|
|
|
|
|
dst_lock = nfs_get_lock_context(nfs_file_open_context(dst));
|
|
|
|
if (IS_ERR(dst_lock)) {
|
|
|
|
err = PTR_ERR(dst_lock);
|
|
|
|
goto out_put_src_lock;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst_exception.state = dst_lock->open_context->state;
|
|
|
|
|
|
|
|
do {
|
2016-05-26 17:33:33 +00:00
|
|
|
inode_lock(file_inode(dst));
|
2017-02-17 23:42:32 +00:00
|
|
|
err = _nfs42_proc_copy(src, src_lock,
|
|
|
|
dst, dst_lock,
|
2019-06-04 15:54:18 +00:00
|
|
|
&args, &res,
|
2019-06-14 18:38:40 +00:00
|
|
|
nss, cnr_stateid, &restart);
|
2016-05-26 17:33:33 +00:00
|
|
|
inode_unlock(file_inode(dst));
|
2013-05-21 20:53:03 +00:00
|
|
|
|
2017-02-17 23:42:32 +00:00
|
|
|
if (err >= 0)
|
|
|
|
break;
|
2023-02-07 17:46:35 +00:00
|
|
|
if ((err == -ENOTSUPP ||
|
|
|
|
err == -NFS4ERR_OFFLOAD_DENIED) &&
|
2019-07-02 18:57:25 +00:00
|
|
|
nfs42_files_from_same_server(src, dst)) {
|
2013-05-21 20:53:03 +00:00
|
|
|
err = -EOPNOTSUPP;
|
|
|
|
break;
|
2018-07-09 19:13:35 +00:00
|
|
|
} else if (err == -EAGAIN) {
|
2019-06-14 18:38:40 +00:00
|
|
|
if (!restart) {
|
|
|
|
dst_exception.retry = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
2023-08-24 20:43:53 +00:00
|
|
|
} else if (err == -NFS4ERR_OFFLOAD_NO_REQS &&
|
|
|
|
args.sync != res.synchronous) {
|
|
|
|
args.sync = res.synchronous;
|
2017-05-08 22:02:24 +00:00
|
|
|
dst_exception.retry = 1;
|
|
|
|
continue;
|
2017-09-26 17:51:39 +00:00
|
|
|
} else if ((err == -ESTALE ||
|
2019-07-02 18:57:25 +00:00
|
|
|
err == -NFS4ERR_OFFLOAD_DENIED ||
|
|
|
|
err == -ENOTSUPP) &&
|
2017-09-25 19:59:44 +00:00
|
|
|
!nfs42_files_from_same_server(src, dst)) {
|
|
|
|
nfs42_do_offload_cancel_async(src, &args.src_stateid);
|
|
|
|
err = -EOPNOTSUPP;
|
|
|
|
break;
|
2013-05-21 20:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err2 = nfs4_handle_exception(server, err, &src_exception);
|
|
|
|
err = nfs4_handle_exception(server, err, &dst_exception);
|
|
|
|
if (!err)
|
|
|
|
err = err2;
|
|
|
|
} while (src_exception.retry || dst_exception.retry);
|
|
|
|
|
|
|
|
nfs_put_lock_context(dst_lock);
|
|
|
|
out_put_src_lock:
|
|
|
|
nfs_put_lock_context(src_lock);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-07-09 19:13:34 +00:00
|
|
|
struct nfs42_offloadcancel_data {
|
|
|
|
struct nfs_server *seq_server;
|
|
|
|
struct nfs42_offload_status_args args;
|
|
|
|
struct nfs42_offload_status_res res;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void nfs42_offload_cancel_prepare(struct rpc_task *task, void *calldata)
|
|
|
|
{
|
|
|
|
struct nfs42_offloadcancel_data *data = calldata;
|
|
|
|
|
|
|
|
nfs4_setup_sequence(data->seq_server->nfs_client,
|
|
|
|
&data->args.osa_seq_args,
|
|
|
|
&data->res.osr_seq_res, task);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nfs42_offload_cancel_done(struct rpc_task *task, void *calldata)
|
|
|
|
{
|
|
|
|
struct nfs42_offloadcancel_data *data = calldata;
|
|
|
|
|
2021-11-04 14:57:14 +00:00
|
|
|
trace_nfs4_offload_cancel(&data->args, task->tk_status);
|
2018-07-09 19:13:34 +00:00
|
|
|
nfs41_sequence_done(task, &data->res.osr_seq_res);
|
|
|
|
if (task->tk_status &&
|
|
|
|
nfs4_async_handle_error(task, data->seq_server, NULL,
|
|
|
|
NULL) == -EAGAIN)
|
|
|
|
rpc_restart_call_prepare(task);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nfs42_free_offloadcancel_data(void *data)
|
|
|
|
{
|
|
|
|
kfree(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct rpc_call_ops nfs42_offload_cancel_ops = {
|
|
|
|
.rpc_call_prepare = nfs42_offload_cancel_prepare,
|
|
|
|
.rpc_call_done = nfs42_offload_cancel_done,
|
|
|
|
.rpc_release = nfs42_free_offloadcancel_data,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int nfs42_do_offload_cancel_async(struct file *dst,
|
|
|
|
nfs4_stateid *stateid)
|
|
|
|
{
|
|
|
|
struct nfs_server *dst_server = NFS_SERVER(file_inode(dst));
|
|
|
|
struct nfs42_offloadcancel_data *data = NULL;
|
|
|
|
struct nfs_open_context *ctx = nfs_file_open_context(dst);
|
|
|
|
struct rpc_task *task;
|
|
|
|
struct rpc_message msg = {
|
|
|
|
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OFFLOAD_CANCEL],
|
|
|
|
.rpc_cred = ctx->cred,
|
|
|
|
};
|
|
|
|
struct rpc_task_setup task_setup_data = {
|
|
|
|
.rpc_client = dst_server->client,
|
|
|
|
.rpc_message = &msg,
|
|
|
|
.callback_ops = &nfs42_offload_cancel_ops,
|
|
|
|
.workqueue = nfsiod_workqueue,
|
|
|
|
.flags = RPC_TASK_ASYNC,
|
|
|
|
};
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (!(dst_server->caps & NFS_CAP_OFFLOAD_CANCEL))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2022-01-29 19:19:15 +00:00
|
|
|
data = kzalloc(sizeof(struct nfs42_offloadcancel_data), GFP_KERNEL);
|
2018-07-09 19:13:34 +00:00
|
|
|
if (data == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
data->seq_server = dst_server;
|
|
|
|
data->args.osa_src_fh = NFS_FH(file_inode(dst));
|
|
|
|
memcpy(&data->args.osa_stateid, stateid,
|
|
|
|
sizeof(data->args.osa_stateid));
|
|
|
|
msg.rpc_argp = &data->args;
|
|
|
|
msg.rpc_resp = &data->res;
|
|
|
|
task_setup_data.callback_data = data;
|
|
|
|
nfs4_init_sequence(&data->args.osa_seq_args, &data->res.osr_seq_res,
|
|
|
|
1, 0);
|
|
|
|
task = rpc_run_task(&task_setup_data);
|
|
|
|
if (IS_ERR(task))
|
|
|
|
return PTR_ERR(task);
|
|
|
|
status = rpc_wait_for_completion_task(task);
|
|
|
|
if (status == -ENOTSUPP)
|
|
|
|
dst_server->caps &= ~NFS_CAP_OFFLOAD_CANCEL;
|
|
|
|
rpc_put_task(task);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2019-11-14 14:01:41 +00:00
|
|
|
static int _nfs42_proc_copy_notify(struct file *src, struct file *dst,
|
|
|
|
struct nfs42_copy_notify_args *args,
|
|
|
|
struct nfs42_copy_notify_res *res)
|
2019-06-04 20:14:30 +00:00
|
|
|
{
|
|
|
|
struct nfs_server *src_server = NFS_SERVER(file_inode(src));
|
|
|
|
struct rpc_message msg = {
|
|
|
|
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COPY_NOTIFY],
|
|
|
|
.rpc_argp = args,
|
|
|
|
.rpc_resp = res,
|
|
|
|
};
|
|
|
|
int status;
|
|
|
|
struct nfs_open_context *ctx;
|
|
|
|
struct nfs_lock_context *l_ctx;
|
|
|
|
|
|
|
|
ctx = get_nfs_open_context(nfs_file_open_context(src));
|
|
|
|
l_ctx = nfs_get_lock_context(ctx);
|
2022-01-25 13:10:45 +00:00
|
|
|
if (IS_ERR(l_ctx)) {
|
|
|
|
status = PTR_ERR(l_ctx);
|
|
|
|
goto out;
|
|
|
|
}
|
2019-06-04 20:14:30 +00:00
|
|
|
|
|
|
|
status = nfs4_set_rw_stateid(&args->cna_src_stateid, ctx, l_ctx,
|
|
|
|
FMODE_READ);
|
|
|
|
nfs_put_lock_context(l_ctx);
|
2019-12-18 21:50:42 +00:00
|
|
|
if (status) {
|
|
|
|
if (status == -EAGAIN)
|
|
|
|
status = -NFS4ERR_BAD_STATEID;
|
2022-01-25 13:10:45 +00:00
|
|
|
goto out;
|
2019-12-18 21:50:42 +00:00
|
|
|
}
|
2019-06-04 20:14:30 +00:00
|
|
|
|
|
|
|
status = nfs4_call_sync(src_server->client, src_server, &msg,
|
|
|
|
&args->cna_seq_args, &res->cnr_seq_res, 0);
|
2021-11-04 14:57:13 +00:00
|
|
|
trace_nfs4_copy_notify(file_inode(src), args, res, status);
|
2019-06-04 20:14:30 +00:00
|
|
|
if (status == -ENOTSUPP)
|
|
|
|
src_server->caps &= ~NFS_CAP_COPY_NOTIFY;
|
|
|
|
|
2022-01-25 13:10:45 +00:00
|
|
|
out:
|
2019-06-04 20:14:30 +00:00
|
|
|
put_nfs_open_context(nfs_file_open_context(src));
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
int nfs42_proc_copy_notify(struct file *src, struct file *dst,
|
|
|
|
struct nfs42_copy_notify_res *res)
|
|
|
|
{
|
|
|
|
struct nfs_server *src_server = NFS_SERVER(file_inode(src));
|
|
|
|
struct nfs42_copy_notify_args *args;
|
|
|
|
struct nfs4_exception exception = {
|
|
|
|
.inode = file_inode(src),
|
|
|
|
};
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (!(src_server->caps & NFS_CAP_COPY_NOTIFY))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2022-01-29 19:19:15 +00:00
|
|
|
args = kzalloc(sizeof(struct nfs42_copy_notify_args), GFP_KERNEL);
|
2019-06-04 20:14:30 +00:00
|
|
|
if (args == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
args->cna_src_fh = NFS_FH(file_inode(src)),
|
|
|
|
args->cna_dst.nl4_type = NL4_NETADDR;
|
|
|
|
nfs42_set_netaddr(dst, &args->cna_dst.u.nl4_addr);
|
|
|
|
exception.stateid = &args->cna_src_stateid;
|
|
|
|
|
|
|
|
do {
|
|
|
|
status = _nfs42_proc_copy_notify(src, dst, args, res);
|
|
|
|
if (status == -ENOTSUPP) {
|
|
|
|
status = -EOPNOTSUPP;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
status = nfs4_handle_exception(src_server, status, &exception);
|
|
|
|
} while (exception.retry);
|
|
|
|
|
|
|
|
out:
|
|
|
|
kfree(args);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2016-02-17 14:48:28 +00:00
|
|
|
static loff_t _nfs42_proc_llseek(struct file *filep,
|
|
|
|
struct nfs_lock_context *lock, loff_t offset, int whence)
|
2014-09-26 17:58:48 +00:00
|
|
|
{
|
|
|
|
struct inode *inode = file_inode(filep);
|
|
|
|
struct nfs42_seek_args args = {
|
|
|
|
.sa_fh = NFS_FH(inode),
|
|
|
|
.sa_offset = offset,
|
|
|
|
.sa_what = (whence == SEEK_HOLE) ?
|
|
|
|
NFS4_CONTENT_HOLE : NFS4_CONTENT_DATA,
|
|
|
|
};
|
|
|
|
struct nfs42_seek_res res;
|
|
|
|
struct rpc_message msg = {
|
|
|
|
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEEK],
|
|
|
|
.rpc_argp = &args,
|
|
|
|
.rpc_resp = &res,
|
|
|
|
};
|
|
|
|
struct nfs_server *server = NFS_SERVER(inode);
|
|
|
|
int status;
|
|
|
|
|
2014-10-23 18:00:54 +00:00
|
|
|
if (!nfs_server_capable(inode, NFS_CAP_SEEK))
|
2014-09-26 17:58:48 +00:00
|
|
|
return -ENOTSUPP;
|
|
|
|
|
2016-02-17 14:48:28 +00:00
|
|
|
status = nfs4_set_rw_stateid(&args.sa_stateid, lock->open_context,
|
|
|
|
lock, FMODE_READ);
|
2019-12-18 21:50:42 +00:00
|
|
|
if (status) {
|
|
|
|
if (status == -EAGAIN)
|
|
|
|
status = -NFS4ERR_BAD_STATEID;
|
2014-09-26 17:58:48 +00:00
|
|
|
return status;
|
2019-12-18 21:50:42 +00:00
|
|
|
}
|
2014-09-26 17:58:48 +00:00
|
|
|
|
2016-06-25 21:57:39 +00:00
|
|
|
status = nfs_filemap_write_and_wait_range(inode->i_mapping,
|
|
|
|
offset, LLONG_MAX);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2014-09-26 17:58:48 +00:00
|
|
|
status = nfs4_call_sync(server->client, server, &msg,
|
|
|
|
&args.seq_args, &res.seq_res, 0);
|
2021-11-04 14:57:08 +00:00
|
|
|
trace_nfs4_llseek(inode, &args, &res, status);
|
2014-09-26 17:58:48 +00:00
|
|
|
if (status == -ENOTSUPP)
|
|
|
|
server->caps &= ~NFS_CAP_SEEK;
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2021-03-31 19:30:25 +00:00
|
|
|
if (whence == SEEK_DATA && res.sr_eof)
|
|
|
|
return -NFS4ERR_NXIO;
|
|
|
|
else
|
|
|
|
return vfs_setpos(filep, res.sr_offset, inode->i_sb->s_maxbytes);
|
2014-09-26 17:58:48 +00:00
|
|
|
}
|
2015-06-23 11:51:55 +00:00
|
|
|
|
2015-07-23 15:08:43 +00:00
|
|
|
loff_t nfs42_proc_llseek(struct file *filep, loff_t offset, int whence)
|
|
|
|
{
|
|
|
|
struct nfs_server *server = NFS_SERVER(file_inode(filep));
|
|
|
|
struct nfs4_exception exception = { };
|
2016-02-17 14:48:28 +00:00
|
|
|
struct nfs_lock_context *lock;
|
2015-09-16 21:21:27 +00:00
|
|
|
loff_t err;
|
2015-07-23 15:08:43 +00:00
|
|
|
|
2016-02-17 14:48:28 +00:00
|
|
|
lock = nfs_get_lock_context(nfs_file_open_context(filep));
|
|
|
|
if (IS_ERR(lock))
|
|
|
|
return PTR_ERR(lock);
|
|
|
|
|
|
|
|
exception.inode = file_inode(filep);
|
|
|
|
exception.state = lock->open_context->state;
|
|
|
|
|
2015-07-23 15:08:43 +00:00
|
|
|
do {
|
2016-02-17 14:48:28 +00:00
|
|
|
err = _nfs42_proc_llseek(filep, lock, offset, whence);
|
2015-09-16 21:21:27 +00:00
|
|
|
if (err >= 0)
|
|
|
|
break;
|
2016-02-17 14:48:28 +00:00
|
|
|
if (err == -ENOTSUPP) {
|
|
|
|
err = -EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
}
|
2015-07-23 15:08:43 +00:00
|
|
|
err = nfs4_handle_exception(server, err, &exception);
|
|
|
|
} while (exception.retry);
|
|
|
|
|
2016-02-17 14:48:28 +00:00
|
|
|
nfs_put_lock_context(lock);
|
2015-07-23 15:08:43 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-23 11:51:56 +00:00
|
|
|
static void
|
|
|
|
nfs42_layoutstat_prepare(struct rpc_task *task, void *calldata)
|
|
|
|
{
|
|
|
|
struct nfs42_layoutstat_data *data = calldata;
|
2016-08-19 19:33:12 +00:00
|
|
|
struct inode *inode = data->inode;
|
|
|
|
struct nfs_server *server = NFS_SERVER(inode);
|
|
|
|
struct pnfs_layout_hdr *lo;
|
2015-06-23 11:51:56 +00:00
|
|
|
|
2016-08-19 19:33:12 +00:00
|
|
|
spin_lock(&inode->i_lock);
|
|
|
|
lo = NFS_I(inode)->layout;
|
|
|
|
if (!pnfs_layout_is_valid(lo)) {
|
|
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
rpc_exit(task, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nfs4_stateid_copy(&data->args.stateid, &lo->plh_stateid);
|
|
|
|
spin_unlock(&inode->i_lock);
|
2017-01-09 21:51:52 +00:00
|
|
|
nfs4_setup_sequence(server->nfs_client, &data->args.seq_args,
|
|
|
|
&data->res.seq_res, task);
|
2015-06-23 11:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nfs42_layoutstat_done(struct rpc_task *task, void *calldata)
|
|
|
|
{
|
|
|
|
struct nfs42_layoutstat_data *data = calldata;
|
2015-12-07 01:55:09 +00:00
|
|
|
struct inode *inode = data->inode;
|
|
|
|
struct pnfs_layout_hdr *lo;
|
2015-06-23 11:51:56 +00:00
|
|
|
|
|
|
|
if (!nfs4_sequence_done(task, &data->res.seq_res))
|
|
|
|
return;
|
|
|
|
|
2015-06-27 15:45:46 +00:00
|
|
|
switch (task->tk_status) {
|
|
|
|
case 0:
|
2020-08-04 15:02:44 +00:00
|
|
|
return;
|
2018-05-30 02:06:08 +00:00
|
|
|
case -NFS4ERR_BADHANDLE:
|
|
|
|
case -ESTALE:
|
|
|
|
pnfs_destroy_layout(NFS_I(inode));
|
|
|
|
break;
|
2015-12-07 01:55:09 +00:00
|
|
|
case -NFS4ERR_EXPIRED:
|
2016-08-05 16:16:19 +00:00
|
|
|
case -NFS4ERR_ADMIN_REVOKED:
|
|
|
|
case -NFS4ERR_DELEG_REVOKED:
|
2015-12-07 01:55:09 +00:00
|
|
|
case -NFS4ERR_STALE_STATEID:
|
|
|
|
case -NFS4ERR_BAD_STATEID:
|
|
|
|
spin_lock(&inode->i_lock);
|
|
|
|
lo = NFS_I(inode)->layout;
|
2016-08-19 19:33:12 +00:00
|
|
|
if (pnfs_layout_is_valid(lo) &&
|
|
|
|
nfs4_stateid_match(&data->args.stateid,
|
2015-12-07 01:55:09 +00:00
|
|
|
&lo->plh_stateid)) {
|
|
|
|
LIST_HEAD(head);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark the bad layout state as invalid, then retry
|
|
|
|
* with the current stateid.
|
|
|
|
*/
|
2016-07-22 15:25:27 +00:00
|
|
|
pnfs_mark_layout_stateid_invalid(lo, &head);
|
2015-12-07 01:55:09 +00:00
|
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
pnfs_free_lseg_list(&head);
|
2017-04-29 14:10:17 +00:00
|
|
|
nfs_commit_inode(inode, 0);
|
2015-12-07 01:55:09 +00:00
|
|
|
} else
|
|
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
break;
|
2016-08-19 19:33:12 +00:00
|
|
|
case -NFS4ERR_OLD_STATEID:
|
|
|
|
spin_lock(&inode->i_lock);
|
|
|
|
lo = NFS_I(inode)->layout;
|
|
|
|
if (pnfs_layout_is_valid(lo) &&
|
|
|
|
nfs4_stateid_match_other(&data->args.stateid,
|
|
|
|
&lo->plh_stateid)) {
|
|
|
|
/* Do we need to delay before resending? */
|
|
|
|
if (!nfs4_stateid_is_newer(&lo->plh_stateid,
|
|
|
|
&data->args.stateid))
|
|
|
|
rpc_delay(task, HZ);
|
|
|
|
rpc_restart_call_prepare(task);
|
|
|
|
}
|
|
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
break;
|
2015-06-27 15:45:46 +00:00
|
|
|
case -ENOTSUPP:
|
|
|
|
case -EOPNOTSUPP:
|
2015-12-07 01:55:09 +00:00
|
|
|
NFS_SERVER(inode)->caps &= ~NFS_CAP_LAYOUTSTATS;
|
2015-06-27 15:45:46 +00:00
|
|
|
}
|
2020-08-04 15:02:44 +00:00
|
|
|
|
|
|
|
trace_nfs4_layoutstats(inode, &data->args.stateid, task->tk_status);
|
2015-06-23 11:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nfs42_layoutstat_release(void *calldata)
|
|
|
|
{
|
|
|
|
struct nfs42_layoutstat_data *data = calldata;
|
2016-10-06 21:53:20 +00:00
|
|
|
struct nfs42_layoutstat_devinfo *devinfo = data->args.devinfo;
|
|
|
|
int i;
|
2015-06-23 11:51:57 +00:00
|
|
|
|
2016-10-06 21:53:20 +00:00
|
|
|
for (i = 0; i < data->args.num_dev; i++) {
|
|
|
|
if (devinfo[i].ld_private.ops && devinfo[i].ld_private.ops->free)
|
|
|
|
devinfo[i].ld_private.ops->free(&devinfo[i].ld_private);
|
|
|
|
}
|
2015-06-23 11:51:56 +00:00
|
|
|
|
|
|
|
pnfs_put_layout_hdr(NFS_I(data->args.inode)->layout);
|
2015-06-23 11:52:03 +00:00
|
|
|
smp_mb__before_atomic();
|
|
|
|
clear_bit(NFS_INO_LAYOUTSTATS, &NFS_I(data->args.inode)->flags);
|
|
|
|
smp_mb__after_atomic();
|
2015-06-23 11:51:56 +00:00
|
|
|
nfs_iput_and_deactive(data->inode);
|
|
|
|
kfree(data->args.devinfo);
|
|
|
|
kfree(data);
|
|
|
|
}
|
|
|
|
|
2015-06-23 11:51:55 +00:00
|
|
|
static const struct rpc_call_ops nfs42_layoutstat_ops = {
|
2015-06-23 11:51:56 +00:00
|
|
|
.rpc_call_prepare = nfs42_layoutstat_prepare,
|
|
|
|
.rpc_call_done = nfs42_layoutstat_done,
|
|
|
|
.rpc_release = nfs42_layoutstat_release,
|
2015-06-23 11:51:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int nfs42_proc_layoutstats_generic(struct nfs_server *server,
|
|
|
|
struct nfs42_layoutstat_data *data)
|
|
|
|
{
|
|
|
|
struct rpc_message msg = {
|
|
|
|
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTSTATS],
|
|
|
|
.rpc_argp = &data->args,
|
|
|
|
.rpc_resp = &data->res,
|
|
|
|
};
|
|
|
|
struct rpc_task_setup task_setup = {
|
|
|
|
.rpc_client = server->client,
|
|
|
|
.rpc_message = &msg,
|
|
|
|
.callback_ops = &nfs42_layoutstat_ops,
|
|
|
|
.callback_data = data,
|
|
|
|
.flags = RPC_TASK_ASYNC,
|
|
|
|
};
|
|
|
|
struct rpc_task *task;
|
|
|
|
|
2015-06-23 11:51:56 +00:00
|
|
|
data->inode = nfs_igrab_and_active(data->args.inode);
|
|
|
|
if (!data->inode) {
|
|
|
|
nfs42_layoutstat_release(data);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
2018-05-04 20:22:50 +00:00
|
|
|
nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0, 0);
|
2015-06-23 11:51:55 +00:00
|
|
|
task = rpc_run_task(&task_setup);
|
|
|
|
if (IS_ERR(task))
|
|
|
|
return PTR_ERR(task);
|
2016-10-04 04:07:43 +00:00
|
|
|
rpc_put_task(task);
|
2015-06-23 11:51:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-09-25 18:24:35 +00:00
|
|
|
|
2019-02-08 15:31:05 +00:00
|
|
|
static struct nfs42_layouterror_data *
|
|
|
|
nfs42_alloc_layouterror_data(struct pnfs_layout_segment *lseg, gfp_t gfp_flags)
|
|
|
|
{
|
|
|
|
struct nfs42_layouterror_data *data;
|
|
|
|
struct inode *inode = lseg->pls_layout->plh_inode;
|
|
|
|
|
|
|
|
data = kzalloc(sizeof(*data), gfp_flags);
|
|
|
|
if (data) {
|
|
|
|
data->args.inode = data->inode = nfs_igrab_and_active(inode);
|
|
|
|
if (data->inode) {
|
|
|
|
data->lseg = pnfs_get_lseg(lseg);
|
|
|
|
if (data->lseg)
|
|
|
|
return data;
|
|
|
|
nfs_iput_and_deactive(data->inode);
|
|
|
|
}
|
|
|
|
kfree(data);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nfs42_free_layouterror_data(struct nfs42_layouterror_data *data)
|
|
|
|
{
|
|
|
|
pnfs_put_lseg(data->lseg);
|
|
|
|
nfs_iput_and_deactive(data->inode);
|
|
|
|
kfree(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nfs42_layouterror_prepare(struct rpc_task *task, void *calldata)
|
|
|
|
{
|
|
|
|
struct nfs42_layouterror_data *data = calldata;
|
|
|
|
struct inode *inode = data->inode;
|
|
|
|
struct nfs_server *server = NFS_SERVER(inode);
|
|
|
|
struct pnfs_layout_hdr *lo = data->lseg->pls_layout;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
spin_lock(&inode->i_lock);
|
|
|
|
if (!pnfs_layout_is_valid(lo)) {
|
|
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
rpc_exit(task, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (i = 0; i < data->args.num_errors; i++)
|
|
|
|
nfs4_stateid_copy(&data->args.errors[i].stateid,
|
|
|
|
&lo->plh_stateid);
|
|
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
nfs4_setup_sequence(server->nfs_client, &data->args.seq_args,
|
|
|
|
&data->res.seq_res, task);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nfs42_layouterror_done(struct rpc_task *task, void *calldata)
|
|
|
|
{
|
|
|
|
struct nfs42_layouterror_data *data = calldata;
|
|
|
|
struct inode *inode = data->inode;
|
|
|
|
struct pnfs_layout_hdr *lo = data->lseg->pls_layout;
|
|
|
|
|
|
|
|
if (!nfs4_sequence_done(task, &data->res.seq_res))
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (task->tk_status) {
|
|
|
|
case 0:
|
2020-08-04 15:02:44 +00:00
|
|
|
return;
|
2019-02-08 15:31:05 +00:00
|
|
|
case -NFS4ERR_BADHANDLE:
|
|
|
|
case -ESTALE:
|
|
|
|
pnfs_destroy_layout(NFS_I(inode));
|
|
|
|
break;
|
|
|
|
case -NFS4ERR_EXPIRED:
|
|
|
|
case -NFS4ERR_ADMIN_REVOKED:
|
|
|
|
case -NFS4ERR_DELEG_REVOKED:
|
|
|
|
case -NFS4ERR_STALE_STATEID:
|
|
|
|
case -NFS4ERR_BAD_STATEID:
|
|
|
|
spin_lock(&inode->i_lock);
|
|
|
|
if (pnfs_layout_is_valid(lo) &&
|
|
|
|
nfs4_stateid_match(&data->args.errors[0].stateid,
|
|
|
|
&lo->plh_stateid)) {
|
|
|
|
LIST_HEAD(head);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark the bad layout state as invalid, then retry
|
|
|
|
* with the current stateid.
|
|
|
|
*/
|
|
|
|
pnfs_mark_layout_stateid_invalid(lo, &head);
|
|
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
pnfs_free_lseg_list(&head);
|
|
|
|
nfs_commit_inode(inode, 0);
|
|
|
|
} else
|
|
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
break;
|
|
|
|
case -NFS4ERR_OLD_STATEID:
|
|
|
|
spin_lock(&inode->i_lock);
|
|
|
|
if (pnfs_layout_is_valid(lo) &&
|
|
|
|
nfs4_stateid_match_other(&data->args.errors[0].stateid,
|
|
|
|
&lo->plh_stateid)) {
|
|
|
|
/* Do we need to delay before resending? */
|
|
|
|
if (!nfs4_stateid_is_newer(&lo->plh_stateid,
|
|
|
|
&data->args.errors[0].stateid))
|
|
|
|
rpc_delay(task, HZ);
|
|
|
|
rpc_restart_call_prepare(task);
|
|
|
|
}
|
|
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
break;
|
|
|
|
case -ENOTSUPP:
|
|
|
|
case -EOPNOTSUPP:
|
|
|
|
NFS_SERVER(inode)->caps &= ~NFS_CAP_LAYOUTERROR;
|
|
|
|
}
|
2020-08-04 15:02:44 +00:00
|
|
|
|
|
|
|
trace_nfs4_layouterror(inode, &data->args.errors[0].stateid,
|
|
|
|
task->tk_status);
|
2019-02-08 15:31:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nfs42_layouterror_release(void *calldata)
|
|
|
|
{
|
|
|
|
struct nfs42_layouterror_data *data = calldata;
|
|
|
|
|
|
|
|
nfs42_free_layouterror_data(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct rpc_call_ops nfs42_layouterror_ops = {
|
|
|
|
.rpc_call_prepare = nfs42_layouterror_prepare,
|
|
|
|
.rpc_call_done = nfs42_layouterror_done,
|
|
|
|
.rpc_release = nfs42_layouterror_release,
|
|
|
|
};
|
|
|
|
|
|
|
|
int nfs42_proc_layouterror(struct pnfs_layout_segment *lseg,
|
|
|
|
const struct nfs42_layout_error *errors, size_t n)
|
|
|
|
{
|
|
|
|
struct inode *inode = lseg->pls_layout->plh_inode;
|
|
|
|
struct nfs42_layouterror_data *data;
|
|
|
|
struct rpc_task *task;
|
|
|
|
struct rpc_message msg = {
|
|
|
|
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTERROR],
|
|
|
|
};
|
|
|
|
struct rpc_task_setup task_setup = {
|
|
|
|
.rpc_message = &msg,
|
|
|
|
.callback_ops = &nfs42_layouterror_ops,
|
|
|
|
.flags = RPC_TASK_ASYNC,
|
|
|
|
};
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (!nfs_server_capable(inode, NFS_CAP_LAYOUTERROR))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
if (n > NFS42_LAYOUTERROR_MAX)
|
|
|
|
return -EINVAL;
|
2022-03-21 19:32:09 +00:00
|
|
|
data = nfs42_alloc_layouterror_data(lseg, nfs_io_gfp_mask());
|
2019-02-08 15:31:05 +00:00
|
|
|
if (!data)
|
|
|
|
return -ENOMEM;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
data->args.errors[i] = errors[i];
|
|
|
|
data->args.num_errors++;
|
|
|
|
data->res.num_errors++;
|
|
|
|
}
|
|
|
|
msg.rpc_argp = &data->args;
|
|
|
|
msg.rpc_resp = &data->res;
|
|
|
|
task_setup.callback_data = data;
|
|
|
|
task_setup.rpc_client = NFS_SERVER(inode)->client;
|
|
|
|
nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0, 0);
|
|
|
|
task = rpc_run_task(&task_setup);
|
|
|
|
if (IS_ERR(task))
|
|
|
|
return PTR_ERR(task);
|
|
|
|
rpc_put_task(task);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(nfs42_proc_layouterror);
|
|
|
|
|
2015-09-25 18:24:35 +00:00
|
|
|
static int _nfs42_proc_clone(struct rpc_message *msg, struct file *src_f,
|
2016-02-17 14:48:28 +00:00
|
|
|
struct file *dst_f, struct nfs_lock_context *src_lock,
|
|
|
|
struct nfs_lock_context *dst_lock, loff_t src_offset,
|
|
|
|
loff_t dst_offset, loff_t count)
|
2015-09-25 18:24:35 +00:00
|
|
|
{
|
|
|
|
struct inode *src_inode = file_inode(src_f);
|
|
|
|
struct inode *dst_inode = file_inode(dst_f);
|
|
|
|
struct nfs_server *server = NFS_SERVER(dst_inode);
|
2021-12-27 19:40:52 +00:00
|
|
|
__u32 dst_bitmask[NFS_BITMASK_SZ];
|
2015-09-25 18:24:35 +00:00
|
|
|
struct nfs42_clone_args args = {
|
|
|
|
.src_fh = NFS_FH(src_inode),
|
|
|
|
.dst_fh = NFS_FH(dst_inode),
|
|
|
|
.src_offset = src_offset,
|
|
|
|
.dst_offset = dst_offset,
|
2015-11-13 08:38:45 +00:00
|
|
|
.count = count,
|
2021-12-27 19:40:52 +00:00
|
|
|
.dst_bitmask = dst_bitmask,
|
2015-09-25 18:24:35 +00:00
|
|
|
};
|
|
|
|
struct nfs42_clone_res res = {
|
|
|
|
.server = server,
|
|
|
|
};
|
|
|
|
int status;
|
|
|
|
|
|
|
|
msg->rpc_argp = &args;
|
|
|
|
msg->rpc_resp = &res;
|
|
|
|
|
2016-02-17 14:48:28 +00:00
|
|
|
status = nfs4_set_rw_stateid(&args.src_stateid, src_lock->open_context,
|
|
|
|
src_lock, FMODE_READ);
|
2019-12-18 21:50:42 +00:00
|
|
|
if (status) {
|
|
|
|
if (status == -EAGAIN)
|
|
|
|
status = -NFS4ERR_BAD_STATEID;
|
2015-09-25 18:24:35 +00:00
|
|
|
return status;
|
2019-12-18 21:50:42 +00:00
|
|
|
}
|
2016-02-17 14:48:28 +00:00
|
|
|
status = nfs4_set_rw_stateid(&args.dst_stateid, dst_lock->open_context,
|
|
|
|
dst_lock, FMODE_WRITE);
|
2019-12-18 21:50:42 +00:00
|
|
|
if (status) {
|
|
|
|
if (status == -EAGAIN)
|
|
|
|
status = -NFS4ERR_BAD_STATEID;
|
2015-09-25 18:24:35 +00:00
|
|
|
return status;
|
2019-12-18 21:50:42 +00:00
|
|
|
}
|
2015-09-25 18:24:35 +00:00
|
|
|
|
|
|
|
res.dst_fattr = nfs_alloc_fattr();
|
|
|
|
if (!res.dst_fattr)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2021-12-27 19:40:52 +00:00
|
|
|
nfs4_bitmask_set(dst_bitmask, server->cache_consistency_bitmask,
|
|
|
|
dst_inode, NFS_INO_INVALID_BLOCKS);
|
|
|
|
|
2015-09-25 18:24:35 +00:00
|
|
|
status = nfs4_call_sync(server->client, server, msg,
|
|
|
|
&args.seq_args, &res.seq_res, 0);
|
2021-11-04 14:57:11 +00:00
|
|
|
trace_nfs4_clone(src_inode, dst_inode, &args, status);
|
2021-04-14 14:10:09 +00:00
|
|
|
if (status == 0) {
|
2022-10-13 15:58:01 +00:00
|
|
|
/* a zero-length count means clone to EOF in src */
|
|
|
|
if (count == 0 && res.dst_fattr->valid & NFS_ATTR_FATTR_SIZE)
|
|
|
|
count = nfs_size_to_loff_t(res.dst_fattr->size) - dst_offset;
|
2021-04-14 14:10:09 +00:00
|
|
|
nfs42_copy_dest_done(dst_inode, dst_offset, count);
|
2015-09-25 18:24:35 +00:00
|
|
|
status = nfs_post_op_update_inode(dst_inode, res.dst_fattr);
|
2021-04-14 14:10:09 +00:00
|
|
|
}
|
2015-09-25 18:24:35 +00:00
|
|
|
|
|
|
|
kfree(res.dst_fattr);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
int nfs42_proc_clone(struct file *src_f, struct file *dst_f,
|
|
|
|
loff_t src_offset, loff_t dst_offset, loff_t count)
|
|
|
|
{
|
|
|
|
struct rpc_message msg = {
|
|
|
|
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLONE],
|
|
|
|
};
|
|
|
|
struct inode *inode = file_inode(src_f);
|
|
|
|
struct nfs_server *server = NFS_SERVER(file_inode(src_f));
|
2016-02-17 14:48:28 +00:00
|
|
|
struct nfs_lock_context *src_lock;
|
|
|
|
struct nfs_lock_context *dst_lock;
|
|
|
|
struct nfs4_exception src_exception = { };
|
|
|
|
struct nfs4_exception dst_exception = { };
|
|
|
|
int err, err2;
|
2015-09-25 18:24:35 +00:00
|
|
|
|
|
|
|
if (!nfs_server_capable(inode, NFS_CAP_CLONE))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2016-02-17 14:48:28 +00:00
|
|
|
src_lock = nfs_get_lock_context(nfs_file_open_context(src_f));
|
|
|
|
if (IS_ERR(src_lock))
|
|
|
|
return PTR_ERR(src_lock);
|
|
|
|
|
|
|
|
src_exception.inode = file_inode(src_f);
|
|
|
|
src_exception.state = src_lock->open_context->state;
|
|
|
|
|
|
|
|
dst_lock = nfs_get_lock_context(nfs_file_open_context(dst_f));
|
|
|
|
if (IS_ERR(dst_lock)) {
|
|
|
|
err = PTR_ERR(dst_lock);
|
|
|
|
goto out_put_src_lock;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst_exception.inode = file_inode(dst_f);
|
|
|
|
dst_exception.state = dst_lock->open_context->state;
|
|
|
|
|
2015-09-25 18:24:35 +00:00
|
|
|
do {
|
2016-02-17 14:48:28 +00:00
|
|
|
err = _nfs42_proc_clone(&msg, src_f, dst_f, src_lock, dst_lock,
|
|
|
|
src_offset, dst_offset, count);
|
2015-09-25 18:24:35 +00:00
|
|
|
if (err == -ENOTSUPP || err == -EOPNOTSUPP) {
|
|
|
|
NFS_SERVER(inode)->caps &= ~NFS_CAP_CLONE;
|
2016-02-17 14:48:28 +00:00
|
|
|
err = -EOPNOTSUPP;
|
|
|
|
break;
|
2015-09-25 18:24:35 +00:00
|
|
|
}
|
|
|
|
|
2016-02-17 14:48:28 +00:00
|
|
|
err2 = nfs4_handle_exception(server, err, &src_exception);
|
|
|
|
err = nfs4_handle_exception(server, err, &dst_exception);
|
|
|
|
if (!err)
|
|
|
|
err = err2;
|
|
|
|
} while (src_exception.retry || dst_exception.retry);
|
2015-09-25 18:24:35 +00:00
|
|
|
|
2016-02-17 14:48:28 +00:00
|
|
|
nfs_put_lock_context(dst_lock);
|
|
|
|
out_put_src_lock:
|
|
|
|
nfs_put_lock_context(src_lock);
|
|
|
|
return err;
|
2015-09-25 18:24:35 +00:00
|
|
|
}
|
2020-06-23 22:39:02 +00:00
|
|
|
|
|
|
|
#define NFS4XATTR_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE)
|
|
|
|
|
|
|
|
static int _nfs42_proc_removexattr(struct inode *inode, const char *name)
|
|
|
|
{
|
|
|
|
struct nfs_server *server = NFS_SERVER(inode);
|
|
|
|
struct nfs42_removexattrargs args = {
|
|
|
|
.fh = NFS_FH(inode),
|
|
|
|
.xattr_name = name,
|
|
|
|
};
|
|
|
|
struct nfs42_removexattrres res;
|
|
|
|
struct rpc_message msg = {
|
|
|
|
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVEXATTR],
|
|
|
|
.rpc_argp = &args,
|
|
|
|
.rpc_resp = &res,
|
|
|
|
};
|
|
|
|
int ret;
|
|
|
|
unsigned long timestamp = jiffies;
|
|
|
|
|
|
|
|
ret = nfs4_call_sync(server->client, server, &msg, &args.seq_args,
|
|
|
|
&res.seq_res, 1);
|
2022-09-22 19:18:50 +00:00
|
|
|
trace_nfs4_removexattr(inode, name, ret);
|
2020-06-23 22:39:02 +00:00
|
|
|
if (!ret)
|
|
|
|
nfs4_update_changeattr(inode, &res.cinfo, timestamp, 0);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _nfs42_proc_setxattr(struct inode *inode, const char *name,
|
|
|
|
const void *buf, size_t buflen, int flags)
|
|
|
|
{
|
|
|
|
struct nfs_server *server = NFS_SERVER(inode);
|
2023-05-04 20:47:16 +00:00
|
|
|
__u32 bitmask[NFS_BITMASK_SZ];
|
2020-06-23 22:39:02 +00:00
|
|
|
struct page *pages[NFS4XATTR_MAXPAGES];
|
|
|
|
struct nfs42_setxattrargs arg = {
|
|
|
|
.fh = NFS_FH(inode),
|
2023-05-04 20:47:16 +00:00
|
|
|
.bitmask = bitmask,
|
2020-06-23 22:39:02 +00:00
|
|
|
.xattr_pages = pages,
|
|
|
|
.xattr_len = buflen,
|
|
|
|
.xattr_name = name,
|
|
|
|
.xattr_flags = flags,
|
|
|
|
};
|
2023-05-04 20:47:16 +00:00
|
|
|
struct nfs42_setxattrres res = {
|
|
|
|
.server = server,
|
|
|
|
};
|
2020-06-23 22:39:02 +00:00
|
|
|
struct rpc_message msg = {
|
|
|
|
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETXATTR],
|
|
|
|
.rpc_argp = &arg,
|
|
|
|
.rpc_resp = &res,
|
|
|
|
};
|
|
|
|
int ret, np;
|
|
|
|
unsigned long timestamp = jiffies;
|
|
|
|
|
|
|
|
if (buflen > server->sxasize)
|
|
|
|
return -ERANGE;
|
|
|
|
|
2023-05-04 20:47:16 +00:00
|
|
|
res.fattr = nfs_alloc_fattr();
|
|
|
|
if (!res.fattr)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2020-06-23 22:39:02 +00:00
|
|
|
if (buflen > 0) {
|
|
|
|
np = nfs4_buf_to_pages_noslab(buf, buflen, arg.xattr_pages);
|
2023-05-04 20:47:16 +00:00
|
|
|
if (np < 0) {
|
|
|
|
ret = np;
|
|
|
|
goto out;
|
|
|
|
}
|
2020-06-23 22:39:02 +00:00
|
|
|
} else
|
|
|
|
np = 0;
|
|
|
|
|
2023-05-04 20:47:16 +00:00
|
|
|
nfs4_bitmask_set(bitmask, server->cache_consistency_bitmask,
|
|
|
|
inode, NFS_INO_INVALID_CHANGE);
|
|
|
|
|
2020-06-23 22:39:02 +00:00
|
|
|
ret = nfs4_call_sync(server->client, server, &msg, &arg.seq_args,
|
|
|
|
&res.seq_res, 1);
|
2022-09-22 19:18:50 +00:00
|
|
|
trace_nfs4_setxattr(inode, name, ret);
|
2020-06-23 22:39:02 +00:00
|
|
|
|
|
|
|
for (; np > 0; np--)
|
|
|
|
put_page(pages[np - 1]);
|
|
|
|
|
2023-05-04 20:47:16 +00:00
|
|
|
if (!ret) {
|
2020-06-23 22:39:02 +00:00
|
|
|
nfs4_update_changeattr(inode, &res.cinfo, timestamp, 0);
|
2023-05-04 20:47:16 +00:00
|
|
|
ret = nfs_post_op_update_inode(inode, res.fattr);
|
|
|
|
}
|
2020-06-23 22:39:02 +00:00
|
|
|
|
2023-05-04 20:47:16 +00:00
|
|
|
out:
|
|
|
|
kfree(res.fattr);
|
2020-06-23 22:39:02 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t _nfs42_proc_getxattr(struct inode *inode, const char *name,
|
2020-12-02 00:34:11 +00:00
|
|
|
void *buf, size_t buflen, struct page **pages,
|
|
|
|
size_t plen)
|
2020-06-23 22:39:02 +00:00
|
|
|
{
|
|
|
|
struct nfs_server *server = NFS_SERVER(inode);
|
|
|
|
struct nfs42_getxattrargs arg = {
|
|
|
|
.fh = NFS_FH(inode),
|
|
|
|
.xattr_name = name,
|
|
|
|
};
|
|
|
|
struct nfs42_getxattrres res;
|
|
|
|
struct rpc_message msg = {
|
|
|
|
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETXATTR],
|
|
|
|
.rpc_argp = &arg,
|
|
|
|
.rpc_resp = &res,
|
|
|
|
};
|
2020-12-02 00:34:11 +00:00
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
arg.xattr_len = plen;
|
|
|
|
arg.xattr_pages = pages;
|
2020-06-23 22:39:02 +00:00
|
|
|
|
|
|
|
ret = nfs4_call_sync(server->client, server, &msg, &arg.seq_args,
|
|
|
|
&res.seq_res, 0);
|
2022-09-22 19:18:50 +00:00
|
|
|
trace_nfs4_getxattr(inode, name, ret);
|
2020-06-23 22:39:02 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2020-06-23 22:39:04 +00:00
|
|
|
/*
|
|
|
|
* Normally, the caching is done one layer up, but for successful
|
|
|
|
* RPCS, always cache the result here, even if the caller was
|
|
|
|
* just querying the length, or if the reply was too big for
|
|
|
|
* the caller. This avoids a second RPC in the case of the
|
|
|
|
* common query-alloc-retrieve cycle for xattrs.
|
|
|
|
*
|
|
|
|
* Note that xattr_len is always capped to XATTR_SIZE_MAX.
|
|
|
|
*/
|
|
|
|
|
|
|
|
nfs4_xattr_cache_add(inode, name, NULL, pages, res.xattr_len);
|
|
|
|
|
2020-06-23 22:39:02 +00:00
|
|
|
if (buflen) {
|
|
|
|
if (res.xattr_len > buflen)
|
|
|
|
return -ERANGE;
|
|
|
|
_copy_from_pages(buf, pages, 0, res.xattr_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.xattr_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t _nfs42_proc_listxattrs(struct inode *inode, void *buf,
|
|
|
|
size_t buflen, u64 *cookiep, bool *eofp)
|
|
|
|
{
|
|
|
|
struct nfs_server *server = NFS_SERVER(inode);
|
|
|
|
struct page **pages;
|
|
|
|
struct nfs42_listxattrsargs arg = {
|
|
|
|
.fh = NFS_FH(inode),
|
|
|
|
.cookie = *cookiep,
|
|
|
|
};
|
|
|
|
struct nfs42_listxattrsres res = {
|
|
|
|
.eof = false,
|
|
|
|
.xattr_buf = buf,
|
|
|
|
.xattr_len = buflen,
|
|
|
|
};
|
|
|
|
struct rpc_message msg = {
|
|
|
|
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LISTXATTRS],
|
|
|
|
.rpc_argp = &arg,
|
|
|
|
.rpc_resp = &res,
|
|
|
|
};
|
|
|
|
u32 xdrlen;
|
2020-11-25 00:15:18 +00:00
|
|
|
int ret, np, i;
|
2020-06-23 22:39:02 +00:00
|
|
|
|
|
|
|
|
2020-11-25 00:15:18 +00:00
|
|
|
ret = -ENOMEM;
|
2020-06-23 22:39:02 +00:00
|
|
|
res.scratch = alloc_page(GFP_KERNEL);
|
|
|
|
if (!res.scratch)
|
2020-11-25 00:15:18 +00:00
|
|
|
goto out;
|
2020-06-23 22:39:02 +00:00
|
|
|
|
|
|
|
xdrlen = nfs42_listxattr_xdrsize(buflen);
|
|
|
|
if (xdrlen > server->lxasize)
|
|
|
|
xdrlen = server->lxasize;
|
|
|
|
np = xdrlen / PAGE_SIZE + 1;
|
|
|
|
|
|
|
|
pages = kcalloc(np, sizeof(struct page *), GFP_KERNEL);
|
2020-11-25 00:15:18 +00:00
|
|
|
if (!pages)
|
|
|
|
goto out_free_scratch;
|
|
|
|
for (i = 0; i < np; i++) {
|
|
|
|
pages[i] = alloc_page(GFP_KERNEL);
|
|
|
|
if (!pages[i])
|
|
|
|
goto out_free_pages;
|
2020-06-23 22:39:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
arg.xattr_pages = pages;
|
|
|
|
arg.count = xdrlen;
|
|
|
|
|
|
|
|
ret = nfs4_call_sync(server->client, server, &msg, &arg.seq_args,
|
|
|
|
&res.seq_res, 0);
|
2022-10-03 17:03:52 +00:00
|
|
|
trace_nfs4_listxattr(inode, ret);
|
2020-06-23 22:39:02 +00:00
|
|
|
|
|
|
|
if (ret >= 0) {
|
|
|
|
ret = res.copied;
|
|
|
|
*cookiep = res.cookie;
|
|
|
|
*eofp = res.eof;
|
|
|
|
}
|
|
|
|
|
2020-11-25 00:15:18 +00:00
|
|
|
out_free_pages:
|
2020-06-23 22:39:02 +00:00
|
|
|
while (--np >= 0) {
|
|
|
|
if (pages[np])
|
|
|
|
__free_page(pages[np]);
|
|
|
|
}
|
|
|
|
kfree(pages);
|
2020-11-25 00:15:18 +00:00
|
|
|
out_free_scratch:
|
|
|
|
__free_page(res.scratch);
|
|
|
|
out:
|
2020-06-23 22:39:02 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t nfs42_proc_getxattr(struct inode *inode, const char *name,
|
|
|
|
void *buf, size_t buflen)
|
|
|
|
{
|
|
|
|
struct nfs4_exception exception = { };
|
2020-12-02 00:34:11 +00:00
|
|
|
ssize_t err, np, i;
|
|
|
|
struct page **pages;
|
|
|
|
|
|
|
|
np = nfs_page_array_len(0, buflen ?: XATTR_SIZE_MAX);
|
|
|
|
pages = kmalloc_array(np, sizeof(*pages), GFP_KERNEL);
|
|
|
|
if (!pages)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (i = 0; i < np; i++) {
|
|
|
|
pages[i] = alloc_page(GFP_KERNEL);
|
|
|
|
if (!pages[i]) {
|
2020-12-16 12:25:13 +00:00
|
|
|
err = -ENOMEM;
|
2020-12-02 00:34:11 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2020-06-23 22:39:02 +00:00
|
|
|
|
2020-12-02 00:34:11 +00:00
|
|
|
/*
|
|
|
|
* The GETXATTR op has no length field in the call, and the
|
|
|
|
* xattr data is at the end of the reply.
|
|
|
|
*
|
|
|
|
* There is no downside in using the page-aligned length. It will
|
|
|
|
* allow receiving and caching xattrs that are too large for the
|
|
|
|
* caller but still fit in the page-rounded value.
|
|
|
|
*/
|
2020-06-23 22:39:02 +00:00
|
|
|
do {
|
2020-12-02 00:34:11 +00:00
|
|
|
err = _nfs42_proc_getxattr(inode, name, buf, buflen,
|
|
|
|
pages, np * PAGE_SIZE);
|
2020-06-23 22:39:02 +00:00
|
|
|
if (err >= 0)
|
|
|
|
break;
|
|
|
|
err = nfs4_handle_exception(NFS_SERVER(inode), err,
|
|
|
|
&exception);
|
|
|
|
} while (exception.retry);
|
|
|
|
|
2020-12-02 00:34:11 +00:00
|
|
|
out:
|
2023-07-25 11:58:58 +00:00
|
|
|
while (--i >= 0)
|
|
|
|
__free_page(pages[i]);
|
2020-12-02 00:34:11 +00:00
|
|
|
kfree(pages);
|
|
|
|
|
2020-06-23 22:39:02 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int nfs42_proc_setxattr(struct inode *inode, const char *name,
|
|
|
|
const void *buf, size_t buflen, int flags)
|
|
|
|
{
|
|
|
|
struct nfs4_exception exception = { };
|
|
|
|
int err;
|
|
|
|
|
|
|
|
do {
|
|
|
|
err = _nfs42_proc_setxattr(inode, name, buf, buflen, flags);
|
|
|
|
if (!err)
|
|
|
|
break;
|
|
|
|
err = nfs4_handle_exception(NFS_SERVER(inode), err,
|
|
|
|
&exception);
|
|
|
|
} while (exception.retry);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t nfs42_proc_listxattrs(struct inode *inode, void *buf,
|
|
|
|
size_t buflen, u64 *cookiep, bool *eofp)
|
|
|
|
{
|
|
|
|
struct nfs4_exception exception = { };
|
|
|
|
ssize_t err;
|
|
|
|
|
|
|
|
do {
|
|
|
|
err = _nfs42_proc_listxattrs(inode, buf, buflen,
|
|
|
|
cookiep, eofp);
|
|
|
|
if (err >= 0)
|
|
|
|
break;
|
|
|
|
err = nfs4_handle_exception(NFS_SERVER(inode), err,
|
|
|
|
&exception);
|
|
|
|
} while (exception.retry);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int nfs42_proc_removexattr(struct inode *inode, const char *name)
|
|
|
|
{
|
|
|
|
struct nfs4_exception exception = { };
|
|
|
|
int err;
|
|
|
|
|
|
|
|
do {
|
|
|
|
err = _nfs42_proc_removexattr(inode, name);
|
|
|
|
if (!err)
|
|
|
|
break;
|
|
|
|
err = nfs4_handle_exception(NFS_SERVER(inode), err,
|
|
|
|
&exception);
|
|
|
|
} while (exception.retry);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|