libceph: fully initialize connection in con_init()
authorAlex Elder <elder@inktank.com>
Sun, 27 May 2012 04:26:43 +0000 (23:26 -0500)
committerAlex Elder <elder@dreamhost.com>
Wed, 6 Jun 2012 14:23:54 +0000 (09:23 -0500)
Move the initialization of a ceph connection's private pointer,
operations vector pointer, and peer name information into
ceph_con_init().  Rearrange the arguments so the connection pointer
is first.  Hide the byte-swapping of the peer entity number inside
ceph_con_init()

Signed-off-by: Alex Elder <elder@inktank.com>
Reviewed-by: Sage Weil <sage@inktank.com>
fs/ceph/mds_client.c
include/linux/ceph/messenger.h
net/ceph/messenger.c
net/ceph/mon_client.c
net/ceph/osd_client.c

index ad30261cd4c0b34c2eb28129f185d411e4ae0855..ecd7f15741c15510c40b99bfc8137336b8f8758e 100644 (file)
@@ -394,11 +394,8 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc,
        s->s_seq = 0;
        mutex_init(&s->s_mutex);
 
-       ceph_con_init(&mdsc->fsc->client->msgr, &s->s_con);
-       s->s_con.private = s;
-       s->s_con.ops = &mds_con_ops;
-       s->s_con.peer_name.type = CEPH_ENTITY_TYPE_MDS;
-       s->s_con.peer_name.num = cpu_to_le64(mds);
+       ceph_con_init(&s->s_con, s, &mds_con_ops, &mdsc->fsc->client->msgr,
+               CEPH_ENTITY_TYPE_MDS, mds);
 
        spin_lock_init(&s->s_gen_ttl_lock);
        s->s_cap_gen = 0;
index 5e852f444f68af1fe23aa93cbb0b11c0f7439dae..dd27837f79ac7cdccbae2dd11e5e48087c869d7b 100644 (file)
@@ -227,8 +227,10 @@ extern void ceph_messenger_init(struct ceph_messenger *msgr,
                        u32 required_features,
                        bool nocrc);
 
-extern void ceph_con_init(struct ceph_messenger *msgr,
-                         struct ceph_connection *con);
+extern void ceph_con_init(struct ceph_connection *con, void *private,
+                       const struct ceph_connection_operations *ops,
+                       struct ceph_messenger *msgr, __u8 entity_type,
+                       __u64 entity_num);
 extern void ceph_con_open(struct ceph_connection *con,
                          struct ceph_entity_addr *addr);
 extern bool ceph_con_opened(struct ceph_connection *con);
index 36b440a00cc2854ebc5e130b8fe041beaa5dd475..3b65f6e6911bc07d194683871b65f8944b05e9e9 100644 (file)
@@ -521,15 +521,22 @@ void ceph_con_put(struct ceph_connection *con)
 /*
  * initialize a new connection.
  */
-void ceph_con_init(struct ceph_messenger *msgr, struct ceph_connection *con)
+void ceph_con_init(struct ceph_connection *con, void *private,
+       const struct ceph_connection_operations *ops,
+       struct ceph_messenger *msgr, __u8 entity_type, __u64 entity_num)
 {
        dout("con_init %p\n", con);
        memset(con, 0, sizeof(*con));
+       con->private = private;
+       con->ops = ops;
        atomic_set(&con->nref, 1);
        con->msgr = msgr;
 
        con_sock_state_init(con);
 
+       con->peer_name.type = (__u8) entity_type;
+       con->peer_name.num = cpu_to_le64(entity_num);
+
        mutex_init(&con->mutex);
        INIT_LIST_HEAD(&con->out_queue);
        INIT_LIST_HEAD(&con->out_sent);
index 6adbea78b168b6a58e92e13831a39da1929fca0f..ab6b24a5169ef047d3aeedfc756ea71bda6da275 100644 (file)
@@ -142,11 +142,9 @@ static int __open_session(struct ceph_mon_client *monc)
                monc->sub_renew_after = jiffies;  /* i.e., expired */
                monc->want_next_osdmap = !!monc->want_next_osdmap;
 
-               ceph_con_init(&monc->client->msgr, &monc->con);
-               monc->con.private = monc;
-               monc->con.ops = &mon_con_ops;
-               monc->con.peer_name.type = CEPH_ENTITY_TYPE_MON;
-               monc->con.peer_name.num = cpu_to_le64(monc->cur_mon);
+               ceph_con_init(&monc->con, monc, &mon_con_ops,
+                       &monc->client->msgr,
+                       CEPH_ENTITY_TYPE_MON, monc->cur_mon);
 
                dout("open_session mon%d opening\n", monc->cur_mon);
                ceph_con_open(&monc->con,
index 5b41a6929cd973e481716dfef3bf748b36ba0868..448c9da8beff65b012d00ba71e2c5bd9b0d066ca 100644 (file)
@@ -640,11 +640,8 @@ static struct ceph_osd *create_osd(struct ceph_osd_client *osdc, int onum)
        INIT_LIST_HEAD(&osd->o_osd_lru);
        osd->o_incarnation = 1;
 
-       ceph_con_init(&osdc->client->msgr, &osd->o_con);
-       osd->o_con.private = osd;
-       osd->o_con.ops = &osd_con_ops;
-       osd->o_con.peer_name.type = CEPH_ENTITY_TYPE_OSD;
-       osd->o_con.peer_name.num = cpu_to_le64(onum);
+       ceph_con_init(&osd->o_con, osd, &osd_con_ops, &osdc->client->msgr,
+               CEPH_ENTITY_TYPE_OSD, onum);
 
        INIT_LIST_HEAD(&osd->o_keepalive_item);
        return osd;