aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSage Weil <sage@inktank.com>2013-03-25 13:26:14 -0400
committerSage Weil <sage@inktank.com>2013-05-02 00:17:14 -0400
commit27859f9773e4a0b2042435b13400ee2c891a61f4 (patch)
tree28b8e7133959c88f4de89cc98eee2016874b1ca6
parent0bed9b5c523d577378b6f83eab5835fe30c27208 (diff)
libceph: wrap auth ops in wrapper functions
Use wrapper functions that check whether the auth op exists so that callers do not need a bunch of conditional checks. Simplifies the external interface. Signed-off-by: Sage Weil <sage@inktank.com> Reviewed-by: Alex Elder <elder@inktank.com>
-rw-r--r--fs/ceph/mds_client.c26
-rw-r--r--include/linux/ceph/auth.h13
-rw-r--r--net/ceph/auth.c47
-rw-r--r--net/ceph/auth_x.c1
-rw-r--r--net/ceph/mon_client.c7
-rw-r--r--net/ceph/osd_client.c26
6 files changed, 84 insertions, 36 deletions
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index 010ff83d640b..13ae44eaa980 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -365,9 +365,9 @@ void ceph_put_mds_session(struct ceph_mds_session *s)
365 atomic_read(&s->s_ref), atomic_read(&s->s_ref)-1); 365 atomic_read(&s->s_ref), atomic_read(&s->s_ref)-1);
366 if (atomic_dec_and_test(&s->s_ref)) { 366 if (atomic_dec_and_test(&s->s_ref)) {
367 if (s->s_auth.authorizer) 367 if (s->s_auth.authorizer)
368 s->s_mdsc->fsc->client->monc.auth->ops->destroy_authorizer( 368 ceph_auth_destroy_authorizer(
369 s->s_mdsc->fsc->client->monc.auth, 369 s->s_mdsc->fsc->client->monc.auth,
370 s->s_auth.authorizer); 370 s->s_auth.authorizer);
371 kfree(s); 371 kfree(s);
372 } 372 }
373} 373}
@@ -3439,18 +3439,17 @@ static struct ceph_auth_handshake *get_authorizer(struct ceph_connection *con,
3439 struct ceph_auth_handshake *auth = &s->s_auth; 3439 struct ceph_auth_handshake *auth = &s->s_auth;
3440 3440
3441 if (force_new && auth->authorizer) { 3441 if (force_new && auth->authorizer) {
3442 if (ac->ops && ac->ops->destroy_authorizer) 3442 ceph_auth_destroy_authorizer(ac, auth->authorizer);
3443 ac->ops->destroy_authorizer(ac, auth->authorizer);
3444 auth->authorizer = NULL; 3443 auth->authorizer = NULL;
3445 } 3444 }
3446 if (!auth->authorizer && ac->ops && ac->ops->create_authorizer) { 3445 if (!auth->authorizer) {
3447 int ret = ac->ops->create_authorizer(ac, CEPH_ENTITY_TYPE_MDS, 3446 int ret = ceph_auth_create_authorizer(ac, CEPH_ENTITY_TYPE_MDS,
3448 auth); 3447 auth);
3449 if (ret) 3448 if (ret)
3450 return ERR_PTR(ret); 3449 return ERR_PTR(ret);
3451 } else if (ac->ops && ac->ops_update_authorizer) { 3450 } else {
3452 int ret = ac->ops->update_authorizer(ac, CEPH_ENTITY_TYPE_MDS, 3451 int ret = ceph_auth_update_authorizer(ac, CEPH_ENTITY_TYPE_MDS,
3453 auth); 3452 auth);
3454 if (ret) 3453 if (ret)
3455 return ERR_PTR(ret); 3454 return ERR_PTR(ret);
3456 } 3455 }
@@ -3466,7 +3465,7 @@ static int verify_authorizer_reply(struct ceph_connection *con, int len)
3466 struct ceph_mds_client *mdsc = s->s_mdsc; 3465 struct ceph_mds_client *mdsc = s->s_mdsc;
3467 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; 3466 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth;
3468 3467
3469 return ac->ops->verify_authorizer_reply(ac, s->s_auth.authorizer, len); 3468 return ceph_auth_verify_authorizer_reply(ac, s->s_auth.authorizer, len);
3470} 3469}
3471 3470
3472static int invalidate_authorizer(struct ceph_connection *con) 3471static int invalidate_authorizer(struct ceph_connection *con)
@@ -3475,8 +3474,7 @@ static int invalidate_authorizer(struct ceph_connection *con)
3475 struct ceph_mds_client *mdsc = s->s_mdsc; 3474 struct ceph_mds_client *mdsc = s->s_mdsc;
3476 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; 3475 struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth;
3477 3476
3478 if (ac->ops->invalidate_authorizer) 3477 ceph_auth_invalidate_authorizer(ac, CEPH_ENTITY_TYPE_MDS);
3479 ac->ops->invalidate_authorizer(ac, CEPH_ENTITY_TYPE_MDS);
3480 3478
3481 return ceph_monc_validate_auth(&mdsc->fsc->client->monc); 3479 return ceph_monc_validate_auth(&mdsc->fsc->client->monc);
3482} 3480}
diff --git a/include/linux/ceph/auth.h b/include/linux/ceph/auth.h
index 73e973e70026..c9c3b3abe4a3 100644
--- a/include/linux/ceph/auth.h
+++ b/include/linux/ceph/auth.h
@@ -97,5 +97,18 @@ extern int ceph_build_auth(struct ceph_auth_client *ac,
97 void *msg_buf, size_t msg_len); 97 void *msg_buf, size_t msg_len);
98 98
99extern int ceph_auth_is_authenticated(struct ceph_auth_client *ac); 99extern int ceph_auth_is_authenticated(struct ceph_auth_client *ac);
100extern int ceph_auth_create_authorizer(struct ceph_auth_client *ac,
101 int peer_type,
102 struct ceph_auth_handshake *auth);
103extern void ceph_auth_destroy_authorizer(struct ceph_auth_client *ac,
104 struct ceph_authorizer *a);
105extern int ceph_auth_update_authorizer(struct ceph_auth_client *ac,
106 int peer_type,
107 struct ceph_auth_handshake *a);
108extern int ceph_auth_verify_authorizer_reply(struct ceph_auth_client *ac,
109 struct ceph_authorizer *a,
110 size_t len);
111extern void ceph_auth_invalidate_authorizer(struct ceph_auth_client *ac,
112 int peer_type);
100 113
101#endif 114#endif
diff --git a/net/ceph/auth.c b/net/ceph/auth.c
index b4bf4ac090f1..a22de543cedb 100644
--- a/net/ceph/auth.c
+++ b/net/ceph/auth.c
@@ -257,3 +257,50 @@ int ceph_auth_is_authenticated(struct ceph_auth_client *ac)
257 return 0; 257 return 0;
258 return ac->ops->is_authenticated(ac); 258 return ac->ops->is_authenticated(ac);
259} 259}
260EXPORT_SYMBOL(ceph_auth_is_authenticated);
261
262int ceph_auth_create_authorizer(struct ceph_auth_client *ac,
263 int peer_type,
264 struct ceph_auth_handshake *auth)
265{
266 if (ac->ops && ac->ops->create_authorizer)
267 return ac->ops->create_authorizer(ac, peer_type, auth);
268 return 0;
269}
270EXPORT_SYMBOL(ceph_auth_create_authorizer);
271
272void ceph_auth_destroy_authorizer(struct ceph_auth_client *ac,
273 struct ceph_authorizer *a)
274{
275 if (ac->ops && ac->ops->destroy_authorizer)
276 ac->ops->destroy_authorizer(ac, a);
277}
278EXPORT_SYMBOL(ceph_auth_destroy_authorizer);
279
280int ceph_auth_update_authorizer(struct ceph_auth_client *ac,
281 int peer_type,
282 struct ceph_auth_handshake *a)
283{
284 int ret = 0;
285
286 if (ac->ops && ac->ops->update_authorizer)
287 ret = ac->ops->update_authorizer(ac, peer_type, a);
288 return ret;
289}
290EXPORT_SYMBOL(ceph_auth_update_authorizer);
291
292int ceph_auth_verify_authorizer_reply(struct ceph_auth_client *ac,
293 struct ceph_authorizer *a, size_t len)
294{
295 if (ac->ops && ac->ops->verify_authorizer_reply)
296 return ac->ops->verify_authorizer_reply(ac, a, len);
297 return 0;
298}
299EXPORT_SYMBOL(ceph_auth_verify_authorizer_reply);
300
301void ceph_auth_invalidate_authorizer(struct ceph_auth_client *ac, int peer_type)
302{
303 if (ac->ops && ac->ops->invalidate_authorizer)
304 ac->ops->invalidate_authorizer(ac, peer_type);
305}
306EXPORT_SYMBOL(ceph_auth_invalidate_authorizer);
diff --git a/net/ceph/auth_x.c b/net/ceph/auth_x.c
index 2d5981555cd6..96238ba95f2b 100644
--- a/net/ceph/auth_x.c
+++ b/net/ceph/auth_x.c
@@ -562,7 +562,6 @@ static int ceph_x_update_authorizer(
562{ 562{
563 struct ceph_x_authorizer *au; 563 struct ceph_x_authorizer *au;
564 struct ceph_x_ticket_handler *th; 564 struct ceph_x_ticket_handler *th;
565 int ret;
566 565
567 th = get_ticket_handler(ac, peer_type); 566 th = get_ticket_handler(ac, peer_type);
568 if (IS_ERR(th)) 567 if (IS_ERR(th))
diff --git a/net/ceph/mon_client.c b/net/ceph/mon_client.c
index aef5b1062bee..1fe25cd29d0e 100644
--- a/net/ceph/mon_client.c
+++ b/net/ceph/mon_client.c
@@ -737,7 +737,7 @@ static void delayed_work(struct work_struct *work)
737 737
738 __validate_auth(monc); 738 __validate_auth(monc);
739 739
740 if (monc->auth->ops->is_authenticated(monc->auth)) 740 if (ceph_auth_is_authenticated(monc->auth))
741 __send_subscribe(monc); 741 __send_subscribe(monc);
742 } 742 }
743 __schedule_delayed(monc); 743 __schedule_delayed(monc);
@@ -892,8 +892,7 @@ static void handle_auth_reply(struct ceph_mon_client *monc,
892 892
893 mutex_lock(&monc->mutex); 893 mutex_lock(&monc->mutex);
894 had_debugfs_info = have_debugfs_info(monc); 894 had_debugfs_info = have_debugfs_info(monc);
895 if (monc->auth->ops) 895 was_auth = ceph_auth_is_authenticated(monc->auth);
896 was_auth = monc->auth->ops->is_authenticated(monc->auth);
897 monc->pending_auth = 0; 896 monc->pending_auth = 0;
898 ret = ceph_handle_auth_reply(monc->auth, msg->front.iov_base, 897 ret = ceph_handle_auth_reply(monc->auth, msg->front.iov_base,
899 msg->front.iov_len, 898 msg->front.iov_len,
@@ -904,7 +903,7 @@ static void handle_auth_reply(struct ceph_mon_client *monc,
904 wake_up_all(&monc->client->auth_wq); 903 wake_up_all(&monc->client->auth_wq);
905 } else if (ret > 0) { 904 } else if (ret > 0) {
906 __send_prepared_auth_request(monc, ret); 905 __send_prepared_auth_request(monc, ret);
907 } else if (!was_auth && monc->auth->ops->is_authenticated(monc->auth)) { 906 } else if (!was_auth && ceph_auth_is_authenticated(monc->auth)) {
908 dout("authenticated, starting session\n"); 907 dout("authenticated, starting session\n");
909 908
910 monc->client->msgr.inst.name.type = CEPH_ENTITY_TYPE_CLIENT; 909 monc->client->msgr.inst.name.type = CEPH_ENTITY_TYPE_CLIENT;
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 5ef24e3e1627..7041906a55a6 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -666,8 +666,7 @@ static void put_osd(struct ceph_osd *osd)
666 if (atomic_dec_and_test(&osd->o_ref) && osd->o_auth.authorizer) { 666 if (atomic_dec_and_test(&osd->o_ref) && osd->o_auth.authorizer) {
667 struct ceph_auth_client *ac = osd->o_osdc->client->monc.auth; 667 struct ceph_auth_client *ac = osd->o_osdc->client->monc.auth;
668 668
669 if (ac->ops && ac->ops->destroy_authorizer) 669 ceph_auth_destroy_authorizer(ac, osd->o_auth.authorizer);
670 ac->ops->destroy_authorizer(ac, osd->o_auth.authorizer);
671 kfree(osd); 670 kfree(osd);
672 } 671 }
673} 672}
@@ -2211,17 +2210,16 @@ static struct ceph_auth_handshake *get_authorizer(struct ceph_connection *con,
2211 struct ceph_auth_handshake *auth = &o->o_auth; 2210 struct ceph_auth_handshake *auth = &o->o_auth;
2212 2211
2213 if (force_new && auth->authorizer) { 2212 if (force_new && auth->authorizer) {
2214 if (ac->ops && ac->ops->destroy_authorizer) 2213 ceph_auth_destroy_authorizer(ac, auth->authorizer);
2215 ac->ops->destroy_authorizer(ac, auth->authorizer);
2216 auth->authorizer = NULL; 2214 auth->authorizer = NULL;
2217 } 2215 }
2218 if (!auth->authorizer && ac->ops && ac->ops->create_authorizer) { 2216 if (!auth->authorizer) {
2219 int ret = ac->ops->create_authorizer(ac, CEPH_ENTITY_TYPE_OSD, 2217 int ret = ceph_auth_create_authorizer(ac, CEPH_ENTITY_TYPE_OSD,
2220 auth); 2218 auth);
2221 if (ret) 2219 if (ret)
2222 return ERR_PTR(ret); 2220 return ERR_PTR(ret);
2223 } else if (ac->ops && ac->ops->update_authorizer) { 2221 } else {
2224 int ret = ac->ops->update_authorizer(ac, CEPH_ENTITY_TYPE_OSD, 2222 int ret = ceph_auth_update_authorizer(ac, CEPH_ENTITY_TYPE_OSD,
2225 auth); 2223 auth);
2226 if (ret) 2224 if (ret)
2227 return ERR_PTR(ret); 2225 return ERR_PTR(ret);
@@ -2238,11 +2236,7 @@ static int verify_authorizer_reply(struct ceph_connection *con, int len)
2238 struct ceph_osd_client *osdc = o->o_osdc; 2236 struct ceph_osd_client *osdc = o->o_osdc;
2239 struct ceph_auth_client *ac = osdc->client->monc.auth; 2237 struct ceph_auth_client *ac = osdc->client->monc.auth;
2240 2238
2241 /* 2239 return ceph_auth_verify_authorizer_reply(ac, o->o_auth.authorizer, len);
2242 * XXX If ac->ops or ac->ops->verify_authorizer_reply is null,
2243 * XXX which do we do: succeed or fail?
2244 */
2245 return ac->ops->verify_authorizer_reply(ac, o->o_auth.authorizer, len);
2246} 2240}
2247 2241
2248static int invalidate_authorizer(struct ceph_connection *con) 2242static int invalidate_authorizer(struct ceph_connection *con)
@@ -2251,9 +2245,7 @@ static int invalidate_authorizer(struct ceph_connection *con)
2251 struct ceph_osd_client *osdc = o->o_osdc; 2245 struct ceph_osd_client *osdc = o->o_osdc;
2252 struct ceph_auth_client *ac = osdc->client->monc.auth; 2246 struct ceph_auth_client *ac = osdc->client->monc.auth;
2253 2247
2254 if (ac->ops && ac->ops->invalidate_authorizer) 2248 ceph_auth_invalidate_authorizer(ac, CEPH_ENTITY_TYPE_OSD);
2255 ac->ops->invalidate_authorizer(ac, CEPH_ENTITY_TYPE_OSD);
2256
2257 return ceph_monc_validate_auth(&osdc->client->monc); 2249 return ceph_monc_validate_auth(&osdc->client->monc);
2258} 2250}
2259 2251