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/statfs.h>
15 #include <linux/string.h>
16 #include <linux/version.h>
17 #include <linux/vmalloc.h>
21 #include "mon_client.h"
25 * Ceph superblock operations
27 * Handle the basics of mounting, unmounting.
32 * find filename portion of a path (/foo/bar/baz -> baz)
34 const char *ceph_file_part(const char *s
, int len
)
36 const char *e
= s
+ len
;
38 while (e
!= s
&& *(e
-1) != '/')
47 static void ceph_put_super(struct super_block
*s
)
49 struct ceph_client
*cl
= ceph_client(s
);
52 ceph_mdsc_close_sessions(&cl
->mdsc
);
56 static int ceph_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
58 struct ceph_client
*client
= ceph_inode_to_client(dentry
->d_inode
);
59 struct ceph_monmap
*monmap
= client
->monc
.monmap
;
60 struct ceph_statfs st
;
65 err
= ceph_monc_do_statfs(&client
->monc
, &st
);
70 buf
->f_type
= CEPH_SUPER_MAGIC
; /* ?? */
73 * express utilization in terms of large blocks to avoid
74 * overflow on 32-bit machines.
76 buf
->f_bsize
= 1 << CEPH_BLOCK_SHIFT
;
77 buf
->f_blocks
= le64_to_cpu(st
.kb
) >> (CEPH_BLOCK_SHIFT
-10);
78 buf
->f_bfree
= (le64_to_cpu(st
.kb
) - le64_to_cpu(st
.kb_used
)) >>
79 (CEPH_BLOCK_SHIFT
-10);
80 buf
->f_bavail
= le64_to_cpu(st
.kb_avail
) >> (CEPH_BLOCK_SHIFT
-10);
82 buf
->f_files
= le64_to_cpu(st
.num_objects
);
84 buf
->f_namelen
= PATH_MAX
;
85 buf
->f_frsize
= PAGE_CACHE_SIZE
;
87 /* leave fsid little-endian, regardless of host endianness */
88 fsid
= *(u64
*)(&monmap
->fsid
) ^ *((u64
*)&monmap
->fsid
+ 1);
89 buf
->f_fsid
.val
[0] = fsid
& 0xffffffff;
90 buf
->f_fsid
.val
[1] = fsid
>> 32;
96 static int ceph_syncfs(struct super_block
*sb
, int wait
)
98 dout("sync_fs %d\n", wait
);
99 ceph_osdc_sync(&ceph_client(sb
)->osdc
);
100 ceph_mdsc_sync(&ceph_client(sb
)->mdsc
);
101 dout("sync_fs %d done\n", wait
);
107 * ceph_show_options - Show mount options in /proc/mounts
108 * @m: seq_file to write to
109 * @mnt: mount descriptor
111 static int ceph_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
113 struct ceph_client
*client
= ceph_sb_to_client(mnt
->mnt_sb
);
114 struct ceph_mount_args
*args
= client
->mount_args
;
116 if (args
->flags
& CEPH_OPT_FSID
)
117 seq_printf(m
, ",fsidmajor=%llu,fsidminor%llu",
118 le64_to_cpu(*(__le64
*)&args
->fsid
.fsid
[0]),
119 le64_to_cpu(*(__le64
*)&args
->fsid
.fsid
[8]));
120 if (args
->flags
& CEPH_OPT_NOSHARE
)
121 seq_puts(m
, ",noshare");
122 if (args
->flags
& CEPH_OPT_DIRSTAT
)
123 seq_puts(m
, ",dirstat");
124 if ((args
->flags
& CEPH_OPT_RBYTES
) == 0)
125 seq_puts(m
, ",norbytes");
126 if (args
->flags
& CEPH_OPT_NOCRC
)
127 seq_puts(m
, ",nocrc");
128 if (args
->flags
& CEPH_OPT_NOASYNCREADDIR
)
129 seq_puts(m
, ",noasyncreaddir");
130 if (strcmp(args
->snapdir_name
, CEPH_SNAPDIRNAME_DEFAULT
))
131 seq_printf(m
, ",snapdirname=%s", args
->snapdir_name
);
133 seq_printf(m
, ",name=%s", args
->name
);
135 seq_puts(m
, ",secret=<hidden>");
142 struct kmem_cache
*ceph_inode_cachep
;
143 struct kmem_cache
*ceph_cap_cachep
;
144 struct kmem_cache
*ceph_dentry_cachep
;
145 struct kmem_cache
*ceph_file_cachep
;
147 static void ceph_inode_init_once(void *foo
)
149 struct ceph_inode_info
*ci
= foo
;
150 inode_init_once(&ci
->vfs_inode
);
153 static int __init
init_caches(void)
155 ceph_inode_cachep
= kmem_cache_create("ceph_inode_info",
156 sizeof(struct ceph_inode_info
),
157 __alignof__(struct ceph_inode_info
),
158 (SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
),
159 ceph_inode_init_once
);
160 if (ceph_inode_cachep
== NULL
)
163 ceph_cap_cachep
= KMEM_CACHE(ceph_cap
,
164 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
);
165 if (ceph_cap_cachep
== NULL
)
168 ceph_dentry_cachep
= KMEM_CACHE(ceph_dentry_info
,
169 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
);
170 if (ceph_dentry_cachep
== NULL
)
173 ceph_file_cachep
= KMEM_CACHE(ceph_file_info
,
174 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
);
175 if (ceph_file_cachep
== NULL
)
181 kmem_cache_destroy(ceph_dentry_cachep
);
183 kmem_cache_destroy(ceph_cap_cachep
);
185 kmem_cache_destroy(ceph_inode_cachep
);
189 static void destroy_caches(void)
191 kmem_cache_destroy(ceph_inode_cachep
);
192 kmem_cache_destroy(ceph_cap_cachep
);
193 kmem_cache_destroy(ceph_dentry_cachep
);
194 kmem_cache_destroy(ceph_file_cachep
);
199 * ceph_umount_begin - initiate forced umount. Tear down down the
200 * mount, skipping steps that may hang while waiting for server(s).
202 static void ceph_umount_begin(struct super_block
*sb
)
204 struct ceph_client
*client
= ceph_sb_to_client(sb
);
206 dout("ceph_umount_begin - starting forced umount\n");
209 client
->mount_state
= CEPH_MOUNT_SHUTDOWN
;
213 static const struct super_operations ceph_super_ops
= {
214 .alloc_inode
= ceph_alloc_inode
,
215 .destroy_inode
= ceph_destroy_inode
,
216 .write_inode
= ceph_write_inode
,
217 .sync_fs
= ceph_syncfs
,
218 .put_super
= ceph_put_super
,
219 .show_options
= ceph_show_options
,
220 .statfs
= ceph_statfs
,
221 .umount_begin
= ceph_umount_begin
,
225 const char *ceph_msg_type_name(int type
)
228 case CEPH_MSG_SHUTDOWN
: return "shutdown";
229 case CEPH_MSG_PING
: return "ping";
230 case CEPH_MSG_AUTH
: return "auth";
231 case CEPH_MSG_AUTH_REPLY
: return "auth_reply";
232 case CEPH_MSG_MON_MAP
: return "mon_map";
233 case CEPH_MSG_MON_GET_MAP
: return "mon_get_map";
234 case CEPH_MSG_MON_SUBSCRIBE
: return "mon_subscribe";
235 case CEPH_MSG_MON_SUBSCRIBE_ACK
: return "mon_subscribe_ack";
236 case CEPH_MSG_STATFS
: return "statfs";
237 case CEPH_MSG_STATFS_REPLY
: return "statfs_reply";
238 case CEPH_MSG_MDS_MAP
: return "mds_map";
239 case CEPH_MSG_CLIENT_SESSION
: return "client_session";
240 case CEPH_MSG_CLIENT_RECONNECT
: return "client_reconnect";
241 case CEPH_MSG_CLIENT_REQUEST
: return "client_request";
242 case CEPH_MSG_CLIENT_REQUEST_FORWARD
: return "client_request_forward";
243 case CEPH_MSG_CLIENT_REPLY
: return "client_reply";
244 case CEPH_MSG_CLIENT_CAPS
: return "client_caps";
245 case CEPH_MSG_CLIENT_CAPRELEASE
: return "client_cap_release";
246 case CEPH_MSG_CLIENT_SNAP
: return "client_snap";
247 case CEPH_MSG_CLIENT_LEASE
: return "client_lease";
248 case CEPH_MSG_OSD_MAP
: return "osd_map";
249 case CEPH_MSG_OSD_OP
: return "osd_op";
250 case CEPH_MSG_OSD_OPREPLY
: return "osd_opreply";
251 default: return "unknown";
267 Opt_caps_wanted_delay_min
,
268 Opt_caps_wanted_delay_max
,
269 Opt_readdir_max_entries
,
276 /* string args above */
287 static match_table_t arg_tokens
= {
288 {Opt_fsidmajor
, "fsidmajor=%ld"},
289 {Opt_fsidminor
, "fsidminor=%ld"},
290 {Opt_monport
, "monport=%d"},
291 {Opt_wsize
, "wsize=%d"},
292 {Opt_rsize
, "rsize=%d"},
293 {Opt_osdtimeout
, "osdtimeout=%d"},
294 {Opt_mount_timeout
, "mount_timeout=%d"},
295 {Opt_caps_wanted_delay_min
, "caps_wanted_delay_min=%d"},
296 {Opt_caps_wanted_delay_max
, "caps_wanted_delay_max=%d"},
297 {Opt_readdir_max_entries
, "readdir_max_entries=%d"},
299 {Opt_snapdirname
, "snapdirname=%s"},
300 {Opt_name
, "name=%s"},
301 {Opt_secret
, "secret=%s"},
302 /* string args above */
304 {Opt_noshare
, "noshare"},
305 {Opt_dirstat
, "dirstat"},
306 {Opt_nodirstat
, "nodirstat"},
307 {Opt_rbytes
, "rbytes"},
308 {Opt_norbytes
, "norbytes"},
309 {Opt_nocrc
, "nocrc"},
310 {Opt_noasyncreaddir
, "noasyncreaddir"},
315 static struct ceph_mount_args
*parse_mount_args(int flags
, char *options
,
316 const char *dev_name
,
319 struct ceph_mount_args
*args
;
322 substring_t argstr
[MAX_OPT_ARGS
];
324 args
= kzalloc(sizeof(*args
), GFP_KERNEL
);
326 return ERR_PTR(-ENOMEM
);
327 args
->mon_addr
= kcalloc(CEPH_MAX_MON
, sizeof(*args
->mon_addr
),
332 dout("parse_mount_args %p, dev_name '%s'\n", args
, dev_name
);
334 /* start with defaults */
335 args
->sb_flags
= flags
;
336 args
->flags
= CEPH_OPT_DEFAULT
;
337 args
->osd_timeout
= 5; /* seconds */
338 args
->mount_timeout
= CEPH_MOUNT_TIMEOUT_DEFAULT
; /* seconds */
339 args
->caps_wanted_delay_min
= CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT
;
340 args
->caps_wanted_delay_max
= CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT
;
341 args
->rsize
= CEPH_MOUNT_RSIZE_DEFAULT
;
342 args
->snapdir_name
= kstrdup(CEPH_SNAPDIRNAME_DEFAULT
, GFP_KERNEL
);
343 args
->cap_release_safety
= CEPH_CAPS_PER_RELEASE
* 4;
344 args
->max_readdir
= 1024;
346 /* ip1[:port1][,ip2[:port2]...]:/subdir/in/fs */
350 *path
= strstr(dev_name
, ":/");
352 pr_err("device name is missing path (no :/ in %s)\n",
358 err
= ceph_parse_ips(dev_name
, *path
, args
->mon_addr
,
359 CEPH_MAX_MON
, &args
->num_mon
);
365 dout("server path '%s'\n", *path
);
367 /* parse mount options */
368 while ((c
= strsep(&options
, ",")) != NULL
) {
369 int token
, intval
, ret
;
373 token
= match_token((char *)c
, arg_tokens
, argstr
);
375 pr_err("bad mount option at '%s'\n", c
);
378 if (token
< Opt_last_int
) {
379 ret
= match_int(&argstr
[0], &intval
);
381 pr_err("bad mount option arg (not int) "
385 dout("got int token %d val %d\n", token
, intval
);
386 } else if (token
> Opt_last_int
&& token
< Opt_last_string
) {
387 dout("got string token %d val %s\n", token
,
390 dout("got token %d\n", token
);
394 *(__le64
*)&args
->fsid
.fsid
[0] = cpu_to_le64(intval
);
397 *(__le64
*)&args
->fsid
.fsid
[8] = cpu_to_le64(intval
);
400 err
= ceph_parse_ips(argstr
[0].from
,
406 args
->flags
|= CEPH_OPT_MYIP
;
409 case Opt_snapdirname
:
410 kfree(args
->snapdir_name
);
411 args
->snapdir_name
= kstrndup(argstr
[0].from
,
412 argstr
[0].to
-argstr
[0].from
,
416 args
->name
= kstrndup(argstr
[0].from
,
417 argstr
[0].to
-argstr
[0].from
,
421 args
->secret
= kstrndup(argstr
[0].from
,
422 argstr
[0].to
-argstr
[0].from
,
428 args
->wsize
= intval
;
431 args
->rsize
= intval
;
434 args
->osd_timeout
= intval
;
436 case Opt_mount_timeout
:
437 args
->mount_timeout
= intval
;
439 case Opt_caps_wanted_delay_min
:
440 args
->caps_wanted_delay_min
= intval
;
442 case Opt_caps_wanted_delay_max
:
443 args
->caps_wanted_delay_max
= intval
;
445 case Opt_readdir_max_entries
:
446 args
->max_readdir
= intval
;
450 args
->flags
|= CEPH_OPT_NOSHARE
;
454 args
->flags
|= CEPH_OPT_DIRSTAT
;
457 args
->flags
&= ~CEPH_OPT_DIRSTAT
;
460 args
->flags
|= CEPH_OPT_RBYTES
;
463 args
->flags
&= ~CEPH_OPT_RBYTES
;
466 args
->flags
|= CEPH_OPT_NOCRC
;
468 case Opt_noasyncreaddir
:
469 args
->flags
|= CEPH_OPT_NOASYNCREADDIR
;
479 kfree(args
->mon_addr
);
484 static void destroy_mount_args(struct ceph_mount_args
*args
)
486 dout("destroy_mount_args %p\n", args
);
487 kfree(args
->snapdir_name
);
488 args
->snapdir_name
= NULL
;
497 * create a fresh client instance
499 static struct ceph_client
*ceph_create_client(struct ceph_mount_args
*args
)
501 struct ceph_client
*client
;
504 client
= kzalloc(sizeof(*client
), GFP_KERNEL
);
506 return ERR_PTR(-ENOMEM
);
508 mutex_init(&client
->mount_mutex
);
510 init_waitqueue_head(&client
->mount_wq
);
513 client
->mount_state
= CEPH_MOUNT_MOUNTING
;
514 client
->mount_args
= args
;
518 client
->mount_err
= 0;
520 err
= bdi_init(&client
->backing_dev_info
);
525 client
->wb_wq
= create_workqueue("ceph-writeback");
526 if (client
->wb_wq
== NULL
)
528 client
->pg_inv_wq
= create_singlethread_workqueue("ceph-pg-invalid");
529 if (client
->pg_inv_wq
== NULL
)
531 client
->trunc_wq
= create_singlethread_workqueue("ceph-trunc");
532 if (client
->trunc_wq
== NULL
)
535 /* set up mempools */
537 client
->wb_pagevec_pool
= mempool_create_kmalloc_pool(10,
538 client
->mount_args
->wsize
>> PAGE_CACHE_SHIFT
);
539 if (!client
->wb_pagevec_pool
)
544 err
= ceph_monc_init(&client
->monc
, client
);
547 err
= ceph_osdc_init(&client
->osdc
, client
);
550 err
= ceph_mdsc_init(&client
->mdsc
, client
);
556 ceph_osdc_stop(&client
->osdc
);
558 ceph_monc_stop(&client
->monc
);
560 mempool_destroy(client
->wb_pagevec_pool
);
562 destroy_workqueue(client
->trunc_wq
);
564 destroy_workqueue(client
->pg_inv_wq
);
566 destroy_workqueue(client
->wb_wq
);
568 bdi_destroy(&client
->backing_dev_info
);
574 static void ceph_destroy_client(struct ceph_client
*client
)
576 dout("destroy_client %p\n", client
);
579 ceph_mdsc_stop(&client
->mdsc
);
580 ceph_monc_stop(&client
->monc
);
581 ceph_osdc_stop(&client
->osdc
);
583 ceph_debugfs_client_cleanup(client
);
584 destroy_workqueue(client
->wb_wq
);
585 destroy_workqueue(client
->pg_inv_wq
);
586 destroy_workqueue(client
->trunc_wq
);
589 ceph_messenger_destroy(client
->msgr
);
590 mempool_destroy(client
->wb_pagevec_pool
);
592 destroy_mount_args(client
->mount_args
);
595 dout("destroy_client %p done\n", client
);
599 * Initially learn our fsid, or verify an fsid matches.
601 int ceph_check_fsid(struct ceph_client
*client
, struct ceph_fsid
*fsid
)
603 if (client
->have_fsid
) {
604 if (ceph_fsid_compare(&client
->fsid
, fsid
)) {
605 pr_err("bad fsid, had " FSID_FORMAT
" got " FSID_FORMAT
,
606 PR_FSID(&client
->fsid
), PR_FSID(fsid
));
610 pr_info("client%lld fsid " FSID_FORMAT
"\n",
611 client
->monc
.auth
->global_id
, PR_FSID(fsid
));
612 memcpy(&client
->fsid
, fsid
, sizeof(*fsid
));
613 ceph_debugfs_client_init(client
);
614 client
->have_fsid
= true;
620 * true if we have the mon map (and have thus joined the cluster)
622 static int have_mon_map(struct ceph_client
*client
)
624 return client
->monc
.monmap
&& client
->monc
.monmap
->epoch
;
628 * Bootstrap mount by opening the root directory. Note the mount
629 * @started time from caller, and time out if this takes too long.
631 static struct dentry
*open_root_dentry(struct ceph_client
*client
,
633 unsigned long started
)
635 struct ceph_mds_client
*mdsc
= &client
->mdsc
;
636 struct ceph_mds_request
*req
= NULL
;
641 dout("open_root_inode opening '%s'\n", path
);
642 req
= ceph_mdsc_create_request(mdsc
, CEPH_MDS_OP_GETATTR
, USE_ANY_MDS
);
644 return ERR_PTR(PTR_ERR(req
));
645 req
->r_path1
= kstrdup(path
, GFP_NOFS
);
646 req
->r_ino1
.ino
= CEPH_INO_ROOT
;
647 req
->r_ino1
.snap
= CEPH_NOSNAP
;
648 req
->r_started
= started
;
649 req
->r_timeout
= client
->mount_args
->mount_timeout
* HZ
;
650 req
->r_args
.getattr
.mask
= cpu_to_le32(CEPH_STAT_CAP_INODE
);
652 err
= ceph_mdsc_do_request(mdsc
, NULL
, req
);
654 dout("open_root_inode success\n");
655 if (ceph_ino(req
->r_target_inode
) == CEPH_INO_ROOT
&&
656 client
->sb
->s_root
== NULL
)
657 root
= d_alloc_root(req
->r_target_inode
);
659 root
= d_obtain_alias(req
->r_target_inode
);
660 req
->r_target_inode
= NULL
;
661 dout("open_root_inode success, root dentry is %p\n", root
);
665 ceph_mdsc_put_request(req
);
670 * mount: join the ceph cluster, and open root directory.
672 static int ceph_mount(struct ceph_client
*client
, struct vfsmount
*mnt
,
675 struct ceph_entity_addr
*myaddr
= NULL
;
677 unsigned long timeout
= client
->mount_args
->mount_timeout
* HZ
;
678 unsigned long started
= jiffies
; /* note the start time */
681 dout("mount start\n");
682 mutex_lock(&client
->mount_mutex
);
684 /* initialize the messenger */
685 if (client
->msgr
== NULL
) {
686 if (ceph_test_opt(client
, MYIP
))
687 myaddr
= &client
->mount_args
->my_addr
;
688 client
->msgr
= ceph_messenger_create(myaddr
);
689 if (IS_ERR(client
->msgr
)) {
690 err
= PTR_ERR(client
->msgr
);
694 client
->msgr
->nocrc
= ceph_test_opt(client
, NOCRC
);
697 /* open session, and wait for mon, mds, and osd maps */
698 err
= ceph_monc_open_session(&client
->monc
);
702 while (!have_mon_map(client
)) {
704 if (timeout
&& time_after_eq(jiffies
, started
+ timeout
))
708 dout("mount waiting for mon_map\n");
709 err
= wait_event_interruptible_timeout(client
->mount_wq
, /* FIXME */
710 have_mon_map(client
) || (client
->mount_err
< 0),
712 if (err
== -EINTR
|| err
== -ERESTARTSYS
)
714 if (client
->mount_err
< 0) {
715 err
= client
->mount_err
;
720 dout("mount opening root\n");
721 root
= open_root_dentry(client
, "", started
);
726 if (client
->sb
->s_root
)
729 client
->sb
->s_root
= root
;
734 dout("mount opening base mountpoint\n");
735 root
= open_root_dentry(client
, path
, started
);
738 dput(client
->sb
->s_root
);
739 client
->sb
->s_root
= NULL
;
744 mnt
->mnt_root
= root
;
745 mnt
->mnt_sb
= client
->sb
;
747 client
->mount_state
= CEPH_MOUNT_MOUNTED
;
748 dout("mount success\n");
752 mutex_unlock(&client
->mount_mutex
);
756 static int ceph_set_super(struct super_block
*s
, void *data
)
758 struct ceph_client
*client
= data
;
761 dout("set_super %p data %p\n", s
, data
);
763 s
->s_flags
= client
->mount_args
->sb_flags
;
764 s
->s_maxbytes
= 1ULL << 40; /* temp value until we get mdsmap */
766 s
->s_fs_info
= client
;
769 s
->s_op
= &ceph_super_ops
;
770 s
->s_export_op
= &ceph_export_ops
;
772 s
->s_time_gran
= 1000; /* 1000 ns == 1 us */
774 ret
= set_anon_super(s
, NULL
); /* what is that second arg for? */
787 * share superblock if same fs AND options
789 static int ceph_compare_super(struct super_block
*sb
, void *data
)
791 struct ceph_client
*new = data
;
792 struct ceph_mount_args
*args
= new->mount_args
;
793 struct ceph_client
*other
= ceph_sb_to_client(sb
);
796 dout("ceph_compare_super %p\n", sb
);
797 if (args
->flags
& CEPH_OPT_FSID
) {
798 if (ceph_fsid_compare(&args
->fsid
, &other
->fsid
)) {
799 dout("fsid doesn't match\n");
803 /* do we share (a) monitor? */
804 for (i
= 0; i
< new->monc
.monmap
->num_mon
; i
++)
805 if (ceph_monmap_contains(other
->monc
.monmap
,
806 &new->monc
.monmap
->mon_inst
[i
].addr
))
808 if (i
== new->monc
.monmap
->num_mon
) {
809 dout("mon ip not part of monmap\n");
812 dout("mon ip matches existing sb %p\n", sb
);
814 if (args
->sb_flags
!= other
->mount_args
->sb_flags
) {
815 dout("flags differ\n");
822 * construct our own bdi so we can control readahead, etc.
824 static int ceph_register_bdi(struct super_block
*sb
, struct ceph_client
*client
)
828 sb
->s_bdi
= &client
->backing_dev_info
;
830 /* set ra_pages based on rsize mount option? */
831 if (client
->mount_args
->rsize
>= PAGE_CACHE_SIZE
)
832 client
->backing_dev_info
.ra_pages
=
833 (client
->mount_args
->rsize
+ PAGE_CACHE_SIZE
- 1)
835 err
= bdi_register_dev(&client
->backing_dev_info
, sb
->s_dev
);
839 static int ceph_get_sb(struct file_system_type
*fs_type
,
840 int flags
, const char *dev_name
, void *data
,
841 struct vfsmount
*mnt
)
843 struct super_block
*sb
;
844 struct ceph_client
*client
;
846 int (*compare_super
)(struct super_block
*, void *) = ceph_compare_super
;
847 const char *path
= NULL
;
848 struct ceph_mount_args
*args
;
850 dout("ceph_get_sb\n");
851 args
= parse_mount_args(flags
, data
, dev_name
, &path
);
857 /* create client (which we may/may not use) */
858 client
= ceph_create_client(args
);
859 if (IS_ERR(client
)) {
860 err
= PTR_ERR(client
);
864 if (client
->mount_args
->flags
& CEPH_OPT_NOSHARE
)
865 compare_super
= NULL
;
866 sb
= sget(fs_type
, compare_super
, ceph_set_super
, client
);
872 if (ceph_client(sb
) != client
) {
873 ceph_destroy_client(client
);
874 client
= ceph_client(sb
);
875 dout("get_sb got existing client %p\n", client
);
877 dout("get_sb using new client %p\n", client
);
878 err
= ceph_register_bdi(sb
, client
);
883 err
= ceph_mount(client
, mnt
, path
);
886 dout("root %p inode %p ino %llx.%llx\n", mnt
->mnt_root
,
887 mnt
->mnt_root
->d_inode
, ceph_vinop(mnt
->mnt_root
->d_inode
));
891 ceph_mdsc_close_sessions(&client
->mdsc
);
892 up_write(&sb
->s_umount
);
893 deactivate_super(sb
);
897 ceph_destroy_client(client
);
899 dout("ceph_get_sb fail %d\n", err
);
903 static void ceph_kill_sb(struct super_block
*s
)
905 struct ceph_client
*client
= ceph_sb_to_client(s
);
906 dout("kill_sb %p\n", s
);
907 ceph_mdsc_pre_umount(&client
->mdsc
);
908 kill_anon_super(s
); /* will call put_super after sb is r/o */
909 bdi_unregister(&client
->backing_dev_info
);
910 bdi_destroy(&client
->backing_dev_info
);
911 ceph_destroy_client(client
);
914 static struct file_system_type ceph_fs_type
= {
915 .owner
= THIS_MODULE
,
917 .get_sb
= ceph_get_sb
,
918 .kill_sb
= ceph_kill_sb
,
919 .fs_flags
= FS_RENAME_DOES_D_MOVE
,
922 #define _STRINGIFY(x) #x
923 #define STRINGIFY(x) _STRINGIFY(x)
925 static int __init
init_ceph(void)
929 ret
= ceph_debugfs_init();
933 ret
= ceph_msgr_init();
943 ret
= register_filesystem(&ceph_fs_type
);
947 pr_info("loaded %d.%d.%d (mon/mds/osd proto %d/%d/%d)\n",
948 CEPH_VERSION_MAJOR
, CEPH_VERSION_MINOR
, CEPH_VERSION_PATCH
,
949 CEPH_MONC_PROTOCOL
, CEPH_MDSC_PROTOCOL
, CEPH_OSDC_PROTOCOL
);
957 ceph_debugfs_cleanup();
962 static void __exit
exit_ceph(void)
965 unregister_filesystem(&ceph_fs_type
);
966 ceph_caps_finalize();
969 ceph_debugfs_cleanup();
972 module_init(init_ceph
);
973 module_exit(exit_ceph
);
975 MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
976 MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
977 MODULE_AUTHOR("Patience Warnick <patience@newdream.net>");
978 MODULE_DESCRIPTION("Ceph filesystem for Linux");
979 MODULE_LICENSE("GPL");