NFS: Add timeout to submounts
[deliverable/linux.git] / fs / nfs / inode.c
index 2f7656b911b66df6f03a96561c2f03534ffa4241..3eea556d8f59274abe631527b4aa1c05bcdf60a6 100644 (file)
@@ -62,9 +62,8 @@ static int nfs_update_inode(struct inode *, struct nfs_fattr *);
 static struct inode *nfs_alloc_inode(struct super_block *sb);
 static void nfs_destroy_inode(struct inode *);
 static int nfs_write_inode(struct inode *,int);
-static void nfs_delete_inode(struct inode *);
 static void nfs_clear_inode(struct inode *);
-static void nfs_umount_begin(struct super_block *);
+static void nfs_umount_begin(struct vfsmount *, int);
 static int  nfs_statfs(struct super_block *, struct kstatfs *);
 static int  nfs_show_options(struct seq_file *, struct vfsmount *);
 static int  nfs_show_stats(struct seq_file *, struct vfsmount *);
@@ -76,7 +75,6 @@ static struct super_operations nfs_sops = {
        .alloc_inode    = nfs_alloc_inode,
        .destroy_inode  = nfs_destroy_inode,
        .write_inode    = nfs_write_inode,
-       .delete_inode   = nfs_delete_inode,
        .statfs         = nfs_statfs,
        .clear_inode    = nfs_clear_inode,
        .umount_begin   = nfs_umount_begin,
@@ -146,31 +144,16 @@ nfs_write_inode(struct inode *inode, int sync)
        return 0;
 }
 
-static void
-nfs_delete_inode(struct inode * inode)
-{
-       dprintk("NFS: delete_inode(%s/%ld)\n", inode->i_sb->s_id, inode->i_ino);
-
-       truncate_inode_pages(&inode->i_data, 0);
-
-       nfs_wb_all(inode);
-       /*
-        * The following should never happen...
-        */
-       if (nfs_have_writebacks(inode)) {
-               printk(KERN_ERR "nfs_delete_inode: inode %ld has pending RPC requests\n", inode->i_ino);
-       }
-
-       clear_inode(inode);
-}
-
 static void
 nfs_clear_inode(struct inode *inode)
 {
        struct nfs_inode *nfsi = NFS_I(inode);
        struct rpc_cred *cred;
 
-       nfs_wb_all(inode);
+       /*
+        * The following should never happen...
+        */
+       BUG_ON(nfs_have_writebacks(inode));
        BUG_ON (!list_empty(&nfsi->open_files));
        nfs_zap_acl_cache(inode);
        cred = nfsi->cache_access.cred;
@@ -179,15 +162,20 @@ nfs_clear_inode(struct inode *inode)
        BUG_ON(atomic_read(&nfsi->data_updates) != 0);
 }
 
-void
-nfs_umount_begin(struct super_block *sb)
+static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
 {
-       struct rpc_clnt *rpc = NFS_SB(sb)->client;
+       struct nfs_server *server;
+       struct rpc_clnt *rpc;
 
+       shrink_submounts(vfsmnt, &nfs_automount_list);
+       if (!(flags & MNT_FORCE))
+               return;
        /* -EIO all pending I/O */
+       server = NFS_SB(vfsmnt->mnt_sb);
+       rpc = server->client;
        if (!IS_ERR(rpc))
                rpc_killall_tasks(rpc);
-       rpc = NFS_SB(sb)->client_acl;
+       rpc = server->client_acl;
        if (!IS_ERR(rpc))
                rpc_killall_tasks(rpc);
 }
@@ -234,6 +222,14 @@ nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
        return nfs_block_bits(bsize, nrbitsp);
 }
 
+static inline void
+nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
+{
+       sb->s_maxbytes = (loff_t)maxfilesize;
+       if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
+               sb->s_maxbytes = MAX_LFS_FILESIZE;
+}
+
 /*
  * Obtain the root inode of the file system.
  */
@@ -249,6 +245,7 @@ nfs_get_root(struct super_block *sb, struct nfs_fh *rootfh, struct nfs_fsinfo *f
                return ERR_PTR(error);
        }
 
+       server->fsid = fsinfo->fattr->fsid;
        return nfs_fhget(sb, rootfh, fsinfo->fattr);
 }
 
@@ -343,9 +340,7 @@ nfs_sb_init(struct super_block *sb, rpc_authflavor_t authflavor)
        }
        server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD;
 
