diff options
author | Trond Myklebust <Trond.Myklebust@netapp.com> | 2006-06-09 09:34:19 -0400 |
---|---|---|
committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2006-06-09 09:34:19 -0400 |
commit | 55a975937d40cac582e981ddc8ed783b3dcc043c (patch) | |
tree | 13507eaebdab5e9c9dd615fe373ec6c0ddcbade4 /fs/nfs/inode.c | |
parent | 8b4bdcf8995dd92b23d2ec22b32aee8fbbb50e1c (diff) |
NFS: Ensure the client submounts, when it crosses a server mountpoint.
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/nfs/inode.c')
-rw-r--r-- | fs/nfs/inode.c | 303 |
1 files changed, 300 insertions, 3 deletions
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index 1a809f6f8989..47167ab64f5b 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c | |||
@@ -221,6 +221,14 @@ nfs_block_size(unsigned long bsize, unsigned char *nrbitsp) | |||
221 | return nfs_block_bits(bsize, nrbitsp); | 221 | return nfs_block_bits(bsize, nrbitsp); |
222 | } | 222 | } |
223 | 223 | ||
224 | static inline void | ||
225 | nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize) | ||
226 | { | ||
227 | sb->s_maxbytes = (loff_t)maxfilesize; | ||
228 | if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0) | ||
229 | sb->s_maxbytes = MAX_LFS_FILESIZE; | ||
230 | } | ||
231 | |||
224 | /* | 232 | /* |
225 | * Obtain the root inode of the file system. | 233 | * Obtain the root inode of the file system. |
226 | */ | 234 | */ |
@@ -331,9 +339,7 @@ nfs_sb_init(struct super_block *sb, rpc_authflavor_t authflavor) | |||
331 | } | 339 | } |
332 | server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD; | 340 | server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD; |
333 | 341 | ||
334 | sb->s_maxbytes = fsinfo.maxfilesize; | 342 | nfs_super_set_maxbytes(sb, fsinfo.maxfilesize); |
335 | if (sb->s_maxbytes > MAX_LFS_FILESIZE) | ||
336 | sb->s_maxbytes = MAX_LFS_FILESIZE; | ||
337 | 343 | ||
338 | server->client->cl_intr = (server->flags & NFS_MOUNT_INTR) ? 1 : 0; | 344 | server->client->cl_intr = (server->flags & NFS_MOUNT_INTR) ? 1 : 0; |
339 | server->client->cl_softrtry = (server->flags & NFS_MOUNT_SOFT) ? 1 : 0; | 345 | server->client->cl_softrtry = (server->flags & NFS_MOUNT_SOFT) ? 1 : 0; |
@@ -877,6 +883,11 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr) | |||
877 | if (nfs_server_capable(inode, NFS_CAP_READDIRPLUS) | 883 | if (nfs_server_capable(inode, NFS_CAP_READDIRPLUS) |
878 | && fattr->size <= NFS_LIMIT_READDIRPLUS) | 884 | && fattr->size <= NFS_LIMIT_READDIRPLUS) |
879 | set_bit(NFS_INO_ADVISE_RDPLUS, &NFS_FLAGS(inode)); | 885 | set_bit(NFS_INO_ADVISE_RDPLUS, &NFS_FLAGS(inode)); |
886 | /* Deal with crossing mountpoints */ | ||
887 | if (!nfs_fsid_equal(&NFS_SB(sb)->fsid, &fattr->fsid)) { | ||
888 | inode->i_op = &nfs_mountpoint_inode_operations; | ||
889 | inode->i_fop = NULL; | ||
890 | } | ||
880 | } else if (S_ISLNK(inode->i_mode)) | 891 | } else if (S_ISLNK(inode->i_mode)) |
881 | inode->i_op = &nfs_symlink_inode_operations; | 892 | inode->i_op = &nfs_symlink_inode_operations; |
882 | else | 893 | else |
@@ -1650,6 +1661,141 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
1650 | * File system information | 1661 | * File system information |
1651 | */ | 1662 | */ |
1652 | 1663 | ||
1664 | /* | ||
1665 | * nfs_path - reconstruct the path given an arbitrary dentry | ||
1666 | * @base - arbitrary string to prepend to the path | ||
1667 | * @dentry - pointer to dentry | ||
1668 | * @buffer - result buffer | ||
1669 | * @buflen - length of buffer | ||
1670 | * | ||
1671 | * Helper function for constructing the path from the | ||
1672 | * root dentry to an arbitrary hashed dentry. | ||
1673 | * | ||
1674 | * This is mainly for use in figuring out the path on the | ||
1675 | * server side when automounting on top of an existing partition. | ||
1676 | */ | ||
1677 | static char *nfs_path(const char *base, const struct dentry *dentry, | ||
1678 | char *buffer, ssize_t buflen) | ||
1679 | { | ||
1680 | char *end = buffer+buflen; | ||
1681 | int namelen; | ||
1682 | |||
1683 | *--end = '\0'; | ||
1684 | buflen--; | ||
1685 | spin_lock(&dcache_lock); | ||
1686 | while (!IS_ROOT(dentry)) { | ||
1687 | namelen = dentry->d_name.len; | ||
1688 | buflen -= namelen + 1; | ||
1689 | if (buflen < 0) | ||
1690 | goto Elong; | ||
1691 | end -= namelen; | ||
1692 | memcpy(end, dentry->d_name.name, namelen); | ||
1693 | *--end = '/'; | ||
1694 | dentry = dentry->d_parent; | ||
1695 | } | ||
1696 | spin_unlock(&dcache_lock); | ||
1697 | namelen = strlen(base); | ||
1698 | /* Strip off excess slashes in base string */ | ||
1699 | while (namelen > 0 && base[namelen - 1] == '/') | ||
1700 | namelen--; | ||
1701 | buflen -= namelen; | ||
1702 | if (buflen < 0) | ||
1703 | goto Elong; | ||
1704 | end -= namelen; | ||
1705 | memcpy(end, base, namelen); | ||
1706 | return end; | ||
1707 | Elong: | ||
1708 | return ERR_PTR(-ENAMETOOLONG); | ||
1709 | } | ||
1710 | |||
1711 | struct nfs_clone_mount { | ||
1712 | const struct super_block *sb; | ||
1713 | const struct dentry *dentry; | ||
1714 | struct nfs_fh *fh; | ||
1715 | struct nfs_fattr *fattr; | ||
1716 | }; | ||
1717 | |||
1718 | static struct super_block *nfs_clone_generic_sb(struct nfs_clone_mount *data, | ||
1719 | struct super_block *(*clone_client)(struct nfs_server *, struct nfs_clone_mount *)) | ||
1720 | { | ||
1721 | struct nfs_server *server; | ||
1722 | struct nfs_server *parent = NFS_SB(data->sb); | ||
1723 | struct super_block *sb = ERR_PTR(-EINVAL); | ||
1724 | void *err = ERR_PTR(-ENOMEM); | ||
1725 | struct inode *root_inode; | ||
1726 | struct nfs_fsinfo fsinfo; | ||
1727 | int len; | ||
1728 | |||
1729 | server = kmalloc(sizeof(struct nfs_server), GFP_KERNEL); | ||
1730 | if (server == NULL) | ||
1731 | goto out_err; | ||
1732 | memcpy(server, parent, sizeof(*server)); | ||
1733 | len = strlen(parent->hostname) + 1; | ||
1734 | server->hostname = kmalloc(len, GFP_KERNEL); | ||
1735 | if (server->hostname == NULL) | ||
1736 | goto free_server; | ||
1737 | memcpy(server->hostname, parent->hostname, len); | ||
1738 | server->fsid = data->fattr->fsid; | ||
1739 | nfs_copy_fh(&server->fh, data->fh); | ||
1740 | if (rpciod_up() != 0) | ||
1741 | goto free_hostname; | ||
1742 | |||
1743 | sb = clone_client(server, data); | ||
1744 | if (IS_ERR((err = sb)) || sb->s_root) | ||
1745 | goto kill_rpciod; | ||
1746 | |||
1747 | sb->s_op = data->sb->s_op; | ||
1748 | sb->s_blocksize = data->sb->s_blocksize; | ||
1749 | sb->s_blocksize_bits = data->sb->s_blocksize_bits; | ||
1750 | sb->s_maxbytes = data->sb->s_maxbytes; | ||
1751 | |||
1752 | server->client_sys = server->client_acl = ERR_PTR(-EINVAL); | ||
1753 | err = ERR_PTR(-ENOMEM); | ||
1754 | server->io_stats = nfs_alloc_iostats(); | ||
1755 | if (server->io_stats == NULL) | ||
1756 | goto out_deactivate; | ||
1757 | |||
1758 | server->client = rpc_clone_client(parent->client); | ||
1759 | if (IS_ERR((err = server->client))) | ||
1760 | goto out_deactivate; | ||
1761 | if (!IS_ERR(parent->client_sys)) { | ||
1762 | server->client_sys = rpc_clone_client(parent->client_sys); | ||
1763 | if (IS_ERR((err = server->client_sys))) | ||
1764 | goto out_deactivate; | ||
1765 | } | ||
1766 | if (!IS_ERR(parent->client_acl)) { | ||
1767 | server->client_acl = rpc_clone_client(parent->client_acl); | ||
1768 | if (IS_ERR((err = server->client_acl))) | ||
1769 | goto out_deactivate; | ||
1770 | } | ||
1771 | root_inode = nfs_fhget(sb, data->fh, data->fattr); | ||
1772 | if (!root_inode) | ||
1773 | goto out_deactivate; | ||
1774 | sb->s_root = d_alloc_root(root_inode); | ||
1775 | if (!sb->s_root) | ||
1776 | goto out_put_root; | ||
1777 | fsinfo.fattr = data->fattr; | ||
1778 | if (NFS_PROTO(root_inode)->fsinfo(server, data->fh, &fsinfo) == 0) | ||
1779 | nfs_super_set_maxbytes(sb, fsinfo.maxfilesize); | ||
1780 | sb->s_root->d_op = server->rpc_ops->dentry_ops; | ||
1781 | sb->s_flags |= MS_ACTIVE; | ||
1782 | return sb; | ||
1783 | out_put_root: | ||
1784 | iput(root_inode); | ||
1785 | out_deactivate: | ||
1786 | up_write(&sb->s_umount); | ||
1787 | deactivate_super(sb); | ||
1788 | return (struct super_block *)err; | ||
1789 | kill_rpciod: | ||
1790 | rpciod_down(); | ||
1791 | free_hostname: | ||
1792 | kfree(server->hostname); | ||
1793 | free_server: | ||
1794 | kfree(server); | ||
1795 | out_err: | ||
1796 | return (struct super_block *)err; | ||
1797 | } | ||
1798 | |||
1653 | static int nfs_set_super(struct super_block *s, void *data) | 1799 | static int nfs_set_super(struct super_block *s, void *data) |
1654 | { | 1800 | { |
1655 | s->s_fs_info = data; | 1801 | s->s_fs_info = data; |
@@ -1807,6 +1953,31 @@ static struct file_system_type nfs_fs_type = { | |||
1807 | .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, | 1953 | .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, |
1808 | }; | 1954 | }; |
1809 | 1955 | ||
1956 | static struct super_block *nfs_clone_client(struct nfs_server *server, struct nfs_clone_mount *data) | ||
1957 | { | ||
1958 | struct super_block *sb; | ||
1959 | |||
1960 | sb = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server); | ||
1961 | if (!IS_ERR(sb) && sb->s_root == NULL && !(server->flags & NFS_MOUNT_NONLM)) | ||
1962 | lockd_up(); | ||
1963 | return sb; | ||
1964 | } | ||
1965 | |||
1966 | static struct super_block *nfs_clone_nfs_sb(struct file_system_type *fs_type, | ||
1967 | int flags, const char *dev_name, void *raw_data) | ||
1968 | { | ||
1969 | struct nfs_clone_mount *data = raw_data; | ||
1970 | return nfs_clone_generic_sb(data, nfs_clone_client); | ||
1971 | } | ||
1972 | |||
1973 | static struct file_system_type clone_nfs_fs_type = { | ||
1974 | .owner = THIS_MODULE, | ||
1975 | .name = "nfs", | ||
1976 | .get_sb = nfs_clone_nfs_sb, | ||
1977 | .kill_sb = nfs_kill_super, | ||
1978 | .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, | ||
1979 | }; | ||
1980 | |||
1810 | #ifdef CONFIG_NFS_V4 | 1981 | #ifdef CONFIG_NFS_V4 |
1811 | 1982 | ||
1812 | static void nfs4_clear_inode(struct inode *); | 1983 | static void nfs4_clear_inode(struct inode *); |
@@ -2156,6 +2327,75 @@ static int param_set_idmap_timeout(const char *val, struct kernel_param *kp) | |||
2156 | module_param_call(idmap_cache_timeout, param_set_idmap_timeout, param_get_int, | 2327 | module_param_call(idmap_cache_timeout, param_set_idmap_timeout, param_get_int, |
2157 | &nfs_idmap_cache_timeout, 0644); | 2328 | &nfs_idmap_cache_timeout, 0644); |
2158 | 2329 | ||
2330 | /* Constructs the SERVER-side path */ | ||
2331 | static inline char *nfs4_path(const struct dentry *dentry, char *buffer, ssize_t buflen) | ||
2332 | { | ||
2333 | return nfs_path(NFS_SB(dentry->d_sb)->mnt_path, dentry, buffer, buflen); | ||
2334 | } | ||
2335 | |||
2336 | static inline char *nfs4_dup_path(const struct dentry *dentry) | ||
2337 | { | ||
2338 | char *page = (char *) __get_free_page(GFP_USER); | ||
2339 | char *path; | ||
2340 | |||
2341 | path = nfs4_path(dentry, page, PAGE_SIZE); | ||
2342 | if (!IS_ERR(path)) { | ||
2343 | int len = PAGE_SIZE + page - path; | ||
2344 | char *tmp = path; | ||
2345 | |||
2346 | path = kmalloc(len, GFP_KERNEL); | ||
2347 | if (path) | ||
2348 | memcpy(path, tmp, len); | ||
2349 | else | ||
2350 | path = ERR_PTR(-ENOMEM); | ||
2351 | } | ||
2352 | free_page((unsigned long)page); | ||
2353 | return path; | ||
2354 | } | ||
2355 | |||
2356 | static struct super_block *nfs4_clone_client(struct nfs_server *server, struct nfs_clone_mount *data) | ||
2357 | { | ||
2358 | const struct dentry *dentry = data->dentry; | ||
2359 | struct nfs4_client *clp = server->nfs4_state; | ||
2360 | struct super_block *sb; | ||
2361 | |||
2362 | server->mnt_path = nfs4_dup_path(dentry); | ||
2363 | if (IS_ERR(server->mnt_path)) { | ||
2364 | sb = (struct super_block *)server->mnt_path; | ||
2365 | goto err; | ||
2366 | } | ||
2367 | sb = sget(&nfs4_fs_type, nfs4_compare_super, nfs_set_super, server); | ||
2368 | if (IS_ERR(sb) || sb->s_root) | ||
2369 | goto free_path; | ||
2370 | nfs4_server_capabilities(server, &server->fh); | ||
2371 | |||
2372 | down_write(&clp->cl_sem); | ||
2373 | atomic_inc(&clp->cl_count); | ||
2374 | list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks); | ||
2375 | up_write(&clp->cl_sem); | ||
2376 | return sb; | ||
2377 | free_path: | ||
2378 | kfree(server->mnt_path); | ||
2379 | err: | ||
2380 | server->mnt_path = NULL; | ||
2381 | return sb; | ||
2382 | } | ||
2383 | |||
2384 | static struct super_block *nfs_clone_nfs4_sb(struct file_system_type *fs_type, | ||
2385 | int flags, const char *dev_name, void *raw_data) | ||
2386 | { | ||
2387 | struct nfs_clone_mount *data = raw_data; | ||
2388 | return nfs_clone_generic_sb(data, nfs4_clone_client); | ||
2389 | } | ||
2390 | |||
2391 | static struct file_system_type clone_nfs4_fs_type = { | ||
2392 | .owner = THIS_MODULE, | ||
2393 | .name = "nfs", | ||
2394 | .get_sb = nfs_clone_nfs4_sb, | ||
2395 | .kill_sb = nfs4_kill_super, | ||
2396 | .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, | ||
2397 | }; | ||
2398 | |||
2159 | #define nfs4_init_once(nfsi) \ | 2399 | #define nfs4_init_once(nfsi) \ |
2160 | do { \ | 2400 | do { \ |
2161 | INIT_LIST_HEAD(&(nfsi)->open_states); \ | 2401 | INIT_LIST_HEAD(&(nfsi)->open_states); \ |
@@ -2183,12 +2423,69 @@ static inline void unregister_nfs4fs(void) | |||
2183 | nfs_unregister_sysctl(); | 2423 | nfs_unregister_sysctl(); |
2184 | } | 2424 | } |
2185 | #else | 2425 | #else |
2426 | #define nfs4_clone_client(a,b) ERR_PTR(-EINVAL) | ||
2186 | #define nfs4_init_once(nfsi) \ | 2427 | #define nfs4_init_once(nfsi) \ |
2187 | do { } while (0) | 2428 | do { } while (0) |
2188 | #define register_nfs4fs() (0) | 2429 | #define register_nfs4fs() (0) |
2189 | #define unregister_nfs4fs() | 2430 | #define unregister_nfs4fs() |
2190 | #endif | 2431 | #endif |
2191 | 2432 | ||
2433 | static inline char *nfs_devname(const struct vfsmount *mnt_parent, | ||
2434 | const struct dentry *dentry, | ||
2435 | char *buffer, ssize_t buflen) | ||
2436 | { | ||
2437 | return nfs_path(mnt_parent->mnt_devname, dentry, buffer, buflen); | ||
2438 | } | ||
2439 | |||
2440 | /** | ||
2441 | * nfs_do_submount - set up mountpoint when crossing a filesystem boundary | ||
2442 | * @mnt_parent - mountpoint of parent directory | ||
2443 | * @dentry - parent directory | ||
2444 | * @fh - filehandle for new root dentry | ||
2445 | * @fattr - attributes for new root inode | ||
2446 | * | ||
2447 | */ | ||
2448 | struct vfsmount *nfs_do_submount(const struct vfsmount *mnt_parent, | ||
2449 | const struct dentry *dentry, struct nfs_fh *fh, | ||
2450 | struct nfs_fattr *fattr) | ||
2451 | { | ||
2452 | struct nfs_clone_mount mountdata = { | ||
2453 | .sb = mnt_parent->mnt_sb, | ||
2454 | .dentry = dentry, | ||
2455 | .fh = fh, | ||
2456 | .fattr = fattr, | ||
2457 | }; | ||
2458 | struct vfsmount *mnt = ERR_PTR(-ENOMEM); | ||
2459 | char *page = (char *) __get_free_page(GFP_USER); | ||
2460 | char *devname; | ||
2461 | |||
2462 | dprintk("%s: submounting on %s/%s\n", __FUNCTION__, | ||
2463 | dentry->d_parent->d_name.name, | ||
2464 | dentry->d_name.name); | ||
2465 | if (page == NULL) | ||
2466 | goto out; | ||
2467 | devname = nfs_devname(mnt_parent, dentry, page, PAGE_SIZE); | ||
2468 | mnt = (struct vfsmount *)devname; | ||
2469 | if (IS_ERR(devname)) | ||
2470 | goto free_page; | ||
2471 | switch (NFS_SB(mnt_parent->mnt_sb)->rpc_ops->version) { | ||
2472 | case 2: | ||
2473 | case 3: | ||
2474 | mnt = vfs_kern_mount(&clone_nfs_fs_type, 0, devname, &mountdata); | ||
2475 | break; | ||
2476 | case 4: | ||
2477 | mnt = vfs_kern_mount(&clone_nfs4_fs_type, 0, devname, &mountdata); | ||
2478 | break; | ||
2479 | default: | ||
2480 | BUG(); | ||
2481 | } | ||
2482 | free_page: | ||
2483 | free_page((unsigned long)page); | ||
2484 | out: | ||
2485 | dprintk("%s: done\n", __FUNCTION__); | ||
2486 | return mnt; | ||
2487 | } | ||
2488 | |||
2192 | extern int nfs_init_nfspagecache(void); | 2489 | extern int nfs_init_nfspagecache(void); |
2193 | extern void nfs_destroy_nfspagecache(void); | 2490 | extern void nfs_destroy_nfspagecache(void); |
2194 | extern int nfs_init_readpagecache(void); | 2491 | extern int nfs_init_readpagecache(void); |