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