提交 f8c38929 编写于 作者: A Alex Elder

rbd: move rbd_opts to struct rbd_device

The rbd options don't really apply to the ceph client.  So don't
store a pointer to it in the ceph_client structure, and put them
(a struct, not a pointer) into the rbd_dev structure proper.

Pass the rbd device structure to rbd_client_create() so it can
assign rbd_dev->rbdc if successful, and have it return an error code
instead of the rbd client pointer.
Signed-off-by: NAlex Elder <elder@inktank.com>
Reviewed-by: NYehuda Sadeh <yehuda@inktank.com>
上级 621901d6
...@@ -98,7 +98,6 @@ struct rbd_options { ...@@ -98,7 +98,6 @@ struct rbd_options {
*/ */
struct rbd_client { struct rbd_client {
struct ceph_client *client; struct ceph_client *client;
struct rbd_options *rbd_opts;
struct kref kref; struct kref kref;
struct list_head node; struct list_head node;
}; };
...@@ -152,6 +151,7 @@ struct rbd_device { ...@@ -152,6 +151,7 @@ struct rbd_device {
struct gendisk *disk; /* blkdev's gendisk and rq */ struct gendisk *disk; /* blkdev's gendisk and rq */
struct request_queue *q; struct request_queue *q;
struct rbd_options rbd_opts;
struct rbd_client *rbd_client; struct rbd_client *rbd_client;
char name[DEV_NAME_LEN]; /* blkdev name, e.g. rbd3 */ char name[DEV_NAME_LEN]; /* blkdev name, e.g. rbd3 */
...@@ -273,8 +273,7 @@ static const struct block_device_operations rbd_bd_ops = { ...@@ -273,8 +273,7 @@ static const struct block_device_operations rbd_bd_ops = {
* Initialize an rbd client instance. * Initialize an rbd client instance.
* We own *ceph_opts. * We own *ceph_opts.
*/ */
static struct rbd_client *rbd_client_create(struct ceph_options *ceph_opts, static struct rbd_client *rbd_client_create(struct ceph_options *ceph_opts)
struct rbd_options *rbd_opts)
{ {
struct rbd_client *rbdc; struct rbd_client *rbdc;
int ret = -ENOMEM; int ret = -ENOMEM;
...@@ -298,8 +297,6 @@ static struct rbd_client *rbd_client_create(struct ceph_options *ceph_opts, ...@@ -298,8 +297,6 @@ static struct rbd_client *rbd_client_create(struct ceph_options *ceph_opts,
if (ret < 0) if (ret < 0)
goto out_err; goto out_err;
rbdc->rbd_opts = rbd_opts;
spin_lock(&rbd_client_list_lock); spin_lock(&rbd_client_list_lock);
list_add_tail(&rbdc->node, &rbd_client_list); list_add_tail(&rbdc->node, &rbd_client_list);
spin_unlock(&rbd_client_list_lock); spin_unlock(&rbd_client_list_lock);
...@@ -402,42 +399,33 @@ static int parse_rbd_opts_token(char *c, void *private) ...@@ -402,42 +399,33 @@ 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 struct rbd_client *rbd_get_client(const char *mon_addr, static int rbd_get_client(struct rbd_device *rbd_dev, const char *mon_addr,
size_t mon_addr_len, size_t mon_addr_len, char *options)
char *options)
{ {
struct rbd_client *rbdc; struct rbd_options *rbd_opts = &rbd_dev->rbd_opts;
struct ceph_options *ceph_opts; struct ceph_options *ceph_opts;
struct rbd_options *rbd_opts; struct rbd_client *rbdc;
rbd_opts = kzalloc(sizeof(*rbd_opts), GFP_KERNEL);
if (!rbd_opts)
return ERR_PTR(-ENOMEM);
rbd_opts->notify_timeout = RBD_NOTIFY_TIMEOUT_DEFAULT; rbd_opts->notify_timeout = RBD_NOTIFY_TIMEOUT_DEFAULT;
ceph_opts = ceph_parse_options(options, mon_addr, ceph_opts = ceph_parse_options(options, mon_addr,
mon_addr + mon_addr_len, mon_addr + mon_addr_len,
parse_rbd_opts_token, rbd_opts); parse_rbd_opts_token, rbd_opts);
if (IS_ERR(ceph_opts)) { if (IS_ERR(ceph_opts))
kfree(rbd_opts); return PTR_ERR(ceph_opts);
return ERR_CAST(ceph_opts);
}
rbdc = rbd_client_find(ceph_opts); rbdc = rbd_client_find(ceph_opts);
if (rbdc) { if (rbdc) {
/* using an existing client */ /* using an existing client */
ceph_destroy_options(ceph_opts); ceph_destroy_options(ceph_opts);
kfree(rbd_opts); } else {
rbdc = rbd_client_create(ceph_opts);
return rbdc;
}
rbdc = rbd_client_create(ceph_opts, rbd_opts);
if (IS_ERR(rbdc)) if (IS_ERR(rbdc))
kfree(rbd_opts); return PTR_ERR(rbdc);
}
rbd_dev->rbd_client = rbdc;
return rbdc; return 0;
} }
/* /*
...@@ -455,7 +443,6 @@ static void rbd_client_release(struct kref *kref) ...@@ -455,7 +443,6 @@ static void rbd_client_release(struct kref *kref)
spin_unlock(&rbd_client_list_lock); spin_unlock(&rbd_client_list_lock);
ceph_destroy_client(rbdc->client); ceph_destroy_client(rbdc->client);
kfree(rbdc->rbd_opts);
kfree(rbdc); kfree(rbdc);
} }
...@@ -2533,13 +2520,9 @@ static ssize_t rbd_add(struct bus_type *bus, ...@@ -2533,13 +2520,9 @@ static ssize_t rbd_add(struct bus_type *bus,
if (rc) if (rc)
goto err_put_id; goto err_put_id;
rbd_dev->rbd_client = rbd_get_client(mon_addrs, mon_addrs_size - 1, rc = rbd_get_client(rbd_dev, mon_addrs, mon_addrs_size - 1, options);
options); if (rc < 0)
if (IS_ERR(rbd_dev->rbd_client)) {
rc = PTR_ERR(rbd_dev->rbd_client);
rbd_dev->rbd_client = NULL;
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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册