xref: /openbmc/linux/fs/ceph/super.c (revision 55e43d6abd078ed6d219902ce8cb4d68e3c993ba)
109c434b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
216725b9dSSage Weil 
33d14c5d2SYehuda Sadeh #include <linux/ceph/ceph_debug.h>
416725b9dSSage Weil 
516725b9dSSage Weil #include <linux/backing-dev.h>
6c309f0abSSage Weil #include <linux/ctype.h>
716725b9dSSage Weil #include <linux/fs.h>
816725b9dSSage Weil #include <linux/inet.h>
916725b9dSSage Weil #include <linux/in6.h>
1016725b9dSSage Weil #include <linux/module.h>
1116725b9dSSage Weil #include <linux/mount.h>
1282995cc6SDavid Howells #include <linux/fs_context.h>
1382995cc6SDavid Howells #include <linux/fs_parser.h>
1416725b9dSSage Weil #include <linux/sched.h>
1516725b9dSSage Weil #include <linux/seq_file.h>
165a0e3ad6STejun Heo #include <linux/slab.h>
1716725b9dSSage Weil #include <linux/statfs.h>
1816725b9dSSage Weil #include <linux/string.h>
1916725b9dSSage Weil 
2016725b9dSSage Weil #include "super.h"
213d14c5d2SYehuda Sadeh #include "mds_client.h"
2299ccbd22SMilosz Tanski #include "cache.h"
232d332d5bSJeff Layton #include "crypto.h"
243d14c5d2SYehuda Sadeh 
251fe60e51SSage Weil #include <linux/ceph/ceph_features.h>
263d14c5d2SYehuda Sadeh #include <linux/ceph/decode.h>
273d14c5d2SYehuda Sadeh #include <linux/ceph/mon_client.h>
283d14c5d2SYehuda Sadeh #include <linux/ceph/auth.h>
293d14c5d2SYehuda Sadeh #include <linux/ceph/debugfs.h>
3016725b9dSSage Weil 
31a0b3a15eSJeff Layton #include <uapi/linux/magic.h>
32a0b3a15eSJeff Layton 
3318f473b3SXiubo Li static DEFINE_SPINLOCK(ceph_fsc_lock);
3418f473b3SXiubo Li static LIST_HEAD(ceph_fsc_list);
3518f473b3SXiubo Li 
3616725b9dSSage Weil /*
3716725b9dSSage Weil  * Ceph superblock operations
3816725b9dSSage Weil  *
3916725b9dSSage Weil  * Handle the basics of mounting, unmounting.
4016725b9dSSage Weil  */
4116725b9dSSage Weil 
4216725b9dSSage Weil /*
4316725b9dSSage Weil  * super ops
4416725b9dSSage Weil  */
ceph_put_super(struct super_block * s)4516725b9dSSage Weil static void ceph_put_super(struct super_block *s)
4616725b9dSSage Weil {
47985b9ee8SXiubo Li 	struct ceph_fs_client *fsc = ceph_sb_to_fs_client(s);
4816725b9dSSage Weil 
4916725b9dSSage Weil 	dout("put_super\n");
506b5717bdSJeff Layton 	ceph_fscrypt_free_dummy_policy(fsc);
513d14c5d2SYehuda Sadeh 	ceph_mdsc_close_sessions(fsc->mdsc);
5216725b9dSSage Weil }
5316725b9dSSage Weil 
ceph_statfs(struct dentry * dentry,struct kstatfs * buf)5416725b9dSSage Weil static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf)
5516725b9dSSage Weil {
56985b9ee8SXiubo Li 	struct ceph_fs_client *fsc = ceph_inode_to_fs_client(d_inode(dentry));
5773fb0949SLuis Henriques 	struct ceph_mon_client *monc = &fsc->client->monc;
5816725b9dSSage Weil 	struct ceph_statfs st;
598cfc0c7eSJeff Layton 	int i, err;
6006d74376SDouglas Fuller 	u64 data_pool;
6106d74376SDouglas Fuller 
6206d74376SDouglas Fuller 	if (fsc->mdsc->mdsmap->m_num_data_pg_pools == 1) {
6306d74376SDouglas Fuller 		data_pool = fsc->mdsc->mdsmap->m_data_pg_pools[0];
6406d74376SDouglas Fuller 	} else {
6506d74376SDouglas Fuller 		data_pool = CEPH_NOPOOL;
6606d74376SDouglas Fuller 	}
6716725b9dSSage Weil 
6816725b9dSSage Weil 	dout("statfs\n");
6973fb0949SLuis Henriques 	err = ceph_monc_do_statfs(monc, data_pool, &st);
7016725b9dSSage Weil 	if (err < 0)
7116725b9dSSage Weil 		return err;
7216725b9dSSage Weil 
7316725b9dSSage Weil 	/* fill in kstatfs */
7416725b9dSSage Weil 	buf->f_type = CEPH_SUPER_MAGIC;  /* ?? */
7516725b9dSSage Weil 
7616725b9dSSage Weil 	/*
770c04a117SXiubo Li 	 * Express utilization in terms of large blocks to avoid
7816725b9dSSage Weil 	 * overflow on 32-bit machines.
7916725b9dSSage Weil 	 */
8092a49fb0SSage Weil 	buf->f_frsize = 1 << CEPH_BLOCK_SHIFT;
819122eed5SLuis Henriques 
829122eed5SLuis Henriques 	/*
839122eed5SLuis Henriques 	 * By default use root quota for stats; fallback to overall filesystem
849122eed5SLuis Henriques 	 * usage if using 'noquotadf' mount option or if the root dir doesn't
859122eed5SLuis Henriques 	 * have max_bytes quota set.
869122eed5SLuis Henriques 	 */
879122eed5SLuis Henriques 	if (ceph_test_mount_opt(fsc, NOQUOTADF) ||
889122eed5SLuis Henriques 	    !ceph_quota_update_statfs(fsc, buf)) {
8916725b9dSSage Weil 		buf->f_blocks = le64_to_cpu(st.kb) >> (CEPH_BLOCK_SHIFT-10);
908f04d422SGreg Farnum 		buf->f_bfree = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);
9116725b9dSSage Weil 		buf->f_bavail = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);
929122eed5SLuis Henriques 	}
9316725b9dSSage Weil 
940c04a117SXiubo Li 	/*
950c04a117SXiubo Li 	 * NOTE: for the time being, we make bsize == frsize to humor
960c04a117SXiubo Li 	 * not-yet-ancient versions of glibc that are broken.
970c04a117SXiubo Li 	 * Someday, we will probably want to report a real block
980c04a117SXiubo Li 	 * size...  whatever that may mean for a network file system!
990c04a117SXiubo Li 	 */
1000c04a117SXiubo Li 	buf->f_bsize = buf->f_frsize;
1010c04a117SXiubo Li 
10216725b9dSSage Weil 	buf->f_files = le64_to_cpu(st.num_objects);
10316725b9dSSage Weil 	buf->f_ffree = -1;
104558d3499SSage Weil 	buf->f_namelen = NAME_MAX;
10516725b9dSSage Weil 
106080a330eSJeff Layton 	/* Must convert the fsid, for consistent values across arches */
1078cfc0c7eSJeff Layton 	buf->f_fsid.val[0] = 0;
10873fb0949SLuis Henriques 	mutex_lock(&monc->mutex);
1098cfc0c7eSJeff Layton 	for (i = 0 ; i < sizeof(monc->monmap->fsid) / sizeof(__le32) ; ++i)
1108cfc0c7eSJeff Layton 		buf->f_fsid.val[0] ^= le32_to_cpu(((__le32 *)&monc->monmap->fsid)[i]);
11173fb0949SLuis Henriques 	mutex_unlock(&monc->mutex);
11273fb0949SLuis Henriques 
1138cfc0c7eSJeff Layton 	/* fold the fs_cluster_id into the upper bits */
1148cfc0c7eSJeff Layton 	buf->f_fsid.val[1] = monc->fs_cluster_id;
11516725b9dSSage Weil 
11616725b9dSSage Weil 	return 0;
11716725b9dSSage Weil }
11816725b9dSSage Weil 
ceph_sync_fs(struct super_block * sb,int wait)1192d9c98aeSSage Weil static int ceph_sync_fs(struct super_block *sb, int wait)
12016725b9dSSage Weil {
121985b9ee8SXiubo Li 	struct ceph_fs_client *fsc = ceph_sb_to_fs_client(sb);
1222d9c98aeSSage Weil 
1232d9c98aeSSage Weil 	if (!wait) {
1242d9c98aeSSage Weil 		dout("sync_fs (non-blocking)\n");
1253d14c5d2SYehuda Sadeh 		ceph_flush_dirty_caps(fsc->mdsc);
1262d9c98aeSSage Weil 		dout("sync_fs (non-blocking) done\n");
1272d9c98aeSSage Weil 		return 0;
1282d9c98aeSSage Weil 	}
1292d9c98aeSSage Weil 
1302d9c98aeSSage Weil 	dout("sync_fs (blocking)\n");
1313d14c5d2SYehuda Sadeh 	ceph_osdc_sync(&fsc->client->osdc);
1323d14c5d2SYehuda Sadeh 	ceph_mdsc_sync(fsc->mdsc);
1332d9c98aeSSage Weil 	dout("sync_fs (blocking) done\n");
13416725b9dSSage Weil 	return 0;
13516725b9dSSage Weil }
13616725b9dSSage Weil 
1372baba250SYehuda Sadeh /*
1383d14c5d2SYehuda Sadeh  * mount options
1392baba250SYehuda Sadeh  */
1403d14c5d2SYehuda Sadeh enum {
1413d14c5d2SYehuda Sadeh 	Opt_wsize,
1423d14c5d2SYehuda Sadeh 	Opt_rsize,
14383817e35SSage Weil 	Opt_rasize,
1443d14c5d2SYehuda Sadeh 	Opt_caps_wanted_delay_min,
1453d14c5d2SYehuda Sadeh 	Opt_caps_wanted_delay_max,
146fe33032dSYan, Zheng 	Opt_caps_max,
1473d14c5d2SYehuda Sadeh 	Opt_readdir_max_entries,
1483d14c5d2SYehuda Sadeh 	Opt_readdir_max_bytes,
1493d14c5d2SYehuda Sadeh 	Opt_congestion_kb,
1503d14c5d2SYehuda Sadeh 	/* int args above */
1513d14c5d2SYehuda Sadeh 	Opt_snapdirname,
152430afbadSYan, Zheng 	Opt_mds_namespace,
153131d7eb4SYan, Zheng 	Opt_recover_session,
15482995cc6SDavid Howells 	Opt_source,
1557b19b4dbSVenky Shankar 	Opt_mon_addr,
1566b5717bdSJeff Layton 	Opt_test_dummy_encryption,
1573d14c5d2SYehuda Sadeh 	/* string args above */
1583d14c5d2SYehuda Sadeh 	Opt_dirstat,
1593d14c5d2SYehuda Sadeh 	Opt_rbytes,
160cffaba15SAlex Elder 	Opt_asyncreaddir,
161a40dc6ccSSage Weil 	Opt_dcache,
162ad1fee96SYehuda Sadeh 	Opt_ino32,
16399ccbd22SMilosz Tanski 	Opt_fscache,
16410183a69SYan, Zheng 	Opt_poolperm,
165e9e427f0SYan, Zheng 	Opt_require_active_mds,
16645195e42SSage Weil 	Opt_acl,
1679122eed5SLuis Henriques 	Opt_quotadf,
168ea4cdc54SLuis Henriques 	Opt_copyfrom,
1692ccb4546SJeff Layton 	Opt_wsync,
17094cc0877SJeff Layton 	Opt_pagecache,
17103bc06c7SJeff Layton 	Opt_sparseread,
1723d14c5d2SYehuda Sadeh };
1732baba250SYehuda Sadeh 
17482995cc6SDavid Howells enum ceph_recover_session_mode {
17582995cc6SDavid Howells 	ceph_recover_session_no,
17682995cc6SDavid Howells 	ceph_recover_session_clean
1773d14c5d2SYehuda Sadeh };
1783d14c5d2SYehuda Sadeh 
1795eede625SAl Viro static const struct constant_table ceph_param_recover[] = {
1802710c957SAl Viro 	{ "no",		ceph_recover_session_no },
1812710c957SAl Viro 	{ "clean",	ceph_recover_session_clean },
18282995cc6SDavid Howells 	{}
18382995cc6SDavid Howells };
18482995cc6SDavid Howells 
185d7167b14SAl Viro static const struct fs_parameter_spec ceph_mount_parameters[] = {
18682995cc6SDavid Howells 	fsparam_flag_no ("acl",				Opt_acl),
18782995cc6SDavid Howells 	fsparam_flag_no ("asyncreaddir",		Opt_asyncreaddir),
188ad8c28a9SJeff Layton 	fsparam_s32	("caps_max",			Opt_caps_max),
18982995cc6SDavid Howells 	fsparam_u32	("caps_wanted_delay_max",	Opt_caps_wanted_delay_max),
19082995cc6SDavid Howells 	fsparam_u32	("caps_wanted_delay_min",	Opt_caps_wanted_delay_min),
191ad8c28a9SJeff Layton 	fsparam_u32	("write_congestion_kb",		Opt_congestion_kb),
19282995cc6SDavid Howells 	fsparam_flag_no ("copyfrom",			Opt_copyfrom),
19382995cc6SDavid Howells 	fsparam_flag_no ("dcache",			Opt_dcache),
19482995cc6SDavid Howells 	fsparam_flag_no ("dirstat",			Opt_dirstat),
19548ce73b1SAl Viro 	fsparam_flag_no	("fsc",				Opt_fscache), // fsc|nofsc
19648ce73b1SAl Viro 	fsparam_string	("fsc",				Opt_fscache), // fsc=...
19782995cc6SDavid Howells 	fsparam_flag_no ("ino32",			Opt_ino32),
19882995cc6SDavid Howells 	fsparam_string	("mds_namespace",		Opt_mds_namespace),
1996b5717bdSJeff Layton 	fsparam_string	("mon_addr",			Opt_mon_addr),
20082995cc6SDavid Howells 	fsparam_flag_no ("poolperm",			Opt_poolperm),
20182995cc6SDavid Howells 	fsparam_flag_no ("quotadf",			Opt_quotadf),
20282995cc6SDavid Howells 	fsparam_u32	("rasize",			Opt_rasize),
20382995cc6SDavid Howells 	fsparam_flag_no ("rbytes",			Opt_rbytes),
204ad8c28a9SJeff Layton 	fsparam_u32	("readdir_max_bytes",		Opt_readdir_max_bytes),
205ad8c28a9SJeff Layton 	fsparam_u32	("readdir_max_entries",		Opt_readdir_max_entries),
2062710c957SAl Viro 	fsparam_enum	("recover_session",		Opt_recover_session, ceph_param_recover),
20782995cc6SDavid Howells 	fsparam_flag_no ("require_active_mds",		Opt_require_active_mds),
20882995cc6SDavid Howells 	fsparam_u32	("rsize",			Opt_rsize),
20982995cc6SDavid Howells 	fsparam_string	("snapdirname",			Opt_snapdirname),
21082995cc6SDavid Howells 	fsparam_string	("source",			Opt_source),
2116b5717bdSJeff Layton 	fsparam_flag	("test_dummy_encryption",	Opt_test_dummy_encryption),
2126b5717bdSJeff Layton 	fsparam_string	("test_dummy_encryption",	Opt_test_dummy_encryption),
21382995cc6SDavid Howells 	fsparam_u32	("wsize",			Opt_wsize),
2142ccb4546SJeff Layton 	fsparam_flag_no	("wsync",			Opt_wsync),
21594cc0877SJeff Layton 	fsparam_flag_no	("pagecache",			Opt_pagecache),
21603bc06c7SJeff Layton 	fsparam_flag_no	("sparseread",			Opt_sparseread),
21782995cc6SDavid Howells 	{}
21882995cc6SDavid Howells };
21982995cc6SDavid Howells 
22082995cc6SDavid Howells struct ceph_parse_opts_ctx {
22182995cc6SDavid Howells 	struct ceph_options		*copts;
22282995cc6SDavid Howells 	struct ceph_mount_options	*opts;
22382995cc6SDavid Howells };
22482995cc6SDavid Howells 
22582995cc6SDavid Howells /*
226b27a939eSIlya Dryomov  * Remove adjacent slashes and then the trailing slash, unless it is
227b27a939eSIlya Dryomov  * the only remaining character.
228b27a939eSIlya Dryomov  *
229b27a939eSIlya Dryomov  * E.g. "//dir1////dir2///" --> "/dir1/dir2", "///" --> "/".
230b27a939eSIlya Dryomov  */
canonicalize_path(char * path)231b27a939eSIlya Dryomov static void canonicalize_path(char *path)
232b27a939eSIlya Dryomov {
233b27a939eSIlya Dryomov 	int i, j = 0;
234b27a939eSIlya Dryomov 
235b27a939eSIlya Dryomov 	for (i = 0; path[i] != '\0'; i++) {
236b27a939eSIlya Dryomov 		if (path[i] != '/' || j < 1 || path[j - 1] != '/')
237b27a939eSIlya Dryomov 			path[j++] = path[i];
238b27a939eSIlya Dryomov 	}
239b27a939eSIlya Dryomov 
240b27a939eSIlya Dryomov 	if (j > 1 && path[j - 1] == '/')
241b27a939eSIlya Dryomov 		j--;
242b27a939eSIlya Dryomov 	path[j] = '\0';
243b27a939eSIlya Dryomov }
244b27a939eSIlya Dryomov 
245b27a939eSIlya Dryomov /*
2467b19b4dbSVenky Shankar  * Check if the mds namespace in ceph_mount_options matches
2477b19b4dbSVenky Shankar  * the passed in namespace string. First time match (when
2487b19b4dbSVenky Shankar  * ->mds_namespace is NULL) is treated specially, since
2497b19b4dbSVenky Shankar  * ->mds_namespace needs to be initialized by the caller.
2507b19b4dbSVenky Shankar  */
namespace_equals(struct ceph_mount_options * fsopt,const char * namespace,size_t len)2517b19b4dbSVenky Shankar static int namespace_equals(struct ceph_mount_options *fsopt,
2527b19b4dbSVenky Shankar 			    const char *namespace, size_t len)
2537b19b4dbSVenky Shankar {
2547b19b4dbSVenky Shankar 	return !(fsopt->mds_namespace &&
2557b19b4dbSVenky Shankar 		 (strlen(fsopt->mds_namespace) != len ||
2567b19b4dbSVenky Shankar 		  strncmp(fsopt->mds_namespace, namespace, len)));
2577b19b4dbSVenky Shankar }
2587b19b4dbSVenky Shankar 
ceph_parse_old_source(const char * dev_name,const char * dev_name_end,struct fs_context * fc)2597b19b4dbSVenky Shankar static int ceph_parse_old_source(const char *dev_name, const char *dev_name_end,
2607b19b4dbSVenky Shankar 				 struct fs_context *fc)
2617b19b4dbSVenky Shankar {
2627b19b4dbSVenky Shankar 	int r;
2637b19b4dbSVenky Shankar 	struct ceph_parse_opts_ctx *pctx = fc->fs_private;
2647b19b4dbSVenky Shankar 	struct ceph_mount_options *fsopt = pctx->opts;
2657b19b4dbSVenky Shankar 
2667b19b4dbSVenky Shankar 	if (*dev_name_end != ':')
2677b19b4dbSVenky Shankar 		return invalfc(fc, "separator ':' missing in source");
2687b19b4dbSVenky Shankar 
2697b19b4dbSVenky Shankar 	r = ceph_parse_mon_ips(dev_name, dev_name_end - dev_name,
2707b19b4dbSVenky Shankar 			       pctx->copts, fc->log.log, ',');
2717b19b4dbSVenky Shankar 	if (r)
2727b19b4dbSVenky Shankar 		return r;
2737b19b4dbSVenky Shankar 
2747b19b4dbSVenky Shankar 	fsopt->new_dev_syntax = false;
2757b19b4dbSVenky Shankar 	return 0;
2767b19b4dbSVenky Shankar }
2777b19b4dbSVenky Shankar 
ceph_parse_new_source(const char * dev_name,const char * dev_name_end,struct fs_context * fc)2787b19b4dbSVenky Shankar static int ceph_parse_new_source(const char *dev_name, const char *dev_name_end,
2797b19b4dbSVenky Shankar 				 struct fs_context *fc)
2807b19b4dbSVenky Shankar {
2817b19b4dbSVenky Shankar 	size_t len;
2827b19b4dbSVenky Shankar 	struct ceph_fsid fsid;
2837b19b4dbSVenky Shankar 	struct ceph_parse_opts_ctx *pctx = fc->fs_private;
284308e0cc3SPatrick Donnelly 	struct ceph_options *opts = pctx->copts;
2857b19b4dbSVenky Shankar 	struct ceph_mount_options *fsopt = pctx->opts;
286308e0cc3SPatrick Donnelly 	const char *name_start = dev_name;
2877b19b4dbSVenky Shankar 	char *fsid_start, *fs_name_start;
2887b19b4dbSVenky Shankar 
2897b19b4dbSVenky Shankar 	if (*dev_name_end != '=') {
2907b19b4dbSVenky Shankar 		dout("separator '=' missing in source");
2917b19b4dbSVenky Shankar 		return -EINVAL;
2927b19b4dbSVenky Shankar 	}
2937b19b4dbSVenky Shankar 
2947b19b4dbSVenky Shankar 	fsid_start = strchr(dev_name, '@');
2957b19b4dbSVenky Shankar 	if (!fsid_start)
2967b19b4dbSVenky Shankar 		return invalfc(fc, "missing cluster fsid");
297308e0cc3SPatrick Donnelly 	len = fsid_start - name_start;
298308e0cc3SPatrick Donnelly 	kfree(opts->name);
299308e0cc3SPatrick Donnelly 	opts->name = kstrndup(name_start, len, GFP_KERNEL);
300308e0cc3SPatrick Donnelly 	if (!opts->name)
301308e0cc3SPatrick Donnelly 		return -ENOMEM;
302308e0cc3SPatrick Donnelly 	dout("using %s entity name", opts->name);
3037b19b4dbSVenky Shankar 
304308e0cc3SPatrick Donnelly 	++fsid_start; /* start of cluster fsid */
3057b19b4dbSVenky Shankar 	fs_name_start = strchr(fsid_start, '.');
3067b19b4dbSVenky Shankar 	if (!fs_name_start)
3077b19b4dbSVenky Shankar 		return invalfc(fc, "missing file system name");
3087b19b4dbSVenky Shankar 
3097b19b4dbSVenky Shankar 	if (ceph_parse_fsid(fsid_start, &fsid))
3107b19b4dbSVenky Shankar 		return invalfc(fc, "Invalid FSID");
3117b19b4dbSVenky Shankar 
3127b19b4dbSVenky Shankar 	++fs_name_start; /* start of file system name */
3137b19b4dbSVenky Shankar 	len = dev_name_end - fs_name_start;
3147b19b4dbSVenky Shankar 
3157b19b4dbSVenky Shankar 	if (!namespace_equals(fsopt, fs_name_start, len))
3167b19b4dbSVenky Shankar 		return invalfc(fc, "Mismatching mds_namespace");
3177b19b4dbSVenky Shankar 	kfree(fsopt->mds_namespace);
3187b19b4dbSVenky Shankar 	fsopt->mds_namespace = kstrndup(fs_name_start, len, GFP_KERNEL);
3197b19b4dbSVenky Shankar 	if (!fsopt->mds_namespace)
3207b19b4dbSVenky Shankar 		return -ENOMEM;
3217b19b4dbSVenky Shankar 	dout("file system (mds namespace) '%s'\n", fsopt->mds_namespace);
3227b19b4dbSVenky Shankar 
3237b19b4dbSVenky Shankar 	fsopt->new_dev_syntax = true;
3247b19b4dbSVenky Shankar 	return 0;
3257b19b4dbSVenky Shankar }
3267b19b4dbSVenky Shankar 
3277b19b4dbSVenky Shankar /*
3287b19b4dbSVenky Shankar  * Parse the source parameter for new device format. Distinguish the device
3297b19b4dbSVenky Shankar  * spec from the path. Try parsing new device format and fallback to old
3307b19b4dbSVenky Shankar  * format if needed.
33182995cc6SDavid Howells  *
3327b19b4dbSVenky Shankar  * New device syntax will looks like:
3337b19b4dbSVenky Shankar  *     <device_spec>=/<path>
3347b19b4dbSVenky Shankar  * where
3357b19b4dbSVenky Shankar  *     <device_spec> is name@fsid.fsname
3367b19b4dbSVenky Shankar  *     <path> is optional, but if present must begin with '/'
3377b19b4dbSVenky Shankar  * (monitor addresses are passed via mount option)
3387b19b4dbSVenky Shankar  *
3397b19b4dbSVenky Shankar  * Old device syntax is:
34082995cc6SDavid Howells  *     <server_spec>[,<server_spec>...]:[<path>]
34182995cc6SDavid Howells  * where
34282995cc6SDavid Howells  *     <server_spec> is <ip>[:<port>]
34382995cc6SDavid Howells  *     <path> is optional, but if present must begin with '/'
34482995cc6SDavid Howells  */
ceph_parse_source(struct fs_parameter * param,struct fs_context * fc)34582995cc6SDavid Howells static int ceph_parse_source(struct fs_parameter *param, struct fs_context *fc)
3463d14c5d2SYehuda Sadeh {
34782995cc6SDavid Howells 	struct ceph_parse_opts_ctx *pctx = fc->fs_private;
34882995cc6SDavid Howells 	struct ceph_mount_options *fsopt = pctx->opts;
34982995cc6SDavid Howells 	char *dev_name = param->string, *dev_name_end;
35082995cc6SDavid Howells 	int ret;
3513d14c5d2SYehuda Sadeh 
35282995cc6SDavid Howells 	dout("%s '%s'\n", __func__, dev_name);
35382995cc6SDavid Howells 	if (!dev_name || !*dev_name)
354d53d0f74SAl Viro 		return invalfc(fc, "Empty source");
3553d14c5d2SYehuda Sadeh 
35682995cc6SDavid Howells 	dev_name_end = strchr(dev_name, '/');
35782995cc6SDavid Howells 	if (dev_name_end) {
3584fbc0c71SXiubo Li 		/*
3594fbc0c71SXiubo Li 		 * The server_path will include the whole chars from userland
3604fbc0c71SXiubo Li 		 * including the leading '/'.
3614fbc0c71SXiubo Li 		 */
362b27a939eSIlya Dryomov 		kfree(fsopt->server_path);
36382995cc6SDavid Howells 		fsopt->server_path = kstrdup(dev_name_end, GFP_KERNEL);
36482995cc6SDavid Howells 		if (!fsopt->server_path)
36582995cc6SDavid Howells 			return -ENOMEM;
366b27a939eSIlya Dryomov 
367b27a939eSIlya Dryomov 		canonicalize_path(fsopt->server_path);
3683d14c5d2SYehuda Sadeh 	} else {
36982995cc6SDavid Howells 		dev_name_end = dev_name + strlen(dev_name);
3703d14c5d2SYehuda Sadeh 	}
3713d14c5d2SYehuda Sadeh 
3727b19b4dbSVenky Shankar 	dev_name_end--;		/* back up to separator */
3737b19b4dbSVenky Shankar 	if (dev_name_end < dev_name)
3747b19b4dbSVenky Shankar 		return invalfc(fc, "Path missing in source");
37582995cc6SDavid Howells 
37682995cc6SDavid Howells 	dout("device name '%.*s'\n", (int)(dev_name_end - dev_name), dev_name);
37782995cc6SDavid Howells 	if (fsopt->server_path)
37882995cc6SDavid Howells 		dout("server path '%s'\n", fsopt->server_path);
37982995cc6SDavid Howells 
3807b19b4dbSVenky Shankar 	dout("trying new device syntax");
3817b19b4dbSVenky Shankar 	ret = ceph_parse_new_source(dev_name, dev_name_end, fc);
3827b19b4dbSVenky Shankar 	if (ret) {
3837b19b4dbSVenky Shankar 		if (ret != -EINVAL)
3847b19b4dbSVenky Shankar 			return ret;
3857b19b4dbSVenky Shankar 		dout("trying old device syntax");
3867b19b4dbSVenky Shankar 		ret = ceph_parse_old_source(dev_name, dev_name_end, fc);
38782995cc6SDavid Howells 		if (ret)
38882995cc6SDavid Howells 			return ret;
3897b19b4dbSVenky Shankar 	}
39082995cc6SDavid Howells 
39182995cc6SDavid Howells 	fc->source = param->string;
39282995cc6SDavid Howells 	param->string = NULL;
39382995cc6SDavid Howells 	return 0;
39482995cc6SDavid Howells }
39582995cc6SDavid Howells 
ceph_parse_mon_addr(struct fs_parameter * param,struct fs_context * fc)3967b19b4dbSVenky Shankar static int ceph_parse_mon_addr(struct fs_parameter *param,
3977b19b4dbSVenky Shankar 			       struct fs_context *fc)
3987b19b4dbSVenky Shankar {
3997b19b4dbSVenky Shankar 	struct ceph_parse_opts_ctx *pctx = fc->fs_private;
4007b19b4dbSVenky Shankar 	struct ceph_mount_options *fsopt = pctx->opts;
4017b19b4dbSVenky Shankar 
4027b19b4dbSVenky Shankar 	kfree(fsopt->mon_addr);
4037b19b4dbSVenky Shankar 	fsopt->mon_addr = param->string;
4047b19b4dbSVenky Shankar 	param->string = NULL;
4057b19b4dbSVenky Shankar 
4067b19b4dbSVenky Shankar 	return ceph_parse_mon_ips(fsopt->mon_addr, strlen(fsopt->mon_addr),
4077b19b4dbSVenky Shankar 				  pctx->copts, fc->log.log, '/');
4087b19b4dbSVenky Shankar }
4097b19b4dbSVenky Shankar 
ceph_parse_mount_param(struct fs_context * fc,struct fs_parameter * param)41082995cc6SDavid Howells static int ceph_parse_mount_param(struct fs_context *fc,
41182995cc6SDavid Howells 				  struct fs_parameter *param)
41282995cc6SDavid Howells {
41382995cc6SDavid Howells 	struct ceph_parse_opts_ctx *pctx = fc->fs_private;
41482995cc6SDavid Howells 	struct ceph_mount_options *fsopt = pctx->opts;
41582995cc6SDavid Howells 	struct fs_parse_result result;
41682995cc6SDavid Howells 	unsigned int mode;
41782995cc6SDavid Howells 	int token, ret;
41882995cc6SDavid Howells 
419cc3c0b53SAl Viro 	ret = ceph_parse_param(param, pctx->copts, fc->log.log);
42082995cc6SDavid Howells 	if (ret != -ENOPARAM)
42182995cc6SDavid Howells 		return ret;
42282995cc6SDavid Howells 
423d7167b14SAl Viro 	token = fs_parse(fc, ceph_mount_parameters, param, &result);
42482995cc6SDavid Howells 	dout("%s fs_parse '%s' token %d\n", __func__, param->key, token);
42582995cc6SDavid Howells 	if (token < 0)
42682995cc6SDavid Howells 		return token;
42782995cc6SDavid Howells 
4283d14c5d2SYehuda Sadeh 	switch (token) {
4293d14c5d2SYehuda Sadeh 	case Opt_snapdirname:
430*f006f6eaSIlya Dryomov 		if (strlen(param->string) > NAME_MAX)
431*f006f6eaSIlya Dryomov 			return invalfc(fc, "snapdirname too long");
4323d14c5d2SYehuda Sadeh 		kfree(fsopt->snapdir_name);
43382995cc6SDavid Howells 		fsopt->snapdir_name = param->string;
43482995cc6SDavid Howells 		param->string = NULL;
4353d14c5d2SYehuda Sadeh 		break;
436235a0982SYan, Zheng 	case Opt_mds_namespace:
4377b19b4dbSVenky Shankar 		if (!namespace_equals(fsopt, param->string, strlen(param->string)))
4387b19b4dbSVenky Shankar 			return invalfc(fc, "Mismatching mds_namespace");
439937441f3SChengguang Xu 		kfree(fsopt->mds_namespace);
44082995cc6SDavid Howells 		fsopt->mds_namespace = param->string;
44182995cc6SDavid Howells 		param->string = NULL;
442235a0982SYan, Zheng 		break;
443131d7eb4SYan, Zheng 	case Opt_recover_session:
44482995cc6SDavid Howells 		mode = result.uint_32;
44582995cc6SDavid Howells 		if (mode == ceph_recover_session_no)
446131d7eb4SYan, Zheng 			fsopt->flags &= ~CEPH_MOUNT_OPT_CLEANRECOVER;
44782995cc6SDavid Howells 		else if (mode == ceph_recover_session_clean)
448131d7eb4SYan, Zheng 			fsopt->flags |= CEPH_MOUNT_OPT_CLEANRECOVER;
44982995cc6SDavid Howells 		else
45082995cc6SDavid Howells 			BUG();
451131d7eb4SYan, Zheng 		break;
45282995cc6SDavid Howells 	case Opt_source:
45382995cc6SDavid Howells 		if (fc->source)
454d53d0f74SAl Viro 			return invalfc(fc, "Multiple sources specified");
45582995cc6SDavid Howells 		return ceph_parse_source(param, fc);
4567b19b4dbSVenky Shankar 	case Opt_mon_addr:
4577b19b4dbSVenky Shankar 		return ceph_parse_mon_addr(param, fc);
4583d14c5d2SYehuda Sadeh 	case Opt_wsize:
45982995cc6SDavid Howells 		if (result.uint_32 < PAGE_SIZE ||
46082995cc6SDavid Howells 		    result.uint_32 > CEPH_MAX_WRITE_SIZE)
46182995cc6SDavid Howells 			goto out_of_range;
46282995cc6SDavid Howells 		fsopt->wsize = ALIGN(result.uint_32, PAGE_SIZE);
4633d14c5d2SYehuda Sadeh 		break;
4643d14c5d2SYehuda Sadeh 	case Opt_rsize:
46582995cc6SDavid Howells 		if (result.uint_32 < PAGE_SIZE ||
46682995cc6SDavid Howells 		    result.uint_32 > CEPH_MAX_READ_SIZE)
46782995cc6SDavid Howells 			goto out_of_range;
46882995cc6SDavid Howells 		fsopt->rsize = ALIGN(result.uint_32, PAGE_SIZE);
4693d14c5d2SYehuda Sadeh 		break;
47083817e35SSage Weil 	case Opt_rasize:
47182995cc6SDavid Howells 		fsopt->rasize = ALIGN(result.uint_32, PAGE_SIZE);
47283817e35SSage Weil 		break;
4733d14c5d2SYehuda Sadeh 	case Opt_caps_wanted_delay_min:
47482995cc6SDavid Howells 		if (result.uint_32 < 1)
47582995cc6SDavid Howells 			goto out_of_range;
47682995cc6SDavid Howells 		fsopt->caps_wanted_delay_min = result.uint_32;
4773d14c5d2SYehuda Sadeh 		break;
4783d14c5d2SYehuda Sadeh 	case Opt_caps_wanted_delay_max:
47982995cc6SDavid Howells 		if (result.uint_32 < 1)
48082995cc6SDavid Howells 			goto out_of_range;
48182995cc6SDavid Howells 		fsopt->caps_wanted_delay_max = result.uint_32;
4823d14c5d2SYehuda Sadeh 		break;
483fe33032dSYan, Zheng 	case Opt_caps_max:
484ad8c28a9SJeff Layton 		if (result.int_32 < 0)
485ad8c28a9SJeff Layton 			goto out_of_range;
486ad8c28a9SJeff Layton 		fsopt->caps_max = result.int_32;
487fe33032dSYan, Zheng 		break;
4883d14c5d2SYehuda Sadeh 	case Opt_readdir_max_entries:
48982995cc6SDavid Howells 		if (result.uint_32 < 1)
49082995cc6SDavid Howells 			goto out_of_range;
49182995cc6SDavid Howells 		fsopt->max_readdir = result.uint_32;
4923d14c5d2SYehuda Sadeh 		break;
4933d14c5d2SYehuda Sadeh 	case Opt_readdir_max_bytes:
49482995cc6SDavid Howells 		if (result.uint_32 < PAGE_SIZE && result.uint_32 != 0)
49582995cc6SDavid Howells 			goto out_of_range;
49682995cc6SDavid Howells 		fsopt->max_readdir_bytes = result.uint_32;
4973d14c5d2SYehuda Sadeh 		break;
4983d14c5d2SYehuda Sadeh 	case Opt_congestion_kb:
49982995cc6SDavid Howells 		if (result.uint_32 < 1024) /* at least 1M */
50082995cc6SDavid Howells 			goto out_of_range;
50182995cc6SDavid Howells 		fsopt->congestion_kb = result.uint_32;
5023d14c5d2SYehuda Sadeh 		break;
5033d14c5d2SYehuda Sadeh 	case Opt_dirstat:
50482995cc6SDavid Howells 		if (!result.negated)
5053d14c5d2SYehuda Sadeh 			fsopt->flags |= CEPH_MOUNT_OPT_DIRSTAT;
50682995cc6SDavid Howells 		else
5073d14c5d2SYehuda Sadeh 			fsopt->flags &= ~CEPH_MOUNT_OPT_DIRSTAT;
5083d14c5d2SYehuda Sadeh 		break;
5093d14c5d2SYehuda Sadeh 	case Opt_rbytes:
51082995cc6SDavid Howells 		if (!result.negated)
5113d14c5d2SYehuda Sadeh 			fsopt->flags |= CEPH_MOUNT_OPT_RBYTES;
51282995cc6SDavid Howells 		else
5133d14c5d2SYehuda Sadeh 			fsopt->flags &= ~CEPH_MOUNT_OPT_RBYTES;
5143d14c5d2SYehuda Sadeh 		break;
515cffaba15SAlex Elder 	case Opt_asyncreaddir:
51682995cc6SDavid Howells 		if (!result.negated)
517cffaba15SAlex Elder 			fsopt->flags &= ~CEPH_MOUNT_OPT_NOASYNCREADDIR;
51882995cc6SDavid Howells 		else
5193d14c5d2SYehuda Sadeh 			fsopt->flags |= CEPH_MOUNT_OPT_NOASYNCREADDIR;
5203d14c5d2SYehuda Sadeh 		break;
521a40dc6ccSSage Weil 	case Opt_dcache:
52282995cc6SDavid Howells 		if (!result.negated)
523a40dc6ccSSage Weil 			fsopt->flags |= CEPH_MOUNT_OPT_DCACHE;
52482995cc6SDavid Howells 		else
525a40dc6ccSSage Weil 			fsopt->flags &= ~CEPH_MOUNT_OPT_DCACHE;
526a40dc6ccSSage Weil 		break;
527ad1fee96SYehuda Sadeh 	case Opt_ino32:
52882995cc6SDavid Howells 		if (!result.negated)
529ad1fee96SYehuda Sadeh 			fsopt->flags |= CEPH_MOUNT_OPT_INO32;
53082995cc6SDavid Howells 		else
531cffaba15SAlex Elder 			fsopt->flags &= ~CEPH_MOUNT_OPT_INO32;
532cffaba15SAlex Elder 		break;
53382995cc6SDavid Howells 
53499ccbd22SMilosz Tanski 	case Opt_fscache:
535ff29fde8SJeff Layton #ifdef CONFIG_CEPH_FSCACHE
5367ae7a828SChengguang Xu 		kfree(fsopt->fscache_uniq);
5377ae7a828SChengguang Xu 		fsopt->fscache_uniq = NULL;
53882995cc6SDavid Howells 		if (result.negated) {
53982995cc6SDavid Howells 			fsopt->flags &= ~CEPH_MOUNT_OPT_FSCACHE;
54082995cc6SDavid Howells 		} else {
54182995cc6SDavid Howells 			fsopt->flags |= CEPH_MOUNT_OPT_FSCACHE;
54282995cc6SDavid Howells 			fsopt->fscache_uniq = param->string;
54382995cc6SDavid Howells 			param->string = NULL;
54482995cc6SDavid Howells 		}
54599ccbd22SMilosz Tanski 		break;
546ff29fde8SJeff Layton #else
547d53d0f74SAl Viro 		return invalfc(fc, "fscache support is disabled");
548ff29fde8SJeff Layton #endif
54910183a69SYan, Zheng 	case Opt_poolperm:
55082995cc6SDavid Howells 		if (!result.negated)
55110183a69SYan, Zheng 			fsopt->flags &= ~CEPH_MOUNT_OPT_NOPOOLPERM;
55282995cc6SDavid Howells 		else
55310183a69SYan, Zheng 			fsopt->flags |= CEPH_MOUNT_OPT_NOPOOLPERM;
55410183a69SYan, Zheng 		break;
555e9e427f0SYan, Zheng 	case Opt_require_active_mds:
55682995cc6SDavid Howells 		if (!result.negated)
557e9e427f0SYan, Zheng 			fsopt->flags &= ~CEPH_MOUNT_OPT_MOUNTWAIT;
55882995cc6SDavid Howells 		else
559e9e427f0SYan, Zheng 			fsopt->flags |= CEPH_MOUNT_OPT_MOUNTWAIT;
560e9e427f0SYan, Zheng 		break;
5619122eed5SLuis Henriques 	case Opt_quotadf:
56282995cc6SDavid Howells 		if (!result.negated)
5639122eed5SLuis Henriques 			fsopt->flags &= ~CEPH_MOUNT_OPT_NOQUOTADF;
56482995cc6SDavid Howells 		else
5659122eed5SLuis Henriques 			fsopt->flags |= CEPH_MOUNT_OPT_NOQUOTADF;
5669122eed5SLuis Henriques 		break;
567ea4cdc54SLuis Henriques 	case Opt_copyfrom:
56882995cc6SDavid Howells 		if (!result.negated)
569ea4cdc54SLuis Henriques 			fsopt->flags &= ~CEPH_MOUNT_OPT_NOCOPYFROM;
57082995cc6SDavid Howells 		else
571ea4cdc54SLuis Henriques 			fsopt->flags |= CEPH_MOUNT_OPT_NOCOPYFROM;
572ea4cdc54SLuis Henriques 		break;
57345195e42SSage Weil 	case Opt_acl:
57482995cc6SDavid Howells 		if (!result.negated) {
57582995cc6SDavid Howells #ifdef CONFIG_CEPH_FS_POSIX_ACL
57682995cc6SDavid Howells 			fc->sb_flags |= SB_POSIXACL;
57782995cc6SDavid Howells #else
578d53d0f74SAl Viro 			return invalfc(fc, "POSIX ACL support is disabled");
57945195e42SSage Weil #endif
58082995cc6SDavid Howells 		} else {
58182995cc6SDavid Howells 			fc->sb_flags &= ~SB_POSIXACL;
58282995cc6SDavid Howells 		}
58345195e42SSage Weil 		break;
5842ccb4546SJeff Layton 	case Opt_wsync:
5852ccb4546SJeff Layton 		if (!result.negated)
5862ccb4546SJeff Layton 			fsopt->flags &= ~CEPH_MOUNT_OPT_ASYNC_DIROPS;
5872ccb4546SJeff Layton 		else
5882ccb4546SJeff Layton 			fsopt->flags |= CEPH_MOUNT_OPT_ASYNC_DIROPS;
5892ccb4546SJeff Layton 		break;
59094cc0877SJeff Layton 	case Opt_pagecache:
59194cc0877SJeff Layton 		if (result.negated)
59294cc0877SJeff Layton 			fsopt->flags |= CEPH_MOUNT_OPT_NOPAGECACHE;
59394cc0877SJeff Layton 		else
59494cc0877SJeff Layton 			fsopt->flags &= ~CEPH_MOUNT_OPT_NOPAGECACHE;
59594cc0877SJeff Layton 		break;
59603bc06c7SJeff Layton 	case Opt_sparseread:
59703bc06c7SJeff Layton 		if (result.negated)
59803bc06c7SJeff Layton 			fsopt->flags &= ~CEPH_MOUNT_OPT_SPARSEREAD;
59903bc06c7SJeff Layton 		else
60003bc06c7SJeff Layton 			fsopt->flags |= CEPH_MOUNT_OPT_SPARSEREAD;
60103bc06c7SJeff Layton 		break;
6026b5717bdSJeff Layton 	case Opt_test_dummy_encryption:
6036b5717bdSJeff Layton #ifdef CONFIG_FS_ENCRYPTION
6046b5717bdSJeff Layton 		fscrypt_free_dummy_policy(&fsopt->dummy_enc_policy);
6056b5717bdSJeff Layton 		ret = fscrypt_parse_test_dummy_encryption(param,
6066b5717bdSJeff Layton 						&fsopt->dummy_enc_policy);
6076b5717bdSJeff Layton 		if (ret == -EINVAL) {
6086b5717bdSJeff Layton 			warnfc(fc, "Value of option \"%s\" is unrecognized",
6096b5717bdSJeff Layton 			       param->key);
6106b5717bdSJeff Layton 		} else if (ret == -EEXIST) {
6116b5717bdSJeff Layton 			warnfc(fc, "Conflicting test_dummy_encryption options");
6126b5717bdSJeff Layton 			ret = -EINVAL;
6136b5717bdSJeff Layton 		}
6146b5717bdSJeff Layton #else
6156b5717bdSJeff Layton 		warnfc(fc,
6166b5717bdSJeff Layton 		       "FS encryption not supported: test_dummy_encryption mount option ignored");
6176b5717bdSJeff Layton #endif
6186b5717bdSJeff Layton 		break;
6193d14c5d2SYehuda Sadeh 	default:
62082995cc6SDavid Howells 		BUG();
6213d14c5d2SYehuda Sadeh 	}
6223d14c5d2SYehuda Sadeh 	return 0;
62382995cc6SDavid Howells 
62482995cc6SDavid Howells out_of_range:
625d53d0f74SAl Viro 	return invalfc(fc, "%s out of range", param->key);
6263d14c5d2SYehuda Sadeh }
6273d14c5d2SYehuda Sadeh 
destroy_mount_options(struct ceph_mount_options * args)6283d14c5d2SYehuda Sadeh static void destroy_mount_options(struct ceph_mount_options *args)
6293d14c5d2SYehuda Sadeh {
6303d14c5d2SYehuda Sadeh 	dout("destroy_mount_options %p\n", args);
63182995cc6SDavid Howells 	if (!args)
63282995cc6SDavid Howells 		return;
63382995cc6SDavid Howells 
6343d14c5d2SYehuda Sadeh 	kfree(args->snapdir_name);
635430afbadSYan, Zheng 	kfree(args->mds_namespace);
6363f384954SYan, Zheng 	kfree(args->server_path);
6371d8f8360SYan, Zheng 	kfree(args->fscache_uniq);
6387b19b4dbSVenky Shankar 	kfree(args->mon_addr);
6396b5717bdSJeff Layton 	fscrypt_free_dummy_policy(&args->dummy_enc_policy);
6403d14c5d2SYehuda Sadeh 	kfree(args);
6413d14c5d2SYehuda Sadeh }
6423d14c5d2SYehuda Sadeh 
strcmp_null(const char * s1,const char * s2)6433d14c5d2SYehuda Sadeh static int strcmp_null(const char *s1, const char *s2)
6443d14c5d2SYehuda Sadeh {
6453d14c5d2SYehuda Sadeh 	if (!s1 && !s2)
6463d14c5d2SYehuda Sadeh 		return 0;
6473d14c5d2SYehuda Sadeh 	if (s1 && !s2)
6483d14c5d2SYehuda Sadeh 		return -1;
6493d14c5d2SYehuda Sadeh 	if (!s1 && s2)
6503d14c5d2SYehuda Sadeh 		return 1;
6513d14c5d2SYehuda Sadeh 	return strcmp(s1, s2);
6523d14c5d2SYehuda Sadeh }
6533d14c5d2SYehuda Sadeh 
compare_mount_options(struct ceph_mount_options * new_fsopt,struct ceph_options * new_opt,struct ceph_fs_client * fsc)6543d14c5d2SYehuda Sadeh static int compare_mount_options(struct ceph_mount_options *new_fsopt,
6553d14c5d2SYehuda Sadeh 				 struct ceph_options *new_opt,
6563d14c5d2SYehuda Sadeh 				 struct ceph_fs_client *fsc)
6573d14c5d2SYehuda Sadeh {
6583d14c5d2SYehuda Sadeh 	struct ceph_mount_options *fsopt1 = new_fsopt;
6593d14c5d2SYehuda Sadeh 	struct ceph_mount_options *fsopt2 = fsc->mount_options;
6603d14c5d2SYehuda Sadeh 	int ofs = offsetof(struct ceph_mount_options, snapdir_name);
6613d14c5d2SYehuda Sadeh 	int ret;
6623d14c5d2SYehuda Sadeh 
6633d14c5d2SYehuda Sadeh 	ret = memcmp(fsopt1, fsopt2, ofs);
6643d14c5d2SYehuda Sadeh 	if (ret)
6653d14c5d2SYehuda Sadeh 		return ret;
6663d14c5d2SYehuda Sadeh 
6673d14c5d2SYehuda Sadeh 	ret = strcmp_null(fsopt1->snapdir_name, fsopt2->snapdir_name);
6683d14c5d2SYehuda Sadeh 	if (ret)
6693d14c5d2SYehuda Sadeh 		return ret;
670b27a939eSIlya Dryomov 
671430afbadSYan, Zheng 	ret = strcmp_null(fsopt1->mds_namespace, fsopt2->mds_namespace);
672430afbadSYan, Zheng 	if (ret)
673430afbadSYan, Zheng 		return ret;
6744fbc0c71SXiubo Li 
675b27a939eSIlya Dryomov 	ret = strcmp_null(fsopt1->server_path, fsopt2->server_path);
6763f384954SYan, Zheng 	if (ret)
6773f384954SYan, Zheng 		return ret;
6784fbc0c71SXiubo Li 
6791d8f8360SYan, Zheng 	ret = strcmp_null(fsopt1->fscache_uniq, fsopt2->fscache_uniq);
6801d8f8360SYan, Zheng 	if (ret)
6811d8f8360SYan, Zheng 		return ret;
6823f384954SYan, Zheng 
6837b19b4dbSVenky Shankar 	ret = strcmp_null(fsopt1->mon_addr, fsopt2->mon_addr);
6847b19b4dbSVenky Shankar 	if (ret)
6857b19b4dbSVenky Shankar 		return ret;
6867b19b4dbSVenky Shankar 
6873d14c5d2SYehuda Sadeh 	return ceph_compare_options(new_opt, fsc->client);
6883d14c5d2SYehuda Sadeh }
6893d14c5d2SYehuda Sadeh 
6906e19a16eSSage Weil /**
6916e19a16eSSage Weil  * ceph_show_options - Show mount options in /proc/mounts
6926e19a16eSSage Weil  * @m: seq_file to write to
69334c80b1dSAl Viro  * @root: root of that (sub)tree
6946e19a16eSSage Weil  */
ceph_show_options(struct seq_file * m,struct dentry * root)69534c80b1dSAl Viro static int ceph_show_options(struct seq_file *m, struct dentry *root)
6966e19a16eSSage Weil {
697985b9ee8SXiubo Li 	struct ceph_fs_client *fsc = ceph_sb_to_fs_client(root->d_sb);
6983d14c5d2SYehuda Sadeh 	struct ceph_mount_options *fsopt = fsc->mount_options;
699ff40f9aeSIlya Dryomov 	size_t pos;
700ff40f9aeSIlya Dryomov 	int ret;
7016e19a16eSSage Weil 
702ff40f9aeSIlya Dryomov 	/* a comma between MNT/MS and client options */
703ff40f9aeSIlya Dryomov 	seq_putc(m, ',');
704ff40f9aeSIlya Dryomov 	pos = m->count;
7053d14c5d2SYehuda Sadeh 
70602b2f549SDongsheng Yang 	ret = ceph_print_client_options(m, fsc->client, false);
707ff40f9aeSIlya Dryomov 	if (ret)
708ff40f9aeSIlya Dryomov 		return ret;
7093d14c5d2SYehuda Sadeh 
710ff40f9aeSIlya Dryomov 	/* retract our comma if no client options */
711ff40f9aeSIlya Dryomov 	if (m->count == pos)
712ff40f9aeSIlya Dryomov 		m->count--;
7133d14c5d2SYehuda Sadeh 
7143d14c5d2SYehuda Sadeh 	if (fsopt->flags & CEPH_MOUNT_OPT_DIRSTAT)
7153d14c5d2SYehuda Sadeh 		seq_puts(m, ",dirstat");
716133e9156SYan, Zheng 	if ((fsopt->flags & CEPH_MOUNT_OPT_RBYTES))
717133e9156SYan, Zheng 		seq_puts(m, ",rbytes");
7183d14c5d2SYehuda Sadeh 	if (fsopt->flags & CEPH_MOUNT_OPT_NOASYNCREADDIR)
7196e19a16eSSage Weil 		seq_puts(m, ",noasyncreaddir");
720ff7eeb82SIlya Dryomov 	if ((fsopt->flags & CEPH_MOUNT_OPT_DCACHE) == 0)
721a40dc6ccSSage Weil 		seq_puts(m, ",nodcache");
7223619aa8bSChengguang Xu 	if (fsopt->flags & CEPH_MOUNT_OPT_INO32)
7233619aa8bSChengguang Xu 		seq_puts(m, ",ino32");
7241d8f8360SYan, Zheng 	if (fsopt->flags & CEPH_MOUNT_OPT_FSCACHE) {
7254d8969afSChengguang Xu 		seq_show_option(m, "fsc", fsopt->fscache_uniq);
7261d8f8360SYan, Zheng 	}
72710183a69SYan, Zheng 	if (fsopt->flags & CEPH_MOUNT_OPT_NOPOOLPERM)
72810183a69SYan, Zheng 		seq_puts(m, ",nopoolperm");
7299122eed5SLuis Henriques 	if (fsopt->flags & CEPH_MOUNT_OPT_NOQUOTADF)
7309122eed5SLuis Henriques 		seq_puts(m, ",noquotadf");
7316e19a16eSSage Weil 
73245195e42SSage Weil #ifdef CONFIG_CEPH_FS_POSIX_ACL
73382995cc6SDavid Howells 	if (root->d_sb->s_flags & SB_POSIXACL)
73445195e42SSage Weil 		seq_puts(m, ",acl");
73545195e42SSage Weil 	else
73645195e42SSage Weil 		seq_puts(m, ",noacl");
73745195e42SSage Weil #endif
73845195e42SSage Weil 
7396f9718feSLuis Henriques 	if ((fsopt->flags & CEPH_MOUNT_OPT_NOCOPYFROM) == 0)
7406f9718feSLuis Henriques 		seq_puts(m, ",copyfrom");
741ea4cdc54SLuis Henriques 
7427b19b4dbSVenky Shankar 	/* dump mds_namespace when old device syntax is in use */
7437b19b4dbSVenky Shankar 	if (fsopt->mds_namespace && !fsopt->new_dev_syntax)
7444d8969afSChengguang Xu 		seq_show_option(m, "mds_namespace", fsopt->mds_namespace);
745131d7eb4SYan, Zheng 
7467b19b4dbSVenky Shankar 	if (fsopt->mon_addr)
7477b19b4dbSVenky Shankar 		seq_printf(m, ",mon_addr=%s", fsopt->mon_addr);
7487b19b4dbSVenky Shankar 
749131d7eb4SYan, Zheng 	if (fsopt->flags & CEPH_MOUNT_OPT_CLEANRECOVER)
750131d7eb4SYan, Zheng 		seq_show_option(m, "recover_session", "clean");
751131d7eb4SYan, Zheng 
752f7a67b46SJeff Layton 	if (!(fsopt->flags & CEPH_MOUNT_OPT_ASYNC_DIROPS))
753f7a67b46SJeff Layton 		seq_puts(m, ",wsync");
75494cc0877SJeff Layton 	if (fsopt->flags & CEPH_MOUNT_OPT_NOPAGECACHE)
75594cc0877SJeff Layton 		seq_puts(m, ",nopagecache");
75603bc06c7SJeff Layton 	if (fsopt->flags & CEPH_MOUNT_OPT_SPARSEREAD)
75703bc06c7SJeff Layton 		seq_puts(m, ",sparseread");
75894cc0877SJeff Layton 
7596b5717bdSJeff Layton 	fscrypt_show_test_dummy_encryption(m, ',', root->d_sb);
7606b5717bdSJeff Layton 
7616dd4940bSIlya Dryomov 	if (fsopt->wsize != CEPH_MAX_WRITE_SIZE)
762ad8c28a9SJeff Layton 		seq_printf(m, ",wsize=%u", fsopt->wsize);
763aa187926SYan, Zheng 	if (fsopt->rsize != CEPH_MAX_READ_SIZE)
764ad8c28a9SJeff Layton 		seq_printf(m, ",rsize=%u", fsopt->rsize);
76583817e35SSage Weil 	if (fsopt->rasize != CEPH_RASIZE_DEFAULT)
766ad8c28a9SJeff Layton 		seq_printf(m, ",rasize=%u", fsopt->rasize);
7673d14c5d2SYehuda Sadeh 	if (fsopt->congestion_kb != default_congestion_kb())
768ad8c28a9SJeff Layton 		seq_printf(m, ",write_congestion_kb=%u", fsopt->congestion_kb);
769fe33032dSYan, Zheng 	if (fsopt->caps_max)
770fe33032dSYan, Zheng 		seq_printf(m, ",caps_max=%d", fsopt->caps_max);
7713d14c5d2SYehuda Sadeh 	if (fsopt->caps_wanted_delay_min != CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT)
772ad8c28a9SJeff Layton 		seq_printf(m, ",caps_wanted_delay_min=%u",
7733d14c5d2SYehuda Sadeh 			 fsopt->caps_wanted_delay_min);
7743d14c5d2SYehuda Sadeh 	if (fsopt->caps_wanted_delay_max != CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT)
775ad8c28a9SJeff Layton 		seq_printf(m, ",caps_wanted_delay_max=%u",
7763d14c5d2SYehuda Sadeh 			   fsopt->caps_wanted_delay_max);
7773d14c5d2SYehuda Sadeh 	if (fsopt->max_readdir != CEPH_MAX_READDIR_DEFAULT)
778ad8c28a9SJeff Layton 		seq_printf(m, ",readdir_max_entries=%u", fsopt->max_readdir);
7793d14c5d2SYehuda Sadeh 	if (fsopt->max_readdir_bytes != CEPH_MAX_READDIR_BYTES_DEFAULT)
780ad8c28a9SJeff Layton 		seq_printf(m, ",readdir_max_bytes=%u", fsopt->max_readdir_bytes);
7813d14c5d2SYehuda Sadeh 	if (strcmp(fsopt->snapdir_name, CEPH_SNAPDIRNAME_DEFAULT))
782a068acf2SKees Cook 		seq_show_option(m, "snapdirname", fsopt->snapdir_name);
783ff40f9aeSIlya Dryomov 
7846e19a16eSSage Weil 	return 0;
7856e19a16eSSage Weil }
7866e19a16eSSage Weil 
7876e19a16eSSage Weil /*
7883d14c5d2SYehuda Sadeh  * handle any mon messages the standard library doesn't understand.
7893d14c5d2SYehuda Sadeh  * return error if we don't either.
7903d14c5d2SYehuda Sadeh  */
extra_mon_dispatch(struct ceph_client * client,struct ceph_msg * msg)7913d14c5d2SYehuda Sadeh static int extra_mon_dispatch(struct ceph_client *client, struct ceph_msg *msg)
7923d14c5d2SYehuda Sadeh {
7933d14c5d2SYehuda Sadeh 	struct ceph_fs_client *fsc = client->private;
7943d14c5d2SYehuda Sadeh 	int type = le16_to_cpu(msg->hdr.type);
7953d14c5d2SYehuda Sadeh 
7963d14c5d2SYehuda Sadeh 	switch (type) {
7973d14c5d2SYehuda Sadeh 	case CEPH_MSG_MDS_MAP:
798430afbadSYan, Zheng 		ceph_mdsc_handle_mdsmap(fsc->mdsc, msg);
7993d14c5d2SYehuda Sadeh 		return 0;
800430afbadSYan, Zheng 	case CEPH_MSG_FS_MAP_USER:
801430afbadSYan, Zheng 		ceph_mdsc_handle_fsmap(fsc->mdsc, msg);
802430afbadSYan, Zheng 		return 0;
8033d14c5d2SYehuda Sadeh 	default:
8043d14c5d2SYehuda Sadeh 		return -1;
8053d14c5d2SYehuda Sadeh 	}
8063d14c5d2SYehuda Sadeh }
8073d14c5d2SYehuda Sadeh 
8083d14c5d2SYehuda Sadeh /*
8093d14c5d2SYehuda Sadeh  * create a new fs client
8108aaff151SIlya Dryomov  *
8118aaff151SIlya Dryomov  * Success or not, this function consumes @fsopt and @opt.
8123d14c5d2SYehuda Sadeh  */
create_fs_client(struct ceph_mount_options * fsopt,struct ceph_options * opt)8130c6d4b4eSH Hartley Sweeten static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
8143d14c5d2SYehuda Sadeh 					struct ceph_options *opt)
8153d14c5d2SYehuda Sadeh {
8163d14c5d2SYehuda Sadeh 	struct ceph_fs_client *fsc;
8178aaff151SIlya Dryomov 	int err;
8183d14c5d2SYehuda Sadeh 
8193d14c5d2SYehuda Sadeh 	fsc = kzalloc(sizeof(*fsc), GFP_KERNEL);
8208aaff151SIlya Dryomov 	if (!fsc) {
8218aaff151SIlya Dryomov 		err = -ENOMEM;
8228aaff151SIlya Dryomov 		goto fail;
8238aaff151SIlya Dryomov 	}
8243d14c5d2SYehuda Sadeh 
82574da4a0fSIlya Dryomov 	fsc->client = ceph_create_client(opt, fsc);
8263d14c5d2SYehuda Sadeh 	if (IS_ERR(fsc->client)) {
8273d14c5d2SYehuda Sadeh 		err = PTR_ERR(fsc->client);
8283d14c5d2SYehuda Sadeh 		goto fail;
8293d14c5d2SYehuda Sadeh 	}
8308aaff151SIlya Dryomov 	opt = NULL; /* fsc->client now owns this */
831c843d13cSIlya Dryomov 
8323d14c5d2SYehuda Sadeh 	fsc->client->extra_mon_dispatch = extra_mon_dispatch;
83302b2f549SDongsheng Yang 	ceph_set_opt(fsc->client, ABORT_ON_FULL);
834430afbadSYan, Zheng 
835d37b1d99SMarkus Elfring 	if (!fsopt->mds_namespace) {
836430afbadSYan, Zheng 		ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_MDSMAP,
837430afbadSYan, Zheng 				   0, true);
838430afbadSYan, Zheng 	} else {
839430afbadSYan, Zheng 		ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_FSMAP,
840430afbadSYan, Zheng 				   0, false);
841430afbadSYan, Zheng 	}
8423d14c5d2SYehuda Sadeh 
8433d14c5d2SYehuda Sadeh 	fsc->mount_options = fsopt;
8443d14c5d2SYehuda Sadeh 
8453d14c5d2SYehuda Sadeh 	fsc->sb = NULL;
8463d14c5d2SYehuda Sadeh 	fsc->mount_state = CEPH_MOUNT_MOUNTING;
84781f148a9SYan, Zheng 	fsc->filp_gen = 1;
84878beb0ffSLuis Henriques 	fsc->have_copy_from2 = true;
8493d14c5d2SYehuda Sadeh 
8503d14c5d2SYehuda Sadeh 	atomic_long_set(&fsc->writeback_count, 0);
851503d4fa6SNeilBrown 	fsc->write_congested = false;
8523d14c5d2SYehuda Sadeh 
8533d14c5d2SYehuda Sadeh 	err = -ENOMEM;
85401e6acc4STejun Heo 	/*
85501e6acc4STejun Heo 	 * The number of concurrent works can be high but they don't need
85601e6acc4STejun Heo 	 * to be processed in parallel, limit concurrency.
85701e6acc4STejun Heo 	 */
8581cf89a8dSYan, Zheng 	fsc->inode_wq = alloc_workqueue("ceph-inode", WQ_UNBOUND, 0);
8591cf89a8dSYan, Zheng 	if (!fsc->inode_wq)
86009dc9fc2SJan Kara 		goto fail_client;
861e3ec8d68SYan, Zheng 	fsc->cap_wq = alloc_workqueue("ceph-cap", 0, 1);
862e3ec8d68SYan, Zheng 	if (!fsc->cap_wq)
8631cf89a8dSYan, Zheng 		goto fail_inode_wq;
8643d14c5d2SYehuda Sadeh 
8654868e537SXiubo Li 	hash_init(fsc->async_unlink_conflict);
8664868e537SXiubo Li 	spin_lock_init(&fsc->async_unlink_conflict_lock);
8674868e537SXiubo Li 
86818f473b3SXiubo Li 	spin_lock(&ceph_fsc_lock);
86918f473b3SXiubo Li 	list_add_tail(&fsc->metric_wakeup, &ceph_fsc_list);
87018f473b3SXiubo Li 	spin_unlock(&ceph_fsc_lock);
87118f473b3SXiubo Li 
8723d14c5d2SYehuda Sadeh 	return fsc;
8733d14c5d2SYehuda Sadeh 
8741cf89a8dSYan, Zheng fail_inode_wq:
8751cf89a8dSYan, Zheng 	destroy_workqueue(fsc->inode_wq);
8763d14c5d2SYehuda Sadeh fail_client:
8773d14c5d2SYehuda Sadeh 	ceph_destroy_client(fsc->client);
8783d14c5d2SYehuda Sadeh fail:
8793d14c5d2SYehuda Sadeh 	kfree(fsc);
8808aaff151SIlya Dryomov 	if (opt)
8818aaff151SIlya Dryomov 		ceph_destroy_options(opt);
8828aaff151SIlya Dryomov 	destroy_mount_options(fsopt);
8833d14c5d2SYehuda Sadeh 	return ERR_PTR(err);
8843d14c5d2SYehuda Sadeh }
8853d14c5d2SYehuda Sadeh 
flush_fs_workqueues(struct ceph_fs_client * fsc)886a57d9064SYan, Zheng static void flush_fs_workqueues(struct ceph_fs_client *fsc)
887a57d9064SYan, Zheng {
8881cf89a8dSYan, Zheng 	flush_workqueue(fsc->inode_wq);
889e3ec8d68SYan, Zheng 	flush_workqueue(fsc->cap_wq);
890a57d9064SYan, Zheng }
891a57d9064SYan, Zheng 
destroy_fs_client(struct ceph_fs_client * fsc)8920c6d4b4eSH Hartley Sweeten static void destroy_fs_client(struct ceph_fs_client *fsc)
8933d14c5d2SYehuda Sadeh {
8943d14c5d2SYehuda Sadeh 	dout("destroy_fs_client %p\n", fsc);
8953d14c5d2SYehuda Sadeh 
89618f473b3SXiubo Li 	spin_lock(&ceph_fsc_lock);
89718f473b3SXiubo Li 	list_del(&fsc->metric_wakeup);
89818f473b3SXiubo Li 	spin_unlock(&ceph_fsc_lock);
89918f473b3SXiubo Li 
9003ee5a701SJeff Layton 	ceph_mdsc_destroy(fsc);
9011cf89a8dSYan, Zheng 	destroy_workqueue(fsc->inode_wq);
902e3ec8d68SYan, Zheng 	destroy_workqueue(fsc->cap_wq);
9033d14c5d2SYehuda Sadeh 
9043d14c5d2SYehuda Sadeh 	destroy_mount_options(fsc->mount_options);
9053d14c5d2SYehuda Sadeh 
9063d14c5d2SYehuda Sadeh 	ceph_destroy_client(fsc->client);
9073d14c5d2SYehuda Sadeh 
9083d14c5d2SYehuda Sadeh 	kfree(fsc);
9093d14c5d2SYehuda Sadeh 	dout("destroy_fs_client %p done\n", fsc);
9103d14c5d2SYehuda Sadeh }
9113d14c5d2SYehuda Sadeh 
9123d14c5d2SYehuda Sadeh /*
9136e19a16eSSage Weil  * caches
9146e19a16eSSage Weil  */
9156e19a16eSSage Weil struct kmem_cache *ceph_inode_cachep;
9166e19a16eSSage Weil struct kmem_cache *ceph_cap_cachep;
917ab58a5a1SXiubo Li struct kmem_cache *ceph_cap_snap_cachep;
918f66fd9f0SYan, Zheng struct kmem_cache *ceph_cap_flush_cachep;
9196e19a16eSSage Weil struct kmem_cache *ceph_dentry_cachep;
9206e19a16eSSage Weil struct kmem_cache *ceph_file_cachep;
921bb48bd4dSChengguang Xu struct kmem_cache *ceph_dir_file_cachep;
922058daab7SJeff Layton struct kmem_cache *ceph_mds_request_cachep;
923a0102bdaSJeff Layton mempool_t *ceph_wb_pagevec_pool;
9246e19a16eSSage Weil 
ceph_inode_init_once(void * foo)9256e19a16eSSage Weil static void ceph_inode_init_once(void *foo)
9266e19a16eSSage Weil {
9276e19a16eSSage Weil 	struct ceph_inode_info *ci = foo;
928874c8ca1SDavid Howells 	inode_init_once(&ci->netfs.inode);
9296e19a16eSSage Weil }
9306e19a16eSSage Weil 
init_caches(void)93116725b9dSSage Weil static int __init init_caches(void)
93216725b9dSSage Weil {
93399ccbd22SMilosz Tanski 	int error = -ENOMEM;
93499ccbd22SMilosz Tanski 
93516725b9dSSage Weil 	ceph_inode_cachep = kmem_cache_create("ceph_inode_info",
93616725b9dSSage Weil 				      sizeof(struct ceph_inode_info),
93716725b9dSSage Weil 				      __alignof__(struct ceph_inode_info),
9385d097056SVladimir Davydov 				      SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|
9395d097056SVladimir Davydov 				      SLAB_ACCOUNT, ceph_inode_init_once);
940d37b1d99SMarkus Elfring 	if (!ceph_inode_cachep)
94116725b9dSSage Weil 		return -ENOMEM;
94216725b9dSSage Weil 
943bc4b5ad3SChengguang Xu 	ceph_cap_cachep = KMEM_CACHE(ceph_cap, SLAB_MEM_SPREAD);
944d37b1d99SMarkus Elfring 	if (!ceph_cap_cachep)
94516725b9dSSage Weil 		goto bad_cap;
946ab58a5a1SXiubo Li 	ceph_cap_snap_cachep = KMEM_CACHE(ceph_cap_snap, SLAB_MEM_SPREAD);
947ab58a5a1SXiubo Li 	if (!ceph_cap_snap_cachep)
948ab58a5a1SXiubo Li 		goto bad_cap_snap;
949f66fd9f0SYan, Zheng 	ceph_cap_flush_cachep = KMEM_CACHE(ceph_cap_flush,
950f66fd9f0SYan, Zheng 					   SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
951d37b1d99SMarkus Elfring 	if (!ceph_cap_flush_cachep)
952f66fd9f0SYan, Zheng 		goto bad_cap_flush;
95316725b9dSSage Weil 
95416725b9dSSage Weil 	ceph_dentry_cachep = KMEM_CACHE(ceph_dentry_info,
95516725b9dSSage Weil 					SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
956d37b1d99SMarkus Elfring 	if (!ceph_dentry_cachep)
95716725b9dSSage Weil 		goto bad_dentry;
95816725b9dSSage Weil 
9596b1a9a6cSNikolay Borisov 	ceph_file_cachep = KMEM_CACHE(ceph_file_info, SLAB_MEM_SPREAD);
960d37b1d99SMarkus Elfring 	if (!ceph_file_cachep)
96116725b9dSSage Weil 		goto bad_file;
96216725b9dSSage Weil 
963bb48bd4dSChengguang Xu 	ceph_dir_file_cachep = KMEM_CACHE(ceph_dir_file_info, SLAB_MEM_SPREAD);
964bb48bd4dSChengguang Xu 	if (!ceph_dir_file_cachep)
965bb48bd4dSChengguang Xu 		goto bad_dir_file;
966bb48bd4dSChengguang Xu 
967058daab7SJeff Layton 	ceph_mds_request_cachep = KMEM_CACHE(ceph_mds_request, SLAB_MEM_SPREAD);
968058daab7SJeff Layton 	if (!ceph_mds_request_cachep)
969058daab7SJeff Layton 		goto bad_mds_req;
970058daab7SJeff Layton 
971da0a3ebfSethanwu 	ceph_wb_pagevec_pool = mempool_create_kmalloc_pool(10,
972da0a3ebfSethanwu 	    (CEPH_MAX_WRITE_SIZE >> PAGE_SHIFT) * sizeof(struct page *));
973a0102bdaSJeff Layton 	if (!ceph_wb_pagevec_pool)
974a0102bdaSJeff Layton 		goto bad_pagevec_pool;
975a0102bdaSJeff Layton 
97699ccbd22SMilosz Tanski 	return 0;
9771c789249SChengguang Xu 
978a0102bdaSJeff Layton bad_pagevec_pool:
979400e1286SJeff Layton 	kmem_cache_destroy(ceph_mds_request_cachep);
980058daab7SJeff Layton bad_mds_req:
981bb48bd4dSChengguang Xu 	kmem_cache_destroy(ceph_dir_file_cachep);
982bb48bd4dSChengguang Xu bad_dir_file:
9831c789249SChengguang Xu 	kmem_cache_destroy(ceph_file_cachep);
98416725b9dSSage Weil bad_file:
98516725b9dSSage Weil 	kmem_cache_destroy(ceph_dentry_cachep);
98616725b9dSSage Weil bad_dentry:
987f66fd9f0SYan, Zheng 	kmem_cache_destroy(ceph_cap_flush_cachep);
988f66fd9f0SYan, Zheng bad_cap_flush:
989ab58a5a1SXiubo Li 	kmem_cache_destroy(ceph_cap_snap_cachep);
990ab58a5a1SXiubo Li bad_cap_snap:
99116725b9dSSage Weil 	kmem_cache_destroy(ceph_cap_cachep);
99216725b9dSSage Weil bad_cap:
99316725b9dSSage Weil 	kmem_cache_destroy(ceph_inode_cachep);
99499ccbd22SMilosz Tanski 	return error;
99516725b9dSSage Weil }
99616725b9dSSage Weil 
destroy_caches(void)99716725b9dSSage Weil static void destroy_caches(void)
99816725b9dSSage Weil {
9998c0a8537SKirill A. Shutemov 	/*
10008c0a8537SKirill A. Shutemov 	 * Make sure all delayed rcu free inodes are flushed before we
10018c0a8537SKirill A. Shutemov 	 * destroy cache.
10028c0a8537SKirill A. Shutemov 	 */
10038c0a8537SKirill A. Shutemov 	rcu_barrier();
100499ccbd22SMilosz Tanski 
100516725b9dSSage Weil 	kmem_cache_destroy(ceph_inode_cachep);
100616725b9dSSage Weil 	kmem_cache_destroy(ceph_cap_cachep);
1007ab58a5a1SXiubo Li 	kmem_cache_destroy(ceph_cap_snap_cachep);
1008f66fd9f0SYan, Zheng 	kmem_cache_destroy(ceph_cap_flush_cachep);
100916725b9dSSage Weil 	kmem_cache_destroy(ceph_dentry_cachep);
101016725b9dSSage Weil 	kmem_cache_destroy(ceph_file_cachep);
1011bb48bd4dSChengguang Xu 	kmem_cache_destroy(ceph_dir_file_cachep);
1012058daab7SJeff Layton 	kmem_cache_destroy(ceph_mds_request_cachep);
1013a0102bdaSJeff Layton 	mempool_destroy(ceph_wb_pagevec_pool);
101416725b9dSSage Weil }
101516725b9dSSage Weil 
__ceph_umount_begin(struct ceph_fs_client * fsc)101650c9132dSJeff Layton static void __ceph_umount_begin(struct ceph_fs_client *fsc)
101750c9132dSJeff Layton {
101850c9132dSJeff Layton 	ceph_osdc_abort_requests(&fsc->client->osdc, -EIO);
101950c9132dSJeff Layton 	ceph_mdsc_force_umount(fsc->mdsc);
102050c9132dSJeff Layton 	fsc->filp_gen++; // invalidate open files
102150c9132dSJeff Layton }
102250c9132dSJeff Layton 
102316725b9dSSage Weil /*
1024f1f565a2SRandy Dunlap  * ceph_umount_begin - initiate forced umount.  Tear down the
102516725b9dSSage Weil  * mount, skipping steps that may hang while waiting for server(s).
102616725b9dSSage Weil  */
ceph_umount_begin(struct super_block * sb)1027631ed4b0SJeff Layton void ceph_umount_begin(struct super_block *sb)
102816725b9dSSage Weil {
1029985b9ee8SXiubo Li 	struct ceph_fs_client *fsc = ceph_sb_to_fs_client(sb);
103016725b9dSSage Weil 
103116725b9dSSage Weil 	dout("ceph_umount_begin - starting forced umount\n");
10323d14c5d2SYehuda Sadeh 	if (!fsc)
103316725b9dSSage Weil 		return;
10343d14c5d2SYehuda Sadeh 	fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
103550c9132dSJeff Layton 	__ceph_umount_begin(fsc);
103616725b9dSSage Weil }
103716725b9dSSage Weil 
103816725b9dSSage Weil static const struct super_operations ceph_super_ops = {
103916725b9dSSage Weil 	.alloc_inode	= ceph_alloc_inode,
1040cfa6d412SAl Viro 	.free_inode	= ceph_free_inode,
104116725b9dSSage Weil 	.write_inode    = ceph_write_inode,
104252dd0f1bSLuis Henriques 	.drop_inode	= generic_delete_inode,
104387bc5b89SYan, Zheng 	.evict_inode	= ceph_evict_inode,
10442d9c98aeSSage Weil 	.sync_fs        = ceph_sync_fs,
104516725b9dSSage Weil 	.put_super	= ceph_put_super,
104616725b9dSSage Weil 	.show_options   = ceph_show_options,
104716725b9dSSage Weil 	.statfs		= ceph_statfs,
104816725b9dSSage Weil 	.umount_begin   = ceph_umount_begin,
104916725b9dSSage Weil };
105016725b9dSSage Weil 
105116725b9dSSage Weil /*
105216725b9dSSage Weil  * Bootstrap mount by opening the root directory.  Note the mount
105316725b9dSSage Weil  * @started time from caller, and time out if this takes too long.
105416725b9dSSage Weil  */
open_root_dentry(struct ceph_fs_client * fsc,const char * path,unsigned long started)10553d14c5d2SYehuda Sadeh static struct dentry *open_root_dentry(struct ceph_fs_client *fsc,
105616725b9dSSage Weil 				       const char *path,
105716725b9dSSage Weil 				       unsigned long started)
105816725b9dSSage Weil {
10593d14c5d2SYehuda Sadeh 	struct ceph_mds_client *mdsc = fsc->mdsc;
106016725b9dSSage Weil 	struct ceph_mds_request *req = NULL;
106116725b9dSSage Weil 	int err;
106216725b9dSSage Weil 	struct dentry *root;
106316725b9dSSage Weil 
106416725b9dSSage Weil 	/* open dir */
106516725b9dSSage Weil 	dout("open_root_inode opening '%s'\n", path);
106616725b9dSSage Weil 	req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_GETATTR, USE_ANY_MDS);
106716725b9dSSage Weil 	if (IS_ERR(req))
10687e34bc52SJulia Lawall 		return ERR_CAST(req);
106916725b9dSSage Weil 	req->r_path1 = kstrdup(path, GFP_NOFS);
1070a149bb9aSSanidhya Kashyap 	if (!req->r_path1) {
1071a149bb9aSSanidhya Kashyap 		root = ERR_PTR(-ENOMEM);
1072a149bb9aSSanidhya Kashyap 		goto out;
1073a149bb9aSSanidhya Kashyap 	}
1074a149bb9aSSanidhya Kashyap 
107516725b9dSSage Weil 	req->r_ino1.ino = CEPH_INO_ROOT;
107616725b9dSSage Weil 	req->r_ino1.snap = CEPH_NOSNAP;
107716725b9dSSage Weil 	req->r_started = started;
1078a319bf56SIlya Dryomov 	req->r_timeout = fsc->client->options->mount_timeout;
107916725b9dSSage Weil 	req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INODE);
108016725b9dSSage Weil 	req->r_num_caps = 2;
108116725b9dSSage Weil 	err = ceph_mdsc_do_request(mdsc, NULL, req);
108216725b9dSSage Weil 	if (err == 0) {
10833c5184efSAl Viro 		struct inode *inode = req->r_target_inode;
10843c5184efSAl Viro 		req->r_target_inode = NULL;
108516725b9dSSage Weil 		dout("open_root_inode success\n");
108648fde701SAl Viro 		root = d_make_root(inode);
10873c5184efSAl Viro 		if (!root) {
10883c5184efSAl Viro 			root = ERR_PTR(-ENOMEM);
10893c5184efSAl Viro 			goto out;
10903c5184efSAl Viro 		}
109116725b9dSSage Weil 		dout("open_root_inode success, root dentry is %p\n", root);
109216725b9dSSage Weil 	} else {
109316725b9dSSage Weil 		root = ERR_PTR(err);
109416725b9dSSage Weil 	}
10953c5184efSAl Viro out:
109616725b9dSSage Weil 	ceph_mdsc_put_request(req);
109716725b9dSSage Weil 	return root;
109816725b9dSSage Weil }
109916725b9dSSage Weil 
11006b5717bdSJeff Layton #ifdef CONFIG_FS_ENCRYPTION
ceph_apply_test_dummy_encryption(struct super_block * sb,struct fs_context * fc,struct ceph_mount_options * fsopt)11016b5717bdSJeff Layton static int ceph_apply_test_dummy_encryption(struct super_block *sb,
11026b5717bdSJeff Layton 					    struct fs_context *fc,
11036b5717bdSJeff Layton 					    struct ceph_mount_options *fsopt)
11046b5717bdSJeff Layton {
11056b5717bdSJeff Layton 	struct ceph_fs_client *fsc = sb->s_fs_info;
11066b5717bdSJeff Layton 
11076b5717bdSJeff Layton 	if (!fscrypt_is_dummy_policy_set(&fsopt->dummy_enc_policy))
11086b5717bdSJeff Layton 		return 0;
11096b5717bdSJeff Layton 
11106b5717bdSJeff Layton 	/* No changing encryption context on remount. */
11116b5717bdSJeff Layton 	if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE &&
11126b5717bdSJeff Layton 	    !fscrypt_is_dummy_policy_set(&fsc->fsc_dummy_enc_policy)) {
11136b5717bdSJeff Layton 		if (fscrypt_dummy_policies_equal(&fsopt->dummy_enc_policy,
11146b5717bdSJeff Layton 						 &fsc->fsc_dummy_enc_policy))
11156b5717bdSJeff Layton 			return 0;
11166b5717bdSJeff Layton 		errorfc(fc, "Can't set test_dummy_encryption on remount");
11176b5717bdSJeff Layton 		return -EINVAL;
11186b5717bdSJeff Layton 	}
11196b5717bdSJeff Layton 
11206b5717bdSJeff Layton 	/* Also make sure fsopt doesn't contain a conflicting value. */
11216b5717bdSJeff Layton 	if (fscrypt_is_dummy_policy_set(&fsc->fsc_dummy_enc_policy)) {
11226b5717bdSJeff Layton 		if (fscrypt_dummy_policies_equal(&fsopt->dummy_enc_policy,
11236b5717bdSJeff Layton 						 &fsc->fsc_dummy_enc_policy))
11246b5717bdSJeff Layton 			return 0;
11256b5717bdSJeff Layton 		errorfc(fc, "Conflicting test_dummy_encryption options");
11266b5717bdSJeff Layton 		return -EINVAL;
11276b5717bdSJeff Layton 	}
11286b5717bdSJeff Layton 
11296b5717bdSJeff Layton 	fsc->fsc_dummy_enc_policy = fsopt->dummy_enc_policy;
11306b5717bdSJeff Layton 	memset(&fsopt->dummy_enc_policy, 0, sizeof(fsopt->dummy_enc_policy));
11316b5717bdSJeff Layton 
11326b5717bdSJeff Layton 	warnfc(fc, "test_dummy_encryption mode enabled");
11336b5717bdSJeff Layton 	return 0;
11346b5717bdSJeff Layton }
11356b5717bdSJeff Layton #else
ceph_apply_test_dummy_encryption(struct super_block * sb,struct fs_context * fc,struct ceph_mount_options * fsopt)11366b5717bdSJeff Layton static int ceph_apply_test_dummy_encryption(struct super_block *sb,
11376b5717bdSJeff Layton 					    struct fs_context *fc,
11386b5717bdSJeff Layton 					    struct ceph_mount_options *fsopt)
11396b5717bdSJeff Layton {
11406b5717bdSJeff Layton 	return 0;
11416b5717bdSJeff Layton }
11426b5717bdSJeff Layton #endif
11436b5717bdSJeff Layton 
114416725b9dSSage Weil /*
114516725b9dSSage Weil  * mount: join the ceph cluster, and open root directory.
114616725b9dSSage Weil  */
ceph_real_mount(struct ceph_fs_client * fsc,struct fs_context * fc)114782995cc6SDavid Howells static struct dentry *ceph_real_mount(struct ceph_fs_client *fsc,
114882995cc6SDavid Howells 				      struct fs_context *fc)
114916725b9dSSage Weil {
115016725b9dSSage Weil 	int err;
115116725b9dSSage Weil 	unsigned long started = jiffies;  /* note the start time */
115216725b9dSSage Weil 	struct dentry *root;
115316725b9dSSage Weil 
1154132ca7e1SYan, Zheng 	dout("mount start %p\n", fsc);
11553d14c5d2SYehuda Sadeh 	mutex_lock(&fsc->client->mount_mutex);
115616725b9dSSage Weil 
1157132ca7e1SYan, Zheng 	if (!fsc->sb->s_root) {
1158b27a939eSIlya Dryomov 		const char *path = fsc->mount_options->server_path ?
1159b27a939eSIlya Dryomov 				     fsc->mount_options->server_path + 1 : "";
1160b27a939eSIlya Dryomov 
11613d14c5d2SYehuda Sadeh 		err = __ceph_open_session(fsc->client, started);
116216725b9dSSage Weil 		if (err < 0)
116316725b9dSSage Weil 			goto out;
116416725b9dSSage Weil 
11651d8f8360SYan, Zheng 		/* setup fscache */
11661d8f8360SYan, Zheng 		if (fsc->mount_options->flags & CEPH_MOUNT_OPT_FSCACHE) {
116782995cc6SDavid Howells 			err = ceph_fscache_register_fs(fsc, fc);
11681d8f8360SYan, Zheng 			if (err < 0)
11691d8f8360SYan, Zheng 				goto out;
11701d8f8360SYan, Zheng 		}
11711d8f8360SYan, Zheng 
11726b5717bdSJeff Layton 		err = ceph_apply_test_dummy_encryption(fsc->sb, fc,
11736b5717bdSJeff Layton 						       fsc->mount_options);
11746b5717bdSJeff Layton 		if (err)
11756b5717bdSJeff Layton 			goto out;
11766b5717bdSJeff Layton 
11774fbc0c71SXiubo Li 		dout("mount opening path '%s'\n", path);
117818106734SChengguang Xu 
11791a829ff2SGreg Kroah-Hartman 		ceph_fs_debugfs_init(fsc);
118018106734SChengguang Xu 
1181ce2728aaSYan, Zheng 		root = open_root_dentry(fsc, path, started);
118216725b9dSSage Weil 		if (IS_ERR(root)) {
118316725b9dSSage Weil 			err = PTR_ERR(root);
118416725b9dSSage Weil 			goto out;
118516725b9dSSage Weil 		}
1186ce2728aaSYan, Zheng 		fsc->sb->s_root = dget(root);
118731ca5878SGeert Uytterhoeven 	} else {
118831ca5878SGeert Uytterhoeven 		root = dget(fsc->sb->s_root);
11893d14c5d2SYehuda Sadeh 	}
119016725b9dSSage Weil 
11913d14c5d2SYehuda Sadeh 	fsc->mount_state = CEPH_MOUNT_MOUNTED;
119216725b9dSSage Weil 	dout("mount success\n");
1193a7f9fb20SAl Viro 	mutex_unlock(&fsc->client->mount_mutex);
1194a7f9fb20SAl Viro 	return root;
119516725b9dSSage Weil 
1196132ca7e1SYan, Zheng out:
1197132ca7e1SYan, Zheng 	mutex_unlock(&fsc->client->mount_mutex);
11986b5717bdSJeff Layton 	ceph_fscrypt_free_dummy_policy(fsc);
1199132ca7e1SYan, Zheng 	return ERR_PTR(err);
120016725b9dSSage Weil }
120116725b9dSSage Weil 
ceph_set_super(struct super_block * s,struct fs_context * fc)120282995cc6SDavid Howells static int ceph_set_super(struct super_block *s, struct fs_context *fc)
120316725b9dSSage Weil {
120482995cc6SDavid Howells 	struct ceph_fs_client *fsc = s->s_fs_info;
120516725b9dSSage Weil 	int ret;
120616725b9dSSage Weil 
120782995cc6SDavid Howells 	dout("set_super %p\n", s);
120816725b9dSSage Weil 
1209719784baSChengguang Xu 	s->s_maxbytes = MAX_LFS_FILESIZE;
121016725b9dSSage Weil 
12117221fe4cSGuangliang Zhao 	s->s_xattr = ceph_xattr_handlers;
12123d14c5d2SYehuda Sadeh 	fsc->sb = s;
1213719784baSChengguang Xu 	fsc->max_file_size = 1ULL << 40; /* temp value until we get mdsmap */
121416725b9dSSage Weil 
121516725b9dSSage Weil 	s->s_op = &ceph_super_ops;
121618fc8abdSAl Viro 	s->s_d_op = &ceph_dentry_ops;
121716725b9dSSage Weil 	s->s_export_op = &ceph_export_ops;
121816725b9dSSage Weil 
12190f7cf80aSLuis Henriques 	s->s_time_gran = 1;
1220028ca4dbSDeepa Dinamani 	s->s_time_min = 0;
1221028ca4dbSDeepa Dinamani 	s->s_time_max = U32_MAX;
1222f7a2d068SXiubo Li 	s->s_flags |= SB_NODIRATIME | SB_NOATIME;
122316725b9dSSage Weil 
12242d332d5bSJeff Layton 	ceph_fscrypt_set_ops(s);
12252d332d5bSJeff Layton 
122682995cc6SDavid Howells 	ret = set_anon_super_fc(s, fc);
122716725b9dSSage Weil 	if (ret != 0)
12283d14c5d2SYehuda Sadeh 		fsc->sb = NULL;
122916725b9dSSage Weil 	return ret;
123016725b9dSSage Weil }
123116725b9dSSage Weil 
123216725b9dSSage Weil /*
123316725b9dSSage Weil  * share superblock if same fs AND options
123416725b9dSSage Weil  */
ceph_compare_super(struct super_block * sb,struct fs_context * fc)123582995cc6SDavid Howells static int ceph_compare_super(struct super_block *sb, struct fs_context *fc)
123616725b9dSSage Weil {
123782995cc6SDavid Howells 	struct ceph_fs_client *new = fc->s_fs_info;
12383d14c5d2SYehuda Sadeh 	struct ceph_mount_options *fsopt = new->mount_options;
12393d14c5d2SYehuda Sadeh 	struct ceph_options *opt = new->client->options;
1240985b9ee8SXiubo Li 	struct ceph_fs_client *fsc = ceph_sb_to_fs_client(sb);
124116725b9dSSage Weil 
124216725b9dSSage Weil 	dout("ceph_compare_super %p\n", sb);
12433d14c5d2SYehuda Sadeh 
124498d0a6fbSJeff Layton 	if (compare_mount_options(fsopt, opt, fsc)) {
12453d14c5d2SYehuda Sadeh 		dout("monitor(s)/mount options don't match\n");
12463d14c5d2SYehuda Sadeh 		return 0;
12473d14c5d2SYehuda Sadeh 	}
12483d14c5d2SYehuda Sadeh 	if ((opt->flags & CEPH_OPT_FSID) &&
124998d0a6fbSJeff Layton 	    ceph_fsid_compare(&opt->fsid, &fsc->client->fsid)) {
125016725b9dSSage Weil 		dout("fsid doesn't match\n");
125116725b9dSSage Weil 		return 0;
125216725b9dSSage Weil 	}
125382995cc6SDavid Howells 	if (fc->sb_flags != (sb->s_flags & ~SB_BORN)) {
125416725b9dSSage Weil 		dout("flags differ\n");
125516725b9dSSage Weil 		return 0;
125616725b9dSSage Weil 	}
125798d0a6fbSJeff Layton 
125898d0a6fbSJeff Layton 	if (fsc->blocklisted && !ceph_test_mount_opt(fsc, CLEANRECOVER)) {
125998d0a6fbSJeff Layton 		dout("client is blocklisted (and CLEANRECOVER is not set)\n");
126098d0a6fbSJeff Layton 		return 0;
126198d0a6fbSJeff Layton 	}
126298d0a6fbSJeff Layton 
126398d0a6fbSJeff Layton 	if (fsc->mount_state == CEPH_MOUNT_SHUTDOWN) {
126498d0a6fbSJeff Layton 		dout("client has been forcibly unmounted\n");
126598d0a6fbSJeff Layton 		return 0;
126698d0a6fbSJeff Layton 	}
126798d0a6fbSJeff Layton 
126816725b9dSSage Weil 	return 1;
126916725b9dSSage Weil }
127016725b9dSSage Weil 
127116725b9dSSage Weil /*
127216725b9dSSage Weil  * construct our own bdi so we can control readahead, etc.
127316725b9dSSage Weil  */
127400d5643eSJeff Mahoney static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
127531e0cf8fSSage Weil 
ceph_setup_bdi(struct super_block * sb,struct ceph_fs_client * fsc)127609dc9fc2SJan Kara static int ceph_setup_bdi(struct super_block *sb, struct ceph_fs_client *fsc)
127716725b9dSSage Weil {
127816725b9dSSage Weil 	int err;
127916725b9dSSage Weil 
128009dc9fc2SJan Kara 	err = super_setup_bdi_name(sb, "ceph-%ld",
128109dc9fc2SJan Kara 				   atomic_long_inc_return(&bdi_seq));
128209dc9fc2SJan Kara 	if (err)
128309dc9fc2SJan Kara 		return err;
128409dc9fc2SJan Kara 
128583817e35SSage Weil 	/* set ra_pages based on rasize mount option? */
12864214fb15SYan, Zheng 	sb->s_bdi->ra_pages = fsc->mount_options->rasize >> PAGE_SHIFT;
1287e9852227SYehuda Sadeh 
1288aa187926SYan, Zheng 	/* set io_pages based on max osd read size */
1289aa187926SYan, Zheng 	sb->s_bdi->io_pages = fsc->mount_options->rsize >> PAGE_SHIFT;
12907c94ba27SAndreas Gerstmayr 
129109dc9fc2SJan Kara 	return 0;
129216725b9dSSage Weil }
129316725b9dSSage Weil 
ceph_get_tree(struct fs_context * fc)129482995cc6SDavid Howells static int ceph_get_tree(struct fs_context *fc)
129516725b9dSSage Weil {
129682995cc6SDavid Howells 	struct ceph_parse_opts_ctx *pctx = fc->fs_private;
12977b19b4dbSVenky Shankar 	struct ceph_mount_options *fsopt = pctx->opts;
129816725b9dSSage Weil 	struct super_block *sb;
12993d14c5d2SYehuda Sadeh 	struct ceph_fs_client *fsc;
1300a7f9fb20SAl Viro 	struct dentry *res;
130182995cc6SDavid Howells 	int (*compare_super)(struct super_block *, struct fs_context *) =
130282995cc6SDavid Howells 		ceph_compare_super;
130316725b9dSSage Weil 	int err;
130416725b9dSSage Weil 
130582995cc6SDavid Howells 	dout("ceph_get_tree\n");
130682995cc6SDavid Howells 
130782995cc6SDavid Howells 	if (!fc->source)
1308d53d0f74SAl Viro 		return invalfc(fc, "No source");
13097b19b4dbSVenky Shankar 	if (fsopt->new_dev_syntax && !fsopt->mon_addr)
13107b19b4dbSVenky Shankar 		return invalfc(fc, "No monitor address");
131145195e42SSage Weil 
131216725b9dSSage Weil 	/* create client (which we may/may not use) */
131382995cc6SDavid Howells 	fsc = create_fs_client(pctx->opts, pctx->copts);
131482995cc6SDavid Howells 	pctx->opts = NULL;
131582995cc6SDavid Howells 	pctx->copts = NULL;
13163d14c5d2SYehuda Sadeh 	if (IS_ERR(fsc)) {
131782995cc6SDavid Howells 		err = PTR_ERR(fsc);
13186b805185SSage Weil 		goto out_final;
13196b805185SSage Weil 	}
132016725b9dSSage Weil 
13213d14c5d2SYehuda Sadeh 	err = ceph_mdsc_init(fsc);
132282995cc6SDavid Howells 	if (err < 0)
13233d14c5d2SYehuda Sadeh 		goto out;
13243d14c5d2SYehuda Sadeh 
13253d14c5d2SYehuda Sadeh 	if (ceph_test_opt(fsc->client, NOSHARE))
132616725b9dSSage Weil 		compare_super = NULL;
132782995cc6SDavid Howells 
132882995cc6SDavid Howells 	fc->s_fs_info = fsc;
132982995cc6SDavid Howells 	sb = sget_fc(fc, compare_super, ceph_set_super);
133082995cc6SDavid Howells 	fc->s_fs_info = NULL;
133116725b9dSSage Weil 	if (IS_ERR(sb)) {
133282995cc6SDavid Howells 		err = PTR_ERR(sb);
133316725b9dSSage Weil 		goto out;
133416725b9dSSage Weil 	}
133516725b9dSSage Weil 
1336985b9ee8SXiubo Li 	if (ceph_sb_to_fs_client(sb) != fsc) {
13373d14c5d2SYehuda Sadeh 		destroy_fs_client(fsc);
1338985b9ee8SXiubo Li 		fsc = ceph_sb_to_fs_client(sb);
13393d14c5d2SYehuda Sadeh 		dout("get_sb got existing client %p\n", fsc);
134016725b9dSSage Weil 	} else {
13413d14c5d2SYehuda Sadeh 		dout("get_sb using new client %p\n", fsc);
134209dc9fc2SJan Kara 		err = ceph_setup_bdi(sb, fsc);
134382995cc6SDavid Howells 		if (err < 0)
134416725b9dSSage Weil 			goto out_splat;
134516725b9dSSage Weil 	}
134616725b9dSSage Weil 
134782995cc6SDavid Howells 	res = ceph_real_mount(fsc, fc);
134882995cc6SDavid Howells 	if (IS_ERR(res)) {
134982995cc6SDavid Howells 		err = PTR_ERR(res);
135016725b9dSSage Weil 		goto out_splat;
135182995cc6SDavid Howells 	}
1352a7f9fb20SAl Viro 	dout("root %p inode %p ino %llx.%llx\n", res,
13532b0143b5SDavid Howells 	     d_inode(res), ceph_vinop(d_inode(res)));
135482995cc6SDavid Howells 	fc->root = fsc->sb->s_root;
135582995cc6SDavid Howells 	return 0;
135616725b9dSSage Weil 
135716725b9dSSage Weil out_splat:
135897820058SXiubo Li 	if (!ceph_mdsmap_is_cluster_available(fsc->mdsc->mdsmap)) {
135997820058SXiubo Li 		pr_info("No mds server is up or the cluster is laggy\n");
136097820058SXiubo Li 		err = -EHOSTUNREACH;
136197820058SXiubo Li 	}
136297820058SXiubo Li 
13633d14c5d2SYehuda Sadeh 	ceph_mdsc_close_sessions(fsc->mdsc);
13643981f2e2SAl Viro 	deactivate_locked_super(sb);
136516725b9dSSage Weil 	goto out_final;
136616725b9dSSage Weil 
136716725b9dSSage Weil out:
13683d14c5d2SYehuda Sadeh 	destroy_fs_client(fsc);
136916725b9dSSage Weil out_final:
137082995cc6SDavid Howells 	dout("ceph_get_tree fail %d\n", err);
137182995cc6SDavid Howells 	return err;
137282995cc6SDavid Howells }
137382995cc6SDavid Howells 
ceph_free_fc(struct fs_context * fc)137482995cc6SDavid Howells static void ceph_free_fc(struct fs_context *fc)
137582995cc6SDavid Howells {
137682995cc6SDavid Howells 	struct ceph_parse_opts_ctx *pctx = fc->fs_private;
137782995cc6SDavid Howells 
137882995cc6SDavid Howells 	if (pctx) {
137982995cc6SDavid Howells 		destroy_mount_options(pctx->opts);
138082995cc6SDavid Howells 		ceph_destroy_options(pctx->copts);
138182995cc6SDavid Howells 		kfree(pctx);
138282995cc6SDavid Howells 	}
138382995cc6SDavid Howells }
138482995cc6SDavid Howells 
ceph_reconfigure_fc(struct fs_context * fc)138582995cc6SDavid Howells static int ceph_reconfigure_fc(struct fs_context *fc)
138682995cc6SDavid Howells {
13876b5717bdSJeff Layton 	int err;
13882ccb4546SJeff Layton 	struct ceph_parse_opts_ctx *pctx = fc->fs_private;
13892ccb4546SJeff Layton 	struct ceph_mount_options *fsopt = pctx->opts;
13906b5717bdSJeff Layton 	struct super_block *sb = fc->root->d_sb;
1391985b9ee8SXiubo Li 	struct ceph_fs_client *fsc = ceph_sb_to_fs_client(sb);
13926b5717bdSJeff Layton 
13936b5717bdSJeff Layton 	err = ceph_apply_test_dummy_encryption(sb, fc, fsopt);
13946b5717bdSJeff Layton 	if (err)
13956b5717bdSJeff Layton 		return err;
13962ccb4546SJeff Layton 
13972ccb4546SJeff Layton 	if (fsopt->flags & CEPH_MOUNT_OPT_ASYNC_DIROPS)
13982ccb4546SJeff Layton 		ceph_set_mount_opt(fsc, ASYNC_DIROPS);
13992ccb4546SJeff Layton 	else
14002ccb4546SJeff Layton 		ceph_clear_mount_opt(fsc, ASYNC_DIROPS);
14012ccb4546SJeff Layton 
140203bc06c7SJeff Layton 	if (fsopt->flags & CEPH_MOUNT_OPT_SPARSEREAD)
140303bc06c7SJeff Layton 		ceph_set_mount_opt(fsc, SPARSEREAD);
140403bc06c7SJeff Layton 	else
140503bc06c7SJeff Layton 		ceph_clear_mount_opt(fsc, SPARSEREAD);
140603bc06c7SJeff Layton 
14072167f2ccSVenky Shankar 	if (strcmp_null(fsc->mount_options->mon_addr, fsopt->mon_addr)) {
14082167f2ccSVenky Shankar 		kfree(fsc->mount_options->mon_addr);
14092167f2ccSVenky Shankar 		fsc->mount_options->mon_addr = fsopt->mon_addr;
14102167f2ccSVenky Shankar 		fsopt->mon_addr = NULL;
14112167f2ccSVenky Shankar 		pr_notice("ceph: monitor addresses recorded, but not used for reconnection");
14122167f2ccSVenky Shankar 	}
14132167f2ccSVenky Shankar 
14146b5717bdSJeff Layton 	sync_filesystem(sb);
141582995cc6SDavid Howells 	return 0;
141682995cc6SDavid Howells }
141782995cc6SDavid Howells 
141882995cc6SDavid Howells static const struct fs_context_operations ceph_context_ops = {
141982995cc6SDavid Howells 	.free		= ceph_free_fc,
142082995cc6SDavid Howells 	.parse_param	= ceph_parse_mount_param,
142182995cc6SDavid Howells 	.get_tree	= ceph_get_tree,
142282995cc6SDavid Howells 	.reconfigure	= ceph_reconfigure_fc,
142382995cc6SDavid Howells };
142482995cc6SDavid Howells 
142582995cc6SDavid Howells /*
142682995cc6SDavid Howells  * Set up the filesystem mount context.
142782995cc6SDavid Howells  */
ceph_init_fs_context(struct fs_context * fc)142882995cc6SDavid Howells static int ceph_init_fs_context(struct fs_context *fc)
142982995cc6SDavid Howells {
143082995cc6SDavid Howells 	struct ceph_parse_opts_ctx *pctx;
143182995cc6SDavid Howells 	struct ceph_mount_options *fsopt;
143282995cc6SDavid Howells 
143382995cc6SDavid Howells 	pctx = kzalloc(sizeof(*pctx), GFP_KERNEL);
143482995cc6SDavid Howells 	if (!pctx)
143582995cc6SDavid Howells 		return -ENOMEM;
143682995cc6SDavid Howells 
143782995cc6SDavid Howells 	pctx->copts = ceph_alloc_options();
143882995cc6SDavid Howells 	if (!pctx->copts)
143982995cc6SDavid Howells 		goto nomem;
144082995cc6SDavid Howells 
144182995cc6SDavid Howells 	pctx->opts = kzalloc(sizeof(*pctx->opts), GFP_KERNEL);
144282995cc6SDavid Howells 	if (!pctx->opts)
144382995cc6SDavid Howells 		goto nomem;
144482995cc6SDavid Howells 
144582995cc6SDavid Howells 	fsopt = pctx->opts;
144682995cc6SDavid Howells 	fsopt->flags = CEPH_MOUNT_OPT_DEFAULT;
144782995cc6SDavid Howells 
144882995cc6SDavid Howells 	fsopt->wsize = CEPH_MAX_WRITE_SIZE;
144982995cc6SDavid Howells 	fsopt->rsize = CEPH_MAX_READ_SIZE;
145082995cc6SDavid Howells 	fsopt->rasize = CEPH_RASIZE_DEFAULT;
145182995cc6SDavid Howells 	fsopt->snapdir_name = kstrdup(CEPH_SNAPDIRNAME_DEFAULT, GFP_KERNEL);
145282995cc6SDavid Howells 	if (!fsopt->snapdir_name)
145382995cc6SDavid Howells 		goto nomem;
145482995cc6SDavid Howells 
145582995cc6SDavid Howells 	fsopt->caps_wanted_delay_min = CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT;
145682995cc6SDavid Howells 	fsopt->caps_wanted_delay_max = CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT;
145782995cc6SDavid Howells 	fsopt->max_readdir = CEPH_MAX_READDIR_DEFAULT;
145882995cc6SDavid Howells 	fsopt->max_readdir_bytes = CEPH_MAX_READDIR_BYTES_DEFAULT;
145982995cc6SDavid Howells 	fsopt->congestion_kb = default_congestion_kb();
146082995cc6SDavid Howells 
14613b20bc2fSXiubo Li #ifdef CONFIG_CEPH_FS_POSIX_ACL
14623b20bc2fSXiubo Li 	fc->sb_flags |= SB_POSIXACL;
14633b20bc2fSXiubo Li #endif
14643b20bc2fSXiubo Li 
146582995cc6SDavid Howells 	fc->fs_private = pctx;
146682995cc6SDavid Howells 	fc->ops = &ceph_context_ops;
146782995cc6SDavid Howells 	return 0;
146882995cc6SDavid Howells 
146982995cc6SDavid Howells nomem:
147082995cc6SDavid Howells 	destroy_mount_options(pctx->opts);
147182995cc6SDavid Howells 	ceph_destroy_options(pctx->copts);
147282995cc6SDavid Howells 	kfree(pctx);
147382995cc6SDavid Howells 	return -ENOMEM;
147416725b9dSSage Weil }
147516725b9dSSage Weil 
1476e3dfcab2SXiubo Li /*
1477e3dfcab2SXiubo Li  * Return true if it successfully increases the blocker counter,
1478e3dfcab2SXiubo Li  * or false if the mdsc is in stopping and flushed state.
1479e3dfcab2SXiubo Li  */
__inc_stopping_blocker(struct ceph_mds_client * mdsc)1480e3dfcab2SXiubo Li static bool __inc_stopping_blocker(struct ceph_mds_client *mdsc)
1481e3dfcab2SXiubo Li {
1482e3dfcab2SXiubo Li 	spin_lock(&mdsc->stopping_lock);
1483e3dfcab2SXiubo Li 	if (mdsc->stopping >= CEPH_MDSC_STOPPING_FLUSHING) {
1484e3dfcab2SXiubo Li 		spin_unlock(&mdsc->stopping_lock);
1485e3dfcab2SXiubo Li 		return false;
1486e3dfcab2SXiubo Li 	}
1487e3dfcab2SXiubo Li 	atomic_inc(&mdsc->stopping_blockers);
1488e3dfcab2SXiubo Li 	spin_unlock(&mdsc->stopping_lock);
1489e3dfcab2SXiubo Li 	return true;
1490e3dfcab2SXiubo Li }
1491e3dfcab2SXiubo Li 
__dec_stopping_blocker(struct ceph_mds_client * mdsc)1492e3dfcab2SXiubo Li static void __dec_stopping_blocker(struct ceph_mds_client *mdsc)
1493e3dfcab2SXiubo Li {
1494e3dfcab2SXiubo Li 	spin_lock(&mdsc->stopping_lock);
1495e3dfcab2SXiubo Li 	if (!atomic_dec_return(&mdsc->stopping_blockers) &&
1496e3dfcab2SXiubo Li 	    mdsc->stopping >= CEPH_MDSC_STOPPING_FLUSHING)
1497e3dfcab2SXiubo Li 		complete_all(&mdsc->stopping_waiter);
1498e3dfcab2SXiubo Li 	spin_unlock(&mdsc->stopping_lock);
1499e3dfcab2SXiubo Li }
1500e3dfcab2SXiubo Li 
1501e3dfcab2SXiubo Li /* For metadata IO requests */
ceph_inc_mds_stopping_blocker(struct ceph_mds_client * mdsc,struct ceph_mds_session * session)1502e3dfcab2SXiubo Li bool ceph_inc_mds_stopping_blocker(struct ceph_mds_client *mdsc,
1503e3dfcab2SXiubo Li 				   struct ceph_mds_session *session)
1504e3dfcab2SXiubo Li {
1505e3dfcab2SXiubo Li 	mutex_lock(&session->s_mutex);
1506e3dfcab2SXiubo Li 	inc_session_sequence(session);
1507e3dfcab2SXiubo Li 	mutex_unlock(&session->s_mutex);
1508e3dfcab2SXiubo Li 
1509e3dfcab2SXiubo Li 	return __inc_stopping_blocker(mdsc);
1510e3dfcab2SXiubo Li }
1511e3dfcab2SXiubo Li 
ceph_dec_mds_stopping_blocker(struct ceph_mds_client * mdsc)1512e3dfcab2SXiubo Li void ceph_dec_mds_stopping_blocker(struct ceph_mds_client *mdsc)
1513e3dfcab2SXiubo Li {
1514e3dfcab2SXiubo Li 	__dec_stopping_blocker(mdsc);
1515e3dfcab2SXiubo Li }
1516e3dfcab2SXiubo Li 
15171464de9fSXiubo Li /* For data IO requests */
ceph_inc_osd_stopping_blocker(struct ceph_mds_client * mdsc)15181464de9fSXiubo Li bool ceph_inc_osd_stopping_blocker(struct ceph_mds_client *mdsc)
15191464de9fSXiubo Li {
15201464de9fSXiubo Li 	return __inc_stopping_blocker(mdsc);
15211464de9fSXiubo Li }
15221464de9fSXiubo Li 
ceph_dec_osd_stopping_blocker(struct ceph_mds_client * mdsc)15231464de9fSXiubo Li void ceph_dec_osd_stopping_blocker(struct ceph_mds_client *mdsc)
15241464de9fSXiubo Li {
15251464de9fSXiubo Li 	__dec_stopping_blocker(mdsc);
15261464de9fSXiubo Li }
15271464de9fSXiubo Li 
ceph_kill_sb(struct super_block * s)152816725b9dSSage Weil static void ceph_kill_sb(struct super_block *s)
152916725b9dSSage Weil {
1530985b9ee8SXiubo Li 	struct ceph_fs_client *fsc = ceph_sb_to_fs_client(s);
1531e3dfcab2SXiubo Li 	struct ceph_mds_client *mdsc = fsc->mdsc;
1532e3dfcab2SXiubo Li 	bool wait;
1533e4d27509SChristoph Hellwig 
153416725b9dSSage Weil 	dout("kill_sb %p\n", s);
1535e4d27509SChristoph Hellwig 
1536e3dfcab2SXiubo Li 	ceph_mdsc_pre_umount(mdsc);
1537a57d9064SYan, Zheng 	flush_fs_workqueues(fsc);
1538a57d9064SYan, Zheng 
1539e7e607bdSXiubo Li 	/*
1540e7e607bdSXiubo Li 	 * Though the kill_anon_super() will finally trigger the
1541e3dfcab2SXiubo Li 	 * sync_filesystem() anyway, we still need to do it here and
1542e3dfcab2SXiubo Li 	 * then bump the stage of shutdown. This will allow us to
1543e3dfcab2SXiubo Li 	 * drop any further message, which will increase the inodes'
1544e3dfcab2SXiubo Li 	 * i_count reference counters but makes no sense any more,
1545e3dfcab2SXiubo Li 	 * from MDSs.
1546e3dfcab2SXiubo Li 	 *
1547e3dfcab2SXiubo Li 	 * Without this when evicting the inodes it may fail in the
1548e3dfcab2SXiubo Li 	 * kill_anon_super(), which will trigger a warning when
1549e3dfcab2SXiubo Li 	 * destroying the fscrypt keyring and then possibly trigger
1550e3dfcab2SXiubo Li 	 * a further crash in ceph module when the iput() tries to
1551e3dfcab2SXiubo Li 	 * evict the inodes later.
1552e7e607bdSXiubo Li 	 */
1553e7e607bdSXiubo Li 	sync_filesystem(s);
1554e7e607bdSXiubo Li 
1555e3dfcab2SXiubo Li 	spin_lock(&mdsc->stopping_lock);
1556e3dfcab2SXiubo Li 	mdsc->stopping = CEPH_MDSC_STOPPING_FLUSHING;
1557e3dfcab2SXiubo Li 	wait = !!atomic_read(&mdsc->stopping_blockers);
1558e3dfcab2SXiubo Li 	spin_unlock(&mdsc->stopping_lock);
1559e7e607bdSXiubo Li 
1560e3dfcab2SXiubo Li 	if (wait && atomic_read(&mdsc->stopping_blockers)) {
1561e3dfcab2SXiubo Li 		long timeleft = wait_for_completion_killable_timeout(
1562e3dfcab2SXiubo Li 					&mdsc->stopping_waiter,
1563e3dfcab2SXiubo Li 					fsc->client->options->mount_timeout);
1564e3dfcab2SXiubo Li 		if (!timeleft) /* timed out */
1565e3dfcab2SXiubo Li 			pr_warn("umount timed out, %ld\n", timeleft);
1566e3dfcab2SXiubo Li 		else if (timeleft < 0) /* killed */
1567e3dfcab2SXiubo Li 			pr_warn("umount was killed, %ld\n", timeleft);
1568e3dfcab2SXiubo Li 	}
1569e3dfcab2SXiubo Li 
1570e3dfcab2SXiubo Li 	mdsc->stopping = CEPH_MDSC_STOPPING_FLUSHED;
1571470a5c77SJeff Layton 	kill_anon_super(s);
157262a65f36SYan, Zheng 
157362a65f36SYan, Zheng 	fsc->client->extra_mon_dispatch = NULL;
157462a65f36SYan, Zheng 	ceph_fs_debugfs_cleanup(fsc);
157562a65f36SYan, Zheng 
15761d8f8360SYan, Zheng 	ceph_fscache_unregister_fs(fsc);
15771d8f8360SYan, Zheng 
15783d14c5d2SYehuda Sadeh 	destroy_fs_client(fsc);
157916725b9dSSage Weil }
158016725b9dSSage Weil 
158116725b9dSSage Weil static struct file_system_type ceph_fs_type = {
158216725b9dSSage Weil 	.owner		= THIS_MODULE,
158316725b9dSSage Weil 	.name		= "ceph",
158482995cc6SDavid Howells 	.init_fs_context = ceph_init_fs_context,
158516725b9dSSage Weil 	.kill_sb	= ceph_kill_sb,
158616725b9dSSage Weil 	.fs_flags	= FS_RENAME_DOES_D_MOVE,
158716725b9dSSage Weil };
15887f78e035SEric W. Biederman MODULE_ALIAS_FS("ceph");
158916725b9dSSage Weil 
ceph_force_reconnect(struct super_block * sb)1590d468e729SYan, Zheng int ceph_force_reconnect(struct super_block *sb)
1591d468e729SYan, Zheng {
1592985b9ee8SXiubo Li 	struct ceph_fs_client *fsc = ceph_sb_to_fs_client(sb);
1593d468e729SYan, Zheng 	int err = 0;
1594d468e729SYan, Zheng 
159550c9132dSJeff Layton 	fsc->mount_state = CEPH_MOUNT_RECOVER;
159650c9132dSJeff Layton 	__ceph_umount_begin(fsc);
1597d468e729SYan, Zheng 
1598d468e729SYan, Zheng 	/* Make sure all page caches get invalidated.
1599d468e729SYan, Zheng 	 * see remove_session_caps_cb() */
1600d468e729SYan, Zheng 	flush_workqueue(fsc->inode_wq);
1601d468e729SYan, Zheng 
16020b98acd6SIlya Dryomov 	/* In case that we were blocklisted. This also reset
1603d468e729SYan, Zheng 	 * all mon/osd connections */
1604d468e729SYan, Zheng 	ceph_reset_client_addr(fsc->client);
1605d468e729SYan, Zheng 
1606d468e729SYan, Zheng 	ceph_osdc_clear_abort_err(&fsc->client->osdc);
1607131d7eb4SYan, Zheng 
16080b98acd6SIlya Dryomov 	fsc->blocklisted = false;
1609d468e729SYan, Zheng 	fsc->mount_state = CEPH_MOUNT_MOUNTED;
1610d468e729SYan, Zheng 
1611d468e729SYan, Zheng 	if (sb->s_root) {
1612d468e729SYan, Zheng 		err = __ceph_do_getattr(d_inode(sb->s_root), NULL,
1613d468e729SYan, Zheng 					CEPH_STAT_CAP_INODE, true);
1614d468e729SYan, Zheng 	}
1615d468e729SYan, Zheng 	return err;
1616d468e729SYan, Zheng }
1617d468e729SYan, Zheng 
init_ceph(void)161816725b9dSSage Weil static int __init init_ceph(void)
161916725b9dSSage Weil {
16203d14c5d2SYehuda Sadeh 	int ret = init_caches();
162116725b9dSSage Weil 	if (ret)
16223d14c5d2SYehuda Sadeh 		goto out;
162316725b9dSSage Weil 
1624eb13e832SYan, Zheng 	ceph_flock_init();
162516725b9dSSage Weil 	ret = register_filesystem(&ceph_fs_type);
162616725b9dSSage Weil 	if (ret)
1627d0f191d2SDavid Disseldorp 		goto out_caches;
162816725b9dSSage Weil 
16293d14c5d2SYehuda Sadeh 	pr_info("loaded (mds proto %d)\n", CEPH_MDSC_PROTOCOL);
16303d14c5d2SYehuda Sadeh 
163116725b9dSSage Weil 	return 0;
163216725b9dSSage Weil 
1633d0f191d2SDavid Disseldorp out_caches:
163416725b9dSSage Weil 	destroy_caches();
163516725b9dSSage Weil out:
163616725b9dSSage Weil 	return ret;
163716725b9dSSage Weil }
163816725b9dSSage Weil 
exit_ceph(void)163916725b9dSSage Weil static void __exit exit_ceph(void)
164016725b9dSSage Weil {
164116725b9dSSage Weil 	dout("exit_ceph\n");
164216725b9dSSage Weil 	unregister_filesystem(&ceph_fs_type);
164316725b9dSSage Weil 	destroy_caches();
164416725b9dSSage Weil }
164516725b9dSSage Weil 
param_set_metrics(const char * val,const struct kernel_param * kp)164618f473b3SXiubo Li static int param_set_metrics(const char *val, const struct kernel_param *kp)
164718f473b3SXiubo Li {
164818f473b3SXiubo Li 	struct ceph_fs_client *fsc;
164918f473b3SXiubo Li 	int ret;
165018f473b3SXiubo Li 
165118f473b3SXiubo Li 	ret = param_set_bool(val, kp);
165218f473b3SXiubo Li 	if (ret) {
165318f473b3SXiubo Li 		pr_err("Failed to parse sending metrics switch value '%s'\n",
165418f473b3SXiubo Li 		       val);
165518f473b3SXiubo Li 		return ret;
165618f473b3SXiubo Li 	} else if (!disable_send_metrics) {
165718f473b3SXiubo Li 		// wake up all the mds clients
165818f473b3SXiubo Li 		spin_lock(&ceph_fsc_lock);
165918f473b3SXiubo Li 		list_for_each_entry(fsc, &ceph_fsc_list, metric_wakeup) {
166018f473b3SXiubo Li 			metric_schedule_delayed(&fsc->mdsc->metric);
166118f473b3SXiubo Li 		}
166218f473b3SXiubo Li 		spin_unlock(&ceph_fsc_lock);
166318f473b3SXiubo Li 	}
166418f473b3SXiubo Li 
166518f473b3SXiubo Li 	return 0;
166618f473b3SXiubo Li }
166718f473b3SXiubo Li 
166818f473b3SXiubo Li static const struct kernel_param_ops param_ops_metrics = {
166918f473b3SXiubo Li 	.set = param_set_metrics,
167018f473b3SXiubo Li 	.get = param_get_bool,
167118f473b3SXiubo Li };
167218f473b3SXiubo Li 
167318f473b3SXiubo Li bool disable_send_metrics = false;
167418f473b3SXiubo Li module_param_cb(disable_send_metrics, &param_ops_metrics, &disable_send_metrics, 0644);
167518f473b3SXiubo Li MODULE_PARM_DESC(disable_send_metrics, "Enable sending perf metrics to ceph cluster (default: on)");
167618f473b3SXiubo Li 
1677adbed05eSVenky Shankar /* for both v1 and v2 syntax */
1678adbed05eSVenky Shankar static bool mount_support = true;
1679adbed05eSVenky Shankar static const struct kernel_param_ops param_ops_mount_syntax = {
1680adbed05eSVenky Shankar 	.get = param_get_bool,
1681adbed05eSVenky Shankar };
1682adbed05eSVenky Shankar module_param_cb(mount_syntax_v1, &param_ops_mount_syntax, &mount_support, 0444);
1683adbed05eSVenky Shankar module_param_cb(mount_syntax_v2, &param_ops_mount_syntax, &mount_support, 0444);
1684adbed05eSVenky Shankar 
168516725b9dSSage Weil module_init(init_ceph);
168616725b9dSSage Weil module_exit(exit_ceph);
168716725b9dSSage Weil 
168816725b9dSSage Weil MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
168916725b9dSSage Weil MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
169016725b9dSSage Weil MODULE_AUTHOR("Patience Warnick <patience@newdream.net>");
169116725b9dSSage Weil MODULE_DESCRIPTION("Ceph filesystem for Linux");
169216725b9dSSage Weil MODULE_LICENSE("GPL");
1693