drm/nouveau: add missing pll_calc calls
[linux-2.6/libata-dev.git] / fs / nfs / nfs4super.c
blobbd61221ad2c5542b08f42249d10285c159f66b1d
1 /*
2 * Copyright (c) 2012 Bryan Schumaker <bjschuma@netapp.com>
3 */
4 #include <linux/init.h>
5 #include <linux/module.h>
6 #include <linux/nfs_idmap.h>
7 #include <linux/nfs4_mount.h>
8 #include <linux/nfs_fs.h>
9 #include "delegation.h"
10 #include "internal.h"
11 #include "nfs4_fs.h"
12 #include "pnfs.h"
13 #include "nfs.h"
15 #define NFSDBG_FACILITY NFSDBG_VFS
17 static int nfs4_write_inode(struct inode *inode, struct writeback_control *wbc);
18 static void nfs4_evict_inode(struct inode *inode);
19 static struct dentry *nfs4_remote_mount(struct file_system_type *fs_type,
20 int flags, const char *dev_name, void *raw_data);
21 static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
22 int flags, const char *dev_name, void *raw_data);
23 static struct dentry *nfs4_remote_referral_mount(struct file_system_type *fs_type,
24 int flags, const char *dev_name, void *raw_data);
26 static struct file_system_type nfs4_remote_fs_type = {
27 .owner = THIS_MODULE,
28 .name = "nfs4",
29 .mount = nfs4_remote_mount,
30 .kill_sb = nfs_kill_super,
31 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
34 static struct file_system_type nfs4_remote_referral_fs_type = {
35 .owner = THIS_MODULE,
36 .name = "nfs4",
37 .mount = nfs4_remote_referral_mount,
38 .kill_sb = nfs_kill_super,
39 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
42 struct file_system_type nfs4_referral_fs_type = {
43 .owner = THIS_MODULE,
44 .name = "nfs4",
45 .mount = nfs4_referral_mount,
46 .kill_sb = nfs_kill_super,
47 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
50 static const struct super_operations nfs4_sops = {
51 .alloc_inode = nfs_alloc_inode,
52 .destroy_inode = nfs_destroy_inode,
53 .write_inode = nfs4_write_inode,
54 .put_super = nfs_put_super,
55 .statfs = nfs_statfs,
56 .evict_inode = nfs4_evict_inode,
57 .umount_begin = nfs_umount_begin,
58 .show_options = nfs_show_options,
59 .show_devname = nfs_show_devname,
60 .show_path = nfs_show_path,
61 .show_stats = nfs_show_stats,
62 .remount_fs = nfs_remount,
65 struct nfs_subversion nfs_v4 = {
66 .owner = THIS_MODULE,
67 .nfs_fs = &nfs4_fs_type,
68 .rpc_vers = &nfs_version4,
69 .rpc_ops = &nfs_v4_clientops,
70 .sops = &nfs4_sops,
71 .xattr = nfs4_xattr_handlers,
74 static int nfs4_write_inode(struct inode *inode, struct writeback_control *wbc)
76 int ret = nfs_write_inode(inode, wbc);
78 if (ret >= 0 && test_bit(NFS_INO_LAYOUTCOMMIT, &NFS_I(inode)->flags)) {
79 int status;
80 bool sync = true;
82 if (wbc->sync_mode == WB_SYNC_NONE)
83 sync = false;
85 status = pnfs_layoutcommit_inode(inode, sync);
86 if (status < 0)
87 return status;
89 return ret;
93 * Clean out any remaining NFSv4 state that might be left over due
94 * to open() calls that passed nfs_atomic_lookup, but failed to call
95 * nfs_open().
97 static void nfs4_evict_inode(struct inode *inode)
99 truncate_inode_pages(&inode->i_data, 0);
100 clear_inode(inode);
101 pnfs_return_layout(inode);
102 pnfs_destroy_layout(NFS_I(inode));
103 /* If we are holding a delegation, return it! */
104 nfs_inode_return_delegation_noreclaim(inode);
105 /* First call standard NFS clear_inode() code */
106 nfs_clear_inode(inode);
110 * Get the superblock for the NFS4 root partition
112 static struct dentry *
113 nfs4_remote_mount(struct file_system_type *fs_type, int flags,
114 const char *dev_name, void *info)
116 struct nfs_mount_info *mount_info = info;
117 struct nfs_server *server;
118 struct dentry *mntroot = ERR_PTR(-ENOMEM);
120 mount_info->set_security = nfs_set_sb_security;
122 /* Get a volume representation */
123 server = nfs4_create_server(mount_info, &nfs_v4);
124 if (IS_ERR(server)) {
125 mntroot = ERR_CAST(server);
126 goto out;
129 mntroot = nfs_fs_mount_common(server, flags, dev_name, mount_info, &nfs_v4);
131 out:
132 return mntroot;
135 static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
136 int flags, void *data, const char *hostname)
138 struct vfsmount *root_mnt;
139 char *root_devname;
140 size_t len;
142 len = strlen(hostname) + 5;
143 root_devname = kmalloc(len, GFP_KERNEL);
144 if (root_devname == NULL)
145 return ERR_PTR(-ENOMEM);
146 /* Does hostname needs to be enclosed in brackets? */
147 if (strchr(hostname, ':'))
148 snprintf(root_devname, len, "[%s]:/", hostname);
149 else
150 snprintf(root_devname, len, "%s:/", hostname);
151 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
152 kfree(root_devname);
153 return root_mnt;
156 struct nfs_referral_count {
157 struct list_head list;
158 const struct task_struct *task;
159 unsigned int referral_count;
162 static LIST_HEAD(nfs_referral_count_list);
163 static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
165 static struct nfs_referral_count *nfs_find_referral_count(void)
167 struct nfs_referral_count *p;
169 list_for_each_entry(p, &nfs_referral_count_list, list) {
170 if (p->task == current)
171 return p;
173 return NULL;
176 #define NFS_MAX_NESTED_REFERRALS 2
178 static int nfs_referral_loop_protect(void)
180 struct nfs_referral_count *p, *new;
181 int ret = -ENOMEM;
183 new = kmalloc(sizeof(*new), GFP_KERNEL);
184 if (!new)
185 goto out;
186 new->task = current;
187 new->referral_count = 1;
189 ret = 0;
190 spin_lock(&nfs_referral_count_list_lock);
191 p = nfs_find_referral_count();
192 if (p != NULL) {
193 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
194 ret = -ELOOP;
195 else
196 p->referral_count++;
197 } else {
198 list_add(&new->list, &nfs_referral_count_list);
199 new = NULL;
201 spin_unlock(&nfs_referral_count_list_lock);
202 kfree(new);
203 out:
204 return ret;
207 static void nfs_referral_loop_unprotect(void)
209 struct nfs_referral_count *p;
211 spin_lock(&nfs_referral_count_list_lock);
212 p = nfs_find_referral_count();
213 p->referral_count--;
214 if (p->referral_count == 0)
215 list_del(&p->list);
216 else
217 p = NULL;
218 spin_unlock(&nfs_referral_count_list_lock);
219 kfree(p);
222 static struct dentry *nfs_follow_remote_path(struct vfsmount *root_mnt,
223 const char *export_path)
225 struct dentry *dentry;
226 int err;
228 if (IS_ERR(root_mnt))
229 return ERR_CAST(root_mnt);
231 err = nfs_referral_loop_protect();
232 if (err) {
233 mntput(root_mnt);
234 return ERR_PTR(err);
237 dentry = mount_subtree(root_mnt, export_path);
238 nfs_referral_loop_unprotect();
240 return dentry;
243 struct dentry *nfs4_try_mount(int flags, const char *dev_name,
244 struct nfs_mount_info *mount_info,
245 struct nfs_subversion *nfs_mod)
247 char *export_path;
248 struct vfsmount *root_mnt;
249 struct dentry *res;
250 struct nfs_parsed_mount_data *data = mount_info->parsed;
252 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
254 export_path = data->nfs_server.export_path;
255 data->nfs_server.export_path = "/";
256 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, mount_info,
257 data->nfs_server.hostname);
258 data->nfs_server.export_path = export_path;
260 res = nfs_follow_remote_path(root_mnt, export_path);
262 dfprintk(MOUNT, "<-- nfs4_try_mount() = %ld%s\n",
263 IS_ERR(res) ? PTR_ERR(res) : 0,
264 IS_ERR(res) ? " [error]" : "");
265 return res;
268 static struct dentry *
269 nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
270 const char *dev_name, void *raw_data)
272 struct nfs_mount_info mount_info = {
273 .fill_super = nfs_fill_super,
274 .set_security = nfs_clone_sb_security,
275 .cloned = raw_data,
277 struct nfs_server *server;
278 struct dentry *mntroot = ERR_PTR(-ENOMEM);
280 dprintk("--> nfs4_referral_get_sb()\n");
282 mount_info.mntfh = nfs_alloc_fhandle();
283 if (mount_info.cloned == NULL || mount_info.mntfh == NULL)
284 goto out;
286 /* create a new volume representation */
287 server = nfs4_create_referral_server(mount_info.cloned, mount_info.mntfh);
288 if (IS_ERR(server)) {
289 mntroot = ERR_CAST(server);
290 goto out;
293 mntroot = nfs_fs_mount_common(server, flags, dev_name, &mount_info, &nfs_v4);
294 out:
295 nfs_free_fhandle(mount_info.mntfh);
296 return mntroot;
300 * Create an NFS4 server record on referral traversal
302 static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,
303 int flags, const char *dev_name, void *raw_data)
305 struct nfs_clone_mount *data = raw_data;
306 char *export_path;
307 struct vfsmount *root_mnt;
308 struct dentry *res;
310 dprintk("--> nfs4_referral_mount()\n");
312 export_path = data->mnt_path;
313 data->mnt_path = "/";
315 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
316 flags, data, data->hostname);
317 data->mnt_path = export_path;
319 res = nfs_follow_remote_path(root_mnt, export_path);
320 dprintk("<-- nfs4_referral_mount() = %ld%s\n",
321 IS_ERR(res) ? PTR_ERR(res) : 0,
322 IS_ERR(res) ? " [error]" : "");
323 return res;
327 static int __init init_nfs_v4(void)
329 int err;
331 err = nfs_idmap_init();
332 if (err)
333 goto out;
335 err = nfs4_register_sysctl();
336 if (err)
337 goto out1;
339 register_nfs_version(&nfs_v4);
340 return 0;
341 out1:
342 nfs_idmap_quit();
343 out:
344 return err;
347 static void __exit exit_nfs_v4(void)
349 unregister_nfs_version(&nfs_v4);
350 nfs4_unregister_sysctl();
351 nfs_idmap_quit();
354 MODULE_LICENSE("GPL");
356 module_init(init_nfs_v4);
357 module_exit(exit_nfs_v4);