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