mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 18:21:24 +02:00
VFS/knfsd: Teach dentry_create() to use atomic_open()
While knfsd offers combined exclusive create and open results to clients, on some filesystems those results may not be atomic. This behavior can be observed. For example, an open O_CREAT with mode 0 will succeed in creating the file but unexpectedly return -EACCES from vfs_open(). Additionally reducing the number of remote RPC calls required for O_CREAT on network filesystem provides a performance benefit in the open path. Teach knfsd's helper dentry_create() to use atomic_open() for filesystems that support it. The previously const @path is passed up to atomic_open() and may be modified depending on whether an existing entry was found or if the atomic_open() returned an error and consumed the passed-in dentry. Signed-off-by: Benjamin Coddington <bcodding@hammerspace.com> Link: https://patch.msgid.link/8e449bfb64ab055abb9fd82641a171531415a88c.1764259052.git.bcodding@hammerspace.com Reviewed-by: Jeff Layton <jlayton@kernel.org> Reviewed-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
36411554e8
commit
64a989dbd1
55
fs/namei.c
55
fs/namei.c
|
|
@ -4953,25 +4953,54 @@ EXPORT_SYMBOL(start_creating_user_path);
|
||||||
* On success, returns a "struct file *". Otherwise a ERR_PTR
|
* On success, returns a "struct file *". Otherwise a ERR_PTR
|
||||||
* is returned.
|
* is returned.
|
||||||
*/
|
*/
|
||||||
struct file *dentry_create(const struct path *path, int flags, umode_t mode,
|
struct file *dentry_create(struct path *path, int flags, umode_t mode,
|
||||||
const struct cred *cred)
|
const struct cred *cred)
|
||||||
{
|
{
|
||||||
struct file *f;
|
struct file *file __free(fput) = NULL;
|
||||||
int error;
|
struct dentry *dentry = path->dentry;
|
||||||
|
struct dentry *dir = dentry->d_parent;
|
||||||
|
struct inode *dir_inode = d_inode(dir);
|
||||||
|
struct mnt_idmap *idmap;
|
||||||
|
int error, create_error;
|
||||||
|
|
||||||
f = alloc_empty_file(flags, cred);
|
file = alloc_empty_file(flags, cred);
|
||||||
if (IS_ERR(f))
|
if (IS_ERR(file))
|
||||||
return f;
|
return file;
|
||||||
|
|
||||||
error = vfs_create(mnt_idmap(path->mnt), path->dentry, mode, NULL);
|
idmap = mnt_idmap(path->mnt);
|
||||||
if (!error)
|
|
||||||
error = vfs_open(path, f);
|
|
||||||
|
|
||||||
if (unlikely(error)) {
|
if (dir_inode->i_op->atomic_open) {
|
||||||
fput(f);
|
path->dentry = dir;
|
||||||
return ERR_PTR(error);
|
mode = vfs_prepare_mode(idmap, dir_inode, mode, S_IALLUGO, S_IFREG);
|
||||||
|
|
||||||
|
create_error = may_o_create(idmap, path, dentry, mode);
|
||||||
|
if (create_error)
|
||||||
|
flags &= ~O_CREAT;
|
||||||
|
|
||||||
|
dentry = atomic_open(path, dentry, file, flags, mode);
|
||||||
|
error = PTR_ERR_OR_ZERO(dentry);
|
||||||
|
|
||||||
|
if (unlikely(create_error) && error == -ENOENT)
|
||||||
|
error = create_error;
|
||||||
|
|
||||||
|
if (!error) {
|
||||||
|
if (file->f_mode & FMODE_CREATED)
|
||||||
|
fsnotify_create(dir->d_inode, dentry);
|
||||||
|
if (file->f_mode & FMODE_OPENED)
|
||||||
|
fsnotify_open(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
path->dentry = dentry;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
error = vfs_create(mnt_idmap(path->mnt), path->dentry, mode, NULL);
|
||||||
|
if (!error)
|
||||||
|
error = vfs_open(path, file);
|
||||||
}
|
}
|
||||||
return f;
|
if (unlikely(error))
|
||||||
|
return ERR_PTR(error);
|
||||||
|
|
||||||
|
return no_free_ptr(file);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(dentry_create);
|
EXPORT_SYMBOL(dentry_create);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -194,7 +194,7 @@ static inline bool nfsd4_create_is_exclusive(int createmode)
|
||||||
}
|
}
|
||||||
|
|
||||||
static __be32
|
static __be32
|
||||||
nfsd4_vfs_create(struct svc_fh *fhp, struct dentry *child,
|
nfsd4_vfs_create(struct svc_fh *fhp, struct dentry **child,
|
||||||
struct nfsd4_open *open)
|
struct nfsd4_open *open)
|
||||||
{
|
{
|
||||||
struct file *filp;
|
struct file *filp;
|
||||||
|
|
@ -202,6 +202,9 @@ nfsd4_vfs_create(struct svc_fh *fhp, struct dentry *child,
|
||||||
int oflags;
|
int oflags;
|
||||||
|
|
||||||
oflags = O_CREAT | O_LARGEFILE;
|
oflags = O_CREAT | O_LARGEFILE;
|
||||||
|
if (nfsd4_create_is_exclusive(open->op_createmode))
|
||||||
|
oflags |= O_EXCL;
|
||||||
|
|
||||||
switch (open->op_share_access & NFS4_SHARE_ACCESS_BOTH) {
|
switch (open->op_share_access & NFS4_SHARE_ACCESS_BOTH) {
|
||||||
case NFS4_SHARE_ACCESS_WRITE:
|
case NFS4_SHARE_ACCESS_WRITE:
|
||||||
oflags |= O_WRONLY;
|
oflags |= O_WRONLY;
|
||||||
|
|
@ -214,9 +217,11 @@ nfsd4_vfs_create(struct svc_fh *fhp, struct dentry *child,
|
||||||
}
|
}
|
||||||
|
|
||||||
path.mnt = fhp->fh_export->ex_path.mnt;
|
path.mnt = fhp->fh_export->ex_path.mnt;
|
||||||
path.dentry = child;
|
path.dentry = *child;
|
||||||
filp = dentry_create(&path, oflags, open->op_iattr.ia_mode,
|
filp = dentry_create(&path, oflags, open->op_iattr.ia_mode,
|
||||||
current_cred());
|
current_cred());
|
||||||
|
*child = path.dentry;
|
||||||
|
|
||||||
if (IS_ERR(filp))
|
if (IS_ERR(filp))
|
||||||
return nfserrno(PTR_ERR(filp));
|
return nfserrno(PTR_ERR(filp));
|
||||||
|
|
||||||
|
|
@ -350,7 +355,7 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
|
||||||
status = fh_fill_pre_attrs(fhp);
|
status = fh_fill_pre_attrs(fhp);
|
||||||
if (status != nfs_ok)
|
if (status != nfs_ok)
|
||||||
goto out;
|
goto out;
|
||||||
status = nfsd4_vfs_create(fhp, child, open);
|
status = nfsd4_vfs_create(fhp, &child, open);
|
||||||
if (status != nfs_ok)
|
if (status != nfs_ok)
|
||||||
goto out;
|
goto out;
|
||||||
open->op_created = true;
|
open->op_created = true;
|
||||||
|
|
|
||||||
|
|
@ -2457,7 +2457,7 @@ struct file *dentry_open(const struct path *path, int flags,
|
||||||
const struct cred *creds);
|
const struct cred *creds);
|
||||||
struct file *dentry_open_nonotify(const struct path *path, int flags,
|
struct file *dentry_open_nonotify(const struct path *path, int flags,
|
||||||
const struct cred *cred);
|
const struct cred *cred);
|
||||||
struct file *dentry_create(const struct path *path, int flags, umode_t mode,
|
struct file *dentry_create(struct path *path, int flags, umode_t mode,
|
||||||
const struct cred *cred);
|
const struct cred *cred);
|
||||||
const struct path *backing_file_user_path(const struct file *f);
|
const struct path *backing_file_user_path(const struct file *f);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user