提交 451146be 编写于 作者: T Trond Myklebust

NFSv4: Fix open(O_TRUNC) and ftruncate() error handling

If the file wasn't opened for writing, then truncate and ftruncate
need to report the appropriate errors.
Reported-by: NMiklos Szeredi <miklos@szeredi.hu>
Signed-off-by: NTrond Myklebust <Trond.Myklebust@netapp.com>
Cc: stable@vger.kernel.org
上级 55725513
...@@ -1429,7 +1429,7 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry ...@@ -1429,7 +1429,7 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
} }
open_flags = nd->intent.open.flags; open_flags = nd->intent.open.flags;
attr.ia_valid = 0; attr.ia_valid = ATTR_OPEN;
ctx = create_nfs_open_context(dentry, open_flags); ctx = create_nfs_open_context(dentry, open_flags);
res = ERR_CAST(ctx); res = ERR_CAST(ctx);
...@@ -1536,7 +1536,7 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd) ...@@ -1536,7 +1536,7 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd)
if (IS_ERR(ctx)) if (IS_ERR(ctx))
goto out; goto out;
attr.ia_valid = 0; attr.ia_valid = ATTR_OPEN;
if (openflags & O_TRUNC) { if (openflags & O_TRUNC) {
attr.ia_valid |= ATTR_SIZE; attr.ia_valid |= ATTR_SIZE;
attr.ia_size = 0; attr.ia_size = 0;
......
...@@ -1954,10 +1954,19 @@ static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, ...@@ -1954,10 +1954,19 @@ static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
}; };
int err; int err;
do { do {
err = nfs4_handle_exception(server, err = _nfs4_do_setattr(inode, cred, fattr, sattr, state);
_nfs4_do_setattr(inode, cred, fattr, sattr, state), switch (err) {
&exception); case -NFS4ERR_OPENMODE:
if (state && !(state->state & FMODE_WRITE)) {
err = -EBADF;
if (sattr->ia_valid & ATTR_OPEN)
err = -EACCES;
goto out;
}
}
err = nfs4_handle_exception(server, err, &exception);
} while (exception.retry); } while (exception.retry);
out:
return err; return err;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册