Skip to content

Commit

Permalink
NFS: report and clear ENOSPC/EFBIG/EDQUOT writeback error on close() …
Browse files Browse the repository at this point in the history
…file

Currently, we report and clear ENOSPC/EFBIG/EDQUOT writeback error on write(),
write() file will report unexpected error if previous writeback error have not
been cleared.

Reproducer:
        nfs server            |       nfs client
 -----------------------------|---------------------------------------------
 # No space left on server    |
 fallocate -l 100G /svr/nospc |
                              | mount -t nfs $nfs_server_ip:/ /mnt
                              |
                              | # Expected error: No space left on device
                              | dd if=/dev/zero of=/mnt/file count=1 ibs=10K
                              |
                              | # Release space on mountpoint
                              | rm /mnt/nospc
                              |
                              | # Just write 512B and report unexpected error
                              | dd if=/dev/zero of=/mnt/file count=1 ibs=10K

Fix this by clearing ENOSPC/EFBIG/EDQUOT writeback error on close file,
it will not clear other errors that are not supposed to be reported by close().

Signed-off-by: ChenXiaoSong <chenxiaosong2@huawei.com>
  • Loading branch information
ChenXiaoSong authored and intel-lab-lkp committed Jun 14, 2022
1 parent b13bacc commit f652526
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
16 changes: 8 additions & 8 deletions fs/nfs/file.c
Expand Up @@ -138,7 +138,7 @@ static int
nfs_file_flush(struct file *file, fl_owner_t id)
{
struct inode *inode = file_inode(file);
errseq_t since;
errseq_t since, error;

dprintk("NFS: flush(%pD2)\n", file);

Expand All @@ -149,7 +149,12 @@ nfs_file_flush(struct file *file, fl_owner_t id)
/* Flush writes to the server and return any errors */
since = filemap_sample_wb_err(file->f_mapping);
nfs_wb_all(inode);
return filemap_check_wb_err(file->f_mapping, since);
error = filemap_check_wb_err(file->f_mapping, since);

if (nfs_should_clear_wb_err(error))
file_check_and_advance_wb_err(file);

return error;
}

ssize_t
Expand Down Expand Up @@ -673,12 +678,7 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)
out:
/* Return error values */
error = filemap_check_wb_err(file->f_mapping, since);
switch (error) {
default:
break;
case -EDQUOT:
case -EFBIG:
case -ENOSPC:
if (nfs_should_clear_wb_err(error)) {
nfs_wb_all(inode);
error = file_check_and_advance_wb_err(file);
if (error < 0)
Expand Down
10 changes: 10 additions & 0 deletions fs/nfs/internal.h
Expand Up @@ -859,3 +859,13 @@ static inline void nfs_set_port(struct sockaddr *sap, int *port,

rpc_set_port(sap, *port);
}

static inline bool nfs_should_clear_wb_err(int error) {
switch (error) {
case -EDQUOT:
case -EFBIG:
case -ENOSPC:
return true;
}
return false;
}
9 changes: 7 additions & 2 deletions fs/nfs/nfs4file.c
Expand Up @@ -113,7 +113,7 @@ static int
nfs4_file_flush(struct file *file, fl_owner_t id)
{
struct inode *inode = file_inode(file);
errseq_t since;
errseq_t since, error;

dprintk("NFS: flush(%pD2)\n", file);

Expand All @@ -131,7 +131,12 @@ nfs4_file_flush(struct file *file, fl_owner_t id)
/* Flush writes to the server and return any errors */
since = filemap_sample_wb_err(file->f_mapping);
nfs_wb_all(inode);
return filemap_check_wb_err(file->f_mapping, since);
error = filemap_check_wb_err(file->f_mapping, since);

if (nfs_should_clear_wb_err(error))
file_check_and_advance_wb_err(file);

return error;
}

#ifdef CONFIG_NFS_V4_2
Expand Down

0 comments on commit f652526

Please sign in to comment.