blob: d80699a4dc264b332c0c00e0da8aeda43b028836 [file] [log] [blame]
Sage Weil16725b92009-10-06 11:31:07 -07001
2#include "ceph_debug.h"
3
4#include <linux/backing-dev.h>
Sage Weilc309f0a2010-06-30 21:34:01 -07005#include <linux/ctype.h>
Sage Weil16725b92009-10-06 11:31:07 -07006#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>
Sage Weil16725b92009-10-06 11:31:07 -070012#include <linux/sched.h>
13#include <linux/seq_file.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Sage Weil16725b92009-10-06 11:31:07 -070015#include <linux/statfs.h>
16#include <linux/string.h>
Sage Weil16725b92009-10-06 11:31:07 -070017
Sage Weil16725b92009-10-06 11:31:07 -070018#include "decode.h"
19#include "super.h"
20#include "mon_client.h"
Sage Weil07433042009-11-18 16:50:41 -080021#include "auth.h"
Sage Weil16725b92009-10-06 11:31:07 -070022
23/*
24 * Ceph superblock operations
25 *
26 * Handle the basics of mounting, unmounting.
27 */
28
29
30/*
31 * find filename portion of a path (/foo/bar/baz -> baz)
32 */
33const char *ceph_file_part(const char *s, int len)
34{
35 const char *e = s + len;
36
37 while (e != s && *(e-1) != '/')
38 e--;
39 return e;
40}
41
42
43/*
44 * super ops
45 */
46static void ceph_put_super(struct super_block *s)
47{
Sage Weil5dfc5892010-05-04 16:14:46 -070048 struct ceph_client *client = ceph_sb_to_client(s);
Sage Weil16725b92009-10-06 11:31:07 -070049
50 dout("put_super\n");
Sage Weil5dfc5892010-05-04 16:14:46 -070051 ceph_mdsc_close_sessions(&client->mdsc);
52
53 /*
54 * ensure we release the bdi before put_anon_super releases
55 * the device name.
56 */
57 if (s->s_bdi == &client->backing_dev_info) {
58 bdi_unregister(&client->backing_dev_info);
59 s->s_bdi = NULL;
60 }
61
Sage Weil16725b92009-10-06 11:31:07 -070062 return;
63}
64
65static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf)
66{
67 struct ceph_client *client = ceph_inode_to_client(dentry->d_inode);
68 struct ceph_monmap *monmap = client->monc.monmap;
69 struct ceph_statfs st;
70 u64 fsid;
71 int err;
72
73 dout("statfs\n");
74 err = ceph_monc_do_statfs(&client->monc, &st);
75 if (err < 0)
76 return err;
77
78 /* fill in kstatfs */
79 buf->f_type = CEPH_SUPER_MAGIC; /* ?? */
80
81 /*
82 * express utilization in terms of large blocks to avoid
83 * overflow on 32-bit machines.
84 */
85 buf->f_bsize = 1 << CEPH_BLOCK_SHIFT;
86 buf->f_blocks = le64_to_cpu(st.kb) >> (CEPH_BLOCK_SHIFT-10);
87 buf->f_bfree = (le64_to_cpu(st.kb) - le64_to_cpu(st.kb_used)) >>
88 (CEPH_BLOCK_SHIFT-10);
89 buf->f_bavail = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);
90
91 buf->f_files = le64_to_cpu(st.num_objects);
92 buf->f_ffree = -1;
Sage Weil558d3492010-06-01 12:51:12 -070093 buf->f_namelen = NAME_MAX;
Sage Weil16725b92009-10-06 11:31:07 -070094 buf->f_frsize = PAGE_CACHE_SIZE;
95
96 /* leave fsid little-endian, regardless of host endianness */
97 fsid = *(u64 *)(&monmap->fsid) ^ *((u64 *)&monmap->fsid + 1);
98 buf->f_fsid.val[0] = fsid & 0xffffffff;
99 buf->f_fsid.val[1] = fsid >> 32;
100
101 return 0;
102}
103
104
105static int ceph_syncfs(struct super_block *sb, int wait)
106{
107 dout("sync_fs %d\n", wait);
Cheng Renquan640ef792010-03-26 17:40:33 +0800108 ceph_osdc_sync(&ceph_sb_to_client(sb)->osdc);
109 ceph_mdsc_sync(&ceph_sb_to_client(sb)->mdsc);
Sage Weilf2cf4182009-10-14 14:09:07 -0700110 dout("sync_fs %d done\n", wait);
Sage Weil16725b92009-10-06 11:31:07 -0700111 return 0;
112}
113
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800114static int default_congestion_kb(void)
115{
116 int congestion_kb;
117
118 /*
119 * Copied from NFS
120 *
121 * congestion size, scale with available memory.
122 *
123 * 64MB: 8192k
124 * 128MB: 11585k
125 * 256MB: 16384k
126 * 512MB: 23170k
127 * 1GB: 32768k
128 * 2GB: 46340k
129 * 4GB: 65536k
130 * 8GB: 92681k
131 * 16GB: 131072k
132 *
133 * This allows larger machines to have larger/more transfers.
134 * Limit the default to 256M
135 */
136 congestion_kb = (16*int_sqrt(totalram_pages)) << (PAGE_SHIFT-10);
137 if (congestion_kb > 256*1024)
138 congestion_kb = 256*1024;
139
140 return congestion_kb;
141}
142
Sage Weil6e19a162010-04-29 16:38:32 -0700143/**
144 * ceph_show_options - Show mount options in /proc/mounts
145 * @m: seq_file to write to
146 * @mnt: mount descriptor
147 */
148static int ceph_show_options(struct seq_file *m, struct vfsmount *mnt)
149{
150 struct ceph_client *client = ceph_sb_to_client(mnt->mnt_sb);
151 struct ceph_mount_args *args = client->mount_args;
152
153 if (args->flags & CEPH_OPT_FSID)
Sage Weila8b763a2010-07-08 13:00:18 -0700154 seq_printf(m, ",fsid=%pU", &args->fsid);
Sage Weil6e19a162010-04-29 16:38:32 -0700155 if (args->flags & CEPH_OPT_NOSHARE)
156 seq_puts(m, ",noshare");
157 if (args->flags & CEPH_OPT_DIRSTAT)
158 seq_puts(m, ",dirstat");
159 if ((args->flags & CEPH_OPT_RBYTES) == 0)
160 seq_puts(m, ",norbytes");
161 if (args->flags & CEPH_OPT_NOCRC)
162 seq_puts(m, ",nocrc");
163 if (args->flags & CEPH_OPT_NOASYNCREADDIR)
164 seq_puts(m, ",noasyncreaddir");
165
166 if (args->mount_timeout != CEPH_MOUNT_TIMEOUT_DEFAULT)
167 seq_printf(m, ",mount_timeout=%d", args->mount_timeout);
168 if (args->osd_idle_ttl != CEPH_OSD_IDLE_TTL_DEFAULT)
169 seq_printf(m, ",osd_idle_ttl=%d", args->osd_idle_ttl);
170 if (args->osd_timeout != CEPH_OSD_TIMEOUT_DEFAULT)
171 seq_printf(m, ",osdtimeout=%d", args->osd_timeout);
172 if (args->osd_keepalive_timeout != CEPH_OSD_KEEPALIVE_DEFAULT)
173 seq_printf(m, ",osdkeepalivetimeout=%d",
174 args->osd_keepalive_timeout);
175 if (args->wsize)
176 seq_printf(m, ",wsize=%d", args->wsize);
177 if (args->rsize != CEPH_MOUNT_RSIZE_DEFAULT)
178 seq_printf(m, ",rsize=%d", args->rsize);
179 if (args->congestion_kb != default_congestion_kb())
180 seq_printf(m, ",write_congestion_kb=%d", args->congestion_kb);
181 if (args->caps_wanted_delay_min != CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT)
182 seq_printf(m, ",caps_wanted_delay_min=%d",
183 args->caps_wanted_delay_min);
184 if (args->caps_wanted_delay_max != CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT)
185 seq_printf(m, ",caps_wanted_delay_max=%d",
186 args->caps_wanted_delay_max);
187 if (args->cap_release_safety != CEPH_CAP_RELEASE_SAFETY_DEFAULT)
188 seq_printf(m, ",cap_release_safety=%d",
189 args->cap_release_safety);
190 if (args->max_readdir != CEPH_MAX_READDIR_DEFAULT)
191 seq_printf(m, ",readdir_max_entries=%d", args->max_readdir);
Sage Weil23804d92010-05-14 13:06:30 -0700192 if (args->max_readdir_bytes != CEPH_MAX_READDIR_BYTES_DEFAULT)
193 seq_printf(m, ",readdir_max_bytes=%d", args->max_readdir_bytes);
Sage Weil6e19a162010-04-29 16:38:32 -0700194 if (strcmp(args->snapdir_name, CEPH_SNAPDIRNAME_DEFAULT))
195 seq_printf(m, ",snapdirname=%s", args->snapdir_name);
196 if (args->name)
197 seq_printf(m, ",name=%s", args->name);
198 if (args->secret)
199 seq_puts(m, ",secret=<hidden>");
200 return 0;
201}
202
203/*
204 * caches
205 */
206struct kmem_cache *ceph_inode_cachep;
207struct kmem_cache *ceph_cap_cachep;
208struct kmem_cache *ceph_dentry_cachep;
209struct kmem_cache *ceph_file_cachep;
210
211static void ceph_inode_init_once(void *foo)
212{
213 struct ceph_inode_info *ci = foo;
214 inode_init_once(&ci->vfs_inode);
215}
216
Sage Weil16725b92009-10-06 11:31:07 -0700217static int __init init_caches(void)
218{
219 ceph_inode_cachep = kmem_cache_create("ceph_inode_info",
220 sizeof(struct ceph_inode_info),
221 __alignof__(struct ceph_inode_info),
222 (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
223 ceph_inode_init_once);
224 if (ceph_inode_cachep == NULL)
225 return -ENOMEM;
226
227 ceph_cap_cachep = KMEM_CACHE(ceph_cap,
228 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
229 if (ceph_cap_cachep == NULL)
230 goto bad_cap;
231
232 ceph_dentry_cachep = KMEM_CACHE(ceph_dentry_info,
233 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
234 if (ceph_dentry_cachep == NULL)
235 goto bad_dentry;
236
237 ceph_file_cachep = KMEM_CACHE(ceph_file_info,
238 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
239 if (ceph_file_cachep == NULL)
240 goto bad_file;
241
242 return 0;
243
244bad_file:
245 kmem_cache_destroy(ceph_dentry_cachep);
246bad_dentry:
247 kmem_cache_destroy(ceph_cap_cachep);
248bad_cap:
249 kmem_cache_destroy(ceph_inode_cachep);
250 return -ENOMEM;
251}
252
253static void destroy_caches(void)
254{
255 kmem_cache_destroy(ceph_inode_cachep);
256 kmem_cache_destroy(ceph_cap_cachep);
257 kmem_cache_destroy(ceph_dentry_cachep);
258 kmem_cache_destroy(ceph_file_cachep);
259}
260
261
262/*
263 * ceph_umount_begin - initiate forced umount. Tear down down the
264 * mount, skipping steps that may hang while waiting for server(s).
265 */
266static void ceph_umount_begin(struct super_block *sb)
267{
268 struct ceph_client *client = ceph_sb_to_client(sb);
269
270 dout("ceph_umount_begin - starting forced umount\n");
271 if (!client)
272 return;
273 client->mount_state = CEPH_MOUNT_SHUTDOWN;
274 return;
275}
276
277static const struct super_operations ceph_super_ops = {
278 .alloc_inode = ceph_alloc_inode,
279 .destroy_inode = ceph_destroy_inode,
280 .write_inode = ceph_write_inode,
281 .sync_fs = ceph_syncfs,
282 .put_super = ceph_put_super,
283 .show_options = ceph_show_options,
284 .statfs = ceph_statfs,
285 .umount_begin = ceph_umount_begin,
286};
287
288
289const char *ceph_msg_type_name(int type)
290{
291 switch (type) {
292 case CEPH_MSG_SHUTDOWN: return "shutdown";
293 case CEPH_MSG_PING: return "ping";
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800294 case CEPH_MSG_AUTH: return "auth";
295 case CEPH_MSG_AUTH_REPLY: return "auth_reply";
Sage Weil16725b92009-10-06 11:31:07 -0700296 case CEPH_MSG_MON_MAP: return "mon_map";
297 case CEPH_MSG_MON_GET_MAP: return "mon_get_map";
298 case CEPH_MSG_MON_SUBSCRIBE: return "mon_subscribe";
299 case CEPH_MSG_MON_SUBSCRIBE_ACK: return "mon_subscribe_ack";
Sage Weil16725b92009-10-06 11:31:07 -0700300 case CEPH_MSG_STATFS: return "statfs";
301 case CEPH_MSG_STATFS_REPLY: return "statfs_reply";
Sage Weil16725b92009-10-06 11:31:07 -0700302 case CEPH_MSG_MDS_MAP: return "mds_map";
303 case CEPH_MSG_CLIENT_SESSION: return "client_session";
304 case CEPH_MSG_CLIENT_RECONNECT: return "client_reconnect";
305 case CEPH_MSG_CLIENT_REQUEST: return "client_request";
306 case CEPH_MSG_CLIENT_REQUEST_FORWARD: return "client_request_forward";
307 case CEPH_MSG_CLIENT_REPLY: return "client_reply";
308 case CEPH_MSG_CLIENT_CAPS: return "client_caps";
309 case CEPH_MSG_CLIENT_CAPRELEASE: return "client_cap_release";
310 case CEPH_MSG_CLIENT_SNAP: return "client_snap";
311 case CEPH_MSG_CLIENT_LEASE: return "client_lease";
Sage Weil16725b92009-10-06 11:31:07 -0700312 case CEPH_MSG_OSD_MAP: return "osd_map";
313 case CEPH_MSG_OSD_OP: return "osd_op";
314 case CEPH_MSG_OSD_OPREPLY: return "osd_opreply";
315 default: return "unknown";
316 }
317}
318
319
320/*
321 * mount options
322 */
323enum {
Sage Weil16725b92009-10-06 11:31:07 -0700324 Opt_wsize,
325 Opt_rsize,
326 Opt_osdtimeout,
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -0800327 Opt_osdkeepalivetimeout,
Sage Weil16725b92009-10-06 11:31:07 -0700328 Opt_mount_timeout,
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800329 Opt_osd_idle_ttl,
Sage Weil16725b92009-10-06 11:31:07 -0700330 Opt_caps_wanted_delay_min,
331 Opt_caps_wanted_delay_max,
Sage Weil6e19a162010-04-29 16:38:32 -0700332 Opt_cap_release_safety,
Sage Weil16725b92009-10-06 11:31:07 -0700333 Opt_readdir_max_entries,
Sage Weil23804d92010-05-14 13:06:30 -0700334 Opt_readdir_max_bytes,
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800335 Opt_congestion_kb,
Sage Weile53c2fe2009-10-27 10:19:28 -0700336 Opt_last_int,
Sage Weil16725b92009-10-06 11:31:07 -0700337 /* int args above */
Sage Weilc309f0a2010-06-30 21:34:01 -0700338 Opt_fsid,
Sage Weil16725b92009-10-06 11:31:07 -0700339 Opt_snapdirname,
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800340 Opt_name,
Sage Weil16725b92009-10-06 11:31:07 -0700341 Opt_secret,
Sage Weile53c2fe2009-10-27 10:19:28 -0700342 Opt_last_string,
Sage Weil16725b92009-10-06 11:31:07 -0700343 /* string args above */
344 Opt_ip,
345 Opt_noshare,
346 Opt_dirstat,
347 Opt_nodirstat,
348 Opt_rbytes,
349 Opt_norbytes,
350 Opt_nocrc,
351 Opt_noasyncreaddir,
352};
353
354static match_table_t arg_tokens = {
Sage Weil16725b92009-10-06 11:31:07 -0700355 {Opt_wsize, "wsize=%d"},
356 {Opt_rsize, "rsize=%d"},
357 {Opt_osdtimeout, "osdtimeout=%d"},
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -0800358 {Opt_osdkeepalivetimeout, "osdkeepalive=%d"},
Sage Weil16725b92009-10-06 11:31:07 -0700359 {Opt_mount_timeout, "mount_timeout=%d"},
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800360 {Opt_osd_idle_ttl, "osd_idle_ttl=%d"},
Sage Weil16725b92009-10-06 11:31:07 -0700361 {Opt_caps_wanted_delay_min, "caps_wanted_delay_min=%d"},
362 {Opt_caps_wanted_delay_max, "caps_wanted_delay_max=%d"},
Sage Weil6e19a162010-04-29 16:38:32 -0700363 {Opt_cap_release_safety, "cap_release_safety=%d"},
Sage Weil16725b92009-10-06 11:31:07 -0700364 {Opt_readdir_max_entries, "readdir_max_entries=%d"},
Sage Weil23804d92010-05-14 13:06:30 -0700365 {Opt_readdir_max_bytes, "readdir_max_bytes=%d"},
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800366 {Opt_congestion_kb, "write_congestion_kb=%d"},
Sage Weil16725b92009-10-06 11:31:07 -0700367 /* int args above */
Sage Weilc309f0a2010-06-30 21:34:01 -0700368 {Opt_fsid, "fsid=%s"},
Sage Weil16725b92009-10-06 11:31:07 -0700369 {Opt_snapdirname, "snapdirname=%s"},
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800370 {Opt_name, "name=%s"},
Sage Weil16725b92009-10-06 11:31:07 -0700371 {Opt_secret, "secret=%s"},
372 /* string args above */
373 {Opt_ip, "ip=%s"},
374 {Opt_noshare, "noshare"},
375 {Opt_dirstat, "dirstat"},
376 {Opt_nodirstat, "nodirstat"},
377 {Opt_rbytes, "rbytes"},
378 {Opt_norbytes, "norbytes"},
379 {Opt_nocrc, "nocrc"},
380 {Opt_noasyncreaddir, "noasyncreaddir"},
381 {-1, NULL}
382};
383
Sage Weilc309f0a2010-06-30 21:34:01 -0700384static int parse_fsid(const char *str, struct ceph_fsid *fsid)
385{
386 int i = 0;
387 char tmp[3];
388 int err = -EINVAL;
389 int d;
390
391 dout("parse_fsid '%s'\n", str);
392 tmp[2] = 0;
393 while (*str && i < 16) {
394 if (ispunct(*str)) {
395 str++;
396 continue;
397 }
398 if (!isxdigit(str[0]) || !isxdigit(str[1]))
399 break;
400 tmp[0] = str[0];
401 tmp[1] = str[1];
402 if (sscanf(tmp, "%x", &d) < 1)
403 break;
404 fsid->fsid[i] = d & 0xff;
405 i++;
406 str += 2;
407 }
408
409 if (i == 16)
410 err = 0;
Sage Weila8b763a2010-07-08 13:00:18 -0700411 dout("parse_fsid ret %d got fsid %pU", err, fsid);
Sage Weilc309f0a2010-06-30 21:34:01 -0700412 return err;
413}
Sage Weil16725b92009-10-06 11:31:07 -0700414
Sage Weil6b805182009-10-27 11:50:50 -0700415static struct ceph_mount_args *parse_mount_args(int flags, char *options,
416 const char *dev_name,
417 const char **path)
Sage Weil16725b92009-10-06 11:31:07 -0700418{
Sage Weil6b805182009-10-27 11:50:50 -0700419 struct ceph_mount_args *args;
Sage Weil16725b92009-10-06 11:31:07 -0700420 const char *c;
Sage Weil6b805182009-10-27 11:50:50 -0700421 int err = -ENOMEM;
Sage Weil16725b92009-10-06 11:31:07 -0700422 substring_t argstr[MAX_OPT_ARGS];
Sage Weil16725b92009-10-06 11:31:07 -0700423
Sage Weil6b805182009-10-27 11:50:50 -0700424 args = kzalloc(sizeof(*args), GFP_KERNEL);
425 if (!args)
426 return ERR_PTR(-ENOMEM);
427 args->mon_addr = kcalloc(CEPH_MAX_MON, sizeof(*args->mon_addr),
428 GFP_KERNEL);
429 if (!args->mon_addr)
430 goto out;
Sage Weil16725b92009-10-06 11:31:07 -0700431
Sage Weil6b805182009-10-27 11:50:50 -0700432 dout("parse_mount_args %p, dev_name '%s'\n", args, dev_name);
Sage Weil7b813c462009-10-26 22:07:53 -0700433
Sage Weil16725b92009-10-06 11:31:07 -0700434 /* start with defaults */
435 args->sb_flags = flags;
436 args->flags = CEPH_OPT_DEFAULT;
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -0800437 args->osd_timeout = CEPH_OSD_TIMEOUT_DEFAULT;
438 args->osd_keepalive_timeout = CEPH_OSD_KEEPALIVE_DEFAULT;
Sage Weil16725b92009-10-06 11:31:07 -0700439 args->mount_timeout = CEPH_MOUNT_TIMEOUT_DEFAULT; /* seconds */
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800440 args->osd_idle_ttl = CEPH_OSD_IDLE_TTL_DEFAULT; /* seconds */
Sage Weil16725b92009-10-06 11:31:07 -0700441 args->caps_wanted_delay_min = CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT;
442 args->caps_wanted_delay_max = CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT;
Sage Weil8fa97652009-10-16 14:44:35 -0700443 args->rsize = CEPH_MOUNT_RSIZE_DEFAULT;
Sage Weil16725b92009-10-06 11:31:07 -0700444 args->snapdir_name = kstrdup(CEPH_SNAPDIRNAME_DEFAULT, GFP_KERNEL);
Sage Weil6e19a162010-04-29 16:38:32 -0700445 args->cap_release_safety = CEPH_CAP_RELEASE_SAFETY_DEFAULT;
446 args->max_readdir = CEPH_MAX_READDIR_DEFAULT;
Sage Weil23804d92010-05-14 13:06:30 -0700447 args->max_readdir_bytes = CEPH_MAX_READDIR_BYTES_DEFAULT;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800448 args->congestion_kb = default_congestion_kb();
Sage Weil16725b92009-10-06 11:31:07 -0700449
450 /* ip1[:port1][,ip2[:port2]...]:/subdir/in/fs */
Sage Weil7b813c462009-10-26 22:07:53 -0700451 err = -EINVAL;
Sage Weil16725b92009-10-06 11:31:07 -0700452 if (!dev_name)
Sage Weil7b813c462009-10-26 22:07:53 -0700453 goto out;
Sage Weil16725b92009-10-06 11:31:07 -0700454 *path = strstr(dev_name, ":/");
455 if (*path == NULL) {
456 pr_err("device name is missing path (no :/ in %s)\n",
457 dev_name);
Sage Weil7b813c462009-10-26 22:07:53 -0700458 goto out;
Sage Weil16725b92009-10-06 11:31:07 -0700459 }
460
461 /* get mon ip(s) */
Sage Weil6b805182009-10-27 11:50:50 -0700462 err = ceph_parse_ips(dev_name, *path, args->mon_addr,
463 CEPH_MAX_MON, &args->num_mon);
Sage Weil16725b92009-10-06 11:31:07 -0700464 if (err < 0)
Sage Weil7b813c462009-10-26 22:07:53 -0700465 goto out;
Sage Weil16725b92009-10-06 11:31:07 -0700466
Sage Weil16725b92009-10-06 11:31:07 -0700467 /* path on server */
468 *path += 2;
469 dout("server path '%s'\n", *path);
470
471 /* parse mount options */
472 while ((c = strsep(&options, ",")) != NULL) {
473 int token, intval, ret;
474 if (!*c)
475 continue;
Sage Weil7b813c462009-10-26 22:07:53 -0700476 err = -EINVAL;
Sage Weil16725b92009-10-06 11:31:07 -0700477 token = match_token((char *)c, arg_tokens, argstr);
478 if (token < 0) {
479 pr_err("bad mount option at '%s'\n", c);
Sage Weil7b813c462009-10-26 22:07:53 -0700480 goto out;
Sage Weil16725b92009-10-06 11:31:07 -0700481 }
Sage Weile53c2fe2009-10-27 10:19:28 -0700482 if (token < Opt_last_int) {
Sage Weil16725b92009-10-06 11:31:07 -0700483 ret = match_int(&argstr[0], &intval);
484 if (ret < 0) {
485 pr_err("bad mount option arg (not int) "
486 "at '%s'\n", c);
487 continue;
488 }
Sage Weile53c2fe2009-10-27 10:19:28 -0700489 dout("got int token %d val %d\n", token, intval);
490 } else if (token > Opt_last_int && token < Opt_last_string) {
491 dout("got string token %d val %s\n", token,
492 argstr[0].from);
493 } else {
494 dout("got token %d\n", token);
Sage Weil16725b92009-10-06 11:31:07 -0700495 }
496 switch (token) {
Sage Weil16725b92009-10-06 11:31:07 -0700497 case Opt_ip:
498 err = ceph_parse_ips(argstr[0].from,
499 argstr[0].to,
500 &args->my_addr,
501 1, NULL);
502 if (err < 0)
Sage Weil6b805182009-10-27 11:50:50 -0700503 goto out;
Sage Weil16725b92009-10-06 11:31:07 -0700504 args->flags |= CEPH_OPT_MYIP;
505 break;
506
Sage Weilc309f0a2010-06-30 21:34:01 -0700507 case Opt_fsid:
508 err = parse_fsid(argstr[0].from, &args->fsid);
509 if (err == 0)
510 args->flags |= CEPH_OPT_FSID;
511 break;
Sage Weil16725b92009-10-06 11:31:07 -0700512 case Opt_snapdirname:
513 kfree(args->snapdir_name);
514 args->snapdir_name = kstrndup(argstr[0].from,
515 argstr[0].to-argstr[0].from,
516 GFP_KERNEL);
517 break;
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800518 case Opt_name:
519 args->name = kstrndup(argstr[0].from,
520 argstr[0].to-argstr[0].from,
521 GFP_KERNEL);
522 break;
Sage Weil16725b92009-10-06 11:31:07 -0700523 case Opt_secret:
524 args->secret = kstrndup(argstr[0].from,
525 argstr[0].to-argstr[0].from,
526 GFP_KERNEL);
527 break;
528
529 /* misc */
530 case Opt_wsize:
531 args->wsize = intval;
532 break;
533 case Opt_rsize:
534 args->rsize = intval;
535 break;
536 case Opt_osdtimeout:
537 args->osd_timeout = intval;
538 break;
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -0800539 case Opt_osdkeepalivetimeout:
540 args->osd_keepalive_timeout = intval;
541 break;
Sage Weil16725b92009-10-06 11:31:07 -0700542 case Opt_mount_timeout:
543 args->mount_timeout = intval;
544 break;
545 case Opt_caps_wanted_delay_min:
546 args->caps_wanted_delay_min = intval;
547 break;
548 case Opt_caps_wanted_delay_max:
549 args->caps_wanted_delay_max = intval;
550 break;
551 case Opt_readdir_max_entries:
552 args->max_readdir = intval;
553 break;
Sage Weil23804d92010-05-14 13:06:30 -0700554 case Opt_readdir_max_bytes:
555 args->max_readdir_bytes = intval;
556 break;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800557 case Opt_congestion_kb:
558 args->congestion_kb = intval;
559 break;
Sage Weil16725b92009-10-06 11:31:07 -0700560
561 case Opt_noshare:
562 args->flags |= CEPH_OPT_NOSHARE;
563 break;
564
565 case Opt_dirstat:
566 args->flags |= CEPH_OPT_DIRSTAT;
567 break;
568 case Opt_nodirstat:
569 args->flags &= ~CEPH_OPT_DIRSTAT;
570 break;
571 case Opt_rbytes:
572 args->flags |= CEPH_OPT_RBYTES;
573 break;
574 case Opt_norbytes:
575 args->flags &= ~CEPH_OPT_RBYTES;
576 break;
577 case Opt_nocrc:
578 args->flags |= CEPH_OPT_NOCRC;
579 break;
580 case Opt_noasyncreaddir:
581 args->flags |= CEPH_OPT_NOASYNCREADDIR;
582 break;
583
584 default:
585 BUG_ON(token);
586 }
587 }
Sage Weil6b805182009-10-27 11:50:50 -0700588 return args;
Sage Weil16725b92009-10-06 11:31:07 -0700589
Sage Weil7b813c462009-10-26 22:07:53 -0700590out:
Sage Weil6b805182009-10-27 11:50:50 -0700591 kfree(args->mon_addr);
592 kfree(args);
593 return ERR_PTR(err);
Sage Weil16725b92009-10-06 11:31:07 -0700594}
595
Sage Weil6b805182009-10-27 11:50:50 -0700596static void destroy_mount_args(struct ceph_mount_args *args)
Sage Weil16725b92009-10-06 11:31:07 -0700597{
Sage Weil6b805182009-10-27 11:50:50 -0700598 dout("destroy_mount_args %p\n", args);
Sage Weil16725b92009-10-06 11:31:07 -0700599 kfree(args->snapdir_name);
600 args->snapdir_name = NULL;
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800601 kfree(args->name);
602 args->name = NULL;
Sage Weil16725b92009-10-06 11:31:07 -0700603 kfree(args->secret);
604 args->secret = NULL;
Sage Weil6b805182009-10-27 11:50:50 -0700605 kfree(args);
Sage Weil16725b92009-10-06 11:31:07 -0700606}
607
608/*
609 * create a fresh client instance
610 */
Sage Weil6b805182009-10-27 11:50:50 -0700611static struct ceph_client *ceph_create_client(struct ceph_mount_args *args)
Sage Weil16725b92009-10-06 11:31:07 -0700612{
613 struct ceph_client *client;
614 int err = -ENOMEM;
615
616 client = kzalloc(sizeof(*client), GFP_KERNEL);
617 if (client == NULL)
618 return ERR_PTR(-ENOMEM);
619
620 mutex_init(&client->mount_mutex);
621
Sage Weil9bd2e6f2010-02-02 16:21:06 -0800622 init_waitqueue_head(&client->auth_wq);
Sage Weil16725b92009-10-06 11:31:07 -0700623
624 client->sb = NULL;
625 client->mount_state = CEPH_MOUNT_MOUNTING;
Sage Weil6b805182009-10-27 11:50:50 -0700626 client->mount_args = args;
Sage Weil16725b92009-10-06 11:31:07 -0700627
628 client->msgr = NULL;
629
Sage Weil9bd2e6f2010-02-02 16:21:06 -0800630 client->auth_err = 0;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800631 atomic_long_set(&client->writeback_count, 0);
Sage Weil16725b92009-10-06 11:31:07 -0700632
Sage Weil859e7b12009-11-02 09:32:47 -0800633 err = bdi_init(&client->backing_dev_info);
634 if (err < 0)
635 goto fail;
636
Sage Weil16725b92009-10-06 11:31:07 -0700637 err = -ENOMEM;
638 client->wb_wq = create_workqueue("ceph-writeback");
639 if (client->wb_wq == NULL)
Sage Weil859e7b12009-11-02 09:32:47 -0800640 goto fail_bdi;
Sage Weil16725b92009-10-06 11:31:07 -0700641 client->pg_inv_wq = create_singlethread_workqueue("ceph-pg-invalid");
642 if (client->pg_inv_wq == NULL)
643 goto fail_wb_wq;
644 client->trunc_wq = create_singlethread_workqueue("ceph-trunc");
645 if (client->trunc_wq == NULL)
646 goto fail_pg_inv_wq;
647
Sage Weilb9bfb932009-11-18 15:08:44 -0800648 /* set up mempools */
649 err = -ENOMEM;
650 client->wb_pagevec_pool = mempool_create_kmalloc_pool(10,
651 client->mount_args->wsize >> PAGE_CACHE_SHIFT);
652 if (!client->wb_pagevec_pool)
653 goto fail_trunc_wq;
654
Sage Weil85ccce42010-02-17 10:02:43 -0800655 /* caps */
656 client->min_caps = args->max_readdir;
Sage Weilb9bfb932009-11-18 15:08:44 -0800657
Sage Weil16725b92009-10-06 11:31:07 -0700658 /* subsystems */
659 err = ceph_monc_init(&client->monc, client);
660 if (err < 0)
Sage Weilb9bfb932009-11-18 15:08:44 -0800661 goto fail_mempool;
Sage Weil16725b92009-10-06 11:31:07 -0700662 err = ceph_osdc_init(&client->osdc, client);
663 if (err < 0)
664 goto fail_monc;
Sage Weil5f44f142009-11-18 14:52:18 -0800665 err = ceph_mdsc_init(&client->mdsc, client);
666 if (err < 0)
667 goto fail_osdc;
Sage Weil16725b92009-10-06 11:31:07 -0700668 return client;
669
Sage Weil5f44f142009-11-18 14:52:18 -0800670fail_osdc:
671 ceph_osdc_stop(&client->osdc);
Sage Weil16725b92009-10-06 11:31:07 -0700672fail_monc:
673 ceph_monc_stop(&client->monc);
Sage Weilb9bfb932009-11-18 15:08:44 -0800674fail_mempool:
675 mempool_destroy(client->wb_pagevec_pool);
Sage Weil16725b92009-10-06 11:31:07 -0700676fail_trunc_wq:
677 destroy_workqueue(client->trunc_wq);
678fail_pg_inv_wq:
679 destroy_workqueue(client->pg_inv_wq);
680fail_wb_wq:
681 destroy_workqueue(client->wb_wq);
Sage Weil859e7b12009-11-02 09:32:47 -0800682fail_bdi:
683 bdi_destroy(&client->backing_dev_info);
Sage Weil16725b92009-10-06 11:31:07 -0700684fail:
685 kfree(client);
686 return ERR_PTR(err);
687}
688
689static void ceph_destroy_client(struct ceph_client *client)
690{
691 dout("destroy_client %p\n", client);
692
693 /* unmount */
694 ceph_mdsc_stop(&client->mdsc);
Sage Weil16725b92009-10-06 11:31:07 -0700695 ceph_osdc_stop(&client->osdc);
696
Sage Weila922d382010-05-29 09:41:23 -0700697 /*
698 * make sure mds and osd connections close out before destroying
699 * the auth module, which is needed to free those connections'
700 * ceph_authorizers.
701 */
702 ceph_msgr_flush();
703
704 ceph_monc_stop(&client->monc);
705
Sage Weil16725b92009-10-06 11:31:07 -0700706 ceph_debugfs_client_cleanup(client);
707 destroy_workqueue(client->wb_wq);
708 destroy_workqueue(client->pg_inv_wq);
709 destroy_workqueue(client->trunc_wq);
710
Sage Weil5dfc5892010-05-04 16:14:46 -0700711 bdi_destroy(&client->backing_dev_info);
712
Sage Weil16725b92009-10-06 11:31:07 -0700713 if (client->msgr)
714 ceph_messenger_destroy(client->msgr);
Sage Weilb9bfb932009-11-18 15:08:44 -0800715 mempool_destroy(client->wb_pagevec_pool);
Sage Weil16725b92009-10-06 11:31:07 -0700716
Sage Weil6b805182009-10-27 11:50:50 -0700717 destroy_mount_args(client->mount_args);
Sage Weil16725b92009-10-06 11:31:07 -0700718
719 kfree(client);
720 dout("destroy_client %p done\n", client);
721}
722
723/*
Sage Weil07433042009-11-18 16:50:41 -0800724 * Initially learn our fsid, or verify an fsid matches.
725 */
726int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid)
727{
728 if (client->have_fsid) {
729 if (ceph_fsid_compare(&client->fsid, fsid)) {
Sage Weila8b763a2010-07-08 13:00:18 -0700730 pr_err("bad fsid, had %pU got %pU",
731 &client->fsid, fsid);
Sage Weil07433042009-11-18 16:50:41 -0800732 return -1;
733 }
734 } else {
Sage Weila8b763a2010-07-08 13:00:18 -0700735 pr_info("client%lld fsid %pU\n", client->monc.auth->global_id,
736 fsid);
Sage Weil07433042009-11-18 16:50:41 -0800737 memcpy(&client->fsid, fsid, sizeof(*fsid));
738 ceph_debugfs_client_init(client);
739 client->have_fsid = true;
740 }
741 return 0;
742}
743
744/*
Sage Weil16725b92009-10-06 11:31:07 -0700745 * true if we have the mon map (and have thus joined the cluster)
746 */
Sage Weil6822d002010-04-07 11:23:20 -0700747static int have_mon_and_osd_map(struct ceph_client *client)
Sage Weil16725b92009-10-06 11:31:07 -0700748{
Sage Weil6822d002010-04-07 11:23:20 -0700749 return client->monc.monmap && client->monc.monmap->epoch &&
750 client->osdc.osdmap && client->osdc.osdmap->epoch;
Sage Weil16725b92009-10-06 11:31:07 -0700751}
752
753/*
754 * Bootstrap mount by opening the root directory. Note the mount
755 * @started time from caller, and time out if this takes too long.
756 */
757static struct dentry *open_root_dentry(struct ceph_client *client,
758 const char *path,
759 unsigned long started)
760{
761 struct ceph_mds_client *mdsc = &client->mdsc;
762 struct ceph_mds_request *req = NULL;
763 int err;
764 struct dentry *root;
765
766 /* open dir */
767 dout("open_root_inode opening '%s'\n", path);
768 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_GETATTR, USE_ANY_MDS);
769 if (IS_ERR(req))
Julia Lawall7e34bc52010-05-22 12:01:14 +0200770 return ERR_CAST(req);
Sage Weil16725b92009-10-06 11:31:07 -0700771 req->r_path1 = kstrdup(path, GFP_NOFS);
772 req->r_ino1.ino = CEPH_INO_ROOT;
773 req->r_ino1.snap = CEPH_NOSNAP;
774 req->r_started = started;
Sage Weil6b805182009-10-27 11:50:50 -0700775 req->r_timeout = client->mount_args->mount_timeout * HZ;
Sage Weil16725b92009-10-06 11:31:07 -0700776 req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INODE);
777 req->r_num_caps = 2;
778 err = ceph_mdsc_do_request(mdsc, NULL, req);
779 if (err == 0) {
780 dout("open_root_inode success\n");
781 if (ceph_ino(req->r_target_inode) == CEPH_INO_ROOT &&
782 client->sb->s_root == NULL)
783 root = d_alloc_root(req->r_target_inode);
784 else
785 root = d_obtain_alias(req->r_target_inode);
786 req->r_target_inode = NULL;
787 dout("open_root_inode success, root dentry is %p\n", root);
788 } else {
789 root = ERR_PTR(err);
790 }
791 ceph_mdsc_put_request(req);
792 return root;
793}
794
795/*
796 * mount: join the ceph cluster, and open root directory.
797 */
798static int ceph_mount(struct ceph_client *client, struct vfsmount *mnt,
799 const char *path)
800{
801 struct ceph_entity_addr *myaddr = NULL;
802 int err;
Sage Weil6b805182009-10-27 11:50:50 -0700803 unsigned long timeout = client->mount_args->mount_timeout * HZ;
Sage Weil16725b92009-10-06 11:31:07 -0700804 unsigned long started = jiffies; /* note the start time */
805 struct dentry *root;
806
807 dout("mount start\n");
808 mutex_lock(&client->mount_mutex);
809
810 /* initialize the messenger */
811 if (client->msgr == NULL) {
812 if (ceph_test_opt(client, MYIP))
Sage Weil6b805182009-10-27 11:50:50 -0700813 myaddr = &client->mount_args->my_addr;
Sage Weil16725b92009-10-06 11:31:07 -0700814 client->msgr = ceph_messenger_create(myaddr);
815 if (IS_ERR(client->msgr)) {
816 err = PTR_ERR(client->msgr);
817 client->msgr = NULL;
818 goto out;
819 }
820 client->msgr->nocrc = ceph_test_opt(client, NOCRC);
821 }
822
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800823 /* open session, and wait for mon, mds, and osd maps */
824 err = ceph_monc_open_session(&client->monc);
Sage Weil16725b92009-10-06 11:31:07 -0700825 if (err < 0)
826 goto out;
827
Sage Weil6822d002010-04-07 11:23:20 -0700828 while (!have_mon_and_osd_map(client)) {
Sage Weil16725b92009-10-06 11:31:07 -0700829 err = -EIO;
830 if (timeout && time_after_eq(jiffies, started + timeout))
831 goto out;
832
833 /* wait */
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800834 dout("mount waiting for mon_map\n");
Sage Weil9bd2e6f2010-02-02 16:21:06 -0800835 err = wait_event_interruptible_timeout(client->auth_wq,
Sage Weil6822d002010-04-07 11:23:20 -0700836 have_mon_and_osd_map(client) || (client->auth_err < 0),
837 timeout);
Sage Weil16725b92009-10-06 11:31:07 -0700838 if (err == -EINTR || err == -ERESTARTSYS)
839 goto out;
Sage Weil9bd2e6f2010-02-02 16:21:06 -0800840 if (client->auth_err < 0) {
841 err = client->auth_err;
Yehuda Sadehdc146572009-11-20 13:59:13 -0800842 goto out;
843 }
Sage Weil16725b92009-10-06 11:31:07 -0700844 }
845
846 dout("mount opening root\n");
847 root = open_root_dentry(client, "", started);
848 if (IS_ERR(root)) {
849 err = PTR_ERR(root);
850 goto out;
851 }
852 if (client->sb->s_root)
853 dput(root);
854 else
855 client->sb->s_root = root;
856
857 if (path[0] == 0) {
858 dget(root);
859 } else {
860 dout("mount opening base mountpoint\n");
861 root = open_root_dentry(client, path, started);
862 if (IS_ERR(root)) {
863 err = PTR_ERR(root);
864 dput(client->sb->s_root);
865 client->sb->s_root = NULL;
866 goto out;
867 }
868 }
869
870 mnt->mnt_root = root;
871 mnt->mnt_sb = client->sb;
872
873 client->mount_state = CEPH_MOUNT_MOUNTED;
874 dout("mount success\n");
875 err = 0;
876
877out:
878 mutex_unlock(&client->mount_mutex);
879 return err;
880}
881
882static int ceph_set_super(struct super_block *s, void *data)
883{
884 struct ceph_client *client = data;
885 int ret;
886
887 dout("set_super %p data %p\n", s, data);
888
Sage Weil6b805182009-10-27 11:50:50 -0700889 s->s_flags = client->mount_args->sb_flags;
Sage Weil16725b92009-10-06 11:31:07 -0700890 s->s_maxbytes = 1ULL << 40; /* temp value until we get mdsmap */
891
892 s->s_fs_info = client;
893 client->sb = s;
894
895 s->s_op = &ceph_super_ops;
896 s->s_export_op = &ceph_export_ops;
897
898 s->s_time_gran = 1000; /* 1000 ns == 1 us */
899
900 ret = set_anon_super(s, NULL); /* what is that second arg for? */
901 if (ret != 0)
902 goto fail;
903
904 return ret;
905
906fail:
907 s->s_fs_info = NULL;
908 client->sb = NULL;
909 return ret;
910}
911
912/*
913 * share superblock if same fs AND options
914 */
915static int ceph_compare_super(struct super_block *sb, void *data)
916{
917 struct ceph_client *new = data;
Sage Weil6b805182009-10-27 11:50:50 -0700918 struct ceph_mount_args *args = new->mount_args;
Sage Weil16725b92009-10-06 11:31:07 -0700919 struct ceph_client *other = ceph_sb_to_client(sb);
920 int i;
921
922 dout("ceph_compare_super %p\n", sb);
923 if (args->flags & CEPH_OPT_FSID) {
924 if (ceph_fsid_compare(&args->fsid, &other->fsid)) {
925 dout("fsid doesn't match\n");
926 return 0;
927 }
928 } else {
929 /* do we share (a) monitor? */
930 for (i = 0; i < new->monc.monmap->num_mon; i++)
931 if (ceph_monmap_contains(other->monc.monmap,
932 &new->monc.monmap->mon_inst[i].addr))
933 break;
934 if (i == new->monc.monmap->num_mon) {
935 dout("mon ip not part of monmap\n");
936 return 0;
937 }
938 dout("mon ip matches existing sb %p\n", sb);
939 }
Sage Weil6b805182009-10-27 11:50:50 -0700940 if (args->sb_flags != other->mount_args->sb_flags) {
Sage Weil16725b92009-10-06 11:31:07 -0700941 dout("flags differ\n");
942 return 0;
943 }
944 return 1;
945}
946
947/*
948 * construct our own bdi so we can control readahead, etc.
949 */
Jeff Mahoney00d56432010-06-10 11:13:58 -0400950static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
Sage Weil31e0cf82010-05-04 16:39:35 -0700951
Sage Weil859e7b12009-11-02 09:32:47 -0800952static int ceph_register_bdi(struct super_block *sb, struct ceph_client *client)
Sage Weil16725b92009-10-06 11:31:07 -0700953{
954 int err;
955
Sage Weil16725b92009-10-06 11:31:07 -0700956 /* set ra_pages based on rsize mount option? */
Sage Weil6b805182009-10-27 11:50:50 -0700957 if (client->mount_args->rsize >= PAGE_CACHE_SIZE)
Sage Weil16725b92009-10-06 11:31:07 -0700958 client->backing_dev_info.ra_pages =
Sage Weil6b805182009-10-27 11:50:50 -0700959 (client->mount_args->rsize + PAGE_CACHE_SIZE - 1)
Sage Weil16725b92009-10-06 11:31:07 -0700960 >> PAGE_SHIFT;
Sage Weil31e0cf82010-05-04 16:39:35 -0700961 err = bdi_register(&client->backing_dev_info, NULL, "ceph-%d",
962 atomic_long_inc_return(&bdi_seq));
Sage Weil5dfc5892010-05-04 16:14:46 -0700963 if (!err)
964 sb->s_bdi = &client->backing_dev_info;
Sage Weil16725b92009-10-06 11:31:07 -0700965 return err;
966}
967
968static int ceph_get_sb(struct file_system_type *fs_type,
969 int flags, const char *dev_name, void *data,
970 struct vfsmount *mnt)
971{
972 struct super_block *sb;
973 struct ceph_client *client;
974 int err;
975 int (*compare_super)(struct super_block *, void *) = ceph_compare_super;
Sage Weil6a18be12009-11-04 11:40:05 -0800976 const char *path = NULL;
Sage Weil6b805182009-10-27 11:50:50 -0700977 struct ceph_mount_args *args;
Sage Weil16725b92009-10-06 11:31:07 -0700978
979 dout("ceph_get_sb\n");
Sage Weil6b805182009-10-27 11:50:50 -0700980 args = parse_mount_args(flags, data, dev_name, &path);
981 if (IS_ERR(args)) {
982 err = PTR_ERR(args);
983 goto out_final;
984 }
Sage Weil16725b92009-10-06 11:31:07 -0700985
986 /* create client (which we may/may not use) */
Sage Weil6b805182009-10-27 11:50:50 -0700987 client = ceph_create_client(args);
988 if (IS_ERR(client)) {
989 err = PTR_ERR(client);
990 goto out_final;
991 }
Sage Weil16725b92009-10-06 11:31:07 -0700992
Sage Weil6b805182009-10-27 11:50:50 -0700993 if (client->mount_args->flags & CEPH_OPT_NOSHARE)
Sage Weil16725b92009-10-06 11:31:07 -0700994 compare_super = NULL;
995 sb = sget(fs_type, compare_super, ceph_set_super, client);
996 if (IS_ERR(sb)) {
997 err = PTR_ERR(sb);
998 goto out;
999 }
1000
Cheng Renquan640ef792010-03-26 17:40:33 +08001001 if (ceph_sb_to_client(sb) != client) {
Sage Weil16725b92009-10-06 11:31:07 -07001002 ceph_destroy_client(client);
Cheng Renquan640ef792010-03-26 17:40:33 +08001003 client = ceph_sb_to_client(sb);
Sage Weil16725b92009-10-06 11:31:07 -07001004 dout("get_sb got existing client %p\n", client);
1005 } else {
1006 dout("get_sb using new client %p\n", client);
Sage Weil859e7b12009-11-02 09:32:47 -08001007 err = ceph_register_bdi(sb, client);
Sage Weil16725b92009-10-06 11:31:07 -07001008 if (err < 0)
1009 goto out_splat;
1010 }
1011
1012 err = ceph_mount(client, mnt, path);
1013 if (err < 0)
1014 goto out_splat;
1015 dout("root %p inode %p ino %llx.%llx\n", mnt->mnt_root,
1016 mnt->mnt_root->d_inode, ceph_vinop(mnt->mnt_root->d_inode));
1017 return 0;
1018
1019out_splat:
1020 ceph_mdsc_close_sessions(&client->mdsc);
Al Viro3981f2e2010-03-21 19:22:29 -04001021 deactivate_locked_super(sb);
Sage Weil16725b92009-10-06 11:31:07 -07001022 goto out_final;
1023
1024out:
1025 ceph_destroy_client(client);
1026out_final:
1027 dout("ceph_get_sb fail %d\n", err);
1028 return err;
1029}
1030
1031static void ceph_kill_sb(struct super_block *s)
1032{
1033 struct ceph_client *client = ceph_sb_to_client(s);
1034 dout("kill_sb %p\n", s);
1035 ceph_mdsc_pre_umount(&client->mdsc);
Sage Weil16725b92009-10-06 11:31:07 -07001036 kill_anon_super(s); /* will call put_super after sb is r/o */
Sage Weil16725b92009-10-06 11:31:07 -07001037 ceph_destroy_client(client);
1038}
1039
1040static struct file_system_type ceph_fs_type = {
1041 .owner = THIS_MODULE,
1042 .name = "ceph",
1043 .get_sb = ceph_get_sb,
1044 .kill_sb = ceph_kill_sb,
1045 .fs_flags = FS_RENAME_DOES_D_MOVE,
1046};
1047
1048#define _STRINGIFY(x) #x
1049#define STRINGIFY(x) _STRINGIFY(x)
1050
1051static int __init init_ceph(void)
1052{
1053 int ret = 0;
1054
1055 ret = ceph_debugfs_init();
1056 if (ret < 0)
1057 goto out;
1058
1059 ret = ceph_msgr_init();
1060 if (ret < 0)
1061 goto out_debugfs;
1062
1063 ret = init_caches();
1064 if (ret)
1065 goto out_msgr;
1066
Sage Weil16725b92009-10-06 11:31:07 -07001067 ret = register_filesystem(&ceph_fs_type);
1068 if (ret)
1069 goto out_icache;
1070
Sage Weilc8f16582010-04-19 13:50:26 -07001071 pr_info("loaded (mon/mds/osd proto %d/%d/%d, osdmap %d/%d %d/%d)\n",
1072 CEPH_MONC_PROTOCOL, CEPH_MDSC_PROTOCOL, CEPH_OSDC_PROTOCOL,
1073 CEPH_OSDMAP_VERSION, CEPH_OSDMAP_VERSION_EXT,
1074 CEPH_OSDMAP_INC_VERSION, CEPH_OSDMAP_INC_VERSION_EXT);
Sage Weil16725b92009-10-06 11:31:07 -07001075 return 0;
1076
1077out_icache:
1078 destroy_caches();
1079out_msgr:
1080 ceph_msgr_exit();
1081out_debugfs:
1082 ceph_debugfs_cleanup();
1083out:
1084 return ret;
1085}
1086
1087static void __exit exit_ceph(void)
1088{
1089 dout("exit_ceph\n");
1090 unregister_filesystem(&ceph_fs_type);
Sage Weil16725b92009-10-06 11:31:07 -07001091 destroy_caches();
1092 ceph_msgr_exit();
1093 ceph_debugfs_cleanup();
1094}
1095
1096module_init(init_ceph);
1097module_exit(exit_ceph);
1098
1099MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
1100MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
1101MODULE_AUTHOR("Patience Warnick <patience@newdream.net>");
1102MODULE_DESCRIPTION("Ceph filesystem for Linux");
1103MODULE_LICENSE("GPL");