blob: f4fa5cf0cdf1d5808a4c8f3685562ab4dd774a84 [file] [log] [blame]
Sage Weil16725b92009-10-06 11:31:07 -07001
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07002#include <linux/ceph/ceph_debug.h>
Sage Weil16725b92009-10-06 11:31:07 -07003
4#include <linux/backing-dev.h>
Sage Weilc309f0a2010-06-30 21:34:01 -07005#include <linux/ctype.h>
Sage Weil16725b92009-10-06 11:31:07 -07006#include <linux/fs.h>
7#include <linux/inet.h>
8#include <linux/in6.h>
9#include <linux/module.h>
10#include <linux/mount.h>
11#include <linux/parser.h>
Sage Weil16725b92009-10-06 11:31:07 -070012#include <linux/sched.h>
13#include <linux/seq_file.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Sage Weil16725b92009-10-06 11:31:07 -070015#include <linux/statfs.h>
16#include <linux/string.h>
Sage Weil16725b92009-10-06 11:31:07 -070017
Sage Weil16725b92009-10-06 11:31:07 -070018#include "super.h"
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070019#include "mds_client.h"
20
21#include <linux/ceph/decode.h>
22#include <linux/ceph/mon_client.h>
23#include <linux/ceph/auth.h>
24#include <linux/ceph/debugfs.h>
Sage Weil16725b92009-10-06 11:31:07 -070025
26/*
27 * Ceph superblock operations
28 *
29 * Handle the basics of mounting, unmounting.
30 */
31
Sage Weil16725b92009-10-06 11:31:07 -070032/*
33 * super ops
34 */
35static void ceph_put_super(struct super_block *s)
36{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070037 struct ceph_fs_client *fsc = ceph_sb_to_client(s);
Sage Weil16725b92009-10-06 11:31:07 -070038
39 dout("put_super\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070040 ceph_mdsc_close_sessions(fsc->mdsc);
Sage Weil5dfc5892010-05-04 16:14:46 -070041
42 /*
43 * ensure we release the bdi before put_anon_super releases
44 * the device name.
45 */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070046 if (s->s_bdi == &fsc->backing_dev_info) {
47 bdi_unregister(&fsc->backing_dev_info);
Sage Weil5dfc5892010-05-04 16:14:46 -070048 s->s_bdi = NULL;
49 }
50
Sage Weil16725b92009-10-06 11:31:07 -070051 return;
52}
53
54static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf)
55{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070056 struct ceph_fs_client *fsc = ceph_inode_to_client(dentry->d_inode);
57 struct ceph_monmap *monmap = fsc->client->monc.monmap;
Sage Weil16725b92009-10-06 11:31:07 -070058 struct ceph_statfs st;
59 u64 fsid;
60 int err;
61
62 dout("statfs\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070063 err = ceph_monc_do_statfs(&fsc->client->monc, &st);
Sage Weil16725b92009-10-06 11:31:07 -070064 if (err < 0)
65 return err;
66
67 /* fill in kstatfs */
68 buf->f_type = CEPH_SUPER_MAGIC; /* ?? */
69
70 /*
71 * express utilization in terms of large blocks to avoid
72 * overflow on 32-bit machines.
Sage Weil999899a2013-02-22 15:31:00 -080073 *
74 * NOTE: for the time being, we make bsize == frsize to humor
75 * not-yet-ancient versions of glibc that are broken.
76 * Someday, we will probably want to report a real block
77 * size... whatever that may mean for a network file system!
Sage Weil16725b92009-10-06 11:31:07 -070078 */
79 buf->f_bsize = 1 << CEPH_BLOCK_SHIFT;
Sage Weil999899a2013-02-22 15:31:00 -080080 buf->f_frsize = 1 << CEPH_BLOCK_SHIFT;
Sage Weil16725b92009-10-06 11:31:07 -070081 buf->f_blocks = le64_to_cpu(st.kb) >> (CEPH_BLOCK_SHIFT-10);
Greg Farnum8f04d422011-07-26 11:26:54 -070082 buf->f_bfree = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);
Sage Weil16725b92009-10-06 11:31:07 -070083 buf->f_bavail = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);
84
85 buf->f_files = le64_to_cpu(st.num_objects);
86 buf->f_ffree = -1;
Sage Weil558d3492010-06-01 12:51:12 -070087 buf->f_namelen = NAME_MAX;
Sage Weil16725b92009-10-06 11:31:07 -070088
89 /* leave fsid little-endian, regardless of host endianness */
90 fsid = *(u64 *)(&monmap->fsid) ^ *((u64 *)&monmap->fsid + 1);
91 buf->f_fsid.val[0] = fsid & 0xffffffff;
92 buf->f_fsid.val[1] = fsid >> 32;
93
94 return 0;
95}
96
97
Sage Weil2d9c98a2010-07-30 09:38:13 -070098static int ceph_sync_fs(struct super_block *sb, int wait)
Sage Weil16725b92009-10-06 11:31:07 -070099{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700100 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
Sage Weil2d9c98a2010-07-30 09:38:13 -0700101
102 if (!wait) {
103 dout("sync_fs (non-blocking)\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700104 ceph_flush_dirty_caps(fsc->mdsc);
Sage Weil2d9c98a2010-07-30 09:38:13 -0700105 dout("sync_fs (non-blocking) done\n");
106 return 0;
107 }
108
109 dout("sync_fs (blocking)\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700110 ceph_osdc_sync(&fsc->client->osdc);
111 ceph_mdsc_sync(fsc->mdsc);
Sage Weil2d9c98a2010-07-30 09:38:13 -0700112 dout("sync_fs (blocking) done\n");
Sage Weil16725b92009-10-06 11:31:07 -0700113 return 0;
114}
115
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700116/*
117 * mount options
118 */
119enum {
120 Opt_wsize,
121 Opt_rsize,
Sage Weil83817e32011-08-04 08:03:44 -0700122 Opt_rasize,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700123 Opt_caps_wanted_delay_min,
124 Opt_caps_wanted_delay_max,
125 Opt_cap_release_safety,
126 Opt_readdir_max_entries,
127 Opt_readdir_max_bytes,
128 Opt_congestion_kb,
129 Opt_last_int,
130 /* int args above */
131 Opt_snapdirname,
132 Opt_last_string,
133 /* string args above */
134 Opt_dirstat,
135 Opt_nodirstat,
136 Opt_rbytes,
137 Opt_norbytes,
Alex Eldercffaba12012-02-15 07:43:54 -0600138 Opt_asyncreaddir,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700139 Opt_noasyncreaddir,
Sage Weila40dc6c2012-01-10 09:12:55 -0800140 Opt_dcache,
141 Opt_nodcache,
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800142 Opt_ino32,
Alex Eldercffaba12012-02-15 07:43:54 -0600143 Opt_noino32,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700144};
145
146static match_table_t fsopt_tokens = {
147 {Opt_wsize, "wsize=%d"},
148 {Opt_rsize, "rsize=%d"},
Sage Weil83817e32011-08-04 08:03:44 -0700149 {Opt_rasize, "rasize=%d"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700150 {Opt_caps_wanted_delay_min, "caps_wanted_delay_min=%d"},
151 {Opt_caps_wanted_delay_max, "caps_wanted_delay_max=%d"},
152 {Opt_cap_release_safety, "cap_release_safety=%d"},
153 {Opt_readdir_max_entries, "readdir_max_entries=%d"},
154 {Opt_readdir_max_bytes, "readdir_max_bytes=%d"},
155 {Opt_congestion_kb, "write_congestion_kb=%d"},
156 /* int args above */
157 {Opt_snapdirname, "snapdirname=%s"},
158 /* string args above */
159 {Opt_dirstat, "dirstat"},
160 {Opt_nodirstat, "nodirstat"},
161 {Opt_rbytes, "rbytes"},
162 {Opt_norbytes, "norbytes"},
Alex Eldercffaba12012-02-15 07:43:54 -0600163 {Opt_asyncreaddir, "asyncreaddir"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700164 {Opt_noasyncreaddir, "noasyncreaddir"},
Sage Weila40dc6c2012-01-10 09:12:55 -0800165 {Opt_dcache, "dcache"},
166 {Opt_nodcache, "nodcache"},
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800167 {Opt_ino32, "ino32"},
Alex Eldercffaba12012-02-15 07:43:54 -0600168 {Opt_noino32, "noino32"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700169 {-1, NULL}
170};
171
172static int parse_fsopt_token(char *c, void *private)
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800173{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700174 struct ceph_mount_options *fsopt = private;
175 substring_t argstr[MAX_OPT_ARGS];
176 int token, intval, ret;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800177
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700178 token = match_token((char *)c, fsopt_tokens, argstr);
179 if (token < 0)
180 return -EINVAL;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800181
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700182 if (token < Opt_last_int) {
183 ret = match_int(&argstr[0], &intval);
184 if (ret < 0) {
185 pr_err("bad mount option arg (not int) "
186 "at '%s'\n", c);
187 return ret;
188 }
189 dout("got int token %d val %d\n", token, intval);
190 } else if (token > Opt_last_int && token < Opt_last_string) {
191 dout("got string token %d val %s\n", token,
192 argstr[0].from);
193 } else {
194 dout("got token %d\n", token);
195 }
196
197 switch (token) {
198 case Opt_snapdirname:
199 kfree(fsopt->snapdir_name);
200 fsopt->snapdir_name = kstrndup(argstr[0].from,
201 argstr[0].to-argstr[0].from,
202 GFP_KERNEL);
203 if (!fsopt->snapdir_name)
204 return -ENOMEM;
205 break;
206
207 /* misc */
208 case Opt_wsize:
209 fsopt->wsize = intval;
210 break;
211 case Opt_rsize:
212 fsopt->rsize = intval;
213 break;
Sage Weil83817e32011-08-04 08:03:44 -0700214 case Opt_rasize:
215 fsopt->rasize = intval;
216 break;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700217 case Opt_caps_wanted_delay_min:
218 fsopt->caps_wanted_delay_min = intval;
219 break;
220 case Opt_caps_wanted_delay_max:
221 fsopt->caps_wanted_delay_max = intval;
222 break;
223 case Opt_readdir_max_entries:
224 fsopt->max_readdir = intval;
225 break;
226 case Opt_readdir_max_bytes:
227 fsopt->max_readdir_bytes = intval;
228 break;
229 case Opt_congestion_kb:
230 fsopt->congestion_kb = intval;
231 break;
232 case Opt_dirstat:
233 fsopt->flags |= CEPH_MOUNT_OPT_DIRSTAT;
234 break;
235 case Opt_nodirstat:
236 fsopt->flags &= ~CEPH_MOUNT_OPT_DIRSTAT;
237 break;
238 case Opt_rbytes:
239 fsopt->flags |= CEPH_MOUNT_OPT_RBYTES;
240 break;
241 case Opt_norbytes:
242 fsopt->flags &= ~CEPH_MOUNT_OPT_RBYTES;
243 break;
Alex Eldercffaba12012-02-15 07:43:54 -0600244 case Opt_asyncreaddir:
245 fsopt->flags &= ~CEPH_MOUNT_OPT_NOASYNCREADDIR;
246 break;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700247 case Opt_noasyncreaddir:
248 fsopt->flags |= CEPH_MOUNT_OPT_NOASYNCREADDIR;
249 break;
Sage Weila40dc6c2012-01-10 09:12:55 -0800250 case Opt_dcache:
251 fsopt->flags |= CEPH_MOUNT_OPT_DCACHE;
252 break;
253 case Opt_nodcache:
254 fsopt->flags &= ~CEPH_MOUNT_OPT_DCACHE;
255 break;
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800256 case Opt_ino32:
257 fsopt->flags |= CEPH_MOUNT_OPT_INO32;
258 break;
Alex Eldercffaba12012-02-15 07:43:54 -0600259 case Opt_noino32:
260 fsopt->flags &= ~CEPH_MOUNT_OPT_INO32;
261 break;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700262 default:
263 BUG_ON(token);
264 }
265 return 0;
266}
267
268static void destroy_mount_options(struct ceph_mount_options *args)
269{
270 dout("destroy_mount_options %p\n", args);
271 kfree(args->snapdir_name);
272 kfree(args);
273}
274
275static int strcmp_null(const char *s1, const char *s2)
276{
277 if (!s1 && !s2)
278 return 0;
279 if (s1 && !s2)
280 return -1;
281 if (!s1 && s2)
282 return 1;
283 return strcmp(s1, s2);
284}
285
286static int compare_mount_options(struct ceph_mount_options *new_fsopt,
287 struct ceph_options *new_opt,
288 struct ceph_fs_client *fsc)
289{
290 struct ceph_mount_options *fsopt1 = new_fsopt;
291 struct ceph_mount_options *fsopt2 = fsc->mount_options;
292 int ofs = offsetof(struct ceph_mount_options, snapdir_name);
293 int ret;
294
295 ret = memcmp(fsopt1, fsopt2, ofs);
296 if (ret)
297 return ret;
298
299 ret = strcmp_null(fsopt1->snapdir_name, fsopt2->snapdir_name);
300 if (ret)
301 return ret;
302
303 return ceph_compare_options(new_opt, fsc->client);
304}
305
306static int parse_mount_options(struct ceph_mount_options **pfsopt,
307 struct ceph_options **popt,
308 int flags, char *options,
309 const char *dev_name,
310 const char **path)
311{
312 struct ceph_mount_options *fsopt;
313 const char *dev_name_end;
314 int err = -ENOMEM;
315
316 fsopt = kzalloc(sizeof(*fsopt), GFP_KERNEL);
317 if (!fsopt)
318 return -ENOMEM;
319
320 dout("parse_mount_options %p, dev_name '%s'\n", fsopt, dev_name);
321
Noah Watkins80db8be2011-08-22 13:49:23 -0600322 fsopt->sb_flags = flags;
323 fsopt->flags = CEPH_MOUNT_OPT_DEFAULT;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700324
Noah Watkins80db8be2011-08-22 13:49:23 -0600325 fsopt->rsize = CEPH_RSIZE_DEFAULT;
326 fsopt->rasize = CEPH_RASIZE_DEFAULT;
327 fsopt->snapdir_name = kstrdup(CEPH_SNAPDIRNAME_DEFAULT, GFP_KERNEL);
Sage Weil50aac4f2011-01-18 07:59:40 -0800328 fsopt->caps_wanted_delay_min = CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT;
329 fsopt->caps_wanted_delay_max = CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT;
Noah Watkins80db8be2011-08-22 13:49:23 -0600330 fsopt->cap_release_safety = CEPH_CAP_RELEASE_SAFETY_DEFAULT;
331 fsopt->max_readdir = CEPH_MAX_READDIR_DEFAULT;
332 fsopt->max_readdir_bytes = CEPH_MAX_READDIR_BYTES_DEFAULT;
333 fsopt->congestion_kb = default_congestion_kb();
334
335 /* ip1[:port1][,ip2[:port2]...]:/subdir/in/fs */
336 err = -EINVAL;
337 if (!dev_name)
338 goto out;
339 *path = strstr(dev_name, ":/");
340 if (*path == NULL) {
341 pr_err("device name is missing path (no :/ in %s)\n",
342 dev_name);
343 goto out;
344 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700345 dev_name_end = *path;
346 dout("device name '%.*s'\n", (int)(dev_name_end - dev_name), dev_name);
347
348 /* path on server */
349 *path += 2;
350 dout("server path '%s'\n", *path);
351
Alex Elderee577412012-01-24 10:08:36 -0600352 *popt = ceph_parse_options(options, dev_name, dev_name_end,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700353 parse_fsopt_token, (void *)fsopt);
Alex Elderee577412012-01-24 10:08:36 -0600354 if (IS_ERR(*popt)) {
355 err = PTR_ERR(*popt);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700356 goto out;
Alex Elderee577412012-01-24 10:08:36 -0600357 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700358
359 /* success */
360 *pfsopt = fsopt;
361 return 0;
362
363out:
364 destroy_mount_options(fsopt);
365 return err;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800366}
367
Sage Weil6e19a162010-04-29 16:38:32 -0700368/**
369 * ceph_show_options - Show mount options in /proc/mounts
370 * @m: seq_file to write to
Al Viro34c80b12011-12-08 21:32:45 -0500371 * @root: root of that (sub)tree
Sage Weil6e19a162010-04-29 16:38:32 -0700372 */
Al Viro34c80b12011-12-08 21:32:45 -0500373static int ceph_show_options(struct seq_file *m, struct dentry *root)
Sage Weil6e19a162010-04-29 16:38:32 -0700374{
Al Viro34c80b12011-12-08 21:32:45 -0500375 struct ceph_fs_client *fsc = ceph_sb_to_client(root->d_sb);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700376 struct ceph_mount_options *fsopt = fsc->mount_options;
377 struct ceph_options *opt = fsc->client->options;
Sage Weil6e19a162010-04-29 16:38:32 -0700378
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700379 if (opt->flags & CEPH_OPT_FSID)
380 seq_printf(m, ",fsid=%pU", &opt->fsid);
381 if (opt->flags & CEPH_OPT_NOSHARE)
Sage Weil6e19a162010-04-29 16:38:32 -0700382 seq_puts(m, ",noshare");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700383 if (opt->flags & CEPH_OPT_NOCRC)
Sage Weil6e19a162010-04-29 16:38:32 -0700384 seq_puts(m, ",nocrc");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700385
386 if (opt->name)
387 seq_printf(m, ",name=%s", opt->name);
Tommi Virtanen8323c3a2011-03-25 16:32:57 -0700388 if (opt->key)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700389 seq_puts(m, ",secret=<hidden>");
390
391 if (opt->mount_timeout != CEPH_MOUNT_TIMEOUT_DEFAULT)
392 seq_printf(m, ",mount_timeout=%d", opt->mount_timeout);
393 if (opt->osd_idle_ttl != CEPH_OSD_IDLE_TTL_DEFAULT)
394 seq_printf(m, ",osd_idle_ttl=%d", opt->osd_idle_ttl);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700395 if (opt->osd_keepalive_timeout != CEPH_OSD_KEEPALIVE_DEFAULT)
396 seq_printf(m, ",osdkeepalivetimeout=%d",
397 opt->osd_keepalive_timeout);
398
399 if (fsopt->flags & CEPH_MOUNT_OPT_DIRSTAT)
400 seq_puts(m, ",dirstat");
401 if ((fsopt->flags & CEPH_MOUNT_OPT_RBYTES) == 0)
402 seq_puts(m, ",norbytes");
403 if (fsopt->flags & CEPH_MOUNT_OPT_NOASYNCREADDIR)
Sage Weil6e19a162010-04-29 16:38:32 -0700404 seq_puts(m, ",noasyncreaddir");
Sage Weila40dc6c2012-01-10 09:12:55 -0800405 if (fsopt->flags & CEPH_MOUNT_OPT_DCACHE)
406 seq_puts(m, ",dcache");
407 else
408 seq_puts(m, ",nodcache");
Sage Weil6e19a162010-04-29 16:38:32 -0700409
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700410 if (fsopt->wsize)
411 seq_printf(m, ",wsize=%d", fsopt->wsize);
Sage Weil80456f82011-03-10 13:33:26 -0800412 if (fsopt->rsize != CEPH_RSIZE_DEFAULT)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700413 seq_printf(m, ",rsize=%d", fsopt->rsize);
Sage Weil83817e32011-08-04 08:03:44 -0700414 if (fsopt->rasize != CEPH_RASIZE_DEFAULT)
Sage Weil21519372011-12-01 08:06:52 -0800415 seq_printf(m, ",rasize=%d", fsopt->rasize);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700416 if (fsopt->congestion_kb != default_congestion_kb())
417 seq_printf(m, ",write_congestion_kb=%d", fsopt->congestion_kb);
418 if (fsopt->caps_wanted_delay_min != CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT)
Sage Weil6e19a162010-04-29 16:38:32 -0700419 seq_printf(m, ",caps_wanted_delay_min=%d",
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700420 fsopt->caps_wanted_delay_min);
421 if (fsopt->caps_wanted_delay_max != CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT)
Sage Weil6e19a162010-04-29 16:38:32 -0700422 seq_printf(m, ",caps_wanted_delay_max=%d",
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700423 fsopt->caps_wanted_delay_max);
424 if (fsopt->cap_release_safety != CEPH_CAP_RELEASE_SAFETY_DEFAULT)
Sage Weil6e19a162010-04-29 16:38:32 -0700425 seq_printf(m, ",cap_release_safety=%d",
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700426 fsopt->cap_release_safety);
427 if (fsopt->max_readdir != CEPH_MAX_READDIR_DEFAULT)
428 seq_printf(m, ",readdir_max_entries=%d", fsopt->max_readdir);
429 if (fsopt->max_readdir_bytes != CEPH_MAX_READDIR_BYTES_DEFAULT)
430 seq_printf(m, ",readdir_max_bytes=%d", fsopt->max_readdir_bytes);
431 if (strcmp(fsopt->snapdir_name, CEPH_SNAPDIRNAME_DEFAULT))
432 seq_printf(m, ",snapdirname=%s", fsopt->snapdir_name);
Sage Weil6e19a162010-04-29 16:38:32 -0700433 return 0;
434}
435
436/*
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700437 * handle any mon messages the standard library doesn't understand.
438 * return error if we don't either.
439 */
440static int extra_mon_dispatch(struct ceph_client *client, struct ceph_msg *msg)
441{
442 struct ceph_fs_client *fsc = client->private;
443 int type = le16_to_cpu(msg->hdr.type);
444
445 switch (type) {
446 case CEPH_MSG_MDS_MAP:
447 ceph_mdsc_handle_map(fsc->mdsc, msg);
448 return 0;
449
450 default:
451 return -1;
452 }
453}
454
455/*
456 * create a new fs client
457 */
H Hartley Sweeten0c6d4b42011-09-23 11:53:30 -0700458static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700459 struct ceph_options *opt)
460{
461 struct ceph_fs_client *fsc;
Sage Weil6ab00d42011-08-09 09:41:59 -0700462 const unsigned supported_features =
463 CEPH_FEATURE_FLOCK |
464 CEPH_FEATURE_DIRLAYOUTHASH;
465 const unsigned required_features = 0;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700466 int err = -ENOMEM;
467
468 fsc = kzalloc(sizeof(*fsc), GFP_KERNEL);
469 if (!fsc)
470 return ERR_PTR(-ENOMEM);
471
Sage Weil6ab00d42011-08-09 09:41:59 -0700472 fsc->client = ceph_create_client(opt, fsc, supported_features,
473 required_features);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700474 if (IS_ERR(fsc->client)) {
475 err = PTR_ERR(fsc->client);
476 goto fail;
477 }
478 fsc->client->extra_mon_dispatch = extra_mon_dispatch;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700479 fsc->client->monc.want_mdsmap = 1;
480
481 fsc->mount_options = fsopt;
482
483 fsc->sb = NULL;
484 fsc->mount_state = CEPH_MOUNT_MOUNTING;
485
486 atomic_long_set(&fsc->writeback_count, 0);
487
488 err = bdi_init(&fsc->backing_dev_info);
489 if (err < 0)
490 goto fail_client;
491
492 err = -ENOMEM;
Tejun Heo01e6acc2011-01-03 14:49:45 +0100493 /*
494 * The number of concurrent works can be high but they don't need
495 * to be processed in parallel, limit concurrency.
496 */
497 fsc->wb_wq = alloc_workqueue("ceph-writeback", 0, 1);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700498 if (fsc->wb_wq == NULL)
499 goto fail_bdi;
Tejun Heo01e6acc2011-01-03 14:49:45 +0100500 fsc->pg_inv_wq = alloc_workqueue("ceph-pg-invalid", 0, 1);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700501 if (fsc->pg_inv_wq == NULL)
502 goto fail_wb_wq;
Tejun Heo01e6acc2011-01-03 14:49:45 +0100503 fsc->trunc_wq = alloc_workqueue("ceph-trunc", 0, 1);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700504 if (fsc->trunc_wq == NULL)
505 goto fail_pg_inv_wq;
506
507 /* set up mempools */
508 err = -ENOMEM;
509 fsc->wb_pagevec_pool = mempool_create_kmalloc_pool(10,
510 fsc->mount_options->wsize >> PAGE_CACHE_SHIFT);
511 if (!fsc->wb_pagevec_pool)
512 goto fail_trunc_wq;
513
514 /* caps */
515 fsc->min_caps = fsopt->max_readdir;
516
517 return fsc;
518
519fail_trunc_wq:
520 destroy_workqueue(fsc->trunc_wq);
521fail_pg_inv_wq:
522 destroy_workqueue(fsc->pg_inv_wq);
523fail_wb_wq:
524 destroy_workqueue(fsc->wb_wq);
525fail_bdi:
526 bdi_destroy(&fsc->backing_dev_info);
527fail_client:
528 ceph_destroy_client(fsc->client);
529fail:
530 kfree(fsc);
531 return ERR_PTR(err);
532}
533
H Hartley Sweeten0c6d4b42011-09-23 11:53:30 -0700534static void destroy_fs_client(struct ceph_fs_client *fsc)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700535{
536 dout("destroy_fs_client %p\n", fsc);
537
538 destroy_workqueue(fsc->wb_wq);
539 destroy_workqueue(fsc->pg_inv_wq);
540 destroy_workqueue(fsc->trunc_wq);
541
542 bdi_destroy(&fsc->backing_dev_info);
543
544 mempool_destroy(fsc->wb_pagevec_pool);
545
546 destroy_mount_options(fsc->mount_options);
547
548 ceph_fs_debugfs_cleanup(fsc);
549
550 ceph_destroy_client(fsc->client);
551
552 kfree(fsc);
553 dout("destroy_fs_client %p done\n", fsc);
554}
555
556/*
Sage Weil6e19a162010-04-29 16:38:32 -0700557 * caches
558 */
559struct kmem_cache *ceph_inode_cachep;
560struct kmem_cache *ceph_cap_cachep;
561struct kmem_cache *ceph_dentry_cachep;
562struct kmem_cache *ceph_file_cachep;
563
564static void ceph_inode_init_once(void *foo)
565{
566 struct ceph_inode_info *ci = foo;
567 inode_init_once(&ci->vfs_inode);
568}
569
Sage Weil16725b92009-10-06 11:31:07 -0700570static int __init init_caches(void)
571{
572 ceph_inode_cachep = kmem_cache_create("ceph_inode_info",
573 sizeof(struct ceph_inode_info),
574 __alignof__(struct ceph_inode_info),
575 (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
576 ceph_inode_init_once);
577 if (ceph_inode_cachep == NULL)
578 return -ENOMEM;
579
580 ceph_cap_cachep = KMEM_CACHE(ceph_cap,
581 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
582 if (ceph_cap_cachep == NULL)
583 goto bad_cap;
584
585 ceph_dentry_cachep = KMEM_CACHE(ceph_dentry_info,
586 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
587 if (ceph_dentry_cachep == NULL)
588 goto bad_dentry;
589
590 ceph_file_cachep = KMEM_CACHE(ceph_file_info,
591 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
592 if (ceph_file_cachep == NULL)
593 goto bad_file;
594
595 return 0;
596
597bad_file:
598 kmem_cache_destroy(ceph_dentry_cachep);
599bad_dentry:
600 kmem_cache_destroy(ceph_cap_cachep);
601bad_cap:
602 kmem_cache_destroy(ceph_inode_cachep);
603 return -ENOMEM;
604}
605
606static void destroy_caches(void)
607{
608 kmem_cache_destroy(ceph_inode_cachep);
609 kmem_cache_destroy(ceph_cap_cachep);
610 kmem_cache_destroy(ceph_dentry_cachep);
611 kmem_cache_destroy(ceph_file_cachep);
612}
613
614
615/*
616 * ceph_umount_begin - initiate forced umount. Tear down down the
617 * mount, skipping steps that may hang while waiting for server(s).
618 */
619static void ceph_umount_begin(struct super_block *sb)
620{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700621 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
Sage Weil16725b92009-10-06 11:31:07 -0700622
623 dout("ceph_umount_begin - starting forced umount\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700624 if (!fsc)
Sage Weil16725b92009-10-06 11:31:07 -0700625 return;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700626 fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
Sage Weil16725b92009-10-06 11:31:07 -0700627 return;
628}
629
630static const struct super_operations ceph_super_ops = {
631 .alloc_inode = ceph_alloc_inode,
632 .destroy_inode = ceph_destroy_inode,
633 .write_inode = ceph_write_inode,
Sage Weil2d9c98a2010-07-30 09:38:13 -0700634 .sync_fs = ceph_sync_fs,
Sage Weil16725b92009-10-06 11:31:07 -0700635 .put_super = ceph_put_super,
636 .show_options = ceph_show_options,
637 .statfs = ceph_statfs,
638 .umount_begin = ceph_umount_begin,
639};
640
Sage Weil16725b92009-10-06 11:31:07 -0700641/*
642 * Bootstrap mount by opening the root directory. Note the mount
643 * @started time from caller, and time out if this takes too long.
644 */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700645static struct dentry *open_root_dentry(struct ceph_fs_client *fsc,
Sage Weil16725b92009-10-06 11:31:07 -0700646 const char *path,
647 unsigned long started)
648{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700649 struct ceph_mds_client *mdsc = fsc->mdsc;
Sage Weil16725b92009-10-06 11:31:07 -0700650 struct ceph_mds_request *req = NULL;
651 int err;
652 struct dentry *root;
653
654 /* open dir */
655 dout("open_root_inode opening '%s'\n", path);
656 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_GETATTR, USE_ANY_MDS);
657 if (IS_ERR(req))
Julia Lawall7e34bc52010-05-22 12:01:14 +0200658 return ERR_CAST(req);
Sage Weil16725b92009-10-06 11:31:07 -0700659 req->r_path1 = kstrdup(path, GFP_NOFS);
660 req->r_ino1.ino = CEPH_INO_ROOT;
661 req->r_ino1.snap = CEPH_NOSNAP;
662 req->r_started = started;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700663 req->r_timeout = fsc->client->options->mount_timeout * HZ;
Sage Weil16725b92009-10-06 11:31:07 -0700664 req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INODE);
665 req->r_num_caps = 2;
666 err = ceph_mdsc_do_request(mdsc, NULL, req);
667 if (err == 0) {
Al Viro3c5184e2012-01-09 16:34:32 -0500668 struct inode *inode = req->r_target_inode;
669 req->r_target_inode = NULL;
Sage Weil16725b92009-10-06 11:31:07 -0700670 dout("open_root_inode success\n");
Al Viro3c5184e2012-01-09 16:34:32 -0500671 if (ceph_ino(inode) == CEPH_INO_ROOT &&
Sage Weil774ac212011-11-11 09:48:08 -0800672 fsc->sb->s_root == NULL) {
Al Viro48fde702012-01-08 22:15:13 -0500673 root = d_make_root(inode);
Al Viro3c5184e2012-01-09 16:34:32 -0500674 if (!root) {
Al Viro3c5184e2012-01-09 16:34:32 -0500675 root = ERR_PTR(-ENOMEM);
676 goto out;
677 }
Sage Weil774ac212011-11-11 09:48:08 -0800678 } else {
Al Viro3c5184e2012-01-09 16:34:32 -0500679 root = d_obtain_alias(inode);
Sage Weil774ac212011-11-11 09:48:08 -0800680 }
Linus Torvalds1a52bb02012-01-13 10:29:21 -0800681 ceph_init_dentry(root);
Sage Weil16725b92009-10-06 11:31:07 -0700682 dout("open_root_inode success, root dentry is %p\n", root);
683 } else {
684 root = ERR_PTR(err);
685 }
Al Viro3c5184e2012-01-09 16:34:32 -0500686out:
Sage Weil16725b92009-10-06 11:31:07 -0700687 ceph_mdsc_put_request(req);
688 return root;
689}
690
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700691
692
693
Sage Weil16725b92009-10-06 11:31:07 -0700694/*
695 * mount: join the ceph cluster, and open root directory.
696 */
Al Viroa7f9fb22010-07-26 16:17:55 +0400697static struct dentry *ceph_real_mount(struct ceph_fs_client *fsc,
Sage Weil16725b92009-10-06 11:31:07 -0700698 const char *path)
699{
Sage Weil16725b92009-10-06 11:31:07 -0700700 int err;
Sage Weil16725b92009-10-06 11:31:07 -0700701 unsigned long started = jiffies; /* note the start time */
702 struct dentry *root;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700703 int first = 0; /* first vfsmount for this super_block */
Sage Weil16725b92009-10-06 11:31:07 -0700704
705 dout("mount start\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700706 mutex_lock(&fsc->client->mount_mutex);
Sage Weil16725b92009-10-06 11:31:07 -0700707
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700708 err = __ceph_open_session(fsc->client, started);
Sage Weil16725b92009-10-06 11:31:07 -0700709 if (err < 0)
710 goto out;
711
Sage Weil16725b92009-10-06 11:31:07 -0700712 dout("mount opening root\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700713 root = open_root_dentry(fsc, "", started);
Sage Weil16725b92009-10-06 11:31:07 -0700714 if (IS_ERR(root)) {
715 err = PTR_ERR(root);
716 goto out;
717 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700718 if (fsc->sb->s_root) {
Sage Weil16725b92009-10-06 11:31:07 -0700719 dput(root);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700720 } else {
721 fsc->sb->s_root = root;
722 first = 1;
723
724 err = ceph_fs_debugfs_init(fsc);
725 if (err < 0)
726 goto fail;
727 }
Sage Weil16725b92009-10-06 11:31:07 -0700728
729 if (path[0] == 0) {
730 dget(root);
731 } else {
732 dout("mount opening base mountpoint\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700733 root = open_root_dentry(fsc, path, started);
Sage Weil16725b92009-10-06 11:31:07 -0700734 if (IS_ERR(root)) {
735 err = PTR_ERR(root);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700736 goto fail;
Sage Weil16725b92009-10-06 11:31:07 -0700737 }
738 }
739
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700740 fsc->mount_state = CEPH_MOUNT_MOUNTED;
Sage Weil16725b92009-10-06 11:31:07 -0700741 dout("mount success\n");
Al Viroa7f9fb22010-07-26 16:17:55 +0400742 mutex_unlock(&fsc->client->mount_mutex);
743 return root;
Sage Weil16725b92009-10-06 11:31:07 -0700744
745out:
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700746 mutex_unlock(&fsc->client->mount_mutex);
Al Viroa7f9fb22010-07-26 16:17:55 +0400747 return ERR_PTR(err);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700748
749fail:
750 if (first) {
751 dput(fsc->sb->s_root);
752 fsc->sb->s_root = NULL;
753 }
754 goto out;
Sage Weil16725b92009-10-06 11:31:07 -0700755}
756
757static int ceph_set_super(struct super_block *s, void *data)
758{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700759 struct ceph_fs_client *fsc = data;
Sage Weil16725b92009-10-06 11:31:07 -0700760 int ret;
761
762 dout("set_super %p data %p\n", s, data);
763
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700764 s->s_flags = fsc->mount_options->sb_flags;
Sage Weil16725b92009-10-06 11:31:07 -0700765 s->s_maxbytes = 1ULL << 40; /* temp value until we get mdsmap */
766
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700767 s->s_fs_info = fsc;
768 fsc->sb = s;
Sage Weil16725b92009-10-06 11:31:07 -0700769
770 s->s_op = &ceph_super_ops;
771 s->s_export_op = &ceph_export_ops;
772
773 s->s_time_gran = 1000; /* 1000 ns == 1 us */
774
775 ret = set_anon_super(s, NULL); /* what is that second arg for? */
776 if (ret != 0)
777 goto fail;
778
779 return ret;
780
781fail:
782 s->s_fs_info = NULL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700783 fsc->sb = NULL;
Sage Weil16725b92009-10-06 11:31:07 -0700784 return ret;
785}
786
787/*
788 * share superblock if same fs AND options
789 */
790static int ceph_compare_super(struct super_block *sb, void *data)
791{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700792 struct ceph_fs_client *new = data;
793 struct ceph_mount_options *fsopt = new->mount_options;
794 struct ceph_options *opt = new->client->options;
795 struct ceph_fs_client *other = ceph_sb_to_client(sb);
Sage Weil16725b92009-10-06 11:31:07 -0700796
797 dout("ceph_compare_super %p\n", sb);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700798
799 if (compare_mount_options(fsopt, opt, other)) {
800 dout("monitor(s)/mount options don't match\n");
801 return 0;
Sage Weil16725b92009-10-06 11:31:07 -0700802 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700803 if ((opt->flags & CEPH_OPT_FSID) &&
804 ceph_fsid_compare(&opt->fsid, &other->client->fsid)) {
805 dout("fsid doesn't match\n");
806 return 0;
807 }
808 if (fsopt->sb_flags != other->mount_options->sb_flags) {
Sage Weil16725b92009-10-06 11:31:07 -0700809 dout("flags differ\n");
810 return 0;
811 }
812 return 1;
813}
814
815/*
816 * construct our own bdi so we can control readahead, etc.
817 */
Jeff Mahoney00d56432010-06-10 11:13:58 -0400818static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
Sage Weil31e0cf82010-05-04 16:39:35 -0700819
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700820static int ceph_register_bdi(struct super_block *sb,
821 struct ceph_fs_client *fsc)
Sage Weil16725b92009-10-06 11:31:07 -0700822{
823 int err;
824
Sage Weil83817e32011-08-04 08:03:44 -0700825 /* set ra_pages based on rasize mount option? */
826 if (fsc->mount_options->rasize >= PAGE_CACHE_SIZE)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700827 fsc->backing_dev_info.ra_pages =
Sage Weil83817e32011-08-04 08:03:44 -0700828 (fsc->mount_options->rasize + PAGE_CACHE_SIZE - 1)
Sage Weil16725b92009-10-06 11:31:07 -0700829 >> PAGE_SHIFT;
Yehuda Sadehe9852222011-07-22 11:12:28 -0700830 else
831 fsc->backing_dev_info.ra_pages =
832 default_backing_dev_info.ra_pages;
833
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700834 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%d",
Sage Weil31e0cf82010-05-04 16:39:35 -0700835 atomic_long_inc_return(&bdi_seq));
Sage Weil5dfc5892010-05-04 16:14:46 -0700836 if (!err)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700837 sb->s_bdi = &fsc->backing_dev_info;
Sage Weil16725b92009-10-06 11:31:07 -0700838 return err;
839}
840
Al Viroa7f9fb22010-07-26 16:17:55 +0400841static struct dentry *ceph_mount(struct file_system_type *fs_type,
842 int flags, const char *dev_name, void *data)
Sage Weil16725b92009-10-06 11:31:07 -0700843{
844 struct super_block *sb;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700845 struct ceph_fs_client *fsc;
Al Viroa7f9fb22010-07-26 16:17:55 +0400846 struct dentry *res;
Sage Weil16725b92009-10-06 11:31:07 -0700847 int err;
848 int (*compare_super)(struct super_block *, void *) = ceph_compare_super;
Sage Weil6a18be12009-11-04 11:40:05 -0800849 const char *path = NULL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700850 struct ceph_mount_options *fsopt = NULL;
851 struct ceph_options *opt = NULL;
Sage Weil16725b92009-10-06 11:31:07 -0700852
Al Viroa7f9fb22010-07-26 16:17:55 +0400853 dout("ceph_mount\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700854 err = parse_mount_options(&fsopt, &opt, flags, data, dev_name, &path);
Al Viroa7f9fb22010-07-26 16:17:55 +0400855 if (err < 0) {
856 res = ERR_PTR(err);
Sage Weil6b805182009-10-27 11:50:50 -0700857 goto out_final;
Al Viroa7f9fb22010-07-26 16:17:55 +0400858 }
Sage Weil16725b92009-10-06 11:31:07 -0700859
860 /* create client (which we may/may not use) */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700861 fsc = create_fs_client(fsopt, opt);
862 if (IS_ERR(fsc)) {
Al Viroa7f9fb22010-07-26 16:17:55 +0400863 res = ERR_CAST(fsc);
Noah Watkins259a1872011-08-22 13:49:41 -0600864 destroy_mount_options(fsopt);
865 ceph_destroy_options(opt);
Sage Weil6b805182009-10-27 11:50:50 -0700866 goto out_final;
867 }
Sage Weil16725b92009-10-06 11:31:07 -0700868
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700869 err = ceph_mdsc_init(fsc);
Al Viroa7f9fb22010-07-26 16:17:55 +0400870 if (err < 0) {
871 res = ERR_PTR(err);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700872 goto out;
Al Viroa7f9fb22010-07-26 16:17:55 +0400873 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700874
875 if (ceph_test_opt(fsc->client, NOSHARE))
Sage Weil16725b92009-10-06 11:31:07 -0700876 compare_super = NULL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700877 sb = sget(fs_type, compare_super, ceph_set_super, fsc);
Sage Weil16725b92009-10-06 11:31:07 -0700878 if (IS_ERR(sb)) {
Al Viroa7f9fb22010-07-26 16:17:55 +0400879 res = ERR_CAST(sb);
Sage Weil16725b92009-10-06 11:31:07 -0700880 goto out;
881 }
882
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700883 if (ceph_sb_to_client(sb) != fsc) {
884 ceph_mdsc_destroy(fsc);
885 destroy_fs_client(fsc);
886 fsc = ceph_sb_to_client(sb);
887 dout("get_sb got existing client %p\n", fsc);
Sage Weil16725b92009-10-06 11:31:07 -0700888 } else {
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700889 dout("get_sb using new client %p\n", fsc);
890 err = ceph_register_bdi(sb, fsc);
Al Viroa7f9fb22010-07-26 16:17:55 +0400891 if (err < 0) {
892 res = ERR_PTR(err);
Sage Weil16725b92009-10-06 11:31:07 -0700893 goto out_splat;
Al Viroa7f9fb22010-07-26 16:17:55 +0400894 }
Sage Weil16725b92009-10-06 11:31:07 -0700895 }
896
Al Viroa7f9fb22010-07-26 16:17:55 +0400897 res = ceph_real_mount(fsc, path);
898 if (IS_ERR(res))
Sage Weil16725b92009-10-06 11:31:07 -0700899 goto out_splat;
Al Viroa7f9fb22010-07-26 16:17:55 +0400900 dout("root %p inode %p ino %llx.%llx\n", res,
901 res->d_inode, ceph_vinop(res->d_inode));
902 return res;
Sage Weil16725b92009-10-06 11:31:07 -0700903
904out_splat:
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700905 ceph_mdsc_close_sessions(fsc->mdsc);
Al Viro3981f2e2010-03-21 19:22:29 -0400906 deactivate_locked_super(sb);
Sage Weil16725b92009-10-06 11:31:07 -0700907 goto out_final;
908
909out:
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700910 ceph_mdsc_destroy(fsc);
911 destroy_fs_client(fsc);
Sage Weil16725b92009-10-06 11:31:07 -0700912out_final:
Al Viroa7f9fb22010-07-26 16:17:55 +0400913 dout("ceph_mount fail %ld\n", PTR_ERR(res));
914 return res;
Sage Weil16725b92009-10-06 11:31:07 -0700915}
916
917static void ceph_kill_sb(struct super_block *s)
918{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700919 struct ceph_fs_client *fsc = ceph_sb_to_client(s);
Sage Weil16725b92009-10-06 11:31:07 -0700920 dout("kill_sb %p\n", s);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700921 ceph_mdsc_pre_umount(fsc->mdsc);
Sage Weil16725b92009-10-06 11:31:07 -0700922 kill_anon_super(s); /* will call put_super after sb is r/o */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700923 ceph_mdsc_destroy(fsc);
924 destroy_fs_client(fsc);
Sage Weil16725b92009-10-06 11:31:07 -0700925}
926
927static struct file_system_type ceph_fs_type = {
928 .owner = THIS_MODULE,
929 .name = "ceph",
Al Viroa7f9fb22010-07-26 16:17:55 +0400930 .mount = ceph_mount,
Sage Weil16725b92009-10-06 11:31:07 -0700931 .kill_sb = ceph_kill_sb,
932 .fs_flags = FS_RENAME_DOES_D_MOVE,
933};
934
935#define _STRINGIFY(x) #x
936#define STRINGIFY(x) _STRINGIFY(x)
937
938static int __init init_ceph(void)
939{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700940 int ret = init_caches();
Sage Weil16725b92009-10-06 11:31:07 -0700941 if (ret)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700942 goto out;
Sage Weil16725b92009-10-06 11:31:07 -0700943
Alex Elder3ce6cd12012-01-23 15:49:28 -0600944 ceph_xattr_init();
Sage Weil16725b92009-10-06 11:31:07 -0700945 ret = register_filesystem(&ceph_fs_type);
946 if (ret)
947 goto out_icache;
948
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700949 pr_info("loaded (mds proto %d)\n", CEPH_MDSC_PROTOCOL);
950
Sage Weil16725b92009-10-06 11:31:07 -0700951 return 0;
952
953out_icache:
Alex Elder3ce6cd12012-01-23 15:49:28 -0600954 ceph_xattr_exit();
Sage Weil16725b92009-10-06 11:31:07 -0700955 destroy_caches();
Sage Weil16725b92009-10-06 11:31:07 -0700956out:
957 return ret;
958}
959
960static void __exit exit_ceph(void)
961{
962 dout("exit_ceph\n");
963 unregister_filesystem(&ceph_fs_type);
Alex Elder3ce6cd12012-01-23 15:49:28 -0600964 ceph_xattr_exit();
Sage Weil16725b92009-10-06 11:31:07 -0700965 destroy_caches();
Sage Weil16725b92009-10-06 11:31:07 -0700966}
967
968module_init(init_ceph);
969module_exit(exit_ceph);
970
971MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
972MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
973MODULE_AUTHOR("Patience Warnick <patience@newdream.net>");
974MODULE_DESCRIPTION("Ceph filesystem for Linux");
975MODULE_LICENSE("GPL");