Skip to content

Commit 15d9882

Browse files
Alex ElderAlex Elder
authored andcommitted
libceph: embed ceph messenger structure in ceph_client
A ceph client has a pointer to a ceph messenger structure in it. There is always exactly one ceph messenger for a ceph client, so there is no need to allocate it separate from the ceph client structure. Switch the ceph_client structure to embed its ceph_messenger structure. Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Yehuda Sadeh <yehuda@inktank.com> Reviewed-by: Sage Weil <sage@inktank.com>
1 parent e220042 commit 15d9882

7 files changed

Lines changed: 26 additions & 45 deletions

File tree

‎fs/ceph/mds_client.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc,
394394
s->s_seq = 0;
395395
mutex_init(&s->s_mutex);
396396

397-
ceph_con_init(mdsc->fsc->client->msgr, &s->s_con);
397+
ceph_con_init(&mdsc->fsc->client->msgr, &s->s_con);
398398
s->s_con.private = s;
399399
s->s_con.ops = &mds_con_ops;
400400
s->s_con.peer_name.type = CEPH_ENTITY_TYPE_MDS;

‎include/linux/ceph/libceph.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ struct ceph_client {
131131
u32 supported_features;
132132
u32 required_features;
133133

134-
struct ceph_messenger *msgr; /* messenger instance */
134+
struct ceph_messenger msgr; /* messenger instance */
135135
struct ceph_mon_client monc;
136136
struct ceph_osd_client osdc;
137137

‎include/linux/ceph/messenger.h‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,11 @@ extern int ceph_msgr_init(void);
211211
extern void ceph_msgr_exit(void);
212212
extern void ceph_msgr_flush(void);
213213

214-
extern struct ceph_messenger *ceph_messenger_create(
215-
struct ceph_entity_addr *myaddr,
216-
u32 features, u32 required);
217-
extern void ceph_messenger_destroy(struct ceph_messenger *);
214+
extern void ceph_messenger_init(struct ceph_messenger *msgr,
215+
struct ceph_entity_addr *myaddr,
216+
u32 supported_features,
217+
u32 required_features,
218+
bool nocrc);
218219

219220
extern void ceph_con_init(struct ceph_messenger *msgr,
220221
struct ceph_connection *con);

‎net/ceph/ceph_common.c‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -468,19 +468,15 @@ struct ceph_client *ceph_create_client(struct ceph_options *opt, void *private,
468468
/* msgr */
469469
if (ceph_test_opt(client, MYIP))
470470
myaddr = &client->options->my_addr;
471-
client->msgr = ceph_messenger_create(myaddr,
472-
client->supported_features,
473-
client->required_features);
474-
if (IS_ERR(client->msgr)) {
475-
err = PTR_ERR(client->msgr);
476-
goto fail;
477-
}
478-
client->msgr->nocrc = ceph_test_opt(client, NOCRC);
471+
ceph_messenger_init(&client->msgr, myaddr,
472+
client->supported_features,
473+
client->required_features,
474+
ceph_test_opt(client, NOCRC));
479475

480476
/* subsystems */
481477
err = ceph_monc_init(&client->monc, client);
482478
if (err < 0)
483-
goto fail_msgr;
479+
goto fail;
484480
err = ceph_osdc_init(&client->osdc, client);
485481
if (err < 0)
486482
goto fail_monc;
@@ -489,8 +485,6 @@ struct ceph_client *ceph_create_client(struct ceph_options *opt, void *private,
489485

490486
fail_monc:
491487
ceph_monc_stop(&client->monc);
492-
fail_msgr:
493-
ceph_messenger_destroy(client->msgr);
494488
fail:
495489
kfree(client);
496490
return ERR_PTR(err);
@@ -515,8 +509,6 @@ void ceph_destroy_client(struct ceph_client *client)
515509

516510
ceph_debugfs_client_cleanup(client);
517511

518-
ceph_messenger_destroy(client->msgr);
519-
520512
ceph_destroy_options(client->options);
521513

522514
kfree(client);

‎net/ceph/messenger.c‎

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,18 +2245,14 @@ static void ceph_fault(struct ceph_connection *con)
22452245

22462246

22472247
/*
2248-
* create a new messenger instance
2248+
* initialize a new messenger instance
22492249
*/
2250-
struct ceph_messenger *ceph_messenger_create(struct ceph_entity_addr *myaddr,
2251-
u32 supported_features,
2252-
u32 required_features)
2250+
void ceph_messenger_init(struct ceph_messenger *msgr,
2251+
struct ceph_entity_addr *myaddr,
2252+
u32 supported_features,
2253+
u32 required_features,
2254+
bool nocrc)
22532255
{
2254-
struct ceph_messenger *msgr;
2255-
2256-
msgr = kzalloc(sizeof(*msgr), GFP_KERNEL);
2257-
if (msgr == NULL)
2258-
return ERR_PTR(-ENOMEM);
2259-
22602256
msgr->supported_features = supported_features;
22612257
msgr->required_features = required_features;
22622258

@@ -2269,19 +2265,11 @@ struct ceph_messenger *ceph_messenger_create(struct ceph_entity_addr *myaddr,
22692265
msgr->inst.addr.type = 0;
22702266
get_random_bytes(&msgr->inst.addr.nonce, sizeof(msgr->inst.addr.nonce));
22712267
encode_my_addr(msgr);
2268+
msgr->nocrc = nocrc;
22722269

2273-
dout("messenger_create %p\n", msgr);
2274-
return msgr;
2275-
}
2276-
EXPORT_SYMBOL(ceph_messenger_create);
2277-
2278-
void ceph_messenger_destroy(struct ceph_messenger *msgr)
2279-
{
2280-
dout("destroy %p\n", msgr);
2281-
kfree(msgr);
2282-
dout("destroyed messenger %p\n", msgr);
2270+
dout("%s %p\n", __func__, msgr);
22832271
}
2284-
EXPORT_SYMBOL(ceph_messenger_destroy);
2272+
EXPORT_SYMBOL(ceph_messenger_init);
22852273

22862274
static void clear_standby(struct ceph_connection *con)
22872275
{

‎net/ceph/mon_client.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
763763
monc->con = kmalloc(sizeof(*monc->con), GFP_KERNEL);
764764
if (!monc->con)
765765
goto out_monmap;
766-
ceph_con_init(monc->client->msgr, monc->con);
766+
ceph_con_init(&monc->client->msgr, monc->con);
767767
monc->con->private = monc;
768768
monc->con->ops = &mon_con_ops;
769769

@@ -880,8 +880,8 @@ static void handle_auth_reply(struct ceph_mon_client *monc,
880880
} else if (!was_auth && monc->auth->ops->is_authenticated(monc->auth)) {
881881
dout("authenticated, starting session\n");
882882

883-
monc->client->msgr->inst.name.type = CEPH_ENTITY_TYPE_CLIENT;
884-
monc->client->msgr->inst.name.num =
883+
monc->client->msgr.inst.name.type = CEPH_ENTITY_TYPE_CLIENT;
884+
monc->client->msgr.inst.name.num =
885885
cpu_to_le64(monc->auth->global_id);
886886

887887
__send_subscribe(monc);

‎net/ceph/osd_client.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ static struct ceph_osd *create_osd(struct ceph_osd_client *osdc)
639639
INIT_LIST_HEAD(&osd->o_osd_lru);
640640
osd->o_incarnation = 1;
641641

642-
ceph_con_init(osdc->client->msgr, &osd->o_con);
642+
ceph_con_init(&osdc->client->msgr, &osd->o_con);
643643
osd->o_con.private = osd;
644644
osd->o_con.ops = &osd_con_ops;
645645
osd->o_con.peer_name.type = CEPH_ENTITY_TYPE_OSD;
@@ -1391,7 +1391,7 @@ void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
13911391
epoch, maplen);
13921392
newmap = osdmap_apply_incremental(&p, next,
13931393
osdc->osdmap,
1394-
osdc->client->msgr);
1394+
&osdc->client->msgr);
13951395
if (IS_ERR(newmap)) {
13961396
err = PTR_ERR(newmap);
13971397
goto bad;

0 commit comments

Comments
 (0)