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.c178
1 files changed, 113 insertions, 65 deletions
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 432f41cd75e6..e7bd0d92600f 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
@@ -958,6 +952,8 @@ 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; 952 int need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME;
959 int err; 953 int err;
960 954
955 /* Flush out writes to the server in order to update c/mtime */
956 nfs_sync_inode(inode, 0, 0, FLUSH_WAIT|FLUSH_NOCOMMIT);
961 if (__IS_FLG(inode, MS_NOATIME)) 957 if (__IS_FLG(inode, MS_NOATIME))
962 need_atime = 0; 958 need_atime = 0;
963 else if (__IS_FLG(inode, MS_NODIRATIME) && S_ISDIR(inode->i_mode)) 959 else if (__IS_FLG(inode, MS_NODIRATIME) && S_ISDIR(inode->i_mode))
@@ -1252,6 +1248,33 @@ void nfs_end_data_update(struct inode *inode)
1252 atomic_dec(&nfsi->data_updates); 1248 atomic_dec(&nfsi->data_updates);
1253} 1249}
1254 1250
1251static void nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1252{
1253 struct nfs_inode *nfsi = NFS_I(inode);
1254
1255 if ((fattr->valid & NFS_ATTR_PRE_CHANGE) != 0
1256 && nfsi->change_attr == fattr->pre_change_attr) {
1257 nfsi->change_attr = fattr->change_attr;
1258 nfsi->cache_change_attribute = jiffies;
1259 }
1260
1261 /* If we have atomic WCC data, we may update some attributes */
1262 if ((fattr->valid & NFS_ATTR_WCC) != 0) {
1263 if (timespec_equal(&inode->i_ctime, &fattr->pre_ctime)) {
1264 memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
1265 nfsi->cache_change_attribute = jiffies;
1266 }
1267 if (timespec_equal(&inode->i_mtime, &fattr->pre_mtime)) {
1268 memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
1269 nfsi->cache_change_attribute = jiffies;
1270 }
1271 if (inode->i_size == fattr->pre_size && nfsi->npages == 0) {
1272 inode->i_size = fattr->size;
1273 nfsi->cache_change_attribute = jiffies;
1274 }
1275 }
1276}
1277
1255/** 1278/**
1256 * nfs_check_inode_attributes - verify consistency of the inode attribute cache 1279 * nfs_check_inode_attributes - verify consistency of the inode attribute cache
1257 * @inode - pointer to inode 1280 * @inode - pointer to inode
@@ -1268,22 +1291,20 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
1268 int data_unstable; 1291 int data_unstable;
1269 1292
1270 1293
1294 if ((fattr->valid & NFS_ATTR_FATTR) == 0)
1295 return 0;
1296
1271 /* Are we in the process of updating data on the server? */ 1297 /* Are we in the process of updating data on the server? */
1272 data_unstable = nfs_caches_unstable(inode); 1298 data_unstable = nfs_caches_unstable(inode);
1273 1299
1274 if (fattr->valid & NFS_ATTR_FATTR_V4) { 1300 /* Do atomic weak cache consistency updates */
1275 if ((fattr->valid & NFS_ATTR_PRE_CHANGE) != 0 1301 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 1302
1285 if ((fattr->valid & NFS_ATTR_FATTR) == 0) { 1303 if ((fattr->valid & NFS_ATTR_FATTR_V4) != 0 &&
1286 return 0; 1304 nfsi->change_attr != fattr->change_attr) {
1305 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
1306 if (!data_unstable)
1307 nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE;
1287 } 1308 }
1288 1309
1289 /* Has the inode gone and changed behind our back? */ 1310 /* Has the inode gone and changed behind our back? */
@@ -1295,14 +1316,6 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
1295 cur_size = i_size_read(inode); 1316 cur_size = i_size_read(inode);
1296 new_isize = nfs_size_to_loff_t(fattr->size); 1317 new_isize = nfs_size_to_loff_t(fattr->size);
1297 1318
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 */ 1319 /* Verify a few of the more important attributes */
1307 if (!timespec_equal(&inode->i_mtime, &fattr->mtime)) { 1320 if (!timespec_equal(&inode->i_mtime, &fattr->mtime)) {
1308 nfsi->cache_validity |= NFS_INO_INVALID_ATTR; 1321 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
@@ -1410,14 +1423,8 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1410 if ((fattr->valid & NFS_ATTR_FATTR) == 0) 1423 if ((fattr->valid & NFS_ATTR_FATTR) == 0)
1411 return 0; 1424 return 0;
1412 1425
1413 if (nfsi->fileid != fattr->fileid) { 1426 if (nfsi->fileid != fattr->fileid)
1414 printk(KERN_ERR "%s: inode number mismatch\n" 1427 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 1428
1422 /* 1429 /*
1423 * Make sure the inode's type hasn't changed. 1430 * Make sure the inode's type hasn't changed.
@@ -1436,6 +1443,9 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1436 if (data_stable) 1443 if (data_stable)
1437 nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ATIME); 1444 nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ATIME);
1438 1445
1446 /* Do atomic weak cache consistency updates */
1447 nfs_wcc_update_inode(inode, fattr);
1448
1439 /* Check if our cached file size is stale */ 1449 /* Check if our cached file size is stale */
1440 new_isize = nfs_size_to_loff_t(fattr->size); 1450 new_isize = nfs_size_to_loff_t(fattr->size);
1441 cur_isize = i_size_read(inode); 1451 cur_isize = i_size_read(inode);
@@ -1539,6 +1549,13 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1539 */ 1549 */
1540 nfs_invalidate_inode(inode); 1550 nfs_invalidate_inode(inode);
1541 return -ESTALE; 1551 return -ESTALE;
1552
1553 out_fileid:
1554 printk(KERN_ERR "NFS: server %s error: fileid changed\n"
1555 "fsid %s: expected fileid 0x%Lx, got 0x%Lx\n",
1556 NFS_SERVER(inode)->hostname, inode->i_sb->s_id,
1557 (long long)nfsi->fileid, (long long)fattr->fileid);
1558 goto out_err;
1542} 1559}
1543 1560
1544/* 1561/*
@@ -1820,25 +1837,10 @@ static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data,
1820 } 1837 }
1821 clnt->cl_intr = 1; 1838 clnt->cl_intr = 1;
1822 clnt->cl_softrtry = 1; 1839 clnt->cl_softrtry = 1;
1823 clnt->cl_chatty = 1;
1824 clp->cl_rpcclient = clnt; 1840 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)); 1841 memcpy(clp->cl_ipaddr, server->ip_addr, sizeof(clp->cl_ipaddr));
1833 nfs_idmap_new(clp); 1842 nfs_idmap_new(clp);
1834 } 1843 }
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); 1844 list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks);
1843 clnt = rpc_clone_client(clp->cl_rpcclient); 1845 clnt = rpc_clone_client(clp->cl_rpcclient);
1844 if (!IS_ERR(clnt)) 1846 if (!IS_ERR(clnt))
@@ -2033,6 +2035,35 @@ static struct file_system_type nfs4_fs_type = {
2033 .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, 2035 .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
2034}; 2036};
2035 2037
2038static const int nfs_set_port_min = 0;
2039static const int nfs_set_port_max = 65535;
2040static int param_set_port(const char *val, struct kernel_param *kp)
2041{
2042 char *endp;
2043 int num = simple_strtol(val, &endp, 0);
2044 if (endp == val || *endp || num < nfs_set_port_min || num > nfs_set_port_max)
2045 return -EINVAL;
2046 *((int *)kp->arg) = num;
2047 return 0;
2048}
2049
2050module_param_call(callback_tcpport, param_set_port, param_get_int,
2051 &nfs_callback_set_tcpport, 0644);
2052
2053static int param_set_idmap_timeout(const char *val, struct kernel_param *kp)
2054{
2055 char *endp;
2056 int num = simple_strtol(val, &endp, 0);
2057 int jif = num * HZ;
2058 if (endp == val || *endp || num < 0 || jif < num)
2059 return -EINVAL;
2060 *((int *)kp->arg) = jif;
2061 return 0;
2062}
2063
2064module_param_call(idmap_cache_timeout, param_set_idmap_timeout, param_get_int,
2065 &nfs_idmap_cache_timeout, 0644);
2066
2036#define nfs4_init_once(nfsi) \ 2067#define nfs4_init_once(nfsi) \
2037 do { \ 2068 do { \
2038 INIT_LIST_HEAD(&(nfsi)->open_states); \ 2069 INIT_LIST_HEAD(&(nfsi)->open_states); \
@@ -2040,8 +2071,25 @@ static struct file_system_type nfs4_fs_type = {
2040 nfsi->delegation_state = 0; \ 2071 nfsi->delegation_state = 0; \
2041 init_rwsem(&nfsi->rwsem); \ 2072 init_rwsem(&nfsi->rwsem); \
2042 } while(0) 2073 } while(0)
2043#define register_nfs4fs() register_filesystem(&nfs4_fs_type) 2074
2044#define unregister_nfs4fs() unregister_filesystem(&nfs4_fs_type) 2075static inline int register_nfs4fs(void)
2076{
2077 int ret;
2078
2079 ret = nfs_register_sysctl();
2080 if (ret != 0)
2081 return ret;
2082 ret = register_filesystem(&nfs4_fs_type);
2083 if (ret != 0)
2084 nfs_unregister_sysctl();
2085 return ret;
2086}
2087
2088static inline void unregister_nfs4fs(void)
2089{
2090 unregister_filesystem(&nfs4_fs_type);
2091 nfs_unregister_sysctl();
2092}
2045#else 2093#else
2046#define nfs4_init_once(nfsi) \ 2094#define nfs4_init_once(nfsi) \
2047 do { } while (0) 2095 do { } while (0)
@@ -2166,11 +2214,11 @@ out:
2166#ifdef CONFIG_PROC_FS 2214#ifdef CONFIG_PROC_FS
2167 rpc_proc_unregister("nfs"); 2215 rpc_proc_unregister("nfs");
2168#endif 2216#endif
2169 nfs_destroy_writepagecache();
2170#ifdef CONFIG_NFS_DIRECTIO 2217#ifdef CONFIG_NFS_DIRECTIO
2171out0:
2172 nfs_destroy_directcache(); 2218 nfs_destroy_directcache();
2219out0:
2173#endif 2220#endif
2221 nfs_destroy_writepagecache();
2174out1: 2222out1:
2175 nfs_destroy_readpagecache(); 2223 nfs_destroy_readpagecache();
2176out2: 2224out2: