diff options
author | Trond Myklebust <Trond.Myklebust@netapp.com> | 2012-04-18 16:29:11 -0400 |
---|---|---|
committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2012-04-19 13:23:09 -0400 |
commit | 451146be933e26e21277852b5e40c6a52266ef96 (patch) | |
tree | 207795769b9e1b18952f67fda9db5c7259fb9d63 /fs | |
parent | 55725513b5ef9d462aa3e18527658a0362aaae83 (diff) |
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: Miklos Szeredi <miklos@szeredi.hu>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Cc: stable@vger.kernel.org
Diffstat (limited to 'fs')
-rw-r--r-- | fs/nfs/dir.c | 4 | ||||
-rw-r--r-- | fs/nfs/nfs4proc.c | 15 |
2 files changed, 14 insertions, 5 deletions
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 4aaf0316d76a..8789210c6905 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c | |||
@@ -1429,7 +1429,7 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry | |||
1429 | } | 1429 | } |
1430 | 1430 | ||
1431 | open_flags = nd->intent.open.flags; | 1431 | open_flags = nd->intent.open.flags; |
1432 | attr.ia_valid = 0; | 1432 | attr.ia_valid = ATTR_OPEN; |
1433 | 1433 | ||
1434 | ctx = create_nfs_open_context(dentry, open_flags); | 1434 | ctx = create_nfs_open_context(dentry, open_flags); |
1435 | res = ERR_CAST(ctx); | 1435 | res = ERR_CAST(ctx); |
@@ -1536,7 +1536,7 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd) | |||
1536 | if (IS_ERR(ctx)) | 1536 | if (IS_ERR(ctx)) |
1537 | goto out; | 1537 | goto out; |
1538 | 1538 | ||
1539 | attr.ia_valid = 0; | 1539 | attr.ia_valid = ATTR_OPEN; |
1540 | if (openflags & O_TRUNC) { | 1540 | if (openflags & O_TRUNC) { |
1541 | attr.ia_valid |= ATTR_SIZE; | 1541 | attr.ia_valid |= ATTR_SIZE; |
1542 | attr.ia_size = 0; | 1542 | attr.ia_size = 0; |
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index ba837d977a1a..f875cf305237 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c | |||
@@ -1954,10 +1954,19 @@ static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, | |||
1954 | }; | 1954 | }; |
1955 | int err; | 1955 | int err; |
1956 | do { | 1956 | do { |
1957 | err = nfs4_handle_exception(server, | 1957 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
1958 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), | 1958 | switch (err) { |
1959 | &exception); | 1959 | case -NFS4ERR_OPENMODE: |
1960 | if (state && !(state->state & FMODE_WRITE)) { | ||
1961 | err = -EBADF; | ||
1962 | if (sattr->ia_valid & ATTR_OPEN) | ||
1963 | err = -EACCES; | ||
1964 | goto out; | ||
1965 | } | ||
1966 | } | ||
1967 | err = nfs4_handle_exception(server, err, &exception); | ||
1960 | } while (exception.retry); | 1968 | } while (exception.retry); |
1969 | out: | ||
1961 | return err; | 1970 | return err; |
1962 | } | 1971 | } |
1963 | 1972 | ||