2024-03-18 18:29:24

by Jeff Layton

[permalink] [raw]
Subject: [PATCH RFC] ntfs3: remove atomic_open

atomic_open is an optional VFS operation, and is primarily for network
filesystems. NFS (for instance) can just send an open call for the last
path component rather than doing a lookup and then having to follow that
up with an open when it doesn't have a dentry in cache.

ntfs3 is a local filesystem however, and its atomic_open just does a
typical lookup + open, but in a convoluted way. atomic_open will also
make directory leases more difficult to implement on the filesystem.

Remove ntfs_atomic_open.

Signed-off-by: Jeff Layton <[email protected]>
---
Am I missing something about why ntfs3 requires an atomic_open op? In
any case, this is only lightly tested, but it seems to work.
---
fs/ntfs3/namei.c | 90 --------------------------------------------------------
1 file changed, 90 deletions(-)

diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c
index 084d19d78397..edb6a7141246 100644
--- a/fs/ntfs3/namei.c
+++ b/fs/ntfs3/namei.c
@@ -358,95 +358,6 @@ static int ntfs_rename(struct mnt_idmap *idmap, struct inode *dir,
return err;
}

-/*
- * ntfs_atomic_open
- *
- * inode_operations::atomic_open
- */
-static int ntfs_atomic_open(struct inode *dir, struct dentry *dentry,
- struct file *file, u32 flags, umode_t mode)
-{
- int err;
- struct inode *inode;
- struct ntfs_fnd *fnd = NULL;
- struct ntfs_inode *ni = ntfs_i(dir);
- struct dentry *d = NULL;
- struct cpu_str *uni = __getname();
- bool locked = false;
-
- if (!uni)
- return -ENOMEM;
-
- err = ntfs_nls_to_utf16(ni->mi.sbi, dentry->d_name.name,
- dentry->d_name.len, uni, NTFS_NAME_LEN,
- UTF16_HOST_ENDIAN);
- if (err < 0)
- goto out;
-
-#ifdef CONFIG_NTFS3_FS_POSIX_ACL
- if (IS_POSIXACL(dir)) {
- /*
- * Load in cache current acl to avoid ni_lock(dir):
- * ntfs_create_inode -> ntfs_init_acl -> posix_acl_create ->
- * ntfs_get_acl -> ntfs_get_acl_ex -> ni_lock
- */
- struct posix_acl *p = get_inode_acl(dir, ACL_TYPE_DEFAULT);
-
- if (IS_ERR(p)) {
- err = PTR_ERR(p);
- goto out;
- }
- posix_acl_release(p);
- }
-#endif
-
- if (d_in_lookup(dentry)) {
- ni_lock_dir(ni);
- locked = true;
- fnd = fnd_get();
- if (!fnd) {
- err = -ENOMEM;
- goto out1;
- }
-
- d = d_splice_alias(dir_search_u(dir, uni, fnd), dentry);
- if (IS_ERR(d)) {
- err = PTR_ERR(d);
- d = NULL;
- goto out2;
- }
-
- if (d)
- dentry = d;
- }
-
- if (!(flags & O_CREAT) || d_really_is_positive(dentry)) {
- err = finish_no_open(file, d);
- goto out2;
- }
-
- file->f_mode |= FMODE_CREATED;
-
- /*
- * fnd contains tree's path to insert to.
- * If fnd is not NULL then dir is locked.
- */
- inode = ntfs_create_inode(file_mnt_idmap(file), dir, dentry, uni,
- mode, 0, NULL, 0, fnd);
- err = IS_ERR(inode) ? PTR_ERR(inode) :
- finish_open(file, dentry, ntfs_file_open);
- dput(d);
-
-out2:
- fnd_put(fnd);
-out1:
- if (locked)
- ni_unlock(ni);
-out:
- __putname(uni);
- return err;
-}
-
struct dentry *ntfs3_get_parent(struct dentry *child)
{
struct inode *inode = d_inode(child);
@@ -612,7 +523,6 @@ const struct inode_operations ntfs_dir_inode_operations = {
.setattr = ntfs3_setattr,
.getattr = ntfs_getattr,
.listxattr = ntfs_listxattr,
- .atomic_open = ntfs_atomic_open,
.fiemap = ntfs_fiemap,
};


---
base-commit: 0a7b0acecea273c8816f4f5b0e189989470404cf
change-id: 20240318-ntfs3-atomic-open-0cc979d7c024

Best regards,
--
Jeff Layton <[email protected]>



2024-03-19 15:29:40

by Christian Brauner

[permalink] [raw]
Subject: Re: [PATCH RFC] ntfs3: remove atomic_open

On Mon, Mar 18, 2024 at 02:28:50PM -0400, Jeff Layton wrote:
> atomic_open is an optional VFS operation, and is primarily for network
> filesystems. NFS (for instance) can just send an open call for the last
> path component rather than doing a lookup and then having to follow that
> up with an open when it doesn't have a dentry in cache.
>
> ntfs3 is a local filesystem however, and its atomic_open just does a
> typical lookup + open, but in a convoluted way. atomic_open will also
> make directory leases more difficult to implement on the filesystem.
>
> Remove ntfs_atomic_open.
>
> Signed-off-by: Jeff Layton <[email protected]>
> ---
> Am I missing something about why ntfs3 requires an atomic_open op? In
> any case, this is only lightly tested, but it seems to work.

Seems we should just remove it.

2024-03-22 02:36:35

by Al Viro

[permalink] [raw]
Subject: Re: [PATCH RFC] ntfs3: remove atomic_open

On Mon, Mar 18, 2024 at 02:28:50PM -0400, Jeff Layton wrote:
> atomic_open is an optional VFS operation, and is primarily for network
> filesystems. NFS (for instance) can just send an open call for the last
> path component rather than doing a lookup and then having to follow that
> up with an open when it doesn't have a dentry in cache.
>
> ntfs3 is a local filesystem however, and its atomic_open just does a
> typical lookup + open, but in a convoluted way. atomic_open will also
> make directory leases more difficult to implement on the filesystem.

FWIW, I'm not sure they are actually doing it correctly, but in any
case - there's no reason whatsoever for implementing that sucker on
a local filesystem. Kill it.

> - inode = ntfs_create_inode(file_mnt_idmap(file), dir, dentry, uni,
> - mode, 0, NULL, 0, fnd);
> - err = IS_ERR(inode) ? PTR_ERR(inode) :
> - finish_open(file, dentry, ntfs_file_open);

.. incidentally, this ntfs_create_inode() thing should not have the
calling conventions it has.

It does create inode, all right - and attaches it to dentry. Then it
proceeds to return the pointer to that new inode, with dentry->d_inode
being the only thing that keeps it alive. That would be defendable
(we are holding a reference to dentry and nobody else could turn
it negative under us), but... look at the callers.

4 out of 5 are of the same form:
inode = ntfs_create_inode(....);
return IS_ERR(inode) ? PTR_ERR(inode) : 0;

The fifth one is the crap above and there we *also* never look at the
return value downstream of that IS_ERR(inode) ? PTR_ERR(inode) : ...;

Which is to say, all callers of that thing don't give a damn about
the pointer per se - they only want to know if it's ERR_PTR(-E...)
or not and if it is, what error had been wrapped into that ERR_PTR().

Simply make it return 0 or -E... - if some future caller really
wants a reference to struct inode that had been created, they can
bloody well pick it from dentry->d_inode.

In any case, this caller should simply die - ->atomic_open() instance
does not buy *anything* here.

Acked-by: Al Viro <[email protected]>