blob: 01be7c1bc4c686c45f24f01a4a24642722aa9dac [file] [log] [blame]
Thomas Gleixner09c434b2019-05-19 13:08:20 +01001// SPDX-License-Identifier: GPL-2.0-only
Sage Weil16725b92009-10-06 11:31:07 -07002
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07003#include <linux/ceph/ceph_debug.h>
Sage Weil16725b92009-10-06 11:31:07 -07004
5#include <linux/backing-dev.h>
Sage Weilc309f0a2010-06-30 21:34:01 -07006#include <linux/ctype.h>
Sage Weil16725b92009-10-06 11:31:07 -07007#include <linux/fs.h>
8#include <linux/inet.h>
9#include <linux/in6.h>
10#include <linux/module.h>
11#include <linux/mount.h>
12#include <linux/parser.h>
Sage Weil16725b92009-10-06 11:31:07 -070013#include <linux/sched.h>
14#include <linux/seq_file.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Sage Weil16725b92009-10-06 11:31:07 -070016#include <linux/statfs.h>
17#include <linux/string.h>
Sage Weil16725b92009-10-06 11:31:07 -070018
Sage Weil16725b92009-10-06 11:31:07 -070019#include "super.h"
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070020#include "mds_client.h"
Milosz Tanski99ccbd22013-08-21 17:29:54 -040021#include "cache.h"
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070022
Sage Weil1fe60e52012-07-30 16:23:22 -070023#include <linux/ceph/ceph_features.h>
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070024#include <linux/ceph/decode.h>
25#include <linux/ceph/mon_client.h>
26#include <linux/ceph/auth.h>
27#include <linux/ceph/debugfs.h>
Sage Weil16725b92009-10-06 11:31:07 -070028
29/*
30 * Ceph superblock operations
31 *
32 * Handle the basics of mounting, unmounting.
33 */
34
Sage Weil16725b92009-10-06 11:31:07 -070035/*
36 * super ops
37 */
38static void ceph_put_super(struct super_block *s)
39{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070040 struct ceph_fs_client *fsc = ceph_sb_to_client(s);
Sage Weil16725b92009-10-06 11:31:07 -070041
42 dout("put_super\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070043 ceph_mdsc_close_sessions(fsc->mdsc);
Sage Weil16725b92009-10-06 11:31:07 -070044}
45
46static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf)
47{
David Howells2b0143b2015-03-17 22:25:59 +000048 struct ceph_fs_client *fsc = ceph_inode_to_client(d_inode(dentry));
Luis Henriques73fb0942018-05-28 18:37:40 +010049 struct ceph_mon_client *monc = &fsc->client->monc;
Sage Weil16725b92009-10-06 11:31:07 -070050 struct ceph_statfs st;
51 u64 fsid;
52 int err;
Douglas Fuller06d74372017-08-16 10:19:27 -040053 u64 data_pool;
54
55 if (fsc->mdsc->mdsmap->m_num_data_pg_pools == 1) {
56 data_pool = fsc->mdsc->mdsmap->m_data_pg_pools[0];
57 } else {
58 data_pool = CEPH_NOPOOL;
59 }
Sage Weil16725b92009-10-06 11:31:07 -070060
61 dout("statfs\n");
Luis Henriques73fb0942018-05-28 18:37:40 +010062 err = ceph_monc_do_statfs(monc, data_pool, &st);
Sage Weil16725b92009-10-06 11:31:07 -070063 if (err < 0)
64 return err;
65
66 /* fill in kstatfs */
67 buf->f_type = CEPH_SUPER_MAGIC; /* ?? */
68
69 /*
70 * express utilization in terms of large blocks to avoid
71 * overflow on 32-bit machines.
Sage Weil92a49fb2013-02-22 15:31:00 -080072 *
73 * NOTE: for the time being, we make bsize == frsize to humor
74 * not-yet-ancient versions of glibc that are broken.
75 * Someday, we will probably want to report a real block
76 * size... whatever that may mean for a network file system!
Sage Weil16725b92009-10-06 11:31:07 -070077 */
78 buf->f_bsize = 1 << CEPH_BLOCK_SHIFT;
Sage Weil92a49fb2013-02-22 15:31:00 -080079 buf->f_frsize = 1 << CEPH_BLOCK_SHIFT;
Luis Henriques9122eed2018-01-31 10:53:13 +000080
81 /*
82 * By default use root quota for stats; fallback to overall filesystem
83 * usage if using 'noquotadf' mount option or if the root dir doesn't
84 * have max_bytes quota set.
85 */
86 if (ceph_test_mount_opt(fsc, NOQUOTADF) ||
87 !ceph_quota_update_statfs(fsc, buf)) {
88 buf->f_blocks = le64_to_cpu(st.kb) >> (CEPH_BLOCK_SHIFT-10);
89 buf->f_bfree = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);
90 buf->f_bavail = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);
91 }
Sage Weil16725b92009-10-06 11:31:07 -070092
93 buf->f_files = le64_to_cpu(st.num_objects);
94 buf->f_ffree = -1;
Sage Weil558d3492010-06-01 12:51:12 -070095 buf->f_namelen = NAME_MAX;
Sage Weil16725b92009-10-06 11:31:07 -070096
Jeff Layton080a3302017-10-23 10:58:40 -040097 /* Must convert the fsid, for consistent values across arches */
Luis Henriques73fb0942018-05-28 18:37:40 +010098 mutex_lock(&monc->mutex);
99 fsid = le64_to_cpu(*(__le64 *)(&monc->monmap->fsid)) ^
100 le64_to_cpu(*((__le64 *)&monc->monmap->fsid + 1));
101 mutex_unlock(&monc->mutex);
102
Sage Weil16725b92009-10-06 11:31:07 -0700103 buf->f_fsid.val[0] = fsid & 0xffffffff;
104 buf->f_fsid.val[1] = fsid >> 32;
105
106 return 0;
107}
108
109
Sage Weil2d9c98a2010-07-30 09:38:13 -0700110static int ceph_sync_fs(struct super_block *sb, int wait)
Sage Weil16725b92009-10-06 11:31:07 -0700111{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700112 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
Sage Weil2d9c98a2010-07-30 09:38:13 -0700113
114 if (!wait) {
115 dout("sync_fs (non-blocking)\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700116 ceph_flush_dirty_caps(fsc->mdsc);
Sage Weil2d9c98a2010-07-30 09:38:13 -0700117 dout("sync_fs (non-blocking) done\n");
118 return 0;
119 }
120
121 dout("sync_fs (blocking)\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700122 ceph_osdc_sync(&fsc->client->osdc);
123 ceph_mdsc_sync(fsc->mdsc);
Sage Weil2d9c98a2010-07-30 09:38:13 -0700124 dout("sync_fs (blocking) done\n");
Sage Weil16725b92009-10-06 11:31:07 -0700125 return 0;
126}
127
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700128/*
129 * mount options
130 */
131enum {
132 Opt_wsize,
133 Opt_rsize,
Sage Weil83817e32011-08-04 08:03:44 -0700134 Opt_rasize,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700135 Opt_caps_wanted_delay_min,
136 Opt_caps_wanted_delay_max,
Yan, Zhengfe330322019-02-01 14:57:15 +0800137 Opt_caps_max,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700138 Opt_readdir_max_entries,
139 Opt_readdir_max_bytes,
140 Opt_congestion_kb,
141 Opt_last_int,
142 /* int args above */
143 Opt_snapdirname,
Yan, Zheng430afba2016-07-08 11:25:38 +0800144 Opt_mds_namespace,
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800145 Opt_fscache_uniq,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700146 Opt_last_string,
147 /* string args above */
148 Opt_dirstat,
149 Opt_nodirstat,
150 Opt_rbytes,
151 Opt_norbytes,
Alex Eldercffaba12012-02-15 07:43:54 -0600152 Opt_asyncreaddir,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700153 Opt_noasyncreaddir,
Sage Weila40dc6c2012-01-10 09:12:55 -0800154 Opt_dcache,
155 Opt_nodcache,
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800156 Opt_ino32,
Alex Eldercffaba12012-02-15 07:43:54 -0600157 Opt_noino32,
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400158 Opt_fscache,
Sage Weil45195e42014-02-16 10:05:29 -0800159 Opt_nofscache,
Yan, Zheng10183a62015-04-27 15:33:28 +0800160 Opt_poolperm,
161 Opt_nopoolperm,
Yan, Zhenge9e427f2016-11-10 16:02:06 +0800162 Opt_require_active_mds,
163 Opt_norequire_active_mds,
Sage Weil45195e42014-02-16 10:05:29 -0800164#ifdef CONFIG_CEPH_FS_POSIX_ACL
165 Opt_acl,
166#endif
Yan, Zheng10183a62015-04-27 15:33:28 +0800167 Opt_noacl,
Luis Henriques9122eed2018-01-31 10:53:13 +0000168 Opt_quotadf,
169 Opt_noquotadf,
Luis Henriquesea4cdc52018-10-15 16:46:00 +0100170 Opt_copyfrom,
171 Opt_nocopyfrom,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700172};
173
174static match_table_t fsopt_tokens = {
175 {Opt_wsize, "wsize=%d"},
176 {Opt_rsize, "rsize=%d"},
Sage Weil83817e32011-08-04 08:03:44 -0700177 {Opt_rasize, "rasize=%d"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700178 {Opt_caps_wanted_delay_min, "caps_wanted_delay_min=%d"},
179 {Opt_caps_wanted_delay_max, "caps_wanted_delay_max=%d"},
Yan, Zhengfe330322019-02-01 14:57:15 +0800180 {Opt_caps_max, "caps_max=%d"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700181 {Opt_readdir_max_entries, "readdir_max_entries=%d"},
182 {Opt_readdir_max_bytes, "readdir_max_bytes=%d"},
183 {Opt_congestion_kb, "write_congestion_kb=%d"},
184 /* int args above */
185 {Opt_snapdirname, "snapdirname=%s"},
Yan, Zheng430afba2016-07-08 11:25:38 +0800186 {Opt_mds_namespace, "mds_namespace=%s"},
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800187 {Opt_fscache_uniq, "fsc=%s"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700188 /* string args above */
189 {Opt_dirstat, "dirstat"},
190 {Opt_nodirstat, "nodirstat"},
191 {Opt_rbytes, "rbytes"},
192 {Opt_norbytes, "norbytes"},
Alex Eldercffaba12012-02-15 07:43:54 -0600193 {Opt_asyncreaddir, "asyncreaddir"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700194 {Opt_noasyncreaddir, "noasyncreaddir"},
Sage Weila40dc6c2012-01-10 09:12:55 -0800195 {Opt_dcache, "dcache"},
196 {Opt_nodcache, "nodcache"},
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800197 {Opt_ino32, "ino32"},
Alex Eldercffaba12012-02-15 07:43:54 -0600198 {Opt_noino32, "noino32"},
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400199 {Opt_fscache, "fsc"},
200 {Opt_nofscache, "nofsc"},
Yan, Zheng10183a62015-04-27 15:33:28 +0800201 {Opt_poolperm, "poolperm"},
202 {Opt_nopoolperm, "nopoolperm"},
Yan, Zhenge9e427f2016-11-10 16:02:06 +0800203 {Opt_require_active_mds, "require_active_mds"},
204 {Opt_norequire_active_mds, "norequire_active_mds"},
Sage Weil45195e42014-02-16 10:05:29 -0800205#ifdef CONFIG_CEPH_FS_POSIX_ACL
206 {Opt_acl, "acl"},
207#endif
208 {Opt_noacl, "noacl"},
Luis Henriques9122eed2018-01-31 10:53:13 +0000209 {Opt_quotadf, "quotadf"},
210 {Opt_noquotadf, "noquotadf"},
Luis Henriquesea4cdc52018-10-15 16:46:00 +0100211 {Opt_copyfrom, "copyfrom"},
212 {Opt_nocopyfrom, "nocopyfrom"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700213 {-1, NULL}
214};
215
216static int parse_fsopt_token(char *c, void *private)
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800217{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700218 struct ceph_mount_options *fsopt = private;
219 substring_t argstr[MAX_OPT_ARGS];
220 int token, intval, ret;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800221
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700222 token = match_token((char *)c, fsopt_tokens, argstr);
223 if (token < 0)
224 return -EINVAL;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800225
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700226 if (token < Opt_last_int) {
227 ret = match_int(&argstr[0], &intval);
228 if (ret < 0) {
Ilya Dryomov2f56b6b2018-06-27 16:38:13 +0200229 pr_err("bad option arg (not int) at '%s'\n", c);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700230 return ret;
231 }
232 dout("got int token %d val %d\n", token, intval);
233 } else if (token > Opt_last_int && token < Opt_last_string) {
234 dout("got string token %d val %s\n", token,
235 argstr[0].from);
236 } else {
237 dout("got token %d\n", token);
238 }
239
240 switch (token) {
241 case Opt_snapdirname:
242 kfree(fsopt->snapdir_name);
243 fsopt->snapdir_name = kstrndup(argstr[0].from,
244 argstr[0].to-argstr[0].from,
245 GFP_KERNEL);
246 if (!fsopt->snapdir_name)
247 return -ENOMEM;
248 break;
Yan, Zheng235a0982016-03-30 17:18:34 +0800249 case Opt_mds_namespace:
Chengguang Xu937441f2018-02-06 08:25:55 +0800250 kfree(fsopt->mds_namespace);
Yan, Zheng430afba2016-07-08 11:25:38 +0800251 fsopt->mds_namespace = kstrndup(argstr[0].from,
252 argstr[0].to-argstr[0].from,
253 GFP_KERNEL);
254 if (!fsopt->mds_namespace)
255 return -ENOMEM;
Yan, Zheng235a0982016-03-30 17:18:34 +0800256 break;
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800257 case Opt_fscache_uniq:
Chengguang Xu937441f2018-02-06 08:25:55 +0800258 kfree(fsopt->fscache_uniq);
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800259 fsopt->fscache_uniq = kstrndup(argstr[0].from,
260 argstr[0].to-argstr[0].from,
261 GFP_KERNEL);
262 if (!fsopt->fscache_uniq)
263 return -ENOMEM;
264 fsopt->flags |= CEPH_MOUNT_OPT_FSCACHE;
265 break;
Yan, Zheng430afba2016-07-08 11:25:38 +0800266 /* misc */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700267 case Opt_wsize:
Chengguang Xu8db0c752018-05-30 16:47:06 +0800268 if (intval < (int)PAGE_SIZE || intval > CEPH_MAX_WRITE_SIZE)
Yan, Zheng95cca2b2017-07-11 17:34:46 +0800269 return -EINVAL;
270 fsopt->wsize = ALIGN(intval, PAGE_SIZE);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700271 break;
272 case Opt_rsize:
Chengguang Xu8db0c752018-05-30 16:47:06 +0800273 if (intval < (int)PAGE_SIZE || intval > CEPH_MAX_READ_SIZE)
Yan, Zhengaa187922017-07-11 15:56:09 +0800274 return -EINVAL;
275 fsopt->rsize = ALIGN(intval, PAGE_SIZE);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700276 break;
Sage Weil83817e32011-08-04 08:03:44 -0700277 case Opt_rasize:
Yan, Zheng4214fb12017-07-11 18:49:44 +0800278 if (intval < 0)
279 return -EINVAL;
Chengguang Xuc36ed502018-05-30 10:13:11 +0800280 fsopt->rasize = ALIGN(intval, PAGE_SIZE);
Sage Weil83817e32011-08-04 08:03:44 -0700281 break;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700282 case Opt_caps_wanted_delay_min:
Yan, Zheng4214fb12017-07-11 18:49:44 +0800283 if (intval < 1)
284 return -EINVAL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700285 fsopt->caps_wanted_delay_min = intval;
286 break;
287 case Opt_caps_wanted_delay_max:
Yan, Zheng4214fb12017-07-11 18:49:44 +0800288 if (intval < 1)
289 return -EINVAL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700290 fsopt->caps_wanted_delay_max = intval;
291 break;
Yan, Zhengfe330322019-02-01 14:57:15 +0800292 case Opt_caps_max:
293 if (intval < 0)
294 return -EINVAL;
295 fsopt->caps_max = intval;
296 break;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700297 case Opt_readdir_max_entries:
Yan, Zheng4214fb12017-07-11 18:49:44 +0800298 if (intval < 1)
299 return -EINVAL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700300 fsopt->max_readdir = intval;
301 break;
302 case Opt_readdir_max_bytes:
Chengguang Xu8db0c752018-05-30 16:47:06 +0800303 if (intval < (int)PAGE_SIZE && intval != 0)
Yan, Zheng4214fb12017-07-11 18:49:44 +0800304 return -EINVAL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700305 fsopt->max_readdir_bytes = intval;
306 break;
307 case Opt_congestion_kb:
Yan, Zheng4214fb12017-07-11 18:49:44 +0800308 if (intval < 1024) /* at least 1M */
309 return -EINVAL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700310 fsopt->congestion_kb = intval;
311 break;
312 case Opt_dirstat:
313 fsopt->flags |= CEPH_MOUNT_OPT_DIRSTAT;
314 break;
315 case Opt_nodirstat:
316 fsopt->flags &= ~CEPH_MOUNT_OPT_DIRSTAT;
317 break;
318 case Opt_rbytes:
319 fsopt->flags |= CEPH_MOUNT_OPT_RBYTES;
320 break;
321 case Opt_norbytes:
322 fsopt->flags &= ~CEPH_MOUNT_OPT_RBYTES;
323 break;
Alex Eldercffaba12012-02-15 07:43:54 -0600324 case Opt_asyncreaddir:
325 fsopt->flags &= ~CEPH_MOUNT_OPT_NOASYNCREADDIR;
326 break;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700327 case Opt_noasyncreaddir:
328 fsopt->flags |= CEPH_MOUNT_OPT_NOASYNCREADDIR;
329 break;
Sage Weila40dc6c2012-01-10 09:12:55 -0800330 case Opt_dcache:
331 fsopt->flags |= CEPH_MOUNT_OPT_DCACHE;
332 break;
333 case Opt_nodcache:
334 fsopt->flags &= ~CEPH_MOUNT_OPT_DCACHE;
335 break;
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800336 case Opt_ino32:
337 fsopt->flags |= CEPH_MOUNT_OPT_INO32;
338 break;
Alex Eldercffaba12012-02-15 07:43:54 -0600339 case Opt_noino32:
340 fsopt->flags &= ~CEPH_MOUNT_OPT_INO32;
341 break;
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400342 case Opt_fscache:
343 fsopt->flags |= CEPH_MOUNT_OPT_FSCACHE;
Chengguang Xu7ae7a822018-02-07 10:27:06 +0800344 kfree(fsopt->fscache_uniq);
345 fsopt->fscache_uniq = NULL;
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400346 break;
347 case Opt_nofscache:
348 fsopt->flags &= ~CEPH_MOUNT_OPT_FSCACHE;
Chengguang Xu7ae7a822018-02-07 10:27:06 +0800349 kfree(fsopt->fscache_uniq);
350 fsopt->fscache_uniq = NULL;
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400351 break;
Yan, Zheng10183a62015-04-27 15:33:28 +0800352 case Opt_poolperm:
353 fsopt->flags &= ~CEPH_MOUNT_OPT_NOPOOLPERM;
Yan, Zheng10183a62015-04-27 15:33:28 +0800354 break;
355 case Opt_nopoolperm:
356 fsopt->flags |= CEPH_MOUNT_OPT_NOPOOLPERM;
357 break;
Yan, Zhenge9e427f2016-11-10 16:02:06 +0800358 case Opt_require_active_mds:
359 fsopt->flags &= ~CEPH_MOUNT_OPT_MOUNTWAIT;
360 break;
361 case Opt_norequire_active_mds:
362 fsopt->flags |= CEPH_MOUNT_OPT_MOUNTWAIT;
363 break;
Luis Henriques9122eed2018-01-31 10:53:13 +0000364 case Opt_quotadf:
365 fsopt->flags &= ~CEPH_MOUNT_OPT_NOQUOTADF;
366 break;
367 case Opt_noquotadf:
368 fsopt->flags |= CEPH_MOUNT_OPT_NOQUOTADF;
369 break;
Luis Henriquesea4cdc52018-10-15 16:46:00 +0100370 case Opt_copyfrom:
371 fsopt->flags &= ~CEPH_MOUNT_OPT_NOCOPYFROM;
372 break;
373 case Opt_nocopyfrom:
374 fsopt->flags |= CEPH_MOUNT_OPT_NOCOPYFROM;
375 break;
Sage Weil45195e42014-02-16 10:05:29 -0800376#ifdef CONFIG_CEPH_FS_POSIX_ACL
377 case Opt_acl:
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800378 fsopt->sb_flags |= SB_POSIXACL;
Sage Weil45195e42014-02-16 10:05:29 -0800379 break;
380#endif
381 case Opt_noacl:
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800382 fsopt->sb_flags &= ~SB_POSIXACL;
Sage Weil45195e42014-02-16 10:05:29 -0800383 break;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700384 default:
385 BUG_ON(token);
386 }
387 return 0;
388}
389
390static void destroy_mount_options(struct ceph_mount_options *args)
391{
392 dout("destroy_mount_options %p\n", args);
393 kfree(args->snapdir_name);
Yan, Zheng430afba2016-07-08 11:25:38 +0800394 kfree(args->mds_namespace);
Yan, Zheng3f384952016-04-21 11:09:55 +0800395 kfree(args->server_path);
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800396 kfree(args->fscache_uniq);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700397 kfree(args);
398}
399
400static int strcmp_null(const char *s1, const char *s2)
401{
402 if (!s1 && !s2)
403 return 0;
404 if (s1 && !s2)
405 return -1;
406 if (!s1 && s2)
407 return 1;
408 return strcmp(s1, s2);
409}
410
411static int compare_mount_options(struct ceph_mount_options *new_fsopt,
412 struct ceph_options *new_opt,
413 struct ceph_fs_client *fsc)
414{
415 struct ceph_mount_options *fsopt1 = new_fsopt;
416 struct ceph_mount_options *fsopt2 = fsc->mount_options;
417 int ofs = offsetof(struct ceph_mount_options, snapdir_name);
418 int ret;
419
420 ret = memcmp(fsopt1, fsopt2, ofs);
421 if (ret)
422 return ret;
423
424 ret = strcmp_null(fsopt1->snapdir_name, fsopt2->snapdir_name);
425 if (ret)
426 return ret;
Yan, Zheng430afba2016-07-08 11:25:38 +0800427 ret = strcmp_null(fsopt1->mds_namespace, fsopt2->mds_namespace);
428 if (ret)
429 return ret;
Yan, Zheng3f384952016-04-21 11:09:55 +0800430 ret = strcmp_null(fsopt1->server_path, fsopt2->server_path);
431 if (ret)
432 return ret;
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800433 ret = strcmp_null(fsopt1->fscache_uniq, fsopt2->fscache_uniq);
434 if (ret)
435 return ret;
Yan, Zheng3f384952016-04-21 11:09:55 +0800436
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700437 return ceph_compare_options(new_opt, fsc->client);
438}
439
440static int parse_mount_options(struct ceph_mount_options **pfsopt,
441 struct ceph_options **popt,
442 int flags, char *options,
Yan, Zheng3f384952016-04-21 11:09:55 +0800443 const char *dev_name)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700444{
445 struct ceph_mount_options *fsopt;
446 const char *dev_name_end;
Alex Elderc98f5332012-08-09 10:33:26 -0700447 int err;
448
449 if (!dev_name || !*dev_name)
450 return -EINVAL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700451
452 fsopt = kzalloc(sizeof(*fsopt), GFP_KERNEL);
453 if (!fsopt)
454 return -ENOMEM;
455
456 dout("parse_mount_options %p, dev_name '%s'\n", fsopt, dev_name);
457
Noah Watkins80db8be2011-08-22 13:49:23 -0600458 fsopt->sb_flags = flags;
459 fsopt->flags = CEPH_MOUNT_OPT_DEFAULT;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700460
Yan, Zheng95cca2b2017-07-11 17:34:46 +0800461 fsopt->wsize = CEPH_MAX_WRITE_SIZE;
Yan, Zhengaa187922017-07-11 15:56:09 +0800462 fsopt->rsize = CEPH_MAX_READ_SIZE;
Noah Watkins80db8be2011-08-22 13:49:23 -0600463 fsopt->rasize = CEPH_RASIZE_DEFAULT;
464 fsopt->snapdir_name = kstrdup(CEPH_SNAPDIRNAME_DEFAULT, GFP_KERNEL);
Sanidhya Kashyapa149bb92015-03-21 12:54:58 -0400465 if (!fsopt->snapdir_name) {
466 err = -ENOMEM;
467 goto out;
468 }
469
Sage Weil50aac4f2011-01-18 07:59:40 -0800470 fsopt->caps_wanted_delay_min = CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT;
471 fsopt->caps_wanted_delay_max = CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT;
Noah Watkins80db8be2011-08-22 13:49:23 -0600472 fsopt->max_readdir = CEPH_MAX_READDIR_DEFAULT;
473 fsopt->max_readdir_bytes = CEPH_MAX_READDIR_BYTES_DEFAULT;
474 fsopt->congestion_kb = default_congestion_kb();
475
Alex Elderc98f5332012-08-09 10:33:26 -0700476 /*
477 * Distinguish the server list from the path in "dev_name".
478 * Internally we do not include the leading '/' in the path.
479 *
480 * "dev_name" will look like:
481 * <server_spec>[,<server_spec>...]:[<path>]
482 * where
483 * <server_spec> is <ip>[:<port>]
484 * <path> is optional, but if present must begin with '/'
485 */
486 dev_name_end = strchr(dev_name, '/');
487 if (dev_name_end) {
Yan, Zhengce2728a2016-09-14 14:53:05 +0800488 if (strlen(dev_name_end) > 1) {
489 fsopt->server_path = kstrdup(dev_name_end, GFP_KERNEL);
490 if (!fsopt->server_path) {
491 err = -ENOMEM;
492 goto out;
493 }
Yan, Zheng3f384952016-04-21 11:09:55 +0800494 }
Alex Elderc98f5332012-08-09 10:33:26 -0700495 } else {
Alex Elderc98f5332012-08-09 10:33:26 -0700496 dev_name_end = dev_name + strlen(dev_name);
Alex Elderc98f5332012-08-09 10:33:26 -0700497 }
Noah Watkins80db8be2011-08-22 13:49:23 -0600498 err = -EINVAL;
Alex Elderc98f5332012-08-09 10:33:26 -0700499 dev_name_end--; /* back up to ':' separator */
Sasha Levin54464292013-07-01 18:33:39 -0400500 if (dev_name_end < dev_name || *dev_name_end != ':') {
Alex Elderc98f5332012-08-09 10:33:26 -0700501 pr_err("device name is missing path (no : separator in %s)\n",
Noah Watkins80db8be2011-08-22 13:49:23 -0600502 dev_name);
503 goto out;
504 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700505 dout("device name '%.*s'\n", (int)(dev_name_end - dev_name), dev_name);
Yan, Zheng3f384952016-04-21 11:09:55 +0800506 if (fsopt->server_path)
507 dout("server path '%s'\n", fsopt->server_path);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700508
Alex Elderee577412012-01-24 10:08:36 -0600509 *popt = ceph_parse_options(options, dev_name, dev_name_end,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700510 parse_fsopt_token, (void *)fsopt);
Alex Elderee577412012-01-24 10:08:36 -0600511 if (IS_ERR(*popt)) {
512 err = PTR_ERR(*popt);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700513 goto out;
Alex Elderee577412012-01-24 10:08:36 -0600514 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700515
516 /* success */
517 *pfsopt = fsopt;
518 return 0;
519
520out:
521 destroy_mount_options(fsopt);
522 return err;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800523}
524
Sage Weil6e19a162010-04-29 16:38:32 -0700525/**
526 * ceph_show_options - Show mount options in /proc/mounts
527 * @m: seq_file to write to
Al Viro34c80b12011-12-08 21:32:45 -0500528 * @root: root of that (sub)tree
Sage Weil6e19a162010-04-29 16:38:32 -0700529 */
Al Viro34c80b12011-12-08 21:32:45 -0500530static int ceph_show_options(struct seq_file *m, struct dentry *root)
Sage Weil6e19a162010-04-29 16:38:32 -0700531{
Al Viro34c80b12011-12-08 21:32:45 -0500532 struct ceph_fs_client *fsc = ceph_sb_to_client(root->d_sb);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700533 struct ceph_mount_options *fsopt = fsc->mount_options;
Ilya Dryomovff40f9a2015-03-25 21:02:16 +0300534 size_t pos;
535 int ret;
Sage Weil6e19a162010-04-29 16:38:32 -0700536
Ilya Dryomovff40f9a2015-03-25 21:02:16 +0300537 /* a comma between MNT/MS and client options */
538 seq_putc(m, ',');
539 pos = m->count;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700540
Dongsheng Yang02b2f542018-12-18 04:31:48 -0500541 ret = ceph_print_client_options(m, fsc->client, false);
Ilya Dryomovff40f9a2015-03-25 21:02:16 +0300542 if (ret)
543 return ret;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700544
Ilya Dryomovff40f9a2015-03-25 21:02:16 +0300545 /* retract our comma if no client options */
546 if (m->count == pos)
547 m->count--;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700548
549 if (fsopt->flags & CEPH_MOUNT_OPT_DIRSTAT)
550 seq_puts(m, ",dirstat");
Yan, Zheng133e9152016-01-25 10:44:33 +0800551 if ((fsopt->flags & CEPH_MOUNT_OPT_RBYTES))
552 seq_puts(m, ",rbytes");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700553 if (fsopt->flags & CEPH_MOUNT_OPT_NOASYNCREADDIR)
Sage Weil6e19a162010-04-29 16:38:32 -0700554 seq_puts(m, ",noasyncreaddir");
Ilya Dryomovff7eeb82015-03-25 21:10:09 +0300555 if ((fsopt->flags & CEPH_MOUNT_OPT_DCACHE) == 0)
Sage Weila40dc6c2012-01-10 09:12:55 -0800556 seq_puts(m, ",nodcache");
Chengguang Xu3619aa82018-06-04 16:03:51 +0800557 if (fsopt->flags & CEPH_MOUNT_OPT_INO32)
558 seq_puts(m, ",ino32");
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800559 if (fsopt->flags & CEPH_MOUNT_OPT_FSCACHE) {
Chengguang Xu4d8969a2018-02-15 15:39:05 +0800560 seq_show_option(m, "fsc", fsopt->fscache_uniq);
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800561 }
Yan, Zheng10183a62015-04-27 15:33:28 +0800562 if (fsopt->flags & CEPH_MOUNT_OPT_NOPOOLPERM)
563 seq_puts(m, ",nopoolperm");
Luis Henriques9122eed2018-01-31 10:53:13 +0000564 if (fsopt->flags & CEPH_MOUNT_OPT_NOQUOTADF)
565 seq_puts(m, ",noquotadf");
Sage Weil6e19a162010-04-29 16:38:32 -0700566
Sage Weil45195e42014-02-16 10:05:29 -0800567#ifdef CONFIG_CEPH_FS_POSIX_ACL
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800568 if (fsopt->sb_flags & SB_POSIXACL)
Sage Weil45195e42014-02-16 10:05:29 -0800569 seq_puts(m, ",acl");
570 else
571 seq_puts(m, ",noacl");
572#endif
573
Luis Henriques6f9718f2018-12-10 10:23:12 +0000574 if ((fsopt->flags & CEPH_MOUNT_OPT_NOCOPYFROM) == 0)
575 seq_puts(m, ",copyfrom");
Luis Henriquesea4cdc52018-10-15 16:46:00 +0100576
Yan, Zheng430afba2016-07-08 11:25:38 +0800577 if (fsopt->mds_namespace)
Chengguang Xu4d8969a2018-02-15 15:39:05 +0800578 seq_show_option(m, "mds_namespace", fsopt->mds_namespace);
Ilya Dryomov6dd49402018-05-03 16:26:55 +0200579 if (fsopt->wsize != CEPH_MAX_WRITE_SIZE)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700580 seq_printf(m, ",wsize=%d", fsopt->wsize);
Yan, Zhengaa187922017-07-11 15:56:09 +0800581 if (fsopt->rsize != CEPH_MAX_READ_SIZE)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700582 seq_printf(m, ",rsize=%d", fsopt->rsize);
Sage Weil83817e32011-08-04 08:03:44 -0700583 if (fsopt->rasize != CEPH_RASIZE_DEFAULT)
Sage Weil21519372011-12-01 08:06:52 -0800584 seq_printf(m, ",rasize=%d", fsopt->rasize);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700585 if (fsopt->congestion_kb != default_congestion_kb())
586 seq_printf(m, ",write_congestion_kb=%d", fsopt->congestion_kb);
Yan, Zhengfe330322019-02-01 14:57:15 +0800587 if (fsopt->caps_max)
588 seq_printf(m, ",caps_max=%d", fsopt->caps_max);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700589 if (fsopt->caps_wanted_delay_min != CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT)
Sage Weil6e19a162010-04-29 16:38:32 -0700590 seq_printf(m, ",caps_wanted_delay_min=%d",
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700591 fsopt->caps_wanted_delay_min);
592 if (fsopt->caps_wanted_delay_max != CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT)
Sage Weil6e19a162010-04-29 16:38:32 -0700593 seq_printf(m, ",caps_wanted_delay_max=%d",
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700594 fsopt->caps_wanted_delay_max);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700595 if (fsopt->max_readdir != CEPH_MAX_READDIR_DEFAULT)
596 seq_printf(m, ",readdir_max_entries=%d", fsopt->max_readdir);
597 if (fsopt->max_readdir_bytes != CEPH_MAX_READDIR_BYTES_DEFAULT)
598 seq_printf(m, ",readdir_max_bytes=%d", fsopt->max_readdir_bytes);
599 if (strcmp(fsopt->snapdir_name, CEPH_SNAPDIRNAME_DEFAULT))
Kees Cooka068acf2015-09-04 15:44:57 -0700600 seq_show_option(m, "snapdirname", fsopt->snapdir_name);
Ilya Dryomovff40f9a2015-03-25 21:02:16 +0300601
Sage Weil6e19a162010-04-29 16:38:32 -0700602 return 0;
603}
604
605/*
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700606 * handle any mon messages the standard library doesn't understand.
607 * return error if we don't either.
608 */
609static int extra_mon_dispatch(struct ceph_client *client, struct ceph_msg *msg)
610{
611 struct ceph_fs_client *fsc = client->private;
612 int type = le16_to_cpu(msg->hdr.type);
613
614 switch (type) {
615 case CEPH_MSG_MDS_MAP:
Yan, Zheng430afba2016-07-08 11:25:38 +0800616 ceph_mdsc_handle_mdsmap(fsc->mdsc, msg);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700617 return 0;
Yan, Zheng430afba2016-07-08 11:25:38 +0800618 case CEPH_MSG_FS_MAP_USER:
619 ceph_mdsc_handle_fsmap(fsc->mdsc, msg);
620 return 0;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700621 default:
622 return -1;
623 }
624}
625
626/*
627 * create a new fs client
Ilya Dryomov8aaff152018-08-24 15:32:43 +0200628 *
629 * Success or not, this function consumes @fsopt and @opt.
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700630 */
H Hartley Sweeten0c6d4b4e22011-09-23 11:53:30 -0700631static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700632 struct ceph_options *opt)
633{
634 struct ceph_fs_client *fsc;
Alex Elder3bf53332013-04-01 10:48:40 -0500635 int page_count;
636 size_t size;
Ilya Dryomov8aaff152018-08-24 15:32:43 +0200637 int err;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700638
639 fsc = kzalloc(sizeof(*fsc), GFP_KERNEL);
Ilya Dryomov8aaff152018-08-24 15:32:43 +0200640 if (!fsc) {
641 err = -ENOMEM;
642 goto fail;
643 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700644
Ilya Dryomov74da4a0f2017-03-03 18:16:07 +0100645 fsc->client = ceph_create_client(opt, fsc);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700646 if (IS_ERR(fsc->client)) {
647 err = PTR_ERR(fsc->client);
648 goto fail;
649 }
Ilya Dryomov8aaff152018-08-24 15:32:43 +0200650 opt = NULL; /* fsc->client now owns this */
Ilya Dryomovc843d132018-05-30 16:29:14 +0200651
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700652 fsc->client->extra_mon_dispatch = extra_mon_dispatch;
Dongsheng Yang02b2f542018-12-18 04:31:48 -0500653 ceph_set_opt(fsc->client, ABORT_ON_FULL);
Yan, Zheng430afba2016-07-08 11:25:38 +0800654
Markus Elfringd37b1d92017-08-20 20:22:02 +0200655 if (!fsopt->mds_namespace) {
Yan, Zheng430afba2016-07-08 11:25:38 +0800656 ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_MDSMAP,
657 0, true);
658 } else {
659 ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_FSMAP,
660 0, false);
661 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700662
663 fsc->mount_options = fsopt;
664
665 fsc->sb = NULL;
666 fsc->mount_state = CEPH_MOUNT_MOUNTING;
667
668 atomic_long_set(&fsc->writeback_count, 0);
669
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700670 err = -ENOMEM;
Tejun Heo01e6acc2011-01-03 14:49:45 +0100671 /*
672 * The number of concurrent works can be high but they don't need
673 * to be processed in parallel, limit concurrency.
674 */
675 fsc->wb_wq = alloc_workqueue("ceph-writeback", 0, 1);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200676 if (!fsc->wb_wq)
Jan Kara09dc9fc2017-04-12 12:24:33 +0200677 goto fail_client;
Tejun Heo01e6acc2011-01-03 14:49:45 +0100678 fsc->pg_inv_wq = alloc_workqueue("ceph-pg-invalid", 0, 1);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200679 if (!fsc->pg_inv_wq)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700680 goto fail_wb_wq;
Tejun Heo01e6acc2011-01-03 14:49:45 +0100681 fsc->trunc_wq = alloc_workqueue("ceph-trunc", 0, 1);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200682 if (!fsc->trunc_wq)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700683 goto fail_pg_inv_wq;
Yan, Zhenge3ec8d62019-01-14 17:21:19 +0800684 fsc->cap_wq = alloc_workqueue("ceph-cap", 0, 1);
685 if (!fsc->cap_wq)
686 goto fail_trunc_wq;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700687
688 /* set up mempools */
689 err = -ENOMEM;
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300690 page_count = fsc->mount_options->wsize >> PAGE_SHIFT;
Alex Elder3bf53332013-04-01 10:48:40 -0500691 size = sizeof (struct page *) * (page_count ? page_count : 1);
692 fsc->wb_pagevec_pool = mempool_create_kmalloc_pool(10, size);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700693 if (!fsc->wb_pagevec_pool)
Yan, Zhenge3ec8d62019-01-14 17:21:19 +0800694 goto fail_cap_wq;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700695
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700696 return fsc;
697
Yan, Zhenge3ec8d62019-01-14 17:21:19 +0800698fail_cap_wq:
699 destroy_workqueue(fsc->cap_wq);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700700fail_trunc_wq:
701 destroy_workqueue(fsc->trunc_wq);
702fail_pg_inv_wq:
703 destroy_workqueue(fsc->pg_inv_wq);
704fail_wb_wq:
705 destroy_workqueue(fsc->wb_wq);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700706fail_client:
707 ceph_destroy_client(fsc->client);
708fail:
709 kfree(fsc);
Ilya Dryomov8aaff152018-08-24 15:32:43 +0200710 if (opt)
711 ceph_destroy_options(opt);
712 destroy_mount_options(fsopt);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700713 return ERR_PTR(err);
714}
715
Yan, Zhenga57d9062018-05-18 16:05:51 +0800716static void flush_fs_workqueues(struct ceph_fs_client *fsc)
717{
718 flush_workqueue(fsc->wb_wq);
719 flush_workqueue(fsc->pg_inv_wq);
720 flush_workqueue(fsc->trunc_wq);
Yan, Zhenge3ec8d62019-01-14 17:21:19 +0800721 flush_workqueue(fsc->cap_wq);
Yan, Zhenga57d9062018-05-18 16:05:51 +0800722}
723
H Hartley Sweeten0c6d4b4e22011-09-23 11:53:30 -0700724static void destroy_fs_client(struct ceph_fs_client *fsc)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700725{
726 dout("destroy_fs_client %p\n", fsc);
727
728 destroy_workqueue(fsc->wb_wq);
729 destroy_workqueue(fsc->pg_inv_wq);
730 destroy_workqueue(fsc->trunc_wq);
Yan, Zhenge3ec8d62019-01-14 17:21:19 +0800731 destroy_workqueue(fsc->cap_wq);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700732
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700733 mempool_destroy(fsc->wb_pagevec_pool);
734
735 destroy_mount_options(fsc->mount_options);
736
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700737 ceph_destroy_client(fsc->client);
738
739 kfree(fsc);
740 dout("destroy_fs_client %p done\n", fsc);
741}
742
743/*
Sage Weil6e19a162010-04-29 16:38:32 -0700744 * caches
745 */
746struct kmem_cache *ceph_inode_cachep;
747struct kmem_cache *ceph_cap_cachep;
Yan, Zhengf66fd9f2015-06-10 17:26:13 +0800748struct kmem_cache *ceph_cap_flush_cachep;
Sage Weil6e19a162010-04-29 16:38:32 -0700749struct kmem_cache *ceph_dentry_cachep;
750struct kmem_cache *ceph_file_cachep;
Chengguang Xubb48bd42018-03-13 10:42:44 +0800751struct kmem_cache *ceph_dir_file_cachep;
Sage Weil6e19a162010-04-29 16:38:32 -0700752
753static void ceph_inode_init_once(void *foo)
754{
755 struct ceph_inode_info *ci = foo;
756 inode_init_once(&ci->vfs_inode);
757}
758
Sage Weil16725b92009-10-06 11:31:07 -0700759static int __init init_caches(void)
760{
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400761 int error = -ENOMEM;
762
Sage Weil16725b92009-10-06 11:31:07 -0700763 ceph_inode_cachep = kmem_cache_create("ceph_inode_info",
764 sizeof(struct ceph_inode_info),
765 __alignof__(struct ceph_inode_info),
Vladimir Davydov5d097052016-01-14 15:18:21 -0800766 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|
767 SLAB_ACCOUNT, ceph_inode_init_once);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200768 if (!ceph_inode_cachep)
Sage Weil16725b92009-10-06 11:31:07 -0700769 return -ENOMEM;
770
Chengguang Xubc4b5ad2018-02-27 13:49:44 +0800771 ceph_cap_cachep = KMEM_CACHE(ceph_cap, SLAB_MEM_SPREAD);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200772 if (!ceph_cap_cachep)
Sage Weil16725b92009-10-06 11:31:07 -0700773 goto bad_cap;
Yan, Zhengf66fd9f2015-06-10 17:26:13 +0800774 ceph_cap_flush_cachep = KMEM_CACHE(ceph_cap_flush,
775 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200776 if (!ceph_cap_flush_cachep)
Yan, Zhengf66fd9f2015-06-10 17:26:13 +0800777 goto bad_cap_flush;
Sage Weil16725b92009-10-06 11:31:07 -0700778
779 ceph_dentry_cachep = KMEM_CACHE(ceph_dentry_info,
780 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200781 if (!ceph_dentry_cachep)
Sage Weil16725b92009-10-06 11:31:07 -0700782 goto bad_dentry;
783
Nikolay Borisov6b1a9a62016-07-25 20:12:13 +0300784 ceph_file_cachep = KMEM_CACHE(ceph_file_info, SLAB_MEM_SPREAD);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200785 if (!ceph_file_cachep)
Sage Weil16725b92009-10-06 11:31:07 -0700786 goto bad_file;
787
Chengguang Xubb48bd42018-03-13 10:42:44 +0800788 ceph_dir_file_cachep = KMEM_CACHE(ceph_dir_file_info, SLAB_MEM_SPREAD);
789 if (!ceph_dir_file_cachep)
790 goto bad_dir_file;
791
Chengguang Xu1c789242018-03-01 14:24:51 +0800792 error = ceph_fscache_register();
793 if (error)
794 goto bad_fscache;
Sage Weil16725b92009-10-06 11:31:07 -0700795
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400796 return 0;
Chengguang Xu1c789242018-03-01 14:24:51 +0800797
798bad_fscache:
Chengguang Xubb48bd42018-03-13 10:42:44 +0800799 kmem_cache_destroy(ceph_dir_file_cachep);
800bad_dir_file:
Chengguang Xu1c789242018-03-01 14:24:51 +0800801 kmem_cache_destroy(ceph_file_cachep);
Sage Weil16725b92009-10-06 11:31:07 -0700802bad_file:
803 kmem_cache_destroy(ceph_dentry_cachep);
804bad_dentry:
Yan, Zhengf66fd9f2015-06-10 17:26:13 +0800805 kmem_cache_destroy(ceph_cap_flush_cachep);
806bad_cap_flush:
Sage Weil16725b92009-10-06 11:31:07 -0700807 kmem_cache_destroy(ceph_cap_cachep);
808bad_cap:
809 kmem_cache_destroy(ceph_inode_cachep);
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400810 return error;
Sage Weil16725b92009-10-06 11:31:07 -0700811}
812
813static void destroy_caches(void)
814{
Kirill A. Shutemov8c0a8532012-09-26 11:33:07 +1000815 /*
816 * Make sure all delayed rcu free inodes are flushed before we
817 * destroy cache.
818 */
819 rcu_barrier();
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400820
Sage Weil16725b92009-10-06 11:31:07 -0700821 kmem_cache_destroy(ceph_inode_cachep);
822 kmem_cache_destroy(ceph_cap_cachep);
Yan, Zhengf66fd9f2015-06-10 17:26:13 +0800823 kmem_cache_destroy(ceph_cap_flush_cachep);
Sage Weil16725b92009-10-06 11:31:07 -0700824 kmem_cache_destroy(ceph_dentry_cachep);
825 kmem_cache_destroy(ceph_file_cachep);
Chengguang Xubb48bd42018-03-13 10:42:44 +0800826 kmem_cache_destroy(ceph_dir_file_cachep);
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400827
828 ceph_fscache_unregister();
Sage Weil16725b92009-10-06 11:31:07 -0700829}
830
831
832/*
833 * ceph_umount_begin - initiate forced umount. Tear down down the
834 * mount, skipping steps that may hang while waiting for server(s).
835 */
836static void ceph_umount_begin(struct super_block *sb)
837{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700838 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
Sage Weil16725b92009-10-06 11:31:07 -0700839
840 dout("ceph_umount_begin - starting forced umount\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700841 if (!fsc)
Sage Weil16725b92009-10-06 11:31:07 -0700842 return;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700843 fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
Yan, Zheng12b69d52018-05-11 17:12:02 +0800844 ceph_osdc_abort_requests(&fsc->client->osdc, -EIO);
Yan, Zheng48fec5d2015-07-01 16:27:46 +0800845 ceph_mdsc_force_umount(fsc->mdsc);
Sage Weil16725b92009-10-06 11:31:07 -0700846 return;
847}
848
Jeff Layton00abf692019-05-07 09:20:54 -0400849static int ceph_remount(struct super_block *sb, int *flags, char *data)
850{
851 sync_filesystem(sb);
852 return 0;
853}
854
Sage Weil16725b92009-10-06 11:31:07 -0700855static const struct super_operations ceph_super_ops = {
856 .alloc_inode = ceph_alloc_inode,
857 .destroy_inode = ceph_destroy_inode,
Al Virocfa6d412019-04-10 15:18:50 -0400858 .free_inode = ceph_free_inode,
Sage Weil16725b92009-10-06 11:31:07 -0700859 .write_inode = ceph_write_inode,
Yan, Zheng9f12bd12013-09-20 19:55:31 +0800860 .drop_inode = ceph_drop_inode,
Sage Weil2d9c98a2010-07-30 09:38:13 -0700861 .sync_fs = ceph_sync_fs,
Sage Weil16725b92009-10-06 11:31:07 -0700862 .put_super = ceph_put_super,
Jeff Layton00abf692019-05-07 09:20:54 -0400863 .remount_fs = ceph_remount,
Sage Weil16725b92009-10-06 11:31:07 -0700864 .show_options = ceph_show_options,
865 .statfs = ceph_statfs,
866 .umount_begin = ceph_umount_begin,
867};
868
Sage Weil16725b92009-10-06 11:31:07 -0700869/*
870 * Bootstrap mount by opening the root directory. Note the mount
871 * @started time from caller, and time out if this takes too long.
872 */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700873static struct dentry *open_root_dentry(struct ceph_fs_client *fsc,
Sage Weil16725b92009-10-06 11:31:07 -0700874 const char *path,
875 unsigned long started)
876{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700877 struct ceph_mds_client *mdsc = fsc->mdsc;
Sage Weil16725b92009-10-06 11:31:07 -0700878 struct ceph_mds_request *req = NULL;
879 int err;
880 struct dentry *root;
881
882 /* open dir */
883 dout("open_root_inode opening '%s'\n", path);
884 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_GETATTR, USE_ANY_MDS);
885 if (IS_ERR(req))
Julia Lawall7e34bc52010-05-22 12:01:14 +0200886 return ERR_CAST(req);
Sage Weil16725b92009-10-06 11:31:07 -0700887 req->r_path1 = kstrdup(path, GFP_NOFS);
Sanidhya Kashyapa149bb92015-03-21 12:54:58 -0400888 if (!req->r_path1) {
889 root = ERR_PTR(-ENOMEM);
890 goto out;
891 }
892
Sage Weil16725b92009-10-06 11:31:07 -0700893 req->r_ino1.ino = CEPH_INO_ROOT;
894 req->r_ino1.snap = CEPH_NOSNAP;
895 req->r_started = started;
Ilya Dryomova319bf52015-05-15 12:02:17 +0300896 req->r_timeout = fsc->client->options->mount_timeout;
Sage Weil16725b92009-10-06 11:31:07 -0700897 req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INODE);
898 req->r_num_caps = 2;
899 err = ceph_mdsc_do_request(mdsc, NULL, req);
900 if (err == 0) {
Al Viro3c5184e2012-01-09 16:34:32 -0500901 struct inode *inode = req->r_target_inode;
902 req->r_target_inode = NULL;
Sage Weil16725b92009-10-06 11:31:07 -0700903 dout("open_root_inode success\n");
Yan, Zhengce2728a2016-09-14 14:53:05 +0800904 root = d_make_root(inode);
905 if (!root) {
906 root = ERR_PTR(-ENOMEM);
907 goto out;
Sage Weil774ac212011-11-11 09:48:08 -0800908 }
Sage Weil16725b92009-10-06 11:31:07 -0700909 dout("open_root_inode success, root dentry is %p\n", root);
910 } else {
911 root = ERR_PTR(err);
912 }
Al Viro3c5184e2012-01-09 16:34:32 -0500913out:
Sage Weil16725b92009-10-06 11:31:07 -0700914 ceph_mdsc_put_request(req);
915 return root;
916}
917
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700918
919
920
Sage Weil16725b92009-10-06 11:31:07 -0700921/*
922 * mount: join the ceph cluster, and open root directory.
923 */
Yan, Zheng3f384952016-04-21 11:09:55 +0800924static struct dentry *ceph_real_mount(struct ceph_fs_client *fsc)
Sage Weil16725b92009-10-06 11:31:07 -0700925{
Sage Weil16725b92009-10-06 11:31:07 -0700926 int err;
Sage Weil16725b92009-10-06 11:31:07 -0700927 unsigned long started = jiffies; /* note the start time */
928 struct dentry *root;
929
Yan, Zheng132ca7e2016-03-12 13:20:48 +0800930 dout("mount start %p\n", fsc);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700931 mutex_lock(&fsc->client->mount_mutex);
Sage Weil16725b92009-10-06 11:31:07 -0700932
Yan, Zheng132ca7e2016-03-12 13:20:48 +0800933 if (!fsc->sb->s_root) {
Yan, Zhengce2728a2016-09-14 14:53:05 +0800934 const char *path;
Yan, Zheng132ca7e2016-03-12 13:20:48 +0800935 err = __ceph_open_session(fsc->client, started);
936 if (err < 0)
937 goto out;
Sage Weil16725b92009-10-06 11:31:07 -0700938
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800939 /* setup fscache */
940 if (fsc->mount_options->flags & CEPH_MOUNT_OPT_FSCACHE) {
941 err = ceph_fscache_register_fs(fsc);
942 if (err < 0)
943 goto out;
944 }
945
Yan, Zhengce2728a2016-09-14 14:53:05 +0800946 if (!fsc->mount_options->server_path) {
947 path = "";
948 dout("mount opening path \\t\n");
949 } else {
950 path = fsc->mount_options->server_path + 1;
951 dout("mount opening path %s\n", path);
952 }
Chengguang Xu18106732018-02-09 20:40:59 +0800953
954 err = ceph_fs_debugfs_init(fsc);
955 if (err < 0)
956 goto out;
957
Yan, Zhengce2728a2016-09-14 14:53:05 +0800958 root = open_root_dentry(fsc, path, started);
Yan, Zheng132ca7e2016-03-12 13:20:48 +0800959 if (IS_ERR(root)) {
960 err = PTR_ERR(root);
961 goto out;
962 }
Yan, Zhengce2728a2016-09-14 14:53:05 +0800963 fsc->sb->s_root = dget(root);
Geert Uytterhoeven31ca5872016-10-13 17:15:37 +0200964 } else {
965 root = dget(fsc->sb->s_root);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700966 }
Sage Weil16725b92009-10-06 11:31:07 -0700967
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700968 fsc->mount_state = CEPH_MOUNT_MOUNTED;
Sage Weil16725b92009-10-06 11:31:07 -0700969 dout("mount success\n");
Al Viroa7f9fb22010-07-26 16:17:55 +0400970 mutex_unlock(&fsc->client->mount_mutex);
971 return root;
Sage Weil16725b92009-10-06 11:31:07 -0700972
Yan, Zheng132ca7e2016-03-12 13:20:48 +0800973out:
974 mutex_unlock(&fsc->client->mount_mutex);
975 return ERR_PTR(err);
Sage Weil16725b92009-10-06 11:31:07 -0700976}
977
978static int ceph_set_super(struct super_block *s, void *data)
979{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700980 struct ceph_fs_client *fsc = data;
Sage Weil16725b92009-10-06 11:31:07 -0700981 int ret;
982
983 dout("set_super %p data %p\n", s, data);
984
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700985 s->s_flags = fsc->mount_options->sb_flags;
Chengguang Xu719784b2018-07-19 22:15:24 +0800986 s->s_maxbytes = MAX_LFS_FILESIZE;
Sage Weil16725b92009-10-06 11:31:07 -0700987
Guangliang Zhao7221fe42013-11-11 15:18:03 +0800988 s->s_xattr = ceph_xattr_handlers;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700989 s->s_fs_info = fsc;
990 fsc->sb = s;
Chengguang Xu719784b2018-07-19 22:15:24 +0800991 fsc->max_file_size = 1ULL << 40; /* temp value until we get mdsmap */
Sage Weil16725b92009-10-06 11:31:07 -0700992
993 s->s_op = &ceph_super_ops;
Al Viro18fc8ab2016-10-28 21:52:50 -0400994 s->s_d_op = &ceph_dentry_ops;
Sage Weil16725b92009-10-06 11:31:07 -0700995 s->s_export_op = &ceph_export_ops;
996
997 s->s_time_gran = 1000; /* 1000 ns == 1 us */
998
999 ret = set_anon_super(s, NULL); /* what is that second arg for? */
1000 if (ret != 0)
1001 goto fail;
1002
1003 return ret;
1004
1005fail:
1006 s->s_fs_info = NULL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001007 fsc->sb = NULL;
Sage Weil16725b92009-10-06 11:31:07 -07001008 return ret;
1009}
1010
1011/*
1012 * share superblock if same fs AND options
1013 */
1014static int ceph_compare_super(struct super_block *sb, void *data)
1015{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001016 struct ceph_fs_client *new = data;
1017 struct ceph_mount_options *fsopt = new->mount_options;
1018 struct ceph_options *opt = new->client->options;
1019 struct ceph_fs_client *other = ceph_sb_to_client(sb);
Sage Weil16725b92009-10-06 11:31:07 -07001020
1021 dout("ceph_compare_super %p\n", sb);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001022
1023 if (compare_mount_options(fsopt, opt, other)) {
1024 dout("monitor(s)/mount options don't match\n");
1025 return 0;
Sage Weil16725b92009-10-06 11:31:07 -07001026 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001027 if ((opt->flags & CEPH_OPT_FSID) &&
1028 ceph_fsid_compare(&opt->fsid, &other->client->fsid)) {
1029 dout("fsid doesn't match\n");
1030 return 0;
1031 }
1032 if (fsopt->sb_flags != other->mount_options->sb_flags) {
Sage Weil16725b92009-10-06 11:31:07 -07001033 dout("flags differ\n");
1034 return 0;
1035 }
1036 return 1;
1037}
1038
1039/*
1040 * construct our own bdi so we can control readahead, etc.
1041 */
Jeff Mahoney00d56432010-06-10 11:13:58 -04001042static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
Sage Weil31e0cf82010-05-04 16:39:35 -07001043
Jan Kara09dc9fc2017-04-12 12:24:33 +02001044static int ceph_setup_bdi(struct super_block *sb, struct ceph_fs_client *fsc)
Sage Weil16725b92009-10-06 11:31:07 -07001045{
1046 int err;
1047
Jan Kara09dc9fc2017-04-12 12:24:33 +02001048 err = super_setup_bdi_name(sb, "ceph-%ld",
1049 atomic_long_inc_return(&bdi_seq));
1050 if (err)
1051 return err;
1052
Sage Weil83817e32011-08-04 08:03:44 -07001053 /* set ra_pages based on rasize mount option? */
Yan, Zheng4214fb12017-07-11 18:49:44 +08001054 sb->s_bdi->ra_pages = fsc->mount_options->rasize >> PAGE_SHIFT;
Yehuda Sadehe9852222011-07-22 11:12:28 -07001055
Yan, Zhengaa187922017-07-11 15:56:09 +08001056 /* set io_pages based on max osd read size */
1057 sb->s_bdi->io_pages = fsc->mount_options->rsize >> PAGE_SHIFT;
Andreas Gerstmayr7c94ba22017-01-10 14:17:56 +01001058
Jan Kara09dc9fc2017-04-12 12:24:33 +02001059 return 0;
Sage Weil16725b92009-10-06 11:31:07 -07001060}
1061
Al Viroa7f9fb22010-07-26 16:17:55 +04001062static struct dentry *ceph_mount(struct file_system_type *fs_type,
1063 int flags, const char *dev_name, void *data)
Sage Weil16725b92009-10-06 11:31:07 -07001064{
1065 struct super_block *sb;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001066 struct ceph_fs_client *fsc;
Al Viroa7f9fb22010-07-26 16:17:55 +04001067 struct dentry *res;
Sage Weil16725b92009-10-06 11:31:07 -07001068 int err;
1069 int (*compare_super)(struct super_block *, void *) = ceph_compare_super;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001070 struct ceph_mount_options *fsopt = NULL;
1071 struct ceph_options *opt = NULL;
Sage Weil16725b92009-10-06 11:31:07 -07001072
Al Viroa7f9fb22010-07-26 16:17:55 +04001073 dout("ceph_mount\n");
Sage Weil45195e42014-02-16 10:05:29 -08001074
1075#ifdef CONFIG_CEPH_FS_POSIX_ACL
Linus Torvalds1751e8a2017-11-27 13:05:09 -08001076 flags |= SB_POSIXACL;
Sage Weil45195e42014-02-16 10:05:29 -08001077#endif
Yan, Zheng3f384952016-04-21 11:09:55 +08001078 err = parse_mount_options(&fsopt, &opt, flags, data, dev_name);
Al Viroa7f9fb22010-07-26 16:17:55 +04001079 if (err < 0) {
1080 res = ERR_PTR(err);
Sage Weil6b805182009-10-27 11:50:50 -07001081 goto out_final;
Al Viroa7f9fb22010-07-26 16:17:55 +04001082 }
Sage Weil16725b92009-10-06 11:31:07 -07001083
1084 /* create client (which we may/may not use) */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001085 fsc = create_fs_client(fsopt, opt);
1086 if (IS_ERR(fsc)) {
Al Viroa7f9fb22010-07-26 16:17:55 +04001087 res = ERR_CAST(fsc);
Sage Weil6b805182009-10-27 11:50:50 -07001088 goto out_final;
1089 }
Sage Weil16725b92009-10-06 11:31:07 -07001090
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001091 err = ceph_mdsc_init(fsc);
Al Viroa7f9fb22010-07-26 16:17:55 +04001092 if (err < 0) {
1093 res = ERR_PTR(err);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001094 goto out;
Al Viroa7f9fb22010-07-26 16:17:55 +04001095 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001096
1097 if (ceph_test_opt(fsc->client, NOSHARE))
Sage Weil16725b92009-10-06 11:31:07 -07001098 compare_super = NULL;
David Howells9249e172012-06-25 12:55:37 +01001099 sb = sget(fs_type, compare_super, ceph_set_super, flags, fsc);
Sage Weil16725b92009-10-06 11:31:07 -07001100 if (IS_ERR(sb)) {
Al Viroa7f9fb22010-07-26 16:17:55 +04001101 res = ERR_CAST(sb);
Sage Weil16725b92009-10-06 11:31:07 -07001102 goto out;
1103 }
1104
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001105 if (ceph_sb_to_client(sb) != fsc) {
1106 ceph_mdsc_destroy(fsc);
1107 destroy_fs_client(fsc);
1108 fsc = ceph_sb_to_client(sb);
1109 dout("get_sb got existing client %p\n", fsc);
Sage Weil16725b92009-10-06 11:31:07 -07001110 } else {
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001111 dout("get_sb using new client %p\n", fsc);
Jan Kara09dc9fc2017-04-12 12:24:33 +02001112 err = ceph_setup_bdi(sb, fsc);
Al Viroa7f9fb22010-07-26 16:17:55 +04001113 if (err < 0) {
1114 res = ERR_PTR(err);
Sage Weil16725b92009-10-06 11:31:07 -07001115 goto out_splat;
Al Viroa7f9fb22010-07-26 16:17:55 +04001116 }
Sage Weil16725b92009-10-06 11:31:07 -07001117 }
1118
Yan, Zheng3f384952016-04-21 11:09:55 +08001119 res = ceph_real_mount(fsc);
Al Viroa7f9fb22010-07-26 16:17:55 +04001120 if (IS_ERR(res))
Sage Weil16725b92009-10-06 11:31:07 -07001121 goto out_splat;
Al Viroa7f9fb22010-07-26 16:17:55 +04001122 dout("root %p inode %p ino %llx.%llx\n", res,
David Howells2b0143b2015-03-17 22:25:59 +00001123 d_inode(res), ceph_vinop(d_inode(res)));
Al Viroa7f9fb22010-07-26 16:17:55 +04001124 return res;
Sage Weil16725b92009-10-06 11:31:07 -07001125
1126out_splat:
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001127 ceph_mdsc_close_sessions(fsc->mdsc);
Al Viro3981f2e2010-03-21 19:22:29 -04001128 deactivate_locked_super(sb);
Sage Weil16725b92009-10-06 11:31:07 -07001129 goto out_final;
1130
1131out:
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001132 ceph_mdsc_destroy(fsc);
1133 destroy_fs_client(fsc);
Sage Weil16725b92009-10-06 11:31:07 -07001134out_final:
Al Viroa7f9fb22010-07-26 16:17:55 +04001135 dout("ceph_mount fail %ld\n", PTR_ERR(res));
1136 return res;
Sage Weil16725b92009-10-06 11:31:07 -07001137}
1138
1139static void ceph_kill_sb(struct super_block *s)
1140{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001141 struct ceph_fs_client *fsc = ceph_sb_to_client(s);
Christoph Hellwige4d27502015-01-14 10:42:38 +01001142 dev_t dev = s->s_dev;
1143
Sage Weil16725b92009-10-06 11:31:07 -07001144 dout("kill_sb %p\n", s);
Christoph Hellwige4d27502015-01-14 10:42:38 +01001145
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001146 ceph_mdsc_pre_umount(fsc->mdsc);
Yan, Zhenga57d9062018-05-18 16:05:51 +08001147 flush_fs_workqueues(fsc);
1148
Christoph Hellwige4d27502015-01-14 10:42:38 +01001149 generic_shutdown_super(s);
Yan, Zheng62a65f32017-06-22 16:26:34 +08001150
1151 fsc->client->extra_mon_dispatch = NULL;
1152 ceph_fs_debugfs_cleanup(fsc);
1153
Yan, Zheng1d8f8362017-06-27 11:57:56 +08001154 ceph_fscache_unregister_fs(fsc);
1155
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001156 ceph_mdsc_destroy(fsc);
Christoph Hellwige4d27502015-01-14 10:42:38 +01001157
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001158 destroy_fs_client(fsc);
Christoph Hellwige4d27502015-01-14 10:42:38 +01001159 free_anon_bdev(dev);
Sage Weil16725b92009-10-06 11:31:07 -07001160}
1161
1162static struct file_system_type ceph_fs_type = {
1163 .owner = THIS_MODULE,
1164 .name = "ceph",
Al Viroa7f9fb22010-07-26 16:17:55 +04001165 .mount = ceph_mount,
Sage Weil16725b92009-10-06 11:31:07 -07001166 .kill_sb = ceph_kill_sb,
1167 .fs_flags = FS_RENAME_DOES_D_MOVE,
1168};
Eric W. Biederman7f78e032013-03-02 19:39:14 -08001169MODULE_ALIAS_FS("ceph");
Sage Weil16725b92009-10-06 11:31:07 -07001170
Sage Weil16725b92009-10-06 11:31:07 -07001171static int __init init_ceph(void)
1172{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001173 int ret = init_caches();
Sage Weil16725b92009-10-06 11:31:07 -07001174 if (ret)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001175 goto out;
Sage Weil16725b92009-10-06 11:31:07 -07001176
Yan, Zhengeb13e832014-03-09 23:16:40 +08001177 ceph_flock_init();
Alex Elder3ce6cd12012-01-23 15:49:28 -06001178 ceph_xattr_init();
Sage Weil16725b92009-10-06 11:31:07 -07001179 ret = register_filesystem(&ceph_fs_type);
1180 if (ret)
Ilya Dryomov34b759b2016-02-16 15:00:24 +01001181 goto out_xattr;
Sage Weil16725b92009-10-06 11:31:07 -07001182
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001183 pr_info("loaded (mds proto %d)\n", CEPH_MDSC_PROTOCOL);
1184
Sage Weil16725b92009-10-06 11:31:07 -07001185 return 0;
1186
Yan, Zheng97c85a82014-11-06 15:09:41 +08001187out_xattr:
Alex Elder3ce6cd12012-01-23 15:49:28 -06001188 ceph_xattr_exit();
Sage Weil16725b92009-10-06 11:31:07 -07001189 destroy_caches();
Sage Weil16725b92009-10-06 11:31:07 -07001190out:
1191 return ret;
1192}
1193
1194static void __exit exit_ceph(void)
1195{
1196 dout("exit_ceph\n");
1197 unregister_filesystem(&ceph_fs_type);
Alex Elder3ce6cd12012-01-23 15:49:28 -06001198 ceph_xattr_exit();
Sage Weil16725b92009-10-06 11:31:07 -07001199 destroy_caches();
Sage Weil16725b92009-10-06 11:31:07 -07001200}
1201
1202module_init(init_ceph);
1203module_exit(exit_ceph);
1204
1205MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
1206MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
1207MODULE_AUTHOR("Patience Warnick <patience@newdream.net>");
1208MODULE_DESCRIPTION("Ceph filesystem for Linux");
1209MODULE_LICENSE("GPL");