blob: 03b63b1cd32cbc91f68f04417f33be1937620a3a [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,
Yan, Zheng131d7eb2019-07-25 20:16:47 +0800146 Opt_recover_session,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700147 Opt_last_string,
148 /* string args above */
149 Opt_dirstat,
150 Opt_nodirstat,
151 Opt_rbytes,
152 Opt_norbytes,
Alex Eldercffaba12012-02-15 07:43:54 -0600153 Opt_asyncreaddir,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700154 Opt_noasyncreaddir,
Sage Weila40dc6c2012-01-10 09:12:55 -0800155 Opt_dcache,
156 Opt_nodcache,
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800157 Opt_ino32,
Alex Eldercffaba12012-02-15 07:43:54 -0600158 Opt_noino32,
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400159 Opt_fscache,
Sage Weil45195e42014-02-16 10:05:29 -0800160 Opt_nofscache,
Yan, Zheng10183a62015-04-27 15:33:28 +0800161 Opt_poolperm,
162 Opt_nopoolperm,
Yan, Zhenge9e427f2016-11-10 16:02:06 +0800163 Opt_require_active_mds,
164 Opt_norequire_active_mds,
Sage Weil45195e42014-02-16 10:05:29 -0800165#ifdef CONFIG_CEPH_FS_POSIX_ACL
166 Opt_acl,
167#endif
Yan, Zheng10183a62015-04-27 15:33:28 +0800168 Opt_noacl,
Luis Henriques9122eed2018-01-31 10:53:13 +0000169 Opt_quotadf,
170 Opt_noquotadf,
Luis Henriquesea4cdc52018-10-15 16:46:00 +0100171 Opt_copyfrom,
172 Opt_nocopyfrom,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700173};
174
175static match_table_t fsopt_tokens = {
176 {Opt_wsize, "wsize=%d"},
177 {Opt_rsize, "rsize=%d"},
Sage Weil83817e32011-08-04 08:03:44 -0700178 {Opt_rasize, "rasize=%d"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700179 {Opt_caps_wanted_delay_min, "caps_wanted_delay_min=%d"},
180 {Opt_caps_wanted_delay_max, "caps_wanted_delay_max=%d"},
Yan, Zhengfe330322019-02-01 14:57:15 +0800181 {Opt_caps_max, "caps_max=%d"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700182 {Opt_readdir_max_entries, "readdir_max_entries=%d"},
183 {Opt_readdir_max_bytes, "readdir_max_bytes=%d"},
184 {Opt_congestion_kb, "write_congestion_kb=%d"},
185 /* int args above */
186 {Opt_snapdirname, "snapdirname=%s"},
Yan, Zheng430afba2016-07-08 11:25:38 +0800187 {Opt_mds_namespace, "mds_namespace=%s"},
Yan, Zheng131d7eb2019-07-25 20:16:47 +0800188 {Opt_recover_session, "recover_session=%s"},
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800189 {Opt_fscache_uniq, "fsc=%s"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700190 /* string args above */
191 {Opt_dirstat, "dirstat"},
192 {Opt_nodirstat, "nodirstat"},
193 {Opt_rbytes, "rbytes"},
194 {Opt_norbytes, "norbytes"},
Alex Eldercffaba12012-02-15 07:43:54 -0600195 {Opt_asyncreaddir, "asyncreaddir"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700196 {Opt_noasyncreaddir, "noasyncreaddir"},
Sage Weila40dc6c2012-01-10 09:12:55 -0800197 {Opt_dcache, "dcache"},
198 {Opt_nodcache, "nodcache"},
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800199 {Opt_ino32, "ino32"},
Alex Eldercffaba12012-02-15 07:43:54 -0600200 {Opt_noino32, "noino32"},
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400201 {Opt_fscache, "fsc"},
202 {Opt_nofscache, "nofsc"},
Yan, Zheng10183a62015-04-27 15:33:28 +0800203 {Opt_poolperm, "poolperm"},
204 {Opt_nopoolperm, "nopoolperm"},
Yan, Zhenge9e427f2016-11-10 16:02:06 +0800205 {Opt_require_active_mds, "require_active_mds"},
206 {Opt_norequire_active_mds, "norequire_active_mds"},
Sage Weil45195e42014-02-16 10:05:29 -0800207#ifdef CONFIG_CEPH_FS_POSIX_ACL
208 {Opt_acl, "acl"},
209#endif
210 {Opt_noacl, "noacl"},
Luis Henriques9122eed2018-01-31 10:53:13 +0000211 {Opt_quotadf, "quotadf"},
212 {Opt_noquotadf, "noquotadf"},
Luis Henriquesea4cdc52018-10-15 16:46:00 +0100213 {Opt_copyfrom, "copyfrom"},
214 {Opt_nocopyfrom, "nocopyfrom"},
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700215 {-1, NULL}
216};
217
218static int parse_fsopt_token(char *c, void *private)
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800219{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700220 struct ceph_mount_options *fsopt = private;
221 substring_t argstr[MAX_OPT_ARGS];
222 int token, intval, ret;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800223
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700224 token = match_token((char *)c, fsopt_tokens, argstr);
225 if (token < 0)
226 return -EINVAL;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800227
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700228 if (token < Opt_last_int) {
229 ret = match_int(&argstr[0], &intval);
230 if (ret < 0) {
Ilya Dryomov2f56b6b2018-06-27 16:38:13 +0200231 pr_err("bad option arg (not int) at '%s'\n", c);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700232 return ret;
233 }
234 dout("got int token %d val %d\n", token, intval);
235 } else if (token > Opt_last_int && token < Opt_last_string) {
236 dout("got string token %d val %s\n", token,
237 argstr[0].from);
238 } else {
239 dout("got token %d\n", token);
240 }
241
242 switch (token) {
243 case Opt_snapdirname:
244 kfree(fsopt->snapdir_name);
245 fsopt->snapdir_name = kstrndup(argstr[0].from,
246 argstr[0].to-argstr[0].from,
247 GFP_KERNEL);
248 if (!fsopt->snapdir_name)
249 return -ENOMEM;
250 break;
Yan, Zheng235a0982016-03-30 17:18:34 +0800251 case Opt_mds_namespace:
Chengguang Xu937441f2018-02-06 08:25:55 +0800252 kfree(fsopt->mds_namespace);
Yan, Zheng430afba2016-07-08 11:25:38 +0800253 fsopt->mds_namespace = kstrndup(argstr[0].from,
254 argstr[0].to-argstr[0].from,
255 GFP_KERNEL);
256 if (!fsopt->mds_namespace)
257 return -ENOMEM;
Yan, Zheng235a0982016-03-30 17:18:34 +0800258 break;
Yan, Zheng131d7eb2019-07-25 20:16:47 +0800259 case Opt_recover_session:
260 if (!strncmp(argstr[0].from, "no",
261 argstr[0].to - argstr[0].from)) {
262 fsopt->flags &= ~CEPH_MOUNT_OPT_CLEANRECOVER;
263 } else if (!strncmp(argstr[0].from, "clean",
264 argstr[0].to - argstr[0].from)) {
265 fsopt->flags |= CEPH_MOUNT_OPT_CLEANRECOVER;
266 } else {
267 return -EINVAL;
268 }
269 break;
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800270 case Opt_fscache_uniq:
Chengguang Xu937441f2018-02-06 08:25:55 +0800271 kfree(fsopt->fscache_uniq);
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800272 fsopt->fscache_uniq = kstrndup(argstr[0].from,
273 argstr[0].to-argstr[0].from,
274 GFP_KERNEL);
275 if (!fsopt->fscache_uniq)
276 return -ENOMEM;
277 fsopt->flags |= CEPH_MOUNT_OPT_FSCACHE;
278 break;
Yan, Zheng430afba2016-07-08 11:25:38 +0800279 /* misc */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700280 case Opt_wsize:
Chengguang Xu8db0c752018-05-30 16:47:06 +0800281 if (intval < (int)PAGE_SIZE || intval > CEPH_MAX_WRITE_SIZE)
Yan, Zheng95cca2b2017-07-11 17:34:46 +0800282 return -EINVAL;
283 fsopt->wsize = ALIGN(intval, PAGE_SIZE);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700284 break;
285 case Opt_rsize:
Chengguang Xu8db0c752018-05-30 16:47:06 +0800286 if (intval < (int)PAGE_SIZE || intval > CEPH_MAX_READ_SIZE)
Yan, Zhengaa187922017-07-11 15:56:09 +0800287 return -EINVAL;
288 fsopt->rsize = ALIGN(intval, PAGE_SIZE);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700289 break;
Sage Weil83817e32011-08-04 08:03:44 -0700290 case Opt_rasize:
Yan, Zheng4214fb12017-07-11 18:49:44 +0800291 if (intval < 0)
292 return -EINVAL;
Chengguang Xuc36ed502018-05-30 10:13:11 +0800293 fsopt->rasize = ALIGN(intval, PAGE_SIZE);
Sage Weil83817e32011-08-04 08:03:44 -0700294 break;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700295 case Opt_caps_wanted_delay_min:
Yan, Zheng4214fb12017-07-11 18:49:44 +0800296 if (intval < 1)
297 return -EINVAL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700298 fsopt->caps_wanted_delay_min = intval;
299 break;
300 case Opt_caps_wanted_delay_max:
Yan, Zheng4214fb12017-07-11 18:49:44 +0800301 if (intval < 1)
302 return -EINVAL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700303 fsopt->caps_wanted_delay_max = intval;
304 break;
Yan, Zhengfe330322019-02-01 14:57:15 +0800305 case Opt_caps_max:
306 if (intval < 0)
307 return -EINVAL;
308 fsopt->caps_max = intval;
309 break;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700310 case Opt_readdir_max_entries:
Yan, Zheng4214fb12017-07-11 18:49:44 +0800311 if (intval < 1)
312 return -EINVAL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700313 fsopt->max_readdir = intval;
314 break;
315 case Opt_readdir_max_bytes:
Chengguang Xu8db0c752018-05-30 16:47:06 +0800316 if (intval < (int)PAGE_SIZE && intval != 0)
Yan, Zheng4214fb12017-07-11 18:49:44 +0800317 return -EINVAL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700318 fsopt->max_readdir_bytes = intval;
319 break;
320 case Opt_congestion_kb:
Yan, Zheng4214fb12017-07-11 18:49:44 +0800321 if (intval < 1024) /* at least 1M */
322 return -EINVAL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700323 fsopt->congestion_kb = intval;
324 break;
325 case Opt_dirstat:
326 fsopt->flags |= CEPH_MOUNT_OPT_DIRSTAT;
327 break;
328 case Opt_nodirstat:
329 fsopt->flags &= ~CEPH_MOUNT_OPT_DIRSTAT;
330 break;
331 case Opt_rbytes:
332 fsopt->flags |= CEPH_MOUNT_OPT_RBYTES;
333 break;
334 case Opt_norbytes:
335 fsopt->flags &= ~CEPH_MOUNT_OPT_RBYTES;
336 break;
Alex Eldercffaba12012-02-15 07:43:54 -0600337 case Opt_asyncreaddir:
338 fsopt->flags &= ~CEPH_MOUNT_OPT_NOASYNCREADDIR;
339 break;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700340 case Opt_noasyncreaddir:
341 fsopt->flags |= CEPH_MOUNT_OPT_NOASYNCREADDIR;
342 break;
Sage Weila40dc6c2012-01-10 09:12:55 -0800343 case Opt_dcache:
344 fsopt->flags |= CEPH_MOUNT_OPT_DCACHE;
345 break;
346 case Opt_nodcache:
347 fsopt->flags &= ~CEPH_MOUNT_OPT_DCACHE;
348 break;
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800349 case Opt_ino32:
350 fsopt->flags |= CEPH_MOUNT_OPT_INO32;
351 break;
Alex Eldercffaba12012-02-15 07:43:54 -0600352 case Opt_noino32:
353 fsopt->flags &= ~CEPH_MOUNT_OPT_INO32;
354 break;
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400355 case Opt_fscache:
356 fsopt->flags |= CEPH_MOUNT_OPT_FSCACHE;
Chengguang Xu7ae7a822018-02-07 10:27:06 +0800357 kfree(fsopt->fscache_uniq);
358 fsopt->fscache_uniq = NULL;
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400359 break;
360 case Opt_nofscache:
361 fsopt->flags &= ~CEPH_MOUNT_OPT_FSCACHE;
Chengguang Xu7ae7a822018-02-07 10:27:06 +0800362 kfree(fsopt->fscache_uniq);
363 fsopt->fscache_uniq = NULL;
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400364 break;
Yan, Zheng10183a62015-04-27 15:33:28 +0800365 case Opt_poolperm:
366 fsopt->flags &= ~CEPH_MOUNT_OPT_NOPOOLPERM;
Yan, Zheng10183a62015-04-27 15:33:28 +0800367 break;
368 case Opt_nopoolperm:
369 fsopt->flags |= CEPH_MOUNT_OPT_NOPOOLPERM;
370 break;
Yan, Zhenge9e427f2016-11-10 16:02:06 +0800371 case Opt_require_active_mds:
372 fsopt->flags &= ~CEPH_MOUNT_OPT_MOUNTWAIT;
373 break;
374 case Opt_norequire_active_mds:
375 fsopt->flags |= CEPH_MOUNT_OPT_MOUNTWAIT;
376 break;
Luis Henriques9122eed2018-01-31 10:53:13 +0000377 case Opt_quotadf:
378 fsopt->flags &= ~CEPH_MOUNT_OPT_NOQUOTADF;
379 break;
380 case Opt_noquotadf:
381 fsopt->flags |= CEPH_MOUNT_OPT_NOQUOTADF;
382 break;
Luis Henriquesea4cdc52018-10-15 16:46:00 +0100383 case Opt_copyfrom:
384 fsopt->flags &= ~CEPH_MOUNT_OPT_NOCOPYFROM;
385 break;
386 case Opt_nocopyfrom:
387 fsopt->flags |= CEPH_MOUNT_OPT_NOCOPYFROM;
388 break;
Sage Weil45195e42014-02-16 10:05:29 -0800389#ifdef CONFIG_CEPH_FS_POSIX_ACL
390 case Opt_acl:
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800391 fsopt->sb_flags |= SB_POSIXACL;
Sage Weil45195e42014-02-16 10:05:29 -0800392 break;
393#endif
394 case Opt_noacl:
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800395 fsopt->sb_flags &= ~SB_POSIXACL;
Sage Weil45195e42014-02-16 10:05:29 -0800396 break;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700397 default:
398 BUG_ON(token);
399 }
400 return 0;
401}
402
403static void destroy_mount_options(struct ceph_mount_options *args)
404{
405 dout("destroy_mount_options %p\n", args);
406 kfree(args->snapdir_name);
Yan, Zheng430afba2016-07-08 11:25:38 +0800407 kfree(args->mds_namespace);
Yan, Zheng3f384952016-04-21 11:09:55 +0800408 kfree(args->server_path);
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800409 kfree(args->fscache_uniq);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700410 kfree(args);
411}
412
413static int strcmp_null(const char *s1, const char *s2)
414{
415 if (!s1 && !s2)
416 return 0;
417 if (s1 && !s2)
418 return -1;
419 if (!s1 && s2)
420 return 1;
421 return strcmp(s1, s2);
422}
423
424static int compare_mount_options(struct ceph_mount_options *new_fsopt,
425 struct ceph_options *new_opt,
426 struct ceph_fs_client *fsc)
427{
428 struct ceph_mount_options *fsopt1 = new_fsopt;
429 struct ceph_mount_options *fsopt2 = fsc->mount_options;
430 int ofs = offsetof(struct ceph_mount_options, snapdir_name);
431 int ret;
432
433 ret = memcmp(fsopt1, fsopt2, ofs);
434 if (ret)
435 return ret;
436
437 ret = strcmp_null(fsopt1->snapdir_name, fsopt2->snapdir_name);
438 if (ret)
439 return ret;
Yan, Zheng430afba2016-07-08 11:25:38 +0800440 ret = strcmp_null(fsopt1->mds_namespace, fsopt2->mds_namespace);
441 if (ret)
442 return ret;
Yan, Zheng3f384952016-04-21 11:09:55 +0800443 ret = strcmp_null(fsopt1->server_path, fsopt2->server_path);
444 if (ret)
445 return ret;
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800446 ret = strcmp_null(fsopt1->fscache_uniq, fsopt2->fscache_uniq);
447 if (ret)
448 return ret;
Yan, Zheng3f384952016-04-21 11:09:55 +0800449
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700450 return ceph_compare_options(new_opt, fsc->client);
451}
452
453static int parse_mount_options(struct ceph_mount_options **pfsopt,
454 struct ceph_options **popt,
455 int flags, char *options,
Yan, Zheng3f384952016-04-21 11:09:55 +0800456 const char *dev_name)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700457{
458 struct ceph_mount_options *fsopt;
459 const char *dev_name_end;
Alex Elderc98f5332012-08-09 10:33:26 -0700460 int err;
461
462 if (!dev_name || !*dev_name)
463 return -EINVAL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700464
465 fsopt = kzalloc(sizeof(*fsopt), GFP_KERNEL);
466 if (!fsopt)
467 return -ENOMEM;
468
469 dout("parse_mount_options %p, dev_name '%s'\n", fsopt, dev_name);
470
Noah Watkins80db8be2011-08-22 13:49:23 -0600471 fsopt->sb_flags = flags;
472 fsopt->flags = CEPH_MOUNT_OPT_DEFAULT;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700473
Yan, Zheng95cca2b2017-07-11 17:34:46 +0800474 fsopt->wsize = CEPH_MAX_WRITE_SIZE;
Yan, Zhengaa187922017-07-11 15:56:09 +0800475 fsopt->rsize = CEPH_MAX_READ_SIZE;
Noah Watkins80db8be2011-08-22 13:49:23 -0600476 fsopt->rasize = CEPH_RASIZE_DEFAULT;
477 fsopt->snapdir_name = kstrdup(CEPH_SNAPDIRNAME_DEFAULT, GFP_KERNEL);
Sanidhya Kashyapa149bb92015-03-21 12:54:58 -0400478 if (!fsopt->snapdir_name) {
479 err = -ENOMEM;
480 goto out;
481 }
482
Sage Weil50aac4f2011-01-18 07:59:40 -0800483 fsopt->caps_wanted_delay_min = CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT;
484 fsopt->caps_wanted_delay_max = CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT;
Noah Watkins80db8be2011-08-22 13:49:23 -0600485 fsopt->max_readdir = CEPH_MAX_READDIR_DEFAULT;
486 fsopt->max_readdir_bytes = CEPH_MAX_READDIR_BYTES_DEFAULT;
487 fsopt->congestion_kb = default_congestion_kb();
488
Alex Elderc98f5332012-08-09 10:33:26 -0700489 /*
490 * Distinguish the server list from the path in "dev_name".
491 * Internally we do not include the leading '/' in the path.
492 *
493 * "dev_name" will look like:
494 * <server_spec>[,<server_spec>...]:[<path>]
495 * where
496 * <server_spec> is <ip>[:<port>]
497 * <path> is optional, but if present must begin with '/'
498 */
499 dev_name_end = strchr(dev_name, '/');
500 if (dev_name_end) {
Yan, Zhengce2728a2016-09-14 14:53:05 +0800501 if (strlen(dev_name_end) > 1) {
502 fsopt->server_path = kstrdup(dev_name_end, GFP_KERNEL);
503 if (!fsopt->server_path) {
504 err = -ENOMEM;
505 goto out;
506 }
Yan, Zheng3f384952016-04-21 11:09:55 +0800507 }
Alex Elderc98f5332012-08-09 10:33:26 -0700508 } else {
Alex Elderc98f5332012-08-09 10:33:26 -0700509 dev_name_end = dev_name + strlen(dev_name);
Alex Elderc98f5332012-08-09 10:33:26 -0700510 }
Noah Watkins80db8be2011-08-22 13:49:23 -0600511 err = -EINVAL;
Alex Elderc98f5332012-08-09 10:33:26 -0700512 dev_name_end--; /* back up to ':' separator */
Sasha Levin54464292013-07-01 18:33:39 -0400513 if (dev_name_end < dev_name || *dev_name_end != ':') {
Alex Elderc98f5332012-08-09 10:33:26 -0700514 pr_err("device name is missing path (no : separator in %s)\n",
Noah Watkins80db8be2011-08-22 13:49:23 -0600515 dev_name);
516 goto out;
517 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700518 dout("device name '%.*s'\n", (int)(dev_name_end - dev_name), dev_name);
Yan, Zheng3f384952016-04-21 11:09:55 +0800519 if (fsopt->server_path)
520 dout("server path '%s'\n", fsopt->server_path);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700521
Alex Elderee577412012-01-24 10:08:36 -0600522 *popt = ceph_parse_options(options, dev_name, dev_name_end,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700523 parse_fsopt_token, (void *)fsopt);
Alex Elderee577412012-01-24 10:08:36 -0600524 if (IS_ERR(*popt)) {
525 err = PTR_ERR(*popt);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700526 goto out;
Alex Elderee577412012-01-24 10:08:36 -0600527 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700528
529 /* success */
530 *pfsopt = fsopt;
531 return 0;
532
533out:
534 destroy_mount_options(fsopt);
535 return err;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800536}
537
Sage Weil6e19a162010-04-29 16:38:32 -0700538/**
539 * ceph_show_options - Show mount options in /proc/mounts
540 * @m: seq_file to write to
Al Viro34c80b12011-12-08 21:32:45 -0500541 * @root: root of that (sub)tree
Sage Weil6e19a162010-04-29 16:38:32 -0700542 */
Al Viro34c80b12011-12-08 21:32:45 -0500543static int ceph_show_options(struct seq_file *m, struct dentry *root)
Sage Weil6e19a162010-04-29 16:38:32 -0700544{
Al Viro34c80b12011-12-08 21:32:45 -0500545 struct ceph_fs_client *fsc = ceph_sb_to_client(root->d_sb);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700546 struct ceph_mount_options *fsopt = fsc->mount_options;
Ilya Dryomovff40f9a2015-03-25 21:02:16 +0300547 size_t pos;
548 int ret;
Sage Weil6e19a162010-04-29 16:38:32 -0700549
Ilya Dryomovff40f9a2015-03-25 21:02:16 +0300550 /* a comma between MNT/MS and client options */
551 seq_putc(m, ',');
552 pos = m->count;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700553
Dongsheng Yang02b2f542018-12-18 04:31:48 -0500554 ret = ceph_print_client_options(m, fsc->client, false);
Ilya Dryomovff40f9a2015-03-25 21:02:16 +0300555 if (ret)
556 return ret;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700557
Ilya Dryomovff40f9a2015-03-25 21:02:16 +0300558 /* retract our comma if no client options */
559 if (m->count == pos)
560 m->count--;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700561
562 if (fsopt->flags & CEPH_MOUNT_OPT_DIRSTAT)
563 seq_puts(m, ",dirstat");
Yan, Zheng133e9152016-01-25 10:44:33 +0800564 if ((fsopt->flags & CEPH_MOUNT_OPT_RBYTES))
565 seq_puts(m, ",rbytes");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700566 if (fsopt->flags & CEPH_MOUNT_OPT_NOASYNCREADDIR)
Sage Weil6e19a162010-04-29 16:38:32 -0700567 seq_puts(m, ",noasyncreaddir");
Ilya Dryomovff7eeb82015-03-25 21:10:09 +0300568 if ((fsopt->flags & CEPH_MOUNT_OPT_DCACHE) == 0)
Sage Weila40dc6c2012-01-10 09:12:55 -0800569 seq_puts(m, ",nodcache");
Chengguang Xu3619aa82018-06-04 16:03:51 +0800570 if (fsopt->flags & CEPH_MOUNT_OPT_INO32)
571 seq_puts(m, ",ino32");
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800572 if (fsopt->flags & CEPH_MOUNT_OPT_FSCACHE) {
Chengguang Xu4d8969a2018-02-15 15:39:05 +0800573 seq_show_option(m, "fsc", fsopt->fscache_uniq);
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800574 }
Yan, Zheng10183a62015-04-27 15:33:28 +0800575 if (fsopt->flags & CEPH_MOUNT_OPT_NOPOOLPERM)
576 seq_puts(m, ",nopoolperm");
Luis Henriques9122eed2018-01-31 10:53:13 +0000577 if (fsopt->flags & CEPH_MOUNT_OPT_NOQUOTADF)
578 seq_puts(m, ",noquotadf");
Sage Weil6e19a162010-04-29 16:38:32 -0700579
Sage Weil45195e42014-02-16 10:05:29 -0800580#ifdef CONFIG_CEPH_FS_POSIX_ACL
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800581 if (fsopt->sb_flags & SB_POSIXACL)
Sage Weil45195e42014-02-16 10:05:29 -0800582 seq_puts(m, ",acl");
583 else
584 seq_puts(m, ",noacl");
585#endif
586
Luis Henriques6f9718f2018-12-10 10:23:12 +0000587 if ((fsopt->flags & CEPH_MOUNT_OPT_NOCOPYFROM) == 0)
588 seq_puts(m, ",copyfrom");
Luis Henriquesea4cdc52018-10-15 16:46:00 +0100589
Yan, Zheng430afba2016-07-08 11:25:38 +0800590 if (fsopt->mds_namespace)
Chengguang Xu4d8969a2018-02-15 15:39:05 +0800591 seq_show_option(m, "mds_namespace", fsopt->mds_namespace);
Yan, Zheng131d7eb2019-07-25 20:16:47 +0800592
593 if (fsopt->flags & CEPH_MOUNT_OPT_CLEANRECOVER)
594 seq_show_option(m, "recover_session", "clean");
595
Ilya Dryomov6dd49402018-05-03 16:26:55 +0200596 if (fsopt->wsize != CEPH_MAX_WRITE_SIZE)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700597 seq_printf(m, ",wsize=%d", fsopt->wsize);
Yan, Zhengaa187922017-07-11 15:56:09 +0800598 if (fsopt->rsize != CEPH_MAX_READ_SIZE)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700599 seq_printf(m, ",rsize=%d", fsopt->rsize);
Sage Weil83817e32011-08-04 08:03:44 -0700600 if (fsopt->rasize != CEPH_RASIZE_DEFAULT)
Sage Weil21519372011-12-01 08:06:52 -0800601 seq_printf(m, ",rasize=%d", fsopt->rasize);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700602 if (fsopt->congestion_kb != default_congestion_kb())
603 seq_printf(m, ",write_congestion_kb=%d", fsopt->congestion_kb);
Yan, Zhengfe330322019-02-01 14:57:15 +0800604 if (fsopt->caps_max)
605 seq_printf(m, ",caps_max=%d", fsopt->caps_max);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700606 if (fsopt->caps_wanted_delay_min != CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT)
Sage Weil6e19a162010-04-29 16:38:32 -0700607 seq_printf(m, ",caps_wanted_delay_min=%d",
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700608 fsopt->caps_wanted_delay_min);
609 if (fsopt->caps_wanted_delay_max != CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT)
Sage Weil6e19a162010-04-29 16:38:32 -0700610 seq_printf(m, ",caps_wanted_delay_max=%d",
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700611 fsopt->caps_wanted_delay_max);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700612 if (fsopt->max_readdir != CEPH_MAX_READDIR_DEFAULT)
613 seq_printf(m, ",readdir_max_entries=%d", fsopt->max_readdir);
614 if (fsopt->max_readdir_bytes != CEPH_MAX_READDIR_BYTES_DEFAULT)
615 seq_printf(m, ",readdir_max_bytes=%d", fsopt->max_readdir_bytes);
616 if (strcmp(fsopt->snapdir_name, CEPH_SNAPDIRNAME_DEFAULT))
Kees Cooka068acf2015-09-04 15:44:57 -0700617 seq_show_option(m, "snapdirname", fsopt->snapdir_name);
Ilya Dryomovff40f9a2015-03-25 21:02:16 +0300618
Sage Weil6e19a162010-04-29 16:38:32 -0700619 return 0;
620}
621
622/*
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700623 * handle any mon messages the standard library doesn't understand.
624 * return error if we don't either.
625 */
626static int extra_mon_dispatch(struct ceph_client *client, struct ceph_msg *msg)
627{
628 struct ceph_fs_client *fsc = client->private;
629 int type = le16_to_cpu(msg->hdr.type);
630
631 switch (type) {
632 case CEPH_MSG_MDS_MAP:
Yan, Zheng430afba2016-07-08 11:25:38 +0800633 ceph_mdsc_handle_mdsmap(fsc->mdsc, msg);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700634 return 0;
Yan, Zheng430afba2016-07-08 11:25:38 +0800635 case CEPH_MSG_FS_MAP_USER:
636 ceph_mdsc_handle_fsmap(fsc->mdsc, msg);
637 return 0;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700638 default:
639 return -1;
640 }
641}
642
643/*
644 * create a new fs client
Ilya Dryomov8aaff152018-08-24 15:32:43 +0200645 *
646 * Success or not, this function consumes @fsopt and @opt.
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700647 */
H Hartley Sweeten0c6d4b4e22011-09-23 11:53:30 -0700648static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700649 struct ceph_options *opt)
650{
651 struct ceph_fs_client *fsc;
Alex Elder3bf53332013-04-01 10:48:40 -0500652 int page_count;
653 size_t size;
Ilya Dryomov8aaff152018-08-24 15:32:43 +0200654 int err;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700655
656 fsc = kzalloc(sizeof(*fsc), GFP_KERNEL);
Ilya Dryomov8aaff152018-08-24 15:32:43 +0200657 if (!fsc) {
658 err = -ENOMEM;
659 goto fail;
660 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700661
Ilya Dryomov74da4a0f2017-03-03 18:16:07 +0100662 fsc->client = ceph_create_client(opt, fsc);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700663 if (IS_ERR(fsc->client)) {
664 err = PTR_ERR(fsc->client);
665 goto fail;
666 }
Ilya Dryomov8aaff152018-08-24 15:32:43 +0200667 opt = NULL; /* fsc->client now owns this */
Ilya Dryomovc843d132018-05-30 16:29:14 +0200668
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700669 fsc->client->extra_mon_dispatch = extra_mon_dispatch;
Dongsheng Yang02b2f542018-12-18 04:31:48 -0500670 ceph_set_opt(fsc->client, ABORT_ON_FULL);
Yan, Zheng430afba2016-07-08 11:25:38 +0800671
Markus Elfringd37b1d92017-08-20 20:22:02 +0200672 if (!fsopt->mds_namespace) {
Yan, Zheng430afba2016-07-08 11:25:38 +0800673 ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_MDSMAP,
674 0, true);
675 } else {
676 ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_FSMAP,
677 0, false);
678 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700679
680 fsc->mount_options = fsopt;
681
682 fsc->sb = NULL;
683 fsc->mount_state = CEPH_MOUNT_MOUNTING;
Yan, Zheng81f148a2019-07-25 20:16:46 +0800684 fsc->filp_gen = 1;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700685
686 atomic_long_set(&fsc->writeback_count, 0);
687
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700688 err = -ENOMEM;
Tejun Heo01e6acc2011-01-03 14:49:45 +0100689 /*
690 * The number of concurrent works can be high but they don't need
691 * to be processed in parallel, limit concurrency.
692 */
Yan, Zheng1cf89a82019-05-18 11:18:44 +0800693 fsc->inode_wq = alloc_workqueue("ceph-inode", WQ_UNBOUND, 0);
694 if (!fsc->inode_wq)
Jan Kara09dc9fc2017-04-12 12:24:33 +0200695 goto fail_client;
Yan, Zhenge3ec8d62019-01-14 17:21:19 +0800696 fsc->cap_wq = alloc_workqueue("ceph-cap", 0, 1);
697 if (!fsc->cap_wq)
Yan, Zheng1cf89a82019-05-18 11:18:44 +0800698 goto fail_inode_wq;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700699
700 /* set up mempools */
701 err = -ENOMEM;
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300702 page_count = fsc->mount_options->wsize >> PAGE_SHIFT;
Alex Elder3bf53332013-04-01 10:48:40 -0500703 size = sizeof (struct page *) * (page_count ? page_count : 1);
704 fsc->wb_pagevec_pool = mempool_create_kmalloc_pool(10, size);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700705 if (!fsc->wb_pagevec_pool)
Yan, Zhenge3ec8d62019-01-14 17:21:19 +0800706 goto fail_cap_wq;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700707
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700708 return fsc;
709
Yan, Zhenge3ec8d62019-01-14 17:21:19 +0800710fail_cap_wq:
711 destroy_workqueue(fsc->cap_wq);
Yan, Zheng1cf89a82019-05-18 11:18:44 +0800712fail_inode_wq:
713 destroy_workqueue(fsc->inode_wq);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700714fail_client:
715 ceph_destroy_client(fsc->client);
716fail:
717 kfree(fsc);
Ilya Dryomov8aaff152018-08-24 15:32:43 +0200718 if (opt)
719 ceph_destroy_options(opt);
720 destroy_mount_options(fsopt);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700721 return ERR_PTR(err);
722}
723
Yan, Zhenga57d9062018-05-18 16:05:51 +0800724static void flush_fs_workqueues(struct ceph_fs_client *fsc)
725{
Yan, Zheng1cf89a82019-05-18 11:18:44 +0800726 flush_workqueue(fsc->inode_wq);
Yan, Zhenge3ec8d62019-01-14 17:21:19 +0800727 flush_workqueue(fsc->cap_wq);
Yan, Zhenga57d9062018-05-18 16:05:51 +0800728}
729
H Hartley Sweeten0c6d4b4e22011-09-23 11:53:30 -0700730static void destroy_fs_client(struct ceph_fs_client *fsc)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700731{
732 dout("destroy_fs_client %p\n", fsc);
733
Yan, Zheng1cf89a82019-05-18 11:18:44 +0800734 destroy_workqueue(fsc->inode_wq);
Yan, Zhenge3ec8d62019-01-14 17:21:19 +0800735 destroy_workqueue(fsc->cap_wq);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700736
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700737 mempool_destroy(fsc->wb_pagevec_pool);
738
739 destroy_mount_options(fsc->mount_options);
740
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700741 ceph_destroy_client(fsc->client);
742
743 kfree(fsc);
744 dout("destroy_fs_client %p done\n", fsc);
745}
746
747/*
Sage Weil6e19a162010-04-29 16:38:32 -0700748 * caches
749 */
750struct kmem_cache *ceph_inode_cachep;
751struct kmem_cache *ceph_cap_cachep;
Yan, Zhengf66fd9f2015-06-10 17:26:13 +0800752struct kmem_cache *ceph_cap_flush_cachep;
Sage Weil6e19a162010-04-29 16:38:32 -0700753struct kmem_cache *ceph_dentry_cachep;
754struct kmem_cache *ceph_file_cachep;
Chengguang Xubb48bd42018-03-13 10:42:44 +0800755struct kmem_cache *ceph_dir_file_cachep;
Sage Weil6e19a162010-04-29 16:38:32 -0700756
757static void ceph_inode_init_once(void *foo)
758{
759 struct ceph_inode_info *ci = foo;
760 inode_init_once(&ci->vfs_inode);
761}
762
Sage Weil16725b92009-10-06 11:31:07 -0700763static int __init init_caches(void)
764{
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400765 int error = -ENOMEM;
766
Sage Weil16725b92009-10-06 11:31:07 -0700767 ceph_inode_cachep = kmem_cache_create("ceph_inode_info",
768 sizeof(struct ceph_inode_info),
769 __alignof__(struct ceph_inode_info),
Vladimir Davydov5d097052016-01-14 15:18:21 -0800770 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|
771 SLAB_ACCOUNT, ceph_inode_init_once);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200772 if (!ceph_inode_cachep)
Sage Weil16725b92009-10-06 11:31:07 -0700773 return -ENOMEM;
774
Chengguang Xubc4b5ad2018-02-27 13:49:44 +0800775 ceph_cap_cachep = KMEM_CACHE(ceph_cap, SLAB_MEM_SPREAD);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200776 if (!ceph_cap_cachep)
Sage Weil16725b92009-10-06 11:31:07 -0700777 goto bad_cap;
Yan, Zhengf66fd9f2015-06-10 17:26:13 +0800778 ceph_cap_flush_cachep = KMEM_CACHE(ceph_cap_flush,
779 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200780 if (!ceph_cap_flush_cachep)
Yan, Zhengf66fd9f2015-06-10 17:26:13 +0800781 goto bad_cap_flush;
Sage Weil16725b92009-10-06 11:31:07 -0700782
783 ceph_dentry_cachep = KMEM_CACHE(ceph_dentry_info,
784 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200785 if (!ceph_dentry_cachep)
Sage Weil16725b92009-10-06 11:31:07 -0700786 goto bad_dentry;
787
Nikolay Borisov6b1a9a62016-07-25 20:12:13 +0300788 ceph_file_cachep = KMEM_CACHE(ceph_file_info, SLAB_MEM_SPREAD);
Markus Elfringd37b1d92017-08-20 20:22:02 +0200789 if (!ceph_file_cachep)
Sage Weil16725b92009-10-06 11:31:07 -0700790 goto bad_file;
791
Chengguang Xubb48bd42018-03-13 10:42:44 +0800792 ceph_dir_file_cachep = KMEM_CACHE(ceph_dir_file_info, SLAB_MEM_SPREAD);
793 if (!ceph_dir_file_cachep)
794 goto bad_dir_file;
795
Chengguang Xu1c789242018-03-01 14:24:51 +0800796 error = ceph_fscache_register();
797 if (error)
798 goto bad_fscache;
Sage Weil16725b92009-10-06 11:31:07 -0700799
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400800 return 0;
Chengguang Xu1c789242018-03-01 14:24:51 +0800801
802bad_fscache:
Chengguang Xubb48bd42018-03-13 10:42:44 +0800803 kmem_cache_destroy(ceph_dir_file_cachep);
804bad_dir_file:
Chengguang Xu1c789242018-03-01 14:24:51 +0800805 kmem_cache_destroy(ceph_file_cachep);
Sage Weil16725b92009-10-06 11:31:07 -0700806bad_file:
807 kmem_cache_destroy(ceph_dentry_cachep);
808bad_dentry:
Yan, Zhengf66fd9f2015-06-10 17:26:13 +0800809 kmem_cache_destroy(ceph_cap_flush_cachep);
810bad_cap_flush:
Sage Weil16725b92009-10-06 11:31:07 -0700811 kmem_cache_destroy(ceph_cap_cachep);
812bad_cap:
813 kmem_cache_destroy(ceph_inode_cachep);
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400814 return error;
Sage Weil16725b92009-10-06 11:31:07 -0700815}
816
817static void destroy_caches(void)
818{
Kirill A. Shutemov8c0a8532012-09-26 11:33:07 +1000819 /*
820 * Make sure all delayed rcu free inodes are flushed before we
821 * destroy cache.
822 */
823 rcu_barrier();
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400824
Sage Weil16725b92009-10-06 11:31:07 -0700825 kmem_cache_destroy(ceph_inode_cachep);
826 kmem_cache_destroy(ceph_cap_cachep);
Yan, Zhengf66fd9f2015-06-10 17:26:13 +0800827 kmem_cache_destroy(ceph_cap_flush_cachep);
Sage Weil16725b92009-10-06 11:31:07 -0700828 kmem_cache_destroy(ceph_dentry_cachep);
829 kmem_cache_destroy(ceph_file_cachep);
Chengguang Xubb48bd42018-03-13 10:42:44 +0800830 kmem_cache_destroy(ceph_dir_file_cachep);
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400831
832 ceph_fscache_unregister();
Sage Weil16725b92009-10-06 11:31:07 -0700833}
834
835
836/*
837 * ceph_umount_begin - initiate forced umount. Tear down down the
838 * mount, skipping steps that may hang while waiting for server(s).
839 */
840static void ceph_umount_begin(struct super_block *sb)
841{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700842 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
Sage Weil16725b92009-10-06 11:31:07 -0700843
844 dout("ceph_umount_begin - starting forced umount\n");
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700845 if (!fsc)
Sage Weil16725b92009-10-06 11:31:07 -0700846 return;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700847 fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
Yan, Zheng12b69d52018-05-11 17:12:02 +0800848 ceph_osdc_abort_requests(&fsc->client->osdc, -EIO);
Yan, Zheng48fec5d2015-07-01 16:27:46 +0800849 ceph_mdsc_force_umount(fsc->mdsc);
Yan, Zheng81f148a2019-07-25 20:16:46 +0800850 fsc->filp_gen++; // invalidate open files
Sage Weil16725b92009-10-06 11:31:07 -0700851}
852
Jeff Layton00abf692019-05-07 09:20:54 -0400853static int ceph_remount(struct super_block *sb, int *flags, char *data)
854{
855 sync_filesystem(sb);
856 return 0;
857}
858
Sage Weil16725b92009-10-06 11:31:07 -0700859static const struct super_operations ceph_super_ops = {
860 .alloc_inode = ceph_alloc_inode,
Al Virocfa6d412019-04-10 15:18:50 -0400861 .free_inode = ceph_free_inode,
Sage Weil16725b92009-10-06 11:31:07 -0700862 .write_inode = ceph_write_inode,
Luis Henriques52dd0f12019-07-05 17:14:56 +0100863 .drop_inode = generic_delete_inode,
Yan, Zheng87bc5b82019-06-02 09:45:38 +0800864 .evict_inode = ceph_evict_inode,
Sage Weil2d9c98a2010-07-30 09:38:13 -0700865 .sync_fs = ceph_sync_fs,
Sage Weil16725b92009-10-06 11:31:07 -0700866 .put_super = ceph_put_super,
Jeff Layton00abf692019-05-07 09:20:54 -0400867 .remount_fs = ceph_remount,
Sage Weil16725b92009-10-06 11:31:07 -0700868 .show_options = ceph_show_options,
869 .statfs = ceph_statfs,
870 .umount_begin = ceph_umount_begin,
871};
872
Sage Weil16725b92009-10-06 11:31:07 -0700873/*
874 * Bootstrap mount by opening the root directory. Note the mount
875 * @started time from caller, and time out if this takes too long.
876 */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700877static struct dentry *open_root_dentry(struct ceph_fs_client *fsc,
Sage Weil16725b92009-10-06 11:31:07 -0700878 const char *path,
879 unsigned long started)
880{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700881 struct ceph_mds_client *mdsc = fsc->mdsc;
Sage Weil16725b92009-10-06 11:31:07 -0700882 struct ceph_mds_request *req = NULL;
883 int err;
884 struct dentry *root;
885
886 /* open dir */
887 dout("open_root_inode opening '%s'\n", path);
888 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_GETATTR, USE_ANY_MDS);
889 if (IS_ERR(req))
Julia Lawall7e34bc52010-05-22 12:01:14 +0200890 return ERR_CAST(req);
Sage Weil16725b92009-10-06 11:31:07 -0700891 req->r_path1 = kstrdup(path, GFP_NOFS);
Sanidhya Kashyapa149bb92015-03-21 12:54:58 -0400892 if (!req->r_path1) {
893 root = ERR_PTR(-ENOMEM);
894 goto out;
895 }
896
Sage Weil16725b92009-10-06 11:31:07 -0700897 req->r_ino1.ino = CEPH_INO_ROOT;
898 req->r_ino1.snap = CEPH_NOSNAP;
899 req->r_started = started;
Ilya Dryomova319bf52015-05-15 12:02:17 +0300900 req->r_timeout = fsc->client->options->mount_timeout;
Sage Weil16725b92009-10-06 11:31:07 -0700901 req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INODE);
902 req->r_num_caps = 2;
903 err = ceph_mdsc_do_request(mdsc, NULL, req);
904 if (err == 0) {
Al Viro3c5184e2012-01-09 16:34:32 -0500905 struct inode *inode = req->r_target_inode;
906 req->r_target_inode = NULL;
Sage Weil16725b92009-10-06 11:31:07 -0700907 dout("open_root_inode success\n");
Yan, Zhengce2728a2016-09-14 14:53:05 +0800908 root = d_make_root(inode);
909 if (!root) {
910 root = ERR_PTR(-ENOMEM);
911 goto out;
Sage Weil774ac212011-11-11 09:48:08 -0800912 }
Sage Weil16725b92009-10-06 11:31:07 -0700913 dout("open_root_inode success, root dentry is %p\n", root);
914 } else {
915 root = ERR_PTR(err);
916 }
Al Viro3c5184e2012-01-09 16:34:32 -0500917out:
Sage Weil16725b92009-10-06 11:31:07 -0700918 ceph_mdsc_put_request(req);
919 return root;
920}
921
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700922
923
924
Sage Weil16725b92009-10-06 11:31:07 -0700925/*
926 * mount: join the ceph cluster, and open root directory.
927 */
Yan, Zheng3f384952016-04-21 11:09:55 +0800928static struct dentry *ceph_real_mount(struct ceph_fs_client *fsc)
Sage Weil16725b92009-10-06 11:31:07 -0700929{
Sage Weil16725b92009-10-06 11:31:07 -0700930 int err;
Sage Weil16725b92009-10-06 11:31:07 -0700931 unsigned long started = jiffies; /* note the start time */
932 struct dentry *root;
933
Yan, Zheng132ca7e2016-03-12 13:20:48 +0800934 dout("mount start %p\n", fsc);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700935 mutex_lock(&fsc->client->mount_mutex);
Sage Weil16725b92009-10-06 11:31:07 -0700936
Yan, Zheng132ca7e2016-03-12 13:20:48 +0800937 if (!fsc->sb->s_root) {
Yan, Zhengce2728a2016-09-14 14:53:05 +0800938 const char *path;
Yan, Zheng132ca7e2016-03-12 13:20:48 +0800939 err = __ceph_open_session(fsc->client, started);
940 if (err < 0)
941 goto out;
Sage Weil16725b92009-10-06 11:31:07 -0700942
Yan, Zheng1d8f8362017-06-27 11:57:56 +0800943 /* setup fscache */
944 if (fsc->mount_options->flags & CEPH_MOUNT_OPT_FSCACHE) {
945 err = ceph_fscache_register_fs(fsc);
946 if (err < 0)
947 goto out;
948 }
949
Yan, Zhengce2728a2016-09-14 14:53:05 +0800950 if (!fsc->mount_options->server_path) {
951 path = "";
952 dout("mount opening path \\t\n");
953 } else {
954 path = fsc->mount_options->server_path + 1;
955 dout("mount opening path %s\n", path);
956 }
Chengguang Xu18106732018-02-09 20:40:59 +0800957
Greg Kroah-Hartman1a829ff2019-06-12 16:55:38 +0200958 ceph_fs_debugfs_init(fsc);
Chengguang Xu18106732018-02-09 20:40:59 +0800959
Yan, Zhengce2728a2016-09-14 14:53:05 +0800960 root = open_root_dentry(fsc, path, started);
Yan, Zheng132ca7e2016-03-12 13:20:48 +0800961 if (IS_ERR(root)) {
962 err = PTR_ERR(root);
963 goto out;
964 }
Yan, Zhengce2728a2016-09-14 14:53:05 +0800965 fsc->sb->s_root = dget(root);
Geert Uytterhoeven31ca5872016-10-13 17:15:37 +0200966 } else {
967 root = dget(fsc->sb->s_root);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700968 }
Sage Weil16725b92009-10-06 11:31:07 -0700969
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700970 fsc->mount_state = CEPH_MOUNT_MOUNTED;
Sage Weil16725b92009-10-06 11:31:07 -0700971 dout("mount success\n");
Al Viroa7f9fb22010-07-26 16:17:55 +0400972 mutex_unlock(&fsc->client->mount_mutex);
973 return root;
Sage Weil16725b92009-10-06 11:31:07 -0700974
Yan, Zheng132ca7e2016-03-12 13:20:48 +0800975out:
976 mutex_unlock(&fsc->client->mount_mutex);
977 return ERR_PTR(err);
Sage Weil16725b92009-10-06 11:31:07 -0700978}
979
980static int ceph_set_super(struct super_block *s, void *data)
981{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700982 struct ceph_fs_client *fsc = data;
Sage Weil16725b92009-10-06 11:31:07 -0700983 int ret;
984
985 dout("set_super %p data %p\n", s, data);
986
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700987 s->s_flags = fsc->mount_options->sb_flags;
Chengguang Xu719784b2018-07-19 22:15:24 +0800988 s->s_maxbytes = MAX_LFS_FILESIZE;
Sage Weil16725b92009-10-06 11:31:07 -0700989
Guangliang Zhao7221fe42013-11-11 15:18:03 +0800990 s->s_xattr = ceph_xattr_handlers;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700991 s->s_fs_info = fsc;
992 fsc->sb = s;
Chengguang Xu719784b2018-07-19 22:15:24 +0800993 fsc->max_file_size = 1ULL << 40; /* temp value until we get mdsmap */
Sage Weil16725b92009-10-06 11:31:07 -0700994
995 s->s_op = &ceph_super_ops;
Al Viro18fc8ab2016-10-28 21:52:50 -0400996 s->s_d_op = &ceph_dentry_ops;
Sage Weil16725b92009-10-06 11:31:07 -0700997 s->s_export_op = &ceph_export_ops;
998
Luis Henriques0f7cf802019-06-27 14:51:22 +0100999 s->s_time_gran = 1;
Sage Weil16725b92009-10-06 11:31:07 -07001000
1001 ret = set_anon_super(s, NULL); /* what is that second arg for? */
1002 if (ret != 0)
1003 goto fail;
1004
1005 return ret;
1006
1007fail:
1008 s->s_fs_info = NULL;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001009 fsc->sb = NULL;
Sage Weil16725b92009-10-06 11:31:07 -07001010 return ret;
1011}
1012
1013/*
1014 * share superblock if same fs AND options
1015 */
1016static int ceph_compare_super(struct super_block *sb, void *data)
1017{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001018 struct ceph_fs_client *new = data;
1019 struct ceph_mount_options *fsopt = new->mount_options;
1020 struct ceph_options *opt = new->client->options;
1021 struct ceph_fs_client *other = ceph_sb_to_client(sb);
Sage Weil16725b92009-10-06 11:31:07 -07001022
1023 dout("ceph_compare_super %p\n", sb);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001024
1025 if (compare_mount_options(fsopt, opt, other)) {
1026 dout("monitor(s)/mount options don't match\n");
1027 return 0;
Sage Weil16725b92009-10-06 11:31:07 -07001028 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001029 if ((opt->flags & CEPH_OPT_FSID) &&
1030 ceph_fsid_compare(&opt->fsid, &other->client->fsid)) {
1031 dout("fsid doesn't match\n");
1032 return 0;
1033 }
1034 if (fsopt->sb_flags != other->mount_options->sb_flags) {
Sage Weil16725b92009-10-06 11:31:07 -07001035 dout("flags differ\n");
1036 return 0;
1037 }
1038 return 1;
1039}
1040
1041/*
1042 * construct our own bdi so we can control readahead, etc.
1043 */
Jeff Mahoney00d56432010-06-10 11:13:58 -04001044static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
Sage Weil31e0cf82010-05-04 16:39:35 -07001045
Jan Kara09dc9fc2017-04-12 12:24:33 +02001046static int ceph_setup_bdi(struct super_block *sb, struct ceph_fs_client *fsc)
Sage Weil16725b92009-10-06 11:31:07 -07001047{
1048 int err;
1049
Jan Kara09dc9fc2017-04-12 12:24:33 +02001050 err = super_setup_bdi_name(sb, "ceph-%ld",
1051 atomic_long_inc_return(&bdi_seq));
1052 if (err)
1053 return err;
1054
Sage Weil83817e32011-08-04 08:03:44 -07001055 /* set ra_pages based on rasize mount option? */
Yan, Zheng4214fb12017-07-11 18:49:44 +08001056 sb->s_bdi->ra_pages = fsc->mount_options->rasize >> PAGE_SHIFT;
Yehuda Sadehe9852222011-07-22 11:12:28 -07001057
Yan, Zhengaa187922017-07-11 15:56:09 +08001058 /* set io_pages based on max osd read size */
1059 sb->s_bdi->io_pages = fsc->mount_options->rsize >> PAGE_SHIFT;
Andreas Gerstmayr7c94ba22017-01-10 14:17:56 +01001060
Jan Kara09dc9fc2017-04-12 12:24:33 +02001061 return 0;
Sage Weil16725b92009-10-06 11:31:07 -07001062}
1063
Al Viroa7f9fb22010-07-26 16:17:55 +04001064static struct dentry *ceph_mount(struct file_system_type *fs_type,
1065 int flags, const char *dev_name, void *data)
Sage Weil16725b92009-10-06 11:31:07 -07001066{
1067 struct super_block *sb;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001068 struct ceph_fs_client *fsc;
Al Viroa7f9fb22010-07-26 16:17:55 +04001069 struct dentry *res;
Sage Weil16725b92009-10-06 11:31:07 -07001070 int err;
1071 int (*compare_super)(struct super_block *, void *) = ceph_compare_super;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001072 struct ceph_mount_options *fsopt = NULL;
1073 struct ceph_options *opt = NULL;
Sage Weil16725b92009-10-06 11:31:07 -07001074
Al Viroa7f9fb22010-07-26 16:17:55 +04001075 dout("ceph_mount\n");
Sage Weil45195e42014-02-16 10:05:29 -08001076
1077#ifdef CONFIG_CEPH_FS_POSIX_ACL
Linus Torvalds1751e8a2017-11-27 13:05:09 -08001078 flags |= SB_POSIXACL;
Sage Weil45195e42014-02-16 10:05:29 -08001079#endif
Yan, Zheng3f384952016-04-21 11:09:55 +08001080 err = parse_mount_options(&fsopt, &opt, flags, data, dev_name);
Al Viroa7f9fb22010-07-26 16:17:55 +04001081 if (err < 0) {
1082 res = ERR_PTR(err);
Sage Weil6b805182009-10-27 11:50:50 -07001083 goto out_final;
Al Viroa7f9fb22010-07-26 16:17:55 +04001084 }
Sage Weil16725b92009-10-06 11:31:07 -07001085
1086 /* create client (which we may/may not use) */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001087 fsc = create_fs_client(fsopt, opt);
1088 if (IS_ERR(fsc)) {
Al Viroa7f9fb22010-07-26 16:17:55 +04001089 res = ERR_CAST(fsc);
Sage Weil6b805182009-10-27 11:50:50 -07001090 goto out_final;
1091 }
Sage Weil16725b92009-10-06 11:31:07 -07001092
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001093 err = ceph_mdsc_init(fsc);
Al Viroa7f9fb22010-07-26 16:17:55 +04001094 if (err < 0) {
1095 res = ERR_PTR(err);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001096 goto out;
Al Viroa7f9fb22010-07-26 16:17:55 +04001097 }
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001098
1099 if (ceph_test_opt(fsc->client, NOSHARE))
Sage Weil16725b92009-10-06 11:31:07 -07001100 compare_super = NULL;
David Howells9249e172012-06-25 12:55:37 +01001101 sb = sget(fs_type, compare_super, ceph_set_super, flags, fsc);
Sage Weil16725b92009-10-06 11:31:07 -07001102 if (IS_ERR(sb)) {
Al Viroa7f9fb22010-07-26 16:17:55 +04001103 res = ERR_CAST(sb);
Sage Weil16725b92009-10-06 11:31:07 -07001104 goto out;
1105 }
1106
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001107 if (ceph_sb_to_client(sb) != fsc) {
1108 ceph_mdsc_destroy(fsc);
1109 destroy_fs_client(fsc);
1110 fsc = ceph_sb_to_client(sb);
1111 dout("get_sb got existing client %p\n", fsc);
Sage Weil16725b92009-10-06 11:31:07 -07001112 } else {
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001113 dout("get_sb using new client %p\n", fsc);
Jan Kara09dc9fc2017-04-12 12:24:33 +02001114 err = ceph_setup_bdi(sb, fsc);
Al Viroa7f9fb22010-07-26 16:17:55 +04001115 if (err < 0) {
1116 res = ERR_PTR(err);
Sage Weil16725b92009-10-06 11:31:07 -07001117 goto out_splat;
Al Viroa7f9fb22010-07-26 16:17:55 +04001118 }
Sage Weil16725b92009-10-06 11:31:07 -07001119 }
1120
Yan, Zheng3f384952016-04-21 11:09:55 +08001121 res = ceph_real_mount(fsc);
Al Viroa7f9fb22010-07-26 16:17:55 +04001122 if (IS_ERR(res))
Sage Weil16725b92009-10-06 11:31:07 -07001123 goto out_splat;
Al Viroa7f9fb22010-07-26 16:17:55 +04001124 dout("root %p inode %p ino %llx.%llx\n", res,
David Howells2b0143b2015-03-17 22:25:59 +00001125 d_inode(res), ceph_vinop(d_inode(res)));
Al Viroa7f9fb22010-07-26 16:17:55 +04001126 return res;
Sage Weil16725b92009-10-06 11:31:07 -07001127
1128out_splat:
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001129 ceph_mdsc_close_sessions(fsc->mdsc);
Al Viro3981f2e2010-03-21 19:22:29 -04001130 deactivate_locked_super(sb);
Sage Weil16725b92009-10-06 11:31:07 -07001131 goto out_final;
1132
1133out:
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001134 ceph_mdsc_destroy(fsc);
1135 destroy_fs_client(fsc);
Sage Weil16725b92009-10-06 11:31:07 -07001136out_final:
Al Viroa7f9fb22010-07-26 16:17:55 +04001137 dout("ceph_mount fail %ld\n", PTR_ERR(res));
1138 return res;
Sage Weil16725b92009-10-06 11:31:07 -07001139}
1140
1141static void ceph_kill_sb(struct super_block *s)
1142{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001143 struct ceph_fs_client *fsc = ceph_sb_to_client(s);
Christoph Hellwige4d27502015-01-14 10:42:38 +01001144 dev_t dev = s->s_dev;
1145
Sage Weil16725b92009-10-06 11:31:07 -07001146 dout("kill_sb %p\n", s);
Christoph Hellwige4d27502015-01-14 10:42:38 +01001147
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001148 ceph_mdsc_pre_umount(fsc->mdsc);
Yan, Zhenga57d9062018-05-18 16:05:51 +08001149 flush_fs_workqueues(fsc);
1150
Christoph Hellwige4d27502015-01-14 10:42:38 +01001151 generic_shutdown_super(s);
Yan, Zheng62a65f32017-06-22 16:26:34 +08001152
1153 fsc->client->extra_mon_dispatch = NULL;
1154 ceph_fs_debugfs_cleanup(fsc);
1155
Yan, Zheng1d8f8362017-06-27 11:57:56 +08001156 ceph_fscache_unregister_fs(fsc);
1157
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001158 ceph_mdsc_destroy(fsc);
Christoph Hellwige4d27502015-01-14 10:42:38 +01001159
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001160 destroy_fs_client(fsc);
Christoph Hellwige4d27502015-01-14 10:42:38 +01001161 free_anon_bdev(dev);
Sage Weil16725b92009-10-06 11:31:07 -07001162}
1163
1164static struct file_system_type ceph_fs_type = {
1165 .owner = THIS_MODULE,
1166 .name = "ceph",
Al Viroa7f9fb22010-07-26 16:17:55 +04001167 .mount = ceph_mount,
Sage Weil16725b92009-10-06 11:31:07 -07001168 .kill_sb = ceph_kill_sb,
1169 .fs_flags = FS_RENAME_DOES_D_MOVE,
1170};
Eric W. Biederman7f78e032013-03-02 19:39:14 -08001171MODULE_ALIAS_FS("ceph");
Sage Weil16725b92009-10-06 11:31:07 -07001172
Yan, Zhengd468e722019-07-25 20:16:44 +08001173int ceph_force_reconnect(struct super_block *sb)
1174{
1175 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
1176 int err = 0;
1177
1178 ceph_umount_begin(sb);
1179
1180 /* Make sure all page caches get invalidated.
1181 * see remove_session_caps_cb() */
1182 flush_workqueue(fsc->inode_wq);
1183
1184 /* In case that we were blacklisted. This also reset
1185 * all mon/osd connections */
1186 ceph_reset_client_addr(fsc->client);
1187
1188 ceph_osdc_clear_abort_err(&fsc->client->osdc);
Yan, Zheng131d7eb2019-07-25 20:16:47 +08001189
1190 fsc->blacklisted = false;
Yan, Zhengd468e722019-07-25 20:16:44 +08001191 fsc->mount_state = CEPH_MOUNT_MOUNTED;
1192
1193 if (sb->s_root) {
1194 err = __ceph_do_getattr(d_inode(sb->s_root), NULL,
1195 CEPH_STAT_CAP_INODE, true);
1196 }
1197 return err;
1198}
1199
Sage Weil16725b92009-10-06 11:31:07 -07001200static int __init init_ceph(void)
1201{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001202 int ret = init_caches();
Sage Weil16725b92009-10-06 11:31:07 -07001203 if (ret)
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001204 goto out;
Sage Weil16725b92009-10-06 11:31:07 -07001205
Yan, Zhengeb13e832014-03-09 23:16:40 +08001206 ceph_flock_init();
Sage Weil16725b92009-10-06 11:31:07 -07001207 ret = register_filesystem(&ceph_fs_type);
1208 if (ret)
David Disseldorpd0f191d2019-04-18 14:15:49 +02001209 goto out_caches;
Sage Weil16725b92009-10-06 11:31:07 -07001210
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001211 pr_info("loaded (mds proto %d)\n", CEPH_MDSC_PROTOCOL);
1212
Sage Weil16725b92009-10-06 11:31:07 -07001213 return 0;
1214
David Disseldorpd0f191d2019-04-18 14:15:49 +02001215out_caches:
Sage Weil16725b92009-10-06 11:31:07 -07001216 destroy_caches();
Sage Weil16725b92009-10-06 11:31:07 -07001217out:
1218 return ret;
1219}
1220
1221static void __exit exit_ceph(void)
1222{
1223 dout("exit_ceph\n");
1224 unregister_filesystem(&ceph_fs_type);
Sage Weil16725b92009-10-06 11:31:07 -07001225 destroy_caches();
Sage Weil16725b92009-10-06 11:31:07 -07001226}
1227
1228module_init(init_ceph);
1229module_exit(exit_ceph);
1230
1231MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
1232MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
1233MODULE_AUTHOR("Patience Warnick <patience@newdream.net>");
1234MODULE_DESCRIPTION("Ceph filesystem for Linux");
1235MODULE_LICENSE("GPL");