2 #include <linux/ceph/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>
19 #include "mds_client.h"
22 #include <linux/ceph/ceph_features.h>
23 #include <linux/ceph/decode.h>
24 #include <linux/ceph/mon_client.h>
25 #include <linux/ceph/auth.h>
26 #include <linux/ceph/debugfs.h>
29 * Ceph superblock operations
31 * Handle the basics of mounting, unmounting.
37 static void ceph_put_super(struct super_block
*s
)
39 struct ceph_fs_client
*fsc
= ceph_sb_to_client(s
);
42 ceph_mdsc_close_sessions(fsc
->mdsc
);
45 static int ceph_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
47 struct ceph_fs_client
*fsc
= ceph_inode_to_client(d_inode(dentry
));
48 struct ceph_monmap
*monmap
= fsc
->client
->monc
.monmap
;
49 struct ceph_statfs st
;
54 err
= ceph_monc_do_statfs(&fsc
->client
->monc
, &st
);
59 buf
->f_type
= CEPH_SUPER_MAGIC
; /* ?? */
62 * express utilization in terms of large blocks to avoid
63 * overflow on 32-bit machines.
65 * NOTE: for the time being, we make bsize == frsize to humor
66 * not-yet-ancient versions of glibc that are broken.
67 * Someday, we will probably want to report a real block
68 * size... whatever that may mean for a network file system!
70 buf
->f_bsize
= 1 << CEPH_BLOCK_SHIFT
;
71 buf
->f_frsize
= 1 << CEPH_BLOCK_SHIFT
;
72 buf
->f_blocks
= le64_to_cpu(st
.kb
) >> (CEPH_BLOCK_SHIFT
-10);
73 buf
->f_bfree
= le64_to_cpu(st
.kb_avail
) >> (CEPH_BLOCK_SHIFT
-10);
74 buf
->f_bavail
= le64_to_cpu(st
.kb_avail
) >> (CEPH_BLOCK_SHIFT
-10);
76 buf
->f_files
= le64_to_cpu(st
.num_objects
);
78 buf
->f_namelen
= NAME_MAX
;
80 /* leave fsid little-endian, regardless of host endianness */
81 fsid
= *(u64
*)(&monmap
->fsid
) ^ *((u64
*)&monmap
->fsid
+ 1);
82 buf
->f_fsid
.val
[0] = fsid
& 0xffffffff;
83 buf
->f_fsid
.val
[1] = fsid
>> 32;
89 static int ceph_sync_fs(struct super_block
*sb
, int wait
)
91 struct ceph_fs_client
*fsc
= ceph_sb_to_client(sb
);
94 dout("sync_fs (non-blocking)\n");
95 ceph_flush_dirty_caps(fsc
->mdsc
);
96 dout("sync_fs (non-blocking) done\n");
100 dout("sync_fs (blocking)\n");
101 ceph_osdc_sync(&fsc
->client
->osdc
);
102 ceph_mdsc_sync(fsc
->mdsc
);
103 dout("sync_fs (blocking) done\n");
114 Opt_caps_wanted_delay_min
,
115 Opt_caps_wanted_delay_max
,
116 Opt_cap_release_safety
,
117 Opt_readdir_max_entries
,
118 Opt_readdir_max_bytes
,
126 /* string args above */
141 Opt_require_active_mds
,
142 Opt_norequire_active_mds
,
143 #ifdef CONFIG_CEPH_FS_POSIX_ACL
149 static match_table_t fsopt_tokens
= {
150 {Opt_wsize
, "wsize=%d"},
151 {Opt_rsize
, "rsize=%d"},
152 {Opt_rasize
, "rasize=%d"},
153 {Opt_caps_wanted_delay_min
, "caps_wanted_delay_min=%d"},
154 {Opt_caps_wanted_delay_max
, "caps_wanted_delay_max=%d"},
155 {Opt_cap_release_safety
, "cap_release_safety=%d"},
156 {Opt_readdir_max_entries
, "readdir_max_entries=%d"},
157 {Opt_readdir_max_bytes
, "readdir_max_bytes=%d"},
158 {Opt_congestion_kb
, "write_congestion_kb=%d"},
160 {Opt_snapdirname
, "snapdirname=%s"},
161 {Opt_mds_namespace
, "mds_namespace=%s"},
162 {Opt_fscache_uniq
, "fsc=%s"},
163 /* string args above */
164 {Opt_dirstat
, "dirstat"},
165 {Opt_nodirstat
, "nodirstat"},
166 {Opt_rbytes
, "rbytes"},
167 {Opt_norbytes
, "norbytes"},
168 {Opt_asyncreaddir
, "asyncreaddir"},
169 {Opt_noasyncreaddir
, "noasyncreaddir"},
170 {Opt_dcache
, "dcache"},
171 {Opt_nodcache
, "nodcache"},
172 {Opt_ino32
, "ino32"},
173 {Opt_noino32
, "noino32"},
174 {Opt_fscache
, "fsc"},
175 {Opt_nofscache
, "nofsc"},
176 {Opt_poolperm
, "poolperm"},
177 {Opt_nopoolperm
, "nopoolperm"},
178 {Opt_require_active_mds
, "require_active_mds"},
179 {Opt_norequire_active_mds
, "norequire_active_mds"},
180 #ifdef CONFIG_CEPH_FS_POSIX_ACL
183 {Opt_noacl
, "noacl"},
187 static int parse_fsopt_token(char *c
, void *private)
189 struct ceph_mount_options
*fsopt
= private;
190 substring_t argstr
[MAX_OPT_ARGS
];
191 int token
, intval
, ret
;
193 token
= match_token((char *)c
, fsopt_tokens
, argstr
);
197 if (token
< Opt_last_int
) {
198 ret
= match_int(&argstr
[0], &intval
);
200 pr_err("bad mount option arg (not int) "
204 dout("got int token %d val %d\n", token
, intval
);
205 } else if (token
> Opt_last_int
&& token
< Opt_last_string
) {
206 dout("got string token %d val %s\n", token
,
209 dout("got token %d\n", token
);
213 case Opt_snapdirname
:
214 kfree(fsopt
->snapdir_name
);
215 fsopt
->snapdir_name
= kstrndup(argstr
[0].from
,
216 argstr
[0].to
-argstr
[0].from
,
218 if (!fsopt
->snapdir_name
)
221 case Opt_mds_namespace
:
222 fsopt
->mds_namespace
= kstrndup(argstr
[0].from
,
223 argstr
[0].to
-argstr
[0].from
,
225 if (!fsopt
->mds_namespace
)
228 case Opt_fscache_uniq
:
229 fsopt
->fscache_uniq
= kstrndup(argstr
[0].from
,
230 argstr
[0].to
-argstr
[0].from
,
232 if (!fsopt
->fscache_uniq
)
234 fsopt
->flags
|= CEPH_MOUNT_OPT_FSCACHE
;
238 fsopt
->wsize
= intval
;
241 fsopt
->rsize
= intval
;
244 fsopt
->rasize
= intval
;
246 case Opt_caps_wanted_delay_min
:
247 fsopt
->caps_wanted_delay_min
= intval
;
249 case Opt_caps_wanted_delay_max
:
250 fsopt
->caps_wanted_delay_max
= intval
;
252 case Opt_readdir_max_entries
:
253 fsopt
->max_readdir
= intval
;
255 case Opt_readdir_max_bytes
:
256 fsopt
->max_readdir_bytes
= intval
;
258 case Opt_congestion_kb
:
259 fsopt
->congestion_kb
= intval
;
262 fsopt
->flags
|= CEPH_MOUNT_OPT_DIRSTAT
;
265 fsopt
->flags
&= ~CEPH_MOUNT_OPT_DIRSTAT
;
268 fsopt
->flags
|= CEPH_MOUNT_OPT_RBYTES
;
271 fsopt
->flags
&= ~CEPH_MOUNT_OPT_RBYTES
;
273 case Opt_asyncreaddir
:
274 fsopt
->flags
&= ~CEPH_MOUNT_OPT_NOASYNCREADDIR
;
276 case Opt_noasyncreaddir
:
277 fsopt
->flags
|= CEPH_MOUNT_OPT_NOASYNCREADDIR
;
280 fsopt
->flags
|= CEPH_MOUNT_OPT_DCACHE
;
283 fsopt
->flags
&= ~CEPH_MOUNT_OPT_DCACHE
;
286 fsopt
->flags
|= CEPH_MOUNT_OPT_INO32
;
289 fsopt
->flags
&= ~CEPH_MOUNT_OPT_INO32
;
292 fsopt
->flags
|= CEPH_MOUNT_OPT_FSCACHE
;
295 fsopt
->flags
&= ~CEPH_MOUNT_OPT_FSCACHE
;
298 fsopt
->flags
&= ~CEPH_MOUNT_OPT_NOPOOLPERM
;
299 printk ("pool perm");
302 fsopt
->flags
|= CEPH_MOUNT_OPT_NOPOOLPERM
;
304 case Opt_require_active_mds
:
305 fsopt
->flags
&= ~CEPH_MOUNT_OPT_MOUNTWAIT
;
307 case Opt_norequire_active_mds
:
308 fsopt
->flags
|= CEPH_MOUNT_OPT_MOUNTWAIT
;
310 #ifdef CONFIG_CEPH_FS_POSIX_ACL
312 fsopt
->sb_flags
|= MS_POSIXACL
;
316 fsopt
->sb_flags
&= ~MS_POSIXACL
;
324 static void destroy_mount_options(struct ceph_mount_options
*args
)
326 dout("destroy_mount_options %p\n", args
);
327 kfree(args
->snapdir_name
);
328 kfree(args
->mds_namespace
);
329 kfree(args
->server_path
);
330 kfree(args
->fscache_uniq
);
334 static int strcmp_null(const char *s1
, const char *s2
)
342 return strcmp(s1
, s2
);
345 static int compare_mount_options(struct ceph_mount_options
*new_fsopt
,
346 struct ceph_options
*new_opt
,
347 struct ceph_fs_client
*fsc
)
349 struct ceph_mount_options
*fsopt1
= new_fsopt
;
350 struct ceph_mount_options
*fsopt2
= fsc
->mount_options
;
351 int ofs
= offsetof(struct ceph_mount_options
, snapdir_name
);
354 ret
= memcmp(fsopt1
, fsopt2
, ofs
);
358 ret
= strcmp_null(fsopt1
->snapdir_name
, fsopt2
->snapdir_name
);
361 ret
= strcmp_null(fsopt1
->mds_namespace
, fsopt2
->mds_namespace
);
364 ret
= strcmp_null(fsopt1
->server_path
, fsopt2
->server_path
);
367 ret
= strcmp_null(fsopt1
->fscache_uniq
, fsopt2
->fscache_uniq
);
371 return ceph_compare_options(new_opt
, fsc
->client
);
374 static int parse_mount_options(struct ceph_mount_options
**pfsopt
,
375 struct ceph_options
**popt
,
376 int flags
, char *options
,
377 const char *dev_name
)
379 struct ceph_mount_options
*fsopt
;
380 const char *dev_name_end
;
383 if (!dev_name
|| !*dev_name
)
386 fsopt
= kzalloc(sizeof(*fsopt
), GFP_KERNEL
);
390 dout("parse_mount_options %p, dev_name '%s'\n", fsopt
, dev_name
);
392 fsopt
->sb_flags
= flags
;
393 fsopt
->flags
= CEPH_MOUNT_OPT_DEFAULT
;
395 fsopt
->rsize
= CEPH_RSIZE_DEFAULT
;
396 fsopt
->rasize
= CEPH_RASIZE_DEFAULT
;
397 fsopt
->snapdir_name
= kstrdup(CEPH_SNAPDIRNAME_DEFAULT
, GFP_KERNEL
);
398 if (!fsopt
->snapdir_name
) {
403 fsopt
->caps_wanted_delay_min
= CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT
;
404 fsopt
->caps_wanted_delay_max
= CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT
;
405 fsopt
->cap_release_safety
= CEPH_CAP_RELEASE_SAFETY_DEFAULT
;
406 fsopt
->max_readdir
= CEPH_MAX_READDIR_DEFAULT
;
407 fsopt
->max_readdir_bytes
= CEPH_MAX_READDIR_BYTES_DEFAULT
;
408 fsopt
->congestion_kb
= default_congestion_kb();
411 * Distinguish the server list from the path in "dev_name".
412 * Internally we do not include the leading '/' in the path.
414 * "dev_name" will look like:
415 * <server_spec>[,<server_spec>...]:[<path>]
417 * <server_spec> is <ip>[:<port>]
418 * <path> is optional, but if present must begin with '/'
420 dev_name_end
= strchr(dev_name
, '/');
422 if (strlen(dev_name_end
) > 1) {
423 fsopt
->server_path
= kstrdup(dev_name_end
, GFP_KERNEL
);
424 if (!fsopt
->server_path
) {
430 dev_name_end
= dev_name
+ strlen(dev_name
);
433 dev_name_end
--; /* back up to ':' separator */
434 if (dev_name_end
< dev_name
|| *dev_name_end
!= ':') {
435 pr_err("device name is missing path (no : separator in %s)\n",
439 dout("device name '%.*s'\n", (int)(dev_name_end
- dev_name
), dev_name
);
440 if (fsopt
->server_path
)
441 dout("server path '%s'\n", fsopt
->server_path
);
443 *popt
= ceph_parse_options(options
, dev_name
, dev_name_end
,
444 parse_fsopt_token
, (void *)fsopt
);
446 err
= PTR_ERR(*popt
);
455 destroy_mount_options(fsopt
);
460 * ceph_show_options - Show mount options in /proc/mounts
461 * @m: seq_file to write to
462 * @root: root of that (sub)tree
464 static int ceph_show_options(struct seq_file
*m
, struct dentry
*root
)
466 struct ceph_fs_client
*fsc
= ceph_sb_to_client(root
->d_sb
);
467 struct ceph_mount_options
*fsopt
= fsc
->mount_options
;
471 /* a comma between MNT/MS and client options */
475 ret
= ceph_print_client_options(m
, fsc
->client
);
479 /* retract our comma if no client options */
483 if (fsopt
->flags
& CEPH_MOUNT_OPT_DIRSTAT
)
484 seq_puts(m
, ",dirstat");
485 if ((fsopt
->flags
& CEPH_MOUNT_OPT_RBYTES
))
486 seq_puts(m
, ",rbytes");
487 if (fsopt
->flags
& CEPH_MOUNT_OPT_NOASYNCREADDIR
)
488 seq_puts(m
, ",noasyncreaddir");
489 if ((fsopt
->flags
& CEPH_MOUNT_OPT_DCACHE
) == 0)
490 seq_puts(m
, ",nodcache");
491 if (fsopt
->flags
& CEPH_MOUNT_OPT_FSCACHE
) {
492 if (fsopt
->fscache_uniq
)
493 seq_printf(m
, ",fsc=%s", fsopt
->fscache_uniq
);
497 if (fsopt
->flags
& CEPH_MOUNT_OPT_NOPOOLPERM
)
498 seq_puts(m
, ",nopoolperm");
500 #ifdef CONFIG_CEPH_FS_POSIX_ACL
501 if (fsopt
->sb_flags
& MS_POSIXACL
)
504 seq_puts(m
, ",noacl");
507 if (fsopt
->mds_namespace
)
508 seq_printf(m
, ",mds_namespace=%s", fsopt
->mds_namespace
);
510 seq_printf(m
, ",wsize=%d", fsopt
->wsize
);
511 if (fsopt
->rsize
!= CEPH_RSIZE_DEFAULT
)
512 seq_printf(m
, ",rsize=%d", fsopt
->rsize
);
513 if (fsopt
->rasize
!= CEPH_RASIZE_DEFAULT
)
514 seq_printf(m
, ",rasize=%d", fsopt
->rasize
);
515 if (fsopt
->congestion_kb
!= default_congestion_kb())
516 seq_printf(m
, ",write_congestion_kb=%d", fsopt
->congestion_kb
);
517 if (fsopt
->caps_wanted_delay_min
!= CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT
)
518 seq_printf(m
, ",caps_wanted_delay_min=%d",
519 fsopt
->caps_wanted_delay_min
);
520 if (fsopt
->caps_wanted_delay_max
!= CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT
)
521 seq_printf(m
, ",caps_wanted_delay_max=%d",
522 fsopt
->caps_wanted_delay_max
);
523 if (fsopt
->cap_release_safety
!= CEPH_CAP_RELEASE_SAFETY_DEFAULT
)
524 seq_printf(m
, ",cap_release_safety=%d",
525 fsopt
->cap_release_safety
);
526 if (fsopt
->max_readdir
!= CEPH_MAX_READDIR_DEFAULT
)
527 seq_printf(m
, ",readdir_max_entries=%d", fsopt
->max_readdir
);
528 if (fsopt
->max_readdir_bytes
!= CEPH_MAX_READDIR_BYTES_DEFAULT
)
529 seq_printf(m
, ",readdir_max_bytes=%d", fsopt
->max_readdir_bytes
);
530 if (strcmp(fsopt
->snapdir_name
, CEPH_SNAPDIRNAME_DEFAULT
))
531 seq_show_option(m
, "snapdirname", fsopt
->snapdir_name
);
537 * handle any mon messages the standard library doesn't understand.
538 * return error if we don't either.
540 static int extra_mon_dispatch(struct ceph_client
*client
, struct ceph_msg
*msg
)
542 struct ceph_fs_client
*fsc
= client
->private;
543 int type
= le16_to_cpu(msg
->hdr
.type
);
546 case CEPH_MSG_MDS_MAP
:
547 ceph_mdsc_handle_mdsmap(fsc
->mdsc
, msg
);
549 case CEPH_MSG_FS_MAP_USER
:
550 ceph_mdsc_handle_fsmap(fsc
->mdsc
, msg
);
558 * create a new fs client
560 static struct ceph_fs_client
*create_fs_client(struct ceph_mount_options
*fsopt
,
561 struct ceph_options
*opt
)
563 struct ceph_fs_client
*fsc
;
568 fsc
= kzalloc(sizeof(*fsc
), GFP_KERNEL
);
570 return ERR_PTR(-ENOMEM
);
572 fsc
->client
= ceph_create_client(opt
, fsc
);
573 if (IS_ERR(fsc
->client
)) {
574 err
= PTR_ERR(fsc
->client
);
577 fsc
->client
->extra_mon_dispatch
= extra_mon_dispatch
;
579 if (fsopt
->mds_namespace
== NULL
) {
580 ceph_monc_want_map(&fsc
->client
->monc
, CEPH_SUB_MDSMAP
,
583 ceph_monc_want_map(&fsc
->client
->monc
, CEPH_SUB_FSMAP
,
587 fsc
->mount_options
= fsopt
;
590 fsc
->mount_state
= CEPH_MOUNT_MOUNTING
;
592 atomic_long_set(&fsc
->writeback_count
, 0);
596 * The number of concurrent works can be high but they don't need
597 * to be processed in parallel, limit concurrency.
599 fsc
->wb_wq
= alloc_workqueue("ceph-writeback", 0, 1);
600 if (fsc
->wb_wq
== NULL
)
602 fsc
->pg_inv_wq
= alloc_workqueue("ceph-pg-invalid", 0, 1);
603 if (fsc
->pg_inv_wq
== NULL
)
605 fsc
->trunc_wq
= alloc_workqueue("ceph-trunc", 0, 1);
606 if (fsc
->trunc_wq
== NULL
)
609 /* set up mempools */
611 page_count
= fsc
->mount_options
->wsize
>> PAGE_SHIFT
;
612 size
= sizeof (struct page
*) * (page_count
? page_count
: 1);
613 fsc
->wb_pagevec_pool
= mempool_create_kmalloc_pool(10, size
);
614 if (!fsc
->wb_pagevec_pool
)
618 fsc
->min_caps
= fsopt
->max_readdir
;
623 destroy_workqueue(fsc
->trunc_wq
);
625 destroy_workqueue(fsc
->pg_inv_wq
);
627 destroy_workqueue(fsc
->wb_wq
);
629 ceph_destroy_client(fsc
->client
);
635 static void destroy_fs_client(struct ceph_fs_client
*fsc
)
637 dout("destroy_fs_client %p\n", fsc
);
639 destroy_workqueue(fsc
->wb_wq
);
640 destroy_workqueue(fsc
->pg_inv_wq
);
641 destroy_workqueue(fsc
->trunc_wq
);
643 mempool_destroy(fsc
->wb_pagevec_pool
);
645 destroy_mount_options(fsc
->mount_options
);
647 ceph_destroy_client(fsc
->client
);
650 dout("destroy_fs_client %p done\n", fsc
);
656 struct kmem_cache
*ceph_inode_cachep
;
657 struct kmem_cache
*ceph_cap_cachep
;
658 struct kmem_cache
*ceph_cap_flush_cachep
;
659 struct kmem_cache
*ceph_dentry_cachep
;
660 struct kmem_cache
*ceph_file_cachep
;
662 static void ceph_inode_init_once(void *foo
)
664 struct ceph_inode_info
*ci
= foo
;
665 inode_init_once(&ci
->vfs_inode
);
668 static int __init
init_caches(void)
672 ceph_inode_cachep
= kmem_cache_create("ceph_inode_info",
673 sizeof(struct ceph_inode_info
),
674 __alignof__(struct ceph_inode_info
),
675 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
|
676 SLAB_ACCOUNT
, ceph_inode_init_once
);
677 if (ceph_inode_cachep
== NULL
)
680 ceph_cap_cachep
= KMEM_CACHE(ceph_cap
,
681 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
);
682 if (ceph_cap_cachep
== NULL
)
684 ceph_cap_flush_cachep
= KMEM_CACHE(ceph_cap_flush
,
685 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
);
686 if (ceph_cap_flush_cachep
== NULL
)
689 ceph_dentry_cachep
= KMEM_CACHE(ceph_dentry_info
,
690 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
);
691 if (ceph_dentry_cachep
== NULL
)
694 ceph_file_cachep
= KMEM_CACHE(ceph_file_info
, SLAB_MEM_SPREAD
);
696 if (ceph_file_cachep
== NULL
)
699 if ((error
= ceph_fscache_register()))
704 kmem_cache_destroy(ceph_dentry_cachep
);
706 kmem_cache_destroy(ceph_cap_flush_cachep
);
708 kmem_cache_destroy(ceph_cap_cachep
);
710 kmem_cache_destroy(ceph_inode_cachep
);
714 static void destroy_caches(void)
717 * Make sure all delayed rcu free inodes are flushed before we
722 kmem_cache_destroy(ceph_inode_cachep
);
723 kmem_cache_destroy(ceph_cap_cachep
);
724 kmem_cache_destroy(ceph_cap_flush_cachep
);
725 kmem_cache_destroy(ceph_dentry_cachep
);
726 kmem_cache_destroy(ceph_file_cachep
);
728 ceph_fscache_unregister();
733 * ceph_umount_begin - initiate forced umount. Tear down down the
734 * mount, skipping steps that may hang while waiting for server(s).
736 static void ceph_umount_begin(struct super_block
*sb
)
738 struct ceph_fs_client
*fsc
= ceph_sb_to_client(sb
);
740 dout("ceph_umount_begin - starting forced umount\n");
743 fsc
->mount_state
= CEPH_MOUNT_SHUTDOWN
;
744 ceph_mdsc_force_umount(fsc
->mdsc
);
748 static const struct super_operations ceph_super_ops
= {
749 .alloc_inode
= ceph_alloc_inode
,
750 .destroy_inode
= ceph_destroy_inode
,
751 .write_inode
= ceph_write_inode
,
752 .drop_inode
= ceph_drop_inode
,
753 .sync_fs
= ceph_sync_fs
,
754 .put_super
= ceph_put_super
,
755 .show_options
= ceph_show_options
,
756 .statfs
= ceph_statfs
,
757 .umount_begin
= ceph_umount_begin
,
761 * Bootstrap mount by opening the root directory. Note the mount
762 * @started time from caller, and time out if this takes too long.
764 static struct dentry
*open_root_dentry(struct ceph_fs_client
*fsc
,
766 unsigned long started
)
768 struct ceph_mds_client
*mdsc
= fsc
->mdsc
;
769 struct ceph_mds_request
*req
= NULL
;
774 dout("open_root_inode opening '%s'\n", path
);
775 req
= ceph_mdsc_create_request(mdsc
, CEPH_MDS_OP_GETATTR
, USE_ANY_MDS
);
777 return ERR_CAST(req
);
778 req
->r_path1
= kstrdup(path
, GFP_NOFS
);
780 root
= ERR_PTR(-ENOMEM
);
784 req
->r_ino1
.ino
= CEPH_INO_ROOT
;
785 req
->r_ino1
.snap
= CEPH_NOSNAP
;
786 req
->r_started
= started
;
787 req
->r_timeout
= fsc
->client
->options
->mount_timeout
;
788 req
->r_args
.getattr
.mask
= cpu_to_le32(CEPH_STAT_CAP_INODE
);
790 err
= ceph_mdsc_do_request(mdsc
, NULL
, req
);
792 struct inode
*inode
= req
->r_target_inode
;
793 req
->r_target_inode
= NULL
;
794 dout("open_root_inode success\n");
795 root
= d_make_root(inode
);
797 root
= ERR_PTR(-ENOMEM
);
800 dout("open_root_inode success, root dentry is %p\n", root
);
805 ceph_mdsc_put_request(req
);
813 * mount: join the ceph cluster, and open root directory.
815 static struct dentry
*ceph_real_mount(struct ceph_fs_client
*fsc
)
818 unsigned long started
= jiffies
; /* note the start time */
820 int first
= 0; /* first vfsmount for this super_block */
822 dout("mount start %p\n", fsc
);
823 mutex_lock(&fsc
->client
->mount_mutex
);
825 if (!fsc
->sb
->s_root
) {
827 err
= __ceph_open_session(fsc
->client
, started
);
832 if (fsc
->mount_options
->flags
& CEPH_MOUNT_OPT_FSCACHE
) {
833 err
= ceph_fscache_register_fs(fsc
);
838 if (!fsc
->mount_options
->server_path
) {
840 dout("mount opening path \\t\n");
842 path
= fsc
->mount_options
->server_path
+ 1;
843 dout("mount opening path %s\n", path
);
845 root
= open_root_dentry(fsc
, path
, started
);
850 fsc
->sb
->s_root
= dget(root
);
853 err
= ceph_fs_debugfs_init(fsc
);
857 root
= dget(fsc
->sb
->s_root
);
860 fsc
->mount_state
= CEPH_MOUNT_MOUNTED
;
861 dout("mount success\n");
862 mutex_unlock(&fsc
->client
->mount_mutex
);
867 dput(fsc
->sb
->s_root
);
868 fsc
->sb
->s_root
= NULL
;
871 mutex_unlock(&fsc
->client
->mount_mutex
);
875 static int ceph_set_super(struct super_block
*s
, void *data
)
877 struct ceph_fs_client
*fsc
= data
;
880 dout("set_super %p data %p\n", s
, data
);
882 s
->s_flags
= fsc
->mount_options
->sb_flags
;
883 s
->s_maxbytes
= 1ULL << 40; /* temp value until we get mdsmap */
885 s
->s_xattr
= ceph_xattr_handlers
;
889 s
->s_op
= &ceph_super_ops
;
890 s
->s_d_op
= &ceph_dentry_ops
;
891 s
->s_export_op
= &ceph_export_ops
;
893 s
->s_time_gran
= 1000; /* 1000 ns == 1 us */
895 ret
= set_anon_super(s
, NULL
); /* what is that second arg for? */
908 * share superblock if same fs AND options
910 static int ceph_compare_super(struct super_block
*sb
, void *data
)
912 struct ceph_fs_client
*new = data
;
913 struct ceph_mount_options
*fsopt
= new->mount_options
;
914 struct ceph_options
*opt
= new->client
->options
;
915 struct ceph_fs_client
*other
= ceph_sb_to_client(sb
);
917 dout("ceph_compare_super %p\n", sb
);
919 if (compare_mount_options(fsopt
, opt
, other
)) {
920 dout("monitor(s)/mount options don't match\n");
923 if ((opt
->flags
& CEPH_OPT_FSID
) &&
924 ceph_fsid_compare(&opt
->fsid
, &other
->client
->fsid
)) {
925 dout("fsid doesn't match\n");
928 if (fsopt
->sb_flags
!= other
->mount_options
->sb_flags
) {
929 dout("flags differ\n");
936 * construct our own bdi so we can control readahead, etc.
938 static atomic_long_t bdi_seq
= ATOMIC_LONG_INIT(0);
940 static int ceph_setup_bdi(struct super_block
*sb
, struct ceph_fs_client
*fsc
)
944 err
= super_setup_bdi_name(sb
, "ceph-%ld",
945 atomic_long_inc_return(&bdi_seq
));
949 /* set ra_pages based on rasize mount option? */
950 if (fsc
->mount_options
->rasize
>= PAGE_SIZE
)
951 sb
->s_bdi
->ra_pages
=
952 (fsc
->mount_options
->rasize
+ PAGE_SIZE
- 1)
955 sb
->s_bdi
->ra_pages
= VM_MAX_READAHEAD
* 1024 / PAGE_SIZE
;
957 if (fsc
->mount_options
->rsize
> fsc
->mount_options
->rasize
&&
958 fsc
->mount_options
->rsize
>= PAGE_SIZE
)
959 sb
->s_bdi
->io_pages
=
960 (fsc
->mount_options
->rsize
+ PAGE_SIZE
- 1)
962 else if (fsc
->mount_options
->rsize
== 0)
963 sb
->s_bdi
->io_pages
= ULONG_MAX
;
968 static struct dentry
*ceph_mount(struct file_system_type
*fs_type
,
969 int flags
, const char *dev_name
, void *data
)
971 struct super_block
*sb
;
972 struct ceph_fs_client
*fsc
;
975 int (*compare_super
)(struct super_block
*, void *) = ceph_compare_super
;
976 struct ceph_mount_options
*fsopt
= NULL
;
977 struct ceph_options
*opt
= NULL
;
979 dout("ceph_mount\n");
981 #ifdef CONFIG_CEPH_FS_POSIX_ACL
982 flags
|= MS_POSIXACL
;
984 err
= parse_mount_options(&fsopt
, &opt
, flags
, data
, dev_name
);
990 /* create client (which we may/may not use) */
991 fsc
= create_fs_client(fsopt
, opt
);
994 destroy_mount_options(fsopt
);
995 ceph_destroy_options(opt
);
999 err
= ceph_mdsc_init(fsc
);
1005 if (ceph_test_opt(fsc
->client
, NOSHARE
))
1006 compare_super
= NULL
;
1007 sb
= sget(fs_type
, compare_super
, ceph_set_super
, flags
, fsc
);
1013 if (ceph_sb_to_client(sb
) != fsc
) {
1014 ceph_mdsc_destroy(fsc
);
1015 destroy_fs_client(fsc
);
1016 fsc
= ceph_sb_to_client(sb
);
1017 dout("get_sb got existing client %p\n", fsc
);
1019 dout("get_sb using new client %p\n", fsc
);
1020 err
= ceph_setup_bdi(sb
, fsc
);
1027 res
= ceph_real_mount(fsc
);
1030 dout("root %p inode %p ino %llx.%llx\n", res
,
1031 d_inode(res
), ceph_vinop(d_inode(res
)));
1035 ceph_mdsc_close_sessions(fsc
->mdsc
);
1036 deactivate_locked_super(sb
);
1040 ceph_mdsc_destroy(fsc
);
1041 destroy_fs_client(fsc
);
1043 dout("ceph_mount fail %ld\n", PTR_ERR(res
));
1047 static void ceph_kill_sb(struct super_block
*s
)
1049 struct ceph_fs_client
*fsc
= ceph_sb_to_client(s
);
1050 dev_t dev
= s
->s_dev
;
1052 dout("kill_sb %p\n", s
);
1054 ceph_mdsc_pre_umount(fsc
->mdsc
);
1055 generic_shutdown_super(s
);
1057 fsc
->client
->extra_mon_dispatch
= NULL
;
1058 ceph_fs_debugfs_cleanup(fsc
);
1060 ceph_fscache_unregister_fs(fsc
);
1062 ceph_mdsc_destroy(fsc
);
1064 destroy_fs_client(fsc
);
1065 free_anon_bdev(dev
);
1068 static struct file_system_type ceph_fs_type
= {
1069 .owner
= THIS_MODULE
,
1071 .mount
= ceph_mount
,
1072 .kill_sb
= ceph_kill_sb
,
1073 .fs_flags
= FS_RENAME_DOES_D_MOVE
,
1075 MODULE_ALIAS_FS("ceph");
1077 static int __init
init_ceph(void)
1079 int ret
= init_caches();
1085 ret
= register_filesystem(&ceph_fs_type
);
1089 pr_info("loaded (mds proto %d)\n", CEPH_MDSC_PROTOCOL
);
1100 static void __exit
exit_ceph(void)
1102 dout("exit_ceph\n");
1103 unregister_filesystem(&ceph_fs_type
);
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");