-       sb->s_maxbytes = fsinfo.maxfilesize;
-       if (sb->s_maxbytes > MAX_LFS_FILESIZE) 
-               sb->s_maxbytes = MAX_LFS_FILESIZE; 
+       nfs_super_set_maxbytes(sb, fsinfo.maxfilesize);
 
        server->client->cl_intr = (server->flags & NFS_MOUNT_INTR) ? 1 : 0;
        server->client->cl_softrtry = (server->flags & NFS_MOUNT_SOFT) ? 1 : 0;
@@ -700,12 +695,9 @@ static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
        /*
         * Display superblock I/O counters
         */
-       for (cpu = 0; cpu < NR_CPUS; cpu++) {
+       for_each_possible_cpu(cpu) {
                struct nfs_iostats *stats;
 
-               if (!cpu_possible(cpu))
-                       continue;
-
                preempt_disable();
                stats = per_cpu_ptr(nfss->io_stats, cpu);
 
@@ -892,6 +884,11 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
                        if (nfs_server_capable(inode, NFS_CAP_READDIRPLUS)
                            && fattr->size <= NFS_LIMIT_READDIRPLUS)
                                set_bit(NFS_INO_ADVISE_RDPLUS, &NFS_FLAGS(inode));
+                       /* Deal with crossing mountpoints */
+                       if (!nfs_fsid_equal(&NFS_SB(sb)->fsid, &fattr->fsid)) {
+                               inode->i_op = &nfs_mountpoint_inode_operations;
+                               inode->i_fop = NULL;
+                       }
                } else if (S_ISLNK(inode->i_mode))
                        inode->i_op = &nfs_symlink_inode_operations;
                else
@@ -1210,6 +1207,7 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
        dfprintk(PAGECACHE, "NFS: revalidating (%s/%Ld)\n",
                inode->i_sb->s_id, (long long)NFS_FILEID(inode));
 
+       nfs_inc_stats(inode, NFSIOS_INODEREVALIDATE);
        lock_kernel();
        if (!inode || is_bad_inode(inode))
                goto out_nowait;
@@ -1223,7 +1221,7 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
                status = -ESTALE;
                /* Do we trust the cached ESTALE? */
                if (NFS_ATTRTIMEO(inode) != 0) {
-                       if (nfsi->cache_validity & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ATIME)) {
+                       if (nfsi->cache_validity & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ATIME)) {
                                /* no */
                        } else
                                goto out;
@@ -1254,8 +1252,6 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
        }
        spin_unlock(&inode->i_lock);
 
-       nfs_revalidate_mapping(inode, inode->i_mapping);
-
        if (nfsi->cache_validity & NFS_INO_INVALID_ACL)
                nfs_zap_acl_cache(inode);
 
