diff mbox series

[v2,18/19] netfs: Keep track of the actual remote file size

Message ID 164678219305.1200972.6459431995188365134.stgit@warthog.procyon.org.uk (mailing list archive)
State New, archived
Headers show
Series netfs: Prep for write helpers | expand

Commit Message

David Howells March 8, 2022, 11:29 p.m. UTC
Provide a place in which to keep track of the actual remote file size in
the netfs context.  This is needed because inode->i_size will be updated as
we buffer writes in the pagecache, but the server file size won't get
updated until we flush them back.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: linux-cachefs@redhat.com

Link: https://lore.kernel.org/r/164623013727.3564931.17659955636985232717.stgit@warthog.procyon.org.uk/ # v1
---

 include/linux/netfs.h |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Jeff Layton March 9, 2022, 8:45 p.m. UTC | #1
On Tue, 2022-03-08 at 23:29 +0000, David Howells wrote:
> Provide a place in which to keep track of the actual remote file size in
> the netfs context.  This is needed because inode->i_size will be updated as
> we buffer writes in the pagecache, but the server file size won't get
> updated until we flush them back.
> 
> Signed-off-by: David Howells <dhowells@redhat.com>
> cc: linux-cachefs@redhat.com
> 
> Link: https://lore.kernel.org/r/164623013727.3564931.17659955636985232717.stgit@warthog.procyon.org.uk/ # v1
> ---
> 
>  include/linux/netfs.h |   16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/include/linux/netfs.h b/include/linux/netfs.h
> index 8458b30172a5..c7bf1eaf51d5 100644
> --- a/include/linux/netfs.h
> +++ b/include/linux/netfs.h
> @@ -126,6 +126,7 @@ struct netfs_i_context {
>  #if IS_ENABLED(CONFIG_FSCACHE)
>  	struct fscache_cookie	*cache;
>  #endif
> +	loff_t			remote_i_size;	/* Size of the remote file */
>  };
>  
>  /*
> @@ -324,6 +325,21 @@ static inline void netfs_i_context_init(struct inode *inode,
>  
>  	memset(ctx, 0, sizeof(*ctx));
>  	ctx->ops = ops;
> +	ctx->remote_i_size = i_size_read(inode);
> +}
> +
> +/**
> + * netfs_resize_file - Note that a file got resized
> + * @inode: The inode being resized
> + * @new_i_size: The new file size
> + *
> + * Inform the netfs lib that a file got resized so that it can adjust its state.
> + */
> +static inline void netfs_resize_file(struct inode *inode, loff_t new_i_size)
> +{
> +	struct netfs_i_context *ctx = netfs_i_context(inode);
> +
> +	ctx->remote_i_size = new_i_size;
>  }
>  
>  /**
> 
> 

This seems like something useful, but I wonder if it'll need some sort
of serialization vs. concurrent updates. Can we assume that netfs itself
will never call netfs_resize_file?

Ceph already has some pretty complicated size tracking, since it can get
async notifications of size changes from the MDS. We'll have to consider
how to integrate this with what it does. Probably this will replace one
(or more?) of its fields.

We may need to offer up some guidance wrt locking.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
David Howells March 9, 2022, 10:27 p.m. UTC | #2
Jeff Layton <jlayton@kernel.org> wrote:

> This seems like something useful, but I wonder if it'll need some sort
> of serialization vs. concurrent updates.

Quite possibly, though that may be something that we have to delegate to the
network filesystem.  kafs, for instance, performs local serialisation of
StoreData RPCs to any given inode because the server will exclusively lock the
remote vnode around the write-to-disk and callback break (ie. change
notification) phases.  This does not preclude, however, another client making
a change whilst the local lock is held.  Of course, in such a case, we're into
conflict resolution and may end up invalidating the local copy.

> Can we assume that netfs itself will never call netfs_resize_file?

Probably.  Depends on how truncation gets handled.

> Ceph already has some pretty complicated size tracking, since it can get
> async notifications of size changes from the MDS. We'll have to consider
> how to integrate this with what it does. Probably this will replace one
> (or more?) of its fields.

ceph's i_reported_size maybe?  cifs has server_eof.

> We may need to offer up some guidance wrt locking.

i_lock may be a good fit.  I wonder if it's worth at some point moving i_lock
to being a seqlock so that various values ordinarily protected by it are
accessible using read_seqbegin().

David
diff mbox series

Patch

diff --git a/include/linux/netfs.h b/include/linux/netfs.h
index 8458b30172a5..c7bf1eaf51d5 100644
--- a/include/linux/netfs.h
+++ b/include/linux/netfs.h
@@ -126,6 +126,7 @@  struct netfs_i_context {
 #if IS_ENABLED(CONFIG_FSCACHE)
 	struct fscache_cookie	*cache;
 #endif
+	loff_t			remote_i_size;	/* Size of the remote file */
 };
 
 /*
@@ -324,6 +325,21 @@  static inline void netfs_i_context_init(struct inode *inode,
 
 	memset(ctx, 0, sizeof(*ctx));
 	ctx->ops = ops;
+	ctx->remote_i_size = i_size_read(inode);
+}
+
+/**
+ * netfs_resize_file - Note that a file got resized
+ * @inode: The inode being resized
+ * @new_i_size: The new file size
+ *
+ * Inform the netfs lib that a file got resized so that it can adjust its state.
+ */
+static inline void netfs_resize_file(struct inode *inode, loff_t new_i_size)
+{
+	struct netfs_i_context *ctx = netfs_i_context(inode);
+
+	ctx->remote_i_size = new_i_size;
 }
 
 /**