hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/net/ceph/mon_client.c
....@@ -39,7 +39,7 @@
3939 /*
4040 * Decode a monmap blob (e.g., during mount).
4141 */
42
-struct ceph_monmap *ceph_monmap_decode(void *p, void *end)
42
+static struct ceph_monmap *ceph_monmap_decode(void *p, void *end)
4343 {
4444 struct ceph_monmap *m = NULL;
4545 int i, err = -EINVAL;
....@@ -50,7 +50,7 @@
5050 ceph_decode_32_safe(&p, end, len, bad);
5151 ceph_decode_need(&p, end, len, bad);
5252
53
- dout("monmap_decode %p %p len %d\n", p, end, (int)(end-p));
53
+ dout("monmap_decode %p %p len %d (%d)\n", p, end, len, (int)(end-p));
5454 p += sizeof(u16); /* skip version */
5555
5656 ceph_decode_need(&p, end, sizeof(fsid) + 2*sizeof(u32), bad);
....@@ -58,7 +58,6 @@
5858 epoch = ceph_decode_32(&p);
5959
6060 num_mon = ceph_decode_32(&p);
61
- ceph_decode_need(&p, end, num_mon*sizeof(m->mon_inst[0]), bad);
6261
6362 if (num_mon > CEPH_MAX_MON)
6463 goto bad;
....@@ -68,17 +67,22 @@
6867 m->fsid = fsid;
6968 m->epoch = epoch;
7069 m->num_mon = num_mon;
71
- ceph_decode_copy(&p, m->mon_inst, num_mon*sizeof(m->mon_inst[0]));
72
- for (i = 0; i < num_mon; i++)
73
- ceph_decode_addr(&m->mon_inst[i].addr);
70
+ for (i = 0; i < num_mon; ++i) {
71
+ struct ceph_entity_inst *inst = &m->mon_inst[i];
7472
73
+ /* copy name portion */
74
+ ceph_decode_copy_safe(&p, end, &inst->name,
75
+ sizeof(inst->name), bad);
76
+ err = ceph_decode_entity_addr(&p, end, &inst->addr);
77
+ if (err)
78
+ goto bad;
79
+ }
7580 dout("monmap_decode epoch %d, num_mon %d\n", m->epoch,
7681 m->num_mon);
7782 for (i = 0; i < m->num_mon; i++)
7883 dout("monmap_decode mon%d is %s\n", i,
79
- ceph_pr_addr(&m->mon_inst[i].addr.in_addr));
84
+ ceph_pr_addr(&m->mon_inst[i].addr));
8085 return m;
81
-
8286 bad:
8387 dout("monmap_decode failed with %d\n", err);
8488 kfree(m);
....@@ -92,9 +96,11 @@
9296 {
9397 int i;
9498
95
- for (i = 0; i < m->num_mon; i++)
96
- if (memcmp(addr, &m->mon_inst[i].addr, sizeof(*addr)) == 0)
99
+ for (i = 0; i < m->num_mon; i++) {
100
+ if (ceph_addr_equal_no_type(addr, &m->mon_inst[i].addr))
97101 return 1;
102
+ }
103
+
98104 return 0;
99105 }
100106
....@@ -203,10 +209,17 @@
203209 {
204210 if (!monc->hunting)
205211 pr_info("mon%d %s session lost, hunting for new mon\n",
206
- monc->cur_mon, ceph_pr_addr(&monc->con.peer_addr.in_addr));
212
+ monc->cur_mon, ceph_pr_addr(&monc->con.peer_addr));
207213
208214 __close_session(monc);
209215 __open_session(monc);
216
+}
217
+
218
+void ceph_monc_reopen_session(struct ceph_mon_client *monc)
219
+{
220
+ mutex_lock(&monc->mutex);
221
+ reopen_session(monc);
222
+ mutex_unlock(&monc->mutex);
210223 }
211224
212225 static void un_backoff(struct ceph_mon_client *monc)
....@@ -456,7 +469,7 @@
456469 struct ceph_msg *msg)
457470 {
458471 struct ceph_client *client = monc->client;
459
- struct ceph_monmap *monmap = NULL, *old = monc->monmap;
472
+ struct ceph_monmap *monmap;
460473 void *p, *end;
461474
462475 mutex_lock(&monc->mutex);
....@@ -469,16 +482,17 @@
469482 if (IS_ERR(monmap)) {
470483 pr_err("problem decoding monmap, %d\n",
471484 (int)PTR_ERR(monmap));
485
+ ceph_msg_dump(msg);
472486 goto out;
473487 }
474488
475
- if (ceph_check_fsid(monc->client, &monmap->fsid) < 0) {
489
+ if (ceph_check_fsid(client, &monmap->fsid) < 0) {
476490 kfree(monmap);
477491 goto out;
478492 }
479493
480
- client->monc.monmap = monmap;
481
- kfree(old);
494
+ kfree(monc->monmap);
495
+ monc->monmap = monmap;
482496
483497 __ceph_monc_got_map(monc, CEPH_SUB_MONMAP, monc->monmap->epoch);
484498 client->have_fsid = true;
....@@ -884,8 +898,9 @@
884898 ceph_msg_dump(msg);
885899 }
886900
887
-int ceph_monc_blacklist_add(struct ceph_mon_client *monc,
888
- struct ceph_entity_addr *client_addr)
901
+static __printf(2, 0)
902
+int do_mon_command_vargs(struct ceph_mon_client *monc, const char *fmt,
903
+ va_list ap)
889904 {
890905 struct ceph_mon_generic_request *req;
891906 struct ceph_mon_command *h;
....@@ -913,29 +928,65 @@
913928 h->monhdr.session_mon_tid = 0;
914929 h->fsid = monc->monmap->fsid;
915930 h->num_strs = cpu_to_le32(1);
916
- len = sprintf(h->str, "{ \"prefix\": \"osd blacklist\", \
917
- \"blacklistop\": \"add\", \
918
- \"addr\": \"%pISpc/%u\" }",
919
- &client_addr->in_addr, le32_to_cpu(client_addr->nonce));
931
+ len = vsprintf(h->str, fmt, ap);
920932 h->str_len = cpu_to_le32(len);
921933 send_generic_request(monc, req);
922934 mutex_unlock(&monc->mutex);
923935
924936 ret = wait_generic_request(req);
925
- if (!ret)
926
- /*
927
- * Make sure we have the osdmap that includes the blacklist
928
- * entry. This is needed to ensure that the OSDs pick up the
929
- * new blacklist before processing any future requests from
930
- * this client.
931
- */
932
- ret = ceph_wait_for_latest_osdmap(monc->client, 0);
933
-
934937 out:
935938 put_generic_request(req);
936939 return ret;
937940 }
938
-EXPORT_SYMBOL(ceph_monc_blacklist_add);
941
+
942
+static __printf(2, 3)
943
+int do_mon_command(struct ceph_mon_client *monc, const char *fmt, ...)
944
+{
945
+ va_list ap;
946
+ int ret;
947
+
948
+ va_start(ap, fmt);
949
+ ret = do_mon_command_vargs(monc, fmt, ap);
950
+ va_end(ap);
951
+ return ret;
952
+}
953
+
954
+int ceph_monc_blocklist_add(struct ceph_mon_client *monc,
955
+ struct ceph_entity_addr *client_addr)
956
+{
957
+ int ret;
958
+
959
+ ret = do_mon_command(monc,
960
+ "{ \"prefix\": \"osd blocklist\", \
961
+ \"blocklistop\": \"add\", \
962
+ \"addr\": \"%pISpc/%u\" }",
963
+ &client_addr->in_addr,
964
+ le32_to_cpu(client_addr->nonce));
965
+ if (ret == -EINVAL) {
966
+ /*
967
+ * The monitor returns EINVAL on an unrecognized command.
968
+ * Try the legacy command -- it is exactly the same except
969
+ * for the name.
970
+ */
971
+ ret = do_mon_command(monc,
972
+ "{ \"prefix\": \"osd blacklist\", \
973
+ \"blacklistop\": \"add\", \
974
+ \"addr\": \"%pISpc/%u\" }",
975
+ &client_addr->in_addr,
976
+ le32_to_cpu(client_addr->nonce));
977
+ }
978
+ if (ret)
979
+ return ret;
980
+
981
+ /*
982
+ * Make sure we have the osdmap that includes the blocklist
983
+ * entry. This is needed to ensure that the OSDs pick up the
984
+ * new blocklist before processing any future requests from
985
+ * this client.
986
+ */
987
+ return ceph_wait_for_latest_osdmap(monc->client, 0);
988
+}
989
+EXPORT_SYMBOL(ceph_monc_blocklist_add);
939990
940991 /*
941992 * Resend pending generic requests.
....@@ -1178,7 +1229,7 @@
11781229 __resend_generic_request(monc);
11791230
11801231 pr_info("mon%d %s session established\n", monc->cur_mon,
1181
- ceph_pr_addr(&monc->con.peer_addr.in_addr));
1232
+ ceph_pr_addr(&monc->con.peer_addr));
11821233 }
11831234
11841235 out:
....@@ -1220,9 +1271,6 @@
12201271 {
12211272 struct ceph_mon_client *monc = con->private;
12221273 int type = le16_to_cpu(msg->hdr.type);
1223
-
1224
- if (!monc)
1225
- return;
12261274
12271275 switch (type) {
12281276 case CEPH_MSG_AUTH_REPLY:
....@@ -1298,7 +1346,7 @@
12981346 * request had a non-zero tid. Work around this weirdness
12991347 * by allocating a new message.
13001348 */
1301
- /* fall through */
1349
+ fallthrough;
13021350 case CEPH_MSG_MON_MAP:
13031351 case CEPH_MSG_MDS_MAP:
13041352 case CEPH_MSG_OSD_MAP: