2 #include "ceph_debug.h"
4 #include <linux/backing-dev.h>
5 #include <linux/ctype.h>
7 #include <linux/inet.h>
9 #include <linux/module.h>
10 #include <linux/mount.h>
11 #include <linux/parser.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>
20 #include "mon_client.h"
24 * Ceph superblock operations
26 * Handle the basics of mounting, unmounting.
31 * find filename portion of a path (/foo/bar/baz -> baz)
33 const char *ceph_file_part(const char *s
, int len
)
35 const char *e
= s
+ len
;
37 while (e
!= s
&& *(e
-1) != '/')
46 static void ceph_put_super(struct super_block
*s
)
48 struct ceph_client
*client
= ceph_sb_to_client(s
);
51 ceph_mdsc_close_sessions(&client
->mdsc
);
54 * ensure we release the bdi before put_anon_super releases
57 if (s
->s_bdi
== &client
->backing_dev_info
) {
58 bdi_unregister(&client
->backing_dev_info
);
65 static int ceph_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
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
;
74 err
= ceph_monc_do_statfs(&client
->monc
, &st
);
79 buf
->f_type
= CEPH_SUPER_MAGIC
; /* ?? */
82 * express utilization in terms of large blocks to avoid
83 * overflow on 32-bit machines.
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);
91 buf
->f_files
= le64_to_cpu(st
.num_objects
);
93 buf
->f_namelen
= NAME_MAX
;
94 buf
->f_frsize
= PAGE_CACHE_SIZE
;
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;
105 static int ceph_sync_fs(struct super_block
*sb
, int wait
)
107 struct ceph_client
*client
= ceph_sb_to_client(sb
);
110 dout("sync_fs (non-blocking)\n");
111 ceph_flush_dirty_caps(&client
->mdsc
);
112 dout("sync_fs (non-blocking) done\n");
116 dout("sync_fs (blocking)\n");
117 ceph_osdc_sync(&ceph_sb_to_client(sb
)->osdc
);
118 ceph_mdsc_sync(&ceph_sb_to_client(sb
)->mdsc
);
119 dout("sync_fs (blocking) done\n");
123 static int default_congestion_kb(void)
130 * congestion size, scale with available memory.
142 * This allows larger machines to have larger/more transfers.
143 * Limit the default to 256M
145 congestion_kb
= (16*int_sqrt(totalram_pages
)) << (PAGE_SHIFT
-10);
146 if (congestion_kb
> 256*1024)
147 congestion_kb
= 256*1024;
149 return congestion_kb
;
153 * ceph_show_options - Show mount options in /proc/mounts
154 * @m: seq_file to write to
155 * @mnt: mount descriptor
157 static int ceph_show_options(struct seq_file
*m
, struct vfsmount
*mnt
)
159 struct ceph_client
*client
= ceph_sb_to_client(mnt
->mnt_sb
);
160 struct ceph_mount_args
*args
= client
->mount_args
;
162 if (args
->flags
& CEPH_OPT_FSID
)
163 seq_printf(m
, ",fsid=%pU", &args
->fsid
);
164 if (args
->flags
& CEPH_OPT_NOSHARE
)
165 seq_puts(m
, ",noshare");
166 if (args
->flags
& CEPH_OPT_DIRSTAT
)
167 seq_puts(m
, ",dirstat");
168 if ((args
->flags
& CEPH_OPT_RBYTES
) == 0)
169 seq_puts(m
, ",norbytes");
170 if (args
->flags
& CEPH_OPT_NOCRC
)
171 seq_puts(m
, ",nocrc");
172 if (args
->flags
& CEPH_OPT_NOASYNCREADDIR
)
173 seq_puts(m
, ",noasyncreaddir");
175 if (args
->mount_timeout
!= CEPH_MOUNT_TIMEOUT_DEFAULT
)
176 seq_printf(m
, ",mount_timeout=%d", args
->mount_timeout
);
177 if (args
->osd_idle_ttl
!= CEPH_OSD_IDLE_TTL_DEFAULT
)
178 seq_printf(m
, ",osd_idle_ttl=%d", args
->osd_idle_ttl
);
179 if (args
->osd_timeout
!= CEPH_OSD_TIMEOUT_DEFAULT
)
180 seq_printf(m
, ",osdtimeout=%d", args
->osd_timeout
);
181 if (args
->osd_keepalive_timeout
!= CEPH_OSD_KEEPALIVE_DEFAULT
)
182 seq_printf(m
, ",osdkeepalivetimeout=%d",
183 args
->osd_keepalive_timeout
);
185 seq_printf(m
, ",wsize=%d", args
->wsize
);
186 if (args
->rsize
!= CEPH_MOUNT_RSIZE_DEFAULT
)
187 seq_printf(m
, ",rsize=%d", args
->rsize
);
188 if (args
->congestion_kb
!= default_congestion_kb())
189 seq_printf(m
, ",write_congestion_kb=%d", args
->congestion_kb
);
190 if (args
->caps_wanted_delay_min
!= CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT
)
191 seq_printf(m
, ",caps_wanted_delay_min=%d",
192 args
->caps_wanted_delay_min
);
193 if (args
->caps_wanted_delay_max
!= CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT
)
194 seq_printf(m
, ",caps_wanted_delay_max=%d",
195 args
->caps_wanted_delay_max
);
196 if (args
->cap_release_safety
!= CEPH_CAP_RELEASE_SAFETY_DEFAULT
)
197 seq_printf(m
, ",cap_release_safety=%d",
198 args
->cap_release_safety
);
199 if (args
->max_readdir
!= CEPH_MAX_READDIR_DEFAULT
)
200 seq_printf(m
, ",readdir_max_entries=%d", args
->max_readdir
);
201 if (args
->max_readdir_bytes
!= CEPH_MAX_READDIR_BYTES_DEFAULT
)
202 seq_printf(m
, ",readdir_max_bytes=%d", args
->max_readdir_bytes
);
203 if (strcmp(args
->snapdir_name
, CEPH_SNAPDIRNAME_DEFAULT
))
204 seq_printf(m
, ",snapdirname=%s", args
->snapdir_name
);
206 seq_printf(m
, ",name=%s", args
->name
);
208 seq_puts(m
, ",secret=<hidden>");
215 struct kmem_cache
*ceph_inode_cachep
;
216 struct kmem_cache
*ceph_cap_cachep
;
217 struct kmem_cache
*ceph_dentry_cachep
;
218 struct kmem_cache
*ceph_file_cachep
;
220 static void ceph_inode_init_once(void *foo
)
222 struct ceph_inode_info
*ci
= foo
;
223 inode_init_once(&ci
->vfs_inode
);
226 static int __init
init_caches(void)
228 ceph_inode_cachep
= kmem_cache_create("ceph_inode_info",
229 sizeof(struct ceph_inode_info
),
230 __alignof__(struct ceph_inode_info
),
231 (SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
),
232 ceph_inode_init_once
);
233 if (ceph_inode_cachep
== NULL
)
236 ceph_cap_cachep
= KMEM_CACHE(ceph_cap
,
237 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
);
238 if (ceph_cap_cachep
== NULL
)
241 ceph_dentry_cachep
= KMEM_CACHE(ceph_dentry_info
,
242 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
);
243 if (ceph_dentry_cachep
== NULL
)
246 ceph_file_cachep
= KMEM_CACHE(ceph_file_info
,
247 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
);
248 if (ceph_file_cachep
== NULL
)
254 kmem_cache_destroy(ceph_dentry_cachep
);
256 kmem_cache_destroy(ceph_cap_cachep
);
258 kmem_cache_destroy(ceph_inode_cachep
);
262 static void destroy_caches(void)
264 kmem_cache_destroy(ceph_inode_cachep
);
265 kmem_cache_destroy(ceph_cap_cachep
);
266 kmem_cache_destroy(ceph_dentry_cachep
);
267 kmem_cache_destroy(ceph_file_cachep
);
272 * ceph_umount_begin - initiate forced umount. Tear down down the
273 * mount, skipping steps that may hang while waiting for server(s).
275 static void ceph_umount_begin(struct super_block
*sb
)
277 struct ceph_client
*client
= ceph_sb_to_client(sb
);
279 dout("ceph_umount_begin - starting forced umount\n");
282 client
->mount_state
= CEPH_MOUNT_SHUTDOWN
;
286 static const struct super_operations ceph_super_ops
= {
287 .alloc_inode
= ceph_alloc_inode
,
288 .destroy_inode
= ceph_destroy_inode
,
289 .write_inode
= ceph_write_inode
,
290 .sync_fs
= ceph_sync_fs
,
291 .put_super
= ceph_put_super
,
292 .show_options
= ceph_show_options
,
293 .statfs
= ceph_statfs
,
294 .umount_begin
= ceph_umount_begin
,
298 const char *ceph_msg_type_name(int type
)
301 case CEPH_MSG_SHUTDOWN
: return "shutdown";
302 case CEPH_MSG_PING
: return "ping";
303 case CEPH_MSG_AUTH
: return "auth";
304 case CEPH_MSG_AUTH_REPLY
: return "auth_reply";
305 case CEPH_MSG_MON_MAP
: return "mon_map";
306 case CEPH_MSG_MON_GET_MAP
: return "mon_get_map";
307 case CEPH_MSG_MON_SUBSCRIBE
: return "mon_subscribe";
308 case CEPH_MSG_MON_SUBSCRIBE_ACK
: return "mon_subscribe_ack";
309 case CEPH_MSG_STATFS
: return "statfs";
310 case CEPH_MSG_STATFS_REPLY
: return "statfs_reply";
311 case CEPH_MSG_MDS_MAP
: return "mds_map";
312 case CEPH_MSG_CLIENT_SESSION
: return "client_session";
313 case CEPH_MSG_CLIENT_RECONNECT
: return "client_reconnect";
314 case CEPH_MSG_CLIENT_REQUEST
: return "client_request";
315 case CEPH_MSG_CLIENT_REQUEST_FORWARD
: return "client_request_forward";
316 case CEPH_MSG_CLIENT_REPLY
: return "client_reply";
317 case CEPH_MSG_CLIENT_CAPS
: return "client_caps";
318 case CEPH_MSG_CLIENT_CAPRELEASE
: return "client_cap_release";
319 case CEPH_MSG_CLIENT_SNAP
: return "client_snap";
320 case CEPH_MSG_CLIENT_LEASE
: return "client_lease";
321 case CEPH_MSG_OSD_MAP
: return "osd_map";
322 case CEPH_MSG_OSD_OP
: return "osd_op";
323 case CEPH_MSG_OSD_OPREPLY
: return "osd_opreply";
324 default: return "unknown";
336 Opt_osdkeepalivetimeout
,
339 Opt_caps_wanted_delay_min
,
340 Opt_caps_wanted_delay_max
,
341 Opt_cap_release_safety
,
342 Opt_readdir_max_entries
,
343 Opt_readdir_max_bytes
,
352 /* string args above */
363 static match_table_t arg_tokens
= {
364 {Opt_wsize
, "wsize=%d"},
365 {Opt_rsize
, "rsize=%d"},
366 {Opt_osdtimeout
, "osdtimeout=%d"},
367 {Opt_osdkeepalivetimeout
, "osdkeepalive=%d"},
368 {Opt_mount_timeout
, "mount_timeout=%d"},
369 {Opt_osd_idle_ttl
, "osd_idle_ttl=%d"},
370 {Opt_caps_wanted_delay_min
, "caps_wanted_delay_min=%d"},
371 {Opt_caps_wanted_delay_max
, "caps_wanted_delay_max=%d"},
372 {Opt_cap_release_safety
, "cap_release_safety=%d"},
373 {Opt_readdir_max_entries
, "readdir_max_entries=%d"},
374 {Opt_readdir_max_bytes
, "readdir_max_bytes=%d"},
375 {Opt_congestion_kb
, "write_congestion_kb=%d"},
377 {Opt_fsid
, "fsid=%s"},
378 {Opt_snapdirname
, "snapdirname=%s"},
379 {Opt_name
, "name=%s"},
380 {Opt_secret
, "secret=%s"},
381 /* string args above */
383 {Opt_noshare
, "noshare"},
384 {Opt_dirstat
, "dirstat"},
385 {Opt_nodirstat
, "nodirstat"},
386 {Opt_rbytes
, "rbytes"},
387 {Opt_norbytes
, "norbytes"},
388 {Opt_nocrc
, "nocrc"},
389 {Opt_noasyncreaddir
, "noasyncreaddir"},
393 static int parse_fsid(const char *str
, struct ceph_fsid
*fsid
)
400 dout("parse_fsid '%s'\n", str
);
402 while (*str
&& i
< 16) {
407 if (!isxdigit(str
[0]) || !isxdigit(str
[1]))
411 if (sscanf(tmp
, "%x", &d
) < 1)
413 fsid
->fsid
[i
] = d
& 0xff;
420 dout("parse_fsid ret %d got fsid %pU", err
, fsid
);
424 static struct ceph_mount_args
*parse_mount_args(int flags
, char *options
,
425 const char *dev_name
,
428 struct ceph_mount_args
*args
;
431 substring_t argstr
[MAX_OPT_ARGS
];
433 args
= kzalloc(sizeof(*args
), GFP_KERNEL
);
435 return ERR_PTR(-ENOMEM
);
436 args
->mon_addr
= kcalloc(CEPH_MAX_MON
, sizeof(*args
->mon_addr
),
441 dout("parse_mount_args %p, dev_name '%s'\n", args
, dev_name
);
443 /* start with defaults */
444 args
->sb_flags
= flags
;
445 args
->flags
= CEPH_OPT_DEFAULT
;
446 args
->osd_timeout
= CEPH_OSD_TIMEOUT_DEFAULT
;
447 args
->osd_keepalive_timeout
= CEPH_OSD_KEEPALIVE_DEFAULT
;
448 args
->mount_timeout
= CEPH_MOUNT_TIMEOUT_DEFAULT
; /* seconds */
449 args
->osd_idle_ttl
= CEPH_OSD_IDLE_TTL_DEFAULT
; /* seconds */
450 args
->caps_wanted_delay_min
= CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT
;
451 args
->caps_wanted_delay_max
= CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT
;
452 args
->rsize
= CEPH_MOUNT_RSIZE_DEFAULT
;
453 args
->snapdir_name
= kstrdup(CEPH_SNAPDIRNAME_DEFAULT
, GFP_KERNEL
);
454 args
->cap_release_safety
= CEPH_CAP_RELEASE_SAFETY_DEFAULT
;
455 args
->max_readdir
= CEPH_MAX_READDIR_DEFAULT
;
456 args
->max_readdir_bytes
= CEPH_MAX_READDIR_BYTES_DEFAULT
;
457 args
->congestion_kb
= default_congestion_kb();
459 /* ip1[:port1][,ip2[:port2]...]:/subdir/in/fs */
463 *path
= strstr(dev_name
, ":/");
465 pr_err("device name is missing path (no :/ in %s)\n",
471 err
= ceph_parse_ips(dev_name
, *path
, args
->mon_addr
,
472 CEPH_MAX_MON
, &args
->num_mon
);
478 dout("server path '%s'\n", *path
);
480 /* parse mount options */
481 while ((c
= strsep(&options
, ",")) != NULL
) {
482 int token
, intval
, ret
;
486 token
= match_token((char *)c
, arg_tokens
, argstr
);
488 pr_err("bad mount option at '%s'\n", c
);
491 if (token
< Opt_last_int
) {
492 ret
= match_int(&argstr
[0], &intval
);
494 pr_err("bad mount option arg (not int) "
498 dout("got int token %d val %d\n", token
, intval
);
499 } else if (token
> Opt_last_int
&& token
< Opt_last_string
) {
500 dout("got string token %d val %s\n", token
,
503 dout("got token %d\n", token
);
507 err
= ceph_parse_ips(argstr
[0].from
,
513 args
->flags
|= CEPH_OPT_MYIP
;
517 err
= parse_fsid(argstr
[0].from
, &args
->fsid
);
519 args
->flags
|= CEPH_OPT_FSID
;
521 case Opt_snapdirname
:
522 kfree(args
->snapdir_name
);
523 args
->snapdir_name
= kstrndup(argstr
[0].from
,
524 argstr
[0].to
-argstr
[0].from
,
528 args
->name
= kstrndup(argstr
[0].from
,
529 argstr
[0].to
-argstr
[0].from
,
533 args
->secret
= kstrndup(argstr
[0].from
,
534 argstr
[0].to
-argstr
[0].from
,
540 args
->wsize
= intval
;
543 args
->rsize
= intval
;
546 args
->osd_timeout
= intval
;
548 case Opt_osdkeepalivetimeout
:
549 args
->osd_keepalive_timeout
= intval
;
551 case Opt_osd_idle_ttl
:
552 args
->osd_idle_ttl
= intval
;
554 case Opt_mount_timeout
:
555 args
->mount_timeout
= intval
;
557 case Opt_caps_wanted_delay_min
:
558 args
->caps_wanted_delay_min
= intval
;
560 case Opt_caps_wanted_delay_max
:
561 args
->caps_wanted_delay_max
= intval
;
563 case Opt_readdir_max_entries
:
564 args
->max_readdir
= intval
;
566 case Opt_readdir_max_bytes
:
567 args
->max_readdir_bytes
= intval
;
569 case Opt_congestion_kb
:
570 args
->congestion_kb
= intval
;
574 args
->flags
|= CEPH_OPT_NOSHARE
;
578 args
->flags
|= CEPH_OPT_DIRSTAT
;
581 args
->flags
&= ~CEPH_OPT_DIRSTAT
;
584 args
->flags
|= CEPH_OPT_RBYTES
;
587 args
->flags
&= ~CEPH_OPT_RBYTES
;
590 args
->flags
|= CEPH_OPT_NOCRC
;
592 case Opt_noasyncreaddir
:
593 args
->flags
|= CEPH_OPT_NOASYNCREADDIR
;
603 kfree(args
->mon_addr
);
608 static void destroy_mount_args(struct ceph_mount_args
*args
)
610 dout("destroy_mount_args %p\n", args
);
611 kfree(args
->snapdir_name
);
612 args
->snapdir_name
= NULL
;
621 * create a fresh client instance
623 static struct ceph_client
*ceph_create_client(struct ceph_mount_args
*args
)
625 struct ceph_client
*client
;
628 client
= kzalloc(sizeof(*client
), GFP_KERNEL
);
630 return ERR_PTR(-ENOMEM
);
632 mutex_init(&client
->mount_mutex
);
634 init_waitqueue_head(&client
->auth_wq
);
637 client
->mount_state
= CEPH_MOUNT_MOUNTING
;
638 client
->mount_args
= args
;
642 client
->auth_err
= 0;
643 atomic_long_set(&client
->writeback_count
, 0);
645 err
= bdi_init(&client
->backing_dev_info
);
650 client
->wb_wq
= create_workqueue("ceph-writeback");
651 if (client
->wb_wq
== NULL
)
653 client
->pg_inv_wq
= create_singlethread_workqueue("ceph-pg-invalid");
654 if (client
->pg_inv_wq
== NULL
)
656 client
->trunc_wq
= create_singlethread_workqueue("ceph-trunc");
657 if (client
->trunc_wq
== NULL
)
660 /* set up mempools */
662 client
->wb_pagevec_pool
= mempool_create_kmalloc_pool(10,
663 client
->mount_args
->wsize
>> PAGE_CACHE_SHIFT
);
664 if (!client
->wb_pagevec_pool
)
668 client
->min_caps
= args
->max_readdir
;
671 err
= ceph_monc_init(&client
->monc
, client
);
674 err
= ceph_osdc_init(&client
->osdc
, client
);
677 err
= ceph_mdsc_init(&client
->mdsc
, client
);
683 ceph_osdc_stop(&client
->osdc
);
685 ceph_monc_stop(&client
->monc
);
687 mempool_destroy(client
->wb_pagevec_pool
);
689 destroy_workqueue(client
->trunc_wq
);
691 destroy_workqueue(client
->pg_inv_wq
);
693 destroy_workqueue(client
->wb_wq
);
695 bdi_destroy(&client
->backing_dev_info
);
701 static void ceph_destroy_client(struct ceph_client
*client
)
703 dout("destroy_client %p\n", client
);
706 ceph_mdsc_stop(&client
->mdsc
);
707 ceph_osdc_stop(&client
->osdc
);
710 * make sure mds and osd connections close out before destroying
711 * the auth module, which is needed to free those connections'
716 ceph_monc_stop(&client
->monc
);
718 ceph_debugfs_client_cleanup(client
);
719 destroy_workqueue(client
->wb_wq
);
720 destroy_workqueue(client
->pg_inv_wq
);
721 destroy_workqueue(client
->trunc_wq
);
723 bdi_destroy(&client
->backing_dev_info
);
726 ceph_messenger_destroy(client
->msgr
);
727 mempool_destroy(client
->wb_pagevec_pool
);
729 destroy_mount_args(client
->mount_args
);
732 dout("destroy_client %p done\n", client
);
736 * Initially learn our fsid, or verify an fsid matches.
738 int ceph_check_fsid(struct ceph_client
*client
, struct ceph_fsid
*fsid
)
740 if (client
->have_fsid
) {
741 if (ceph_fsid_compare(&client
->fsid
, fsid
)) {
742 pr_err("bad fsid, had %pU got %pU",
743 &client
->fsid
, fsid
);
747 pr_info("client%lld fsid %pU\n", client
->monc
.auth
->global_id
,
749 memcpy(&client
->fsid
, fsid
, sizeof(*fsid
));
750 ceph_debugfs_client_init(client
);
751 client
->have_fsid
= true;
757 * true if we have the mon map (and have thus joined the cluster)
759 static int have_mon_and_osd_map(struct ceph_client
*client
)
761 return client
->monc
.monmap
&& client
->monc
.monmap
->epoch
&&
762 client
->osdc
.osdmap
&& client
->osdc
.osdmap
->epoch
;
766 * Bootstrap mount by opening the root directory. Note the mount
767 * @started time from caller, and time out if this takes too long.
769 static struct dentry
*open_root_dentry(struct ceph_client
*client
,
771 unsigned long started
)
773 struct ceph_mds_client
*mdsc
= &client
->mdsc
;
774 struct ceph_mds_request
*req
= NULL
;
779 dout("open_root_inode opening '%s'\n", path
);
780 req
= ceph_mdsc_create_request(mdsc
, CEPH_MDS_OP_GETATTR
, USE_ANY_MDS
);
782 return ERR_CAST(req
);
783 req
->r_path1
= kstrdup(path
, GFP_NOFS
);
784 req
->r_ino1
.ino
= CEPH_INO_ROOT
;
785 req
->r_ino1
.snap
= CEPH_NOSNAP
;
786 req
->r_started
= started
;
787 req
->r_timeout
= client
->mount_args
->mount_timeout
* HZ
;
788 req
->r_args
.getattr
.mask
= cpu_to_le32(CEPH_STAT_CAP_INODE
);
790 err
= ceph_mdsc_do_request(mdsc
, NULL
, req
);
792 dout("open_root_inode success\n");
793 if (ceph_ino(req
->r_target_inode
) == CEPH_INO_ROOT
&&
794 client
->sb
->s_root
== NULL
)
795 root
= d_alloc_root(req
->r_target_inode
);
797 root
= d_obtain_alias(req
->r_target_inode
);
798 req
->r_target_inode
= NULL
;
799 dout("open_root_inode success, root dentry is %p\n", root
);
803 ceph_mdsc_put_request(req
);
808 * mount: join the ceph cluster, and open root directory.
810 static int ceph_mount(struct ceph_client
*client
, struct vfsmount
*mnt
,
813 struct ceph_entity_addr
*myaddr
= NULL
;
815 unsigned long timeout
= client
->mount_args
->mount_timeout
* HZ
;
816 unsigned long started
= jiffies
; /* note the start time */
819 dout("mount start\n");
820 mutex_lock(&client
->mount_mutex
);
822 /* initialize the messenger */
823 if (client
->msgr
== NULL
) {
824 if (ceph_test_opt(client
, MYIP
))
825 myaddr
= &client
->mount_args
->my_addr
;
826 client
->msgr
= ceph_messenger_create(myaddr
);
827 if (IS_ERR(client
->msgr
)) {
828 err
= PTR_ERR(client
->msgr
);
832 client
->msgr
->nocrc
= ceph_test_opt(client
, NOCRC
);
835 /* open session, and wait for mon, mds, and osd maps */
836 err
= ceph_monc_open_session(&client
->monc
);
840 while (!have_mon_and_osd_map(client
)) {
842 if (timeout
&& time_after_eq(jiffies
, started
+ timeout
))
846 dout("mount waiting for mon_map\n");
847 err
= wait_event_interruptible_timeout(client
->auth_wq
,
848 have_mon_and_osd_map(client
) || (client
->auth_err
< 0),
850 if (err
== -EINTR
|| err
== -ERESTARTSYS
)
852 if (client
->auth_err
< 0) {
853 err
= client
->auth_err
;
858 dout("mount opening root\n");
859 root
= open_root_dentry(client
, "", started
);
864 if (client
->sb
->s_root
)
867 client
->sb
->s_root
= root
;
872 dout("mount opening base mountpoint\n");
873 root
= open_root_dentry(client
, path
, started
);
876 dput(client
->sb
->s_root
);
877 client
->sb
->s_root
= NULL
;
882 mnt
->mnt_root
= root
;
883 mnt
->mnt_sb
= client
->sb
;
885 client
->mount_state
= CEPH_MOUNT_MOUNTED
;
886 dout("mount success\n");
890 mutex_unlock(&client
->mount_mutex
);
894 static int ceph_set_super(struct super_block
*s
, void *data
)
896 struct ceph_client
*client
= data
;
899 dout("set_super %p data %p\n", s
, data
);
901 s
->s_flags
= client
->mount_args
->sb_flags
;
902 s
->s_maxbytes
= 1ULL << 40; /* temp value until we get mdsmap */
904 s
->s_fs_info
= client
;
907 s
->s_op
= &ceph_super_ops
;
908 s
->s_export_op
= &ceph_export_ops
;
910 s
->s_time_gran
= 1000; /* 1000 ns == 1 us */
912 ret
= set_anon_super(s
, NULL
); /* what is that second arg for? */
925 * share superblock if same fs AND options
927 static int ceph_compare_super(struct super_block
*sb
, void *data
)
929 struct ceph_client
*new = data
;
930 struct ceph_mount_args
*args
= new->mount_args
;
931 struct ceph_client
*other
= ceph_sb_to_client(sb
);
934 dout("ceph_compare_super %p\n", sb
);
935 if (args
->flags
& CEPH_OPT_FSID
) {
936 if (ceph_fsid_compare(&args
->fsid
, &other
->fsid
)) {
937 dout("fsid doesn't match\n");
941 /* do we share (a) monitor? */
942 for (i
= 0; i
< new->monc
.monmap
->num_mon
; i
++)
943 if (ceph_monmap_contains(other
->monc
.monmap
,
944 &new->monc
.monmap
->mon_inst
[i
].addr
))
946 if (i
== new->monc
.monmap
->num_mon
) {
947 dout("mon ip not part of monmap\n");
950 dout("mon ip matches existing sb %p\n", sb
);
952 if (args
->sb_flags
!= other
->mount_args
->sb_flags
) {
953 dout("flags differ\n");
960 * construct our own bdi so we can control readahead, etc.
962 static atomic_long_t bdi_seq
= ATOMIC_LONG_INIT(0);
964 static int ceph_register_bdi(struct super_block
*sb
, struct ceph_client
*client
)
968 /* set ra_pages based on rsize mount option? */
969 if (client
->mount_args
->rsize
>= PAGE_CACHE_SIZE
)
970 client
->backing_dev_info
.ra_pages
=
971 (client
->mount_args
->rsize
+ PAGE_CACHE_SIZE
- 1)
973 err
= bdi_register(&client
->backing_dev_info
, NULL
, "ceph-%d",
974 atomic_long_inc_return(&bdi_seq
));
976 sb
->s_bdi
= &client
->backing_dev_info
;
980 static int ceph_get_sb(struct file_system_type
*fs_type
,
981 int flags
, const char *dev_name
, void *data
,
982 struct vfsmount
*mnt
)
984 struct super_block
*sb
;
985 struct ceph_client
*client
;
987 int (*compare_super
)(struct super_block
*, void *) = ceph_compare_super
;
988 const char *path
= NULL
;
989 struct ceph_mount_args
*args
;
991 dout("ceph_get_sb\n");
992 args
= parse_mount_args(flags
, data
, dev_name
, &path
);
998 /* create client (which we may/may not use) */
999 client
= ceph_create_client(args
);
1000 if (IS_ERR(client
)) {
1001 err
= PTR_ERR(client
);
1005 if (client
->mount_args
->flags
& CEPH_OPT_NOSHARE
)
1006 compare_super
= NULL
;
1007 sb
= sget(fs_type
, compare_super
, ceph_set_super
, client
);
1013 if (ceph_sb_to_client(sb
) != client
) {
1014 ceph_destroy_client(client
);
1015 client
= ceph_sb_to_client(sb
);
1016 dout("get_sb got existing client %p\n", client
);
1018 dout("get_sb using new client %p\n", client
);
1019 err
= ceph_register_bdi(sb
, client
);
1024 err
= ceph_mount(client
, mnt
, path
);
1027 dout("root %p inode %p ino %llx.%llx\n", mnt
->mnt_root
,
1028 mnt
->mnt_root
->d_inode
, ceph_vinop(mnt
->mnt_root
->d_inode
));
1032 ceph_mdsc_close_sessions(&client
->mdsc
);
1033 deactivate_locked_super(sb
);
1037 ceph_destroy_client(client
);
1039 dout("ceph_get_sb fail %d\n", err
);
1043 static void ceph_kill_sb(struct super_block
*s
)
1045 struct ceph_client
*client
= ceph_sb_to_client(s
);
1046 dout("kill_sb %p\n", s
);
1047 ceph_mdsc_pre_umount(&client
->mdsc
);
1048 kill_anon_super(s
); /* will call put_super after sb is r/o */
1049 ceph_destroy_client(client
);
1052 static struct file_system_type ceph_fs_type
= {
1053 .owner
= THIS_MODULE
,
1055 .get_sb
= ceph_get_sb
,
1056 .kill_sb
= ceph_kill_sb
,
1057 .fs_flags
= FS_RENAME_DOES_D_MOVE
,
1060 #define _STRINGIFY(x) #x
1061 #define STRINGIFY(x) _STRINGIFY(x)
1063 static int __init
init_ceph(void)
1067 ret
= ceph_debugfs_init();
1071 ret
= ceph_msgr_init();
1075 ret
= init_caches();
1079 ret
= register_filesystem(&ceph_fs_type
);
1083 pr_info("loaded (mon/mds/osd proto %d/%d/%d, osdmap %d/%d %d/%d)\n",
1084 CEPH_MONC_PROTOCOL
, CEPH_MDSC_PROTOCOL
, CEPH_OSDC_PROTOCOL
,
1085 CEPH_OSDMAP_VERSION
, CEPH_OSDMAP_VERSION_EXT
,
1086 CEPH_OSDMAP_INC_VERSION
, CEPH_OSDMAP_INC_VERSION_EXT
);
1094 ceph_debugfs_cleanup();
1099 static void __exit
exit_ceph(void)
1101 dout("exit_ceph\n");
1102 unregister_filesystem(&ceph_fs_type
);
1105 ceph_debugfs_cleanup();
1108 module_init(init_ceph
);
1109 module_exit(exit_ceph
);
1111 MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
1112 MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
1113 MODULE_AUTHOR("Patience Warnick <patience@newdream.net>");
1114 MODULE_DESCRIPTION("Ceph filesystem for Linux");
1115 MODULE_LICENSE("GPL");