diff options
author | Yehuda Sadeh <yehuda@hq.newdream.net> | 2010-04-06 18:14:15 -0400 |
---|---|---|
committer | Sage Weil <sage@newdream.net> | 2010-10-20 18:37:28 -0400 |
commit | 3d14c5d2b6e15c21d8e5467dc62d33127c23a644 (patch) | |
tree | 7d123c47847df9d1e865b6b78dc7da3fe739b704 /fs/ceph/mds_client.c | |
parent | ae1533b62b3369e6ae32338f4a77d64d0e88f676 (diff) |
ceph: factor out libceph from Ceph file system
This factors out protocol and low-level storage parts of ceph into a
separate libceph module living in net/ceph and include/linux/ceph. This
is mostly a matter of moving files around. However, a few key pieces
of the interface change as well:
- ceph_client becomes ceph_fs_client and ceph_client, where the latter
captures the mon and osd clients, and the fs_client gets the mds client
and file system specific pieces.
- Mount option parsing and debugfs setup is correspondingly broken into
two pieces.
- The mon client gets a generic handler callback for otherwise unknown
messages (mds map, in this case).
- The basic supported/required feature bits can be expanded (and are by
ceph_fs_client).
No functional change, aside from some subtle error handling cases that got
cleaned up in the refactoring process.
Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'fs/ceph/mds_client.c')
-rw-r--r-- | fs/ceph/mds_client.c | 86 |
1 files changed, 51 insertions, 35 deletions
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index fad95f8f2608..33568239a08e 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c | |||
@@ -1,17 +1,20 @@ | |||
1 | #include "ceph_debug.h" | 1 | #include <linux/ceph/ceph_debug.h> |
2 | 2 | ||
3 | #include <linux/wait.h> | 3 | #include <linux/wait.h> |
4 | #include <linux/slab.h> | 4 | #include <linux/slab.h> |
5 | #include <linux/sched.h> | 5 | #include <linux/sched.h> |
6 | #include <linux/smp_lock.h> | 6 | #include <linux/smp_lock.h> |
7 | #include <linux/debugfs.h> | ||
8 | #include <linux/seq_file.h> | ||
7 | 9 | ||
8 | #include "mds_client.h" | ||
9 | #include "mon_client.h" | ||
10 | #include "super.h" | 10 | #include "super.h" |
11 | #include "messenger.h" | 11 | #include "mds_client.h" |
12 | #include "decode.h" | 12 | |
13 | #include "auth.h" | 13 | #include <linux/ceph/messenger.h> |
14 | #include "pagelist.h" | 14 | #include <linux/ceph/decode.h> |
15 | #include <linux/ceph/pagelist.h> | ||
16 | #include <linux/ceph/auth.h> | ||
17 | #include <linux/ceph/debugfs.h> | ||
15 | 18 | ||
16 | /* | 19 | /* |
17 | * A cluster of MDS (metadata server) daemons is responsible for | 20 | * A cluster of MDS (metadata server) daemons is responsible for |
@@ -286,8 +289,9 @@ void ceph_put_mds_session(struct ceph_mds_session *s) | |||
286 | atomic_read(&s->s_ref), atomic_read(&s->s_ref)-1); | 289 | atomic_read(&s->s_ref), atomic_read(&s->s_ref)-1); |
287 | if (atomic_dec_and_test(&s->s_ref)) { | 290 | if (atomic_dec_and_test(&s->s_ref)) { |
288 | if (s->s_authorizer) | 291 | if (s->s_authorizer) |
289 | s->s_mdsc->client->monc.auth->ops->destroy_authorizer( | 292 | s->s_mdsc->fsc->client->monc.auth->ops->destroy_authorizer( |
290 | s->s_mdsc->client->monc.auth, s->s_authorizer); | 293 | s->s_mdsc->fsc->client->monc.auth, |
294 | s->s_authorizer); | ||
291 | kfree(s); | 295 | kfree(s); |
292 | } | 296 | } |
293 | } | 297 | } |
@@ -344,7 +348,7 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc, | |||
344 | s->s_seq = 0; | 348 | s->s_seq = 0; |
345 | mutex_init(&s->s_mutex); | 349 | mutex_init(&s->s_mutex); |
346 | 350 | ||
347 | ceph_con_init(mdsc->client->msgr, &s->s_con); | 351 | ceph_con_init(mdsc->fsc->client->msgr, &s->s_con); |
348 | s->s_con.private = s; | 352 | s->s_con.private = s; |
349 | s->s_con.ops = &mds_con_ops; | 353 | s->s_con.ops = &mds_con_ops; |
350 | s->s_con.peer_name.type = CEPH_ENTITY_TYPE_MDS; | 354 | s->s_con.peer_name.type = CEPH_ENTITY_TYPE_MDS; |
@@ -599,7 +603,7 @@ static int __choose_mds(struct ceph_mds_client *mdsc, | |||
599 | } else if (req->r_dentry) { | 603 | } else if (req->r_dentry) { |
600 | struct inode *dir = req->r_dentry->d_parent->d_inode; | 604 | struct inode *dir = req->r_dentry->d_parent->d_inode; |
601 | 605 | ||
602 | if (dir->i_sb != mdsc->client->sb) { | 606 | if (dir->i_sb != mdsc->fsc->sb) { |
603 | /* not this fs! */ | 607 | /* not this fs! */ |
604 | inode = req->r_dentry->d_inode; | 608 | inode = req->r_dentry->d_inode; |
605 | } else if (ceph_snap(dir) != CEPH_NOSNAP) { | 609 | } else if (ceph_snap(dir) != CEPH_NOSNAP) { |
@@ -884,7 +888,7 @@ static int remove_session_caps_cb(struct inode *inode, struct ceph_cap *cap, | |||
884 | __ceph_remove_cap(cap); | 888 | __ceph_remove_cap(cap); |
885 | if (!__ceph_is_any_real_caps(ci)) { | 889 | if (!__ceph_is_any_real_caps(ci)) { |
886 | struct ceph_mds_client *mdsc = | 890 | struct ceph_mds_client *mdsc = |
887 | &ceph_sb_to_client(inode->i_sb)->mdsc; | 891 | ceph_sb_to_client(inode->i_sb)->mdsc; |
888 | 892 | ||
889 | spin_lock(&mdsc->cap_dirty_lock); | 893 | spin_lock(&mdsc->cap_dirty_lock); |
890 | if (!list_empty(&ci->i_dirty_item)) { | 894 | if (!list_empty(&ci->i_dirty_item)) { |
@@ -1146,7 +1150,7 @@ int ceph_add_cap_releases(struct ceph_mds_client *mdsc, | |||
1146 | struct ceph_msg *msg, *partial = NULL; | 1150 | struct ceph_msg *msg, *partial = NULL; |
1147 | struct ceph_mds_cap_release *head; | 1151 | struct ceph_mds_cap_release *head; |
1148 | int err = -ENOMEM; | 1152 | int err = -ENOMEM; |
1149 | int extra = mdsc->client->mount_args->cap_release_safety; | 1153 | int extra = mdsc->fsc->mount_options->cap_release_safety; |
1150 | int num; | 1154 | int num; |
1151 | 1155 | ||
1152 | dout("add_cap_releases %p mds%d extra %d\n", session, session->s_mds, | 1156 | dout("add_cap_releases %p mds%d extra %d\n", session, session->s_mds, |
@@ -2085,7 +2089,7 @@ static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg) | |||
2085 | 2089 | ||
2086 | /* insert trace into our cache */ | 2090 | /* insert trace into our cache */ |
2087 | mutex_lock(&req->r_fill_mutex); | 2091 | mutex_lock(&req->r_fill_mutex); |
2088 | err = ceph_fill_trace(mdsc->client->sb, req, req->r_session); | 2092 | err = ceph_fill_trace(mdsc->fsc->sb, req, req->r_session); |
2089 | if (err == 0) { | 2093 | if (err == 0) { |
2090 | if (result == 0 && rinfo->dir_nr) | 2094 | if (result == 0 && rinfo->dir_nr) |
2091 | ceph_readdir_prepopulate(req, req->r_session); | 2095 | ceph_readdir_prepopulate(req, req->r_session); |
@@ -2613,7 +2617,7 @@ static void handle_lease(struct ceph_mds_client *mdsc, | |||
2613 | struct ceph_mds_session *session, | 2617 | struct ceph_mds_session *session, |
2614 | struct ceph_msg *msg) | 2618 | struct ceph_msg *msg) |
2615 | { | 2619 | { |
2616 | struct super_block *sb = mdsc->client->sb; | 2620 | struct super_block *sb = mdsc->fsc->sb; |
2617 | struct inode *inode; | 2621 | struct inode *inode; |
2618 | struct ceph_inode_info *ci; | 2622 | struct ceph_inode_info *ci; |
2619 | struct dentry *parent, *dentry; | 2623 | struct dentry *parent, *dentry; |
@@ -2891,10 +2895,16 @@ static void delayed_work(struct work_struct *work) | |||
2891 | schedule_delayed(mdsc); | 2895 | schedule_delayed(mdsc); |
2892 | } | 2896 | } |
2893 | 2897 | ||
2898 | int ceph_mdsc_init(struct ceph_fs_client *fsc) | ||
2894 | 2899 | ||
2895 | int ceph_mdsc_init(struct ceph_mds_client *mdsc, struct ceph_client *client) | ||
2896 | { | 2900 | { |
2897 | mdsc->client = client; | 2901 | struct ceph_mds_client *mdsc; |
2902 | |||
2903 | mdsc = kzalloc(sizeof(struct ceph_mds_client), GFP_NOFS); | ||
2904 | if (!mdsc) | ||
2905 | return -ENOMEM; | ||
2906 | mdsc->fsc = fsc; | ||
2907 | fsc->mdsc = mdsc; | ||
2898 | mutex_init(&mdsc->mutex); | 2908 | mutex_init(&mdsc->mutex); |
2899 | mdsc->mdsmap = kzalloc(sizeof(*mdsc->mdsmap), GFP_NOFS); | 2909 | mdsc->mdsmap = kzalloc(sizeof(*mdsc->mdsmap), GFP_NOFS); |
2900 | if (mdsc->mdsmap == NULL) | 2910 | if (mdsc->mdsmap == NULL) |
@@ -2927,7 +2937,7 @@ int ceph_mdsc_init(struct ceph_mds_client *mdsc, struct ceph_client *client) | |||
2927 | INIT_LIST_HEAD(&mdsc->dentry_lru); | 2937 | INIT_LIST_HEAD(&mdsc->dentry_lru); |
2928 | 2938 | ||
2929 | ceph_caps_init(mdsc); | 2939 | ceph_caps_init(mdsc); |
2930 | ceph_adjust_min_caps(mdsc, client->min_caps); | 2940 | ceph_adjust_min_caps(mdsc, fsc->min_caps); |
2931 | 2941 | ||
2932 | return 0; | 2942 | return 0; |
2933 | } | 2943 | } |
@@ -2939,7 +2949,7 @@ int ceph_mdsc_init(struct ceph_mds_client *mdsc, struct ceph_client *client) | |||
2939 | static void wait_requests(struct ceph_mds_client *mdsc) | 2949 | static void wait_requests(struct ceph_mds_client *mdsc) |
2940 | { | 2950 | { |
2941 | struct ceph_mds_request *req; | 2951 | struct ceph_mds_request *req; |
2942 | struct ceph_client *client = mdsc->client; | 2952 | struct ceph_fs_client *fsc = mdsc->fsc; |
2943 | 2953 | ||
2944 | mutex_lock(&mdsc->mutex); | 2954 | mutex_lock(&mdsc->mutex); |
2945 | if (__get_oldest_req(mdsc)) { | 2955 | if (__get_oldest_req(mdsc)) { |
@@ -2947,7 +2957,7 @@ static void wait_requests(struct ceph_mds_client *mdsc) | |||
2947 | 2957 | ||
2948 | dout("wait_requests waiting for requests\n"); | 2958 | dout("wait_requests waiting for requests\n"); |
2949 | wait_for_completion_timeout(&mdsc->safe_umount_waiters, | 2959 | wait_for_completion_timeout(&mdsc->safe_umount_waiters, |
2950 | client->mount_args->mount_timeout * HZ); | 2960 | fsc->client->options->mount_timeout * HZ); |
2951 | 2961 | ||
2952 | /* tear down remaining requests */ | 2962 | /* tear down remaining requests */ |
2953 | mutex_lock(&mdsc->mutex); | 2963 | mutex_lock(&mdsc->mutex); |
@@ -3030,7 +3040,7 @@ void ceph_mdsc_sync(struct ceph_mds_client *mdsc) | |||
3030 | { | 3040 | { |
3031 | u64 want_tid, want_flush; | 3041 | u64 want_tid, want_flush; |
3032 | 3042 | ||
3033 | if (mdsc->client->mount_state == CEPH_MOUNT_SHUTDOWN) | 3043 | if (mdsc->fsc->mount_state == CEPH_MOUNT_SHUTDOWN) |
3034 | return; | 3044 | return; |
3035 | 3045 | ||
3036 | dout("sync\n"); | 3046 | dout("sync\n"); |
@@ -3053,7 +3063,7 @@ bool done_closing_sessions(struct ceph_mds_client *mdsc) | |||
3053 | { | 3063 | { |
3054 | int i, n = 0; | 3064 | int i, n = 0; |
3055 | 3065 | ||
3056 | if (mdsc->client->mount_state == CEPH_MOUNT_SHUTDOWN) | 3066 | if (mdsc->fsc->mount_state == CEPH_MOUNT_SHUTDOWN) |
3057 | return true; | 3067 | return true; |
3058 | 3068 | ||
3059 | mutex_lock(&mdsc->mutex); | 3069 | mutex_lock(&mdsc->mutex); |
@@ -3071,8 +3081,8 @@ void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc) | |||
3071 | { | 3081 | { |
3072 | struct ceph_mds_session *session; | 3082 | struct ceph_mds_session *session; |
3073 | int i; | 3083 | int i; |
3074 | struct ceph_client *client = mdsc->client; | 3084 | struct ceph_fs_client *fsc = mdsc->fsc; |
3075 | unsigned long timeout = client->mount_args->mount_timeout * HZ; | 3085 | unsigned long timeout = fsc->client->options->mount_timeout * HZ; |
3076 | 3086 | ||
3077 | dout("close_sessions\n"); | 3087 | dout("close_sessions\n"); |
3078 | 3088 | ||
@@ -3119,7 +3129,7 @@ void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc) | |||
3119 | dout("stopped\n"); | 3129 | dout("stopped\n"); |
3120 | } | 3130 | } |
3121 | 3131 | ||
3122 | void ceph_mdsc_stop(struct ceph_mds_client *mdsc) | 3132 | static void ceph_mdsc_stop(struct ceph_mds_client *mdsc) |
3123 | { | 3133 | { |
3124 | dout("stop\n"); | 3134 | dout("stop\n"); |
3125 | cancel_delayed_work_sync(&mdsc->delayed_work); /* cancel timer */ | 3135 | cancel_delayed_work_sync(&mdsc->delayed_work); /* cancel timer */ |
@@ -3129,6 +3139,15 @@ void ceph_mdsc_stop(struct ceph_mds_client *mdsc) | |||
3129 | ceph_caps_finalize(mdsc); | 3139 | ceph_caps_finalize(mdsc); |
3130 | } | 3140 | } |
3131 | 3141 | ||
3142 | void ceph_mdsc_destroy(struct ceph_fs_client *fsc) | ||
3143 | { | ||
3144 | struct ceph_mds_client *mdsc = fsc->mdsc; | ||
3145 | |||
3146 | ceph_mdsc_stop(mdsc); | ||
3147 | fsc->mdsc = NULL; | ||
3148 | kfree(mdsc); | ||
3149 | } | ||
3150 | |||
3132 | 3151 | ||
3133 | /* | 3152 | /* |
3134 | * handle mds map update. | 3153 | * handle mds map update. |
@@ -3145,14 +3164,14 @@ void ceph_mdsc_handle_map(struct ceph_mds_client *mdsc, struct ceph_msg *msg) | |||
3145 | 3164 | ||
3146 | ceph_decode_need(&p, end, sizeof(fsid)+2*sizeof(u32), bad); | 3165 | ceph_decode_need(&p, end, sizeof(fsid)+2*sizeof(u32), bad); |
3147 | ceph_decode_copy(&p, &fsid, sizeof(fsid)); | 3166 | ceph_decode_copy(&p, &fsid, sizeof(fsid)); |
3148 | if (ceph_check_fsid(mdsc->client, &fsid) < 0) | 3167 | if (ceph_check_fsid(mdsc->fsc->client, &fsid) < 0) |
3149 | return; | 3168 | return; |
3150 | epoch = ceph_decode_32(&p); | 3169 | epoch = ceph_decode_32(&p); |
3151 | maplen = ceph_decode_32(&p); | 3170 | maplen = ceph_decode_32(&p); |
3152 | dout("handle_map epoch %u len %d\n", epoch, (int)maplen); | 3171 | dout("handle_map epoch %u len %d\n", epoch, (int)maplen); |
3153 | 3172 | ||
3154 | /* do we need it? */ | 3173 | /* do we need it? */ |
3155 | ceph_monc_got_mdsmap(&mdsc->client->monc, epoch); | 3174 | ceph_monc_got_mdsmap(&mdsc->fsc->client->monc, epoch); |
3156 | mutex_lock(&mdsc->mutex); | 3175 | mutex_lock(&mdsc->mutex); |
3157 | if (mdsc->mdsmap && epoch <= mdsc->mdsmap->m_epoch) { | 3176 | if (mdsc->mdsmap && epoch <= mdsc->mdsmap->m_epoch) { |
3158 | dout("handle_map epoch %u <= our %u\n", | 3177 | dout("handle_map epoch %u <= our %u\n", |
@@ -3176,7 +3195,7 @@ void ceph_mdsc_handle_map(struct ceph_mds_client *mdsc, struct ceph_msg *msg) | |||
3176 | } else { | 3195 | } else { |
3177 | mdsc->mdsmap = newmap; /* first mds map */ | 3196 | mdsc->mdsmap = newmap; /* first mds map */ |
3178 | } | 3197 | } |
3179 | mdsc->client->sb->s_maxbytes = mdsc->mdsmap->m_max_file_size; | 3198 | mdsc->fsc->sb->s_maxbytes = mdsc->mdsmap->m_max_file_size; |
3180 | 3199 | ||
3181 | __wake_requests(mdsc, &mdsc->waiting_for_map); | 3200 | __wake_requests(mdsc, &mdsc->waiting_for_map); |
3182 | 3201 | ||
@@ -3277,7 +3296,7 @@ static int get_authorizer(struct ceph_connection *con, | |||
3277 | { | 3296 | { |
3278 | struct ceph_mds_session *s = con->private; | 3297 | struct ceph_mds_session *s = con->private; |
3279 | struct ceph_mds_client *mdsc = s->s_mdsc; | 3298 | struct ceph_mds_client *mdsc = s->s_mdsc; |
3280 | struct ceph_auth_client *ac = mdsc->client->monc.auth; | 3299 | struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; |
3281 | int ret = 0; | 3300 | int ret = 0; |
3282 | 3301 | ||
3283 | if (force_new && s->s_authorizer) { | 3302 | if (force_new && s->s_authorizer) { |
@@ -3311,7 +3330,7 @@ static int verify_authorizer_reply(struct ceph_connection *con, int len) | |||
3311 | { | 3330 | { |
3312 | struct ceph_mds_session *s = con->private; | 3331 | struct ceph_mds_session *s = con->private; |
3313 | struct ceph_mds_client *mdsc = s->s_mdsc; | 3332 | struct ceph_mds_client *mdsc = s->s_mdsc; |
3314 | struct ceph_auth_client *ac = mdsc->client->monc.auth; | 3333 | struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; |
3315 | 3334 | ||
3316 | return ac->ops->verify_authorizer_reply(ac, s->s_authorizer, len); | 3335 | return ac->ops->verify_authorizer_reply(ac, s->s_authorizer, len); |
3317 | } | 3336 | } |
@@ -3320,12 +3339,12 @@ static int invalidate_authorizer(struct ceph_connection *con) | |||
3320 | { | 3339 | { |
3321 | struct ceph_mds_session *s = con->private; | 3340 | struct ceph_mds_session *s = con->private; |
3322 | struct ceph_mds_client *mdsc = s->s_mdsc; | 3341 | struct ceph_mds_client *mdsc = s->s_mdsc; |
3323 | struct ceph_auth_client *ac = mdsc->client->monc.auth; | 3342 | struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; |
3324 | 3343 | ||
3325 | if (ac->ops->invalidate_authorizer) | 3344 | if (ac->ops->invalidate_authorizer) |
3326 | ac->ops->invalidate_authorizer(ac, CEPH_ENTITY_TYPE_MDS); | 3345 | ac->ops->invalidate_authorizer(ac, CEPH_ENTITY_TYPE_MDS); |
3327 | 3346 | ||
3328 | return ceph_monc_validate_auth(&mdsc->client->monc); | 3347 | return ceph_monc_validate_auth(&mdsc->fsc->client->monc); |
3329 | } | 3348 | } |
3330 | 3349 | ||
3331 | static const struct ceph_connection_operations mds_con_ops = { | 3350 | static const struct ceph_connection_operations mds_con_ops = { |
@@ -3338,7 +3357,4 @@ static const struct ceph_connection_operations mds_con_ops = { | |||
3338 | .peer_reset = peer_reset, | 3357 | .peer_reset = peer_reset, |
3339 | }; | 3358 | }; |
3340 | 3359 | ||
3341 | |||
3342 | |||
3343 | |||
3344 | /* eof */ | 3360 | /* eof */ |