@@ -1289,8 +1285,7 @@ int nfs_attribute_timeout(struct inode *inode)
  */
 int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
 {
-       nfs_inc_stats(inode, NFSIOS_INODEREVALIDATE);
-       if (!(NFS_I(inode)->cache_validity & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA))
+       if (!(NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATTR)
                        && !nfs_attribute_timeout(inode))
                return NFS_STALE(inode) ? -ESTALE : 0;
        return __nfs_revalidate_inode(server, inode);
@@ -1301,9 +1296,16 @@ int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
  * @inode - pointer to host inode
  * @mapping - pointer to mapping
  */
-void nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
+int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
 {
        struct nfs_inode *nfsi = NFS_I(inode);
+       int ret = 0;
+
+       if (NFS_STALE(inode))
+               ret = -ESTALE;
+       if ((nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
+                       || nfs_attribute_timeout(inode))
+               ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
 
        if (nfsi->cache_validity & NFS_INO_INVALID_DATA) {
                nfs_inc_stats(inode, NFSIOS_DATAINVALIDATE);
@@ -1324,6 +1326,7 @@ void nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
                                inode->i_sb->s_id,
                                (long long)NFS_FILEID(inode));
        }
+       return ret;
 }
 
 /**
@@ -1363,12 +1366,6 @@ static void nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
 {
        struct nfs_inode *nfsi = NFS_I(inode);
 
-       if ((fattr->valid & NFS_ATTR_PRE_CHANGE) != 0
-                       && nfsi->change_attr == fattr->pre_change_attr) {
-               nfsi->change_attr = fattr->change_attr;
-               nfsi->cache_change_attribute = jiffies;
-       }
-
        /* If we have atomic WCC data, we may update some attributes */
        if ((fattr->valid & NFS_ATTR_WCC) != 0) {
                if (timespec_equal(&inode->i_ctime, &fattr->pre_ctime)) {
@@ -1402,9 +1399,6 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
        int data_unstable;
 
 
-       if ((fattr->valid & NFS_ATTR_FATTR) == 0)
-               return 0;
-
        /* Has the inode gone and changed behind our back? */
        if (nfsi->fileid != fattr->fileid
                        || (inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT)) {
@@ -1417,20 +1411,13 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
        /* Do atomic weak cache consistency updates */
        nfs_wcc_update_inode(inode, fattr);
 
-       if ((fattr->valid & NFS_ATTR_FATTR_V4) != 0) {
-               if (nfsi->change_attr == fattr->change_attr)
-                       goto out;
-               nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
-               if (!data_unstable)
-                       nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE;
-       }
+       if ((fattr->valid & NFS_ATTR_FATTR_V4) != 0 &&
+                       nfsi->change_attr != fattr->change_attr)
+               nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
 
        /* Verify a few of the more important attributes */
-       if (!timespec_equal(&inode->i_mtime, &fattr->mtime)) {
-               nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
-               if (!data_unstable)
-                       nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE;
-       }
+       if (!timespec_equal(&inode->i_mtime, &fattr->mtime))
+               nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
 
        cur_size = i_size_read(inode);
        new_isize = nfs_size_to_loff_t(fattr->size);
@@ -1447,7 +1434,6 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
        if (inode->i_nlink != fattr->nlink)
                nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
 
-out:
        if (!timespec_equal(&inode->i_atime, &fattr->atime))
                nfsi->cache_validity |= NFS_INO_INVALID_ATIME;
 
@@ -1473,7 +1459,6 @@ int nfs_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)
        if ((fattr->valid & NFS_ATTR_FATTR) == 0)
                return 0;
        spin_lock(&inode->i_lock);
-       nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE;
        if (time_after(fattr->time_start, nfsi->last_updated))
                status = nfs_update_inode(inode, fattr);
        else
@@ -1498,7 +1483,7 @@ int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr)
 
        spin_lock(&inode->i_lock);
        if (unlikely((fattr->valid & NFS_ATTR_FATTR) == 0)) {
-               nfsi->cache_validity |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS;
+               nfsi->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
                goto out;
        }
        status = nfs_update_inode(inode, fattr);
@@ -1521,6 +1506,7 @@ out:
  */
 static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
 {
+       struct nfs_server *server;
        struct nfs_inode *nfsi = NFS_I(inode);
        loff_t cur_isize, new_isize;
        unsigned int    invalid = 0;
@@ -1530,9 +1516,6 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
                        __FUNCTION__, inode->i_sb->s_id, inode->i_ino,
                        atomic_read(&inode->i_count), fattr->valid);
 
-       if ((fattr->valid & NFS_ATTR_FATTR) == 0)
-               return 0;
-
        if (nfsi->fileid != fattr->fileid)
                goto out_fileid;
 
@@ -1542,6 +1525,12 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
        if ((inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT))
                goto out_changed;
 
+       server = NFS_SERVER(inode);
+       /* Update the fsid if and only if this is the root directory */
+       if (inode == inode->i_sb->s_root->d_inode
+                       && !nfs_fsid_equal(&server->fsid, &fattr->fsid))
+               server->fsid = fattr->fsid;
+
        /*
         * Update the read time so we don't revalidate too often.
         */
@@ -1551,7 +1540,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
        /* Are we racing with known updates of the metadata on the server? */
        data_stable = nfs_verify_change_attribute(inode, fattr->time_start);
        if (data_stable)
-               nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ATIME);
+               nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_ATIME);
 
        /* Do atomic weak cache consistency updates */
        nfs_wcc_update_inode(inode, fattr);
@@ -1615,15 +1604,13 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
                inode->i_blksize = fattr->du.nfs2.blocksize;
        }
 
