diff options
author | Alex Elder <elder@dreamhost.com> | 2012-02-02 09:13:30 -0500 |
---|---|---|
committer | Alex Elder <elder@dreamhost.com> | 2012-03-22 11:47:48 -0400 |
commit | d720bcb0a8f246eb441ba9d4f341bc16746556c6 (patch) | |
tree | 9df53a7ff220547c7150be803c8a3e8cca0664b1 /drivers/block/rbd.c | |
parent | f0f8cef5a30504eaeba5588a9115b46c824d91a3 (diff) |
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: Alex Elder <elder@dreamhost.com>
Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'drivers/block/rbd.c')
-rw-r--r-- | drivers/block/rbd.c | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 812fd38cba3d..3e6f300ba9f1 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c | |||
@@ -384,17 +384,15 @@ static int parse_rbd_opts_token(char *c, void *private) | |||
384 | * Get a ceph client with specific addr and configuration, if one does | 384 | * Get a ceph client with specific addr and configuration, if one does |
385 | * not exist create it. | 385 | * not exist create it. |
386 | */ | 386 | */ |
387 | static int rbd_get_client(struct rbd_device *rbd_dev, const char *mon_addr, | 387 | static struct rbd_client *rbd_get_client(const char *mon_addr, char *options) |
388 | char *options) | ||
389 | { | 388 | { |
390 | struct rbd_client *rbdc; | 389 | struct rbd_client *rbdc; |
391 | struct ceph_options *opt; | 390 | struct ceph_options *opt; |
392 | int ret; | ||
393 | struct rbd_options *rbd_opts; | 391 | struct rbd_options *rbd_opts; |
394 | 392 | ||
395 | rbd_opts = kzalloc(sizeof(*rbd_opts), GFP_KERNEL); | 393 | rbd_opts = kzalloc(sizeof(*rbd_opts), GFP_KERNEL); |
396 | if (!rbd_opts) | 394 | if (!rbd_opts) |
397 | return -ENOMEM; | 395 | return ERR_PTR(-ENOMEM); |
398 | 396 | ||
399 | rbd_opts->notify_timeout = RBD_NOTIFY_TIMEOUT_DEFAULT; | 397 | rbd_opts->notify_timeout = RBD_NOTIFY_TIMEOUT_DEFAULT; |
400 | 398 | ||
@@ -402,8 +400,8 @@ static int rbd_get_client(struct rbd_device *rbd_dev, const char *mon_addr, | |||
402 | mon_addr + strlen(mon_addr), | 400 | mon_addr + strlen(mon_addr), |
403 | parse_rbd_opts_token, rbd_opts); | 401 | parse_rbd_opts_token, rbd_opts); |
404 | if (IS_ERR(opt)) { | 402 | if (IS_ERR(opt)) { |
405 | ret = PTR_ERR(opt); | 403 | kfree(rbd_opts); |
406 | goto done_err; | 404 | return ERR_CAST(opt); |
407 | } | 405 | } |
408 | 406 | ||
409 | spin_lock(&rbd_client_list_lock); | 407 | 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 | kref_get(&rbdc->kref); | 411 | kref_get(&rbdc->kref); |
414 | spin_unlock(&rbd_client_list_lock); | 412 | spin_unlock(&rbd_client_list_lock); |
415 | 413 | ||
416 | rbd_dev->rbd_client = rbdc; | ||
417 | |||
418 | ceph_destroy_options(opt); | 414 | ceph_destroy_options(opt); |
419 | kfree(rbd_opts); | 415 | kfree(rbd_opts); |
420 | 416 | ||
421 | return 0; | 417 | return rbdc; |
422 | } | 418 | } |
423 | spin_unlock(&rbd_client_list_lock); | 419 | spin_unlock(&rbd_client_list_lock); |
424 | 420 | ||
425 | rbdc = rbd_client_create(opt, rbd_opts); | 421 | rbdc = rbd_client_create(opt, rbd_opts); |
426 | 422 | ||
427 | if (IS_ERR(rbdc)) { | 423 | if (IS_ERR(rbdc)) |
428 | ret = PTR_ERR(rbdc); | 424 | kfree(rbd_opts); |
429 | goto done_err; | ||
430 | } | ||
431 | 425 | ||
432 | rbd_dev->rbd_client = rbdc; | 426 | return rbdc; |
433 | return 0; | ||
434 | done_err: | ||
435 | kfree(rbd_opts); | ||
436 | return ret; | ||
437 | } | 427 | } |
438 | 428 | ||
439 | /* | 429 | /* |
@@ -2290,9 +2280,11 @@ static ssize_t rbd_add(struct bus_type *bus, | |||
2290 | /* initialize rest of new object */ | 2280 | /* initialize rest of new object */ |
2291 | snprintf(rbd_dev->name, DEV_NAME_LEN, RBD_DRV_NAME "%d", rbd_dev->id); | 2281 | snprintf(rbd_dev->name, DEV_NAME_LEN, RBD_DRV_NAME "%d", rbd_dev->id); |
2292 | 2282 | ||
2293 | rc = rbd_get_client(rbd_dev, mon_dev_name, options); | 2283 | rbd_dev->rbd_client = rbd_get_client(mon_dev_name, options); |
2294 | if (rc < 0) | 2284 | if (IS_ERR(rbd_dev->rbd_client)) { |
2285 | rc = PTR_ERR(rbd_dev->rbd_client); | ||
2295 | goto err_put_id; | 2286 | goto err_put_id; |
2287 | } | ||
2296 | 2288 | ||
2297 | /* pick the pool */ | 2289 | /* pick the pool */ |
2298 | osdc = &rbd_dev->rbd_client->client->osdc; | 2290 | osdc = &rbd_dev->rbd_client->client->osdc; |