mon_client.c (00498b994113a871a556f7ff24a4cf8a00611700) mon_client.c (cd1a677cad994021b19665ed476aea63f5d54f31)
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/ceph/ceph_debug.h>
3
4#include <linux/module.h>
5#include <linux/types.h>
6#include <linux/slab.h>
7#include <linux/random.h>
8#include <linux/sched.h>

--- 243 unchanged lines hidden (view full) ---

252 monc->sub_renew_after = jiffies; /* i.e., expired */
253 monc->sub_renew_sent = 0;
254
255 dout("%s opening mon%d\n", __func__, monc->cur_mon);
256 ceph_con_open(&monc->con, CEPH_ENTITY_TYPE_MON, monc->cur_mon,
257 &monc->monmap->mon_inst[monc->cur_mon].addr);
258
259 /*
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/ceph/ceph_debug.h>
3
4#include <linux/module.h>
5#include <linux/types.h>
6#include <linux/slab.h>
7#include <linux/random.h>
8#include <linux/sched.h>

--- 243 unchanged lines hidden (view full) ---

252 monc->sub_renew_after = jiffies; /* i.e., expired */
253 monc->sub_renew_sent = 0;
254
255 dout("%s opening mon%d\n", __func__, monc->cur_mon);
256 ceph_con_open(&monc->con, CEPH_ENTITY_TYPE_MON, monc->cur_mon,
257 &monc->monmap->mon_inst[monc->cur_mon].addr);
258
259 /*
260 * send an initial keepalive to ensure our timestamp is valid
261 * by the time we are in an OPENED state
260 * Queue a keepalive to ensure that in case of an early fault
261 * the messenger doesn't put us into STANDBY state and instead
262 * retries. This also ensures that our timestamp is valid by
263 * the time we finish hunting and delayed_work() checks it.
262 */
263 ceph_con_keepalive(&monc->con);
264 */
265 ceph_con_keepalive(&monc->con);
266 if (ceph_msgr2(monc->client)) {
267 monc->pending_auth = 1;
268 return;
269 }
264
265 /* initiate authentication handshake */
266 ret = ceph_auth_build_hello(monc->auth,
267 monc->m_auth->front.iov_base,
268 monc->m_auth->front_alloc_len);
269 BUG_ON(ret <= 0);
270 __send_prepared_auth_request(monc, ret);
271}

--- 266 unchanged lines hidden (view full) ---

538 void *p, *end;
539
540 mutex_lock(&monc->mutex);
541
542 dout("handle_monmap\n");
543 p = msg->front.iov_base;
544 end = p + msg->front.iov_len;
545
270
271 /* initiate authentication handshake */
272 ret = ceph_auth_build_hello(monc->auth,
273 monc->m_auth->front.iov_base,
274 monc->m_auth->front_alloc_len);
275 BUG_ON(ret <= 0);
276 __send_prepared_auth_request(monc, ret);
277}

--- 266 unchanged lines hidden (view full) ---

