| .. | .. |
|---|
| 39 | 39 | /* |
|---|
| 40 | 40 | * Decode a monmap blob (e.g., during mount). |
|---|
| 41 | 41 | */ |
|---|
| 42 | | -struct ceph_monmap *ceph_monmap_decode(void *p, void *end) |
|---|
| 42 | +static struct ceph_monmap *ceph_monmap_decode(void *p, void *end) |
|---|
| 43 | 43 | { |
|---|
| 44 | 44 | struct ceph_monmap *m = NULL; |
|---|
| 45 | 45 | int i, err = -EINVAL; |
|---|
| .. | .. |
|---|
| 50 | 50 | ceph_decode_32_safe(&p, end, len, bad); |
|---|
| 51 | 51 | ceph_decode_need(&p, end, len, bad); |
|---|
| 52 | 52 | |
|---|
| 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)); |
|---|
| 54 | 54 | p += sizeof(u16); /* skip version */ |
|---|
| 55 | 55 | |
|---|
| 56 | 56 | ceph_decode_need(&p, end, sizeof(fsid) + 2*sizeof(u32), bad); |
|---|
| .. | .. |
|---|
| 58 | 58 | epoch = ceph_decode_32(&p); |
|---|
| 59 | 59 | |
|---|
| 60 | 60 | num_mon = ceph_decode_32(&p); |
|---|
| 61 | | - ceph_decode_need(&p, end, num_mon*sizeof(m->mon_inst[0]), bad); |
|---|
| 62 | 61 | |
|---|
| 63 | 62 | if (num_mon > CEPH_MAX_MON) |
|---|
| 64 | 63 | goto bad; |
|---|
| .. | .. |
|---|
| 68 | 67 | m->fsid = fsid; |
|---|
| 69 | 68 | m->epoch = epoch; |
|---|
| 70 | 69 | 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]; |
|---|
| 74 | 72 | |
|---|
| 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 | + } |
|---|
| 75 | 80 | dout("monmap_decode epoch %d, num_mon %d\n", m->epoch, |
|---|
| 76 | 81 | m->num_mon); |
|---|
| 77 | 82 | for (i = 0; i < m->num_mon; i++) |
|---|
| 78 | 83 | 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)); |
|---|
| 80 | 85 | return m; |
|---|
| 81 | | - |
|---|
| 82 | 86 | bad: |
|---|
| 83 | 87 | dout("monmap_decode failed with %d\n", err); |
|---|
| 84 | 88 | kfree(m); |
|---|
| .. | .. |
|---|
| 203 | 207 | { |
|---|
| 204 | 208 | if (!monc->hunting) |
|---|
| 205 | 209 | 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)); |
|---|
| 207 | 211 | |
|---|
| 208 | 212 | __close_session(monc); |
|---|
| 209 | 213 | __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); |
|---|
| 210 | 221 | } |
|---|
| 211 | 222 | |
|---|
| 212 | 223 | static void un_backoff(struct ceph_mon_client *monc) |
|---|
| .. | .. |
|---|
| 456 | 467 | struct ceph_msg *msg) |
|---|
| 457 | 468 | { |
|---|
| 458 | 469 | struct ceph_client *client = monc->client; |
|---|
| 459 | | - struct ceph_monmap *monmap = NULL, *old = monc->monmap; |
|---|
| 470 | + struct ceph_monmap *monmap; |
|---|
| 460 | 471 | void *p, *end; |
|---|
| 461 | 472 | |
|---|
| 462 | 473 | mutex_lock(&monc->mutex); |
|---|
| .. | .. |
|---|
| 469 | 480 | if (IS_ERR(monmap)) { |
|---|
| 470 | 481 | pr_err("problem decoding monmap, %d\n", |
|---|
| 471 | 482 | (int)PTR_ERR(monmap)); |
|---|
| 483 | + ceph_msg_dump(msg); |
|---|
| 472 | 484 | goto out; |
|---|
| 473 | 485 | } |
|---|
| 474 | 486 | |
|---|
| 475 | | - if (ceph_check_fsid(monc->client, &monmap->fsid) < 0) { |
|---|
| 487 | + if (ceph_check_fsid(client, &monmap->fsid) < 0) { |
|---|
| 476 | 488 | kfree(monmap); |
|---|
| 477 | 489 | goto out; |
|---|
| 478 | 490 | } |
|---|
| 479 | 491 | |
|---|
| 480 | | - client->monc.monmap = monmap; |
|---|
| 481 | | - kfree(old); |
|---|
| 492 | + kfree(monc->monmap); |
|---|
| 493 | + monc->monmap = monmap; |
|---|
| 482 | 494 | |
|---|
| 483 | 495 | __ceph_monc_got_map(monc, CEPH_SUB_MONMAP, monc->monmap->epoch); |
|---|
| 484 | 496 | client->have_fsid = true; |
|---|
| .. | .. |
|---|
| 884 | 896 | ceph_msg_dump(msg); |
|---|
| 885 | 897 | } |
|---|
| 886 | 898 | |
|---|
| 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) |
|---|
| 889 | 902 | { |
|---|
| 890 | 903 | struct ceph_mon_generic_request *req; |
|---|
| 891 | 904 | struct ceph_mon_command *h; |
|---|
| .. | .. |
|---|
| 913 | 926 | h->monhdr.session_mon_tid = 0; |
|---|
| 914 | 927 | h->fsid = monc->monmap->fsid; |
|---|
| 915 | 928 | 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); |
|---|
| 920 | 930 | h->str_len = cpu_to_le32(len); |
|---|
| 921 | 931 | send_generic_request(monc, req); |
|---|
| 922 | 932 | mutex_unlock(&monc->mutex); |
|---|
| 923 | 933 | |
|---|
| 924 | 934 | 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 | | - |
|---|
| 934 | 935 | out: |
|---|
| 935 | 936 | put_generic_request(req); |
|---|
| 936 | 937 | return ret; |
|---|
| 937 | 938 | } |
|---|
| 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); |
|---|
| 939 | 988 | |
|---|
| 940 | 989 | /* |
|---|
| 941 | 990 | * Resend pending generic requests. |
|---|
| .. | .. |
|---|
| 1178 | 1227 | __resend_generic_request(monc); |
|---|
| 1179 | 1228 | |
|---|
| 1180 | 1229 | 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)); |
|---|
| 1182 | 1231 | } |
|---|
| 1183 | 1232 | |
|---|
| 1184 | 1233 | out: |
|---|
| .. | .. |
|---|
| 1220 | 1269 | { |
|---|
| 1221 | 1270 | struct ceph_mon_client *monc = con->private; |
|---|
| 1222 | 1271 | int type = le16_to_cpu(msg->hdr.type); |
|---|
| 1223 | | - |
|---|
| 1224 | | - if (!monc) |
|---|
| 1225 | | - return; |
|---|
| 1226 | 1272 | |
|---|
| 1227 | 1273 | switch (type) { |
|---|
| 1228 | 1274 | case CEPH_MSG_AUTH_REPLY: |
|---|
| .. | .. |
|---|
| 1298 | 1344 | * request had a non-zero tid. Work around this weirdness |
|---|
| 1299 | 1345 | * by allocating a new message. |
|---|
| 1300 | 1346 | */ |
|---|
| 1301 | | - /* fall through */ |
|---|
| 1347 | + fallthrough; |
|---|
| 1302 | 1348 | case CEPH_MSG_MON_MAP: |
|---|
| 1303 | 1349 | case CEPH_MSG_MDS_MAP: |
|---|
| 1304 | 1350 | case CEPH_MSG_OSD_MAP: |
|---|