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_mon_client
*monc
= &fsc
->client
->monc
;
49 struct ceph_statfs st
;
54 if (fsc
->mdsc
->mdsmap
->m_num_data_pg_pools
== 1) {
55 data_pool
= fsc
->mdsc
->mdsmap
->m_data_pg_pools
[0];
57 data_pool
= CEPH_NOPOOL
;
61 err
= ceph_monc_do_statfs(monc
, data_pool
, &st
);
66 buf
->f_type
= CEPH_SUPER_MAGIC
; /* ?? */
69 * express utilization in terms of large blocks to avoid
70 * overflow on 32-bit machines.
72 * NOTE: for the time being, we make bsize == frsize to humor
73 * not-yet-ancient versions of glibc that are broken.
74 * Someday, we will probably want to report a real block
75 * size... whatever that may mean for a network file system!
77 buf
->f_bsize
= 1 << CEPH_BLOCK_SHIFT
;
78 buf
->f_frsize
= 1 << CEPH_BLOCK_SHIFT
;
79 buf
->f_blocks
= le64_to_cpu(st
.kb
) >> (CEPH_BLOCK_SHIFT
-10);
80 buf
->f_bfree
= le64_to_cpu(st
.kb_avail
) >> (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
= NAME_MAX
;
87 /* Must convert the fsid, for consistent values across arches */
88 mutex_lock(&monc
->mutex
);
89 fsid
= le64_to_cpu(*(__le64
*)(&monc
->monmap
->fsid
)) ^
90 le64_to_cpu(*((__le64
*)&monc
->monmap
->fsid
+ 1));
91 mutex_unlock(&monc
->mutex
);
93 buf
->f_fsid
.val
[0] = fsid
& 0xffffffff;
94 buf
->f_fsid
.val
[1] = fsid
>> 32;
100 static int ceph_sync_fs(struct super_block
*sb
, int wait
)
102 struct ceph_fs_client
*fsc
= ceph_sb_to_client(sb
);
105 dout("sync_fs (non-blocking)\n");
106 ceph_flush_dirty_caps(fsc
->mdsc
);
107 dout("sync_fs (non-blocking) done\n");
111 dout("sync_fs (blocking)\n");
112 ceph_osdc_sync(&fsc
->client
->osdc
);
113 ceph_mdsc_sync(fsc
->mdsc
);
114 dout("sync_fs (blocking) done\n");
125 Opt_caps_wanted_delay_min
,
126 Opt_caps_wanted_delay_max
,
127 Opt_readdir_max_entries
,
128 Opt_readdir_max_bytes
,
136 /* string args above */
151 Opt_require_active_mds
,
152 Opt_norequire_active_mds
,
153 #ifdef CONFIG_CEPH_FS_POSIX_ACL
159 static match_table_t fsopt_tokens
= {
160 {Opt_wsize
, "wsize=%d"},
161 {Opt_rsize
, "rsize=%d"},
162 {Opt_rasize
, "rasize=%d"},
163 {Opt_caps_wanted_delay_min
, "caps_wanted_delay_min=%d"},
164 {Opt_caps_wanted_delay_max
, "caps_wanted_delay_max=%d"},
165 {Opt_readdir_max_entries
, "readdir_max_entries=%d"},
166 {Opt_readdir_max_bytes
, "readdir_max_bytes=%d"},
167 {Opt_congestion_kb
, "write_congestion_kb=%d"},
169 {Opt_snapdirname
, "snapdirname=%s"},
170 {Opt_mds_namespace
, "mds_namespace=%s"},
171 {Opt_fscache_uniq
, "fsc=%s"},
172 /* string args above */
173 {Opt_dirstat
, "dirstat"},
174 {Opt_nodirstat
, "nodirstat"},
175 {Opt_rbytes
, "rbytes"},
176 {Opt_norbytes
, "norbytes"},
177 {Opt_asyncreaddir
, "asyncreaddir"},
178 {Opt_noasyncreaddir
, "noasyncreaddir"},
179 {Opt_dcache
, "dcache"},
180 {Opt_nodcache
, "nodcache"},
181 {Opt_ino32
, "ino32"},
182 {Opt_noino32
, "noino32"},
183 {Opt_fscache
, "fsc"},
184 {Opt_nofscache
, "nofsc"},
185 {Opt_poolperm
, "poolperm"},
186 {Opt_nopoolperm
, "nopoolperm"},
187 {Opt_require_active_mds
, "require_active_mds"},
188 {Opt_norequire_active_mds
, "norequire_active_mds"},
189 #ifdef CONFIG_CEPH_FS_POSIX_ACL
192 {Opt_noacl
, "noacl"},
196 static int parse_fsopt_token(char *c
, void *private)
198 struct ceph_mount_options
*fsopt
= private;
199 substring_t argstr
[MAX_OPT_ARGS
];
200 int token
, intval
, ret
;
202 token
= match_token((char *)c
, fsopt_tokens
, argstr
);
206 if (token
< Opt_last_int
) {
207 ret
= match_int(&argstr
[0], &intval
);
209 pr_err("bad mount option arg (not int) "
213 dout("got int token %d val %d\n", token
, intval
);
214 } else if (token
> Opt_last_int
&& token
< Opt_last_string
) {
215 dout("got string token %d val %s\n", token
,
218 dout("got token %d\n", token
);
222 case Opt_snapdirname
:
223 kfree(fsopt
->snapdir_name
);
224 fsopt
->snapdir_name
= kstrndup(argstr
[0].from
,
225 argstr
[0].to
-argstr
[0].from
,
227 if (!fsopt
->snapdir_name
)
230 case Opt_mds_namespace
:
231 kfree(fsopt
->mds_namespace
);
232 fsopt
->mds_namespace
= kstrndup(argstr
[0].from
,
233 argstr
[0].to
-argstr
[0].from
,
235 if (!fsopt
->mds_namespace
)
238 case Opt_fscache_uniq
:
239 kfree(fsopt
->fscache_uniq
);
240 fsopt
->fscache_uniq
= kstrndup(argstr
[0].from
,
241 argstr
[0].to
-argstr
[0].from
,
243 if (!fsopt
->fscache_uniq
)
245 fsopt
->flags
|= CEPH_MOUNT_OPT_FSCACHE
;
249 if (intval
< PAGE_SIZE
|| intval
> CEPH_MAX_WRITE_SIZE
)
251 fsopt
->wsize
= ALIGN(intval
, PAGE_SIZE
);
254 if (intval
< PAGE_SIZE
|| intval
> CEPH_MAX_READ_SIZE
)
256 fsopt
->rsize
= ALIGN(intval
, PAGE_SIZE
);
261 fsopt
->rasize
= ALIGN(intval
, PAGE_SIZE
);
263 case Opt_caps_wanted_delay_min
:
266 fsopt
->caps_wanted_delay_min
= intval
;
268 case Opt_caps_wanted_delay_max
:
271 fsopt
->caps_wanted_delay_max
= intval
;
273 case Opt_readdir_max_entries
:
276 fsopt
->max_readdir
= intval
;
278 case Opt_readdir_max_bytes
:
279 if (intval
< PAGE_SIZE
&& intval
!= 0)
281 fsopt
->max_readdir_bytes
= intval
;
283 case Opt_congestion_kb
:
284 if (intval
< 1024) /* at least 1M */
286 fsopt
->congestion_kb
= intval
;
289 fsopt
->flags
|= CEPH_MOUNT_OPT_DIRSTAT
;
292 fsopt
->flags
&= ~CEPH_MOUNT_OPT_DIRSTAT
;
295 fsopt
->flags
|= CEPH_MOUNT_OPT_RBYTES
;
298 fsopt
->flags
&= ~CEPH_MOUNT_OPT_RBYTES
;
300 case Opt_asyncreaddir
:
301 fsopt
->flags
&= ~CEPH_MOUNT_OPT_NOASYNCREADDIR
;
303 case Opt_noasyncreaddir
:
304 fsopt
->flags
|= CEPH_MOUNT_OPT_NOASYNCREADDIR
;
307 fsopt
->flags
|= CEPH_MOUNT_OPT_DCACHE
;
310 fsopt
->flags
&= ~CEPH_MOUNT_OPT_DCACHE
;
313 fsopt
->flags
|= CEPH_MOUNT_OPT_INO32
;
316 fsopt
->flags
&= ~CEPH_MOUNT_OPT_INO32
;
319 fsopt
->flags
|= CEPH_MOUNT_OPT_FSCACHE
;
322 fsopt
->flags
&= ~CEPH_MOUNT_OPT_FSCACHE
;
325 fsopt
->flags
&= ~CEPH_MOUNT_OPT_NOPOOLPERM
;
326 printk ("pool perm");
329 fsopt
->flags
|= CEPH_MOUNT_OPT_NOPOOLPERM
;
331 case Opt_require_active_mds
:
332 fsopt
->flags
&= ~CEPH_MOUNT_OPT_MOUNTWAIT
;
334 case Opt_norequire_active_mds
:
335 fsopt
->flags
|= CEPH_MOUNT_OPT_MOUNTWAIT
;
337 #ifdef CONFIG_CEPH_FS_POSIX_ACL
339 fsopt
->sb_flags
|= SB_POSIXACL
;
343 fsopt
->sb_flags
&= ~SB_POSIXACL
;
351 static void destroy_mount_options(struct ceph_mount_options
*args
)
353 dout("destroy_mount_options %p\n", args
);
354 kfree(args
->snapdir_name
);
355 kfree(args
->mds_namespace
);
356 kfree(args
->server_path
);
357 kfree(args
->fscache_uniq
);
361 static int strcmp_null(const char *s1
, const char *s2
)
369 return strcmp(s1
, s2
);
372 static int compare_mount_options(struct ceph_mount_options
*new_fsopt
,
373 struct ceph_options
*new_opt
,
374 struct ceph_fs_client
*fsc
)
376 struct ceph_mount_options
*fsopt1
= new_fsopt
;
377 struct ceph_mount_options
*fsopt2
= fsc
->mount_options
;
378 int ofs
= offsetof(struct ceph_mount_options
, snapdir_name
);
381 ret
= memcmp(fsopt1
, fsopt2
, ofs
);
385 ret
= strcmp_null(fsopt1
->snapdir_name
, fsopt2
->snapdir_name
);
388 ret
= strcmp_null(fsopt1
->mds_namespace
, fsopt2
->mds_namespace
);
391 ret
= strcmp_null(fsopt1
->server_path
, fsopt2
->server_path
);
394 ret
= strcmp_null(fsopt1
->fscache_uniq
, fsopt2
->fscache_uniq
);
398 return ceph_compare_options(new_opt
, fsc
->client
);
401 static int parse_mount_options(struct ceph_mount_options
**pfsopt
,
402 struct ceph_options
**popt
,
403 int flags
, char *options
,
404 const char *dev_name
)
406 struct ceph_mount_options
*fsopt
;
407 const char *dev_name_end
;
410 if (!dev_name
|| !*dev_name
)
413 fsopt
= kzalloc(sizeof(*fsopt
), GFP_KERNEL
);
417 dout("parse_mount_options %p, dev_name '%s'\n", fsopt
, dev_name
);
419 fsopt
->sb_flags
= flags
;
420 fsopt
->flags
= CEPH_MOUNT_OPT_DEFAULT
;
422 fsopt
->wsize
= CEPH_MAX_WRITE_SIZE
;
423 fsopt
->rsize
= CEPH_MAX_READ_SIZE
;
424 fsopt
->rasize
= CEPH_RASIZE_DEFAULT
;
425 fsopt
->snapdir_name
= kstrdup(CEPH_SNAPDIRNAME_DEFAULT
, GFP_KERNEL
);
426 if (!fsopt
->snapdir_name
) {
431 fsopt
->caps_wanted_delay_min
= CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT
;
432 fsopt
->caps_wanted_delay_max
= CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT
;
433 fsopt
->max_readdir
= CEPH_MAX_READDIR_DEFAULT
;
434 fsopt
->max_readdir_bytes
= CEPH_MAX_READDIR_BYTES_DEFAULT
;
435 fsopt
->congestion_kb
= default_congestion_kb();
438 * Distinguish the server list from the path in "dev_name".
439 * Internally we do not include the leading '/' in the path.
441 * "dev_name" will look like:
442 * <server_spec>[,<server_spec>...]:[<path>]
444 * <server_spec> is <ip>[:<port>]
445 * <path> is optional, but if present must begin with '/'
447 dev_name_end
= strchr(dev_name
, '/');
449 if (strlen(dev_name_end
) > 1) {
450 fsopt
->server_path
= kstrdup(dev_name_end
, GFP_KERNEL
);
451 if (!fsopt
->server_path
) {
457 dev_name_end
= dev_name
+ strlen(dev_name
);
460 dev_name_end
--; /* back up to ':' separator */
461 if (dev_name_end
< dev_name
|| *dev_name_end
!= ':') {
462 pr_err("device name is missing path (no : separator in %s)\n",
466 dout("device name '%.*s'\n", (int)(dev_name_end
- dev_name
), dev_name
);
467 if (fsopt
->server_path
)
468 dout("server path '%s'\n", fsopt
->server_path
);
470 *popt
= ceph_parse_options(options
, dev_name
, dev_name_end
,
471 parse_fsopt_token
, (void *)fsopt
);
473 err
= PTR_ERR(*popt
);
482 destroy_mount_options(fsopt
);
487 * ceph_show_options - Show mount options in /proc/mounts
488 * @m: seq_file to write to
489 * @root: root of that (sub)tree
491 static int ceph_show_options(struct seq_file
*m
, struct dentry
*root
)
493 struct ceph_fs_client
*fsc
= ceph_sb_to_client(root
->d_sb
);
494 struct ceph_mount_options
*fsopt
= fsc
->mount_options
;
498 /* a comma between MNT/MS and client options */
502 ret
= ceph_print_client_options(m
, fsc
->client
);
506 /* retract our comma if no client options */
510 if (fsopt
->flags
& CEPH_MOUNT_OPT_DIRSTAT
)
511 seq_puts(m
, ",dirstat");
512 if ((fsopt
->flags
& CEPH_MOUNT_OPT_RBYTES
))
513 seq_puts(m
, ",rbytes");
514 if (fsopt
->flags
& CEPH_MOUNT_OPT_NOASYNCREADDIR
)
515 seq_puts(m
, ",noasyncreaddir");
516 if ((fsopt
->flags
& CEPH_MOUNT_OPT_DCACHE
) == 0)
517 seq_puts(m
, ",nodcache");
518 if (fsopt
->flags
& CEPH_MOUNT_OPT_FSCACHE
) {
519 if (fsopt
->fscache_uniq
)
520 seq_printf(m
, ",fsc=%s", fsopt
->fscache_uniq
);
524 if (fsopt
->flags
& CEPH_MOUNT_OPT_NOPOOLPERM
)
525 seq_puts(m
, ",nopoolperm");
527 #ifdef CONFIG_CEPH_FS_POSIX_ACL
528 if (fsopt
->sb_flags
& SB_POSIXACL
)
531 seq_puts(m
, ",noacl");
534 if (fsopt
->mds_namespace
)
535 seq_printf(m
, ",mds_namespace=%s", fsopt
->mds_namespace
);
537 seq_printf(m
, ",wsize=%d", fsopt
->wsize
);
538 if (fsopt
->rsize
!= CEPH_MAX_READ_SIZE
)
539 seq_printf(m
, ",rsize=%d", fsopt
->rsize
);
540 if (fsopt
->rasize
!= CEPH_RASIZE_DEFAULT
)
541 seq_printf(m
, ",rasize=%d", fsopt
->rasize
);
542 if (fsopt
->congestion_kb
!= default_congestion_kb())
543 seq_printf(m
, ",write_congestion_kb=%d", fsopt
->congestion_kb
);
544 if (fsopt
->caps_wanted_delay_min
!= CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT
)
545 seq_printf(m
, ",caps_wanted_delay_min=%d",
546 fsopt
->caps_wanted_delay_min
);
547 if (fsopt
->caps_wanted_delay_max
!= CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT
)
548 seq_printf(m
, ",caps_wanted_delay_max=%d",
549 fsopt
->caps_wanted_delay_max
);
550 if (fsopt
->max_readdir
!= CEPH_MAX_READDIR_DEFAULT
)
551 seq_printf(m
, ",readdir_max_entries=%d", fsopt
->max_readdir
);
552 if (fsopt
->max_readdir_bytes
!= CEPH_MAX_READDIR_BYTES_DEFAULT
)
553 seq_printf(m
, ",readdir_max_bytes=%d", fsopt
->max_readdir_bytes
);
554 if (strcmp(fsopt
->snapdir_name
, CEPH_SNAPDIRNAME_DEFAULT
))
555 seq_show_option(m
, "snapdirname", fsopt
->snapdir_name
);
561 * handle any mon messages the standard library doesn't understand.
562 * return error if we don't either.
564 static int extra_mon_dispatch(struct ceph_client
*client
, struct ceph_msg
*msg
)
566 struct ceph_fs_client
*fsc
= client
->private;
567 int type
= le16_to_cpu(msg
->hdr
.type
);
570 case CEPH_MSG_MDS_MAP
:
571 ceph_mdsc_handle_mdsmap(fsc
->mdsc
, msg
);
573 case CEPH_MSG_FS_MAP_USER
:
574 ceph_mdsc_handle_fsmap(fsc
->mdsc
, msg
);
582 * create a new fs client
584 static struct ceph_fs_client
*create_fs_client(struct ceph_mount_options
*fsopt
,
585 struct ceph_options
*opt
)
587 struct ceph_fs_client
*fsc
;
592 fsc
= kzalloc(sizeof(*fsc
), GFP_KERNEL
);
594 return ERR_PTR(-ENOMEM
);
596 fsc
->client
= ceph_create_client(opt
, fsc
);
597 if (IS_ERR(fsc
->client
)) {
598 err
= PTR_ERR(fsc
->client
);
601 fsc
->client
->extra_mon_dispatch
= extra_mon_dispatch
;
603 if (!fsopt
->mds_namespace
) {
604 ceph_monc_want_map(&fsc
->client
->monc
, CEPH_SUB_MDSMAP
,
607 ceph_monc_want_map(&fsc
->client
->monc
, CEPH_SUB_FSMAP
,
611 fsc
->mount_options
= fsopt
;
614 fsc
->mount_state
= CEPH_MOUNT_MOUNTING
;
616 atomic_long_set(&fsc
->writeback_count
, 0);
620 * The number of concurrent works can be high but they don't need
621 * to be processed in parallel, limit concurrency.
623 fsc
->wb_wq
= alloc_workqueue("ceph-writeback", 0, 1);
626 fsc
->pg_inv_wq
= alloc_workqueue("ceph-pg-invalid", 0, 1);
629 fsc
->trunc_wq
= alloc_workqueue("ceph-trunc", 0, 1);
633 /* set up mempools */
635 page_count
= fsc
->mount_options
->wsize
>> PAGE_SHIFT
;
636 size
= sizeof (struct page
*) * (page_count
? page_count
: 1);
637 fsc
->wb_pagevec_pool
= mempool_create_kmalloc_pool(10, size
);
638 if (!fsc
->wb_pagevec_pool
)
642 fsc
->min_caps
= fsopt
->max_readdir
;
647 destroy_workqueue(fsc
->trunc_wq
);
649 destroy_workqueue(fsc
->pg_inv_wq
);
651 destroy_workqueue(fsc
->wb_wq
);
653 ceph_destroy_client(fsc
->client
);
659 static void destroy_fs_client(struct ceph_fs_client
*fsc
)
661 dout("destroy_fs_client %p\n", fsc
);
663 destroy_workqueue(fsc
->wb_wq
);
664 destroy_workqueue(fsc
->pg_inv_wq
);
665 destroy_workqueue(fsc
->trunc_wq
);
667 mempool_destroy(fsc
->wb_pagevec_pool
);
669 destroy_mount_options(fsc
->mount_options
);
671 ceph_destroy_client(fsc
->client
);
674 dout("destroy_fs_client %p done\n", fsc
);
680 struct kmem_cache
*ceph_inode_cachep
;
681 struct kmem_cache
*ceph_cap_cachep
;
682 struct kmem_cache
*ceph_cap_flush_cachep
;
683 struct kmem_cache
*ceph_dentry_cachep
;
684 struct kmem_cache
*ceph_file_cachep
;
686 static void ceph_inode_init_once(void *foo
)
688 struct ceph_inode_info
*ci
= foo
;
689 inode_init_once(&ci
->vfs_inode
);
692 static int __init
init_caches(void)
696 ceph_inode_cachep
= kmem_cache_create("ceph_inode_info",
697 sizeof(struct ceph_inode_info
),
698 __alignof__(struct ceph_inode_info
),
699 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
|
700 SLAB_ACCOUNT
, ceph_inode_init_once
);
701 if (!ceph_inode_cachep
)
704 ceph_cap_cachep
= KMEM_CACHE(ceph_cap
,
705 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
);
706 if (!ceph_cap_cachep
)
708 ceph_cap_flush_cachep
= KMEM_CACHE(ceph_cap_flush
,
709 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
);
710 if (!ceph_cap_flush_cachep
)
713 ceph_dentry_cachep
= KMEM_CACHE(ceph_dentry_info
,
714 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
);
715 if (!ceph_dentry_cachep
)
718 ceph_file_cachep
= KMEM_CACHE(ceph_file_info
, SLAB_MEM_SPREAD
);
719 if (!ceph_file_cachep
)
722 error
= ceph_fscache_register();
729 kmem_cache_destroy(ceph_file_cachep
);
731 kmem_cache_destroy(ceph_dentry_cachep
);
733 kmem_cache_destroy(ceph_cap_flush_cachep
);
735 kmem_cache_destroy(ceph_cap_cachep
);
737 kmem_cache_destroy(ceph_inode_cachep
);
741 static void destroy_caches(void)
744 * Make sure all delayed rcu free inodes are flushed before we
749 kmem_cache_destroy(ceph_inode_cachep
);
750 kmem_cache_destroy(ceph_cap_cachep
);
751 kmem_cache_destroy(ceph_cap_flush_cachep
);
752 kmem_cache_destroy(ceph_dentry_cachep
);
753 kmem_cache_destroy(ceph_file_cachep
);
755 ceph_fscache_unregister();
760 * ceph_umount_begin - initiate forced umount. Tear down down the
761 * mount, skipping steps that may hang while waiting for server(s).
763 static void ceph_umount_begin(struct super_block
*sb
)
765 struct ceph_fs_client
*fsc
= ceph_sb_to_client(sb
);
767 dout("ceph_umount_begin - starting forced umount\n");
770 fsc
->mount_state
= CEPH_MOUNT_SHUTDOWN
;
771 ceph_mdsc_force_umount(fsc
->mdsc
);
775 static const struct super_operations ceph_super_ops
= {
776 .alloc_inode
= ceph_alloc_inode
,
777 .destroy_inode
= ceph_destroy_inode
,
778 .write_inode
= ceph_write_inode
,
779 .drop_inode
= ceph_drop_inode
,
780 .sync_fs
= ceph_sync_fs
,
781 .put_super
= ceph_put_super
,
782 .show_options
= ceph_show_options
,
783 .statfs
= ceph_statfs
,
784 .umount_begin
= ceph_umount_begin
,
788 * Bootstrap mount by opening the root directory. Note the mount
789 * @started time from caller, and time out if this takes too long.
791 static struct dentry
*open_root_dentry(struct ceph_fs_client
*fsc
,
793 unsigned long started
)
795 struct ceph_mds_client
*mdsc
= fsc
->mdsc
;
796 struct ceph_mds_request
*req
= NULL
;
801 dout("open_root_inode opening '%s'\n", path
);
802 req
= ceph_mdsc_create_request(mdsc
, CEPH_MDS_OP_GETATTR
, USE_ANY_MDS
);
804 return ERR_CAST(req
);
805 req
->r_path1
= kstrdup(path
, GFP_NOFS
);
807 root
= ERR_PTR(-ENOMEM
);
811 req
->r_ino1
.ino
= CEPH_INO_ROOT
;
812 req
->r_ino1
.snap
= CEPH_NOSNAP
;
813 req
->r_started
= started
;
814 req
->r_timeout
= fsc
->client
->options
->mount_timeout
;
815 req
->r_args
.getattr
.mask
= cpu_to_le32(CEPH_STAT_CAP_INODE
);
817 err
= ceph_mdsc_do_request(mdsc
, NULL
, req
);
819 struct inode
*inode
= req
->r_target_inode
;
820 req
->r_target_inode
= NULL
;
821 dout("open_root_inode success\n");
822 root
= d_make_root(inode
);
824 root
= ERR_PTR(-ENOMEM
);
827 dout("open_root_inode success, root dentry is %p\n", root
);
832 ceph_mdsc_put_request(req
);
840 * mount: join the ceph cluster, and open root directory.
842 static struct dentry
*ceph_real_mount(struct ceph_fs_client
*fsc
)
845 unsigned long started
= jiffies
; /* note the start time */
848 dout("mount start %p\n", fsc
);
849 mutex_lock(&fsc
->client
->mount_mutex
);
851 if (!fsc
->sb
->s_root
) {
853 err
= __ceph_open_session(fsc
->client
, started
);
858 if (fsc
->mount_options
->flags
& CEPH_MOUNT_OPT_FSCACHE
) {
859 err
= ceph_fscache_register_fs(fsc
);
864 if (!fsc
->mount_options
->server_path
) {
866 dout("mount opening path \\t\n");
868 path
= fsc
->mount_options
->server_path
+ 1;
869 dout("mount opening path %s\n", path
);
872 err
= ceph_fs_debugfs_init(fsc
);
876 root
= open_root_dentry(fsc
, path
, started
);
881 fsc
->sb
->s_root
= dget(root
);
883 root
= dget(fsc
->sb
->s_root
);
886 fsc
->mount_state
= CEPH_MOUNT_MOUNTED
;
887 dout("mount success\n");
888 mutex_unlock(&fsc
->client
->mount_mutex
);
892 mutex_unlock(&fsc
->client
->mount_mutex
);
896 static int ceph_set_super(struct super_block
*s
, void *data
)
898 struct ceph_fs_client
*fsc
= data
;
901 dout("set_super %p data %p\n", s
, data
);
903 s
->s_flags
= fsc
->mount_options
->sb_flags
;
904 s
->s_maxbytes
= 1ULL << 40; /* temp value until we get mdsmap */
906 s
->s_xattr
= ceph_xattr_handlers
;
910 s
->s_op
= &ceph_super_ops
;
911 s
->s_d_op
= &ceph_dentry_ops
;
912 s
->s_export_op
= &ceph_export_ops
;
914 s
->s_time_gran
= 1000; /* 1000 ns == 1 us */
916 ret
= set_anon_super(s
, NULL
); /* what is that second arg for? */
929 * share superblock if same fs AND options
931 static int ceph_compare_super(struct super_block
*sb
, void *data
)
933 struct ceph_fs_client
*new = data
;
934 struct ceph_mount_options
*fsopt
= new->mount_options
;
935 struct ceph_options
*opt
= new->client
->options
;
936 struct ceph_fs_client
*other
= ceph_sb_to_client(sb
);
938 dout("ceph_compare_super %p\n", sb
);
940 if (compare_mount_options(fsopt
, opt
, other
)) {
941 dout("monitor(s)/mount options don't match\n");
944 if ((opt
->flags
& CEPH_OPT_FSID
) &&
945 ceph_fsid_compare(&opt
->fsid
, &other
->client
->fsid
)) {
946 dout("fsid doesn't match\n");
949 if (fsopt
->sb_flags
!= other
->mount_options
->sb_flags
) {
950 dout("flags differ\n");
957 * construct our own bdi so we can control readahead, etc.
959 static atomic_long_t bdi_seq
= ATOMIC_LONG_INIT(0);
961 static int ceph_setup_bdi(struct super_block
*sb
, struct ceph_fs_client
*fsc
)
965 err
= super_setup_bdi_name(sb
, "ceph-%ld",
966 atomic_long_inc_return(&bdi_seq
));
970 /* set ra_pages based on rasize mount option? */
971 sb
->s_bdi
->ra_pages
= fsc
->mount_options
->rasize
>> PAGE_SHIFT
;
973 /* set io_pages based on max osd read size */
974 sb
->s_bdi
->io_pages
= fsc
->mount_options
->rsize
>> PAGE_SHIFT
;
979 static struct dentry
*ceph_mount(struct file_system_type
*fs_type
,
980 int flags
, const char *dev_name
, void *data
)
982 struct super_block
*sb
;
983 struct ceph_fs_client
*fsc
;
986 int (*compare_super
)(struct super_block
*, void *) = ceph_compare_super
;
987 struct ceph_mount_options
*fsopt
= NULL
;
988 struct ceph_options
*opt
= NULL
;
990 dout("ceph_mount\n");
992 #ifdef CONFIG_CEPH_FS_POSIX_ACL
993 flags
|= SB_POSIXACL
;
995 err
= parse_mount_options(&fsopt
, &opt
, flags
, data
, dev_name
);
1001 /* create client (which we may/may not use) */
1002 fsc
= create_fs_client(fsopt
, opt
);
1004 res
= ERR_CAST(fsc
);
1005 destroy_mount_options(fsopt
);
1006 ceph_destroy_options(opt
);
1010 err
= ceph_mdsc_init(fsc
);
1016 if (ceph_test_opt(fsc
->client
, NOSHARE
))
1017 compare_super
= NULL
;
1018 sb
= sget(fs_type
, compare_super
, ceph_set_super
, flags
, fsc
);
1024 if (ceph_sb_to_client(sb
) != fsc
) {
1025 ceph_mdsc_destroy(fsc
);
1026 destroy_fs_client(fsc
);
1027 fsc
= ceph_sb_to_client(sb
);
1028 dout("get_sb got existing client %p\n", fsc
);
1030 dout("get_sb using new client %p\n", fsc
);
1031 err
= ceph_setup_bdi(sb
, fsc
);
1038 res
= ceph_real_mount(fsc
);
1041 dout("root %p inode %p ino %llx.%llx\n", res
,
1042 d_inode(res
), ceph_vinop(d_inode(res
)));
1046 ceph_mdsc_close_sessions(fsc
->mdsc
);
1047 deactivate_locked_super(sb
);
1051 ceph_mdsc_destroy(fsc
);
1052 destroy_fs_client(fsc
);
1054 dout("ceph_mount fail %ld\n", PTR_ERR(res
));
1058 static void ceph_kill_sb(struct super_block
*s
)
1060 struct ceph_fs_client
*fsc
= ceph_sb_to_client(s
);
1061 dev_t dev
= s
->s_dev
;
1063 dout("kill_sb %p\n", s
);
1065 ceph_mdsc_pre_umount(fsc
->mdsc
);
1066 generic_shutdown_super(s
);
1068 fsc
->client
->extra_mon_dispatch
= NULL
;
1069 ceph_fs_debugfs_cleanup(fsc
);
1071 ceph_fscache_unregister_fs(fsc
);
1073 ceph_mdsc_destroy(fsc
);
1075 destroy_fs_client(fsc
);
1076 free_anon_bdev(dev
);
1079 static struct file_system_type ceph_fs_type
= {
1080 .owner
= THIS_MODULE
,
1082 .mount
= ceph_mount
,
1083 .kill_sb
= ceph_kill_sb
,
1084 .fs_flags
= FS_RENAME_DOES_D_MOVE
,
1086 MODULE_ALIAS_FS("ceph");
1088 static int __init
init_ceph(void)
1090 int ret
= init_caches();
1096 ret
= register_filesystem(&ceph_fs_type
);
1100 pr_info("loaded (mds proto %d)\n", CEPH_MDSC_PROTOCOL
);
1111 static void __exit
exit_ceph(void)
1113 dout("exit_ceph\n");
1114 unregister_filesystem(&ceph_fs_type
);
1119 module_init(init_ceph
);
1120 module_exit(exit_ceph
);
1122 MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
1123 MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
1124 MODULE_AUTHOR("Patience Warnick <patience@newdream.net>");
1125 MODULE_DESCRIPTION("Ceph filesystem for Linux");
1126 MODULE_LICENSE("GPL");