-       if ((fattr->valid & NFS_ATTR_FATTR_V4)) {
-               if (nfsi->change_attr != fattr->change_attr) {
-                       dprintk("NFS: change_attr change on server for file %s/%ld\n",
-                                       inode->i_sb->s_id, inode->i_ino);
-                       nfsi->change_attr = fattr->change_attr;
-                       invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
-                       nfsi->cache_change_attribute = jiffies;
-               } else
-                       invalid &= ~(NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA);
+       if ((fattr->valid & NFS_ATTR_FATTR_V4) != 0 &&
+                       nfsi->change_attr != fattr->change_attr) {
+               dprintk("NFS: change_attr change on server for file %s/%ld\n",
+                               inode->i_sb->s_id, inode->i_ino);
+               nfsi->change_attr = fattr->change_attr;
+               invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
+               nfsi->cache_change_attribute = jiffies;
        }
 
        /* Update attrtimeo value if we're out of the unstable period */
@@ -1675,6 +1662,141 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
  * File system information
  */
 
+/*
+ * nfs_path - reconstruct the path given an arbitrary dentry
+ * @base - arbitrary string to prepend to the path
+ * @dentry - pointer to dentry
+ * @buffer - result buffer
+ * @buflen - length of buffer
+ *
+ * Helper function for constructing the path from the
+ * root dentry to an arbitrary hashed dentry.
+ *
+ * This is mainly for use in figuring out the path on the
+ * server side when automounting on top of an existing partition.
+ */
+static char *nfs_path(const char *base, const struct dentry *dentry,
+                     char *buffer, ssize_t buflen)
+{
+       char *end = buffer+buflen;
+       int namelen;
+
+       *--end = '\0';
+       buflen--;
+       spin_lock(&dcache_lock);
+       while (!IS_ROOT(dentry)) {
+               namelen = dentry->d_name.len;
+               buflen -= namelen + 1;
+               if (buflen < 0)
+                       goto Elong;
+               end -= namelen;
+               memcpy(end, dentry->d_name.name, namelen);
+               *--end = '/';
+               dentry = dentry->d_parent;
+       }
+       spin_unlock(&dcache_lock);
+       namelen = strlen(base);
+       /* Strip off excess slashes in base string */
+       while (namelen > 0 && base[namelen - 1] == '/')
+               namelen--;
+       buflen -= namelen;
+       if (buflen < 0)
+               goto Elong;
+       end -= namelen;
+       memcpy(end, base, namelen);
+       return end;
+Elong:
+       return ERR_PTR(-ENAMETOOLONG);
+}
+
+struct nfs_clone_mount {
+       const struct super_block *sb;
+       const struct dentry *dentry;
+       struct nfs_fh *fh;
+       struct nfs_fattr *fattr;
+};
+
+static struct super_block *nfs_clone_generic_sb(struct nfs_clone_mount *data,
+               struct super_block *(*clone_client)(struct nfs_server *, struct nfs_clone_mount *))
+{
+       struct nfs_server *server;
+       struct nfs_server *parent = NFS_SB(data->sb);
+       struct super_block *sb = ERR_PTR(-EINVAL);
+       void *err = ERR_PTR(-ENOMEM);
+       struct inode *root_inode;
+       struct nfs_fsinfo fsinfo;
+       int len;
+
+       server = kmalloc(sizeof(struct nfs_server), GFP_KERNEL);
+       if (server == NULL)
+               goto out_err;
+       memcpy(server, parent, sizeof(*server));
+       len = strlen(parent->hostname) + 1;
+       server->hostname = kmalloc(len, GFP_KERNEL);
+       if (server->hostname == NULL)
+               goto free_server;
+       memcpy(server->hostname, parent->hostname, len);
+       server->fsid = data->fattr->fsid;
+       nfs_copy_fh(&server->fh, data->fh);
+       if (rpciod_up() != 0)
+               goto free_hostname;
+
+       sb = clone_client(server, data);
+       if (IS_ERR((err = sb)) || sb->s_root)
+               goto kill_rpciod;
+
+       sb->s_op = data->sb->s_op;
+       sb->s_blocksize = data->sb->s_blocksize;
+       sb->s_blocksize_bits = data->sb->s_blocksize_bits;
+       sb->s_maxbytes = data->sb->s_maxbytes;
+
+       server->client_sys = server->client_acl = ERR_PTR(-EINVAL);
+       err = ERR_PTR(-ENOMEM);
+       server->io_stats = nfs_alloc_iostats();
+       if (server->io_stats == NULL)
+               goto out_deactivate;
+
+       server->client = rpc_clone_client(parent->client);
+       if (IS_ERR((err = server->client)))
+               goto out_deactivate;
+       if (!IS_ERR(parent->client_sys)) {
+               server->client_sys = rpc_clone_client(parent->client_sys);
+               if (IS_ERR((err = server->client_sys)))
+                       goto out_deactivate;
+       }
+       if (!IS_ERR(parent->client_acl)) {
+               server->client_acl = rpc_clone_client(parent->client_acl);
+               if (IS_ERR((err = server->client_acl)))
+                       goto out_deactivate;
+       }
+       root_inode = nfs_fhget(sb, data->fh, data->fattr);
+       if (!root_inode)
+               goto out_deactivate;
+       sb->s_root = d_alloc_root(root_inode);
+       if (!sb->s_root)
+               goto out_put_root;
+       fsinfo.fattr = data->fattr;
+       if (NFS_PROTO(root_inode)->fsinfo(server, data->fh, &fsinfo) == 0)
+               nfs_super_set_maxbytes(sb, fsinfo.maxfilesize);
+       sb->s_root->d_op = server->rpc_ops->dentry_ops;
+       sb->s_flags |= MS_ACTIVE;
+       return sb;
+out_put_root:
+       iput(root_inode);
+out_deactivate:
+       up_write(&sb->s_umount);
+       deactivate_super(sb);
+       return (struct super_block *)err;
+kill_rpciod:
+       rpciod_down();
+free_hostname:
+       kfree(server->hostname);
+free_server:
+       kfree(server);
+out_err:
+       return (struct super_block *)err;
+}
+
 static int nfs_set_super(struct super_block *s, void *data)
 {
        s->s_fs_info = data;
@@ -1822,6 +1944,7 @@ static void nfs_kill_super(struct super_block *s)
        nfs_free_iostats(server->io_stats);
        kfree(server->hostname);
        kfree(server);
+       nfs_release_automount_timer();
 }
 
 static struct file_system_type nfs_fs_type = {
@@ -1832,6 +1955,31 @@ static struct file_system_type nfs_fs_type = {
        .fs_flags       = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
 };
 
+static struct super_block *nfs_clone_client(struct nfs_server *server, struct nfs_clone_mount *data)
+{
+       struct super_block *sb;
+
+       sb = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
+       if (!IS_ERR(sb) && sb->s_root == NULL && !(server->flags & NFS_MOUNT_NONLM))
+               lockd_up();
+       return sb;
+}
+
+static struct super_block *nfs_clone_nfs_sb(struct file_system_type *fs_type,
+               int flags, const char *dev_name, void *raw_data)
+{
+       struct nfs_clone_mount *data = raw_data;
+       return nfs_clone_generic_sb(data, nfs_clone_client);
+}
+
+static struct file_system_type clone_nfs_fs_type = {
+       .owner          = THIS_MODULE,
+       .name           = "nfs",
+       .get_sb         = nfs_clone_nfs_sb,
+       .kill_sb        = nfs_kill_super,
+       .fs_flags       = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
+};
+
 #ifdef CONFIG_NFS_V4
 
 static void nfs4_clear_inode(struct inode *);
@@ -1841,7 +1989,6 @@ static struct super_operations nfs4_sops = {
        .alloc_inode    = nfs_alloc_inode,
        .destroy_inode  = nfs_destroy_inode,
        .write_inode    = nfs_write_inode,
-       .delete_inode   = nfs_delete_inode,
        .statfs         = nfs_statfs,
        .clear_inode    = nfs4_clear_inode,
        .umount_begin   = nfs_umount_begin,
@@ -2143,6 +2290,7 @@ static void nfs4_kill_super(struct super_block *sb)
        nfs_free_iostats(server->io_stats);
        kfree(server->hostname);
        kfree(server);
+       nfs_release_automount_timer();
 }
 
 static struct file_system_type nfs4_fs_type = {
@@ -2182,6 +2330,75 @@ static int param_set_idmap_timeout(const char *val, struct kernel_param *kp)
 module_param_call(idmap_cache_timeout, param_set_idmap_timeout, param_get_int,
                 &nfs_idmap_cache_timeout, 0644);
 
+/* Constructs the SERVER-side path */
+static inline char *nfs4_path(const struct dentry *dentry, char *buffer, ssize_t buflen)
+{
+       return nfs_path(NFS_SB(dentry->d_sb)->mnt_path, dentry, buffer, buflen);
+}
+
+static inline char *nfs4_dup_path(const struct dentry *dentry)
+{
+       char *page = (char *) __get_free_page(GFP_USER);
+       char *path;
+
+       path = nfs4_path(dentry, page, PAGE_SIZE);
+       if (!IS_ERR(path)) {
+               int len = PAGE_SIZE + page - path;
+               char *tmp = path;
+
+               path = kmalloc(len, GFP_KERNEL);
+               if (path)
+                       memcpy(path, tmp, len);
+               else
+                       path = ERR_PTR(-ENOMEM);
+       }
+       free_page((unsigned long)page);
+       return path;
+}
+
+static struct super_block *nfs4_clone_client(struct nfs_server *server, struct nfs_clone_mount *data)
+{
+       const struct dentry *dentry = data->dentry;
+       struct nfs4_client *clp = server->nfs4_state;
+       struct super_block *sb;
+
+       server->mnt_path = nfs4_dup_path(dentry);
+       if (IS_ERR(server->mnt_path)) {
+               sb = (struct super_block *)server->mnt_path;
+               goto err;
+       }
+       sb = sget(&nfs4_fs_type, nfs4_compare_super, nfs_set_super, server);
+       if (IS_ERR(sb) || sb->s_root)
+               goto free_path;
+       nfs4_server_capabilities(server, &server->fh);
+
+       down_write(&clp->cl_sem);
+       atomic_inc(&clp->cl_count);
+       list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks);
+       up_write(&clp->cl_sem);
+       return sb;
+free_path:
+       kfree(server->mnt_path);
+err:
+       server->mnt_path = NULL;
+       return sb;
+}
+
+static struct super_block *nfs_clone_nfs4_sb(struct file_system_type *fs_type,
+               int flags, const char *dev_name, void *raw_data)
+{
+       struct nfs_clone_mount *data = raw_data;
+       return nfs_clone_generic_sb(data, nfs4_clone_client);
+}
+
+static struct file_system_type clone_nfs4_fs_type = {
+       .owner          = THIS_MODULE,
+       .name           = "nfs",
+       .get_sb         = nfs_clone_nfs4_sb,
+       .kill_sb        = nfs4_kill_super,
+       .fs_flags       = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
+};
+
 #define nfs4_init_once(nfsi) \
        do { \
                INIT_LIST_HEAD(&(nfsi)->open_states); \
@@ -2209,12 +2426,69 @@ static inline void unregister_nfs4fs(void)
        nfs_unregister_sysctl();
 }
 #else
+#define nfs4_clone_client(a,b) ERR_PTR(-EINVAL)
 #define nfs4_init_once(nfsi) \
        do { } while (0)
 #define register_nfs4fs() (0)
 #define unregister_nfs4fs()
 #endif
 
+static inline char *nfs_devname(const struct vfsmount *mnt_parent,
+                        const struct dentry *dentry,
+                        char *buffer, ssize_t buflen)
+{
+       return nfs_path(mnt_parent->mnt_devname, dentry, buffer, buflen);
+}
+
+/**
+ * nfs_do_submount - set up mountpoint when crossing a filesystem boundary
+ * @mnt_parent - mountpoint of parent directory
+ * @dentry - parent directory
+ * @fh - filehandle for new root dentry
+ * @fattr - attributes for new root inode
+ *
+ */
+struct vfsmount *nfs_do_submount(const struct vfsmount *mnt_parent,
+               const struct dentry *dentry, struct nfs_fh *fh,
+               struct nfs_fattr *fattr)
+{
+       struct nfs_clone_mount mountdata = {
+               .sb = mnt_parent->mnt_sb,
+               .dentry = dentry,
+               .fh = fh,
+               .fattr = fattr,
+       };
+       struct vfsmount *mnt = ERR_PTR(-ENOMEM);
+       char *page = (char *) __get_free_page(GFP_USER);
+       char *devname;
+
+       dprintk("%s: submounting on %s/%s\n", __FUNCTION__,
+                       dentry->d_parent->d_name.name,
+                       dentry->d_name.name);
+       if (page == NULL)
+               goto out;
+       devname = nfs_devname(mnt_parent, dentry, page, PAGE_SIZE);
+       mnt = (struct vfsmount *)devname;
+       if (IS_ERR(devname))
+               goto free_page;
+       switch (NFS_SB(mnt_parent->mnt_sb)->rpc_ops->version) {
+               case 2:
+               case 3:
+                       mnt = vfs_kern_mount(&clone_nfs_fs_type, 0, devname, &mountdata);
+                       break;
+               case 4:
+                       mnt = vfs_kern_mount(&clone_nfs4_fs_type, 0, devname, &mountdata);
+                       break;
+               default:
+                       BUG();
+       }
+free_page:
+       free_page((unsigned long)page);
+out:
+       dprintk("%s: done\n", __FUNCTION__);
+       return mnt;
+}
+
 extern int nfs_init_nfspagecache(void);
 extern void nfs_destroy_nfspagecache(void);
 extern int nfs_init_readpagecache(void);
This page took 0.033219 seconds and 5 git commands to generate.