|
|
aeab634 |
From: Trond Myklebust <Trond.Myklebust@netapp.com>
|
|
|
aeab634 |
|
|
|
aeab634 |
If the file wasn't opened for writing, then truncate and ftruncate
|
|
|
aeab634 |
need to report the appropriate errors.
|
|
|
aeab634 |
|
|
|
aeab634 |
Reported-by: Miklos Szeredi <miklos@szeredi.hu>
|
|
|
aeab634 |
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
|
|
|
aeab634 |
Cc: stable@vger.kernel.org
|
|
|
aeab634 |
---
|
|
|
aeab634 |
fs/nfs/dir.c | 4 ++--
|
|
|
aeab634 |
fs/nfs/nfs4proc.c | 15 ++++++++++++---
|
|
|
aeab634 |
2 files changed, 14 insertions(+), 5 deletions(-)
|
|
|
aeab634 |
|
|
|
aeab634 |
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
|
|
|
aeab634 |
index bb132a8..51a2686 100644
|
|
|
aeab634 |
--- a/fs/nfs/dir.c
|
|
|
aeab634 |
+++ b/fs/nfs/dir.c
|
|
|
aeab634 |
@@ -1429,7 +1429,7 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
|
|
|
aeab634 |
}
|
|
|
aeab634 |
|
|
|
aeab634 |
open_flags = nd->intent.open.flags;
|
|
|
aeab634 |
- attr.ia_valid = 0;
|
|
|
aeab634 |
+ attr.ia_valid = ATTR_OPEN;
|
|
|
aeab634 |
|
|
|
aeab634 |
ctx = create_nfs_open_context(dentry, open_flags);
|
|
|
aeab634 |
res = ERR_CAST(ctx);
|
|
|
aeab634 |
@@ -1536,7 +1536,7 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd)
|
|
|
aeab634 |
if (IS_ERR(ctx))
|
|
|
aeab634 |
goto out;
|
|
|
aeab634 |
|
|
|
aeab634 |
- attr.ia_valid = 0;
|
|
|
aeab634 |
+ attr.ia_valid = ATTR_OPEN;
|
|
|
aeab634 |
if (openflags & O_TRUNC) {
|
|
|
aeab634 |
attr.ia_valid |= ATTR_SIZE;
|
|
|
aeab634 |
attr.ia_size = 0;
|
|
|
aeab634 |
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
|
|
|
aeab634 |
index c4c6b48..e2a2893 100644
|
|
|
aeab634 |
--- a/fs/nfs/nfs4proc.c
|
|
|
aeab634 |
+++ b/fs/nfs/nfs4proc.c
|
|
|
aeab634 |
@@ -1921,10 +1921,19 @@ static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
|
|
|
aeab634 |
};
|
|
|
aeab634 |
int err;
|
|
|
aeab634 |
do {
|
|
|
aeab634 |
- err = nfs4_handle_exception(server,
|
|
|
aeab634 |
- _nfs4_do_setattr(inode, cred, fattr, sattr, state),
|
|
|
aeab634 |
- &exception);
|
|
|
aeab634 |
+ err = _nfs4_do_setattr(inode, cred, fattr, sattr, state);
|
|
|
aeab634 |
+ switch (err) {
|
|
|
aeab634 |
+ case -NFS4ERR_OPENMODE:
|
|
|
aeab634 |
+ if (state && !(state->state & FMODE_WRITE)) {
|
|
|
aeab634 |
+ err = -EBADF;
|
|
|
aeab634 |
+ if (sattr->ia_valid & ATTR_OPEN)
|
|
|
aeab634 |
+ err = -EACCES;
|
|
|
aeab634 |
+ goto out;
|
|
|
aeab634 |
+ }
|
|
|
aeab634 |
+ }
|
|
|
aeab634 |
+ err = nfs4_handle_exception(server, err, &exception);
|
|
|
aeab634 |
} while (exception.retry);
|
|
|
aeab634 |
+out:
|
|
|
aeab634 |
return err;
|
|
|
aeab634 |
}
|
|
|
aeab634 |
|
|
|
aeab634 |
--
|
|
|
aeab634 |
1.7.7.6
|
|
|
aeab634 |
|
|
|
aeab634 |
_______________________________________________
|
|
|
aeab634 |
kernel mailing list
|
|
|
aeab634 |
kernel@lists.fedoraproject.org
|
|
|
aeab634 |
https://admin.fedoraproject.org/mailman/listinfo/kernel
|