nfs: propagate fileid changed errors back to syscall
Subsystems (2)
PATCH 1/1 nfs: propagate fileid changed errors back to syscall
Hello! This is the first kernel patch I have tried to upstream. I'm following along with the kernel newbies guide but apologies if I got anything wrong.
Currently, if there is a mismatch in the request and response fileids in an NFS request, the kernel logs an error and attempts to return ESTALE. However, this error is currently dropped before it makes it all the way to userspace. This appears to be a mistake, since as far as I can tell that ESTALE value is never consumed from anywhere.
Callstack for async NFS write, at time of error:
nfs_update_inode <- returns -ESTALE nfs_refresh_inode_locked nfs_writeback_update_inode <- error is dropped here nfs3_write_done
nfs_writeback_done
nfs_pgio_result <- other errors are collected here rpc_exit_task
__rpc_execute
rpc_async_schedule
process_one_work
worker_thread
kthread
ret_from_fork
We ran into this issue ourselves, and seeing the -ESTALE in the kernel source code but not from userspace was surprising.
I tested a rebased version of this patch on an el8 kernel (v6.1.114), and it seems to correctly propagate this error.
Quoted 1 line
8------------------------------------------------------8<
If an NFS server returns a response with a different file id to the response, the kernel currently prints out an error and attempts to return -ESTALE. However, this -ESTALE value is never surfaced anywhere.
This patch modifies nfs_writeback_update_inode() to propagate these errors up the call stack, and modifies nfs_pgio_result() to report the resulting error.
--- fs/nfs/filelayout/filelayout.c | 2 +- fs/nfs/flexfilelayout/flexfilelayout.c | 2 +- fs/nfs/internal.h | 2 +- fs/nfs/nfs3proc.c | 2 +- fs/nfs/nfs4proc.c | 2 +- fs/nfs/pagelist.c | 5 ++++- fs/nfs/proc.c | 2 +- fs/nfs/write.c | 9 ++++++--- 8 files changed, 16 insertions(+), 10 deletions(-)
fs/nfs/filelayout/filelayout.c +1 -1
@@ -335,7 +335,7 @@ static int filelayout_write_done_cb(struct rpc_task *task,/* zero out the fattr */ hdr->fattr.valid =0 ;if (task->tk_status >=0 ) -nfs_writeback_update_inode (hdr); +return nfs_writeback_update_inode (hdr);return 0 ; }
fs/nfs/flexfilelayout/flexfilelayout.c +1 -1
@@ -1503,7 +1503,7 @@ static int ff_layout_write_done_cb(struct rpc_task *task,/* zero out fattr since we don't care DS attr at all */ hdr->fattr.valid =0 ;if (task->tk_status >=0 ) -nfs_writeback_update_inode (hdr); +return nfs_writeback_update_inode (hdr);return 0 ; }
fs/nfs/internal.h +1 -1
@@ -592,7 +592,7 @@ void nfs_mark_request_commit(struct nfs_page *req,struct nfs_commit_info *cinfo, u32 ds_commit_idx);int nfs_write_need_commit (struct nfs_pgio_header *); -void nfs_writeback_update_inode (struct nfs_pgio_header *hdr); +int nfs_writeback_update_inode (struct nfs_pgio_header *hdr);int nfs_generic_commit_list (struct inode *inode,struct list_head *head,int how,struct nfs_commit_info *cinfo); void nfs_retry_commit(struct list_head *page_list,
fs/nfs/nfs3proc.c +1 -1
@@ -887,7 +887,7 @@ static int nfs3_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr)if (nfs3_async_handle_jukebox (task, inode))return -EAGAIN ;if (task->tk_status >=0 ) -nfs_writeback_update_inode (hdr); +return nfs_writeback_update_inode (hdr);return 0 ; }
fs/nfs/nfs4proc.c +1 -1
@@ -5661,7 +5661,7 @@ static int nfs4_write_done_cb(struct rpc_task *task, }if (task->tk_status >=0 ) {renew_lease (NFS_SERVER (inode), hdr->timestamp); -nfs_writeback_update_inode (hdr); +return nfs_writeback_update_inode (hdr); }return 0 ; }
fs/nfs/pagelist.c +4 -1
@@ -854,9 +854,12 @@ static void nfs_pgio_result(struct rpc_task *task, void *calldata) {struct nfs_pgio_header *hdr = calldata;struct inode *inode = hdr->inode; +int status = hdr->rw_ops->rw_done (task, hdr, inode); -if (hdr->rw_ops->rw_done (task, hdr, inode) !=0 ) +if (status !=0 ) { +nfs_set_pgio_error (hdr, status, hdr->args.offset);return ; + }if (task->tk_status <0 )nfs_set_pgio_error (hdr, task->tk_status, hdr->args.offset);else
fs/nfs/proc.c +1 -1
@@ -629,7 +629,7 @@ static int nfs_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr) {if (task->tk_status >=0 ) { hdr->res.count = hdr->args.count; -nfs_writeback_update_inode (hdr); +return nfs_writeback_update_inode (hdr); }return 0 ; }
fs/nfs/write.c +6 -3
@@ -1507,22 +1507,25 @@ static void nfs_writeback_check_extend(struct nfs_pgio_header *hdr, fattr->valid |=NFS_ATTR_FATTR_SIZE ; } -void nfs_writeback_update_inode (struct nfs_pgio_header *hdr) +int nfs_writeback_update_inode (struct nfs_pgio_header *hdr) {struct nfs_fattr *fattr = &hdr->fattr;struct inode *inode = hdr->inode; +int ret =0 ;if (nfs_have_delegated_mtime (inode)) {spin_lock (&inode->i_lock);nfs_set_cache_invalid (inode,NFS_INO_INVALID_BLOCKS );spin_unlock (&inode->i_lock); -return ; +return 0 ; }spin_lock (&inode->i_lock);nfs_writeback_check_extend (hdr, fattr); -nfs_post_op_update_inode_force_wcc_locked (inode, fattr); + ret =nfs_post_op_update_inode_force_wcc_locked (inode, fattr);spin_unlock (&inode->i_lock); + +return ret; }EXPORT_SYMBOL_GPL (nfs_writeback_update_inode);
Signature · 1 line
2.39.3
Quoted 29 lines · Nikhil Jha
Hello! This is the first kernel patch I have tried to upstream. I'm following along with the kernel newbies guide but apologies if I got anything wrong.
Currently, if there is a mismatch in the request and response fileids in an NFS request, the kernel logs an error and attempts to return ESTALE. However, this error is currently dropped before it makes it all the way to userspace. This appears to be a mistake, since as far as I can tell that ESTALE value is never consumed from anywhere.
Callstack for async NFS write, at time of error:
nfs_update_inode<- returns-ESTALEnfs_refresh_inode_lockednfs_writeback_update_inode<- error is dropped herenfs3_write_done
nfs_writeback_done
nfs_pgio_result<- other errors are collected hererpc_exit_task
__rpc_execute
rpc_async_schedule
process_one_work
worker_thread
kthread
ret_from_forkWe ran into this issue ourselves, and seeing the
-ESTALEin the kernel source code but not from userspace was surprising.
Quoted 8 lines
I tested a rebased version of this patch on an el8 kernel (v6.1.114), and it seems to correctly propagate this error.
Quoted 1 line
8------------------------------------------------------8<
If an NFS server returns a response with a different file id to the response, the kernel currently prints out an error and attempts to return
-ESTALE. However, this-ESTALEvalue is never surfaced anywhere.
Hi Nikhil Jha,
Will this cause us to return -ESTALE to the application even if the WRITE was successful?
Ben
Quoted 40 lines · Benjamin Coddington
Quoted 29 lines · Nikhil Jha
Hello! This is the first kernel patch I have tried to upstream. I'm following along with the kernel newbies guide but apologies if I got anything wrong.
Currently, if there is a mismatch in the request and response fileids in an NFS request, the kernel logs an error and attempts to return ESTALE. However, this error is currently dropped before it makes it all the way to userspace. This appears to be a mistake, since as far as I can tell that ESTALE value is never consumed from anywhere.
Callstack for async NFS write, at time of error:
nfs_update_inode<- returns-ESTALEnfs_refresh_inode_lockednfs_writeback_update_inode<- error is dropped herenfs3_write_done
nfs_writeback_done
nfs_pgio_result<- other errors are collected hererpc_exit_task
__rpc_execute
rpc_async_schedule
process_one_work
worker_thread
kthread
ret_from_forkWe ran into this issue ourselves, and seeing the
-ESTALEin the kernel source code but not from userspace was surprising.Quoted 8 lines
I tested a rebased version of this patch on an el8 kernel (v6.1.114), and it seems to correctly propagate this error.
Quoted 1 line
8------------------------------------------------------8<
If an NFS server returns a response with a different file id to the response, the kernel currently prints out an error and attempts to return
-ESTALE. However, this-ESTALEvalue is never surfaced anywhere.
Quoted 7 lines
Hi Nikhil Jha,
Will this cause us to return
-ESTALEto the application even if the WRITE was successful?Ben
Hi Ben,
Hmm.. I'm not sure how to answer that question exactly. A fileid is only mismatched between a request RPC and response RPC when something really weird is going on (i.e. a bug in the NFS server), so it's hard to reason about if a WRITE was successful or not.
The return -ESTALE was already in the kernel code, but this particular codepath seems to have accidentally dropped that error.
Nikhil
Quoted 71 lines · Nikhil Jha
Quoted 51 lines · Benjamin Coddington
Quoted 40 lines · Nikhil Jha
Hello! This is the first kernel patch I have tried to upstream. I'm
following along with the kernel newbies guide but apologies if I got
anything wrong.Currently, if there is a mismatch in the request and response fileids in
an NFS request, the kernel logs an error and attempts to return ESTALE.
However, this error is currently dropped before it makes it all the way
to userspace. This appears to be a mistake, since as far as I can tell
that ESTALE value is never consumed from anywhere.Callstack for async NFS write, at time of error:
nfs_update_inode<- returns-ESTALEnfs_refresh_inode_lockednfs_writeback_update_inode<- error is dropped herenfs3_write_done
nfs_writeback_done
nfs_pgio_result<- other errors are collected hererpc_exit_task
__rpc_execute
rpc_async_schedule
process_one_work
worker_thread
kthread
ret_from_forkWe ran into this issue ourselves, and seeing the
-ESTALEin the kernel
source code but not from userspace was surprising.I tested a rebased version of this patch on an el8 kernel (v6.1.114),
and it seems to correctly propagate this error.Quoted 8 lines
Quoted 1 line
8------------------------------------------------------8<
If an NFS server returns a response with a different file id to the
response, the kernel currently prints out an error and attempts to
return-ESTALE. However, this-ESTALEvalue is never surfaced anywhere.Quoted 8 lines
Hi Nikhil Jha,
Will this cause us to return
-ESTALEto the application even if the WRITE
was successful?Ben
Hi Ben,
Hmm.. I'm not sure how to answer that question exactly. A fileid is only
mismatched between a request RPC and response RPC when something really
weird is going on (i.e. a bug in the NFS server), so it's hard to reason
about if a WRITE was successful or not.
Quoted 6 lines
The
return -ESTALEwas already in the kernel code, but this particular
codepath seems to have accidentally dropped that error.Nikhil
I'm not keen on taking any client changes to paper over what appears to be a major server bug. We simply can't support broken servers that reuse filehandles across files.
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Quoted 76 lines · Trond Myklebust
Quoted 75 lines · Nikhil Jha
Quoted 51 lines · Benjamin Coddington
Quoted 40 lines · Nikhil Jha
Hello! This is the first kernel patch I have tried to upstream. I'm
following along with the kernel newbies guide but apologies if I got
anything wrong.Currently, if there is a mismatch in the request and response fileids in
an NFS request, the kernel logs an error and attempts to return ESTALE.
However, this error is currently dropped before it makes it all the way
to userspace. This appears to be a mistake, since as far as I can tell
that ESTALE value is never consumed from anywhere.Callstack for async NFS write, at time of error:
nfs_update_inode<- returns-ESTALEnfs_refresh_inode_lockednfs_writeback_update_inode<- error is dropped herenfs3_write_done
nfs_writeback_done
nfs_pgio_result<- other errors are collected hererpc_exit_task
__rpc_execute
rpc_async_schedule
process_one_work
worker_thread
kthread
ret_from_forkWe ran into this issue ourselves, and seeing the
-ESTALEin the kernel
source code but not from userspace was surprising.I tested a rebased version of this patch on an el8 kernel (v6.1.114),
and it seems to correctly propagate this error.Quoted 8 lines
Quoted 1 line
8------------------------------------------------------8<
If an NFS server returns a response with a different file id to the
response, the kernel currently prints out an error and attempts to
return-ESTALE. However, this-ESTALEvalue is never surfaced anywhere.Quoted 8 lines
Hi Nikhil Jha,
Will this cause us to return
-ESTALEto the application even if the WRITE
was successful?Ben
Hi Ben,
Hmm.. I'm not sure how to answer that question exactly. A fileid is only
mismatched between a request RPC and response RPC when something really
weird is going on (i.e. a bug in the NFS server), so it's hard to reason
about if a WRITE was successful or not.The
return -ESTALEwas already in the kernel code, but this particular
codepath seems to have accidentally dropped that error.
Quoted 12 lines
Quoted 2 lines
Nikhil
I'm not keen on taking any client changes to paper over what appears to be a major server bug. We simply can't support broken servers that reuse filehandles across files.
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Right, this patch *doesn't* alleviate any server bug from the client. I don't think it would make sense to try to fix a buggy server from the Linux NFS client. What I'm thinking about is...
1. We're already detecting this problem, printing an error message, and trying to return ESTALE.
2. That ESTALE is not propagated anywhere. It just gets dropped.
If we don't want this ESTALE to be visible, should it just get removed entirely? The value does not appear to be consumed from anywhere in the kernel code.