blob: 6d5bb2f74612003edbcd6204b3c6dcdb86f0ef80 [file] [log] [blame]
Sage Weil16725b92009-10-06 11:31:07 -07001
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07002#include <linux/ceph/ceph_debug.h>
Sage Weil16725b92009-10-06 11:31:07 -07003
4#include <linux/backing-dev.h>
Sage Weilc309f0a2010-06-30 21:34:01 -07005#include <linux/ctype.h>
Sage Weil16725b92009-10-06 11:31:07 -07006#include <linux/fs.h>
7#include <linux/inet.h>
8#include <linux/in6.h>
9#include <linux/module.h>
10#include <linux/mount.h>
11#include <linux/parser.h>
Sage Weil16725b92009-10-06 11:31:07 -070012#include <linux/sched.h>
13#include <linux/seq_file.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Sage Weil16725b92009-10-06 11:31:07 -070015#include <linux/statfs.h>
16#include <linux/string.h>
Sage Weil16725b92009-10-06 11:31:07 -070017
Sage Weil16725b92009-10-06 11:31:07 -070018#include "super.h"
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070019#include "mds_client.h"
Milosz Tanski99ccbd22013-08-21 17:29:54 -040020#include "cache.h"
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070021
Sage Weil1fe60e52012-07-30 16:23:22 -070022#include <linux/ceph/ceph_features.h>
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070023#include <linux/ceph/decode.h>
24#include <linux/ceph/mon_client.h>
25#include <linux/ceph/auth.h>
26#include <linux/ceph/debugfs.h>
Sage Weil16725b92009-10-06 11:31:07 -070027
28/*
29 * Ceph superblock operations
30 *
31 * Handle the basics of mounting, unmounting.
32 */
33
Sage Weil16725b92009-10-06 11:31:07 -070034/*
35 * super ops
36 */
37static void ceph_put_super(struct super_block *s)
38{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070039 struct ceph_fs_client *fsc = ceph_sb_to_client(s);
Sage Weil16725b92009-10-06 11:31:07 -070040
41 dout("put_super\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070042 ceph_mdsc_close_sessions(fsc->mdsc);
Sage Weil16725b92009-10-06 11:31:07 -070043}
44
45static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf)
46{
David Howells2b0143b2015-03-17 22:25:59 +000047 struct ceph_fs_client *fsc = ceph_inode_to_client(d_inode(dentry));
Luis Henriques73fb0942018-05-28 18:37:40 +010048 struct ceph_mon_client *monc = &fsc->client->monc;
Sage Weil16725b92009-10-06 11:31:07 -070049 struct ceph_statfs st;
50 u64 fsid;
51 int err;
Douglas Fuller06d74372017-08-16 10:19:27 -040052 u64 data_pool;
53
54 if (fsc->mdsc->mdsmap->m_num_data_pg_pools == 1) {
55 data_pool = fsc->mdsc->mdsmap->m_data_pg_pools[0];
56 } else {
57 data_pool = CEPH_NOPOOL;
58 }
Sage Weil16725b92009-10-06 11:31:07 -070059
60 dout("statfs\n");
Luis Henriques73fb0942018-05-28 18:37:40 +010061 err = ceph_monc_do_statfs(monc, data_pool, &st);
Sage Weil16725b92009-10-06 11:31:07 -070062 if (err < 0)
63 return err;
64
65 /* fill in kstatfs */
66 buf->f_type = CEPH_SUPER_MAGIC; /* ?? */
67
68 /*
69 * express utilization in terms of large blocks to avoid
70 * overflow on 32-bit machines.
Sage Weil92a49fb2013-02-22 15:31:00 -080071 *
72 * NOTE: for the time being, we make bsize == frsize to humor
73 * not-yet-ancient versions of glibc that are broken.
74 * Someday, we will probably want to report a real block
75 * size... whatever that may mean for a network file system!
Sage Weil16725b92009-10-06 11:31:07 -070076 */
77 buf->f_bsize = 1 << CEPH_BLOCK_SHIFT;
Sage Weil92a49fb2013-02-22 15:31:00 -080078 buf->f_frsize = 1 << CEPH_BLOCK_SHIFT;
Luis Henriques9122eed2018-01-31 10:53:13 +000079
80 /*
81 * By default use root quota for stats; fallback to overall filesystem
82 * usage if using 'noquotadf' mount option or if the root dir doesn't
83 * have max_bytes quota set.
84 */
85 if (ceph_test_mount_opt(fsc, NOQUOTADF) ||
86 !ceph_quota_update_statfs(fsc, buf)) {
87 buf->f_blocks = le64_to_cpu(st.kb) >> (CEPH_BLOCK_SHIFT-10);
88 buf->f_bfree = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);
89 buf->f_bavail = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);
90 }
Sage Weil16725b92009-10-06 11:31:07 -070091
92 buf->f_files = le64_to_cpu(st.num_objects);
93 buf->f_ffree = -1;
Sage Weil558d3492010-06-01 12:51:12 -070094 buf->f_namelen = NAME_MAX;
Sage Weil16725b92009-10-06 11:31:07 -070095
Jeff Layton080a3302017-10-23 10:58:40 -040096 /* Must convert the fsid, for consistent values across arches */
Luis Henriques73fb0942018-05-28 18:37:40 +010097 mutex_lock(&monc->mutex);
98 fsid = le64_to_cpu(*(__le64 *)(&monc->monmap->fsid)) ^
99 le64_to_cpu(*((__le64 *)&monc->monmap->fsid + 1));
100 mutex_unlock(&monc->mutex);
101
Sage Weil16725b92009-10-06 11:31:07 -0700102 buf->f_fsid.val[0] = fsid & 0xffffffff;
103 buf->f_fsid.val[1] = fsid >> 32;
104
105 return 0;
106}
107
108
Sage Weil2d9c98a2010-07-30 09:38:13 -0700109static int ceph_sync_fs(struct super_block *sb, int wait)
Sage Weil16725b92009-10-06 11:31:07 -0700110{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700111 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
Sage Weil2d9c98a2010-07-30 09:38:13 -0700112
113 if (!wait) {
114 dout("sync_fs (non-blocking)\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700115 ceph_flush_dirty_caps(fsc->mdsc);
Sage Weil2d9c98a2010-07-30 09:38:13 -0700116 dout("sync_fs (non-blocking) done\n");
117 return 0;
118 }
119
120 dout("sync_fs (blocking)\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700121 ceph_osdc_sync(&fsc->client->osdc);
122 ceph_mdsc_sync(fsc->mdsc);
Sage Weil2d9c98a2010-07-30 09:38:13 -0700123 dout("sync_fs (blocking) done\n");
Sage Weil16725b92009-10-06 11:31:07 -0700124 return 0;
125}
126
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700127/*
128 * mount options
129 */
130enum {
131 Opt_wsize,
132 Opt_rsize,
Sage Weil83817e32011-08-04 08:03:44 -0700133 Opt_rasize,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700134 Opt_caps_wanted_delay_min,
135 Opt_caps_wanted_delay_max,
Yan, Zhengfe330322019-02-01 14:57:15 +0800136 Opt_caps_max,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700137 Opt_readdir_max_entries,
138 Opt_readdir_max_bytes,
139 Opt_congestion_kb,
140 Opt_last_int,
141 /* int args above */
142 Opt_snapdirname,
Yan, Zheng430afba2016-07-08 11:25:38 +0800143 Opt_mds_namespace,
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800144 Opt_fscache_uniq,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700145 Opt_last_string,
146 /* string args above */
147 Opt_dirstat,
148 Opt_nodirstat,
149 Opt_rbytes,
150 Opt_norbytes,
Alex Eldercffaba12012-02-15 07:43:54 -0600151 Opt_asyncreaddir,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700152 Opt_noasyncreaddir,
Sage Weila40dc6c2012-01-10 09:12:55 -0800153 Opt_dcache,
154 Opt_nodcache,
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800155 Opt_ino32,
Alex Eldercffaba12012-02-15 07:43:54 -0600156 Opt_noino32,
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400157 Opt_fscache,
Sage Weil45195e42014-02-16 10:05:29 -0800158 Opt_nofscache,
Yan, Zheng10183a62015-04-27 15:33:28 +0800159 Opt_poolperm,
160 Opt_nopoolperm,
Yan, Zhenge9e427f2016-11-10 16:02:06 +0800161 Opt_require_active_mds,
162 Opt_norequire_active_mds,
Sage Weil45195e42014-02-16 10:05:29 -0800163#ifdef CONFIG_CEPH_FS_POSIX_ACL
164 Opt_acl,
165#endif
Yan, Zheng10183a62015-04-27 15:33:28 +0800166 Opt_noacl,
Luis Henriques9122eed2018-01-31 10:53:13 +0000167 Opt_quotadf,
168 Opt_noquotadf,
Luis Henriquesea4cdc52018-10-15 16:46:00 +0100169 Opt_copyfrom,
170 Opt_nocopyfrom,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700171};
172
173static match_table_t fsopt_tokens = {
174 {Opt_wsize, "wsize=%d"},
175 {Opt_rsize, "rsize=%d"},
Sage Weil83817e32011-08-04 08:03:44 -0700176 {Opt_rasize, "rasize=%d"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700177 {Opt_caps_wanted_delay_min, "caps_wanted_delay_min=%d"},
178 {Opt_caps_wanted_delay_max, "caps_wanted_delay_max=%d"},
Yan, Zhengfe330322019-02-01 14:57:15 +0800179 {Opt_caps_max, "caps_max=%d"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700180 {Opt_readdir_max_entries, "readdir_max_entries=%d"},
181 {Opt_readdir_max_bytes, "readdir_max_bytes=%d"},
182 {Opt_congestion_kb, "write_congestion_kb=%d"},
183 /* int args above */
184 {Opt_snapdirname, "snapdirname=%s"},
Yan, Zheng430afba2016-07-08 11:25:38 +0800185 {Opt_mds_namespace, "mds_namespace=%s"},
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800186 {Opt_fscache_uniq, "fsc=%s"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700187 /* string args above */
188 {Opt_dirstat, "dirstat"},
189 {Opt_nodirstat, "nodirstat"},
190 {Opt_rbytes, "rbytes"},
191 {Opt_norbytes, "norbytes"},
Alex Eldercffaba12012-02-15 07:43:54 -0600192 {Opt_asyncreaddir, "asyncreaddir"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700193 {Opt_noasyncreaddir, "noasyncreaddir"},
Sage Weila40dc6c2012-01-10 09:12:55 -0800194 {Opt_dcache, "dcache"},
195 {Opt_nodcache, "nodcache"},
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800196 {Opt_ino32, "ino32"},
Alex Eldercffaba12012-02-15 07:43:54 -0600197 {Opt_noino32, "noino32"},
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400198 {Opt_fscache, "fsc"},
199 {Opt_nofscache, "nofsc"},
Yan, Zheng10183a62015-04-27 15:33:28 +0800200 {Opt_poolperm, "poolperm"},
201 {Opt_nopoolperm, "nopoolperm"},
Yan, Zhenge9e427f2016-11-10 16:02:06 +0800202 {Opt_require_active_mds, "require_active_mds"},
203 {Opt_norequire_active_mds, "norequire_active_mds"},
Sage Weil45195e42014-02-16 10:05:29 -0800204#ifdef CONFIG_CEPH_FS_POSIX_ACL
205 {Opt_acl, "acl"},
206#endif
207 {Opt_noacl, "noacl"},
Luis Henriques9122eed2018-01-31 10:53:13 +0000208 {Opt_quotadf, "quotadf"},
209 {Opt_noquotadf, "noquotadf"},
Luis Henriquesea4cdc52018-10-15 16:46:00 +0100210 {Opt_copyfrom, "copyfrom"},
211 {Opt_nocopyfrom, "nocopyfrom"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700212 {-1, NULL}
213};
214
215static int parse_fsopt_token(char *c, void *private)
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800216{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700217 struct ceph_mount_options *fsopt = private;
218 substring_t argstr[MAX_OPT_ARGS];
219 int token, intval, ret;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800220
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700221 token = match_token((char *)c, fsopt_tokens, argstr);
222 if (token < 0)
223 return -EINVAL;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800224
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700225 if (token < Opt_last_int) {
226 ret = match_int(&argstr[0], &intval);
227 if (ret < 0) {
Ilya Dryomov2f56b6b2018-06-27 16:38:13 +0200228 pr_err("bad option arg (not int) at '%s'\n", c);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700229 return ret;
230 }
231 dout("got int token %d val %d\n", token, intval);
232 } else if (token > Opt_last_int && token < Opt_last_string) {
233 dout("got string token %d val %s\n", token,
234 argstr[0].from);
235 } else {
236 dout("got token %d\n", token);
237 }
238
239 switch (token) {
240 case Opt_snapdirname:
241 kfree(fsopt->snapdir_name);
242 fsopt->snapdir_name = kstrndup(argstr[0].from,
243 argstr[0].to-argstr[0].from,
244 GFP_KERNEL);
245 if (!fsopt->snapdir_name)
246 return -ENOMEM;
247 break;
Yan, Zheng235a0982016-03-30 17:18:34 +0800248 case Opt_mds_namespace:
Chengguang Xu937441f2018-02-06 08:25:55 +0800249 kfree(fsopt->mds_namespace);
Yan, Zheng430afba2016-07-08 11:25:38 +0800250 fsopt->mds_namespace = kstrndup(argstr[0].from,
251 argstr[0].to-argstr[0].from,
252 GFP_KERNEL);
253 if (!fsopt->mds_namespace)
254 return -ENOMEM;
Yan, Zheng235a0982016-03-30 17:18:34 +0800255 break;
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800256 case Opt_fscache_uniq:
Chengguang Xu937441f2018-02-06 08:25:55 +0800257 kfree(fsopt->fscache_uniq);
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800258 fsopt->fscache_uniq = kstrndup(argstr[0].from,
259 argstr[0].to-argstr[0].from,
260 GFP_KERNEL);
261 if (!fsopt->fscache_uniq)
262 return -ENOMEM;
263 fsopt->flags |= CEPH_MOUNT_OPT_FSCACHE;
264 break;
Yan, Zheng430afba2016-07-08 11:25:38 +0800265 /* misc */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700266 case Opt_wsize:
Chengguang Xu8db0c752018-05-30 16:47:06 +0800267 if (intval < (int)PAGE_SIZE || intval > CEPH_MAX_WRITE_SIZE)
Yan, Zheng95cca2b2017-07-11 17:34:46 +0800268 return -EINVAL;
269 fsopt->wsize = ALIGN(intval, PAGE_SIZE);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700270 break;
271 case Opt_rsize:
Chengguang Xu8db0c752018-05-30 16:47:06 +0800272 if (intval < (int)PAGE_SIZE || intval > CEPH_MAX_READ_SIZE)
Yan, Zhengaa187922017-07-11 15:56:09 +0800273 return -EINVAL;
274 fsopt->rsize = ALIGN(intval, PAGE_SIZE);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700275 break;
Sage Weil83817e32011-08-04 08:03:44 -0700276 case Opt_rasize:
Yan, Zheng4214fb12017-07-11 18:49:44 +0800277 if (intval < 0)
278 return -EINVAL;
Chengguang Xuc36ed502018-05-30 10:13:11 +0800279 fsopt->rasize = ALIGN(intval, PAGE_SIZE);
Sage Weil83817e32011-08-04 08:03:44 -0700280 break;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700281 case Opt_caps_wanted_delay_min:
Yan, Zheng4214fb12017-07-11 18:49:44 +0800282 if (intval < 1)
283 return -EINVAL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700284 fsopt->caps_wanted_delay_min = intval;
285 break;
286 case Opt_caps_wanted_delay_max:
Yan, Zheng4214fb12017-07-11 18:49:44 +0800287 if (intval < 1)
288 return -EINVAL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700289 fsopt->caps_wanted_delay_max = intval;
290 break;
Yan, Zhengfe330322019-02-01 14:57:15 +0800291 case Opt_caps_max:
292 if (intval < 0)
293 return -EINVAL;
294 fsopt->caps_max = intval;
295 break;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700296 case Opt_readdir_max_entries:
Yan, Zheng4214fb12017-07-11 18:49:44 +0800297 if (intval < 1)
298 return -EINVAL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700299 fsopt->max_readdir = intval;
300 break;
301 case Opt_readdir_max_bytes:
Chengguang Xu8db0c752018-05-30 16:47:06 +0800302 if (intval < (int)PAGE_SIZE && intval != 0)
Yan, Zheng4214fb12017-07-11 18:49:44 +0800303 return -EINVAL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700304 fsopt->max_readdir_bytes = intval;
305 break;
306 case Opt_congestion_kb:
Yan, Zheng4214fb12017-07-11 18:49:44 +0800307 if (intval < 1024) /* at least 1M */
308 return -EINVAL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700309 fsopt->congestion_kb = intval;
310 break;
311 case Opt_dirstat:
312 fsopt->flags |= CEPH_MOUNT_OPT_DIRSTAT;
313 break;
314 case Opt_nodirstat:
315 fsopt->flags &= ~CEPH_MOUNT_OPT_DIRSTAT;
316 break;
317 case Opt_rbytes:
318 fsopt->flags |= CEPH_MOUNT_OPT_RBYTES;
319 break;
320 case Opt_norbytes:
321 fsopt->flags &= ~CEPH_MOUNT_OPT_RBYTES;
322 break;
Alex Eldercffaba12012-02-15 07:43:54 -0600323 case Opt_asyncreaddir:
324 fsopt->flags &= ~CEPH_MOUNT_OPT_NOASYNCREADDIR;
325 break;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700326 case Opt_noasyncreaddir:
327 fsopt->flags |= CEPH_MOUNT_OPT_NOASYNCREADDIR;
328 break;
Sage Weila40dc6c2012-01-10 09:12:55 -0800329 case Opt_dcache:
330 fsopt->flags |= CEPH_MOUNT_OPT_DCACHE;
331 break;
332 case Opt_nodcache:
333 fsopt->flags &= ~CEPH_MOUNT_OPT_DCACHE;
334 break;
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800335 case Opt_ino32:
336 fsopt->flags |= CEPH_MOUNT_OPT_INO32;
337 break;
Alex Eldercffaba12012-02-15 07:43:54 -0600338 case Opt_noino32:
339 fsopt->flags &= ~CEPH_MOUNT_OPT_INO32;
340 break;
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400341 case Opt_fscache:
342 fsopt->flags |= CEPH_MOUNT_OPT_FSCACHE;
Chengguang Xu7ae7a822018-02-07 10:27:06 +0800343 kfree(fsopt->fscache_uniq);
344 fsopt->fscache_uniq = NULL;
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400345 break;
346 case Opt_nofscache:
347 fsopt->flags &= ~CEPH_MOUNT_OPT_FSCACHE;
Chengguang Xu7ae7a822018-02-07 10:27:06 +0800348 kfree(fsopt->fscache_uniq);
349 fsopt->fscache_uniq = NULL;
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400350 break;
Yan, Zheng10183a62015-04-27 15:33:28 +0800351 case Opt_poolperm:
352 fsopt->flags &= ~CEPH_MOUNT_OPT_NOPOOLPERM;
Yan, Zheng10183a62015-04-27 15:33:28 +0800353 break;
354 case Opt_nopoolperm:
355 fsopt->flags |= CEPH_MOUNT_OPT_NOPOOLPERM;
356 break;
Yan, Zhenge9e427f2016-11-10 16:02:06 +0800357 case Opt_require_active_mds:
358 fsopt->flags &= ~CEPH_MOUNT_OPT_MOUNTWAIT;
359 break;
360 case Opt_norequire_active_mds:
361 fsopt->flags |= CEPH_MOUNT_OPT_MOUNTWAIT;
362 break;
Luis Henriques9122eed2018-01-31 10:53:13 +0000363 case Opt_quotadf:
364 fsopt->flags &= ~CEPH_MOUNT_OPT_NOQUOTADF;
365 break;
366 case Opt_noquotadf:
367 fsopt->flags |= CEPH_MOUNT_OPT_NOQUOTADF;
368 break;
Luis Henriquesea4cdc52018-10-15 16:46:00 +0100369 case Opt_copyfrom:
370 fsopt->flags &= ~CEPH_MOUNT_OPT_NOCOPYFROM;
371 break;
372 case Opt_nocopyfrom:
373 fsopt->flags |= CEPH_MOUNT_OPT_NOCOPYFROM;
374 break;
Sage Weil45195e42014-02-16 10:05:29 -0800375#ifdef CONFIG_CEPH_FS_POSIX_ACL
376 case Opt_acl:
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800377 fsopt->sb_flags |= SB_POSIXACL;
Sage Weil45195e42014-02-16 10:05:29 -0800378 break;
379#endif
380 case Opt_noacl:
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800381 fsopt->sb_flags &= ~SB_POSIXACL;
Sage Weil45195e42014-02-16 10:05:29 -0800382 break;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700383 default:
384 BUG_ON(token);
385 }
386 return 0;
387}
388
389static void destroy_mount_options(struct ceph_mount_options *args)
390{
391 dout("destroy_mount_options %p\n", args);
392 kfree(args->snapdir_name);
Yan, Zheng430afba2016-07-08 11:25:38 +0800393 kfree(args->mds_namespace);
Yan, Zheng3f384952016-04-21 11:09:55 +0800394 kfree(args->server_path);
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800395 kfree(args->fscache_uniq);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700396 kfree(args);
397}
398
399static int strcmp_null(const char *s1, const char *s2)
400{
401 if (!s1 && !s2)
402 return 0;
403 if (s1 && !s2)
404 return -1;
405 if (!s1 && s2)
406 return 1;
407 return strcmp(s1, s2);
408}
409
410static int compare_mount_options(struct ceph_mount_options *new_fsopt,
411 struct ceph_options *new_opt,
412 struct ceph_fs_client *fsc)
413{
414 struct ceph_mount_options *fsopt1 = new_fsopt;
415 struct ceph_mount_options *fsopt2 = fsc->mount_options;
416 int ofs = offsetof(struct ceph_mount_options, snapdir_name);
417 int ret;
418
419 ret = memcmp(fsopt1, fsopt2, ofs);
420 if (ret)
421 return ret;
422
423 ret = strcmp_null(fsopt1->snapdir_name, fsopt2->snapdir_name);
424 if (ret)
425 return ret;
Yan, Zheng430afba2016-07-08 11:25:38 +0800426 ret = strcmp_null(fsopt1->mds_namespace, fsopt2->mds_namespace);
427 if (ret)
428 return ret;
Yan, Zheng3f384952016-04-21 11:09:55 +0800429 ret = strcmp_null(fsopt1->server_path, fsopt2->server_path);
430 if (ret)
431 return ret;
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800432 ret = strcmp_null(fsopt1->fscache_uniq, fsopt2->fscache_uniq);
433 if (ret)
434 return ret;
Yan, Zheng3f384952016-04-21 11:09:55 +0800435
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700436 return ceph_compare_options(new_opt, fsc->client);
437}
438
439static int parse_mount_options(struct ceph_mount_options **pfsopt,
440 struct ceph_options **popt,
441 int flags, char *options,
Yan, Zheng3f384952016-04-21 11:09:55 +0800442 const char *dev_name)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700443{
444 struct ceph_mount_options *fsopt;
445 const char *dev_name_end;
Alex Elderc98f5332012-08-09 10:33:26 -0700446 int err;
447
448 if (!dev_name || !*dev_name)
449 return -EINVAL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700450
451 fsopt = kzalloc(sizeof(*fsopt), GFP_KERNEL);
452 if (!fsopt)
453 return -ENOMEM;
454
455 dout("parse_mount_options %p, dev_name '%s'\n", fsopt, dev_name);
456
Noah Watkins80db8be2011-08-22 13:49:23 -0600457 fsopt->sb_flags = flags;
458 fsopt->flags = CEPH_MOUNT_OPT_DEFAULT;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700459
Yan, Zheng95cca2b2017-07-11 17:34:46 +0800460 fsopt->wsize = CEPH_MAX_WRITE_SIZE;
Yan, Zhengaa187922017-07-11 15:56:09 +0800461 fsopt->rsize = CEPH_MAX_READ_SIZE;
Noah Watkins80db8be2011-08-22 13:49:23 -0600462 fsopt->rasize = CEPH_RASIZE_DEFAULT;
463 fsopt->snapdir_name = kstrdup(CEPH_SNAPDIRNAME_DEFAULT, GFP_KERNEL);
Sanidhya Kashyapa149bb92015-03-21 12:54:58 -0400464 if (!fsopt->snapdir_name) {
465 err = -ENOMEM;
466 goto out;
467 }
468
Sage Weil50aac4f2011-01-18 07:59:40 -0800469 fsopt->caps_wanted_delay_min = CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT;
470 fsopt->caps_wanted_delay_max = CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT;
Noah Watkins80db8be2011-08-22 13:49:23 -0600471 fsopt->max_readdir = CEPH_MAX_READDIR_DEFAULT;
472 fsopt->max_readdir_bytes = CEPH_MAX_READDIR_BYTES_DEFAULT;
473 fsopt->congestion_kb = default_congestion_kb();
474
Alex Elderc98f5332012-08-09 10:33:26 -0700475 /*
476 * Distinguish the server list from the path in "dev_name".
477 * Internally we do not include the leading '/' in the path.
478 *
479 * "dev_name" will look like:
480 * <server_spec>[,<server_spec>...]:[<path>]
481 * where
482 * <server_spec> is <ip>[:<port>]
483 * <path> is optional, but if present must begin with '/'
484 */
485 dev_name_end = strchr(dev_name, '/');
486 if (dev_name_end) {
Yan, Zhengce2728a2016-09-14 14:53:05 +0800487 if (strlen(dev_name_end) > 1) {
488 fsopt->server_path = kstrdup(dev_name_end, GFP_KERNEL);
489 if (!fsopt->server_path) {
490 err = -ENOMEM;
491 goto out;
492 }
Yan, Zheng3f384952016-04-21 11:09:55 +0800493 }
Alex Elderc98f5332012-08-09 10:33:26 -0700494 } else {
Alex Elderc98f5332012-08-09 10:33:26 -0700495 dev_name_end = dev_name + strlen(dev_name);
Alex Elderc98f5332012-08-09 10:33:26 -0700496 }
Noah Watkins80db8be2011-08-22 13:49:23 -0600497 err = -EINVAL;
Alex Elderc98f5332012-08-09 10:33:26 -0700498 dev_name_end--; /* back up to ':' separator */
Sasha Levin54464292013-07-01 18:33:39 -0400499 if (dev_name_end < dev_name || *dev_name_end != ':') {
Alex Elderc98f5332012-08-09 10:33:26 -0700500 pr_err("device name is missing path (no : separator in %s)\n",
Noah Watkins80db8be2011-08-22 13:49:23 -0600501 dev_name);
502 goto out;
503 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700504 dout("device name '%.*s'\n", (int)(dev_name_end - dev_name), dev_name);
Yan, Zheng3f384952016-04-21 11:09:55 +0800505 if (fsopt->server_path)
506 dout("server path '%s'\n", fsopt->server_path);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700507
Alex Elderee577412012-01-24 10:08:36 -0600508 *popt = ceph_parse_options(options, dev_name, dev_name_end,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700509 parse_fsopt_token, (void *)fsopt);
Alex Elderee577412012-01-24 10:08:36 -0600510 if (IS_ERR(*popt)) {
511 err = PTR_ERR(*popt);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700512 goto out;
Alex Elderee577412012-01-24 10:08:36 -0600513 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700514
515 /* success */
516 *pfsopt = fsopt;
517 return 0;
518
519out:
520 destroy_mount_options(fsopt);
521 return err;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800522}
523
Sage Weil6e19a162010-04-29 16:38:32 -0700524/**
525 * ceph_show_options - Show mount options in /proc/mounts
526 * @m: seq_file to write to
Al Viro34c80b12011-12-08 21:32:45 -0500527 * @root: root of that (sub)tree
Sage Weil6e19a162010-04-29 16:38:32 -0700528 */
Al Viro34c80b12011-12-08 21:32:45 -0500529static int ceph_show_options(struct seq_file *m, struct dentry *root)
Sage Weil6e19a162010-04-29 16:38:32 -0700530{
Al Viro34c80b12011-12-08 21:32:45 -0500531 struct ceph_fs_client *fsc = ceph_sb_to_client(root->d_sb);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700532 struct ceph_mount_options *fsopt = fsc->mount_options;
Ilya Dryomovff40f9a2015-03-25 21:02:16 +0300533 size_t pos;
534 int ret;
Sage Weil6e19a162010-04-29 16:38:32 -0700535
Ilya Dryomovff40f9a2015-03-25 21:02:16 +0300536 /* a comma between MNT/MS and client options */
537 seq_putc(m, ',');
538 pos = m->count;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700539
Dongsheng Yang02b2f542018-12-18 04:31:48 -0500540 ret = ceph_print_client_options(m, fsc->client, false);
Ilya Dryomovff40f9a2015-03-25 21:02:16 +0300541 if (ret)
542 return ret;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700543
Ilya Dryomovff40f9a2015-03-25 21:02:16 +0300544 /* retract our comma if no client options */
545 if (m->count == pos)
546 m->count--;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700547
548 if (fsopt->flags & CEPH_MOUNT_OPT_DIRSTAT)
549 seq_puts(m, ",dirstat");
Yan, Zheng133e9152016-01-25 10:44:33 +0800550 if ((fsopt->flags & CEPH_MOUNT_OPT_RBYTES))
551 seq_puts(m, ",rbytes");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700552 if (fsopt->flags & CEPH_MOUNT_OPT_NOASYNCREADDIR)
Sage Weil6e19a162010-04-29 16:38:32 -0700553 seq_puts(m, ",noasyncreaddir");
Ilya Dryomovff7eeb82015-03-25 21:10:09 +0300554 if ((fsopt->flags & CEPH_MOUNT_OPT_DCACHE) == 0)
Sage Weila40dc6c2012-01-10 09:12:55 -0800555 seq_puts(m, ",nodcache");
Chengguang Xu3619aa82018-06-04 16:03:51 +0800556 if (fsopt->flags & CEPH_MOUNT_OPT_INO32)
557 seq_puts(m, ",ino32");
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800558 if (fsopt->flags & CEPH_MOUNT_OPT_FSCACHE) {
Chengguang Xu4d8969a2018-02-15 15:39:05 +0800559 seq_show_option(m, "fsc", fsopt->fscache_uniq);
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800560 }
Yan, Zheng10183a62015-04-27 15:33:28 +0800561 if (fsopt->flags & CEPH_MOUNT_OPT_NOPOOLPERM)
562 seq_puts(m, ",nopoolperm");
Luis Henriques9122eed2018-01-31 10:53:13 +0000563 if (fsopt->flags & CEPH_MOUNT_OPT_NOQUOTADF)
564 seq_puts(m, ",noquotadf");
Sage Weil6e19a162010-04-29 16:38:32 -0700565
Sage Weil45195e42014-02-16 10:05:29 -0800566#ifdef CONFIG_CEPH_FS_POSIX_ACL
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800567 if (fsopt->sb_flags & SB_POSIXACL)
Sage Weil45195e42014-02-16 10:05:29 -0800568 seq_puts(m, ",acl");
569 else
570 seq_puts(m, ",noacl");
571#endif
572
Luis Henriques6f9718f2018-12-10 10:23:12 +0000573 if ((fsopt->flags & CEPH_MOUNT_OPT_NOCOPYFROM) == 0)
574 seq_puts(m, ",copyfrom");
Luis Henriquesea4cdc52018-10-15 16:46:00 +0100575
Yan, Zheng430afba2016-07-08 11:25:38 +0800576 if (fsopt->mds_namespace)
Chengguang Xu4d8969a2018-02-15 15:39:05 +0800577 seq_show_option(m, "mds_namespace", fsopt->mds_namespace);
Ilya Dryomov6dd49402018-05-03 16:26:55 +0200578 if (fsopt->wsize != CEPH_MAX_WRITE_SIZE)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700579 seq_printf(m, ",wsize=%d", fsopt->wsize);
Yan, Zhengaa187922017-07-11 15:56:09 +0800580 if (fsopt->rsize != CEPH_MAX_READ_SIZE)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700581 seq_printf(m, ",rsize=%d", fsopt->rsize);
Sage Weil83817e32011-08-04 08:03:44 -0700582 if (fsopt->rasize != CEPH_RASIZE_DEFAULT)
Sage Weil21519372011-12-01 08:06:52 -0800583 seq_printf(m, ",rasize=%d", fsopt->rasize);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700584 if (fsopt->congestion_kb != default_congestion_kb())
585 seq_printf(m, ",write_congestion_kb=%d", fsopt->congestion_kb);
Yan, Zhengfe330322019-02-01 14:57:15 +0800586 if (fsopt->caps_max)
587 seq_printf(m, ",caps_max=%d", fsopt->caps_max);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700588 if (fsopt->caps_wanted_delay_min != CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT)
Sage Weil6e19a162010-04-29 16:38:32 -0700589 seq_printf(m, ",caps_wanted_delay_min=%d",
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700590 fsopt->caps_wanted_delay_min);
591 if (fsopt->caps_wanted_delay_max != CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT)
Sage Weil6e19a162010-04-29 16:38:32 -0700592 seq_printf(m, ",caps_wanted_delay_max=%d",
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700593 fsopt->caps_wanted_delay_max);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700594 if (fsopt->max_readdir != CEPH_MAX_READDIR_DEFAULT)
595 seq_printf(m, ",readdir_max_entries=%d", fsopt->max_readdir);
596 if (fsopt->max_readdir_bytes != CEPH_MAX_READDIR_BYTES_DEFAULT)
597 seq_printf(m, ",readdir_max_bytes=%d", fsopt->max_readdir_bytes);
598 if (strcmp(fsopt->snapdir_name, CEPH_SNAPDIRNAME_DEFAULT))
Kees Cooka068acf2015-09-04 15:44:57 -0700599 seq_show_option(m, "snapdirname", fsopt->snapdir_name);
Ilya Dryomovff40f9a2015-03-25 21:02:16 +0300600
Sage Weil6e19a162010-04-29 16:38:32 -0700601 return 0;
602}
603
604/*
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700605 * handle any mon messages the standard library doesn't understand.
606 * return error if we don't either.
607 */
608static int extra_mon_dispatch(struct ceph_client *client, struct ceph_msg *msg)
609{
610 struct ceph_fs_client *fsc = client->private;
611 int type = le16_to_cpu(msg->hdr.type);
612
613 switch (type) {
614 case CEPH_MSG_MDS_MAP:
Yan, Zheng430afba2016-07-08 11:25:38 +0800615 ceph_mdsc_handle_mdsmap(fsc->mdsc, msg);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700616 return 0;
Yan, Zheng430afba2016-07-08 11:25:38 +0800617 case CEPH_MSG_FS_MAP_USER:
618 ceph_mdsc_handle_fsmap(fsc->mdsc, msg);
619 return 0;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700620 default:
621 return -1;
622 }
623}
624
625/*
626 * create a new fs client
Ilya Dryomov8aaff152018-08-24 15:32:43 +0200627 *
628 * Success or not, this function consumes @fsopt and @opt.
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700629 */
H Hartley Sweeten0c6d4b4e22011-09-23 11:53:30 -0700630static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700631 struct ceph_options *opt)
632{
633 struct ceph_fs_client *fsc;
Alex Elder3bf53332013-04-01 10:48:40 -0500634 int page_count;
635 size_t size;
Ilya Dryomov8aaff152018-08-24 15:32:43 +0200636 int err;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700637
638 fsc = kzalloc(sizeof(*fsc), GFP_KERNEL);
Ilya Dryomov8aaff152018-08-24 15:32:43 +0200639 if (!fsc) {
640 err = -ENOMEM;
641 goto fail;
642 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700643
Ilya Dryomov74da4a0f2017-03-03 18:16:07 +0100644 fsc->client = ceph_create_client(opt, fsc);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700645 if (IS_ERR(fsc->client)) {
646 err = PTR_ERR(fsc->client);
647 goto fail;
648 }
Ilya Dryomov8aaff152018-08-24 15:32:43 +0200649 opt = NULL; /* fsc->client now owns this */
Ilya Dryomovc843d132018-05-30 16:29:14 +0200650
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700651 fsc->client->extra_mon_dispatch = extra_mon_dispatch;
Dongsheng Yang02b2f542018-12-18 04:31:48 -0500652 ceph_set_opt(fsc->client, ABORT_ON_FULL);
Yan, Zheng430afba2016-07-08 11:25:38 +0800653
Markus Elfringd37b1d92017-08-20 20:22:02 +0200654 if (!fsopt->mds_namespace) {
Yan, Zheng430afba2016-07-08 11:25:38 +0800655 ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_MDSMAP,
656 0, true);
657 } else {
658 ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_FSMAP,
659 0, false);
660 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700661
662 fsc->mount_options = fsopt;
663
664 fsc->sb = NULL;
665 fsc->mount_state = CEPH_MOUNT_MOUNTING;
666
667 atomic_long_set(&fsc->writeback_count, 0);
668
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700669 err = -ENOMEM;
Tejun Heo01e6acc2011-01-03 14:49:45 +0100670 /*
671 * The number of concurrent works can be high but they don't need
672 * to be processed in parallel, limit concurrency.
673 */
674 fsc->wb_wq = alloc_workqueue("ceph-writeback", 0, 1);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200675 if (!fsc->wb_wq)
Jan Kara09dc9fc2017-04-12 12:24:33 +0200676 goto fail_client;
Tejun Heo01e6acc2011-01-03 14:49:45 +0100677 fsc->pg_inv_wq = alloc_workqueue("ceph-pg-invalid", 0, 1);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200678 if (!fsc->pg_inv_wq)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700679 goto fail_wb_wq;
Tejun Heo01e6acc2011-01-03 14:49:45 +0100680 fsc->trunc_wq = alloc_workqueue("ceph-trunc", 0, 1);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200681 if (!fsc->trunc_wq)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700682 goto fail_pg_inv_wq;
Yan, Zhenge3ec8d62019-01-14 17:21:19 +0800683 fsc->cap_wq = alloc_workqueue("ceph-cap", 0, 1);
684 if (!fsc->cap_wq)
685 goto fail_trunc_wq;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700686
687 /* set up mempools */
688 err = -ENOMEM;
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300689 page_count = fsc->mount_options->wsize >> PAGE_SHIFT;
Alex Elder3bf53332013-04-01 10:48:40 -0500690 size = sizeof (struct page *) * (page_count ? page_count : 1);
691 fsc->wb_pagevec_pool = mempool_create_kmalloc_pool(10, size);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700692 if (!fsc->wb_pagevec_pool)
Yan, Zhenge3ec8d62019-01-14 17:21:19 +0800693 goto fail_cap_wq;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700694
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700695 return fsc;
696
Yan, Zhenge3ec8d62019-01-14 17:21:19 +0800697fail_cap_wq:
698 destroy_workqueue(fsc->cap_wq);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700699fail_trunc_wq:
700 destroy_workqueue(fsc->trunc_wq);
701fail_pg_inv_wq:
702 destroy_workqueue(fsc->pg_inv_wq);
703fail_wb_wq:
704 destroy_workqueue(fsc->wb_wq);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700705fail_client:
706 ceph_destroy_client(fsc->client);
707fail:
708 kfree(fsc);
Ilya Dryomov8aaff152018-08-24 15:32:43 +0200709 if (opt)
710 ceph_destroy_options(opt);
711 destroy_mount_options(fsopt);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700712 return ERR_PTR(err);
713}
714
Yan, Zhenga57d9062018-05-18 16:05:51 +0800715static void flush_fs_workqueues(struct ceph_fs_client *fsc)
716{
717 flush_workqueue(fsc->wb_wq);
718 flush_workqueue(fsc->pg_inv_wq);
719 flush_workqueue(fsc->trunc_wq);
Yan, Zhenge3ec8d62019-01-14 17:21:19 +0800720 flush_workqueue(fsc->cap_wq);
Yan, Zhenga57d9062018-05-18 16:05:51 +0800721}
722
H Hartley Sweeten0c6d4b4e22011-09-23 11:53:30 -0700723static void destroy_fs_client(struct ceph_fs_client *fsc)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700724{
725 dout("destroy_fs_client %p\n", fsc);
726
727 destroy_workqueue(fsc->wb_wq);
728 destroy_workqueue(fsc->pg_inv_wq);
729 destroy_workqueue(fsc->trunc_wq);
Yan, Zhenge3ec8d62019-01-14 17:21:19 +0800730 destroy_workqueue(fsc->cap_wq);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700731
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700732 mempool_destroy(fsc->wb_pagevec_pool);
733
734 destroy_mount_options(fsc->mount_options);
735
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700736 ceph_destroy_client(fsc->client);
737
738 kfree(fsc);
739 dout("destroy_fs_client %p done\n", fsc);
740}
741
742/*
Sage Weil6e19a162010-04-29 16:38:32 -0700743 * caches
744 */
745struct kmem_cache *ceph_inode_cachep;
746struct kmem_cache *ceph_cap_cachep;
Yan, Zhengf66fd9f2015-06-10 17:26:13 +0800747struct kmem_cache *ceph_cap_flush_cachep;
Sage Weil6e19a162010-04-29 16:38:32 -0700748struct kmem_cache *ceph_dentry_cachep;
749struct kmem_cache *ceph_file_cachep;
Chengguang Xubb48bd42018-03-13 10:42:44 +0800750struct kmem_cache *ceph_dir_file_cachep;
Sage Weil6e19a162010-04-29 16:38:32 -0700751
752static void ceph_inode_init_once(void *foo)
753{
754 struct ceph_inode_info *ci = foo;
755 inode_init_once(&ci->vfs_inode);
756}
757
Sage Weil16725b92009-10-06 11:31:07 -0700758static int __init init_caches(void)
759{
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400760 int error = -ENOMEM;
761
Sage Weil16725b92009-10-06 11:31:07 -0700762 ceph_inode_cachep = kmem_cache_create("ceph_inode_info",
763 sizeof(struct ceph_inode_info),
764 __alignof__(struct ceph_inode_info),
Vladimir Davydov5d097052016-01-14 15:18:21 -0800765 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|
766 SLAB_ACCOUNT, ceph_inode_init_once);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200767 if (!ceph_inode_cachep)
Sage Weil16725b92009-10-06 11:31:07 -0700768 return -ENOMEM;
769
Chengguang Xubc4b5ad2018-02-27 13:49:44 +0800770 ceph_cap_cachep = KMEM_CACHE(ceph_cap, SLAB_MEM_SPREAD);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200771 if (!ceph_cap_cachep)
Sage Weil16725b92009-10-06 11:31:07 -0700772 goto bad_cap;
Yan, Zhengf66fd9f2015-06-10 17:26:13 +0800773 ceph_cap_flush_cachep = KMEM_CACHE(ceph_cap_flush,
774 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200775 if (!ceph_cap_flush_cachep)
Yan, Zhengf66fd9f2015-06-10 17:26:13 +0800776 goto bad_cap_flush;
Sage Weil16725b92009-10-06 11:31:07 -0700777
778 ceph_dentry_cachep = KMEM_CACHE(ceph_dentry_info,
779 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200780 if (!ceph_dentry_cachep)
Sage Weil16725b92009-10-06 11:31:07 -0700781 goto bad_dentry;
782
Nikolay Borisov6b1a9a62016-07-25 20:12:13 +0300783 ceph_file_cachep = KMEM_CACHE(ceph_file_info, SLAB_MEM_SPREAD);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200784 if (!ceph_file_cachep)
Sage Weil16725b92009-10-06 11:31:07 -0700785 goto bad_file;
786
Chengguang Xubb48bd42018-03-13 10:42:44 +0800787 ceph_dir_file_cachep = KMEM_CACHE(ceph_dir_file_info, SLAB_MEM_SPREAD);
788 if (!ceph_dir_file_cachep)
789 goto bad_dir_file;
790
Chengguang Xu1c789242018-03-01 14:24:51 +0800791 error = ceph_fscache_register();
792 if (error)
793 goto bad_fscache;
Sage Weil16725b92009-10-06 11:31:07 -0700794
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400795 return 0;
Chengguang Xu1c789242018-03-01 14:24:51 +0800796
797bad_fscache:
Chengguang Xubb48bd42018-03-13 10:42:44 +0800798 kmem_cache_destroy(ceph_dir_file_cachep);
799bad_dir_file:
Chengguang Xu1c789242018-03-01 14:24:51 +0800800 kmem_cache_destroy(ceph_file_cachep);
Sage Weil16725b92009-10-06 11:31:07 -0700801bad_file:
802 kmem_cache_destroy(ceph_dentry_cachep);
803bad_dentry:
Yan, Zhengf66fd9f2015-06-10 17:26:13 +0800804 kmem_cache_destroy(ceph_cap_flush_cachep);
805bad_cap_flush:
Sage Weil16725b92009-10-06 11:31:07 -0700806 kmem_cache_destroy(ceph_cap_cachep);
807bad_cap:
808 kmem_cache_destroy(ceph_inode_cachep);
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400809 return error;
Sage Weil16725b92009-10-06 11:31:07 -0700810}
811
812static void destroy_caches(void)
813{
Kirill A. Shutemov8c0a8532012-09-26 11:33:07 +1000814 /*
815 * Make sure all delayed rcu free inodes are flushed before we
816 * destroy cache.
817 */
818 rcu_barrier();
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400819
Sage Weil16725b92009-10-06 11:31:07 -0700820 kmem_cache_destroy(ceph_inode_cachep);
821 kmem_cache_destroy(ceph_cap_cachep);
Yan, Zhengf66fd9f2015-06-10 17:26:13 +0800822 kmem_cache_destroy(ceph_cap_flush_cachep);
Sage Weil16725b92009-10-06 11:31:07 -0700823 kmem_cache_destroy(ceph_dentry_cachep);
824 kmem_cache_destroy(ceph_file_cachep);
Chengguang Xubb48bd42018-03-13 10:42:44 +0800825 kmem_cache_destroy(ceph_dir_file_cachep);
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400826
827 ceph_fscache_unregister();
Sage Weil16725b92009-10-06 11:31:07 -0700828}
829
830
831/*
832 * ceph_umount_begin - initiate forced umount. Tear down down the
833 * mount, skipping steps that may hang while waiting for server(s).
834 */
835static void ceph_umount_begin(struct super_block *sb)
836{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700837 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
Sage Weil16725b92009-10-06 11:31:07 -0700838
839 dout("ceph_umount_begin - starting forced umount\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700840 if (!fsc)
Sage Weil16725b92009-10-06 11:31:07 -0700841 return;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700842 fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
Yan, Zheng12b69d52018-05-11 17:12:02 +0800843 ceph_osdc_abort_requests(&fsc->client->osdc, -EIO);
Yan, Zheng48fec5d2015-07-01 16:27:46 +0800844 ceph_mdsc_force_umount(fsc->mdsc);
Sage Weil16725b92009-10-06 11:31:07 -0700845 return;
846}
847
848static const struct super_operations ceph_super_ops = {
849 .alloc_inode = ceph_alloc_inode,
850 .destroy_inode = ceph_destroy_inode,
851 .write_inode = ceph_write_inode,
Yan, Zheng9f12bd12013-09-20 19:55:31 +0800852 .drop_inode = ceph_drop_inode,
Sage Weil2d9c98a2010-07-30 09:38:13 -0700853 .sync_fs = ceph_sync_fs,
Sage Weil16725b92009-10-06 11:31:07 -0700854 .put_super = ceph_put_super,
855 .show_options = ceph_show_options,
856 .statfs = ceph_statfs,
857 .umount_begin = ceph_umount_begin,
858};
859
Sage Weil16725b92009-10-06 11:31:07 -0700860/*
861 * Bootstrap mount by opening the root directory. Note the mount
862 * @started time from caller, and time out if this takes too long.
863 */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700864static struct dentry *open_root_dentry(struct ceph_fs_client *fsc,
Sage Weil16725b92009-10-06 11:31:07 -0700865 const char *path,
866 unsigned long started)
867{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700868 struct ceph_mds_client *mdsc = fsc->mdsc;
Sage Weil16725b92009-10-06 11:31:07 -0700869 struct ceph_mds_request *req = NULL;
870 int err;
871 struct dentry *root;
872
873 /* open dir */
874 dout("open_root_inode opening '%s'\n", path);
875 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_GETATTR, USE_ANY_MDS);
876 if (IS_ERR(req))
Julia Lawall7e34bc52010-05-22 12:01:14 +0200877 return ERR_CAST(req);
Sage Weil16725b92009-10-06 11:31:07 -0700878 req->r_path1 = kstrdup(path, GFP_NOFS);
Sanidhya Kashyapa149bb92015-03-21 12:54:58 -0400879 if (!req->r_path1) {
880 root = ERR_PTR(-ENOMEM);
881 goto out;
882 }
883
Sage Weil16725b92009-10-06 11:31:07 -0700884 req->r_ino1.ino = CEPH_INO_ROOT;
885 req->r_ino1.snap = CEPH_NOSNAP;
886 req->r_started = started;
Ilya Dryomova319bf52015-05-15 12:02:17 +0300887 req->r_timeout = fsc->client->options->mount_timeout;
Sage Weil16725b92009-10-06 11:31:07 -0700888 req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INODE);
889 req->r_num_caps = 2;
890 err = ceph_mdsc_do_request(mdsc, NULL, req);
891 if (err == 0) {
Al Viro3c5184e2012-01-09 16:34:32 -0500892 struct inode *inode = req->r_target_inode;
893 req->r_target_inode = NULL;
Sage Weil16725b92009-10-06 11:31:07 -0700894 dout("open_root_inode success\n");
Yan, Zhengce2728a2016-09-14 14:53:05 +0800895 root = d_make_root(inode);
896 if (!root) {
897 root = ERR_PTR(-ENOMEM);
898 goto out;
Sage Weil774ac212011-11-11 09:48:08 -0800899 }
Sage Weil16725b92009-10-06 11:31:07 -0700900 dout("open_root_inode success, root dentry is %p\n", root);
901 } else {
902 root = ERR_PTR(err);
903 }
Al Viro3c5184e2012-01-09 16:34:32 -0500904out:
Sage Weil16725b92009-10-06 11:31:07 -0700905 ceph_mdsc_put_request(req);
906 return root;
907}
908
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700909
910
911
Sage Weil16725b92009-10-06 11:31:07 -0700912/*
913 * mount: join the ceph cluster, and open root directory.
914 */
Yan, Zheng3f384952016-04-21 11:09:55 +0800915static struct dentry *ceph_real_mount(struct ceph_fs_client *fsc)
Sage Weil16725b92009-10-06 11:31:07 -0700916{
Sage Weil16725b92009-10-06 11:31:07 -0700917 int err;
Sage Weil16725b92009-10-06 11:31:07 -0700918 unsigned long started = jiffies; /* note the start time */
919 struct dentry *root;
920
Yan, Zheng132ca7e2016-03-12 13:20:48 +0800921 dout("mount start %p\n", fsc);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700922 mutex_lock(&fsc->client->mount_mutex);
Sage Weil16725b92009-10-06 11:31:07 -0700923
Yan, Zheng132ca7e2016-03-12 13:20:48 +0800924 if (!fsc->sb->s_root) {
Yan, Zhengce2728a2016-09-14 14:53:05 +0800925 const char *path;
Yan, Zheng132ca7e2016-03-12 13:20:48 +0800926 err = __ceph_open_session(fsc->client, started);
927 if (err < 0)
928 goto out;
Sage Weil16725b92009-10-06 11:31:07 -0700929
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800930 /* setup fscache */
931 if (fsc->mount_options->flags & CEPH_MOUNT_OPT_FSCACHE) {
932 err = ceph_fscache_register_fs(fsc);
933 if (err < 0)
934 goto out;
935 }
936
Yan, Zhengce2728a2016-09-14 14:53:05 +0800937 if (!fsc->mount_options->server_path) {
938 path = "";
939 dout("mount opening path \\t\n");
940 } else {
941 path = fsc->mount_options->server_path + 1;
942 dout("mount opening path %s\n", path);
943 }
Chengguang Xu18106732018-02-09 20:40:59 +0800944
945 err = ceph_fs_debugfs_init(fsc);
946 if (err < 0)
947 goto out;
948
Yan, Zhengce2728a2016-09-14 14:53:05 +0800949 root = open_root_dentry(fsc, path, started);
Yan, Zheng132ca7e2016-03-12 13:20:48 +0800950 if (IS_ERR(root)) {
951 err = PTR_ERR(root);
952 goto out;
953 }
Yan, Zhengce2728a2016-09-14 14:53:05 +0800954 fsc->sb->s_root = dget(root);
Geert Uytterhoeven31ca5872016-10-13 17:15:37 +0200955 } else {
956 root = dget(fsc->sb->s_root);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700957 }
Sage Weil16725b92009-10-06 11:31:07 -0700958
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700959 fsc->mount_state = CEPH_MOUNT_MOUNTED;
Sage Weil16725b92009-10-06 11:31:07 -0700960 dout("mount success\n");
Al Viroa7f9fb22010-07-26 16:17:55 +0400961 mutex_unlock(&fsc->client->mount_mutex);
962 return root;
Sage Weil16725b92009-10-06 11:31:07 -0700963
Yan, Zheng132ca7e2016-03-12 13:20:48 +0800964out:
965 mutex_unlock(&fsc->client->mount_mutex);
966 return ERR_PTR(err);
Sage Weil16725b92009-10-06 11:31:07 -0700967}
968
969static int ceph_set_super(struct super_block *s, void *data)
970{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700971 struct ceph_fs_client *fsc = data;
Sage Weil16725b92009-10-06 11:31:07 -0700972 int ret;
973
974 dout("set_super %p data %p\n", s, data);
975
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700976 s->s_flags = fsc->mount_options->sb_flags;
Chengguang Xu719784b2018-07-19 22:15:24 +0800977 s->s_maxbytes = MAX_LFS_FILESIZE;
Sage Weil16725b92009-10-06 11:31:07 -0700978
Guangliang Zhao7221fe42013-11-11 15:18:03 +0800979 s->s_xattr = ceph_xattr_handlers;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700980 s->s_fs_info = fsc;
981 fsc->sb = s;
Chengguang Xu719784b2018-07-19 22:15:24 +0800982 fsc->max_file_size = 1ULL << 40; /* temp value until we get mdsmap */
Sage Weil16725b92009-10-06 11:31:07 -0700983
984 s->s_op = &ceph_super_ops;
Al Viro18fc8ab2016-10-28 21:52:50 -0400985 s->s_d_op = &ceph_dentry_ops;
Sage Weil16725b92009-10-06 11:31:07 -0700986 s->s_export_op = &ceph_export_ops;
987
988 s->s_time_gran = 1000; /* 1000 ns == 1 us */
989
990 ret = set_anon_super(s, NULL); /* what is that second arg for? */
991 if (ret != 0)
992 goto fail;
993
994 return ret;
995
996fail:
997 s->s_fs_info = NULL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700998 fsc->sb = NULL;
Sage Weil16725b92009-10-06 11:31:07 -0700999 return ret;
1000}
1001
1002/*
1003 * share superblock if same fs AND options
1004 */
1005static int ceph_compare_super(struct super_block *sb, void *data)
1006{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001007 struct ceph_fs_client *new = data;
1008 struct ceph_mount_options *fsopt = new->mount_options;
1009 struct ceph_options *opt = new->client->options;
1010 struct ceph_fs_client *other = ceph_sb_to_client(sb);
Sage Weil16725b92009-10-06 11:31:07 -07001011
1012 dout("ceph_compare_super %p\n", sb);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001013
1014 if (compare_mount_options(fsopt, opt, other)) {
1015 dout("monitor(s)/mount options don't match\n");
1016 return 0;
Sage Weil16725b92009-10-06 11:31:07 -07001017 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001018 if ((opt->flags & CEPH_OPT_FSID) &&
1019 ceph_fsid_compare(&opt->fsid, &other->client->fsid)) {
1020 dout("fsid doesn't match\n");
1021 return 0;
1022 }
1023 if (fsopt->sb_flags != other->mount_options->sb_flags) {
Sage Weil16725b92009-10-06 11:31:07 -07001024 dout("flags differ\n");
1025 return 0;
1026 }
1027 return 1;
1028}
1029
1030/*
1031 * construct our own bdi so we can control readahead, etc.
1032 */
Jeff Mahoney00d56432010-06-10 11:13:58 -04001033static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
Sage Weil31e0cf82010-05-04 16:39:35 -07001034
Jan Kara09dc9fc2017-04-12 12:24:33 +02001035static int ceph_setup_bdi(struct super_block *sb, struct ceph_fs_client *fsc)
Sage Weil16725b92009-10-06 11:31:07 -07001036{
1037 int err;
1038
Jan Kara09dc9fc2017-04-12 12:24:33 +02001039 err = super_setup_bdi_name(sb, "ceph-%ld",
1040 atomic_long_inc_return(&bdi_seq));
1041 if (err)
1042 return err;
1043
Sage Weil83817e32011-08-04 08:03:44 -07001044 /* set ra_pages based on rasize mount option? */
Yan, Zheng4214fb12017-07-11 18:49:44 +08001045 sb->s_bdi->ra_pages = fsc->mount_options->rasize >> PAGE_SHIFT;
Yehuda Sadehe9852222011-07-22 11:12:28 -07001046
Yan, Zhengaa187922017-07-11 15:56:09 +08001047 /* set io_pages based on max osd read size */
1048 sb->s_bdi->io_pages = fsc->mount_options->rsize >> PAGE_SHIFT;
Andreas Gerstmayr7c94ba22017-01-10 14:17:56 +01001049
Jan Kara09dc9fc2017-04-12 12:24:33 +02001050 return 0;
Sage Weil16725b92009-10-06 11:31:07 -07001051}
1052
Al Viroa7f9fb22010-07-26 16:17:55 +04001053static struct dentry *ceph_mount(struct file_system_type *fs_type,
1054 int flags, const char *dev_name, void *data)
Sage Weil16725b92009-10-06 11:31:07 -07001055{
1056 struct super_block *sb;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001057 struct ceph_fs_client *fsc;
Al Viroa7f9fb22010-07-26 16:17:55 +04001058 struct dentry *res;
Sage Weil16725b92009-10-06 11:31:07 -07001059 int err;
1060 int (*compare_super)(struct super_block *, void *) = ceph_compare_super;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001061 struct ceph_mount_options *fsopt = NULL;
1062 struct ceph_options *opt = NULL;
Sage Weil16725b92009-10-06 11:31:07 -07001063
Al Viroa7f9fb22010-07-26 16:17:55 +04001064 dout("ceph_mount\n");
Sage Weil45195e42014-02-16 10:05:29 -08001065
1066#ifdef CONFIG_CEPH_FS_POSIX_ACL
Linus Torvalds1751e8a2017-11-27 13:05:09 -08001067 flags |= SB_POSIXACL;
Sage Weil45195e42014-02-16 10:05:29 -08001068#endif
Yan, Zheng3f384952016-04-21 11:09:55 +08001069 err = parse_mount_options(&fsopt, &opt, flags, data, dev_name);
Al Viroa7f9fb22010-07-26 16:17:55 +04001070 if (err < 0) {
1071 res = ERR_PTR(err);
Sage Weil6b805182009-10-27 11:50:50 -07001072 goto out_final;
Al Viroa7f9fb22010-07-26 16:17:55 +04001073 }
Sage Weil16725b92009-10-06 11:31:07 -07001074
1075 /* create client (which we may/may not use) */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001076 fsc = create_fs_client(fsopt, opt);
1077 if (IS_ERR(fsc)) {
Al Viroa7f9fb22010-07-26 16:17:55 +04001078 res = ERR_CAST(fsc);
Sage Weil6b805182009-10-27 11:50:50 -07001079 goto out_final;
1080 }
Sage Weil16725b92009-10-06 11:31:07 -07001081
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001082 err = ceph_mdsc_init(fsc);
Al Viroa7f9fb22010-07-26 16:17:55 +04001083 if (err < 0) {
1084 res = ERR_PTR(err);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001085 goto out;
Al Viroa7f9fb22010-07-26 16:17:55 +04001086 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001087
1088 if (ceph_test_opt(fsc->client, NOSHARE))
Sage Weil16725b92009-10-06 11:31:07 -07001089 compare_super = NULL;
David Howells9249e172012-06-25 12:55:37 +01001090 sb = sget(fs_type, compare_super, ceph_set_super, flags, fsc);
Sage Weil16725b92009-10-06 11:31:07 -07001091 if (IS_ERR(sb)) {
Al Viroa7f9fb22010-07-26 16:17:55 +04001092 res = ERR_CAST(sb);
Sage Weil16725b92009-10-06 11:31:07 -07001093 goto out;
1094 }
1095
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001096 if (ceph_sb_to_client(sb) != fsc) {
1097 ceph_mdsc_destroy(fsc);
1098 destroy_fs_client(fsc);
1099 fsc = ceph_sb_to_client(sb);
1100 dout("get_sb got existing client %p\n", fsc);
Sage Weil16725b92009-10-06 11:31:07 -07001101 } else {
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001102 dout("get_sb using new client %p\n", fsc);
Jan Kara09dc9fc2017-04-12 12:24:33 +02001103 err = ceph_setup_bdi(sb, fsc);
Al Viroa7f9fb22010-07-26 16:17:55 +04001104 if (err < 0) {
1105 res = ERR_PTR(err);
Sage Weil16725b92009-10-06 11:31:07 -07001106 goto out_splat;
Al Viroa7f9fb22010-07-26 16:17:55 +04001107 }
Sage Weil16725b92009-10-06 11:31:07 -07001108 }
1109
Yan, Zheng3f384952016-04-21 11:09:55 +08001110 res = ceph_real_mount(fsc);
Al Viroa7f9fb22010-07-26 16:17:55 +04001111 if (IS_ERR(res))
Sage Weil16725b92009-10-06 11:31:07 -07001112 goto out_splat;
Al Viroa7f9fb22010-07-26 16:17:55 +04001113 dout("root %p inode %p ino %llx.%llx\n", res,
David Howells2b0143b2015-03-17 22:25:59 +00001114 d_inode(res), ceph_vinop(d_inode(res)));
Al Viroa7f9fb22010-07-26 16:17:55 +04001115 return res;
Sage Weil16725b92009-10-06 11:31:07 -07001116
1117out_splat:
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001118 ceph_mdsc_close_sessions(fsc->mdsc);
Al Viro3981f2e2010-03-21 19:22:29 -04001119 deactivate_locked_super(sb);
Sage Weil16725b92009-10-06 11:31:07 -07001120 goto out_final;
1121
1122out:
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001123 ceph_mdsc_destroy(fsc);
1124 destroy_fs_client(fsc);
Sage Weil16725b92009-10-06 11:31:07 -07001125out_final:
Al Viroa7f9fb22010-07-26 16:17:55 +04001126 dout("ceph_mount fail %ld\n", PTR_ERR(res));
1127 return res;
Sage Weil16725b92009-10-06 11:31:07 -07001128}
1129
1130static void ceph_kill_sb(struct super_block *s)
1131{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001132 struct ceph_fs_client *fsc = ceph_sb_to_client(s);
Christoph Hellwige4d27502015-01-14 10:42:38 +01001133 dev_t dev = s->s_dev;
1134
Sage Weil16725b92009-10-06 11:31:07 -07001135 dout("kill_sb %p\n", s);
Christoph Hellwige4d27502015-01-14 10:42:38 +01001136
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001137 ceph_mdsc_pre_umount(fsc->mdsc);
Yan, Zhenga57d9062018-05-18 16:05:51 +08001138 flush_fs_workqueues(fsc);
1139
Christoph Hellwige4d27502015-01-14 10:42:38 +01001140 generic_shutdown_super(s);
Yan, Zheng62a65f32017-06-22 16:26:34 +08001141
1142 fsc->client->extra_mon_dispatch = NULL;
1143 ceph_fs_debugfs_cleanup(fsc);
1144
Yan, Zheng1d8f8362017-06-27 11:57:56 +08001145 ceph_fscache_unregister_fs(fsc);
1146
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001147 ceph_mdsc_destroy(fsc);
Christoph Hellwige4d27502015-01-14 10:42:38 +01001148
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001149 destroy_fs_client(fsc);
Christoph Hellwige4d27502015-01-14 10:42:38 +01001150 free_anon_bdev(dev);
Sage Weil16725b92009-10-06 11:31:07 -07001151}
1152
1153static struct file_system_type ceph_fs_type = {
1154 .owner = THIS_MODULE,
1155 .name = "ceph",
Al Viroa7f9fb22010-07-26 16:17:55 +04001156 .mount = ceph_mount,
Sage Weil16725b92009-10-06 11:31:07 -07001157 .kill_sb = ceph_kill_sb,
1158 .fs_flags = FS_RENAME_DOES_D_MOVE,
1159};
Eric W. Biederman7f78e032013-03-02 19:39:14 -08001160MODULE_ALIAS_FS("ceph");
Sage Weil16725b92009-10-06 11:31:07 -07001161
Sage Weil16725b92009-10-06 11:31:07 -07001162static int __init init_ceph(void)
1163{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001164 int ret = init_caches();
Sage Weil16725b92009-10-06 11:31:07 -07001165 if (ret)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001166 goto out;
Sage Weil16725b92009-10-06 11:31:07 -07001167
Yan, Zhengeb13e832014-03-09 23:16:40 +08001168 ceph_flock_init();
Alex Elder3ce6cd12012-01-23 15:49:28 -06001169 ceph_xattr_init();
Sage Weil16725b92009-10-06 11:31:07 -07001170 ret = register_filesystem(&ceph_fs_type);
1171 if (ret)
Ilya Dryomov34b759b2016-02-16 15:00:24 +01001172 goto out_xattr;
Sage Weil16725b92009-10-06 11:31:07 -07001173
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001174 pr_info("loaded (mds proto %d)\n", CEPH_MDSC_PROTOCOL);
1175
Sage Weil16725b92009-10-06 11:31:07 -07001176 return 0;
1177
Yan, Zheng97c85a82014-11-06 15:09:41 +08001178out_xattr:
Alex Elder3ce6cd12012-01-23 15:49:28 -06001179 ceph_xattr_exit();
Sage Weil16725b92009-10-06 11:31:07 -07001180 destroy_caches();
Sage Weil16725b92009-10-06 11:31:07 -07001181out:
1182 return ret;
1183}
1184
1185static void __exit exit_ceph(void)
1186{
1187 dout("exit_ceph\n");
1188 unregister_filesystem(&ceph_fs_type);
Alex Elder3ce6cd12012-01-23 15:49:28 -06001189 ceph_xattr_exit();
Sage Weil16725b92009-10-06 11:31:07 -07001190 destroy_caches();
Sage Weil16725b92009-10-06 11:31:07 -07001191}
1192
1193module_init(init_ceph);
1194module_exit(exit_ceph);
1195
1196MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
1197MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
1198MODULE_AUTHOR("Patience Warnick <patience@newdream.net>");
1199MODULE_DESCRIPTION("Ceph filesystem for Linux");
1200MODULE_LICENSE("GPL");