aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-07-16 17:49:49 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-16 17:49:49 -0400
commit8df1b049bc86495a40e421abc8b9cf1dda32f0d9 (patch)
treeed0d7f582b401852a9ea98f572076131950a15c4 /fs
parenta3cf859321486f69506326146ab3e2fd15c05c3f (diff)
parentcadc723cc19ce6b881d973d3c04e25ebb83058e6 (diff)
Merge git://git.linux-nfs.org/projects/trondmy/nfs-2.6
* git://git.linux-nfs.org/projects/trondmy/nfs-2.6: (82 commits) NFSv4: Remove BKL from the nfsv4 state recovery SUNRPC: Remove the BKL from the callback functions NFS: Remove BKL from the readdir code NFS: Remove BKL from the symlink code NFS: Remove BKL from the sillydelete operations NFS: Remove the BKL from the rename, rmdir and unlink operations NFS: Remove BKL from NFS lookup code NFS: Remove the BKL from nfs_link() NFS: Remove the BKL from the inode creation operations NFS: Remove BKL usage from open() NFS: Remove BKL usage from the write path NFS: Remove the BKL from the permission checking code NFS: Remove attribute update related BKL references NFS: Remove BKL requirement from attribute updates NFS: Protect inode->i_nlink updates using inode->i_lock nfs: set correct fl_len in nlmclnt_test() SUNRPC: Support registering IPv6 interfaces with local rpcbind daemon SUNRPC: Refactor rpcb_register to make rpcbindv4 support easier SUNRPC: None of rpcb_create's callers wants a privileged source port SUNRPC: Introduce a specific rpcb_create for contacting localhost ...
Diffstat (limited to 'fs')
-rw-r--r--fs/Kconfig136
-rw-r--r--fs/lockd/clntproc.c8
-rw-r--r--fs/lockd/svc4proc.c2
-rw-r--r--fs/lockd/svclock.c7
-rw-r--r--fs/lockd/svcproc.c2
-rw-r--r--fs/nfs/callback.c34
-rw-r--r--fs/nfs/client.c13
-rw-r--r--fs/nfs/dir.c88
-rw-r--r--fs/nfs/direct.c4
-rw-r--r--fs/nfs/file.c155
-rw-r--r--fs/nfs/inode.c79
-rw-r--r--fs/nfs/internal.h1
-rw-r--r--fs/nfs/iostat.h119
-rw-r--r--fs/nfs/nfs3acl.c9
-rw-r--r--fs/nfs/nfs3proc.c275
-rw-r--r--fs/nfs/nfs4proc.c265
-rw-r--r--fs/nfs/nfs4state.c2
-rw-r--r--fs/nfs/nfsroot.c10
-rw-r--r--fs/nfs/proc.c28
-rw-r--r--fs/nfs/super.c882
-rw-r--r--fs/nfs/write.c322
-rw-r--r--fs/nfsd/nfs4callback.c2
22 files changed, 1395 insertions, 1048 deletions
diff --git a/fs/Kconfig b/fs/Kconfig
index 313b2e06ded5..84ab76a206a0 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -1544,10 +1544,6 @@ config UFS_FS
1544 The recently released UFS2 variant (used in FreeBSD 5.x) is 1544 The recently released UFS2 variant (used in FreeBSD 5.x) is
1545 READ-ONLY supported. 1545 READ-ONLY supported.
1546 1546
1547 If you only intend to mount files from some other Unix over the
1548 network using NFS, you don't need the UFS file system support (but
1549 you need NFS file system support obviously).
1550
1551 Note that this option is generally not needed for floppies, since a 1547 Note that this option is generally not needed for floppies, since a
1552 good portable way to transport files and directories between unixes 1548 good portable way to transport files and directories between unixes
1553 (and even other operating systems) is given by the tar program ("man 1549 (and even other operating systems) is given by the tar program ("man
@@ -1587,6 +1583,7 @@ menuconfig NETWORK_FILESYSTEMS
1587 Say Y here to get to see options for network filesystems and 1583 Say Y here to get to see options for network filesystems and
1588 filesystem-related networking code, such as NFS daemon and 1584 filesystem-related networking code, such as NFS daemon and
1589 RPCSEC security modules. 1585 RPCSEC security modules.
1586
1590 This option alone does not add any kernel code. 1587 This option alone does not add any kernel code.
1591 1588
1592 If you say N, all options in this submenu will be skipped and 1589 If you say N, all options in this submenu will be skipped and
@@ -1595,76 +1592,92 @@ menuconfig NETWORK_FILESYSTEMS
1595if NETWORK_FILESYSTEMS 1592if NETWORK_FILESYSTEMS
1596 1593
1597config NFS_FS 1594config NFS_FS
1598 tristate "NFS file system support" 1595 tristate "NFS client support"
1599 depends on INET 1596 depends on INET
1600 select LOCKD 1597 select LOCKD
1601 select SUNRPC 1598 select SUNRPC
1602 select NFS_ACL_SUPPORT if NFS_V3_ACL 1599 select NFS_ACL_SUPPORT if NFS_V3_ACL
1603 help 1600 help
1604 If you are connected to some other (usually local) Unix computer 1601 Choose Y here if you want to access files residing on other
1605 (using SLIP, PLIP, PPP or Ethernet) and want to mount files residing 1602 computers using Sun's Network File System protocol. To compile
1606 on that computer (the NFS server) using the Network File Sharing 1603 this file system support as a module, choose M here: the module
1607 protocol, say Y. "Mounting files" means that the client can access 1604 will be called nfs.
1608 the files with usual UNIX commands as if they were sitting on the
1609 client's hard disk. For this to work, the server must run the
1610 programs nfsd and mountd (but does not need to have NFS file system
1611 support enabled in its kernel). NFS is explained in the Network
1612 Administrator's Guide, available from
1613 <http://www.tldp.org/docs.html#guide>, on its man page: "man
1614 nfs", and in the NFS-HOWTO.
1615
1616 A superior but less widely used alternative to NFS is provided by
1617 the Coda file system; see "Coda file system support" below.
1618 1605
1619 If you say Y here, you should have said Y to TCP/IP networking also. 1606 To mount file systems exported by NFS servers, you also need to
1620 This option would enlarge your kernel by about 27 KB. 1607 install the user space mount.nfs command which can be found in
1608 the Linux nfs-utils package, available from http://linux-nfs.org/.
1609 Information about using the mount command is available in the
1610 mount(8) man page. More detail about the Linux NFS client
1611 implementation is available via the nfs(5) man page.
1621 1612
1622 To compile this file system support as a module, choose M here: the 1613 Below you can choose which versions of the NFS protocol are
1623 module will be called nfs. 1614 available in the kernel to mount NFS servers. Support for NFS
1615 version 2 (RFC 1094) is always available when NFS_FS is selected.
1624 1616
1625 If you are configuring a diskless machine which will mount its root 1617 To configure a system which mounts its root file system via NFS
1626 file system over NFS at boot time, say Y here and to "Kernel 1618 at boot time, say Y here, select "Kernel level IP
1627 level IP autoconfiguration" above and to "Root file system on NFS" 1619 autoconfiguration" in the NETWORK menu, and select "Root file
1628 below. You cannot compile this driver as a module in this case. 1620 system on NFS" below. You cannot compile this file system as a
1629 There are two packages designed for booting diskless machines over 1621 module in this case.
1630 the net: netboot, available from
1631 <http://ftp1.sourceforge.net/netboot/>, and Etherboot,
1632 available from <http://ftp1.sourceforge.net/etherboot/>.
1633 1622
1634 If you don't know what all this is about, say N. 1623 If unsure, say N.
1635 1624
1636config NFS_V3 1625config NFS_V3
1637 bool "Provide NFSv3 client support" 1626 bool "NFS client support for NFS version 3"
1638 depends on NFS_FS 1627 depends on NFS_FS
1639 help 1628 help
1640 Say Y here if you want your NFS client to be able to speak version 1629 This option enables support for version 3 of the NFS protocol
1641 3 of the NFS protocol. 1630 (RFC 1813) in the kernel's NFS client.
1642 1631
1643 If unsure, say Y. 1632 If unsure, say Y.
1644 1633
1645config NFS_V3_ACL 1634config NFS_V3_ACL
1646 bool "Provide client support for the NFSv3 ACL protocol extension" 1635 bool "NFS client support for the NFSv3 ACL protocol extension"
1647 depends on NFS_V3 1636 depends on NFS_V3
1648 help 1637 help
1649 Implement the NFSv3 ACL protocol extension for manipulating POSIX 1638 Some NFS servers support an auxiliary NFSv3 ACL protocol that
1650 Access Control Lists. The server should also be compiled with 1639 Sun added to Solaris but never became an official part of the
1651 the NFSv3 ACL protocol extension; see the CONFIG_NFSD_V3_ACL option. 1640 NFS version 3 protocol. This protocol extension allows
1641 applications on NFS clients to manipulate POSIX Access Control
1642 Lists on files residing on NFS servers. NFS servers enforce
1643 ACLs on local files whether this protocol is available or not.
1644
1645 Choose Y here if your NFS server supports the Solaris NFSv3 ACL
1646 protocol extension and you want your NFS client to allow
1647 applications to access and modify ACLs on files on the server.
1648
1649 Most NFS servers don't support the Solaris NFSv3 ACL protocol
1650 extension. You can choose N here or specify the "noacl" mount
1651 option to prevent your NFS client from trying to use the NFSv3
1652 ACL protocol.
1652 1653
1653 If unsure, say N. 1654 If unsure, say N.
1654 1655
1655config NFS_V4 1656config NFS_V4
1656 bool "Provide NFSv4 client support (EXPERIMENTAL)" 1657 bool "NFS client support for NFS version 4 (EXPERIMENTAL)"
1657 depends on NFS_FS && EXPERIMENTAL 1658 depends on NFS_FS && EXPERIMENTAL
1658 select RPCSEC_GSS_KRB5 1659 select RPCSEC_GSS_KRB5
1659 help 1660 help
1660 Say Y here if you want your NFS client to be able to speak the newer 1661 This option enables support for version 4 of the NFS protocol
1661 version 4 of the NFS protocol. 1662 (RFC 3530) in the kernel's NFS client.
1662 1663
1663 Note: Requires auxiliary userspace daemons which may be found on 1664 To mount NFS servers using NFSv4, you also need to install user
1664 http://www.citi.umich.edu/projects/nfsv4/ 1665 space programs which can be found in the Linux nfs-utils package,
1666 available from http://linux-nfs.org/.
1665 1667
1666 If unsure, say N. 1668 If unsure, say N.
1667 1669
1670config ROOT_NFS
1671 bool "Root file system on NFS"
1672 depends on NFS_FS=y && IP_PNP
1673 help
1674 If you want your system to mount its root file system via NFS,
1675 choose Y here. This is common practice for managing systems
1676 without local permanent storage. For details, read
1677 <file:Documentation/filesystems/nfsroot.txt>.
1678
1679 Most people say N here.
1680
1668config NFSD 1681config NFSD
1669 tristate "NFS server support" 1682 tristate "NFS server support"
1670 depends on INET 1683 depends on INET
@@ -1746,20 +1759,6 @@ config NFSD_V4
1746 1759
1747 If unsure, say N. 1760 If unsure, say N.
1748 1761
1749config ROOT_NFS
1750 bool "Root file system on NFS"
1751 depends on NFS_FS=y && IP_PNP
1752 help
1753 If you want your Linux box to mount its whole root file system (the
1754 one containing the directory /) from some other computer over the
1755 net via NFS (presumably because your box doesn't have a hard disk),
1756 say Y. Read <file:Documentation/filesystems/nfsroot.txt> for
1757 details. It is likely that in this case, you also want to say Y to
1758 "Kernel level IP autoconfiguration" so that your box can discover
1759 its network address at boot time.
1760
1761 Most people say N here.
1762
1763config LOCKD 1762config LOCKD
1764 tristate 1763 tristate
1765 1764
@@ -1800,27 +1799,6 @@ config SUNRPC_XPRT_RDMA
1800 1799
1801 If unsure, say N. 1800 If unsure, say N.
1802 1801
1803config SUNRPC_BIND34
1804 bool "Support for rpcbind versions 3 & 4 (EXPERIMENTAL)"
1805 depends on SUNRPC && EXPERIMENTAL
1806 default n
1807 help
1808 RPC requests over IPv6 networks require support for larger
1809 addresses when performing an RPC bind. Sun added support for
1810 IPv6 addressing by creating two new versions of the rpcbind
1811 protocol (RFC 1833).
1812
1813 This option enables support in the kernel RPC client for
1814 querying rpcbind servers via versions 3 and 4 of the rpcbind
1815 protocol. The kernel automatically falls back to version 2
1816 if a remote rpcbind service does not support versions 3 or 4.
1817 By themselves, these new versions do not provide support for
1818 RPC over IPv6, but the new protocol versions are necessary to
1819 support it.
1820
1821 If unsure, say N to get traditional behavior (version 2 rpcbind
1822 requests only).
1823
1824config RPCSEC_GSS_KRB5 1802config RPCSEC_GSS_KRB5
1825 tristate "Secure RPC: Kerberos V mechanism (EXPERIMENTAL)" 1803 tristate "Secure RPC: Kerberos V mechanism (EXPERIMENTAL)"
1826 depends on SUNRPC && EXPERIMENTAL 1804 depends on SUNRPC && EXPERIMENTAL
diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
index 5df517b81f3f..1f6dc518505c 100644
--- a/fs/lockd/clntproc.c
+++ b/fs/lockd/clntproc.c
@@ -224,7 +224,9 @@ void nlm_release_call(struct nlm_rqst *call)
224 224
225static void nlmclnt_rpc_release(void *data) 225static void nlmclnt_rpc_release(void *data)
226{ 226{
227 lock_kernel();
227 nlm_release_call(data); 228 nlm_release_call(data);
229 unlock_kernel();
228} 230}
229 231
230static int nlm_wait_on_grace(wait_queue_head_t *queue) 232static int nlm_wait_on_grace(wait_queue_head_t *queue)
@@ -430,7 +432,7 @@ nlmclnt_test(struct nlm_rqst *req, struct file_lock *fl)
430 * Report the conflicting lock back to the application. 432 * Report the conflicting lock back to the application.
431 */ 433 */
432 fl->fl_start = req->a_res.lock.fl.fl_start; 434 fl->fl_start = req->a_res.lock.fl.fl_start;
433 fl->fl_end = req->a_res.lock.fl.fl_start; 435 fl->fl_end = req->a_res.lock.fl.fl_end;
434 fl->fl_type = req->a_res.lock.fl.fl_type; 436 fl->fl_type = req->a_res.lock.fl.fl_type;
435 fl->fl_pid = 0; 437 fl->fl_pid = 0;
436 break; 438 break;
@@ -710,7 +712,9 @@ static void nlmclnt_unlock_callback(struct rpc_task *task, void *data)
710die: 712die:
711 return; 713 return;
712 retry_rebind: 714 retry_rebind:
715 lock_kernel();
713 nlm_rebind_host(req->a_host); 716 nlm_rebind_host(req->a_host);
717 unlock_kernel();
714 retry_unlock: 718 retry_unlock:
715 rpc_restart_call(task); 719 rpc_restart_call(task);
716} 720}
@@ -788,7 +792,9 @@ retry_cancel:
788 /* Don't ever retry more than 3 times */ 792 /* Don't ever retry more than 3 times */
789 if (req->a_retries++ >= NLMCLNT_MAX_RETRIES) 793 if (req->a_retries++ >= NLMCLNT_MAX_RETRIES)
790 goto die; 794 goto die;
795 lock_kernel();
791 nlm_rebind_host(req->a_host); 796 nlm_rebind_host(req->a_host);
797 unlock_kernel();
792 rpc_restart_call(task); 798 rpc_restart_call(task);
793 rpc_delay(task, 30 * HZ); 799 rpc_delay(task, 30 * HZ);
794} 800}
diff --git a/fs/lockd/svc4proc.c b/fs/lockd/svc4proc.c
index 385437e3387d..2e27176ff42f 100644
--- a/fs/lockd/svc4proc.c
+++ b/fs/lockd/svc4proc.c
@@ -248,7 +248,9 @@ static void nlm4svc_callback_exit(struct rpc_task *task, void *data)
248 248
249static void nlm4svc_callback_release(void *data) 249static void nlm4svc_callback_release(void *data)
250{ 250{
251 lock_kernel();
251 nlm_release_call(data); 252 nlm_release_call(data);
253 unlock_kernel();
252} 254}
253 255
254static const struct rpc_call_ops nlm4svc_callback_ops = { 256static const struct rpc_call_ops nlm4svc_callback_ops = {
diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index 81aca859bfde..56a08ab9a4cb 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -795,6 +795,7 @@ static void nlmsvc_grant_callback(struct rpc_task *task, void *data)
795 795
796 dprintk("lockd: GRANT_MSG RPC callback\n"); 796 dprintk("lockd: GRANT_MSG RPC callback\n");
797 797
798 lock_kernel();
798 /* if the block is not on a list at this point then it has 799 /* if the block is not on a list at this point then it has
799 * been invalidated. Don't try to requeue it. 800 * been invalidated. Don't try to requeue it.
800 * 801 *
@@ -804,7 +805,7 @@ static void nlmsvc_grant_callback(struct rpc_task *task, void *data)
804 * for nlm_blocked? 805 * for nlm_blocked?
805 */ 806 */
806 if (list_empty(&block->b_list)) 807 if (list_empty(&block->b_list))
807 return; 808 goto out;
808 809
809 /* Technically, we should down the file semaphore here. Since we 810 /* Technically, we should down the file semaphore here. Since we
810 * move the block towards the head of the queue only, no harm 811 * move the block towards the head of the queue only, no harm
@@ -818,13 +819,17 @@ static void nlmsvc_grant_callback(struct rpc_task *task, void *data)
818 } 819 }
819 nlmsvc_insert_block(block, timeout); 820 nlmsvc_insert_block(block, timeout);
820 svc_wake_up(block->b_daemon); 821 svc_wake_up(block->b_daemon);
822out:
823 unlock_kernel();
821} 824}
822 825
823static void nlmsvc_grant_release(void *data) 826static void nlmsvc_grant_release(void *data)
824{ 827{
825 struct nlm_rqst *call = data; 828 struct nlm_rqst *call = data;
826 829
830 lock_kernel();
827 nlmsvc_release_block(call->a_block); 831 nlmsvc_release_block(call->a_block);
832 unlock_kernel();
828} 833}
829 834
830static const struct rpc_call_ops nlmsvc_grant_ops = { 835static const struct rpc_call_ops nlmsvc_grant_ops = {
diff --git a/fs/lockd/svcproc.c b/fs/lockd/svcproc.c
index 88379cc6e0b1..ce6952b50a75 100644
--- a/fs/lockd/svcproc.c
+++ b/fs/lockd/svcproc.c
@@ -278,7 +278,9 @@ static void nlmsvc_callback_exit(struct rpc_task *task, void *data)
278 278
279static void nlmsvc_callback_release(void *data) 279static void nlmsvc_callback_release(void *data)
280{ 280{
281 lock_kernel();
281 nlm_release_call(data); 282 nlm_release_call(data);
283 unlock_kernel();
282} 284}
283 285
284static const struct rpc_call_ops nlmsvc_callback_ops = { 286static const struct rpc_call_ops nlmsvc_callback_ops = {
diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
index c1e7c8300629..f447f4b4476c 100644
--- a/fs/nfs/callback.c
+++ b/fs/nfs/callback.c
@@ -27,7 +27,7 @@
27 27
28struct nfs_callback_data { 28struct nfs_callback_data {
29 unsigned int users; 29 unsigned int users;
30 struct svc_serv *serv; 30 struct svc_rqst *rqst;
31 struct task_struct *task; 31 struct task_struct *task;
32}; 32};
33 33
@@ -91,21 +91,17 @@ nfs_callback_svc(void *vrqstp)
91 svc_process(rqstp); 91 svc_process(rqstp);
92 } 92 }
93 unlock_kernel(); 93 unlock_kernel();
94 nfs_callback_info.task = NULL;
95 svc_exit_thread(rqstp);
96 return 0; 94 return 0;
97} 95}
98 96
99/* 97/*
100 * Bring up the server process if it is not already up. 98 * Bring up the callback thread if it is not already up.
101 */ 99 */
102int nfs_callback_up(void) 100int nfs_callback_up(void)
103{ 101{
104 struct svc_serv *serv = NULL; 102 struct svc_serv *serv = NULL;
105 struct svc_rqst *rqstp;
106 int ret = 0; 103 int ret = 0;
107 104
108 lock_kernel();
109 mutex_lock(&nfs_callback_mutex); 105 mutex_lock(&nfs_callback_mutex);
110 if (nfs_callback_info.users++ || nfs_callback_info.task != NULL) 106 if (nfs_callback_info.users++ || nfs_callback_info.task != NULL)
111 goto out; 107 goto out;
@@ -121,22 +117,23 @@ int nfs_callback_up(void)
121 nfs_callback_tcpport = ret; 117 nfs_callback_tcpport = ret;
122 dprintk("Callback port = 0x%x\n", nfs_callback_tcpport); 118 dprintk("Callback port = 0x%x\n", nfs_callback_tcpport);
123 119
124 rqstp = svc_prepare_thread(serv, &serv->sv_pools[0]); 120 nfs_callback_info.rqst = svc_prepare_thread(serv, &serv->sv_pools[0]);
125 if (IS_ERR(rqstp)) { 121 if (IS_ERR(nfs_callback_info.rqst)) {
126 ret = PTR_ERR(rqstp); 122 ret = PTR_ERR(nfs_callback_info.rqst);
123 nfs_callback_info.rqst = NULL;
127 goto out_err; 124 goto out_err;
128 } 125 }
129 126
130 svc_sock_update_bufs(serv); 127 svc_sock_update_bufs(serv);
131 nfs_callback_info.serv = serv;
132 128
133 nfs_callback_info.task = kthread_run(nfs_callback_svc, rqstp, 129 nfs_callback_info.task = kthread_run(nfs_callback_svc,
130 nfs_callback_info.rqst,
134 "nfsv4-svc"); 131 "nfsv4-svc");
135 if (IS_ERR(nfs_callback_info.task)) { 132 if (IS_ERR(nfs_callback_info.task)) {
136 ret = PTR_ERR(nfs_callback_info.task); 133 ret = PTR_ERR(nfs_callback_info.task);
137 nfs_callback_info.serv = NULL; 134 svc_exit_thread(nfs_callback_info.rqst);
135 nfs_callback_info.rqst = NULL;
138 nfs_callback_info.task = NULL; 136 nfs_callback_info.task = NULL;
139 svc_exit_thread(rqstp);
140 goto out_err; 137 goto out_err;
141 } 138 }
142out: 139out:
@@ -149,7 +146,6 @@ out:
149 if (serv) 146 if (serv)
150 svc_destroy(serv); 147 svc_destroy(serv);
151 mutex_unlock(&nfs_callback_mutex); 148 mutex_unlock(&nfs_callback_mutex);
152 unlock_kernel();
153 return ret; 149 return ret;
154out_err: 150out_err:
155 dprintk("Couldn't create callback socket or server thread; err = %d\n", 151 dprintk("Couldn't create callback socket or server thread; err = %d\n",
@@ -159,17 +155,19 @@ out_err:
159} 155}
160 156
161/* 157/*
162 * Kill the server process if it is not already down. 158 * Kill the callback thread if it's no longer being used.
163 */ 159 */
164void nfs_callback_down(void) 160void nfs_callback_down(void)
165{ 161{
166 lock_kernel();
167 mutex_lock(&nfs_callback_mutex); 162 mutex_lock(&nfs_callback_mutex);
168 nfs_callback_info.users--; 163 nfs_callback_info.users--;
169 if (nfs_callback_info.users == 0 && nfs_callback_info.task != NULL) 164 if (nfs_callback_info.users == 0 && nfs_callback_info.task != NULL) {
170 kthread_stop(nfs_callback_info.task); 165 kthread_stop(nfs_callback_info.task);
166 svc_exit_thread(nfs_callback_info.rqst);
167 nfs_callback_info.rqst = NULL;
168 nfs_callback_info.task = NULL;
169 }
171 mutex_unlock(&nfs_callback_mutex); 170 mutex_unlock(&nfs_callback_mutex);
172 unlock_kernel();
173} 171}
174 172
175static int nfs_callback_authenticate(struct svc_rqst *rqstp) 173static int nfs_callback_authenticate(struct svc_rqst *rqstp)
diff --git a/fs/nfs/client.c b/fs/nfs/client.c
index f2a092ca69b5..5ee23e7058b3 100644
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -431,14 +431,14 @@ static void nfs_init_timeout_values(struct rpc_timeout *to, int proto,
431{ 431{
432 to->to_initval = timeo * HZ / 10; 432 to->to_initval = timeo * HZ / 10;
433 to->to_retries = retrans; 433 to->to_retries = retrans;
434 if (!to->to_retries)
435 to->to_retries = 2;
436 434
437 switch (proto) { 435 switch (proto) {
438 case XPRT_TRANSPORT_TCP: 436 case XPRT_TRANSPORT_TCP:
439 case XPRT_TRANSPORT_RDMA: 437 case XPRT_TRANSPORT_RDMA:
438 if (to->to_retries == 0)
439 to->to_retries = NFS_DEF_TCP_RETRANS;
440 if (to->to_initval == 0) 440 if (to->to_initval == 0)
441 to->to_initval = 60 * HZ; 441 to->to_initval = NFS_DEF_TCP_TIMEO * HZ / 10;
442 if (to->to_initval > NFS_MAX_TCP_TIMEOUT) 442 if (to->to_initval > NFS_MAX_TCP_TIMEOUT)
443 to->to_initval = NFS_MAX_TCP_TIMEOUT; 443 to->to_initval = NFS_MAX_TCP_TIMEOUT;
444 to->to_increment = to->to_initval; 444 to->to_increment = to->to_initval;
@@ -450,14 +450,17 @@ static void nfs_init_timeout_values(struct rpc_timeout *to, int proto,
450 to->to_exponential = 0; 450 to->to_exponential = 0;
451 break; 451 break;
452 case XPRT_TRANSPORT_UDP: 452 case XPRT_TRANSPORT_UDP:
453 default: 453 if (to->to_retries == 0)
454 to->to_retries = NFS_DEF_UDP_RETRANS;
454 if (!to->to_initval) 455 if (!to->to_initval)
455 to->to_initval = 11 * HZ / 10; 456 to->to_initval = NFS_DEF_UDP_TIMEO * HZ / 10;
456 if (to->to_initval > NFS_MAX_UDP_TIMEOUT) 457 if (to->to_initval > NFS_MAX_UDP_TIMEOUT)
457 to->to_initval = NFS_MAX_UDP_TIMEOUT; 458 to->to_initval = NFS_MAX_UDP_TIMEOUT;
458 to->to_maxval = NFS_MAX_UDP_TIMEOUT; 459 to->to_maxval = NFS_MAX_UDP_TIMEOUT;
459 to->to_exponential = 1; 460 to->to_exponential = 1;
460 break; 461 break;
462 default:
463 BUG();
461 } 464 }
462} 465}
463 466
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 982a2064fe4c..28a238dab23a 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -133,13 +133,14 @@ nfs_opendir(struct inode *inode, struct file *filp)
133{ 133{
134 int res; 134 int res;
135 135
136 dfprintk(VFS, "NFS: opendir(%s/%ld)\n", 136 dfprintk(FILE, "NFS: open dir(%s/%s)\n",
137 inode->i_sb->s_id, inode->i_ino); 137 filp->f_path.dentry->d_parent->d_name.name,
138 filp->f_path.dentry->d_name.name);
139
140 nfs_inc_stats(inode, NFSIOS_VFSOPEN);
138 141
139 lock_kernel();
140 /* Call generic open code in order to cache credentials */ 142 /* Call generic open code in order to cache credentials */
141 res = nfs_open(inode, filp); 143 res = nfs_open(inode, filp);
142 unlock_kernel();
143 return res; 144 return res;
144} 145}
145 146
@@ -528,13 +529,11 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
528 struct nfs_fattr fattr; 529 struct nfs_fattr fattr;
529 long res; 530 long res;
530 531
531 dfprintk(VFS, "NFS: readdir(%s/%s) starting at cookie %Lu\n", 532 dfprintk(FILE, "NFS: readdir(%s/%s) starting at cookie %llu\n",
532 dentry->d_parent->d_name.name, dentry->d_name.name, 533 dentry->d_parent->d_name.name, dentry->d_name.name,
533 (long long)filp->f_pos); 534 (long long)filp->f_pos);
534 nfs_inc_stats(inode, NFSIOS_VFSGETDENTS); 535 nfs_inc_stats(inode, NFSIOS_VFSGETDENTS);
535 536
536 lock_kernel();
537
538 /* 537 /*
539 * filp->f_pos points to the dirent entry number. 538 * filp->f_pos points to the dirent entry number.
540 * *desc->dir_cookie has the cookie for the next entry. We have 539 * *desc->dir_cookie has the cookie for the next entry. We have
@@ -592,10 +591,9 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
592 } 591 }
593out: 592out:
594 nfs_unblock_sillyrename(dentry); 593 nfs_unblock_sillyrename(dentry);
595 unlock_kernel();
596 if (res > 0) 594 if (res > 0)
597 res = 0; 595 res = 0;
598 dfprintk(VFS, "NFS: readdir(%s/%s) returns %ld\n", 596 dfprintk(FILE, "NFS: readdir(%s/%s) returns %ld\n",
599 dentry->d_parent->d_name.name, dentry->d_name.name, 597 dentry->d_parent->d_name.name, dentry->d_name.name,
600 res); 598 res);
601 return res; 599 return res;
@@ -603,7 +601,15 @@ out:
603 601
604static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int origin) 602static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int origin)
605{ 603{
606 mutex_lock(&filp->f_path.dentry->d_inode->i_mutex); 604 struct dentry *dentry = filp->f_path.dentry;
605 struct inode *inode = dentry->d_inode;
606
607 dfprintk(FILE, "NFS: llseek dir(%s/%s, %lld, %d)\n",
608 dentry->d_parent->d_name.name,
609 dentry->d_name.name,
610 offset, origin);
611
612 mutex_lock(&inode->i_mutex);
607 switch (origin) { 613 switch (origin) {
608 case 1: 614 case 1:
609 offset += filp->f_pos; 615 offset += filp->f_pos;
@@ -619,7 +625,7 @@ static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int origin)
619 nfs_file_open_context(filp)->dir_cookie = 0; 625 nfs_file_open_context(filp)->dir_cookie = 0;
620 } 626 }
621out: 627out:
622 mutex_unlock(&filp->f_path.dentry->d_inode->i_mutex); 628 mutex_unlock(&inode->i_mutex);
623 return offset; 629 return offset;
624} 630}
625 631
@@ -629,10 +635,11 @@ out:
629 */ 635 */
630static int nfs_fsync_dir(struct file *filp, struct dentry *dentry, int datasync) 636static int nfs_fsync_dir(struct file *filp, struct dentry *dentry, int datasync)
631{ 637{
632 dfprintk(VFS, "NFS: fsync_dir(%s/%s) datasync %d\n", 638 dfprintk(FILE, "NFS: fsync dir(%s/%s) datasync %d\n",
633 dentry->d_parent->d_name.name, dentry->d_name.name, 639 dentry->d_parent->d_name.name, dentry->d_name.name,
634 datasync); 640 datasync);
635 641
642 nfs_inc_stats(dentry->d_inode, NFSIOS_VFSFSYNC);
636 return 0; 643 return 0;
637} 644}
638 645
@@ -767,7 +774,6 @@ static int nfs_lookup_revalidate(struct dentry * dentry, struct nameidata *nd)
767 struct nfs_fattr fattr; 774 struct nfs_fattr fattr;
768 775
769 parent = dget_parent(dentry); 776 parent = dget_parent(dentry);
770 lock_kernel();
771 dir = parent->d_inode; 777 dir = parent->d_inode;
772 nfs_inc_stats(dir, NFSIOS_DENTRYREVALIDATE); 778 nfs_inc_stats(dir, NFSIOS_DENTRYREVALIDATE);
773 inode = dentry->d_inode; 779 inode = dentry->d_inode;
@@ -805,7 +811,6 @@ static int nfs_lookup_revalidate(struct dentry * dentry, struct nameidata *nd)
805 811
806 nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 812 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
807 out_valid: 813 out_valid:
808 unlock_kernel();
809 dput(parent); 814 dput(parent);
810 dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is valid\n", 815 dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is valid\n",
811 __func__, dentry->d_parent->d_name.name, 816 __func__, dentry->d_parent->d_name.name,
@@ -824,7 +829,6 @@ out_zap_parent:
824 shrink_dcache_parent(dentry); 829 shrink_dcache_parent(dentry);
825 } 830 }
826 d_drop(dentry); 831 d_drop(dentry);
827 unlock_kernel();
828 dput(parent); 832 dput(parent);
829 dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is invalid\n", 833 dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is invalid\n",
830 __func__, dentry->d_parent->d_name.name, 834 __func__, dentry->d_parent->d_name.name,
@@ -858,6 +862,14 @@ static int nfs_dentry_delete(struct dentry *dentry)
858 862
859} 863}
860 864
865static void nfs_drop_nlink(struct inode *inode)
866{
867 spin_lock(&inode->i_lock);
868 if (inode->i_nlink > 0)
869 drop_nlink(inode);
870 spin_unlock(&inode->i_lock);
871}
872
861/* 873/*
862 * Called when the dentry loses inode. 874 * Called when the dentry loses inode.
863 * We use it to clean up silly-renamed files. 875 * We use it to clean up silly-renamed files.
@@ -869,10 +881,8 @@ static void nfs_dentry_iput(struct dentry *dentry, struct inode *inode)
869 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_DATA; 881 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_DATA;
870 882
871 if (dentry->d_flags & DCACHE_NFSFS_RENAMED) { 883 if (dentry->d_flags & DCACHE_NFSFS_RENAMED) {
872 lock_kernel();
873 drop_nlink(inode); 884 drop_nlink(inode);
874 nfs_complete_unlink(dentry, inode); 885 nfs_complete_unlink(dentry, inode);
875 unlock_kernel();
876 } 886 }
877 iput(inode); 887 iput(inode);
878} 888}
@@ -903,8 +913,6 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru
903 res = ERR_PTR(-ENOMEM); 913 res = ERR_PTR(-ENOMEM);
904 dentry->d_op = NFS_PROTO(dir)->dentry_ops; 914 dentry->d_op = NFS_PROTO(dir)->dentry_ops;
905 915
906 lock_kernel();
907
908 /* 916 /*
909 * If we're doing an exclusive create, optimize away the lookup 917 * If we're doing an exclusive create, optimize away the lookup
910 * but don't hash the dentry. 918 * but don't hash the dentry.
@@ -912,7 +920,7 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru
912 if (nfs_is_exclusive_create(dir, nd)) { 920 if (nfs_is_exclusive_create(dir, nd)) {
913 d_instantiate(dentry, NULL); 921 d_instantiate(dentry, NULL);
914 res = NULL; 922 res = NULL;
915 goto out_unlock; 923 goto out;
916 } 924 }
917 925
918 parent = dentry->d_parent; 926 parent = dentry->d_parent;
@@ -940,8 +948,6 @@ no_entry:
940 nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 948 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
941out_unblock_sillyrename: 949out_unblock_sillyrename:
942 nfs_unblock_sillyrename(parent); 950 nfs_unblock_sillyrename(parent);
943out_unlock:
944 unlock_kernel();
945out: 951out:
946 return res; 952 return res;
947} 953}
@@ -999,9 +1005,7 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
999 } 1005 }
1000 1006
1001 /* Open the file on the server */ 1007 /* Open the file on the server */
1002 lock_kernel();
1003 res = nfs4_atomic_open(dir, dentry, nd); 1008 res = nfs4_atomic_open(dir, dentry, nd);
1004 unlock_kernel();
1005 if (IS_ERR(res)) { 1009 if (IS_ERR(res)) {
1006 error = PTR_ERR(res); 1010 error = PTR_ERR(res);
1007 switch (error) { 1011 switch (error) {
@@ -1063,9 +1067,7 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd)
1063 * operations that change the directory. We therefore save the 1067 * operations that change the directory. We therefore save the
1064 * change attribute *before* we do the RPC call. 1068 * change attribute *before* we do the RPC call.
1065 */ 1069 */
1066 lock_kernel();
1067 ret = nfs4_open_revalidate(dir, dentry, openflags, nd); 1070 ret = nfs4_open_revalidate(dir, dentry, openflags, nd);
1068 unlock_kernel();
1069out: 1071out:
1070 dput(parent); 1072 dput(parent);
1071 if (!ret) 1073 if (!ret)
@@ -1218,14 +1220,11 @@ static int nfs_create(struct inode *dir, struct dentry *dentry, int mode,
1218 if ((nd->flags & LOOKUP_CREATE) != 0) 1220 if ((nd->flags & LOOKUP_CREATE) != 0)
1219 open_flags = nd->intent.open.flags; 1221 open_flags = nd->intent.open.flags;
1220 1222
1221 lock_kernel();
1222 error = NFS_PROTO(dir)->create(dir, dentry, &attr, open_flags, nd); 1223 error = NFS_PROTO(dir)->create(dir, dentry, &attr, open_flags, nd);
1223 if (error != 0) 1224 if (error != 0)
1224 goto out_err; 1225 goto out_err;
1225 unlock_kernel();
1226 return 0; 1226 return 0;
1227out_err: 1227out_err:
1228 unlock_kernel();
1229 d_drop(dentry); 1228 d_drop(dentry);
1230 return error; 1229 return error;
1231} 1230}
@@ -1248,14 +1247,11 @@ nfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
1248 attr.ia_mode = mode; 1247 attr.ia_mode = mode;
1249 attr.ia_valid = ATTR_MODE; 1248 attr.ia_valid = ATTR_MODE;
1250 1249
1251 lock_kernel();
1252 status = NFS_PROTO(dir)->mknod(dir, dentry, &attr, rdev); 1250 status = NFS_PROTO(dir)->mknod(dir, dentry, &attr, rdev);
1253 if (status != 0) 1251 if (status != 0)
1254 goto out_err; 1252 goto out_err;
1255 unlock_kernel();
1256 return 0; 1253 return 0;
1257out_err: 1254out_err:
1258 unlock_kernel();
1259 d_drop(dentry); 1255 d_drop(dentry);
1260 return status; 1256 return status;
1261} 1257}
@@ -1274,15 +1270,12 @@ static int nfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1274 attr.ia_valid = ATTR_MODE; 1270 attr.ia_valid = ATTR_MODE;
1275 attr.ia_mode = mode | S_IFDIR; 1271 attr.ia_mode = mode | S_IFDIR;
1276 1272
1277 lock_kernel();
1278 error = NFS_PROTO(dir)->mkdir(dir, dentry, &attr); 1273 error = NFS_PROTO(dir)->mkdir(dir, dentry, &attr);
1279 if (error != 0) 1274 if (error != 0)
1280 goto out_err; 1275 goto out_err;
1281 unlock_kernel();
1282 return 0; 1276 return 0;
1283out_err: 1277out_err:
1284 d_drop(dentry); 1278 d_drop(dentry);
1285 unlock_kernel();
1286 return error; 1279 return error;
1287} 1280}
1288 1281
@@ -1299,14 +1292,12 @@ static int nfs_rmdir(struct inode *dir, struct dentry *dentry)
1299 dfprintk(VFS, "NFS: rmdir(%s/%ld), %s\n", 1292 dfprintk(VFS, "NFS: rmdir(%s/%ld), %s\n",
1300 dir->i_sb->s_id, dir->i_ino, dentry->d_name.name); 1293 dir->i_sb->s_id, dir->i_ino, dentry->d_name.name);
1301 1294
1302 lock_kernel();
1303 error = NFS_PROTO(dir)->rmdir(dir, &dentry->d_name); 1295 error = NFS_PROTO(dir)->rmdir(dir, &dentry->d_name);
1304 /* Ensure the VFS deletes this inode */ 1296 /* Ensure the VFS deletes this inode */
1305 if (error == 0 && dentry->d_inode != NULL) 1297 if (error == 0 && dentry->d_inode != NULL)
1306 clear_nlink(dentry->d_inode); 1298 clear_nlink(dentry->d_inode);
1307 else if (error == -ENOENT) 1299 else if (error == -ENOENT)
1308 nfs_dentry_handle_enoent(dentry); 1300 nfs_dentry_handle_enoent(dentry);
1309 unlock_kernel();
1310 1301
1311 return error; 1302 return error;
1312} 1303}
@@ -1408,7 +1399,7 @@ static int nfs_safe_remove(struct dentry *dentry)
1408 error = NFS_PROTO(dir)->remove(dir, &dentry->d_name); 1399 error = NFS_PROTO(dir)->remove(dir, &dentry->d_name);
1409 /* The VFS may want to delete this inode */ 1400 /* The VFS may want to delete this inode */
1410 if (error == 0) 1401 if (error == 0)
1411 drop_nlink(inode); 1402 nfs_drop_nlink(inode);
1412 nfs_mark_for_revalidate(inode); 1403 nfs_mark_for_revalidate(inode);
1413 } else 1404 } else
1414 error = NFS_PROTO(dir)->remove(dir, &dentry->d_name); 1405 error = NFS_PROTO(dir)->remove(dir, &dentry->d_name);
@@ -1431,7 +1422,6 @@ static int nfs_unlink(struct inode *dir, struct dentry *dentry)
1431 dfprintk(VFS, "NFS: unlink(%s/%ld, %s)\n", dir->i_sb->s_id, 1422 dfprintk(VFS, "NFS: unlink(%s/%ld, %s)\n", dir->i_sb->s_id,
1432 dir->i_ino, dentry->d_name.name); 1423 dir->i_ino, dentry->d_name.name);
1433 1424
1434 lock_kernel();
1435 spin_lock(&dcache_lock); 1425 spin_lock(&dcache_lock);
1436 spin_lock(&dentry->d_lock); 1426 spin_lock(&dentry->d_lock);
1437 if (atomic_read(&dentry->d_count) > 1) { 1427 if (atomic_read(&dentry->d_count) > 1) {
@@ -1440,7 +1430,6 @@ static int nfs_unlink(struct inode *dir, struct dentry *dentry)
1440 /* Start asynchronous writeout of the inode */ 1430 /* Start asynchronous writeout of the inode */
1441 write_inode_now(dentry->d_inode, 0); 1431 write_inode_now(dentry->d_inode, 0);
1442 error = nfs_sillyrename(dir, dentry); 1432 error = nfs_sillyrename(dir, dentry);
1443 unlock_kernel();
1444 return error; 1433 return error;
1445 } 1434 }
1446 if (!d_unhashed(dentry)) { 1435 if (!d_unhashed(dentry)) {
@@ -1454,7 +1443,6 @@ static int nfs_unlink(struct inode *dir, struct dentry *dentry)
1454 nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 1443 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
1455 } else if (need_rehash) 1444 } else if (need_rehash)
1456 d_rehash(dentry); 1445 d_rehash(dentry);
1457 unlock_kernel();
1458 return error; 1446 return error;
1459} 1447}
1460 1448
@@ -1491,13 +1479,9 @@ static int nfs_symlink(struct inode *dir, struct dentry *dentry, const char *sym
1491 attr.ia_mode = S_IFLNK | S_IRWXUGO; 1479 attr.ia_mode = S_IFLNK | S_IRWXUGO;
1492 attr.ia_valid = ATTR_MODE; 1480 attr.ia_valid = ATTR_MODE;
1493 1481
1494 lock_kernel();
1495
1496 page = alloc_page(GFP_HIGHUSER); 1482 page = alloc_page(GFP_HIGHUSER);
1497 if (!page) { 1483 if (!page)
1498 unlock_kernel();
1499 return -ENOMEM; 1484 return -ENOMEM;
1500 }
1501 1485
1502 kaddr = kmap_atomic(page, KM_USER0); 1486 kaddr = kmap_atomic(page, KM_USER0);
1503 memcpy(kaddr, symname, pathlen); 1487 memcpy(kaddr, symname, pathlen);
@@ -1512,7 +1496,6 @@ static int nfs_symlink(struct inode *dir, struct dentry *dentry, const char *sym
1512 dentry->d_name.name, symname, error); 1496 dentry->d_name.name, symname, error);
1513 d_drop(dentry); 1497 d_drop(dentry);
1514 __free_page(page); 1498 __free_page(page);
1515 unlock_kernel();
1516 return error; 1499 return error;
1517 } 1500 }
1518 1501
@@ -1530,7 +1513,6 @@ static int nfs_symlink(struct inode *dir, struct dentry *dentry, const char *sym
1530 } else 1513 } else
1531 __free_page(page); 1514 __free_page(page);
1532 1515
1533 unlock_kernel();
1534 return 0; 1516 return 0;
1535} 1517}
1536 1518
@@ -1544,14 +1526,12 @@ nfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
1544 old_dentry->d_parent->d_name.name, old_dentry->d_name.name, 1526 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
1545 dentry->d_parent->d_name.name, dentry->d_name.name); 1527 dentry->d_parent->d_name.name, dentry->d_name.name);
1546 1528
1547 lock_kernel();
1548 d_drop(dentry); 1529 d_drop(dentry);
1549 error = NFS_PROTO(dir)->link(inode, dir, &dentry->d_name); 1530 error = NFS_PROTO(dir)->link(inode, dir, &dentry->d_name);
1550 if (error == 0) { 1531 if (error == 0) {
1551 atomic_inc(&inode->i_count); 1532 atomic_inc(&inode->i_count);
1552 d_add(dentry, inode); 1533 d_add(dentry, inode);
1553 } 1534 }
1554 unlock_kernel();
1555 return error; 1535 return error;
1556} 1536}
1557 1537
@@ -1591,7 +1571,6 @@ static int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1591 * To prevent any new references to the target during the rename, 1571 * To prevent any new references to the target during the rename,
1592 * we unhash the dentry and free the inode in advance. 1572 * we unhash the dentry and free the inode in advance.
1593 */ 1573 */
1594 lock_kernel();
1595 if (!d_unhashed(new_dentry)) { 1574 if (!d_unhashed(new_dentry)) {
1596 d_drop(new_dentry); 1575 d_drop(new_dentry);
1597 rehash = new_dentry; 1576 rehash = new_dentry;
@@ -1635,7 +1614,7 @@ static int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1635 /* dentry still busy? */ 1614 /* dentry still busy? */
1636 goto out; 1615 goto out;
1637 } else 1616 } else
1638 drop_nlink(new_inode); 1617 nfs_drop_nlink(new_inode);
1639 1618
1640go_ahead: 1619go_ahead:
1641 /* 1620 /*
@@ -1669,7 +1648,6 @@ out:
1669 /* new dentry created? */ 1648 /* new dentry created? */
1670 if (dentry) 1649 if (dentry)
1671 dput(dentry); 1650 dput(dentry);
1672 unlock_kernel();
1673 return error; 1651 return error;
1674} 1652}
1675 1653
@@ -1962,8 +1940,6 @@ int nfs_permission(struct inode *inode, int mask, struct nameidata *nd)
1962 } 1940 }
1963 1941
1964force_lookup: 1942force_lookup:
1965 lock_kernel();
1966
1967 if (!NFS_PROTO(inode)->access) 1943 if (!NFS_PROTO(inode)->access)
1968 goto out_notsup; 1944 goto out_notsup;
1969 1945
@@ -1973,7 +1949,6 @@ force_lookup:
1973 put_rpccred(cred); 1949 put_rpccred(cred);
1974 } else 1950 } else
1975 res = PTR_ERR(cred); 1951 res = PTR_ERR(cred);
1976 unlock_kernel();
1977out: 1952out:
1978 dfprintk(VFS, "NFS: permission(%s/%ld), mask=0x%x, res=%d\n", 1953 dfprintk(VFS, "NFS: permission(%s/%ld), mask=0x%x, res=%d\n",
1979 inode->i_sb->s_id, inode->i_ino, mask, res); 1954 inode->i_sb->s_id, inode->i_ino, mask, res);
@@ -1982,7 +1957,6 @@ out_notsup:
1982 res = nfs_revalidate_inode(NFS_SERVER(inode), inode); 1957 res = nfs_revalidate_inode(NFS_SERVER(inode), inode);
1983 if (res == 0) 1958 if (res == 0)
1984 res = generic_permission(inode, mask, NULL); 1959 res = generic_permission(inode, mask, NULL);
1985 unlock_kernel();
1986 goto out; 1960 goto out;
1987} 1961}
1988 1962
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index 4757a2b326a1..08f6b040d289 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -890,7 +890,7 @@ ssize_t nfs_file_direct_read(struct kiocb *iocb, const struct iovec *iov,
890 count = iov_length(iov, nr_segs); 890 count = iov_length(iov, nr_segs);
891 nfs_add_stats(mapping->host, NFSIOS_DIRECTREADBYTES, count); 891 nfs_add_stats(mapping->host, NFSIOS_DIRECTREADBYTES, count);
892 892
893 dprintk("nfs: direct read(%s/%s, %zd@%Ld)\n", 893 dfprintk(FILE, "NFS: direct read(%s/%s, %zd@%Ld)\n",
894 file->f_path.dentry->d_parent->d_name.name, 894 file->f_path.dentry->d_parent->d_name.name,
895 file->f_path.dentry->d_name.name, 895 file->f_path.dentry->d_name.name,
896 count, (long long) pos); 896 count, (long long) pos);
@@ -947,7 +947,7 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, const struct iovec *iov,
947 count = iov_length(iov, nr_segs); 947 count = iov_length(iov, nr_segs);
948 nfs_add_stats(mapping->host, NFSIOS_DIRECTWRITTENBYTES, count); 948 nfs_add_stats(mapping->host, NFSIOS_DIRECTWRITTENBYTES, count);
949 949
950 dfprintk(VFS, "nfs: direct write(%s/%s, %zd@%Ld)\n", 950 dfprintk(FILE, "NFS: direct write(%s/%s, %zd@%Ld)\n",
951 file->f_path.dentry->d_parent->d_name.name, 951 file->f_path.dentry->d_parent->d_name.name,
952 file->f_path.dentry->d_name.name, 952 file->f_path.dentry->d_name.name,
953 count, (long long) pos); 953 count, (long long) pos);
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 4e98a56a1777..78460657f5cb 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -50,7 +50,7 @@ static ssize_t nfs_file_read(struct kiocb *, const struct iovec *iov,
50static ssize_t nfs_file_write(struct kiocb *, const struct iovec *iov, 50static ssize_t nfs_file_write(struct kiocb *, const struct iovec *iov,
51 unsigned long nr_segs, loff_t pos); 51 unsigned long nr_segs, loff_t pos);
52static int nfs_file_flush(struct file *, fl_owner_t id); 52static int nfs_file_flush(struct file *, fl_owner_t id);
53static int nfs_fsync(struct file *, struct dentry *dentry, int datasync); 53static int nfs_file_fsync(struct file *, struct dentry *dentry, int datasync);
54static int nfs_check_flags(int flags); 54static int nfs_check_flags(int flags);
55static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl); 55static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl);
56static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl); 56static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl);
@@ -72,7 +72,7 @@ const struct file_operations nfs_file_operations = {
72 .open = nfs_file_open, 72 .open = nfs_file_open,
73 .flush = nfs_file_flush, 73 .flush = nfs_file_flush,
74 .release = nfs_file_release, 74 .release = nfs_file_release,
75 .fsync = nfs_fsync, 75 .fsync = nfs_file_fsync,
76 .lock = nfs_lock, 76 .lock = nfs_lock,
77 .flock = nfs_flock, 77 .flock = nfs_flock,
78 .splice_read = nfs_file_splice_read, 78 .splice_read = nfs_file_splice_read,
@@ -119,25 +119,33 @@ nfs_file_open(struct inode *inode, struct file *filp)
119{ 119{
120 int res; 120 int res;
121 121
122 dprintk("NFS: open file(%s/%s)\n",
123 filp->f_path.dentry->d_parent->d_name.name,
124 filp->f_path.dentry->d_name.name);
125
122 res = nfs_check_flags(filp->f_flags); 126 res = nfs_check_flags(filp->f_flags);
123 if (res) 127 if (res)
124 return res; 128 return res;
125 129
126 nfs_inc_stats(inode, NFSIOS_VFSOPEN); 130 nfs_inc_stats(inode, NFSIOS_VFSOPEN);
127 lock_kernel(); 131 res = nfs_open(inode, filp);
128 res = NFS_PROTO(inode)->file_open(inode, filp);
129 unlock_kernel();
130 return res; 132 return res;
131} 133}
132 134
133static int 135static int
134nfs_file_release(struct inode *inode, struct file *filp) 136nfs_file_release(struct inode *inode, struct file *filp)
135{ 137{
138 struct dentry *dentry = filp->f_path.dentry;
139
140 dprintk("NFS: release(%s/%s)\n",
141 dentry->d_parent->d_name.name,
142 dentry->d_name.name);
143
136 /* Ensure that dirty pages are flushed out with the right creds */ 144 /* Ensure that dirty pages are flushed out with the right creds */
137 if (filp->f_mode & FMODE_WRITE) 145 if (filp->f_mode & FMODE_WRITE)
138 nfs_wb_all(filp->f_path.dentry->d_inode); 146 nfs_wb_all(dentry->d_inode);
139 nfs_inc_stats(inode, NFSIOS_VFSRELEASE); 147 nfs_inc_stats(inode, NFSIOS_VFSRELEASE);
140 return NFS_PROTO(inode)->file_release(inode, filp); 148 return nfs_release(inode, filp);
141} 149}
142 150
143/** 151/**
@@ -171,6 +179,12 @@ force_reval:
171static loff_t nfs_file_llseek(struct file *filp, loff_t offset, int origin) 179static loff_t nfs_file_llseek(struct file *filp, loff_t offset, int origin)
172{ 180{
173 loff_t loff; 181 loff_t loff;
182
183 dprintk("NFS: llseek file(%s/%s, %lld, %d)\n",
184 filp->f_path.dentry->d_parent->d_name.name,
185 filp->f_path.dentry->d_name.name,
186 offset, origin);
187
174 /* origin == SEEK_END => we must revalidate the cached file length */ 188 /* origin == SEEK_END => we must revalidate the cached file length */
175 if (origin == SEEK_END) { 189 if (origin == SEEK_END) {
176 struct inode *inode = filp->f_mapping->host; 190 struct inode *inode = filp->f_mapping->host;
@@ -185,7 +199,7 @@ static loff_t nfs_file_llseek(struct file *filp, loff_t offset, int origin)
185} 199}
186 200
187/* 201/*
188 * Helper for nfs_file_flush() and nfs_fsync() 202 * Helper for nfs_file_flush() and nfs_file_fsync()
189 * 203 *
190 * Notice that it clears the NFS_CONTEXT_ERROR_WRITE before synching to 204 * Notice that it clears the NFS_CONTEXT_ERROR_WRITE before synching to
191 * disk, but it retrieves and clears ctx->error after synching, despite 205 * disk, but it retrieves and clears ctx->error after synching, despite
@@ -211,16 +225,18 @@ static int nfs_do_fsync(struct nfs_open_context *ctx, struct inode *inode)
211 225
212/* 226/*
213 * Flush all dirty pages, and check for write errors. 227 * Flush all dirty pages, and check for write errors.
214 *
215 */ 228 */
216static int 229static int
217nfs_file_flush(struct file *file, fl_owner_t id) 230nfs_file_flush(struct file *file, fl_owner_t id)
218{ 231{
219 struct nfs_open_context *ctx = nfs_file_open_context(file); 232 struct nfs_open_context *ctx = nfs_file_open_context(file);
220 struct inode *inode = file->f_path.dentry->d_inode; 233 struct dentry *dentry = file->f_path.dentry;
234 struct inode *inode = dentry->d_inode;
221 int status; 235 int status;
222 236
223 dfprintk(VFS, "nfs: flush(%s/%ld)\n", inode->i_sb->s_id, inode->i_ino); 237 dprintk("NFS: flush(%s/%s)\n",
238 dentry->d_parent->d_name.name,
239 dentry->d_name.name);
224 240
225 if ((file->f_mode & FMODE_WRITE) == 0) 241 if ((file->f_mode & FMODE_WRITE) == 0)
226 return 0; 242 return 0;
@@ -245,7 +261,7 @@ nfs_file_read(struct kiocb *iocb, const struct iovec *iov,
245 if (iocb->ki_filp->f_flags & O_DIRECT) 261 if (iocb->ki_filp->f_flags & O_DIRECT)
246 return nfs_file_direct_read(iocb, iov, nr_segs, pos); 262 return nfs_file_direct_read(iocb, iov, nr_segs, pos);
247 263
248 dfprintk(VFS, "nfs: read(%s/%s, %lu@%lu)\n", 264 dprintk("NFS: read(%s/%s, %lu@%lu)\n",
249 dentry->d_parent->d_name.name, dentry->d_name.name, 265 dentry->d_parent->d_name.name, dentry->d_name.name,
250 (unsigned long) count, (unsigned long) pos); 266 (unsigned long) count, (unsigned long) pos);
251 267
@@ -265,7 +281,7 @@ nfs_file_splice_read(struct file *filp, loff_t *ppos,
265 struct inode *inode = dentry->d_inode; 281 struct inode *inode = dentry->d_inode;
266 ssize_t res; 282 ssize_t res;
267 283
268 dfprintk(VFS, "nfs: splice_read(%s/%s, %lu@%Lu)\n", 284 dprintk("NFS: splice_read(%s/%s, %lu@%Lu)\n",
269 dentry->d_parent->d_name.name, dentry->d_name.name, 285 dentry->d_parent->d_name.name, dentry->d_name.name,
270 (unsigned long) count, (unsigned long long) *ppos); 286 (unsigned long) count, (unsigned long long) *ppos);
271 287
@@ -282,7 +298,7 @@ nfs_file_mmap(struct file * file, struct vm_area_struct * vma)
282 struct inode *inode = dentry->d_inode; 298 struct inode *inode = dentry->d_inode;
283 int status; 299 int status;
284 300
285 dfprintk(VFS, "nfs: mmap(%s/%s)\n", 301 dprintk("NFS: mmap(%s/%s)\n",
286 dentry->d_parent->d_name.name, dentry->d_name.name); 302 dentry->d_parent->d_name.name, dentry->d_name.name);
287 303
288 status = nfs_revalidate_mapping(inode, file->f_mapping); 304 status = nfs_revalidate_mapping(inode, file->f_mapping);
@@ -300,12 +316,14 @@ nfs_file_mmap(struct file * file, struct vm_area_struct * vma)
300 * whether any write errors occurred for this process. 316 * whether any write errors occurred for this process.
301 */ 317 */
302static int 318static int
303nfs_fsync(struct file *file, struct dentry *dentry, int datasync) 319nfs_file_fsync(struct file *file, struct dentry *dentry, int datasync)
304{ 320{
305 struct nfs_open_context *ctx = nfs_file_open_context(file); 321 struct nfs_open_context *ctx = nfs_file_open_context(file);
306 struct inode *inode = dentry->d_inode; 322 struct inode *inode = dentry->d_inode;
307 323
308 dfprintk(VFS, "nfs: fsync(%s/%ld)\n", inode->i_sb->s_id, inode->i_ino); 324 dprintk("NFS: fsync file(%s/%s) datasync %d\n",
325 dentry->d_parent->d_name.name, dentry->d_name.name,
326 datasync);
309 327
310 nfs_inc_stats(inode, NFSIOS_VFSFSYNC); 328 nfs_inc_stats(inode, NFSIOS_VFSFSYNC);
311 return nfs_do_fsync(ctx, inode); 329 return nfs_do_fsync(ctx, inode);
@@ -328,6 +346,11 @@ static int nfs_write_begin(struct file *file, struct address_space *mapping,
328 struct page *page; 346 struct page *page;
329 index = pos >> PAGE_CACHE_SHIFT; 347 index = pos >> PAGE_CACHE_SHIFT;
330 348
349 dfprintk(PAGECACHE, "NFS: write_begin(%s/%s(%ld), %u@%lld)\n",
350 file->f_path.dentry->d_parent->d_name.name,
351 file->f_path.dentry->d_name.name,
352 mapping->host->i_ino, len, (long long) pos);
353
331 page = __grab_cache_page(mapping, index); 354 page = __grab_cache_page(mapping, index);
332 if (!page) 355 if (!page)
333 return -ENOMEM; 356 return -ENOMEM;
@@ -348,9 +371,32 @@ static int nfs_write_end(struct file *file, struct address_space *mapping,
348 unsigned offset = pos & (PAGE_CACHE_SIZE - 1); 371 unsigned offset = pos & (PAGE_CACHE_SIZE - 1);
349 int status; 372 int status;
350 373
351 lock_kernel(); 374 dfprintk(PAGECACHE, "NFS: write_end(%s/%s(%ld), %u@%lld)\n",
375 file->f_path.dentry->d_parent->d_name.name,
376 file->f_path.dentry->d_name.name,
377 mapping->host->i_ino, len, (long long) pos);
378
379 /*
380 * Zero any uninitialised parts of the page, and then mark the page
381 * as up to date if it turns out that we're extending the file.
382 */
383 if (!PageUptodate(page)) {
384 unsigned pglen = nfs_page_length(page);
385 unsigned end = offset + len;
386
387 if (pglen == 0) {
388 zero_user_segments(page, 0, offset,
389 end, PAGE_CACHE_SIZE);
390 SetPageUptodate(page);
391 } else if (end >= pglen) {
392 zero_user_segment(page, end, PAGE_CACHE_SIZE);
393 if (offset == 0)
394 SetPageUptodate(page);
395 } else
396 zero_user_segment(page, pglen, PAGE_CACHE_SIZE);
397 }
398
352 status = nfs_updatepage(file, page, offset, copied); 399 status = nfs_updatepage(file, page, offset, copied);
353 unlock_kernel();
354 400
355 unlock_page(page); 401 unlock_page(page);
356 page_cache_release(page); 402 page_cache_release(page);
@@ -362,6 +408,8 @@ static int nfs_write_end(struct file *file, struct address_space *mapping,
362 408
363static void nfs_invalidate_page(struct page *page, unsigned long offset) 409static void nfs_invalidate_page(struct page *page, unsigned long offset)
364{ 410{
411 dfprintk(PAGECACHE, "NFS: invalidate_page(%p, %lu)\n", page, offset);
412
365 if (offset != 0) 413 if (offset != 0)
366 return; 414 return;
367 /* Cancel any unstarted writes on this page */ 415 /* Cancel any unstarted writes on this page */
@@ -370,13 +418,20 @@ static void nfs_invalidate_page(struct page *page, unsigned long offset)
370 418
371static int nfs_release_page(struct page *page, gfp_t gfp) 419static int nfs_release_page(struct page *page, gfp_t gfp)
372{ 420{
421 dfprintk(PAGECACHE, "NFS: release_page(%p)\n", page);
422
373 /* If PagePrivate() is set, then the page is not freeable */ 423 /* If PagePrivate() is set, then the page is not freeable */
374 return 0; 424 return 0;
375} 425}
376 426
377static int nfs_launder_page(struct page *page) 427static int nfs_launder_page(struct page *page)
378{ 428{
379 return nfs_wb_page(page->mapping->host, page); 429 struct inode *inode = page->mapping->host;
430
431 dfprintk(PAGECACHE, "NFS: launder_page(%ld, %llu)\n",
432 inode->i_ino, (long long)page_offset(page));
433
434 return nfs_wb_page(inode, page);
380} 435}
381 436
382const struct address_space_operations nfs_file_aops = { 437const struct address_space_operations nfs_file_aops = {
@@ -396,13 +451,19 @@ const struct address_space_operations nfs_file_aops = {
396static int nfs_vm_page_mkwrite(struct vm_area_struct *vma, struct page *page) 451static int nfs_vm_page_mkwrite(struct vm_area_struct *vma, struct page *page)
397{ 452{
398 struct file *filp = vma->vm_file; 453 struct file *filp = vma->vm_file;
454 struct dentry *dentry = filp->f_path.dentry;
399 unsigned pagelen; 455 unsigned pagelen;
400 int ret = -EINVAL; 456 int ret = -EINVAL;
401 struct address_space *mapping; 457 struct address_space *mapping;
402 458
459 dfprintk(PAGECACHE, "NFS: vm_page_mkwrite(%s/%s(%ld), offset %lld)\n",
460 dentry->d_parent->d_name.name, dentry->d_name.name,
461 filp->f_mapping->host->i_ino,
462 (long long)page_offset(page));
463
403 lock_page(page); 464 lock_page(page);
404 mapping = page->mapping; 465 mapping = page->mapping;
405 if (mapping != vma->vm_file->f_path.dentry->d_inode->i_mapping) 466 if (mapping != dentry->d_inode->i_mapping)
406 goto out_unlock; 467 goto out_unlock;
407 468
408 ret = 0; 469 ret = 0;
@@ -450,9 +511,9 @@ static ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov,
450 if (iocb->ki_filp->f_flags & O_DIRECT) 511 if (iocb->ki_filp->f_flags & O_DIRECT)
451 return nfs_file_direct_write(iocb, iov, nr_segs, pos); 512 return nfs_file_direct_write(iocb, iov, nr_segs, pos);
452 513
453 dfprintk(VFS, "nfs: write(%s/%s(%ld), %lu@%Ld)\n", 514 dprintk("NFS: write(%s/%s, %lu@%Ld)\n",
454 dentry->d_parent->d_name.name, dentry->d_name.name, 515 dentry->d_parent->d_name.name, dentry->d_name.name,
455 inode->i_ino, (unsigned long) count, (long long) pos); 516 (unsigned long) count, (long long) pos);
456 517
457 result = -EBUSY; 518 result = -EBUSY;
458 if (IS_SWAPFILE(inode)) 519 if (IS_SWAPFILE(inode))
@@ -586,7 +647,8 @@ static int do_setlk(struct file *filp, int cmd, struct file_lock *fl)
586 * This makes locking act as a cache coherency point. 647 * This makes locking act as a cache coherency point.
587 */ 648 */
588 nfs_sync_mapping(filp->f_mapping); 649 nfs_sync_mapping(filp->f_mapping);
589 nfs_zap_caches(inode); 650 if (!nfs_have_delegation(inode, FMODE_READ))
651 nfs_zap_caches(inode);
590out: 652out:
591 return status; 653 return status;
592} 654}
@@ -596,23 +658,35 @@ out:
596 */ 658 */
597static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl) 659static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl)
598{ 660{
599 struct inode * inode = filp->f_mapping->host; 661 struct inode *inode = filp->f_mapping->host;
662 int ret = -ENOLCK;
600 663
601 dprintk("NFS: nfs_lock(f=%s/%ld, t=%x, fl=%x, r=%Ld:%Ld)\n", 664 dprintk("NFS: lock(%s/%s, t=%x, fl=%x, r=%lld:%lld)\n",
602 inode->i_sb->s_id, inode->i_ino, 665 filp->f_path.dentry->d_parent->d_name.name,
666 filp->f_path.dentry->d_name.name,
603 fl->fl_type, fl->fl_flags, 667 fl->fl_type, fl->fl_flags,
604 (long long)fl->fl_start, (long long)fl->fl_end); 668 (long long)fl->fl_start, (long long)fl->fl_end);
669
605 nfs_inc_stats(inode, NFSIOS_VFSLOCK); 670 nfs_inc_stats(inode, NFSIOS_VFSLOCK);
606 671
607 /* No mandatory locks over NFS */ 672 /* No mandatory locks over NFS */
608 if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK) 673 if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
609 return -ENOLCK; 674 goto out_err;
675
676 if (NFS_PROTO(inode)->lock_check_bounds != NULL) {
677 ret = NFS_PROTO(inode)->lock_check_bounds(fl);
678 if (ret < 0)
679 goto out_err;
680 }
610 681
611 if (IS_GETLK(cmd)) 682 if (IS_GETLK(cmd))
612 return do_getlk(filp, cmd, fl); 683 ret = do_getlk(filp, cmd, fl);
613 if (fl->fl_type == F_UNLCK) 684 else if (fl->fl_type == F_UNLCK)
614 return do_unlk(filp, cmd, fl); 685 ret = do_unlk(filp, cmd, fl);
615 return do_setlk(filp, cmd, fl); 686 else
687 ret = do_setlk(filp, cmd, fl);
688out_err:
689 return ret;
616} 690}
617 691
618/* 692/*
@@ -620,9 +694,9 @@ static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl)
620 */ 694 */
621static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl) 695static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl)
622{ 696{
623 dprintk("NFS: nfs_flock(f=%s/%ld, t=%x, fl=%x)\n", 697 dprintk("NFS: flock(%s/%s, t=%x, fl=%x)\n",
624 filp->f_path.dentry->d_inode->i_sb->s_id, 698 filp->f_path.dentry->d_parent->d_name.name,
625 filp->f_path.dentry->d_inode->i_ino, 699 filp->f_path.dentry->d_name.name,
626 fl->fl_type, fl->fl_flags); 700 fl->fl_type, fl->fl_flags);
627 701
628 /* 702 /*
@@ -645,12 +719,15 @@ static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl)
645 return do_setlk(filp, cmd, fl); 719 return do_setlk(filp, cmd, fl);
646} 720}
647 721
722/*
723 * There is no protocol support for leases, so we have no way to implement
724 * them correctly in the face of opens by other clients.
725 */
648static int nfs_setlease(struct file *file, long arg, struct file_lock **fl) 726static int nfs_setlease(struct file *file, long arg, struct file_lock **fl)
649{ 727{
650 /* 728 dprintk("NFS: setlease(%s/%s, arg=%ld)\n",
651 * There is no protocol support for leases, so we have no way 729 file->f_path.dentry->d_parent->d_name.name,
652 * to implement them correctly in the face of opens by other 730 file->f_path.dentry->d_name.name, arg);
653 * clients. 731
654 */
655 return -EINVAL; 732 return -EINVAL;
656} 733}
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 596c5d8e86f4..df23f987da6b 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -57,8 +57,6 @@ static int enable_ino64 = NFS_64_BIT_INODE_NUMBERS_ENABLED;
57static void nfs_invalidate_inode(struct inode *); 57static void nfs_invalidate_inode(struct inode *);
58static int nfs_update_inode(struct inode *, struct nfs_fattr *); 58static int nfs_update_inode(struct inode *, struct nfs_fattr *);
59 59
60static void nfs_zap_acl_cache(struct inode *);
61
62static struct kmem_cache * nfs_inode_cachep; 60static struct kmem_cache * nfs_inode_cachep;
63 61
64static inline unsigned long 62static inline unsigned long
@@ -167,7 +165,7 @@ void nfs_zap_mapping(struct inode *inode, struct address_space *mapping)
167 } 165 }
168} 166}
169 167
170static void nfs_zap_acl_cache(struct inode *inode) 168void nfs_zap_acl_cache(struct inode *inode)
171{ 169{
172 void (*clear_acl_cache)(struct inode *); 170 void (*clear_acl_cache)(struct inode *);
173 171
@@ -347,7 +345,7 @@ out_no_inode:
347 goto out; 345 goto out;
348} 346}
349 347
350#define NFS_VALID_ATTRS (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE|ATTR_ATIME|ATTR_ATIME_SET|ATTR_MTIME|ATTR_MTIME_SET) 348#define NFS_VALID_ATTRS (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE|ATTR_ATIME|ATTR_ATIME_SET|ATTR_MTIME|ATTR_MTIME_SET|ATTR_FILE)
351 349
352int 350int
353nfs_setattr(struct dentry *dentry, struct iattr *attr) 351nfs_setattr(struct dentry *dentry, struct iattr *attr)
@@ -369,10 +367,9 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
369 367
370 /* Optimization: if the end result is no change, don't RPC */ 368 /* Optimization: if the end result is no change, don't RPC */
371 attr->ia_valid &= NFS_VALID_ATTRS; 369 attr->ia_valid &= NFS_VALID_ATTRS;
372 if (attr->ia_valid == 0) 370 if ((attr->ia_valid & ~ATTR_FILE) == 0)
373 return 0; 371 return 0;
374 372
375 lock_kernel();
376 /* Write all dirty data */ 373 /* Write all dirty data */
377 if (S_ISREG(inode->i_mode)) { 374 if (S_ISREG(inode->i_mode)) {
378 filemap_write_and_wait(inode->i_mapping); 375 filemap_write_and_wait(inode->i_mapping);
@@ -386,11 +383,66 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
386 error = NFS_PROTO(inode)->setattr(dentry, &fattr, attr); 383 error = NFS_PROTO(inode)->setattr(dentry, &fattr, attr);
387 if (error == 0) 384 if (error == 0)
388 nfs_refresh_inode(inode, &fattr); 385 nfs_refresh_inode(inode, &fattr);
389 unlock_kernel();
390 return error; 386 return error;
391} 387}
392 388
393/** 389/**
390 * nfs_vmtruncate - unmap mappings "freed" by truncate() syscall
391 * @inode: inode of the file used
392 * @offset: file offset to start truncating
393 *
394 * This is a copy of the common vmtruncate, but with the locking
395 * corrected to take into account the fact that NFS requires
396 * inode->i_size to be updated under the inode->i_lock.
397 */
398static int nfs_vmtruncate(struct inode * inode, loff_t offset)
399{
400 if (i_size_read(inode) < offset) {
401 unsigned long limit;
402
403 limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
404 if (limit != RLIM_INFINITY && offset > limit)
405 goto out_sig;
406 if (offset > inode->i_sb->s_maxbytes)
407 goto out_big;
408 spin_lock(&inode->i_lock);
409 i_size_write(inode, offset);
410 spin_unlock(&inode->i_lock);
411 } else {
412 struct address_space *mapping = inode->i_mapping;
413
414 /*
415 * truncation of in-use swapfiles is disallowed - it would
416 * cause subsequent swapout to scribble on the now-freed
417 * blocks.
418 */
419 if (IS_SWAPFILE(inode))
420 return -ETXTBSY;
421 spin_lock(&inode->i_lock);
422 i_size_write(inode, offset);
423 spin_unlock(&inode->i_lock);
424
425 /*
426 * unmap_mapping_range is called twice, first simply for
427 * efficiency so that truncate_inode_pages does fewer
428 * single-page unmaps. However after this first call, and
429 * before truncate_inode_pages finishes, it is possible for
430 * private pages to be COWed, which remain after
431 * truncate_inode_pages finishes, hence the second
432 * unmap_mapping_range call must be made for correctness.
433 */
434 unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
435 truncate_inode_pages(mapping, offset);
436 unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
437 }
438 return 0;
439out_sig:
440 send_sig(SIGXFSZ, current, 0);
441out_big:
442 return -EFBIG;
443}
444
445/**
394 * nfs_setattr_update_inode - Update inode metadata after a setattr call. 446 * nfs_setattr_update_inode - Update inode metadata after a setattr call.
395 * @inode: pointer to struct inode 447 * @inode: pointer to struct inode
396 * @attr: pointer to struct iattr 448 * @attr: pointer to struct iattr
@@ -416,8 +468,7 @@ void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr)
416 } 468 }
417 if ((attr->ia_valid & ATTR_SIZE) != 0) { 469 if ((attr->ia_valid & ATTR_SIZE) != 0) {
418 nfs_inc_stats(inode, NFSIOS_SETATTRTRUNC); 470 nfs_inc_stats(inode, NFSIOS_SETATTRTRUNC);
419 inode->i_size = attr->ia_size; 471 nfs_vmtruncate(inode, attr->ia_size);
420 vmtruncate(inode, attr->ia_size);
421 } 472 }
422} 473}
423 474
@@ -647,7 +698,6 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
647 inode->i_sb->s_id, (long long)NFS_FILEID(inode)); 698 inode->i_sb->s_id, (long long)NFS_FILEID(inode));
648 699
649 nfs_inc_stats(inode, NFSIOS_INODEREVALIDATE); 700 nfs_inc_stats(inode, NFSIOS_INODEREVALIDATE);
650 lock_kernel();
651 if (is_bad_inode(inode)) 701 if (is_bad_inode(inode))
652 goto out_nowait; 702 goto out_nowait;
653 if (NFS_STALE(inode)) 703 if (NFS_STALE(inode))
@@ -696,7 +746,6 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
696 nfs_wake_up_inode(inode); 746 nfs_wake_up_inode(inode);
697 747
698 out_nowait: 748 out_nowait:
699 unlock_kernel();
700 return status; 749 return status;
701} 750}
702 751
@@ -831,9 +880,9 @@ static void nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
831 if (S_ISDIR(inode->i_mode)) 880 if (S_ISDIR(inode->i_mode))
832 nfsi->cache_validity |= NFS_INO_INVALID_DATA; 881 nfsi->cache_validity |= NFS_INO_INVALID_DATA;
833 } 882 }
834 if (inode->i_size == nfs_size_to_loff_t(fattr->pre_size) && 883 if (i_size_read(inode) == nfs_size_to_loff_t(fattr->pre_size) &&
835 nfsi->npages == 0) 884 nfsi->npages == 0)
836 inode->i_size = nfs_size_to_loff_t(fattr->size); 885 i_size_write(inode, nfs_size_to_loff_t(fattr->size));
837 } 886 }
838} 887}
839 888
@@ -974,7 +1023,7 @@ int nfs_post_op_update_inode_force_wcc(struct inode *inode, struct nfs_fattr *fa
974 (fattr->valid & NFS_ATTR_WCC) == 0) { 1023 (fattr->valid & NFS_ATTR_WCC) == 0) {
975 memcpy(&fattr->pre_ctime, &inode->i_ctime, sizeof(fattr->pre_ctime)); 1024 memcpy(&fattr->pre_ctime, &inode->i_ctime, sizeof(fattr->pre_ctime));
976 memcpy(&fattr->pre_mtime, &inode->i_mtime, sizeof(fattr->pre_mtime)); 1025 memcpy(&fattr->pre_mtime, &inode->i_mtime, sizeof(fattr->pre_mtime));
977 fattr->pre_size = inode->i_size; 1026 fattr->pre_size = i_size_read(inode);
978 fattr->valid |= NFS_ATTR_WCC; 1027 fattr->valid |= NFS_ATTR_WCC;
979 } 1028 }
980 return nfs_post_op_update_inode(inode, fattr); 1029 return nfs_post_op_update_inode(inode, fattr);
@@ -1059,7 +1108,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1059 /* Do we perhaps have any outstanding writes, or has 1108 /* Do we perhaps have any outstanding writes, or has
1060 * the file grown beyond our last write? */ 1109 * the file grown beyond our last write? */
1061 if (nfsi->npages == 0 || new_isize > cur_isize) { 1110 if (nfsi->npages == 0 || new_isize > cur_isize) {
1062 inode->i_size = new_isize; 1111 i_size_write(inode, new_isize);
1063 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; 1112 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
1064 } 1113 }
1065 dprintk("NFS: isize change on server for file %s/%ld\n", 1114 dprintk("NFS: isize change on server for file %s/%ld\n",
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index 04ae867dddba..24241fcbb98d 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -150,6 +150,7 @@ extern void nfs_clear_inode(struct inode *);
150#ifdef CONFIG_NFS_V4 150#ifdef CONFIG_NFS_V4
151extern void nfs4_clear_inode(struct inode *); 151extern void nfs4_clear_inode(struct inode *);
152#endif 152#endif
153void nfs_zap_acl_cache(struct inode *inode);
153 154
154/* super.c */ 155/* super.c */
155extern struct file_system_type nfs_xdev_fs_type; 156extern struct file_system_type nfs_xdev_fs_type;
diff --git a/fs/nfs/iostat.h b/fs/nfs/iostat.h
index 6350ecbde589..a36952810032 100644
--- a/fs/nfs/iostat.h
+++ b/fs/nfs/iostat.h
@@ -5,135 +5,41 @@
5 * 5 *
6 * Copyright (C) 2005, 2006 Chuck Lever <cel@netapp.com> 6 * Copyright (C) 2005, 2006 Chuck Lever <cel@netapp.com>
7 * 7 *
8 * NFS client per-mount statistics provide information about the health of
9 * the NFS client and the health of each NFS mount point. Generally these
10 * are not for detailed problem diagnosis, but simply to indicate that there
11 * is a problem.
12 *
13 * These counters are not meant to be human-readable, but are meant to be
14 * integrated into system monitoring tools such as "sar" and "iostat". As
15 * such, the counters are sampled by the tools over time, and are never
16 * zeroed after a file system is mounted. Moving averages can be computed
17 * by the tools by taking the difference between two instantaneous samples
18 * and dividing that by the time between the samples.
19 */ 8 */
20 9
21#ifndef _NFS_IOSTAT 10#ifndef _NFS_IOSTAT
22#define _NFS_IOSTAT 11#define _NFS_IOSTAT
23 12
24#define NFS_IOSTAT_VERS "1.0"
25
26/*
27 * NFS byte counters
28 *
29 * 1. SERVER - the number of payload bytes read from or written to the
30 * server by the NFS client via an NFS READ or WRITE request.
31 *
32 * 2. NORMAL - the number of bytes read or written by applications via
33 * the read(2) and write(2) system call interfaces.
34 *
35 * 3. DIRECT - the number of bytes read or written from files opened
36 * with the O_DIRECT flag.
37 *
38 * These counters give a view of the data throughput into and out of the NFS
39 * client. Comparing the number of bytes requested by an application with the
40 * number of bytes the client requests from the server can provide an
41 * indication of client efficiency (per-op, cache hits, etc).
42 *
43 * These counters can also help characterize which access methods are in
44 * use. DIRECT by itself shows whether there is any O_DIRECT traffic.
45 * NORMAL + DIRECT shows how much data is going through the system call
46 * interface. A large amount of SERVER traffic without much NORMAL or
47 * DIRECT traffic shows that applications are using mapped files.
48 *
49 * NFS page counters
50 *
51 * These count the number of pages read or written via nfs_readpage(),
52 * nfs_readpages(), or their write equivalents.
53 */
54enum nfs_stat_bytecounters {
55 NFSIOS_NORMALREADBYTES = 0,
56 NFSIOS_NORMALWRITTENBYTES,
57 NFSIOS_DIRECTREADBYTES,
58 NFSIOS_DIRECTWRITTENBYTES,
59 NFSIOS_SERVERREADBYTES,
60 NFSIOS_SERVERWRITTENBYTES,
61 NFSIOS_READPAGES,
62 NFSIOS_WRITEPAGES,
63 __NFSIOS_BYTESMAX,
64};
65
66/*
67 * NFS event counters
68 *
69 * These counters provide a low-overhead way of monitoring client activity
70 * without enabling NFS trace debugging. The counters show the rate at
71 * which VFS requests are made, and how often the client invalidates its
72 * data and attribute caches. This allows system administrators to monitor
73 * such things as how close-to-open is working, and answer questions such
74 * as "why are there so many GETATTR requests on the wire?"
75 *
76 * They also count anamolous events such as short reads and writes, silly
77 * renames due to close-after-delete, and operations that change the size
78 * of a file (such operations can often be the source of data corruption
79 * if applications aren't using file locking properly).
80 */
81enum nfs_stat_eventcounters {
82 NFSIOS_INODEREVALIDATE = 0,
83 NFSIOS_DENTRYREVALIDATE,
84 NFSIOS_DATAINVALIDATE,
85 NFSIOS_ATTRINVALIDATE,
86 NFSIOS_VFSOPEN,
87 NFSIOS_VFSLOOKUP,
88 NFSIOS_VFSACCESS,
89 NFSIOS_VFSUPDATEPAGE,
90 NFSIOS_VFSREADPAGE,
91 NFSIOS_VFSREADPAGES,
92 NFSIOS_VFSWRITEPAGE,
93 NFSIOS_VFSWRITEPAGES,
94 NFSIOS_VFSGETDENTS,
95 NFSIOS_VFSSETATTR,
96 NFSIOS_VFSFLUSH,
97 NFSIOS_VFSFSYNC,
98 NFSIOS_VFSLOCK,
99 NFSIOS_VFSRELEASE,
100 NFSIOS_CONGESTIONWAIT,
101 NFSIOS_SETATTRTRUNC,
102 NFSIOS_EXTENDWRITE,
103 NFSIOS_SILLYRENAME,
104 NFSIOS_SHORTREAD,
105 NFSIOS_SHORTWRITE,
106 NFSIOS_DELAY,
107 __NFSIOS_COUNTSMAX,
108};
109
110#ifdef __KERNEL__
111
112#include <linux/percpu.h> 13#include <linux/percpu.h>
113#include <linux/cache.h> 14#include <linux/cache.h>
15#include <linux/nfs_iostat.h>
114 16
115struct nfs_iostats { 17struct nfs_iostats {
116 unsigned long long bytes[__NFSIOS_BYTESMAX]; 18 unsigned long long bytes[__NFSIOS_BYTESMAX];
117 unsigned long events[__NFSIOS_COUNTSMAX]; 19 unsigned long events[__NFSIOS_COUNTSMAX];
118} ____cacheline_aligned; 20} ____cacheline_aligned;
119 21
120static inline void nfs_inc_server_stats(struct nfs_server *server, enum nfs_stat_eventcounters stat) 22static inline void nfs_inc_server_stats(const struct nfs_server *server,
23 enum nfs_stat_eventcounters stat)
121{ 24{
122 struct nfs_iostats *iostats; 25 struct nfs_iostats *iostats;
123 int cpu; 26 int cpu;
124 27
125 cpu = get_cpu(); 28 cpu = get_cpu();
126 iostats = per_cpu_ptr(server->io_stats, cpu); 29 iostats = per_cpu_ptr(server->io_stats, cpu);
127 iostats->events[stat] ++; 30 iostats->events[stat]++;
128 put_cpu_no_resched(); 31 put_cpu_no_resched();
129} 32}
130 33
131static inline void nfs_inc_stats(struct inode *inode, enum nfs_stat_eventcounters stat) 34static inline void nfs_inc_stats(const struct inode *inode,
35 enum nfs_stat_eventcounters stat)
132{ 36{
133 nfs_inc_server_stats(NFS_SERVER(inode), stat); 37 nfs_inc_server_stats(NFS_SERVER(inode), stat);
134} 38}
135 39
136static inline void nfs_add_server_stats(struct nfs_server *server, enum nfs_stat_bytecounters stat, unsigned long addend) 40static inline void nfs_add_server_stats(const struct nfs_server *server,
41 enum nfs_stat_bytecounters stat,
42 unsigned long addend)
137{ 43{
138 struct nfs_iostats *iostats; 44 struct nfs_iostats *iostats;
139 int cpu; 45 int cpu;
@@ -144,7 +50,9 @@ static inline void nfs_add_server_stats(struct nfs_server *server, enum nfs_stat
144 put_cpu_no_resched(); 50 put_cpu_no_resched();
145} 51}
146 52
147static inline void nfs_add_stats(struct inode *inode, enum nfs_stat_bytecounters stat, unsigned long addend) 53static inline void nfs_add_stats(const struct inode *inode,
54 enum nfs_stat_bytecounters stat,
55 unsigned long addend)
148{ 56{
149 nfs_add_server_stats(NFS_SERVER(inode), stat, addend); 57 nfs_add_server_stats(NFS_SERVER(inode), stat, addend);
150} 58}
@@ -160,5 +68,4 @@ static inline void nfs_free_iostats(struct nfs_iostats *stats)
160 free_percpu(stats); 68 free_percpu(stats);
161} 69}
162 70
163#endif 71#endif /* _NFS_IOSTAT */
164#endif
diff --git a/fs/nfs/nfs3acl.c b/fs/nfs/nfs3acl.c
index 9b7362565c0c..423842f51ac9 100644
--- a/fs/nfs/nfs3acl.c
+++ b/fs/nfs/nfs3acl.c
@@ -5,6 +5,8 @@
5#include <linux/posix_acl_xattr.h> 5#include <linux/posix_acl_xattr.h>
6#include <linux/nfsacl.h> 6#include <linux/nfsacl.h>
7 7
8#include "internal.h"
9
8#define NFSDBG_FACILITY NFSDBG_PROC 10#define NFSDBG_FACILITY NFSDBG_PROC
9 11
10ssize_t nfs3_listxattr(struct dentry *dentry, char *buffer, size_t size) 12ssize_t nfs3_listxattr(struct dentry *dentry, char *buffer, size_t size)
@@ -205,6 +207,8 @@ struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
205 status = nfs_revalidate_inode(server, inode); 207 status = nfs_revalidate_inode(server, inode);
206 if (status < 0) 208 if (status < 0)
207 return ERR_PTR(status); 209 return ERR_PTR(status);
210 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL)
211 nfs_zap_acl_cache(inode);
208 acl = nfs3_get_cached_acl(inode, type); 212 acl = nfs3_get_cached_acl(inode, type);
209 if (acl != ERR_PTR(-EAGAIN)) 213 if (acl != ERR_PTR(-EAGAIN))
210 return acl; 214 return acl;
@@ -319,9 +323,8 @@ static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
319 dprintk("NFS call setacl\n"); 323 dprintk("NFS call setacl\n");
320 msg.rpc_proc = &server->client_acl->cl_procinfo[ACLPROC3_SETACL]; 324 msg.rpc_proc = &server->client_acl->cl_procinfo[ACLPROC3_SETACL];
321 status = rpc_call_sync(server->client_acl, &msg, 0); 325 status = rpc_call_sync(server->client_acl, &msg, 0);
322 spin_lock(&inode->i_lock); 326 nfs_access_zap_cache(inode);
323 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS; 327 nfs_zap_acl_cache(inode);
324 spin_unlock(&inode->i_lock);
325 dprintk("NFS reply setacl: %d\n", status); 328 dprintk("NFS reply setacl: %d\n", status);
326 329
327 /* pages may have been allocated at the xdr layer. */ 330 /* pages may have been allocated at the xdr layer. */
diff --git a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c
index c3523ad03ed1..1e750e4574a9 100644
--- a/fs/nfs/nfs3proc.c
+++ b/fs/nfs/nfs3proc.c
@@ -129,6 +129,8 @@ nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
129 int status; 129 int status;
130 130
131 dprintk("NFS call setattr\n"); 131 dprintk("NFS call setattr\n");
132 if (sattr->ia_valid & ATTR_FILE)
133 msg.rpc_cred = nfs_file_cred(sattr->ia_file);
132 nfs_fattr_init(fattr); 134 nfs_fattr_init(fattr);
133 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); 135 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
134 if (status == 0) 136 if (status == 0)
@@ -248,6 +250,53 @@ static int nfs3_proc_readlink(struct inode *inode, struct page *page,
248 return status; 250 return status;
249} 251}
250 252
253struct nfs3_createdata {
254 struct rpc_message msg;
255 union {
256 struct nfs3_createargs create;
257 struct nfs3_mkdirargs mkdir;
258 struct nfs3_symlinkargs symlink;
259 struct nfs3_mknodargs mknod;
260 } arg;
261 struct nfs3_diropres res;
262 struct nfs_fh fh;
263 struct nfs_fattr fattr;
264 struct nfs_fattr dir_attr;
265};
266
267static struct nfs3_createdata *nfs3_alloc_createdata(void)
268{
269 struct nfs3_createdata *data;
270
271 data = kzalloc(sizeof(*data), GFP_KERNEL);
272 if (data != NULL) {
273 data->msg.rpc_argp = &data->arg;
274 data->msg.rpc_resp = &data->res;
275 data->res.fh = &data->fh;
276 data->res.fattr = &data->fattr;
277 data->res.dir_attr = &data->dir_attr;
278 nfs_fattr_init(data->res.fattr);
279 nfs_fattr_init(data->res.dir_attr);
280 }
281 return data;
282}
283
284static int nfs3_do_create(struct inode *dir, struct dentry *dentry, struct nfs3_createdata *data)
285{
286 int status;
287
288 status = rpc_call_sync(NFS_CLIENT(dir), &data->msg, 0);
289 nfs_post_op_update_inode(dir, data->res.dir_attr);
290 if (status == 0)
291 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
292 return status;
293}
294
295static void nfs3_free_createdata(struct nfs3_createdata *data)
296{
297 kfree(data);
298}
299
251/* 300/*
252 * Create a regular file. 301 * Create a regular file.
253 * For now, we don't implement O_EXCL. 302 * For now, we don't implement O_EXCL.
@@ -256,70 +305,60 @@ static int
256nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, 305nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
257 int flags, struct nameidata *nd) 306 int flags, struct nameidata *nd)
258{ 307{
259 struct nfs_fh fhandle; 308 struct nfs3_createdata *data;
260 struct nfs_fattr fattr;
261 struct nfs_fattr dir_attr;
262 struct nfs3_createargs arg = {
263 .fh = NFS_FH(dir),
264 .name = dentry->d_name.name,
265 .len = dentry->d_name.len,
266 .sattr = sattr,
267 };
268 struct nfs3_diropres res = {
269 .dir_attr = &dir_attr,
270 .fh = &fhandle,
271 .fattr = &fattr
272 };
273 struct rpc_message msg = {
274 .rpc_proc = &nfs3_procedures[NFS3PROC_CREATE],
275 .rpc_argp = &arg,
276 .rpc_resp = &res,
277 };
278 mode_t mode = sattr->ia_mode; 309 mode_t mode = sattr->ia_mode;
279 int status; 310 int status = -ENOMEM;
280 311
281 dprintk("NFS call create %s\n", dentry->d_name.name); 312 dprintk("NFS call create %s\n", dentry->d_name.name);
282 arg.createmode = NFS3_CREATE_UNCHECKED; 313
314 data = nfs3_alloc_createdata();
315 if (data == NULL)
316 goto out;
317
318 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_CREATE];
319 data->arg.create.fh = NFS_FH(dir);
320 data->arg.create.name = dentry->d_name.name;
321 data->arg.create.len = dentry->d_name.len;
322 data->arg.create.sattr = sattr;
323
324 data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
283 if (flags & O_EXCL) { 325 if (flags & O_EXCL) {
284 arg.createmode = NFS3_CREATE_EXCLUSIVE; 326 data->arg.create.createmode = NFS3_CREATE_EXCLUSIVE;
285 arg.verifier[0] = jiffies; 327 data->arg.create.verifier[0] = jiffies;
286 arg.verifier[1] = current->pid; 328 data->arg.create.verifier[1] = current->pid;
287 } 329 }
288 330
289 sattr->ia_mode &= ~current->fs->umask; 331 sattr->ia_mode &= ~current->fs->umask;
290 332
291again: 333 for (;;) {
292 nfs_fattr_init(&dir_attr); 334 status = nfs3_do_create(dir, dentry, data);
293 nfs_fattr_init(&fattr);
294 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
295 nfs_refresh_inode(dir, &dir_attr);
296 335
297 /* If the server doesn't support the exclusive creation semantics, 336 if (status != -ENOTSUPP)
298 * try again with simple 'guarded' mode. */ 337 break;
299 if (status == -ENOTSUPP) { 338 /* If the server doesn't support the exclusive creation
300 switch (arg.createmode) { 339 * semantics, try again with simple 'guarded' mode. */
340 switch (data->arg.create.createmode) {
301 case NFS3_CREATE_EXCLUSIVE: 341 case NFS3_CREATE_EXCLUSIVE:
302 arg.createmode = NFS3_CREATE_GUARDED; 342 data->arg.create.createmode = NFS3_CREATE_GUARDED;
303 break; 343 break;
304 344
305 case NFS3_CREATE_GUARDED: 345 case NFS3_CREATE_GUARDED:
306 arg.createmode = NFS3_CREATE_UNCHECKED; 346 data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
307 break; 347 break;
308 348
309 case NFS3_CREATE_UNCHECKED: 349 case NFS3_CREATE_UNCHECKED:
310 goto out; 350 goto out;
311 } 351 }
312 goto again; 352 nfs_fattr_init(data->res.dir_attr);
353 nfs_fattr_init(data->res.fattr);
313 } 354 }
314 355
315 if (status == 0)
316 status = nfs_instantiate(dentry, &fhandle, &fattr);
317 if (status != 0) 356 if (status != 0)
318 goto out; 357 goto out;
319 358
320 /* When we created the file with exclusive semantics, make 359 /* When we created the file with exclusive semantics, make
321 * sure we set the attributes afterwards. */ 360 * sure we set the attributes afterwards. */
322 if (arg.createmode == NFS3_CREATE_EXCLUSIVE) { 361 if (data->arg.create.createmode == NFS3_CREATE_EXCLUSIVE) {
323 dprintk("NFS call setattr (post-create)\n"); 362 dprintk("NFS call setattr (post-create)\n");
324 363
325 if (!(sattr->ia_valid & ATTR_ATIME_SET)) 364 if (!(sattr->ia_valid & ATTR_ATIME_SET))
@@ -330,14 +369,15 @@ again:
330 /* Note: we could use a guarded setattr here, but I'm 369 /* Note: we could use a guarded setattr here, but I'm
331 * not sure this buys us anything (and I'd have 370 * not sure this buys us anything (and I'd have
332 * to revamp the NFSv3 XDR code) */ 371 * to revamp the NFSv3 XDR code) */
333 status = nfs3_proc_setattr(dentry, &fattr, sattr); 372 status = nfs3_proc_setattr(dentry, data->res.fattr, sattr);
334 nfs_post_op_update_inode(dentry->d_inode, &fattr); 373 nfs_post_op_update_inode(dentry->d_inode, data->res.fattr);
335 dprintk("NFS reply setattr (post-create): %d\n", status); 374 dprintk("NFS reply setattr (post-create): %d\n", status);
375 if (status != 0)
376 goto out;
336 } 377 }
337 if (status != 0)
338 goto out;
339 status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode); 378 status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
340out: 379out:
380 nfs3_free_createdata(data);
341 dprintk("NFS reply create: %d\n", status); 381 dprintk("NFS reply create: %d\n", status);
342 return status; 382 return status;
343} 383}
@@ -452,40 +492,28 @@ static int
452nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page, 492nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
453 unsigned int len, struct iattr *sattr) 493 unsigned int len, struct iattr *sattr)
454{ 494{
455 struct nfs_fh fhandle; 495 struct nfs3_createdata *data;
456 struct nfs_fattr fattr, dir_attr; 496 int status = -ENOMEM;
457 struct nfs3_symlinkargs arg = {
458 .fromfh = NFS_FH(dir),
459 .fromname = dentry->d_name.name,
460 .fromlen = dentry->d_name.len,
461 .pages = &page,
462 .pathlen = len,
463 .sattr = sattr
464 };
465 struct nfs3_diropres res = {
466 .dir_attr = &dir_attr,
467 .fh = &fhandle,
468 .fattr = &fattr
469 };
470 struct rpc_message msg = {
471 .rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK],
472 .rpc_argp = &arg,
473 .rpc_resp = &res,
474 };
475 int status;
476 497
477 if (len > NFS3_MAXPATHLEN) 498 if (len > NFS3_MAXPATHLEN)
478 return -ENAMETOOLONG; 499 return -ENAMETOOLONG;
479 500
480 dprintk("NFS call symlink %s\n", dentry->d_name.name); 501 dprintk("NFS call symlink %s\n", dentry->d_name.name);
481 502
482 nfs_fattr_init(&dir_attr); 503 data = nfs3_alloc_createdata();
483 nfs_fattr_init(&fattr); 504 if (data == NULL)
484 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
485 nfs_post_op_update_inode(dir, &dir_attr);
486 if (status != 0)
487 goto out; 505 goto out;
488 status = nfs_instantiate(dentry, &fhandle, &fattr); 506 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK];
507 data->arg.symlink.fromfh = NFS_FH(dir);
508 data->arg.symlink.fromname = dentry->d_name.name;
509 data->arg.symlink.fromlen = dentry->d_name.len;
510 data->arg.symlink.pages = &page;
511 data->arg.symlink.pathlen = len;
512 data->arg.symlink.sattr = sattr;
513
514 status = nfs3_do_create(dir, dentry, data);
515
516 nfs3_free_createdata(data);
489out: 517out:
490 dprintk("NFS reply symlink: %d\n", status); 518 dprintk("NFS reply symlink: %d\n", status);
491 return status; 519 return status;
@@ -494,42 +522,31 @@ out:
494static int 522static int
495nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr) 523nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
496{ 524{
497 struct nfs_fh fhandle; 525 struct nfs3_createdata *data;
498 struct nfs_fattr fattr, dir_attr;
499 struct nfs3_mkdirargs arg = {
500 .fh = NFS_FH(dir),
501 .name = dentry->d_name.name,
502 .len = dentry->d_name.len,
503 .sattr = sattr
504 };
505 struct nfs3_diropres res = {
506 .dir_attr = &dir_attr,
507 .fh = &fhandle,
508 .fattr = &fattr
509 };
510 struct rpc_message msg = {
511 .rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR],
512 .rpc_argp = &arg,
513 .rpc_resp = &res,
514 };
515 int mode = sattr->ia_mode; 526 int mode = sattr->ia_mode;
516 int status; 527 int status = -ENOMEM;
517 528
518 dprintk("NFS call mkdir %s\n", dentry->d_name.name); 529 dprintk("NFS call mkdir %s\n", dentry->d_name.name);
519 530
520 sattr->ia_mode &= ~current->fs->umask; 531 sattr->ia_mode &= ~current->fs->umask;
521 532
522 nfs_fattr_init(&dir_attr); 533 data = nfs3_alloc_createdata();
523 nfs_fattr_init(&fattr); 534 if (data == NULL)
524 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
525 nfs_post_op_update_inode(dir, &dir_attr);
526 if (status != 0)
527 goto out; 535 goto out;
528 status = nfs_instantiate(dentry, &fhandle, &fattr); 536
537 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR];
538 data->arg.mkdir.fh = NFS_FH(dir);
539 data->arg.mkdir.name = dentry->d_name.name;
540 data->arg.mkdir.len = dentry->d_name.len;
541 data->arg.mkdir.sattr = sattr;
542
543 status = nfs3_do_create(dir, dentry, data);
529 if (status != 0) 544 if (status != 0)
530 goto out; 545 goto out;
546
531 status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode); 547 status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
532out: 548out:
549 nfs3_free_createdata(data);
533 dprintk("NFS reply mkdir: %d\n", status); 550 dprintk("NFS reply mkdir: %d\n", status);
534 return status; 551 return status;
535} 552}
@@ -615,52 +632,50 @@ static int
615nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr, 632nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
616 dev_t rdev) 633 dev_t rdev)
617{ 634{
618 struct nfs_fh fh; 635 struct nfs3_createdata *data;
619 struct nfs_fattr fattr, dir_attr;
620 struct nfs3_mknodargs arg = {
621 .fh = NFS_FH(dir),
622 .name = dentry->d_name.name,
623 .len = dentry->d_name.len,
624 .sattr = sattr,
625 .rdev = rdev
626 };
627 struct nfs3_diropres res = {
628 .dir_attr = &dir_attr,
629 .fh = &fh,
630 .fattr = &fattr
631 };
632 struct rpc_message msg = {
633 .rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD],
634 .rpc_argp = &arg,
635 .rpc_resp = &res,
636 };
637 mode_t mode = sattr->ia_mode; 636 mode_t mode = sattr->ia_mode;
638 int status; 637 int status = -ENOMEM;
639
640 switch (sattr->ia_mode & S_IFMT) {
641 case S_IFBLK: arg.type = NF3BLK; break;
642 case S_IFCHR: arg.type = NF3CHR; break;
643 case S_IFIFO: arg.type = NF3FIFO; break;
644 case S_IFSOCK: arg.type = NF3SOCK; break;
645 default: return -EINVAL;
646 }
647 638
648 dprintk("NFS call mknod %s %u:%u\n", dentry->d_name.name, 639 dprintk("NFS call mknod %s %u:%u\n", dentry->d_name.name,
649 MAJOR(rdev), MINOR(rdev)); 640 MAJOR(rdev), MINOR(rdev));
650 641
651 sattr->ia_mode &= ~current->fs->umask; 642 sattr->ia_mode &= ~current->fs->umask;
652 643
653 nfs_fattr_init(&dir_attr); 644 data = nfs3_alloc_createdata();
654 nfs_fattr_init(&fattr); 645 if (data == NULL)
655 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
656 nfs_post_op_update_inode(dir, &dir_attr);
657 if (status != 0)
658 goto out; 646 goto out;
659 status = nfs_instantiate(dentry, &fh, &fattr); 647
648 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD];
649 data->arg.mknod.fh = NFS_FH(dir);
650 data->arg.mknod.name = dentry->d_name.name;
651 data->arg.mknod.len = dentry->d_name.len;
652 data->arg.mknod.sattr = sattr;
653 data->arg.mknod.rdev = rdev;
654
655 switch (sattr->ia_mode & S_IFMT) {
656 case S_IFBLK:
657 data->arg.mknod.type = NF3BLK;
658 break;
659 case S_IFCHR:
660 data->arg.mknod.type = NF3CHR;
661 break;
662 case S_IFIFO:
663 data->arg.mknod.type = NF3FIFO;
664 break;
665 case S_IFSOCK:
666 data->arg.mknod.type = NF3SOCK;
667 break;
668 default:
669 status = -EINVAL;
670 goto out;
671 }
672
673 status = nfs3_do_create(dir, dentry, data);
660 if (status != 0) 674 if (status != 0)
661 goto out; 675 goto out;
662 status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode); 676 status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
663out: 677out:
678 nfs3_free_createdata(data);
664 dprintk("NFS reply mknod: %d\n", status); 679 dprintk("NFS reply mknod: %d\n", status);
665 return status; 680 return status;
666} 681}
@@ -801,8 +816,6 @@ const struct nfs_rpc_ops nfs_v3_clientops = {
801 .write_done = nfs3_write_done, 816 .write_done = nfs3_write_done,
802 .commit_setup = nfs3_proc_commit_setup, 817 .commit_setup = nfs3_proc_commit_setup,
803 .commit_done = nfs3_commit_done, 818 .commit_done = nfs3_commit_done,
804 .file_open = nfs_open,
805 .file_release = nfs_release,
806 .lock = nfs3_proc_lock, 819 .lock = nfs3_proc_lock,
807 .clear_acl_cache = nfs3_forget_cached_acls, 820 .clear_acl_cache = nfs3_forget_cached_acls,
808}; 821};
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 1293e0acd82b..c910413eaeca 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -451,9 +451,7 @@ static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
451 /* Save the delegation */ 451 /* Save the delegation */
452 memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); 452 memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data));
453 rcu_read_unlock(); 453 rcu_read_unlock();
454 lock_kernel();
455 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); 454 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode);
456 unlock_kernel();
457 if (ret != 0) 455 if (ret != 0)
458 goto out; 456 goto out;
459 ret = -EAGAIN; 457 ret = -EAGAIN;
@@ -1139,8 +1137,9 @@ static struct nfs4_state *nfs4_do_open(struct inode *dir, struct path *path, int
1139 return res; 1137 return res;
1140} 1138}
1141 1139
1142static int _nfs4_do_setattr(struct inode *inode, struct nfs_fattr *fattr, 1140static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
1143 struct iattr *sattr, struct nfs4_state *state) 1141 struct nfs_fattr *fattr, struct iattr *sattr,
1142 struct nfs4_state *state)
1144{ 1143{
1145 struct nfs_server *server = NFS_SERVER(inode); 1144 struct nfs_server *server = NFS_SERVER(inode);
1146 struct nfs_setattrargs arg = { 1145 struct nfs_setattrargs arg = {
@@ -1154,9 +1153,10 @@ static int _nfs4_do_setattr(struct inode *inode, struct nfs_fattr *fattr,
1154 .server = server, 1153 .server = server,
1155 }; 1154 };
1156 struct rpc_message msg = { 1155 struct rpc_message msg = {
1157 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], 1156 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
1158 .rpc_argp = &arg, 1157 .rpc_argp = &arg,
1159 .rpc_resp = &res, 1158 .rpc_resp = &res,
1159 .rpc_cred = cred,
1160 }; 1160 };
1161 unsigned long timestamp = jiffies; 1161 unsigned long timestamp = jiffies;
1162 int status; 1162 int status;
@@ -1166,7 +1166,6 @@ static int _nfs4_do_setattr(struct inode *inode, struct nfs_fattr *fattr,
1166 if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { 1166 if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) {
1167 /* Use that stateid */ 1167 /* Use that stateid */
1168 } else if (state != NULL) { 1168 } else if (state != NULL) {
1169 msg.rpc_cred = state->owner->so_cred;
1170 nfs4_copy_stateid(&arg.stateid, state, current->files); 1169 nfs4_copy_stateid(&arg.stateid, state, current->files);
1171 } else 1170 } else
1172 memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); 1171 memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid));
@@ -1177,15 +1176,16 @@ static int _nfs4_do_setattr(struct inode *inode, struct nfs_fattr *fattr,
1177 return status; 1176 return status;
1178} 1177}
1179 1178
1180static int nfs4_do_setattr(struct inode *inode, struct nfs_fattr *fattr, 1179static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
1181 struct iattr *sattr, struct nfs4_state *state) 1180 struct nfs_fattr *fattr, struct iattr *sattr,
1181 struct nfs4_state *state)
1182{ 1182{
1183 struct nfs_server *server = NFS_SERVER(inode); 1183 struct nfs_server *server = NFS_SERVER(inode);
1184 struct nfs4_exception exception = { }; 1184 struct nfs4_exception exception = { };
1185 int err; 1185 int err;
1186 do { 1186 do {
1187 err = nfs4_handle_exception(server, 1187 err = nfs4_handle_exception(server,
1188 _nfs4_do_setattr(inode, fattr, sattr, state), 1188 _nfs4_do_setattr(inode, cred, fattr, sattr, state),
1189 &exception); 1189 &exception);
1190 } while (exception.retry); 1190 } while (exception.retry);
1191 return err; 1191 return err;
@@ -1647,29 +1647,25 @@ static int
1647nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, 1647nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
1648 struct iattr *sattr) 1648 struct iattr *sattr)
1649{ 1649{
1650 struct rpc_cred *cred;
1651 struct inode *inode = dentry->d_inode; 1650 struct inode *inode = dentry->d_inode;
1652 struct nfs_open_context *ctx; 1651 struct rpc_cred *cred = NULL;
1653 struct nfs4_state *state = NULL; 1652 struct nfs4_state *state = NULL;
1654 int status; 1653 int status;
1655 1654
1656 nfs_fattr_init(fattr); 1655 nfs_fattr_init(fattr);
1657 1656
1658 cred = rpc_lookup_cred();
1659 if (IS_ERR(cred))
1660 return PTR_ERR(cred);
1661
1662 /* Search for an existing open(O_WRITE) file */ 1657 /* Search for an existing open(O_WRITE) file */
1663 ctx = nfs_find_open_context(inode, cred, FMODE_WRITE); 1658 if (sattr->ia_valid & ATTR_FILE) {
1664 if (ctx != NULL) 1659 struct nfs_open_context *ctx;
1660
1661 ctx = nfs_file_open_context(sattr->ia_file);
1662 cred = ctx->cred;
1665 state = ctx->state; 1663 state = ctx->state;
1664 }
1666 1665
1667 status = nfs4_do_setattr(inode, fattr, sattr, state); 1666 status = nfs4_do_setattr(inode, cred, fattr, sattr, state);
1668 if (status == 0) 1667 if (status == 0)
1669 nfs_setattr_update_inode(inode, sattr); 1668 nfs_setattr_update_inode(inode, sattr);
1670 if (ctx != NULL)
1671 put_nfs_open_context(ctx);
1672 put_rpccred(cred);
1673 return status; 1669 return status;
1674} 1670}
1675 1671
@@ -1897,17 +1893,16 @@ nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
1897 goto out; 1893 goto out;
1898 } 1894 }
1899 state = nfs4_do_open(dir, &path, flags, sattr, cred); 1895 state = nfs4_do_open(dir, &path, flags, sattr, cred);
1900 put_rpccred(cred);
1901 d_drop(dentry); 1896 d_drop(dentry);
1902 if (IS_ERR(state)) { 1897 if (IS_ERR(state)) {
1903 status = PTR_ERR(state); 1898 status = PTR_ERR(state);
1904 goto out; 1899 goto out_putcred;
1905 } 1900 }
1906 d_add(dentry, igrab(state->inode)); 1901 d_add(dentry, igrab(state->inode));
1907 nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 1902 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
1908 if (flags & O_EXCL) { 1903 if (flags & O_EXCL) {
1909 struct nfs_fattr fattr; 1904 struct nfs_fattr fattr;
1910 status = nfs4_do_setattr(state->inode, &fattr, sattr, state); 1905 status = nfs4_do_setattr(state->inode, cred, &fattr, sattr, state);
1911 if (status == 0) 1906 if (status == 0)
1912 nfs_setattr_update_inode(state->inode, sattr); 1907 nfs_setattr_update_inode(state->inode, sattr);
1913 nfs_post_op_update_inode(state->inode, &fattr); 1908 nfs_post_op_update_inode(state->inode, &fattr);
@@ -1916,6 +1911,8 @@ nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
1916 status = nfs4_intent_set_file(nd, &path, state); 1911 status = nfs4_intent_set_file(nd, &path, state);
1917 else 1912 else
1918 nfs4_close_sync(&path, state, flags); 1913 nfs4_close_sync(&path, state, flags);
1914out_putcred:
1915 put_rpccred(cred);
1919out: 1916out:
1920 return status; 1917 return status;
1921} 1918}
@@ -2079,47 +2076,81 @@ static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *n
2079 return err; 2076 return err;
2080} 2077}
2081 2078
2079struct nfs4_createdata {
2080 struct rpc_message msg;
2081 struct nfs4_create_arg arg;
2082 struct nfs4_create_res res;
2083 struct nfs_fh fh;
2084 struct nfs_fattr fattr;
2085 struct nfs_fattr dir_fattr;
2086};
2087
2088static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir,
2089 struct qstr *name, struct iattr *sattr, u32 ftype)
2090{
2091 struct nfs4_createdata *data;
2092
2093 data = kzalloc(sizeof(*data), GFP_KERNEL);
2094 if (data != NULL) {
2095 struct nfs_server *server = NFS_SERVER(dir);
2096
2097 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE];
2098 data->msg.rpc_argp = &data->arg;
2099 data->msg.rpc_resp = &data->res;
2100 data->arg.dir_fh = NFS_FH(dir);
2101 data->arg.server = server;
2102 data->arg.name = name;
2103 data->arg.attrs = sattr;
2104 data->arg.ftype = ftype;
2105 data->arg.bitmask = server->attr_bitmask;
2106 data->res.server = server;
2107 data->res.fh = &data->fh;
2108 data->res.fattr = &data->fattr;
2109 data->res.dir_fattr = &data->dir_fattr;
2110 nfs_fattr_init(data->res.fattr);
2111 nfs_fattr_init(data->res.dir_fattr);
2112 }
2113 return data;
2114}
2115
2116static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data)
2117{
2118 int status = rpc_call_sync(NFS_CLIENT(dir), &data->msg, 0);
2119 if (status == 0) {
2120 update_changeattr(dir, &data->res.dir_cinfo);
2121 nfs_post_op_update_inode(dir, data->res.dir_fattr);
2122 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
2123 }
2124 return status;
2125}
2126
2127static void nfs4_free_createdata(struct nfs4_createdata *data)
2128{
2129 kfree(data);
2130}
2131
2082static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, 2132static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
2083 struct page *page, unsigned int len, struct iattr *sattr) 2133 struct page *page, unsigned int len, struct iattr *sattr)
2084{ 2134{
2085 struct nfs_server *server = NFS_SERVER(dir); 2135 struct nfs4_createdata *data;
2086 struct nfs_fh fhandle; 2136 int status = -ENAMETOOLONG;
2087 struct nfs_fattr fattr, dir_fattr;
2088 struct nfs4_create_arg arg = {
2089 .dir_fh = NFS_FH(dir),
2090 .server = server,
2091 .name = &dentry->d_name,
2092 .attrs = sattr,
2093 .ftype = NF4LNK,
2094 .bitmask = server->attr_bitmask,
2095 };
2096 struct nfs4_create_res res = {
2097 .server = server,
2098 .fh = &fhandle,
2099 .fattr = &fattr,
2100 .dir_fattr = &dir_fattr,
2101 };
2102 struct rpc_message msg = {
2103 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK],
2104 .rpc_argp = &arg,
2105 .rpc_resp = &res,
2106 };
2107 int status;
2108 2137
2109 if (len > NFS4_MAXPATHLEN) 2138 if (len > NFS4_MAXPATHLEN)
2110 return -ENAMETOOLONG; 2139 goto out;
2111 2140
2112 arg.u.symlink.pages = &page; 2141 status = -ENOMEM;
2113 arg.u.symlink.len = len; 2142 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK);
2114 nfs_fattr_init(&fattr); 2143 if (data == NULL)
2115 nfs_fattr_init(&dir_fattr); 2144 goto out;
2145
2146 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK];
2147 data->arg.u.symlink.pages = &page;
2148 data->arg.u.symlink.len = len;
2116 2149
2117 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); 2150 status = nfs4_do_create(dir, dentry, data);
2118 if (!status) { 2151
2119 update_changeattr(dir, &res.dir_cinfo); 2152 nfs4_free_createdata(data);
2120 nfs_post_op_update_inode(dir, res.dir_fattr); 2153out:
2121 status = nfs_instantiate(dentry, &fhandle, &fattr);
2122 }
2123 return status; 2154 return status;
2124} 2155}
2125 2156
@@ -2140,39 +2171,17 @@ static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
2140static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, 2171static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
2141 struct iattr *sattr) 2172 struct iattr *sattr)
2142{ 2173{
2143 struct nfs_server *server = NFS_SERVER(dir); 2174 struct nfs4_createdata *data;
2144 struct nfs_fh fhandle; 2175 int status = -ENOMEM;
2145 struct nfs_fattr fattr, dir_fattr;
2146 struct nfs4_create_arg arg = {
2147 .dir_fh = NFS_FH(dir),
2148 .server = server,
2149 .name = &dentry->d_name,
2150 .attrs = sattr,
2151 .ftype = NF4DIR,
2152 .bitmask = server->attr_bitmask,
2153 };
2154 struct nfs4_create_res res = {
2155 .server = server,
2156 .fh = &fhandle,
2157 .fattr = &fattr,
2158 .dir_fattr = &dir_fattr,
2159 };
2160 struct rpc_message msg = {
2161 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE],
2162 .rpc_argp = &arg,
2163 .rpc_resp = &res,
2164 };
2165 int status;
2166 2176
2167 nfs_fattr_init(&fattr); 2177 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR);
2168 nfs_fattr_init(&dir_fattr); 2178 if (data == NULL)
2169 2179 goto out;
2170 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); 2180
2171 if (!status) { 2181 status = nfs4_do_create(dir, dentry, data);
2172 update_changeattr(dir, &res.dir_cinfo); 2182
2173 nfs_post_op_update_inode(dir, res.dir_fattr); 2183 nfs4_free_createdata(data);
2174 status = nfs_instantiate(dentry, &fhandle, &fattr); 2184out:
2175 }
2176 return status; 2185 return status;
2177} 2186}
2178 2187
@@ -2242,56 +2251,34 @@ static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
2242static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, 2251static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
2243 struct iattr *sattr, dev_t rdev) 2252 struct iattr *sattr, dev_t rdev)
2244{ 2253{
2245 struct nfs_server *server = NFS_SERVER(dir); 2254 struct nfs4_createdata *data;
2246 struct nfs_fh fh; 2255 int mode = sattr->ia_mode;
2247 struct nfs_fattr fattr, dir_fattr; 2256 int status = -ENOMEM;
2248 struct nfs4_create_arg arg = {
2249 .dir_fh = NFS_FH(dir),
2250 .server = server,
2251 .name = &dentry->d_name,
2252 .attrs = sattr,
2253 .bitmask = server->attr_bitmask,
2254 };
2255 struct nfs4_create_res res = {
2256 .server = server,
2257 .fh = &fh,
2258 .fattr = &fattr,
2259 .dir_fattr = &dir_fattr,
2260 };
2261 struct rpc_message msg = {
2262 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE],
2263 .rpc_argp = &arg,
2264 .rpc_resp = &res,
2265 };
2266 int status;
2267 int mode = sattr->ia_mode;
2268
2269 nfs_fattr_init(&fattr);
2270 nfs_fattr_init(&dir_fattr);
2271 2257
2272 BUG_ON(!(sattr->ia_valid & ATTR_MODE)); 2258 BUG_ON(!(sattr->ia_valid & ATTR_MODE));
2273 BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode)); 2259 BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode));
2260
2261 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK);
2262 if (data == NULL)
2263 goto out;
2264
2274 if (S_ISFIFO(mode)) 2265 if (S_ISFIFO(mode))
2275 arg.ftype = NF4FIFO; 2266 data->arg.ftype = NF4FIFO;
2276 else if (S_ISBLK(mode)) { 2267 else if (S_ISBLK(mode)) {
2277 arg.ftype = NF4BLK; 2268 data->arg.ftype = NF4BLK;
2278 arg.u.device.specdata1 = MAJOR(rdev); 2269 data->arg.u.device.specdata1 = MAJOR(rdev);
2279 arg.u.device.specdata2 = MINOR(rdev); 2270 data->arg.u.device.specdata2 = MINOR(rdev);
2280 } 2271 }
2281 else if (S_ISCHR(mode)) { 2272 else if (S_ISCHR(mode)) {
2282 arg.ftype = NF4CHR; 2273 data->arg.ftype = NF4CHR;
2283 arg.u.device.specdata1 = MAJOR(rdev); 2274 data->arg.u.device.specdata1 = MAJOR(rdev);
2284 arg.u.device.specdata2 = MINOR(rdev); 2275 data->arg.u.device.specdata2 = MINOR(rdev);
2285 } 2276 }
2286 else
2287 arg.ftype = NF4SOCK;
2288 2277
2289 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); 2278 status = nfs4_do_create(dir, dentry, data);
2290 if (status == 0) { 2279
2291 update_changeattr(dir, &res.dir_cinfo); 2280 nfs4_free_createdata(data);
2292 nfs_post_op_update_inode(dir, res.dir_fattr); 2281out:
2293 status = nfs_instantiate(dentry, &fh, &fattr);
2294 }
2295 return status; 2282 return status;
2296} 2283}
2297 2284
@@ -2706,6 +2693,8 @@ static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)
2706 ret = nfs_revalidate_inode(server, inode); 2693 ret = nfs_revalidate_inode(server, inode);
2707 if (ret < 0) 2694 if (ret < 0)
2708 return ret; 2695 return ret;
2696 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL)
2697 nfs_zap_acl_cache(inode);
2709 ret = nfs4_read_cached_acl(inode, buf, buflen); 2698 ret = nfs4_read_cached_acl(inode, buf, buflen);
2710 if (ret != -ENOENT) 2699 if (ret != -ENOENT)
2711 return ret; 2700 return ret;
@@ -2733,7 +2722,8 @@ static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t bufl
2733 nfs_inode_return_delegation(inode); 2722 nfs_inode_return_delegation(inode);
2734 buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase); 2723 buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
2735 ret = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); 2724 ret = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
2736 nfs_zap_caches(inode); 2725 nfs_access_zap_cache(inode);
2726 nfs_zap_acl_cache(inode);
2737 return ret; 2727 return ret;
2738} 2728}
2739 2729
@@ -2767,8 +2757,7 @@ nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server)
2767 task->tk_status = 0; 2757 task->tk_status = 0;
2768 return -EAGAIN; 2758 return -EAGAIN;
2769 case -NFS4ERR_DELAY: 2759 case -NFS4ERR_DELAY:
2770 nfs_inc_server_stats((struct nfs_server *) server, 2760 nfs_inc_server_stats(server, NFSIOS_DELAY);
2771 NFSIOS_DELAY);
2772 case -NFS4ERR_GRACE: 2761 case -NFS4ERR_GRACE:
2773 rpc_delay(task, NFS4_POLL_RETRY_MAX); 2762 rpc_delay(task, NFS4_POLL_RETRY_MAX);
2774 task->tk_status = 0; 2763 task->tk_status = 0;
@@ -2933,7 +2922,7 @@ static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp, struct rpc_cre
2933 2922
2934int nfs4_proc_setclientid_confirm(struct nfs_client *clp, struct rpc_cred *cred) 2923int nfs4_proc_setclientid_confirm(struct nfs_client *clp, struct rpc_cred *cred)
2935{ 2924{
2936 long timeout; 2925 long timeout = 0;
2937 int err; 2926 int err;
2938 do { 2927 do {
2939 err = _nfs4_proc_setclientid_confirm(clp, cred); 2928 err = _nfs4_proc_setclientid_confirm(clp, cred);
@@ -3725,8 +3714,6 @@ const struct nfs_rpc_ops nfs_v4_clientops = {
3725 .write_done = nfs4_write_done, 3714 .write_done = nfs4_write_done,
3726 .commit_setup = nfs4_proc_commit_setup, 3715 .commit_setup = nfs4_proc_commit_setup,
3727 .commit_done = nfs4_commit_done, 3716 .commit_done = nfs4_commit_done,
3728 .file_open = nfs_open,
3729 .file_release = nfs_release,
3730 .lock = nfs4_proc_lock, 3717 .lock = nfs4_proc_lock,
3731 .clear_acl_cache = nfs4_zap_acl_attr, 3718 .clear_acl_cache = nfs4_zap_acl_attr,
3732}; 3719};
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 856a8934f610..401ef8b28f97 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -940,7 +940,6 @@ static int reclaimer(void *ptr)
940 allow_signal(SIGKILL); 940 allow_signal(SIGKILL);
941 941
942 /* Ensure exclusive access to NFSv4 state */ 942 /* Ensure exclusive access to NFSv4 state */
943 lock_kernel();
944 down_write(&clp->cl_sem); 943 down_write(&clp->cl_sem);
945 /* Are there any NFS mounts out there? */ 944 /* Are there any NFS mounts out there? */
946 if (list_empty(&clp->cl_superblocks)) 945 if (list_empty(&clp->cl_superblocks))
@@ -1000,7 +999,6 @@ restart_loop:
1000 nfs_delegation_reap_unclaimed(clp); 999 nfs_delegation_reap_unclaimed(clp);
1001out: 1000out:
1002 up_write(&clp->cl_sem); 1001 up_write(&clp->cl_sem);
1003 unlock_kernel();
1004 if (status == -NFS4ERR_CB_PATH_DOWN) 1002 if (status == -NFS4ERR_CB_PATH_DOWN)
1005 nfs_handle_cb_pathdown(clp); 1003 nfs_handle_cb_pathdown(clp);
1006 nfs4_clear_recover_bit(clp); 1004 nfs4_clear_recover_bit(clp);
diff --git a/fs/nfs/nfsroot.c b/fs/nfs/nfsroot.c
index 531379d36823..46763d1cd397 100644
--- a/fs/nfs/nfsroot.c
+++ b/fs/nfs/nfsroot.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * $Id: nfsroot.c,v 1.45 1998/03/07 10:44:46 mj Exp $
3 *
4 * Copyright (C) 1995, 1996 Gero Kuhlmann <gero@gkminix.han.de> 2 * Copyright (C) 1995, 1996 Gero Kuhlmann <gero@gkminix.han.de>
5 * 3 *
6 * Allow an NFS filesystem to be mounted as root. The way this works is: 4 * Allow an NFS filesystem to be mounted as root. The way this works is:
@@ -297,10 +295,10 @@ static int __init root_nfs_name(char *name)
297 nfs_data.flags = NFS_MOUNT_NONLM; /* No lockd in nfs root yet */ 295 nfs_data.flags = NFS_MOUNT_NONLM; /* No lockd in nfs root yet */
298 nfs_data.rsize = NFS_DEF_FILE_IO_SIZE; 296 nfs_data.rsize = NFS_DEF_FILE_IO_SIZE;
299 nfs_data.wsize = NFS_DEF_FILE_IO_SIZE; 297 nfs_data.wsize = NFS_DEF_FILE_IO_SIZE;
300 nfs_data.acregmin = 3; 298 nfs_data.acregmin = NFS_DEF_ACREGMIN;
301 nfs_data.acregmax = 60; 299 nfs_data.acregmax = NFS_DEF_ACREGMAX;
302 nfs_data.acdirmin = 30; 300 nfs_data.acdirmin = NFS_DEF_ACDIRMIN;
303 nfs_data.acdirmax = 60; 301 nfs_data.acdirmax = NFS_DEF_ACDIRMAX;
304 strcpy(buf, NFS_ROOT); 302 strcpy(buf, NFS_ROOT);
305 303
306 /* Process options received from the remote server */ 304 /* Process options received from the remote server */
diff --git a/fs/nfs/proc.c b/fs/nfs/proc.c
index 03599bfe81cf..4dbb84df1b68 100644
--- a/fs/nfs/proc.c
+++ b/fs/nfs/proc.c
@@ -129,6 +129,8 @@ nfs_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
129 sattr->ia_mode &= S_IALLUGO; 129 sattr->ia_mode &= S_IALLUGO;
130 130
131 dprintk("NFS call setattr\n"); 131 dprintk("NFS call setattr\n");
132 if (sattr->ia_valid & ATTR_FILE)
133 msg.rpc_cred = nfs_file_cred(sattr->ia_file);
132 nfs_fattr_init(fattr); 134 nfs_fattr_init(fattr);
133 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); 135 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
134 if (status == 0) 136 if (status == 0)
@@ -598,6 +600,29 @@ nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
598 return nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl); 600 return nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl);
599} 601}
600 602
603/* Helper functions for NFS lock bounds checking */
604#define NFS_LOCK32_OFFSET_MAX ((__s32)0x7fffffffUL)
605static int nfs_lock_check_bounds(const struct file_lock *fl)
606{
607 __s32 start, end;
608
609 start = (__s32)fl->fl_start;
610 if ((loff_t)start != fl->fl_start)
611 goto out_einval;
612
613 if (fl->fl_end != OFFSET_MAX) {
614 end = (__s32)fl->fl_end;
615 if ((loff_t)end != fl->fl_end)
616 goto out_einval;
617 } else
618 end = NFS_LOCK32_OFFSET_MAX;
619
620 if (start < 0 || start > end)
621 goto out_einval;
622 return 0;
623out_einval:
624 return -EINVAL;
625}
601 626
602const struct nfs_rpc_ops nfs_v2_clientops = { 627const struct nfs_rpc_ops nfs_v2_clientops = {
603 .version = 2, /* protocol version */ 628 .version = 2, /* protocol version */
@@ -630,7 +655,6 @@ const struct nfs_rpc_ops nfs_v2_clientops = {
630 .write_setup = nfs_proc_write_setup, 655 .write_setup = nfs_proc_write_setup,
631 .write_done = nfs_write_done, 656 .write_done = nfs_write_done,
632 .commit_setup = nfs_proc_commit_setup, 657 .commit_setup = nfs_proc_commit_setup,
633 .file_open = nfs_open,
634 .file_release = nfs_release,
635 .lock = nfs_proc_lock, 658 .lock = nfs_proc_lock,
659 .lock_check_bounds = nfs_lock_check_bounds,
636}; 660};
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 614efeed5437..1b94e3650f5c 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -47,6 +47,7 @@
47#include <linux/inet.h> 47#include <linux/inet.h>
48#include <linux/in6.h> 48#include <linux/in6.h>
49#include <net/ipv6.h> 49#include <net/ipv6.h>
50#include <linux/netdevice.h>
50#include <linux/nfs_xdr.h> 51#include <linux/nfs_xdr.h>
51#include <linux/magic.h> 52#include <linux/magic.h>
52#include <linux/parser.h> 53#include <linux/parser.h>
@@ -65,7 +66,6 @@
65enum { 66enum {
66 /* Mount options that take no arguments */ 67 /* Mount options that take no arguments */
67 Opt_soft, Opt_hard, 68 Opt_soft, Opt_hard,
68 Opt_intr, Opt_nointr,
69 Opt_posix, Opt_noposix, 69 Opt_posix, Opt_noposix,
70 Opt_cto, Opt_nocto, 70 Opt_cto, Opt_nocto,
71 Opt_ac, Opt_noac, 71 Opt_ac, Opt_noac,
@@ -92,8 +92,8 @@ enum {
92 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost, 92 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
93 Opt_addr, Opt_mountaddr, Opt_clientaddr, 93 Opt_addr, Opt_mountaddr, Opt_clientaddr,
94 94
95 /* Mount options that are ignored */ 95 /* Special mount options */
96 Opt_userspace, Opt_deprecated, 96 Opt_userspace, Opt_deprecated, Opt_sloppy,
97 97
98 Opt_err 98 Opt_err
99}; 99};
@@ -101,10 +101,14 @@ enum {
101static match_table_t nfs_mount_option_tokens = { 101static match_table_t nfs_mount_option_tokens = {
102 { Opt_userspace, "bg" }, 102 { Opt_userspace, "bg" },
103 { Opt_userspace, "fg" }, 103 { Opt_userspace, "fg" },
104 { Opt_userspace, "retry=%s" },
105
106 { Opt_sloppy, "sloppy" },
107
104 { Opt_soft, "soft" }, 108 { Opt_soft, "soft" },
105 { Opt_hard, "hard" }, 109 { Opt_hard, "hard" },
106 { Opt_intr, "intr" }, 110 { Opt_deprecated, "intr" },
107 { Opt_nointr, "nointr" }, 111 { Opt_deprecated, "nointr" },
108 { Opt_posix, "posix" }, 112 { Opt_posix, "posix" },
109 { Opt_noposix, "noposix" }, 113 { Opt_noposix, "noposix" },
110 { Opt_cto, "cto" }, 114 { Opt_cto, "cto" },
@@ -136,7 +140,6 @@ static match_table_t nfs_mount_option_tokens = {
136 { Opt_acdirmin, "acdirmin=%u" }, 140 { Opt_acdirmin, "acdirmin=%u" },
137 { Opt_acdirmax, "acdirmax=%u" }, 141 { Opt_acdirmax, "acdirmax=%u" },
138 { Opt_actimeo, "actimeo=%u" }, 142 { Opt_actimeo, "actimeo=%u" },
139 { Opt_userspace, "retry=%u" },
140 { Opt_namelen, "namlen=%u" }, 143 { Opt_namelen, "namlen=%u" },
141 { Opt_mountport, "mountport=%u" }, 144 { Opt_mountport, "mountport=%u" },
142 { Opt_mountvers, "mountvers=%u" }, 145 { Opt_mountvers, "mountvers=%u" },
@@ -207,6 +210,7 @@ static int nfs_xdev_get_sb(struct file_system_type *fs_type,
207 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); 210 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
208static void nfs_kill_super(struct super_block *); 211static void nfs_kill_super(struct super_block *);
209static void nfs_put_super(struct super_block *); 212static void nfs_put_super(struct super_block *);
213static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
210 214
211static struct file_system_type nfs_fs_type = { 215static struct file_system_type nfs_fs_type = {
212 .owner = THIS_MODULE, 216 .owner = THIS_MODULE,
@@ -234,6 +238,7 @@ static const struct super_operations nfs_sops = {
234 .umount_begin = nfs_umount_begin, 238 .umount_begin = nfs_umount_begin,
235 .show_options = nfs_show_options, 239 .show_options = nfs_show_options,
236 .show_stats = nfs_show_stats, 240 .show_stats = nfs_show_stats,
241 .remount_fs = nfs_remount,
237}; 242};
238 243
239#ifdef CONFIG_NFS_V4 244#ifdef CONFIG_NFS_V4
@@ -278,6 +283,7 @@ static const struct super_operations nfs4_sops = {
278 .umount_begin = nfs_umount_begin, 283 .umount_begin = nfs_umount_begin,
279 .show_options = nfs_show_options, 284 .show_options = nfs_show_options,
280 .show_stats = nfs_show_stats, 285 .show_stats = nfs_show_stats,
286 .remount_fs = nfs_remount,
281}; 287};
282#endif 288#endif
283 289
@@ -368,8 +374,6 @@ static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
368 }; 374 };
369 int error; 375 int error;
370 376
371 lock_kernel();
372
373 error = server->nfs_client->rpc_ops->statfs(server, fh, &res); 377 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
374 if (error < 0) 378 if (error < 0)
375 goto out_err; 379 goto out_err;
@@ -401,12 +405,10 @@ static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
401 405
402 buf->f_namelen = server->namelen; 406 buf->f_namelen = server->namelen;
403 407
404 unlock_kernel();
405 return 0; 408 return 0;
406 409
407 out_err: 410 out_err:
408 dprintk("%s: statfs error = %d\n", __func__, -error); 411 dprintk("%s: statfs error = %d\n", __func__, -error);
409 unlock_kernel();
410 return error; 412 return error;
411} 413}
412 414
@@ -514,13 +516,13 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
514 if (nfss->bsize != 0) 516 if (nfss->bsize != 0)
515 seq_printf(m, ",bsize=%u", nfss->bsize); 517 seq_printf(m, ",bsize=%u", nfss->bsize);
516 seq_printf(m, ",namlen=%u", nfss->namelen); 518 seq_printf(m, ",namlen=%u", nfss->namelen);
517 if (nfss->acregmin != 3*HZ || showdefaults) 519 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
518 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ); 520 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
519 if (nfss->acregmax != 60*HZ || showdefaults) 521 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
520 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ); 522 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
521 if (nfss->acdirmin != 30*HZ || showdefaults) 523 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
522 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ); 524 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
523 if (nfss->acdirmax != 60*HZ || showdefaults) 525 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
524 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ); 526 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
525 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) { 527 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
526 if (nfss->flags & nfs_infop->flag) 528 if (nfss->flags & nfs_infop->flag)
@@ -702,49 +704,233 @@ static int nfs_verify_server_address(struct sockaddr *addr)
702 return 0; 704 return 0;
703} 705}
704 706
707static void nfs_parse_ipv4_address(char *string, size_t str_len,
708 struct sockaddr *sap, size_t *addr_len)
709{
710 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
711 u8 *addr = (u8 *)&sin->sin_addr.s_addr;
712
713 if (str_len <= INET_ADDRSTRLEN) {
714 dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n",
715 (int)str_len, string);
716
717 sin->sin_family = AF_INET;
718 *addr_len = sizeof(*sin);
719 if (in4_pton(string, str_len, addr, '\0', NULL))
720 return;
721 }
722
723 sap->sa_family = AF_UNSPEC;
724 *addr_len = 0;
725}
726
727#define IPV6_SCOPE_DELIMITER '%'
728
729#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
730static void nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
731 const char *delim,
732 struct sockaddr_in6 *sin6)
733{
734 char *p;
735 size_t len;
736
737 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
738 return ;
739 if (*delim != IPV6_SCOPE_DELIMITER)
740 return;
741
742 len = (string + str_len) - delim - 1;
743 p = kstrndup(delim + 1, len, GFP_KERNEL);
744 if (p) {
745 unsigned long scope_id = 0;
746 struct net_device *dev;
747
748 dev = dev_get_by_name(&init_net, p);
749 if (dev != NULL) {
750 scope_id = dev->ifindex;
751 dev_put(dev);
752 } else {
753 /* scope_id is set to zero on error */
754 strict_strtoul(p, 10, &scope_id);
755 }
756
757 kfree(p);
758 sin6->sin6_scope_id = scope_id;
759 dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
760 }
761}
762
763static void nfs_parse_ipv6_address(char *string, size_t str_len,
764 struct sockaddr *sap, size_t *addr_len)
765{
766 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
767 u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
768 const char *delim;
769
770 if (str_len <= INET6_ADDRSTRLEN) {
771 dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n",
772 (int)str_len, string);
773
774 sin6->sin6_family = AF_INET6;
775 *addr_len = sizeof(*sin6);
776 if (in6_pton(string, str_len, addr, IPV6_SCOPE_DELIMITER, &delim)) {
777 nfs_parse_ipv6_scope_id(string, str_len, delim, sin6);
778 return;
779 }
780 }
781
782 sap->sa_family = AF_UNSPEC;
783 *addr_len = 0;
784}
785#else
786static void nfs_parse_ipv6_address(char *string, size_t str_len,
787 struct sockaddr *sap, size_t *addr_len)
788{
789 sap->sa_family = AF_UNSPEC;
790 *addr_len = 0;
791}
792#endif
793
705/* 794/*
706 * Parse string addresses passed in via a mount option, 795 * Construct a sockaddr based on the contents of a string that contains
707 * and construct a sockaddr based on the result. 796 * an IP address in presentation format.
708 * 797 *
709 * If address parsing fails, set the sockaddr's address 798 * If there is a problem constructing the new sockaddr, set the address
710 * family to AF_UNSPEC to force nfs_verify_server_address() 799 * family to AF_UNSPEC.
711 * to punt the mount.
712 */ 800 */
713static void nfs_parse_server_address(char *value, 801static void nfs_parse_ip_address(char *string, size_t str_len,
714 struct sockaddr *sap, 802 struct sockaddr *sap, size_t *addr_len)
715 size_t *len)
716{ 803{
717 if (strchr(value, ':')) { 804 unsigned int i, colons;
718 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
719 u8 *addr = (u8 *)&ap->sin6_addr.in6_u;
720 805
721 ap->sin6_family = AF_INET6; 806 colons = 0;
722 *len = sizeof(*ap); 807 for (i = 0; i < str_len; i++)
723 if (in6_pton(value, -1, addr, '\0', NULL)) 808 if (string[i] == ':')
724 return; 809 colons++;
725 } else { 810
726 struct sockaddr_in *ap = (struct sockaddr_in *)sap; 811 if (colons >= 2)
727 u8 *addr = (u8 *)&ap->sin_addr.s_addr; 812 nfs_parse_ipv6_address(string, str_len, sap, addr_len);
813 else
814 nfs_parse_ipv4_address(string, str_len, sap, addr_len);
815}
816
817/*
818 * Sanity check the NFS transport protocol.
819 *
820 */
821static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
822{
823 switch (mnt->nfs_server.protocol) {
824 case XPRT_TRANSPORT_UDP:
825 case XPRT_TRANSPORT_TCP:
826 case XPRT_TRANSPORT_RDMA:
827 break;
828 default:
829 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
830 }
831}
832
833/*
834 * For text based NFSv2/v3 mounts, the mount protocol transport default
835 * settings should depend upon the specified NFS transport.
836 */
837static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
838{
839 nfs_validate_transport_protocol(mnt);
728 840
729 ap->sin_family = AF_INET; 841 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
730 *len = sizeof(*ap); 842 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
731 if (in4_pton(value, -1, addr, '\0', NULL))
732 return; 843 return;
844 switch (mnt->nfs_server.protocol) {
845 case XPRT_TRANSPORT_UDP:
846 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
847 break;
848 case XPRT_TRANSPORT_TCP:
849 case XPRT_TRANSPORT_RDMA:
850 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
733 } 851 }
852}
734 853
735 sap->sa_family = AF_UNSPEC; 854/*
736 *len = 0; 855 * Parse the value of the 'sec=' option.
856 *
857 * The flavor_len setting is for v4 mounts.
858 */
859static int nfs_parse_security_flavors(char *value,
860 struct nfs_parsed_mount_data *mnt)
861{
862 substring_t args[MAX_OPT_ARGS];
863
864 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
865
866 switch (match_token(value, nfs_secflavor_tokens, args)) {
867 case Opt_sec_none:
868 mnt->auth_flavor_len = 0;
869 mnt->auth_flavors[0] = RPC_AUTH_NULL;
870 break;
871 case Opt_sec_sys:
872 mnt->auth_flavor_len = 0;
873 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
874 break;
875 case Opt_sec_krb5:
876 mnt->auth_flavor_len = 1;
877 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
878 break;
879 case Opt_sec_krb5i:
880 mnt->auth_flavor_len = 1;
881 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
882 break;
883 case Opt_sec_krb5p:
884 mnt->auth_flavor_len = 1;
885 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
886 break;
887 case Opt_sec_lkey:
888 mnt->auth_flavor_len = 1;
889 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
890 break;
891 case Opt_sec_lkeyi:
892 mnt->auth_flavor_len = 1;
893 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
894 break;
895 case Opt_sec_lkeyp:
896 mnt->auth_flavor_len = 1;
897 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
898 break;
899 case Opt_sec_spkm:
900 mnt->auth_flavor_len = 1;
901 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
902 break;
903 case Opt_sec_spkmi:
904 mnt->auth_flavor_len = 1;
905 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
906 break;
907 case Opt_sec_spkmp:
908 mnt->auth_flavor_len = 1;
909 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
910 break;
911 default:
912 return 0;
913 }
914
915 return 1;
916}
917
918static void nfs_parse_invalid_value(const char *option)
919{
920 dfprintk(MOUNT, "NFS: bad value specified for %s option\n", option);
737} 921}
738 922
739/* 923/*
740 * Error-check and convert a string of mount options from user space into 924 * Error-check and convert a string of mount options from user space into
741 * a data structure 925 * a data structure. The whole mount string is processed; bad options are
926 * skipped as they are encountered. If there were no errors, return 1;
927 * otherwise return 0 (zero).
742 */ 928 */
743static int nfs_parse_mount_options(char *raw, 929static int nfs_parse_mount_options(char *raw,
744 struct nfs_parsed_mount_data *mnt) 930 struct nfs_parsed_mount_data *mnt)
745{ 931{
746 char *p, *string, *secdata; 932 char *p, *string, *secdata;
747 int rc; 933 int rc, sloppy = 0, errors = 0;
748 934
749 if (!raw) { 935 if (!raw) {
750 dfprintk(MOUNT, "NFS: mount options string was NULL.\n"); 936 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
@@ -777,15 +963,16 @@ static int nfs_parse_mount_options(char *raw,
777 963
778 token = match_token(p, nfs_mount_option_tokens, args); 964 token = match_token(p, nfs_mount_option_tokens, args);
779 switch (token) { 965 switch (token) {
966
967 /*
968 * boolean options: foo/nofoo
969 */
780 case Opt_soft: 970 case Opt_soft:
781 mnt->flags |= NFS_MOUNT_SOFT; 971 mnt->flags |= NFS_MOUNT_SOFT;
782 break; 972 break;
783 case Opt_hard: 973 case Opt_hard:
784 mnt->flags &= ~NFS_MOUNT_SOFT; 974 mnt->flags &= ~NFS_MOUNT_SOFT;
785 break; 975 break;
786 case Opt_intr:
787 case Opt_nointr:
788 break;
789 case Opt_posix: 976 case Opt_posix:
790 mnt->flags |= NFS_MOUNT_POSIX; 977 mnt->flags |= NFS_MOUNT_POSIX;
791 break; 978 break;
@@ -819,20 +1006,14 @@ static int nfs_parse_mount_options(char *raw,
819 case Opt_udp: 1006 case Opt_udp:
820 mnt->flags &= ~NFS_MOUNT_TCP; 1007 mnt->flags &= ~NFS_MOUNT_TCP;
821 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP; 1008 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
822 mnt->timeo = 7;
823 mnt->retrans = 5;
824 break; 1009 break;
825 case Opt_tcp: 1010 case Opt_tcp:
826 mnt->flags |= NFS_MOUNT_TCP; 1011 mnt->flags |= NFS_MOUNT_TCP;
827 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP; 1012 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
828 mnt->timeo = 600;
829 mnt->retrans = 2;
830 break; 1013 break;
831 case Opt_rdma: 1014 case Opt_rdma:
832 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */ 1015 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
833 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA; 1016 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
834 mnt->timeo = 600;
835 mnt->retrans = 2;
836 break; 1017 break;
837 case Opt_acl: 1018 case Opt_acl:
838 mnt->flags &= ~NFS_MOUNT_NOACL; 1019 mnt->flags &= ~NFS_MOUNT_NOACL;
@@ -853,165 +1034,144 @@ static int nfs_parse_mount_options(char *raw,
853 mnt->flags |= NFS_MOUNT_UNSHARED; 1034 mnt->flags |= NFS_MOUNT_UNSHARED;
854 break; 1035 break;
855 1036
1037 /*
1038 * options that take numeric values
1039 */
856 case Opt_port: 1040 case Opt_port:
857 if (match_int(args, &option)) 1041 if (match_int(args, &option) ||
858 return 0; 1042 option < 0 || option > USHORT_MAX) {
859 if (option < 0 || option > 65535) 1043 errors++;
860 return 0; 1044 nfs_parse_invalid_value("port");
861 mnt->nfs_server.port = option; 1045 } else
1046 mnt->nfs_server.port = option;
862 break; 1047 break;
863 case Opt_rsize: 1048 case Opt_rsize:
864 if (match_int(args, &mnt->rsize)) 1049 if (match_int(args, &option) || option < 0) {
865 return 0; 1050 errors++;
1051 nfs_parse_invalid_value("rsize");
1052 } else
1053 mnt->rsize = option;
866 break; 1054 break;
867 case Opt_wsize: 1055 case Opt_wsize:
868 if (match_int(args, &mnt->wsize)) 1056 if (match_int(args, &option) || option < 0) {
869 return 0; 1057 errors++;
1058 nfs_parse_invalid_value("wsize");
1059 } else
1060 mnt->wsize = option;
870 break; 1061 break;
871 case Opt_bsize: 1062 case Opt_bsize:
872 if (match_int(args, &option)) 1063 if (match_int(args, &option) || option < 0) {
873 return 0; 1064 errors++;
874 if (option < 0) 1065 nfs_parse_invalid_value("bsize");
875 return 0; 1066 } else
876 mnt->bsize = option; 1067 mnt->bsize = option;
877 break; 1068 break;
878 case Opt_timeo: 1069 case Opt_timeo:
879 if (match_int(args, &mnt->timeo)) 1070 if (match_int(args, &option) || option <= 0) {
880 return 0; 1071 errors++;
1072 nfs_parse_invalid_value("timeo");
1073 } else
1074 mnt->timeo = option;
881 break; 1075 break;
882 case Opt_retrans: 1076 case Opt_retrans:
883 if (match_int(args, &mnt->retrans)) 1077 if (match_int(args, &option) || option <= 0) {
884 return 0; 1078 errors++;
1079 nfs_parse_invalid_value("retrans");
1080 } else
1081 mnt->retrans = option;
885 break; 1082 break;
886 case Opt_acregmin: 1083 case Opt_acregmin:
887 if (match_int(args, &mnt->acregmin)) 1084 if (match_int(args, &option) || option < 0) {
888 return 0; 1085 errors++;
1086 nfs_parse_invalid_value("acregmin");
1087 } else
1088 mnt->acregmin = option;
889 break; 1089 break;
890 case Opt_acregmax: 1090 case Opt_acregmax:
891 if (match_int(args, &mnt->acregmax)) 1091 if (match_int(args, &option) || option < 0) {
892 return 0; 1092 errors++;
1093 nfs_parse_invalid_value("acregmax");
1094 } else
1095 mnt->acregmax = option;
893 break; 1096 break;
894 case Opt_acdirmin: 1097 case Opt_acdirmin:
895 if (match_int(args, &mnt->acdirmin)) 1098 if (match_int(args, &option) || option < 0) {
896 return 0; 1099 errors++;
1100 nfs_parse_invalid_value("acdirmin");
1101 } else
1102 mnt->acdirmin = option;
897 break; 1103 break;
898 case Opt_acdirmax: 1104 case Opt_acdirmax:
899 if (match_int(args, &mnt->acdirmax)) 1105 if (match_int(args, &option) || option < 0) {
900 return 0; 1106 errors++;
1107 nfs_parse_invalid_value("acdirmax");
1108 } else
1109 mnt->acdirmax = option;
901 break; 1110 break;
902 case Opt_actimeo: 1111 case Opt_actimeo:
903 if (match_int(args, &option)) 1112 if (match_int(args, &option) || option < 0) {
904 return 0; 1113 errors++;
905 if (option < 0) 1114 nfs_parse_invalid_value("actimeo");
906 return 0; 1115 } else
907 mnt->acregmin = 1116 mnt->acregmin = mnt->acregmax =
908 mnt->acregmax = 1117 mnt->acdirmin = mnt->acdirmax = option;
909 mnt->acdirmin =
910 mnt->acdirmax = option;
911 break; 1118 break;
912 case Opt_namelen: 1119 case Opt_namelen:
913 if (match_int(args, &mnt->namlen)) 1120 if (match_int(args, &option) || option < 0) {
914 return 0; 1121 errors++;
1122 nfs_parse_invalid_value("namlen");
1123 } else
1124 mnt->namlen = option;
915 break; 1125 break;
916 case Opt_mountport: 1126 case Opt_mountport:
917 if (match_int(args, &option)) 1127 if (match_int(args, &option) ||
918 return 0; 1128 option < 0 || option > USHORT_MAX) {
919 if (option < 0 || option > 65535) 1129 errors++;
920 return 0; 1130 nfs_parse_invalid_value("mountport");
921 mnt->mount_server.port = option; 1131 } else
1132 mnt->mount_server.port = option;
922 break; 1133 break;
923 case Opt_mountvers: 1134 case Opt_mountvers:
924 if (match_int(args, &option)) 1135 if (match_int(args, &option) ||
925 return 0; 1136 option < NFS_MNT_VERSION ||
926 if (option < 0) 1137 option > NFS_MNT3_VERSION) {
927 return 0; 1138 errors++;
928 mnt->mount_server.version = option; 1139 nfs_parse_invalid_value("mountvers");
1140 } else
1141 mnt->mount_server.version = option;
929 break; 1142 break;
930 case Opt_nfsvers: 1143 case Opt_nfsvers:
931 if (match_int(args, &option)) 1144 if (match_int(args, &option)) {
932 return 0; 1145 errors++;
1146 nfs_parse_invalid_value("nfsvers");
1147 break;
1148 }
933 switch (option) { 1149 switch (option) {
934 case 2: 1150 case NFS2_VERSION:
935 mnt->flags &= ~NFS_MOUNT_VER3; 1151 mnt->flags &= ~NFS_MOUNT_VER3;
936 break; 1152 break;
937 case 3: 1153 case NFS3_VERSION:
938 mnt->flags |= NFS_MOUNT_VER3; 1154 mnt->flags |= NFS_MOUNT_VER3;
939 break; 1155 break;
940 default: 1156 default:
941 goto out_unrec_vers; 1157 errors++;
1158 nfs_parse_invalid_value("nfsvers");
942 } 1159 }
943 break; 1160 break;
944 1161
1162 /*
1163 * options that take text values
1164 */
945 case Opt_sec: 1165 case Opt_sec:
946 string = match_strdup(args); 1166 string = match_strdup(args);
947 if (string == NULL) 1167 if (string == NULL)
948 goto out_nomem; 1168 goto out_nomem;
949 token = match_token(string, nfs_secflavor_tokens, args); 1169 rc = nfs_parse_security_flavors(string, mnt);
950 kfree(string); 1170 kfree(string);
951 1171 if (!rc) {
952 /* 1172 errors++;
953 * The flags setting is for v2/v3. The flavor_len 1173 dfprintk(MOUNT, "NFS: unrecognized "
954 * setting is for v4. v2/v3 also need to know the 1174 "security flavor\n");
955 * difference between NULL and UNIX.
956 */
957 switch (token) {
958 case Opt_sec_none:
959 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
960 mnt->auth_flavor_len = 0;
961 mnt->auth_flavors[0] = RPC_AUTH_NULL;
962 break;
963 case Opt_sec_sys:
964 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
965 mnt->auth_flavor_len = 0;
966 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
967 break;
968 case Opt_sec_krb5:
969 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
970 mnt->auth_flavor_len = 1;
971 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
972 break;
973 case Opt_sec_krb5i:
974 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
975 mnt->auth_flavor_len = 1;
976 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
977 break;
978 case Opt_sec_krb5p:
979 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
980 mnt->auth_flavor_len = 1;
981 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
982 break;
983 case Opt_sec_lkey:
984 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
985 mnt->auth_flavor_len = 1;
986 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
987 break;
988 case Opt_sec_lkeyi:
989 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
990 mnt->auth_flavor_len = 1;
991 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
992 break;
993 case Opt_sec_lkeyp:
994 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
995 mnt->auth_flavor_len = 1;
996 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
997 break;
998 case Opt_sec_spkm:
999 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1000 mnt->auth_flavor_len = 1;
1001 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1002 break;
1003 case Opt_sec_spkmi:
1004 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1005 mnt->auth_flavor_len = 1;
1006 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1007 break;
1008 case Opt_sec_spkmp:
1009 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1010 mnt->auth_flavor_len = 1;
1011 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1012 break;
1013 default:
1014 goto out_unrec_sec;
1015 } 1175 }
1016 break; 1176 break;
1017 case Opt_proto: 1177 case Opt_proto:
@@ -1026,24 +1186,20 @@ static int nfs_parse_mount_options(char *raw,
1026 case Opt_xprt_udp: 1186 case Opt_xprt_udp:
1027 mnt->flags &= ~NFS_MOUNT_TCP; 1187 mnt->flags &= ~NFS_MOUNT_TCP;
1028 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP; 1188 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1029 mnt->timeo = 7;
1030 mnt->retrans = 5;
1031 break; 1189 break;
1032 case Opt_xprt_tcp: 1190 case Opt_xprt_tcp:
1033 mnt->flags |= NFS_MOUNT_TCP; 1191 mnt->flags |= NFS_MOUNT_TCP;
1034 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP; 1192 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1035 mnt->timeo = 600;
1036 mnt->retrans = 2;
1037 break; 1193 break;
1038 case Opt_xprt_rdma: 1194 case Opt_xprt_rdma:
1039 /* vector side protocols to TCP */ 1195 /* vector side protocols to TCP */
1040 mnt->flags |= NFS_MOUNT_TCP; 1196 mnt->flags |= NFS_MOUNT_TCP;
1041 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA; 1197 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1042 mnt->timeo = 600;
1043 mnt->retrans = 2;
1044 break; 1198 break;
1045 default: 1199 default:
1046 goto out_unrec_xprt; 1200 errors++;
1201 dfprintk(MOUNT, "NFS: unrecognized "
1202 "transport protocol\n");
1047 } 1203 }
1048 break; 1204 break;
1049 case Opt_mountproto: 1205 case Opt_mountproto:
@@ -1063,16 +1219,19 @@ static int nfs_parse_mount_options(char *raw,
1063 break; 1219 break;
1064 case Opt_xprt_rdma: /* not used for side protocols */ 1220 case Opt_xprt_rdma: /* not used for side protocols */
1065 default: 1221 default:
1066 goto out_unrec_xprt; 1222 errors++;
1223 dfprintk(MOUNT, "NFS: unrecognized "
1224 "transport protocol\n");
1067 } 1225 }
1068 break; 1226 break;
1069 case Opt_addr: 1227 case Opt_addr:
1070 string = match_strdup(args); 1228 string = match_strdup(args);
1071 if (string == NULL) 1229 if (string == NULL)
1072 goto out_nomem; 1230 goto out_nomem;
1073 nfs_parse_server_address(string, (struct sockaddr *) 1231 nfs_parse_ip_address(string, strlen(string),
1074 &mnt->nfs_server.address, 1232 (struct sockaddr *)
1075 &mnt->nfs_server.addrlen); 1233 &mnt->nfs_server.address,
1234 &mnt->nfs_server.addrlen);
1076 kfree(string); 1235 kfree(string);
1077 break; 1236 break;
1078 case Opt_clientaddr: 1237 case Opt_clientaddr:
@@ -1093,24 +1252,33 @@ static int nfs_parse_mount_options(char *raw,
1093 string = match_strdup(args); 1252 string = match_strdup(args);
1094 if (string == NULL) 1253 if (string == NULL)
1095 goto out_nomem; 1254 goto out_nomem;
1096 nfs_parse_server_address(string, (struct sockaddr *) 1255 nfs_parse_ip_address(string, strlen(string),
1097 &mnt->mount_server.address, 1256 (struct sockaddr *)
1098 &mnt->mount_server.addrlen); 1257 &mnt->mount_server.address,
1258 &mnt->mount_server.addrlen);
1099 kfree(string); 1259 kfree(string);
1100 break; 1260 break;
1101 1261
1262 /*
1263 * Special options
1264 */
1265 case Opt_sloppy:
1266 sloppy = 1;
1267 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1268 break;
1102 case Opt_userspace: 1269 case Opt_userspace:
1103 case Opt_deprecated: 1270 case Opt_deprecated:
1271 dfprintk(MOUNT, "NFS: ignoring mount option "
1272 "'%s'\n", p);
1104 break; 1273 break;
1105 1274
1106 default: 1275 default:
1107 goto out_unknown; 1276 errors++;
1277 dfprintk(MOUNT, "NFS: unrecognized mount option "
1278 "'%s'\n", p);
1108 } 1279 }
1109 } 1280 }
1110 1281
1111 nfs_set_port((struct sockaddr *)&mnt->nfs_server.address,
1112 mnt->nfs_server.port);
1113
1114 return 1; 1282 return 1;
1115 1283
1116out_nomem: 1284out_nomem:
@@ -1120,21 +1288,6 @@ out_security_failure:
1120 free_secdata(secdata); 1288 free_secdata(secdata);
1121 printk(KERN_INFO "NFS: security options invalid: %d\n", rc); 1289 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1122 return 0; 1290 return 0;
1123out_unrec_vers:
1124 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
1125 return 0;
1126
1127out_unrec_xprt:
1128 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
1129 return 0;
1130
1131out_unrec_sec:
1132 printk(KERN_INFO "NFS: unrecognized security flavor\n");
1133 return 0;
1134
1135out_unknown:
1136 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
1137 return 0;
1138} 1291}
1139 1292
1140/* 1293/*
@@ -1188,11 +1341,146 @@ static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1188 if (status == 0) 1341 if (status == 0)
1189 return 0; 1342 return 0;
1190 1343
1191 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d", 1344 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1192 hostname, status); 1345 hostname, status);
1193 return status; 1346 return status;
1194} 1347}
1195 1348
1349static int nfs_parse_simple_hostname(const char *dev_name,
1350 char **hostname, size_t maxnamlen,
1351 char **export_path, size_t maxpathlen)
1352{
1353 size_t len;
1354 char *colon, *comma;
1355
1356 colon = strchr(dev_name, ':');
1357 if (colon == NULL)
1358 goto out_bad_devname;
1359
1360 len = colon - dev_name;
1361 if (len > maxnamlen)
1362 goto out_hostname;
1363
1364 /* N.B. caller will free nfs_server.hostname in all cases */
1365 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1366 if (!*hostname)
1367 goto out_nomem;
1368
1369 /* kill possible hostname list: not supported */
1370 comma = strchr(*hostname, ',');
1371 if (comma != NULL) {
1372 if (comma == *hostname)
1373 goto out_bad_devname;
1374 *comma = '\0';
1375 }
1376
1377 colon++;
1378 len = strlen(colon);
1379 if (len > maxpathlen)
1380 goto out_path;
1381 *export_path = kstrndup(colon, len, GFP_KERNEL);
1382 if (!*export_path)
1383 goto out_nomem;
1384
1385 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1386 return 0;
1387
1388out_bad_devname:
1389 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1390 return -EINVAL;
1391
1392out_nomem:
1393 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1394 return -ENOMEM;
1395
1396out_hostname:
1397 dfprintk(MOUNT, "NFS: server hostname too long\n");
1398 return -ENAMETOOLONG;
1399
1400out_path:
1401 dfprintk(MOUNT, "NFS: export pathname too long\n");
1402 return -ENAMETOOLONG;
1403}
1404
1405/*
1406 * Hostname has square brackets around it because it contains one or
1407 * more colons. We look for the first closing square bracket, and a
1408 * colon must follow it.
1409 */
1410static int nfs_parse_protected_hostname(const char *dev_name,
1411 char **hostname, size_t maxnamlen,
1412 char **export_path, size_t maxpathlen)
1413{
1414 size_t len;
1415 char *start, *end;
1416
1417 start = (char *)(dev_name + 1);
1418
1419 end = strchr(start, ']');
1420 if (end == NULL)
1421 goto out_bad_devname;
1422 if (*(end + 1) != ':')
1423 goto out_bad_devname;
1424
1425 len = end - start;
1426 if (len > maxnamlen)
1427 goto out_hostname;
1428
1429 /* N.B. caller will free nfs_server.hostname in all cases */
1430 *hostname = kstrndup(start, len, GFP_KERNEL);
1431 if (*hostname == NULL)
1432 goto out_nomem;
1433
1434 end += 2;
1435 len = strlen(end);
1436 if (len > maxpathlen)
1437 goto out_path;
1438 *export_path = kstrndup(end, len, GFP_KERNEL);
1439 if (!*export_path)
1440 goto out_nomem;
1441
1442 return 0;
1443
1444out_bad_devname:
1445 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1446 return -EINVAL;
1447
1448out_nomem:
1449 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1450 return -ENOMEM;
1451
1452out_hostname:
1453 dfprintk(MOUNT, "NFS: server hostname too long\n");
1454 return -ENAMETOOLONG;
1455
1456out_path:
1457 dfprintk(MOUNT, "NFS: export pathname too long\n");
1458 return -ENAMETOOLONG;
1459}
1460
1461/*
1462 * Split "dev_name" into "hostname:export_path".
1463 *
1464 * The leftmost colon demarks the split between the server's hostname
1465 * and the export path. If the hostname starts with a left square
1466 * bracket, then it may contain colons.
1467 *
1468 * Note: caller frees hostname and export path, even on error.
1469 */
1470static int nfs_parse_devname(const char *dev_name,
1471 char **hostname, size_t maxnamlen,
1472 char **export_path, size_t maxpathlen)
1473{
1474 if (*dev_name == '[')
1475 return nfs_parse_protected_hostname(dev_name,
1476 hostname, maxnamlen,
1477 export_path, maxpathlen);
1478
1479 return nfs_parse_simple_hostname(dev_name,
1480 hostname, maxnamlen,
1481 export_path, maxpathlen);
1482}
1483
1196/* 1484/*
1197 * Validate the NFS2/NFS3 mount data 1485 * Validate the NFS2/NFS3 mount data
1198 * - fills in the mount root filehandle 1486 * - fills in the mount root filehandle
@@ -1222,16 +1510,14 @@ static int nfs_validate_mount_data(void *options,
1222 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP); 1510 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1223 args->rsize = NFS_MAX_FILE_IO_SIZE; 1511 args->rsize = NFS_MAX_FILE_IO_SIZE;
1224 args->wsize = NFS_MAX_FILE_IO_SIZE; 1512 args->wsize = NFS_MAX_FILE_IO_SIZE;
1225 args->timeo = 600; 1513 args->acregmin = NFS_DEF_ACREGMIN;
1226 args->retrans = 2; 1514 args->acregmax = NFS_DEF_ACREGMAX;
1227 args->acregmin = 3; 1515 args->acdirmin = NFS_DEF_ACDIRMIN;
1228 args->acregmax = 60; 1516 args->acdirmax = NFS_DEF_ACDIRMAX;
1229 args->acdirmin = 30;
1230 args->acdirmax = 60;
1231 args->mount_server.port = 0; /* autobind unless user sets port */ 1517 args->mount_server.port = 0; /* autobind unless user sets port */
1232 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
1233 args->nfs_server.port = 0; /* autobind unless user sets port */ 1518 args->nfs_server.port = 0; /* autobind unless user sets port */
1234 args->nfs_server.protocol = XPRT_TRANSPORT_TCP; 1519 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1520 args->auth_flavors[0] = RPC_AUTH_UNIX;
1235 1521
1236 switch (data->version) { 1522 switch (data->version) {
1237 case 1: 1523 case 1:
@@ -1289,7 +1575,9 @@ static int nfs_validate_mount_data(void *options,
1289 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL); 1575 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1290 args->namlen = data->namlen; 1576 args->namlen = data->namlen;
1291 args->bsize = data->bsize; 1577 args->bsize = data->bsize;
1292 args->auth_flavors[0] = data->pseudoflavor; 1578
1579 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1580 args->auth_flavors[0] = data->pseudoflavor;
1293 if (!args->nfs_server.hostname) 1581 if (!args->nfs_server.hostname)
1294 goto out_nomem; 1582 goto out_nomem;
1295 1583
@@ -1321,8 +1609,6 @@ static int nfs_validate_mount_data(void *options,
1321 1609
1322 break; 1610 break;
1323 default: { 1611 default: {
1324 unsigned int len;
1325 char *c;
1326 int status; 1612 int status;
1327 1613
1328 if (nfs_parse_mount_options((char *)options, args) == 0) 1614 if (nfs_parse_mount_options((char *)options, args) == 0)
@@ -1332,21 +1618,22 @@ static int nfs_validate_mount_data(void *options,
1332 &args->nfs_server.address)) 1618 &args->nfs_server.address))
1333 goto out_no_address; 1619 goto out_no_address;
1334 1620
1335 c = strchr(dev_name, ':'); 1621 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
1336 if (c == NULL) 1622 args->nfs_server.port);
1337 return -EINVAL;
1338 len = c - dev_name;
1339 /* N.B. caller will free nfs_server.hostname in all cases */
1340 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
1341 if (!args->nfs_server.hostname)
1342 goto out_nomem;
1343 1623
1344 c++; 1624 nfs_set_mount_transport_protocol(args);
1345 if (strlen(c) > NFS_MAXPATHLEN) 1625
1346 return -ENAMETOOLONG; 1626 status = nfs_parse_devname(dev_name,
1347 args->nfs_server.export_path = c; 1627 &args->nfs_server.hostname,
1628 PAGE_SIZE,
1629 &args->nfs_server.export_path,
1630 NFS_MAXPATHLEN);
1631 if (!status)
1632 status = nfs_try_mount(args, mntfh);
1633
1634 kfree(args->nfs_server.export_path);
1635 args->nfs_server.export_path = NULL;
1348 1636
1349 status = nfs_try_mount(args, mntfh);
1350 if (status) 1637 if (status)
1351 return status; 1638 return status;
1352 1639
@@ -1354,9 +1641,6 @@ static int nfs_validate_mount_data(void *options,
1354 } 1641 }
1355 } 1642 }
1356 1643
1357 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1358 args->auth_flavors[0] = RPC_AUTH_UNIX;
1359
1360#ifndef CONFIG_NFS_V3 1644#ifndef CONFIG_NFS_V3
1361 if (args->flags & NFS_MOUNT_VER3) 1645 if (args->flags & NFS_MOUNT_VER3)
1362 goto out_v3_not_compiled; 1646 goto out_v3_not_compiled;
@@ -1396,6 +1680,80 @@ out_invalid_fh:
1396 return -EINVAL; 1680 return -EINVAL;
1397} 1681}
1398 1682
1683static int
1684nfs_compare_remount_data(struct nfs_server *nfss,
1685 struct nfs_parsed_mount_data *data)
1686{
1687 if (data->flags != nfss->flags ||
1688 data->rsize != nfss->rsize ||
1689 data->wsize != nfss->wsize ||
1690 data->retrans != nfss->client->cl_timeout->to_retries ||
1691 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1692 data->acregmin != nfss->acregmin / HZ ||
1693 data->acregmax != nfss->acregmax / HZ ||
1694 data->acdirmin != nfss->acdirmin / HZ ||
1695 data->acdirmax != nfss->acdirmax / HZ ||
1696 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1697 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1698 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1699 data->nfs_server.addrlen) != 0)
1700 return -EINVAL;
1701
1702 return 0;
1703}
1704
1705static int
1706nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1707{
1708 int error;
1709 struct nfs_server *nfss = sb->s_fs_info;
1710 struct nfs_parsed_mount_data *data;
1711 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1712 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
1713 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
1714
1715 /*
1716 * Userspace mount programs that send binary options generally send
1717 * them populated with default values. We have no way to know which
1718 * ones were explicitly specified. Fall back to legacy behavior and
1719 * just return success.
1720 */
1721 if ((nfsvers == 4 && options4->version == 1) ||
1722 (nfsvers <= 3 && options->version >= 1 &&
1723 options->version <= 6))
1724 return 0;
1725
1726 data = kzalloc(sizeof(*data), GFP_KERNEL);
1727 if (data == NULL)
1728 return -ENOMEM;
1729
1730 /* fill out struct with values from existing mount */
1731 data->flags = nfss->flags;
1732 data->rsize = nfss->rsize;
1733 data->wsize = nfss->wsize;
1734 data->retrans = nfss->client->cl_timeout->to_retries;
1735 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1736 data->acregmin = nfss->acregmin / HZ;
1737 data->acregmax = nfss->acregmax / HZ;
1738 data->acdirmin = nfss->acdirmin / HZ;
1739 data->acdirmax = nfss->acdirmax / HZ;
1740 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1741 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1742 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1743 data->nfs_server.addrlen);
1744
1745 /* overwrite those values with any that were specified */
1746 error = nfs_parse_mount_options((char *)options, data);
1747 if (error < 0)
1748 goto out;
1749
1750 /* compare new mount options with old ones */
1751 error = nfs_compare_remount_data(nfss, data);
1752out:
1753 kfree(data);
1754 return error;
1755}
1756
1399/* 1757/*
1400 * Initialise the common bits of the superblock 1758 * Initialise the common bits of the superblock
1401 */ 1759 */
@@ -1811,14 +2169,13 @@ static int nfs4_validate_mount_data(void *options,
1811 2169
1812 args->rsize = NFS_MAX_FILE_IO_SIZE; 2170 args->rsize = NFS_MAX_FILE_IO_SIZE;
1813 args->wsize = NFS_MAX_FILE_IO_SIZE; 2171 args->wsize = NFS_MAX_FILE_IO_SIZE;
1814 args->timeo = 600; 2172 args->acregmin = NFS_DEF_ACREGMIN;
1815 args->retrans = 2; 2173 args->acregmax = NFS_DEF_ACREGMAX;
1816 args->acregmin = 3; 2174 args->acdirmin = NFS_DEF_ACDIRMIN;
1817 args->acregmax = 60; 2175 args->acdirmax = NFS_DEF_ACDIRMAX;
1818 args->acdirmin = 30;
1819 args->acdirmax = 60;
1820 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */ 2176 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
1821 args->nfs_server.protocol = XPRT_TRANSPORT_TCP; 2177 args->auth_flavors[0] = RPC_AUTH_UNIX;
2178 args->auth_flavor_len = 0;
1822 2179
1823 switch (data->version) { 2180 switch (data->version) {
1824 case 1: 2181 case 1:
@@ -1834,18 +2191,13 @@ static int nfs4_validate_mount_data(void *options,
1834 &args->nfs_server.address)) 2191 &args->nfs_server.address))
1835 goto out_no_address; 2192 goto out_no_address;
1836 2193
1837 switch (data->auth_flavourlen) { 2194 if (data->auth_flavourlen) {
1838 case 0: 2195 if (data->auth_flavourlen > 1)
1839 args->auth_flavors[0] = RPC_AUTH_UNIX; 2196 goto out_inval_auth;
1840 break;
1841 case 1:
1842 if (copy_from_user(&args->auth_flavors[0], 2197 if (copy_from_user(&args->auth_flavors[0],
1843 data->auth_flavours, 2198 data->auth_flavours,
1844 sizeof(args->auth_flavors[0]))) 2199 sizeof(args->auth_flavors[0])))
1845 return -EFAULT; 2200 return -EFAULT;
1846 break;
1847 default:
1848 goto out_inval_auth;
1849 } 2201 }
1850 2202
1851 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN); 2203 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
@@ -1879,10 +2231,11 @@ static int nfs4_validate_mount_data(void *options,
1879 args->acdirmin = data->acdirmin; 2231 args->acdirmin = data->acdirmin;
1880 args->acdirmax = data->acdirmax; 2232 args->acdirmax = data->acdirmax;
1881 args->nfs_server.protocol = data->proto; 2233 args->nfs_server.protocol = data->proto;
2234 nfs_validate_transport_protocol(args);
1882 2235
1883 break; 2236 break;
1884 default: { 2237 default: {
1885 unsigned int len; 2238 int status;
1886 2239
1887 if (nfs_parse_mount_options((char *)options, args) == 0) 2240 if (nfs_parse_mount_options((char *)options, args) == 0)
1888 return -EINVAL; 2241 return -EINVAL;
@@ -1891,44 +2244,25 @@ static int nfs4_validate_mount_data(void *options,
1891 &args->nfs_server.address)) 2244 &args->nfs_server.address))
1892 return -EINVAL; 2245 return -EINVAL;
1893 2246
1894 switch (args->auth_flavor_len) { 2247 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
1895 case 0: 2248 args->nfs_server.port);
1896 args->auth_flavors[0] = RPC_AUTH_UNIX;
1897 break;
1898 case 1:
1899 break;
1900 default:
1901 goto out_inval_auth;
1902 }
1903 2249
1904 /* 2250 nfs_validate_transport_protocol(args);
1905 * Split "dev_name" into "hostname:mntpath".
1906 */
1907 c = strchr(dev_name, ':');
1908 if (c == NULL)
1909 return -EINVAL;
1910 /* while calculating len, pretend ':' is '\0' */
1911 len = c - dev_name;
1912 if (len > NFS4_MAXNAMLEN)
1913 return -ENAMETOOLONG;
1914 /* N.B. caller will free nfs_server.hostname in all cases */
1915 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
1916 if (!args->nfs_server.hostname)
1917 goto out_nomem;
1918
1919 c++; /* step over the ':' */
1920 len = strlen(c);
1921 if (len > NFS4_MAXPATHLEN)
1922 return -ENAMETOOLONG;
1923 args->nfs_server.export_path = kstrndup(c, len, GFP_KERNEL);
1924 if (!args->nfs_server.export_path)
1925 goto out_nomem;
1926 2251
1927 dprintk("NFS: MNTPATH: '%s'\n", args->nfs_server.export_path); 2252 if (args->auth_flavor_len > 1)
2253 goto out_inval_auth;
1928 2254
1929 if (args->client_address == NULL) 2255 if (args->client_address == NULL)
1930 goto out_no_client_address; 2256 goto out_no_client_address;
1931 2257
2258 status = nfs_parse_devname(dev_name,
2259 &args->nfs_server.hostname,
2260 NFS4_MAXNAMLEN,
2261 &args->nfs_server.export_path,
2262 NFS4_MAXPATHLEN);
2263 if (status < 0)
2264 return status;
2265
1932 break; 2266 break;
1933 } 2267 }
1934 } 2268 }
@@ -1944,10 +2278,6 @@ out_inval_auth:
1944 data->auth_flavourlen); 2278 data->auth_flavourlen);
1945 return -EINVAL; 2279 return -EINVAL;
1946 2280
1947out_nomem:
1948 dfprintk(MOUNT, "NFS4: not enough memory to handle mount options\n");
1949 return -ENOMEM;
1950
1951out_no_address: 2281out_no_address:
1952 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n"); 2282 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1953 return -EINVAL; 2283 return -EINVAL;
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index f333848fd3be..3229e217c773 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -34,9 +34,6 @@
34/* 34/*
35 * Local function declarations 35 * Local function declarations
36 */ 36 */
37static struct nfs_page * nfs_update_request(struct nfs_open_context*,
38 struct page *,
39 unsigned int, unsigned int);
40static void nfs_pageio_init_write(struct nfs_pageio_descriptor *desc, 37static void nfs_pageio_init_write(struct nfs_pageio_descriptor *desc,
41 struct inode *inode, int ioflags); 38 struct inode *inode, int ioflags);
42static void nfs_redirty_request(struct nfs_page *req); 39static void nfs_redirty_request(struct nfs_page *req);
@@ -136,16 +133,21 @@ static struct nfs_page *nfs_page_find_request(struct page *page)
136static void nfs_grow_file(struct page *page, unsigned int offset, unsigned int count) 133static void nfs_grow_file(struct page *page, unsigned int offset, unsigned int count)
137{ 134{
138 struct inode *inode = page->mapping->host; 135 struct inode *inode = page->mapping->host;
139 loff_t end, i_size = i_size_read(inode); 136 loff_t end, i_size;
140 pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT; 137 pgoff_t end_index;
141 138
139 spin_lock(&inode->i_lock);
140 i_size = i_size_read(inode);
141 end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
142 if (i_size > 0 && page->index < end_index) 142 if (i_size > 0 && page->index < end_index)
143 return; 143 goto out;
144 end = ((loff_t)page->index << PAGE_CACHE_SHIFT) + ((loff_t)offset+count); 144 end = ((loff_t)page->index << PAGE_CACHE_SHIFT) + ((loff_t)offset+count);
145 if (i_size >= end) 145 if (i_size >= end)
146 return; 146 goto out;
147 nfs_inc_stats(inode, NFSIOS_EXTENDWRITE);
148 i_size_write(inode, end); 147 i_size_write(inode, end);
148 nfs_inc_stats(inode, NFSIOS_EXTENDWRITE);
149out:
150 spin_unlock(&inode->i_lock);
149} 151}
150 152
151/* A writeback failed: mark the page as bad, and invalidate the page cache */ 153/* A writeback failed: mark the page as bad, and invalidate the page cache */
@@ -169,29 +171,6 @@ static void nfs_mark_uptodate(struct page *page, unsigned int base, unsigned int
169 SetPageUptodate(page); 171 SetPageUptodate(page);
170} 172}
171 173
172static int nfs_writepage_setup(struct nfs_open_context *ctx, struct page *page,
173 unsigned int offset, unsigned int count)
174{
175 struct nfs_page *req;
176 int ret;
177
178 for (;;) {
179 req = nfs_update_request(ctx, page, offset, count);
180 if (!IS_ERR(req))
181 break;
182 ret = PTR_ERR(req);
183 if (ret != -EBUSY)
184 return ret;
185 ret = nfs_wb_page(page->mapping->host, page);
186 if (ret != 0)
187 return ret;
188 }
189 /* Update file length */
190 nfs_grow_file(page, offset, count);
191 nfs_clear_page_tag_locked(req);
192 return 0;
193}
194
195static int wb_priority(struct writeback_control *wbc) 174static int wb_priority(struct writeback_control *wbc)
196{ 175{
197 if (wbc->for_reclaim) 176 if (wbc->for_reclaim)
@@ -268,12 +247,9 @@ static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio,
268 return ret; 247 return ret;
269 spin_lock(&inode->i_lock); 248 spin_lock(&inode->i_lock);
270 } 249 }
271 if (test_bit(PG_NEED_COMMIT, &req->wb_flags)) { 250 if (test_bit(PG_CLEAN, &req->wb_flags)) {
272 /* This request is marked for commit */
273 spin_unlock(&inode->i_lock); 251 spin_unlock(&inode->i_lock);
274 nfs_clear_page_tag_locked(req); 252 BUG();
275 nfs_pageio_complete(pgio);
276 return 0;
277 } 253 }
278 if (nfs_set_page_writeback(page) != 0) { 254 if (nfs_set_page_writeback(page) != 0) {
279 spin_unlock(&inode->i_lock); 255 spin_unlock(&inode->i_lock);
@@ -355,11 +331,19 @@ int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc)
355/* 331/*
356 * Insert a write request into an inode 332 * Insert a write request into an inode
357 */ 333 */
358static void nfs_inode_add_request(struct inode *inode, struct nfs_page *req) 334static int nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
359{ 335{
360 struct nfs_inode *nfsi = NFS_I(inode); 336 struct nfs_inode *nfsi = NFS_I(inode);
361 int error; 337 int error;
362 338
339 error = radix_tree_preload(GFP_NOFS);
340 if (error != 0)
341 goto out;
342
343 /* Lock the request! */
344 nfs_lock_request_dontget(req);
345
346 spin_lock(&inode->i_lock);
363 error = radix_tree_insert(&nfsi->nfs_page_tree, req->wb_index, req); 347 error = radix_tree_insert(&nfsi->nfs_page_tree, req->wb_index, req);
364 BUG_ON(error); 348 BUG_ON(error);
365 if (!nfsi->npages) { 349 if (!nfsi->npages) {
@@ -373,6 +357,10 @@ static void nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
373 kref_get(&req->wb_kref); 357 kref_get(&req->wb_kref);
374 radix_tree_tag_set(&nfsi->nfs_page_tree, req->wb_index, 358 radix_tree_tag_set(&nfsi->nfs_page_tree, req->wb_index,
375 NFS_PAGE_TAG_LOCKED); 359 NFS_PAGE_TAG_LOCKED);
360 spin_unlock(&inode->i_lock);
361 radix_tree_preload_end();
362out:
363 return error;
376} 364}
377 365
378/* 366/*
@@ -405,19 +393,6 @@ nfs_mark_request_dirty(struct nfs_page *req)
405 __set_page_dirty_nobuffers(req->wb_page); 393 __set_page_dirty_nobuffers(req->wb_page);
406} 394}
407 395
408/*
409 * Check if a request is dirty
410 */
411static inline int
412nfs_dirty_request(struct nfs_page *req)
413{
414 struct page *page = req->wb_page;
415
416 if (page == NULL || test_bit(PG_NEED_COMMIT, &req->wb_flags))
417 return 0;
418 return !PageWriteback(page);
419}
420
421#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) 396#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
422/* 397/*
423 * Add a request to the inode's commit list. 398 * Add a request to the inode's commit list.
@@ -430,7 +405,7 @@ nfs_mark_request_commit(struct nfs_page *req)
430 405
431 spin_lock(&inode->i_lock); 406 spin_lock(&inode->i_lock);
432 nfsi->ncommit++; 407 nfsi->ncommit++;
433 set_bit(PG_NEED_COMMIT, &(req)->wb_flags); 408 set_bit(PG_CLEAN, &(req)->wb_flags);
434 radix_tree_tag_set(&nfsi->nfs_page_tree, 409 radix_tree_tag_set(&nfsi->nfs_page_tree,
435 req->wb_index, 410 req->wb_index,
436 NFS_PAGE_TAG_COMMIT); 411 NFS_PAGE_TAG_COMMIT);
@@ -440,6 +415,19 @@ nfs_mark_request_commit(struct nfs_page *req)
440 __mark_inode_dirty(inode, I_DIRTY_DATASYNC); 415 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
441} 416}
442 417
418static int
419nfs_clear_request_commit(struct nfs_page *req)
420{
421 struct page *page = req->wb_page;
422
423 if (test_and_clear_bit(PG_CLEAN, &(req)->wb_flags)) {
424 dec_zone_page_state(page, NR_UNSTABLE_NFS);
425 dec_bdi_stat(page->mapping->backing_dev_info, BDI_RECLAIMABLE);
426 return 1;
427 }
428 return 0;
429}
430
443static inline 431static inline
444int nfs_write_need_commit(struct nfs_write_data *data) 432int nfs_write_need_commit(struct nfs_write_data *data)
445{ 433{
@@ -449,7 +437,7 @@ int nfs_write_need_commit(struct nfs_write_data *data)
449static inline 437static inline
450int nfs_reschedule_unstable_write(struct nfs_page *req) 438int nfs_reschedule_unstable_write(struct nfs_page *req)
451{ 439{
452 if (test_bit(PG_NEED_COMMIT, &req->wb_flags)) { 440 if (test_and_clear_bit(PG_NEED_COMMIT, &req->wb_flags)) {
453 nfs_mark_request_commit(req); 441 nfs_mark_request_commit(req);
454 return 1; 442 return 1;
455 } 443 }
@@ -465,6 +453,12 @@ nfs_mark_request_commit(struct nfs_page *req)
465{ 453{
466} 454}
467 455
456static inline int
457nfs_clear_request_commit(struct nfs_page *req)
458{
459 return 0;
460}
461
468static inline 462static inline
469int nfs_write_need_commit(struct nfs_write_data *data) 463int nfs_write_need_commit(struct nfs_write_data *data)
470{ 464{
@@ -522,11 +516,8 @@ static void nfs_cancel_commit_list(struct list_head *head)
522 516
523 while(!list_empty(head)) { 517 while(!list_empty(head)) {
524 req = nfs_list_entry(head->next); 518 req = nfs_list_entry(head->next);
525 dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
526 dec_bdi_stat(req->wb_page->mapping->backing_dev_info,
527 BDI_RECLAIMABLE);
528 nfs_list_remove_request(req); 519 nfs_list_remove_request(req);
529 clear_bit(PG_NEED_COMMIT, &(req)->wb_flags); 520 nfs_clear_request_commit(req);
530 nfs_inode_remove_request(req); 521 nfs_inode_remove_request(req);
531 nfs_unlock_request(req); 522 nfs_unlock_request(req);
532 } 523 }
@@ -564,110 +555,124 @@ static inline int nfs_scan_commit(struct inode *inode, struct list_head *dst, pg
564#endif 555#endif
565 556
566/* 557/*
567 * Try to update any existing write request, or create one if there is none. 558 * Search for an existing write request, and attempt to update
568 * In order to match, the request's credentials must match those of 559 * it to reflect a new dirty region on a given page.
569 * the calling process.
570 * 560 *
571 * Note: Should always be called with the Page Lock held! 561 * If the attempt fails, then the existing request is flushed out
562 * to disk.
572 */ 563 */
573static struct nfs_page * nfs_update_request(struct nfs_open_context* ctx, 564static struct nfs_page *nfs_try_to_update_request(struct inode *inode,
574 struct page *page, unsigned int offset, unsigned int bytes) 565 struct page *page,
566 unsigned int offset,
567 unsigned int bytes)
575{ 568{
576 struct address_space *mapping = page->mapping; 569 struct nfs_page *req;
577 struct inode *inode = mapping->host; 570 unsigned int rqend;
578 struct nfs_page *req, *new = NULL; 571 unsigned int end;
579 pgoff_t rqend, end; 572 int error;
573
574 if (!PagePrivate(page))
575 return NULL;
580 576
581 end = offset + bytes; 577 end = offset + bytes;
578 spin_lock(&inode->i_lock);
582 579
583 for (;;) { 580 for (;;) {
584 /* Loop over all inode entries and see if we find 581 req = nfs_page_find_request_locked(page);
585 * A request for the page we wish to update 582 if (req == NULL)
583 goto out_unlock;
584
585 rqend = req->wb_offset + req->wb_bytes;
586 /*
587 * Tell the caller to flush out the request if
588 * the offsets are non-contiguous.
589 * Note: nfs_flush_incompatible() will already
590 * have flushed out requests having wrong owners.
586 */ 591 */
587 if (new) { 592 if (offset > rqend
588 if (radix_tree_preload(GFP_NOFS)) { 593 || end < req->wb_offset)
589 nfs_release_request(new); 594 goto out_flushme;
590 return ERR_PTR(-ENOMEM);
591 }
592 }
593 595
594 spin_lock(&inode->i_lock); 596 if (nfs_set_page_tag_locked(req))
595 req = nfs_page_find_request_locked(page);
596 if (req) {
597 if (!nfs_set_page_tag_locked(req)) {
598 int error;
599
600 spin_unlock(&inode->i_lock);
601 error = nfs_wait_on_request(req);
602 nfs_release_request(req);
603 if (error < 0) {
604 if (new) {
605 radix_tree_preload_end();
606 nfs_release_request(new);
607 }
608 return ERR_PTR(error);
609 }
610 continue;
611 }
612 spin_unlock(&inode->i_lock);
613 if (new) {
614 radix_tree_preload_end();
615 nfs_release_request(new);
616 }
617 break; 597 break;
618 }
619 598
620 if (new) { 599 /* The request is locked, so wait and then retry */
621 nfs_lock_request_dontget(new);
622 nfs_inode_add_request(inode, new);
623 spin_unlock(&inode->i_lock);
624 radix_tree_preload_end();
625 req = new;
626 goto zero_page;
627 }
628 spin_unlock(&inode->i_lock); 600 spin_unlock(&inode->i_lock);
629 601 error = nfs_wait_on_request(req);
630 new = nfs_create_request(ctx, inode, page, offset, bytes); 602 nfs_release_request(req);
631 if (IS_ERR(new)) 603 if (error != 0)
632 return new; 604 goto out_err;
605 spin_lock(&inode->i_lock);
633 } 606 }
634 607
635 /* We have a request for our page. 608 if (nfs_clear_request_commit(req))
636 * If the creds don't match, or the 609 radix_tree_tag_clear(&NFS_I(inode)->nfs_page_tree,
637 * page addresses don't match, 610 req->wb_index, NFS_PAGE_TAG_COMMIT);
638 * tell the caller to wait on the conflicting
639 * request.
640 */
641 rqend = req->wb_offset + req->wb_bytes;
642 if (req->wb_context != ctx
643 || req->wb_page != page
644 || !nfs_dirty_request(req)
645 || offset > rqend || end < req->wb_offset) {
646 nfs_clear_page_tag_locked(req);
647 return ERR_PTR(-EBUSY);
648 }
649 611
650 /* Okay, the request matches. Update the region */ 612 /* Okay, the request matches. Update the region */
651 if (offset < req->wb_offset) { 613 if (offset < req->wb_offset) {
652 req->wb_offset = offset; 614 req->wb_offset = offset;
653 req->wb_pgbase = offset; 615 req->wb_pgbase = offset;
654 req->wb_bytes = max(end, rqend) - req->wb_offset;
655 goto zero_page;
656 } 616 }
657
658 if (end > rqend) 617 if (end > rqend)
659 req->wb_bytes = end - req->wb_offset; 618 req->wb_bytes = end - req->wb_offset;
660 619 else
620 req->wb_bytes = rqend - req->wb_offset;
621out_unlock:
622 spin_unlock(&inode->i_lock);
661 return req; 623 return req;
662zero_page: 624out_flushme:
663 /* If this page might potentially be marked as up to date, 625 spin_unlock(&inode->i_lock);
664 * then we need to zero any uninitalised data. */ 626 nfs_release_request(req);
665 if (req->wb_pgbase == 0 && req->wb_bytes != PAGE_CACHE_SIZE 627 error = nfs_wb_page(inode, page);
666 && !PageUptodate(req->wb_page)) 628out_err:
667 zero_user_segment(req->wb_page, req->wb_bytes, PAGE_CACHE_SIZE); 629 return ERR_PTR(error);
630}
631
632/*
633 * Try to update an existing write request, or create one if there is none.
634 *
635 * Note: Should always be called with the Page Lock held to prevent races
636 * if we have to add a new request. Also assumes that the caller has
637 * already called nfs_flush_incompatible() if necessary.
638 */
639static struct nfs_page * nfs_setup_write_request(struct nfs_open_context* ctx,
640 struct page *page, unsigned int offset, unsigned int bytes)
641{
642 struct inode *inode = page->mapping->host;
643 struct nfs_page *req;
644 int error;
645
646 req = nfs_try_to_update_request(inode, page, offset, bytes);
647 if (req != NULL)
648 goto out;
649 req = nfs_create_request(ctx, inode, page, offset, bytes);
650 if (IS_ERR(req))
651 goto out;
652 error = nfs_inode_add_request(inode, req);
653 if (error != 0) {
654 nfs_release_request(req);
655 req = ERR_PTR(error);
656 }
657out:
668 return req; 658 return req;
669} 659}
670 660
661static int nfs_writepage_setup(struct nfs_open_context *ctx, struct page *page,
662 unsigned int offset, unsigned int count)
663{
664 struct nfs_page *req;
665
666 req = nfs_setup_write_request(ctx, page, offset, count);
667 if (IS_ERR(req))
668 return PTR_ERR(req);
669 /* Update file length */
670 nfs_grow_file(page, offset, count);
671 nfs_mark_uptodate(page, req->wb_pgbase, req->wb_bytes);
672 nfs_clear_page_tag_locked(req);
673 return 0;
674}
675
671int nfs_flush_incompatible(struct file *file, struct page *page) 676int nfs_flush_incompatible(struct file *file, struct page *page)
672{ 677{
673 struct nfs_open_context *ctx = nfs_file_open_context(file); 678 struct nfs_open_context *ctx = nfs_file_open_context(file);
@@ -685,8 +690,7 @@ int nfs_flush_incompatible(struct file *file, struct page *page)
685 req = nfs_page_find_request(page); 690 req = nfs_page_find_request(page);
686 if (req == NULL) 691 if (req == NULL)
687 return 0; 692 return 0;
688 do_flush = req->wb_page != page || req->wb_context != ctx 693 do_flush = req->wb_page != page || req->wb_context != ctx;
689 || !nfs_dirty_request(req);
690 nfs_release_request(req); 694 nfs_release_request(req);
691 if (!do_flush) 695 if (!do_flush)
692 return 0; 696 return 0;
@@ -721,10 +725,10 @@ int nfs_updatepage(struct file *file, struct page *page,
721 725
722 nfs_inc_stats(inode, NFSIOS_VFSUPDATEPAGE); 726 nfs_inc_stats(inode, NFSIOS_VFSUPDATEPAGE);
723 727
724 dprintk("NFS: nfs_updatepage(%s/%s %d@%Ld)\n", 728 dprintk("NFS: nfs_updatepage(%s/%s %d@%lld)\n",
725 file->f_path.dentry->d_parent->d_name.name, 729 file->f_path.dentry->d_parent->d_name.name,
726 file->f_path.dentry->d_name.name, count, 730 file->f_path.dentry->d_name.name, count,
727 (long long)(page_offset(page) +offset)); 731 (long long)(page_offset(page) + offset));
728 732
729 /* If we're not using byte range locks, and we know the page 733 /* If we're not using byte range locks, and we know the page
730 * is up to date, it may be more efficient to extend the write 734 * is up to date, it may be more efficient to extend the write
@@ -744,7 +748,7 @@ int nfs_updatepage(struct file *file, struct page *page,
744 else 748 else
745 __set_page_dirty_nobuffers(page); 749 __set_page_dirty_nobuffers(page);
746 750
747 dprintk("NFS: nfs_updatepage returns %d (isize %Ld)\n", 751 dprintk("NFS: nfs_updatepage returns %d (isize %lld)\n",
748 status, (long long)i_size_read(inode)); 752 status, (long long)i_size_read(inode));
749 return status; 753 return status;
750} 754}
@@ -752,12 +756,7 @@ int nfs_updatepage(struct file *file, struct page *page,
752static void nfs_writepage_release(struct nfs_page *req) 756static void nfs_writepage_release(struct nfs_page *req)
753{ 757{
754 758
755 if (PageError(req->wb_page)) { 759 if (PageError(req->wb_page) || !nfs_reschedule_unstable_write(req)) {
756 nfs_end_page_writeback(req->wb_page);
757 nfs_inode_remove_request(req);
758 } else if (!nfs_reschedule_unstable_write(req)) {
759 /* Set the PG_uptodate flag */
760 nfs_mark_uptodate(req->wb_page, req->wb_pgbase, req->wb_bytes);
761 nfs_end_page_writeback(req->wb_page); 760 nfs_end_page_writeback(req->wb_page);
762 nfs_inode_remove_request(req); 761 nfs_inode_remove_request(req);
763 } else 762 } else
@@ -834,7 +833,7 @@ static int nfs_write_rpcsetup(struct nfs_page *req,
834 NFS_PROTO(inode)->write_setup(data, &msg); 833 NFS_PROTO(inode)->write_setup(data, &msg);
835 834
836 dprintk("NFS: %5u initiated write call " 835 dprintk("NFS: %5u initiated write call "
837 "(req %s/%Ld, %u bytes @ offset %Lu)\n", 836 "(req %s/%lld, %u bytes @ offset %llu)\n",
838 data->task.tk_pid, 837 data->task.tk_pid,
839 inode->i_sb->s_id, 838 inode->i_sb->s_id,
840 (long long)NFS_FILEID(inode), 839 (long long)NFS_FILEID(inode),
@@ -978,13 +977,13 @@ static void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
978static void nfs_writeback_done_partial(struct rpc_task *task, void *calldata) 977static void nfs_writeback_done_partial(struct rpc_task *task, void *calldata)
979{ 978{
980 struct nfs_write_data *data = calldata; 979 struct nfs_write_data *data = calldata;
981 struct nfs_page *req = data->req;
982 980
983 dprintk("NFS: write (%s/%Ld %d@%Ld)", 981 dprintk("NFS: %5u write(%s/%lld %d@%lld)",
984 req->wb_context->path.dentry->d_inode->i_sb->s_id, 982 task->tk_pid,
985 (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode), 983 data->req->wb_context->path.dentry->d_inode->i_sb->s_id,
986 req->wb_bytes, 984 (long long)
987 (long long)req_offset(req)); 985 NFS_FILEID(data->req->wb_context->path.dentry->d_inode),
986 data->req->wb_bytes, (long long)req_offset(data->req));
988 987
989 nfs_writeback_done(task, data); 988 nfs_writeback_done(task, data);
990} 989}
@@ -1058,7 +1057,8 @@ static void nfs_writeback_release_full(void *calldata)
1058 1057
1059 nfs_list_remove_request(req); 1058 nfs_list_remove_request(req);
1060 1059
1061 dprintk("NFS: write (%s/%Ld %d@%Ld)", 1060 dprintk("NFS: %5u write (%s/%lld %d@%lld)",
1061 data->task.tk_pid,
1062 req->wb_context->path.dentry->d_inode->i_sb->s_id, 1062 req->wb_context->path.dentry->d_inode->i_sb->s_id,
1063 (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode), 1063 (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode),
1064 req->wb_bytes, 1064 req->wb_bytes,
@@ -1078,8 +1078,6 @@ static void nfs_writeback_release_full(void *calldata)
1078 dprintk(" marked for commit\n"); 1078 dprintk(" marked for commit\n");
1079 goto next; 1079 goto next;
1080 } 1080 }
1081 /* Set the PG_uptodate flag? */
1082 nfs_mark_uptodate(page, req->wb_pgbase, req->wb_bytes);
1083 dprintk(" OK\n"); 1081 dprintk(" OK\n");
1084remove_request: 1082remove_request:
1085 nfs_end_page_writeback(page); 1083 nfs_end_page_writeback(page);
@@ -1133,7 +1131,7 @@ int nfs_writeback_done(struct rpc_task *task, struct nfs_write_data *data)
1133 static unsigned long complain; 1131 static unsigned long complain;
1134 1132
1135 if (time_before(complain, jiffies)) { 1133 if (time_before(complain, jiffies)) {
1136 dprintk("NFS: faulty NFS server %s:" 1134 dprintk("NFS: faulty NFS server %s:"
1137 " (committed = %d) != (stable = %d)\n", 1135 " (committed = %d) != (stable = %d)\n",
1138 NFS_SERVER(data->inode)->nfs_client->cl_hostname, 1136 NFS_SERVER(data->inode)->nfs_client->cl_hostname,
1139 resp->verf->committed, argp->stable); 1137 resp->verf->committed, argp->stable);
@@ -1297,12 +1295,9 @@ static void nfs_commit_release(void *calldata)
1297 while (!list_empty(&data->pages)) { 1295 while (!list_empty(&data->pages)) {
1298 req = nfs_list_entry(data->pages.next); 1296 req = nfs_list_entry(data->pages.next);
1299 nfs_list_remove_request(req); 1297 nfs_list_remove_request(req);
1300 clear_bit(PG_NEED_COMMIT, &(req)->wb_flags); 1298 nfs_clear_request_commit(req);
1301 dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
1302 dec_bdi_stat(req->wb_page->mapping->backing_dev_info,
1303 BDI_RECLAIMABLE);
1304 1299
1305 dprintk("NFS: commit (%s/%Ld %d@%Ld)", 1300 dprintk("NFS: commit (%s/%lld %d@%lld)",
1306 req->wb_context->path.dentry->d_inode->i_sb->s_id, 1301 req->wb_context->path.dentry->d_inode->i_sb->s_id,
1307 (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode), 1302 (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode),
1308 req->wb_bytes, 1303 req->wb_bytes,
@@ -1318,9 +1313,6 @@ static void nfs_commit_release(void *calldata)
1318 * returned by the server against all stored verfs. */ 1313 * returned by the server against all stored verfs. */
1319 if (!memcmp(req->wb_verf.verifier, data->verf.verifier, sizeof(data->verf.verifier))) { 1314 if (!memcmp(req->wb_verf.verifier, data->verf.verifier, sizeof(data->verf.verifier))) {
1320 /* We have a match */ 1315 /* We have a match */
1321 /* Set the PG_uptodate flag */
1322 nfs_mark_uptodate(req->wb_page, req->wb_pgbase,
1323 req->wb_bytes);
1324 nfs_inode_remove_request(req); 1316 nfs_inode_remove_request(req);
1325 dprintk(" OK\n"); 1317 dprintk(" OK\n");
1326 goto next; 1318 goto next;
@@ -1479,7 +1471,7 @@ int nfs_wb_page_cancel(struct inode *inode, struct page *page)
1479 req = nfs_page_find_request(page); 1471 req = nfs_page_find_request(page);
1480 if (req == NULL) 1472 if (req == NULL)
1481 goto out; 1473 goto out;
1482 if (test_bit(PG_NEED_COMMIT, &req->wb_flags)) { 1474 if (test_bit(PG_CLEAN, &req->wb_flags)) {
1483 nfs_release_request(req); 1475 nfs_release_request(req);
1484 break; 1476 break;
1485 } 1477 }
diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c
index 4d4760e687c3..702fa577aa6e 100644
--- a/fs/nfsd/nfs4callback.c
+++ b/fs/nfsd/nfs4callback.c
@@ -381,7 +381,7 @@ static int do_probe_callback(void *data)
381 .program = &cb_program, 381 .program = &cb_program,
382 .version = nfs_cb_version[1]->number, 382 .version = nfs_cb_version[1]->number,
383 .authflavor = RPC_AUTH_UNIX, /* XXX: need AUTH_GSS... */ 383 .authflavor = RPC_AUTH_UNIX, /* XXX: need AUTH_GSS... */
384 .flags = (RPC_CLNT_CREATE_NOPING), 384 .flags = (RPC_CLNT_CREATE_NOPING | RPC_CLNT_CREATE_QUIET),
385 }; 385 };
386 struct rpc_message msg = { 386 struct rpc_message msg = {
387 .rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_NULL], 387 .rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_NULL],