blob: 2df963f1cf5a3b84615772e793cd45eeddec801f [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"
Milosz Tanski99ccbd22013-08-21 17:29:54 -040020#include "cache.h"
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070021
Sage Weil1fe60e52012-07-30 16:23:22 -070022#include <linux/ceph/ceph_features.h>
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070023#include <linux/ceph/decode.h>
24#include <linux/ceph/mon_client.h>
25#include <linux/ceph/auth.h>
26#include <linux/ceph/debugfs.h>
Sage Weil16725b92009-10-06 11:31:07 -070027
28/*
29 * Ceph superblock operations
30 *
31 * Handle the basics of mounting, unmounting.
32 */
33
Sage Weil16725b92009-10-06 11:31:07 -070034/*
35 * super ops
36 */
37static void ceph_put_super(struct super_block *s)
38{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070039 struct ceph_fs_client *fsc = ceph_sb_to_client(s);
Sage Weil16725b92009-10-06 11:31:07 -070040
41 dout("put_super\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070042 ceph_mdsc_close_sessions(fsc->mdsc);
Sage Weil5dfc5892010-05-04 16:14:46 -070043
44 /*
45 * ensure we release the bdi before put_anon_super releases
46 * the device name.
47 */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070048 if (s->s_bdi == &fsc->backing_dev_info) {
49 bdi_unregister(&fsc->backing_dev_info);
Sage Weil5dfc5892010-05-04 16:14:46 -070050 s->s_bdi = NULL;
51 }
52
Sage Weil16725b92009-10-06 11:31:07 -070053 return;
54}
55
56static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf)
57{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070058 struct ceph_fs_client *fsc = ceph_inode_to_client(dentry->d_inode);
59 struct ceph_monmap *monmap = fsc->client->monc.monmap;
Sage Weil16725b92009-10-06 11:31:07 -070060 struct ceph_statfs st;
61 u64 fsid;
62 int err;
63
64 dout("statfs\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070065 err = ceph_monc_do_statfs(&fsc->client->monc, &st);
Sage Weil16725b92009-10-06 11:31:07 -070066 if (err < 0)
67 return err;
68
69 /* fill in kstatfs */
70 buf->f_type = CEPH_SUPER_MAGIC; /* ?? */
71
72 /*
73 * express utilization in terms of large blocks to avoid
74 * overflow on 32-bit machines.
Sage Weil92a49fb2013-02-22 15:31:00 -080075 *
76 * NOTE: for the time being, we make bsize == frsize to humor
77 * not-yet-ancient versions of glibc that are broken.
78 * Someday, we will probably want to report a real block
79 * size... whatever that may mean for a network file system!
Sage Weil16725b92009-10-06 11:31:07 -070080 */
81 buf->f_bsize = 1 << CEPH_BLOCK_SHIFT;
Sage Weil92a49fb2013-02-22 15:31:00 -080082 buf->f_frsize = 1 << CEPH_BLOCK_SHIFT;
Sage Weil16725b92009-10-06 11:31:07 -070083 buf->f_blocks = le64_to_cpu(st.kb) >> (CEPH_BLOCK_SHIFT-10);
Greg Farnum8f04d422011-07-26 11:26:54 -070084 buf->f_bfree = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);
Sage Weil16725b92009-10-06 11:31:07 -070085 buf->f_bavail = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);
86
87 buf->f_files = le64_to_cpu(st.num_objects);
88 buf->f_ffree = -1;
Sage Weil558d3492010-06-01 12:51:12 -070089 buf->f_namelen = NAME_MAX;
Sage Weil16725b92009-10-06 11:31:07 -070090
91 /* leave fsid little-endian, regardless of host endianness */
92 fsid = *(u64 *)(&monmap->fsid) ^ *((u64 *)&monmap->fsid + 1);
93 buf->f_fsid.val[0] = fsid & 0xffffffff;
94 buf->f_fsid.val[1] = fsid >> 32;
95
96 return 0;
97}
98
99
Sage Weil2d9c98a2010-07-30 09:38:13 -0700100static int ceph_sync_fs(struct super_block *sb, int wait)
Sage Weil16725b92009-10-06 11:31:07 -0700101{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700102 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
Sage Weil2d9c98a2010-07-30 09:38:13 -0700103
104 if (!wait) {
105 dout("sync_fs (non-blocking)\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700106 ceph_flush_dirty_caps(fsc->mdsc);
Sage Weil2d9c98a2010-07-30 09:38:13 -0700107 dout("sync_fs (non-blocking) done\n");
108 return 0;
109 }
110
111 dout("sync_fs (blocking)\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700112 ceph_osdc_sync(&fsc->client->osdc);
113 ceph_mdsc_sync(fsc->mdsc);
Sage Weil2d9c98a2010-07-30 09:38:13 -0700114 dout("sync_fs (blocking) done\n");
Sage Weil16725b92009-10-06 11:31:07 -0700115 return 0;
116}
117
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700118/*
119 * mount options
120 */
121enum {
122 Opt_wsize,
123 Opt_rsize,
Sage Weil83817e32011-08-04 08:03:44 -0700124 Opt_rasize,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700125 Opt_caps_wanted_delay_min,
126 Opt_caps_wanted_delay_max,
127 Opt_cap_release_safety,
128 Opt_readdir_max_entries,
129 Opt_readdir_max_bytes,
130 Opt_congestion_kb,
131 Opt_last_int,
132 /* int args above */
133 Opt_snapdirname,
134 Opt_last_string,
135 /* string args above */
136 Opt_dirstat,
137 Opt_nodirstat,
138 Opt_rbytes,
139 Opt_norbytes,
Alex Eldercffaba12012-02-15 07:43:54 -0600140 Opt_asyncreaddir,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700141 Opt_noasyncreaddir,
Sage Weila40dc6c2012-01-10 09:12:55 -0800142 Opt_dcache,
143 Opt_nodcache,
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800144 Opt_ino32,
Alex Eldercffaba12012-02-15 07:43:54 -0600145 Opt_noino32,
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400146 Opt_fscache,
147 Opt_nofscache
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700148};
149
150static match_table_t fsopt_tokens = {
151 {Opt_wsize, "wsize=%d"},
152 {Opt_rsize, "rsize=%d"},
Sage Weil83817e32011-08-04 08:03:44 -0700153 {Opt_rasize, "rasize=%d"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700154 {Opt_caps_wanted_delay_min, "caps_wanted_delay_min=%d"},
155 {Opt_caps_wanted_delay_max, "caps_wanted_delay_max=%d"},
156 {Opt_cap_release_safety, "cap_release_safety=%d"},
157 {Opt_readdir_max_entries, "readdir_max_entries=%d"},
158 {Opt_readdir_max_bytes, "readdir_max_bytes=%d"},
159 {Opt_congestion_kb, "write_congestion_kb=%d"},
160 /* int args above */
161 {Opt_snapdirname, "snapdirname=%s"},
162 /* string args above */
163 {Opt_dirstat, "dirstat"},
164 {Opt_nodirstat, "nodirstat"},
165 {Opt_rbytes, "rbytes"},
166 {Opt_norbytes, "norbytes"},
Alex Eldercffaba12012-02-15 07:43:54 -0600167 {Opt_asyncreaddir, "asyncreaddir"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700168 {Opt_noasyncreaddir, "noasyncreaddir"},
Sage Weila40dc6c2012-01-10 09:12:55 -0800169 {Opt_dcache, "dcache"},
170 {Opt_nodcache, "nodcache"},
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800171 {Opt_ino32, "ino32"},
Alex Eldercffaba12012-02-15 07:43:54 -0600172 {Opt_noino32, "noino32"},
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400173 {Opt_fscache, "fsc"},
174 {Opt_nofscache, "nofsc"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700175 {-1, NULL}
176};
177
178static int parse_fsopt_token(char *c, void *private)
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800179{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700180 struct ceph_mount_options *fsopt = private;
181 substring_t argstr[MAX_OPT_ARGS];
182 int token, intval, ret;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800183
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700184 token = match_token((char *)c, fsopt_tokens, argstr);
185 if (token < 0)
186 return -EINVAL;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800187
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700188 if (token < Opt_last_int) {
189 ret = match_int(&argstr[0], &intval);
190 if (ret < 0) {
191 pr_err("bad mount option arg (not int) "
192 "at '%s'\n", c);
193 return ret;
194 }
195 dout("got int token %d val %d\n", token, intval);
196 } else if (token > Opt_last_int && token < Opt_last_string) {
197 dout("got string token %d val %s\n", token,
198 argstr[0].from);
199 } else {
200 dout("got token %d\n", token);
201 }
202
203 switch (token) {
204 case Opt_snapdirname:
205 kfree(fsopt->snapdir_name);
206 fsopt->snapdir_name = kstrndup(argstr[0].from,
207 argstr[0].to-argstr[0].from,
208 GFP_KERNEL);
209 if (!fsopt->snapdir_name)
210 return -ENOMEM;
211 break;
212
213 /* misc */
214 case Opt_wsize:
215 fsopt->wsize = intval;
216 break;
217 case Opt_rsize:
218 fsopt->rsize = intval;
219 break;
Sage Weil83817e32011-08-04 08:03:44 -0700220 case Opt_rasize:
221 fsopt->rasize = intval;
222 break;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700223 case Opt_caps_wanted_delay_min:
224 fsopt->caps_wanted_delay_min = intval;
225 break;
226 case Opt_caps_wanted_delay_max:
227 fsopt->caps_wanted_delay_max = intval;
228 break;
229 case Opt_readdir_max_entries:
230 fsopt->max_readdir = intval;
231 break;
232 case Opt_readdir_max_bytes:
233 fsopt->max_readdir_bytes = intval;
234 break;
235 case Opt_congestion_kb:
236 fsopt->congestion_kb = intval;
237 break;
238 case Opt_dirstat:
239 fsopt->flags |= CEPH_MOUNT_OPT_DIRSTAT;
240 break;
241 case Opt_nodirstat:
242 fsopt->flags &= ~CEPH_MOUNT_OPT_DIRSTAT;
243 break;
244 case Opt_rbytes:
245 fsopt->flags |= CEPH_MOUNT_OPT_RBYTES;
246 break;
247 case Opt_norbytes:
248 fsopt->flags &= ~CEPH_MOUNT_OPT_RBYTES;
249 break;
Alex Eldercffaba12012-02-15 07:43:54 -0600250 case Opt_asyncreaddir:
251 fsopt->flags &= ~CEPH_MOUNT_OPT_NOASYNCREADDIR;
252 break;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700253 case Opt_noasyncreaddir:
254 fsopt->flags |= CEPH_MOUNT_OPT_NOASYNCREADDIR;
255 break;
Sage Weila40dc6c2012-01-10 09:12:55 -0800256 case Opt_dcache:
257 fsopt->flags |= CEPH_MOUNT_OPT_DCACHE;
258 break;
259 case Opt_nodcache:
260 fsopt->flags &= ~CEPH_MOUNT_OPT_DCACHE;
261 break;
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800262 case Opt_ino32:
263 fsopt->flags |= CEPH_MOUNT_OPT_INO32;
264 break;
Alex Eldercffaba12012-02-15 07:43:54 -0600265 case Opt_noino32:
266 fsopt->flags &= ~CEPH_MOUNT_OPT_INO32;
267 break;
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400268 case Opt_fscache:
269 fsopt->flags |= CEPH_MOUNT_OPT_FSCACHE;
270 break;
271 case Opt_nofscache:
272 fsopt->flags &= ~CEPH_MOUNT_OPT_FSCACHE;
273 break;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700274 default:
275 BUG_ON(token);
276 }
277 return 0;
278}
279
280static void destroy_mount_options(struct ceph_mount_options *args)
281{
282 dout("destroy_mount_options %p\n", args);
283 kfree(args->snapdir_name);
284 kfree(args);
285}
286
287static int strcmp_null(const char *s1, const char *s2)
288{
289 if (!s1 && !s2)
290 return 0;
291 if (s1 && !s2)
292 return -1;
293 if (!s1 && s2)
294 return 1;
295 return strcmp(s1, s2);
296}
297
298static int compare_mount_options(struct ceph_mount_options *new_fsopt,
299 struct ceph_options *new_opt,
300 struct ceph_fs_client *fsc)
301{
302 struct ceph_mount_options *fsopt1 = new_fsopt;
303 struct ceph_mount_options *fsopt2 = fsc->mount_options;
304 int ofs = offsetof(struct ceph_mount_options, snapdir_name);
305 int ret;
306
307 ret = memcmp(fsopt1, fsopt2, ofs);
308 if (ret)
309 return ret;
310
311 ret = strcmp_null(fsopt1->snapdir_name, fsopt2->snapdir_name);
312 if (ret)
313 return ret;
314
315 return ceph_compare_options(new_opt, fsc->client);
316}
317
318static int parse_mount_options(struct ceph_mount_options **pfsopt,
319 struct ceph_options **popt,
320 int flags, char *options,
321 const char *dev_name,
322 const char **path)
323{
324 struct ceph_mount_options *fsopt;
325 const char *dev_name_end;
Alex Elderc98f5332012-08-09 10:33:26 -0700326 int err;
327
328 if (!dev_name || !*dev_name)
329 return -EINVAL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700330
331 fsopt = kzalloc(sizeof(*fsopt), GFP_KERNEL);
332 if (!fsopt)
333 return -ENOMEM;
334
335 dout("parse_mount_options %p, dev_name '%s'\n", fsopt, dev_name);
336
Noah Watkins80db8be2011-08-22 13:49:23 -0600337 fsopt->sb_flags = flags;
338 fsopt->flags = CEPH_MOUNT_OPT_DEFAULT;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700339
Noah Watkins80db8be2011-08-22 13:49:23 -0600340 fsopt->rsize = CEPH_RSIZE_DEFAULT;
341 fsopt->rasize = CEPH_RASIZE_DEFAULT;
342 fsopt->snapdir_name = kstrdup(CEPH_SNAPDIRNAME_DEFAULT, GFP_KERNEL);
Sage Weil50aac4f2011-01-18 07:59:40 -0800343 fsopt->caps_wanted_delay_min = CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT;
344 fsopt->caps_wanted_delay_max = CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT;
Noah Watkins80db8be2011-08-22 13:49:23 -0600345 fsopt->cap_release_safety = CEPH_CAP_RELEASE_SAFETY_DEFAULT;
346 fsopt->max_readdir = CEPH_MAX_READDIR_DEFAULT;
347 fsopt->max_readdir_bytes = CEPH_MAX_READDIR_BYTES_DEFAULT;
348 fsopt->congestion_kb = default_congestion_kb();
349
Alex Elderc98f5332012-08-09 10:33:26 -0700350 /*
351 * Distinguish the server list from the path in "dev_name".
352 * Internally we do not include the leading '/' in the path.
353 *
354 * "dev_name" will look like:
355 * <server_spec>[,<server_spec>...]:[<path>]
356 * where
357 * <server_spec> is <ip>[:<port>]
358 * <path> is optional, but if present must begin with '/'
359 */
360 dev_name_end = strchr(dev_name, '/');
361 if (dev_name_end) {
362 /* skip over leading '/' for path */
363 *path = dev_name_end + 1;
364 } else {
365 /* path is empty */
366 dev_name_end = dev_name + strlen(dev_name);
367 *path = dev_name_end;
368 }
Noah Watkins80db8be2011-08-22 13:49:23 -0600369 err = -EINVAL;
Alex Elderc98f5332012-08-09 10:33:26 -0700370 dev_name_end--; /* back up to ':' separator */
Sasha Levin54464292013-07-01 18:33:39 -0400371 if (dev_name_end < dev_name || *dev_name_end != ':') {
Alex Elderc98f5332012-08-09 10:33:26 -0700372 pr_err("device name is missing path (no : separator in %s)\n",
Noah Watkins80db8be2011-08-22 13:49:23 -0600373 dev_name);
374 goto out;
375 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700376 dout("device name '%.*s'\n", (int)(dev_name_end - dev_name), dev_name);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700377 dout("server path '%s'\n", *path);
378
Alex Elderee577412012-01-24 10:08:36 -0600379 *popt = ceph_parse_options(options, dev_name, dev_name_end,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700380 parse_fsopt_token, (void *)fsopt);
Alex Elderee577412012-01-24 10:08:36 -0600381 if (IS_ERR(*popt)) {
382 err = PTR_ERR(*popt);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700383 goto out;
Alex Elderee577412012-01-24 10:08:36 -0600384 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700385
386 /* success */
387 *pfsopt = fsopt;
388 return 0;
389
390out:
391 destroy_mount_options(fsopt);
392 return err;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800393}
394
Sage Weil6e19a162010-04-29 16:38:32 -0700395/**
396 * ceph_show_options - Show mount options in /proc/mounts
397 * @m: seq_file to write to
Al Viro34c80b12011-12-08 21:32:45 -0500398 * @root: root of that (sub)tree
Sage Weil6e19a162010-04-29 16:38:32 -0700399 */
Al Viro34c80b12011-12-08 21:32:45 -0500400static int ceph_show_options(struct seq_file *m, struct dentry *root)
Sage Weil6e19a162010-04-29 16:38:32 -0700401{
Al Viro34c80b12011-12-08 21:32:45 -0500402 struct ceph_fs_client *fsc = ceph_sb_to_client(root->d_sb);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700403 struct ceph_mount_options *fsopt = fsc->mount_options;
404 struct ceph_options *opt = fsc->client->options;
Sage Weil6e19a162010-04-29 16:38:32 -0700405
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700406 if (opt->flags & CEPH_OPT_FSID)
407 seq_printf(m, ",fsid=%pU", &opt->fsid);
408 if (opt->flags & CEPH_OPT_NOSHARE)
Sage Weil6e19a162010-04-29 16:38:32 -0700409 seq_puts(m, ",noshare");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700410 if (opt->flags & CEPH_OPT_NOCRC)
Sage Weil6e19a162010-04-29 16:38:32 -0700411 seq_puts(m, ",nocrc");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700412
413 if (opt->name)
414 seq_printf(m, ",name=%s", opt->name);
Tommi Virtanen8323c3a2011-03-25 16:32:57 -0700415 if (opt->key)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700416 seq_puts(m, ",secret=<hidden>");
417
418 if (opt->mount_timeout != CEPH_MOUNT_TIMEOUT_DEFAULT)
419 seq_printf(m, ",mount_timeout=%d", opt->mount_timeout);
420 if (opt->osd_idle_ttl != CEPH_OSD_IDLE_TTL_DEFAULT)
421 seq_printf(m, ",osd_idle_ttl=%d", opt->osd_idle_ttl);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700422 if (opt->osd_keepalive_timeout != CEPH_OSD_KEEPALIVE_DEFAULT)
423 seq_printf(m, ",osdkeepalivetimeout=%d",
424 opt->osd_keepalive_timeout);
425
426 if (fsopt->flags & CEPH_MOUNT_OPT_DIRSTAT)
427 seq_puts(m, ",dirstat");
428 if ((fsopt->flags & CEPH_MOUNT_OPT_RBYTES) == 0)
429 seq_puts(m, ",norbytes");
430 if (fsopt->flags & CEPH_MOUNT_OPT_NOASYNCREADDIR)
Sage Weil6e19a162010-04-29 16:38:32 -0700431 seq_puts(m, ",noasyncreaddir");
Sage Weila40dc6c2012-01-10 09:12:55 -0800432 if (fsopt->flags & CEPH_MOUNT_OPT_DCACHE)
433 seq_puts(m, ",dcache");
434 else
435 seq_puts(m, ",nodcache");
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400436 if (fsopt->flags & CEPH_MOUNT_OPT_FSCACHE)
437 seq_puts(m, ",fsc");
438 else
439 seq_puts(m, ",nofsc");
Sage Weil6e19a162010-04-29 16:38:32 -0700440
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700441 if (fsopt->wsize)
442 seq_printf(m, ",wsize=%d", fsopt->wsize);
Sage Weil80456f82011-03-10 13:33:26 -0800443 if (fsopt->rsize != CEPH_RSIZE_DEFAULT)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700444 seq_printf(m, ",rsize=%d", fsopt->rsize);
Sage Weil83817e32011-08-04 08:03:44 -0700445 if (fsopt->rasize != CEPH_RASIZE_DEFAULT)
Sage Weil21519372011-12-01 08:06:52 -0800446 seq_printf(m, ",rasize=%d", fsopt->rasize);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700447 if (fsopt->congestion_kb != default_congestion_kb())
448 seq_printf(m, ",write_congestion_kb=%d", fsopt->congestion_kb);
449 if (fsopt->caps_wanted_delay_min != CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT)
Sage Weil6e19a162010-04-29 16:38:32 -0700450 seq_printf(m, ",caps_wanted_delay_min=%d",
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700451 fsopt->caps_wanted_delay_min);
452 if (fsopt->caps_wanted_delay_max != CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT)
Sage Weil6e19a162010-04-29 16:38:32 -0700453 seq_printf(m, ",caps_wanted_delay_max=%d",
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700454 fsopt->caps_wanted_delay_max);
455 if (fsopt->cap_release_safety != CEPH_CAP_RELEASE_SAFETY_DEFAULT)
Sage Weil6e19a162010-04-29 16:38:32 -0700456 seq_printf(m, ",cap_release_safety=%d",
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700457 fsopt->cap_release_safety);
458 if (fsopt->max_readdir != CEPH_MAX_READDIR_DEFAULT)
459 seq_printf(m, ",readdir_max_entries=%d", fsopt->max_readdir);
460 if (fsopt->max_readdir_bytes != CEPH_MAX_READDIR_BYTES_DEFAULT)
461 seq_printf(m, ",readdir_max_bytes=%d", fsopt->max_readdir_bytes);
462 if (strcmp(fsopt->snapdir_name, CEPH_SNAPDIRNAME_DEFAULT))
463 seq_printf(m, ",snapdirname=%s", fsopt->snapdir_name);
Sage Weil6e19a162010-04-29 16:38:32 -0700464 return 0;
465}
466
467/*
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700468 * handle any mon messages the standard library doesn't understand.
469 * return error if we don't either.
470 */
471static int extra_mon_dispatch(struct ceph_client *client, struct ceph_msg *msg)
472{
473 struct ceph_fs_client *fsc = client->private;
474 int type = le16_to_cpu(msg->hdr.type);
475
476 switch (type) {
477 case CEPH_MSG_MDS_MAP:
478 ceph_mdsc_handle_map(fsc->mdsc, msg);
479 return 0;
480
481 default:
482 return -1;
483 }
484}
485
486/*
487 * create a new fs client
488 */
H Hartley Sweeten0c6d4b4e22011-09-23 11:53:30 -0700489static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700490 struct ceph_options *opt)
491{
492 struct ceph_fs_client *fsc;
Ilya Dryomov12b46292013-12-24 21:19:23 +0200493 const u64 supported_features =
Sage Weil6ab00d42011-08-09 09:41:59 -0700494 CEPH_FEATURE_FLOCK |
495 CEPH_FEATURE_DIRLAYOUTHASH;
Ilya Dryomov12b46292013-12-24 21:19:23 +0200496 const u64 required_features = 0;
Alex Elder3bf53332013-04-01 10:48:40 -0500497 int page_count;
498 size_t size;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700499 int err = -ENOMEM;
500
501 fsc = kzalloc(sizeof(*fsc), GFP_KERNEL);
502 if (!fsc)
503 return ERR_PTR(-ENOMEM);
504
Sage Weil6ab00d42011-08-09 09:41:59 -0700505 fsc->client = ceph_create_client(opt, fsc, supported_features,
506 required_features);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700507 if (IS_ERR(fsc->client)) {
508 err = PTR_ERR(fsc->client);
509 goto fail;
510 }
511 fsc->client->extra_mon_dispatch = extra_mon_dispatch;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700512 fsc->client->monc.want_mdsmap = 1;
513
514 fsc->mount_options = fsopt;
515
516 fsc->sb = NULL;
517 fsc->mount_state = CEPH_MOUNT_MOUNTING;
518
519 atomic_long_set(&fsc->writeback_count, 0);
520
521 err = bdi_init(&fsc->backing_dev_info);
522 if (err < 0)
523 goto fail_client;
524
525 err = -ENOMEM;
Tejun Heo01e6acc2011-01-03 14:49:45 +0100526 /*
527 * The number of concurrent works can be high but they don't need
528 * to be processed in parallel, limit concurrency.
529 */
530 fsc->wb_wq = alloc_workqueue("ceph-writeback", 0, 1);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700531 if (fsc->wb_wq == NULL)
532 goto fail_bdi;
Tejun Heo01e6acc2011-01-03 14:49:45 +0100533 fsc->pg_inv_wq = alloc_workqueue("ceph-pg-invalid", 0, 1);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700534 if (fsc->pg_inv_wq == NULL)
535 goto fail_wb_wq;
Tejun Heo01e6acc2011-01-03 14:49:45 +0100536 fsc->trunc_wq = alloc_workqueue("ceph-trunc", 0, 1);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700537 if (fsc->trunc_wq == NULL)
538 goto fail_pg_inv_wq;
539
540 /* set up mempools */
541 err = -ENOMEM;
Alex Elder3bf53332013-04-01 10:48:40 -0500542 page_count = fsc->mount_options->wsize >> PAGE_CACHE_SHIFT;
543 size = sizeof (struct page *) * (page_count ? page_count : 1);
544 fsc->wb_pagevec_pool = mempool_create_kmalloc_pool(10, size);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700545 if (!fsc->wb_pagevec_pool)
546 goto fail_trunc_wq;
547
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400548 /* setup fscache */
549 if ((fsopt->flags & CEPH_MOUNT_OPT_FSCACHE) &&
550 (ceph_fscache_register_fs(fsc) != 0))
551 goto fail_fscache;
552
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700553 /* caps */
554 fsc->min_caps = fsopt->max_readdir;
555
556 return fsc;
557
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400558fail_fscache:
559 ceph_fscache_unregister_fs(fsc);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700560fail_trunc_wq:
561 destroy_workqueue(fsc->trunc_wq);
562fail_pg_inv_wq:
563 destroy_workqueue(fsc->pg_inv_wq);
564fail_wb_wq:
565 destroy_workqueue(fsc->wb_wq);
566fail_bdi:
567 bdi_destroy(&fsc->backing_dev_info);
568fail_client:
569 ceph_destroy_client(fsc->client);
570fail:
571 kfree(fsc);
572 return ERR_PTR(err);
573}
574
H Hartley Sweeten0c6d4b4e22011-09-23 11:53:30 -0700575static void destroy_fs_client(struct ceph_fs_client *fsc)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700576{
577 dout("destroy_fs_client %p\n", fsc);
578
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400579 ceph_fscache_unregister_fs(fsc);
580
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700581 destroy_workqueue(fsc->wb_wq);
582 destroy_workqueue(fsc->pg_inv_wq);
583 destroy_workqueue(fsc->trunc_wq);
584
585 bdi_destroy(&fsc->backing_dev_info);
586
587 mempool_destroy(fsc->wb_pagevec_pool);
588
589 destroy_mount_options(fsc->mount_options);
590
591 ceph_fs_debugfs_cleanup(fsc);
592
593 ceph_destroy_client(fsc->client);
594
595 kfree(fsc);
596 dout("destroy_fs_client %p done\n", fsc);
597}
598
599/*
Sage Weil6e19a162010-04-29 16:38:32 -0700600 * caches
601 */
602struct kmem_cache *ceph_inode_cachep;
603struct kmem_cache *ceph_cap_cachep;
604struct kmem_cache *ceph_dentry_cachep;
605struct kmem_cache *ceph_file_cachep;
606
607static void ceph_inode_init_once(void *foo)
608{
609 struct ceph_inode_info *ci = foo;
610 inode_init_once(&ci->vfs_inode);
611}
612
Sage Weil16725b92009-10-06 11:31:07 -0700613static int __init init_caches(void)
614{
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400615 int error = -ENOMEM;
616
Sage Weil16725b92009-10-06 11:31:07 -0700617 ceph_inode_cachep = kmem_cache_create("ceph_inode_info",
618 sizeof(struct ceph_inode_info),
619 __alignof__(struct ceph_inode_info),
620 (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
621 ceph_inode_init_once);
622 if (ceph_inode_cachep == NULL)
623 return -ENOMEM;
624
625 ceph_cap_cachep = KMEM_CACHE(ceph_cap,
626 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
627 if (ceph_cap_cachep == NULL)
628 goto bad_cap;
629
630 ceph_dentry_cachep = KMEM_CACHE(ceph_dentry_info,
631 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
632 if (ceph_dentry_cachep == NULL)
633 goto bad_dentry;
634
635 ceph_file_cachep = KMEM_CACHE(ceph_file_info,
636 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
637 if (ceph_file_cachep == NULL)
638 goto bad_file;
639
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400640 if ((error = ceph_fscache_register()))
641 goto bad_file;
Sage Weil16725b92009-10-06 11:31:07 -0700642
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400643 return 0;
Sage Weil16725b92009-10-06 11:31:07 -0700644bad_file:
645 kmem_cache_destroy(ceph_dentry_cachep);
646bad_dentry:
647 kmem_cache_destroy(ceph_cap_cachep);
648bad_cap:
649 kmem_cache_destroy(ceph_inode_cachep);
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400650 return error;
Sage Weil16725b92009-10-06 11:31:07 -0700651}
652
653static void destroy_caches(void)
654{
Kirill A. Shutemov8c0a8532012-09-26 11:33:07 +1000655 /*
656 * Make sure all delayed rcu free inodes are flushed before we
657 * destroy cache.
658 */
659 rcu_barrier();
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400660
Sage Weil16725b92009-10-06 11:31:07 -0700661 kmem_cache_destroy(ceph_inode_cachep);
662 kmem_cache_destroy(ceph_cap_cachep);
663 kmem_cache_destroy(ceph_dentry_cachep);
664 kmem_cache_destroy(ceph_file_cachep);
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400665
666 ceph_fscache_unregister();
Sage Weil16725b92009-10-06 11:31:07 -0700667}
668
669
670/*
671 * ceph_umount_begin - initiate forced umount. Tear down down the
672 * mount, skipping steps that may hang while waiting for server(s).
673 */
674static void ceph_umount_begin(struct super_block *sb)
675{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700676 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
Sage Weil16725b92009-10-06 11:31:07 -0700677
678 dout("ceph_umount_begin - starting forced umount\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700679 if (!fsc)
Sage Weil16725b92009-10-06 11:31:07 -0700680 return;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700681 fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
Sage Weil16725b92009-10-06 11:31:07 -0700682 return;
683}
684
685static const struct super_operations ceph_super_ops = {
686 .alloc_inode = ceph_alloc_inode,
687 .destroy_inode = ceph_destroy_inode,
688 .write_inode = ceph_write_inode,
Yan, Zheng9f12bd12013-09-20 19:55:31 +0800689 .drop_inode = ceph_drop_inode,
Sage Weil2d9c98a2010-07-30 09:38:13 -0700690 .sync_fs = ceph_sync_fs,
Sage Weil16725b92009-10-06 11:31:07 -0700691 .put_super = ceph_put_super,
692 .show_options = ceph_show_options,
693 .statfs = ceph_statfs,
694 .umount_begin = ceph_umount_begin,
695};
696
Sage Weil16725b92009-10-06 11:31:07 -0700697/*
698 * Bootstrap mount by opening the root directory. Note the mount
699 * @started time from caller, and time out if this takes too long.
700 */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700701static struct dentry *open_root_dentry(struct ceph_fs_client *fsc,
Sage Weil16725b92009-10-06 11:31:07 -0700702 const char *path,
703 unsigned long started)
704{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700705 struct ceph_mds_client *mdsc = fsc->mdsc;
Sage Weil16725b92009-10-06 11:31:07 -0700706 struct ceph_mds_request *req = NULL;
707 int err;
708 struct dentry *root;
709
710 /* open dir */
711 dout("open_root_inode opening '%s'\n", path);
712 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_GETATTR, USE_ANY_MDS);
713 if (IS_ERR(req))
Julia Lawall7e34bc52010-05-22 12:01:14 +0200714 return ERR_CAST(req);
Sage Weil16725b92009-10-06 11:31:07 -0700715 req->r_path1 = kstrdup(path, GFP_NOFS);
716 req->r_ino1.ino = CEPH_INO_ROOT;
717 req->r_ino1.snap = CEPH_NOSNAP;
718 req->r_started = started;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700719 req->r_timeout = fsc->client->options->mount_timeout * HZ;
Sage Weil16725b92009-10-06 11:31:07 -0700720 req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INODE);
721 req->r_num_caps = 2;
722 err = ceph_mdsc_do_request(mdsc, NULL, req);
723 if (err == 0) {
Al Viro3c5184e2012-01-09 16:34:32 -0500724 struct inode *inode = req->r_target_inode;
725 req->r_target_inode = NULL;
Sage Weil16725b92009-10-06 11:31:07 -0700726 dout("open_root_inode success\n");
Al Viro3c5184e2012-01-09 16:34:32 -0500727 if (ceph_ino(inode) == CEPH_INO_ROOT &&
Sage Weil774ac212011-11-11 09:48:08 -0800728 fsc->sb->s_root == NULL) {
Al Viro48fde702012-01-08 22:15:13 -0500729 root = d_make_root(inode);
Al Viro3c5184e2012-01-09 16:34:32 -0500730 if (!root) {
Al Viro3c5184e2012-01-09 16:34:32 -0500731 root = ERR_PTR(-ENOMEM);
732 goto out;
733 }
Sage Weil774ac212011-11-11 09:48:08 -0800734 } else {
Al Viro3c5184e2012-01-09 16:34:32 -0500735 root = d_obtain_alias(inode);
Sage Weil774ac212011-11-11 09:48:08 -0800736 }
Linus Torvalds1a52bb02012-01-13 10:29:21 -0800737 ceph_init_dentry(root);
Sage Weil16725b92009-10-06 11:31:07 -0700738 dout("open_root_inode success, root dentry is %p\n", root);
739 } else {
740 root = ERR_PTR(err);
741 }
Al Viro3c5184e2012-01-09 16:34:32 -0500742out:
Sage Weil16725b92009-10-06 11:31:07 -0700743 ceph_mdsc_put_request(req);
744 return root;
745}
746
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700747
748
749
Sage Weil16725b92009-10-06 11:31:07 -0700750/*
751 * mount: join the ceph cluster, and open root directory.
752 */
Al Viroa7f9fb22010-07-26 16:17:55 +0400753static struct dentry *ceph_real_mount(struct ceph_fs_client *fsc,
Sage Weil16725b92009-10-06 11:31:07 -0700754 const char *path)
755{
Sage Weil16725b92009-10-06 11:31:07 -0700756 int err;
Sage Weil16725b92009-10-06 11:31:07 -0700757 unsigned long started = jiffies; /* note the start time */
758 struct dentry *root;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700759 int first = 0; /* first vfsmount for this super_block */
Sage Weil16725b92009-10-06 11:31:07 -0700760
761 dout("mount start\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700762 mutex_lock(&fsc->client->mount_mutex);
Sage Weil16725b92009-10-06 11:31:07 -0700763
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700764 err = __ceph_open_session(fsc->client, started);
Sage Weil16725b92009-10-06 11:31:07 -0700765 if (err < 0)
766 goto out;
767
Sage Weil16725b92009-10-06 11:31:07 -0700768 dout("mount opening root\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700769 root = open_root_dentry(fsc, "", started);
Sage Weil16725b92009-10-06 11:31:07 -0700770 if (IS_ERR(root)) {
771 err = PTR_ERR(root);
772 goto out;
773 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700774 if (fsc->sb->s_root) {
Sage Weil16725b92009-10-06 11:31:07 -0700775 dput(root);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700776 } else {
777 fsc->sb->s_root = root;
778 first = 1;
779
780 err = ceph_fs_debugfs_init(fsc);
781 if (err < 0)
782 goto fail;
783 }
Sage Weil16725b92009-10-06 11:31:07 -0700784
785 if (path[0] == 0) {
786 dget(root);
787 } else {
788 dout("mount opening base mountpoint\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700789 root = open_root_dentry(fsc, path, started);
Sage Weil16725b92009-10-06 11:31:07 -0700790 if (IS_ERR(root)) {
791 err = PTR_ERR(root);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700792 goto fail;
Sage Weil16725b92009-10-06 11:31:07 -0700793 }
794 }
795
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700796 fsc->mount_state = CEPH_MOUNT_MOUNTED;
Sage Weil16725b92009-10-06 11:31:07 -0700797 dout("mount success\n");
Al Viroa7f9fb22010-07-26 16:17:55 +0400798 mutex_unlock(&fsc->client->mount_mutex);
799 return root;
Sage Weil16725b92009-10-06 11:31:07 -0700800
801out:
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700802 mutex_unlock(&fsc->client->mount_mutex);
Al Viroa7f9fb22010-07-26 16:17:55 +0400803 return ERR_PTR(err);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700804
805fail:
806 if (first) {
807 dput(fsc->sb->s_root);
808 fsc->sb->s_root = NULL;
809 }
810 goto out;
Sage Weil16725b92009-10-06 11:31:07 -0700811}
812
813static int ceph_set_super(struct super_block *s, void *data)
814{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700815 struct ceph_fs_client *fsc = data;
Sage Weil16725b92009-10-06 11:31:07 -0700816 int ret;
817
818 dout("set_super %p data %p\n", s, data);
819
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700820 s->s_flags = fsc->mount_options->sb_flags;
Sage Weil16725b92009-10-06 11:31:07 -0700821 s->s_maxbytes = 1ULL << 40; /* temp value until we get mdsmap */
Guangliang Zhao7221fe42013-11-11 15:18:03 +0800822#ifdef CONFIG_CEPH_FS_POSIX_ACL
823 s->s_flags |= MS_POSIXACL;
824#endif
Sage Weil16725b92009-10-06 11:31:07 -0700825
Guangliang Zhao7221fe42013-11-11 15:18:03 +0800826 s->s_xattr = ceph_xattr_handlers;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700827 s->s_fs_info = fsc;
828 fsc->sb = s;
Sage Weil16725b92009-10-06 11:31:07 -0700829
830 s->s_op = &ceph_super_ops;
831 s->s_export_op = &ceph_export_ops;
832
833 s->s_time_gran = 1000; /* 1000 ns == 1 us */
834
835 ret = set_anon_super(s, NULL); /* what is that second arg for? */
836 if (ret != 0)
837 goto fail;
838
839 return ret;
840
841fail:
842 s->s_fs_info = NULL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700843 fsc->sb = NULL;
Sage Weil16725b92009-10-06 11:31:07 -0700844 return ret;
845}
846
847/*
848 * share superblock if same fs AND options
849 */
850static int ceph_compare_super(struct super_block *sb, void *data)
851{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700852 struct ceph_fs_client *new = data;
853 struct ceph_mount_options *fsopt = new->mount_options;
854 struct ceph_options *opt = new->client->options;
855 struct ceph_fs_client *other = ceph_sb_to_client(sb);
Sage Weil16725b92009-10-06 11:31:07 -0700856
857 dout("ceph_compare_super %p\n", sb);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700858
859 if (compare_mount_options(fsopt, opt, other)) {
860 dout("monitor(s)/mount options don't match\n");
861 return 0;
Sage Weil16725b92009-10-06 11:31:07 -0700862 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700863 if ((opt->flags & CEPH_OPT_FSID) &&
864 ceph_fsid_compare(&opt->fsid, &other->client->fsid)) {
865 dout("fsid doesn't match\n");
866 return 0;
867 }
868 if (fsopt->sb_flags != other->mount_options->sb_flags) {
Sage Weil16725b92009-10-06 11:31:07 -0700869 dout("flags differ\n");
870 return 0;
871 }
872 return 1;
873}
874
875/*
876 * construct our own bdi so we can control readahead, etc.
877 */
Jeff Mahoney00d56432010-06-10 11:13:58 -0400878static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
Sage Weil31e0cf82010-05-04 16:39:35 -0700879
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700880static int ceph_register_bdi(struct super_block *sb,
881 struct ceph_fs_client *fsc)
Sage Weil16725b92009-10-06 11:31:07 -0700882{
883 int err;
884
Sage Weil83817e32011-08-04 08:03:44 -0700885 /* set ra_pages based on rasize mount option? */
886 if (fsc->mount_options->rasize >= PAGE_CACHE_SIZE)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700887 fsc->backing_dev_info.ra_pages =
Sage Weil83817e32011-08-04 08:03:44 -0700888 (fsc->mount_options->rasize + PAGE_CACHE_SIZE - 1)
Sage Weil16725b92009-10-06 11:31:07 -0700889 >> PAGE_SHIFT;
Yehuda Sadehe9852222011-07-22 11:12:28 -0700890 else
891 fsc->backing_dev_info.ra_pages =
892 default_backing_dev_info.ra_pages;
893
Joe Perchesd2cc4dd2012-11-29 08:37:03 -0600894 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
Sage Weil31e0cf82010-05-04 16:39:35 -0700895 atomic_long_inc_return(&bdi_seq));
Sage Weil5dfc5892010-05-04 16:14:46 -0700896 if (!err)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700897 sb->s_bdi = &fsc->backing_dev_info;
Sage Weil16725b92009-10-06 11:31:07 -0700898 return err;
899}
900
Al Viroa7f9fb22010-07-26 16:17:55 +0400901static struct dentry *ceph_mount(struct file_system_type *fs_type,
902 int flags, const char *dev_name, void *data)
Sage Weil16725b92009-10-06 11:31:07 -0700903{
904 struct super_block *sb;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700905 struct ceph_fs_client *fsc;
Al Viroa7f9fb22010-07-26 16:17:55 +0400906 struct dentry *res;
Sage Weil16725b92009-10-06 11:31:07 -0700907 int err;
908 int (*compare_super)(struct super_block *, void *) = ceph_compare_super;
Sage Weil6a18be12009-11-04 11:40:05 -0800909 const char *path = NULL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700910 struct ceph_mount_options *fsopt = NULL;
911 struct ceph_options *opt = NULL;
Sage Weil16725b92009-10-06 11:31:07 -0700912
Al Viroa7f9fb22010-07-26 16:17:55 +0400913 dout("ceph_mount\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700914 err = parse_mount_options(&fsopt, &opt, flags, data, dev_name, &path);
Al Viroa7f9fb22010-07-26 16:17:55 +0400915 if (err < 0) {
916 res = ERR_PTR(err);
Sage Weil6b805182009-10-27 11:50:50 -0700917 goto out_final;
Al Viroa7f9fb22010-07-26 16:17:55 +0400918 }
Sage Weil16725b92009-10-06 11:31:07 -0700919
920 /* create client (which we may/may not use) */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700921 fsc = create_fs_client(fsopt, opt);
922 if (IS_ERR(fsc)) {
Al Viroa7f9fb22010-07-26 16:17:55 +0400923 res = ERR_CAST(fsc);
Noah Watkins259a1872011-08-22 13:49:41 -0600924 destroy_mount_options(fsopt);
925 ceph_destroy_options(opt);
Sage Weil6b805182009-10-27 11:50:50 -0700926 goto out_final;
927 }
Sage Weil16725b92009-10-06 11:31:07 -0700928
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700929 err = ceph_mdsc_init(fsc);
Al Viroa7f9fb22010-07-26 16:17:55 +0400930 if (err < 0) {
931 res = ERR_PTR(err);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700932 goto out;
Al Viroa7f9fb22010-07-26 16:17:55 +0400933 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700934
935 if (ceph_test_opt(fsc->client, NOSHARE))
Sage Weil16725b92009-10-06 11:31:07 -0700936 compare_super = NULL;
David Howells9249e172012-06-25 12:55:37 +0100937 sb = sget(fs_type, compare_super, ceph_set_super, flags, fsc);
Sage Weil16725b92009-10-06 11:31:07 -0700938 if (IS_ERR(sb)) {
Al Viroa7f9fb22010-07-26 16:17:55 +0400939 res = ERR_CAST(sb);
Sage Weil16725b92009-10-06 11:31:07 -0700940 goto out;
941 }
942
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700943 if (ceph_sb_to_client(sb) != fsc) {
944 ceph_mdsc_destroy(fsc);
945 destroy_fs_client(fsc);
946 fsc = ceph_sb_to_client(sb);
947 dout("get_sb got existing client %p\n", fsc);
Sage Weil16725b92009-10-06 11:31:07 -0700948 } else {
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700949 dout("get_sb using new client %p\n", fsc);
950 err = ceph_register_bdi(sb, fsc);
Al Viroa7f9fb22010-07-26 16:17:55 +0400951 if (err < 0) {
952 res = ERR_PTR(err);
Sage Weil16725b92009-10-06 11:31:07 -0700953 goto out_splat;
Al Viroa7f9fb22010-07-26 16:17:55 +0400954 }
Sage Weil16725b92009-10-06 11:31:07 -0700955 }
956
Al Viroa7f9fb22010-07-26 16:17:55 +0400957 res = ceph_real_mount(fsc, path);
958 if (IS_ERR(res))
Sage Weil16725b92009-10-06 11:31:07 -0700959 goto out_splat;
Al Viroa7f9fb22010-07-26 16:17:55 +0400960 dout("root %p inode %p ino %llx.%llx\n", res,
961 res->d_inode, ceph_vinop(res->d_inode));
962 return res;
Sage Weil16725b92009-10-06 11:31:07 -0700963
964out_splat:
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700965 ceph_mdsc_close_sessions(fsc->mdsc);
Al Viro3981f2e2010-03-21 19:22:29 -0400966 deactivate_locked_super(sb);
Sage Weil16725b92009-10-06 11:31:07 -0700967 goto out_final;
968
969out:
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700970 ceph_mdsc_destroy(fsc);
971 destroy_fs_client(fsc);
Sage Weil16725b92009-10-06 11:31:07 -0700972out_final:
Al Viroa7f9fb22010-07-26 16:17:55 +0400973 dout("ceph_mount fail %ld\n", PTR_ERR(res));
974 return res;
Sage Weil16725b92009-10-06 11:31:07 -0700975}
976
977static void ceph_kill_sb(struct super_block *s)
978{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700979 struct ceph_fs_client *fsc = ceph_sb_to_client(s);
Sage Weil16725b92009-10-06 11:31:07 -0700980 dout("kill_sb %p\n", s);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700981 ceph_mdsc_pre_umount(fsc->mdsc);
Sage Weil16725b92009-10-06 11:31:07 -0700982 kill_anon_super(s); /* will call put_super after sb is r/o */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700983 ceph_mdsc_destroy(fsc);
984 destroy_fs_client(fsc);
Sage Weil16725b92009-10-06 11:31:07 -0700985}
986
987static struct file_system_type ceph_fs_type = {
988 .owner = THIS_MODULE,
989 .name = "ceph",
Al Viroa7f9fb22010-07-26 16:17:55 +0400990 .mount = ceph_mount,
Sage Weil16725b92009-10-06 11:31:07 -0700991 .kill_sb = ceph_kill_sb,
992 .fs_flags = FS_RENAME_DOES_D_MOVE,
993};
Eric W. Biederman7f78e032013-03-02 19:39:14 -0800994MODULE_ALIAS_FS("ceph");
Sage Weil16725b92009-10-06 11:31:07 -0700995
996#define _STRINGIFY(x) #x
997#define STRINGIFY(x) _STRINGIFY(x)
998
999static int __init init_ceph(void)
1000{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001001 int ret = init_caches();
Sage Weil16725b92009-10-06 11:31:07 -07001002 if (ret)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001003 goto out;
Sage Weil16725b92009-10-06 11:31:07 -07001004
Alex Elder3ce6cd12012-01-23 15:49:28 -06001005 ceph_xattr_init();
Sage Weil16725b92009-10-06 11:31:07 -07001006 ret = register_filesystem(&ceph_fs_type);
1007 if (ret)
1008 goto out_icache;
1009
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001010 pr_info("loaded (mds proto %d)\n", CEPH_MDSC_PROTOCOL);
1011
Sage Weil16725b92009-10-06 11:31:07 -07001012 return 0;
1013
1014out_icache:
Alex Elder3ce6cd12012-01-23 15:49:28 -06001015 ceph_xattr_exit();
Sage Weil16725b92009-10-06 11:31:07 -07001016 destroy_caches();
Sage Weil16725b92009-10-06 11:31:07 -07001017out:
1018 return ret;
1019}
1020
1021static void __exit exit_ceph(void)
1022{
1023 dout("exit_ceph\n");
1024 unregister_filesystem(&ceph_fs_type);
Alex Elder3ce6cd12012-01-23 15:49:28 -06001025 ceph_xattr_exit();
Sage Weil16725b92009-10-06 11:31:07 -07001026 destroy_caches();
Sage Weil16725b92009-10-06 11:31:07 -07001027}
1028
1029module_init(init_ceph);
1030module_exit(exit_ceph);
1031
1032MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
1033MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
1034MODULE_AUTHOR("Patience Warnick <patience@newdream.net>");
1035MODULE_DESCRIPTION("Ceph filesystem for Linux");
1036MODULE_LICENSE("GPL");