From cc63cd5150282119073692ce90853f298bf5f369 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 8 Jan 2008 15:57:27 -0800 Subject: [PATCH] client: encode connect_seq, minor accept cleanup --- src/kernel/messenger.c | 53 ++++++++++++++++++------------------------ src/kernel/messenger.h | 13 ++++++++--- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/kernel/messenger.c b/src/kernel/messenger.c index cda4a6c3989af..8a644a4a2eab5 100644 --- a/src/kernel/messenger.c +++ b/src/kernel/messenger.c @@ -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); } diff --git a/src/kernel/messenger.h b/src/kernel/messenger.h index 3bbb568a88f2d..010e5dd56e612 100644 --- a/src/kernel/messenger.h +++ b/src/kernel/messenger.h @@ -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) -- 2.39.5