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 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* linux/fs/nfs/unlink.c
|
|
|
|
*
|
|
|
|
* nfs sillydelete handling
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/dcache.h>
|
|
|
|
#include <linux/sunrpc/sched.h>
|
|
|
|
#include <linux/sunrpc/clnt.h>
|
|
|
|
#include <linux/nfs_fs.h>
|
2007-10-20 10:59:18 +08:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/wait.h>
|
2010-09-18 05:31:30 +08:00
|
|
|
#include <linux/namei.h>
|
2014-03-17 19:06:58 +08:00
|
|
|
#include <linux/fsnotify.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-11-08 17:05:04 +08:00
|
|
|
#include "internal.h"
|
2009-04-01 21:22:24 +08:00
|
|
|
#include "nfs4_fs.h"
|
2010-09-18 05:31:30 +08:00
|
|
|
#include "iostat.h"
|
|
|
|
#include "delegation.h"
|
2007-11-08 17:05:04 +08:00
|
|
|
|
2013-08-22 00:08:45 +08:00
|
|
|
#include "nfstrace.h"
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
2007-07-15 03:39:58 +08:00
|
|
|
* nfs_free_unlinkdata - release data from a sillydelete operation.
|
2005-04-17 06:20:36 +08:00
|
|
|
* @data: pointer to unlink structure.
|
|
|
|
*/
|
|
|
|
static void
|
2007-07-15 03:39:58 +08:00
|
|
|
nfs_free_unlinkdata(struct nfs_unlinkdata *data)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-12-03 08:30:31 +08:00
|
|
|
put_cred(data->cred);
|
2007-07-15 03:39:58 +08:00
|
|
|
kfree(data->args.name.name);
|
|
|
|
kfree(data);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nfs_async_unlink_done - Sillydelete post-processing
|
|
|
|
* @task: rpc_task of the sillydelete
|
2019-02-19 02:32:38 +08:00
|
|
|
* @calldata: pointer to nfs_unlinkdata
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Do the directory attribute update.
|
|
|
|
*/
|
2006-01-03 16:55:04 +08:00
|
|
|
static void nfs_async_unlink_done(struct rpc_task *task, void *calldata)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-07-15 03:39:58 +08:00
|
|
|
struct nfs_unlinkdata *data = calldata;
|
2016-04-29 11:56:31 +08:00
|
|
|
struct inode *dir = d_inode(data->dentry->d_parent);
|
2007-07-15 03:39:58 +08:00
|
|
|
|
2013-08-22 00:08:45 +08:00
|
|
|
trace_nfs_sillyrename_unlink(data, task->tk_status);
|
2007-07-15 03:39:58 +08:00
|
|
|
if (!NFS_PROTO(dir)->unlink_done(task, dir))
|
2011-10-20 03:17:29 +08:00
|
|
|
rpc_restart_call_prepare(task);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nfs_async_unlink_release - Release the sillydelete data.
|
2019-02-19 02:32:38 +08:00
|
|
|
* @calldata: struct nfs_unlinkdata to release
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* We need to call nfs_put_unlinkdata as a 'tk_release' task since the
|
|
|
|
* rpc_task would be freed too.
|
|
|
|
*/
|
2006-01-03 16:55:04 +08:00
|
|
|
static void nfs_async_unlink_release(void *calldata)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-01-03 16:55:04 +08:00
|
|
|
struct nfs_unlinkdata *data = calldata;
|
2016-04-29 11:56:31 +08:00
|
|
|
struct dentry *dentry = data->dentry;
|
|
|
|
struct super_block *sb = dentry->d_sb;
|
2007-10-16 06:17:53 +08:00
|
|
|
|
2016-04-29 11:56:31 +08:00
|
|
|
up_read_non_owner(&NFS_I(d_inode(dentry->d_parent))->rmdir_sem);
|
|
|
|
d_lookup_done(dentry);
|
2007-07-15 03:39:58 +08:00
|
|
|
nfs_free_unlinkdata(data);
|
2016-04-29 11:56:31 +08:00
|
|
|
dput(dentry);
|
2013-01-12 05:39:51 +08:00
|
|
|
nfs_sb_deactive(sb);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-03-12 01:11:00 +08:00
|
|
|
static void nfs_unlink_prepare(struct rpc_task *task, void *calldata)
|
2009-04-01 21:22:24 +08:00
|
|
|
{
|
|
|
|
struct nfs_unlinkdata *data = calldata;
|
2016-04-29 11:56:31 +08:00
|
|
|
struct inode *dir = d_inode(data->dentry->d_parent);
|
|
|
|
NFS_PROTO(dir)->unlink_rpc_prepare(task, data);
|
2009-04-01 21:22:24 +08:00
|
|
|
}
|
|
|
|
|
2006-01-03 16:55:04 +08:00
|
|
|
static const struct rpc_call_ops nfs_unlink_ops = {
|
|
|
|
.rpc_call_done = nfs_async_unlink_done,
|
|
|
|
.rpc_release = nfs_async_unlink_release,
|
2009-04-01 21:22:24 +08:00
|
|
|
.rpc_call_prepare = nfs_unlink_prepare,
|
2006-01-03 16:55:04 +08:00
|
|
|
};
|
|
|
|
|
2018-05-31 04:11:52 +08:00
|
|
|
static void nfs_do_call_unlink(struct inode *inode, struct nfs_unlinkdata *data)
|
2007-07-15 03:39:58 +08:00
|
|
|
{
|
2007-07-15 03:40:01 +08:00
|
|
|
struct rpc_message msg = {
|
|
|
|
.rpc_argp = &data->args,
|
|
|
|
.rpc_resp = &data->res,
|
|
|
|
.rpc_cred = data->cred,
|
|
|
|
};
|
2007-07-15 03:39:59 +08:00
|
|
|
struct rpc_task_setup task_setup_data = {
|
2007-07-15 03:40:01 +08:00
|
|
|
.rpc_message = &msg,
|
2007-07-15 03:39:59 +08:00
|
|
|
.callback_ops = &nfs_unlink_ops,
|
|
|
|
.callback_data = data,
|
2008-07-28 06:19:01 +08:00
|
|
|
.workqueue = nfsiod_workqueue,
|
2007-07-15 03:39:59 +08:00
|
|
|
.flags = RPC_TASK_ASYNC,
|
|
|
|
};
|
2007-07-15 03:39:58 +08:00
|
|
|
struct rpc_task *task;
|
2016-04-29 11:56:31 +08:00
|
|
|
struct inode *dir = d_inode(data->dentry->d_parent);
|
|
|
|
nfs_sb_active(dir->i_sb);
|
|
|
|
data->args.fh = NFS_FH(dir);
|
|
|
|
nfs_fattr_init(data->res.dir_attr);
|
|
|
|
|
2018-05-31 04:11:52 +08:00
|
|
|
NFS_PROTO(dir)->unlink_setup(&msg, data->dentry, inode);
|
2016-04-29 11:56:31 +08:00
|
|
|
|
|
|
|
task_setup_data.rpc_client = NFS_CLIENT(dir);
|
|
|
|
task = rpc_run_task(&task_setup_data);
|
|
|
|
if (!IS_ERR(task))
|
|
|
|
rpc_put_task_async(task);
|
|
|
|
}
|
|
|
|
|
2018-05-31 04:11:52 +08:00
|
|
|
static int nfs_call_unlink(struct dentry *dentry, struct inode *inode, struct nfs_unlinkdata *data)
|
2016-04-29 11:56:31 +08:00
|
|
|
{
|
|
|
|
struct inode *dir = d_inode(dentry->d_parent);
|
2007-10-16 06:17:53 +08:00
|
|
|
struct dentry *alias;
|
|
|
|
|
2016-04-29 11:56:31 +08:00
|
|
|
down_read_non_owner(&NFS_I(dir)->rmdir_sem);
|
|
|
|
alias = d_alloc_parallel(dentry->d_parent, &data->args.name, &data->wq);
|
|
|
|
if (IS_ERR(alias)) {
|
|
|
|
up_read_non_owner(&NFS_I(dir)->rmdir_sem);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!d_in_lookup(alias)) {
|
2011-07-18 23:26:30 +08:00
|
|
|
int ret;
|
2011-03-16 17:44:14 +08:00
|
|
|
void *devname_garbage = NULL;
|
2008-01-29 08:42:59 +08:00
|
|
|
|
2007-10-16 06:17:53 +08:00
|
|
|
/*
|
|
|
|
* Hey, we raced with lookup... See if we need to transfer
|
|
|
|
* the sillyrename information to the aliased dentry.
|
|
|
|
*/
|
|
|
|
spin_lock(&alias->d_lock);
|
2016-04-29 11:56:31 +08:00
|
|
|
if (d_really_is_positive(alias) &&
|
2008-01-29 08:42:59 +08:00
|
|
|
!(alias->d_flags & DCACHE_NFSFS_RENAMED)) {
|
2011-03-16 17:44:14 +08:00
|
|
|
devname_garbage = alias->d_fsdata;
|
2007-10-16 06:17:53 +08:00
|
|
|
alias->d_fsdata = data;
|
2008-01-27 06:37:47 +08:00
|
|
|
alias->d_flags |= DCACHE_NFSFS_RENAMED;
|
2007-10-16 06:17:53 +08:00
|
|
|
ret = 1;
|
2011-07-18 23:26:30 +08:00
|
|
|
} else
|
|
|
|
ret = 0;
|
2007-10-16 06:17:53 +08:00
|
|
|
spin_unlock(&alias->d_lock);
|
|
|
|
dput(alias);
|
2016-04-29 11:56:31 +08:00
|
|
|
up_read_non_owner(&NFS_I(dir)->rmdir_sem);
|
2011-03-16 17:44:14 +08:00
|
|
|
/*
|
|
|
|
* If we'd displaced old cached devname, free it. At that
|
|
|
|
* point dentry is definitely not a root, so we won't need
|
|
|
|
* that anymore.
|
|
|
|
*/
|
2011-07-18 23:26:30 +08:00
|
|
|
kfree(devname_garbage);
|
2007-10-16 06:17:53 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2016-04-29 11:56:31 +08:00
|
|
|
data->dentry = alias;
|
2018-05-31 04:11:52 +08:00
|
|
|
nfs_do_call_unlink(inode, data);
|
2007-10-16 06:17:53 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* nfs_async_unlink - asynchronous unlinking of a file
|
2019-02-19 02:32:38 +08:00
|
|
|
* @dentry: parent directory of dentry
|
|
|
|
* @name: name of dentry to unlink
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2010-09-18 05:31:30 +08:00
|
|
|
static int
|
2016-07-21 04:34:42 +08:00
|
|
|
nfs_async_unlink(struct dentry *dentry, const struct qstr *name)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-07-15 03:39:58 +08:00
|
|
|
struct nfs_unlinkdata *data;
|
|
|
|
int status = -ENOMEM;
|
2011-03-16 17:44:14 +08:00
|
|
|
void *devname_garbage = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-21 02:44:10 +08:00
|
|
|
data = kzalloc(sizeof(*data), GFP_KERNEL);
|
2007-07-15 03:39:58 +08:00
|
|
|
if (data == NULL)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto out;
|
2016-04-29 11:56:31 +08:00
|
|
|
data->args.name.name = kstrdup(name->name, GFP_KERNEL);
|
|
|
|
if (!data->args.name.name)
|
|
|
|
goto out_free;
|
|
|
|
data->args.name.len = name->len;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-12-03 08:30:31 +08:00
|
|
|
data->cred = get_current_cred();
|
2010-04-17 04:22:50 +08:00
|
|
|
data->res.dir_attr = &data->dir_attr;
|
2016-04-29 11:56:31 +08:00
|
|
|
init_waitqueue_head(&data->wq);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-07-15 03:39:58 +08:00
|
|
|
status = -EBUSY;
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock(&dentry->d_lock);
|
2007-07-15 03:39:58 +08:00
|
|
|
if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
|
|
|
|
goto out_unlock;
|
2005-04-17 06:20:36 +08:00
|
|
|
dentry->d_flags |= DCACHE_NFSFS_RENAMED;
|
2011-03-16 17:44:14 +08:00
|
|
|
devname_garbage = dentry->d_fsdata;
|
2007-07-15 03:39:58 +08:00
|
|
|
dentry->d_fsdata = data;
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock(&dentry->d_lock);
|
2011-03-16 17:44:14 +08:00
|
|
|
/*
|
|
|
|
* If we'd displaced old cached devname, free it. At that
|
|
|
|
* point dentry is definitely not a root, so we won't need
|
|
|
|
* that anymore.
|
|
|
|
*/
|
2013-02-13 04:03:42 +08:00
|
|
|
kfree(devname_garbage);
|
2007-07-15 03:39:58 +08:00
|
|
|
return 0;
|
|
|
|
out_unlock:
|
|
|
|
spin_unlock(&dentry->d_lock);
|
2018-12-03 08:30:31 +08:00
|
|
|
put_cred(data->cred);
|
2016-04-29 11:56:31 +08:00
|
|
|
kfree(data->args.name.name);
|
2005-04-17 06:20:36 +08:00
|
|
|
out_free:
|
|
|
|
kfree(data);
|
2007-07-15 03:39:58 +08:00
|
|
|
out:
|
2005-04-17 06:20:36 +08:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nfs_complete_unlink - Initialize completion of the sillydelete
|
|
|
|
* @dentry: dentry to delete
|
2007-07-15 03:39:58 +08:00
|
|
|
* @inode: inode
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Since we're most likely to be called by dentry_iput(), we
|
|
|
|
* only use the dentry to find the sillydelete. We then copy the name
|
|
|
|
* into the qstr.
|
|
|
|
*/
|
|
|
|
void
|
2007-07-15 03:39:58 +08:00
|
|
|
nfs_complete_unlink(struct dentry *dentry, struct inode *inode)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2016-04-29 11:56:31 +08:00
|
|
|
struct nfs_unlinkdata *data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock(&dentry->d_lock);
|
2016-04-29 11:56:31 +08:00
|
|
|
dentry->d_flags &= ~DCACHE_NFSFS_RENAMED;
|
|
|
|
data = dentry->d_fsdata;
|
|
|
|
dentry->d_fsdata = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock(&dentry->d_lock);
|
2007-07-15 03:39:58 +08:00
|
|
|
|
2018-05-31 04:11:52 +08:00
|
|
|
if (NFS_STALE(inode) || !nfs_call_unlink(dentry, inode, data))
|
2007-07-15 03:39:58 +08:00
|
|
|
nfs_free_unlinkdata(data);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-09-18 05:31:30 +08:00
|
|
|
|
2010-09-18 05:31:57 +08:00
|
|
|
/* Cancel a queued async unlink. Called when a sillyrename run fails. */
|
|
|
|
static void
|
|
|
|
nfs_cancel_async_unlink(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
spin_lock(&dentry->d_lock);
|
|
|
|
if (dentry->d_flags & DCACHE_NFSFS_RENAMED) {
|
|
|
|
struct nfs_unlinkdata *data = dentry->d_fsdata;
|
|
|
|
|
|
|
|
dentry->d_flags &= ~DCACHE_NFSFS_RENAMED;
|
2011-03-16 17:44:14 +08:00
|
|
|
dentry->d_fsdata = NULL;
|
2010-09-18 05:31:57 +08:00
|
|
|
spin_unlock(&dentry->d_lock);
|
|
|
|
nfs_free_unlinkdata(data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
spin_unlock(&dentry->d_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nfs_async_rename_done - Sillyrename post-processing
|
|
|
|
* @task: rpc_task of the sillyrename
|
|
|
|
* @calldata: nfs_renamedata for the sillyrename
|
|
|
|
*
|
|
|
|
* Do the directory attribute updates and the d_move
|
|
|
|
*/
|
|
|
|
static void nfs_async_rename_done(struct rpc_task *task, void *calldata)
|
|
|
|
{
|
|
|
|
struct nfs_renamedata *data = calldata;
|
|
|
|
struct inode *old_dir = data->old_dir;
|
|
|
|
struct inode *new_dir = data->new_dir;
|
2011-07-18 23:26:30 +08:00
|
|
|
struct dentry *old_dentry = data->old_dentry;
|
2010-09-18 05:31:57 +08:00
|
|
|
|
2013-08-22 00:08:45 +08:00
|
|
|
trace_nfs_sillyrename_rename(old_dir, old_dentry,
|
|
|
|
new_dir, data->new_dentry, task->tk_status);
|
2010-09-18 05:31:57 +08:00
|
|
|
if (!NFS_PROTO(old_dir)->rename_done(task, old_dir, new_dir)) {
|
2011-10-20 03:17:29 +08:00
|
|
|
rpc_restart_call_prepare(task);
|
2010-09-18 05:31:57 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-17 19:06:54 +08:00
|
|
|
if (data->complete)
|
|
|
|
data->complete(task, data);
|
2010-09-18 05:31:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nfs_async_rename_release - Release the sillyrename data.
|
|
|
|
* @calldata: the struct nfs_renamedata to be released
|
|
|
|
*/
|
|
|
|
static void nfs_async_rename_release(void *calldata)
|
|
|
|
{
|
|
|
|
struct nfs_renamedata *data = calldata;
|
|
|
|
struct super_block *sb = data->old_dir->i_sb;
|
|
|
|
|
2015-03-18 06:25:59 +08:00
|
|
|
if (d_really_is_positive(data->old_dentry))
|
|
|
|
nfs_mark_for_revalidate(d_inode(data->old_dentry));
|
2010-09-18 05:31:57 +08:00
|
|
|
|
2017-06-16 23:13:00 +08:00
|
|
|
/* The result of the rename is unknown. Play it safe by
|
|
|
|
* forcing a new lookup */
|
|
|
|
if (data->cancelled) {
|
|
|
|
spin_lock(&data->old_dir->i_lock);
|
|
|
|
nfs_force_lookup_revalidate(data->old_dir);
|
|
|
|
spin_unlock(&data->old_dir->i_lock);
|
|
|
|
if (data->new_dir != data->old_dir) {
|
|
|
|
spin_lock(&data->new_dir->i_lock);
|
|
|
|
nfs_force_lookup_revalidate(data->new_dir);
|
|
|
|
spin_unlock(&data->new_dir->i_lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-18 05:31:57 +08:00
|
|
|
dput(data->old_dentry);
|
|
|
|
dput(data->new_dentry);
|
|
|
|
iput(data->old_dir);
|
|
|
|
iput(data->new_dir);
|
|
|
|
nfs_sb_deactive(sb);
|
2018-12-03 08:30:31 +08:00
|
|
|
put_cred(data->cred);
|
2010-09-18 05:31:57 +08:00
|
|
|
kfree(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nfs_rename_prepare(struct rpc_task *task, void *calldata)
|
|
|
|
{
|
|
|
|
struct nfs_renamedata *data = calldata;
|
2012-03-20 02:54:42 +08:00
|
|
|
NFS_PROTO(data->old_dir)->rename_rpc_prepare(task, data);
|
2010-09-18 05:31:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct rpc_call_ops nfs_rename_ops = {
|
|
|
|
.rpc_call_done = nfs_async_rename_done,
|
|
|
|
.rpc_release = nfs_async_rename_release,
|
|
|
|
.rpc_call_prepare = nfs_rename_prepare,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nfs_async_rename - perform an asynchronous rename operation
|
|
|
|
* @old_dir: directory that currently holds the dentry to be renamed
|
|
|
|
* @new_dir: target directory for the rename
|
|
|
|
* @old_dentry: original dentry to be renamed
|
|
|
|
* @new_dentry: dentry to which the old_dentry should be renamed
|
2019-02-19 02:32:38 +08:00
|
|
|
* @complete: Function to run on successful completion
|
2010-09-18 05:31:57 +08:00
|
|
|
*
|
|
|
|
* It's expected that valid references to the dentries and inodes are held
|
|
|
|
*/
|
2014-03-17 19:06:55 +08:00
|
|
|
struct rpc_task *
|
2010-09-18 05:31:57 +08:00
|
|
|
nfs_async_rename(struct inode *old_dir, struct inode *new_dir,
|
2014-03-17 19:06:54 +08:00
|
|
|
struct dentry *old_dentry, struct dentry *new_dentry,
|
|
|
|
void (*complete)(struct rpc_task *, struct nfs_renamedata *))
|
2010-09-18 05:31:57 +08:00
|
|
|
{
|
|
|
|
struct nfs_renamedata *data;
|
|
|
|
struct rpc_message msg = { };
|
|
|
|
struct rpc_task_setup task_setup_data = {
|
|
|
|
.rpc_message = &msg,
|
|
|
|
.callback_ops = &nfs_rename_ops,
|
|
|
|
.workqueue = nfsiod_workqueue,
|
|
|
|
.rpc_client = NFS_CLIENT(old_dir),
|
|
|
|
.flags = RPC_TASK_ASYNC,
|
|
|
|
};
|
|
|
|
|
2010-09-24 21:17:01 +08:00
|
|
|
data = kzalloc(sizeof(*data), GFP_KERNEL);
|
2010-09-18 05:31:57 +08:00
|
|
|
if (data == NULL)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
2010-12-21 23:52:24 +08:00
|
|
|
task_setup_data.callback_data = data;
|
2010-09-18 05:31:57 +08:00
|
|
|
|
2018-12-03 08:30:31 +08:00
|
|
|
data->cred = get_current_cred();
|
2010-09-18 05:31:57 +08:00
|
|
|
|
|
|
|
msg.rpc_argp = &data->args;
|
|
|
|
msg.rpc_resp = &data->res;
|
|
|
|
msg.rpc_cred = data->cred;
|
|
|
|
|
|
|
|
/* set up nfs_renamedata */
|
|
|
|
data->old_dir = old_dir;
|
2010-10-27 23:00:08 +08:00
|
|
|
ihold(old_dir);
|
2010-09-18 05:31:57 +08:00
|
|
|
data->new_dir = new_dir;
|
2010-10-27 23:00:08 +08:00
|
|
|
ihold(new_dir);
|
2010-09-18 05:31:57 +08:00
|
|
|
data->old_dentry = dget(old_dentry);
|
|
|
|
data->new_dentry = dget(new_dentry);
|
|
|
|
nfs_fattr_init(&data->old_fattr);
|
|
|
|
nfs_fattr_init(&data->new_fattr);
|
2014-03-17 19:06:54 +08:00
|
|
|
data->complete = complete;
|
2010-09-18 05:31:57 +08:00
|
|
|
|
|
|
|
/* set up nfs_renameargs */
|
|
|
|
data->args.old_dir = NFS_FH(old_dir);
|
|
|
|
data->args.old_name = &old_dentry->d_name;
|
|
|
|
data->args.new_dir = NFS_FH(new_dir);
|
|
|
|
data->args.new_name = &new_dentry->d_name;
|
|
|
|
|
|
|
|
/* set up nfs_renameres */
|
|
|
|
data->res.old_fattr = &data->old_fattr;
|
|
|
|
data->res.new_fattr = &data->new_fattr;
|
|
|
|
|
|
|
|
nfs_sb_active(old_dir->i_sb);
|
|
|
|
|
2018-03-21 04:43:16 +08:00
|
|
|
NFS_PROTO(data->old_dir)->rename_setup(&msg, old_dentry, new_dentry);
|
2010-09-18 05:31:57 +08:00
|
|
|
|
2010-09-22 04:52:40 +08:00
|
|
|
return rpc_run_task(&task_setup_data);
|
2010-09-18 05:31:57 +08:00
|
|
|
}
|
|
|
|
|
2014-03-17 19:06:54 +08:00
|
|
|
/*
|
|
|
|
* Perform tasks needed when a sillyrename is done such as cancelling the
|
|
|
|
* queued async unlink if it failed.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
nfs_complete_sillyrename(struct rpc_task *task, struct nfs_renamedata *data)
|
|
|
|
{
|
2014-03-17 19:06:58 +08:00
|
|
|
struct dentry *dentry = data->old_dentry;
|
|
|
|
|
|
|
|
if (task->tk_status != 0) {
|
|
|
|
nfs_cancel_async_unlink(dentry);
|
|
|
|
return;
|
|
|
|
}
|
2014-03-17 19:06:54 +08:00
|
|
|
}
|
|
|
|
|
2013-08-22 07:54:08 +08:00
|
|
|
#define SILLYNAME_PREFIX ".nfs"
|
|
|
|
#define SILLYNAME_PREFIX_LEN ((unsigned)sizeof(SILLYNAME_PREFIX) - 1)
|
|
|
|
#define SILLYNAME_FILEID_LEN ((unsigned)sizeof(u64) << 1)
|
|
|
|
#define SILLYNAME_COUNTER_LEN ((unsigned)sizeof(unsigned int) << 1)
|
|
|
|
#define SILLYNAME_LEN (SILLYNAME_PREFIX_LEN + \
|
|
|
|
SILLYNAME_FILEID_LEN + \
|
|
|
|
SILLYNAME_COUNTER_LEN)
|
|
|
|
|
2010-09-18 05:31:30 +08:00
|
|
|
/**
|
|
|
|
* nfs_sillyrename - Perform a silly-rename of a dentry
|
|
|
|
* @dir: inode of directory that contains dentry
|
|
|
|
* @dentry: dentry to be sillyrenamed
|
|
|
|
*
|
|
|
|
* NFSv2/3 is stateless and the server doesn't know when the client is
|
|
|
|
* holding a file open. To prevent application problems when a file is
|
|
|
|
* unlinked while it's still open, the client performs a "silly-rename".
|
|
|
|
* That is, it renames the file to a hidden file in the same directory,
|
|
|
|
* and only performs the unlink once the last reference to it is put.
|
|
|
|
*
|
|
|
|
* The final cleanup is done during dentry_iput.
|
2011-07-16 07:09:08 +08:00
|
|
|
*
|
|
|
|
* (Note: NFSv4 is stateful, and has opens, so in theory an NFSv4 server
|
|
|
|
* could take responsibility for keeping open files referenced. The server
|
|
|
|
* would also need to ensure that opened-but-deleted files were kept over
|
|
|
|
* reboots. However, we may not assume a server does so. (RFC 5661
|
|
|
|
* does provide an OPEN4_RESULT_PRESERVE_UNLINKED flag that a server can
|
|
|
|
* use to advertise that it does this; some day we may take advantage of
|
|
|
|
* it.))
|
2010-09-18 05:31:30 +08:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
nfs_sillyrename(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
|
|
|
static unsigned int sillycounter;
|
2013-08-22 07:54:08 +08:00
|
|
|
unsigned char silly[SILLYNAME_LEN + 1];
|
|
|
|
unsigned long long fileid;
|
2010-09-18 05:31:30 +08:00
|
|
|
struct dentry *sdentry;
|
2018-04-10 02:11:32 +08:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2010-09-18 05:31:57 +08:00
|
|
|
struct rpc_task *task;
|
2013-10-12 04:15:54 +08:00
|
|
|
int error = -EBUSY;
|
2010-09-18 05:31:30 +08:00
|
|
|
|
2013-09-16 22:53:17 +08:00
|
|
|
dfprintk(VFS, "NFS: silly-rename(%pd2, ct=%d)\n",
|
|
|
|
dentry, d_count(dentry));
|
2010-09-18 05:31:30 +08:00
|
|
|
nfs_inc_stats(dir, NFSIOS_SILLYRENAME);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We don't allow a dentry to be silly-renamed twice.
|
|
|
|
*/
|
|
|
|
if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
|
|
|
|
goto out;
|
|
|
|
|
2015-03-18 06:25:59 +08:00
|
|
|
fileid = NFS_FILEID(d_inode(dentry));
|
2010-09-18 05:31:30 +08:00
|
|
|
|
|
|
|
sdentry = NULL;
|
|
|
|
do {
|
2013-08-22 07:54:08 +08:00
|
|
|
int slen;
|
2010-09-18 05:31:30 +08:00
|
|
|
dput(sdentry);
|
|
|
|
sillycounter++;
|
2013-08-22 07:54:08 +08:00
|
|
|
slen = scnprintf(silly, sizeof(silly),
|
|
|
|
SILLYNAME_PREFIX "%0*llx%0*x",
|
|
|
|
SILLYNAME_FILEID_LEN, fileid,
|
|
|
|
SILLYNAME_COUNTER_LEN, sillycounter);
|
2010-09-18 05:31:30 +08:00
|
|
|
|
2013-09-16 22:53:17 +08:00
|
|
|
dfprintk(VFS, "NFS: trying to rename %pd to %s\n",
|
|
|
|
dentry, silly);
|
2010-09-18 05:31:30 +08:00
|
|
|
|
|
|
|
sdentry = lookup_one_len(silly, dentry->d_parent, slen);
|
|
|
|
/*
|
|
|
|
* N.B. Better to return EBUSY here ... it could be
|
|
|
|
* dangerous to delete the file while it's in use.
|
|
|
|
*/
|
|
|
|
if (IS_ERR(sdentry))
|
|
|
|
goto out;
|
2015-03-18 06:25:59 +08:00
|
|
|
} while (d_inode(sdentry) != NULL); /* need negative lookup */
|
2010-09-18 05:31:30 +08:00
|
|
|
|
2018-04-10 02:11:32 +08:00
|
|
|
ihold(inode);
|
|
|
|
|
2010-09-18 05:31:57 +08:00
|
|
|
/* queue unlink first. Can't do this from rpc_release as it
|
|
|
|
* has to allocate memory
|
|
|
|
*/
|
2016-04-29 11:56:31 +08:00
|
|
|
error = nfs_async_unlink(dentry, &sdentry->d_name);
|
2010-09-18 05:31:57 +08:00
|
|
|
if (error)
|
|
|
|
goto out_dput;
|
|
|
|
|
|
|
|
/* run the rename task, undo unlink if it fails */
|
2014-03-17 19:06:54 +08:00
|
|
|
task = nfs_async_rename(dir, dir, dentry, sdentry,
|
|
|
|
nfs_complete_sillyrename);
|
2010-09-18 05:31:57 +08:00
|
|
|
if (IS_ERR(task)) {
|
|
|
|
error = -EBUSY;
|
|
|
|
nfs_cancel_async_unlink(dentry);
|
|
|
|
goto out_dput;
|
2010-09-18 05:31:30 +08:00
|
|
|
}
|
2010-09-18 05:31:57 +08:00
|
|
|
|
|
|
|
/* wait for the RPC task to complete, unless a SIGKILL intervenes */
|
|
|
|
error = rpc_wait_for_completion_task(task);
|
|
|
|
if (error == 0)
|
|
|
|
error = task->tk_status;
|
NFS: Don't allow NFS silly-renamed files to be deleted, no signal
Commit 73ca100 broke the code that prevents the client from deleting
a silly renamed dentry. This affected "delete on last close"
semantics as after that commit, nothing prevented removal of
silly-renamed files. As a result, a process holding a file open
could easily get an ESTALE on the file in a directory where some
other process issued 'rm -rf some_dir_containing_the_file' twice.
Before the commit, any attempt at unlinking silly renamed files would
fail inside may_delete() with -EBUSY because of the
DCACHE_NFSFS_RENAMED flag. The following testcase demonstrates
the problem:
tail -f /nfsmnt/dir/file &
rm -rf /nfsmnt/dir
rm -rf /nfsmnt/dir
# second removal does not fail, 'tail' process receives ESTALE
The problem with the above commit is that it unhashes the old and
new dentries from the lookup path, even in the normal case when
a signal is not encountered and it would have been safe to call
d_move. Unfortunately the old dentry has the special
DCACHE_NFSFS_RENAMED flag set on it. Unhashing has the
side-effect that future lookups call d_alloc(), allocating a new
dentry without the special flag for any silly-renamed files. As a
result, subsequent calls to unlink silly renamed files do not fail
but allow the removal to go through. This will result in ESTALE
errors for any other process doing operations on the file.
To fix this, go back to using d_move on success.
For the signal case, it's unclear what we may safely do beyond d_drop.
Reported-by: Dave Wysochanski <dwysocha@redhat.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Acked-by: Jeff Layton <jlayton@redhat.com>
Cc: stable@vger.kernel.org
2013-02-23 01:53:43 +08:00
|
|
|
switch (error) {
|
|
|
|
case 0:
|
|
|
|
/* The rename succeeded */
|
|
|
|
nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
|
2018-04-10 02:11:32 +08:00
|
|
|
spin_lock(&inode->i_lock);
|
|
|
|
NFS_I(inode)->attr_gencount = nfs_inc_attr_generation_counter();
|
|
|
|
NFS_I(inode)->cache_validity |= NFS_INO_INVALID_CHANGE
|
|
|
|
| NFS_INO_INVALID_CTIME
|
|
|
|
| NFS_INO_REVAL_FORCED;
|
|
|
|
spin_unlock(&inode->i_lock);
|
NFS: Don't allow NFS silly-renamed files to be deleted, no signal
Commit 73ca100 broke the code that prevents the client from deleting
a silly renamed dentry. This affected "delete on last close"
semantics as after that commit, nothing prevented removal of
silly-renamed files. As a result, a process holding a file open
could easily get an ESTALE on the file in a directory where some
other process issued 'rm -rf some_dir_containing_the_file' twice.
Before the commit, any attempt at unlinking silly renamed files would
fail inside may_delete() with -EBUSY because of the
DCACHE_NFSFS_RENAMED flag. The following testcase demonstrates
the problem:
tail -f /nfsmnt/dir/file &
rm -rf /nfsmnt/dir
rm -rf /nfsmnt/dir
# second removal does not fail, 'tail' process receives ESTALE
The problem with the above commit is that it unhashes the old and
new dentries from the lookup path, even in the normal case when
a signal is not encountered and it would have been safe to call
d_move. Unfortunately the old dentry has the special
DCACHE_NFSFS_RENAMED flag set on it. Unhashing has the
side-effect that future lookups call d_alloc(), allocating a new
dentry without the special flag for any silly-renamed files. As a
result, subsequent calls to unlink silly renamed files do not fail
but allow the removal to go through. This will result in ESTALE
errors for any other process doing operations on the file.
To fix this, go back to using d_move on success.
For the signal case, it's unclear what we may safely do beyond d_drop.
Reported-by: Dave Wysochanski <dwysocha@redhat.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Acked-by: Jeff Layton <jlayton@redhat.com>
Cc: stable@vger.kernel.org
2013-02-23 01:53:43 +08:00
|
|
|
d_move(dentry, sdentry);
|
|
|
|
break;
|
|
|
|
case -ERESTARTSYS:
|
|
|
|
/* The result of the rename is unknown. Play it safe by
|
|
|
|
* forcing a new lookup */
|
|
|
|
d_drop(dentry);
|
|
|
|
d_drop(sdentry);
|
|
|
|
}
|
2010-09-18 05:31:57 +08:00
|
|
|
rpc_put_task(task);
|
|
|
|
out_dput:
|
2018-04-10 02:11:32 +08:00
|
|
|
iput(inode);
|
2010-09-18 05:31:30 +08:00
|
|
|
dput(sdentry);
|
|
|
|
out:
|
|
|
|
return error;
|
|
|
|
}
|