]>
Commit | Line | Data |
---|---|---|
16725b9d | 1 | |
3d14c5d2 | 2 | #include <linux/ceph/ceph_debug.h> |
16725b9d SW |
3 | |
4 | #include <linux/backing-dev.h> | |
c309f0ab | 5 | #include <linux/ctype.h> |
16725b9d SW |
6 | #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> | |
16725b9d SW |
12 | #include <linux/sched.h> |
13 | #include <linux/seq_file.h> | |
5a0e3ad6 | 14 | #include <linux/slab.h> |
16725b9d SW |
15 | #include <linux/statfs.h> |
16 | #include <linux/string.h> | |
16725b9d | 17 | |
16725b9d | 18 | #include "super.h" |
3d14c5d2 | 19 | #include "mds_client.h" |
99ccbd22 | 20 | #include "cache.h" |
3d14c5d2 | 21 | |
1fe60e51 | 22 | #include <linux/ceph/ceph_features.h> |
3d14c5d2 YS |
23 | #include <linux/ceph/decode.h> |
24 | #include <linux/ceph/mon_client.h> | |
25 | #include <linux/ceph/auth.h> | |
26 | #include <linux/ceph/debugfs.h> | |
16725b9d SW |
27 | |
28 | /* | |
29 | * Ceph superblock operations | |
30 | * | |
31 | * Handle the basics of mounting, unmounting. | |
32 | */ | |
33 | ||
16725b9d SW |
34 | /* |
35 | * super ops | |
36 | */ | |
37 | static void ceph_put_super(struct super_block *s) | |
38 | { | |
3d14c5d2 | 39 | struct ceph_fs_client *fsc = ceph_sb_to_client(s); |
16725b9d SW |
40 | |
41 | dout("put_super\n"); | |
3d14c5d2 | 42 | ceph_mdsc_close_sessions(fsc->mdsc); |
16725b9d SW |
43 | } |
44 | ||
45 | static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf) | |
46 | { | |
2b0143b5 | 47 | struct ceph_fs_client *fsc = ceph_inode_to_client(d_inode(dentry)); |
3d14c5d2 | 48 | struct ceph_monmap *monmap = fsc->client->monc.monmap; |
16725b9d SW |
49 | struct ceph_statfs st; |
50 | u64 fsid; | |
51 | int err; | |
06d74376 DF |
52 | 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 | } | |
16725b9d SW |
59 | |
60 | dout("statfs\n"); | |
06d74376 | 61 | err = ceph_monc_do_statfs(&fsc->client->monc, data_pool, &st); |
16725b9d SW |
62 | 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. | |
92a49fb0 SW |
71 | * |
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! | |
16725b9d SW |
76 | */ |
77 | buf->f_bsize = 1 << CEPH_BLOCK_SHIFT; | |
92a49fb0 | 78 | buf->f_frsize = 1 << CEPH_BLOCK_SHIFT; |
9122eed5 LH |
79 | |
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 | } | |
16725b9d SW |
91 | |
92 | buf->f_files = le64_to_cpu(st.num_objects); | |
93 | buf->f_ffree = -1; | |
558d3499 | 94 | buf->f_namelen = NAME_MAX; |
16725b9d | 95 | |
080a330e JL |
96 | /* Must convert the fsid, for consistent values across arches */ |
97 | fsid = le64_to_cpu(*(__le64 *)(&monmap->fsid)) ^ | |
98 | le64_to_cpu(*((__le64 *)&monmap->fsid + 1)); | |
16725b9d SW |
99 | buf->f_fsid.val[0] = fsid & 0xffffffff; |
100 | buf->f_fsid.val[1] = fsid >> 32; | |
101 | ||
102 | return 0; | |
103 | } | |
104 | ||
105 | ||
2d9c98ae | 106 | static int ceph_sync_fs(struct super_block *sb, int wait) |
16725b9d | 107 | { |
3d14c5d2 | 108 | struct ceph_fs_client *fsc = ceph_sb_to_client(sb); |
2d9c98ae SW |
109 | |
110 | if (!wait) { | |
111 | dout("sync_fs (non-blocking)\n"); | |
3d14c5d2 | 112 | ceph_flush_dirty_caps(fsc->mdsc); |
2d9c98ae SW |
113 | dout("sync_fs (non-blocking) done\n"); |
114 | return 0; | |
115 | } | |
116 | ||
117 | dout("sync_fs (blocking)\n"); | |
3d14c5d2 YS |
118 | ceph_osdc_sync(&fsc->client->osdc); |
119 | ceph_mdsc_sync(fsc->mdsc); | |
2d9c98ae | 120 | dout("sync_fs (blocking) done\n"); |
16725b9d SW |
121 | return 0; |
122 | } | |
123 | ||
16725b9d SW |
124 | /* |
125 | * mount options | |
126 | */ | |
127 | enum { | |
16725b9d SW |
128 | Opt_wsize, |
129 | Opt_rsize, | |
83817e35 | 130 | Opt_rasize, |
16725b9d SW |
131 | Opt_caps_wanted_delay_min, |
132 | Opt_caps_wanted_delay_max, | |
133 | Opt_readdir_max_entries, | |
23804d91 | 134 | Opt_readdir_max_bytes, |
2baba250 | 135 | Opt_congestion_kb, |
e53c2fe0 | 136 | Opt_last_int, |
16725b9d SW |
137 | /* int args above */ |
138 | Opt_snapdirname, | |
430afbad | 139 | Opt_mds_namespace, |
1d8f8360 | 140 | Opt_fscache_uniq, |
e53c2fe0 | 141 | Opt_last_string, |
16725b9d | 142 | /* string args above */ |
16725b9d SW |
143 | Opt_dirstat, |
144 | Opt_nodirstat, | |
145 | Opt_rbytes, | |
146 | Opt_norbytes, | |
cffaba15 | 147 | Opt_asyncreaddir, |
16725b9d | 148 | Opt_noasyncreaddir, |
a40dc6cc SW |
149 | Opt_dcache, |
150 | Opt_nodcache, | |
ad1fee96 | 151 | Opt_ino32, |
cffaba15 | 152 | Opt_noino32, |
99ccbd22 | 153 | Opt_fscache, |
45195e42 | 154 | Opt_nofscache, |
10183a69 YZ |
155 | Opt_poolperm, |
156 | Opt_nopoolperm, | |
e9e427f0 YZ |
157 | Opt_require_active_mds, |
158 | Opt_norequire_active_mds, | |
45195e42 SW |
159 | #ifdef CONFIG_CEPH_FS_POSIX_ACL |
160 | Opt_acl, | |
161 | #endif | |
10183a69 | 162 | Opt_noacl, |
9122eed5 LH |
163 | Opt_quotadf, |
164 | Opt_noquotadf, | |
16725b9d SW |
165 | }; |
166 | ||
3d14c5d2 | 167 | static match_table_t fsopt_tokens = { |
16725b9d SW |
168 | {Opt_wsize, "wsize=%d"}, |
169 | {Opt_rsize, "rsize=%d"}, | |
83817e35 | 170 | {Opt_rasize, "rasize=%d"}, |
16725b9d SW |
171 | {Opt_caps_wanted_delay_min, "caps_wanted_delay_min=%d"}, |
172 | {Opt_caps_wanted_delay_max, "caps_wanted_delay_max=%d"}, | |
173 | {Opt_readdir_max_entries, "readdir_max_entries=%d"}, | |
23804d91 | 174 | {Opt_readdir_max_bytes, "readdir_max_bytes=%d"}, |
2baba250 | 175 | {Opt_congestion_kb, "write_congestion_kb=%d"}, |
16725b9d SW |
176 | /* int args above */ |
177 | {Opt_snapdirname, "snapdirname=%s"}, | |
430afbad | 178 | {Opt_mds_namespace, "mds_namespace=%s"}, |
1d8f8360 | 179 | {Opt_fscache_uniq, "fsc=%s"}, |
16725b9d | 180 | /* string args above */ |
16725b9d SW |
181 | {Opt_dirstat, "dirstat"}, |
182 | {Opt_nodirstat, "nodirstat"}, | |
183 | {Opt_rbytes, "rbytes"}, | |
184 | {Opt_norbytes, "norbytes"}, | |
cffaba15 | 185 | {Opt_asyncreaddir, "asyncreaddir"}, |
16725b9d | 186 | {Opt_noasyncreaddir, "noasyncreaddir"}, |
a40dc6cc SW |
187 | {Opt_dcache, "dcache"}, |
188 | {Opt_nodcache, "nodcache"}, | |
ad1fee96 | 189 | {Opt_ino32, "ino32"}, |
cffaba15 | 190 | {Opt_noino32, "noino32"}, |
99ccbd22 MT |
191 | {Opt_fscache, "fsc"}, |
192 | {Opt_nofscache, "nofsc"}, | |
10183a69 YZ |
193 | {Opt_poolperm, "poolperm"}, |
194 | {Opt_nopoolperm, "nopoolperm"}, | |
e9e427f0 YZ |
195 | {Opt_require_active_mds, "require_active_mds"}, |
196 | {Opt_norequire_active_mds, "norequire_active_mds"}, | |
45195e42 SW |
197 | #ifdef CONFIG_CEPH_FS_POSIX_ACL |
198 | {Opt_acl, "acl"}, | |
199 | #endif | |
200 | {Opt_noacl, "noacl"}, | |
9122eed5 LH |
201 | {Opt_quotadf, "quotadf"}, |
202 | {Opt_noquotadf, "noquotadf"}, | |
16725b9d SW |
203 | {-1, NULL} |
204 | }; | |
205 | ||
3d14c5d2 | 206 | static int parse_fsopt_token(char *c, void *private) |
c309f0ab | 207 | { |
3d14c5d2 YS |
208 | struct ceph_mount_options *fsopt = private; |
209 | substring_t argstr[MAX_OPT_ARGS]; | |
210 | int token, intval, ret; | |
211 | ||
212 | token = match_token((char *)c, fsopt_tokens, argstr); | |
213 | if (token < 0) | |
214 | return -EINVAL; | |
215 | ||
216 | if (token < Opt_last_int) { | |
217 | ret = match_int(&argstr[0], &intval); | |
218 | if (ret < 0) { | |
219 | pr_err("bad mount option arg (not int) " | |
220 | "at '%s'\n", c); | |
221 | return ret; | |
c309f0ab | 222 | } |
3d14c5d2 YS |
223 | dout("got int token %d val %d\n", token, intval); |
224 | } else if (token > Opt_last_int && token < Opt_last_string) { | |
225 | dout("got string token %d val %s\n", token, | |
226 | argstr[0].from); | |
227 | } else { | |
228 | dout("got token %d\n", token); | |
c309f0ab SW |
229 | } |
230 | ||
3d14c5d2 YS |
231 | switch (token) { |
232 | case Opt_snapdirname: | |
233 | kfree(fsopt->snapdir_name); | |
234 | fsopt->snapdir_name = kstrndup(argstr[0].from, | |
235 | argstr[0].to-argstr[0].from, | |
236 | GFP_KERNEL); | |
237 | if (!fsopt->snapdir_name) | |
238 | return -ENOMEM; | |
239 | break; | |
235a0982 | 240 | case Opt_mds_namespace: |
937441f3 | 241 | kfree(fsopt->mds_namespace); |
430afbad YZ |
242 | fsopt->mds_namespace = kstrndup(argstr[0].from, |
243 | argstr[0].to-argstr[0].from, | |
244 | GFP_KERNEL); | |
245 | if (!fsopt->mds_namespace) | |
246 | return -ENOMEM; | |
235a0982 | 247 | break; |
1d8f8360 | 248 | case Opt_fscache_uniq: |
937441f3 | 249 | kfree(fsopt->fscache_uniq); |
1d8f8360 YZ |
250 | fsopt->fscache_uniq = kstrndup(argstr[0].from, |
251 | argstr[0].to-argstr[0].from, | |
252 | GFP_KERNEL); | |
253 | if (!fsopt->fscache_uniq) | |
254 | return -ENOMEM; | |
255 | fsopt->flags |= CEPH_MOUNT_OPT_FSCACHE; | |
256 | break; | |
430afbad | 257 | /* misc */ |
3d14c5d2 | 258 | case Opt_wsize: |
95cca2b4 YZ |
259 | if (intval < PAGE_SIZE || intval > CEPH_MAX_WRITE_SIZE) |
260 | return -EINVAL; | |
261 | fsopt->wsize = ALIGN(intval, PAGE_SIZE); | |
3d14c5d2 YS |
262 | break; |
263 | case Opt_rsize: | |
aa187926 YZ |
264 | if (intval < PAGE_SIZE || intval > CEPH_MAX_READ_SIZE) |
265 | return -EINVAL; | |
266 | fsopt->rsize = ALIGN(intval, PAGE_SIZE); | |
3d14c5d2 | 267 | break; |
83817e35 | 268 | case Opt_rasize: |
4214fb15 YZ |
269 | if (intval < 0) |
270 | return -EINVAL; | |
271 | fsopt->rasize = ALIGN(intval + PAGE_SIZE - 1, PAGE_SIZE); | |
83817e35 | 272 | break; |
3d14c5d2 | 273 | case Opt_caps_wanted_delay_min: |
4214fb15 YZ |
274 | if (intval < 1) |
275 | return -EINVAL; | |
3d14c5d2 YS |
276 | fsopt->caps_wanted_delay_min = intval; |
277 | break; | |
278 | case Opt_caps_wanted_delay_max: | |
4214fb15 YZ |
279 | if (intval < 1) |
280 | return -EINVAL; | |
3d14c5d2 YS |
281 | fsopt->caps_wanted_delay_max = intval; |
282 | break; | |
283 | case Opt_readdir_max_entries: | |
4214fb15 YZ |
284 | if (intval < 1) |
285 | return -EINVAL; | |
3d14c5d2 YS |
286 | fsopt->max_readdir = intval; |
287 | break; | |
288 | case Opt_readdir_max_bytes: | |
4214fb15 YZ |
289 | if (intval < PAGE_SIZE && intval != 0) |
290 | return -EINVAL; | |
3d14c5d2 YS |
291 | fsopt->max_readdir_bytes = intval; |
292 | break; | |
293 | case Opt_congestion_kb: | |
4214fb15 YZ |
294 | if (intval < 1024) /* at least 1M */ |
295 | return -EINVAL; | |
3d14c5d2 YS |
296 | fsopt->congestion_kb = intval; |
297 | break; | |
298 | case Opt_dirstat: | |
299 | fsopt->flags |= CEPH_MOUNT_OPT_DIRSTAT; | |
300 | break; | |
301 | case Opt_nodirstat: | |
302 | fsopt->flags &= ~CEPH_MOUNT_OPT_DIRSTAT; | |
303 | break; | |
304 | case Opt_rbytes: | |
305 | fsopt->flags |= CEPH_MOUNT_OPT_RBYTES; | |
306 | break; | |
307 | case Opt_norbytes: | |
308 | fsopt->flags &= ~CEPH_MOUNT_OPT_RBYTES; | |
309 | break; | |
cffaba15 AE |
310 | case Opt_asyncreaddir: |
311 | fsopt->flags &= ~CEPH_MOUNT_OPT_NOASYNCREADDIR; | |
312 | break; | |
3d14c5d2 YS |
313 | case Opt_noasyncreaddir: |
314 | fsopt->flags |= CEPH_MOUNT_OPT_NOASYNCREADDIR; | |
315 | break; | |
a40dc6cc SW |
316 | case Opt_dcache: |
317 | fsopt->flags |= CEPH_MOUNT_OPT_DCACHE; | |
318 | break; | |
319 | case Opt_nodcache: | |
320 | fsopt->flags &= ~CEPH_MOUNT_OPT_DCACHE; | |
321 | break; | |
ad1fee96 YS |
322 | case Opt_ino32: |
323 | fsopt->flags |= CEPH_MOUNT_OPT_INO32; | |
324 | break; | |
cffaba15 AE |
325 | case Opt_noino32: |
326 | fsopt->flags &= ~CEPH_MOUNT_OPT_INO32; | |
327 | break; | |
99ccbd22 MT |
328 | case Opt_fscache: |
329 | fsopt->flags |= CEPH_MOUNT_OPT_FSCACHE; | |
7ae7a828 CX |
330 | kfree(fsopt->fscache_uniq); |
331 | fsopt->fscache_uniq = NULL; | |
99ccbd22 MT |
332 | break; |
333 | case Opt_nofscache: | |
334 | fsopt->flags &= ~CEPH_MOUNT_OPT_FSCACHE; | |
7ae7a828 CX |
335 | kfree(fsopt->fscache_uniq); |
336 | fsopt->fscache_uniq = NULL; | |
99ccbd22 | 337 | break; |
10183a69 YZ |
338 | case Opt_poolperm: |
339 | fsopt->flags &= ~CEPH_MOUNT_OPT_NOPOOLPERM; | |
10183a69 YZ |
340 | break; |
341 | case Opt_nopoolperm: | |
342 | fsopt->flags |= CEPH_MOUNT_OPT_NOPOOLPERM; | |
343 | break; | |
e9e427f0 YZ |
344 | case Opt_require_active_mds: |
345 | fsopt->flags &= ~CEPH_MOUNT_OPT_MOUNTWAIT; | |
346 | break; | |
347 | case Opt_norequire_active_mds: | |
348 | fsopt->flags |= CEPH_MOUNT_OPT_MOUNTWAIT; | |
349 | break; | |
9122eed5 LH |
350 | case Opt_quotadf: |
351 | fsopt->flags &= ~CEPH_MOUNT_OPT_NOQUOTADF; | |
352 | break; | |
353 | case Opt_noquotadf: | |
354 | fsopt->flags |= CEPH_MOUNT_OPT_NOQUOTADF; | |
355 | break; | |
45195e42 SW |
356 | #ifdef CONFIG_CEPH_FS_POSIX_ACL |
357 | case Opt_acl: | |
1751e8a6 | 358 | fsopt->sb_flags |= SB_POSIXACL; |
45195e42 SW |
359 | break; |
360 | #endif | |
361 | case Opt_noacl: | |
1751e8a6 | 362 | fsopt->sb_flags &= ~SB_POSIXACL; |
45195e42 | 363 | break; |
3d14c5d2 YS |
364 | default: |
365 | BUG_ON(token); | |
366 | } | |
367 | return 0; | |
c309f0ab | 368 | } |
16725b9d | 369 | |
3d14c5d2 | 370 | static void destroy_mount_options(struct ceph_mount_options *args) |
16725b9d | 371 | { |
3d14c5d2 YS |
372 | dout("destroy_mount_options %p\n", args); |
373 | kfree(args->snapdir_name); | |
430afbad | 374 | kfree(args->mds_namespace); |
3f384954 | 375 | kfree(args->server_path); |
1d8f8360 | 376 | kfree(args->fscache_uniq); |
3d14c5d2 YS |
377 | kfree(args); |
378 | } | |
16725b9d | 379 | |
3d14c5d2 YS |
380 | static int strcmp_null(const char *s1, const char *s2) |
381 | { | |
382 | if (!s1 && !s2) | |
383 | return 0; | |
384 | if (s1 && !s2) | |
385 | return -1; | |
386 | if (!s1 && s2) | |
387 | return 1; | |
388 | return strcmp(s1, s2); | |
389 | } | |
16725b9d | 390 | |
3d14c5d2 YS |
391 | static int compare_mount_options(struct ceph_mount_options *new_fsopt, |
392 | struct ceph_options *new_opt, | |
393 | struct ceph_fs_client *fsc) | |
394 | { | |
395 | struct ceph_mount_options *fsopt1 = new_fsopt; | |
396 | struct ceph_mount_options *fsopt2 = fsc->mount_options; | |
397 | int ofs = offsetof(struct ceph_mount_options, snapdir_name); | |
398 | int ret; | |
16725b9d | 399 | |
3d14c5d2 YS |
400 | ret = memcmp(fsopt1, fsopt2, ofs); |
401 | if (ret) | |
402 | return ret; | |
403 | ||
404 | ret = strcmp_null(fsopt1->snapdir_name, fsopt2->snapdir_name); | |
430afbad YZ |
405 | if (ret) |
406 | return ret; | |
407 | ret = strcmp_null(fsopt1->mds_namespace, fsopt2->mds_namespace); | |
3d14c5d2 YS |
408 | if (ret) |
409 | return ret; | |
3f384954 | 410 | ret = strcmp_null(fsopt1->server_path, fsopt2->server_path); |
1d8f8360 YZ |
411 | if (ret) |
412 | return ret; | |
413 | ret = strcmp_null(fsopt1->fscache_uniq, fsopt2->fscache_uniq); | |
3f384954 YZ |
414 | if (ret) |
415 | return ret; | |
416 | ||
3d14c5d2 YS |
417 | return ceph_compare_options(new_opt, fsc->client); |
418 | } | |
419 | ||
420 | static int parse_mount_options(struct ceph_mount_options **pfsopt, | |
421 | struct ceph_options **popt, | |
422 | int flags, char *options, | |
3f384954 | 423 | const char *dev_name) |
3d14c5d2 YS |
424 | { |
425 | struct ceph_mount_options *fsopt; | |
426 | const char *dev_name_end; | |
c98f533c AE |
427 | int err; |
428 | ||
429 | if (!dev_name || !*dev_name) | |
430 | return -EINVAL; | |
3d14c5d2 YS |
431 | |
432 | fsopt = kzalloc(sizeof(*fsopt), GFP_KERNEL); | |
433 | if (!fsopt) | |
434 | return -ENOMEM; | |
435 | ||
436 | dout("parse_mount_options %p, dev_name '%s'\n", fsopt, dev_name); | |
437 | ||
80db8bea NW |
438 | fsopt->sb_flags = flags; |
439 | fsopt->flags = CEPH_MOUNT_OPT_DEFAULT; | |
3d14c5d2 | 440 | |
95cca2b4 | 441 | fsopt->wsize = CEPH_MAX_WRITE_SIZE; |
aa187926 | 442 | fsopt->rsize = CEPH_MAX_READ_SIZE; |
80db8bea NW |
443 | fsopt->rasize = CEPH_RASIZE_DEFAULT; |
444 | fsopt->snapdir_name = kstrdup(CEPH_SNAPDIRNAME_DEFAULT, GFP_KERNEL); | |
a149bb9a SK |
445 | if (!fsopt->snapdir_name) { |
446 | err = -ENOMEM; | |
447 | goto out; | |
448 | } | |
449 | ||
50aac4fe SW |
450 | fsopt->caps_wanted_delay_min = CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT; |
451 | fsopt->caps_wanted_delay_max = CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT; | |
80db8bea NW |
452 | fsopt->max_readdir = CEPH_MAX_READDIR_DEFAULT; |
453 | fsopt->max_readdir_bytes = CEPH_MAX_READDIR_BYTES_DEFAULT; | |
454 | fsopt->congestion_kb = default_congestion_kb(); | |
455 | ||
c98f533c AE |
456 | /* |
457 | * Distinguish the server list from the path in "dev_name". | |
458 | * Internally we do not include the leading '/' in the path. | |
459 | * | |
460 | * "dev_name" will look like: | |
461 | * <server_spec>[,<server_spec>...]:[<path>] | |
462 | * where | |
463 | * <server_spec> is <ip>[:<port>] | |
464 | * <path> is optional, but if present must begin with '/' | |
465 | */ | |
466 | dev_name_end = strchr(dev_name, '/'); | |
467 | if (dev_name_end) { | |
ce2728aa YZ |
468 | if (strlen(dev_name_end) > 1) { |
469 | fsopt->server_path = kstrdup(dev_name_end, GFP_KERNEL); | |
470 | if (!fsopt->server_path) { | |
471 | err = -ENOMEM; | |
472 | goto out; | |
473 | } | |
3f384954 | 474 | } |
c98f533c | 475 | } else { |
c98f533c | 476 | dev_name_end = dev_name + strlen(dev_name); |
c98f533c | 477 | } |
80db8bea | 478 | err = -EINVAL; |
c98f533c | 479 | dev_name_end--; /* back up to ':' separator */ |
54464296 | 480 | if (dev_name_end < dev_name || *dev_name_end != ':') { |
c98f533c | 481 | pr_err("device name is missing path (no : separator in %s)\n", |
80db8bea NW |
482 | dev_name); |
483 | goto out; | |
484 | } | |
3d14c5d2 | 485 | dout("device name '%.*s'\n", (int)(dev_name_end - dev_name), dev_name); |
3f384954 YZ |
486 | if (fsopt->server_path) |
487 | dout("server path '%s'\n", fsopt->server_path); | |
16725b9d | 488 | |
ee57741c | 489 | *popt = ceph_parse_options(options, dev_name, dev_name_end, |
3d14c5d2 | 490 | parse_fsopt_token, (void *)fsopt); |
ee57741c AE |
491 | if (IS_ERR(*popt)) { |
492 | err = PTR_ERR(*popt); | |
3d14c5d2 | 493 | goto out; |
ee57741c | 494 | } |
3d14c5d2 YS |
495 | |
496 | /* success */ | |
497 | *pfsopt = fsopt; | |
498 | return 0; | |
16725b9d | 499 | |
7b813c46 | 500 | out: |
3d14c5d2 YS |
501 | destroy_mount_options(fsopt); |
502 | return err; | |
16725b9d SW |
503 | } |
504 | ||
3d14c5d2 YS |
505 | /** |
506 | * ceph_show_options - Show mount options in /proc/mounts | |
507 | * @m: seq_file to write to | |
34c80b1d | 508 | * @root: root of that (sub)tree |
3d14c5d2 | 509 | */ |
34c80b1d | 510 | static int ceph_show_options(struct seq_file *m, struct dentry *root) |
16725b9d | 511 | { |
34c80b1d | 512 | struct ceph_fs_client *fsc = ceph_sb_to_client(root->d_sb); |
3d14c5d2 | 513 | struct ceph_mount_options *fsopt = fsc->mount_options; |
ff40f9ae ID |
514 | size_t pos; |
515 | int ret; | |
516 | ||
517 | /* a comma between MNT/MS and client options */ | |
518 | seq_putc(m, ','); | |
519 | pos = m->count; | |
520 | ||
521 | ret = ceph_print_client_options(m, fsc->client); | |
522 | if (ret) | |
523 | return ret; | |
524 | ||
525 | /* retract our comma if no client options */ | |
526 | if (m->count == pos) | |
527 | m->count--; | |
3d14c5d2 YS |
528 | |
529 | if (fsopt->flags & CEPH_MOUNT_OPT_DIRSTAT) | |
530 | seq_puts(m, ",dirstat"); | |
133e9156 YZ |
531 | if ((fsopt->flags & CEPH_MOUNT_OPT_RBYTES)) |
532 | seq_puts(m, ",rbytes"); | |
3d14c5d2 YS |
533 | if (fsopt->flags & CEPH_MOUNT_OPT_NOASYNCREADDIR) |
534 | seq_puts(m, ",noasyncreaddir"); | |
ff7eeb82 | 535 | if ((fsopt->flags & CEPH_MOUNT_OPT_DCACHE) == 0) |
a40dc6cc | 536 | seq_puts(m, ",nodcache"); |
1d8f8360 | 537 | if (fsopt->flags & CEPH_MOUNT_OPT_FSCACHE) { |
4d8969af | 538 | seq_show_option(m, "fsc", fsopt->fscache_uniq); |
1d8f8360 | 539 | } |
10183a69 YZ |
540 | if (fsopt->flags & CEPH_MOUNT_OPT_NOPOOLPERM) |
541 | seq_puts(m, ",nopoolperm"); | |
9122eed5 LH |
542 | if (fsopt->flags & CEPH_MOUNT_OPT_NOQUOTADF) |
543 | seq_puts(m, ",noquotadf"); | |
3d14c5d2 | 544 | |
45195e42 | 545 | #ifdef CONFIG_CEPH_FS_POSIX_ACL |
1751e8a6 | 546 | if (fsopt->sb_flags & SB_POSIXACL) |
45195e42 SW |
547 | seq_puts(m, ",acl"); |
548 | else | |
549 | seq_puts(m, ",noacl"); | |
550 | #endif | |
551 | ||
430afbad | 552 | if (fsopt->mds_namespace) |
4d8969af | 553 | seq_show_option(m, "mds_namespace", fsopt->mds_namespace); |
6dd4940b | 554 | if (fsopt->wsize != CEPH_MAX_WRITE_SIZE) |
3d14c5d2 | 555 | seq_printf(m, ",wsize=%d", fsopt->wsize); |
aa187926 | 556 | if (fsopt->rsize != CEPH_MAX_READ_SIZE) |
3d14c5d2 | 557 | seq_printf(m, ",rsize=%d", fsopt->rsize); |
83817e35 | 558 | if (fsopt->rasize != CEPH_RASIZE_DEFAULT) |
2151937d | 559 | seq_printf(m, ",rasize=%d", fsopt->rasize); |
3d14c5d2 YS |
560 | if (fsopt->congestion_kb != default_congestion_kb()) |
561 | seq_printf(m, ",write_congestion_kb=%d", fsopt->congestion_kb); | |
562 | if (fsopt->caps_wanted_delay_min != CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT) | |
563 | seq_printf(m, ",caps_wanted_delay_min=%d", | |
564 | fsopt->caps_wanted_delay_min); | |
565 | if (fsopt->caps_wanted_delay_max != CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT) | |
566 | seq_printf(m, ",caps_wanted_delay_max=%d", | |
567 | fsopt->caps_wanted_delay_max); | |
3d14c5d2 YS |
568 | if (fsopt->max_readdir != CEPH_MAX_READDIR_DEFAULT) |
569 | seq_printf(m, ",readdir_max_entries=%d", fsopt->max_readdir); | |
570 | if (fsopt->max_readdir_bytes != CEPH_MAX_READDIR_BYTES_DEFAULT) | |
571 | seq_printf(m, ",readdir_max_bytes=%d", fsopt->max_readdir_bytes); | |
572 | if (strcmp(fsopt->snapdir_name, CEPH_SNAPDIRNAME_DEFAULT)) | |
a068acf2 | 573 | seq_show_option(m, "snapdirname", fsopt->snapdir_name); |
ff40f9ae | 574 | |
3d14c5d2 | 575 | return 0; |
16725b9d SW |
576 | } |
577 | ||
578 | /* | |
3d14c5d2 YS |
579 | * handle any mon messages the standard library doesn't understand. |
580 | * return error if we don't either. | |
16725b9d | 581 | */ |
3d14c5d2 | 582 | static int extra_mon_dispatch(struct ceph_client *client, struct ceph_msg *msg) |
16725b9d | 583 | { |
3d14c5d2 YS |
584 | struct ceph_fs_client *fsc = client->private; |
585 | int type = le16_to_cpu(msg->hdr.type); | |
586 | ||
587 | switch (type) { | |
588 | case CEPH_MSG_MDS_MAP: | |
430afbad YZ |
589 | ceph_mdsc_handle_mdsmap(fsc->mdsc, msg); |
590 | return 0; | |
591 | case CEPH_MSG_FS_MAP_USER: | |
592 | ceph_mdsc_handle_fsmap(fsc->mdsc, msg); | |
3d14c5d2 | 593 | return 0; |
3d14c5d2 YS |
594 | default: |
595 | return -1; | |
596 | } | |
597 | } | |
598 | ||
599 | /* | |
600 | * create a new fs client | |
601 | */ | |
0c6d4b4e | 602 | static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt, |
3d14c5d2 YS |
603 | struct ceph_options *opt) |
604 | { | |
605 | struct ceph_fs_client *fsc; | |
3bf53337 AE |
606 | int page_count; |
607 | size_t size; | |
16725b9d SW |
608 | int err = -ENOMEM; |
609 | ||
3d14c5d2 YS |
610 | fsc = kzalloc(sizeof(*fsc), GFP_KERNEL); |
611 | if (!fsc) | |
16725b9d SW |
612 | return ERR_PTR(-ENOMEM); |
613 | ||
74da4a0f | 614 | fsc->client = ceph_create_client(opt, fsc); |
3d14c5d2 YS |
615 | if (IS_ERR(fsc->client)) { |
616 | err = PTR_ERR(fsc->client); | |
617 | goto fail; | |
618 | } | |
c843d13c | 619 | |
3d14c5d2 | 620 | fsc->client->extra_mon_dispatch = extra_mon_dispatch; |
c843d13c | 621 | fsc->client->osdc.abort_on_full = true; |
430afbad | 622 | |
d37b1d99 | 623 | if (!fsopt->mds_namespace) { |
430afbad YZ |
624 | ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_MDSMAP, |
625 | 0, true); | |
626 | } else { | |
627 | ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_FSMAP, | |
628 | 0, false); | |
629 | } | |
16725b9d | 630 | |
3d14c5d2 | 631 | fsc->mount_options = fsopt; |
16725b9d | 632 | |
3d14c5d2 YS |
633 | fsc->sb = NULL; |
634 | fsc->mount_state = CEPH_MOUNT_MOUNTING; | |
16725b9d | 635 | |
3d14c5d2 | 636 | atomic_long_set(&fsc->writeback_count, 0); |
16725b9d SW |
637 | |
638 | err = -ENOMEM; | |
01e6acc4 TH |
639 | /* |
640 | * The number of concurrent works can be high but they don't need | |
641 | * to be processed in parallel, limit concurrency. | |
642 | */ | |
643 | fsc->wb_wq = alloc_workqueue("ceph-writeback", 0, 1); | |
d37b1d99 | 644 | if (!fsc->wb_wq) |
09dc9fc2 | 645 | goto fail_client; |
01e6acc4 | 646 | fsc->pg_inv_wq = alloc_workqueue("ceph-pg-invalid", 0, 1); |
d37b1d99 | 647 | if (!fsc->pg_inv_wq) |
16725b9d | 648 | goto fail_wb_wq; |
01e6acc4 | 649 | fsc->trunc_wq = alloc_workqueue("ceph-trunc", 0, 1); |
d37b1d99 | 650 | if (!fsc->trunc_wq) |
16725b9d SW |
651 | goto fail_pg_inv_wq; |
652 | ||
b9bfb93c SW |
653 | /* set up mempools */ |
654 | err = -ENOMEM; | |
09cbfeaf | 655 | page_count = fsc->mount_options->wsize >> PAGE_SHIFT; |
3bf53337 AE |
656 | size = sizeof (struct page *) * (page_count ? page_count : 1); |
657 | fsc->wb_pagevec_pool = mempool_create_kmalloc_pool(10, size); | |
3d14c5d2 | 658 | if (!fsc->wb_pagevec_pool) |
b9bfb93c SW |
659 | goto fail_trunc_wq; |
660 | ||
85ccce43 | 661 | /* caps */ |
3d14c5d2 YS |
662 | fsc->min_caps = fsopt->max_readdir; |
663 | ||
664 | return fsc; | |
b9bfb93c | 665 | |
16725b9d | 666 | fail_trunc_wq: |
3d14c5d2 | 667 | destroy_workqueue(fsc->trunc_wq); |
16725b9d | 668 | fail_pg_inv_wq: |
3d14c5d2 | 669 | destroy_workqueue(fsc->pg_inv_wq); |
16725b9d | 670 | fail_wb_wq: |
3d14c5d2 | 671 | destroy_workqueue(fsc->wb_wq); |
3d14c5d2 YS |
672 | fail_client: |
673 | ceph_destroy_client(fsc->client); | |
16725b9d | 674 | fail: |
3d14c5d2 | 675 | kfree(fsc); |
16725b9d SW |
676 | return ERR_PTR(err); |
677 | } | |
678 | ||
a57d9064 YZ |
679 | static void flush_fs_workqueues(struct ceph_fs_client *fsc) |
680 | { | |
681 | flush_workqueue(fsc->wb_wq); | |
682 | flush_workqueue(fsc->pg_inv_wq); | |
683 | flush_workqueue(fsc->trunc_wq); | |
684 | } | |
685 | ||
0c6d4b4e | 686 | static void destroy_fs_client(struct ceph_fs_client *fsc) |
16725b9d | 687 | { |
3d14c5d2 | 688 | dout("destroy_fs_client %p\n", fsc); |
16725b9d | 689 | |
3d14c5d2 YS |
690 | destroy_workqueue(fsc->wb_wq); |
691 | destroy_workqueue(fsc->pg_inv_wq); | |
692 | destroy_workqueue(fsc->trunc_wq); | |
16725b9d | 693 | |
3d14c5d2 | 694 | mempool_destroy(fsc->wb_pagevec_pool); |
16725b9d | 695 | |
3d14c5d2 | 696 | destroy_mount_options(fsc->mount_options); |
5dfc589a | 697 | |
3d14c5d2 | 698 | ceph_destroy_client(fsc->client); |
16725b9d | 699 | |
3d14c5d2 YS |
700 | kfree(fsc); |
701 | dout("destroy_fs_client %p done\n", fsc); | |
16725b9d SW |
702 | } |
703 | ||
0743304d | 704 | /* |
3d14c5d2 | 705 | * caches |
0743304d | 706 | */ |
3d14c5d2 YS |
707 | struct kmem_cache *ceph_inode_cachep; |
708 | struct kmem_cache *ceph_cap_cachep; | |
f66fd9f0 | 709 | struct kmem_cache *ceph_cap_flush_cachep; |
3d14c5d2 YS |
710 | struct kmem_cache *ceph_dentry_cachep; |
711 | struct kmem_cache *ceph_file_cachep; | |
bb48bd4d | 712 | struct kmem_cache *ceph_dir_file_cachep; |
3d14c5d2 YS |
713 | |
714 | static void ceph_inode_init_once(void *foo) | |
0743304d | 715 | { |
3d14c5d2 YS |
716 | struct ceph_inode_info *ci = foo; |
717 | inode_init_once(&ci->vfs_inode); | |
718 | } | |
719 | ||
720 | static int __init init_caches(void) | |
721 | { | |
99ccbd22 MT |
722 | int error = -ENOMEM; |
723 | ||
3d14c5d2 YS |
724 | ceph_inode_cachep = kmem_cache_create("ceph_inode_info", |
725 | sizeof(struct ceph_inode_info), | |
726 | __alignof__(struct ceph_inode_info), | |
5d097056 VD |
727 | SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD| |
728 | SLAB_ACCOUNT, ceph_inode_init_once); | |
d37b1d99 | 729 | if (!ceph_inode_cachep) |
3d14c5d2 YS |
730 | return -ENOMEM; |
731 | ||
bc4b5ad3 | 732 | ceph_cap_cachep = KMEM_CACHE(ceph_cap, SLAB_MEM_SPREAD); |
d37b1d99 | 733 | if (!ceph_cap_cachep) |
3d14c5d2 | 734 | goto bad_cap; |
f66fd9f0 YZ |
735 | ceph_cap_flush_cachep = KMEM_CACHE(ceph_cap_flush, |
736 | SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD); | |
d37b1d99 | 737 | if (!ceph_cap_flush_cachep) |
f66fd9f0 | 738 | goto bad_cap_flush; |
3d14c5d2 YS |
739 | |
740 | ceph_dentry_cachep = KMEM_CACHE(ceph_dentry_info, | |
741 | SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD); | |
d37b1d99 | 742 | if (!ceph_dentry_cachep) |
3d14c5d2 YS |
743 | goto bad_dentry; |
744 | ||
6b1a9a6c | 745 | ceph_file_cachep = KMEM_CACHE(ceph_file_info, SLAB_MEM_SPREAD); |
d37b1d99 | 746 | if (!ceph_file_cachep) |
3d14c5d2 YS |
747 | goto bad_file; |
748 | ||
bb48bd4d CX |
749 | ceph_dir_file_cachep = KMEM_CACHE(ceph_dir_file_info, SLAB_MEM_SPREAD); |
750 | if (!ceph_dir_file_cachep) | |
751 | goto bad_dir_file; | |
752 | ||
1c789249 CX |
753 | error = ceph_fscache_register(); |
754 | if (error) | |
755 | goto bad_fscache; | |
3d14c5d2 | 756 | |
99ccbd22 | 757 | return 0; |
1c789249 CX |
758 | |
759 | bad_fscache: | |
bb48bd4d CX |
760 | kmem_cache_destroy(ceph_dir_file_cachep); |
761 | bad_dir_file: | |
1c789249 | 762 | kmem_cache_destroy(ceph_file_cachep); |
3d14c5d2 YS |
763 | bad_file: |
764 | kmem_cache_destroy(ceph_dentry_cachep); | |
765 | bad_dentry: | |
f66fd9f0 YZ |
766 | kmem_cache_destroy(ceph_cap_flush_cachep); |
767 | bad_cap_flush: | |
3d14c5d2 YS |
768 | kmem_cache_destroy(ceph_cap_cachep); |
769 | bad_cap: | |
770 | kmem_cache_destroy(ceph_inode_cachep); | |
99ccbd22 | 771 | return error; |
0743304d SW |
772 | } |
773 | ||
3d14c5d2 YS |
774 | static void destroy_caches(void) |
775 | { | |
8c0a8537 KS |
776 | /* |
777 | * Make sure all delayed rcu free inodes are flushed before we | |
778 | * destroy cache. | |
779 | */ | |
780 | rcu_barrier(); | |
99ccbd22 | 781 | |
3d14c5d2 YS |
782 | kmem_cache_destroy(ceph_inode_cachep); |
783 | kmem_cache_destroy(ceph_cap_cachep); | |
f66fd9f0 | 784 | kmem_cache_destroy(ceph_cap_flush_cachep); |
3d14c5d2 YS |
785 | kmem_cache_destroy(ceph_dentry_cachep); |
786 | kmem_cache_destroy(ceph_file_cachep); | |
bb48bd4d | 787 | kmem_cache_destroy(ceph_dir_file_cachep); |
99ccbd22 MT |
788 | |
789 | ceph_fscache_unregister(); | |
3d14c5d2 YS |
790 | } |
791 | ||
792 | ||
16725b9d | 793 | /* |
3d14c5d2 YS |
794 | * ceph_umount_begin - initiate forced umount. Tear down down the |
795 | * mount, skipping steps that may hang while waiting for server(s). | |
16725b9d | 796 | */ |
3d14c5d2 | 797 | static void ceph_umount_begin(struct super_block *sb) |
16725b9d | 798 | { |
3d14c5d2 YS |
799 | struct ceph_fs_client *fsc = ceph_sb_to_client(sb); |
800 | ||
801 | dout("ceph_umount_begin - starting forced umount\n"); | |
802 | if (!fsc) | |
803 | return; | |
804 | fsc->mount_state = CEPH_MOUNT_SHUTDOWN; | |
12b69d5f | 805 | ceph_osdc_abort_requests(&fsc->client->osdc, -EIO); |
48fec5d0 | 806 | ceph_mdsc_force_umount(fsc->mdsc); |
3d14c5d2 | 807 | return; |
16725b9d SW |
808 | } |
809 | ||
3d14c5d2 YS |
810 | static const struct super_operations ceph_super_ops = { |
811 | .alloc_inode = ceph_alloc_inode, | |
812 | .destroy_inode = ceph_destroy_inode, | |
813 | .write_inode = ceph_write_inode, | |
9f12bd11 | 814 | .drop_inode = ceph_drop_inode, |
3d14c5d2 YS |
815 | .sync_fs = ceph_sync_fs, |
816 | .put_super = ceph_put_super, | |
817 | .show_options = ceph_show_options, | |
818 | .statfs = ceph_statfs, | |
819 | .umount_begin = ceph_umount_begin, | |
820 | }; | |
821 | ||
16725b9d SW |
822 | /* |
823 | * Bootstrap mount by opening the root directory. Note the mount | |
824 | * @started time from caller, and time out if this takes too long. | |
825 | */ | |
3d14c5d2 | 826 | static struct dentry *open_root_dentry(struct ceph_fs_client *fsc, |
16725b9d SW |
827 | const char *path, |
828 | unsigned long started) | |
829 | { | |
3d14c5d2 | 830 | struct ceph_mds_client *mdsc = fsc->mdsc; |
16725b9d SW |
831 | struct ceph_mds_request *req = NULL; |
832 | int err; | |
833 | struct dentry *root; | |
834 | ||
835 | /* open dir */ | |
836 | dout("open_root_inode opening '%s'\n", path); | |
837 | req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_GETATTR, USE_ANY_MDS); | |
838 | if (IS_ERR(req)) | |
7e34bc52 | 839 | return ERR_CAST(req); |
16725b9d | 840 | req->r_path1 = kstrdup(path, GFP_NOFS); |
a149bb9a SK |
841 | if (!req->r_path1) { |
842 | root = ERR_PTR(-ENOMEM); | |
843 | goto out; | |
844 | } | |
845 | ||
16725b9d SW |
846 | req->r_ino1.ino = CEPH_INO_ROOT; |
847 | req->r_ino1.snap = CEPH_NOSNAP; | |
848 | req->r_started = started; | |
a319bf56 | 849 | req->r_timeout = fsc->client->options->mount_timeout; |
16725b9d SW |
850 | req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INODE); |
851 | req->r_num_caps = 2; | |
852 | err = ceph_mdsc_do_request(mdsc, NULL, req); | |
853 | if (err == 0) { | |
3c5184ef AV |
854 | struct inode *inode = req->r_target_inode; |
855 | req->r_target_inode = NULL; | |
16725b9d | 856 | dout("open_root_inode success\n"); |
ce2728aa YZ |
857 | root = d_make_root(inode); |
858 | if (!root) { | |
859 | root = ERR_PTR(-ENOMEM); | |
860 | goto out; | |
774ac21d | 861 | } |
16725b9d SW |
862 | dout("open_root_inode success, root dentry is %p\n", root); |
863 | } else { | |
864 | root = ERR_PTR(err); | |
865 | } | |
3c5184ef | 866 | out: |
16725b9d SW |
867 | ceph_mdsc_put_request(req); |
868 | return root; | |
869 | } | |
870 | ||
3d14c5d2 YS |
871 | |
872 | ||
873 | ||
16725b9d SW |
874 | /* |
875 | * mount: join the ceph cluster, and open root directory. | |
876 | */ | |
3f384954 | 877 | static struct dentry *ceph_real_mount(struct ceph_fs_client *fsc) |
16725b9d | 878 | { |
16725b9d | 879 | int err; |
16725b9d SW |
880 | unsigned long started = jiffies; /* note the start time */ |
881 | struct dentry *root; | |
882 | ||
132ca7e1 | 883 | dout("mount start %p\n", fsc); |
3d14c5d2 | 884 | mutex_lock(&fsc->client->mount_mutex); |
16725b9d | 885 | |
132ca7e1 | 886 | if (!fsc->sb->s_root) { |
ce2728aa | 887 | const char *path; |
132ca7e1 YZ |
888 | err = __ceph_open_session(fsc->client, started); |
889 | if (err < 0) | |
890 | goto out; | |
16725b9d | 891 | |
1d8f8360 YZ |
892 | /* setup fscache */ |
893 | if (fsc->mount_options->flags & CEPH_MOUNT_OPT_FSCACHE) { | |
894 | err = ceph_fscache_register_fs(fsc); | |
895 | if (err < 0) | |
896 | goto out; | |
897 | } | |
898 | ||
ce2728aa YZ |
899 | if (!fsc->mount_options->server_path) { |
900 | path = ""; | |
901 | dout("mount opening path \\t\n"); | |
902 | } else { | |
903 | path = fsc->mount_options->server_path + 1; | |
904 | dout("mount opening path %s\n", path); | |
905 | } | |
18106734 CX |
906 | |
907 | err = ceph_fs_debugfs_init(fsc); | |
908 | if (err < 0) | |
909 | goto out; | |
910 | ||
ce2728aa | 911 | root = open_root_dentry(fsc, path, started); |
132ca7e1 YZ |
912 | if (IS_ERR(root)) { |
913 | err = PTR_ERR(root); | |
914 | goto out; | |
915 | } | |
ce2728aa | 916 | fsc->sb->s_root = dget(root); |
31ca5878 GU |
917 | } else { |
918 | root = dget(fsc->sb->s_root); | |
3d14c5d2 | 919 | } |
16725b9d | 920 | |
3d14c5d2 | 921 | fsc->mount_state = CEPH_MOUNT_MOUNTED; |
16725b9d | 922 | dout("mount success\n"); |
a7f9fb20 AV |
923 | mutex_unlock(&fsc->client->mount_mutex); |
924 | return root; | |
16725b9d | 925 | |
132ca7e1 YZ |
926 | out: |
927 | mutex_unlock(&fsc->client->mount_mutex); | |
928 | return ERR_PTR(err); | |
16725b9d SW |
929 | } |
930 | ||
931 | static int ceph_set_super(struct super_block *s, void *data) | |
932 | { | |
3d14c5d2 | 933 | struct ceph_fs_client *fsc = data; |
16725b9d SW |
934 | int ret; |
935 | ||
936 | dout("set_super %p data %p\n", s, data); | |
937 | ||
3d14c5d2 | 938 | s->s_flags = fsc->mount_options->sb_flags; |
16725b9d SW |
939 | s->s_maxbytes = 1ULL << 40; /* temp value until we get mdsmap */ |
940 | ||
7221fe4c | 941 | s->s_xattr = ceph_xattr_handlers; |
3d14c5d2 YS |
942 | s->s_fs_info = fsc; |
943 | fsc->sb = s; | |
16725b9d SW |
944 | |
945 | s->s_op = &ceph_super_ops; | |
18fc8abd | 946 | s->s_d_op = &ceph_dentry_ops; |
16725b9d SW |
947 | s->s_export_op = &ceph_export_ops; |
948 | ||
949 | s->s_time_gran = 1000; /* 1000 ns == 1 us */ | |
950 | ||
951 | ret = set_anon_super(s, NULL); /* what is that second arg for? */ | |
952 | if (ret != 0) | |
953 | goto fail; | |
954 | ||
955 | return ret; | |
956 | ||
957 | fail: | |
958 | s->s_fs_info = NULL; | |
3d14c5d2 | 959 | fsc->sb = NULL; |
16725b9d SW |
960 | return ret; |
961 | } | |
962 | ||
963 | /* | |
964 | * share superblock if same fs AND options | |
965 | */ | |
966 | static int ceph_compare_super(struct super_block *sb, void *data) | |
967 | { | |
3d14c5d2 YS |
968 | struct ceph_fs_client *new = data; |
969 | struct ceph_mount_options *fsopt = new->mount_options; | |
970 | struct ceph_options *opt = new->client->options; | |
971 | struct ceph_fs_client *other = ceph_sb_to_client(sb); | |
16725b9d SW |
972 | |
973 | dout("ceph_compare_super %p\n", sb); | |
3d14c5d2 YS |
974 | |
975 | if (compare_mount_options(fsopt, opt, other)) { | |
976 | dout("monitor(s)/mount options don't match\n"); | |
977 | return 0; | |
16725b9d | 978 | } |
3d14c5d2 YS |
979 | if ((opt->flags & CEPH_OPT_FSID) && |
980 | ceph_fsid_compare(&opt->fsid, &other->client->fsid)) { | |
981 | dout("fsid doesn't match\n"); | |
982 | return 0; | |
983 | } | |
984 | if (fsopt->sb_flags != other->mount_options->sb_flags) { | |
16725b9d SW |
985 | dout("flags differ\n"); |
986 | return 0; | |
987 | } | |
988 | return 1; | |
989 | } | |
990 | ||
991 | /* | |
992 | * construct our own bdi so we can control readahead, etc. | |
993 | */ | |
00d5643e | 994 | static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0); |
31e0cf8f | 995 | |
09dc9fc2 | 996 | static int ceph_setup_bdi(struct super_block *sb, struct ceph_fs_client *fsc) |
16725b9d SW |
997 | { |
998 | int err; | |
999 | ||
09dc9fc2 JK |
1000 | err = super_setup_bdi_name(sb, "ceph-%ld", |
1001 | atomic_long_inc_return(&bdi_seq)); | |
1002 | if (err) | |
1003 | return err; | |
1004 | ||
83817e35 | 1005 | /* set ra_pages based on rasize mount option? */ |
4214fb15 | 1006 | sb->s_bdi->ra_pages = fsc->mount_options->rasize >> PAGE_SHIFT; |
e9852227 | 1007 | |
aa187926 YZ |
1008 | /* set io_pages based on max osd read size */ |
1009 | sb->s_bdi->io_pages = fsc->mount_options->rsize >> PAGE_SHIFT; | |
7c94ba27 | 1010 | |
09dc9fc2 | 1011 | return 0; |
16725b9d SW |
1012 | } |
1013 | ||
a7f9fb20 AV |
1014 | static struct dentry *ceph_mount(struct file_system_type *fs_type, |
1015 | int flags, const char *dev_name, void *data) | |
16725b9d SW |
1016 | { |
1017 | struct super_block *sb; | |
3d14c5d2 | 1018 | struct ceph_fs_client *fsc; |
a7f9fb20 | 1019 | struct dentry *res; |
16725b9d SW |
1020 | int err; |
1021 | int (*compare_super)(struct super_block *, void *) = ceph_compare_super; | |
3d14c5d2 YS |
1022 | struct ceph_mount_options *fsopt = NULL; |
1023 | struct ceph_options *opt = NULL; | |
16725b9d | 1024 | |
a7f9fb20 | 1025 | dout("ceph_mount\n"); |
45195e42 SW |
1026 | |
1027 | #ifdef CONFIG_CEPH_FS_POSIX_ACL | |
1751e8a6 | 1028 | flags |= SB_POSIXACL; |
45195e42 | 1029 | #endif |
3f384954 | 1030 | err = parse_mount_options(&fsopt, &opt, flags, data, dev_name); |
a7f9fb20 AV |
1031 | if (err < 0) { |
1032 | res = ERR_PTR(err); | |
6b805185 | 1033 | goto out_final; |
a7f9fb20 | 1034 | } |
16725b9d SW |
1035 | |
1036 | /* create client (which we may/may not use) */ | |
3d14c5d2 YS |
1037 | fsc = create_fs_client(fsopt, opt); |
1038 | if (IS_ERR(fsc)) { | |
a7f9fb20 | 1039 | res = ERR_CAST(fsc); |
259a187a NW |
1040 | destroy_mount_options(fsopt); |
1041 | ceph_destroy_options(opt); | |
6b805185 SW |
1042 | goto out_final; |
1043 | } | |
16725b9d | 1044 | |
3d14c5d2 | 1045 | err = ceph_mdsc_init(fsc); |
a7f9fb20 AV |
1046 | if (err < 0) { |
1047 | res = ERR_PTR(err); | |
3d14c5d2 | 1048 | goto out; |
a7f9fb20 | 1049 | } |
3d14c5d2 YS |
1050 | |
1051 | if (ceph_test_opt(fsc->client, NOSHARE)) | |
16725b9d | 1052 | compare_super = NULL; |
9249e17f | 1053 | sb = sget(fs_type, compare_super, ceph_set_super, flags, fsc); |
16725b9d | 1054 | if (IS_ERR(sb)) { |
a7f9fb20 | 1055 | res = ERR_CAST(sb); |
16725b9d SW |
1056 | goto out; |
1057 | } | |
1058 | ||
3d14c5d2 YS |
1059 | if (ceph_sb_to_client(sb) != fsc) { |
1060 | ceph_mdsc_destroy(fsc); | |
1061 | destroy_fs_client(fsc); | |
1062 | fsc = ceph_sb_to_client(sb); | |
1063 | dout("get_sb got existing client %p\n", fsc); | |
16725b9d | 1064 | } else { |
3d14c5d2 | 1065 | dout("get_sb using new client %p\n", fsc); |
09dc9fc2 | 1066 | err = ceph_setup_bdi(sb, fsc); |
a7f9fb20 AV |
1067 | if (err < 0) { |
1068 | res = ERR_PTR(err); | |
16725b9d | 1069 | goto out_splat; |
a7f9fb20 | 1070 | } |
16725b9d SW |
1071 | } |
1072 | ||
3f384954 | 1073 | res = ceph_real_mount(fsc); |
a7f9fb20 | 1074 | if (IS_ERR(res)) |
16725b9d | 1075 | goto out_splat; |
a7f9fb20 | 1076 | dout("root %p inode %p ino %llx.%llx\n", res, |
2b0143b5 | 1077 | d_inode(res), ceph_vinop(d_inode(res))); |
a7f9fb20 | 1078 | return res; |
16725b9d SW |
1079 | |
1080 | out_splat: | |
3d14c5d2 | 1081 | ceph_mdsc_close_sessions(fsc->mdsc); |
3981f2e2 | 1082 | deactivate_locked_super(sb); |
16725b9d SW |
1083 | goto out_final; |
1084 | ||
1085 | out: | |
3d14c5d2 YS |
1086 | ceph_mdsc_destroy(fsc); |
1087 | destroy_fs_client(fsc); | |
16725b9d | 1088 | out_final: |
a7f9fb20 AV |
1089 | dout("ceph_mount fail %ld\n", PTR_ERR(res)); |
1090 | return res; | |
16725b9d SW |
1091 | } |
1092 | ||
1093 | static void ceph_kill_sb(struct super_block *s) | |
1094 | { | |
3d14c5d2 | 1095 | struct ceph_fs_client *fsc = ceph_sb_to_client(s); |
e4d27509 CH |
1096 | dev_t dev = s->s_dev; |
1097 | ||
16725b9d | 1098 | dout("kill_sb %p\n", s); |
e4d27509 | 1099 | |
3d14c5d2 | 1100 | ceph_mdsc_pre_umount(fsc->mdsc); |
a57d9064 YZ |
1101 | flush_fs_workqueues(fsc); |
1102 | ||
e4d27509 | 1103 | generic_shutdown_super(s); |
62a65f36 YZ |
1104 | |
1105 | fsc->client->extra_mon_dispatch = NULL; | |
1106 | ceph_fs_debugfs_cleanup(fsc); | |
1107 | ||
1d8f8360 YZ |
1108 | ceph_fscache_unregister_fs(fsc); |
1109 | ||
3d14c5d2 | 1110 | ceph_mdsc_destroy(fsc); |
e4d27509 | 1111 | |
3d14c5d2 | 1112 | destroy_fs_client(fsc); |
e4d27509 | 1113 | free_anon_bdev(dev); |
16725b9d SW |
1114 | } |
1115 | ||
1116 | static struct file_system_type ceph_fs_type = { | |
1117 | .owner = THIS_MODULE, | |
1118 | .name = "ceph", | |
a7f9fb20 | 1119 | .mount = ceph_mount, |
16725b9d SW |
1120 | .kill_sb = ceph_kill_sb, |
1121 | .fs_flags = FS_RENAME_DOES_D_MOVE, | |
1122 | }; | |
7f78e035 | 1123 | MODULE_ALIAS_FS("ceph"); |
16725b9d | 1124 | |
16725b9d SW |
1125 | static int __init init_ceph(void) |
1126 | { | |
3d14c5d2 | 1127 | int ret = init_caches(); |
16725b9d | 1128 | if (ret) |
3d14c5d2 | 1129 | goto out; |
16725b9d | 1130 | |
eb13e832 | 1131 | ceph_flock_init(); |
3ce6cd12 | 1132 | ceph_xattr_init(); |
16725b9d SW |
1133 | ret = register_filesystem(&ceph_fs_type); |
1134 | if (ret) | |
34b759b4 | 1135 | goto out_xattr; |
16725b9d | 1136 | |
3d14c5d2 YS |
1137 | pr_info("loaded (mds proto %d)\n", CEPH_MDSC_PROTOCOL); |
1138 | ||
16725b9d SW |
1139 | return 0; |
1140 | ||
97c85a82 | 1141 | out_xattr: |
3ce6cd12 | 1142 | ceph_xattr_exit(); |
16725b9d | 1143 | destroy_caches(); |
16725b9d SW |
1144 | out: |
1145 | return ret; | |
1146 | } | |
1147 | ||
1148 | static void __exit exit_ceph(void) | |
1149 | { | |
1150 | dout("exit_ceph\n"); | |
1151 | unregister_filesystem(&ceph_fs_type); | |
3ce6cd12 | 1152 | ceph_xattr_exit(); |
16725b9d | 1153 | destroy_caches(); |
16725b9d SW |
1154 | } |
1155 | ||
1156 | module_init(init_ceph); | |
1157 | module_exit(exit_ceph); | |
1158 | ||
1159 | MODULE_AUTHOR("Sage Weil <[email protected]>"); | |
1160 | MODULE_AUTHOR("Yehuda Sadeh <[email protected]>"); | |
1161 | MODULE_AUTHOR("Patience Warnick <[email protected]>"); | |
1162 | MODULE_DESCRIPTION("Ceph filesystem for Linux"); | |
1163 | MODULE_LICENSE("GPL"); |