diff options
Diffstat (limited to 'fs/nfs/dir.c')
-rw-r--r-- | fs/nfs/dir.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index fd9a872fada0..bb132a88f4e8 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c | |||
@@ -1429,6 +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 | 1433 | ||
1433 | ctx = create_nfs_open_context(dentry, open_flags); | 1434 | ctx = create_nfs_open_context(dentry, open_flags); |
1434 | res = ERR_CAST(ctx); | 1435 | res = ERR_CAST(ctx); |
@@ -1437,11 +1438,14 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry | |||
1437 | 1438 | ||
1438 | if (nd->flags & LOOKUP_CREATE) { | 1439 | if (nd->flags & LOOKUP_CREATE) { |
1439 | attr.ia_mode = nd->intent.open.create_mode; | 1440 | attr.ia_mode = nd->intent.open.create_mode; |
1440 | attr.ia_valid = ATTR_MODE; | 1441 | attr.ia_valid |= ATTR_MODE; |
1441 | attr.ia_mode &= ~current_umask(); | 1442 | attr.ia_mode &= ~current_umask(); |
1442 | } else { | 1443 | } else |
1443 | open_flags &= ~(O_EXCL | O_CREAT); | 1444 | open_flags &= ~(O_EXCL | O_CREAT); |
1444 | attr.ia_valid = 0; | 1445 | |
1446 | if (open_flags & O_TRUNC) { | ||
1447 | attr.ia_valid |= ATTR_SIZE; | ||
1448 | attr.ia_size = 0; | ||
1445 | } | 1449 | } |
1446 | 1450 | ||
1447 | /* Open the file on the server */ | 1451 | /* Open the file on the server */ |
@@ -1495,6 +1499,7 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd) | |||
1495 | struct inode *inode; | 1499 | struct inode *inode; |
1496 | struct inode *dir; | 1500 | struct inode *dir; |
1497 | struct nfs_open_context *ctx; | 1501 | struct nfs_open_context *ctx; |
1502 | struct iattr attr; | ||
1498 | int openflags, ret = 0; | 1503 | int openflags, ret = 0; |
1499 | 1504 | ||
1500 | if (nd->flags & LOOKUP_RCU) | 1505 | if (nd->flags & LOOKUP_RCU) |
@@ -1523,19 +1528,27 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd) | |||
1523 | /* We cannot do exclusive creation on a positive dentry */ | 1528 | /* We cannot do exclusive creation on a positive dentry */ |
1524 | if ((openflags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL)) | 1529 | if ((openflags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL)) |
1525 | goto no_open_dput; | 1530 | goto no_open_dput; |
1526 | /* We can't create new files, or truncate existing ones here */ | 1531 | /* We can't create new files here */ |
1527 | openflags &= ~(O_CREAT|O_EXCL|O_TRUNC); | 1532 | openflags &= ~(O_CREAT|O_EXCL); |
1528 | 1533 | ||
1529 | ctx = create_nfs_open_context(dentry, openflags); | 1534 | ctx = create_nfs_open_context(dentry, openflags); |
1530 | ret = PTR_ERR(ctx); | 1535 | ret = PTR_ERR(ctx); |
1531 | if (IS_ERR(ctx)) | 1536 | if (IS_ERR(ctx)) |
1532 | goto out; | 1537 | goto out; |
1538 | |||
1539 | attr.ia_valid = 0; | ||
1540 | if (openflags & O_TRUNC) { | ||
1541 | attr.ia_valid |= ATTR_SIZE; | ||
1542 | attr.ia_size = 0; | ||
1543 | nfs_wb_all(inode); | ||
1544 | } | ||
1545 | |||
1533 | /* | 1546 | /* |
1534 | * Note: we're not holding inode->i_mutex and so may be racing with | 1547 | * Note: we're not holding inode->i_mutex and so may be racing with |
1535 | * operations that change the directory. We therefore save the | 1548 | * operations that change the directory. We therefore save the |
1536 | * change attribute *before* we do the RPC call. | 1549 | * change attribute *before* we do the RPC call. |
1537 | */ | 1550 | */ |
1538 | inode = NFS_PROTO(dir)->open_context(dir, ctx, openflags, NULL); | 1551 | inode = NFS_PROTO(dir)->open_context(dir, ctx, openflags, &attr); |
1539 | if (IS_ERR(inode)) { | 1552 | if (IS_ERR(inode)) { |
1540 | ret = PTR_ERR(inode); | 1553 | ret = PTR_ERR(inode); |
1541 | switch (ret) { | 1554 | switch (ret) { |