blob: 33a32ad9c6a4ec66e321a91534aed862aa09007e [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 Weil486eae12013-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 Weil486eae12013-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
Kees Cook1c2c11f2015-09-04 15:44:57 -0700386 if (opt->name) {
387 seq_puts(m, ",name=");
388 seq_escape(m, opt->name, ", \t\n\\");
389 }
Tommi Virtanen8323c3a2011-03-25 16:32:57 -0700390 if (opt->key)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700391 seq_puts(m, ",secret=<hidden>");
392
393 if (opt->mount_timeout != CEPH_MOUNT_TIMEOUT_DEFAULT)
394 seq_printf(m, ",mount_timeout=%d", opt->mount_timeout);
395 if (opt->osd_idle_ttl != CEPH_OSD_IDLE_TTL_DEFAULT)
396 seq_printf(m, ",osd_idle_ttl=%d", opt->osd_idle_ttl);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700397 if (opt->osd_keepalive_timeout != CEPH_OSD_KEEPALIVE_DEFAULT)
398 seq_printf(m, ",osdkeepalivetimeout=%d",
399 opt->osd_keepalive_timeout);
400
401 if (fsopt->flags & CEPH_MOUNT_OPT_DIRSTAT)
402 seq_puts(m, ",dirstat");
403 if ((fsopt->flags & CEPH_MOUNT_OPT_RBYTES) == 0)
404 seq_puts(m, ",norbytes");
405 if (fsopt->flags & CEPH_MOUNT_OPT_NOASYNCREADDIR)
Sage Weil6e19a162010-04-29 16:38:32 -0700406 seq_puts(m, ",noasyncreaddir");
Sage Weila40dc6c2012-01-10 09:12:55 -0800407 if (fsopt->flags & CEPH_MOUNT_OPT_DCACHE)
408 seq_puts(m, ",dcache");
409 else
410 seq_puts(m, ",nodcache");
Sage Weil6e19a162010-04-29 16:38:32 -0700411
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700412 if (fsopt->wsize)
413 seq_printf(m, ",wsize=%d", fsopt->wsize);
Sage Weil80456f82011-03-10 13:33:26 -0800414 if (fsopt->rsize != CEPH_RSIZE_DEFAULT)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700415 seq_printf(m, ",rsize=%d", fsopt->rsize);
Sage Weil83817e32011-08-04 08:03:44 -0700416 if (fsopt->rasize != CEPH_RASIZE_DEFAULT)
Sage Weil21519372011-12-01 08:06:52 -0800417 seq_printf(m, ",rasize=%d", fsopt->rasize);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700418 if (fsopt->congestion_kb != default_congestion_kb())
419 seq_printf(m, ",write_congestion_kb=%d", fsopt->congestion_kb);
420 if (fsopt->caps_wanted_delay_min != CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT)
Sage Weil6e19a162010-04-29 16:38:32 -0700421 seq_printf(m, ",caps_wanted_delay_min=%d",
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700422 fsopt->caps_wanted_delay_min);
423 if (fsopt->caps_wanted_delay_max != CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT)
Sage Weil6e19a162010-04-29 16:38:32 -0700424 seq_printf(m, ",caps_wanted_delay_max=%d",
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700425 fsopt->caps_wanted_delay_max);
426 if (fsopt->cap_release_safety != CEPH_CAP_RELEASE_SAFETY_DEFAULT)
Sage Weil6e19a162010-04-29 16:38:32 -0700427 seq_printf(m, ",cap_release_safety=%d",
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700428 fsopt->cap_release_safety);
429 if (fsopt->max_readdir != CEPH_MAX_READDIR_DEFAULT)
430 seq_printf(m, ",readdir_max_entries=%d", fsopt->max_readdir);
431 if (fsopt->max_readdir_bytes != CEPH_MAX_READDIR_BYTES_DEFAULT)
432 seq_printf(m, ",readdir_max_bytes=%d", fsopt->max_readdir_bytes);
433 if (strcmp(fsopt->snapdir_name, CEPH_SNAPDIRNAME_DEFAULT))
Kees Cook1c2c11f2015-09-04 15:44:57 -0700434 seq_show_option(m, "snapdirname", fsopt->snapdir_name);
Sage Weil6e19a162010-04-29 16:38:32 -0700435 return 0;
436}
437
438/*
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700439 * handle any mon messages the standard library doesn't understand.
440 * return error if we don't either.
441 */
442static int extra_mon_dispatch(struct ceph_client *client, struct ceph_msg *msg)
443{
444 struct ceph_fs_client *fsc = client->private;
445 int type = le16_to_cpu(msg->hdr.type);
446
447 switch (type) {
448 case CEPH_MSG_MDS_MAP:
449 ceph_mdsc_handle_map(fsc->mdsc, msg);
450 return 0;
451
452 default:
453 return -1;
454 }
455}
456
457/*
458 * create a new fs client
459 */
H Hartley Sweeten0c6d4b42011-09-23 11:53:30 -0700460static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700461 struct ceph_options *opt)
462{
463 struct ceph_fs_client *fsc;
Sage Weil6ab00d42011-08-09 09:41:59 -0700464 const unsigned supported_features =
465 CEPH_FEATURE_FLOCK |
466 CEPH_FEATURE_DIRLAYOUTHASH;
467 const unsigned required_features = 0;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700468 int err = -ENOMEM;
469
470 fsc = kzalloc(sizeof(*fsc), GFP_KERNEL);
471 if (!fsc)
472 return ERR_PTR(-ENOMEM);
473
Sage Weil6ab00d42011-08-09 09:41:59 -0700474 fsc->client = ceph_create_client(opt, fsc, supported_features,
475 required_features);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700476 if (IS_ERR(fsc->client)) {
477 err = PTR_ERR(fsc->client);
478 goto fail;
479 }
480 fsc->client->extra_mon_dispatch = extra_mon_dispatch;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700481 fsc->client->monc.want_mdsmap = 1;
482
483 fsc->mount_options = fsopt;
484
485 fsc->sb = NULL;
486 fsc->mount_state = CEPH_MOUNT_MOUNTING;
487
488 atomic_long_set(&fsc->writeback_count, 0);
489
490 err = bdi_init(&fsc->backing_dev_info);
491 if (err < 0)
492 goto fail_client;
493
494 err = -ENOMEM;
Tejun Heo01e6acc2011-01-03 14:49:45 +0100495 /*
496 * The number of concurrent works can be high but they don't need
497 * to be processed in parallel, limit concurrency.
498 */
499 fsc->wb_wq = alloc_workqueue("ceph-writeback", 0, 1);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700500 if (fsc->wb_wq == NULL)
501 goto fail_bdi;
Tejun Heo01e6acc2011-01-03 14:49:45 +0100502 fsc->pg_inv_wq = alloc_workqueue("ceph-pg-invalid", 0, 1);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700503 if (fsc->pg_inv_wq == NULL)
504 goto fail_wb_wq;
Tejun Heo01e6acc2011-01-03 14:49:45 +0100505 fsc->trunc_wq = alloc_workqueue("ceph-trunc", 0, 1);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700506 if (fsc->trunc_wq == NULL)
507 goto fail_pg_inv_wq;
508
509 /* set up mempools */
510 err = -ENOMEM;
511 fsc->wb_pagevec_pool = mempool_create_kmalloc_pool(10,
512 fsc->mount_options->wsize >> PAGE_CACHE_SHIFT);
513 if (!fsc->wb_pagevec_pool)
514 goto fail_trunc_wq;
515
516 /* caps */
517 fsc->min_caps = fsopt->max_readdir;
518
519 return fsc;
520
521fail_trunc_wq:
522 destroy_workqueue(fsc->trunc_wq);
523fail_pg_inv_wq:
524 destroy_workqueue(fsc->pg_inv_wq);
525fail_wb_wq:
526 destroy_workqueue(fsc->wb_wq);
527fail_bdi:
528 bdi_destroy(&fsc->backing_dev_info);
529fail_client:
530 ceph_destroy_client(fsc->client);
531fail:
532 kfree(fsc);
533 return ERR_PTR(err);
534}
535
H Hartley Sweeten0c6d4b42011-09-23 11:53:30 -0700536static void destroy_fs_client(struct ceph_fs_client *fsc)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700537{
538 dout("destroy_fs_client %p\n", fsc);
539
540 destroy_workqueue(fsc->wb_wq);
541 destroy_workqueue(fsc->pg_inv_wq);
542 destroy_workqueue(fsc->trunc_wq);
543
544 bdi_destroy(&fsc->backing_dev_info);
545
546 mempool_destroy(fsc->wb_pagevec_pool);
547
548 destroy_mount_options(fsc->mount_options);
549
550 ceph_fs_debugfs_cleanup(fsc);
551
552 ceph_destroy_client(fsc->client);
553
554 kfree(fsc);
555 dout("destroy_fs_client %p done\n", fsc);
556}
557
558/*
Sage Weil6e19a162010-04-29 16:38:32 -0700559 * caches
560 */
561struct kmem_cache *ceph_inode_cachep;
562struct kmem_cache *ceph_cap_cachep;
563struct kmem_cache *ceph_dentry_cachep;
564struct kmem_cache *ceph_file_cachep;
565
566static void ceph_inode_init_once(void *foo)
567{
568 struct ceph_inode_info *ci = foo;
569 inode_init_once(&ci->vfs_inode);
570}
571
Sage Weil16725b92009-10-06 11:31:07 -0700572static int __init init_caches(void)
573{
574 ceph_inode_cachep = kmem_cache_create("ceph_inode_info",
575 sizeof(struct ceph_inode_info),
576 __alignof__(struct ceph_inode_info),
577 (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
578 ceph_inode_init_once);
579 if (ceph_inode_cachep == NULL)
580 return -ENOMEM;
581
582 ceph_cap_cachep = KMEM_CACHE(ceph_cap,
583 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
584 if (ceph_cap_cachep == NULL)
585 goto bad_cap;
586
587 ceph_dentry_cachep = KMEM_CACHE(ceph_dentry_info,
588 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
589 if (ceph_dentry_cachep == NULL)
590 goto bad_dentry;
591
592 ceph_file_cachep = KMEM_CACHE(ceph_file_info,
593 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
594 if (ceph_file_cachep == NULL)
595 goto bad_file;
596
597 return 0;
598
599bad_file:
600 kmem_cache_destroy(ceph_dentry_cachep);
601bad_dentry:
602 kmem_cache_destroy(ceph_cap_cachep);
603bad_cap:
604 kmem_cache_destroy(ceph_inode_cachep);
605 return -ENOMEM;
606}
607
608static void destroy_caches(void)
609{
610 kmem_cache_destroy(ceph_inode_cachep);
611 kmem_cache_destroy(ceph_cap_cachep);
612 kmem_cache_destroy(ceph_dentry_cachep);
613 kmem_cache_destroy(ceph_file_cachep);
614}
615
616
617/*
618 * ceph_umount_begin - initiate forced umount. Tear down down the
619 * mount, skipping steps that may hang while waiting for server(s).
620 */
621static void ceph_umount_begin(struct super_block *sb)
622{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700623 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
Sage Weil16725b92009-10-06 11:31:07 -0700624
625 dout("ceph_umount_begin - starting forced umount\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700626 if (!fsc)
Sage Weil16725b92009-10-06 11:31:07 -0700627 return;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700628 fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
Sage Weil16725b92009-10-06 11:31:07 -0700629 return;
630}
631
632static const struct super_operations ceph_super_ops = {
633 .alloc_inode = ceph_alloc_inode,
634 .destroy_inode = ceph_destroy_inode,
635 .write_inode = ceph_write_inode,
Sage Weil2d9c98a2010-07-30 09:38:13 -0700636 .sync_fs = ceph_sync_fs,
Sage Weil16725b92009-10-06 11:31:07 -0700637 .put_super = ceph_put_super,
638 .show_options = ceph_show_options,
639 .statfs = ceph_statfs,
640 .umount_begin = ceph_umount_begin,
641};
642
Sage Weil16725b92009-10-06 11:31:07 -0700643/*
644 * Bootstrap mount by opening the root directory. Note the mount
645 * @started time from caller, and time out if this takes too long.
646 */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700647static struct dentry *open_root_dentry(struct ceph_fs_client *fsc,
Sage Weil16725b92009-10-06 11:31:07 -0700648 const char *path,
649 unsigned long started)
650{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700651 struct ceph_mds_client *mdsc = fsc->mdsc;
Sage Weil16725b92009-10-06 11:31:07 -0700652 struct ceph_mds_request *req = NULL;
653 int err;
654 struct dentry *root;
655
656 /* open dir */
657 dout("open_root_inode opening '%s'\n", path);
658 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_GETATTR, USE_ANY_MDS);
659 if (IS_ERR(req))
Julia Lawall7e34bc52010-05-22 12:01:14 +0200660 return ERR_CAST(req);
Sage Weil16725b92009-10-06 11:31:07 -0700661 req->r_path1 = kstrdup(path, GFP_NOFS);
662 req->r_ino1.ino = CEPH_INO_ROOT;
663 req->r_ino1.snap = CEPH_NOSNAP;
664 req->r_started = started;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700665 req->r_timeout = fsc->client->options->mount_timeout * HZ;
Sage Weil16725b92009-10-06 11:31:07 -0700666 req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INODE);
667 req->r_num_caps = 2;
668 err = ceph_mdsc_do_request(mdsc, NULL, req);
669 if (err == 0) {
Al Viro3c5184e2012-01-09 16:34:32 -0500670 struct inode *inode = req->r_target_inode;
671 req->r_target_inode = NULL;
Sage Weil16725b92009-10-06 11:31:07 -0700672 dout("open_root_inode success\n");
Al Viro3c5184e2012-01-09 16:34:32 -0500673 if (ceph_ino(inode) == CEPH_INO_ROOT &&
Sage Weil774ac212011-11-11 09:48:08 -0800674 fsc->sb->s_root == NULL) {
Al Viro48fde702012-01-08 22:15:13 -0500675 root = d_make_root(inode);
Al Viro3c5184e2012-01-09 16:34:32 -0500676 if (!root) {
Al Viro3c5184e2012-01-09 16:34:32 -0500677 root = ERR_PTR(-ENOMEM);
678 goto out;
679 }
Sage Weil774ac212011-11-11 09:48:08 -0800680 } else {
Al Viro3c5184e2012-01-09 16:34:32 -0500681 root = d_obtain_alias(inode);
Sage Weil774ac212011-11-11 09:48:08 -0800682 }
Linus Torvalds1a52bb02012-01-13 10:29:21 -0800683 ceph_init_dentry(root);
Sage Weil16725b92009-10-06 11:31:07 -0700684 dout("open_root_inode success, root dentry is %p\n", root);
685 } else {
686 root = ERR_PTR(err);
687 }
Al Viro3c5184e2012-01-09 16:34:32 -0500688out:
Sage Weil16725b92009-10-06 11:31:07 -0700689 ceph_mdsc_put_request(req);
690 return root;
691}
692
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700693
694
695
Sage Weil16725b92009-10-06 11:31:07 -0700696/*
697 * mount: join the ceph cluster, and open root directory.
698 */
Al Viroa7f9fb22010-07-26 16:17:55 +0400699static struct dentry *ceph_real_mount(struct ceph_fs_client *fsc,
Sage Weil16725b92009-10-06 11:31:07 -0700700 const char *path)
701{
Sage Weil16725b92009-10-06 11:31:07 -0700702 int err;
Sage Weil16725b92009-10-06 11:31:07 -0700703 unsigned long started = jiffies; /* note the start time */
704 struct dentry *root;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700705 int first = 0; /* first vfsmount for this super_block */
Sage Weil16725b92009-10-06 11:31:07 -0700706
707 dout("mount start\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700708 mutex_lock(&fsc->client->mount_mutex);
Sage Weil16725b92009-10-06 11:31:07 -0700709
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700710 err = __ceph_open_session(fsc->client, started);
Sage Weil16725b92009-10-06 11:31:07 -0700711 if (err < 0)
712 goto out;
713
Sage Weil16725b92009-10-06 11:31:07 -0700714 dout("mount opening root\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700715 root = open_root_dentry(fsc, "", started);
Sage Weil16725b92009-10-06 11:31:07 -0700716 if (IS_ERR(root)) {
717 err = PTR_ERR(root);
718 goto out;
719 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700720 if (fsc->sb->s_root) {
Sage Weil16725b92009-10-06 11:31:07 -0700721 dput(root);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700722 } else {
723 fsc->sb->s_root = root;
724 first = 1;
725
726 err = ceph_fs_debugfs_init(fsc);
727 if (err < 0)
728 goto fail;
729 }
Sage Weil16725b92009-10-06 11:31:07 -0700730
731 if (path[0] == 0) {
732 dget(root);
733 } else {
734 dout("mount opening base mountpoint\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700735 root = open_root_dentry(fsc, path, started);
Sage Weil16725b92009-10-06 11:31:07 -0700736 if (IS_ERR(root)) {
737 err = PTR_ERR(root);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700738 goto fail;
Sage Weil16725b92009-10-06 11:31:07 -0700739 }
740 }
741
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700742 fsc->mount_state = CEPH_MOUNT_MOUNTED;
Sage Weil16725b92009-10-06 11:31:07 -0700743 dout("mount success\n");
Al Viroa7f9fb22010-07-26 16:17:55 +0400744 mutex_unlock(&fsc->client->mount_mutex);
745 return root;
Sage Weil16725b92009-10-06 11:31:07 -0700746
747out:
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700748 mutex_unlock(&fsc->client->mount_mutex);
Al Viroa7f9fb22010-07-26 16:17:55 +0400749 return ERR_PTR(err);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700750
751fail:
752 if (first) {
753 dput(fsc->sb->s_root);
754 fsc->sb->s_root = NULL;
755 }
756 goto out;
Sage Weil16725b92009-10-06 11:31:07 -0700757}
758
759static int ceph_set_super(struct super_block *s, void *data)
760{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700761 struct ceph_fs_client *fsc = data;
Sage Weil16725b92009-10-06 11:31:07 -0700762 int ret;
763
764 dout("set_super %p data %p\n", s, data);
765
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700766 s->s_flags = fsc->mount_options->sb_flags;
Sage Weil16725b92009-10-06 11:31:07 -0700767 s->s_maxbytes = 1ULL << 40; /* temp value until we get mdsmap */
768
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700769 s->s_fs_info = fsc;
770 fsc->sb = s;
Sage Weil16725b92009-10-06 11:31:07 -0700771
772 s->s_op = &ceph_super_ops;
773 s->s_export_op = &ceph_export_ops;
774
775 s->s_time_gran = 1000; /* 1000 ns == 1 us */
776
777 ret = set_anon_super(s, NULL); /* what is that second arg for? */
778 if (ret != 0)
779 goto fail;
780
781 return ret;
782
783fail:
784 s->s_fs_info = NULL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700785 fsc->sb = NULL;
Sage Weil16725b92009-10-06 11:31:07 -0700786 return ret;
787}
788
789/*
790 * share superblock if same fs AND options
791 */
792static int ceph_compare_super(struct super_block *sb, void *data)
793{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700794 struct ceph_fs_client *new = data;
795 struct ceph_mount_options *fsopt = new->mount_options;
796 struct ceph_options *opt = new->client->options;
797 struct ceph_fs_client *other = ceph_sb_to_client(sb);
Sage Weil16725b92009-10-06 11:31:07 -0700798
799 dout("ceph_compare_super %p\n", sb);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700800
801 if (compare_mount_options(fsopt, opt, other)) {
802 dout("monitor(s)/mount options don't match\n");
803 return 0;
Sage Weil16725b92009-10-06 11:31:07 -0700804 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700805 if ((opt->flags & CEPH_OPT_FSID) &&
806 ceph_fsid_compare(&opt->fsid, &other->client->fsid)) {
807 dout("fsid doesn't match\n");
808 return 0;
809 }
810 if (fsopt->sb_flags != other->mount_options->sb_flags) {
Sage Weil16725b92009-10-06 11:31:07 -0700811 dout("flags differ\n");
812 return 0;
813 }
814 return 1;
815}
816
817/*
818 * construct our own bdi so we can control readahead, etc.
819 */
Jeff Mahoney00d56432010-06-10 11:13:58 -0400820static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
Sage Weil31e0cf82010-05-04 16:39:35 -0700821
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700822static int ceph_register_bdi(struct super_block *sb,
823 struct ceph_fs_client *fsc)
Sage Weil16725b92009-10-06 11:31:07 -0700824{
825 int err;
826
Sage Weil83817e32011-08-04 08:03:44 -0700827 /* set ra_pages based on rasize mount option? */
828 if (fsc->mount_options->rasize >= PAGE_CACHE_SIZE)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700829 fsc->backing_dev_info.ra_pages =
Sage Weil83817e32011-08-04 08:03:44 -0700830 (fsc->mount_options->rasize + PAGE_CACHE_SIZE - 1)
Sage Weil16725b92009-10-06 11:31:07 -0700831 >> PAGE_SHIFT;
Yehuda Sadehe9852222011-07-22 11:12:28 -0700832 else
833 fsc->backing_dev_info.ra_pages =
834 default_backing_dev_info.ra_pages;
835
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700836 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%d",
Sage Weil31e0cf82010-05-04 16:39:35 -0700837 atomic_long_inc_return(&bdi_seq));
Sage Weil5dfc5892010-05-04 16:14:46 -0700838 if (!err)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700839 sb->s_bdi = &fsc->backing_dev_info;
Sage Weil16725b92009-10-06 11:31:07 -0700840 return err;
841}
842
Al Viroa7f9fb22010-07-26 16:17:55 +0400843static struct dentry *ceph_mount(struct file_system_type *fs_type,
844 int flags, const char *dev_name, void *data)
Sage Weil16725b92009-10-06 11:31:07 -0700845{
846 struct super_block *sb;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700847 struct ceph_fs_client *fsc;
Al Viroa7f9fb22010-07-26 16:17:55 +0400848 struct dentry *res;
Sage Weil16725b92009-10-06 11:31:07 -0700849 int err;
850 int (*compare_super)(struct super_block *, void *) = ceph_compare_super;
Sage Weil6a18be12009-11-04 11:40:05 -0800851 const char *path = NULL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700852 struct ceph_mount_options *fsopt = NULL;
853 struct ceph_options *opt = NULL;
Sage Weil16725b92009-10-06 11:31:07 -0700854
Al Viroa7f9fb22010-07-26 16:17:55 +0400855 dout("ceph_mount\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700856 err = parse_mount_options(&fsopt, &opt, flags, data, dev_name, &path);
Al Viroa7f9fb22010-07-26 16:17:55 +0400857 if (err < 0) {
858 res = ERR_PTR(err);
Sage Weil6b805182009-10-27 11:50:50 -0700859 goto out_final;
Al Viroa7f9fb22010-07-26 16:17:55 +0400860 }
Sage Weil16725b92009-10-06 11:31:07 -0700861
862 /* create client (which we may/may not use) */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700863 fsc = create_fs_client(fsopt, opt);
864 if (IS_ERR(fsc)) {
Al Viroa7f9fb22010-07-26 16:17:55 +0400865 res = ERR_CAST(fsc);
Noah Watkins259a1872011-08-22 13:49:41 -0600866 destroy_mount_options(fsopt);
867 ceph_destroy_options(opt);
Sage Weil6b805182009-10-27 11:50:50 -0700868 goto out_final;
869 }
Sage Weil16725b92009-10-06 11:31:07 -0700870
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700871 err = ceph_mdsc_init(fsc);
Al Viroa7f9fb22010-07-26 16:17:55 +0400872 if (err < 0) {
873 res = ERR_PTR(err);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700874 goto out;
Al Viroa7f9fb22010-07-26 16:17:55 +0400875 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700876
877 if (ceph_test_opt(fsc->client, NOSHARE))
Sage Weil16725b92009-10-06 11:31:07 -0700878 compare_super = NULL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700879 sb = sget(fs_type, compare_super, ceph_set_super, fsc);
Sage Weil16725b92009-10-06 11:31:07 -0700880 if (IS_ERR(sb)) {
Al Viroa7f9fb22010-07-26 16:17:55 +0400881 res = ERR_CAST(sb);
Sage Weil16725b92009-10-06 11:31:07 -0700882 goto out;
883 }
884
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700885 if (ceph_sb_to_client(sb) != fsc) {
886 ceph_mdsc_destroy(fsc);
887 destroy_fs_client(fsc);
888 fsc = ceph_sb_to_client(sb);
889 dout("get_sb got existing client %p\n", fsc);
Sage Weil16725b92009-10-06 11:31:07 -0700890 } else {
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700891 dout("get_sb using new client %p\n", fsc);
892 err = ceph_register_bdi(sb, fsc);
Al Viroa7f9fb22010-07-26 16:17:55 +0400893 if (err < 0) {
894 res = ERR_PTR(err);
Sage Weil16725b92009-10-06 11:31:07 -0700895 goto out_splat;
Al Viroa7f9fb22010-07-26 16:17:55 +0400896 }
Sage Weil16725b92009-10-06 11:31:07 -0700897 }
898
Al Viroa7f9fb22010-07-26 16:17:55 +0400899 res = ceph_real_mount(fsc, path);
900 if (IS_ERR(res))
Sage Weil16725b92009-10-06 11:31:07 -0700901 goto out_splat;
Al Viroa7f9fb22010-07-26 16:17:55 +0400902 dout("root %p inode %p ino %llx.%llx\n", res,
903 res->d_inode, ceph_vinop(res->d_inode));
904 return res;
Sage Weil16725b92009-10-06 11:31:07 -0700905
906out_splat:
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700907 ceph_mdsc_close_sessions(fsc->mdsc);
Al Viro3981f2e2010-03-21 19:22:29 -0400908 deactivate_locked_super(sb);
Sage Weil16725b92009-10-06 11:31:07 -0700909 goto out_final;
910
911out:
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700912 ceph_mdsc_destroy(fsc);
913 destroy_fs_client(fsc);
Sage Weil16725b92009-10-06 11:31:07 -0700914out_final:
Al Viroa7f9fb22010-07-26 16:17:55 +0400915 dout("ceph_mount fail %ld\n", PTR_ERR(res));
916 return res;
Sage Weil16725b92009-10-06 11:31:07 -0700917}
918
919static void ceph_kill_sb(struct super_block *s)
920{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700921 struct ceph_fs_client *fsc = ceph_sb_to_client(s);
Sage Weil16725b92009-10-06 11:31:07 -0700922 dout("kill_sb %p\n", s);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700923 ceph_mdsc_pre_umount(fsc->mdsc);
Sage Weil16725b92009-10-06 11:31:07 -0700924 kill_anon_super(s); /* will call put_super after sb is r/o */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700925 ceph_mdsc_destroy(fsc);
926 destroy_fs_client(fsc);
Sage Weil16725b92009-10-06 11:31:07 -0700927}
928
929static struct file_system_type ceph_fs_type = {
930 .owner = THIS_MODULE,
931 .name = "ceph",
Al Viroa7f9fb22010-07-26 16:17:55 +0400932 .mount = ceph_mount,
Sage Weil16725b92009-10-06 11:31:07 -0700933 .kill_sb = ceph_kill_sb,
934 .fs_flags = FS_RENAME_DOES_D_MOVE,
935};
Eric W. Biederman93e6dc12013-03-02 19:39:14 -0800936MODULE_ALIAS_FS("ceph");
Sage Weil16725b92009-10-06 11:31:07 -0700937
938#define _STRINGIFY(x) #x
939#define STRINGIFY(x) _STRINGIFY(x)
940
941static int __init init_ceph(void)
942{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700943 int ret = init_caches();
Sage Weil16725b92009-10-06 11:31:07 -0700944 if (ret)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700945 goto out;
Sage Weil16725b92009-10-06 11:31:07 -0700946
Alex Elder3ce6cd12012-01-23 15:49:28 -0600947 ceph_xattr_init();
Sage Weil16725b92009-10-06 11:31:07 -0700948 ret = register_filesystem(&ceph_fs_type);
949 if (ret)
950 goto out_icache;
951
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700952 pr_info("loaded (mds proto %d)\n", CEPH_MDSC_PROTOCOL);
953
Sage Weil16725b92009-10-06 11:31:07 -0700954 return 0;
955
956out_icache:
Alex Elder3ce6cd12012-01-23 15:49:28 -0600957 ceph_xattr_exit();
Sage Weil16725b92009-10-06 11:31:07 -0700958 destroy_caches();
Sage Weil16725b92009-10-06 11:31:07 -0700959out:
960 return ret;
961}
962
963static void __exit exit_ceph(void)
964{
965 dout("exit_ceph\n");
966 unregister_filesystem(&ceph_fs_type);
Alex Elder3ce6cd12012-01-23 15:49:28 -0600967 ceph_xattr_exit();
Sage Weil16725b92009-10-06 11:31:07 -0700968 destroy_caches();
Sage Weil16725b92009-10-06 11:31:07 -0700969}
970
971module_init(init_ceph);
972module_exit(exit_ceph);
973
974MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
975MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
976MODULE_AUTHOR("Patience Warnick <patience@newdream.net>");
977MODULE_DESCRIPTION("Ceph filesystem for Linux");
978MODULE_LICENSE("GPL");