mirror of https://github.com/torvalds/linux.git
xfs: convert xfs_open_by_handle() to FD_PREPARE()
Link: https://patch.msgid.link/20251123-work-fd-prepare-v4-17-b6efa1706cfd@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
39f6e7581a
commit
993f30468e
|
|
@ -233,14 +233,11 @@ xfs_open_by_handle(
|
||||||
xfs_fsop_handlereq_t *hreq)
|
xfs_fsop_handlereq_t *hreq)
|
||||||
{
|
{
|
||||||
const struct cred *cred = current_cred();
|
const struct cred *cred = current_cred();
|
||||||
int error;
|
|
||||||
int fd;
|
|
||||||
int permflag;
|
int permflag;
|
||||||
struct file *filp;
|
|
||||||
struct inode *inode;
|
struct inode *inode;
|
||||||
struct dentry *dentry;
|
struct dentry *dentry;
|
||||||
fmode_t fmode;
|
fmode_t fmode;
|
||||||
struct path path;
|
struct path path __free(path_put) = {};
|
||||||
|
|
||||||
if (!capable(CAP_SYS_ADMIN))
|
if (!capable(CAP_SYS_ADMIN))
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
|
|
@ -249,12 +246,11 @@ xfs_open_by_handle(
|
||||||
if (IS_ERR(dentry))
|
if (IS_ERR(dentry))
|
||||||
return PTR_ERR(dentry);
|
return PTR_ERR(dentry);
|
||||||
inode = d_inode(dentry);
|
inode = d_inode(dentry);
|
||||||
|
path.dentry = dentry;
|
||||||
|
|
||||||
/* Restrict xfs_open_by_handle to directories & regular files. */
|
/* Restrict xfs_open_by_handle to directories & regular files. */
|
||||||
if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) {
|
if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)))
|
||||||
error = -EPERM;
|
return -EPERM;
|
||||||
goto out_dput;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if BITS_PER_LONG != 32
|
#if BITS_PER_LONG != 32
|
||||||
hreq->oflags |= O_LARGEFILE;
|
hreq->oflags |= O_LARGEFILE;
|
||||||
|
|
@ -263,48 +259,30 @@ xfs_open_by_handle(
|
||||||
permflag = hreq->oflags;
|
permflag = hreq->oflags;
|
||||||
fmode = OPEN_FMODE(permflag);
|
fmode = OPEN_FMODE(permflag);
|
||||||
if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) &&
|
if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) &&
|
||||||
(fmode & FMODE_WRITE) && IS_APPEND(inode)) {
|
(fmode & FMODE_WRITE) && IS_APPEND(inode))
|
||||||
error = -EPERM;
|
return -EPERM;
|
||||||
goto out_dput;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((fmode & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
|
if ((fmode & FMODE_WRITE) && IS_IMMUTABLE(inode))
|
||||||
error = -EPERM;
|
return -EPERM;
|
||||||
goto out_dput;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Can't write directories. */
|
/* Can't write directories. */
|
||||||
if (S_ISDIR(inode->i_mode) && (fmode & FMODE_WRITE)) {
|
if (S_ISDIR(inode->i_mode) && (fmode & FMODE_WRITE))
|
||||||
error = -EISDIR;
|
return -EISDIR;
|
||||||
goto out_dput;
|
|
||||||
}
|
|
||||||
|
|
||||||
fd = get_unused_fd_flags(0);
|
path.mnt = mntget(parfilp->f_path.mnt);
|
||||||
if (fd < 0) {
|
|
||||||
error = fd;
|
|
||||||
goto out_dput;
|
|
||||||
}
|
|
||||||
|
|
||||||
path.mnt = parfilp->f_path.mnt;
|
FD_PREPARE(fdf, 0, dentry_open(&path, hreq->oflags, cred));
|
||||||
path.dentry = dentry;
|
if (fdf.err)
|
||||||
filp = dentry_open(&path, hreq->oflags, cred);
|
return fdf.err;
|
||||||
dput(dentry);
|
|
||||||
if (IS_ERR(filp)) {
|
|
||||||
put_unused_fd(fd);
|
|
||||||
return PTR_ERR(filp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (S_ISREG(inode->i_mode)) {
|
if (S_ISREG(inode->i_mode)) {
|
||||||
|
struct file *filp = fd_prepare_file(fdf);
|
||||||
|
|
||||||
filp->f_flags |= O_NOATIME;
|
filp->f_flags |= O_NOATIME;
|
||||||
filp->f_mode |= FMODE_NOCMTIME;
|
filp->f_mode |= FMODE_NOCMTIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd_install(fd, filp);
|
return fd_publish(fdf);
|
||||||
return fd;
|
|
||||||
|
|
||||||
out_dput:
|
|
||||||
dput(dentry);
|
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue