forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
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);
....@@ -203,10 +207,17 @@
203207 {
204208 if (!monc->hunting)
205209 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));
210
+ monc->cur_mon, ceph_pr_addr(&monc->con.peer_addr));
207211
208212 __close_session(monc);
209213 __open_session(monc);
214
+}
215
+
216
+void ceph_monc_reopen_session(struct ceph_mon_client *monc)
217
+{
218
+ mutex_lock(&monc->mutex);
219
+ reopen_session(monc);
220
+ mutex_unlock(&monc->mutex);
210221 }
211222
212223 static void un_backoff(struct ceph_mon_client *monc)
....@@ -456,7 +467,7 @@
456467 struct ceph_msg *msg)
457468 {
458469 struct ceph_client *client = monc->client;
459
- struct ceph_monmap *monmap = NULL, *old = monc->monmap;
470
+ struct ceph_monmap *monmap;
460471 void *p, *end;
461472
462473 mutex_lock(&monc->mutex);
....@@ -469,16 +480,17 @@
469480 if (IS_ERR(monmap)) {
470481 pr_err("problem decoding monmap, %d\n",
471482 (int)PTR_ERR(monmap));
483
+ ceph_msg_dump(msg);
472484 goto out;
473485 }
474486
475
- if (ceph_check_fsid(monc->client, &monmap->fsid) < 0) {
487
+ if (ceph_check_fsid(client, &monmap->fsid) < 0) {
476488 kfree(monmap);
477489 goto out;
478490 }
479491
480
- client->monc.monmap = monmap;
481
- kfree(old);
492
+ kfree(monc->monmap);
493
+ monc->monmap = monmap;
482494
483495 __ceph_monc_got_map(monc, CEPH_SUB_MONMAP, monc->monmap->epoch);
484496 client->have_fsid = true;
....@@ -884,8 +896,9 @@
884896 ceph_msg_dump(msg);
885897 }
886898
887
-int ceph_monc_blacklist_add(struct ceph_mon_client *monc,
888
- struct ceph_entity_addr *client_addr)
899
+static __printf(2, 0)
900
+int do_mon_command_vargs(struct ceph_mon_client *monc, const char *fmt,
901
+ va_list ap)
889902 {
890903 struct ceph_mon_generic_request *req;
891904 struct ceph_mon_command *h;
....@@ -913,29 +926,65 @@
913926 h->monhdr.session_mon_tid = 0;
914927 h->fsid = monc->monmap->fsid;
915928 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));
929
+ len = vsprintf(h->str, fmt, ap);
920930 h->str_len = cpu_to_le32(len);
921931 send_generic_request(monc, req);
922932 mutex_unlock(&monc->mutex);
923933
924934 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
-
934935 out:
935936 put_generic_request(req);
936937 return ret;
937938 }
938
-EXPORT_SYMBOL(ceph_monc_blacklist_add);
939
+
940
+static __printf(2, 3)
941
+int do_mon_command(struct ceph_mon_client *monc, const char *fmt, ...)
942
+{
943
+ va_list ap;
944
+ int ret;
945
+
946
+ va_start(ap, fmt);
947
+ ret = do_mon_command_vargs(monc, fmt, ap);
948
+ va_end(ap);
949
+ return ret;
950
+}
951
+
952
+int ceph_monc_blocklist_add(struct ceph_mon_client *monc,
953
+ struct ceph_entity_addr *client_addr)
954
+{
955
+ int ret;
956
+
957
+ ret = do_mon_command(monc,
958
+ "{ \"prefix\": \"osd blocklist\", \
959
+ \"blocklistop\": \"add\", \
960
+ \"addr\": \"%pISpc/%u\" }",
961
+ &client_addr->in_addr,
962
+ le32_to_cpu(client_addr->nonce));
963
+ if (ret == -EINVAL) {
964
+ /*
965
+ * The monitor returns EINVAL on an unrecognized command.
966
+ * Try the legacy command -- it is exactly the same except
967
+ * for the name.
968
+ */
969
+ ret = do_mon_command(monc,
970
+ "{ \"prefix\": \"osd blacklist\", \
971
+ \"blacklistop\": \"add\", \
972
+ \"addr\": \"%pISpc/%u\" }",
973
+ &client_addr->in_addr,
974
+ le32_to_cpu(client_addr->nonce));
975
+ }
976
+ if (ret)
977
+ return ret;
978
+
979
+ /*
980
+ * Make sure we have the osdmap that includes the blocklist
981
+ * entry. This is needed to ensure that the OSDs pick up the
982
+ * new blocklist before processing any future requests from
983
+ * this client.
984
+ */
985
+ return ceph_wait_for_latest_osdmap(monc->client, 0);
986
+}
987
+EXPORT_SYMBOL(ceph_monc_blocklist_add);
939988
940989 /*
941990 * Resend pending generic requests.
....@@ -1178,7 +1227,7 @@
11781227 __resend_generic_request(monc);
11791228
11801229 pr_info("mon%d %s session established\n", monc->cur_mon,
1181
- ceph_pr_addr(&monc->con.peer_addr.in_addr));
1230
+ ceph_pr_addr(&monc->con.peer_addr));
11821231 }
11831232
11841233 out:
....@@ -1220,9 +1269,6 @@
12201269 {
12211270 struct ceph_mon_client *monc = con->private;
12221271 int type = le16_to_cpu(msg->hdr.type);
1223
-
1224
- if (!monc)
1225
- return;
12261272
12271273 switch (type) {
12281274 case CEPH_MSG_AUTH_REPLY:
....@@ -1298,7 +1344,7 @@
12981344 * request had a non-zero tid. Work around this weirdness
12991345 * by allocating a new message.
13001346 */
1301
- /* fall through */
1347
+ fallthrough;
13021348 case CEPH_MSG_MON_MAP:
13031349 case CEPH_MSG_MDS_MAP:
13041350 case CEPH_MSG_OSD_MAP: