1 // SPDX-License-Identifier: GPL-2.0-only
3 #include <linux/ceph/ceph_debug.h>
5 #include <linux/backing-dev.h>
6 #include <linux/ctype.h>
8 #include <linux/inet.h>
10 #include <linux/module.h>
11 #include <linux/mount.h>
12 #include <linux/fs_context.h>
13 #include <linux/fs_parser.h>
14 #include <linux/sched.h>
15 #include <linux/seq_file.h>
16 #include <linux/slab.h>
17 #include <linux/statfs.h>
18 #include <linux/string.h>
21 #include "mds_client.h"
25 #include <linux/ceph/ceph_features.h>
26 #include <linux/ceph/decode.h>
27 #include <linux/ceph/mon_client.h>
28 #include <linux/ceph/auth.h>
29 #include <linux/ceph/debugfs.h>
31 #include <uapi/linux/magic.h>
33 static DEFINE_SPINLOCK(ceph_fsc_lock);
34 static LIST_HEAD(ceph_fsc_list);
37 * Ceph superblock operations
39 * Handle the basics of mounting, unmounting.
45 static void ceph_put_super(struct super_block *s)
47 struct ceph_fs_client *fsc = ceph_sb_to_client(s);
50 ceph_fscrypt_free_dummy_policy(fsc);
51 ceph_mdsc_close_sessions(fsc->mdsc);
54 static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf)
56 struct ceph_fs_client *fsc = ceph_inode_to_client(d_inode(dentry));
57 struct ceph_mon_client *monc = &fsc->client->monc;
58 struct ceph_statfs st;
62 if (fsc->mdsc->mdsmap->m_num_data_pg_pools == 1) {
63 data_pool = fsc->mdsc->mdsmap->m_data_pg_pools[0];
65 data_pool = CEPH_NOPOOL;
69 err = ceph_monc_do_statfs(monc, data_pool, &st);
74 buf->f_type = CEPH_SUPER_MAGIC; /* ?? */
77 * Express utilization in terms of large blocks to avoid
78 * overflow on 32-bit machines.
80 buf->f_frsize = 1 << CEPH_BLOCK_SHIFT;
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.
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);
95 * NOTE: for the time being, we make bsize == frsize to humor
96 * not-yet-ancient versions of glibc that are broken.
97 * Someday, we will probably want to report a real block
98 * size... whatever that may mean for a network file system!
100 buf->f_bsize = buf->f_frsize;
102 buf->f_files = le64_to_cpu(st.num_objects);
104 buf->f_namelen = NAME_MAX;
106 /* Must convert the fsid, for consistent values across arches */
107 buf->f_fsid.val[0] = 0;
108 mutex_lock(&monc->mutex);
109 for (i = 0 ; i < sizeof(monc->monmap->fsid) / sizeof(__le32) ; ++i)
110 buf->f_fsid.val[0] ^= le32_to_cpu(((__le32 *)&monc->monmap->fsid)[i]);
111 mutex_unlock(&monc->mutex);
113 /* fold the fs_cluster_id into the upper bits */
114 buf->f_fsid.val[1] = monc->fs_cluster_id;
119 static int ceph_sync_fs(struct super_block *sb, int wait)
121 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
124 dout("sync_fs (non-blocking)\n");
125 ceph_flush_dirty_caps(fsc->mdsc);
126 dout("sync_fs (non-blocking) done\n");
130 dout("sync_fs (blocking)\n");
131 ceph_osdc_sync(&fsc->client->osdc);
132 ceph_mdsc_sync(fsc->mdsc);
133 dout("sync_fs (blocking) done\n");
144 Opt_caps_wanted_delay_min,
145 Opt_caps_wanted_delay_max,
147 Opt_readdir_max_entries,
148 Opt_readdir_max_bytes,
156 Opt_test_dummy_encryption,
157 /* string args above */
165 Opt_require_active_mds,
174 enum ceph_recover_session_mode {
175 ceph_recover_session_no,
176 ceph_recover_session_clean
179 static const struct constant_table ceph_param_recover[] = {
180 { "no", ceph_recover_session_no },
181 { "clean", ceph_recover_session_clean },
185 static const struct fs_parameter_spec ceph_mount_parameters[] = {
186 fsparam_flag_no ("acl", Opt_acl),
187 fsparam_flag_no ("asyncreaddir", Opt_asyncreaddir),
188 fsparam_s32 ("caps_max", Opt_caps_max),
189 fsparam_u32 ("caps_wanted_delay_max", Opt_caps_wanted_delay_max),
190 fsparam_u32 ("caps_wanted_delay_min", Opt_caps_wanted_delay_min),
191 fsparam_u32 ("write_congestion_kb", Opt_congestion_kb),
192 fsparam_flag_no ("copyfrom", Opt_copyfrom),
193 fsparam_flag_no ("dcache", Opt_dcache),
194 fsparam_flag_no ("dirstat", Opt_dirstat),
195 fsparam_flag_no ("fsc", Opt_fscache), // fsc|nofsc
196 fsparam_string ("fsc", Opt_fscache), // fsc=...
197 fsparam_flag_no ("ino32", Opt_ino32),
198 fsparam_string ("mds_namespace", Opt_mds_namespace),
199 fsparam_string ("mon_addr", Opt_mon_addr),
200 fsparam_flag_no ("poolperm", Opt_poolperm),
201 fsparam_flag_no ("quotadf", Opt_quotadf),
202 fsparam_u32 ("rasize", Opt_rasize),
203 fsparam_flag_no ("rbytes", Opt_rbytes),
204 fsparam_u32 ("readdir_max_bytes", Opt_readdir_max_bytes),
205 fsparam_u32 ("readdir_max_entries", Opt_readdir_max_entries),
206 fsparam_enum ("recover_session", Opt_recover_session, ceph_param_recover),
207 fsparam_flag_no ("require_active_mds", Opt_require_active_mds),
208 fsparam_u32 ("rsize", Opt_rsize),
209 fsparam_string ("snapdirname", Opt_snapdirname),
210 fsparam_string ("source", Opt_source),
211 fsparam_flag ("test_dummy_encryption", Opt_test_dummy_encryption),
212 fsparam_string ("test_dummy_encryption", Opt_test_dummy_encryption),
213 fsparam_u32 ("wsize", Opt_wsize),
214 fsparam_flag_no ("wsync", Opt_wsync),
215 fsparam_flag_no ("pagecache", Opt_pagecache),
216 fsparam_flag_no ("sparseread", Opt_sparseread),
220 struct ceph_parse_opts_ctx {
221 struct ceph_options *copts;
222 struct ceph_mount_options *opts;
226 * Remove adjacent slashes and then the trailing slash, unless it is
227 * the only remaining character.
229 * E.g. "//dir1////dir2///" --> "/dir1/dir2", "///" --> "/".
231 static void canonicalize_path(char *path)
235 for (i = 0; path[i] != '\0'; i++) {
236 if (path[i] != '/' || j < 1 || path[j - 1] != '/')
240 if (j > 1 && path[j - 1] == '/')
246 * Check if the mds namespace in ceph_mount_options matches
247 * the passed in namespace string. First time match (when
248 * ->mds_namespace is NULL) is treated specially, since
249 * ->mds_namespace needs to be initialized by the caller.
251 static int namespace_equals(struct ceph_mount_options *fsopt,
252 const char *namespace, size_t len)
254 return !(fsopt->mds_namespace &&
255 (strlen(fsopt->mds_namespace) != len ||
256 strncmp(fsopt->mds_namespace, namespace, len)));
259 static int ceph_parse_old_source(const char *dev_name, const char *dev_name_end,
260 struct fs_context *fc)
263 struct ceph_parse_opts_ctx *pctx = fc->fs_private;
264 struct ceph_mount_options *fsopt = pctx->opts;
266 if (*dev_name_end != ':')
267 return invalfc(fc, "separator ':' missing in source");
269 r = ceph_parse_mon_ips(dev_name, dev_name_end - dev_name,
270 pctx->copts, fc->log.log, ',');
274 fsopt->new_dev_syntax = false;
278 static int ceph_parse_new_source(const char *dev_name, const char *dev_name_end,
279 struct fs_context *fc)
282 struct ceph_fsid fsid;
283 struct ceph_parse_opts_ctx *pctx = fc->fs_private;
284 struct ceph_mount_options *fsopt = pctx->opts;
285 char *fsid_start, *fs_name_start;
287 if (*dev_name_end != '=') {
288 dout("separator '=' missing in source");
292 fsid_start = strchr(dev_name, '@');
294 return invalfc(fc, "missing cluster fsid");
295 ++fsid_start; /* start of cluster fsid */
297 fs_name_start = strchr(fsid_start, '.');
299 return invalfc(fc, "missing file system name");
301 if (ceph_parse_fsid(fsid_start, &fsid))
302 return invalfc(fc, "Invalid FSID");
304 ++fs_name_start; /* start of file system name */
305 len = dev_name_end - fs_name_start;
307 if (!namespace_equals(fsopt, fs_name_start, len))
308 return invalfc(fc, "Mismatching mds_namespace");
309 kfree(fsopt->mds_namespace);
310 fsopt->mds_namespace = kstrndup(fs_name_start, len, GFP_KERNEL);
311 if (!fsopt->mds_namespace)
313 dout("file system (mds namespace) '%s'\n", fsopt->mds_namespace);
315 fsopt->new_dev_syntax = true;
320 * Parse the source parameter for new device format. Distinguish the device
321 * spec from the path. Try parsing new device format and fallback to old
324 * New device syntax will looks like:
325 * <device_spec>=/<path>
328 * <path> is optional, but if present must begin with '/'
329 * (monitor addresses are passed via mount option)
331 * Old device syntax is:
332 * <server_spec>[,<server_spec>...]:[<path>]
334 * <server_spec> is <ip>[:<port>]
335 * <path> is optional, but if present must begin with '/'
337 static int ceph_parse_source(struct fs_parameter *param, struct fs_context *fc)
339 struct ceph_parse_opts_ctx *pctx = fc->fs_private;
340 struct ceph_mount_options *fsopt = pctx->opts;
341 char *dev_name = param->string, *dev_name_end;
344 dout("%s '%s'\n", __func__, dev_name);
345 if (!dev_name || !*dev_name)
346 return invalfc(fc, "Empty source");
348 dev_name_end = strchr(dev_name, '/');
351 * The server_path will include the whole chars from userland
352 * including the leading '/'.
354 kfree(fsopt->server_path);
355 fsopt->server_path = kstrdup(dev_name_end, GFP_KERNEL);
356 if (!fsopt->server_path)
359 canonicalize_path(fsopt->server_path);
361 dev_name_end = dev_name + strlen(dev_name);
364 dev_name_end--; /* back up to separator */
365 if (dev_name_end < dev_name)
366 return invalfc(fc, "Path missing in source");
368 dout("device name '%.*s'\n", (int)(dev_name_end - dev_name), dev_name);
369 if (fsopt->server_path)
370 dout("server path '%s'\n", fsopt->server_path);
372 dout("trying new device syntax");
373 ret = ceph_parse_new_source(dev_name, dev_name_end, fc);
377 dout("trying old device syntax");
378 ret = ceph_parse_old_source(dev_name, dev_name_end, fc);
383 fc->source = param->string;
384 param->string = NULL;
388 static int ceph_parse_mon_addr(struct fs_parameter *param,
389 struct fs_context *fc)
391 struct ceph_parse_opts_ctx *pctx = fc->fs_private;
392 struct ceph_mount_options *fsopt = pctx->opts;
394 kfree(fsopt->mon_addr);
395 fsopt->mon_addr = param->string;
396 param->string = NULL;
398 return ceph_parse_mon_ips(fsopt->mon_addr, strlen(fsopt->mon_addr),
399 pctx->copts, fc->log.log, '/');
402 static int ceph_parse_mount_param(struct fs_context *fc,
403 struct fs_parameter *param)
405 struct ceph_parse_opts_ctx *pctx = fc->fs_private;
406 struct ceph_mount_options *fsopt = pctx->opts;
407 struct fs_parse_result result;
411 ret = ceph_parse_param(param, pctx->copts, fc->log.log);
412 if (ret != -ENOPARAM)
415 token = fs_parse(fc, ceph_mount_parameters, param, &result);
416 dout("%s fs_parse '%s' token %d\n", __func__, param->key, token);
421 case Opt_snapdirname:
422 kfree(fsopt->snapdir_name);
423 fsopt->snapdir_name = param->string;
424 param->string = NULL;
426 case Opt_mds_namespace:
427 if (!namespace_equals(fsopt, param->string, strlen(param->string)))
428 return invalfc(fc, "Mismatching mds_namespace");
429 kfree(fsopt->mds_namespace);
430 fsopt->mds_namespace = param->string;
431 param->string = NULL;
433 case Opt_recover_session:
434 mode = result.uint_32;
435 if (mode == ceph_recover_session_no)
436 fsopt->flags &= ~CEPH_MOUNT_OPT_CLEANRECOVER;
437 else if (mode == ceph_recover_session_clean)
438 fsopt->flags |= CEPH_MOUNT_OPT_CLEANRECOVER;
444 return invalfc(fc, "Multiple sources specified");
445 return ceph_parse_source(param, fc);
447 return ceph_parse_mon_addr(param, fc);
449 if (result.uint_32 < PAGE_SIZE ||
450 result.uint_32 > CEPH_MAX_WRITE_SIZE)
452 fsopt->wsize = ALIGN(result.uint_32, PAGE_SIZE);
455 if (result.uint_32 < PAGE_SIZE ||
456 result.uint_32 > CEPH_MAX_READ_SIZE)
458 fsopt->rsize = ALIGN(result.uint_32, PAGE_SIZE);
461 fsopt->rasize = ALIGN(result.uint_32, PAGE_SIZE);
463 case Opt_caps_wanted_delay_min:
464 if (result.uint_32 < 1)
466 fsopt->caps_wanted_delay_min = result.uint_32;
468 case Opt_caps_wanted_delay_max:
469 if (result.uint_32 < 1)
471 fsopt->caps_wanted_delay_max = result.uint_32;
474 if (result.int_32 < 0)
476 fsopt->caps_max = result.int_32;
478 case Opt_readdir_max_entries:
479 if (result.uint_32 < 1)
481 fsopt->max_readdir = result.uint_32;
483 case Opt_readdir_max_bytes:
484 if (result.uint_32 < PAGE_SIZE && result.uint_32 != 0)
486 fsopt->max_readdir_bytes = result.uint_32;
488 case Opt_congestion_kb:
489 if (result.uint_32 < 1024) /* at least 1M */
491 fsopt->congestion_kb = result.uint_32;
495 fsopt->flags |= CEPH_MOUNT_OPT_DIRSTAT;
497 fsopt->flags &= ~CEPH_MOUNT_OPT_DIRSTAT;
501 fsopt->flags |= CEPH_MOUNT_OPT_RBYTES;
503 fsopt->flags &= ~CEPH_MOUNT_OPT_RBYTES;
505 case Opt_asyncreaddir:
507 fsopt->flags &= ~CEPH_MOUNT_OPT_NOASYNCREADDIR;
509 fsopt->flags |= CEPH_MOUNT_OPT_NOASYNCREADDIR;
513 fsopt->flags |= CEPH_MOUNT_OPT_DCACHE;
515 fsopt->flags &= ~CEPH_MOUNT_OPT_DCACHE;
519 fsopt->flags |= CEPH_MOUNT_OPT_INO32;
521 fsopt->flags &= ~CEPH_MOUNT_OPT_INO32;
525 #ifdef CONFIG_CEPH_FSCACHE
526 kfree(fsopt->fscache_uniq);
527 fsopt->fscache_uniq = NULL;
528 if (result.negated) {
529 fsopt->flags &= ~CEPH_MOUNT_OPT_FSCACHE;
531 fsopt->flags |= CEPH_MOUNT_OPT_FSCACHE;
532 fsopt->fscache_uniq = param->string;
533 param->string = NULL;
537 return invalfc(fc, "fscache support is disabled");
541 fsopt->flags &= ~CEPH_MOUNT_OPT_NOPOOLPERM;
543 fsopt->flags |= CEPH_MOUNT_OPT_NOPOOLPERM;
545 case Opt_require_active_mds:
547 fsopt->flags &= ~CEPH_MOUNT_OPT_MOUNTWAIT;
549 fsopt->flags |= CEPH_MOUNT_OPT_MOUNTWAIT;
553 fsopt->flags &= ~CEPH_MOUNT_OPT_NOQUOTADF;
555 fsopt->flags |= CEPH_MOUNT_OPT_NOQUOTADF;
559 fsopt->flags &= ~CEPH_MOUNT_OPT_NOCOPYFROM;
561 fsopt->flags |= CEPH_MOUNT_OPT_NOCOPYFROM;
564 if (!result.negated) {
565 #ifdef CONFIG_CEPH_FS_POSIX_ACL
566 fc->sb_flags |= SB_POSIXACL;
568 return invalfc(fc, "POSIX ACL support is disabled");
571 fc->sb_flags &= ~SB_POSIXACL;
576 fsopt->flags &= ~CEPH_MOUNT_OPT_ASYNC_DIROPS;
578 fsopt->flags |= CEPH_MOUNT_OPT_ASYNC_DIROPS;
582 fsopt->flags |= CEPH_MOUNT_OPT_NOPAGECACHE;
584 fsopt->flags &= ~CEPH_MOUNT_OPT_NOPAGECACHE;
588 fsopt->flags &= ~CEPH_MOUNT_OPT_SPARSEREAD;
590 fsopt->flags |= CEPH_MOUNT_OPT_SPARSEREAD;
592 case Opt_test_dummy_encryption:
593 #ifdef CONFIG_FS_ENCRYPTION
594 fscrypt_free_dummy_policy(&fsopt->dummy_enc_policy);
595 ret = fscrypt_parse_test_dummy_encryption(param,
596 &fsopt->dummy_enc_policy);
597 if (ret == -EINVAL) {
598 warnfc(fc, "Value of option \"%s\" is unrecognized",
600 } else if (ret == -EEXIST) {
601 warnfc(fc, "Conflicting test_dummy_encryption options");
606 "FS encryption not supported: test_dummy_encryption mount option ignored");
615 return invalfc(fc, "%s out of range", param->key);
618 static void destroy_mount_options(struct ceph_mount_options *args)
620 dout("destroy_mount_options %p\n", args);
624 kfree(args->snapdir_name);
625 kfree(args->mds_namespace);
626 kfree(args->server_path);
627 kfree(args->fscache_uniq);
628 kfree(args->mon_addr);
629 fscrypt_free_dummy_policy(&args->dummy_enc_policy);
633 static int strcmp_null(const char *s1, const char *s2)
641 return strcmp(s1, s2);
644 static int compare_mount_options(struct ceph_mount_options *new_fsopt,
645 struct ceph_options *new_opt,
646 struct ceph_fs_client *fsc)
648 struct ceph_mount_options *fsopt1 = new_fsopt;
649 struct ceph_mount_options *fsopt2 = fsc->mount_options;
650 int ofs = offsetof(struct ceph_mount_options, snapdir_name);
653 ret = memcmp(fsopt1, fsopt2, ofs);
657 ret = strcmp_null(fsopt1->snapdir_name, fsopt2->snapdir_name);
661 ret = strcmp_null(fsopt1->mds_namespace, fsopt2->mds_namespace);
665 ret = strcmp_null(fsopt1->server_path, fsopt2->server_path);
669 ret = strcmp_null(fsopt1->fscache_uniq, fsopt2->fscache_uniq);
673 ret = strcmp_null(fsopt1->mon_addr, fsopt2->mon_addr);
677 return ceph_compare_options(new_opt, fsc->client);
681 * ceph_show_options - Show mount options in /proc/mounts
682 * @m: seq_file to write to
683 * @root: root of that (sub)tree
685 static int ceph_show_options(struct seq_file *m, struct dentry *root)
687 struct ceph_fs_client *fsc = ceph_sb_to_client(root->d_sb);
688 struct ceph_mount_options *fsopt = fsc->mount_options;
692 /* a comma between MNT/MS and client options */
696 ret = ceph_print_client_options(m, fsc->client, false);
700 /* retract our comma if no client options */
704 if (fsopt->flags & CEPH_MOUNT_OPT_DIRSTAT)
705 seq_puts(m, ",dirstat");
706 if ((fsopt->flags & CEPH_MOUNT_OPT_RBYTES))
707 seq_puts(m, ",rbytes");
708 if (fsopt->flags & CEPH_MOUNT_OPT_NOASYNCREADDIR)
709 seq_puts(m, ",noasyncreaddir");
710 if ((fsopt->flags & CEPH_MOUNT_OPT_DCACHE) == 0)
711 seq_puts(m, ",nodcache");
712 if (fsopt->flags & CEPH_MOUNT_OPT_INO32)
713 seq_puts(m, ",ino32");
714 if (fsopt->flags & CEPH_MOUNT_OPT_FSCACHE) {
715 seq_show_option(m, "fsc", fsopt->fscache_uniq);
717 if (fsopt->flags & CEPH_MOUNT_OPT_NOPOOLPERM)
718 seq_puts(m, ",nopoolperm");
719 if (fsopt->flags & CEPH_MOUNT_OPT_NOQUOTADF)
720 seq_puts(m, ",noquotadf");
722 #ifdef CONFIG_CEPH_FS_POSIX_ACL
723 if (root->d_sb->s_flags & SB_POSIXACL)
726 seq_puts(m, ",noacl");
729 if ((fsopt->flags & CEPH_MOUNT_OPT_NOCOPYFROM) == 0)
730 seq_puts(m, ",copyfrom");
732 /* dump mds_namespace when old device syntax is in use */
733 if (fsopt->mds_namespace && !fsopt->new_dev_syntax)
734 seq_show_option(m, "mds_namespace", fsopt->mds_namespace);
737 seq_printf(m, ",mon_addr=%s", fsopt->mon_addr);
739 if (fsopt->flags & CEPH_MOUNT_OPT_CLEANRECOVER)
740 seq_show_option(m, "recover_session", "clean");
742 if (!(fsopt->flags & CEPH_MOUNT_OPT_ASYNC_DIROPS))
743 seq_puts(m, ",wsync");
744 if (fsopt->flags & CEPH_MOUNT_OPT_NOPAGECACHE)
745 seq_puts(m, ",nopagecache");
746 if (fsopt->flags & CEPH_MOUNT_OPT_SPARSEREAD)
747 seq_puts(m, ",sparseread");
749 fscrypt_show_test_dummy_encryption(m, ',', root->d_sb);
751 if (fsopt->wsize != CEPH_MAX_WRITE_SIZE)
752 seq_printf(m, ",wsize=%u", fsopt->wsize);
753 if (fsopt->rsize != CEPH_MAX_READ_SIZE)
754 seq_printf(m, ",rsize=%u", fsopt->rsize);
755 if (fsopt->rasize != CEPH_RASIZE_DEFAULT)
756 seq_printf(m, ",rasize=%u", fsopt->rasize);
757 if (fsopt->congestion_kb != default_congestion_kb())
758 seq_printf(m, ",write_congestion_kb=%u", fsopt->congestion_kb);
760 seq_printf(m, ",caps_max=%d", fsopt->caps_max);
761 if (fsopt->caps_wanted_delay_min != CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT)
762 seq_printf(m, ",caps_wanted_delay_min=%u",
763 fsopt->caps_wanted_delay_min);
764 if (fsopt->caps_wanted_delay_max != CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT)
765 seq_printf(m, ",caps_wanted_delay_max=%u",
766 fsopt->caps_wanted_delay_max);
767 if (fsopt->max_readdir != CEPH_MAX_READDIR_DEFAULT)
768 seq_printf(m, ",readdir_max_entries=%u", fsopt->max_readdir);
769 if (fsopt->max_readdir_bytes != CEPH_MAX_READDIR_BYTES_DEFAULT)
770 seq_printf(m, ",readdir_max_bytes=%u", fsopt->max_readdir_bytes);
771 if (strcmp(fsopt->snapdir_name, CEPH_SNAPDIRNAME_DEFAULT))
772 seq_show_option(m, "snapdirname", fsopt->snapdir_name);
778 * handle any mon messages the standard library doesn't understand.
779 * return error if we don't either.
781 static int extra_mon_dispatch(struct ceph_client *client, struct ceph_msg *msg)
783 struct ceph_fs_client *fsc = client->private;
784 int type = le16_to_cpu(msg->hdr.type);
787 case CEPH_MSG_MDS_MAP:
788 ceph_mdsc_handle_mdsmap(fsc->mdsc, msg);
790 case CEPH_MSG_FS_MAP_USER:
791 ceph_mdsc_handle_fsmap(fsc->mdsc, msg);
799 * create a new fs client
801 * Success or not, this function consumes @fsopt and @opt.
803 static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
804 struct ceph_options *opt)
806 struct ceph_fs_client *fsc;
809 fsc = kzalloc(sizeof(*fsc), GFP_KERNEL);
815 fsc->client = ceph_create_client(opt, fsc);
816 if (IS_ERR(fsc->client)) {
817 err = PTR_ERR(fsc->client);
820 opt = NULL; /* fsc->client now owns this */
822 fsc->client->extra_mon_dispatch = extra_mon_dispatch;
823 ceph_set_opt(fsc->client, ABORT_ON_FULL);
825 if (!fsopt->mds_namespace) {
826 ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_MDSMAP,
829 ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_FSMAP,
833 fsc->mount_options = fsopt;
836 fsc->mount_state = CEPH_MOUNT_MOUNTING;
838 fsc->have_copy_from2 = true;
840 atomic_long_set(&fsc->writeback_count, 0);
841 fsc->write_congested = false;
845 * The number of concurrent works can be high but they don't need
846 * to be processed in parallel, limit concurrency.
848 fsc->inode_wq = alloc_workqueue("ceph-inode", WQ_UNBOUND, 0);
851 fsc->cap_wq = alloc_workqueue("ceph-cap", 0, 1);
855 hash_init(fsc->async_unlink_conflict);
856 spin_lock_init(&fsc->async_unlink_conflict_lock);
858 spin_lock(&ceph_fsc_lock);
859 list_add_tail(&fsc->metric_wakeup, &ceph_fsc_list);
860 spin_unlock(&ceph_fsc_lock);
865 destroy_workqueue(fsc->inode_wq);
867 ceph_destroy_client(fsc->client);
871 ceph_destroy_options(opt);
872 destroy_mount_options(fsopt);
876 static void flush_fs_workqueues(struct ceph_fs_client *fsc)
878 flush_workqueue(fsc->inode_wq);
879 flush_workqueue(fsc->cap_wq);
882 static void destroy_fs_client(struct ceph_fs_client *fsc)
884 dout("destroy_fs_client %p\n", fsc);
886 spin_lock(&ceph_fsc_lock);
887 list_del(&fsc->metric_wakeup);
888 spin_unlock(&ceph_fsc_lock);
890 ceph_mdsc_destroy(fsc);
891 destroy_workqueue(fsc->inode_wq);
892 destroy_workqueue(fsc->cap_wq);
894 destroy_mount_options(fsc->mount_options);
896 ceph_destroy_client(fsc->client);
899 dout("destroy_fs_client %p done\n", fsc);
905 struct kmem_cache *ceph_inode_cachep;
906 struct kmem_cache *ceph_cap_cachep;
907 struct kmem_cache *ceph_cap_snap_cachep;
908 struct kmem_cache *ceph_cap_flush_cachep;
909 struct kmem_cache *ceph_dentry_cachep;
910 struct kmem_cache *ceph_file_cachep;
911 struct kmem_cache *ceph_dir_file_cachep;
912 struct kmem_cache *ceph_mds_request_cachep;
913 mempool_t *ceph_wb_pagevec_pool;
915 static void ceph_inode_init_once(void *foo)
917 struct ceph_inode_info *ci = foo;
918 inode_init_once(&ci->netfs.inode);
921 static int __init init_caches(void)
925 ceph_inode_cachep = kmem_cache_create("ceph_inode_info",
926 sizeof(struct ceph_inode_info),
927 __alignof__(struct ceph_inode_info),
928 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|
929 SLAB_ACCOUNT, ceph_inode_init_once);
930 if (!ceph_inode_cachep)
933 ceph_cap_cachep = KMEM_CACHE(ceph_cap, SLAB_MEM_SPREAD);
934 if (!ceph_cap_cachep)
936 ceph_cap_snap_cachep = KMEM_CACHE(ceph_cap_snap, SLAB_MEM_SPREAD);
937 if (!ceph_cap_snap_cachep)
939 ceph_cap_flush_cachep = KMEM_CACHE(ceph_cap_flush,
940 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
941 if (!ceph_cap_flush_cachep)
944 ceph_dentry_cachep = KMEM_CACHE(ceph_dentry_info,
945 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
946 if (!ceph_dentry_cachep)
949 ceph_file_cachep = KMEM_CACHE(ceph_file_info, SLAB_MEM_SPREAD);
950 if (!ceph_file_cachep)
953 ceph_dir_file_cachep = KMEM_CACHE(ceph_dir_file_info, SLAB_MEM_SPREAD);
954 if (!ceph_dir_file_cachep)
957 ceph_mds_request_cachep = KMEM_CACHE(ceph_mds_request, SLAB_MEM_SPREAD);
958 if (!ceph_mds_request_cachep)
961 ceph_wb_pagevec_pool = mempool_create_kmalloc_pool(10, CEPH_MAX_WRITE_SIZE >> PAGE_SHIFT);
962 if (!ceph_wb_pagevec_pool)
963 goto bad_pagevec_pool;
968 kmem_cache_destroy(ceph_mds_request_cachep);
970 kmem_cache_destroy(ceph_dir_file_cachep);
972 kmem_cache_destroy(ceph_file_cachep);
974 kmem_cache_destroy(ceph_dentry_cachep);
976 kmem_cache_destroy(ceph_cap_flush_cachep);
978 kmem_cache_destroy(ceph_cap_snap_cachep);
980 kmem_cache_destroy(ceph_cap_cachep);
982 kmem_cache_destroy(ceph_inode_cachep);
986 static void destroy_caches(void)
989 * Make sure all delayed rcu free inodes are flushed before we
994 kmem_cache_destroy(ceph_inode_cachep);
995 kmem_cache_destroy(ceph_cap_cachep);
996 kmem_cache_destroy(ceph_cap_snap_cachep);
997 kmem_cache_destroy(ceph_cap_flush_cachep);
998 kmem_cache_destroy(ceph_dentry_cachep);
999 kmem_cache_destroy(ceph_file_cachep);
1000 kmem_cache_destroy(ceph_dir_file_cachep);
1001 kmem_cache_destroy(ceph_mds_request_cachep);
1002 mempool_destroy(ceph_wb_pagevec_pool);
1005 static void __ceph_umount_begin(struct ceph_fs_client *fsc)
1007 ceph_osdc_abort_requests(&fsc->client->osdc, -EIO);
1008 ceph_mdsc_force_umount(fsc->mdsc);
1009 fsc->filp_gen++; // invalidate open files
1013 * ceph_umount_begin - initiate forced umount. Tear down the
1014 * mount, skipping steps that may hang while waiting for server(s).
1016 void ceph_umount_begin(struct super_block *sb)
1018 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
1020 dout("ceph_umount_begin - starting forced umount\n");
1023 fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
1024 __ceph_umount_begin(fsc);
1027 static const struct super_operations ceph_super_ops = {
1028 .alloc_inode = ceph_alloc_inode,
1029 .free_inode = ceph_free_inode,
1030 .write_inode = ceph_write_inode,
1031 .drop_inode = generic_delete_inode,
1032 .evict_inode = ceph_evict_inode,
1033 .sync_fs = ceph_sync_fs,
1034 .put_super = ceph_put_super,
1035 .show_options = ceph_show_options,
1036 .statfs = ceph_statfs,
1037 .umount_begin = ceph_umount_begin,
1041 * Bootstrap mount by opening the root directory. Note the mount
1042 * @started time from caller, and time out if this takes too long.
1044 static struct dentry *open_root_dentry(struct ceph_fs_client *fsc,
1046 unsigned long started)
1048 struct ceph_mds_client *mdsc = fsc->mdsc;
1049 struct ceph_mds_request *req = NULL;
1051 struct dentry *root;
1054 dout("open_root_inode opening '%s'\n", path);
1055 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_GETATTR, USE_ANY_MDS);
1057 return ERR_CAST(req);
1058 req->r_path1 = kstrdup(path, GFP_NOFS);
1059 if (!req->r_path1) {
1060 root = ERR_PTR(-ENOMEM);
1064 req->r_ino1.ino = CEPH_INO_ROOT;
1065 req->r_ino1.snap = CEPH_NOSNAP;
1066 req->r_started = started;
1067 req->r_timeout = fsc->client->options->mount_timeout;
1068 req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INODE);
1069 req->r_num_caps = 2;
1070 err = ceph_mdsc_do_request(mdsc, NULL, req);
1072 struct inode *inode = req->r_target_inode;
1073 req->r_target_inode = NULL;
1074 dout("open_root_inode success\n");
1075 root = d_make_root(inode);
1077 root = ERR_PTR(-ENOMEM);
1080 dout("open_root_inode success, root dentry is %p\n", root);
1082 root = ERR_PTR(err);
1085 ceph_mdsc_put_request(req);
1089 #ifdef CONFIG_FS_ENCRYPTION
1090 static int ceph_apply_test_dummy_encryption(struct super_block *sb,
1091 struct fs_context *fc,
1092 struct ceph_mount_options *fsopt)
1094 struct ceph_fs_client *fsc = sb->s_fs_info;
1096 if (!fscrypt_is_dummy_policy_set(&fsopt->dummy_enc_policy))
1099 /* No changing encryption context on remount. */
1100 if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE &&
1101 !fscrypt_is_dummy_policy_set(&fsc->fsc_dummy_enc_policy)) {
1102 if (fscrypt_dummy_policies_equal(&fsopt->dummy_enc_policy,
1103 &fsc->fsc_dummy_enc_policy))
1105 errorfc(fc, "Can't set test_dummy_encryption on remount");
1109 /* Also make sure fsopt doesn't contain a conflicting value. */
1110 if (fscrypt_is_dummy_policy_set(&fsc->fsc_dummy_enc_policy)) {
1111 if (fscrypt_dummy_policies_equal(&fsopt->dummy_enc_policy,
1112 &fsc->fsc_dummy_enc_policy))
1114 errorfc(fc, "Conflicting test_dummy_encryption options");
1118 fsc->fsc_dummy_enc_policy = fsopt->dummy_enc_policy;
1119 memset(&fsopt->dummy_enc_policy, 0, sizeof(fsopt->dummy_enc_policy));
1121 warnfc(fc, "test_dummy_encryption mode enabled");
1125 static int ceph_apply_test_dummy_encryption(struct super_block *sb,
1126 struct fs_context *fc,
1127 struct ceph_mount_options *fsopt)
1134 * mount: join the ceph cluster, and open root directory.
1136 static struct dentry *ceph_real_mount(struct ceph_fs_client *fsc,
1137 struct fs_context *fc)
1140 unsigned long started = jiffies; /* note the start time */
1141 struct dentry *root;
1143 dout("mount start %p\n", fsc);
1144 mutex_lock(&fsc->client->mount_mutex);
1146 if (!fsc->sb->s_root) {
1147 const char *path = fsc->mount_options->server_path ?
1148 fsc->mount_options->server_path + 1 : "";
1150 err = __ceph_open_session(fsc->client, started);
1155 if (fsc->mount_options->flags & CEPH_MOUNT_OPT_FSCACHE) {
1156 err = ceph_fscache_register_fs(fsc, fc);
1161 err = ceph_apply_test_dummy_encryption(fsc->sb, fc,
1162 fsc->mount_options);
1166 dout("mount opening path '%s'\n", path);
1168 ceph_fs_debugfs_init(fsc);
1170 root = open_root_dentry(fsc, path, started);
1172 err = PTR_ERR(root);
1175 fsc->sb->s_root = dget(root);
1177 root = dget(fsc->sb->s_root);
1180 fsc->mount_state = CEPH_MOUNT_MOUNTED;
1181 dout("mount success\n");
1182 mutex_unlock(&fsc->client->mount_mutex);
1186 mutex_unlock(&fsc->client->mount_mutex);
1187 ceph_fscrypt_free_dummy_policy(fsc);
1188 return ERR_PTR(err);
1191 static int ceph_set_super(struct super_block *s, struct fs_context *fc)
1193 struct ceph_fs_client *fsc = s->s_fs_info;
1196 dout("set_super %p\n", s);
1198 s->s_maxbytes = MAX_LFS_FILESIZE;
1200 s->s_xattr = ceph_xattr_handlers;
1202 fsc->max_file_size = 1ULL << 40; /* temp value until we get mdsmap */
1204 s->s_op = &ceph_super_ops;
1205 s->s_d_op = &ceph_dentry_ops;
1206 s->s_export_op = &ceph_export_ops;
1210 s->s_time_max = U32_MAX;
1211 s->s_flags |= SB_NODIRATIME | SB_NOATIME;
1213 ceph_fscrypt_set_ops(s);
1215 ret = set_anon_super_fc(s, fc);
1222 * share superblock if same fs AND options
1224 static int ceph_compare_super(struct super_block *sb, struct fs_context *fc)
1226 struct ceph_fs_client *new = fc->s_fs_info;
1227 struct ceph_mount_options *fsopt = new->mount_options;
1228 struct ceph_options *opt = new->client->options;
1229 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
1231 dout("ceph_compare_super %p\n", sb);
1233 if (compare_mount_options(fsopt, opt, fsc)) {
1234 dout("monitor(s)/mount options don't match\n");
1237 if ((opt->flags & CEPH_OPT_FSID) &&
1238 ceph_fsid_compare(&opt->fsid, &fsc->client->fsid)) {
1239 dout("fsid doesn't match\n");
1242 if (fc->sb_flags != (sb->s_flags & ~SB_BORN)) {
1243 dout("flags differ\n");
1247 if (fsc->blocklisted && !ceph_test_mount_opt(fsc, CLEANRECOVER)) {
1248 dout("client is blocklisted (and CLEANRECOVER is not set)\n");
1252 if (fsc->mount_state == CEPH_MOUNT_SHUTDOWN) {
1253 dout("client has been forcibly unmounted\n");
1261 * construct our own bdi so we can control readahead, etc.
1263 static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
1265 static int ceph_setup_bdi(struct super_block *sb, struct ceph_fs_client *fsc)
1269 err = super_setup_bdi_name(sb, "ceph-%ld",
1270 atomic_long_inc_return(&bdi_seq));
1274 /* set ra_pages based on rasize mount option? */
1275 sb->s_bdi->ra_pages = fsc->mount_options->rasize >> PAGE_SHIFT;
1277 /* set io_pages based on max osd read size */
1278 sb->s_bdi->io_pages = fsc->mount_options->rsize >> PAGE_SHIFT;
1283 static int ceph_get_tree(struct fs_context *fc)
1285 struct ceph_parse_opts_ctx *pctx = fc->fs_private;
1286 struct ceph_mount_options *fsopt = pctx->opts;
1287 struct super_block *sb;
1288 struct ceph_fs_client *fsc;
1290 int (*compare_super)(struct super_block *, struct fs_context *) =
1294 dout("ceph_get_tree\n");
1297 return invalfc(fc, "No source");
1298 if (fsopt->new_dev_syntax && !fsopt->mon_addr)
1299 return invalfc(fc, "No monitor address");
1301 /* create client (which we may/may not use) */
1302 fsc = create_fs_client(pctx->opts, pctx->copts);
1310 err = ceph_mdsc_init(fsc);
1314 if (ceph_test_opt(fsc->client, NOSHARE))
1315 compare_super = NULL;
1317 fc->s_fs_info = fsc;
1318 sb = sget_fc(fc, compare_super, ceph_set_super);
1319 fc->s_fs_info = NULL;
1325 if (ceph_sb_to_client(sb) != fsc) {
1326 destroy_fs_client(fsc);
1327 fsc = ceph_sb_to_client(sb);
1328 dout("get_sb got existing client %p\n", fsc);
1330 dout("get_sb using new client %p\n", fsc);
1331 err = ceph_setup_bdi(sb, fsc);
1336 res = ceph_real_mount(fsc, fc);
1341 dout("root %p inode %p ino %llx.%llx\n", res,
1342 d_inode(res), ceph_vinop(d_inode(res)));
1343 fc->root = fsc->sb->s_root;
1347 if (!ceph_mdsmap_is_cluster_available(fsc->mdsc->mdsmap)) {
1348 pr_info("No mds server is up or the cluster is laggy\n");
1349 err = -EHOSTUNREACH;
1352 ceph_mdsc_close_sessions(fsc->mdsc);
1353 deactivate_locked_super(sb);
1357 destroy_fs_client(fsc);
1359 dout("ceph_get_tree fail %d\n", err);
1363 static void ceph_free_fc(struct fs_context *fc)
1365 struct ceph_parse_opts_ctx *pctx = fc->fs_private;
1368 destroy_mount_options(pctx->opts);
1369 ceph_destroy_options(pctx->copts);
1374 static int ceph_reconfigure_fc(struct fs_context *fc)
1377 struct ceph_parse_opts_ctx *pctx = fc->fs_private;
1378 struct ceph_mount_options *fsopt = pctx->opts;
1379 struct super_block *sb = fc->root->d_sb;
1380 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
1382 err = ceph_apply_test_dummy_encryption(sb, fc, fsopt);
1386 if (fsopt->flags & CEPH_MOUNT_OPT_ASYNC_DIROPS)
1387 ceph_set_mount_opt(fsc, ASYNC_DIROPS);
1389 ceph_clear_mount_opt(fsc, ASYNC_DIROPS);
1391 if (fsopt->flags & CEPH_MOUNT_OPT_SPARSEREAD)
1392 ceph_set_mount_opt(fsc, SPARSEREAD);
1394 ceph_clear_mount_opt(fsc, SPARSEREAD);
1396 if (strcmp_null(fsc->mount_options->mon_addr, fsopt->mon_addr)) {
1397 kfree(fsc->mount_options->mon_addr);
1398 fsc->mount_options->mon_addr = fsopt->mon_addr;
1399 fsopt->mon_addr = NULL;
1400 pr_notice("ceph: monitor addresses recorded, but not used for reconnection");
1403 sync_filesystem(sb);
1407 static const struct fs_context_operations ceph_context_ops = {
1408 .free = ceph_free_fc,
1409 .parse_param = ceph_parse_mount_param,
1410 .get_tree = ceph_get_tree,
1411 .reconfigure = ceph_reconfigure_fc,
1415 * Set up the filesystem mount context.
1417 static int ceph_init_fs_context(struct fs_context *fc)
1419 struct ceph_parse_opts_ctx *pctx;
1420 struct ceph_mount_options *fsopt;
1422 pctx = kzalloc(sizeof(*pctx), GFP_KERNEL);
1426 pctx->copts = ceph_alloc_options();
1430 pctx->opts = kzalloc(sizeof(*pctx->opts), GFP_KERNEL);
1435 fsopt->flags = CEPH_MOUNT_OPT_DEFAULT;
1437 fsopt->wsize = CEPH_MAX_WRITE_SIZE;
1438 fsopt->rsize = CEPH_MAX_READ_SIZE;
1439 fsopt->rasize = CEPH_RASIZE_DEFAULT;
1440 fsopt->snapdir_name = kstrdup(CEPH_SNAPDIRNAME_DEFAULT, GFP_KERNEL);
1441 if (!fsopt->snapdir_name)
1444 fsopt->caps_wanted_delay_min = CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT;
1445 fsopt->caps_wanted_delay_max = CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT;
1446 fsopt->max_readdir = CEPH_MAX_READDIR_DEFAULT;
1447 fsopt->max_readdir_bytes = CEPH_MAX_READDIR_BYTES_DEFAULT;
1448 fsopt->congestion_kb = default_congestion_kb();
1450 #ifdef CONFIG_CEPH_FS_POSIX_ACL
1451 fc->sb_flags |= SB_POSIXACL;
1454 fc->fs_private = pctx;
1455 fc->ops = &ceph_context_ops;
1459 destroy_mount_options(pctx->opts);
1460 ceph_destroy_options(pctx->copts);
1466 * Return true if it successfully increases the blocker counter,
1467 * or false if the mdsc is in stopping and flushed state.
1469 static bool __inc_stopping_blocker(struct ceph_mds_client *mdsc)
1471 spin_lock(&mdsc->stopping_lock);
1472 if (mdsc->stopping >= CEPH_MDSC_STOPPING_FLUSHING) {
1473 spin_unlock(&mdsc->stopping_lock);
1476 atomic_inc(&mdsc->stopping_blockers);
1477 spin_unlock(&mdsc->stopping_lock);
1481 static void __dec_stopping_blocker(struct ceph_mds_client *mdsc)
1483 spin_lock(&mdsc->stopping_lock);
1484 if (!atomic_dec_return(&mdsc->stopping_blockers) &&
1485 mdsc->stopping >= CEPH_MDSC_STOPPING_FLUSHING)
1486 complete_all(&mdsc->stopping_waiter);
1487 spin_unlock(&mdsc->stopping_lock);
1490 /* For metadata IO requests */
1491 bool ceph_inc_mds_stopping_blocker(struct ceph_mds_client *mdsc,
1492 struct ceph_mds_session *session)
1494 mutex_lock(&session->s_mutex);
1495 inc_session_sequence(session);
1496 mutex_unlock(&session->s_mutex);
1498 return __inc_stopping_blocker(mdsc);
1501 void ceph_dec_mds_stopping_blocker(struct ceph_mds_client *mdsc)
1503 __dec_stopping_blocker(mdsc);
1506 /* For data IO requests */
1507 bool ceph_inc_osd_stopping_blocker(struct ceph_mds_client *mdsc)
1509 return __inc_stopping_blocker(mdsc);
1512 void ceph_dec_osd_stopping_blocker(struct ceph_mds_client *mdsc)
1514 __dec_stopping_blocker(mdsc);
1517 static void ceph_kill_sb(struct super_block *s)
1519 struct ceph_fs_client *fsc = ceph_sb_to_client(s);
1520 struct ceph_mds_client *mdsc = fsc->mdsc;
1523 dout("kill_sb %p\n", s);
1525 ceph_mdsc_pre_umount(mdsc);
1526 flush_fs_workqueues(fsc);
1529 * Though the kill_anon_super() will finally trigger the
1530 * sync_filesystem() anyway, we still need to do it here and
1531 * then bump the stage of shutdown. This will allow us to
1532 * drop any further message, which will increase the inodes'
1533 * i_count reference counters but makes no sense any more,
1536 * Without this when evicting the inodes it may fail in the
1537 * kill_anon_super(), which will trigger a warning when
1538 * destroying the fscrypt keyring and then possibly trigger
1539 * a further crash in ceph module when the iput() tries to
1540 * evict the inodes later.
1544 spin_lock(&mdsc->stopping_lock);
1545 mdsc->stopping = CEPH_MDSC_STOPPING_FLUSHING;
1546 wait = !!atomic_read(&mdsc->stopping_blockers);
1547 spin_unlock(&mdsc->stopping_lock);
1549 if (wait && atomic_read(&mdsc->stopping_blockers)) {
1550 long timeleft = wait_for_completion_killable_timeout(
1551 &mdsc->stopping_waiter,
1552 fsc->client->options->mount_timeout);
1553 if (!timeleft) /* timed out */
1554 pr_warn("umount timed out, %ld\n", timeleft);
1555 else if (timeleft < 0) /* killed */
1556 pr_warn("umount was killed, %ld\n", timeleft);
1559 mdsc->stopping = CEPH_MDSC_STOPPING_FLUSHED;
1562 fsc->client->extra_mon_dispatch = NULL;
1563 ceph_fs_debugfs_cleanup(fsc);
1565 ceph_fscache_unregister_fs(fsc);
1567 destroy_fs_client(fsc);
1570 static struct file_system_type ceph_fs_type = {
1571 .owner = THIS_MODULE,
1573 .init_fs_context = ceph_init_fs_context,
1574 .kill_sb = ceph_kill_sb,
1575 .fs_flags = FS_RENAME_DOES_D_MOVE,
1577 MODULE_ALIAS_FS("ceph");
1579 int ceph_force_reconnect(struct super_block *sb)
1581 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
1584 fsc->mount_state = CEPH_MOUNT_RECOVER;
1585 __ceph_umount_begin(fsc);
1587 /* Make sure all page caches get invalidated.
1588 * see remove_session_caps_cb() */
1589 flush_workqueue(fsc->inode_wq);
1591 /* In case that we were blocklisted. This also reset
1592 * all mon/osd connections */
1593 ceph_reset_client_addr(fsc->client);
1595 ceph_osdc_clear_abort_err(&fsc->client->osdc);
1597 fsc->blocklisted = false;
1598 fsc->mount_state = CEPH_MOUNT_MOUNTED;
1601 err = __ceph_do_getattr(d_inode(sb->s_root), NULL,
1602 CEPH_STAT_CAP_INODE, true);
1607 static int __init init_ceph(void)
1609 int ret = init_caches();
1614 ret = register_filesystem(&ceph_fs_type);
1618 pr_info("loaded (mds proto %d)\n", CEPH_MDSC_PROTOCOL);
1628 static void __exit exit_ceph(void)
1630 dout("exit_ceph\n");
1631 unregister_filesystem(&ceph_fs_type);
1635 static int param_set_metrics(const char *val, const struct kernel_param *kp)
1637 struct ceph_fs_client *fsc;
1640 ret = param_set_bool(val, kp);
1642 pr_err("Failed to parse sending metrics switch value '%s'\n",
1645 } else if (!disable_send_metrics) {
1646 // wake up all the mds clients
1647 spin_lock(&ceph_fsc_lock);
1648 list_for_each_entry(fsc, &ceph_fsc_list, metric_wakeup) {
1649 metric_schedule_delayed(&fsc->mdsc->metric);
1651 spin_unlock(&ceph_fsc_lock);
1657 static const struct kernel_param_ops param_ops_metrics = {
1658 .set = param_set_metrics,
1659 .get = param_get_bool,
1662 bool disable_send_metrics = false;
1663 module_param_cb(disable_send_metrics, ¶m_ops_metrics, &disable_send_metrics, 0644);
1664 MODULE_PARM_DESC(disable_send_metrics, "Enable sending perf metrics to ceph cluster (default: on)");
1666 /* for both v1 and v2 syntax */
1667 static bool mount_support = true;
1668 static const struct kernel_param_ops param_ops_mount_syntax = {
1669 .get = param_get_bool,
1671 module_param_cb(mount_syntax_v1, ¶m_ops_mount_syntax, &mount_support, 0444);
1672 module_param_cb(mount_syntax_v2, ¶m_ops_mount_syntax, &mount_support, 0444);
1674 module_init(init_ceph);
1675 module_exit(exit_ceph);
1680 MODULE_DESCRIPTION("Ceph filesystem for Linux");
1681 MODULE_LICENSE("GPL");