mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-24 05:10:51 +07:00
vfs: create vfs helper vfs_tmpfile()
Factor out some common vfs bits from do_tmpfile() to be used by overlayfs for concurrent copy up. Signed-off-by: Amir Goldstein <amir73il@gmail.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
This commit is contained in:
parent
7ce7d89f48
commit
af7bd4dc13
68
fs/namei.c
68
fs/namei.c
@ -3353,13 +3353,50 @@ static int do_last(struct nameidata *nd,
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct dentry *vfs_tmpfile(struct dentry *dentry, umode_t mode, int open_flag)
|
||||||
|
{
|
||||||
|
static const struct qstr name = QSTR_INIT("/", 1);
|
||||||
|
struct dentry *child = NULL;
|
||||||
|
struct inode *dir = dentry->d_inode;
|
||||||
|
struct inode *inode;
|
||||||
|
int error;
|
||||||
|
|
||||||
|
/* we want directory to be writable */
|
||||||
|
error = inode_permission(dir, MAY_WRITE | MAY_EXEC);
|
||||||
|
if (error)
|
||||||
|
goto out_err;
|
||||||
|
error = -EOPNOTSUPP;
|
||||||
|
if (!dir->i_op->tmpfile)
|
||||||
|
goto out_err;
|
||||||
|
error = -ENOMEM;
|
||||||
|
child = d_alloc(dentry, &name);
|
||||||
|
if (unlikely(!child))
|
||||||
|
goto out_err;
|
||||||
|
error = dir->i_op->tmpfile(dir, child, mode);
|
||||||
|
if (error)
|
||||||
|
goto out_err;
|
||||||
|
error = -ENOENT;
|
||||||
|
inode = child->d_inode;
|
||||||
|
if (unlikely(!inode))
|
||||||
|
goto out_err;
|
||||||
|
if (!(open_flag & O_EXCL)) {
|
||||||
|
spin_lock(&inode->i_lock);
|
||||||
|
inode->i_state |= I_LINKABLE;
|
||||||
|
spin_unlock(&inode->i_lock);
|
||||||
|
}
|
||||||
|
return child;
|
||||||
|
|
||||||
|
out_err:
|
||||||
|
dput(child);
|
||||||
|
return ERR_PTR(error);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(vfs_tmpfile);
|
||||||
|
|
||||||
static int do_tmpfile(struct nameidata *nd, unsigned flags,
|
static int do_tmpfile(struct nameidata *nd, unsigned flags,
|
||||||
const struct open_flags *op,
|
const struct open_flags *op,
|
||||||
struct file *file, int *opened)
|
struct file *file, int *opened)
|
||||||
{
|
{
|
||||||
static const struct qstr name = QSTR_INIT("/", 1);
|
|
||||||
struct dentry *child;
|
struct dentry *child;
|
||||||
struct inode *dir;
|
|
||||||
struct path path;
|
struct path path;
|
||||||
int error = path_lookupat(nd, flags | LOOKUP_DIRECTORY, &path);
|
int error = path_lookupat(nd, flags | LOOKUP_DIRECTORY, &path);
|
||||||
if (unlikely(error))
|
if (unlikely(error))
|
||||||
@ -3367,25 +3404,12 @@ static int do_tmpfile(struct nameidata *nd, unsigned flags,
|
|||||||
error = mnt_want_write(path.mnt);
|
error = mnt_want_write(path.mnt);
|
||||||
if (unlikely(error))
|
if (unlikely(error))
|
||||||
goto out;
|
goto out;
|
||||||
dir = path.dentry->d_inode;
|
child = vfs_tmpfile(path.dentry, op->mode, op->open_flag);
|
||||||
/* we want directory to be writable */
|
error = PTR_ERR(child);
|
||||||
error = inode_permission(dir, MAY_WRITE | MAY_EXEC);
|
if (unlikely(IS_ERR(child)))
|
||||||
if (error)
|
|
||||||
goto out2;
|
goto out2;
|
||||||
if (!dir->i_op->tmpfile) {
|
|
||||||
error = -EOPNOTSUPP;
|
|
||||||
goto out2;
|
|
||||||
}
|
|
||||||
child = d_alloc(path.dentry, &name);
|
|
||||||
if (unlikely(!child)) {
|
|
||||||
error = -ENOMEM;
|
|
||||||
goto out2;
|
|
||||||
}
|
|
||||||
dput(path.dentry);
|
dput(path.dentry);
|
||||||
path.dentry = child;
|
path.dentry = child;
|
||||||
error = dir->i_op->tmpfile(dir, child, op->mode);
|
|
||||||
if (error)
|
|
||||||
goto out2;
|
|
||||||
audit_inode(nd->name, child, 0);
|
audit_inode(nd->name, child, 0);
|
||||||
/* Don't check for other permissions, the inode was just created */
|
/* Don't check for other permissions, the inode was just created */
|
||||||
error = may_open(&path, 0, op->open_flag);
|
error = may_open(&path, 0, op->open_flag);
|
||||||
@ -3396,14 +3420,8 @@ static int do_tmpfile(struct nameidata *nd, unsigned flags,
|
|||||||
if (error)
|
if (error)
|
||||||
goto out2;
|
goto out2;
|
||||||
error = open_check_o_direct(file);
|
error = open_check_o_direct(file);
|
||||||
if (error) {
|
if (error)
|
||||||
fput(file);
|
fput(file);
|
||||||
} else if (!(op->open_flag & O_EXCL)) {
|
|
||||||
struct inode *inode = file_inode(file);
|
|
||||||
spin_lock(&inode->i_lock);
|
|
||||||
inode->i_state |= I_LINKABLE;
|
|
||||||
spin_unlock(&inode->i_lock);
|
|
||||||
}
|
|
||||||
out2:
|
out2:
|
||||||
mnt_drop_write(path.mnt);
|
mnt_drop_write(path.mnt);
|
||||||
out:
|
out:
|
||||||
|
@ -1561,6 +1561,9 @@ extern int vfs_unlink(struct inode *, struct dentry *, struct inode **);
|
|||||||
extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *, struct inode **, unsigned int);
|
extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *, struct inode **, unsigned int);
|
||||||
extern int vfs_whiteout(struct inode *, struct dentry *);
|
extern int vfs_whiteout(struct inode *, struct dentry *);
|
||||||
|
|
||||||
|
extern struct dentry *vfs_tmpfile(struct dentry *dentry, umode_t mode,
|
||||||
|
int open_flag);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* VFS file helper functions.
|
* VFS file helper functions.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user