2 #include "ceph_debug.h"
4 #include <linux/backing-dev.h>
6 #include <linux/inet.h>
8 #include <linux/module.h>
9 #include <linux/mount.h>
10 #include <linux/parser.h>
11 #include <linux/rwsem.h>
12 #include <linux/sched.h>
13 #include <linux/seq_file.h>
14 #include <linux/slab.h>
15 #include <linux/statfs.h>
16 #include <linux/string.h>
17 #include <linux/version.h>
18 #include <linux/vmalloc.h>
22 #include "mon_client.h"
26 * Ceph superblock operations
28 * Handle the basics of mounting, unmounting.
33 * find filename portion of a path (/foo/bar/baz -> baz)
35 const char *ceph_file_part(const char *s
, int len
)
37 const char *e
= s
+ len
;
39 while (e
!= s
&& *(e
-1) != '/')
48 static void ceph_put_super(struct super_block
*s
)
50 struct ceph_client
*cl
= ceph_client(s
);
53 ceph_mdsc_close_sessions(&cl
->mdsc
);
57 static int ceph_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
59 struct ceph_client
*client
= ceph_inode_to_client(dentry
->d_inode
);
60 struct ceph_monmap
*monmap
= client
->monc
.monmap
;
61 struct ceph_statfs st
;
66 err
= ceph_monc_do_statfs(&client
->monc
, &st
);
71 buf
->f_type
= CEPH_SUPER_MAGIC
; /* ?? */
74 * express utilization in terms of large blocks to avoid
75 * overflow on 32-bit machines.
77 buf
->f_bsize
= 1 << CEPH_BLOCK_SHIFT
;
78 buf
->f_blocks
= le64_to_cpu(st
.kb
) >> (CEPH_BLOCK_SHIFT
-10);
79 buf
->f_bfree
= (le64_to_cpu(st
.kb
) - le64_to_cpu(st
.kb_used
)) >>
80 (CEPH_BLOCK_SHIFT
-10);
81 buf
->f_bavail
= le64_to_cpu(st
.kb_avail
) >> (CEPH_BLOCK_SHIFT
-10);
83 buf
->f_files
= le64_to_cpu(st
.num_objects
);
85 buf
->f_namelen
= PATH_MAX
;
86 buf
->f_frsize
= PAGE_CACHE_SIZE
;
88 /* leave fsid little-endian, regardless of host endianness */
89 fsid
= *(u64
*)(&monmap
->fsid
) ^ *((u64
*)&monmap
->fsid
+ 1);
90 buf
->f_fsid
.val
[0] = fsid
& 0xffffffff;
91 buf
->f_fsid
.val
[1] = fsid
>> 32;
97 static int ceph_syncfs(struct super_block
*sb
, int wait
)
99 dout("sync_fs %d\n", wait
);
100 ceph_osdc_sync(&ceph_client(sb
)->osdc
);
101 ceph_mdsc_sync(&ceph_client(sb
)->mdsc
);
102 dout("sync_fs %d done\n", wait
);
108 * ceph_show_options - Show mount options in /proc/mounts
109 * @m: seq_file to write to
110 * @mnt: mount descriptor
112 static int ceph_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
114 struct ceph_client
*client
= ceph_sb_to_client(mnt
->mnt_sb
);
115 struct ceph_mount_args
*args
= client
->mount_args
;
117 if (args
->flags
& CEPH_OPT_FSID
)
118 seq_printf(m
, ",fsidmajor=%llu,fsidminor%llu",
119 le64_to_cpu(*(__le64
*)&args
->fsid
.fsid
[0]),
120 le64_to_cpu(*(__le64
*)&args
->fsid
.fsid
[8]));
121 if (args
->flags
& CEPH_OPT_NOSHARE
)
122 seq_puts(m
, ",noshare");
123 if (args
->flags
& CEPH_OPT_DIRSTAT
)
124 seq_puts(m
, ",dirstat");
125 if ((args
->flags
& CEPH_OPT_RBYTES
) == 0)
126 seq_puts(m
, ",norbytes");
127 if (args
->flags
& CEPH_OPT_NOCRC
)
128 seq_puts(m
, ",nocrc");
129 if (args
->flags
& CEPH_OPT_NOASYNCREADDIR
)
130 seq_puts(m
, ",noasyncreaddir");
131 if (strcmp(args
->snapdir_name
, CEPH_SNAPDIRNAME_DEFAULT
))
132 seq_printf(m
, ",snapdirname=%s", args
->snapdir_name
);
134 seq_printf(m
, ",name=%s", args
->name
);
136 seq_puts(m
, ",secret=<hidden>");
143 struct kmem_cache
*ceph_inode_cachep
;
144 struct kmem_cache
*ceph_cap_cachep
;
145 struct kmem_cache
*ceph_dentry_cachep
;
146 struct kmem_cache
*ceph_file_cachep
;
148 static void ceph_inode_init_once(void *foo
)
150 struct ceph_inode_info
*ci
= foo
;
151 inode_init_once(&ci
->vfs_inode
);
154 static int default_congestion_kb(void)
161 * congestion size, scale with available memory.
173 * This allows larger machines to have larger/more transfers.
174 * Limit the default to 256M
176 congestion_kb
= (16*int_sqrt(totalram_pages
)) << (PAGE_SHIFT
-10);
177 if (congestion_kb
> 256*1024)
178 congestion_kb
= 256*1024;
180 return congestion_kb
;
183 static int __init
init_caches(void)
185 ceph_inode_cachep
= kmem_cache_create("ceph_inode_info",
186 sizeof(struct ceph_inode_info
),
187 __alignof__(struct ceph_inode_info
),
188 (SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
),
189 ceph_inode_init_once
);
190 if (ceph_inode_cachep
== NULL
)
193 ceph_cap_cachep
= KMEM_CACHE(ceph_cap
,
194 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
);
195 if (ceph_cap_cachep
== NULL
)
198 ceph_dentry_cachep
= KMEM_CACHE(ceph_dentry_info
,
199 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
);
200 if (ceph_dentry_cachep
== NULL
)
203 ceph_file_cachep
= KMEM_CACHE(ceph_file_info
,
204 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
);
205 if (ceph_file_cachep
== NULL
)
211 kmem_cache_destroy(ceph_dentry_cachep
);
213 kmem_cache_destroy(ceph_cap_cachep
);
215 kmem_cache_destroy(ceph_inode_cachep
);
219 static void destroy_caches(void)
221 kmem_cache_destroy(ceph_inode_cachep
);
222 kmem_cache_destroy(ceph_cap_cachep
);
223 kmem_cache_destroy(ceph_dentry_cachep
);
224 kmem_cache_destroy(ceph_file_cachep
);
229 * ceph_umount_begin - initiate forced umount. Tear down down the
230 * mount, skipping steps that may hang while waiting for server(s).
232 static void ceph_umount_begin(struct super_block
*sb
)
234 struct ceph_client
*client
= ceph_sb_to_client(sb
);
236 dout("ceph_umount_begin - starting forced umount\n");
239 client
->mount_state
= CEPH_MOUNT_SHUTDOWN
;
243 static const struct super_operations ceph_super_ops
= {
244 .alloc_inode
= ceph_alloc_inode
,
245 .destroy_inode
= ceph_destroy_inode
,
246 .write_inode
= ceph_write_inode
,
247 .sync_fs
= ceph_syncfs
,
248 .put_super
= ceph_put_super
,
249 .show_options
= ceph_show_options
,
250 .statfs
= ceph_statfs
,
251 .umount_begin
= ceph_umount_begin
,
255 const char *ceph_msg_type_name(int type
)
258 case CEPH_MSG_SHUTDOWN
: return "shutdown";
259 case CEPH_MSG_PING
: return "ping";
260 case CEPH_MSG_AUTH
: return "auth";
261 case CEPH_MSG_AUTH_REPLY
: return "auth_reply";
262 case CEPH_MSG_MON_MAP
: return "mon_map";
263 case CEPH_MSG_MON_GET_MAP
: return "mon_get_map";
264 case CEPH_MSG_MON_SUBSCRIBE
: return "mon_subscribe";
265 case CEPH_MSG_MON_SUBSCRIBE_ACK
: return "mon_subscribe_ack";
266 case CEPH_MSG_STATFS
: return "statfs";
267 case CEPH_MSG_STATFS_REPLY
: return "statfs_reply";
268 case CEPH_MSG_MDS_MAP
: return "mds_map";
269 case CEPH_MSG_CLIENT_SESSION
: return "client_session";
270 case CEPH_MSG_CLIENT_RECONNECT
: return "client_reconnect";
271 case CEPH_MSG_CLIENT_REQUEST
: return "client_request";
272 case CEPH_MSG_CLIENT_REQUEST_FORWARD
: return "client_request_forward";
273 case CEPH_MSG_CLIENT_REPLY
: return "client_reply";
274 case CEPH_MSG_CLIENT_CAPS
: return "client_caps";
275 case CEPH_MSG_CLIENT_CAPRELEASE
: return "client_cap_release";
276 case CEPH_MSG_CLIENT_SNAP
: return "client_snap";
277 case CEPH_MSG_CLIENT_LEASE
: return "client_lease";
278 case CEPH_MSG_OSD_MAP
: return "osd_map";
279 case CEPH_MSG_OSD_OP
: return "osd_op";
280 case CEPH_MSG_OSD_OPREPLY
: return "osd_opreply";
281 default: return "unknown";
296 Opt_osdkeepalivetimeout
,
299 Opt_caps_wanted_delay_min
,
300 Opt_caps_wanted_delay_max
,
301 Opt_readdir_max_entries
,
309 /* string args above */
320 static match_table_t arg_tokens
= {
321 {Opt_fsidmajor
, "fsidmajor=%ld"},
322 {Opt_fsidminor
, "fsidminor=%ld"},
323 {Opt_monport
, "monport=%d"},
324 {Opt_wsize
, "wsize=%d"},
325 {Opt_rsize
, "rsize=%d"},
326 {Opt_osdtimeout
, "osdtimeout=%d"},
327 {Opt_osdkeepalivetimeout
, "osdkeepalive=%d"},
328 {Opt_mount_timeout
, "mount_timeout=%d"},
329 {Opt_osd_idle_ttl
, "osd_idle_ttl=%d"},
330 {Opt_caps_wanted_delay_min
, "caps_wanted_delay_min=%d"},
331 {Opt_caps_wanted_delay_max
, "caps_wanted_delay_max=%d"},
332 {Opt_readdir_max_entries
, "readdir_max_entries=%d"},
333 {Opt_congestion_kb
, "write_congestion_kb=%d"},
335 {Opt_snapdirname
, "snapdirname=%s"},
336 {Opt_name
, "name=%s"},
337 {Opt_secret
, "secret=%s"},
338 /* string args above */
340 {Opt_noshare
, "noshare"},
341 {Opt_dirstat
, "dirstat"},
342 {Opt_nodirstat
, "nodirstat"},
343 {Opt_rbytes
, "rbytes"},
344 {Opt_norbytes
, "norbytes"},
345 {Opt_nocrc
, "nocrc"},
346 {Opt_noasyncreaddir
, "noasyncreaddir"},
351 static struct ceph_mount_args
*parse_mount_args(int flags
, char *options
,
352 const char *dev_name
,
355 struct ceph_mount_args
*args
;
358 substring_t argstr
[MAX_OPT_ARGS
];
360 args
= kzalloc(sizeof(*args
), GFP_KERNEL
);
362 return ERR_PTR(-ENOMEM
);
363 args
->mon_addr
= kcalloc(CEPH_MAX_MON
, sizeof(*args
->mon_addr
),
368 dout("parse_mount_args %p, dev_name '%s'\n", args
, dev_name
);
370 /* start with defaults */
371 args
->sb_flags
= flags
;
372 args
->flags
= CEPH_OPT_DEFAULT
;
373 args
->osd_timeout
= CEPH_OSD_TIMEOUT_DEFAULT
;
374 args
->osd_keepalive_timeout
= CEPH_OSD_KEEPALIVE_DEFAULT
;
375 args
->mount_timeout
= CEPH_MOUNT_TIMEOUT_DEFAULT
; /* seconds */
376 args
->osd_idle_ttl
= CEPH_OSD_IDLE_TTL_DEFAULT
; /* seconds */
377 args
->caps_wanted_delay_min
= CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT
;
378 args
->caps_wanted_delay_max
= CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT
;
379 args
->rsize
= CEPH_MOUNT_RSIZE_DEFAULT
;
380 args
->snapdir_name
= kstrdup(CEPH_SNAPDIRNAME_DEFAULT
, GFP_KERNEL
);
381 args
->cap_release_safety
= CEPH_CAPS_PER_RELEASE
* 4;
382 args
->max_readdir
= 1024;
383 args
->congestion_kb
= default_congestion_kb();
385 /* ip1[:port1][,ip2[:port2]...]:/subdir/in/fs */
389 *path
= strstr(dev_name
, ":/");
391 pr_err("device name is missing path (no :/ in %s)\n",
397 err
= ceph_parse_ips(dev_name
, *path
, args
->mon_addr
,
398 CEPH_MAX_MON
, &args
->num_mon
);
404 dout("server path '%s'\n", *path
);
406 /* parse mount options */
407 while ((c
= strsep(&options
, ",")) != NULL
) {
408 int token
, intval
, ret
;
412 token
= match_token((char *)c
, arg_tokens
, argstr
);
414 pr_err("bad mount option at '%s'\n", c
);
417 if (token
< Opt_last_int
) {
418 ret
= match_int(&argstr
[0], &intval
);
420 pr_err("bad mount option arg (not int) "
424 dout("got int token %d val %d\n", token
, intval
);
425 } else if (token
> Opt_last_int
&& token
< Opt_last_string
) {
426 dout("got string token %d val %s\n", token
,
429 dout("got token %d\n", token
);
433 *(__le64
*)&args
->fsid
.fsid
[0] = cpu_to_le64(intval
);
436 *(__le64
*)&args
->fsid
.fsid
[8] = cpu_to_le64(intval
);
439 err
= ceph_parse_ips(argstr
[0].from
,
445 args
->flags
|= CEPH_OPT_MYIP
;
448 case Opt_snapdirname
:
449 kfree(args
->snapdir_name
);
450 args
->snapdir_name
= kstrndup(argstr
[0].from
,
451 argstr
[0].to
-argstr
[0].from
,
455 args
->name
= kstrndup(argstr
[0].from
,
456 argstr
[0].to
-argstr
[0].from
,
460 args
->secret
= kstrndup(argstr
[0].from
,
461 argstr
[0].to
-argstr
[0].from
,
467 args
->wsize
= intval
;
470 args
->rsize
= intval
;
473 args
->osd_timeout
= intval
;
475 case Opt_osdkeepalivetimeout
:
476 args
->osd_keepalive_timeout
= intval
;
478 case Opt_mount_timeout
:
479 args
->mount_timeout
= intval
;
481 case Opt_caps_wanted_delay_min
:
482 args
->caps_wanted_delay_min
= intval
;
484 case Opt_caps_wanted_delay_max
:
485 args
->caps_wanted_delay_max
= intval
;
487 case Opt_readdir_max_entries
:
488 args
->max_readdir
= intval
;
490 case Opt_congestion_kb
:
491 args
->congestion_kb
= intval
;
495 args
->flags
|= CEPH_OPT_NOSHARE
;
499 args
->flags
|= CEPH_OPT_DIRSTAT
;
502 args
->flags
&= ~CEPH_OPT_DIRSTAT
;
505 args
->flags
|= CEPH_OPT_RBYTES
;
508 args
->flags
&= ~CEPH_OPT_RBYTES
;
511 args
->flags
|= CEPH_OPT_NOCRC
;
513 case Opt_noasyncreaddir
:
514 args
->flags
|= CEPH_OPT_NOASYNCREADDIR
;
524 kfree(args
->mon_addr
);
529 static void destroy_mount_args(struct ceph_mount_args
*args
)
531 dout("destroy_mount_args %p\n", args
);
532 kfree(args
->snapdir_name
);
533 args
->snapdir_name
= NULL
;
542 * create a fresh client instance
544 static struct ceph_client
*ceph_create_client(struct ceph_mount_args
*args
)
546 struct ceph_client
*client
;
549 client
= kzalloc(sizeof(*client
), GFP_KERNEL
);
551 return ERR_PTR(-ENOMEM
);
553 mutex_init(&client
->mount_mutex
);
555 init_waitqueue_head(&client
->auth_wq
);
558 client
->mount_state
= CEPH_MOUNT_MOUNTING
;
559 client
->mount_args
= args
;
563 client
->auth_err
= 0;
564 atomic_long_set(&client
->writeback_count
, 0);
566 err
= bdi_init(&client
->backing_dev_info
);
571 client
->wb_wq
= create_workqueue("ceph-writeback");
572 if (client
->wb_wq
== NULL
)
574 client
->pg_inv_wq
= create_singlethread_workqueue("ceph-pg-invalid");
575 if (client
->pg_inv_wq
== NULL
)
577 client
->trunc_wq
= create_singlethread_workqueue("ceph-trunc");
578 if (client
->trunc_wq
== NULL
)
581 /* set up mempools */
583 client
->wb_pagevec_pool
= mempool_create_kmalloc_pool(10,
584 client
->mount_args
->wsize
>> PAGE_CACHE_SHIFT
);
585 if (!client
->wb_pagevec_pool
)
589 client
->min_caps
= args
->max_readdir
;
590 ceph_adjust_min_caps(client
->min_caps
);
593 err
= ceph_monc_init(&client
->monc
, client
);
596 err
= ceph_osdc_init(&client
->osdc
, client
);
599 err
= ceph_mdsc_init(&client
->mdsc
, client
);
605 ceph_osdc_stop(&client
->osdc
);
607 ceph_monc_stop(&client
->monc
);
609 mempool_destroy(client
->wb_pagevec_pool
);
611 destroy_workqueue(client
->trunc_wq
);
613 destroy_workqueue(client
->pg_inv_wq
);
615 destroy_workqueue(client
->wb_wq
);
617 bdi_destroy(&client
->backing_dev_info
);
623 static void ceph_destroy_client(struct ceph_client
*client
)
625 dout("destroy_client %p\n", client
);
628 ceph_mdsc_stop(&client
->mdsc
);
629 ceph_monc_stop(&client
->monc
);
630 ceph_osdc_stop(&client
->osdc
);
632 ceph_adjust_min_caps(-client
->min_caps
);
634 ceph_debugfs_client_cleanup(client
);
635 destroy_workqueue(client
->wb_wq
);
636 destroy_workqueue(client
->pg_inv_wq
);
637 destroy_workqueue(client
->trunc_wq
);
640 ceph_messenger_destroy(client
->msgr
);
641 mempool_destroy(client
->wb_pagevec_pool
);
643 destroy_mount_args(client
->mount_args
);
646 dout("destroy_client %p done\n", client
);
650 * Initially learn our fsid, or verify an fsid matches.
652 int ceph_check_fsid(struct ceph_client
*client
, struct ceph_fsid
*fsid
)
654 if (client
->have_fsid
) {
655 if (ceph_fsid_compare(&client
->fsid
, fsid
)) {
656 pr_err("bad fsid, had " FSID_FORMAT
" got " FSID_FORMAT
,
657 PR_FSID(&client
->fsid
), PR_FSID(fsid
));
661 pr_info("client%lld fsid " FSID_FORMAT
"\n",
662 client
->monc
.auth
->global_id
, PR_FSID(fsid
));
663 memcpy(&client
->fsid
, fsid
, sizeof(*fsid
));
664 ceph_debugfs_client_init(client
);
665 client
->have_fsid
= true;
671 * true if we have the mon map (and have thus joined the cluster)
673 static int have_mon_map(struct ceph_client
*client
)
675 return client
->monc
.monmap
&& client
->monc
.monmap
->epoch
;
679 * Bootstrap mount by opening the root directory. Note the mount
680 * @started time from caller, and time out if this takes too long.
682 static struct dentry
*open_root_dentry(struct ceph_client
*client
,
684 unsigned long started
)
686 struct ceph_mds_client
*mdsc
= &client
->mdsc
;
687 struct ceph_mds_request
*req
= NULL
;
692 dout("open_root_inode opening '%s'\n", path
);
693 req
= ceph_mdsc_create_request(mdsc
, CEPH_MDS_OP_GETATTR
, USE_ANY_MDS
);
695 return ERR_PTR(PTR_ERR(req
));
696 req
->r_path1
= kstrdup(path
, GFP_NOFS
);
697 req
->r_ino1
.ino
= CEPH_INO_ROOT
;
698 req
->r_ino1
.snap
= CEPH_NOSNAP
;
699 req
->r_started
= started
;
700 req
->r_timeout
= client
->mount_args
->mount_timeout
* HZ
;
701 req
->r_args
.getattr
.mask
= cpu_to_le32(CEPH_STAT_CAP_INODE
);
703 err
= ceph_mdsc_do_request(mdsc
, NULL
, req
);
705 dout("open_root_inode success\n");
706 if (ceph_ino(req
->r_target_inode
) == CEPH_INO_ROOT
&&
707 client
->sb
->s_root
== NULL
)
708 root
= d_alloc_root(req
->r_target_inode
);
710 root
= d_obtain_alias(req
->r_target_inode
);
711 req
->r_target_inode
= NULL
;
712 dout("open_root_inode success, root dentry is %p\n", root
);
716 ceph_mdsc_put_request(req
);
721 * mount: join the ceph cluster, and open root directory.
723 static int ceph_mount(struct ceph_client
*client
, struct vfsmount
*mnt
,
726 struct ceph_entity_addr
*myaddr
= NULL
;
728 unsigned long timeout
= client
->mount_args
->mount_timeout
* HZ
;
729 unsigned long started
= jiffies
; /* note the start time */
732 dout("mount start\n");
733 mutex_lock(&client
->mount_mutex
);
735 /* initialize the messenger */
736 if (client
->msgr
== NULL
) {
737 if (ceph_test_opt(client
, MYIP
))
738 myaddr
= &client
->mount_args
->my_addr
;
739 client
->msgr
= ceph_messenger_create(myaddr
);
740 if (IS_ERR(client
->msgr
)) {
741 err
= PTR_ERR(client
->msgr
);
745 client
->msgr
->nocrc
= ceph_test_opt(client
, NOCRC
);
748 /* open session, and wait for mon, mds, and osd maps */
749 err
= ceph_monc_open_session(&client
->monc
);
753 while (!have_mon_map(client
)) {
755 if (timeout
&& time_after_eq(jiffies
, started
+ timeout
))
759 dout("mount waiting for mon_map\n");
760 err
= wait_event_interruptible_timeout(client
->auth_wq
,
761 have_mon_map(client
) || (client
->auth_err
< 0),
763 if (err
== -EINTR
|| err
== -ERESTARTSYS
)
765 if (client
->auth_err
< 0) {
766 err
= client
->auth_err
;
771 dout("mount opening root\n");
772 root
= open_root_dentry(client
, "", started
);
777 if (client
->sb
->s_root
)
780 client
->sb
->s_root
= root
;
785 dout("mount opening base mountpoint\n");
786 root
= open_root_dentry(client
, path
, started
);
789 dput(client
->sb
->s_root
);
790 client
->sb
->s_root
= NULL
;
795 mnt
->mnt_root
= root
;
796 mnt
->mnt_sb
= client
->sb
;
798 client
->mount_state
= CEPH_MOUNT_MOUNTED
;
799 dout("mount success\n");
803 mutex_unlock(&client
->mount_mutex
);
807 static int ceph_set_super(struct super_block
*s
, void *data
)
809 struct ceph_client
*client
= data
;
812 dout("set_super %p data %p\n", s
, data
);
814 s
->s_flags
= client
->mount_args
->sb_flags
;
815 s
->s_maxbytes
= 1ULL << 40; /* temp value until we get mdsmap */
817 s
->s_fs_info
= client
;
820 s
->s_op
= &ceph_super_ops
;
821 s
->s_export_op
= &ceph_export_ops
;
823 s
->s_time_gran
= 1000; /* 1000 ns == 1 us */
825 ret
= set_anon_super(s
, NULL
); /* what is that second arg for? */
838 * share superblock if same fs AND options
840 static int ceph_compare_super(struct super_block
*sb
, void *data
)
842 struct ceph_client
*new = data
;
843 struct ceph_mount_args
*args
= new->mount_args
;
844 struct ceph_client
*other
= ceph_sb_to_client(sb
);
847 dout("ceph_compare_super %p\n", sb
);
848 if (args
->flags
& CEPH_OPT_FSID
) {
849 if (ceph_fsid_compare(&args
->fsid
, &other
->fsid
)) {
850 dout("fsid doesn't match\n");
854 /* do we share (a) monitor? */
855 for (i
= 0; i
< new->monc
.monmap
->num_mon
; i
++)
856 if (ceph_monmap_contains(other
->monc
.monmap
,
857 &new->monc
.monmap
->mon_inst
[i
].addr
))
859 if (i
== new->monc
.monmap
->num_mon
) {
860 dout("mon ip not part of monmap\n");
863 dout("mon ip matches existing sb %p\n", sb
);
865 if (args
->sb_flags
!= other
->mount_args
->sb_flags
) {
866 dout("flags differ\n");
873 * construct our own bdi so we can control readahead, etc.
875 static int ceph_register_bdi(struct super_block
*sb
, struct ceph_client
*client
)
879 sb
->s_bdi
= &client
->backing_dev_info
;
881 /* set ra_pages based on rsize mount option? */
882 if (client
->mount_args
->rsize
>= PAGE_CACHE_SIZE
)
883 client
->backing_dev_info
.ra_pages
=
884 (client
->mount_args
->rsize
+ PAGE_CACHE_SIZE
- 1)
886 err
= bdi_register_dev(&client
->backing_dev_info
, sb
->s_dev
);
890 static int ceph_get_sb(struct file_system_type
*fs_type
,
891 int flags
, const char *dev_name
, void *data
,
892 struct vfsmount
*mnt
)
894 struct super_block
*sb
;
895 struct ceph_client
*client
;
897 int (*compare_super
)(struct super_block
*, void *) = ceph_compare_super
;
898 const char *path
= NULL
;
899 struct ceph_mount_args
*args
;
901 dout("ceph_get_sb\n");
902 args
= parse_mount_args(flags
, data
, dev_name
, &path
);
908 /* create client (which we may/may not use) */
909 client
= ceph_create_client(args
);
910 if (IS_ERR(client
)) {
911 err
= PTR_ERR(client
);
915 if (client
->mount_args
->flags
& CEPH_OPT_NOSHARE
)
916 compare_super
= NULL
;
917 sb
= sget(fs_type
, compare_super
, ceph_set_super
, client
);
923 if (ceph_client(sb
) != client
) {
924 ceph_destroy_client(client
);
925 client
= ceph_client(sb
);
926 dout("get_sb got existing client %p\n", client
);
928 dout("get_sb using new client %p\n", client
);
929 err
= ceph_register_bdi(sb
, client
);
934 err
= ceph_mount(client
, mnt
, path
);
937 dout("root %p inode %p ino %llx.%llx\n", mnt
->mnt_root
,
938 mnt
->mnt_root
->d_inode
, ceph_vinop(mnt
->mnt_root
->d_inode
));
942 ceph_mdsc_close_sessions(&client
->mdsc
);
943 up_write(&sb
->s_umount
);
944 deactivate_super(sb
);
948 ceph_destroy_client(client
);
950 dout("ceph_get_sb fail %d\n", err
);
954 static void ceph_kill_sb(struct super_block
*s
)
956 struct ceph_client
*client
= ceph_sb_to_client(s
);
957 dout("kill_sb %p\n", s
);
958 ceph_mdsc_pre_umount(&client
->mdsc
);
959 kill_anon_super(s
); /* will call put_super after sb is r/o */
960 if (s
->s_bdi
== &client
->backing_dev_info
)
961 bdi_unregister(&client
->backing_dev_info
);
962 bdi_destroy(&client
->backing_dev_info
);
963 ceph_destroy_client(client
);
966 static struct file_system_type ceph_fs_type
= {
967 .owner
= THIS_MODULE
,
969 .get_sb
= ceph_get_sb
,
970 .kill_sb
= ceph_kill_sb
,
971 .fs_flags
= FS_RENAME_DOES_D_MOVE
,
974 #define _STRINGIFY(x) #x
975 #define STRINGIFY(x) _STRINGIFY(x)
977 static int __init
init_ceph(void)
981 ret
= ceph_debugfs_init();
985 ret
= ceph_msgr_init();
995 ret
= register_filesystem(&ceph_fs_type
);
999 pr_info("loaded %d.%d.%d (mon/mds/osd proto %d/%d/%d)\n",
1000 CEPH_VERSION_MAJOR
, CEPH_VERSION_MINOR
, CEPH_VERSION_PATCH
,
1001 CEPH_MONC_PROTOCOL
, CEPH_MDSC_PROTOCOL
, CEPH_OSDC_PROTOCOL
);
1009 ceph_debugfs_cleanup();
1014 static void __exit
exit_ceph(void)
1016 dout("exit_ceph\n");
1017 unregister_filesystem(&ceph_fs_type
);
1018 ceph_caps_finalize();
1021 ceph_debugfs_cleanup();
1024 module_init(init_ceph
);
1025 module_exit(exit_ceph
);
1027 MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
1028 MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
1029 MODULE_AUTHOR("Patience Warnick <patience@newdream.net>");
1030 MODULE_DESCRIPTION("Ceph filesystem for Linux");
1031 MODULE_LICENSE("GPL");