Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Commit

Permalink
Remove vn_rename and vn_remove
Browse files Browse the repository at this point in the history
Both vn_rename and vn_remove have been historically problematic
to implement reliably.  Rather than fixing them yet again they
are being removed.

Reviewed-by: Arkadiusz Bubala <arkadiusz.bubala@open-e.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #648
Closes #661
  • Loading branch information
behlendorf authored and tonyhutter committed Mar 14, 2018
1 parent cbf0dff commit 1cb26f0
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 416 deletions.
101 changes: 0 additions & 101 deletions config/spl-build.m4
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ AC_DEFUN([SPL_AC_CONFIG_KERNEL], [
SPL_AC_CONFIG_TRIM_UNUSED_KSYMS
SPL_AC_PDE_DATA
SPL_AC_SET_FS_PWD_WITH_CONST
SPL_AC_2ARGS_VFS_UNLINK
SPL_AC_4ARGS_VFS_RENAME
SPL_AC_2ARGS_VFS_FSYNC
SPL_AC_INODE_TRUNCATE_RANGE
SPL_AC_FS_STRUCT_SPINLOCK
Expand Down Expand Up @@ -936,105 +934,6 @@ AC_DEFUN([SPL_AC_SET_FS_PWD_WITH_CONST],
EXTRA_KCFLAGS="$tmp_flags"
])

dnl #
dnl # 3.13 API change
dnl # vfs_unlink() updated to take a third delegated_inode argument.
dnl #
AC_DEFUN([SPL_AC_2ARGS_VFS_UNLINK],
[AC_MSG_CHECKING([whether vfs_unlink() wants 2 args])
SPL_LINUX_TRY_COMPILE([
#include <linux/fs.h>
],[
vfs_unlink((struct inode *) NULL, (struct dentry *) NULL);
],[
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_2ARGS_VFS_UNLINK, 1,
[vfs_unlink() wants 2 args])
],[
AC_MSG_RESULT(no)
dnl #
dnl # Linux 3.13 API change
dnl # Added delegated inode
dnl #
AC_MSG_CHECKING([whether vfs_unlink() wants 3 args])
SPL_LINUX_TRY_COMPILE([
#include <linux/fs.h>
],[
vfs_unlink((struct inode *) NULL,
(struct dentry *) NULL,
(struct inode **) NULL);
],[
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_3ARGS_VFS_UNLINK, 1,
[vfs_unlink() wants 3 args])
],[
AC_MSG_ERROR(no)
])
])
])

dnl #
dnl # 3.13 and 3.15 API changes
dnl # Added delegated inode and flags argument.
dnl #
AC_DEFUN([SPL_AC_4ARGS_VFS_RENAME],
[AC_MSG_CHECKING([whether vfs_rename() wants 4 args])
SPL_LINUX_TRY_COMPILE([
#include <linux/fs.h>
],[
vfs_rename((struct inode *) NULL, (struct dentry *) NULL,
(struct inode *) NULL, (struct dentry *) NULL);
],[
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_4ARGS_VFS_RENAME, 1,
[vfs_rename() wants 4 args])
],[
AC_MSG_RESULT(no)
dnl #
dnl # Linux 3.13 API change
dnl # Added delegated inode
dnl #
AC_MSG_CHECKING([whether vfs_rename() wants 5 args])
SPL_LINUX_TRY_COMPILE([
#include <linux/fs.h>
],[
vfs_rename((struct inode *) NULL,
(struct dentry *) NULL,
(struct inode *) NULL,
(struct dentry *) NULL,
(struct inode **) NULL);
],[
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_5ARGS_VFS_RENAME, 1,
[vfs_rename() wants 5 args])
],[
AC_MSG_RESULT(no)
dnl #
dnl # Linux 3.15 API change
dnl # Added flags
dnl #
AC_MSG_CHECKING([whether vfs_rename() wants 6 args])
SPL_LINUX_TRY_COMPILE([
#include <linux/fs.h>
],[
vfs_rename((struct inode *) NULL,
(struct dentry *) NULL,
(struct inode *) NULL,
(struct dentry *) NULL,
(struct inode **) NULL,
(unsigned int) 0);
],[
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_6ARGS_VFS_RENAME, 1,
[vfs_rename() wants 6 args])
],[
AC_MSG_ERROR(no)
])
])
])
])

