NFS: Add FATTR4_WORD1_SPACE_USED to the cache_consistency_bitmask
Subsystems (2)
PATCH 1/2 NFS: Add FATTR4_WORD1_SPACE_USED to the cache_consistency_bitmask
From: Anna Schumaker <[email protected]>
Changing a sparse file could have an effect not only on the file size, but also on the number of blocks used by the file in the underlying filesystem. Let's update the SPACE_USED attribute whenever we update SIZE to be as accurate as possible.
This patch fixes xfstests generic/568, which tests that fallocating an unaligned range allocates all blocks touched by that range. Without this patch, stat reports 0 bytes used immediately after the fallocate. Adding a sleep 5 to the test also catches the update, but it's better to just do it when we know something has changed.
--- fs/nfs/nfs4proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/nfs4proc.c +1 -1
@@ -3775,7 +3775,7 @@ static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fmemcpy (server->cache_consistency_bitmask, res.attr_bitmask,sizeof (server->cache_consistency_bitmask)); server->cache_consistency_bitmask[0 ] &=FATTR4_WORD0_CHANGE |FATTR4_WORD0_SIZE ; - server->cache_consistency_bitmask[1 ] &=FATTR4_WORD1_TIME_METADATA |FATTR4_WORD1_TIME_MODIFY ; + server->cache_consistency_bitmask[1 ] &=FATTR4_WORD1_TIME_METADATA |FATTR4_WORD1_TIME_MODIFY |FATTR4_WORD1_SPACE_USED ; server->cache_consistency_bitmask[2 ] =0 ;/* Avoid a regression due to buggy server */
Signature · 1 line
2.24.0
PATCH 2/2 NFS: Return -ETXTBSY when attempting to write to a swapfile
From: Anna Schumaker <[email protected]>
My understanding is that -EBUSY refers to the underlying device, and that -ETXTBSY is used when attempting to access a file in use by the kernel (like a swapfile). Changing this return code helps us pass xfstests generic/569
--- fs/nfs/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/file.c +1 -1
@@ -649,7 +649,7 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) out_swapfile:printk (KERN_INFO "NFS: attempt to write to active swap file!\n" ); -return -EBUSY ; +return -ETXTBSY ; }EXPORT_SYMBOL_GPL (nfs_file_write);
Signature · 1 line
2.24.0
Quoted 36 lines · On Fri, 2019-11-08 at 16:02 -0500, [email protected] wrote:
From: Anna Schumaker <[email protected]>
Changing a sparse file could have an effect not only on the file size,
but also on the number of blocks used by the file in the underlying filesystem. Let's update theSPACE_USEDattribute whenever we update SIZE to be as accurate as possible.This patch fixes xfstests generic/568, which tests that fallocating an
unaligned range allocates all blocks touched by that range. Without this
patch,statreports 0 bytes used immediately after the fallocate. Adding asleep 5to the test also catches the update, but it's better
to just do it when we know something has changed.Signed-off-by Anna Schumaker <[email protected]>--- fs/nfs/nfs4proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/nfs/nfs4proc.c +0
-0@@ -3775,7 +3775,7 @@ static int _nfs4_server_capabilities(struct
nfs_server*server, structnfs_fh*fmemcpy(server->cache_consistency_bitmask,
res.attr_bitmask,sizeof(server->cache_consistency_bitmask));
server->cache_consistency_bitmask[0] &=
FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE;fs/nfs/nfs4proc.c +0
-1- server->cache_consistency_bitmask[1] &=FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
fs/nfs/nfs4proc.c +1
-0+ server->cache_consistency_bitmask[1] &=
Quoted 2 lines
FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY|FATTR4_WORD1_SPAC
E_USED;
I'd rather not do this. Space used is not a cache consistency attribute , as we do not use it to revalidate the cache and it can be rather expensive to retrieve on some platforms.
I'd therefore prefer that we just make sure we mark the cache validity with NFS_INO_INVALID_OTHER when we have a write succeed on a sparse file.
Quoted 3 lines
fs/nfs/nfs4proc.c +0
-0server->cache_consistency_bitmask[2 ] =0 ;/* Avoid a regression due to buggy server */
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Hi Trond,
Quoted 30 lines · Trond Myklebust
Quoted 29 lines · On Fri, 2019-11-08 at 16:02 -0500, [email protected] wrote:
From: Anna Schumaker <[email protected]>
Changing a sparse file could have an effect not only on the file size,
but also on the number of blocks used by the file in the underlying filesystem. Let's update theSPACE_USEDattribute whenever we update SIZE to be as accurate as possible.This patch fixes xfstests generic/568, which tests that fallocating an
unaligned range allocates all blocks touched by that range. Without this
patch,statreports 0 bytes used immediately after the fallocate. Adding asleep 5to the test also catches the update, but it's better
to just do it when we know something has changed.Signed-off-by Anna Schumaker <[email protected]>--- fs/nfs/nfs4proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/nfs/nfs4proc.c +0
-0@@ -3775,7 +3775,7 @@ static int _nfs4_server_capabilities(struct
nfs_server*server, structnfs_fh*f
Quoted 13 lines
Quoted 9 lines
memcpy(server->cache_consistency_bitmask,
res.attr_bitmask,sizeof(server->cache_consistency_bitmask));
server->cache_consistency_bitmask[0] &=
FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE;fs/nfs/nfs4proc.c +0
-1- server->cache_consistency_bitmask[1] &=FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
fs/nfs/nfs4proc.c +1
-0+ server->cache_consistency_bitmask[1] &=FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY|FATTR4_WORD1_SPAC
E_USED;I'd rather not do this. Space used is not a cache consistency attribute , as we do not use it to revalidate the cache and it can be rather expensive to retrieve on some platforms.
Okay, that makes sense.
Quoted 4 lines
I'd therefore prefer that we just make sure we mark the cache validity with
NFS_INO_INVALID_OTHERwhen we have a write succeed on a sparse file.
It looks like setting falloc_bitmask to use the standard nfs4_fattr_bitmap instead of the cache_consistency_bitmask will also update the SPACE_USED attribute after a fallocate call.
I'll play around with NFS_INO_INVALID_OTHER next, but making use of the trailing getattr that ALLOCATE and DEALLOCATE already have seems more straightforward to me.
Anna
Quoted 10 lines
Quoted 4 lines
fs/nfs/nfs4proc.c +0
-0server->cache_consistency_bitmask[2 ] =0 ;/* Avoid a regression due to buggy server */ Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]