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/parser.h>
13 #include <linux/sched.h>
14 #include <linux/seq_file.h>
15 #include <linux/slab.h>
16 #include <linux/statfs.h>
17 #include <linux/string.h>
20 #include "mds_client.h"
23 #include <linux/ceph/ceph_features.h>
24 #include <linux/ceph/decode.h>
25 #include <linux/ceph/mon_client.h>
26 #include <linux/ceph/auth.h>
27 #include <linux/ceph/debugfs.h>
30 * Ceph superblock operations
32 * Handle the basics of mounting, unmounting.
38 static void ceph_put_super(struct super_block *s)
40 struct ceph_fs_client *fsc = ceph_sb_to_client(s);
43 ceph_mdsc_close_sessions(fsc->mdsc);
46 static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf)
48 struct ceph_fs_client *fsc = ceph_inode_to_client(d_inode(dentry));
49 struct ceph_mon_client *monc = &fsc->client->monc;
50 struct ceph_statfs st;
55 if (fsc->mdsc->mdsmap->m_num_data_pg_pools == 1) {
56 data_pool = fsc->mdsc->mdsmap->m_data_pg_pools[0];
58 data_pool = CEPH_NOPOOL;
62 err = ceph_monc_do_statfs(monc, data_pool, &st);
67 buf->f_type = CEPH_SUPER_MAGIC; /* ?? */
70 * express utilization in terms of large blocks to avoid
71 * overflow on 32-bit machines.
73 * NOTE: for the time being, we make bsize == frsize to humor
74 * not-yet-ancient versions of glibc that are broken.
75 * Someday, we will probably want to report a real block
76 * size... whatever that may mean for a network file system!
78 buf->f_bsize = 1 << CEPH_BLOCK_SHIFT;
79 buf->f_frsize = 1 << CEPH_BLOCK_SHIFT;
82 * By default use root quota for stats; fallback to overall filesystem
83 * usage if using 'noquotadf' mount option or if the root dir doesn't
84 * have max_bytes quota set.
86 if (ceph_test_mount_opt(fsc, NOQUOTADF) ||
87 !ceph_quota_update_statfs(fsc, buf)) {
88 buf->f_blocks = le64_to_cpu(st.kb) >> (CEPH_BLOCK_SHIFT-10);
89 buf->f_bfree = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);
90 buf->f_bavail = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);
93 buf->f_files = le64_to_cpu(st.num_objects);
95 buf->f_namelen = NAME_MAX;
97 /* Must convert the fsid, for consistent values across arches */
98 mutex_lock(&monc->mutex);
99 fsid = le64_to_cpu(*(__le64 *)(&monc->monmap->fsid)) ^
100 le64_to_cpu(*((__le64 *)&monc->monmap->fsid + 1));
101 mutex_unlock(&monc->mutex);
103 buf->f_fsid.val[0] = fsid & 0xffffffff;
104 buf->f_fsid.val[1] = fsid >> 32;
110 static int ceph_sync_fs(struct super_block *sb, int wait)
112 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
115 dout("sync_fs (non-blocking)\n");
116 ceph_flush_dirty_caps(fsc->mdsc);
117 dout("sync_fs (non-blocking) done\n");
121 dout("sync_fs (blocking)\n");
122 ceph_osdc_sync(&fsc->client->osdc);
123 ceph_mdsc_sync(fsc->mdsc);
124 dout("sync_fs (blocking) done\n");
135 Opt_caps_wanted_delay_min,
136 Opt_caps_wanted_delay_max,
138 Opt_readdir_max_entries,
139 Opt_readdir_max_bytes,
148 /* string args above */
163 Opt_require_active_mds,
164 Opt_norequire_active_mds,
165 #ifdef CONFIG_CEPH_FS_POSIX_ACL
175 static match_table_t fsopt_tokens = {
176 {Opt_wsize, "wsize=%d"},
177 {Opt_rsize, "rsize=%d"},
178 {Opt_rasize, "rasize=%d"},
179 {Opt_caps_wanted_delay_min, "caps_wanted_delay_min=%d"},
180 {Opt_caps_wanted_delay_max, "caps_wanted_delay_max=%d"},
181 {Opt_caps_max, "caps_max=%d"},
182 {Opt_readdir_max_entries, "readdir_max_entries=%d"},
183 {Opt_readdir_max_bytes, "readdir_max_bytes=%d"},
184 {Opt_congestion_kb, "write_congestion_kb=%d"},
186 {Opt_snapdirname, "snapdirname=%s"},
187 {Opt_mds_namespace, "mds_namespace=%s"},
188 {Opt_recover_session, "recover_session=%s"},
189 {Opt_fscache_uniq, "fsc=%s"},
190 /* string args above */
191 {Opt_dirstat, "dirstat"},
192 {Opt_nodirstat, "nodirstat"},
193 {Opt_rbytes, "rbytes"},
194 {Opt_norbytes, "norbytes"},
195 {Opt_asyncreaddir, "asyncreaddir"},
196 {Opt_noasyncreaddir, "noasyncreaddir"},
197 {Opt_dcache, "dcache"},
198 {Opt_nodcache, "nodcache"},
199 {Opt_ino32, "ino32"},
200 {Opt_noino32, "noino32"},
201 {Opt_fscache, "fsc"},
202 {Opt_nofscache, "nofsc"},
203 {Opt_poolperm, "poolperm"},
204 {Opt_nopoolperm, "nopoolperm"},
205 {Opt_require_active_mds, "require_active_mds"},
206 {Opt_norequire_active_mds, "norequire_active_mds"},
207 #ifdef CONFIG_CEPH_FS_POSIX_ACL
210 {Opt_noacl, "noacl"},
211 {Opt_quotadf, "quotadf"},
212 {Opt_noquotadf, "noquotadf"},
213 {Opt_copyfrom, "copyfrom"},
214 {Opt_nocopyfrom, "nocopyfrom"},
218 static int parse_fsopt_token(char *c, void *private)
220 struct ceph_mount_options *fsopt = private;
221 substring_t argstr[MAX_OPT_ARGS];
222 int token, intval, ret;
224 token = match_token((char *)c, fsopt_tokens, argstr);
228 if (token < Opt_last_int) {
229 ret = match_int(&argstr[0], &intval);
231 pr_err("bad option arg (not int) at '%s'\n", c);
234 dout("got int token %d val %d\n", token, intval);
235 } else if (token > Opt_last_int && token < Opt_last_string) {
236 dout("got string token %d val %s\n", token,
239 dout("got token %d\n", token);
243 case Opt_snapdirname:
244 kfree(fsopt->snapdir_name);
245 fsopt->snapdir_name = kstrndup(argstr[0].from,
246 argstr[0].to-argstr[0].from,
248 if (!fsopt->snapdir_name)
251 case Opt_mds_namespace:
252 kfree(fsopt->mds_namespace);
253 fsopt->mds_namespace = kstrndup(argstr[0].from,
254 argstr[0].to-argstr[0].from,
256 if (!fsopt->mds_namespace)
259 case Opt_recover_session:
260 if (!strncmp(argstr[0].from, "no",
261 argstr[0].to - argstr[0].from)) {
262 fsopt->flags &= ~CEPH_MOUNT_OPT_CLEANRECOVER;
263 } else if (!strncmp(argstr[0].from, "clean",
264 argstr[0].to - argstr[0].from)) {
265 fsopt->flags |= CEPH_MOUNT_OPT_CLEANRECOVER;
270 case Opt_fscache_uniq:
271 kfree(fsopt->fscache_uniq);
272 fsopt->fscache_uniq = kstrndup(argstr[0].from,
273 argstr[0].to-argstr[0].from,
275 if (!fsopt->fscache_uniq)
277 fsopt->flags |= CEPH_MOUNT_OPT_FSCACHE;
281 if (intval < (int)PAGE_SIZE || intval > CEPH_MAX_WRITE_SIZE)
283 fsopt->wsize = ALIGN(intval, PAGE_SIZE);
286 if (intval < (int)PAGE_SIZE || intval > CEPH_MAX_READ_SIZE)
288 fsopt->rsize = ALIGN(intval, PAGE_SIZE);
293 fsopt->rasize = ALIGN(intval, PAGE_SIZE);
295 case Opt_caps_wanted_delay_min:
298 fsopt->caps_wanted_delay_min = intval;
300 case Opt_caps_wanted_delay_max:
303 fsopt->caps_wanted_delay_max = intval;
308 fsopt->caps_max = intval;
310 case Opt_readdir_max_entries:
313 fsopt->max_readdir = intval;
315 case Opt_readdir_max_bytes:
316 if (intval < (int)PAGE_SIZE && intval != 0)
318 fsopt->max_readdir_bytes = intval;
320 case Opt_congestion_kb:
321 if (intval < 1024) /* at least 1M */
323 fsopt->congestion_kb = intval;
326 fsopt->flags |= CEPH_MOUNT_OPT_DIRSTAT;
329 fsopt->flags &= ~CEPH_MOUNT_OPT_DIRSTAT;
332 fsopt->flags |= CEPH_MOUNT_OPT_RBYTES;
335 fsopt->flags &= ~CEPH_MOUNT_OPT_RBYTES;
337 case Opt_asyncreaddir:
338 fsopt->flags &= ~CEPH_MOUNT_OPT_NOASYNCREADDIR;
340 case Opt_noasyncreaddir:
341 fsopt->flags |= CEPH_MOUNT_OPT_NOASYNCREADDIR;
344 fsopt->flags |= CEPH_MOUNT_OPT_DCACHE;
347 fsopt->flags &= ~CEPH_MOUNT_OPT_DCACHE;
350 fsopt->flags |= CEPH_MOUNT_OPT_INO32;
353 fsopt->flags &= ~CEPH_MOUNT_OPT_INO32;
356 fsopt->flags |= CEPH_MOUNT_OPT_FSCACHE;
357 kfree(fsopt->fscache_uniq);
358 fsopt->fscache_uniq = NULL;
361 fsopt->flags &= ~CEPH_MOUNT_OPT_FSCACHE;
362 kfree(fsopt->fscache_uniq);
363 fsopt->fscache_uniq = NULL;
366 fsopt->flags &= ~CEPH_MOUNT_OPT_NOPOOLPERM;
369 fsopt->flags |= CEPH_MOUNT_OPT_NOPOOLPERM;
371 case Opt_require_active_mds:
372 fsopt->flags &= ~CEPH_MOUNT_OPT_MOUNTWAIT;
374 case Opt_norequire_active_mds:
375 fsopt->flags |= CEPH_MOUNT_OPT_MOUNTWAIT;
378 fsopt->flags &= ~CEPH_MOUNT_OPT_NOQUOTADF;
381 fsopt->flags |= CEPH_MOUNT_OPT_NOQUOTADF;
384 fsopt->flags &= ~CEPH_MOUNT_OPT_NOCOPYFROM;
387 fsopt->flags |= CEPH_MOUNT_OPT_NOCOPYFROM;
389 #ifdef CONFIG_CEPH_FS_POSIX_ACL
391 fsopt->sb_flags |= SB_POSIXACL;
395 fsopt->sb_flags &= ~SB_POSIXACL;
403 static void destroy_mount_options(struct ceph_mount_options *args)
405 dout("destroy_mount_options %p\n", args);
406 kfree(args->snapdir_name);
407 kfree(args->mds_namespace);
408 kfree(args->server_path);
409 kfree(args->fscache_uniq);
413 static int strcmp_null(const char *s1, const char *s2)
421 return strcmp(s1, s2);
424 static int compare_mount_options(struct ceph_mount_options *new_fsopt,
425 struct ceph_options *new_opt,
426 struct ceph_fs_client *fsc)
428 struct ceph_mount_options *fsopt1 = new_fsopt;
429 struct ceph_mount_options *fsopt2 = fsc->mount_options;
430 int ofs = offsetof(struct ceph_mount_options, snapdir_name);
433 ret = memcmp(fsopt1, fsopt2, ofs);
437 ret = strcmp_null(fsopt1->snapdir_name, fsopt2->snapdir_name);
440 ret = strcmp_null(fsopt1->mds_namespace, fsopt2->mds_namespace);
443 ret = strcmp_null(fsopt1->server_path, fsopt2->server_path);
446 ret = strcmp_null(fsopt1->fscache_uniq, fsopt2->fscache_uniq);
450 return ceph_compare_options(new_opt, fsc->client);
453 static int parse_mount_options(struct ceph_mount_options **pfsopt,
454 struct ceph_options **popt,
455 int flags, char *options,
456 const char *dev_name)
458 struct ceph_mount_options *fsopt;
459 const char *dev_name_end;
462 if (!dev_name || !*dev_name)
465 fsopt = kzalloc(sizeof(*fsopt), GFP_KERNEL);
469 dout("parse_mount_options %p, dev_name '%s'\n", fsopt, dev_name);
471 fsopt->sb_flags = flags;
472 fsopt->flags = CEPH_MOUNT_OPT_DEFAULT;
474 fsopt->wsize = CEPH_MAX_WRITE_SIZE;
475 fsopt->rsize = CEPH_MAX_READ_SIZE;
476 fsopt->rasize = CEPH_RASIZE_DEFAULT;
477 fsopt->snapdir_name = kstrdup(CEPH_SNAPDIRNAME_DEFAULT, GFP_KERNEL);
478 if (!fsopt->snapdir_name) {
483 fsopt->caps_wanted_delay_min = CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT;
484 fsopt->caps_wanted_delay_max = CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT;
485 fsopt->max_readdir = CEPH_MAX_READDIR_DEFAULT;
486 fsopt->max_readdir_bytes = CEPH_MAX_READDIR_BYTES_DEFAULT;
487 fsopt->congestion_kb = default_congestion_kb();
490 * Distinguish the server list from the path in "dev_name".
491 * Internally we do not include the leading '/' in the path.
493 * "dev_name" will look like:
494 * <server_spec>[,<server_spec>...]:[<path>]
496 * <server_spec> is <ip>[:<port>]
497 * <path> is optional, but if present must begin with '/'
499 dev_name_end = strchr(dev_name, '/');
501 if (strlen(dev_name_end) > 1) {
502 fsopt->server_path = kstrdup(dev_name_end, GFP_KERNEL);
503 if (!fsopt->server_path) {
509 dev_name_end = dev_name + strlen(dev_name);
512 dev_name_end--; /* back up to ':' separator */
513 if (dev_name_end < dev_name || *dev_name_end != ':') {
514 pr_err("device name is missing path (no : separator in %s)\n",
518 dout("device name '%.*s'\n", (int)(dev_name_end - dev_name), dev_name);
519 if (fsopt->server_path)
520 dout("server path '%s'\n", fsopt->server_path);
522 *popt = ceph_parse_options(options, dev_name, dev_name_end,
523 parse_fsopt_token, (void *)fsopt);
525 err = PTR_ERR(*popt);
534 destroy_mount_options(fsopt);
539 * ceph_show_options - Show mount options in /proc/mounts
540 * @m: seq_file to write to
541 * @root: root of that (sub)tree
543 static int ceph_show_options(struct seq_file *m, struct dentry *root)
545 struct ceph_fs_client *fsc = ceph_sb_to_client(root->d_sb);
546 struct ceph_mount_options *fsopt = fsc->mount_options;
550 /* a comma between MNT/MS and client options */
554 ret = ceph_print_client_options(m, fsc->client, false);
558 /* retract our comma if no client options */
562 if (fsopt->flags & CEPH_MOUNT_OPT_DIRSTAT)
563 seq_puts(m, ",dirstat");
564 if ((fsopt->flags & CEPH_MOUNT_OPT_RBYTES))
565 seq_puts(m, ",rbytes");
566 if (fsopt->flags & CEPH_MOUNT_OPT_NOASYNCREADDIR)
567 seq_puts(m, ",noasyncreaddir");
568 if ((fsopt->flags & CEPH_MOUNT_OPT_DCACHE) == 0)
569 seq_puts(m, ",nodcache");
570 if (fsopt->flags & CEPH_MOUNT_OPT_INO32)
571 seq_puts(m, ",ino32");
572 if (fsopt->flags & CEPH_MOUNT_OPT_FSCACHE) {
573 seq_show_option(m, "fsc", fsopt->fscache_uniq);
575 if (fsopt->flags & CEPH_MOUNT_OPT_NOPOOLPERM)
576 seq_puts(m, ",nopoolperm");
577 if (fsopt->flags & CEPH_MOUNT_OPT_NOQUOTADF)
578 seq_puts(m, ",noquotadf");
580 #ifdef CONFIG_CEPH_FS_POSIX_ACL
581 if (fsopt->sb_flags & SB_POSIXACL)
584 seq_puts(m, ",noacl");
587 if ((fsopt->flags & CEPH_MOUNT_OPT_NOCOPYFROM) == 0)
588 seq_puts(m, ",copyfrom");
590 if (fsopt->mds_namespace)
591 seq_show_option(m, "mds_namespace", fsopt->mds_namespace);
593 if (fsopt->flags & CEPH_MOUNT_OPT_CLEANRECOVER)
594 seq_show_option(m, "recover_session", "clean");
596 if (fsopt->wsize != CEPH_MAX_WRITE_SIZE)
597 seq_printf(m, ",wsize=%d", fsopt->wsize);
598 if (fsopt->rsize != CEPH_MAX_READ_SIZE)
599 seq_printf(m, ",rsize=%d", fsopt->rsize);
600 if (fsopt->rasize != CEPH_RASIZE_DEFAULT)
601 seq_printf(m, ",rasize=%d", fsopt->rasize);
602 if (fsopt->congestion_kb != default_congestion_kb())
603 seq_printf(m, ",write_congestion_kb=%d", fsopt->congestion_kb);
605 seq_printf(m, ",caps_max=%d", fsopt->caps_max);
606 if (fsopt->caps_wanted_delay_min != CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT)
607 seq_printf(m, ",caps_wanted_delay_min=%d",
608 fsopt->caps_wanted_delay_min);
609 if (fsopt->caps_wanted_delay_max != CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT)
610 seq_printf(m, ",caps_wanted_delay_max=%d",
611 fsopt->caps_wanted_delay_max);
612 if (fsopt->max_readdir != CEPH_MAX_READDIR_DEFAULT)
613 seq_printf(m, ",readdir_max_entries=%d", fsopt->max_readdir);
614 if (fsopt->max_readdir_bytes != CEPH_MAX_READDIR_BYTES_DEFAULT)
615 seq_printf(m, ",readdir_max_bytes=%d", fsopt->max_readdir_bytes);
616 if (strcmp(fsopt->snapdir_name, CEPH_SNAPDIRNAME_DEFAULT))
617 seq_show_option(m, "snapdirname", fsopt->snapdir_name);
623 * handle any mon messages the standard library doesn't understand.
624 * return error if we don't either.
626 static int extra_mon_dispatch(struct ceph_client *client, struct ceph_msg *msg)
628 struct ceph_fs_client *fsc = client->private;
629 int type = le16_to_cpu(msg->hdr.type);
632 case CEPH_MSG_MDS_MAP:
633 ceph_mdsc_handle_mdsmap(fsc->mdsc, msg);
635 case CEPH_MSG_FS_MAP_USER:
636 ceph_mdsc_handle_fsmap(fsc->mdsc, msg);
644 * create a new fs client
646 * Success or not, this function consumes @fsopt and @opt.
648 static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
649 struct ceph_options *opt)
651 struct ceph_fs_client *fsc;
656 fsc = kzalloc(sizeof(*fsc), GFP_KERNEL);
662 fsc->client = ceph_create_client(opt, fsc);
663 if (IS_ERR(fsc->client)) {
664 err = PTR_ERR(fsc->client);
667 opt = NULL; /* fsc->client now owns this */
669 fsc->client->extra_mon_dispatch = extra_mon_dispatch;
670 ceph_set_opt(fsc->client, ABORT_ON_FULL);
672 if (!fsopt->mds_namespace) {
673 ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_MDSMAP,
676 ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_FSMAP,
680 fsc->mount_options = fsopt;
683 fsc->mount_state = CEPH_MOUNT_MOUNTING;
686 atomic_long_set(&fsc->writeback_count, 0);
690 * The number of concurrent works can be high but they don't need
691 * to be processed in parallel, limit concurrency.
693 fsc->inode_wq = alloc_workqueue("ceph-inode", WQ_UNBOUND, 0);
696 fsc->cap_wq = alloc_workqueue("ceph-cap", 0, 1);
700 /* set up mempools */
702 page_count = fsc->mount_options->wsize >> PAGE_SHIFT;
703 size = sizeof (struct page *) * (page_count ? page_count : 1);
704 fsc->wb_pagevec_pool = mempool_create_kmalloc_pool(10, size);
705 if (!fsc->wb_pagevec_pool)
711 destroy_workqueue(fsc->cap_wq);
713 destroy_workqueue(fsc->inode_wq);
715 ceph_destroy_client(fsc->client);
719 ceph_destroy_options(opt);
720 destroy_mount_options(fsopt);
724 static void flush_fs_workqueues(struct ceph_fs_client *fsc)
726 flush_workqueue(fsc->inode_wq);
727 flush_workqueue(fsc->cap_wq);
730 static void destroy_fs_client(struct ceph_fs_client *fsc)
732 dout("destroy_fs_client %p\n", fsc);
734 ceph_mdsc_destroy(fsc);
735 destroy_workqueue(fsc->inode_wq);
736 destroy_workqueue(fsc->cap_wq);
738 mempool_destroy(fsc->wb_pagevec_pool);
740 destroy_mount_options(fsc->mount_options);
742 ceph_destroy_client(fsc->client);
745 dout("destroy_fs_client %p done\n", fsc);
751 struct kmem_cache *ceph_inode_cachep;
752 struct kmem_cache *ceph_cap_cachep;
753 struct kmem_cache *ceph_cap_flush_cachep;
754 struct kmem_cache *ceph_dentry_cachep;
755 struct kmem_cache *ceph_file_cachep;
756 struct kmem_cache *ceph_dir_file_cachep;
758 static void ceph_inode_init_once(void *foo)
760 struct ceph_inode_info *ci = foo;
761 inode_init_once(&ci->vfs_inode);
764 static int __init init_caches(void)
768 ceph_inode_cachep = kmem_cache_create("ceph_inode_info",
769 sizeof(struct ceph_inode_info),
770 __alignof__(struct ceph_inode_info),
771 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|
772 SLAB_ACCOUNT, ceph_inode_init_once);
773 if (!ceph_inode_cachep)
776 ceph_cap_cachep = KMEM_CACHE(ceph_cap, SLAB_MEM_SPREAD);
777 if (!ceph_cap_cachep)
779 ceph_cap_flush_cachep = KMEM_CACHE(ceph_cap_flush,
780 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
781 if (!ceph_cap_flush_cachep)
784 ceph_dentry_cachep = KMEM_CACHE(ceph_dentry_info,
785 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
786 if (!ceph_dentry_cachep)
789 ceph_file_cachep = KMEM_CACHE(ceph_file_info, SLAB_MEM_SPREAD);
790 if (!ceph_file_cachep)
793 ceph_dir_file_cachep = KMEM_CACHE(ceph_dir_file_info, SLAB_MEM_SPREAD);
794 if (!ceph_dir_file_cachep)
797 error = ceph_fscache_register();
804 kmem_cache_destroy(ceph_dir_file_cachep);
806 kmem_cache_destroy(ceph_file_cachep);
808 kmem_cache_destroy(ceph_dentry_cachep);
810 kmem_cache_destroy(ceph_cap_flush_cachep);
812 kmem_cache_destroy(ceph_cap_cachep);
814 kmem_cache_destroy(ceph_inode_cachep);
818 static void destroy_caches(void)
821 * Make sure all delayed rcu free inodes are flushed before we
826 kmem_cache_destroy(ceph_inode_cachep);
827 kmem_cache_destroy(ceph_cap_cachep);
828 kmem_cache_destroy(ceph_cap_flush_cachep);
829 kmem_cache_destroy(ceph_dentry_cachep);
830 kmem_cache_destroy(ceph_file_cachep);
831 kmem_cache_destroy(ceph_dir_file_cachep);
833 ceph_fscache_unregister();
838 * ceph_umount_begin - initiate forced umount. Tear down down the
839 * mount, skipping steps that may hang while waiting for server(s).
841 static void ceph_umount_begin(struct super_block *sb)
843 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
845 dout("ceph_umount_begin - starting forced umount\n");
848 fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
849 ceph_osdc_abort_requests(&fsc->client->osdc, -EIO);
850 ceph_mdsc_force_umount(fsc->mdsc);
851 fsc->filp_gen++; // invalidate open files
854 static int ceph_remount(struct super_block *sb, int *flags, char *data)
860 static const struct super_operations ceph_super_ops = {
861 .alloc_inode = ceph_alloc_inode,
862 .free_inode = ceph_free_inode,
863 .write_inode = ceph_write_inode,
864 .drop_inode = generic_delete_inode,
865 .evict_inode = ceph_evict_inode,
866 .sync_fs = ceph_sync_fs,
867 .put_super = ceph_put_super,
868 .remount_fs = ceph_remount,
869 .show_options = ceph_show_options,
870 .statfs = ceph_statfs,
871 .umount_begin = ceph_umount_begin,
875 * Bootstrap mount by opening the root directory. Note the mount
876 * @started time from caller, and time out if this takes too long.
878 static struct dentry *open_root_dentry(struct ceph_fs_client *fsc,
880 unsigned long started)
882 struct ceph_mds_client *mdsc = fsc->mdsc;
883 struct ceph_mds_request *req = NULL;
888 dout("open_root_inode opening '%s'\n", path);
889 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_GETATTR, USE_ANY_MDS);
891 return ERR_CAST(req);
892 req->r_path1 = kstrdup(path, GFP_NOFS);
894 root = ERR_PTR(-ENOMEM);
898 req->r_ino1.ino = CEPH_INO_ROOT;
899 req->r_ino1.snap = CEPH_NOSNAP;
900 req->r_started = started;
901 req->r_timeout = fsc->client->options->mount_timeout;
902 req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INODE);
904 err = ceph_mdsc_do_request(mdsc, NULL, req);
906 struct inode *inode = req->r_target_inode;
907 req->r_target_inode = NULL;
908 dout("open_root_inode success\n");
909 root = d_make_root(inode);
911 root = ERR_PTR(-ENOMEM);
914 dout("open_root_inode success, root dentry is %p\n", root);
919 ceph_mdsc_put_request(req);
927 * mount: join the ceph cluster, and open root directory.
929 static struct dentry *ceph_real_mount(struct ceph_fs_client *fsc)
932 unsigned long started = jiffies; /* note the start time */
935 dout("mount start %p\n", fsc);
936 mutex_lock(&fsc->client->mount_mutex);
938 if (!fsc->sb->s_root) {
940 err = __ceph_open_session(fsc->client, started);
945 if (fsc->mount_options->flags & CEPH_MOUNT_OPT_FSCACHE) {
946 err = ceph_fscache_register_fs(fsc);
951 if (!fsc->mount_options->server_path) {
953 dout("mount opening path \\t\n");
955 path = fsc->mount_options->server_path + 1;
956 dout("mount opening path %s\n", path);
959 ceph_fs_debugfs_init(fsc);
961 root = open_root_dentry(fsc, path, started);
966 fsc->sb->s_root = dget(root);
968 root = dget(fsc->sb->s_root);
971 fsc->mount_state = CEPH_MOUNT_MOUNTED;
972 dout("mount success\n");
973 mutex_unlock(&fsc->client->mount_mutex);
977 mutex_unlock(&fsc->client->mount_mutex);
981 static int ceph_set_super(struct super_block *s, void *data)
983 struct ceph_fs_client *fsc = data;
986 dout("set_super %p data %p\n", s, data);
988 s->s_flags = fsc->mount_options->sb_flags;
989 s->s_maxbytes = MAX_LFS_FILESIZE;
991 s->s_xattr = ceph_xattr_handlers;
994 fsc->max_file_size = 1ULL << 40; /* temp value until we get mdsmap */
996 s->s_op = &ceph_super_ops;
997 s->s_d_op = &ceph_dentry_ops;
998 s->s_export_op = &ceph_export_ops;
1002 s->s_time_max = U32_MAX;
1004 ret = set_anon_super(s, NULL); /* what is that second arg for? */
1011 s->s_fs_info = NULL;
1017 * share superblock if same fs AND options
1019 static int ceph_compare_super(struct super_block *sb, void *data)
1021 struct ceph_fs_client *new = data;
1022 struct ceph_mount_options *fsopt = new->mount_options;
1023 struct ceph_options *opt = new->client->options;
1024 struct ceph_fs_client *other = ceph_sb_to_client(sb);
1026 dout("ceph_compare_super %p\n", sb);
1028 if (compare_mount_options(fsopt, opt, other)) {
1029 dout("monitor(s)/mount options don't match\n");
1032 if ((opt->flags & CEPH_OPT_FSID) &&
1033 ceph_fsid_compare(&opt->fsid, &other->client->fsid)) {
1034 dout("fsid doesn't match\n");
1037 if (fsopt->sb_flags != other->mount_options->sb_flags) {
1038 dout("flags differ\n");
1045 * construct our own bdi so we can control readahead, etc.
1047 static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
1049 static int ceph_setup_bdi(struct super_block *sb, struct ceph_fs_client *fsc)
1053 err = super_setup_bdi_name(sb, "ceph-%ld",
1054 atomic_long_inc_return(&bdi_seq));
1058 /* set ra_pages based on rasize mount option? */
1059 sb->s_bdi->ra_pages = fsc->mount_options->rasize >> PAGE_SHIFT;
1061 /* set io_pages based on max osd read size */
1062 sb->s_bdi->io_pages = fsc->mount_options->rsize >> PAGE_SHIFT;
1067 static struct dentry *ceph_mount(struct file_system_type *fs_type,
1068 int flags, const char *dev_name, void *data)
1070 struct super_block *sb;
1071 struct ceph_fs_client *fsc;
1074 int (*compare_super)(struct super_block *, void *) = ceph_compare_super;
1075 struct ceph_mount_options *fsopt = NULL;
1076 struct ceph_options *opt = NULL;
1078 dout("ceph_mount\n");
1080 #ifdef CONFIG_CEPH_FS_POSIX_ACL
1081 flags |= SB_POSIXACL;
1083 err = parse_mount_options(&fsopt, &opt, flags, data, dev_name);
1089 /* create client (which we may/may not use) */
1090 fsc = create_fs_client(fsopt, opt);
1092 res = ERR_CAST(fsc);
1096 err = ceph_mdsc_init(fsc);
1102 if (ceph_test_opt(fsc->client, NOSHARE))
1103 compare_super = NULL;
1104 sb = sget(fs_type, compare_super, ceph_set_super, flags, fsc);
1110 if (ceph_sb_to_client(sb) != fsc) {
1111 destroy_fs_client(fsc);
1112 fsc = ceph_sb_to_client(sb);
1113 dout("get_sb got existing client %p\n", fsc);
1115 dout("get_sb using new client %p\n", fsc);
1116 err = ceph_setup_bdi(sb, fsc);
1123 res = ceph_real_mount(fsc);
1126 dout("root %p inode %p ino %llx.%llx\n", res,
1127 d_inode(res), ceph_vinop(d_inode(res)));
1131 ceph_mdsc_close_sessions(fsc->mdsc);
1132 deactivate_locked_super(sb);
1136 destroy_fs_client(fsc);
1138 dout("ceph_mount fail %ld\n", PTR_ERR(res));
1142 static void ceph_kill_sb(struct super_block *s)
1144 struct ceph_fs_client *fsc = ceph_sb_to_client(s);
1145 dev_t dev = s->s_dev;
1147 dout("kill_sb %p\n", s);
1149 ceph_mdsc_pre_umount(fsc->mdsc);
1150 flush_fs_workqueues(fsc);
1152 generic_shutdown_super(s);
1154 fsc->client->extra_mon_dispatch = NULL;
1155 ceph_fs_debugfs_cleanup(fsc);
1157 ceph_fscache_unregister_fs(fsc);
1159 destroy_fs_client(fsc);
1160 free_anon_bdev(dev);
1163 static struct file_system_type ceph_fs_type = {
1164 .owner = THIS_MODULE,
1166 .mount = ceph_mount,
1167 .kill_sb = ceph_kill_sb,
1168 .fs_flags = FS_RENAME_DOES_D_MOVE,
1170 MODULE_ALIAS_FS("ceph");
1172 int ceph_force_reconnect(struct super_block *sb)
1174 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
1177 ceph_umount_begin(sb);
1179 /* Make sure all page caches get invalidated.
1180 * see remove_session_caps_cb() */
1181 flush_workqueue(fsc->inode_wq);
1183 /* In case that we were blacklisted. This also reset
1184 * all mon/osd connections */
1185 ceph_reset_client_addr(fsc->client);
1187 ceph_osdc_clear_abort_err(&fsc->client->osdc);
1189 fsc->blacklisted = false;
1190 fsc->mount_state = CEPH_MOUNT_MOUNTED;
1193 err = __ceph_do_getattr(d_inode(sb->s_root), NULL,
1194 CEPH_STAT_CAP_INODE, true);
1199 static int __init init_ceph(void)
1201 int ret = init_caches();
1206 ret = register_filesystem(&ceph_fs_type);
1210 pr_info("loaded (mds proto %d)\n", CEPH_MDSC_PROTOCOL);
1220 static void __exit exit_ceph(void)
1222 dout("exit_ceph\n");
1223 unregister_filesystem(&ceph_fs_type);
1227 module_init(init_ceph);
1228 module_exit(exit_ceph);
1230 MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
1231 MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
1232 MODULE_AUTHOR("Patience Warnick <patience@newdream.net>");
1233 MODULE_DESCRIPTION("Ceph filesystem for Linux");
1234 MODULE_LICENSE("GPL");