Commit 5f004cf2 authored by Trond Myklebust's avatar Trond Myklebust

NFS: Make read() return an ESTALE if the file has been deleted

Currently, a read() request will return EIO even if the file has been
deleted on the server, simply because that is what the VM will return
if the call to readpage() fails to update the page.

Ensure that readpage() marks the inode as stale if it receives an ESTALE.
Then return that error to userland.
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 2dec5146
...@@ -568,8 +568,13 @@ int nfs_readpage_result(struct rpc_task *task, struct nfs_read_data *data) ...@@ -568,8 +568,13 @@ int nfs_readpage_result(struct rpc_task *task, struct nfs_read_data *data)
nfs_add_stats(data->inode, NFSIOS_SERVERREADBYTES, resp->count); nfs_add_stats(data->inode, NFSIOS_SERVERREADBYTES, resp->count);
/* Is this a short read? */ if (task->tk_status < 0) {
if (task->tk_status >= 0 && resp->count < argp->count && !resp->eof) { if (task->tk_status == -ESTALE) {
set_bit(NFS_INO_STALE, &NFS_FLAGS(data->inode));
nfs_mark_for_revalidate(data->inode);
}
} else if (resp->count < argp->count && !resp->eof) {
/* This is a short read! */
nfs_inc_stats(data->inode, NFSIOS_SHORTREAD); nfs_inc_stats(data->inode, NFSIOS_SHORTREAD);
/* Has the server at least made some progress? */ /* Has the server at least made some progress? */
if (resp->count != 0) { if (resp->count != 0) {
...@@ -616,6 +621,10 @@ int nfs_readpage(struct file *file, struct page *page) ...@@ -616,6 +621,10 @@ int nfs_readpage(struct file *file, struct page *page)
if (error) if (error)
goto out_error; goto out_error;
error = -ESTALE;
if (NFS_STALE(inode))
goto out_error;
if (file == NULL) { if (file == NULL) {
ctx = nfs_find_open_context(inode, NULL, FMODE_READ); ctx = nfs_find_open_context(inode, NULL, FMODE_READ);
if (ctx == NULL) if (ctx == NULL)
...@@ -678,7 +687,7 @@ int nfs_readpages(struct file *filp, struct address_space *mapping, ...@@ -678,7 +687,7 @@ int nfs_readpages(struct file *filp, struct address_space *mapping,
}; };
struct inode *inode = mapping->host; struct inode *inode = mapping->host;
struct nfs_server *server = NFS_SERVER(inode); struct nfs_server *server = NFS_SERVER(inode);
int ret; int ret = -ESTALE;
dprintk("NFS: nfs_readpages (%s/%Ld %d)\n", dprintk("NFS: nfs_readpages (%s/%Ld %d)\n",
inode->i_sb->s_id, inode->i_sb->s_id,
...@@ -686,6 +695,9 @@ int nfs_readpages(struct file *filp, struct address_space *mapping, ...@@ -686,6 +695,9 @@ int nfs_readpages(struct file *filp, struct address_space *mapping,
nr_pages); nr_pages);
nfs_inc_stats(inode, NFSIOS_VFSREADPAGES); nfs_inc_stats(inode, NFSIOS_VFSREADPAGES);
if (NFS_STALE(inode))
goto out;
if (filp == NULL) { if (filp == NULL) {
desc.ctx = nfs_find_open_context(inode, NULL, FMODE_READ); desc.ctx = nfs_find_open_context(inode, NULL, FMODE_READ);
if (desc.ctx == NULL) if (desc.ctx == NULL)
...@@ -701,6 +713,7 @@ int nfs_readpages(struct file *filp, struct address_space *mapping, ...@@ -701,6 +713,7 @@ int nfs_readpages(struct file *filp, struct address_space *mapping,
ret = err; ret = err;
} }
put_nfs_open_context(desc.ctx); put_nfs_open_context(desc.ctx);
out:
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment