All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cachefiles: Fix incorrect length to fallocate()
@ 2022-03-03 11:55 David Howells
  2022-03-03 12:51 ` Jeff Layton
  0 siblings, 1 reply; 3+ messages in thread
From: David Howells @ 2022-03-03 11:55 UTC (permalink / raw)
  To: jlayton; +Cc: Jeffle Xu, linux-cachefs, dhowells, linux-fsdevel, linux-kernel

When cachefiles_shorten_object() calls fallocate() to shape the cache file
to match the DIO size, it passes the total file size it wants to achieve,
not the amount of zeros that should be inserted.  Since this is meant to
preallocate that amount of storage for the file, it can cause the cache to
fill up the disk and hit ENOSPC.

Fix this by passing the length actually required to go from the current EOF
to the desired EOF.

Fixes: 7623ed6772de ("cachefiles: Implement cookie resize for truncate")
Reported-by: Jeffle Xu <jefflexu@linux.alibaba.com>
Signed-off-by: David Howells <dhowells@redhat.com>
cc: linux-cachefs@redhat.com
---

 fs/cachefiles/interface.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c
index 51c968cd00a6..ae93cee9d25d 100644
--- a/fs/cachefiles/interface.c
+++ b/fs/cachefiles/interface.c
@@ -254,7 +254,7 @@ static bool cachefiles_shorten_object(struct cachefiles_object *object,
 		ret = cachefiles_inject_write_error();
 		if (ret == 0)
 			ret = vfs_fallocate(file, FALLOC_FL_ZERO_RANGE,
-					    new_size, dio_size);
+					    new_size, dio_size - new_size);
 		if (ret < 0) {
 			trace_cachefiles_io_error(object, file_inode(file), ret,
 						  cachefiles_trace_fallocate_error);



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

* Re: [PATCH] cachefiles: Fix incorrect length to fallocate()
  2022-03-03 11:55 [PATCH] cachefiles: Fix incorrect length to fallocate() David Howells
@ 2022-03-03 12:51 ` Jeff Layton
  0 siblings, 0 replies; 3+ messages in thread
From: Jeff Layton @ 2022-03-03 12:51 UTC (permalink / raw)
  To: David Howells; +Cc: Jeffle Xu, linux-cachefs, linux-fsdevel, linux-kernel

On Thu, 2022-03-03 at 11:55 +0000, David Howells wrote:
> When cachefiles_shorten_object() calls fallocate() to shape the cache file
> to match the DIO size, it passes the total file size it wants to achieve,
> not the amount of zeros that should be inserted.  Since this is meant to
> preallocate that amount of storage for the file, it can cause the cache to
> fill up the disk and hit ENOSPC.
> 
> Fix this by passing the length actually required to go from the current EOF
> to the desired EOF.
> 
> Fixes: 7623ed6772de ("cachefiles: Implement cookie resize for truncate")
> Reported-by: Jeffle Xu <jefflexu@linux.alibaba.com>
> Signed-off-by: David Howells <dhowells@redhat.com>
> cc: linux-cachefs@redhat.com
> ---
> 
>  fs/cachefiles/interface.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c
> index 51c968cd00a6..ae93cee9d25d 100644
> --- a/fs/cachefiles/interface.c
> +++ b/fs/cachefiles/interface.c
> @@ -254,7 +254,7 @@ static bool cachefiles_shorten_object(struct cachefiles_object *object,
>  		ret = cachefiles_inject_write_error();
>  		if (ret == 0)
>  			ret = vfs_fallocate(file, FALLOC_FL_ZERO_RANGE,
> -					    new_size, dio_size);
> +					    new_size, dio_size - new_size);
>  		if (ret < 0) {
>  			trace_cachefiles_io_error(object, file_inode(file), ret,
>  						  cachefiles_trace_fallocate_error);
> 
> 

Looks good!

I could often force the cache to fill up with the right fsstress run on
ceph, but with this in place I'm on the 5th run of xfstest generic/013
and it hasn't happened yet. You can add these if you like:

Tested-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Jeff Layton <jlayton@kernel.org>

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

* [PATCH] cachefiles: Fix incorrect length to fallocate()
@ 2022-03-03 13:05 David Howells
  0 siblings, 0 replies; 3+ messages in thread
From: David Howells @ 2022-03-03 13:05 UTC (permalink / raw)
  To: torvalds
  Cc: Jeffle Xu, Jeff Layton, Jeff Layton, linux-cachefs, dhowells,
	linux-fsdevel, linux-kernel

When cachefiles_shorten_object() calls fallocate() to shape the cache file
to match the DIO size, it passes the total file size it wants to achieve,
not the amount of zeros that should be inserted.  Since this is meant to
preallocate that amount of storage for the file, it can cause the cache to
fill up the disk and hit ENOSPC.

Fix this by passing the length actually required to go from the current EOF
to the desired EOF.

Fixes: 7623ed6772de ("cachefiles: Implement cookie resize for truncate")
Reported-by: Jeffle Xu <jefflexu@linux.alibaba.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Tested-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
cc: linux-cachefs@redhat.com
Link: https://lore.kernel.org/r/164630854858.3665356.17419701804248490708.stgit@warthog.procyon.org.uk # v1
---

 fs/cachefiles/interface.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c
index 51c968cd00a6..ae93cee9d25d 100644
--- a/fs/cachefiles/interface.c
+++ b/fs/cachefiles/interface.c
@@ -254,7 +254,7 @@ static bool cachefiles_shorten_object(struct cachefiles_object *object,
 		ret = cachefiles_inject_write_error();
 		if (ret == 0)
 			ret = vfs_fallocate(file, FALLOC_FL_ZERO_RANGE,
-					    new_size, dio_size);
+					    new_size, dio_size - new_size);
 		if (ret < 0) {
 			trace_cachefiles_io_error(object, file_inode(file), ret,
 						  cachefiles_trace_fallocate_error);



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

end of thread, other threads:[~2022-03-03 13:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-03 11:55 [PATCH] cachefiles: Fix incorrect length to fallocate() David Howells
2022-03-03 12:51 ` Jeff Layton
2022-03-03 13:05 David Howells

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.