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

rbd: consolidate rbd_dev init in rbd_add()

Group the allocation and initialization of fields of the rbd device
structure created in rbd_add().  Move the grouped code down later in
the function, just prior to the call to rbd_dev_probe().  This is
for the most part simple code movement.
Signed-off-by: NAlex Elder <elder@inktank.com>
Reviewed-by: NJosh Durgin <josh.durgin@inktank.com>
上级 9d3997fd
...@@ -3232,29 +3232,16 @@ static ssize_t rbd_add(struct bus_type *bus, ...@@ -3232,29 +3232,16 @@ static ssize_t rbd_add(struct bus_type *bus,
if (!try_module_get(THIS_MODULE)) if (!try_module_get(THIS_MODULE))
return -ENODEV; return -ENODEV;
rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL);
if (!rbd_dev)
return -ENOMEM;
/* static rbd_device initialization */
spin_lock_init(&rbd_dev->lock);
INIT_LIST_HEAD(&rbd_dev->node);
INIT_LIST_HEAD(&rbd_dev->snaps);
init_rwsem(&rbd_dev->header_rwsem);
/* parse add command */ /* parse add command */
rc = rbd_add_parse_args(buf, &ceph_opts, &rbd_opts, &spec); rc = rbd_add_parse_args(buf, &ceph_opts, &rbd_opts, &spec);
if (rc < 0) if (rc < 0)
goto err_out_mem; goto err_out_module;
rbd_dev->mapping.read_only = rbd_opts->read_only;
rbdc = rbd_get_client(ceph_opts); rbdc = rbd_get_client(ceph_opts);
if (IS_ERR(rbdc)) { if (IS_ERR(rbdc)) {
rc = PTR_ERR(rbdc); rc = PTR_ERR(rbdc);
goto err_out_args; goto err_out_args;
} }
rbd_dev->rbd_client = rbdc;
ceph_opts = NULL; /* ceph_opts now owned by rbd_dev client */ ceph_opts = NULL; /* ceph_opts now owned by rbd_dev client */
/* pick the pool */ /* pick the pool */
...@@ -3264,11 +3251,22 @@ static ssize_t rbd_add(struct bus_type *bus, ...@@ -3264,11 +3251,22 @@ static ssize_t rbd_add(struct bus_type *bus,
goto err_out_client; goto err_out_client;
spec->pool_id = (u64) rc; spec->pool_id = (u64) rc;
rbd_dev = kzalloc(sizeof (*rbd_dev), GFP_KERNEL);
if (!rbd_dev)
goto err_out_client;
spin_lock_init(&rbd_dev->lock);
INIT_LIST_HEAD(&rbd_dev->node);
INIT_LIST_HEAD(&rbd_dev->snaps);
init_rwsem(&rbd_dev->header_rwsem);
rbd_dev->rbd_client = rbdc;
rbd_dev->spec = spec; rbd_dev->spec = spec;
rbd_dev->mapping.read_only = rbd_opts->read_only;
rc = rbd_dev_probe(rbd_dev); rc = rbd_dev_probe(rbd_dev);
if (rc < 0) if (rc < 0)
goto err_out_client; goto err_out_mem;
/* no need to lock here, as rbd_dev is not registered yet */ /* no need to lock here, as rbd_dev is not registered yet */
rc = rbd_dev_snaps_update(rbd_dev); rc = rbd_dev_snaps_update(rbd_dev);
...@@ -3348,19 +3346,20 @@ static ssize_t rbd_add(struct bus_type *bus, ...@@ -3348,19 +3346,20 @@ static ssize_t rbd_add(struct bus_type *bus,
rbd_remove_all_snaps(rbd_dev); rbd_remove_all_snaps(rbd_dev);
err_out_probe: err_out_probe:
rbd_header_free(&rbd_dev->header); rbd_header_free(&rbd_dev->header);
err_out_client:
kfree(rbd_dev->header_name); kfree(rbd_dev->header_name);
err_out_mem:
kfree(rbd_dev);
err_out_client:
rbd_put_client(rbdc); rbd_put_client(rbdc);
err_out_args: err_out_args:
if (ceph_opts) if (ceph_opts)
ceph_destroy_options(ceph_opts); ceph_destroy_options(ceph_opts);
kfree(rbd_opts); kfree(rbd_opts);
rbd_spec_put(spec); rbd_spec_put(spec);
err_out_mem: err_out_module:
kfree(rbd_dev); module_put(THIS_MODULE);
dout("Error adding device %s\n", buf); dout("Error adding device %s\n", buf);
module_put(THIS_MODULE);
return (ssize_t) rc; return (ssize_t) rc;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册