dnl #
dnl # 2.6.36 API change,
dnl # The 'struct fs_struct->lock' was changed from a rwlock_t to
Expand Down
2 changes: 0 additions & 2 deletions include/sys/vnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ extern int vn_rdwr(uio_rw_t uio, vnode_t *vp, void *addr, ssize_t len,
extern int vn_close(vnode_t *vp, int flags, int x1, int x2, void *x3, void *x4);
extern int vn_seek(vnode_t *vp, offset_t o, offset_t *op, void *ct);

extern int vn_remove(const char *path, uio_seg_t seg, int flags);
extern int vn_rename(const char *path1, const char *path2, int x1);
extern int vn_getattr(vnode_t *vp, vattr_t *vap, int flags, void *x3, void *x4);
extern int vn_fsync(vnode_t *vp, int flags, void *x3, void *x4);
extern int vn_space(vnode_t *vp, int cmd, struct flock *bfp, int flag,
Expand Down
217 changes: 0 additions & 217 deletions module/spl/spl-vnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,223 +269,6 @@ vn_seek(vnode_t *vp, offset_t ooff, offset_t *noffp, void *ct)
}
EXPORT_SYMBOL(vn_seek);

/*
* spl_basename() takes a NULL-terminated string s as input containing a path.
* It returns a char pointer to a string and a length that describe the
* basename of the path. If the basename is not "." or "/", it will be an index
* into the string. While the string should be NULL terminated, the section
* referring to the basename is not. spl_basename is dual-licensed GPLv2+ and
* CC0. Anyone wishing to reuse it in another codebase may pick either license.
*/
static void
spl_basename(const char *s, const char **str, int *len)
{
size_t i, end;

ASSERT(str);
ASSERT(len);

if (!s || !*s) {
*str = ".";
*len = 1;
return;
}

i = strlen(s) - 1;

while (i && s[i--] == '/');

if (i == 0) {
*str = "/";
*len = 1;
return;
}

end = i;

for (end = i; i; i--) {
if (s[i] == '/') {
*str = &s[i+1];
*len = end - i + 1;
return;
}
}

*str = s;
*len = end + 1;
}

static struct dentry *
spl_kern_path_locked(const char *name, struct path *path)
{
struct path parent;
struct dentry *dentry;
const char *basename;
int len;
int rc;

ASSERT(name);
ASSERT(path);

spl_basename(name, &basename, &len);

/* We do not accept "." or ".." */
if (len <= 2 && basename[0] == '.')
if (len == 1 || basename[1] == '.')
return (ERR_PTR(-EACCES));

rc = kern_path(name, LOOKUP_PARENT, &parent);
if (rc)
return (ERR_PTR(rc));

/* use I_MUTEX_PARENT because vfs_unlink needs it */
spl_inode_lock_nested(parent.dentry->d_inode, I_MUTEX_PARENT);

dentry = lookup_one_len(basename, parent.dentry, len);
if (IS_ERR(dentry)) {
spl_inode_unlock(parent.dentry->d_inode);
path_put(&parent);
} else {
*path = parent;
}

return (dentry);
}

/* Based on do_unlinkat() from linux/fs/namei.c */
int
vn_remove(const char *path, uio_seg_t seg, int flags)
{
struct dentry *dentry;
struct path parent;
struct inode *inode = NULL;
int rc = 0;

ASSERT(seg == UIO_SYSSPACE);
ASSERT(flags == RMFILE);

dentry = spl_kern_path_locked(path, &parent);
rc = PTR_ERR(dentry);
if (!IS_ERR(dentry)) {
if (parent.dentry->d_name.name[parent.dentry->d_name.len]) {
rc = 0;
goto slashes;
}

inode = dentry->d_inode;
if (inode) {
atomic_inc(&inode->i_count);
} else {
rc = 0;
goto slashes;
}

#ifdef HAVE_2ARGS_VFS_UNLINK
rc = vfs_unlink(parent.dentry->d_inode, dentry);
#else
rc = vfs_unlink(parent.dentry->d_inode, dentry, NULL);
#endif /* HAVE_2ARGS_VFS_UNLINK */
exit1:
dput(dentry);
} else {
return (-rc);
}

spl_inode_unlock(parent.dentry->d_inode);
if (inode)
iput(inode); /* truncate the inode here */

path_put(&parent);
return (-rc);

slashes:
rc = !dentry->d_inode ? -ENOENT :
S_ISDIR(dentry->d_inode->i_mode) ? -EISDIR : -ENOTDIR;
goto exit1;
} /* vn_remove() */
EXPORT_SYMBOL(vn_remove);

/* Based on do_rename() from linux/fs/namei.c */
int
vn_rename(const char *oldname, const char *newname, int x1)
{
struct dentry *old_dir, *new_dir;
struct dentry *old_dentry, *new_dentry;
struct dentry *trap;
struct path old_parent, new_parent;
int rc = 0;

old_dentry = spl_kern_path_locked(oldname, &old_parent);
if (IS_ERR(old_dentry)) {
rc = PTR_ERR(old_dentry);
goto exit;
}

spl_inode_unlock(old_parent.dentry->d_inode);

new_dentry = spl_kern_path_locked(newname, &new_parent);
if (IS_ERR(new_dentry)) {
rc = PTR_ERR(new_dentry);
goto exit2;
}

spl_inode_unlock(new_parent.dentry->d_inode);

rc = -EXDEV;
if (old_parent.mnt != new_parent.mnt)
goto exit3;

old_dir = old_parent.dentry;
new_dir = new_parent.dentry;
trap = lock_rename(new_dir, old_dir);

/* source should not be ancestor of target */
rc = -EINVAL;
if (old_dentry == trap)
goto exit4;

/* target should not be an ancestor of source */
rc = -ENOTEMPTY;
if (new_dentry == trap)
goto exit4;

/* source must exist */
rc = -ENOENT;
if (!old_dentry->d_inode)
goto exit4;

/* unless the source is a directory trailing slashes give -ENOTDIR */
if (!S_ISDIR(old_dentry->d_inode->i_mode)) {
rc = -ENOTDIR;
if (old_dentry->d_name.name[old_dentry->d_name.len])
goto exit4;
if (new_dentry->d_name.name[new_dentry->d_name.len])
goto exit4;
}

#if defined(HAVE_4ARGS_VFS_RENAME)
rc = vfs_rename(old_dir->d_inode, old_dentry,
new_dir->d_inode, new_dentry);
#elif defined(HAVE_5ARGS_VFS_RENAME)
rc = vfs_rename(old_dir->d_inode, old_dentry,
new_dir->d_inode, new_dentry, NULL);
#else
rc = vfs_rename(old_dir->d_inode, old_dentry,
new_dir->d_inode, new_dentry, NULL, 0);
#endif
exit4:
unlock_rename(new_dir, old_dir);
exit3:
dput(new_dentry);
path_put(&new_parent);
exit2:
dput(old_dentry);
path_put(&old_parent);
exit:
return (-rc);
}
EXPORT_SYMBOL(vn_rename);

int
vn_getattr(vnode_t *vp, vattr_t *vap, int flags, void *x3, void *x4)
{
Expand Down
Loading

0 comments on commit 1cb26f0

Please sign in to comment.