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.c203
1 files changed, 128 insertions, 75 deletions
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 432f41cd75e6..a77ee95b7efb 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -40,6 +40,7 @@
40#include <asm/uaccess.h> 40#include <asm/uaccess.h>
41 41
42#include "nfs4_fs.h" 42#include "nfs4_fs.h"
43#include "callback.h"
43#include "delegation.h" 44#include "delegation.h"
44 45
45#define NFSDBG_FACILITY NFSDBG_VFS 46#define NFSDBG_FACILITY NFSDBG_VFS
@@ -221,10 +222,10 @@ nfs_calc_block_size(u64 tsize)
221static inline unsigned long 222static inline unsigned long
222nfs_block_size(unsigned long bsize, unsigned char *nrbitsp) 223nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
223{ 224{
224 if (bsize < 1024) 225 if (bsize < NFS_MIN_FILE_IO_SIZE)
225 bsize = NFS_DEF_FILE_IO_BUFFER_SIZE; 226 bsize = NFS_DEF_FILE_IO_SIZE;
226 else if (bsize >= NFS_MAX_FILE_IO_BUFFER_SIZE) 227 else if (bsize >= NFS_MAX_FILE_IO_SIZE)
227 bsize = NFS_MAX_FILE_IO_BUFFER_SIZE; 228 bsize = NFS_MAX_FILE_IO_SIZE;
228 229
229 return nfs_block_bits(bsize, nrbitsp); 230 return nfs_block_bits(bsize, nrbitsp);
230} 231}
@@ -307,20 +308,15 @@ nfs_sb_init(struct super_block *sb, rpc_authflavor_t authflavor)
307 max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL); 308 max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL);
308 if (server->rsize > max_rpc_payload) 309 if (server->rsize > max_rpc_payload)
309 server->rsize = max_rpc_payload; 310 server->rsize = max_rpc_payload;
310 if (server->wsize > max_rpc_payload) 311 if (server->rsize > NFS_MAX_FILE_IO_SIZE)
311 server->wsize = max_rpc_payload; 312 server->rsize = NFS_MAX_FILE_IO_SIZE;
312
313 server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; 313 server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
314 if (server->rpages > NFS_READ_MAXIOV) {
315 server->rpages = NFS_READ_MAXIOV;
316 server->rsize = server->rpages << PAGE_CACHE_SHIFT;
317 }
318 314
315 if (server->wsize > max_rpc_payload)
316 server->wsize = max_rpc_payload;
317 if (server->wsize > NFS_MAX_FILE_IO_SIZE)
318 server->wsize = NFS_MAX_FILE_IO_SIZE;
319 server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; 319 server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
320 if (server->wpages > NFS_WRITE_MAXIOV) {
321 server->wpages = NFS_WRITE_MAXIOV;
322 server->wsize = server->wpages << PAGE_CACHE_SHIFT;
323 }
324 320
325 if (sb->s_blocksize == 0) 321 if (sb->s_blocksize == 0)
326 sb->s_blocksize = nfs_block_bits(server->wsize, 322 sb->s_blocksize = nfs_block_bits(server->wsize,
@@ -417,7 +413,6 @@ nfs_create_client(struct nfs_server *server, const struct nfs_mount_data *data)
417 413
418 clnt->cl_intr = 1; 414 clnt->cl_intr = 1;
419 clnt->cl_softrtry = 1; 415 clnt->cl_softrtry = 1;
420 clnt->cl_chatty = 1;
421 416
422 return clnt; 417 return clnt;
423 418
@@ -575,11 +570,10 @@ nfs_statfs(struct super_block *sb, struct kstatfs *buf)
575 buf->f_namelen = server->namelen; 570 buf->f_namelen = server->namelen;
576 out: 571 out:
577 unlock_kernel(); 572 unlock_kernel();
578
579 return 0; 573 return 0;
580 574
581 out_err: 575 out_err:
582 printk(KERN_WARNING "nfs_statfs: statfs error = %d\n", -error); 576 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
583 buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; 577 buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1;
584 goto out; 578 goto out;
585 579
@@ -650,10 +644,7 @@ int nfs_sync_mapping(struct address_space *mapping)
650 if (mapping->nrpages == 0) 644 if (mapping->nrpages == 0)
651 return 0; 645 return 0;
652 unmap_mapping_range(mapping, 0, 0, 0); 646 unmap_mapping_range(mapping, 0, 0, 0);
653 ret = filemap_fdatawrite(mapping); 647 ret = filemap_write_and_wait(mapping);
654 if (ret != 0)
655 goto out;
656 ret = filemap_fdatawait(mapping);
657 if (ret != 0) 648 if (ret != 0)
658 goto out; 649 goto out;
659 ret = nfs_wb_all(mapping->host); 650 ret = nfs_wb_all(mapping->host);
@@ -870,8 +861,7 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
870 nfs_begin_data_update(inode); 861 nfs_begin_data_update(inode);
871 /* Write all dirty data if we're changing file permissions or size */ 862 /* Write all dirty data if we're changing file permissions or size */
872 if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE)) != 0) { 863 if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE)) != 0) {
873 if (filemap_fdatawrite(inode->i_mapping) == 0) 864 filemap_write_and_wait(inode->i_mapping);
874 filemap_fdatawait(inode->i_mapping);
875 nfs_wb_all(inode); 865 nfs_wb_all(inode);
876 } 866 }
877 /* 867 /*
@@ -958,11 +948,22 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
958 int need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME; 948 int need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME;
959 int err; 949 int err;
960 950
961 if (__IS_FLG(inode, MS_NOATIME)) 951 /* Flush out writes to the server in order to update c/mtime */
962 need_atime = 0; 952 nfs_sync_inode(inode, 0, 0, FLUSH_WAIT|FLUSH_NOCOMMIT);
963 else if (__IS_FLG(inode, MS_NODIRATIME) && S_ISDIR(inode->i_mode)) 953
954 /*
955 * We may force a getattr if the user cares about atime.
956 *
957 * Note that we only have to check the vfsmount flags here:
958 * - NFS always sets S_NOATIME by so checking it would give a
959 * bogus result
960 * - NFS never sets MS_NOATIME or MS_NODIRATIME so there is
961 * no point in checking those.
962 */
963 if ((mnt->mnt_flags & MNT_NOATIME) ||
964 ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode)))
964 need_atime = 0; 965 need_atime = 0;
965 /* We may force a getattr if the user cares about atime */ 966
966 if (need_atime) 967 if (need_atime)
967 err = __nfs_revalidate_inode(NFS_SERVER(inode), inode); 968 err = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
968 else 969 else
@@ -1252,6 +1253,33 @@ void nfs_end_data_update(struct inode *inode)
1252 atomic_dec(&nfsi->data_updates); 1253 atomic_dec(&nfsi->data_updates);
1253} 1254}
1254 1255
1256static void nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1257{
1258 struct nfs_inode *nfsi = NFS_I(inode);
1259
1260 if ((fattr->valid & NFS_ATTR_PRE_CHANGE) != 0
1261 && nfsi->change_attr == fattr->pre_change_attr) {
1262 nfsi->change_attr = fattr->change_attr;
1263 nfsi->cache_change_attribute = jiffies;
1264 }
1265
1266 /* If we have atomic WCC data, we may update some attributes */
1267 if ((fattr->valid & NFS_ATTR_WCC) != 0) {
1268 if (timespec_equal(&inode->i_ctime, &fattr->pre_ctime)) {
1269 memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
1270 nfsi->cache_change_attribute = jiffies;
1271 }
1272 if (timespec_equal(&inode->i_mtime, &fattr->pre_mtime)) {
1273 memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
1274 nfsi->cache_change_attribute = jiffies;
1275 }
1276 if (inode->i_size == fattr->pre_size && nfsi->npages == 0) {
1277 inode->i_size = fattr->size;
1278 nfsi->cache_change_attribute = jiffies;
1279 }
1280 }
1281}
1282
1255/** 1283/**
1256 * nfs_check_inode_attributes - verify consistency of the inode attribute cache 1284 * nfs_check_inode_attributes - verify consistency of the inode attribute cache
1257 * @inode - pointer to inode 1285 * @inode - pointer to inode
@@ -1268,22 +1296,20 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
1268 int data_unstable; 1296 int data_unstable;
1269 1297
1270 1298
1299 if ((fattr->valid & NFS_ATTR_FATTR) == 0)
1300 return 0;
1301
1271 /* Are we in the process of updating data on the server? */ 1302 /* Are we in the process of updating data on the server? */
1272 data_unstable = nfs_caches_unstable(inode); 1303 data_unstable = nfs_caches_unstable(inode);
1273 1304
1274 if (fattr->valid & NFS_ATTR_FATTR_V4) { 1305 /* Do atomic weak cache consistency updates */
1275 if ((fattr->valid & NFS_ATTR_PRE_CHANGE) != 0 1306 nfs_wcc_update_inode(inode, fattr);
1276 && nfsi->change_attr == fattr->pre_change_attr)
1277 nfsi->change_attr = fattr->change_attr;
1278 if (nfsi->change_attr != fattr->change_attr) {
1279 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
1280 if (!data_unstable)
1281 nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE;
1282 }
1283 }
1284 1307
1285 if ((fattr->valid & NFS_ATTR_FATTR) == 0) { 1308 if ((fattr->valid & NFS_ATTR_FATTR_V4) != 0 &&
1286 return 0; 1309 nfsi->change_attr != fattr->change_attr) {
1310 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
1311 if (!data_unstable)
1312 nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE;
1287 } 1313 }
1288 1314
1289 /* Has the inode gone and changed behind our back? */ 1315 /* Has the inode gone and changed behind our back? */
@@ -1295,14 +1321,6 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
1295 cur_size = i_size_read(inode); 1321 cur_size = i_size_read(inode);
1296 new_isize = nfs_size_to_loff_t(fattr->size); 1322 new_isize = nfs_size_to_loff_t(fattr->size);
1297 1323
1298 /* If we have atomic WCC data, we may update some attributes */
1299 if ((fattr->valid & NFS_ATTR_WCC) != 0) {
1300 if (timespec_equal(&inode->i_ctime, &fattr->pre_ctime))
1301 memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
1302 if (timespec_equal(&inode->i_mtime, &fattr->pre_mtime))
1303 memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
1304 }
1305
1306 /* Verify a few of the more important attributes */ 1324 /* Verify a few of the more important attributes */
1307 if (!timespec_equal(&inode->i_mtime, &fattr->mtime)) { 1325 if (!timespec_equal(&inode->i_mtime, &fattr->mtime)) {
1308 nfsi->cache_validity |= NFS_INO_INVALID_ATTR; 1326 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
@@ -1410,14 +1428,8 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1410 if ((fattr->valid & NFS_ATTR_FATTR) == 0) 1428 if ((fattr->valid & NFS_ATTR_FATTR) == 0)
1411 return 0; 1429 return 0;
1412 1430
1413 if (nfsi->fileid != fattr->fileid) { 1431 if (nfsi->fileid != fattr->fileid)
1414 printk(KERN_ERR "%s: inode number mismatch\n" 1432 goto out_fileid;
1415 "expected (%s/0x%Lx), got (%s/0x%Lx)\n",
1416 __FUNCTION__,
1417 inode->i_sb->s_id, (long long)nfsi->fileid,
1418 inode->i_sb->s_id, (long long)fattr->fileid);
1419 goto out_err;
1420 }
1421 1433
1422 /* 1434 /*
1423 * Make sure the inode's type hasn't changed. 1435 * Make sure the inode's type hasn't changed.
@@ -1436,6 +1448,9 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1436 if (data_stable) 1448 if (data_stable)
1437 nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ATIME); 1449 nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ATIME);
1438 1450
1451 /* Do atomic weak cache consistency updates */
1452 nfs_wcc_update_inode(inode, fattr);
1453
1439 /* Check if our cached file size is stale */ 1454 /* Check if our cached file size is stale */
1440 new_isize = nfs_size_to_loff_t(fattr->size); 1455 new_isize = nfs_size_to_loff_t(fattr->size);
1441 cur_isize = i_size_read(inode); 1456 cur_isize = i_size_read(inode);
@@ -1539,6 +1554,13 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1539 */ 1554 */
1540 nfs_invalidate_inode(inode); 1555 nfs_invalidate_inode(inode);
1541 return -ESTALE; 1556 return -ESTALE;
1557
1558 out_fileid:
1559 printk(KERN_ERR "NFS: server %s error: fileid changed\n"
1560 "fsid %s: expected fileid 0x%Lx, got 0x%Lx\n",
1561 NFS_SERVER(inode)->hostname, inode->i_sb->s_id,
1562 (long long)nfsi->fileid, (long long)fattr->fileid);
1563 goto out_err;
1542} 1564}
1543 1565
1544/* 1566/*
@@ -1820,25 +1842,10 @@ static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data,
1820 } 1842 }
1821 clnt->cl_intr = 1; 1843 clnt->cl_intr = 1;
1822 clnt->cl_softrtry = 1; 1844 clnt->cl_softrtry = 1;
1823 clnt->cl_chatty = 1;
1824 clp->cl_rpcclient = clnt; 1845 clp->cl_rpcclient = clnt;
1825 clp->cl_cred = rpcauth_lookupcred(clnt->cl_auth, 0);
1826 if (IS_ERR(clp->cl_cred)) {
1827 up_write(&clp->cl_sem);
1828 err = PTR_ERR(clp->cl_cred);
1829 clp->cl_cred = NULL;
1830 goto out_fail;
1831 }
1832 memcpy(clp->cl_ipaddr, server->ip_addr, sizeof(clp->cl_ipaddr)); 1846 memcpy(clp->cl_ipaddr, server->ip_addr, sizeof(clp->cl_ipaddr));
1833 nfs_idmap_new(clp); 1847 nfs_idmap_new(clp);
1834 } 1848 }
1835 if (list_empty(&clp->cl_superblocks)) {
1836 err = nfs4_init_client(clp);
1837 if (err != 0) {
1838 up_write(&clp->cl_sem);
1839 goto out_fail;
1840 }
1841 }
1842 list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks); 1849 list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks);
1843 clnt = rpc_clone_client(clp->cl_rpcclient); 1850 clnt = rpc_clone_client(clp->cl_rpcclient);
1844 if (!IS_ERR(clnt)) 1851 if (!IS_ERR(clnt))
@@ -2033,6 +2040,35 @@ static struct file_system_type nfs4_fs_type = {
2033 .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, 2040 .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
2034}; 2041};
2035 2042
2043static const int nfs_set_port_min = 0;
2044static const int nfs_set_port_max = 65535;
2045static int param_set_port(const char *val, struct kernel_param *kp)
2046{
2047 char *endp;
2048 int num = simple_strtol(val, &endp, 0);
2049 if (endp == val || *endp || num < nfs_set_port_min || num > nfs_set_port_max)
2050 return -EINVAL;
2051 *((int *)kp->arg) = num;
2052 return 0;
2053}
2054
2055module_param_call(callback_tcpport, param_set_port, param_get_int,
2056 &nfs_callback_set_tcpport, 0644);
2057
2058static int param_set_idmap_timeout(const char *val, struct kernel_param *kp)
2059{
2060 char *endp;
2061 int num = simple_strtol(val, &endp, 0);
2062 int jif = num * HZ;
2063 if (endp == val || *endp || num < 0 || jif < num)
2064 return -EINVAL;
2065 *((int *)kp->arg) = jif;
2066 return 0;
2067}
2068
2069module_param_call(idmap_cache_timeout, param_set_idmap_timeout, param_get_int,
2070 &nfs_idmap_cache_timeout, 0644);
2071
2036#define nfs4_init_once(nfsi) \ 2072#define nfs4_init_once(nfsi) \
2037 do { \ 2073 do { \
2038 INIT_LIST_HEAD(&(nfsi)->open_states); \ 2074 INIT_LIST_HEAD(&(nfsi)->open_states); \
@@ -2040,8 +2076,25 @@ static struct file_system_type nfs4_fs_type = {
2040 nfsi->delegation_state = 0; \ 2076 nfsi->delegation_state = 0; \
2041 init_rwsem(&nfsi->rwsem); \ 2077 init_rwsem(&nfsi->rwsem); \
2042 } while(0) 2078 } while(0)
2043#define register_nfs4fs() register_filesystem(&nfs4_fs_type) 2079
2044#define unregister_nfs4fs() unregister_filesystem(&nfs4_fs_type) 2080static inline int register_nfs4fs(void)
2081{
2082 int ret;
2083
2084 ret = nfs_register_sysctl();
2085 if (ret != 0)
2086 return ret;
2087 ret = register_filesystem(&nfs4_fs_type);
2088 if (ret != 0)
2089 nfs_unregister_sysctl();
2090 return ret;
2091}
2092
2093static inline void unregister_nfs4fs(void)
2094{
2095 unregister_filesystem(&nfs4_fs_type);
2096 nfs_unregister_sysctl();
2097}
2045#else 2098#else
2046#define nfs4_init_once(nfsi) \ 2099#define nfs4_init_once(nfsi) \
2047 do { } while (0) 2100 do { } while (0)
@@ -2166,11 +2219,11 @@ out:
2166#ifdef CONFIG_PROC_FS 2219#ifdef CONFIG_PROC_FS
2167 rpc_proc_unregister("nfs"); 2220 rpc_proc_unregister("nfs");
2168#endif 2221#endif
2169 nfs_destroy_writepagecache();
2170#ifdef CONFIG_NFS_DIRECTIO 2222#ifdef CONFIG_NFS_DIRECTIO
2171out0:
2172 nfs_destroy_directcache(); 2223 nfs_destroy_directcache();
2224out0:
2173#endif 2225#endif
2226 nfs_destroy_writepagecache();
2174out1: 2227out1:
2175 nfs_destroy_readpagecache(); 2228 nfs_destroy_readpagecache();
2176out2: 2229out2: