From: Bernd Schubert <bernd.schubert@fastmail.fm>
To: Chuck Lever <cel@kernel.org>,
viro@zeniv.linux.org.uk, brauner@kernel.org, hughd@google.com,
akpm@linux-foundation.org
Cc: Chuck Lever <chuck.lever@oracle.com>,
linux-mm@kvack.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH v3 3/3] shmem: stable directory offsets
Date: Mon, 26 Jun 2023 15:18:41 +0200 [thread overview]
Message-ID: <f6191d0e-ede3-620b-ae96-311b001e1ece@fastmail.fm> (raw)
In-Reply-To: <168605707262.32244.4794425063054676856.stgit@manet.1015granger.net>
On 6/6/23 15:11, Chuck Lever wrote:
> From: Chuck Lever <chuck.lever@oracle.com>
>
> The current cursor-based directory offset mechanism doesn't work
> when a tmpfs filesystem is exported via NFS. This is because NFS
> clients do not open directories. Each server-side READDIR operation
> has to open the directory, read it, then close it. The cursor state
> for that directory, being associated strictly with the opened
> struct file, is thus discarded after each NFS READDIR operation.
>
> Directory offsets are cached not only by NFS clients, but also by
> user space libraries on those clients. Essentially there is no way
> to invalidate those caches when directory offsets have changed on
> an NFS server after the offset-to-dentry mapping changes. Thus the
> whole application stack depends on unchanging directory offsets.
>
> The solution we've come up with is to make the directory offset for
> each file in a tmpfs filesystem stable for the life of the directory
> entry it represents.
>
> shmem_readdir() and shmem_dir_llseek() now use an xarray to map each
> directory offset (an loff_t integer) to the memory address of a
> struct dentry.
>
> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
> ---
> mm/shmem.c | 39 +++++++++++++++++++++++++++++++++++----
> 1 file changed, 35 insertions(+), 4 deletions(-)
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index 721f9fd064aa..fd9571056181 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -2410,7 +2410,8 @@ static struct inode *shmem_get_inode(struct mnt_idmap *idmap, struct super_block
> /* Some things misbehave if size == 0 on a directory */
> inode->i_size = 2 * BOGO_DIRENT_SIZE;
> inode->i_op = &shmem_dir_inode_operations;
> - inode->i_fop = &simple_dir_operations;
> + inode->i_fop = &stable_dir_operations;
> + stable_offset_init(inode);
> break;
> case S_IFLNK:
> /*
> @@ -2950,6 +2951,10 @@ shmem_mknod(struct mnt_idmap *idmap, struct inode *dir,
> if (error && error != -EOPNOTSUPP)
> goto out_iput;
>
> + error = stable_offset_add(dir, dentry);
> + if (error)
> + goto out_iput;
> +
> error = 0;
This line can be removed?
> dir->i_size += BOGO_DIRENT_SIZE;
> dir->i_ctime = dir->i_mtime = current_time(dir);
> @@ -3027,6 +3032,10 @@ static int shmem_link(struct dentry *old_dentry, struct inode *dir, struct dentr
> goto out;
> }
>
> + ret = stable_offset_add(dir, dentry);
> + if (ret)
> + goto out;
> +
I think this should call shmem_free_inode() before goto out - reverse
what shmem_reserve_inode() has done.
> dir->i_size += BOGO_DIRENT_SIZE;
> inode->i_ctime = dir->i_ctime = dir->i_mtime = current_time(inode);
> inode_inc_iversion(dir);
> @@ -3045,6 +3054,8 @@ static int shmem_unlink(struct inode *dir, struct dentry *dentry)
> if (inode->i_nlink > 1 && !S_ISDIR(inode->i_mode))
> shmem_free_inode(inode->i_sb);
>
> + stable_offset_remove(dir, dentry);
> +
> dir->i_size -= BOGO_DIRENT_SIZE;
> inode->i_ctime = dir->i_ctime = dir->i_mtime = current_time(inode);
> inode_inc_iversion(dir);
> @@ -3103,24 +3114,37 @@ static int shmem_rename2(struct mnt_idmap *idmap,
> {
> struct inode *inode = d_inode(old_dentry);
> int they_are_dirs = S_ISDIR(inode->i_mode);
> + int error;
>
> if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
> return -EINVAL;
>
> - if (flags & RENAME_EXCHANGE)
> + if (flags & RENAME_EXCHANGE) {
> + stable_offset_remove(old_dir, old_dentry);
> + stable_offset_remove(new_dir, new_dentry);
> + error = stable_offset_add(new_dir, old_dentry);
> + if (error)
> + return error;
> + error = stable_offset_add(old_dir, new_dentry);
> + if (error)
> + return error;
> return simple_rename_exchange(old_dir, old_dentry, new_dir, new_dentry);
> + }
Hmm, error handling issues? Everything needs to be reversed when any of
the operations fails?
>
> if (!simple_empty(new_dentry))
> return -ENOTEMPTY;
>
> if (flags & RENAME_WHITEOUT) {
> - int error;
> -
> error = shmem_whiteout(idmap, old_dir, old_dentry);
> if (error)
> return error;
> }
>
> + stable_offset_remove(old_dir, old_dentry);
> + error = stable_offset_add(new_dir, old_dentry);
> + if (error)
> + return error;
> +
> if (d_really_is_positive(new_dentry)) {
> (void) shmem_unlink(new_dir, new_dentry);
> if (they_are_dirs) {
> @@ -3185,6 +3209,11 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,
> folio_unlock(folio);
> folio_put(folio);
> }
> +
> + error = stable_offset_add(dir, dentry);
> + if (error)
> + goto out_iput;
> +
Error handling, there is a kmemdup() above which needs to be freed? I'm
not sure about folio, automatically released with the inode?
> dir->i_size += BOGO_DIRENT_SIZE;
> dir->i_ctime = dir->i_mtime = current_time(dir);
> inode_inc_iversion(dir);
> @@ -3920,6 +3949,8 @@ static void shmem_destroy_inode(struct inode *inode)
> {
> if (S_ISREG(inode->i_mode))
> mpol_free_shared_policy(&SHMEM_I(inode)->policy);
> + if (S_ISDIR(inode->i_mode))
> + stable_offset_destroy(inode);
> }
>
> static void shmem_init_inode(void *foo)
>
>
Thanks,
Bernd
next prev parent reply other threads:[~2023-06-26 13:18 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <168605676256.32244.6158641147817585524.stgit@manet.1015granger.net>
2023-06-21 13:12 ` [PATCH v3 0/3] shmemfs " Chuck Lever III
2023-06-21 14:25 ` Christian Brauner
[not found] ` <168605705924.32244.13384849924097654559.stgit@manet.1015granger.net>
2023-06-23 22:21 ` [PATCH v3 1/3] libfs: Add directory operations for stable offsets Bernd Schubert
2023-06-26 13:36 ` Bernd Schubert
2023-06-26 14:50 ` Chuck Lever III
2023-06-26 15:01 ` Bernd Schubert
2023-06-26 15:22 ` Bernd Schubert
[not found] ` <168605707262.32244.4794425063054676856.stgit@manet.1015granger.net>
2023-06-26 13:18 ` Bernd Schubert [this message]
2023-06-26 15:16 ` [PATCH v3 3/3] shmem: stable directory offsets Chuck Lever III
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f6191d0e-ede3-620b-ae96-311b001e1ece@fastmail.fm \
--to=bernd.schubert@fastmail.fm \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=cel@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=hughd@google.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox