History

libceph: mon_get_version request infrastructure

Add support for mon_get_version requests to libceph. This reuses much of the ceph_mon_generic_request infrastructure, with one exception. Older OSDs don't set mon_get_version reply hdr->tid even if the original request had a non-zero tid, which makes it impossible to lookup ceph_mon_generic_request contexts by tid in get_generic_reply() for such replies. As a workaround, we allocate a reply message on the reply path. This can probably interfere with revoke, but I don't see a better way.

Ilya Dryomov committed 12 years ago

Commit 513a8241 parent 002b36b4 files · +128 −8Browse files

Unified · Split

4 files
  1. include/linux/ceph/mon_client.h +6 −3
  2. net/ceph/ceph_common.c +2 −0
  3. net/ceph/debugfs.c +2 −0
  4. net/ceph/mon_client.c +118 −5
include/linux/ceph/mon_client.h+6−3
@@ -40,9 +40,9 @@ struct ceph_mon_request { · 39 unmodified lines
4040 };
4141
4242 /*
43− * ceph_mon_generic_request is being used for the statfs and poolop requests
44− * which are bening done a bit differently because we need to get data back
45− * to the caller
43+ * ceph_mon_generic_request is being used for the statfs, poolop and
44+ * mon_get_version requests which are being done a bit differently
45+ * because we need to get data back to the caller
4646 */
4747 struct ceph_mon_generic_request {
4848 struct kref kref;
@@ -108,6 +108,9 @@ extern void ceph_monc_request_next_osdmap(struct ceph_mon_client *monc); · 59 unmodified lines
108108 extern int ceph_monc_do_statfs(struct ceph_mon_client *monc,
109109 struct ceph_statfs *buf);
110110
111+extern int ceph_monc_do_get_version(struct ceph_mon_client *monc,
112+ const char *what, u64 *newest);
113+
111114 extern int ceph_monc_open_session(struct ceph_mon_client *monc);
112115
113116 extern int ceph_monc_validate_auth(struct ceph_mon_client *monc);
net/ceph/ceph_common.c+2−0
@@ -72,6 +72,8 @@ const char *ceph_msg_type_name(int type) · 71 unmodified lines
7272 case CEPH_MSG_MON_SUBSCRIBE_ACK: return "mon_subscribe_ack";
7373 case CEPH_MSG_STATFS: return "statfs";
7474 case CEPH_MSG_STATFS_REPLY: return "statfs_reply";
75+ case CEPH_MSG_MON_GET_VERSION: return "mon_get_version";
76+ case CEPH_MSG_MON_GET_VERSION_REPLY: return "mon_get_version_reply";
7577 case CEPH_MSG_MDS_MAP: return "mds_map";
7678 case CEPH_MSG_CLIENT_SESSION: return "client_session";
7779 case CEPH_MSG_CLIENT_RECONNECT: return "client_reconnect";
net/ceph/debugfs.c+2−0
@@ -129,6 +129,8 @@ static int monc_show(struct seq_file *s, void *p) · 128 unmodified lines
129129 seq_printf(s, "%llu statfs\n", req->tid);
130130 else if (op == CEPH_MSG_POOLOP)
131131 seq_printf(s, "%llu poolop\n", req->tid);
132+ else if (op == CEPH_MSG_MON_GET_VERSION)
133+ seq_printf(s, "%llu mon_get_version", req->tid);
132134 else
133135 seq_printf(s, "%llu unknown\n", req->tid);
134136 }
net/ceph/mon_client.c+118−5
@@ -477,14 +477,13 @@ static struct ceph_msg *get_generic_reply(struct ceph_connection *con, · 476 unmodified lines
477477 return m;
478478 }
479479
480−static int do_generic_request(struct ceph_mon_client *monc,
481− struct ceph_mon_generic_request *req)
480+static int __do_generic_request(struct ceph_mon_client *monc, u64 tid,
481+ struct ceph_mon_generic_request *req)
482482 {
483483 int err;
484484
485485 /* register request */
486− mutex_lock(&monc->mutex);
487− req->tid = ++monc->last_tid;
486+ req->tid = tid != 0 ? tid : ++monc->last_tid;
488487 req->request->hdr.tid = cpu_to_le64(req->tid);
489488 __insert_generic_request(monc, req);
490489 monc->num_generic_requests++;
@@ -496,13 +495,24 @@ static int do_generic_request(struct ceph_mon_client *monc, · 5 unmodified lines
496495 mutex_lock(&monc->mutex);
497496 rb_erase(&req->node, &monc->generic_request_tree);
498497 monc->num_generic_requests--;
499− mutex_unlock(&monc->mutex);
500498
501499 if (!err)
502500 err = req->result;
503501 return err;
504502 }
505503
504+static int do_generic_request(struct ceph_mon_client *monc,
505+ struct ceph_mon_generic_request *req)
506+{
507+ int err;
508+
509+ mutex_lock(&monc->mutex);
510+ err = __do_generic_request(monc, 0, req);
511+ mutex_unlock(&monc->mutex);
512+
513+ return err;
514+}
515+
506516 /*
507517 * statfs
508518 */
@@ -579,6 +589,96 @@ out: · 70 unmodified lines
579589 }
580590 EXPORT_SYMBOL(ceph_monc_do_statfs);
581591
592+static void handle_get_version_reply(struct ceph_mon_client *monc,
593+ struct ceph_msg *msg)
594+{
595+ struct ceph_mon_generic_request *req;
596+ u64 tid = le64_to_cpu(msg->hdr.tid);
597+ void *p = msg->front.iov_base;
598+ void *end = p + msg->front_alloc_len;
599+ u64 handle;
600+
601+ dout("%s %p tid %llu\n", __func__, msg, tid);
602+
603+ ceph_decode_need(&p, end, 2*sizeof(u64), bad);
604+ handle = ceph_decode_64(&p);
605+ if (tid != 0 && tid != handle)
606+ goto bad;
607+
608+ mutex_lock(&monc->mutex);
609+ req = __lookup_generic_req(monc, handle);
610+ if (req) {
611+ *(u64 *)req->buf = ceph_decode_64(&p);
612+ req->result = 0;
613+ get_generic_request(req);
614+ }
615+ mutex_unlock(&monc->mutex);
616+ if (req) {
617+ complete_all(&req->completion);
618+ put_generic_request(req);
619+ }
620+
621+ return;
622+bad:
623+ pr_err("corrupt mon_get_version reply\n");
624+ ceph_msg_dump(msg);
625+}
626+
627+/*
628+ * Send MMonGetVersion and wait for the reply.
629+ *
630+ * @what: one of "mdsmap", "osdmap" or "monmap"
631+ */
632+int ceph_monc_do_get_version(struct ceph_mon_client *monc, const char *what,
633+ u64 *newest)
634+{
635+ struct ceph_mon_generic_request *req;
636+ void *p, *end;
637+ u64 tid;
638+ int err;
639+
640+ req = kzalloc(sizeof(*req), GFP_NOFS);
641+ if (!req)
642+ return -ENOMEM;
643+
644+ kref_init(&req->kref);
645+ req->buf = newest;
646+ req->buf_len = sizeof(*newest);
647+ init_completion(&req->completion);
648+
649+ req->request = ceph_msg_new(CEPH_MSG_MON_GET_VERSION,
650+ sizeof(u64) + sizeof(u32) + strlen(what),
651+ GFP_NOFS, true);
652+ if (!req->request) {
653+ err = -ENOMEM;
654+ goto out;
655+ }
656+
657+ req->reply = ceph_msg_new(CEPH_MSG_MON_GET_VERSION_REPLY, 1024,
658+ GFP_NOFS, true);
659+ if (!req->reply) {
660+ err = -ENOMEM;
661+ goto out;
662+ }
663+
664+ p = req->request->front.iov_base;
665+ end = p + req->request->front_alloc_len;
666+
667+ /* fill out request */
668+ mutex_lock(&monc->mutex);
669+ tid = ++monc->last_tid;
670+ ceph_encode_64(&p, tid); /* handle */
671+ ceph_encode_string(&p, end, what, strlen(what));
672+
673+ err = __do_generic_request(monc, tid, req);
674+
675+ mutex_unlock(&monc->mutex);
676+out:
677+ kref_put(&req->kref, release_generic_request);
678+ return err;
679+}
680+EXPORT_SYMBOL(ceph_monc_do_get_version);
681+
582682 /*
583683 * pool ops
584684 */
@@ -981,6 +1081,10 @@ static void dispatch(struct ceph_connection *con, struct ceph_msg *msg) · 396 unmodified lines
9811081 handle_statfs_reply(monc, msg);
9821082 break;
9831083
1084+ case CEPH_MSG_MON_GET_VERSION_REPLY:
1085+ handle_get_version_reply(monc, msg);
1086+ break;
1087+
9841088 case CEPH_MSG_POOLOP_REPLY:
9851089 handle_poolop_reply(monc, msg);
9861090 break;
@@ -1029,6 +1133,15 @@ static struct ceph_msg *mon_alloc_msg(struct ceph_connection *con, · 42 unmodified lines
10291133 case CEPH_MSG_AUTH_REPLY:
10301134 m = ceph_msg_get(monc->m_auth_reply);
10311135 break;
1136+ case CEPH_MSG_MON_GET_VERSION_REPLY:
1137+ if (le64_to_cpu(hdr->tid) != 0)
1138+ return get_generic_reply(con, hdr, skip);
1139+
1140+ /*
1141+ * Older OSDs don't set reply tid even if the orignal
1142+ * request had a non-zero tid. Workaround this weirdness
1143+ * by falling through to the allocate case.
1144+ */
10321145 case CEPH_MSG_MON_MAP:
10331146 case CEPH_MSG_MDS_MAP:
10341147 case CEPH_MSG_OSD_MAP:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t