544 void *p, *end;
545
546 mutex_lock(&monc->mutex);
547
548 dout("handle_monmap\n");
549 p = msg->front.iov_base;
550 end = p + msg->front.iov_len;
551
546 monmap = ceph_monmap_decode(&p, end, false);
552 monmap = ceph_monmap_decode(&p, end, ceph_msgr2(client));
547 if (IS_ERR(monmap)) {
548 pr_err("problem decoding monmap, %d\n",
549 (int)PTR_ERR(monmap));
550 ceph_msg_dump(msg);
551 goto out;
552 }
553
554 if (ceph_check_fsid(client, &monmap->fsid) < 0) {

--- 559 unchanged lines hidden (view full) ---

1114}
1115
1116/*
1117 * On startup, we build a temporary monmap populated with the IPs
1118 * provided by mount(2).
1119 */
1120static int build_initial_monmap(struct ceph_mon_client *monc)
1121{
553 if (IS_ERR(monmap)) {
554 pr_err("problem decoding monmap, %d\n",
555 (int)PTR_ERR(monmap));
556 ceph_msg_dump(msg);
557 goto out;
558 }
559
560 if (ceph_check_fsid(client, &monmap->fsid) < 0) {

--- 559 unchanged lines hidden (view full) ---

1120}
1121
1122/*
1123 * On startup, we build a temporary monmap populated with the IPs
1124 * provided by mount(2).
1125 */
1126static int build_initial_monmap(struct ceph_mon_client *monc)
1127{
1128 __le32 my_type = ceph_msgr2(monc->client) ?
1129 CEPH_ENTITY_ADDR_TYPE_MSGR2 : CEPH_ENTITY_ADDR_TYPE_LEGACY;
1122 struct ceph_options *opt = monc->client->options;
1130 struct ceph_options *opt = monc->client->options;
1123 struct ceph_entity_addr *mon_addr = opt->mon_addr;
1124 int num_mon = opt->num_mon;
1125 int i;
1126
1127 /* build initial monmap */
1128 monc->monmap = kzalloc(struct_size(monc->monmap, mon_inst, num_mon),
1129 GFP_KERNEL);
1130 if (!monc->monmap)
1131 return -ENOMEM;
1131 int num_mon = opt->num_mon;
1132 int i;
1133
1134 /* build initial monmap */
1135 monc->monmap = kzalloc(struct_size(monc->monmap, mon_inst, num_mon),
1136 GFP_KERNEL);
1137 if (!monc->monmap)
1138 return -ENOMEM;
1139
1132 for (i = 0; i < num_mon; i++) {
1140 for (i = 0; i < num_mon; i++) {
1133 monc->monmap->mon_inst[i].addr = mon_addr[i];
1134 monc->monmap->mon_inst[i].addr.nonce = 0;
1135 monc->monmap->mon_inst[i].name.type =
1136 CEPH_ENTITY_TYPE_MON;
1137 monc->monmap->mon_inst[i].name.num = cpu_to_le64(i);
1141 struct ceph_entity_inst *inst = &monc->monmap->mon_inst[i];
1142
1143 memcpy(&inst->addr.in_addr, &opt->mon_addr[i].in_addr,
1144 sizeof(inst->addr.in_addr));
1145 inst->addr.type = my_type;
1146 inst->addr.nonce = 0;
1147 inst->name.type = CEPH_ENTITY_TYPE_MON;
1148 inst->name.num = cpu_to_le64(i);
1138 }
1139 monc->monmap->num_mon = num_mon;
1140 return 0;
1141}
1142
1143int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
1144{
1145 int err = 0;

--- 186 unchanged lines hidden (view full) ---

1332
1333 mutex_lock(&monc->mutex);
1334 ret = __validate_auth(monc);
1335 mutex_unlock(&monc->mutex);
1336 return ret;
1337}
1338EXPORT_SYMBOL(ceph_monc_validate_auth);
1339
1149 }
1150 monc->monmap->num_mon = num_mon;
1151 return 0;
1152}
1153
1154int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
1155{
1156 int err = 0;

--- 186 unchanged lines hidden (view full) ---

1343
1344 mutex_lock(&monc->mutex);
1345 ret = __validate_auth(monc);
1346 mutex_unlock(&monc->mutex);
1347 return ret;
1348}
1349EXPORT_SYMBOL(ceph_monc_validate_auth);
1350
1351static int mon_get_auth_request(struct ceph_connection *con,
1352 void *buf, int *buf_len,
1353 void **authorizer, int *authorizer_len)
1354{
1355 struct ceph_mon_client *monc = con->private;
1356 int ret;
1357
1358 mutex_lock(&monc->mutex);
1359 ret = ceph_auth_get_request(monc->auth, buf, *buf_len);
1360 mutex_unlock(&monc->mutex);
1361 if (ret < 0)
1362 return ret;
1363
1364 *buf_len = ret;
1365 *authorizer = NULL;
1366 *authorizer_len = 0;
1367 return 0;
1368}
1369
1370static int mon_handle_auth_reply_more(struct ceph_connection *con,
1371 void *reply, int reply_len,
1372 void *buf, int *buf_len,
1373 void **authorizer, int *authorizer_len)
1374{
1375 struct ceph_mon_client *monc = con->private;
1376 int ret;
1377
1378 mutex_lock(&monc->mutex);
1379 ret = ceph_auth_handle_reply_more(monc->auth, reply, reply_len,
1380 buf, *buf_len);
1381 mutex_unlock(&monc->mutex);
1382 if (ret < 0)
1383 return ret;
1384
1385 *buf_len = ret;
1386 *authorizer = NULL;
1387 *authorizer_len = 0;
1388 return 0;
1389}
1390
1391static int mon_handle_auth_done(struct ceph_connection *con,
1392 u64 global_id, void *reply, int reply_len,
1393 u8 *session_key, int *session_key_len,
1394 u8 *con_secret, int *con_secret_len)
1395{
1396 struct ceph_mon_client *monc = con->private;
1397 bool was_authed;
1398 int ret;
1399
1400 mutex_lock(&monc->mutex);
1401 WARN_ON(!monc->hunting);
1402 was_authed = ceph_auth_is_authenticated(monc->auth);
1403 ret = ceph_auth_handle_reply_done(monc->auth, global_id,
1404 reply, reply_len,
1405 session_key, session_key_len,
1406 con_secret, con_secret_len);
1407 finish_auth(monc, ret, was_authed);
1408 if (!ret)
1409 finish_hunting(monc);
1410 mutex_unlock(&monc->mutex);
1411 return 0;
1412}
1413
1414static int mon_handle_auth_bad_method(struct ceph_connection *con,
1415 int used_proto, int result,
1416 const int *allowed_protos, int proto_cnt,
1417 const int *allowed_modes, int mode_cnt)
1418{
1419 struct ceph_mon_client *monc = con->private;
1420 bool was_authed;
1421
1422 mutex_lock(&monc->mutex);
1423 WARN_ON(!monc->hunting);
1424 was_authed = ceph_auth_is_authenticated(monc->auth);
1425 ceph_auth_handle_bad_method(monc->auth, used_proto, result,
1426 allowed_protos, proto_cnt,
1427 allowed_modes, mode_cnt);
1428 finish_auth(monc, -EACCES, was_authed);
1429 mutex_unlock(&monc->mutex);
1430 return 0;
1431}
1432
1340/*
1341 * handle incoming message
1342 */
1343static void dispatch(struct ceph_connection *con, struct ceph_msg *msg)
1344{
1345 struct ceph_mon_client *monc = con->private;
1346 int type = le16_to_cpu(msg->hdr.type);
1347

--- 134 unchanged lines hidden (view full) ---

1482}
1483
1484static const struct ceph_connection_operations mon_con_ops = {
1485 .get = con_get,
1486 .put = con_put,
1487 .dispatch = dispatch,
1488 .fault = mon_fault,
1489 .alloc_msg = mon_alloc_msg,
1433/*
1434 * handle incoming message
1435 */
1436static void dispatch(struct ceph_connection *con, struct ceph_msg *msg)
1437{
1438 struct ceph_mon_client *monc = con->private;
1439 int type = le16_to_cpu(msg->hdr.type);
1440

--- 134 unchanged lines hidden (view full) ---

1575}
1576
1577static const struct ceph_connection_operations mon_con_ops = {
1578 .get = con_get,
1579 .put = con_put,
1580 .dispatch = dispatch,
1581 .fault = mon_fault,
1582 .alloc_msg = mon_alloc_msg,
1583 .get_auth_request = mon_get_auth_request,
1584 .handle_auth_reply_more = mon_handle_auth_reply_more,
1585 .handle_auth_done = mon_handle_auth_done,
1586 .handle_auth_bad_method = mon_handle_auth_bad_method,
1490};
1587};