Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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