aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nfs/inode.c')
-rw-r--r--fs/nfs/inode.c110
1 files changed, 76 insertions, 34 deletions
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 7d2d6c72aa78..6f4850deb272 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -37,6 +37,7 @@
37#include <linux/inet.h> 37#include <linux/inet.h>
38#include <linux/nfs_xdr.h> 38#include <linux/nfs_xdr.h>
39#include <linux/slab.h> 39#include <linux/slab.h>
40#include <linux/compat.h>
40 41
41#include <asm/system.h> 42#include <asm/system.h>
42#include <asm/uaccess.h> 43#include <asm/uaccess.h>
@@ -48,6 +49,7 @@
48#include "internal.h" 49#include "internal.h"
49#include "fscache.h" 50#include "fscache.h"
50#include "dns_resolve.h" 51#include "dns_resolve.h"
52#include "pnfs.h"
51 53
52#define NFSDBG_FACILITY NFSDBG_VFS 54#define NFSDBG_FACILITY NFSDBG_VFS
53 55
@@ -88,7 +90,11 @@ int nfs_wait_bit_killable(void *word)
88 */ 90 */
89u64 nfs_compat_user_ino64(u64 fileid) 91u64 nfs_compat_user_ino64(u64 fileid)
90{ 92{
91 int ino; 93#ifdef CONFIG_COMPAT
94 compat_ulong_t ino;
95#else
96 unsigned long ino;
97#endif
92 98
93 if (enable_ino64) 99 if (enable_ino64)
94 return fileid; 100 return fileid;
@@ -234,9 +240,6 @@ nfs_init_locked(struct inode *inode, void *opaque)
234 return 0; 240 return 0;
235} 241}
236 242
237/* Don't use READDIRPLUS on directories that we believe are too large */
238#define NFS_LIMIT_READDIRPLUS (8*PAGE_SIZE)
239
240/* 243/*
241 * This is our front-end to iget that looks up inodes by file handle 244 * This is our front-end to iget that looks up inodes by file handle
242 * instead of inode number. 245 * instead of inode number.
@@ -251,7 +254,10 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
251 struct inode *inode = ERR_PTR(-ENOENT); 254 struct inode *inode = ERR_PTR(-ENOENT);
252 unsigned long hash; 255 unsigned long hash;
253 256
254 if ((fattr->valid & NFS_ATTR_FATTR_FILEID) == 0) 257 nfs_attr_check_mountpoint(sb, fattr);
258
259 if (((fattr->valid & NFS_ATTR_FATTR_FILEID) == 0) &&
260 !nfs_attr_use_mounted_on_fileid(fattr))
255 goto out_no_inode; 261 goto out_no_inode;
256 if ((fattr->valid & NFS_ATTR_FATTR_TYPE) == 0) 262 if ((fattr->valid & NFS_ATTR_FATTR_TYPE) == 0)
257 goto out_no_inode; 263 goto out_no_inode;
@@ -291,18 +297,18 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
291 } else if (S_ISDIR(inode->i_mode)) { 297 } else if (S_ISDIR(inode->i_mode)) {
292 inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->dir_inode_ops; 298 inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->dir_inode_ops;
293 inode->i_fop = &nfs_dir_operations; 299 inode->i_fop = &nfs_dir_operations;
294 if (nfs_server_capable(inode, NFS_CAP_READDIRPLUS) 300 inode->i_data.a_ops = &nfs_dir_aops;
295 && fattr->size <= NFS_LIMIT_READDIRPLUS) 301 if (nfs_server_capable(inode, NFS_CAP_READDIRPLUS))
296 set_bit(NFS_INO_ADVISE_RDPLUS, &NFS_I(inode)->flags); 302 set_bit(NFS_INO_ADVISE_RDPLUS, &NFS_I(inode)->flags);
297 /* Deal with crossing mountpoints */ 303 /* Deal with crossing mountpoints */
298 if ((fattr->valid & NFS_ATTR_FATTR_FSID) 304 if (fattr->valid & NFS_ATTR_FATTR_MOUNTPOINT ||
299 && !nfs_fsid_equal(&NFS_SB(sb)->fsid, &fattr->fsid)) { 305 fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) {
300 if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) 306 if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)
301 inode->i_op = &nfs_referral_inode_operations; 307 inode->i_op = &nfs_referral_inode_operations;
302 else 308 else
303 inode->i_op = &nfs_mountpoint_inode_operations; 309 inode->i_op = &nfs_mountpoint_inode_operations;
304 inode->i_fop = NULL; 310 inode->i_fop = NULL;
305 set_bit(NFS_INO_MOUNTPOINT, &nfsi->flags); 311 inode->i_flags |= S_AUTOMOUNT;
306 } 312 }
307 } else if (S_ISLNK(inode->i_mode)) 313 } else if (S_ISLNK(inode->i_mode))
308 inode->i_op = &nfs_symlink_inode_operations; 314 inode->i_op = &nfs_symlink_inode_operations;
@@ -623,7 +629,7 @@ void nfs_close_context(struct nfs_open_context *ctx, int is_sync)
623 nfs_revalidate_inode(server, inode); 629 nfs_revalidate_inode(server, inode);
624} 630}
625 631
626static struct nfs_open_context *alloc_nfs_open_context(struct path *path, struct rpc_cred *cred) 632struct nfs_open_context *alloc_nfs_open_context(struct path *path, struct rpc_cred *cred, fmode_t f_mode)
627{ 633{
628 struct nfs_open_context *ctx; 634 struct nfs_open_context *ctx;
629 635
@@ -633,11 +639,12 @@ static struct nfs_open_context *alloc_nfs_open_context(struct path *path, struct
633 path_get(&ctx->path); 639 path_get(&ctx->path);
634 ctx->cred = get_rpccred(cred); 640 ctx->cred = get_rpccred(cred);
635 ctx->state = NULL; 641 ctx->state = NULL;
642 ctx->mode = f_mode;
636 ctx->flags = 0; 643 ctx->flags = 0;
637 ctx->error = 0; 644 ctx->error = 0;
638 ctx->dir_cookie = 0;
639 nfs_init_lock_context(&ctx->lock_context); 645 nfs_init_lock_context(&ctx->lock_context);
640 ctx->lock_context.open_context = ctx; 646 ctx->lock_context.open_context = ctx;
647 INIT_LIST_HEAD(&ctx->list);
641 } 648 }
642 return ctx; 649 return ctx;
643} 650}
@@ -653,11 +660,15 @@ static void __put_nfs_open_context(struct nfs_open_context *ctx, int is_sync)
653{ 660{
654 struct inode *inode = ctx->path.dentry->d_inode; 661 struct inode *inode = ctx->path.dentry->d_inode;
655 662
656 if (!atomic_dec_and_lock(&ctx->lock_context.count, &inode->i_lock)) 663 if (!list_empty(&ctx->list)) {
664 if (!atomic_dec_and_lock(&ctx->lock_context.count, &inode->i_lock))
665 return;
666 list_del(&ctx->list);
667 spin_unlock(&inode->i_lock);
668 } else if (!atomic_dec_and_test(&ctx->lock_context.count))
657 return; 669 return;
658 list_del(&ctx->list); 670 if (inode != NULL)
659 spin_unlock(&inode->i_lock); 671 NFS_PROTO(inode)->close_context(ctx, is_sync);
660 NFS_PROTO(inode)->close_context(ctx, is_sync);
661 if (ctx->cred != NULL) 672 if (ctx->cred != NULL)
662 put_rpccred(ctx->cred); 673 put_rpccred(ctx->cred);
663 path_put(&ctx->path); 674 path_put(&ctx->path);
@@ -673,7 +684,7 @@ void put_nfs_open_context(struct nfs_open_context *ctx)
673 * Ensure that mmap has a recent RPC credential for use when writing out 684 * Ensure that mmap has a recent RPC credential for use when writing out
674 * shared pages 685 * shared pages
675 */ 686 */
676static void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx) 687void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx)
677{ 688{
678 struct inode *inode = filp->f_path.dentry->d_inode; 689 struct inode *inode = filp->f_path.dentry->d_inode;
679 struct nfs_inode *nfsi = NFS_I(inode); 690 struct nfs_inode *nfsi = NFS_I(inode);
@@ -730,11 +741,10 @@ int nfs_open(struct inode *inode, struct file *filp)
730 cred = rpc_lookup_cred(); 741 cred = rpc_lookup_cred();
731 if (IS_ERR(cred)) 742 if (IS_ERR(cred))
732 return PTR_ERR(cred); 743 return PTR_ERR(cred);
733 ctx = alloc_nfs_open_context(&filp->f_path, cred); 744 ctx = alloc_nfs_open_context(&filp->f_path, cred, filp->f_mode);
734 put_rpccred(cred); 745 put_rpccred(cred);
735 if (ctx == NULL) 746 if (ctx == NULL)
736 return -ENOMEM; 747 return -ENOMEM;
737 ctx->mode = filp->f_mode;
738 nfs_file_set_open_context(filp, ctx); 748 nfs_file_set_open_context(filp, ctx);
739 put_nfs_open_context(ctx); 749 put_nfs_open_context(ctx);
740 nfs_fscache_set_inode_cookie(inode, filp); 750 nfs_fscache_set_inode_cookie(inode, filp);
@@ -878,9 +888,10 @@ out:
878 return ret; 888 return ret;
879} 889}
880 890
881static void nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr) 891static unsigned long nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
882{ 892{
883 struct nfs_inode *nfsi = NFS_I(inode); 893 struct nfs_inode *nfsi = NFS_I(inode);
894 unsigned long ret = 0;
884 895
885 if ((fattr->valid & NFS_ATTR_FATTR_PRECHANGE) 896 if ((fattr->valid & NFS_ATTR_FATTR_PRECHANGE)
886 && (fattr->valid & NFS_ATTR_FATTR_CHANGE) 897 && (fattr->valid & NFS_ATTR_FATTR_CHANGE)
@@ -888,25 +899,32 @@ static void nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
888 nfsi->change_attr = fattr->change_attr; 899 nfsi->change_attr = fattr->change_attr;
889 if (S_ISDIR(inode->i_mode)) 900 if (S_ISDIR(inode->i_mode))
890 nfsi->cache_validity |= NFS_INO_INVALID_DATA; 901 nfsi->cache_validity |= NFS_INO_INVALID_DATA;
902 ret |= NFS_INO_INVALID_ATTR;
891 } 903 }
892 /* If we have atomic WCC data, we may update some attributes */ 904 /* If we have atomic WCC data, we may update some attributes */
893 if ((fattr->valid & NFS_ATTR_FATTR_PRECTIME) 905 if ((fattr->valid & NFS_ATTR_FATTR_PRECTIME)
894 && (fattr->valid & NFS_ATTR_FATTR_CTIME) 906 && (fattr->valid & NFS_ATTR_FATTR_CTIME)
895 && timespec_equal(&inode->i_ctime, &fattr->pre_ctime)) 907 && timespec_equal(&inode->i_ctime, &fattr->pre_ctime)) {
896 memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime)); 908 memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
909 ret |= NFS_INO_INVALID_ATTR;
910 }
897 911
898 if ((fattr->valid & NFS_ATTR_FATTR_PREMTIME) 912 if ((fattr->valid & NFS_ATTR_FATTR_PREMTIME)
899 && (fattr->valid & NFS_ATTR_FATTR_MTIME) 913 && (fattr->valid & NFS_ATTR_FATTR_MTIME)
900 && timespec_equal(&inode->i_mtime, &fattr->pre_mtime)) { 914 && timespec_equal(&inode->i_mtime, &fattr->pre_mtime)) {
901 memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime)); 915 memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
902 if (S_ISDIR(inode->i_mode)) 916 if (S_ISDIR(inode->i_mode))
903 nfsi->cache_validity |= NFS_INO_INVALID_DATA; 917 nfsi->cache_validity |= NFS_INO_INVALID_DATA;
918 ret |= NFS_INO_INVALID_ATTR;
904 } 919 }
905 if ((fattr->valid & NFS_ATTR_FATTR_PRESIZE) 920 if ((fattr->valid & NFS_ATTR_FATTR_PRESIZE)
906 && (fattr->valid & NFS_ATTR_FATTR_SIZE) 921 && (fattr->valid & NFS_ATTR_FATTR_SIZE)
907 && i_size_read(inode) == nfs_size_to_loff_t(fattr->pre_size) 922 && i_size_read(inode) == nfs_size_to_loff_t(fattr->pre_size)
908 && nfsi->npages == 0) 923 && nfsi->npages == 0) {
909 i_size_write(inode, nfs_size_to_loff_t(fattr->size)); 924 i_size_write(inode, nfs_size_to_loff_t(fattr->size));
925 ret |= NFS_INO_INVALID_ATTR;
926 }
927 return ret;
910} 928}
911 929
912/** 930/**
@@ -1205,7 +1223,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1205 /* Update the fsid? */ 1223 /* Update the fsid? */
1206 if (S_ISDIR(inode->i_mode) && (fattr->valid & NFS_ATTR_FATTR_FSID) && 1224 if (S_ISDIR(inode->i_mode) && (fattr->valid & NFS_ATTR_FATTR_FSID) &&
1207 !nfs_fsid_equal(&server->fsid, &fattr->fsid) && 1225 !nfs_fsid_equal(&server->fsid, &fattr->fsid) &&
1208 !test_bit(NFS_INO_MOUNTPOINT, &nfsi->flags)) 1226 !IS_AUTOMOUNT(inode))
1209 server->fsid = fattr->fsid; 1227 server->fsid = fattr->fsid;
1210 1228
1211 /* 1229 /*
@@ -1220,7 +1238,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1220 | NFS_INO_REVAL_PAGECACHE); 1238 | NFS_INO_REVAL_PAGECACHE);
1221 1239
1222 /* Do atomic weak cache consistency updates */ 1240 /* Do atomic weak cache consistency updates */
1223 nfs_wcc_update_inode(inode, fattr); 1241 invalid |= nfs_wcc_update_inode(inode, fattr);
1224 1242
1225 /* More cache consistency checks */ 1243 /* More cache consistency checks */
1226 if (fattr->valid & NFS_ATTR_FATTR_CHANGE) { 1244 if (fattr->valid & NFS_ATTR_FATTR_CHANGE) {
@@ -1277,12 +1295,17 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1277 if (new_isize != cur_isize) { 1295 if (new_isize != cur_isize) {
1278 /* Do we perhaps have any outstanding writes, or has 1296 /* Do we perhaps have any outstanding writes, or has
1279 * the file grown beyond our last write? */ 1297 * the file grown beyond our last write? */
1280 if (nfsi->npages == 0 || new_isize > cur_isize) { 1298 if ((nfsi->npages == 0 && !test_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) ||
1299 new_isize > cur_isize) {
1281 i_size_write(inode, new_isize); 1300 i_size_write(inode, new_isize);
1282 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; 1301 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
1283 } 1302 }
1284 dprintk("NFS: isize change on server for file %s/%ld\n", 1303 dprintk("NFS: isize change on server for file %s/%ld "
1285 inode->i_sb->s_id, inode->i_ino); 1304 "(%Ld to %Ld)\n",
1305 inode->i_sb->s_id,
1306 inode->i_ino,
1307 (long long)cur_isize,
1308 (long long)new_isize);
1286 } 1309 }
1287 } else 1310 } else
1288 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR 1311 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
@@ -1409,6 +1432,8 @@ void nfs4_evict_inode(struct inode *inode)
1409{ 1432{
1410 truncate_inode_pages(&inode->i_data, 0); 1433 truncate_inode_pages(&inode->i_data, 0);
1411 end_writeback(inode); 1434 end_writeback(inode);
1435 pnfs_return_layout(inode);
1436 pnfs_destroy_layout(NFS_I(inode));
1412 /* If we are holding a delegation, return it! */ 1437 /* If we are holding a delegation, return it! */
1413 nfs_inode_return_delegation_noreclaim(inode); 1438 nfs_inode_return_delegation_noreclaim(inode);
1414 /* First call standard NFS clear_inode() code */ 1439 /* First call standard NFS clear_inode() code */
@@ -1434,11 +1459,18 @@ struct inode *nfs_alloc_inode(struct super_block *sb)
1434 return &nfsi->vfs_inode; 1459 return &nfsi->vfs_inode;
1435} 1460}
1436 1461
1437void nfs_destroy_inode(struct inode *inode) 1462static void nfs_i_callback(struct rcu_head *head)
1438{ 1463{
1464 struct inode *inode = container_of(head, struct inode, i_rcu);
1465 INIT_LIST_HEAD(&inode->i_dentry);
1439 kmem_cache_free(nfs_inode_cachep, NFS_I(inode)); 1466 kmem_cache_free(nfs_inode_cachep, NFS_I(inode));
1440} 1467}
1441 1468
1469void nfs_destroy_inode(struct inode *inode)
1470{
1471 call_rcu(&inode->i_rcu, nfs_i_callback);
1472}
1473
1442static inline void nfs4_init_once(struct nfs_inode *nfsi) 1474static inline void nfs4_init_once(struct nfs_inode *nfsi)
1443{ 1475{
1444#ifdef CONFIG_NFS_V4 1476#ifdef CONFIG_NFS_V4
@@ -1446,6 +1478,8 @@ static inline void nfs4_init_once(struct nfs_inode *nfsi)
1446 nfsi->delegation = NULL; 1478 nfsi->delegation = NULL;
1447 nfsi->delegation_state = 0; 1479 nfsi->delegation_state = 0;
1448 init_rwsem(&nfsi->rwsem); 1480 init_rwsem(&nfsi->rwsem);
1481 nfsi->layout = NULL;
1482 atomic_set(&nfsi->commits_outstanding, 0);
1449#endif 1483#endif
1450} 1484}
1451 1485
@@ -1493,7 +1527,7 @@ static int nfsiod_start(void)
1493{ 1527{
1494 struct workqueue_struct *wq; 1528 struct workqueue_struct *wq;
1495 dprintk("RPC: creating workqueue nfsiod\n"); 1529 dprintk("RPC: creating workqueue nfsiod\n");
1496 wq = create_singlethread_workqueue("nfsiod"); 1530 wq = alloc_workqueue("nfsiod", WQ_MEM_RECLAIM, 0);
1497 if (wq == NULL) 1531 if (wq == NULL)
1498 return -ENOMEM; 1532 return -ENOMEM;
1499 nfsiod_workqueue = wq; 1533 nfsiod_workqueue = wq;
@@ -1521,6 +1555,10 @@ static int __init init_nfs_fs(void)
1521{ 1555{
1522 int err; 1556 int err;
1523 1557
1558 err = nfs_idmap_init();
1559 if (err < 0)
1560 goto out9;
1561
1524 err = nfs_dns_resolver_init(); 1562 err = nfs_dns_resolver_init();
1525 if (err < 0) 1563 if (err < 0)
1526 goto out8; 1564 goto out8;
@@ -1585,6 +1623,8 @@ out6:
1585out7: 1623out7:
1586 nfs_dns_resolver_destroy(); 1624 nfs_dns_resolver_destroy();
1587out8: 1625out8:
1626 nfs_idmap_quit();
1627out9:
1588 return err; 1628 return err;
1589} 1629}
1590 1630
@@ -1597,9 +1637,11 @@ static void __exit exit_nfs_fs(void)
1597 nfs_destroy_nfspagecache(); 1637 nfs_destroy_nfspagecache();
1598 nfs_fscache_unregister(); 1638 nfs_fscache_unregister();
1599 nfs_dns_resolver_destroy(); 1639 nfs_dns_resolver_destroy();
1640 nfs_idmap_quit();
1600#ifdef CONFIG_PROC_FS 1641#ifdef CONFIG_PROC_FS
1601 rpc_proc_unregister("nfs"); 1642 rpc_proc_unregister("nfs");
1602#endif 1643#endif
1644 nfs_cleanup_cb_ident_idr();
1603 unregister_nfs_fs(); 1645 unregister_nfs_fs();
1604 nfs_fs_proc_exit(); 1646 nfs_fs_proc_exit();
1605 nfsiod_stop(); 1647 nfsiod_stop();