]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: encode connect_seq, minor accept cleanup
authorSage Weil <sage@newdream.net>
Tue, 8 Jan 2008 23:57:27 +0000 (15:57 -0800)
committerSage Weil <sage@newdream.net>
Tue, 8 Jan 2008 23:57:27 +0000 (15:57 -0800)
src/kernel/messenger.c
src/kernel/messenger.h

index cda4a6c3989afc781cfdaf22abbafdb35acd4f2b..8a644a4a2eab5c682cc51725f22877eeb3a87739 100644 (file)
@@ -388,56 +388,49 @@ static void prepare_write_ack(struct ceph_connection *con)
 
        con->out_kvec[0].iov_base = &tag_ack;
        con->out_kvec[0].iov_len = 1;
-       con->out_kvec[1].iov_base = &con->in_seq_acked;
-       con->out_kvec[1].iov_len = sizeof(con->in_seq_acked);
+       con->onwire32 = cpu_to_le32(con->in_seq_acked);
+       con->out_kvec[1].iov_base = &con->onwire32;
+       con->out_kvec[1].iov_len = 4;
        con->out_kvec_left = 2;
-       con->out_kvec_bytes = 1 + sizeof(con->in_seq_acked);
+       con->out_kvec_bytes = 1 + 4;
        con->out_kvec_cur = con->out_kvec;
        set_bit(WRITE_PENDING, &con->state);
 }
 
 static void prepare_write_connect(struct ceph_messenger *msgr, struct ceph_connection *con)
 {
-       con->out_kvec[0].iov_base = &msgr->inst.addr;
-       con->out_kvec[0].iov_len = sizeof(msgr->inst.addr);
-       con->out_kvec[1].iov_base = &con->connect_seq;
-       con->out_kvec[1].iov_len = sizeof(con->connect_seq);
+       ceph_encode_addr(&con->onwire_addr, &msgr->inst.addr);
+       con->out_kvec[0].iov_base = &con->onwire_addr;
+       con->out_kvec[0].iov_len = sizeof(con->onwire_addr);
+       con->onwire32 = cpu_to_le32(con->connect_seq);
+       con->out_kvec[1].iov_base = &con->onwire32;
+       con->out_kvec[1].iov_len = 4;
        con->out_kvec_left = 2;
-       con->out_kvec_bytes = sizeof(msgr->inst.addr) + sizeof(con->connect_seq);
+       con->out_kvec_bytes = sizeof(con->onwire_addr) + 4;
        con->out_kvec_cur = con->out_kvec;
        set_bit(WRITE_PENDING, &con->state);
 }
 
 static void prepare_write_accept_announce(struct ceph_messenger *msgr, struct ceph_connection *con)
 {
-       con->out_kvec[0].iov_base = &msgr->inst.addr;
-       con->out_kvec[0].iov_len = sizeof(msgr->inst.addr);
+       ceph_encode_addr(&con->onwire_addr, &msgr->inst.addr);
+       con->out_kvec[0].iov_base = &con->onwire_addr;
+       con->out_kvec[0].iov_len = sizeof(con->onwire_addr);
        con->out_kvec_left = 1;
-       con->out_kvec_bytes = sizeof(msgr->inst.addr);
+       con->out_kvec_bytes = sizeof(con->onwire_addr);
        con->out_kvec_cur = con->out_kvec;
        set_bit(WRITE_PENDING, &con->state);
 }
 
-static void prepare_write_accept_ready(struct ceph_connection *con)
+static void prepare_write_accept_reply(struct ceph_connection *con, char *ptag)
 {
-       con->out_kvec[0].iov_base = &tag_ready;
+       con->out_kvec[0].iov_base = ptag;
        con->out_kvec[0].iov_len = 1;
-       con->out_kvec[1].iov_base = &con->connect_seq;
-       con->out_kvec[1].iov_len = sizeof(con->connect_seq);
+       con->onwire32 = cpu_to_le32(con->connect_seq);
+       con->out_kvec[1].iov_base = &con->onwire32;
+       con->out_kvec[1].iov_len = 4;
        con->out_kvec_left = 2;
-       con->out_kvec_bytes = 1 + sizeof(con->connect_seq);
-       con->out_kvec_cur = con->out_kvec;
-       set_bit(WRITE_PENDING, &con->state);
-}
-
-static void prepare_write_accept_reject(struct ceph_connection *con)
-{
-       con->out_kvec[0].iov_base = &tag_reject;
-       con->out_kvec[0].iov_len = 1;
-       con->out_kvec[1].iov_base = &con->connect_seq;
-       con->out_kvec[1].iov_len = sizeof(con->connect_seq);
-       con->out_kvec_left = 2;
-       con->out_kvec_bytes = 1 + sizeof(con->connect_seq);
+       con->out_kvec_bytes = 1 + 4;
        con->out_kvec_cur = con->out_kvec;
        set_bit(WRITE_PENDING, &con->state);
 }
@@ -812,9 +805,9 @@ static void process_accept(struct ceph_connection *con)
        /* the result? */
        clear_bit(ACCEPTING, &con->state);
        if (test_bit(REJECTING, &con->state))
-               prepare_write_accept_reject(con);
+               prepare_write_accept_reply(con, &tag_reject);
        else
-               prepare_write_accept_ready(con);
+               prepare_write_accept_reply(con, &tag_ready);
        /* queue write */
        queue_work(send_wq, &con->swork.work);
 }
index 3bbb568a88f2dd6d08f9f6265b3a7fe3d5b81147..010e5dd56e6129b8443a568d44dd54401b2e2458 100644 (file)
@@ -82,6 +82,9 @@ struct ceph_connection {
        __u32 out_seq;               /* last message queued for send */
        __u32 in_seq, in_seq_acked;  /* last message received, acked */
 
+       __le32 onwire32;
+       struct ceph_entity_addr onwire_addr;
+
        /* connect state */
        struct ceph_entity_addr actual_peer_addr;
        __u32 peer_connect_seq;
@@ -169,6 +172,12 @@ static __inline__ int ceph_decode_addr(void **p, void *end, struct ceph_entity_a
        ceph_decode_copy(p, end, &v->ipaddr, sizeof(v->ipaddr));
        return 0;
 }
+static __inline__ void ceph_encode_addr(struct ceph_entity_addr *to, struct ceph_entity_addr *from)
+{
+       to->erank = cpu_to_le32(from->erank);
+       to->nonce = cpu_to_le32(from->nonce);
+       to->ipaddr = from->ipaddr;
+}
 
 static __inline__ int ceph_decode_name(void **p, void *end, struct ceph_entity_name *v) {
        if (unlikely(*p + sizeof(*v) > end))
@@ -192,9 +201,7 @@ static __inline__ void ceph_encode_inst(struct ceph_entity_inst *to, struct ceph
 {
        to->name.type = cpu_to_le32(from->name.type);
        to->name.num = cpu_to_le32(from->name.num);
-       to->addr.erank = cpu_to_le32(from->addr.erank);
-       to->addr.nonce = cpu_to_le32(from->addr.nonce);
-       to->addr.ipaddr = from->addr.ipaddr;
+       ceph_encode_addr(&to->addr, &from->addr);
 }
 
 static __inline__ void ceph_encode_header(struct ceph_msg_header *to, struct ceph_msg_header *from)