From 187e792d0ab438a5f0dfe8f00def70a7a91982e6 Mon Sep 17 00:00:00 2001 From: sageweil Date: Tue, 9 Oct 2007 17:29:48 +0000 Subject: [PATCH] split out raw bit sof msg_types git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1896 29311d96-e01e-0410-9327-a35deaab8ce9 --- trunk/ceph/include/ceph_inttypes.h | 8 +++++ trunk/ceph/msg/ceph_msg_types.h | 38 +++++++++++++++++++++ trunk/ceph/msg/msg_types.h | 55 +++++++++++++++--------------- 3 files changed, 74 insertions(+), 27 deletions(-) create mode 100644 trunk/ceph/include/ceph_inttypes.h create mode 100644 trunk/ceph/msg/ceph_msg_types.h diff --git a/trunk/ceph/include/ceph_inttypes.h b/trunk/ceph/include/ceph_inttypes.h new file mode 100644 index 0000000000000..c31c76ace1c5d --- /dev/null +++ b/trunk/ceph/include/ceph_inttypes.h @@ -0,0 +1,8 @@ +#ifndef __CEPH_INTTYPES_H +#define __CEPH_INTTYPES_H + +typedef uint32_t __u32; +typedef uint16_t __u16; +typedef uint8_t __u8; + +#endif diff --git a/trunk/ceph/msg/ceph_msg_types.h b/trunk/ceph/msg/ceph_msg_types.h new file mode 100644 index 0000000000000..b6412976d6bf2 --- /dev/null +++ b/trunk/ceph/msg/ceph_msg_types.h @@ -0,0 +1,38 @@ +/* -*- mode:C++; tab-width:8; c-basic-offset:8; indent-tabs-mode:t -*- + * vim: ts=8 sw=8 smarttab + */ +#ifndef __CEPH_MSG_TYPES_H +#define __CEPH_MSG_TYPES_H + +/* + * entity_name + */ +struct ceph_entity_name { + __u32 type; + __u32 num; +}; + +#define CEPH_ENTITY_TYPE_MON 1 +#define CEPH_ENTITY_TYPE_MDS 2 +#define CEPH_ENTITY_TYPE_OSD 3 +#define CEPH_ENTITY_TYPE_CLIENT 4 +#define CEPH_ENTITY_TYPE_ADMIN 5 + + +/* + * entity_addr + * ipv4 only for now + */ +struct ceph_entity_addr { + __u8 ipq[4]; + __u32 port; + __u32 nonce; +}; + + +struct ceph_entity_inst { + struct ceph_entity_name name; + struct ceph_entity_addr addr; +}; + +#endif diff --git a/trunk/ceph/msg/msg_types.h b/trunk/ceph/msg/msg_types.h index 23c14c8c25c11..793520d4a446b 100644 --- a/trunk/ceph/msg/msg_types.h +++ b/trunk/ceph/msg/msg_types.h @@ -15,27 +15,29 @@ #ifndef __MSG_TYPES_H #define __MSG_TYPES_H +// raw C structs +#include "include/ceph_inttypes.h" +#include "ceph_msg_types.h" + #include "include/types.h" #include "include/blobhash.h" #include "tcp.h" -// new typed msg_addr_t way! class entity_name_t { - int32_t _type; - int32_t _num; + struct ceph_entity_name v; public: - static const int TYPE_MON = 1; - static const int TYPE_MDS = 2; - static const int TYPE_OSD = 3; - static const int TYPE_CLIENT = 4; - static const int TYPE_ADMIN = 5; + static const int TYPE_MON = CEPH_ENTITY_TYPE_MON; + static const int TYPE_MDS = CEPH_ENTITY_TYPE_MDS; + static const int TYPE_OSD = CEPH_ENTITY_TYPE_OSD; + static const int TYPE_CLIENT = CEPH_ENTITY_TYPE_CLIENT; + static const int TYPE_ADMIN = CEPH_ENTITY_TYPE_ADMIN; static const int NEW = -1; // cons - entity_name_t() : _type(0), _num(0) {} - entity_name_t(int t, int n=NEW) : _type(t), _num(n) {} + entity_name_t() { v.type = v.num = 0; } + entity_name_t(int t, int n=NEW) { v.type = t; v.num = n; } // static cons static entity_name_t MON(int i=NEW) { return entity_name_t(TYPE_MON, i); } @@ -44,8 +46,8 @@ public: static entity_name_t CLIENT(int i=NEW) { return entity_name_t(TYPE_CLIENT, i); } static entity_name_t ADMIN(int i=NEW) { return entity_name_t(TYPE_ADMIN, i); } - int num() const { return _num; } - int type() const { return _type; } + int num() const { return v.num; } + int type() const { return v.type; } const char *type_str() const { switch (type()) { case TYPE_MDS: return "mds"; @@ -105,34 +107,33 @@ namespace __gnu_cxx { * ipv4 for now. */ struct entity_addr_t { - uint8_t ipq[4]; - uint32_t port; - uint32_t nonce; // bind time, or pid, or something unique! + struct ceph_entity_addr v; - entity_addr_t() : port(0), nonce(0) { - ipq[0] = ipq[1] = ipq[2] = ipq[3] = 0; + entity_addr_t() { + v.port = v.nonce = 0; + v.ipq[0] = v.ipq[1] = v.ipq[2] = v.ipq[3] = 0; } void set_addr(tcpaddr_t a) { - memcpy((char*)ipq, (char*)&a.sin_addr.s_addr, 4); - port = ntohs(a.sin_port); + memcpy((char*)v.ipq, (char*)&a.sin_addr.s_addr, 4); + v.port = ntohs(a.sin_port); } void make_addr(tcpaddr_t& a) const { memset(&a, 0, sizeof(a)); a.sin_family = AF_INET; - memcpy((char*)&a.sin_addr.s_addr, (char*)ipq, 4); - a.sin_port = htons(port); + memcpy((char*)&a.sin_addr.s_addr, (char*)v.ipq, 4); + a.sin_port = htons(v.port); } }; inline ostream& operator<<(ostream& out, const entity_addr_t &addr) { - return out << (int)addr.ipq[0] - << '.' << (int)addr.ipq[1] - << '.' << (int)addr.ipq[2] - << '.' << (int)addr.ipq[3] - << ':' << addr.port - << '.' << addr.nonce; + return out << (int)addr.v.ipq[0] + << '.' << (int)addr.v.ipq[1] + << '.' << (int)addr.v.ipq[2] + << '.' << (int)addr.v.ipq[3] + << ':' << addr.v.port + << '.' << addr.v.nonce; } inline bool operator==(const entity_addr_t& a, const entity_addr_t& b) { return memcmp(&a, &b, sizeof(a)) == 0; } -- 2.39.5