2022-03-05 20:29:01

by Trond Myklebust

[permalink] [raw]
Subject: Re: [PATCH -next 2/2] nfs: nfs_file_write() check writeback errors correctly

On Sat, 2022-03-05 at 20:46 +0800, ChenXiaoSong wrote:
> If nobody has seen the writeback error yet, then
> filemap_sample_wb_err()
> always return 0. Even if there is no new writeback error between
> filemap_sample_wb_err() and filemap_check_wb_err(),
> filemap_check_wb_err() will return the old error.
>
> Fix this by using file->f_mapping->wb_err as the old error.
>
> Fixes: ce368536dd61 ("nfs: nfs_file_write() should check for
> writeback errors")
> Signed-off-by: ChenXiaoSong <[email protected]>
> ---
>  fs/nfs/file.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/nfs/file.c b/fs/nfs/file.c
> index 83d63bce9596..8763f89c176a 100644
> --- a/fs/nfs/file.c
> +++ b/fs/nfs/file.c
> @@ -635,7 +635,7 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct
> iov_iter *from)
>  
>         nfs_clear_invalid_mapping(file->f_mapping);
>  
> -       since = filemap_sample_wb_err(file->f_mapping);
> +       since = file->f_mapping->wb_err;
>         nfs_start_io_write(inode);
>         result = generic_write_checks(iocb, from);
>         if (result > 0) {
> @@ -669,7 +669,7 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct
> iov_iter *from)
>                 goto out;
>  
>         /* Return error values */
> -       error = filemap_check_wb_err(file->f_mapping, since);
> +       error = errseq_check(&file->f_mapping->wb_err, since);
>         if (nfs_need_check_write(file, inode, error)) {
>                 int err = nfs_wb_all(inode);
>                 if (err < 0)

Hmm... Why isn't this considered a bug with filemap_sample_wb_err()? If
what you say is true, then do_dentry_open() could be picking up
existing errors from the filesystem and from the inode and propagating
them to random processes.

It basically means everyone who cares about correctness of the error
return values needs to do a fsync() immediately after open() in order
to sync up the value in file->f_wb_err.

--
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]



2022-03-06 11:34:51

by ChenXiaoSong

[permalink] [raw]
Subject: Re: [PATCH -next 2/2] nfs: nfs_file_write() check writeback errors correctly

filemap_sample_wb_err() -> errseq_sample() initialise errseq_t variable
`since`, the caller of this function will checks for an error using
filemap_check_wb_err(since) -> errseq_check().

filemap_sample_wb_err's purpose is just sampling consumed (seen)
writeback error to initialise errseq_t variable. I understand that
filemap_sample_wb_err()/filemap_check_wb_err() cannot detect the new
error between filemap_sample_wb_err() and filemap_check_wb_err().

It would be better using file->f_mapping->wb_err instead of
filemap_sample_wb_err() in nfs_file_write() to sample wb_err at that
time point.

In do_dentry_open(), we just sample consumed(seen) writeback error. It
is necessary to consume the writeback error before close() over.

There is some cases that writeback error have not been consumed(seen)
after close() file over, I think it is unexpected behavior, is this a
bug? It is worth noting that fsync() will not be called after close() in
nfs.

在 2022/3/6 1:12, Trond Myklebust 写道:
> Hmm... Why isn't this considered a bug with filemap_sample_wb_err()? If
> what you say is true, then do_dentry_open() could be picking up
> existing errors from the filesystem and from the inode and propagating
> them to random processes.
>
> It basically means everyone who cares about correctness of the error
> return values needs to do a fsync() immediately after open() in order
> to sync up the value in file->f_wb_err.
>