1 // SPDX-License-Identifier: GPL-2.0-only
3 #include <linux/ceph/ceph_debug.h>
5 #include <linux/backing-dev.h>
6 #include <linux/ctype.h>
8 #include <linux/inet.h>
10 #include <linux/module.h>
11 #include <linux/mount.h>
12 #include <linux/parser.h>
13 #include <linux/sched.h>
14 #include <linux/seq_file.h>
15 #include <linux/slab.h>
16 #include <linux/statfs.h>
17 #include <linux/string.h>
20 #include "mds_client.h"
23 #include <linux/ceph/ceph_features.h>
24 #include <linux/ceph/decode.h>
25 #include <linux/ceph/mon_client.h>
26 #include <linux/ceph/auth.h>
27 #include <linux/ceph/debugfs.h>
30 * Ceph superblock operations
32 * Handle the basics of mounting, unmounting.
38 static void ceph_put_super(struct super_block
*s
)
40 struct ceph_fs_client
*fsc
= ceph_sb_to_client(s
);
43 ceph_mdsc_close_sessions(fsc
->mdsc
);
46 static int ceph_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
48 struct ceph_fs_client
*fsc
= ceph_inode_to_client(d_inode(dentry
));
49 struct ceph_mon_client
*monc
= &fsc
->client
->monc
;
50 struct ceph_statfs st
;
55 if (fsc
->mdsc
->mdsmap
->m_num_data_pg_pools
== 1) {
56 data_pool
= fsc
->mdsc
->mdsmap
->m_data_pg_pools
[0];
58 data_pool
= CEPH_NOPOOL
;
62 err
= ceph_monc_do_statfs(monc
, data_pool
, &st
);
67 buf
->f_type
= CEPH_SUPER_MAGIC
; /* ?? */
70 * express utilization in terms of large blocks to avoid
71 * overflow on 32-bit machines.
73 * NOTE: for the time being, we make bsize == frsize to humor
74 * not-yet-ancient versions of glibc that are broken.
75 * Someday, we will probably want to report a real block
76 * size... whatever that may mean for a network file system!
78 buf
->f_bsize
= 1 << CEPH_BLOCK_SHIFT
;
79 buf
->f_frsize
= 1 << CEPH_BLOCK_SHIFT
;
82 * By default use root quota for stats; fallback to overall filesystem
83 * usage if using 'noquotadf' mount option or if the root dir doesn't
84 * have max_bytes quota set.
86 if (ceph_test_mount_opt(fsc
, NOQUOTADF
) ||
87 !ceph_quota_update_statfs(fsc
, buf
)) {
88 buf
->f_blocks
= le64_to_cpu(st
.kb
) >> (CEPH_BLOCK_SHIFT
-10);
89 buf
->f_bfree
= le64_to_cpu(st
.kb_avail
) >> (CEPH_BLOCK_SHIFT
-10);
90 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
= NAME_MAX
;
97 /* Must convert the fsid, for consistent values across arches */
98 mutex_lock(&monc
->mutex
);
99 fsid
= le64_to_cpu(*(__le64
*)(&monc
->monmap
->fsid
)) ^
100 le64_to_cpu(*((__le64
*)&monc
->monmap
->fsid
+ 1));
101 mutex_unlock(&monc
->mutex
);
103 buf
->f_fsid
.val
[0] = fsid
& 0xffffffff;
104 buf
->f_fsid
.val
[1] = fsid
>> 32;
110 static int ceph_sync_fs(struct super_block
*sb
, int wait
)
112 struct ceph_fs_client
*fsc
= ceph_sb_to_client(sb
);
115 dout("sync_fs (non-blocking)\n");
116 ceph_flush_dirty_caps(fsc
->mdsc
);
117 dout("sync_fs (non-blocking) done\n");
121 dout("sync_fs (blocking)\n");
122 ceph_osdc_sync(&fsc
->client
->osdc
);
123 ceph_mdsc_sync(fsc
->mdsc
);
124 dout("sync_fs (blocking) done\n");
135 Opt_caps_wanted_delay_min
,
136 Opt_caps_wanted_delay_max
,
138 Opt_readdir_max_entries
,
139 Opt_readdir_max_bytes
,
147 /* string args above */
162 Opt_require_active_mds
,
163 Opt_norequire_active_mds
,
164 #ifdef CONFIG_CEPH_FS_POSIX_ACL
174 static match_table_t fsopt_tokens
= {
175 {Opt_wsize
, "wsize=%d"},
176 {Opt_rsize
, "rsize=%d"},
177 {Opt_rasize
, "rasize=%d"},
178 {Opt_caps_wanted_delay_min
, "caps_wanted_delay_min=%d"},
179 {Opt_caps_wanted_delay_max
, "caps_wanted_delay_max=%d"},
180 {Opt_caps_max
, "caps_max=%d"},
181 {Opt_readdir_max_entries
, "readdir_max_entries=%d"},
182 {Opt_readdir_max_bytes
, "readdir_max_bytes=%d"},
183 {Opt_congestion_kb
, "write_congestion_kb=%d"},
185 {Opt_snapdirname
, "snapdirname=%s"},
186 {Opt_mds_namespace
, "mds_namespace=%s"},
187 {Opt_fscache_uniq
, "fsc=%s"},
188 /* string args above */
189 {Opt_dirstat
, "dirstat"},
190 {Opt_nodirstat
, "nodirstat"},
191 {Opt_rbytes
, "rbytes"},
192 {Opt_norbytes
, "norbytes"},
193 {Opt_asyncreaddir
, "asyncreaddir"},
194 {Opt_noasyncreaddir
, "noasyncreaddir"},
195 {Opt_dcache
, "dcache"},
196 {Opt_nodcache
, "nodcache"},
197 {Opt_ino32
, "ino32"},
198 {Opt_noino32
, "noino32"},
199 {Opt_fscache
, "fsc"},
200 {Opt_nofscache
, "nofsc"},
201 {Opt_poolperm
, "poolperm"},
202 {Opt_nopoolperm
, "nopoolperm"},
203 {Opt_require_active_mds
, "require_active_mds"},
204 {Opt_norequire_active_mds
, "norequire_active_mds"},
205 #ifdef CONFIG_CEPH_FS_POSIX_ACL
208 {Opt_noacl
, "noacl"},
209 {Opt_quotadf
, "quotadf"},
210 {Opt_noquotadf
, "noquotadf"},
211 {Opt_copyfrom
, "copyfrom"},
212 {Opt_nocopyfrom
, "nocopyfrom"},
216 static int parse_fsopt_token(char *c
, void *private)
218 struct ceph_mount_options
*fsopt
= private;
219 substring_t argstr
[MAX_OPT_ARGS
];
220 int token
, intval
, ret
;
222 token
= match_token((char *)c
, fsopt_tokens
, argstr
);
226 if (token
< Opt_last_int
) {
227 ret
= match_int(&argstr
[0], &intval
);
229 pr_err("bad option arg (not int) at '%s'\n", c
);
232 dout("got int token %d val %d\n", token
, intval
);
233 } else if (token
> Opt_last_int
&& token
< Opt_last_string
) {
234 dout("got string token %d val %s\n", token
,
237 dout("got token %d\n", token
);
241 case Opt_snapdirname
:
242 kfree(fsopt
->snapdir_name
);
243 fsopt
->snapdir_name
= kstrndup(argstr
[0].from
,
244 argstr
[0].to
-argstr
[0].from
,
246 if (!fsopt
->snapdir_name
)
249 case Opt_mds_namespace
:
250 kfree(fsopt
->mds_namespace
);
251 fsopt
->mds_namespace
= kstrndup(argstr
[0].from
,
252 argstr
[0].to
-argstr
[0].from
,
254 if (!fsopt
->mds_namespace
)
257 case Opt_fscache_uniq
:
258 kfree(fsopt
->fscache_uniq
);
259 fsopt
->fscache_uniq
= kstrndup(argstr
[0].from
,
260 argstr
[0].to
-argstr
[0].from
,
262 if (!fsopt
->fscache_uniq
)
264 fsopt
->flags
|= CEPH_MOUNT_OPT_FSCACHE
;
268 if (intval
< (int)PAGE_SIZE
|| intval
> CEPH_MAX_WRITE_SIZE
)
270 fsopt
->wsize
= ALIGN(intval
, PAGE_SIZE
);
273 if (intval
< (int)PAGE_SIZE
|| intval
> CEPH_MAX_READ_SIZE
)
275 fsopt
->rsize
= ALIGN(intval
, PAGE_SIZE
);
280 fsopt
->rasize
= ALIGN(intval
, PAGE_SIZE
);
282 case Opt_caps_wanted_delay_min
:
285 fsopt
->caps_wanted_delay_min
= intval
;
287 case Opt_caps_wanted_delay_max
:
290 fsopt
->caps_wanted_delay_max
= intval
;
295 fsopt
->caps_max
= intval
;
297 case Opt_readdir_max_entries
:
300 fsopt
->max_readdir
= intval
;
302 case Opt_readdir_max_bytes
:
303 if (intval
< (int)PAGE_SIZE
&& intval
!= 0)
305 fsopt
->max_readdir_bytes
= intval
;
307 case Opt_congestion_kb
:
308 if (intval
< 1024) /* at least 1M */
310 fsopt
->congestion_kb
= intval
;
313 fsopt
->flags
|= CEPH_MOUNT_OPT_DIRSTAT
;
316 fsopt
->flags
&= ~CEPH_MOUNT_OPT_DIRSTAT
;
319 fsopt
->flags
|= CEPH_MOUNT_OPT_RBYTES
;
322 fsopt
->flags
&= ~CEPH_MOUNT_OPT_RBYTES
;
324 case Opt_asyncreaddir
:
325 fsopt
->flags
&= ~CEPH_MOUNT_OPT_NOASYNCREADDIR
;
327 case Opt_noasyncreaddir
:
328 fsopt
->flags
|= CEPH_MOUNT_OPT_NOASYNCREADDIR
;
331 fsopt
->flags
|= CEPH_MOUNT_OPT_DCACHE
;
334 fsopt
->flags
&= ~CEPH_MOUNT_OPT_DCACHE
;
337 fsopt
->flags
|= CEPH_MOUNT_OPT_INO32
;
340 fsopt
->flags
&= ~CEPH_MOUNT_OPT_INO32
;
343 fsopt
->flags
|= CEPH_MOUNT_OPT_FSCACHE
;
344 kfree(fsopt
->fscache_uniq
);
345 fsopt
->fscache_uniq
= NULL
;
348 fsopt
->flags
&= ~CEPH_MOUNT_OPT_FSCACHE
;
349 kfree(fsopt
->fscache_uniq
);
350 fsopt
->fscache_uniq
= NULL
;
353 fsopt
->flags
&= ~CEPH_MOUNT_OPT_NOPOOLPERM
;
356 fsopt
->flags
|= CEPH_MOUNT_OPT_NOPOOLPERM
;
358 case Opt_require_active_mds
:
359 fsopt
->flags
&= ~CEPH_MOUNT_OPT_MOUNTWAIT
;
361 case Opt_norequire_active_mds
:
362 fsopt
->flags
|= CEPH_MOUNT_OPT_MOUNTWAIT
;
365 fsopt
->flags
&= ~CEPH_MOUNT_OPT_NOQUOTADF
;
368 fsopt
->flags
|= CEPH_MOUNT_OPT_NOQUOTADF
;
371 fsopt
->flags
&= ~CEPH_MOUNT_OPT_NOCOPYFROM
;
374 fsopt
->flags
|= CEPH_MOUNT_OPT_NOCOPYFROM
;
376 #ifdef CONFIG_CEPH_FS_POSIX_ACL
378 fsopt
->sb_flags
|= SB_POSIXACL
;
382 fsopt
->sb_flags
&= ~SB_POSIXACL
;
390 static void destroy_mount_options(struct ceph_mount_options
*args
)
392 dout("destroy_mount_options %p\n", args
);
393 kfree(args
->snapdir_name
);
394 kfree(args
->mds_namespace
);
395 kfree(args
->server_path
);
396 kfree(args
->fscache_uniq
);
400 static int strcmp_null(const char *s1
, const char *s2
)
408 return strcmp(s1
, s2
);
411 static int compare_mount_options(struct ceph_mount_options
*new_fsopt
,
412 struct ceph_options
*new_opt
,
413 struct ceph_fs_client
*fsc
)
415 struct ceph_mount_options
*fsopt1
= new_fsopt
;
416 struct ceph_mount_options
*fsopt2
= fsc
->mount_options
;
417 int ofs
= offsetof(struct ceph_mount_options
, snapdir_name
);
420 ret
= memcmp(fsopt1
, fsopt2
, ofs
);
424 ret
= strcmp_null(fsopt1
->snapdir_name
, fsopt2
->snapdir_name
);
427 ret
= strcmp_null(fsopt1
->mds_namespace
, fsopt2
->mds_namespace
);
430 ret
= strcmp_null(fsopt1
->server_path
, fsopt2
->server_path
);
433 ret
= strcmp_null(fsopt1
->fscache_uniq
, fsopt2
->fscache_uniq
);
437 return ceph_compare_options(new_opt
, fsc
->client
);
440 static int parse_mount_options(struct ceph_mount_options
**pfsopt
,
441 struct ceph_options
**popt
,
442 int flags
, char *options
,
443 const char *dev_name
)
445 struct ceph_mount_options
*fsopt
;
446 const char *dev_name_end
;
449 if (!dev_name
|| !*dev_name
)
452 fsopt
= kzalloc(sizeof(*fsopt
), GFP_KERNEL
);
456 dout("parse_mount_options %p, dev_name '%s'\n", fsopt
, dev_name
);
458 fsopt
->sb_flags
= flags
;
459 fsopt
->flags
= CEPH_MOUNT_OPT_DEFAULT
;
461 fsopt
->wsize
= CEPH_MAX_WRITE_SIZE
;
462 fsopt
->rsize
= CEPH_MAX_READ_SIZE
;
463 fsopt
->rasize
= CEPH_RASIZE_DEFAULT
;
464 fsopt
->snapdir_name
= kstrdup(CEPH_SNAPDIRNAME_DEFAULT
, GFP_KERNEL
);
465 if (!fsopt
->snapdir_name
) {
470 fsopt
->caps_wanted_delay_min
= CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT
;
471 fsopt
->caps_wanted_delay_max
= CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT
;
472 fsopt
->max_readdir
= CEPH_MAX_READDIR_DEFAULT
;
473 fsopt
->max_readdir_bytes
= CEPH_MAX_READDIR_BYTES_DEFAULT
;
474 fsopt
->congestion_kb
= default_congestion_kb();
477 * Distinguish the server list from the path in "dev_name".
478 * Internally we do not include the leading '/' in the path.
480 * "dev_name" will look like:
481 * <server_spec>[,<server_spec>...]:[<path>]
483 * <server_spec> is <ip>[:<port>]
484 * <path> is optional, but if present must begin with '/'
486 dev_name_end
= strchr(dev_name
, '/');
488 if (strlen(dev_name_end
) > 1) {
489 fsopt
->server_path
= kstrdup(dev_name_end
, GFP_KERNEL
);
490 if (!fsopt
->server_path
) {
496 dev_name_end
= dev_name
+ strlen(dev_name
);
499 dev_name_end
--; /* back up to ':' separator */
500 if (dev_name_end
< dev_name
|| *dev_name_end
!= ':') {
501 pr_err("device name is missing path (no : separator in %s)\n",
505 dout("device name '%.*s'\n", (int)(dev_name_end
- dev_name
), dev_name
);
506 if (fsopt
->server_path
)
507 dout("server path '%s'\n", fsopt
->server_path
);
509 *popt
= ceph_parse_options(options
, dev_name
, dev_name_end
,
510 parse_fsopt_token
, (void *)fsopt
);
512 err
= PTR_ERR(*popt
);
521 destroy_mount_options(fsopt
);
526 * ceph_show_options - Show mount options in /proc/mounts
527 * @m: seq_file to write to
528 * @root: root of that (sub)tree
530 static int ceph_show_options(struct seq_file
*m
, struct dentry
*root
)
532 struct ceph_fs_client
*fsc
= ceph_sb_to_client(root
->d_sb
);
533 struct ceph_mount_options
*fsopt
= fsc
->mount_options
;
537 /* a comma between MNT/MS and client options */
541 ret
= ceph_print_client_options(m
, fsc
->client
, false);
545 /* retract our comma if no client options */
549 if (fsopt
->flags
& CEPH_MOUNT_OPT_DIRSTAT
)
550 seq_puts(m
, ",dirstat");
551 if ((fsopt
->flags
& CEPH_MOUNT_OPT_RBYTES
))
552 seq_puts(m
, ",rbytes");
553 if (fsopt
->flags
& CEPH_MOUNT_OPT_NOASYNCREADDIR
)
554 seq_puts(m
, ",noasyncreaddir");
555 if ((fsopt
->flags
& CEPH_MOUNT_OPT_DCACHE
) == 0)
556 seq_puts(m
, ",nodcache");
557 if (fsopt
->flags
& CEPH_MOUNT_OPT_INO32
)
558 seq_puts(m
, ",ino32");
559 if (fsopt
->flags
& CEPH_MOUNT_OPT_FSCACHE
) {
560 seq_show_option(m
, "fsc", fsopt
->fscache_uniq
);
562 if (fsopt
->flags
& CEPH_MOUNT_OPT_NOPOOLPERM
)
563 seq_puts(m
, ",nopoolperm");
564 if (fsopt
->flags
& CEPH_MOUNT_OPT_NOQUOTADF
)
565 seq_puts(m
, ",noquotadf");
567 #ifdef CONFIG_CEPH_FS_POSIX_ACL
568 if (fsopt
->sb_flags
& SB_POSIXACL
)
571 seq_puts(m
, ",noacl");
574 if ((fsopt
->flags
& CEPH_MOUNT_OPT_NOCOPYFROM
) == 0)
575 seq_puts(m
, ",copyfrom");
577 if (fsopt
->mds_namespace
)
578 seq_show_option(m
, "mds_namespace", fsopt
->mds_namespace
);
579 if (fsopt
->wsize
!= CEPH_MAX_WRITE_SIZE
)
580 seq_printf(m
, ",wsize=%d", fsopt
->wsize
);
581 if (fsopt
->rsize
!= CEPH_MAX_READ_SIZE
)
582 seq_printf(m
, ",rsize=%d", fsopt
->rsize
);
583 if (fsopt
->rasize
!= CEPH_RASIZE_DEFAULT
)
584 seq_printf(m
, ",rasize=%d", fsopt
->rasize
);
585 if (fsopt
->congestion_kb
!= default_congestion_kb())
586 seq_printf(m
, ",write_congestion_kb=%d", fsopt
->congestion_kb
);
588 seq_printf(m
, ",caps_max=%d", fsopt
->caps_max
);
589 if (fsopt
->caps_wanted_delay_min
!= CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT
)
590 seq_printf(m
, ",caps_wanted_delay_min=%d",
591 fsopt
->caps_wanted_delay_min
);
592 if (fsopt
->caps_wanted_delay_max
!= CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT
)
593 seq_printf(m
, ",caps_wanted_delay_max=%d",
594 fsopt
->caps_wanted_delay_max
);
595 if (fsopt
->max_readdir
!= CEPH_MAX_READDIR_DEFAULT
)
596 seq_printf(m
, ",readdir_max_entries=%d", fsopt
->max_readdir
);
597 if (fsopt
->max_readdir_bytes
!= CEPH_MAX_READDIR_BYTES_DEFAULT
)
598 seq_printf(m
, ",readdir_max_bytes=%d", fsopt
->max_readdir_bytes
);
599 if (strcmp(fsopt
->snapdir_name
, CEPH_SNAPDIRNAME_DEFAULT
))
600 seq_show_option(m
, "snapdirname", fsopt
->snapdir_name
);
606 * handle any mon messages the standard library doesn't understand.
607 * return error if we don't either.
609 static int extra_mon_dispatch(struct ceph_client
*client
, struct ceph_msg
*msg
)
611 struct ceph_fs_client
*fsc
= client
->private;
612 int type
= le16_to_cpu(msg
->hdr
.type
);
615 case CEPH_MSG_MDS_MAP
:
616 ceph_mdsc_handle_mdsmap(fsc
->mdsc
, msg
);
618 case CEPH_MSG_FS_MAP_USER
:
619 ceph_mdsc_handle_fsmap(fsc
->mdsc
, msg
);
627 * create a new fs client
629 * Success or not, this function consumes @fsopt and @opt.
631 static struct ceph_fs_client
*create_fs_client(struct ceph_mount_options
*fsopt
,
632 struct ceph_options
*opt
)
634 struct ceph_fs_client
*fsc
;
639 fsc
= kzalloc(sizeof(*fsc
), GFP_KERNEL
);
645 fsc
->client
= ceph_create_client(opt
, fsc
);
646 if (IS_ERR(fsc
->client
)) {
647 err
= PTR_ERR(fsc
->client
);
650 opt
= NULL
; /* fsc->client now owns this */
652 fsc
->client
->extra_mon_dispatch
= extra_mon_dispatch
;
653 ceph_set_opt(fsc
->client
, ABORT_ON_FULL
);
655 if (!fsopt
->mds_namespace
) {
656 ceph_monc_want_map(&fsc
->client
->monc
, CEPH_SUB_MDSMAP
,
659 ceph_monc_want_map(&fsc
->client
->monc
, CEPH_SUB_FSMAP
,
663 fsc
->mount_options
= fsopt
;
666 fsc
->mount_state
= CEPH_MOUNT_MOUNTING
;
668 atomic_long_set(&fsc
->writeback_count
, 0);
672 * The number of concurrent works can be high but they don't need
673 * to be processed in parallel, limit concurrency.
675 fsc
->inode_wq
= alloc_workqueue("ceph-inode", WQ_UNBOUND
, 0);
678 fsc
->cap_wq
= alloc_workqueue("ceph-cap", 0, 1);
682 /* set up mempools */
684 page_count
= fsc
->mount_options
->wsize
>> PAGE_SHIFT
;
685 size
= sizeof (struct page
*) * (page_count
? page_count
: 1);
686 fsc
->wb_pagevec_pool
= mempool_create_kmalloc_pool(10, size
);
687 if (!fsc
->wb_pagevec_pool
)
693 destroy_workqueue(fsc
->cap_wq
);
695 destroy_workqueue(fsc
->inode_wq
);
697 ceph_destroy_client(fsc
->client
);
701 ceph_destroy_options(opt
);
702 destroy_mount_options(fsopt
);
706 static void flush_fs_workqueues(struct ceph_fs_client
*fsc
)
708 flush_workqueue(fsc
->inode_wq
);
709 flush_workqueue(fsc
->cap_wq
);
712 static void destroy_fs_client(struct ceph_fs_client
*fsc
)
714 dout("destroy_fs_client %p\n", fsc
);
716 destroy_workqueue(fsc
->inode_wq
);
717 destroy_workqueue(fsc
->cap_wq
);
719 mempool_destroy(fsc
->wb_pagevec_pool
);
721 destroy_mount_options(fsc
->mount_options
);
723 ceph_destroy_client(fsc
->client
);
726 dout("destroy_fs_client %p done\n", fsc
);
732 struct kmem_cache
*ceph_inode_cachep
;
733 struct kmem_cache
*ceph_cap_cachep
;
734 struct kmem_cache
*ceph_cap_flush_cachep
;
735 struct kmem_cache
*ceph_dentry_cachep
;
736 struct kmem_cache
*ceph_file_cachep
;
737 struct kmem_cache
*ceph_dir_file_cachep
;
739 static void ceph_inode_init_once(void *foo
)
741 struct ceph_inode_info
*ci
= foo
;
742 inode_init_once(&ci
->vfs_inode
);
745 static int __init
init_caches(void)
749 ceph_inode_cachep
= kmem_cache_create("ceph_inode_info",
750 sizeof(struct ceph_inode_info
),
751 __alignof__(struct ceph_inode_info
),
752 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
|
753 SLAB_ACCOUNT
, ceph_inode_init_once
);
754 if (!ceph_inode_cachep
)
757 ceph_cap_cachep
= KMEM_CACHE(ceph_cap
, SLAB_MEM_SPREAD
);
758 if (!ceph_cap_cachep
)
760 ceph_cap_flush_cachep
= KMEM_CACHE(ceph_cap_flush
,
761 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
);
762 if (!ceph_cap_flush_cachep
)
765 ceph_dentry_cachep
= KMEM_CACHE(ceph_dentry_info
,
766 SLAB_RECLAIM_ACCOUNT
|SLAB_MEM_SPREAD
);
767 if (!ceph_dentry_cachep
)
770 ceph_file_cachep
= KMEM_CACHE(ceph_file_info
, SLAB_MEM_SPREAD
);
771 if (!ceph_file_cachep
)
774 ceph_dir_file_cachep
= KMEM_CACHE(ceph_dir_file_info
, SLAB_MEM_SPREAD
);
775 if (!ceph_dir_file_cachep
)
778 error
= ceph_fscache_register();
785 kmem_cache_destroy(ceph_dir_file_cachep
);
787 kmem_cache_destroy(ceph_file_cachep
);
789 kmem_cache_destroy(ceph_dentry_cachep
);
791 kmem_cache_destroy(ceph_cap_flush_cachep
);
793 kmem_cache_destroy(ceph_cap_cachep
);
795 kmem_cache_destroy(ceph_inode_cachep
);
799 static void destroy_caches(void)
802 * Make sure all delayed rcu free inodes are flushed before we
807 kmem_cache_destroy(ceph_inode_cachep
);
808 kmem_cache_destroy(ceph_cap_cachep
);
809 kmem_cache_destroy(ceph_cap_flush_cachep
);
810 kmem_cache_destroy(ceph_dentry_cachep
);
811 kmem_cache_destroy(ceph_file_cachep
);
812 kmem_cache_destroy(ceph_dir_file_cachep
);
814 ceph_fscache_unregister();
819 * ceph_umount_begin - initiate forced umount. Tear down down the
820 * mount, skipping steps that may hang while waiting for server(s).
822 static void ceph_umount_begin(struct super_block
*sb
)
824 struct ceph_fs_client
*fsc
= ceph_sb_to_client(sb
);
826 dout("ceph_umount_begin - starting forced umount\n");
829 fsc
->mount_state
= CEPH_MOUNT_SHUTDOWN
;
830 ceph_osdc_abort_requests(&fsc
->client
->osdc
, -EIO
);
831 ceph_mdsc_force_umount(fsc
->mdsc
);
835 static int ceph_remount(struct super_block
*sb
, int *flags
, char *data
)
841 static const struct super_operations ceph_super_ops
= {
842 .alloc_inode
= ceph_alloc_inode
,
843 .free_inode
= ceph_free_inode
,
844 .write_inode
= ceph_write_inode
,
845 .drop_inode
= generic_delete_inode
,
846 .evict_inode
= ceph_evict_inode
,
847 .sync_fs
= ceph_sync_fs
,
848 .put_super
= ceph_put_super
,
849 .remount_fs
= ceph_remount
,
850 .show_options
= ceph_show_options
,
851 .statfs
= ceph_statfs
,
852 .umount_begin
= ceph_umount_begin
,
856 * Bootstrap mount by opening the root directory. Note the mount
857 * @started time from caller, and time out if this takes too long.
859 static struct dentry
*open_root_dentry(struct ceph_fs_client
*fsc
,
861 unsigned long started
)
863 struct ceph_mds_client
*mdsc
= fsc
->mdsc
;
864 struct ceph_mds_request
*req
= NULL
;
869 dout("open_root_inode opening '%s'\n", path
);
870 req
= ceph_mdsc_create_request(mdsc
, CEPH_MDS_OP_GETATTR
, USE_ANY_MDS
);
872 return ERR_CAST(req
);
873 req
->r_path1
= kstrdup(path
, GFP_NOFS
);
875 root
= ERR_PTR(-ENOMEM
);
879 req
->r_ino1
.ino
= CEPH_INO_ROOT
;
880 req
->r_ino1
.snap
= CEPH_NOSNAP
;
881 req
->r_started
= started
;
882 req
->r_timeout
= fsc
->client
->options
->mount_timeout
;
883 req
->r_args
.getattr
.mask
= cpu_to_le32(CEPH_STAT_CAP_INODE
);
885 err
= ceph_mdsc_do_request(mdsc
, NULL
, req
);
887 struct inode
*inode
= req
->r_target_inode
;
888 req
->r_target_inode
= NULL
;
889 dout("open_root_inode success\n");
890 root
= d_make_root(inode
);
892 root
= ERR_PTR(-ENOMEM
);
895 dout("open_root_inode success, root dentry is %p\n", root
);
900 ceph_mdsc_put_request(req
);
908 * mount: join the ceph cluster, and open root directory.
910 static struct dentry
*ceph_real_mount(struct ceph_fs_client
*fsc
)
913 unsigned long started
= jiffies
; /* note the start time */
916 dout("mount start %p\n", fsc
);
917 mutex_lock(&fsc
->client
->mount_mutex
);
919 if (!fsc
->sb
->s_root
) {
921 err
= __ceph_open_session(fsc
->client
, started
);
926 if (fsc
->mount_options
->flags
& CEPH_MOUNT_OPT_FSCACHE
) {
927 err
= ceph_fscache_register_fs(fsc
);
932 if (!fsc
->mount_options
->server_path
) {
934 dout("mount opening path \\t\n");
936 path
= fsc
->mount_options
->server_path
+ 1;
937 dout("mount opening path %s\n", path
);
940 ceph_fs_debugfs_init(fsc
);
942 root
= open_root_dentry(fsc
, path
, started
);
947 fsc
->sb
->s_root
= dget(root
);
949 root
= dget(fsc
->sb
->s_root
);
952 fsc
->mount_state
= CEPH_MOUNT_MOUNTED
;
953 dout("mount success\n");
954 mutex_unlock(&fsc
->client
->mount_mutex
);
958 mutex_unlock(&fsc
->client
->mount_mutex
);
962 static int ceph_set_super(struct super_block
*s
, void *data
)
964 struct ceph_fs_client
*fsc
= data
;
967 dout("set_super %p data %p\n", s
, data
);
969 s
->s_flags
= fsc
->mount_options
->sb_flags
;
970 s
->s_maxbytes
= MAX_LFS_FILESIZE
;
972 s
->s_xattr
= ceph_xattr_handlers
;
975 fsc
->max_file_size
= 1ULL << 40; /* temp value until we get mdsmap */
977 s
->s_op
= &ceph_super_ops
;
978 s
->s_d_op
= &ceph_dentry_ops
;
979 s
->s_export_op
= &ceph_export_ops
;
983 ret
= set_anon_super(s
, NULL
); /* what is that second arg for? */
996 * share superblock if same fs AND options
998 static int ceph_compare_super(struct super_block
*sb
, void *data
)
1000 struct ceph_fs_client
*new = data
;
1001 struct ceph_mount_options
*fsopt
= new->mount_options
;
1002 struct ceph_options
*opt
= new->client
->options
;
1003 struct ceph_fs_client
*other
= ceph_sb_to_client(sb
);
1005 dout("ceph_compare_super %p\n", sb
);
1007 if (compare_mount_options(fsopt
, opt
, other
)) {
1008 dout("monitor(s)/mount options don't match\n");
1011 if ((opt
->flags
& CEPH_OPT_FSID
) &&
1012 ceph_fsid_compare(&opt
->fsid
, &other
->client
->fsid
)) {
1013 dout("fsid doesn't match\n");
1016 if (fsopt
->sb_flags
!= other
->mount_options
->sb_flags
) {
1017 dout("flags differ\n");
1024 * construct our own bdi so we can control readahead, etc.
1026 static atomic_long_t bdi_seq
= ATOMIC_LONG_INIT(0);
1028 static int ceph_setup_bdi(struct super_block
*sb
, struct ceph_fs_client
*fsc
)
1032 err
= super_setup_bdi_name(sb
, "ceph-%ld",
1033 atomic_long_inc_return(&bdi_seq
));
1037 /* set ra_pages based on rasize mount option? */
1038 sb
->s_bdi
->ra_pages
= fsc
->mount_options
->rasize
>> PAGE_SHIFT
;
1040 /* set io_pages based on max osd read size */
1041 sb
->s_bdi
->io_pages
= fsc
->mount_options
->rsize
>> PAGE_SHIFT
;
1046 static struct dentry
*ceph_mount(struct file_system_type
*fs_type
,
1047 int flags
, const char *dev_name
, void *data
)
1049 struct super_block
*sb
;
1050 struct ceph_fs_client
*fsc
;
1053 int (*compare_super
)(struct super_block
*, void *) = ceph_compare_super
;
1054 struct ceph_mount_options
*fsopt
= NULL
;
1055 struct ceph_options
*opt
= NULL
;
1057 dout("ceph_mount\n");
1059 #ifdef CONFIG_CEPH_FS_POSIX_ACL
1060 flags
|= SB_POSIXACL
;
1062 err
= parse_mount_options(&fsopt
, &opt
, flags
, data
, dev_name
);
1068 /* create client (which we may/may not use) */
1069 fsc
= create_fs_client(fsopt
, opt
);
1071 res
= ERR_CAST(fsc
);
1075 err
= ceph_mdsc_init(fsc
);
1081 if (ceph_test_opt(fsc
->client
, NOSHARE
))
1082 compare_super
= NULL
;
1083 sb
= sget(fs_type
, compare_super
, ceph_set_super
, flags
, fsc
);
1089 if (ceph_sb_to_client(sb
) != fsc
) {
1090 ceph_mdsc_destroy(fsc
);
1091 destroy_fs_client(fsc
);
1092 fsc
= ceph_sb_to_client(sb
);
1093 dout("get_sb got existing client %p\n", fsc
);
1095 dout("get_sb using new client %p\n", fsc
);
1096 err
= ceph_setup_bdi(sb
, fsc
);
1103 res
= ceph_real_mount(fsc
);
1106 dout("root %p inode %p ino %llx.%llx\n", res
,
1107 d_inode(res
), ceph_vinop(d_inode(res
)));
1111 ceph_mdsc_close_sessions(fsc
->mdsc
);
1112 deactivate_locked_super(sb
);
1116 ceph_mdsc_destroy(fsc
);
1117 destroy_fs_client(fsc
);
1119 dout("ceph_mount fail %ld\n", PTR_ERR(res
));
1123 static void ceph_kill_sb(struct super_block
*s
)
1125 struct ceph_fs_client
*fsc
= ceph_sb_to_client(s
);
1126 dev_t dev
= s
->s_dev
;
1128 dout("kill_sb %p\n", s
);
1130 ceph_mdsc_pre_umount(fsc
->mdsc
);
1131 flush_fs_workqueues(fsc
);
1133 generic_shutdown_super(s
);
1135 fsc
->client
->extra_mon_dispatch
= NULL
;
1136 ceph_fs_debugfs_cleanup(fsc
);
1138 ceph_fscache_unregister_fs(fsc
);
1140 ceph_mdsc_destroy(fsc
);
1142 destroy_fs_client(fsc
);
1143 free_anon_bdev(dev
);
1146 static struct file_system_type ceph_fs_type
= {
1147 .owner
= THIS_MODULE
,
1149 .mount
= ceph_mount
,
1150 .kill_sb
= ceph_kill_sb
,
1151 .fs_flags
= FS_RENAME_DOES_D_MOVE
,
1153 MODULE_ALIAS_FS("ceph");
1155 static int __init
init_ceph(void)
1157 int ret
= init_caches();
1162 ret
= register_filesystem(&ceph_fs_type
);
1166 pr_info("loaded (mds proto %d)\n", CEPH_MDSC_PROTOCOL
);
1176 static void __exit
exit_ceph(void)
1178 dout("exit_ceph\n");
1179 unregister_filesystem(&ceph_fs_type
);
1183 module_init(init_ceph
);
1184 module_exit(exit_ceph
);
1186 MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
1187 MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
1188 MODULE_AUTHOR("Patience Warnick <patience@newdream.net>");
1189 MODULE_DESCRIPTION("Ceph filesystem for Linux");
1190 MODULE_LICENSE("GPL");