]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - fs/ceph/super.c
Merge drm/drm-next into drm-intel-next-queued
[mirror_ubuntu-hirsute-kernel.git] / fs / ceph / super.c
CommitLineData
09c434b8 1// SPDX-License-Identifier: GPL-2.0-only
16725b9d 2
3d14c5d2 3#include <linux/ceph/ceph_debug.h>
16725b9d
SW
4
5#include <linux/backing-dev.h>
c309f0ab 6#include <linux/ctype.h>
16725b9d
SW
7#include <linux/fs.h>
8#include <linux/inet.h>
9#include <linux/in6.h>
10#include <linux/module.h>
11#include <linux/mount.h>
82995cc6
DH
12#include <linux/fs_context.h>
13#include <linux/fs_parser.h>
16725b9d
SW
14#include <linux/sched.h>
15#include <linux/seq_file.h>
5a0e3ad6 16#include <linux/slab.h>
16725b9d
SW
17#include <linux/statfs.h>
18#include <linux/string.h>
16725b9d 19
16725b9d 20#include "super.h"
3d14c5d2 21#include "mds_client.h"
99ccbd22 22#include "cache.h"
3d14c5d2 23
1fe60e51 24#include <linux/ceph/ceph_features.h>
3d14c5d2
YS
25#include <linux/ceph/decode.h>
26#include <linux/ceph/mon_client.h>
27#include <linux/ceph/auth.h>
28#include <linux/ceph/debugfs.h>
16725b9d
SW
29
30/*
31 * Ceph superblock operations
32 *
33 * Handle the basics of mounting, unmounting.
34 */
35
16725b9d
SW
36/*
37 * super ops
38 */
39static void ceph_put_super(struct super_block *s)
40{
3d14c5d2 41 struct ceph_fs_client *fsc = ceph_sb_to_client(s);
16725b9d
SW
42
43 dout("put_super\n");
3d14c5d2 44 ceph_mdsc_close_sessions(fsc->mdsc);
16725b9d
SW
45}
46
47static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf)
48{
2b0143b5 49 struct ceph_fs_client *fsc = ceph_inode_to_client(d_inode(dentry));
73fb0949 50 struct ceph_mon_client *monc = &fsc->client->monc;
16725b9d
SW
51 struct ceph_statfs st;
52 u64 fsid;
53 int err;
06d74376
DF
54 u64 data_pool;
55
56 if (fsc->mdsc->mdsmap->m_num_data_pg_pools == 1) {
57 data_pool = fsc->mdsc->mdsmap->m_data_pg_pools[0];
58 } else {
59 data_pool = CEPH_NOPOOL;
60 }
16725b9d
SW
61
62 dout("statfs\n");
73fb0949 63 err = ceph_monc_do_statfs(monc, data_pool, &st);
16725b9d
SW
64 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.
92a49fb0
SW
73 *
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!
16725b9d
SW
78 */
79 buf->f_bsize = 1 << CEPH_BLOCK_SHIFT;
92a49fb0 80 buf->f_frsize = 1 << CEPH_BLOCK_SHIFT;
9122eed5
LH
81
82 /*
83 * By default use root quota for stats; fallback to overall filesystem
84 * usage if using 'noquotadf' mount option or if the root dir doesn't
85 * have max_bytes quota set.
86 */
87 if (ceph_test_mount_opt(fsc, NOQUOTADF) ||
88 !ceph_quota_update_statfs(fsc, buf)) {
89 buf->f_blocks = le64_to_cpu(st.kb) >> (CEPH_BLOCK_SHIFT-10);
90 buf->f_bfree = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);
91 buf->f_bavail = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);
92 }
16725b9d
SW
93
94 buf->f_files = le64_to_cpu(st.num_objects);
95 buf->f_ffree = -1;
558d3499 96 buf->f_namelen = NAME_MAX;
16725b9d 97
080a330e 98 /* Must convert the fsid, for consistent values across arches */
73fb0949
LH
99 mutex_lock(&monc->mutex);
100 fsid = le64_to_cpu(*(__le64 *)(&monc->monmap->fsid)) ^
101 le64_to_cpu(*((__le64 *)&monc->monmap->fsid + 1));
102 mutex_unlock(&monc->mutex);
103
16725b9d
SW
104 buf->f_fsid.val[0] = fsid & 0xffffffff;
105 buf->f_fsid.val[1] = fsid >> 32;
106
107 return 0;
108}
109
2d9c98ae 110static int ceph_sync_fs(struct super_block *sb, int wait)
16725b9d 111{
3d14c5d2 112 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
2d9c98ae
SW
113
114 if (!wait) {
115 dout("sync_fs (non-blocking)\n");
3d14c5d2 116 ceph_flush_dirty_caps(fsc->mdsc);
2d9c98ae
SW
117 dout("sync_fs (non-blocking) done\n");
118 return 0;
119 }
120
121 dout("sync_fs (blocking)\n");
3d14c5d2
YS
122 ceph_osdc_sync(&fsc->client->osdc);
123 ceph_mdsc_sync(fsc->mdsc);
2d9c98ae 124 dout("sync_fs (blocking) done\n");
16725b9d
SW
125 return 0;
126}
127
16725b9d
SW
128/*
129 * mount options
130 */
131enum {
16725b9d
SW
132 Opt_wsize,
133 Opt_rsize,
83817e35 134 Opt_rasize,
16725b9d
SW
135 Opt_caps_wanted_delay_min,
136 Opt_caps_wanted_delay_max,
fe33032d 137 Opt_caps_max,
16725b9d 138 Opt_readdir_max_entries,
23804d91 139 Opt_readdir_max_bytes,
2baba250 140 Opt_congestion_kb,
16725b9d
SW
141 /* int args above */
142 Opt_snapdirname,
430afbad 143 Opt_mds_namespace,
131d7eb4 144 Opt_recover_session,
82995cc6 145 Opt_source,
16725b9d 146 /* string args above */
16725b9d 147 Opt_dirstat,
16725b9d 148 Opt_rbytes,
cffaba15 149 Opt_asyncreaddir,
a40dc6cc 150 Opt_dcache,
ad1fee96 151 Opt_ino32,
99ccbd22 152 Opt_fscache,
10183a69 153 Opt_poolperm,
e9e427f0 154 Opt_require_active_mds,
45195e42 155 Opt_acl,
9122eed5 156 Opt_quotadf,
ea4cdc54 157 Opt_copyfrom,
16725b9d
SW
158};
159
82995cc6
DH
160enum ceph_recover_session_mode {
161 ceph_recover_session_no,
162 ceph_recover_session_clean
163};
164
5eede625 165static const struct constant_table ceph_param_recover[] = {
2710c957
AV
166 { "no", ceph_recover_session_no },
167 { "clean", ceph_recover_session_clean },
82995cc6
DH
168 {}
169};
170
d7167b14 171static const struct fs_parameter_spec ceph_mount_parameters[] = {
82995cc6
DH
172 fsparam_flag_no ("acl", Opt_acl),
173 fsparam_flag_no ("asyncreaddir", Opt_asyncreaddir),
ad8c28a9 174 fsparam_s32 ("caps_max", Opt_caps_max),
82995cc6
DH
175 fsparam_u32 ("caps_wanted_delay_max", Opt_caps_wanted_delay_max),
176 fsparam_u32 ("caps_wanted_delay_min", Opt_caps_wanted_delay_min),
ad8c28a9 177 fsparam_u32 ("write_congestion_kb", Opt_congestion_kb),
82995cc6
DH
178 fsparam_flag_no ("copyfrom", Opt_copyfrom),
179 fsparam_flag_no ("dcache", Opt_dcache),
180 fsparam_flag_no ("dirstat", Opt_dirstat),
48ce73b1
AV
181 fsparam_flag_no ("fsc", Opt_fscache), // fsc|nofsc
182 fsparam_string ("fsc", Opt_fscache), // fsc=...
82995cc6
DH
183 fsparam_flag_no ("ino32", Opt_ino32),
184 fsparam_string ("mds_namespace", Opt_mds_namespace),
185 fsparam_flag_no ("poolperm", Opt_poolperm),
186 fsparam_flag_no ("quotadf", Opt_quotadf),
187 fsparam_u32 ("rasize", Opt_rasize),
188 fsparam_flag_no ("rbytes", Opt_rbytes),
ad8c28a9
JL
189 fsparam_u32 ("readdir_max_bytes", Opt_readdir_max_bytes),
190 fsparam_u32 ("readdir_max_entries", Opt_readdir_max_entries),
2710c957 191 fsparam_enum ("recover_session", Opt_recover_session, ceph_param_recover),
82995cc6
DH
192 fsparam_flag_no ("require_active_mds", Opt_require_active_mds),
193 fsparam_u32 ("rsize", Opt_rsize),
194 fsparam_string ("snapdirname", Opt_snapdirname),
195 fsparam_string ("source", Opt_source),
196 fsparam_u32 ("wsize", Opt_wsize),
197 {}
198};
199
82995cc6
DH
200struct ceph_parse_opts_ctx {
201 struct ceph_options *copts;
202 struct ceph_mount_options *opts;
203};
204
b27a939e
ID
205/*
206 * Remove adjacent slashes and then the trailing slash, unless it is
207 * the only remaining character.
208 *
209 * E.g. "//dir1////dir2///" --> "/dir1/dir2", "///" --> "/".
210 */
211static void canonicalize_path(char *path)
212{
213 int i, j = 0;
214
215 for (i = 0; path[i] != '\0'; i++) {
216 if (path[i] != '/' || j < 1 || path[j - 1] != '/')
217 path[j++] = path[i];
218 }
219
220 if (j > 1 && path[j - 1] == '/')
221 j--;
222 path[j] = '\0';
223}
224
82995cc6
DH
225/*
226 * Parse the source parameter. Distinguish the server list from the path.
82995cc6
DH
227 *
228 * The source will look like:
229 * <server_spec>[,<server_spec>...]:[<path>]
230 * where
231 * <server_spec> is <ip>[:<port>]
232 * <path> is optional, but if present must begin with '/'
233 */
234static int ceph_parse_source(struct fs_parameter *param, struct fs_context *fc)
c309f0ab 235{
82995cc6
DH
236 struct ceph_parse_opts_ctx *pctx = fc->fs_private;
237 struct ceph_mount_options *fsopt = pctx->opts;
238 char *dev_name = param->string, *dev_name_end;
239 int ret;
3d14c5d2 240
82995cc6
DH
241 dout("%s '%s'\n", __func__, dev_name);
242 if (!dev_name || !*dev_name)
d53d0f74 243 return invalfc(fc, "Empty source");
3d14c5d2 244
82995cc6
DH
245 dev_name_end = strchr(dev_name, '/');
246 if (dev_name_end) {
4fbc0c71
XL
247 /*
248 * The server_path will include the whole chars from userland
249 * including the leading '/'.
250 */
b27a939e 251 kfree(fsopt->server_path);
4fbc0c71
XL
252 fsopt->server_path = kstrdup(dev_name_end, GFP_KERNEL);
253 if (!fsopt->server_path)
254 return -ENOMEM;
b27a939e
ID
255
256 canonicalize_path(fsopt->server_path);
3d14c5d2 257 } else {
82995cc6 258 dev_name_end = dev_name + strlen(dev_name);
c309f0ab
SW
259 }
260
82995cc6
DH
261 dev_name_end--; /* back up to ':' separator */
262 if (dev_name_end < dev_name || *dev_name_end != ':')
d53d0f74 263 return invalfc(fc, "No path or : separator in source");
82995cc6
DH
264
265 dout("device name '%.*s'\n", (int)(dev_name_end - dev_name), dev_name);
266 if (fsopt->server_path)
267 dout("server path '%s'\n", fsopt->server_path);
268
269 ret = ceph_parse_mon_ips(param->string, dev_name_end - dev_name,
cc3c0b53 270 pctx->copts, fc->log.log);
82995cc6
DH
271 if (ret)
272 return ret;
273
274 fc->source = param->string;
275 param->string = NULL;
276 return 0;
277}
278
279static int ceph_parse_mount_param(struct fs_context *fc,
280 struct fs_parameter *param)
281{
282 struct ceph_parse_opts_ctx *pctx = fc->fs_private;
283 struct ceph_mount_options *fsopt = pctx->opts;
284 struct fs_parse_result result;
285 unsigned int mode;
286 int token, ret;
287
cc3c0b53 288 ret = ceph_parse_param(param, pctx->copts, fc->log.log);
82995cc6
DH
289 if (ret != -ENOPARAM)
290 return ret;
291
d7167b14 292 token = fs_parse(fc, ceph_mount_parameters, param, &result);
82995cc6
DH
293 dout("%s fs_parse '%s' token %d\n", __func__, param->key, token);
294 if (token < 0)
295 return token;
296
3d14c5d2
YS
297 switch (token) {
298 case Opt_snapdirname:
299 kfree(fsopt->snapdir_name);
82995cc6
DH
300 fsopt->snapdir_name = param->string;
301 param->string = NULL;
3d14c5d2 302 break;
235a0982 303 case Opt_mds_namespace:
937441f3 304 kfree(fsopt->mds_namespace);
82995cc6
DH
305 fsopt->mds_namespace = param->string;
306 param->string = NULL;
235a0982 307 break;
131d7eb4 308 case Opt_recover_session:
82995cc6
DH
309 mode = result.uint_32;
310 if (mode == ceph_recover_session_no)
131d7eb4 311 fsopt->flags &= ~CEPH_MOUNT_OPT_CLEANRECOVER;
82995cc6 312 else if (mode == ceph_recover_session_clean)
131d7eb4 313 fsopt->flags |= CEPH_MOUNT_OPT_CLEANRECOVER;
82995cc6
DH
314 else
315 BUG();
1d8f8360 316 break;
82995cc6
DH
317 case Opt_source:
318 if (fc->source)
d53d0f74 319 return invalfc(fc, "Multiple sources specified");
82995cc6 320 return ceph_parse_source(param, fc);
3d14c5d2 321 case Opt_wsize:
82995cc6
DH
322 if (result.uint_32 < PAGE_SIZE ||
323 result.uint_32 > CEPH_MAX_WRITE_SIZE)
324 goto out_of_range;
325 fsopt->wsize = ALIGN(result.uint_32, PAGE_SIZE);
3d14c5d2
YS
326 break;
327 case Opt_rsize:
82995cc6
DH
328 if (result.uint_32 < PAGE_SIZE ||
329 result.uint_32 > CEPH_MAX_READ_SIZE)
330 goto out_of_range;
331 fsopt->rsize = ALIGN(result.uint_32, PAGE_SIZE);
3d14c5d2 332 break;
83817e35 333 case Opt_rasize:
82995cc6 334 fsopt->rasize = ALIGN(result.uint_32, PAGE_SIZE);
83817e35 335 break;
3d14c5d2 336 case Opt_caps_wanted_delay_min:
82995cc6
DH
337 if (result.uint_32 < 1)
338 goto out_of_range;
339 fsopt->caps_wanted_delay_min = result.uint_32;
3d14c5d2
YS
340 break;
341 case Opt_caps_wanted_delay_max:
82995cc6
DH
342 if (result.uint_32 < 1)
343 goto out_of_range;
344 fsopt->caps_wanted_delay_max = result.uint_32;
3d14c5d2 345 break;
fe33032d 346 case Opt_caps_max:
ad8c28a9
JL
347 if (result.int_32 < 0)
348 goto out_of_range;
349 fsopt->caps_max = result.int_32;
fe33032d 350 break;
3d14c5d2 351 case Opt_readdir_max_entries:
82995cc6
DH
352 if (result.uint_32 < 1)
353 goto out_of_range;
354 fsopt->max_readdir = result.uint_32;
3d14c5d2
YS
355 break;
356 case Opt_readdir_max_bytes:
82995cc6
DH
357 if (result.uint_32 < PAGE_SIZE && result.uint_32 != 0)
358 goto out_of_range;
359 fsopt->max_readdir_bytes = result.uint_32;
3d14c5d2
YS
360 break;
361 case Opt_congestion_kb:
82995cc6
DH
362 if (result.uint_32 < 1024) /* at least 1M */
363 goto out_of_range;
364 fsopt->congestion_kb = result.uint_32;
3d14c5d2
YS
365 break;
366 case Opt_dirstat:
82995cc6
DH
367 if (!result.negated)
368 fsopt->flags |= CEPH_MOUNT_OPT_DIRSTAT;
369 else
370 fsopt->flags &= ~CEPH_MOUNT_OPT_DIRSTAT;
3d14c5d2
YS
371 break;
372 case Opt_rbytes:
82995cc6
DH
373 if (!result.negated)
374 fsopt->flags |= CEPH_MOUNT_OPT_RBYTES;
375 else
376 fsopt->flags &= ~CEPH_MOUNT_OPT_RBYTES;
3d14c5d2 377 break;
cffaba15 378 case Opt_asyncreaddir:
82995cc6
DH
379 if (!result.negated)
380 fsopt->flags &= ~CEPH_MOUNT_OPT_NOASYNCREADDIR;
381 else
382 fsopt->flags |= CEPH_MOUNT_OPT_NOASYNCREADDIR;
3d14c5d2 383 break;
a40dc6cc 384 case Opt_dcache:
82995cc6
DH
385 if (!result.negated)
386 fsopt->flags |= CEPH_MOUNT_OPT_DCACHE;
387 else
388 fsopt->flags &= ~CEPH_MOUNT_OPT_DCACHE;
a40dc6cc 389 break;
ad1fee96 390 case Opt_ino32:
82995cc6
DH
391 if (!result.negated)
392 fsopt->flags |= CEPH_MOUNT_OPT_INO32;
393 else
394 fsopt->flags &= ~CEPH_MOUNT_OPT_INO32;
cffaba15 395 break;
82995cc6 396
99ccbd22 397 case Opt_fscache:
ff29fde8 398#ifdef CONFIG_CEPH_FSCACHE
7ae7a828
CX
399 kfree(fsopt->fscache_uniq);
400 fsopt->fscache_uniq = NULL;
82995cc6
DH
401 if (result.negated) {
402 fsopt->flags &= ~CEPH_MOUNT_OPT_FSCACHE;
403 } else {
404 fsopt->flags |= CEPH_MOUNT_OPT_FSCACHE;
405 fsopt->fscache_uniq = param->string;
406 param->string = NULL;
407 }
99ccbd22 408 break;
ff29fde8 409#else
d53d0f74 410 return invalfc(fc, "fscache support is disabled");
ff29fde8 411#endif
10183a69 412 case Opt_poolperm:
82995cc6
DH
413 if (!result.negated)
414 fsopt->flags &= ~CEPH_MOUNT_OPT_NOPOOLPERM;
415 else
416 fsopt->flags |= CEPH_MOUNT_OPT_NOPOOLPERM;
10183a69 417 break;
e9e427f0 418 case Opt_require_active_mds:
82995cc6
DH
419 if (!result.negated)
420 fsopt->flags &= ~CEPH_MOUNT_OPT_MOUNTWAIT;
421 else
422 fsopt->flags |= CEPH_MOUNT_OPT_MOUNTWAIT;
e9e427f0 423 break;
9122eed5 424 case Opt_quotadf:
82995cc6
DH
425 if (!result.negated)
426 fsopt->flags &= ~CEPH_MOUNT_OPT_NOQUOTADF;
427 else
428 fsopt->flags |= CEPH_MOUNT_OPT_NOQUOTADF;
9122eed5 429 break;
ea4cdc54 430 case Opt_copyfrom:
82995cc6
DH
431 if (!result.negated)
432 fsopt->flags &= ~CEPH_MOUNT_OPT_NOCOPYFROM;
433 else
434 fsopt->flags |= CEPH_MOUNT_OPT_NOCOPYFROM;
ea4cdc54 435 break;
45195e42 436 case Opt_acl:
82995cc6
DH
437 if (!result.negated) {
438#ifdef CONFIG_CEPH_FS_POSIX_ACL
439 fc->sb_flags |= SB_POSIXACL;
440#else
d53d0f74 441 return invalfc(fc, "POSIX ACL support is disabled");
45195e42 442#endif
82995cc6
DH
443 } else {
444 fc->sb_flags &= ~SB_POSIXACL;
445 }
45195e42 446 break;
3d14c5d2 447 default:
82995cc6 448 BUG();
3d14c5d2
YS
449 }
450 return 0;
82995cc6
DH
451
452out_of_range:
d53d0f74 453 return invalfc(fc, "%s out of range", param->key);
c309f0ab 454}
16725b9d 455
3d14c5d2 456static void destroy_mount_options(struct ceph_mount_options *args)
16725b9d 457{
3d14c5d2 458 dout("destroy_mount_options %p\n", args);
82995cc6
DH
459 if (!args)
460 return;
461
3d14c5d2 462 kfree(args->snapdir_name);
430afbad 463 kfree(args->mds_namespace);
3f384954 464 kfree(args->server_path);
1d8f8360 465 kfree(args->fscache_uniq);
3d14c5d2
YS
466 kfree(args);
467}
16725b9d 468
3d14c5d2
YS
469static int strcmp_null(const char *s1, const char *s2)
470{
471 if (!s1 && !s2)
472 return 0;
473 if (s1 && !s2)
474 return -1;
475 if (!s1 && s2)
476 return 1;
477 return strcmp(s1, s2);
478}
16725b9d 479
3d14c5d2
YS
480static int compare_mount_options(struct ceph_mount_options *new_fsopt,
481 struct ceph_options *new_opt,
482 struct ceph_fs_client *fsc)
483{
484 struct ceph_mount_options *fsopt1 = new_fsopt;
485 struct ceph_mount_options *fsopt2 = fsc->mount_options;
486 int ofs = offsetof(struct ceph_mount_options, snapdir_name);
487 int ret;
16725b9d 488
3d14c5d2
YS
489 ret = memcmp(fsopt1, fsopt2, ofs);
490 if (ret)
491 return ret;
492
493 ret = strcmp_null(fsopt1->snapdir_name, fsopt2->snapdir_name);
430afbad
YZ
494 if (ret)
495 return ret;
b27a939e 496
430afbad 497 ret = strcmp_null(fsopt1->mds_namespace, fsopt2->mds_namespace);
3d14c5d2
YS
498 if (ret)
499 return ret;
4fbc0c71 500
b27a939e 501 ret = strcmp_null(fsopt1->server_path, fsopt2->server_path);
1d8f8360
YZ
502 if (ret)
503 return ret;
4fbc0c71 504
1d8f8360 505 ret = strcmp_null(fsopt1->fscache_uniq, fsopt2->fscache_uniq);
3f384954
YZ
506 if (ret)
507 return ret;
508
3d14c5d2
YS
509 return ceph_compare_options(new_opt, fsc->client);
510}
511
3d14c5d2
YS
512/**
513 * ceph_show_options - Show mount options in /proc/mounts
514 * @m: seq_file to write to
34c80b1d 515 * @root: root of that (sub)tree
3d14c5d2 516 */
34c80b1d 517static int ceph_show_options(struct seq_file *m, struct dentry *root)
16725b9d 518{
34c80b1d 519 struct ceph_fs_client *fsc = ceph_sb_to_client(root->d_sb);
3d14c5d2 520 struct ceph_mount_options *fsopt = fsc->mount_options;
ff40f9ae
ID
521 size_t pos;
522 int ret;
523
524 /* a comma between MNT/MS and client options */
525 seq_putc(m, ',');
526 pos = m->count;
527
02b2f549 528 ret = ceph_print_client_options(m, fsc->client, false);
ff40f9ae
ID
529 if (ret)
530 return ret;
531
532 /* retract our comma if no client options */
533 if (m->count == pos)
534 m->count--;
3d14c5d2
YS
535
536 if (fsopt->flags & CEPH_MOUNT_OPT_DIRSTAT)
537 seq_puts(m, ",dirstat");
133e9156
YZ
538 if ((fsopt->flags & CEPH_MOUNT_OPT_RBYTES))
539 seq_puts(m, ",rbytes");
3d14c5d2
YS
540 if (fsopt->flags & CEPH_MOUNT_OPT_NOASYNCREADDIR)
541 seq_puts(m, ",noasyncreaddir");
ff7eeb82 542 if ((fsopt->flags & CEPH_MOUNT_OPT_DCACHE) == 0)
a40dc6cc 543 seq_puts(m, ",nodcache");
3619aa8b
CX
544 if (fsopt->flags & CEPH_MOUNT_OPT_INO32)
545 seq_puts(m, ",ino32");
1d8f8360 546 if (fsopt->flags & CEPH_MOUNT_OPT_FSCACHE) {
4d8969af 547 seq_show_option(m, "fsc", fsopt->fscache_uniq);
1d8f8360 548 }
10183a69
YZ
549 if (fsopt->flags & CEPH_MOUNT_OPT_NOPOOLPERM)
550 seq_puts(m, ",nopoolperm");
9122eed5
LH
551 if (fsopt->flags & CEPH_MOUNT_OPT_NOQUOTADF)
552 seq_puts(m, ",noquotadf");
3d14c5d2 553
45195e42 554#ifdef CONFIG_CEPH_FS_POSIX_ACL
82995cc6 555 if (root->d_sb->s_flags & SB_POSIXACL)
45195e42
SW
556 seq_puts(m, ",acl");
557 else
558 seq_puts(m, ",noacl");
559#endif
560
6f9718fe
LH
561 if ((fsopt->flags & CEPH_MOUNT_OPT_NOCOPYFROM) == 0)
562 seq_puts(m, ",copyfrom");
ea4cdc54 563
430afbad 564 if (fsopt->mds_namespace)
4d8969af 565 seq_show_option(m, "mds_namespace", fsopt->mds_namespace);
131d7eb4
YZ
566
567 if (fsopt->flags & CEPH_MOUNT_OPT_CLEANRECOVER)
568 seq_show_option(m, "recover_session", "clean");
569
6dd4940b 570 if (fsopt->wsize != CEPH_MAX_WRITE_SIZE)
ad8c28a9 571 seq_printf(m, ",wsize=%u", fsopt->wsize);
aa187926 572 if (fsopt->rsize != CEPH_MAX_READ_SIZE)
ad8c28a9 573 seq_printf(m, ",rsize=%u", fsopt->rsize);
83817e35 574 if (fsopt->rasize != CEPH_RASIZE_DEFAULT)
ad8c28a9 575 seq_printf(m, ",rasize=%u", fsopt->rasize);
3d14c5d2 576 if (fsopt->congestion_kb != default_congestion_kb())
ad8c28a9 577 seq_printf(m, ",write_congestion_kb=%u", fsopt->congestion_kb);
fe33032d
YZ
578 if (fsopt->caps_max)
579 seq_printf(m, ",caps_max=%d", fsopt->caps_max);
3d14c5d2 580 if (fsopt->caps_wanted_delay_min != CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT)
ad8c28a9 581 seq_printf(m, ",caps_wanted_delay_min=%u",
3d14c5d2
YS
582 fsopt->caps_wanted_delay_min);
583 if (fsopt->caps_wanted_delay_max != CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT)
ad8c28a9 584 seq_printf(m, ",caps_wanted_delay_max=%u",
3d14c5d2 585 fsopt->caps_wanted_delay_max);
3d14c5d2 586 if (fsopt->max_readdir != CEPH_MAX_READDIR_DEFAULT)
ad8c28a9 587 seq_printf(m, ",readdir_max_entries=%u", fsopt->max_readdir);
3d14c5d2 588 if (fsopt->max_readdir_bytes != CEPH_MAX_READDIR_BYTES_DEFAULT)
ad8c28a9 589 seq_printf(m, ",readdir_max_bytes=%u", fsopt->max_readdir_bytes);
3d14c5d2 590 if (strcmp(fsopt->snapdir_name, CEPH_SNAPDIRNAME_DEFAULT))
a068acf2 591 seq_show_option(m, "snapdirname", fsopt->snapdir_name);
ff40f9ae 592
3d14c5d2 593 return 0;
16725b9d
SW
594}
595
596/*
3d14c5d2
YS
597 * handle any mon messages the standard library doesn't understand.
598 * return error if we don't either.
16725b9d 599 */
3d14c5d2 600static int extra_mon_dispatch(struct ceph_client *client, struct ceph_msg *msg)
16725b9d 601{
3d14c5d2
YS
602 struct ceph_fs_client *fsc = client->private;
603 int type = le16_to_cpu(msg->hdr.type);
604
605 switch (type) {
606 case CEPH_MSG_MDS_MAP:
430afbad
YZ
607 ceph_mdsc_handle_mdsmap(fsc->mdsc, msg);
608 return 0;
609 case CEPH_MSG_FS_MAP_USER:
610 ceph_mdsc_handle_fsmap(fsc->mdsc, msg);
3d14c5d2 611 return 0;
3d14c5d2
YS
612 default:
613 return -1;
614 }
615}
616
617/*
618 * create a new fs client
8aaff151
ID
619 *
620 * Success or not, this function consumes @fsopt and @opt.
3d14c5d2 621 */
0c6d4b4e 622static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
3d14c5d2
YS
623 struct ceph_options *opt)
624{
625 struct ceph_fs_client *fsc;
3bf53337
AE
626 int page_count;
627 size_t size;
8aaff151 628 int err;
16725b9d 629
3d14c5d2 630 fsc = kzalloc(sizeof(*fsc), GFP_KERNEL);
8aaff151
ID
631 if (!fsc) {
632 err = -ENOMEM;
633 goto fail;
634 }
16725b9d 635
74da4a0f 636 fsc->client = ceph_create_client(opt, fsc);
3d14c5d2
YS
637 if (IS_ERR(fsc->client)) {
638 err = PTR_ERR(fsc->client);
639 goto fail;
640 }
8aaff151 641 opt = NULL; /* fsc->client now owns this */
c843d13c 642
3d14c5d2 643 fsc->client->extra_mon_dispatch = extra_mon_dispatch;
02b2f549 644 ceph_set_opt(fsc->client, ABORT_ON_FULL);
430afbad 645
d37b1d99 646 if (!fsopt->mds_namespace) {
430afbad
YZ
647 ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_MDSMAP,
648 0, true);
649 } else {
650 ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_FSMAP,
651 0, false);
652 }
16725b9d 653
3d14c5d2 654 fsc->mount_options = fsopt;
16725b9d 655
3d14c5d2
YS
656 fsc->sb = NULL;
657 fsc->mount_state = CEPH_MOUNT_MOUNTING;
81f148a9 658 fsc->filp_gen = 1;
78beb0ff 659 fsc->have_copy_from2 = true;
16725b9d 660
3d14c5d2 661 atomic_long_set(&fsc->writeback_count, 0);
16725b9d
SW
662
663 err = -ENOMEM;
01e6acc4
TH
664 /*
665 * The number of concurrent works can be high but they don't need
666 * to be processed in parallel, limit concurrency.
667 */
1cf89a8d
YZ
668 fsc->inode_wq = alloc_workqueue("ceph-inode", WQ_UNBOUND, 0);
669 if (!fsc->inode_wq)
09dc9fc2 670 goto fail_client;
e3ec8d68
YZ
671 fsc->cap_wq = alloc_workqueue("ceph-cap", 0, 1);
672 if (!fsc->cap_wq)
1cf89a8d 673 goto fail_inode_wq;
16725b9d 674
b9bfb93c
SW
675 /* set up mempools */
676 err = -ENOMEM;
09cbfeaf 677 page_count = fsc->mount_options->wsize >> PAGE_SHIFT;
3bf53337
AE
678 size = sizeof (struct page *) * (page_count ? page_count : 1);
679 fsc->wb_pagevec_pool = mempool_create_kmalloc_pool(10, size);
3d14c5d2 680 if (!fsc->wb_pagevec_pool)
e3ec8d68 681 goto fail_cap_wq;
b9bfb93c 682
3d14c5d2 683 return fsc;
b9bfb93c 684
e3ec8d68
YZ
685fail_cap_wq:
686 destroy_workqueue(fsc->cap_wq);
1cf89a8d
YZ
687fail_inode_wq:
688 destroy_workqueue(fsc->inode_wq);
3d14c5d2
YS
689fail_client:
690 ceph_destroy_client(fsc->client);
16725b9d 691fail:
3d14c5d2 692 kfree(fsc);
8aaff151
ID
693 if (opt)
694 ceph_destroy_options(opt);
695 destroy_mount_options(fsopt);
16725b9d
SW
696 return ERR_PTR(err);
697}
698
a57d9064
YZ
699static void flush_fs_workqueues(struct ceph_fs_client *fsc)
700{
1cf89a8d 701 flush_workqueue(fsc->inode_wq);
e3ec8d68 702 flush_workqueue(fsc->cap_wq);
a57d9064
YZ
703}
704
0c6d4b4e 705static void destroy_fs_client(struct ceph_fs_client *fsc)
16725b9d 706{
3d14c5d2 707 dout("destroy_fs_client %p\n", fsc);
16725b9d 708
3ee5a701 709 ceph_mdsc_destroy(fsc);
1cf89a8d 710 destroy_workqueue(fsc->inode_wq);
e3ec8d68 711 destroy_workqueue(fsc->cap_wq);
16725b9d 712
3d14c5d2 713 mempool_destroy(fsc->wb_pagevec_pool);
16725b9d 714
3d14c5d2 715 destroy_mount_options(fsc->mount_options);
5dfc589a 716
3d14c5d2 717 ceph_destroy_client(fsc->client);
16725b9d 718
3d14c5d2
YS
719 kfree(fsc);
720 dout("destroy_fs_client %p done\n", fsc);
16725b9d
SW
721}
722
0743304d 723/*
3d14c5d2 724 * caches
0743304d 725 */
3d14c5d2
YS
726struct kmem_cache *ceph_inode_cachep;
727struct kmem_cache *ceph_cap_cachep;
f66fd9f0 728struct kmem_cache *ceph_cap_flush_cachep;
3d14c5d2
YS
729struct kmem_cache *ceph_dentry_cachep;
730struct kmem_cache *ceph_file_cachep;
bb48bd4d 731struct kmem_cache *ceph_dir_file_cachep;
3d14c5d2
YS
732
733static void ceph_inode_init_once(void *foo)
0743304d 734{
3d14c5d2
YS
735 struct ceph_inode_info *ci = foo;
736 inode_init_once(&ci->vfs_inode);
737}
738
739static int __init init_caches(void)
740{
99ccbd22
MT
741 int error = -ENOMEM;
742
3d14c5d2
YS
743 ceph_inode_cachep = kmem_cache_create("ceph_inode_info",
744 sizeof(struct ceph_inode_info),
745 __alignof__(struct ceph_inode_info),
5d097056
VD
746 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|
747 SLAB_ACCOUNT, ceph_inode_init_once);
d37b1d99 748 if (!ceph_inode_cachep)
3d14c5d2
YS
749 return -ENOMEM;
750
bc4b5ad3 751 ceph_cap_cachep = KMEM_CACHE(ceph_cap, SLAB_MEM_SPREAD);
d37b1d99 752 if (!ceph_cap_cachep)
3d14c5d2 753 goto bad_cap;
f66fd9f0
YZ
754 ceph_cap_flush_cachep = KMEM_CACHE(ceph_cap_flush,
755 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
d37b1d99 756 if (!ceph_cap_flush_cachep)
f66fd9f0 757 goto bad_cap_flush;
3d14c5d2
YS
758
759 ceph_dentry_cachep = KMEM_CACHE(ceph_dentry_info,
760 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
d37b1d99 761 if (!ceph_dentry_cachep)
3d14c5d2
YS
762 goto bad_dentry;
763
6b1a9a6c 764 ceph_file_cachep = KMEM_CACHE(ceph_file_info, SLAB_MEM_SPREAD);
d37b1d99 765 if (!ceph_file_cachep)
3d14c5d2
YS
766 goto bad_file;
767
bb48bd4d
CX
768 ceph_dir_file_cachep = KMEM_CACHE(ceph_dir_file_info, SLAB_MEM_SPREAD);
769 if (!ceph_dir_file_cachep)
770 goto bad_dir_file;
771
1c789249
CX
772 error = ceph_fscache_register();
773 if (error)
774 goto bad_fscache;
3d14c5d2 775
99ccbd22 776 return 0;
1c789249
CX
777
778bad_fscache:
bb48bd4d
CX
779 kmem_cache_destroy(ceph_dir_file_cachep);
780bad_dir_file:
1c789249 781 kmem_cache_destroy(ceph_file_cachep);
3d14c5d2
YS
782bad_file:
783 kmem_cache_destroy(ceph_dentry_cachep);
784bad_dentry:
f66fd9f0
YZ
785 kmem_cache_destroy(ceph_cap_flush_cachep);
786bad_cap_flush:
3d14c5d2
YS
787 kmem_cache_destroy(ceph_cap_cachep);
788bad_cap:
789 kmem_cache_destroy(ceph_inode_cachep);
99ccbd22 790 return error;
0743304d
SW
791}
792
3d14c5d2
YS
793static void destroy_caches(void)
794{
8c0a8537
KS
795 /*
796 * Make sure all delayed rcu free inodes are flushed before we
797 * destroy cache.
798 */
799 rcu_barrier();
99ccbd22 800
3d14c5d2
YS
801 kmem_cache_destroy(ceph_inode_cachep);
802 kmem_cache_destroy(ceph_cap_cachep);
f66fd9f0 803 kmem_cache_destroy(ceph_cap_flush_cachep);
3d14c5d2
YS
804 kmem_cache_destroy(ceph_dentry_cachep);
805 kmem_cache_destroy(ceph_file_cachep);
bb48bd4d 806 kmem_cache_destroy(ceph_dir_file_cachep);
99ccbd22
MT
807
808 ceph_fscache_unregister();
3d14c5d2
YS
809}
810
16725b9d 811/*
3d14c5d2
YS
812 * ceph_umount_begin - initiate forced umount. Tear down down the
813 * mount, skipping steps that may hang while waiting for server(s).
16725b9d 814 */
3d14c5d2 815static void ceph_umount_begin(struct super_block *sb)
16725b9d 816{
3d14c5d2
YS
817 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
818
819 dout("ceph_umount_begin - starting forced umount\n");
820 if (!fsc)
821 return;
822 fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
12b69d5f 823 ceph_osdc_abort_requests(&fsc->client->osdc, -EIO);
48fec5d0 824 ceph_mdsc_force_umount(fsc->mdsc);
81f148a9 825 fsc->filp_gen++; // invalidate open files
16725b9d
SW
826}
827
3d14c5d2
YS
828static const struct super_operations ceph_super_ops = {
829 .alloc_inode = ceph_alloc_inode,
cfa6d412 830 .free_inode = ceph_free_inode,
3d14c5d2 831 .write_inode = ceph_write_inode,
52dd0f1b 832 .drop_inode = generic_delete_inode,
87bc5b89 833 .evict_inode = ceph_evict_inode,
3d14c5d2
YS
834 .sync_fs = ceph_sync_fs,
835 .put_super = ceph_put_super,
836 .show_options = ceph_show_options,
837 .statfs = ceph_statfs,
838 .umount_begin = ceph_umount_begin,
839};
840
16725b9d
SW
841/*
842 * Bootstrap mount by opening the root directory. Note the mount
843 * @started time from caller, and time out if this takes too long.
844 */
3d14c5d2 845static struct dentry *open_root_dentry(struct ceph_fs_client *fsc,
16725b9d
SW
846 const char *path,
847 unsigned long started)
848{
3d14c5d2 849 struct ceph_mds_client *mdsc = fsc->mdsc;
16725b9d
SW
850 struct ceph_mds_request *req = NULL;
851 int err;
852 struct dentry *root;
853
854 /* open dir */
855 dout("open_root_inode opening '%s'\n", path);
856 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_GETATTR, USE_ANY_MDS);
857 if (IS_ERR(req))
7e34bc52 858 return ERR_CAST(req);
16725b9d 859 req->r_path1 = kstrdup(path, GFP_NOFS);
a149bb9a
SK
860 if (!req->r_path1) {
861 root = ERR_PTR(-ENOMEM);
862 goto out;
863 }
864
16725b9d
SW
865 req->r_ino1.ino = CEPH_INO_ROOT;
866 req->r_ino1.snap = CEPH_NOSNAP;
867 req->r_started = started;
a319bf56 868 req->r_timeout = fsc->client->options->mount_timeout;
16725b9d
SW
869 req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INODE);
870 req->r_num_caps = 2;
871 err = ceph_mdsc_do_request(mdsc, NULL, req);
872 if (err == 0) {
3c5184ef
AV
873 struct inode *inode = req->r_target_inode;
874 req->r_target_inode = NULL;
16725b9d 875 dout("open_root_inode success\n");
ce2728aa
YZ
876 root = d_make_root(inode);
877 if (!root) {
878 root = ERR_PTR(-ENOMEM);
879 goto out;
774ac21d 880 }
16725b9d
SW
881 dout("open_root_inode success, root dentry is %p\n", root);
882 } else {
883 root = ERR_PTR(err);
884 }
3c5184ef 885out:
16725b9d
SW
886 ceph_mdsc_put_request(req);
887 return root;
888}
889
890/*
891 * mount: join the ceph cluster, and open root directory.
892 */
82995cc6
DH
893static struct dentry *ceph_real_mount(struct ceph_fs_client *fsc,
894 struct fs_context *fc)
16725b9d 895{
16725b9d 896 int err;
16725b9d
SW
897 unsigned long started = jiffies; /* note the start time */
898 struct dentry *root;
899
132ca7e1 900 dout("mount start %p\n", fsc);
3d14c5d2 901 mutex_lock(&fsc->client->mount_mutex);
16725b9d 902
132ca7e1 903 if (!fsc->sb->s_root) {
b27a939e
ID
904 const char *path = fsc->mount_options->server_path ?
905 fsc->mount_options->server_path + 1 : "";
906
132ca7e1
YZ
907 err = __ceph_open_session(fsc->client, started);
908 if (err < 0)
909 goto out;
16725b9d 910
1d8f8360
YZ
911 /* setup fscache */
912 if (fsc->mount_options->flags & CEPH_MOUNT_OPT_FSCACHE) {
82995cc6 913 err = ceph_fscache_register_fs(fsc, fc);
1d8f8360
YZ
914 if (err < 0)
915 goto out;
916 }
917
4fbc0c71 918 dout("mount opening path '%s'\n", path);
18106734 919
1a829ff2 920 ceph_fs_debugfs_init(fsc);
18106734 921
ce2728aa 922 root = open_root_dentry(fsc, path, started);
132ca7e1
YZ
923 if (IS_ERR(root)) {
924 err = PTR_ERR(root);
925 goto out;
926 }
ce2728aa 927 fsc->sb->s_root = dget(root);
31ca5878
GU
928 } else {
929 root = dget(fsc->sb->s_root);
3d14c5d2 930 }
16725b9d 931
3d14c5d2 932 fsc->mount_state = CEPH_MOUNT_MOUNTED;
16725b9d 933 dout("mount success\n");
a7f9fb20
AV
934 mutex_unlock(&fsc->client->mount_mutex);
935 return root;
16725b9d 936
132ca7e1
YZ
937out:
938 mutex_unlock(&fsc->client->mount_mutex);
939 return ERR_PTR(err);
16725b9d
SW
940}
941
82995cc6 942static int ceph_set_super(struct super_block *s, struct fs_context *fc)
16725b9d 943{
82995cc6 944 struct ceph_fs_client *fsc = s->s_fs_info;
16725b9d
SW
945 int ret;
946
82995cc6 947 dout("set_super %p\n", s);
16725b9d 948
719784ba 949 s->s_maxbytes = MAX_LFS_FILESIZE;
16725b9d 950
7221fe4c 951 s->s_xattr = ceph_xattr_handlers;
3d14c5d2 952 fsc->sb = s;
719784ba 953 fsc->max_file_size = 1ULL << 40; /* temp value until we get mdsmap */
16725b9d
SW
954
955 s->s_op = &ceph_super_ops;
18fc8abd 956 s->s_d_op = &ceph_dentry_ops;
16725b9d
SW
957 s->s_export_op = &ceph_export_ops;
958
0f7cf80a 959 s->s_time_gran = 1;
028ca4db
DD
960 s->s_time_min = 0;
961 s->s_time_max = U32_MAX;
16725b9d 962
82995cc6 963 ret = set_anon_super_fc(s, fc);
16725b9d 964 if (ret != 0)
82995cc6 965 fsc->sb = NULL;
16725b9d
SW
966 return ret;
967}
968
969/*
970 * share superblock if same fs AND options
971 */
82995cc6 972static int ceph_compare_super(struct super_block *sb, struct fs_context *fc)
16725b9d 973{
82995cc6 974 struct ceph_fs_client *new = fc->s_fs_info;
3d14c5d2
YS
975 struct ceph_mount_options *fsopt = new->mount_options;
976 struct ceph_options *opt = new->client->options;
977 struct ceph_fs_client *other = ceph_sb_to_client(sb);
16725b9d
SW
978
979 dout("ceph_compare_super %p\n", sb);
3d14c5d2
YS
980
981 if (compare_mount_options(fsopt, opt, other)) {
982 dout("monitor(s)/mount options don't match\n");
983 return 0;
16725b9d 984 }
3d14c5d2
YS
985 if ((opt->flags & CEPH_OPT_FSID) &&
986 ceph_fsid_compare(&opt->fsid, &other->client->fsid)) {
987 dout("fsid doesn't match\n");
988 return 0;
989 }
82995cc6 990 if (fc->sb_flags != (sb->s_flags & ~SB_BORN)) {
16725b9d
SW
991 dout("flags differ\n");
992 return 0;
993 }
994 return 1;
995}
996
997/*
998 * construct our own bdi so we can control readahead, etc.
999 */
00d5643e 1000static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
31e0cf8f 1001
09dc9fc2 1002static int ceph_setup_bdi(struct super_block *sb, struct ceph_fs_client *fsc)
16725b9d
SW
1003{
1004 int err;
1005
09dc9fc2
JK
1006 err = super_setup_bdi_name(sb, "ceph-%ld",
1007 atomic_long_inc_return(&bdi_seq));
1008 if (err)
1009 return err;
1010
83817e35 1011 /* set ra_pages based on rasize mount option? */
4214fb15 1012 sb->s_bdi->ra_pages = fsc->mount_options->rasize >> PAGE_SHIFT;
e9852227 1013
aa187926
YZ
1014 /* set io_pages based on max osd read size */
1015 sb->s_bdi->io_pages = fsc->mount_options->rsize >> PAGE_SHIFT;
7c94ba27 1016
09dc9fc2 1017 return 0;
16725b9d
SW
1018}
1019
82995cc6 1020static int ceph_get_tree(struct fs_context *fc)
16725b9d 1021{
82995cc6 1022 struct ceph_parse_opts_ctx *pctx = fc->fs_private;
16725b9d 1023 struct super_block *sb;
3d14c5d2 1024 struct ceph_fs_client *fsc;
a7f9fb20 1025 struct dentry *res;
82995cc6
DH
1026 int (*compare_super)(struct super_block *, struct fs_context *) =
1027 ceph_compare_super;
16725b9d 1028 int err;
16725b9d 1029
82995cc6
DH
1030 dout("ceph_get_tree\n");
1031
1032 if (!fc->source)
d53d0f74 1033 return invalfc(fc, "No source");
45195e42 1034
16725b9d 1035 /* create client (which we may/may not use) */
82995cc6
DH
1036 fsc = create_fs_client(pctx->opts, pctx->copts);
1037 pctx->opts = NULL;
1038 pctx->copts = NULL;
3d14c5d2 1039 if (IS_ERR(fsc)) {
82995cc6 1040 err = PTR_ERR(fsc);
6b805185
SW
1041 goto out_final;
1042 }
16725b9d 1043
3d14c5d2 1044 err = ceph_mdsc_init(fsc);
82995cc6 1045 if (err < 0)
3d14c5d2
YS
1046 goto out;
1047
1048 if (ceph_test_opt(fsc->client, NOSHARE))
16725b9d 1049 compare_super = NULL;
82995cc6
DH
1050
1051 fc->s_fs_info = fsc;
1052 sb = sget_fc(fc, compare_super, ceph_set_super);
1053 fc->s_fs_info = NULL;
16725b9d 1054 if (IS_ERR(sb)) {
82995cc6 1055 err = PTR_ERR(sb);
16725b9d
SW
1056 goto out;
1057 }
1058
3d14c5d2 1059 if (ceph_sb_to_client(sb) != fsc) {
3d14c5d2
YS
1060 destroy_fs_client(fsc);
1061 fsc = ceph_sb_to_client(sb);
1062 dout("get_sb got existing client %p\n", fsc);
16725b9d 1063 } else {
3d14c5d2 1064 dout("get_sb using new client %p\n", fsc);
09dc9fc2 1065 err = ceph_setup_bdi(sb, fsc);
82995cc6 1066 if (err < 0)
16725b9d
SW
1067 goto out_splat;
1068 }
1069
82995cc6
DH
1070 res = ceph_real_mount(fsc, fc);
1071 if (IS_ERR(res)) {
1072 err = PTR_ERR(res);
16725b9d 1073 goto out_splat;
82995cc6 1074 }
a7f9fb20 1075 dout("root %p inode %p ino %llx.%llx\n", res,
2b0143b5 1076 d_inode(res), ceph_vinop(d_inode(res)));
82995cc6
DH
1077 fc->root = fsc->sb->s_root;
1078 return 0;
16725b9d
SW
1079
1080out_splat:
97820058
XL
1081 if (!ceph_mdsmap_is_cluster_available(fsc->mdsc->mdsmap)) {
1082 pr_info("No mds server is up or the cluster is laggy\n");
1083 err = -EHOSTUNREACH;
1084 }
1085
3d14c5d2 1086 ceph_mdsc_close_sessions(fsc->mdsc);
3981f2e2 1087 deactivate_locked_super(sb);
16725b9d
SW
1088 goto out_final;
1089
1090out:
3d14c5d2 1091 destroy_fs_client(fsc);
16725b9d 1092out_final:
82995cc6
DH
1093 dout("ceph_get_tree fail %d\n", err);
1094 return err;
1095}
1096
1097static void ceph_free_fc(struct fs_context *fc)
1098{
1099 struct ceph_parse_opts_ctx *pctx = fc->fs_private;
1100
1101 if (pctx) {
1102 destroy_mount_options(pctx->opts);
1103 ceph_destroy_options(pctx->copts);
1104 kfree(pctx);
1105 }
1106}
1107
1108static int ceph_reconfigure_fc(struct fs_context *fc)
1109{
1110 sync_filesystem(fc->root->d_sb);
1111 return 0;
1112}
1113
1114static const struct fs_context_operations ceph_context_ops = {
1115 .free = ceph_free_fc,
1116 .parse_param = ceph_parse_mount_param,
1117 .get_tree = ceph_get_tree,
1118 .reconfigure = ceph_reconfigure_fc,
1119};
1120
1121/*
1122 * Set up the filesystem mount context.
1123 */
1124static int ceph_init_fs_context(struct fs_context *fc)
1125{
1126 struct ceph_parse_opts_ctx *pctx;
1127 struct ceph_mount_options *fsopt;
1128
1129 pctx = kzalloc(sizeof(*pctx), GFP_KERNEL);
1130 if (!pctx)
1131 return -ENOMEM;
1132
1133 pctx->copts = ceph_alloc_options();
1134 if (!pctx->copts)
1135 goto nomem;
1136
1137 pctx->opts = kzalloc(sizeof(*pctx->opts), GFP_KERNEL);
1138 if (!pctx->opts)
1139 goto nomem;
1140
1141 fsopt = pctx->opts;
1142 fsopt->flags = CEPH_MOUNT_OPT_DEFAULT;
1143
1144 fsopt->wsize = CEPH_MAX_WRITE_SIZE;
1145 fsopt->rsize = CEPH_MAX_READ_SIZE;
1146 fsopt->rasize = CEPH_RASIZE_DEFAULT;
1147 fsopt->snapdir_name = kstrdup(CEPH_SNAPDIRNAME_DEFAULT, GFP_KERNEL);
1148 if (!fsopt->snapdir_name)
1149 goto nomem;
1150
1151 fsopt->caps_wanted_delay_min = CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT;
1152 fsopt->caps_wanted_delay_max = CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT;
1153 fsopt->max_readdir = CEPH_MAX_READDIR_DEFAULT;
1154 fsopt->max_readdir_bytes = CEPH_MAX_READDIR_BYTES_DEFAULT;
1155 fsopt->congestion_kb = default_congestion_kb();
1156
3b20bc2f
XL
1157#ifdef CONFIG_CEPH_FS_POSIX_ACL
1158 fc->sb_flags |= SB_POSIXACL;
1159#endif
1160
82995cc6
DH
1161 fc->fs_private = pctx;
1162 fc->ops = &ceph_context_ops;
1163 return 0;
1164
1165nomem:
1166 destroy_mount_options(pctx->opts);
1167 ceph_destroy_options(pctx->copts);
1168 kfree(pctx);
1169 return -ENOMEM;
16725b9d
SW
1170}
1171
1172static void ceph_kill_sb(struct super_block *s)
1173{
3d14c5d2 1174 struct ceph_fs_client *fsc = ceph_sb_to_client(s);
e4d27509
CH
1175 dev_t dev = s->s_dev;
1176
16725b9d 1177 dout("kill_sb %p\n", s);
e4d27509 1178
3d14c5d2 1179 ceph_mdsc_pre_umount(fsc->mdsc);
a57d9064
YZ
1180 flush_fs_workqueues(fsc);
1181
e4d27509 1182 generic_shutdown_super(s);
62a65f36
YZ
1183
1184 fsc->client->extra_mon_dispatch = NULL;
1185 ceph_fs_debugfs_cleanup(fsc);
1186
1d8f8360
YZ
1187 ceph_fscache_unregister_fs(fsc);
1188
3d14c5d2 1189 destroy_fs_client(fsc);
e4d27509 1190 free_anon_bdev(dev);
16725b9d
SW
1191}
1192
1193static struct file_system_type ceph_fs_type = {
1194 .owner = THIS_MODULE,
1195 .name = "ceph",
82995cc6 1196 .init_fs_context = ceph_init_fs_context,
16725b9d
SW
1197 .kill_sb = ceph_kill_sb,
1198 .fs_flags = FS_RENAME_DOES_D_MOVE,
1199};
7f78e035 1200MODULE_ALIAS_FS("ceph");
16725b9d 1201
d468e729
YZ
1202int ceph_force_reconnect(struct super_block *sb)
1203{
1204 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
1205 int err = 0;
1206
1207 ceph_umount_begin(sb);
1208
1209 /* Make sure all page caches get invalidated.
1210 * see remove_session_caps_cb() */
1211 flush_workqueue(fsc->inode_wq);
1212
1213 /* In case that we were blacklisted. This also reset
1214 * all mon/osd connections */
1215 ceph_reset_client_addr(fsc->client);
1216
1217 ceph_osdc_clear_abort_err(&fsc->client->osdc);
131d7eb4
YZ
1218
1219 fsc->blacklisted = false;
d468e729
YZ
1220 fsc->mount_state = CEPH_MOUNT_MOUNTED;
1221
1222 if (sb->s_root) {
1223 err = __ceph_do_getattr(d_inode(sb->s_root), NULL,
1224 CEPH_STAT_CAP_INODE, true);
1225 }
1226 return err;
1227}
1228
16725b9d
SW
1229static int __init init_ceph(void)
1230{
3d14c5d2 1231 int ret = init_caches();
16725b9d 1232 if (ret)
3d14c5d2 1233 goto out;
16725b9d 1234
eb13e832 1235 ceph_flock_init();
16725b9d
SW
1236 ret = register_filesystem(&ceph_fs_type);
1237 if (ret)
d0f191d2 1238 goto out_caches;
16725b9d 1239
3d14c5d2
YS
1240 pr_info("loaded (mds proto %d)\n", CEPH_MDSC_PROTOCOL);
1241
16725b9d
SW
1242 return 0;
1243
d0f191d2 1244out_caches:
16725b9d 1245 destroy_caches();
16725b9d
SW
1246out:
1247 return ret;
1248}
1249
1250static void __exit exit_ceph(void)
1251{
1252 dout("exit_ceph\n");
1253 unregister_filesystem(&ceph_fs_type);
16725b9d 1254 destroy_caches();
16725b9d
SW
1255}
1256
1257module_init(init_ceph);
1258module_exit(exit_ceph);
1259
1260MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
1261MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
1262MODULE_AUTHOR("Patience Warnick <patience@newdream.net>");
1263MODULE_DESCRIPTION("Ceph filesystem for Linux");
1264MODULE_LICENSE("GPL");