linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RESEND PATCH v2] tmpfs: allow decoding a file handle of an unlinked file
@ 2018-04-23 20:25 Amir Goldstein
  2018-04-23 22:38 ` NeilBrown
  0 siblings, 1 reply; 2+ messages in thread
From: Amir Goldstein @ 2018-04-23 20:25 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Neil Brown, Hugh Dickins, linux-fsdevel, Linux NFS Mailing List,
	Jeff Layton, J. Bruce Fields, Al Viro

tmpfs uses the helper d_find_alias() to find a dentry from a decoded
inode, but d_find_alias() skips unhashed dentries, so unlinked files
cannot be decoded from a file handle.

This can be reproduced using xfstests test program open_by_handle:
$ open_by handle -c /tmp/testdir
$ open_by_handle -dk /tmp/testdir
open_by_handle(/tmp/testdir/file000000) returned 116 incorrectly on an
unlinked open file!

To fix this, if d_find_alias() can't find a hashed alias, call
d_find_any_alias() to return an unhashed one.

Cc: Hugh Dickins <hughd@google.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---

Hi Andrew,

I was nudging Hugh over at LSF/MM about this patch and he has
suggested that I send it to you, because he has no idea about the
exportfs parts.

The test for decoding a file handle of an unlinked file has already
been merged to xfstest generic/467 and the test is failing on tmpfs
without this change.

Can you please take this patch.

Thanks,
Amir.

 mm/shmem.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index 07a1d22807be..5d3fa4099f54 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -3404,6 +3404,15 @@ static int shmem_match(struct inode *ino, void *vfh)
        return ino->i_ino == inum && fh[0] == ino->i_generation;
 }

+/* Find any alias of inode, but prefer a hashed alias */
+static struct dentry *shmem_find_alias(struct inode *inode)
+{
+       struct dentry *alias = d_find_alias(inode);
+
+       return alias ?: d_find_any_alias(inode);
+}
+
+
 static struct dentry *shmem_fh_to_dentry(struct super_block *sb,
                struct fid *fid, int fh_len, int fh_type)
 {
@@ -3420,7 +3429,7 @@ static struct dentry *shmem_fh_to_dentry(struct
super_block *sb,
        inode = ilookup5(sb, (unsigned long)(inum + fid->raw[0]),
                        shmem_match, fid->raw);
        if (inode) {
-               dentry = d_find_alias(inode);
+               dentry = shmem_find_alias(inode);
                iput(inode);
        }

--
2.7.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [RESEND PATCH v2] tmpfs: allow decoding a file handle of an unlinked file
  2018-04-23 20:25 [RESEND PATCH v2] tmpfs: allow decoding a file handle of an unlinked file Amir Goldstein
@ 2018-04-23 22:38 ` NeilBrown
  0 siblings, 0 replies; 2+ messages in thread
From: NeilBrown @ 2018-04-23 22:38 UTC (permalink / raw)
  To: Amir Goldstein, Andrew Morton
  Cc: Neil Brown, Hugh Dickins, linux-fsdevel, Linux NFS Mailing List,
	Jeff Layton, J. Bruce Fields, Al Viro

[-- Attachment #1: Type: text/plain, Size: 2470 bytes --]

On Mon, Apr 23 2018, Amir Goldstein wrote:

> tmpfs uses the helper d_find_alias() to find a dentry from a decoded
> inode, but d_find_alias() skips unhashed dentries, so unlinked files
> cannot be decoded from a file handle.
>
> This can be reproduced using xfstests test program open_by_handle:
> $ open_by handle -c /tmp/testdir
> $ open_by_handle -dk /tmp/testdir
> open_by_handle(/tmp/testdir/file000000) returned 116 incorrectly on an
> unlinked open file!
>
> To fix this, if d_find_alias() can't find a hashed alias, call
> d_find_any_alias() to return an unhashed one.
>
> Cc: Hugh Dickins <hughd@google.com>
> Cc: Al Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Reviewed-by: NeilBrown <neilb@suse.com>

Looks reasonable to me.  You could possibly just use d_find_any_alias()
unconditionally, but there is sometimes a small benefit in getting a
hashed aliases if there is one.

Thanks,
NeilBrown

> ---
>
> Hi Andrew,
>
> I was nudging Hugh over at LSF/MM about this patch and he has
> suggested that I send it to you, because he has no idea about the
> exportfs parts.
>
> The test for decoding a file handle of an unlinked file has already
> been merged to xfstest generic/467 and the test is failing on tmpfs
> without this change.
>
> Can you please take this patch.
>
> Thanks,
> Amir.
>
>  mm/shmem.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index 07a1d22807be..5d3fa4099f54 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -3404,6 +3404,15 @@ static int shmem_match(struct inode *ino, void *vfh)
>         return ino->i_ino == inum && fh[0] == ino->i_generation;
>  }
>
> +/* Find any alias of inode, but prefer a hashed alias */
> +static struct dentry *shmem_find_alias(struct inode *inode)
> +{
> +       struct dentry *alias = d_find_alias(inode);
> +
> +       return alias ?: d_find_any_alias(inode);
> +}
> +
> +
>  static struct dentry *shmem_fh_to_dentry(struct super_block *sb,
>                 struct fid *fid, int fh_len, int fh_type)
>  {
> @@ -3420,7 +3429,7 @@ static struct dentry *shmem_fh_to_dentry(struct
> super_block *sb,
>         inode = ilookup5(sb, (unsigned long)(inum + fid->raw[0]),
>                         shmem_match, fid->raw);
>         if (inode) {
> -               dentry = d_find_alias(inode);
> +               dentry = shmem_find_alias(inode);
>                 iput(inode);
>         }
>
> --
> 2.7.4

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-04-23 22:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-23 20:25 [RESEND PATCH v2] tmpfs: allow decoding a file handle of an unlinked file Amir Goldstein
2018-04-23 22:38 ` NeilBrown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).