Skip to content

Commit

Permalink
libceph: create messenger with client
Browse files Browse the repository at this point in the history
This simplifies the init/shutdown paths, and makes client->msgr available
during the rest of the setup process.

Signed-off-by: Sage Weil <[email protected]>
  • Loading branch information
liewegas committed Oct 25, 2011
1 parent 6a8ea47 commit 6ab00d4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 28 deletions.
2 changes: 1 addition & 1 deletion drivers/block/rbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ static struct rbd_client *rbd_client_create(struct ceph_options *opt,
kref_init(&rbdc->kref);
INIT_LIST_HEAD(&rbdc->node);

rbdc->client = ceph_create_client(opt, rbdc);
rbdc->client = ceph_create_client(opt, rbdc, 0, 0);
if (IS_ERR(rbdc->client))
goto out_rbdc;
opt = NULL; /* Now rbdc->client is responsible for opt */
Expand Down
9 changes: 6 additions & 3 deletions fs/ceph/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,20 +430,23 @@ struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
struct ceph_options *opt)
{
struct ceph_fs_client *fsc;
const unsigned supported_features =
CEPH_FEATURE_FLOCK |
CEPH_FEATURE_DIRLAYOUTHASH;
const unsigned required_features = 0;
int err = -ENOMEM;

fsc = kzalloc(sizeof(*fsc), GFP_KERNEL);
if (!fsc)
return ERR_PTR(-ENOMEM);

fsc->client = ceph_create_client(opt, fsc);
fsc->client = ceph_create_client(opt, fsc, supported_features,
required_features);
if (IS_ERR(fsc->client)) {
err = PTR_ERR(fsc->client);
goto fail;
}
fsc->client->extra_mon_dispatch = extra_mon_dispatch;
fsc->client->supported_features |= CEPH_FEATURE_FLOCK |
CEPH_FEATURE_DIRLAYOUTHASH;
fsc->client->monc.want_mdsmap = 1;

fsc->mount_options = fsopt;
Expand Down
4 changes: 3 additions & 1 deletion include/linux/ceph/libceph.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ extern void ceph_destroy_options(struct ceph_options *opt);
extern int ceph_compare_options(struct ceph_options *new_opt,
struct ceph_client *client);
extern struct ceph_client *ceph_create_client(struct ceph_options *opt,
void *private);
void *private,
unsigned supported_features,
unsigned required_features);
extern u64 ceph_client_id(struct ceph_client *client);
extern void ceph_destroy_client(struct ceph_client *client);
extern int __ceph_open_session(struct ceph_client *client,
Expand Down
47 changes: 24 additions & 23 deletions net/ceph/ceph_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,12 @@ EXPORT_SYMBOL(ceph_client_id);
/*
* create a fresh client instance
*/
struct ceph_client *ceph_create_client(struct ceph_options *opt, void *private)
struct ceph_client *ceph_create_client(struct ceph_options *opt, void *private,
unsigned supported_features,
unsigned required_features)
{
struct ceph_client *client;
struct ceph_entity_addr *myaddr = NULL;
int err = -ENOMEM;

client = kzalloc(sizeof(*client), GFP_KERNEL);
Expand All @@ -449,15 +452,27 @@ struct ceph_client *ceph_create_client(struct ceph_options *opt, void *private)
client->auth_err = 0;

client->extra_mon_dispatch = NULL;
client->supported_features = CEPH_FEATURE_SUPPORTED_DEFAULT;
client->required_features = CEPH_FEATURE_REQUIRED_DEFAULT;

client->msgr = NULL;
client->supported_features = CEPH_FEATURE_SUPPORTED_DEFAULT |
supported_features;
client->required_features = CEPH_FEATURE_REQUIRED_DEFAULT |
required_features;

/* msgr */
if (ceph_test_opt(client, MYIP))
myaddr = &client->options->my_addr;
client->msgr = ceph_messenger_create(myaddr,
client->supported_features,
client->required_features);
if (IS_ERR(client->msgr)) {
err = PTR_ERR(client->msgr);
goto fail;
}
client->msgr->nocrc = ceph_test_opt(client, NOCRC);

/* subsystems */
err = ceph_monc_init(&client->monc, client);
if (err < 0)
goto fail;
goto fail_msgr;
err = ceph_osdc_init(&client->osdc, client);
if (err < 0)
goto fail_monc;
Expand All @@ -466,6 +481,8 @@ struct ceph_client *ceph_create_client(struct ceph_options *opt, void *private)

fail_monc:
ceph_monc_stop(&client->monc);
fail_msgr:
ceph_messenger_destroy(client->msgr);
fail:
kfree(client);
return ERR_PTR(err);
Expand All @@ -490,8 +507,7 @@ void ceph_destroy_client(struct ceph_client *client)

ceph_debugfs_client_cleanup(client);

if (client->msgr)
ceph_messenger_destroy(client->msgr);
ceph_messenger_destroy(client->msgr);

ceph_destroy_options(client->options);

Expand All @@ -514,24 +530,9 @@ static int have_mon_and_osd_map(struct ceph_client *client)
*/
int __ceph_open_session(struct ceph_client *client, unsigned long started)
{
struct ceph_entity_addr *myaddr = NULL;
int err;
unsigned long timeout = client->options->mount_timeout * HZ;

/* initialize the messenger */
if (client->msgr == NULL) {
if (ceph_test_opt(client, MYIP))
myaddr = &client->options->my_addr;
client->msgr = ceph_messenger_create(myaddr,
client->supported_features,
client->required_features);
if (IS_ERR(client->msgr)) {
client->msgr = NULL;
return PTR_ERR(client->msgr);
}
client->msgr->nocrc = ceph_test_opt(client, NOCRC);
}

/* open session, and wait for mon and osd maps */
err = ceph_monc_open_session(&client->monc);
if (err < 0)
Expand Down

0 comments on commit 6ab00d4

Please sign in to comment.