kernel-wide: replace USHORT_MAX, SHORT_MAX and SHORT_MIN with USHRT_MAX, SHRT_MAX...
[safe/jmp/linux-2.6] / fs / nfs / super.c
index 69804a8..04214fc 100644 (file)
 #include <linux/smp_lock.h>
 #include <linux/seq_file.h>
 #include <linux/mount.h>
+#include <linux/mnt_namespace.h>
+#include <linux/namei.h>
 #include <linux/nfs_idmap.h>
 #include <linux/vfs.h>
 #include <linux/inet.h>
 #include <linux/in6.h>
+#include <linux/slab.h>
 #include <net/ipv6.h>
 #include <linux/netdevice.h>
 #include <linux/nfs_xdr.h>
@@ -71,7 +74,7 @@ enum {
        Opt_cto, Opt_nocto,
        Opt_ac, Opt_noac,
        Opt_lock, Opt_nolock,
-       Opt_v2, Opt_v3,
+       Opt_v2, Opt_v3, Opt_v4,
        Opt_udp, Opt_tcp, Opt_rdma,
        Opt_acl, Opt_noacl,
        Opt_rdirplus, Opt_nordirplus,
@@ -125,6 +128,7 @@ static const match_table_t nfs_mount_option_tokens = {
        { Opt_nolock, "nolock" },
        { Opt_v2, "v2" },
        { Opt_v3, "v3" },
+       { Opt_v4, "v4" },
        { Opt_udp, "udp" },
        { Opt_tcp, "tcp" },
        { Opt_rdma, "rdma" },
@@ -137,26 +141,25 @@ static const match_table_t nfs_mount_option_tokens = {
        { Opt_resvport, "resvport" },
        { Opt_noresvport, "noresvport" },
        { Opt_fscache, "fsc" },
-       { Opt_fscache_uniq, "fsc=%s" },
        { Opt_nofscache, "nofsc" },
 
-       { Opt_port, "port=%u" },
-       { Opt_rsize, "rsize=%u" },
-       { Opt_wsize, "wsize=%u" },
-       { Opt_bsize, "bsize=%u" },
-       { Opt_timeo, "timeo=%u" },
-       { Opt_retrans, "retrans=%u" },
-       { Opt_acregmin, "acregmin=%u" },
-       { Opt_acregmax, "acregmax=%u" },
-       { Opt_acdirmin, "acdirmin=%u" },
-       { Opt_acdirmax, "acdirmax=%u" },
-       { Opt_actimeo, "actimeo=%u" },
-       { Opt_namelen, "namlen=%u" },
-       { Opt_mountport, "mountport=%u" },
-       { Opt_mountvers, "mountvers=%u" },
-       { Opt_nfsvers, "nfsvers=%u" },
-       { Opt_nfsvers, "vers=%u" },
-       { Opt_minorversion, "minorversion=%u" },
+       { Opt_port, "port=%s" },
+       { Opt_rsize, "rsize=%s" },
+       { Opt_wsize, "wsize=%s" },
+       { Opt_bsize, "bsize=%s" },
+       { Opt_timeo, "timeo=%s" },
+       { Opt_retrans, "retrans=%s" },
+       { Opt_acregmin, "acregmin=%s" },
+       { Opt_acregmax, "acregmax=%s" },
+       { Opt_acdirmin, "acdirmin=%s" },
+       { Opt_acdirmax, "acdirmax=%s" },
+       { Opt_actimeo, "actimeo=%s" },
+       { Opt_namelen, "namlen=%s" },
+       { Opt_mountport, "mountport=%s" },
+       { Opt_mountvers, "mountvers=%s" },
+       { Opt_nfsvers, "nfsvers=%s" },
+       { Opt_nfsvers, "vers=%s" },
+       { Opt_minorversion, "minorversion=%s" },
 
        { Opt_sec, "sec=%s" },
        { Opt_proto, "proto=%s" },
@@ -167,19 +170,22 @@ static const match_table_t nfs_mount_option_tokens = {
        { Opt_mountaddr, "mountaddr=%s" },
 
        { Opt_lookupcache, "lookupcache=%s" },
+       { Opt_fscache_uniq, "fsc=%s" },
 
        { Opt_err, NULL }
 };
 
 enum {
-       Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
+       Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
 
        Opt_xprt_err
 };
 
 static const match_table_t nfs_xprt_protocol_tokens = {
        { Opt_xprt_udp, "udp" },
+       { Opt_xprt_udp6, "udp6" },
        { Opt_xprt_tcp, "tcp" },
+       { Opt_xprt_tcp6, "tcp6" },
        { Opt_xprt_rdma, "rdma" },
 
        { Opt_xprt_err, NULL }
@@ -238,6 +244,7 @@ static int  nfs_show_stats(struct seq_file *, struct vfsmount *);
 static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
 static int nfs_xdev_get_sb(struct file_system_type *fs_type,
                int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
+static void nfs_put_super(struct super_block *);
 static void nfs_kill_super(struct super_block *);
 static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
 
@@ -261,6 +268,7 @@ static const struct super_operations nfs_sops = {
        .alloc_inode    = nfs_alloc_inode,
        .destroy_inode  = nfs_destroy_inode,
        .write_inode    = nfs_write_inode,
+       .put_super      = nfs_put_super,
        .statfs         = nfs_statfs,
        .clear_inode    = nfs_clear_inode,
        .umount_begin   = nfs_umount_begin,
@@ -270,12 +278,20 @@ static const struct super_operations nfs_sops = {
 };
 
 #ifdef CONFIG_NFS_V4
+static int nfs4_validate_text_mount_data(void *options,
+       struct nfs_parsed_mount_data *args, const char *dev_name);
+static int nfs4_try_mount(int flags, const char *dev_name,
+       struct nfs_parsed_mount_data *data, struct vfsmount *mnt);
 static int nfs4_get_sb(struct file_system_type *fs_type,
        int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
+static int nfs4_remote_get_sb(struct file_system_type *fs_type,
+       int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
 static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
        int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
        int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
+static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
+       int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
 static void nfs4_kill_super(struct super_block *sb);
 
 static struct file_system_type nfs4_fs_type = {
@@ -286,6 +302,14 @@ static struct file_system_type nfs4_fs_type = {
        .fs_flags       = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
 };
 
+static struct file_system_type nfs4_remote_fs_type = {
+       .owner          = THIS_MODULE,
+       .name           = "nfs4",
+       .get_sb         = nfs4_remote_get_sb,
+       .kill_sb        = nfs4_kill_super,
+       .fs_flags       = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
+};
+
 struct file_system_type nfs4_xdev_fs_type = {
        .owner          = THIS_MODULE,
        .name           = "nfs4",
@@ -294,6 +318,14 @@ struct file_system_type nfs4_xdev_fs_type = {
        .fs_flags       = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
 };
 
+static struct file_system_type nfs4_remote_referral_fs_type = {
+       .owner          = THIS_MODULE,
+       .name           = "nfs4",
+       .get_sb         = nfs4_remote_referral_get_sb,
+       .kill_sb        = nfs4_kill_super,
+       .fs_flags       = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
+};
+
 struct file_system_type nfs4_referral_fs_type = {
        .owner          = THIS_MODULE,
        .name           = "nfs4",
@@ -306,6 +338,7 @@ static const struct super_operations nfs4_sops = {
        .alloc_inode    = nfs_alloc_inode,
        .destroy_inode  = nfs_destroy_inode,
        .write_inode    = nfs_write_inode,
+       .put_super      = nfs_put_super,
        .statfs         = nfs_statfs,
        .clear_inode    = nfs4_clear_inode,
        .umount_begin   = nfs_umount_begin,
@@ -390,15 +423,19 @@ static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
        unsigned char blockbits;
        unsigned long blockres;
        struct nfs_fh *fh = NFS_FH(dentry->d_inode);
-       struct nfs_fattr fattr;
-       struct nfs_fsstat res = {
-                       .fattr = &fattr,
-       };
-       int error;
+       struct nfs_fsstat res;
+       int error = -ENOMEM;
+
+       res.fattr = nfs_alloc_fattr();
+       if (res.fattr == NULL)
+               goto out_err;
 
        error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
+
+       nfs_free_fattr(res.fattr);
        if (error < 0)
                goto out_err;
+
        buf->f_type = NFS_SUPER_MAGIC;
 
        /*
@@ -465,6 +502,45 @@ static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
        return sec_flavours[i].str;
 }
 
+static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
+                                 int showdefaults)
+{
+       struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
+
+       seq_printf(m, ",mountproto=");
+       switch (sap->sa_family) {
+       case AF_INET:
+               switch (nfss->mountd_protocol) {
+               case IPPROTO_UDP:
+                       seq_printf(m, RPCBIND_NETID_UDP);
+                       break;
+               case IPPROTO_TCP:
+                       seq_printf(m, RPCBIND_NETID_TCP);
+                       break;
+               default:
+                       if (showdefaults)
+                               seq_printf(m, "auto");
+               }
+               break;
+       case AF_INET6:
+               switch (nfss->mountd_protocol) {
+               case IPPROTO_UDP:
+                       seq_printf(m, RPCBIND_NETID_UDP6);
+                       break;
+               case IPPROTO_TCP:
+                       seq_printf(m, RPCBIND_NETID_TCP6);
+                       break;
+               default:
+                       if (showdefaults)
+                               seq_printf(m, "auto");
+               }
+               break;
+       default:
+               if (showdefaults)
+                       seq_printf(m, "auto");
+       }
+}
+
 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
                                    int showdefaults)
 {
@@ -478,7 +554,7 @@ static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
        }
        case AF_INET6: {
                struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
-               seq_printf(m, ",mountaddr=%pI6", &sin6->sin6_addr);
+               seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
                break;
        }
        default:
@@ -491,17 +567,7 @@ static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
        if (nfss->mountd_port || showdefaults)
                seq_printf(m, ",mountport=%u", nfss->mountd_port);
 
-       switch (nfss->mountd_protocol) {
-       case IPPROTO_UDP:
-               seq_printf(m, ",mountproto=udp");
-               break;
-       case IPPROTO_TCP:
-               seq_printf(m, ",mountproto=tcp");
-               break;
-       default:
-               if (showdefaults)
-                       seq_printf(m, ",mountproto=auto");
-       }
+       nfs_show_mountd_netid(m, nfss, showdefaults);
 }
 
 /*
@@ -516,7 +582,6 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
                const char *nostr;
        } nfs_info[] = {
                { NFS_MOUNT_SOFT, ",soft", ",hard" },
-               { NFS_MOUNT_INTR, ",intr", ",nointr" },
                { NFS_MOUNT_POSIX, ",posix", "" },
                { NFS_MOUNT_NOCTO, ",nocto", "" },
                { NFS_MOUNT_NOAC, ",noac", "" },
@@ -552,7 +617,7 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
                        seq_puts(m, nfs_infop->nostr);
        }
        seq_printf(m, ",proto=%s",
-                  rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
+                  rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
        if (version == 4) {
                if (nfss->port != NFS_PORT)
                        seq_printf(m, ",port=%u", nfss->port);
@@ -688,8 +753,6 @@ static void nfs_umount_begin(struct super_block *sb)
        struct nfs_server *server;
        struct rpc_clnt *rpc;
 
-       lock_kernel();
-
        server = NFS_SB(sb);
        /* -EIO all pending I/O */
        rpc = server->client_acl;
@@ -698,8 +761,27 @@ static void nfs_umount_begin(struct super_block *sb)
        rpc = server->client;
        if (!IS_ERR(rpc))
                rpc_killall_tasks(rpc);
+}
 
-       unlock_kernel();
+static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
+{
+       struct nfs_parsed_mount_data *data;
+
+       data = kzalloc(sizeof(*data), GFP_KERNEL);
+       if (data) {
+               data->acregmin          = NFS_DEF_ACREGMIN;
+               data->acregmax          = NFS_DEF_ACREGMAX;
+               data->acdirmin          = NFS_DEF_ACDIRMIN;
+               data->acdirmax          = NFS_DEF_ACDIRMAX;
+               data->mount_server.port = NFS_UNSPEC_PORT;
+               data->nfs_server.port   = NFS_UNSPEC_PORT;
+               data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
+               data->auth_flavors[0]   = RPC_AUTH_UNIX;
+               data->auth_flavor_len   = 1;
+               data->version           = version;
+               data->minorversion      = 0;
+       }
+       return data;
 }
 
 /*
@@ -721,127 +803,21 @@ static int nfs_verify_server_address(struct sockaddr *addr)
        }
        }
 
+       dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
        return 0;
 }
 
-static void nfs_parse_ipv4_address(char *string, size_t str_len,
-                                  struct sockaddr *sap, size_t *addr_len)
-{
-       struct sockaddr_in *sin = (struct sockaddr_in *)sap;
-       u8 *addr = (u8 *)&sin->sin_addr.s_addr;
-
-       if (str_len <= INET_ADDRSTRLEN) {
-               dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n",
-                               (int)str_len, string);
-
-               sin->sin_family = AF_INET;
-               *addr_len = sizeof(*sin);
-               if (in4_pton(string, str_len, addr, '\0', NULL))
-                       return;
-       }
-
-       sap->sa_family = AF_UNSPEC;
-       *addr_len = 0;
-}
-
-#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
-static int nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
-                                  const char *delim,
-                                  struct sockaddr_in6 *sin6)
-{
-       char *p;
-       size_t len;
-
-       if ((string + str_len) == delim)
-               return 1;
-
-       if (*delim != IPV6_SCOPE_DELIMITER)
-               return 0;
-
-       if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
-               return 0;
-
-       len = (string + str_len) - delim - 1;
-       p = kstrndup(delim + 1, len, GFP_KERNEL);
-       if (p) {
-               unsigned long scope_id = 0;
-               struct net_device *dev;
-
-               dev = dev_get_by_name(&init_net, p);
-               if (dev != NULL) {
-                       scope_id = dev->ifindex;
-                       dev_put(dev);
-               } else {
-                       if (strict_strtoul(p, 10, &scope_id) == 0) {
-                               kfree(p);
-                               return 0;
-                       }
-               }
-
-               kfree(p);
-
-               sin6->sin6_scope_id = scope_id;
-               dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
-               return 1;
-       }
-
-       return 0;
-}
-
-static void nfs_parse_ipv6_address(char *string, size_t str_len,
-                                  struct sockaddr *sap, size_t *addr_len)
-{
-       struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
-       u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
-       const char *delim;
-
-       if (str_len <= INET6_ADDRSTRLEN) {
-               dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n",
-                               (int)str_len, string);
-
-               sin6->sin6_family = AF_INET6;
-               *addr_len = sizeof(*sin6);
-               if (in6_pton(string, str_len, addr,
-                                       IPV6_SCOPE_DELIMITER, &delim) != 0) {
-                       if (nfs_parse_ipv6_scope_id(string, str_len,
-                                                       delim, sin6) != 0)
-                               return;
-               }
-       }
-
-       sap->sa_family = AF_UNSPEC;
-       *addr_len = 0;
-}
-#else
-static void nfs_parse_ipv6_address(char *string, size_t str_len,
-                                  struct sockaddr *sap, size_t *addr_len)
-{
-       sap->sa_family = AF_UNSPEC;
-       *addr_len = 0;
-}
-#endif
-
 /*
- * Construct a sockaddr based on the contents of a string that contains
- * an IP address in presentation format.
- *
- * If there is a problem constructing the new sockaddr, set the address
- * family to AF_UNSPEC.
+ * Select between a default port value and a user-specified port value.
+ * If a zero value is set, then autobind will be used.
  */
-void nfs_parse_ip_address(char *string, size_t str_len,
-                                struct sockaddr *sap, size_t *addr_len)
+static void nfs_set_port(struct sockaddr *sap, int *port,
+                                const unsigned short default_port)
 {
-       unsigned int i, colons;
+       if (*port == NFS_UNSPEC_PORT)
+               *port = default_port;
 
-       colons = 0;
-       for (i = 0; i < str_len; i++)
-               if (string[i] == ':')
-                       colons++;
-
-       if (colons >= 2)
-               nfs_parse_ipv6_address(string, str_len, sap, addr_len);
-       else
-               nfs_parse_ipv4_address(string, str_len, sap, addr_len);
+       rpc_set_port(sap, *port);
 }
 
 /*
@@ -883,8 +859,6 @@ static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
 
 /*
  * Parse the value of the 'sec=' option.
- *
- * The flavor_len setting is for v4 mounts.
  */
 static int nfs_parse_security_flavors(char *value,
                                      struct nfs_parsed_mount_data *mnt)
@@ -895,61 +869,46 @@ static int nfs_parse_security_flavors(char *value,
 
        switch (match_token(value, nfs_secflavor_tokens, args)) {
        case Opt_sec_none:
-               mnt->auth_flavor_len = 0;
                mnt->auth_flavors[0] = RPC_AUTH_NULL;
                break;
        case Opt_sec_sys:
-               mnt->auth_flavor_len = 0;
                mnt->auth_flavors[0] = RPC_AUTH_UNIX;
                break;
        case Opt_sec_krb5:
-               mnt->auth_flavor_len = 1;
                mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
                break;
        case Opt_sec_krb5i:
-               mnt->auth_flavor_len = 1;
                mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
                break;
        case Opt_sec_krb5p:
-               mnt->auth_flavor_len = 1;
                mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
                break;
        case Opt_sec_lkey:
-               mnt->auth_flavor_len = 1;
                mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
                break;
        case Opt_sec_lkeyi:
-               mnt->auth_flavor_len = 1;
                mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
                break;
        case Opt_sec_lkeyp:
-               mnt->auth_flavor_len = 1;
                mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
                break;
        case Opt_sec_spkm:
-               mnt->auth_flavor_len = 1;
                mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
                break;
        case Opt_sec_spkmi:
-               mnt->auth_flavor_len = 1;
                mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
                break;
        case Opt_sec_spkmp:
-               mnt->auth_flavor_len = 1;
                mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
                break;
        default:
                return 0;
        }
 
+       mnt->auth_flavor_len = 1;
        return 1;
 }
 
-static void nfs_parse_invalid_value(const char *option)
-{
-       dfprintk(MOUNT, "NFS:   bad value specified for %s option\n", option);
-}
-
 /*
  * Error-check and convert a string of mount options from user space into
  * a data structure.  The whole mount string is processed; bad options are
@@ -960,7 +919,9 @@ static int nfs_parse_mount_options(char *raw,
                                   struct nfs_parsed_mount_data *mnt)
 {
        char *p, *string, *secdata;
-       int rc, sloppy = 0, errors = 0;
+       int rc, sloppy = 0, invalid_option = 0;
+       unsigned short protofamily = AF_UNSPEC;
+       unsigned short mountfamily = AF_UNSPEC;
 
        if (!raw) {
                dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
@@ -984,7 +945,8 @@ static int nfs_parse_mount_options(char *raw,
 
        while ((p = strsep(&raw, ",")) != NULL) {
                substring_t args[MAX_OPT_ARGS];
-               int option, token;
+               unsigned long option;
+               int token;
 
                if (!*p)
                        continue;
@@ -1029,10 +991,18 @@ static int nfs_parse_mount_options(char *raw,
                        break;
                case Opt_v2:
                        mnt->flags &= ~NFS_MOUNT_VER3;
+                       mnt->version = 2;
                        break;
                case Opt_v3:
                        mnt->flags |= NFS_MOUNT_VER3;
+                       mnt->version = 3;
                        break;
+#ifdef CONFIG_NFS_V4
+               case Opt_v4:
+                       mnt->flags &= ~NFS_MOUNT_VER3;
+                       mnt->version = 4;
+                       break;
+#endif
                case Opt_udp:
                        mnt->flags &= ~NFS_MOUNT_TCP;
                        mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
@@ -1080,144 +1050,190 @@ static int nfs_parse_mount_options(char *raw,
                        kfree(mnt->fscache_uniq);
                        mnt->fscache_uniq = NULL;
                        break;
-               case Opt_fscache_uniq:
-                       string = match_strdup(args);
-                       if (!string)
-                               goto out_nomem;
-                       kfree(mnt->fscache_uniq);
-                       mnt->fscache_uniq = string;
-                       mnt->options |= NFS_OPTION_FSCACHE;
-                       break;
 
                /*
                 * options that take numeric values
                 */
                case Opt_port:
-                       if (match_int(args, &option) ||
-                           option < 0 || option > USHORT_MAX) {
-                               errors++;
-                               nfs_parse_invalid_value("port");
-                       } else
-                               mnt->nfs_server.port = option;
+                       string = match_strdup(args);
+                       if (string == NULL)
+                               goto out_nomem;
+                       rc = strict_strtoul(string, 10, &option);
+                       kfree(string);
+                       if (rc != 0 || option > USHRT_MAX)
+                               goto out_invalid_value;
+                       mnt->nfs_server.port = option;
                        break;
                case Opt_rsize:
-                       if (match_int(args, &option) || option < 0) {
-                               errors++;
-                               nfs_parse_invalid_value("rsize");
-                       } else
-                               mnt->rsize = option;
+                       string = match_strdup(args);
+                       if (string == NULL)
+                               goto out_nomem;
+                       rc = strict_strtoul(string, 10, &option);
+                       kfree(string);
+                       if (rc != 0)
+                               goto out_invalid_value;
+                       mnt->rsize = option;
                        break;
                case Opt_wsize:
-                       if (match_int(args, &option) || option < 0) {
-                               errors++;
-                               nfs_parse_invalid_value("wsize");
-                       } else
-                               mnt->wsize = option;
+                       string = match_strdup(args);
+                       if (string == NULL)
+                               goto out_nomem;
+                       rc = strict_strtoul(string, 10, &option);
+                       kfree(string);
+                       if (rc != 0)
+                               goto out_invalid_value;
+                       mnt->wsize = option;
                        break;
                case Opt_bsize:
-                       if (match_int(args, &option) || option < 0) {
-                               errors++;
-                               nfs_parse_invalid_value("bsize");
-                       } else
-                               mnt->bsize = option;
+                       string = match_strdup(args);
+                       if (string == NULL)
+                               goto out_nomem;
+                       rc = strict_strtoul(string, 10, &option);
+                       kfree(string);
+                       if (rc != 0)
+                               goto out_invalid_value;
+                       mnt->bsize = option;
                        break;
                case Opt_timeo:
-                       if (match_int(args, &option) || option <= 0) {
-                               errors++;
-                               nfs_parse_invalid_value("timeo");
-                       } else
-                               mnt->timeo = option;
+                       string = match_strdup(args);
+                       if (string == NULL)
+                               goto out_nomem;
+                       rc = strict_strtoul(string, 10, &option);
+                       kfree(string);
+                       if (rc != 0 || option == 0)
+                               goto out_invalid_value;
+                       mnt->timeo = option;
                        break;
                case Opt_retrans:
-                       if (match_int(args, &option) || option <= 0) {
-                               errors++;
-                               nfs_parse_invalid_value("retrans");
-                       } else
-                               mnt->retrans = option;
+                       string = match_strdup(args);
+                       if (string == NULL)
+                               goto out_nomem;
+                       rc = strict_strtoul(string, 10, &option);
+                       kfree(string);
+                       if (rc != 0 || option == 0)
+                               goto out_invalid_value;
+                       mnt->retrans = option;
                        break;
                case Opt_acregmin:
-                       if (match_int(args, &option) || option < 0) {
-                               errors++;
-                               nfs_parse_invalid_value("acregmin");
-                       } else
-                               mnt->acregmin = option;
+                       string = match_strdup(args);
+                       if (string == NULL)
+                               goto out_nomem;
+                       rc = strict_strtoul(string, 10, &option);
+                       kfree(string);
+                       if (rc != 0)
+                               goto out_invalid_value;
+                       mnt->acregmin = option;
                        break;
                case Opt_acregmax:
-                       if (match_int(args, &option) || option < 0) {
-                               errors++;
-                               nfs_parse_invalid_value("acregmax");
-                       } else
-                               mnt->acregmax = option;
+                       string = match_strdup(args);
+                       if (string == NULL)
+                               goto out_nomem;
+                       rc = strict_strtoul(string, 10, &option);
+                       kfree(string);
+                       if (rc != 0)
+                               goto out_invalid_value;
+                       mnt->acregmax = option;
                        break;
                case Opt_acdirmin:
-                       if (match_int(args, &option) || option < 0) {
-                               errors++;
-                               nfs_parse_invalid_value("acdirmin");
-                       } else
-                               mnt->acdirmin = option;
+                       string = match_strdup(args);
+                       if (string == NULL)
+                               goto out_nomem;
+                       rc = strict_strtoul(string, 10, &option);
+                       kfree(string);
+                       if (rc != 0)
+                               goto out_invalid_value;
+                       mnt->acdirmin = option;
                        break;
                case Opt_acdirmax:
-                       if (match_int(args, &option) || option < 0) {
-                               errors++;
-                               nfs_parse_invalid_value("acdirmax");
-                       } else
-                               mnt->acdirmax = option;
+                       string = match_strdup(args);
+                       if (string == NULL)
+                               goto out_nomem;
+                       rc = strict_strtoul(string, 10, &option);
+                       kfree(string);
+                       if (rc != 0)
+                               goto out_invalid_value;
+                       mnt->acdirmax = option;
                        break;
                case Opt_actimeo:
-                       if (match_int(args, &option) || option < 0) {
-                               errors++;
-                               nfs_parse_invalid_value("actimeo");
-                       } else
-                               mnt->acregmin = mnt->acregmax =
-                               mnt->acdirmin = mnt->acdirmax = option;
+                       string = match_strdup(args);
+                       if (string == NULL)
+                               goto out_nomem;
+                       rc = strict_strtoul(string, 10, &option);
+                       kfree(string);
+                       if (rc != 0)
+                               goto out_invalid_value;
+                       mnt->acregmin = mnt->acregmax =
+                       mnt->acdirmin = mnt->acdirmax = option;
                        break;
                case Opt_namelen:
-                       if (match_int(args, &option) || option < 0) {
-                               errors++;
-                               nfs_parse_invalid_value("namlen");
-                       } else
-                               mnt->namlen = option;
+                       string = match_strdup(args);
+                       if (string == NULL)
+                               goto out_nomem;
+                       rc = strict_strtoul(string, 10, &option);
+                       kfree(string);
+                       if (rc != 0)
+                               goto out_invalid_value;
+                       mnt->namlen = option;
                        break;
                case Opt_mountport:
-                       if (match_int(args, &option) ||
-                           option < 0 || option > USHORT_MAX) {
-                               errors++;
-                               nfs_parse_invalid_value("mountport");
-                       } else
-                               mnt->mount_server.port = option;
+                       string = match_strdup(args);
+                       if (string == NULL)
+                               goto out_nomem;
+                       rc = strict_strtoul(string, 10, &option);
+                       kfree(string);
+                       if (rc != 0 || option > USHRT_MAX)
+                               goto out_invalid_value;
+                       mnt->mount_server.port = option;
                        break;
                case Opt_mountvers:
-                       if (match_int(args, &option) ||
+                       string = match_strdup(args);
+                       if (string == NULL)
+                               goto out_nomem;
+                       rc = strict_strtoul(string, 10, &option);
+                       kfree(string);
+                       if (rc != 0 ||
                            option < NFS_MNT_VERSION ||
-                           option > NFS_MNT3_VERSION) {
-                               errors++;
-                               nfs_parse_invalid_value("mountvers");
-                       } else
-                               mnt->mount_server.version = option;
+                           option > NFS_MNT3_VERSION)
+                               goto out_invalid_value;
+                       mnt->mount_server.version = option;
                        break;
                case Opt_nfsvers:
-                       if (match_int(args, &option)) {
-                               errors++;
-                               nfs_parse_invalid_value("nfsvers");
-                               break;
-                       }
+                       string = match_strdup(args);
+                       if (string == NULL)
+                               goto out_nomem;
+                       rc = strict_strtoul(string, 10, &option);
+                       kfree(string);
+                       if (rc != 0)
+                               goto out_invalid_value;
                        switch (option) {
                        case NFS2_VERSION:
                                mnt->flags &= ~NFS_MOUNT_VER3;
+                               mnt->version = 2;
                                break;
                        case NFS3_VERSION:
                                mnt->flags |= NFS_MOUNT_VER3;
+                               mnt->version = 3;
                                break;
+#ifdef CONFIG_NFS_V4
+                       case NFS4_VERSION:
+                               mnt->flags &= ~NFS_MOUNT_VER3;
+                               mnt->version = 4;
+                               break;
+#endif
                        default:
-                               errors++;
-                               nfs_parse_invalid_value("nfsvers");
+                               goto out_invalid_value;
                        }
                        break;
                case Opt_minorversion:
-                       if (match_int(args, &option))
-                               return 0;
-                       if (option < 0 || option > NFS4_MAX_MINOR_VERSION)
-                               return 0;
+                       string = match_strdup(args);
+                       if (string == NULL)
+                               goto out_nomem;
+                       rc = strict_strtoul(string, 10, &option);
+                       kfree(string);
+                       if (rc != 0)
+                               goto out_invalid_value;
+                       if (option > NFS4_MAX_MINOR_VERSION)
+                               goto out_invalid_value;
                        mnt->minorversion = option;
                        break;
 
@@ -1231,9 +1247,9 @@ static int nfs_parse_mount_options(char *raw,
                        rc = nfs_parse_security_flavors(string, mnt);
                        kfree(string);
                        if (!rc) {
-                               errors++;
                                dfprintk(MOUNT, "NFS:   unrecognized "
                                                "security flavor\n");
+                               return 0;
                        }
                        break;
                case Opt_proto:
@@ -1243,27 +1259,35 @@ static int nfs_parse_mount_options(char *raw,
                        token = match_token(string,
                                            nfs_xprt_protocol_tokens, args);
 
+                       protofamily = AF_INET;
                        switch (token) {
+                       case Opt_xprt_udp6:
+                               protofamily = AF_INET6;
                        case Opt_xprt_udp:
                                mnt->flags &= ~NFS_MOUNT_TCP;
                                mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
+                               kfree(string);
                                break;
+                       case Opt_xprt_tcp6:
+                               protofamily = AF_INET6;
                        case Opt_xprt_tcp:
                                mnt->flags |= NFS_MOUNT_TCP;
                                mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
+                               kfree(string);
                                break;
                        case Opt_xprt_rdma:
                                /* vector side protocols to TCP */
                                mnt->flags |= NFS_MOUNT_TCP;
                                mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
                                xprt_load_transport(string);
+                               kfree(string);
                                break;
                        default:
-                               errors++;
                                dfprintk(MOUNT, "NFS:   unrecognized "
                                                "transport protocol\n");
+                               kfree(string);
+                               return 0;
                        }
-                       kfree(string);
                        break;
                case Opt_mountproto:
                        string = match_strdup(args);
@@ -1273,29 +1297,37 @@ static int nfs_parse_mount_options(char *raw,
                                            nfs_xprt_protocol_tokens, args);
                        kfree(string);
 
+                       mountfamily = AF_INET;
                        switch (token) {
+                       case Opt_xprt_udp6:
+                               mountfamily = AF_INET6;
                        case Opt_xprt_udp:
                                mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
                                break;
+                       case Opt_xprt_tcp6:
+                               mountfamily = AF_INET6;
                        case Opt_xprt_tcp:
                                mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
                                break;
                        case Opt_xprt_rdma: /* not used for side protocols */
                        default:
-                               errors++;
                                dfprintk(MOUNT, "NFS:   unrecognized "
                                                "transport protocol\n");
+                               return 0;
                        }
                        break;
                case Opt_addr:
                        string = match_strdup(args);
                        if (string == NULL)
                                goto out_nomem;
-                       nfs_parse_ip_address(string, strlen(string),
-                                            (struct sockaddr *)
-                                               &mnt->nfs_server.address,
-                                            &mnt->nfs_server.addrlen);
+                       mnt->nfs_server.addrlen =
+                               rpc_pton(string, strlen(string),
+                                       (struct sockaddr *)
+                                       &mnt->nfs_server.address,
+                                       sizeof(mnt->nfs_server.address));
                        kfree(string);
+                       if (mnt->nfs_server.addrlen == 0)
+                               goto out_invalid_address;
                        break;
                case Opt_clientaddr:
                        string = match_strdup(args);
@@ -1315,11 +1347,14 @@ static int nfs_parse_mount_options(char *raw,
                        string = match_strdup(args);
                        if (string == NULL)
                                goto out_nomem;
-                       nfs_parse_ip_address(string, strlen(string),
-                                            (struct sockaddr *)
-                                               &mnt->mount_server.address,
-                                            &mnt->mount_server.addrlen);
+                       mnt->mount_server.addrlen =
+                               rpc_pton(string, strlen(string),
+                                       (struct sockaddr *)
+                                       &mnt->mount_server.address,
+                                       sizeof(mnt->mount_server.address));
                        kfree(string);
+                       if (mnt->mount_server.addrlen == 0)
+                               goto out_invalid_address;
                        break;
                case Opt_lookupcache:
                        string = match_strdup(args);
@@ -1340,11 +1375,19 @@ static int nfs_parse_mount_options(char *raw,
                                        mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
                                        break;
                                default:
-                                       errors++;
                                        dfprintk(MOUNT, "NFS:   invalid "
                                                        "lookupcache argument\n");
+                                       return 0;
                        };
                        break;
+               case Opt_fscache_uniq:
+                       string = match_strdup(args);
+                       if (string == NULL)
+                               goto out_nomem;
+                       kfree(mnt->fscache_uniq);
+                       mnt->fscache_uniq = string;
+                       mnt->options |= NFS_OPTION_FSCACHE;
+                       break;
 
                /*
                 * Special options
@@ -1360,20 +1403,48 @@ static int nfs_parse_mount_options(char *raw,
                        break;
 
                default:
-                       errors++;
+                       invalid_option = 1;
                        dfprintk(MOUNT, "NFS:   unrecognized mount option "
                                        "'%s'\n", p);
                }
        }
 
-       if (errors > 0) {
-               dfprintk(MOUNT, "NFS: parsing encountered %d error%s\n",
-                               errors, (errors == 1 ? "" : "s"));
-               if (!sloppy)
-                       return 0;
+       if (!sloppy && invalid_option)
+               return 0;
+
+       /*
+        * verify that any proto=/mountproto= options match the address
+        * familiies in the addr=/mountaddr= options.
+        */
+       if (protofamily != AF_UNSPEC &&
+           protofamily != mnt->nfs_server.address.ss_family)
+               goto out_proto_mismatch;
+
+       if (mountfamily != AF_UNSPEC) {
+               if (mnt->mount_server.addrlen) {
+                       if (mountfamily != mnt->mount_server.address.ss_family)
+                               goto out_mountproto_mismatch;
+               } else {
+                       if (mountfamily != mnt->nfs_server.address.ss_family)
+                               goto out_mountproto_mismatch;
+               }
        }
+
        return 1;
 
+out_mountproto_mismatch:
+       printk(KERN_INFO "NFS: mount server address does not match mountproto= "
+                        "option\n");
+       return 0;
+out_proto_mismatch:
+       printk(KERN_INFO "NFS: server address does not match proto= option\n");
+       return 0;
+out_invalid_address:
+       printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
+       return 0;
+out_invalid_value:
+       printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
+       return 0;
 out_nomem:
        printk(KERN_INFO "NFS: not enough memory to parse option\n");
        return 0;
@@ -1384,12 +1455,60 @@ out_security_failure:
 }
 
 /*
+ * Match the requested auth flavors with the list returned by
+ * the server.  Returns zero and sets the mount's authentication
+ * flavor on success; returns -EACCES if server does not support
+ * the requested flavor.
+ */
+static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
+                            struct nfs_mount_request *request)
+{
+       unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
+
+       /*
+        * Certain releases of Linux's mountd return an empty
+        * flavor list.  To prevent behavioral regression with
+        * these servers (ie. rejecting mounts that used to
+        * succeed), revert to pre-2.6.32 behavior (no checking)
+        * if the returned flavor list is empty.
+        */
+       if (server_authlist_len == 0)
+               return 0;
+
+       /*
+        * We avoid sophisticated negotiating here, as there are
+        * plenty of cases where we can get it wrong, providing
+        * either too little or too much security.
+        *
+        * RFC 2623, section 2.7 suggests we SHOULD prefer the
+        * flavor listed first.  However, some servers list
+        * AUTH_NULL first.  Our caller plants AUTH_SYS, the
+        * preferred default, in args->auth_flavors[0] if user
+        * didn't specify sec= mount option.
+        */
+       for (i = 0; i < args->auth_flavor_len; i++)
+               for (j = 0; j < server_authlist_len; j++)
+                       if (args->auth_flavors[i] == request->auth_flavs[j]) {
+                               dfprintk(MOUNT, "NFS: using auth flavor %d\n",
+                                       request->auth_flavs[j]);
+                               args->auth_flavors[0] = request->auth_flavs[j];
+                               return 0;
+                       }
+
+       dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
+       nfs_umount(request);
+       return -EACCES;
+}
+
+/*
  * Use the remote server's MOUNT service to request the NFS file handle
  * corresponding to the provided path.
  */
 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
                         struct nfs_fh *root_fh)
 {
+       rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
+       unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
        struct nfs_mount_request request = {
                .sap            = (struct sockaddr *)
                                                &args->mount_server.address,
@@ -1397,14 +1516,19 @@ static int nfs_try_mount(struct nfs_parsed_mount_data *args,
                .protocol       = args->mount_server.protocol,
                .fh             = root_fh,
                .noresvport     = args->flags & NFS_MOUNT_NORESVPORT,
+               .auth_flav_len  = &server_authlist_len,
+               .auth_flavs     = server_authlist,
        };
        int status;
 
        if (args->mount_server.version == 0) {
-               if (args->flags & NFS_MOUNT_VER3)
-                       args->mount_server.version = NFS_MNT3_VERSION;
-               else
-                       args->mount_server.version = NFS_MNT_VERSION;
+               switch (args->version) {
+                       default:
+                               args->mount_server.version = NFS_MNT3_VERSION;
+                               break;
+                       case 2:
+                               args->mount_server.version = NFS_MNT_VERSION;
+               }
        }
        request.version = args->mount_server.version;
 
@@ -1422,23 +1546,25 @@ static int nfs_try_mount(struct nfs_parsed_mount_data *args,
                args->mount_server.addrlen = args->nfs_server.addrlen;
        }
        request.salen = args->mount_server.addrlen;
-
-       /*
-        * autobind will be used if mount_server.port == 0
-        */
-       nfs_set_port(request.sap, args->mount_server.port);
+       nfs_set_port(request.sap, &args->mount_server.port, 0);
 
        /*
         * Now ask the mount server to map our export path
         * to a file handle.
         */
        status = nfs_mount(&request);
-       if (status == 0)
-               return 0;
+       if (status != 0) {
+               dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
+                               request.hostname, status);
+               return status;
+       }
 
-       dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
-                       request.hostname, status);
-       return status;
+       /*
+        * MNTv1 (NFSv2) does not support auth flavor negotiation.
+        */
+       if (args->mount_server.version != NFS_MNT3_VERSION)
+               return 0;
+       return nfs_walk_authlist(args, &request);
 }
 
 static int nfs_parse_simple_hostname(const char *dev_name,
@@ -1598,22 +1724,11 @@ static int nfs_validate_mount_data(void *options,
                                   const char *dev_name)
 {
        struct nfs_mount_data *data = (struct nfs_mount_data *)options;
+       struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
 
        if (data == NULL)
                goto out_no_data;
 
-       args->flags             = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
-       args->rsize             = NFS_MAX_FILE_IO_SIZE;
-       args->wsize             = NFS_MAX_FILE_IO_SIZE;
-       args->acregmin          = NFS_DEF_ACREGMIN;
-       args->acregmax          = NFS_DEF_ACREGMAX;
-       args->acdirmin          = NFS_DEF_ACDIRMIN;
-       args->acdirmax          = NFS_DEF_ACDIRMAX;
-       args->mount_server.port = 0;    /* autobind unless user sets port */
-       args->nfs_server.port   = 0;    /* autobind unless user sets port */
-       args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
-       args->auth_flavors[0]   = RPC_AUTH_UNIX;
-
        switch (data->version) {
        case 1:
                data->namlen = 0;
@@ -1634,8 +1749,11 @@ static int nfs_validate_mount_data(void *options,
                        if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
                                goto out_invalid_fh;
                        mntfh->size = data->root.size;
-               } else
+                       args->version = 3;
+               } else {
                        mntfh->size = NFS2_FHSIZE;
+                       args->version = 2;
+               }
 
 
                memcpy(mntfh->data, data->root.data, mntfh->size);
@@ -1657,11 +1775,9 @@ static int nfs_validate_mount_data(void *options,
                args->acdirmin          = data->acdirmin;
                args->acdirmax          = data->acdirmax;
 
-               memcpy(&args->nfs_server.address, &data->addr,
-                      sizeof(data->addr));
+               memcpy(sap, &data->addr, sizeof(data->addr));
                args->nfs_server.addrlen = sizeof(data->addr);
-               if (!nfs_verify_server_address((struct sockaddr *)
-                                               &args->nfs_server.address))
+               if (!nfs_verify_server_address(sap))
                        goto out_no_address;
 
                if (!(data->flags & NFS_MOUNT_TCP))
@@ -1709,12 +1825,18 @@ static int nfs_validate_mount_data(void *options,
                if (nfs_parse_mount_options((char *)options, args) == 0)
                        return -EINVAL;
 
-               if (!nfs_verify_server_address((struct sockaddr *)
-                                               &args->nfs_server.address))
+               if (!nfs_verify_server_address(sap))
                        goto out_no_address;
 
-               nfs_set_port((struct sockaddr *)&args->nfs_server.address,
-                               args->nfs_server.port);
+               if (args->version == 4)
+#ifdef CONFIG_NFS_V4
+                       return nfs4_validate_text_mount_data(options,
+                                                            args, dev_name);
+#else
+                       goto out_v4_not_compiled;
+#endif
+
+               nfs_set_port(sap, &args->nfs_server.port, 0);
 
                nfs_set_mount_transport_protocol(args);
 
@@ -1737,7 +1859,7 @@ static int nfs_validate_mount_data(void *options,
        }
 
 #ifndef CONFIG_NFS_V3
-       if (args->flags & NFS_MOUNT_VER3)
+       if (args->version == 3)
                goto out_v3_not_compiled;
 #endif /* !CONFIG_NFS_V3 */
 
@@ -1762,6 +1884,12 @@ out_v3_not_compiled:
        return -EPROTONOSUPPORT;
 #endif /* !CONFIG_NFS_V3 */
 
+#ifndef CONFIG_NFS_V4
+out_v4_not_compiled:
+       dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
+       return -EPROTONOSUPPORT;
+#endif /* !CONFIG_NFS_V4 */
+
 out_nomem:
        dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
        return -ENOMEM;
@@ -1789,9 +1917,10 @@ nfs_compare_remount_data(struct nfs_server *nfss,
            data->acdirmin != nfss->acdirmin / HZ ||
            data->acdirmax != nfss->acdirmax / HZ ||
            data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
+           data->nfs_server.port != nfss->port ||
            data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
-           memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
-                  data->nfs_server.addrlen) != 0)
+           !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
+                         (struct sockaddr *)&nfss->nfs_client->cl_addr))
                return -EINVAL;
 
        return 0;
@@ -1833,6 +1962,7 @@ nfs_remount(struct super_block *sb, int *flags, char *raw_data)
        data->acdirmin = nfss->acdirmin / HZ;
        data->acdirmax = nfss->acdirmax / HZ;
        data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
+       data->nfs_server.port = nfss->port;
        data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
        memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
                data->nfs_server.addrlen);
@@ -1869,6 +1999,8 @@ static inline void nfs_initialise_sb(struct super_block *sb)
        if (server->flags & NFS_MOUNT_NOAC)
                sb->s_flags |= MS_SYNCHRONOUS;
 
+       sb->s_bdi = &server->backing_dev_info;
+
        nfs_super_set_maxbytes(sb, server->maxfilesize);
 }
 
@@ -1885,7 +2017,7 @@ static void nfs_fill_super(struct super_block *sb,
        if (data->bsize)
                sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
 
-       if (server->flags & NFS_MOUNT_VER3) {
+       if (server->nfs_client->rpc_ops->version == 3) {
                /* The VFS shouldn't apply the umask to mode bits. We will do
                 * so ourselves when necessary.
                 */
@@ -1909,7 +2041,7 @@ static void nfs_clone_super(struct super_block *sb,
        sb->s_blocksize = old_sb->s_blocksize;
        sb->s_maxbytes = old_sb->s_maxbytes;
 
-       if (server->flags & NFS_MOUNT_VER3) {
+       if (server->nfs_client->rpc_ops->version == 3) {
                /* The VFS shouldn't apply the umask to mode bits. We will do
                 * so ourselves when necessary.
                 */
@@ -2043,8 +2175,8 @@ static int nfs_get_sb(struct file_system_type *fs_type,
        };
        int error = -ENOMEM;
 
-       data = kzalloc(sizeof(*data), GFP_KERNEL);
-       mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
+       data = nfs_alloc_parsed_mount_data(3);
+       mntfh = nfs_alloc_fhandle();
        if (data == NULL || mntfh == NULL)
                goto out_free_fh;
 
@@ -2055,6 +2187,15 @@ static int nfs_get_sb(struct file_system_type *fs_type,
        if (error < 0)
                goto out;
 
+#ifdef CONFIG_NFS_V4
+       if (data->version == 4) {
+               error = nfs4_try_mount(flags, dev_name, data, mnt);
+               kfree(data->client_address);
+               kfree(data->nfs_server.export_path);
+               goto out;
+       }
+#endif /* CONFIG_NFS_V4 */
+
        /* Get a volume representation */
        server = nfs_create_server(data, mntfh);
        if (IS_ERR(server)) {
@@ -2079,13 +2220,14 @@ static int nfs_get_sb(struct file_system_type *fs_type,
        } else {
                error = nfs_bdi_register(server);
                if (error)
-                       goto error_splat_super;
+                       goto error_splat_bdi;
        }
 
        if (!s->s_root) {
                /* initial superblock/root creation */
                nfs_fill_super(s, data);
-               nfs_fscache_get_super_cookie(s, data);
+               nfs_fscache_get_super_cookie(
+                       s, data ? data->fscache_uniq : NULL, NULL);
        }
 
        mntroot = nfs_get_root(s, mntfh);
@@ -2109,7 +2251,7 @@ out:
        kfree(data->fscache_uniq);
        security_free_mnt_opts(&data->lsm_opts);
 out_free_fh:
-       kfree(mntfh);
+       nfs_free_fhandle(mntfh);
        kfree(data);
        return error;
 
@@ -2120,18 +2262,31 @@ out_err_nosb:
 error_splat_root:
        dput(mntroot);
 error_splat_super:
+       if (server && !s->s_root)
+               bdi_unregister(&server->backing_dev_info);
+error_splat_bdi:
        deactivate_locked_super(s);
        goto out;
 }
 
 /*
+ * Ensure that we unregister the bdi before kill_anon_super
+ * releases the device name
+ */
+static void nfs_put_super(struct super_block *s)
+{
+       struct nfs_server *server = NFS_SB(s);
+
+       bdi_unregister(&server->backing_dev_info);
+}
+
+/*
  * Destroy an NFS2/3 superblock
  */
 static void nfs_kill_super(struct super_block *s)
 {
        struct nfs_server *server = NFS_SB(s);
 
-       bdi_unregister(&server->backing_dev_info);
        kill_anon_super(s);
        nfs_fscache_release_super_cookie(s);
        nfs_free_server(server);
@@ -2180,12 +2335,13 @@ static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
        } else {
                error = nfs_bdi_register(server);
                if (error)
-                       goto error_splat_super;
+                       goto error_splat_bdi;
        }
 
        if (!s->s_root) {
                /* initial superblock/root creation */
                nfs_clone_super(s, data->sb);
+               nfs_fscache_get_super_cookie(s, NULL, data);
        }
 
        mntroot = nfs_get_root(s, data->fh);
@@ -2216,6 +2372,9 @@ out_err_noserver:
        return error;
 
 error_splat_super:
+       if (server && !s->s_root)
+               bdi_unregister(&server->backing_dev_info);
+error_splat_bdi:
        deactivate_locked_super(s);
        dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
        return error;
@@ -2247,6 +2406,48 @@ static void nfs4_fill_super(struct super_block *sb)
        nfs_initialise_sb(sb);
 }
 
+static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
+{
+       args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3);
+}
+
+static int nfs4_validate_text_mount_data(void *options,
+                                        struct nfs_parsed_mount_data *args,
+                                        const char *dev_name)
+{
+       struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
+
+       nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
+
+       nfs_validate_transport_protocol(args);
+
+       nfs4_validate_mount_flags(args);
+
+       if (args->version != 4) {
+               dfprintk(MOUNT,
+                        "NFS4: Illegal mount version\n");
+               return -EINVAL;
+       }
+
+       if (args->auth_flavor_len > 1) {
+               dfprintk(MOUNT,
+                        "NFS4: Too many RPC auth flavours specified\n");
+               return -EINVAL;
+       }
+
+       if (args->client_address == NULL) {
+               dfprintk(MOUNT,
+                        "NFS4: mount program didn't pass callback address\n");
+               return -EINVAL;
+       }
+
+       return nfs_parse_devname(dev_name,
+                                  &args->nfs_server.hostname,
+                                  NFS4_MAXNAMLEN,
+                                  &args->nfs_server.export_path,
+                                  NFS4_MAXPATHLEN);
+}
+
 /*
  * Validate NFSv4 mount options
  */
@@ -2254,36 +2455,23 @@ static int nfs4_validate_mount_data(void *options,
                                    struct nfs_parsed_mount_data *args,
                                    const char *dev_name)
 {
-       struct sockaddr_in *ap;
+       struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
        struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
        char *c;
 
        if (data == NULL)
                goto out_no_data;
 
-       args->rsize             = NFS_MAX_FILE_IO_SIZE;
-       args->wsize             = NFS_MAX_FILE_IO_SIZE;
-       args->acregmin          = NFS_DEF_ACREGMIN;
-       args->acregmax          = NFS_DEF_ACREGMAX;
-       args->acdirmin          = NFS_DEF_ACDIRMIN;
-       args->acdirmax          = NFS_DEF_ACDIRMAX;
-       args->nfs_server.port   = NFS_PORT; /* 2049 unless user set port= */
-       args->auth_flavors[0]   = RPC_AUTH_UNIX;
-       args->auth_flavor_len   = 0;
-       args->minorversion      = 0;
-
        switch (data->version) {
        case 1:
-               ap = (struct sockaddr_in *)&args->nfs_server.address;
                if (data->host_addrlen > sizeof(args->nfs_server.address))
                        goto out_no_address;
                if (data->host_addrlen == 0)
                        goto out_no_address;
                args->nfs_server.addrlen = data->host_addrlen;
-               if (copy_from_user(ap, data->host_addr, data->host_addrlen))
+               if (copy_from_user(sap, data->host_addr, data->host_addrlen))
                        return -EFAULT;
-               if (!nfs_verify_server_address((struct sockaddr *)
-                                               &args->nfs_server.address))
+               if (!nfs_verify_server_address(sap))
                        goto out_no_address;
 
                if (data->auth_flavourlen) {
@@ -2329,37 +2517,14 @@ static int nfs4_validate_mount_data(void *options,
                nfs_validate_transport_protocol(args);
 
                break;
-       default: {
-               int status;
-
+       default:
                if (nfs_parse_mount_options((char *)options, args) == 0)
                        return -EINVAL;
 
-               if (!nfs_verify_server_address((struct sockaddr *)
-                                               &args->nfs_server.address))
+               if (!nfs_verify_server_address(sap))
                        return -EINVAL;
 
-               nfs_set_port((struct sockaddr *)&args->nfs_server.address,
-                               args->nfs_server.port);
-
-               nfs_validate_transport_protocol(args);
-
-               if (args->auth_flavor_len > 1)
-                       goto out_inval_auth;
-
-               if (args->client_address == NULL)
-                       goto out_no_client_address;
-
-               status = nfs_parse_devname(dev_name,
-                                          &args->nfs_server.hostname,
-                                          NFS4_MAXNAMLEN,
-                                          &args->nfs_server.export_path,
-                                          NFS4_MAXPATHLEN);
-               if (status < 0)
-                       return status;
-
-               break;
-               }
+               return nfs4_validate_text_mount_data(options, args, dev_name);
        }
 
        return 0;
@@ -2376,19 +2541,15 @@ out_inval_auth:
 out_no_address:
        dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
        return -EINVAL;
-
-out_no_client_address:
-       dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
-       return -EINVAL;
 }
 
 /*
- * Get the superblock for an NFS4 mountpoint
+ * Get the superblock for the NFS4 root partition
  */
-static int nfs4_get_sb(struct file_system_type *fs_type,
+static int nfs4_remote_get_sb(struct file_system_type *fs_type,
        int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
 {
-       struct nfs_parsed_mount_data *data;
+       struct nfs_parsed_mount_data *data = raw_data;
        struct super_block *s;
        struct nfs_server *server;
        struct nfs_fh *mntfh;
@@ -2399,18 +2560,12 @@ static int nfs4_get_sb(struct file_system_type *fs_type,
        };
        int error = -ENOMEM;
 
-       data = kzalloc(sizeof(*data), GFP_KERNEL);
-       mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
+       mntfh = nfs_alloc_fhandle();
        if (data == NULL || mntfh == NULL)
                goto out_free_fh;
 
        security_init_mnt_opts(&data->lsm_opts);
 
-       /* Validate the mount data */
-       error = nfs4_validate_mount_data(raw_data, data, dev_name);
-       if (error < 0)
-               goto out;
-
        /* Get a volume representation */
        server = nfs4_create_server(data, mntfh);
        if (IS_ERR(server)) {
@@ -2423,7 +2578,7 @@ static int nfs4_get_sb(struct file_system_type *fs_type,
                compare_super = NULL;
 
        /* Get a superblock - note that we may end up sharing one that already exists */
-       s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
+       s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
        if (IS_ERR(s)) {
                error = PTR_ERR(s);
                goto out_free;
@@ -2435,13 +2590,14 @@ static int nfs4_get_sb(struct file_system_type *fs_type,
        } else {
                error = nfs_bdi_register(server);
                if (error)
-                       goto error_splat_super;
+                       goto error_splat_bdi;
        }
 
        if (!s->s_root) {
                /* initial superblock/root creation */
                nfs4_fill_super(s);
-               nfs_fscache_get_super_cookie(s, data);
+               nfs_fscache_get_super_cookie(
+                       s, data ? data->fscache_uniq : NULL, NULL);
        }
 
        mntroot = nfs4_get_root(s, mntfh);
@@ -2460,14 +2616,9 @@ static int nfs4_get_sb(struct file_system_type *fs_type,
        error = 0;
 
 out:
-       kfree(data->client_address);
-       kfree(data->nfs_server.export_path);
-       kfree(data->nfs_server.hostname);
-       kfree(data->fscache_uniq);
        security_free_mnt_opts(&data->lsm_opts);
 out_free_fh:
-       kfree(mntfh);
-       kfree(data);
+       nfs_free_fhandle(mntfh);
        return error;
 
 out_free:
@@ -2477,10 +2628,228 @@ out_free:
 error_splat_root:
        dput(mntroot);
 error_splat_super:
+       if (server && !s->s_root)
+               bdi_unregister(&server->backing_dev_info);
+error_splat_bdi:
        deactivate_locked_super(s);
        goto out;
 }
 
+static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
+               int flags, void *data, const char *hostname)
+{
+       struct vfsmount *root_mnt;
+       char *root_devname;
+       size_t len;
+
+       len = strlen(hostname) + 3;
+       root_devname = kmalloc(len, GFP_KERNEL);
+       if (root_devname == NULL)
+               return ERR_PTR(-ENOMEM);
+       snprintf(root_devname, len, "%s:/", hostname);
+       root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
+       kfree(root_devname);
+       return root_mnt;
+}
+
+static void nfs_fix_devname(const struct path *path, struct vfsmount *mnt)
+{
+       char *page = (char *) __get_free_page(GFP_KERNEL);
+       char *devname, *tmp;
+
+       if (page == NULL)
+               return;
+       devname = nfs_path(path->mnt->mnt_devname,
+                       path->mnt->mnt_root, path->dentry,
+                       page, PAGE_SIZE);
+       if (IS_ERR(devname))
+               goto out_freepage;
+       tmp = kstrdup(devname, GFP_KERNEL);
+       if (tmp == NULL)
+               goto out_freepage;
+       kfree(mnt->mnt_devname);
+       mnt->mnt_devname = tmp;
+out_freepage:
+       free_page((unsigned long)page);
+}
+
+struct nfs_referral_count {
+       struct list_head list;
+       const struct task_struct *task;
+       unsigned int referral_count;
+};
+
+static LIST_HEAD(nfs_referral_count_list);
+static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
+
+static struct nfs_referral_count *nfs_find_referral_count(void)
+{
+       struct nfs_referral_count *p;
+
+       list_for_each_entry(p, &nfs_referral_count_list, list) {
+               if (p->task == current)
+                       return p;
+       }
+       return NULL;
+}
+
+#define NFS_MAX_NESTED_REFERRALS 2
+
+static int nfs_referral_loop_protect(void)
+{
+       struct nfs_referral_count *p, *new;
+       int ret = -ENOMEM;
+
+       new = kmalloc(sizeof(*new), GFP_KERNEL);
+       if (!new)
+               goto out;
+       new->task = current;
+       new->referral_count = 1;
+
+       ret = 0;
+       spin_lock(&nfs_referral_count_list_lock);
+       p = nfs_find_referral_count();
+       if (p != NULL) {
+               if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
+                       ret = -ELOOP;
+               else
+                       p->referral_count++;
+       } else {
+               list_add(&new->list, &nfs_referral_count_list);
+               new = NULL;
+       }
+       spin_unlock(&nfs_referral_count_list_lock);
+       kfree(new);
+out:
+       return ret;
+}
+
+static void nfs_referral_loop_unprotect(void)
+{
+       struct nfs_referral_count *p;
+
+       spin_lock(&nfs_referral_count_list_lock);
+       p = nfs_find_referral_count();
+       p->referral_count--;
+       if (p->referral_count == 0)
+               list_del(&p->list);
+       else
+               p = NULL;
+       spin_unlock(&nfs_referral_count_list_lock);
+       kfree(p);
+}
+
+static int nfs_follow_remote_path(struct vfsmount *root_mnt,
+               const char *export_path, struct vfsmount *mnt_target)
+{
+       struct nameidata *nd = NULL;
+       struct mnt_namespace *ns_private;
+       struct super_block *s;
+       int ret;
+
+       nd = kmalloc(sizeof(*nd), GFP_KERNEL);
+       if (nd == NULL)
+               return -ENOMEM;
+
+       ns_private = create_mnt_ns(root_mnt);
+       ret = PTR_ERR(ns_private);
+       if (IS_ERR(ns_private))
+               goto out_mntput;
+
+       ret = nfs_referral_loop_protect();
+       if (ret != 0)
+               goto out_put_mnt_ns;
+
+       ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
+                       export_path, LOOKUP_FOLLOW, nd);
+
+       nfs_referral_loop_unprotect();
+       put_mnt_ns(ns_private);
+
+       if (ret != 0)
+               goto out_err;
+
+       s = nd->path.mnt->mnt_sb;
+       atomic_inc(&s->s_active);
+       mnt_target->mnt_sb = s;
+       mnt_target->mnt_root = dget(nd->path.dentry);
+
+       /* Correct the device pathname */
+       nfs_fix_devname(&nd->path, mnt_target);
+
+       path_put(&nd->path);
+       kfree(nd);
+       down_write(&s->s_umount);
+       return 0;
+out_put_mnt_ns:
+       put_mnt_ns(ns_private);
+out_mntput:
+       mntput(root_mnt);
+out_err:
+       kfree(nd);
+       return ret;
+}
+
+static int nfs4_try_mount(int flags, const char *dev_name,
+                        struct nfs_parsed_mount_data *data,
+                        struct vfsmount *mnt)
+{
+       char *export_path;
+       struct vfsmount *root_mnt;
+       int error;
+
+       dfprintk(MOUNT, "--> nfs4_try_mount()\n");
+
+       export_path = data->nfs_server.export_path;
+       data->nfs_server.export_path = "/";
+       root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
+                       data->nfs_server.hostname);
+       data->nfs_server.export_path = export_path;
+
+       error = PTR_ERR(root_mnt);
+       if (IS_ERR(root_mnt))
+               goto out;
+
+       error = nfs_follow_remote_path(root_mnt, export_path, mnt);
+
+out:
+       dfprintk(MOUNT, "<-- nfs4_try_mount() = %d%s\n", error,
+                       error != 0 ? " [error]" : "");
+       return error;
+}
+
+/*
+ * Get the superblock for an NFS4 mountpoint
+ */
+static int nfs4_get_sb(struct file_system_type *fs_type,
+       int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
+{
+       struct nfs_parsed_mount_data *data;
+       int error = -ENOMEM;
+
+       data = nfs_alloc_parsed_mount_data(4);
+       if (data == NULL)
+               goto out_free_data;
+
+       /* Validate the mount data */
+       error = nfs4_validate_mount_data(raw_data, data, dev_name);
+       if (error < 0)
+               goto out;
+
+       error = nfs4_try_mount(flags, dev_name, data, mnt);
+
+out:
+       kfree(data->client_address);
+       kfree(data->nfs_server.export_path);
+       kfree(data->nfs_server.hostname);
+       kfree(data->fscache_uniq);
+out_free_data:
+       kfree(data);
+       dprintk("<-- nfs4_get_sb() = %d%s\n", error,
+                       error != 0 ? " [error]" : "");
+       return error;
+}
+
 static void nfs4_kill_super(struct super_block *sb)
 {
        struct nfs_server *server = NFS_SB(sb);
@@ -2488,7 +2857,6 @@ static void nfs4_kill_super(struct super_block *sb)
        dprintk("--> %s\n", __func__);
        nfs_super_return_all_delegations(sb);
        kill_anon_super(sb);
-       nfs4_renewd_prepare_shutdown(server);
        nfs_fscache_release_super_cookie(sb);
        nfs_free_server(server);
        dprintk("<-- %s\n", __func__);
@@ -2537,12 +2905,13 @@ static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
        } else {
                error = nfs_bdi_register(server);
                if (error)
-                       goto error_splat_super;
+                       goto error_splat_bdi;
        }
 
        if (!s->s_root) {
                /* initial superblock/root creation */
                nfs4_clone_super(s, data->sb);
+               nfs_fscache_get_super_cookie(s, NULL, data);
        }
 
        mntroot = nfs4_get_root(s, data->fh);
@@ -2572,33 +2941,37 @@ out_err_noserver:
        return error;
 
 error_splat_super:
+       if (server && !s->s_root)
+               bdi_unregister(&server->backing_dev_info);
+error_splat_bdi:
        deactivate_locked_super(s);
        dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
        return error;
 }
 
-/*
- * Create an NFS4 server record on referral traversal
- */
-static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
-                               const char *dev_name, void *raw_data,
-                               struct vfsmount *mnt)
+static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
+               int flags, const char *dev_name, void *raw_data,
+               struct vfsmount *mnt)
 {
        struct nfs_clone_mount *data = raw_data;
        struct super_block *s;
        struct nfs_server *server;
        struct dentry *mntroot;
-       struct nfs_fh mntfh;
+       struct nfs_fh *mntfh;
        int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
        struct nfs_sb_mountdata sb_mntdata = {
                .mntflags = flags,
        };
-       int error;
+       int error = -ENOMEM;
 
        dprintk("--> nfs4_referral_get_sb()\n");
 
+       mntfh = nfs_alloc_fhandle();
+       if (mntfh == NULL)
+               goto out_err_nofh;
+
        /* create a new volume representation */
-       server = nfs4_create_referral_server(data, &mntfh);
+       server = nfs4_create_referral_server(data, mntfh);
        if (IS_ERR(server)) {
                error = PTR_ERR(server);
                goto out_err_noserver;
@@ -2621,15 +2994,16 @@ static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
        } else {
                error = nfs_bdi_register(server);
                if (error)
-                       goto error_splat_super;
+                       goto error_splat_bdi;
        }
 
        if (!s->s_root) {
                /* initial superblock/root creation */
                nfs4_fill_super(s);
+               nfs_fscache_get_super_cookie(s, NULL, data);
        }
 
-       mntroot = nfs4_get_root(s, &mntfh);
+       mntroot = nfs4_get_root(s, mntfh);
        if (IS_ERR(mntroot)) {
                error = PTR_ERR(mntroot);
                goto error_splat_super;
@@ -2646,19 +3020,58 @@ static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
 
        security_sb_clone_mnt_opts(data->sb, s);
 
+       nfs_free_fhandle(mntfh);
        dprintk("<-- nfs4_referral_get_sb() = 0\n");
        return 0;
 
 out_err_nosb:
        nfs_free_server(server);
 out_err_noserver:
+       nfs_free_fhandle(mntfh);
+out_err_nofh:
        dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
        return error;
 
 error_splat_super:
+       if (server && !s->s_root)
+               bdi_unregister(&server->backing_dev_info);
+error_splat_bdi:
        deactivate_locked_super(s);
+       nfs_free_fhandle(mntfh);
        dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
        return error;
 }
 
+/*
+ * Create an NFS4 server record on referral traversal
+ */
+static int nfs4_referral_get_sb(struct file_system_type *fs_type,
+               int flags, const char *dev_name, void *raw_data,
+               struct vfsmount *mnt)
+{
+       struct nfs_clone_mount *data = raw_data;
+       char *export_path;
+       struct vfsmount *root_mnt;
+       int error;
+
+       dprintk("--> nfs4_referral_get_sb()\n");
+
+       export_path = data->mnt_path;
+       data->mnt_path = "/";
+
+       root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
+                       flags, data, data->hostname);
+       data->mnt_path = export_path;
+
+       error = PTR_ERR(root_mnt);
+       if (IS_ERR(root_mnt))
+               goto out;
+
+       error = nfs_follow_remote_path(root_mnt, export_path, mnt);
+out:
+       dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error,
+                       error != 0 ? " [error]" : "");
+       return error;
+}
+
 #endif /* CONFIG_NFS_V4 */