Commit d720bcb0 authored by Alex Elder's avatar Alex Elder

rbd: have rbd_get_client() return a rbd_client

Since rbd_get_client() currently returns an error code.  It assigns
the rbd_client field of the rbd_device structure it is passed if
successful.  Instead, have it return the created rbd_client
structure and return a pointer-coded error if there is an error.
This makes the assignment of the client pointer more obvious at the
call site.
Signed-off-by: default avatarAlex Elder <elder@dreamhost.com>
Signed-off-by: default avatarSage Weil <sage@newdream.net>
parent f0f8cef5
...@@ -384,17 +384,15 @@ static int parse_rbd_opts_token(char *c, void *private) ...@@ -384,17 +384,15 @@ static int parse_rbd_opts_token(char *c, void *private)
* Get a ceph client with specific addr and configuration, if one does * Get a ceph client with specific addr and configuration, if one does
* not exist create it. * not exist create it.
*/ */
static int rbd_get_client(struct rbd_device *rbd_dev, const char *mon_addr, static struct rbd_client *rbd_get_client(const char *mon_addr, char *options)
char *options)
{ {
struct rbd_client *rbdc; struct rbd_client *rbdc;
struct ceph_options *opt; struct ceph_options *opt;
int ret;
struct rbd_options *rbd_opts; struct rbd_options *rbd_opts;
rbd_opts = kzalloc(sizeof(*rbd_opts), GFP_KERNEL); rbd_opts = kzalloc(sizeof(*rbd_opts), GFP_KERNEL);
if (!rbd_opts) if (!rbd_opts)
return -ENOMEM; return ERR_PTR(-ENOMEM);
rbd_opts->notify_timeout = RBD_NOTIFY_TIMEOUT_DEFAULT; rbd_opts->notify_timeout = RBD_NOTIFY_TIMEOUT_DEFAULT;
...@@ -402,8 +400,8 @@ static int rbd_get_client(struct rbd_device *rbd_dev, const char *mon_addr, ...@@ -402,8 +400,8 @@ static int rbd_get_client(struct rbd_device *rbd_dev, const char *mon_addr,
mon_addr + strlen(mon_addr), mon_addr + strlen(mon_addr),
parse_rbd_opts_token, rbd_opts); parse_rbd_opts_token, rbd_opts);
if (IS_ERR(opt)) { if (IS_ERR(opt)) {
ret = PTR_ERR(opt); kfree(rbd_opts);
goto done_err; return ERR_CAST(opt);
} }
spin_lock(&rbd_client_list_lock); spin_lock(&rbd_client_list_lock);
...@@ -413,27 +411,19 @@ static int rbd_get_client(struct rbd_device *rbd_dev, const char *mon_addr, ...@@ -413,27 +411,19 @@ static int rbd_get_client(struct rbd_device *rbd_dev, const char *mon_addr,
kref_get(&rbdc->kref); kref_get(&rbdc->kref);
spin_unlock(&rbd_client_list_lock); spin_unlock(&rbd_client_list_lock);
rbd_dev->rbd_client = rbdc;
ceph_destroy_options(opt); ceph_destroy_options(opt);
kfree(rbd_opts); kfree(rbd_opts);
return 0; return rbdc;
} }
spin_unlock(&rbd_client_list_lock); spin_unlock(&rbd_client_list_lock);
rbdc = rbd_client_create(opt, rbd_opts); rbdc = rbd_client_create(opt, rbd_opts);
if (IS_ERR(rbdc)) { if (IS_ERR(rbdc))
ret = PTR_ERR(rbdc); kfree(rbd_opts);
goto done_err;
}
rbd_dev->rbd_client = rbdc; return rbdc;
return 0;
done_err:
kfree(rbd_opts);
return ret;
} }
/* /*
...@@ -2290,9 +2280,11 @@ static ssize_t rbd_add(struct bus_type *bus, ...@@ -2290,9 +2280,11 @@ static ssize_t rbd_add(struct bus_type *bus,
/* initialize rest of new object */ /* initialize rest of new object */
snprintf(rbd_dev->name, DEV_NAME_LEN, RBD_DRV_NAME "%d", rbd_dev->id); snprintf(rbd_dev->name, DEV_NAME_LEN, RBD_DRV_NAME "%d", rbd_dev->id);
rc = rbd_get_client(rbd_dev, mon_dev_name, options); rbd_dev->rbd_client = rbd_get_client(mon_dev_name, options);
if (rc < 0) if (IS_ERR(rbd_dev->rbd_client)) {
rc = PTR_ERR(rbd_dev->rbd_client);
goto err_put_id; goto err_put_id;
}
/* pick the pool */ /* pick the pool */
osdc = &rbd_dev->rbd_client->client->osdc; osdc = &rbd_dev->rbd_client->client->osdc;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment