blob: c1ea38e5aebdf03d40e4e48f2b3b6684f4e13739 [file] [log] [blame]
Sage Weil16725b92009-10-06 11:31:07 -07001
2#include "ceph_debug.h"
3
4#include <linux/backing-dev.h>
5#include <linux/fs.h>
6#include <linux/inet.h>
7#include <linux/in6.h>
8#include <linux/module.h>
9#include <linux/mount.h>
10#include <linux/parser.h>
Sage Weil16725b92009-10-06 11:31:07 -070011#include <linux/sched.h>
12#include <linux/seq_file.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Sage Weil16725b92009-10-06 11:31:07 -070014#include <linux/statfs.h>
15#include <linux/string.h>
Sage Weil16725b92009-10-06 11:31:07 -070016
Sage Weil16725b92009-10-06 11:31:07 -070017#include "decode.h"
18#include "super.h"
19#include "mon_client.h"
Sage Weil07433042009-11-18 16:50:41 -080020#include "auth.h"
Sage Weil16725b92009-10-06 11:31:07 -070021
22/*
23 * Ceph superblock operations
24 *
25 * Handle the basics of mounting, unmounting.
26 */
27
28
29/*
30 * find filename portion of a path (/foo/bar/baz -> baz)
31 */
32const char *ceph_file_part(const char *s, int len)
33{
34 const char *e = s + len;
35
36 while (e != s && *(e-1) != '/')
37 e--;
38 return e;
39}
40
41
42/*
43 * super ops
44 */
45static void ceph_put_super(struct super_block *s)
46{
Sage Weil5dfc5892010-05-04 16:14:46 -070047 struct ceph_client *client = ceph_sb_to_client(s);
Sage Weil16725b92009-10-06 11:31:07 -070048
49 dout("put_super\n");
Sage Weil5dfc5892010-05-04 16:14:46 -070050 ceph_mdsc_close_sessions(&client->mdsc);
51
52 /*
53 * ensure we release the bdi before put_anon_super releases
54 * the device name.
55 */
56 if (s->s_bdi == &client->backing_dev_info) {
57 bdi_unregister(&client->backing_dev_info);
58 s->s_bdi = NULL;
59 }
60
Sage Weil16725b92009-10-06 11:31:07 -070061 return;
62}
63
64static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf)
65{
66 struct ceph_client *client = ceph_inode_to_client(dentry->d_inode);
67 struct ceph_monmap *monmap = client->monc.monmap;
68 struct ceph_statfs st;
69 u64 fsid;
70 int err;
71
72 dout("statfs\n");
73 err = ceph_monc_do_statfs(&client->monc, &st);
74 if (err < 0)
75 return err;
76
77 /* fill in kstatfs */
78 buf->f_type = CEPH_SUPER_MAGIC; /* ?? */
79
80 /*
81 * express utilization in terms of large blocks to avoid
82 * overflow on 32-bit machines.
83 */
84 buf->f_bsize = 1 << CEPH_BLOCK_SHIFT;
85 buf->f_blocks = le64_to_cpu(st.kb) >> (CEPH_BLOCK_SHIFT-10);
86 buf->f_bfree = (le64_to_cpu(st.kb) - le64_to_cpu(st.kb_used)) >>
87 (CEPH_BLOCK_SHIFT-10);
88 buf->f_bavail = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);
89
90 buf->f_files = le64_to_cpu(st.num_objects);
91 buf->f_ffree = -1;
Sage Weil558d3492010-06-01 12:51:12 -070092 buf->f_namelen = NAME_MAX;
Sage Weil16725b92009-10-06 11:31:07 -070093 buf->f_frsize = PAGE_CACHE_SIZE;
94
95 /* leave fsid little-endian, regardless of host endianness */
96 fsid = *(u64 *)(&monmap->fsid) ^ *((u64 *)&monmap->fsid + 1);
97 buf->f_fsid.val[0] = fsid & 0xffffffff;
98 buf->f_fsid.val[1] = fsid >> 32;
99
100 return 0;
101}
102
103
104static int ceph_syncfs(struct super_block *sb, int wait)
105{
106 dout("sync_fs %d\n", wait);
Cheng Renquan640ef792010-03-26 17:40:33 +0800107 ceph_osdc_sync(&ceph_sb_to_client(sb)->osdc);
108 ceph_mdsc_sync(&ceph_sb_to_client(sb)->mdsc);
Sage Weilf2cf4182009-10-14 14:09:07 -0700109 dout("sync_fs %d done\n", wait);
Sage Weil16725b92009-10-06 11:31:07 -0700110 return 0;
111}
112
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800113static int default_congestion_kb(void)
114{
115 int congestion_kb;
116
117 /*
118 * Copied from NFS
119 *
120 * congestion size, scale with available memory.
121 *
122 * 64MB: 8192k
123 * 128MB: 11585k
124 * 256MB: 16384k
125 * 512MB: 23170k
126 * 1GB: 32768k
127 * 2GB: 46340k
128 * 4GB: 65536k
129 * 8GB: 92681k
130 * 16GB: 131072k
131 *
132 * This allows larger machines to have larger/more transfers.
133 * Limit the default to 256M
134 */
135 congestion_kb = (16*int_sqrt(totalram_pages)) << (PAGE_SHIFT-10);
136 if (congestion_kb > 256*1024)
137 congestion_kb = 256*1024;
138
139 return congestion_kb;
140}
141
Sage Weil6e19a162010-04-29 16:38:32 -0700142/**
143 * ceph_show_options - Show mount options in /proc/mounts
144 * @m: seq_file to write to
145 * @mnt: mount descriptor
146 */
147static int ceph_show_options(struct seq_file *m, struct vfsmount *mnt)
148{
149 struct ceph_client *client = ceph_sb_to_client(mnt->mnt_sb);
150 struct ceph_mount_args *args = client->mount_args;
151
152 if (args->flags & CEPH_OPT_FSID)
153 seq_printf(m, ",fsidmajor=%llu,fsidminor%llu",
154 le64_to_cpu(*(__le64 *)&args->fsid.fsid[0]),
155 le64_to_cpu(*(__le64 *)&args->fsid.fsid[8]));
156 if (args->flags & CEPH_OPT_NOSHARE)
157 seq_puts(m, ",noshare");
158 if (args->flags & CEPH_OPT_DIRSTAT)
159 seq_puts(m, ",dirstat");
160 if ((args->flags & CEPH_OPT_RBYTES) == 0)
161 seq_puts(m, ",norbytes");
162 if (args->flags & CEPH_OPT_NOCRC)
163 seq_puts(m, ",nocrc");
164 if (args->flags & CEPH_OPT_NOASYNCREADDIR)
165 seq_puts(m, ",noasyncreaddir");
166
167 if (args->mount_timeout != CEPH_MOUNT_TIMEOUT_DEFAULT)
168 seq_printf(m, ",mount_timeout=%d", args->mount_timeout);
169 if (args->osd_idle_ttl != CEPH_OSD_IDLE_TTL_DEFAULT)
170 seq_printf(m, ",osd_idle_ttl=%d", args->osd_idle_ttl);
171 if (args->osd_timeout != CEPH_OSD_TIMEOUT_DEFAULT)
172 seq_printf(m, ",osdtimeout=%d", args->osd_timeout);
173 if (args->osd_keepalive_timeout != CEPH_OSD_KEEPALIVE_DEFAULT)
174 seq_printf(m, ",osdkeepalivetimeout=%d",
175 args->osd_keepalive_timeout);
176 if (args->wsize)
177 seq_printf(m, ",wsize=%d", args->wsize);
178 if (args->rsize != CEPH_MOUNT_RSIZE_DEFAULT)
179 seq_printf(m, ",rsize=%d", args->rsize);
180 if (args->congestion_kb != default_congestion_kb())
181 seq_printf(m, ",write_congestion_kb=%d", args->congestion_kb);
182 if (args->caps_wanted_delay_min != CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT)
183 seq_printf(m, ",caps_wanted_delay_min=%d",
184 args->caps_wanted_delay_min);
185 if (args->caps_wanted_delay_max != CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT)
186 seq_printf(m, ",caps_wanted_delay_max=%d",
187 args->caps_wanted_delay_max);
188 if (args->cap_release_safety != CEPH_CAP_RELEASE_SAFETY_DEFAULT)
189 seq_printf(m, ",cap_release_safety=%d",
190 args->cap_release_safety);
191 if (args->max_readdir != CEPH_MAX_READDIR_DEFAULT)
192 seq_printf(m, ",readdir_max_entries=%d", args->max_readdir);
Sage Weil23804d92010-05-14 13:06:30 -0700193 if (args->max_readdir_bytes != CEPH_MAX_READDIR_BYTES_DEFAULT)
194 seq_printf(m, ",readdir_max_bytes=%d", args->max_readdir_bytes);
Sage Weil6e19a162010-04-29 16:38:32 -0700195 if (strcmp(args->snapdir_name, CEPH_SNAPDIRNAME_DEFAULT))
196 seq_printf(m, ",snapdirname=%s", args->snapdir_name);
197 if (args->name)
198 seq_printf(m, ",name=%s", args->name);
199 if (args->secret)
200 seq_puts(m, ",secret=<hidden>");
201 return 0;
202}
203
204/*
205 * caches
206 */
207struct kmem_cache *ceph_inode_cachep;
208struct kmem_cache *ceph_cap_cachep;
209struct kmem_cache *ceph_dentry_cachep;
210struct kmem_cache *ceph_file_cachep;
211
212static void ceph_inode_init_once(void *foo)
213{
214 struct ceph_inode_info *ci = foo;
215 inode_init_once(&ci->vfs_inode);
216}
217
Sage Weil16725b92009-10-06 11:31:07 -0700218static int __init init_caches(void)
219{
220 ceph_inode_cachep = kmem_cache_create("ceph_inode_info",
221 sizeof(struct ceph_inode_info),
222 __alignof__(struct ceph_inode_info),
223 (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
224 ceph_inode_init_once);
225 if (ceph_inode_cachep == NULL)
226 return -ENOMEM;
227
228 ceph_cap_cachep = KMEM_CACHE(ceph_cap,
229 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
230 if (ceph_cap_cachep == NULL)
231 goto bad_cap;
232
233 ceph_dentry_cachep = KMEM_CACHE(ceph_dentry_info,
234 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
235 if (ceph_dentry_cachep == NULL)
236 goto bad_dentry;
237
238 ceph_file_cachep = KMEM_CACHE(ceph_file_info,
239 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
240 if (ceph_file_cachep == NULL)
241 goto bad_file;
242
243 return 0;
244
245bad_file:
246 kmem_cache_destroy(ceph_dentry_cachep);
247bad_dentry:
248 kmem_cache_destroy(ceph_cap_cachep);
249bad_cap:
250 kmem_cache_destroy(ceph_inode_cachep);
251 return -ENOMEM;
252}
253
254static void destroy_caches(void)
255{
256 kmem_cache_destroy(ceph_inode_cachep);
257 kmem_cache_destroy(ceph_cap_cachep);
258 kmem_cache_destroy(ceph_dentry_cachep);
259 kmem_cache_destroy(ceph_file_cachep);
260}
261
262
263/*
264 * ceph_umount_begin - initiate forced umount. Tear down down the
265 * mount, skipping steps that may hang while waiting for server(s).
266 */
267static void ceph_umount_begin(struct super_block *sb)
268{
269 struct ceph_client *client = ceph_sb_to_client(sb);
270
271 dout("ceph_umount_begin - starting forced umount\n");
272 if (!client)
273 return;
274 client->mount_state = CEPH_MOUNT_SHUTDOWN;
275 return;
276}
277
278static const struct super_operations ceph_super_ops = {
279 .alloc_inode = ceph_alloc_inode,
280 .destroy_inode = ceph_destroy_inode,
281 .write_inode = ceph_write_inode,
282 .sync_fs = ceph_syncfs,
283 .put_super = ceph_put_super,
284 .show_options = ceph_show_options,
285 .statfs = ceph_statfs,
286 .umount_begin = ceph_umount_begin,
287};
288
289
290const char *ceph_msg_type_name(int type)
291{
292 switch (type) {
293 case CEPH_MSG_SHUTDOWN: return "shutdown";
294 case CEPH_MSG_PING: return "ping";
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800295 case CEPH_MSG_AUTH: return "auth";
296 case CEPH_MSG_AUTH_REPLY: return "auth_reply";
Sage Weil16725b92009-10-06 11:31:07 -0700297 case CEPH_MSG_MON_MAP: return "mon_map";
298 case CEPH_MSG_MON_GET_MAP: return "mon_get_map";
299 case CEPH_MSG_MON_SUBSCRIBE: return "mon_subscribe";
300 case CEPH_MSG_MON_SUBSCRIBE_ACK: return "mon_subscribe_ack";
Sage Weil16725b92009-10-06 11:31:07 -0700301 case CEPH_MSG_STATFS: return "statfs";
302 case CEPH_MSG_STATFS_REPLY: return "statfs_reply";
Sage Weil16725b92009-10-06 11:31:07 -0700303 case CEPH_MSG_MDS_MAP: return "mds_map";
304 case CEPH_MSG_CLIENT_SESSION: return "client_session";
305 case CEPH_MSG_CLIENT_RECONNECT: return "client_reconnect";
306 case CEPH_MSG_CLIENT_REQUEST: return "client_request";
307 case CEPH_MSG_CLIENT_REQUEST_FORWARD: return "client_request_forward";
308 case CEPH_MSG_CLIENT_REPLY: return "client_reply";
309 case CEPH_MSG_CLIENT_CAPS: return "client_caps";
310 case CEPH_MSG_CLIENT_CAPRELEASE: return "client_cap_release";
311 case CEPH_MSG_CLIENT_SNAP: return "client_snap";
312 case CEPH_MSG_CLIENT_LEASE: return "client_lease";
Sage Weil16725b92009-10-06 11:31:07 -0700313 case CEPH_MSG_OSD_MAP: return "osd_map";
314 case CEPH_MSG_OSD_OP: return "osd_op";
315 case CEPH_MSG_OSD_OPREPLY: return "osd_opreply";
316 default: return "unknown";
317 }
318}
319
320
321/*
322 * mount options
323 */
324enum {
325 Opt_fsidmajor,
326 Opt_fsidminor,
Sage Weil16725b92009-10-06 11:31:07 -0700327 Opt_wsize,
328 Opt_rsize,
329 Opt_osdtimeout,
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -0800330 Opt_osdkeepalivetimeout,
Sage Weil16725b92009-10-06 11:31:07 -0700331 Opt_mount_timeout,
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800332 Opt_osd_idle_ttl,
Sage Weil16725b92009-10-06 11:31:07 -0700333 Opt_caps_wanted_delay_min,
334 Opt_caps_wanted_delay_max,
Sage Weil6e19a162010-04-29 16:38:32 -0700335 Opt_cap_release_safety,
Sage Weil16725b92009-10-06 11:31:07 -0700336 Opt_readdir_max_entries,
Sage Weil23804d92010-05-14 13:06:30 -0700337 Opt_readdir_max_bytes,
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800338 Opt_congestion_kb,
Sage Weile53c2fe2009-10-27 10:19:28 -0700339 Opt_last_int,
Sage Weil16725b92009-10-06 11:31:07 -0700340 /* int args above */
341 Opt_snapdirname,
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800342 Opt_name,
Sage Weil16725b92009-10-06 11:31:07 -0700343 Opt_secret,
Sage Weile53c2fe2009-10-27 10:19:28 -0700344 Opt_last_string,
Sage Weil16725b92009-10-06 11:31:07 -0700345 /* string args above */
346 Opt_ip,
347 Opt_noshare,
348 Opt_dirstat,
349 Opt_nodirstat,
350 Opt_rbytes,
351 Opt_norbytes,
352 Opt_nocrc,
353 Opt_noasyncreaddir,
354};
355
356static match_table_t arg_tokens = {
357 {Opt_fsidmajor, "fsidmajor=%ld"},
358 {Opt_fsidminor, "fsidminor=%ld"},
Sage Weil16725b92009-10-06 11:31:07 -0700359 {Opt_wsize, "wsize=%d"},
360 {Opt_rsize, "rsize=%d"},
361 {Opt_osdtimeout, "osdtimeout=%d"},
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -0800362 {Opt_osdkeepalivetimeout, "osdkeepalive=%d"},
Sage Weil16725b92009-10-06 11:31:07 -0700363 {Opt_mount_timeout, "mount_timeout=%d"},
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800364 {Opt_osd_idle_ttl, "osd_idle_ttl=%d"},
Sage Weil16725b92009-10-06 11:31:07 -0700365 {Opt_caps_wanted_delay_min, "caps_wanted_delay_min=%d"},
366 {Opt_caps_wanted_delay_max, "caps_wanted_delay_max=%d"},
Sage Weil6e19a162010-04-29 16:38:32 -0700367 {Opt_cap_release_safety, "cap_release_safety=%d"},
Sage Weil16725b92009-10-06 11:31:07 -0700368 {Opt_readdir_max_entries, "readdir_max_entries=%d"},
Sage Weil23804d92010-05-14 13:06:30 -0700369 {Opt_readdir_max_bytes, "readdir_max_bytes=%d"},
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800370 {Opt_congestion_kb, "write_congestion_kb=%d"},
Sage Weil16725b92009-10-06 11:31:07 -0700371 /* int args above */
372 {Opt_snapdirname, "snapdirname=%s"},
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800373 {Opt_name, "name=%s"},
Sage Weil16725b92009-10-06 11:31:07 -0700374 {Opt_secret, "secret=%s"},
375 /* string args above */
376 {Opt_ip, "ip=%s"},
377 {Opt_noshare, "noshare"},
378 {Opt_dirstat, "dirstat"},
379 {Opt_nodirstat, "nodirstat"},
380 {Opt_rbytes, "rbytes"},
381 {Opt_norbytes, "norbytes"},
382 {Opt_nocrc, "nocrc"},
383 {Opt_noasyncreaddir, "noasyncreaddir"},
384 {-1, NULL}
385};
386
387
Sage Weil6b805182009-10-27 11:50:50 -0700388static struct ceph_mount_args *parse_mount_args(int flags, char *options,
389 const char *dev_name,
390 const char **path)
Sage Weil16725b92009-10-06 11:31:07 -0700391{
Sage Weil6b805182009-10-27 11:50:50 -0700392 struct ceph_mount_args *args;
Sage Weil16725b92009-10-06 11:31:07 -0700393 const char *c;
Sage Weil6b805182009-10-27 11:50:50 -0700394 int err = -ENOMEM;
Sage Weil16725b92009-10-06 11:31:07 -0700395 substring_t argstr[MAX_OPT_ARGS];
Sage Weil16725b92009-10-06 11:31:07 -0700396
Sage Weil6b805182009-10-27 11:50:50 -0700397 args = kzalloc(sizeof(*args), GFP_KERNEL);
398 if (!args)
399 return ERR_PTR(-ENOMEM);
400 args->mon_addr = kcalloc(CEPH_MAX_MON, sizeof(*args->mon_addr),
401 GFP_KERNEL);
402 if (!args->mon_addr)
403 goto out;
Sage Weil16725b92009-10-06 11:31:07 -0700404
Sage Weil6b805182009-10-27 11:50:50 -0700405 dout("parse_mount_args %p, dev_name '%s'\n", args, dev_name);
Sage Weil7b813c462009-10-26 22:07:53 -0700406
Sage Weil16725b92009-10-06 11:31:07 -0700407 /* start with defaults */
408 args->sb_flags = flags;
409 args->flags = CEPH_OPT_DEFAULT;
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -0800410 args->osd_timeout = CEPH_OSD_TIMEOUT_DEFAULT;
411 args->osd_keepalive_timeout = CEPH_OSD_KEEPALIVE_DEFAULT;
Sage Weil16725b92009-10-06 11:31:07 -0700412 args->mount_timeout = CEPH_MOUNT_TIMEOUT_DEFAULT; /* seconds */
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800413 args->osd_idle_ttl = CEPH_OSD_IDLE_TTL_DEFAULT; /* seconds */
Sage Weil16725b92009-10-06 11:31:07 -0700414 args->caps_wanted_delay_min = CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT;
415 args->caps_wanted_delay_max = CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT;
Sage Weil8fa97652009-10-16 14:44:35 -0700416 args->rsize = CEPH_MOUNT_RSIZE_DEFAULT;
Sage Weil16725b92009-10-06 11:31:07 -0700417 args->snapdir_name = kstrdup(CEPH_SNAPDIRNAME_DEFAULT, GFP_KERNEL);
Sage Weil6e19a162010-04-29 16:38:32 -0700418 args->cap_release_safety = CEPH_CAP_RELEASE_SAFETY_DEFAULT;
419 args->max_readdir = CEPH_MAX_READDIR_DEFAULT;
Sage Weil23804d92010-05-14 13:06:30 -0700420 args->max_readdir_bytes = CEPH_MAX_READDIR_BYTES_DEFAULT;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800421 args->congestion_kb = default_congestion_kb();
Sage Weil16725b92009-10-06 11:31:07 -0700422
423 /* ip1[:port1][,ip2[:port2]...]:/subdir/in/fs */
Sage Weil7b813c462009-10-26 22:07:53 -0700424 err = -EINVAL;
Sage Weil16725b92009-10-06 11:31:07 -0700425 if (!dev_name)
Sage Weil7b813c462009-10-26 22:07:53 -0700426 goto out;
Sage Weil16725b92009-10-06 11:31:07 -0700427 *path = strstr(dev_name, ":/");
428 if (*path == NULL) {
429 pr_err("device name is missing path (no :/ in %s)\n",
430 dev_name);
Sage Weil7b813c462009-10-26 22:07:53 -0700431 goto out;
Sage Weil16725b92009-10-06 11:31:07 -0700432 }
433
434 /* get mon ip(s) */
Sage Weil6b805182009-10-27 11:50:50 -0700435 err = ceph_parse_ips(dev_name, *path, args->mon_addr,
436 CEPH_MAX_MON, &args->num_mon);
Sage Weil16725b92009-10-06 11:31:07 -0700437 if (err < 0)
Sage Weil7b813c462009-10-26 22:07:53 -0700438 goto out;
Sage Weil16725b92009-10-06 11:31:07 -0700439
Sage Weil16725b92009-10-06 11:31:07 -0700440 /* path on server */
441 *path += 2;
442 dout("server path '%s'\n", *path);
443
444 /* parse mount options */
445 while ((c = strsep(&options, ",")) != NULL) {
446 int token, intval, ret;
447 if (!*c)
448 continue;
Sage Weil7b813c462009-10-26 22:07:53 -0700449 err = -EINVAL;
Sage Weil16725b92009-10-06 11:31:07 -0700450 token = match_token((char *)c, arg_tokens, argstr);
451 if (token < 0) {
452 pr_err("bad mount option at '%s'\n", c);
Sage Weil7b813c462009-10-26 22:07:53 -0700453 goto out;
Sage Weil16725b92009-10-06 11:31:07 -0700454 }
Sage Weile53c2fe2009-10-27 10:19:28 -0700455 if (token < Opt_last_int) {
Sage Weil16725b92009-10-06 11:31:07 -0700456 ret = match_int(&argstr[0], &intval);
457 if (ret < 0) {
458 pr_err("bad mount option arg (not int) "
459 "at '%s'\n", c);
460 continue;
461 }
Sage Weile53c2fe2009-10-27 10:19:28 -0700462 dout("got int token %d val %d\n", token, intval);
463 } else if (token > Opt_last_int && token < Opt_last_string) {
464 dout("got string token %d val %s\n", token,
465 argstr[0].from);
466 } else {
467 dout("got token %d\n", token);
Sage Weil16725b92009-10-06 11:31:07 -0700468 }
469 switch (token) {
470 case Opt_fsidmajor:
471 *(__le64 *)&args->fsid.fsid[0] = cpu_to_le64(intval);
472 break;
473 case Opt_fsidminor:
474 *(__le64 *)&args->fsid.fsid[8] = cpu_to_le64(intval);
475 break;
476 case Opt_ip:
477 err = ceph_parse_ips(argstr[0].from,
478 argstr[0].to,
479 &args->my_addr,
480 1, NULL);
481 if (err < 0)
Sage Weil6b805182009-10-27 11:50:50 -0700482 goto out;
Sage Weil16725b92009-10-06 11:31:07 -0700483 args->flags |= CEPH_OPT_MYIP;
484 break;
485
486 case Opt_snapdirname:
487 kfree(args->snapdir_name);
488 args->snapdir_name = kstrndup(argstr[0].from,
489 argstr[0].to-argstr[0].from,
490 GFP_KERNEL);
491 break;
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800492 case Opt_name:
493 args->name = kstrndup(argstr[0].from,
494 argstr[0].to-argstr[0].from,
495 GFP_KERNEL);
496 break;
Sage Weil16725b92009-10-06 11:31:07 -0700497 case Opt_secret:
498 args->secret = kstrndup(argstr[0].from,
499 argstr[0].to-argstr[0].from,
500 GFP_KERNEL);
501 break;
502
503 /* misc */
504 case Opt_wsize:
505 args->wsize = intval;
506 break;
507 case Opt_rsize:
508 args->rsize = intval;
509 break;
510 case Opt_osdtimeout:
511 args->osd_timeout = intval;
512 break;
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -0800513 case Opt_osdkeepalivetimeout:
514 args->osd_keepalive_timeout = intval;
515 break;
Sage Weil16725b92009-10-06 11:31:07 -0700516 case Opt_mount_timeout:
517 args->mount_timeout = intval;
518 break;
519 case Opt_caps_wanted_delay_min:
520 args->caps_wanted_delay_min = intval;
521 break;
522 case Opt_caps_wanted_delay_max:
523 args->caps_wanted_delay_max = intval;
524 break;
525 case Opt_readdir_max_entries:
526 args->max_readdir = intval;
527 break;
Sage Weil23804d92010-05-14 13:06:30 -0700528 case Opt_readdir_max_bytes:
529 args->max_readdir_bytes = intval;
530 break;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800531 case Opt_congestion_kb:
532 args->congestion_kb = intval;
533 break;
Sage Weil16725b92009-10-06 11:31:07 -0700534
535 case Opt_noshare:
536 args->flags |= CEPH_OPT_NOSHARE;
537 break;
538
539 case Opt_dirstat:
540 args->flags |= CEPH_OPT_DIRSTAT;
541 break;
542 case Opt_nodirstat:
543 args->flags &= ~CEPH_OPT_DIRSTAT;
544 break;
545 case Opt_rbytes:
546 args->flags |= CEPH_OPT_RBYTES;
547 break;
548 case Opt_norbytes:
549 args->flags &= ~CEPH_OPT_RBYTES;
550 break;
551 case Opt_nocrc:
552 args->flags |= CEPH_OPT_NOCRC;
553 break;
554 case Opt_noasyncreaddir:
555 args->flags |= CEPH_OPT_NOASYNCREADDIR;
556 break;
557
558 default:
559 BUG_ON(token);
560 }
561 }
Sage Weil6b805182009-10-27 11:50:50 -0700562 return args;
Sage Weil16725b92009-10-06 11:31:07 -0700563
Sage Weil7b813c462009-10-26 22:07:53 -0700564out:
Sage Weil6b805182009-10-27 11:50:50 -0700565 kfree(args->mon_addr);
566 kfree(args);
567 return ERR_PTR(err);
Sage Weil16725b92009-10-06 11:31:07 -0700568}
569
Sage Weil6b805182009-10-27 11:50:50 -0700570static void destroy_mount_args(struct ceph_mount_args *args)
Sage Weil16725b92009-10-06 11:31:07 -0700571{
Sage Weil6b805182009-10-27 11:50:50 -0700572 dout("destroy_mount_args %p\n", args);
Sage Weil16725b92009-10-06 11:31:07 -0700573 kfree(args->snapdir_name);
574 args->snapdir_name = NULL;
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800575 kfree(args->name);
576 args->name = NULL;
Sage Weil16725b92009-10-06 11:31:07 -0700577 kfree(args->secret);
578 args->secret = NULL;
Sage Weil6b805182009-10-27 11:50:50 -0700579 kfree(args);
Sage Weil16725b92009-10-06 11:31:07 -0700580}
581
582/*
583 * create a fresh client instance
584 */
Sage Weil6b805182009-10-27 11:50:50 -0700585static struct ceph_client *ceph_create_client(struct ceph_mount_args *args)
Sage Weil16725b92009-10-06 11:31:07 -0700586{
587 struct ceph_client *client;
588 int err = -ENOMEM;
589
590 client = kzalloc(sizeof(*client), GFP_KERNEL);
591 if (client == NULL)
592 return ERR_PTR(-ENOMEM);
593
594 mutex_init(&client->mount_mutex);
595
Sage Weil9bd2e6f2010-02-02 16:21:06 -0800596 init_waitqueue_head(&client->auth_wq);
Sage Weil16725b92009-10-06 11:31:07 -0700597
598 client->sb = NULL;
599 client->mount_state = CEPH_MOUNT_MOUNTING;
Sage Weil6b805182009-10-27 11:50:50 -0700600 client->mount_args = args;
Sage Weil16725b92009-10-06 11:31:07 -0700601
602 client->msgr = NULL;
603
Sage Weil9bd2e6f2010-02-02 16:21:06 -0800604 client->auth_err = 0;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800605 atomic_long_set(&client->writeback_count, 0);
Sage Weil16725b92009-10-06 11:31:07 -0700606
Sage Weil859e7b12009-11-02 09:32:47 -0800607 err = bdi_init(&client->backing_dev_info);
608 if (err < 0)
609 goto fail;
610
Sage Weil16725b92009-10-06 11:31:07 -0700611 err = -ENOMEM;
612 client->wb_wq = create_workqueue("ceph-writeback");
613 if (client->wb_wq == NULL)
Sage Weil859e7b12009-11-02 09:32:47 -0800614 goto fail_bdi;
Sage Weil16725b92009-10-06 11:31:07 -0700615 client->pg_inv_wq = create_singlethread_workqueue("ceph-pg-invalid");
616 if (client->pg_inv_wq == NULL)
617 goto fail_wb_wq;
618 client->trunc_wq = create_singlethread_workqueue("ceph-trunc");
619 if (client->trunc_wq == NULL)
620 goto fail_pg_inv_wq;
621
Sage Weilb9bfb932009-11-18 15:08:44 -0800622 /* set up mempools */
623 err = -ENOMEM;
624 client->wb_pagevec_pool = mempool_create_kmalloc_pool(10,
625 client->mount_args->wsize >> PAGE_CACHE_SHIFT);
626 if (!client->wb_pagevec_pool)
627 goto fail_trunc_wq;
628
Sage Weil85ccce42010-02-17 10:02:43 -0800629 /* caps */
630 client->min_caps = args->max_readdir;
Sage Weilb9bfb932009-11-18 15:08:44 -0800631
Sage Weil16725b92009-10-06 11:31:07 -0700632 /* subsystems */
633 err = ceph_monc_init(&client->monc, client);
634 if (err < 0)
Sage Weilb9bfb932009-11-18 15:08:44 -0800635 goto fail_mempool;
Sage Weil16725b92009-10-06 11:31:07 -0700636 err = ceph_osdc_init(&client->osdc, client);
637 if (err < 0)
638 goto fail_monc;
Sage Weil5f44f142009-11-18 14:52:18 -0800639 err = ceph_mdsc_init(&client->mdsc, client);
640 if (err < 0)
641 goto fail_osdc;
Sage Weil16725b92009-10-06 11:31:07 -0700642 return client;
643
Sage Weil5f44f142009-11-18 14:52:18 -0800644fail_osdc:
645 ceph_osdc_stop(&client->osdc);
Sage Weil16725b92009-10-06 11:31:07 -0700646fail_monc:
647 ceph_monc_stop(&client->monc);
Sage Weilb9bfb932009-11-18 15:08:44 -0800648fail_mempool:
649 mempool_destroy(client->wb_pagevec_pool);
Sage Weil16725b92009-10-06 11:31:07 -0700650fail_trunc_wq:
651 destroy_workqueue(client->trunc_wq);
652fail_pg_inv_wq:
653 destroy_workqueue(client->pg_inv_wq);
654fail_wb_wq:
655 destroy_workqueue(client->wb_wq);
Sage Weil859e7b12009-11-02 09:32:47 -0800656fail_bdi:
657 bdi_destroy(&client->backing_dev_info);
Sage Weil16725b92009-10-06 11:31:07 -0700658fail:
659 kfree(client);
660 return ERR_PTR(err);
661}
662
663static void ceph_destroy_client(struct ceph_client *client)
664{
665 dout("destroy_client %p\n", client);
666
667 /* unmount */
668 ceph_mdsc_stop(&client->mdsc);
Sage Weil16725b92009-10-06 11:31:07 -0700669 ceph_osdc_stop(&client->osdc);
670
Sage Weila922d382010-05-29 09:41:23 -0700671 /*
672 * make sure mds and osd connections close out before destroying
673 * the auth module, which is needed to free those connections'
674 * ceph_authorizers.
675 */
676 ceph_msgr_flush();
677
678 ceph_monc_stop(&client->monc);
679
Sage Weil16725b92009-10-06 11:31:07 -0700680 ceph_debugfs_client_cleanup(client);
681 destroy_workqueue(client->wb_wq);
682 destroy_workqueue(client->pg_inv_wq);
683 destroy_workqueue(client->trunc_wq);
684
Sage Weil5dfc5892010-05-04 16:14:46 -0700685 bdi_destroy(&client->backing_dev_info);
686
Sage Weil16725b92009-10-06 11:31:07 -0700687 if (client->msgr)
688 ceph_messenger_destroy(client->msgr);
Sage Weilb9bfb932009-11-18 15:08:44 -0800689 mempool_destroy(client->wb_pagevec_pool);
Sage Weil16725b92009-10-06 11:31:07 -0700690
Sage Weil6b805182009-10-27 11:50:50 -0700691 destroy_mount_args(client->mount_args);
Sage Weil16725b92009-10-06 11:31:07 -0700692
693 kfree(client);
694 dout("destroy_client %p done\n", client);
695}
696
697/*
Sage Weil07433042009-11-18 16:50:41 -0800698 * Initially learn our fsid, or verify an fsid matches.
699 */
700int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid)
701{
702 if (client->have_fsid) {
703 if (ceph_fsid_compare(&client->fsid, fsid)) {
Sage Weil9ec7cab2009-12-14 15:13:47 -0800704 pr_err("bad fsid, had " FSID_FORMAT " got " FSID_FORMAT,
705 PR_FSID(&client->fsid), PR_FSID(fsid));
Sage Weil07433042009-11-18 16:50:41 -0800706 return -1;
707 }
708 } else {
709 pr_info("client%lld fsid " FSID_FORMAT "\n",
710 client->monc.auth->global_id, PR_FSID(fsid));
711 memcpy(&client->fsid, fsid, sizeof(*fsid));
712 ceph_debugfs_client_init(client);
713 client->have_fsid = true;
714 }
715 return 0;
716}
717
718/*
Sage Weil16725b92009-10-06 11:31:07 -0700719 * true if we have the mon map (and have thus joined the cluster)
720 */
Sage Weil6822d002010-04-07 11:23:20 -0700721static int have_mon_and_osd_map(struct ceph_client *client)
Sage Weil16725b92009-10-06 11:31:07 -0700722{
Sage Weil6822d002010-04-07 11:23:20 -0700723 return client->monc.monmap && client->monc.monmap->epoch &&
724 client->osdc.osdmap && client->osdc.osdmap->epoch;
Sage Weil16725b92009-10-06 11:31:07 -0700725}
726
727/*
728 * Bootstrap mount by opening the root directory. Note the mount
729 * @started time from caller, and time out if this takes too long.
730 */
731static struct dentry *open_root_dentry(struct ceph_client *client,
732 const char *path,
733 unsigned long started)
734{
735 struct ceph_mds_client *mdsc = &client->mdsc;
736 struct ceph_mds_request *req = NULL;
737 int err;
738 struct dentry *root;
739
740 /* open dir */
741 dout("open_root_inode opening '%s'\n", path);
742 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_GETATTR, USE_ANY_MDS);
743 if (IS_ERR(req))
Julia Lawall7e34bc52010-05-22 12:01:14 +0200744 return ERR_CAST(req);
Sage Weil16725b92009-10-06 11:31:07 -0700745 req->r_path1 = kstrdup(path, GFP_NOFS);
746 req->r_ino1.ino = CEPH_INO_ROOT;
747 req->r_ino1.snap = CEPH_NOSNAP;
748 req->r_started = started;
Sage Weil6b805182009-10-27 11:50:50 -0700749 req->r_timeout = client->mount_args->mount_timeout * HZ;
Sage Weil16725b92009-10-06 11:31:07 -0700750 req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INODE);
751 req->r_num_caps = 2;
752 err = ceph_mdsc_do_request(mdsc, NULL, req);
753 if (err == 0) {
754 dout("open_root_inode success\n");
755 if (ceph_ino(req->r_target_inode) == CEPH_INO_ROOT &&
756 client->sb->s_root == NULL)
757 root = d_alloc_root(req->r_target_inode);
758 else
759 root = d_obtain_alias(req->r_target_inode);
760 req->r_target_inode = NULL;
761 dout("open_root_inode success, root dentry is %p\n", root);
762 } else {
763 root = ERR_PTR(err);
764 }
765 ceph_mdsc_put_request(req);
766 return root;
767}
768
769/*
770 * mount: join the ceph cluster, and open root directory.
771 */
772static int ceph_mount(struct ceph_client *client, struct vfsmount *mnt,
773 const char *path)
774{
775 struct ceph_entity_addr *myaddr = NULL;
776 int err;
Sage Weil6b805182009-10-27 11:50:50 -0700777 unsigned long timeout = client->mount_args->mount_timeout * HZ;
Sage Weil16725b92009-10-06 11:31:07 -0700778 unsigned long started = jiffies; /* note the start time */
779 struct dentry *root;
780
781 dout("mount start\n");
782 mutex_lock(&client->mount_mutex);
783
784 /* initialize the messenger */
785 if (client->msgr == NULL) {
786 if (ceph_test_opt(client, MYIP))
Sage Weil6b805182009-10-27 11:50:50 -0700787 myaddr = &client->mount_args->my_addr;
Sage Weil16725b92009-10-06 11:31:07 -0700788 client->msgr = ceph_messenger_create(myaddr);
789 if (IS_ERR(client->msgr)) {
790 err = PTR_ERR(client->msgr);
791 client->msgr = NULL;
792 goto out;
793 }
794 client->msgr->nocrc = ceph_test_opt(client, NOCRC);
795 }
796
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800797 /* open session, and wait for mon, mds, and osd maps */
798 err = ceph_monc_open_session(&client->monc);
Sage Weil16725b92009-10-06 11:31:07 -0700799 if (err < 0)
800 goto out;
801
Sage Weil6822d002010-04-07 11:23:20 -0700802 while (!have_mon_and_osd_map(client)) {
Sage Weil16725b92009-10-06 11:31:07 -0700803 err = -EIO;
804 if (timeout && time_after_eq(jiffies, started + timeout))
805 goto out;
806
807 /* wait */
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800808 dout("mount waiting for mon_map\n");
Sage Weil9bd2e6f2010-02-02 16:21:06 -0800809 err = wait_event_interruptible_timeout(client->auth_wq,
Sage Weil6822d002010-04-07 11:23:20 -0700810 have_mon_and_osd_map(client) || (client->auth_err < 0),
811 timeout);
Sage Weil16725b92009-10-06 11:31:07 -0700812 if (err == -EINTR || err == -ERESTARTSYS)
813 goto out;
Sage Weil9bd2e6f2010-02-02 16:21:06 -0800814 if (client->auth_err < 0) {
815 err = client->auth_err;
Yehuda Sadehdc146572009-11-20 13:59:13 -0800816 goto out;
817 }
Sage Weil16725b92009-10-06 11:31:07 -0700818 }
819
820 dout("mount opening root\n");
821 root = open_root_dentry(client, "", started);
822 if (IS_ERR(root)) {
823 err = PTR_ERR(root);
824 goto out;
825 }
826 if (client->sb->s_root)
827 dput(root);
828 else
829 client->sb->s_root = root;
830
831 if (path[0] == 0) {
832 dget(root);
833 } else {
834 dout("mount opening base mountpoint\n");
835 root = open_root_dentry(client, path, started);
836 if (IS_ERR(root)) {
837 err = PTR_ERR(root);
838 dput(client->sb->s_root);
839 client->sb->s_root = NULL;
840 goto out;
841 }
842 }
843
844 mnt->mnt_root = root;
845 mnt->mnt_sb = client->sb;
846
847 client->mount_state = CEPH_MOUNT_MOUNTED;
848 dout("mount success\n");
849 err = 0;
850
851out:
852 mutex_unlock(&client->mount_mutex);
853 return err;
854}
855
856static int ceph_set_super(struct super_block *s, void *data)
857{
858 struct ceph_client *client = data;
859 int ret;
860
861 dout("set_super %p data %p\n", s, data);
862
Sage Weil6b805182009-10-27 11:50:50 -0700863 s->s_flags = client->mount_args->sb_flags;
Sage Weil16725b92009-10-06 11:31:07 -0700864 s->s_maxbytes = 1ULL << 40; /* temp value until we get mdsmap */
865
866 s->s_fs_info = client;
867 client->sb = s;
868
869 s->s_op = &ceph_super_ops;
870 s->s_export_op = &ceph_export_ops;
871
872 s->s_time_gran = 1000; /* 1000 ns == 1 us */
873
874 ret = set_anon_super(s, NULL); /* what is that second arg for? */
875 if (ret != 0)
876 goto fail;
877
878 return ret;
879
880fail:
881 s->s_fs_info = NULL;
882 client->sb = NULL;
883 return ret;
884}
885
886/*
887 * share superblock if same fs AND options
888 */
889static int ceph_compare_super(struct super_block *sb, void *data)
890{
891 struct ceph_client *new = data;
Sage Weil6b805182009-10-27 11:50:50 -0700892 struct ceph_mount_args *args = new->mount_args;
Sage Weil16725b92009-10-06 11:31:07 -0700893 struct ceph_client *other = ceph_sb_to_client(sb);
894 int i;
895
896 dout("ceph_compare_super %p\n", sb);
897 if (args->flags & CEPH_OPT_FSID) {
898 if (ceph_fsid_compare(&args->fsid, &other->fsid)) {
899 dout("fsid doesn't match\n");
900 return 0;
901 }
902 } else {
903 /* do we share (a) monitor? */
904 for (i = 0; i < new->monc.monmap->num_mon; i++)
905 if (ceph_monmap_contains(other->monc.monmap,
906 &new->monc.monmap->mon_inst[i].addr))
907 break;
908 if (i == new->monc.monmap->num_mon) {
909 dout("mon ip not part of monmap\n");
910 return 0;
911 }
912 dout("mon ip matches existing sb %p\n", sb);
913 }
Sage Weil6b805182009-10-27 11:50:50 -0700914 if (args->sb_flags != other->mount_args->sb_flags) {
Sage Weil16725b92009-10-06 11:31:07 -0700915 dout("flags differ\n");
916 return 0;
917 }
918 return 1;
919}
920
921/*
922 * construct our own bdi so we can control readahead, etc.
923 */
Jeff Mahoney00d56432010-06-10 11:13:58 -0400924static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
Sage Weil31e0cf82010-05-04 16:39:35 -0700925
Sage Weil859e7b12009-11-02 09:32:47 -0800926static int ceph_register_bdi(struct super_block *sb, struct ceph_client *client)
Sage Weil16725b92009-10-06 11:31:07 -0700927{
928 int err;
929
Sage Weil16725b92009-10-06 11:31:07 -0700930 /* set ra_pages based on rsize mount option? */
Sage Weil6b805182009-10-27 11:50:50 -0700931 if (client->mount_args->rsize >= PAGE_CACHE_SIZE)
Sage Weil16725b92009-10-06 11:31:07 -0700932 client->backing_dev_info.ra_pages =
Sage Weil6b805182009-10-27 11:50:50 -0700933 (client->mount_args->rsize + PAGE_CACHE_SIZE - 1)
Sage Weil16725b92009-10-06 11:31:07 -0700934 >> PAGE_SHIFT;
Sage Weil31e0cf82010-05-04 16:39:35 -0700935 err = bdi_register(&client->backing_dev_info, NULL, "ceph-%d",
936 atomic_long_inc_return(&bdi_seq));
Sage Weil5dfc5892010-05-04 16:14:46 -0700937 if (!err)
938 sb->s_bdi = &client->backing_dev_info;
Sage Weil16725b92009-10-06 11:31:07 -0700939 return err;
940}
941
942static int ceph_get_sb(struct file_system_type *fs_type,
943 int flags, const char *dev_name, void *data,
944 struct vfsmount *mnt)
945{
946 struct super_block *sb;
947 struct ceph_client *client;
948 int err;
949 int (*compare_super)(struct super_block *, void *) = ceph_compare_super;
Sage Weil6a18be12009-11-04 11:40:05 -0800950 const char *path = NULL;
Sage Weil6b805182009-10-27 11:50:50 -0700951 struct ceph_mount_args *args;
Sage Weil16725b92009-10-06 11:31:07 -0700952
953 dout("ceph_get_sb\n");
Sage Weil6b805182009-10-27 11:50:50 -0700954 args = parse_mount_args(flags, data, dev_name, &path);
955 if (IS_ERR(args)) {
956 err = PTR_ERR(args);
957 goto out_final;
958 }
Sage Weil16725b92009-10-06 11:31:07 -0700959
960 /* create client (which we may/may not use) */
Sage Weil6b805182009-10-27 11:50:50 -0700961 client = ceph_create_client(args);
962 if (IS_ERR(client)) {
963 err = PTR_ERR(client);
964 goto out_final;
965 }
Sage Weil16725b92009-10-06 11:31:07 -0700966
Sage Weil6b805182009-10-27 11:50:50 -0700967 if (client->mount_args->flags & CEPH_OPT_NOSHARE)
Sage Weil16725b92009-10-06 11:31:07 -0700968 compare_super = NULL;
969 sb = sget(fs_type, compare_super, ceph_set_super, client);
970 if (IS_ERR(sb)) {
971 err = PTR_ERR(sb);
972 goto out;
973 }
974
Cheng Renquan640ef792010-03-26 17:40:33 +0800975 if (ceph_sb_to_client(sb) != client) {
Sage Weil16725b92009-10-06 11:31:07 -0700976 ceph_destroy_client(client);
Cheng Renquan640ef792010-03-26 17:40:33 +0800977 client = ceph_sb_to_client(sb);
Sage Weil16725b92009-10-06 11:31:07 -0700978 dout("get_sb got existing client %p\n", client);
979 } else {
980 dout("get_sb using new client %p\n", client);
Sage Weil859e7b12009-11-02 09:32:47 -0800981 err = ceph_register_bdi(sb, client);
Sage Weil16725b92009-10-06 11:31:07 -0700982 if (err < 0)
983 goto out_splat;
984 }
985
986 err = ceph_mount(client, mnt, path);
987 if (err < 0)
988 goto out_splat;
989 dout("root %p inode %p ino %llx.%llx\n", mnt->mnt_root,
990 mnt->mnt_root->d_inode, ceph_vinop(mnt->mnt_root->d_inode));
991 return 0;
992
993out_splat:
994 ceph_mdsc_close_sessions(&client->mdsc);
Al Viro3981f2e2010-03-21 19:22:29 -0400995 deactivate_locked_super(sb);
Sage Weil16725b92009-10-06 11:31:07 -0700996 goto out_final;
997
998out:
999 ceph_destroy_client(client);
1000out_final:
1001 dout("ceph_get_sb fail %d\n", err);
1002 return err;
1003}
1004
1005static void ceph_kill_sb(struct super_block *s)
1006{
1007 struct ceph_client *client = ceph_sb_to_client(s);
1008 dout("kill_sb %p\n", s);
1009 ceph_mdsc_pre_umount(&client->mdsc);
Sage Weil16725b92009-10-06 11:31:07 -07001010 kill_anon_super(s); /* will call put_super after sb is r/o */
Sage Weil16725b92009-10-06 11:31:07 -07001011 ceph_destroy_client(client);
1012}
1013
1014static struct file_system_type ceph_fs_type = {
1015 .owner = THIS_MODULE,
1016 .name = "ceph",
1017 .get_sb = ceph_get_sb,
1018 .kill_sb = ceph_kill_sb,
1019 .fs_flags = FS_RENAME_DOES_D_MOVE,
1020};
1021
1022#define _STRINGIFY(x) #x
1023#define STRINGIFY(x) _STRINGIFY(x)
1024
1025static int __init init_ceph(void)
1026{
1027 int ret = 0;
1028
1029 ret = ceph_debugfs_init();
1030 if (ret < 0)
1031 goto out;
1032
1033 ret = ceph_msgr_init();
1034 if (ret < 0)
1035 goto out_debugfs;
1036
1037 ret = init_caches();
1038 if (ret)
1039 goto out_msgr;
1040
Sage Weil16725b92009-10-06 11:31:07 -07001041 ret = register_filesystem(&ceph_fs_type);
1042 if (ret)
1043 goto out_icache;
1044
Sage Weilc8f16582010-04-19 13:50:26 -07001045 pr_info("loaded (mon/mds/osd proto %d/%d/%d, osdmap %d/%d %d/%d)\n",
1046 CEPH_MONC_PROTOCOL, CEPH_MDSC_PROTOCOL, CEPH_OSDC_PROTOCOL,
1047 CEPH_OSDMAP_VERSION, CEPH_OSDMAP_VERSION_EXT,
1048 CEPH_OSDMAP_INC_VERSION, CEPH_OSDMAP_INC_VERSION_EXT);
Sage Weil16725b92009-10-06 11:31:07 -07001049 return 0;
1050
1051out_icache:
1052 destroy_caches();
1053out_msgr:
1054 ceph_msgr_exit();
1055out_debugfs:
1056 ceph_debugfs_cleanup();
1057out:
1058 return ret;
1059}
1060
1061static void __exit exit_ceph(void)
1062{
1063 dout("exit_ceph\n");
1064 unregister_filesystem(&ceph_fs_type);
Sage Weil16725b92009-10-06 11:31:07 -07001065 destroy_caches();
1066 ceph_msgr_exit();
1067 ceph_debugfs_cleanup();
1068}
1069
1070module_init(init_ceph);
1071module_exit(exit_ceph);
1072
1073MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
1074MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
1075MODULE_AUTHOR("Patience Warnick <patience@newdream.net>");
1076MODULE_DESCRIPTION("Ceph filesystem for Linux");
1077MODULE_LICENSE("GPL");