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
*client
= ceph_sb_to_client(s
);
53 ceph_mdsc_close_sessions(&client
->mdsc
);
56 * ensure we release the bdi before put_anon_super releases
59 if (s
->s_bdi
== &client
->backing_dev_info
) {
60 bdi_unregister(&client
->backing_dev_info
);
67 static int ceph_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
69 struct ceph_client
*client
= ceph_inode_to_client(dentry
->d_inode
);
70 struct ceph_monmap
*monmap
= client
->monc
.monmap
;
71 struct ceph_statfs st
;
76 err
= ceph_monc_do_statfs(&client
->monc
, &st
);
81 buf
->f_type
= CEPH_SUPER_MAGIC
; /* ?? */
84 * express utilization in terms of large blocks to avoid
85 * overflow on 32-bit machines.
87 buf
->f_bsize
= 1 << CEPH_BLOCK_SHIFT
;
88 buf
->f_blocks
= le64_to_cpu(st
.kb
) >> (CEPH_BLOCK_SHIFT
-10);
89 buf
->f_bfree
= (le64_to_cpu(st
.kb
) - le64_to_cpu(st
.kb_used
)) >>
90 (CEPH_BLOCK_SHIFT
-10);
91 buf
->f_bavail
= le64_to_cpu(st
.kb_avail
) >> (CEPH_BLOCK_SHIFT
-10);
93 buf
->f_files
= le64_to_cpu(st
.num_objects
);
95 buf
->f_namelen
= PATH_MAX
;
96 buf
->f_frsize
= PAGE_CACHE_SIZE
;
98 /* leave fsid little-endian, regardless of host endianness */
99 fsid
= *(u64
*)(&monmap
->fsid
) ^ *((u64
*)&monmap
->fsid
+ 1);
100 buf
->f_fsid
.val
[0] = fsid
& 0xffffffff;
101 buf
->f_fsid
.val
[1] = fsid
>> 32;
107 static int ceph_syncfs(struct super_block
*sb
, int wait
)
109 dout("sync_fs %d\n", wait
);
110 ceph_osdc_sync(&ceph_client(sb
)->osdc
);
111 ceph_mdsc_sync(&ceph_client(sb
)->mdsc
);
112 dout("sync_fs %d done\n", wait
);
118 * ceph_show_options - Show mount options in /proc/mounts
119 * @m: seq_file to write to
120 * @mnt: mount descriptor
122 static int ceph_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
124 struct ceph_client
*client
= ceph_sb_to_client(mnt
->mnt_sb
);
125 struct ceph_mount_args
*args
= client
->mount_args
;
127 if (args
->flags
& CEPH_OPT_FSID
)
128 seq_printf(m
, ",fsidmajor=%llu,fsidminor%llu",
129 le64_to_cpu(*(__le64
*)&args
->fsid
.fsid
[0]),
130 le64_to_cpu(*(__le64
*)&args
->fsid
.fsid
[8]));
131 if (args
->flags
& CEPH_OPT_NOSHARE
)
132 seq_puts(m
, ",noshare");
133 if (args
->flags
& CEPH_OPT_DIRSTAT
)
134 seq_puts(m
, ",dirstat");
135 if ((args
->flags
& CEPH_OPT_RBYTES
) == 0)
136 seq_puts(m
, ",norbytes");
137 if (args
->flags
& CEPH_OPT_NOCRC
)
138 seq_puts(m
, ",nocrc");
139 if (args
->flags
& CEPH_OPT_NOASYNCREADDIR
)
140 seq_puts(m
, ",noasyncreaddir");
141 if (strcmp(args
->snapdir_name
, CEPH_SNAPDIRNAME_DEFAULT
))
142 seq_printf(m
, ",snapdirname=%s", args
->snapdir_name
);
144 seq_printf(m
, ",name=%s", args
->name
);
146 seq_puts(m
, ",secret=<hidden>");
153 struct kmem_cache
*ceph_inode_cachep
;
154 struct kmem_cache
*ceph_cap_cachep
;
155 struct kmem_cache
*ceph_dentry_cachep
;
156 struct kmem_cache
*ceph_file_cachep
;
158 static void ceph_inode_init_once(void *foo
)
160 struct ceph_inode_info
*ci
= foo
;
161 inode_init_once(&ci
->vfs_inode
);
164 static int default_congestion_kb(void)
171 * congestion size, scale with available memory.
183 * This allows larger machines to have larger/more transfers.
184 * Limit the default to 256M
186 congestion_kb
= (16*int_sqrt(totalram_pages
)) << (PAGE_SHIFT
-10);
187 if (congestion_kb
> 256*1024)
188 congestion_kb
= 256*1024;
190 return congestion_kb
;
193 static int __init
init_caches(void)
195 ceph_inode_cachep
= kmem_cache_create("ceph_inode_info",
196 sizeof(struct ceph_inode_info
),
197 __alignof__(struct ceph_inode_info
),
198 (SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
),
199 ceph_inode_init_once
);
200 if (ceph_inode_cachep
== NULL
)
203 ceph_cap_cachep
= KMEM_CACHE(ceph_cap
,
204 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
);
205 if (ceph_cap_cachep
== NULL
)
208 ceph_dentry_cachep
= KMEM_CACHE(ceph_dentry_info
,
209 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
);
210 if (ceph_dentry_cachep
== NULL
)
213 ceph_file_cachep
= KMEM_CACHE(ceph_file_info
,
214 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
);
215 if (ceph_file_cachep
== NULL
)
221 kmem_cache_destroy(ceph_dentry_cachep
);
223 kmem_cache_destroy(ceph_cap_cachep
);
225 kmem_cache_destroy(ceph_inode_cachep
);
229 static void destroy_caches(void)
231 kmem_cache_destroy(ceph_inode_cachep
);
232 kmem_cache_destroy(ceph_cap_cachep
);
233 kmem_cache_destroy(ceph_dentry_cachep
);
234 kmem_cache_destroy(ceph_file_cachep
);
239 * ceph_umount_begin - initiate forced umount. Tear down down the
240 * mount, skipping steps that may hang while waiting for server(s).
242 static void ceph_umount_begin(struct super_block
*sb
)
244 struct ceph_client
*client
= ceph_sb_to_client(sb
);
246 dout("ceph_umount_begin - starting forced umount\n");
249 client
->mount_state
= CEPH_MOUNT_SHUTDOWN
;
253 static const struct super_operations ceph_super_ops
= {
254 .alloc_inode
= ceph_alloc_inode
,
255 .destroy_inode
= ceph_destroy_inode
,
256 .write_inode
= ceph_write_inode
,
257 .sync_fs
= ceph_syncfs
,
258 .put_super
= ceph_put_super
,
259 .show_options
= ceph_show_options
,
260 .statfs
= ceph_statfs
,
261 .umount_begin
= ceph_umount_begin
,
265 const char *ceph_msg_type_name(int type
)
268 case CEPH_MSG_SHUTDOWN
: return "shutdown";
269 case CEPH_MSG_PING
: return "ping";
270 case CEPH_MSG_AUTH
: return "auth";
271 case CEPH_MSG_AUTH_REPLY
: return "auth_reply";
272 case CEPH_MSG_MON_MAP
: return "mon_map";
273 case CEPH_MSG_MON_GET_MAP
: return "mon_get_map";
274 case CEPH_MSG_MON_SUBSCRIBE
: return "mon_subscribe";
275 case CEPH_MSG_MON_SUBSCRIBE_ACK
: return "mon_subscribe_ack";
276 case CEPH_MSG_STATFS
: return "statfs";
277 case CEPH_MSG_STATFS_REPLY
: return "statfs_reply";
278 case CEPH_MSG_MDS_MAP
: return "mds_map";
279 case CEPH_MSG_CLIENT_SESSION
: return "client_session";
280 case CEPH_MSG_CLIENT_RECONNECT
: return "client_reconnect";
281 case CEPH_MSG_CLIENT_REQUEST
: return "client_request";
282 case CEPH_MSG_CLIENT_REQUEST_FORWARD
: return "client_request_forward";
283 case CEPH_MSG_CLIENT_REPLY
: return "client_reply";
284 case CEPH_MSG_CLIENT_CAPS
: return "client_caps";
285 case CEPH_MSG_CLIENT_CAPRELEASE
: return "client_cap_release";
286 case CEPH_MSG_CLIENT_SNAP
: return "client_snap";
287 case CEPH_MSG_CLIENT_LEASE
: return "client_lease";
288 case CEPH_MSG_OSD_MAP
: return "osd_map";
289 case CEPH_MSG_OSD_OP
: return "osd_op";
290 case CEPH_MSG_OSD_OPREPLY
: return "osd_opreply";
291 default: return "unknown";
306 Opt_osdkeepalivetimeout
,
309 Opt_caps_wanted_delay_min
,
310 Opt_caps_wanted_delay_max
,
311 Opt_readdir_max_entries
,
319 /* string args above */
330 static match_table_t arg_tokens
= {
331 {Opt_fsidmajor
, "fsidmajor=%ld"},
332 {Opt_fsidminor
, "fsidminor=%ld"},
333 {Opt_monport
, "monport=%d"},
334 {Opt_wsize
, "wsize=%d"},
335 {Opt_rsize
, "rsize=%d"},
336 {Opt_osdtimeout
, "osdtimeout=%d"},
337 {Opt_osdkeepalivetimeout
, "osdkeepalive=%d"},
338 {Opt_mount_timeout
, "mount_timeout=%d"},
339 {Opt_osd_idle_ttl
, "osd_idle_ttl=%d"},
340 {Opt_caps_wanted_delay_min
, "caps_wanted_delay_min=%d"},
341 {Opt_caps_wanted_delay_max
, "caps_wanted_delay_max=%d"},
342 {Opt_readdir_max_entries
, "readdir_max_entries=%d"},
343 {Opt_congestion_kb
, "write_congestion_kb=%d"},
345 {Opt_snapdirname
, "snapdirname=%s"},
346 {Opt_name
, "name=%s"},
347 {Opt_secret
, "secret=%s"},
348 /* string args above */
350 {Opt_noshare
, "noshare"},
351 {Opt_dirstat
, "dirstat"},
352 {Opt_nodirstat
, "nodirstat"},
353 {Opt_rbytes
, "rbytes"},
354 {Opt_norbytes
, "norbytes"},
355 {Opt_nocrc
, "nocrc"},
356 {Opt_noasyncreaddir
, "noasyncreaddir"},
361 static struct ceph_mount_args
*parse_mount_args(int flags
, char *options
,
362 const char *dev_name
,
365 struct ceph_mount_args
*args
;
368 substring_t argstr
[MAX_OPT_ARGS
];
370 args
= kzalloc(sizeof(*args
), GFP_KERNEL
);
372 return ERR_PTR(-ENOMEM
);
373 args
->mon_addr
= kcalloc(CEPH_MAX_MON
, sizeof(*args
->mon_addr
),
378 dout("parse_mount_args %p, dev_name '%s'\n", args
, dev_name
);
380 /* start with defaults */
381 args
->sb_flags
= flags
;
382 args
->flags
= CEPH_OPT_DEFAULT
;
383 args
->osd_timeout
= CEPH_OSD_TIMEOUT_DEFAULT
;
384 args
->osd_keepalive_timeout
= CEPH_OSD_KEEPALIVE_DEFAULT
;
385 args
->mount_timeout
= CEPH_MOUNT_TIMEOUT_DEFAULT
; /* seconds */
386 args
->osd_idle_ttl
= CEPH_OSD_IDLE_TTL_DEFAULT
; /* seconds */
387 args
->caps_wanted_delay_min
= CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT
;
388 args
->caps_wanted_delay_max
= CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT
;
389 args
->rsize
= CEPH_MOUNT_RSIZE_DEFAULT
;
390 args
->snapdir_name
= kstrdup(CEPH_SNAPDIRNAME_DEFAULT
, GFP_KERNEL
);
391 args
->cap_release_safety
= CEPH_CAPS_PER_RELEASE
* 4;
392 args
->max_readdir
= 1024;
393 args
->congestion_kb
= default_congestion_kb();
395 /* ip1[:port1][,ip2[:port2]...]:/subdir/in/fs */
399 *path
= strstr(dev_name
, ":/");
401 pr_err("device name is missing path (no :/ in %s)\n",
407 err
= ceph_parse_ips(dev_name
, *path
, args
->mon_addr
,
408 CEPH_MAX_MON
, &args
->num_mon
);
414 dout("server path '%s'\n", *path
);
416 /* parse mount options */
417 while ((c
= strsep(&options
, ",")) != NULL
) {
418 int token
, intval
, ret
;
422 token
= match_token((char *)c
, arg_tokens
, argstr
);
424 pr_err("bad mount option at '%s'\n", c
);
427 if (token
< Opt_last_int
) {
428 ret
= match_int(&argstr
[0], &intval
);
430 pr_err("bad mount option arg (not int) "
434 dout("got int token %d val %d\n", token
, intval
);
435 } else if (token
> Opt_last_int
&& token
< Opt_last_string
) {
436 dout("got string token %d val %s\n", token
,
439 dout("got token %d\n", token
);
443 *(__le64
*)&args
->fsid
.fsid
[0] = cpu_to_le64(intval
);
446 *(__le64
*)&args
->fsid
.fsid
[8] = cpu_to_le64(intval
);
449 err
= ceph_parse_ips(argstr
[0].from
,
455 args
->flags
|= CEPH_OPT_MYIP
;
458 case Opt_snapdirname
:
459 kfree(args
->snapdir_name
);
460 args
->snapdir_name
= kstrndup(argstr
[0].from
,
461 argstr
[0].to
-argstr
[0].from
,
465 args
->name
= kstrndup(argstr
[0].from
,
466 argstr
[0].to
-argstr
[0].from
,
470 args
->secret
= kstrndup(argstr
[0].from
,
471 argstr
[0].to
-argstr
[0].from
,
477 args
->wsize
= intval
;
480 args
->rsize
= intval
;
483 args
->osd_timeout
= intval
;
485 case Opt_osdkeepalivetimeout
:
486 args
->osd_keepalive_timeout
= intval
;
488 case Opt_mount_timeout
:
489 args
->mount_timeout
= intval
;
491 case Opt_caps_wanted_delay_min
:
492 args
->caps_wanted_delay_min
= intval
;
494 case Opt_caps_wanted_delay_max
:
495 args
->caps_wanted_delay_max
= intval
;
497 case Opt_readdir_max_entries
:
498 args
->max_readdir
= intval
;
500 case Opt_congestion_kb
:
501 args
->congestion_kb
= intval
;
505 args
->flags
|= CEPH_OPT_NOSHARE
;
509 args
->flags
|= CEPH_OPT_DIRSTAT
;
512 args
->flags
&= ~CEPH_OPT_DIRSTAT
;
515 args
->flags
|= CEPH_OPT_RBYTES
;
518 args
->flags
&= ~CEPH_OPT_RBYTES
;
521 args
->flags
|= CEPH_OPT_NOCRC
;
523 case Opt_noasyncreaddir
:
524 args
->flags
|= CEPH_OPT_NOASYNCREADDIR
;
534 kfree(args
->mon_addr
);
539 static void destroy_mount_args(struct ceph_mount_args
*args
)
541 dout("destroy_mount_args %p\n", args
);
542 kfree(args
->snapdir_name
);
543 args
->snapdir_name
= NULL
;
552 * create a fresh client instance
554 static struct ceph_client
*ceph_create_client(struct ceph_mount_args
*args
)
556 struct ceph_client
*client
;
559 client
= kzalloc(sizeof(*client
), GFP_KERNEL
);
561 return ERR_PTR(-ENOMEM
);
563 mutex_init(&client
->mount_mutex
);
565 init_waitqueue_head(&client
->auth_wq
);
568 client
->mount_state
= CEPH_MOUNT_MOUNTING
;
569 client
->mount_args
= args
;
573 client
->auth_err
= 0;
574 atomic_long_set(&client
->writeback_count
, 0);
576 err
= bdi_init(&client
->backing_dev_info
);
581 client
->wb_wq
= create_workqueue("ceph-writeback");
582 if (client
->wb_wq
== NULL
)
584 client
->pg_inv_wq
= create_singlethread_workqueue("ceph-pg-invalid");
585 if (client
->pg_inv_wq
== NULL
)
587 client
->trunc_wq
= create_singlethread_workqueue("ceph-trunc");
588 if (client
->trunc_wq
== NULL
)
591 /* set up mempools */
593 client
->wb_pagevec_pool
= mempool_create_kmalloc_pool(10,
594 client
->mount_args
->wsize
>> PAGE_CACHE_SHIFT
);
595 if (!client
->wb_pagevec_pool
)
599 client
->min_caps
= args
->max_readdir
;
600 ceph_adjust_min_caps(client
->min_caps
);
603 err
= ceph_monc_init(&client
->monc
, client
);
606 err
= ceph_osdc_init(&client
->osdc
, client
);
609 err
= ceph_mdsc_init(&client
->mdsc
, client
);
615 ceph_osdc_stop(&client
->osdc
);
617 ceph_monc_stop(&client
->monc
);
619 mempool_destroy(client
->wb_pagevec_pool
);
621 destroy_workqueue(client
->trunc_wq
);
623 destroy_workqueue(client
->pg_inv_wq
);
625 destroy_workqueue(client
->wb_wq
);
627 bdi_destroy(&client
->backing_dev_info
);
633 static void ceph_destroy_client(struct ceph_client
*client
)
635 dout("destroy_client %p\n", client
);
638 ceph_mdsc_stop(&client
->mdsc
);
639 ceph_monc_stop(&client
->monc
);
640 ceph_osdc_stop(&client
->osdc
);
642 ceph_adjust_min_caps(-client
->min_caps
);
644 ceph_debugfs_client_cleanup(client
);
645 destroy_workqueue(client
->wb_wq
);
646 destroy_workqueue(client
->pg_inv_wq
);
647 destroy_workqueue(client
->trunc_wq
);
649 bdi_destroy(&client
->backing_dev_info
);
652 ceph_messenger_destroy(client
->msgr
);
653 mempool_destroy(client
->wb_pagevec_pool
);
655 destroy_mount_args(client
->mount_args
);
658 dout("destroy_client %p done\n", client
);
662 * Initially learn our fsid, or verify an fsid matches.
664 int ceph_check_fsid(struct ceph_client
*client
, struct ceph_fsid
*fsid
)
666 if (client
->have_fsid
) {
667 if (ceph_fsid_compare(&client
->fsid
, fsid
)) {
668 pr_err("bad fsid, had " FSID_FORMAT
" got " FSID_FORMAT
,
669 PR_FSID(&client
->fsid
), PR_FSID(fsid
));
673 pr_info("client%lld fsid " FSID_FORMAT
"\n",
674 client
->monc
.auth
->global_id
, PR_FSID(fsid
));
675 memcpy(&client
->fsid
, fsid
, sizeof(*fsid
));
676 ceph_debugfs_client_init(client
);
677 client
->have_fsid
= true;
683 * true if we have the mon map (and have thus joined the cluster)
685 static int have_mon_map(struct ceph_client
*client
)
687 return client
->monc
.monmap
&& client
->monc
.monmap
->epoch
;
691 * Bootstrap mount by opening the root directory. Note the mount
692 * @started time from caller, and time out if this takes too long.
694 static struct dentry
*open_root_dentry(struct ceph_client
*client
,
696 unsigned long started
)
698 struct ceph_mds_client
*mdsc
= &client
->mdsc
;
699 struct ceph_mds_request
*req
= NULL
;
704 dout("open_root_inode opening '%s'\n", path
);
705 req
= ceph_mdsc_create_request(mdsc
, CEPH_MDS_OP_GETATTR
, USE_ANY_MDS
);
707 return ERR_PTR(PTR_ERR(req
));
708 req
->r_path1
= kstrdup(path
, GFP_NOFS
);
709 req
->r_ino1
.ino
= CEPH_INO_ROOT
;
710 req
->r_ino1
.snap
= CEPH_NOSNAP
;
711 req
->r_started
= started
;
712 req
->r_timeout
= client
->mount_args
->mount_timeout
* HZ
;
713 req
->r_args
.getattr
.mask
= cpu_to_le32(CEPH_STAT_CAP_INODE
);
715 err
= ceph_mdsc_do_request(mdsc
, NULL
, req
);
717 dout("open_root_inode success\n");
718 if (ceph_ino(req
->r_target_inode
) == CEPH_INO_ROOT
&&
719 client
->sb
->s_root
== NULL
)
720 root
= d_alloc_root(req
->r_target_inode
);
722 root
= d_obtain_alias(req
->r_target_inode
);
723 req
->r_target_inode
= NULL
;
724 dout("open_root_inode success, root dentry is %p\n", root
);
728 ceph_mdsc_put_request(req
);
733 * mount: join the ceph cluster, and open root directory.
735 static int ceph_mount(struct ceph_client
*client
, struct vfsmount
*mnt
,
738 struct ceph_entity_addr
*myaddr
= NULL
;
740 unsigned long timeout
= client
->mount_args
->mount_timeout
* HZ
;
741 unsigned long started
= jiffies
; /* note the start time */
744 dout("mount start\n");
745 mutex_lock(&client
->mount_mutex
);
747 /* initialize the messenger */
748 if (client
->msgr
== NULL
) {
749 if (ceph_test_opt(client
, MYIP
))
750 myaddr
= &client
->mount_args
->my_addr
;
751 client
->msgr
= ceph_messenger_create(myaddr
);
752 if (IS_ERR(client
->msgr
)) {
753 err
= PTR_ERR(client
->msgr
);
757 client
->msgr
->nocrc
= ceph_test_opt(client
, NOCRC
);
760 /* open session, and wait for mon, mds, and osd maps */
761 err
= ceph_monc_open_session(&client
->monc
);
765 while (!have_mon_map(client
)) {
767 if (timeout
&& time_after_eq(jiffies
, started
+ timeout
))
771 dout("mount waiting for mon_map\n");
772 err
= wait_event_interruptible_timeout(client
->auth_wq
,
773 have_mon_map(client
) || (client
->auth_err
< 0),
775 if (err
== -EINTR
|| err
== -ERESTARTSYS
)
777 if (client
->auth_err
< 0) {
778 err
= client
->auth_err
;
783 dout("mount opening root\n");
784 root
= open_root_dentry(client
, "", started
);
789 if (client
->sb
->s_root
)
792 client
->sb
->s_root
= root
;
797 dout("mount opening base mountpoint\n");
798 root
= open_root_dentry(client
, path
, started
);
801 dput(client
->sb
->s_root
);
802 client
->sb
->s_root
= NULL
;
807 mnt
->mnt_root
= root
;
808 mnt
->mnt_sb
= client
->sb
;
810 client
->mount_state
= CEPH_MOUNT_MOUNTED
;
811 dout("mount success\n");
815 mutex_unlock(&client
->mount_mutex
);
819 static int ceph_set_super(struct super_block
*s
, void *data
)
821 struct ceph_client
*client
= data
;
824 dout("set_super %p data %p\n", s
, data
);
826 s
->s_flags
= client
->mount_args
->sb_flags
;
827 s
->s_maxbytes
= 1ULL << 40; /* temp value until we get mdsmap */
829 s
->s_fs_info
= client
;
832 s
->s_op
= &ceph_super_ops
;
833 s
->s_export_op
= &ceph_export_ops
;
835 s
->s_time_gran
= 1000; /* 1000 ns == 1 us */
837 ret
= set_anon_super(s
, NULL
); /* what is that second arg for? */
850 * share superblock if same fs AND options
852 static int ceph_compare_super(struct super_block
*sb
, void *data
)
854 struct ceph_client
*new = data
;
855 struct ceph_mount_args
*args
= new->mount_args
;
856 struct ceph_client
*other
= ceph_sb_to_client(sb
);
859 dout("ceph_compare_super %p\n", sb
);
860 if (args
->flags
& CEPH_OPT_FSID
) {
861 if (ceph_fsid_compare(&args
->fsid
, &other
->fsid
)) {
862 dout("fsid doesn't match\n");
866 /* do we share (a) monitor? */
867 for (i
= 0; i
< new->monc
.monmap
->num_mon
; i
++)
868 if (ceph_monmap_contains(other
->monc
.monmap
,
869 &new->monc
.monmap
->mon_inst
[i
].addr
))
871 if (i
== new->monc
.monmap
->num_mon
) {
872 dout("mon ip not part of monmap\n");
875 dout("mon ip matches existing sb %p\n", sb
);
877 if (args
->sb_flags
!= other
->mount_args
->sb_flags
) {
878 dout("flags differ\n");
885 * construct our own bdi so we can control readahead, etc.
887 static int ceph_register_bdi(struct super_block
*sb
, struct ceph_client
*client
)
891 /* set ra_pages based on rsize mount option? */
892 if (client
->mount_args
->rsize
>= PAGE_CACHE_SIZE
)
893 client
->backing_dev_info
.ra_pages
=
894 (client
->mount_args
->rsize
+ PAGE_CACHE_SIZE
- 1)
896 err
= bdi_register_dev(&client
->backing_dev_info
, sb
->s_dev
);
898 sb
->s_bdi
= &client
->backing_dev_info
;
902 static int ceph_get_sb(struct file_system_type
*fs_type
,
903 int flags
, const char *dev_name
, void *data
,
904 struct vfsmount
*mnt
)
906 struct super_block
*sb
;
907 struct ceph_client
*client
;
909 int (*compare_super
)(struct super_block
*, void *) = ceph_compare_super
;
910 const char *path
= NULL
;
911 struct ceph_mount_args
*args
;
913 dout("ceph_get_sb\n");
914 args
= parse_mount_args(flags
, data
, dev_name
, &path
);
920 /* create client (which we may/may not use) */
921 client
= ceph_create_client(args
);
922 if (IS_ERR(client
)) {
923 err
= PTR_ERR(client
);
927 if (client
->mount_args
->flags
& CEPH_OPT_NOSHARE
)
928 compare_super
= NULL
;
929 sb
= sget(fs_type
, compare_super
, ceph_set_super
, client
);
935 if (ceph_client(sb
) != client
) {
936 ceph_destroy_client(client
);
937 client
= ceph_client(sb
);
938 dout("get_sb got existing client %p\n", client
);
940 dout("get_sb using new client %p\n", client
);
941 err
= ceph_register_bdi(sb
, client
);
946 err
= ceph_mount(client
, mnt
, path
);
949 dout("root %p inode %p ino %llx.%llx\n", mnt
->mnt_root
,
950 mnt
->mnt_root
->d_inode
, ceph_vinop(mnt
->mnt_root
->d_inode
));
954 ceph_mdsc_close_sessions(&client
->mdsc
);
955 up_write(&sb
->s_umount
);
956 deactivate_super(sb
);
960 ceph_destroy_client(client
);
962 dout("ceph_get_sb fail %d\n", err
);
966 static void ceph_kill_sb(struct super_block
*s
)
968 struct ceph_client
*client
= ceph_sb_to_client(s
);
969 dout("kill_sb %p\n", s
);
970 ceph_mdsc_pre_umount(&client
->mdsc
);
971 kill_anon_super(s
); /* will call put_super after sb is r/o */
972 ceph_destroy_client(client
);
975 static struct file_system_type ceph_fs_type
= {
976 .owner
= THIS_MODULE
,
978 .get_sb
= ceph_get_sb
,
979 .kill_sb
= ceph_kill_sb
,
980 .fs_flags
= FS_RENAME_DOES_D_MOVE
,
983 #define _STRINGIFY(x) #x
984 #define STRINGIFY(x) _STRINGIFY(x)
986 static int __init
init_ceph(void)
990 ret
= ceph_debugfs_init();
994 ret
= ceph_msgr_init();
1004 ret
= register_filesystem(&ceph_fs_type
);
1008 pr_info("loaded (mon/mds/osd proto %d/%d/%d, osdmap %d/%d %d/%d)\n",
1009 CEPH_MONC_PROTOCOL
, CEPH_MDSC_PROTOCOL
, CEPH_OSDC_PROTOCOL
,
1010 CEPH_OSDMAP_VERSION
, CEPH_OSDMAP_VERSION_EXT
,
1011 CEPH_OSDMAP_INC_VERSION
, CEPH_OSDMAP_INC_VERSION_EXT
);
1019 ceph_debugfs_cleanup();
1024 static void __exit
exit_ceph(void)
1026 dout("exit_ceph\n");
1027 unregister_filesystem(&ceph_fs_type
);
1028 ceph_caps_finalize();
1031 ceph_debugfs_cleanup();
1034 module_init(init_ceph
);
1035 module_exit(exit_ceph
);
1037 MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
1038 MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
1039 MODULE_AUTHOR("Patience Warnick <patience@newdream.net>");
1040 MODULE_DESCRIPTION("Ceph filesystem for Linux");
1041 MODULE_LICENSE("GPL");