Commit dc79b113 authored by Alex Elder's avatar Alex Elder

rbd: have rbd_add_parse_args() return error

Change the interface to rbd_add_parse_args() so it returns an
error code rather than a pointer.  Return the ceph_options result
via a pointer whose address is passed as an argument.
Signed-off-by: default avatarAlex Elder <elder@inktank.com>
Reviewed-by: default avatarJosh Durgin <josh.durgin@inktank.com>
parent 4e9afeba
...@@ -2841,30 +2841,31 @@ static inline char *dup_token(const char **buf, size_t *lenp) ...@@ -2841,30 +2841,31 @@ static inline char *dup_token(const char **buf, size_t *lenp)
* *
* Note: rbd_dev is assumed to have been initially zero-filled. * Note: rbd_dev is assumed to have been initially zero-filled.
*/ */
static struct ceph_options *rbd_add_parse_args(struct rbd_device *rbd_dev, static int rbd_add_parse_args(struct rbd_device *rbd_dev,
const char *buf, const char *buf,
struct ceph_options **ceph_opts,
struct rbd_options **opts) struct rbd_options **opts)
{ {
size_t len; size_t len;
const char *mon_addrs; const char *mon_addrs;
size_t mon_addrs_size; size_t mon_addrs_size;
char *options; char *options;
struct ceph_options *err_ptr = ERR_PTR(-EINVAL);
struct ceph_options *ceph_opts;
struct rbd_options *rbd_opts = NULL; struct rbd_options *rbd_opts = NULL;
int ret;
/* The first four tokens are required */ /* The first four tokens are required */
len = next_token(&buf); len = next_token(&buf);
if (!len) if (!len)
return err_ptr; /* Missing monitor address(es) */ return -EINVAL; /* Missing monitor address(es) */
mon_addrs = buf; mon_addrs = buf;
mon_addrs_size = len + 1; mon_addrs_size = len + 1;
buf += len; buf += len;
ret = -EINVAL;
options = dup_token(&buf, NULL); options = dup_token(&buf, NULL);
if (!options) if (!options)
goto out_mem; return -ENOMEM;
if (!*options) if (!*options)
goto out_err; /* Missing options */ goto out_err; /* Missing options */
...@@ -2889,7 +2890,7 @@ static struct ceph_options *rbd_add_parse_args(struct rbd_device *rbd_dev, ...@@ -2889,7 +2890,7 @@ static struct ceph_options *rbd_add_parse_args(struct rbd_device *rbd_dev,
buf = RBD_SNAP_HEAD_NAME; /* No snapshot supplied */ buf = RBD_SNAP_HEAD_NAME; /* No snapshot supplied */
len = sizeof (RBD_SNAP_HEAD_NAME) - 1; len = sizeof (RBD_SNAP_HEAD_NAME) - 1;
} else if (len > RBD_MAX_SNAP_NAME_LEN) { } else if (len > RBD_MAX_SNAP_NAME_LEN) {
err_ptr = ERR_PTR(-ENAMETOOLONG); ret = -ENAMETOOLONG;
goto out_err; goto out_err;
} }
rbd_dev->snap_name = kmalloc(len + 1, GFP_KERNEL); rbd_dev->snap_name = kmalloc(len + 1, GFP_KERNEL);
...@@ -2906,15 +2907,19 @@ static struct ceph_options *rbd_add_parse_args(struct rbd_device *rbd_dev, ...@@ -2906,15 +2907,19 @@ static struct ceph_options *rbd_add_parse_args(struct rbd_device *rbd_dev,
rbd_opts->read_only = RBD_READ_ONLY_DEFAULT; rbd_opts->read_only = RBD_READ_ONLY_DEFAULT;
ceph_opts = ceph_parse_options(options, mon_addrs, *ceph_opts = ceph_parse_options(options, mon_addrs,
mon_addrs + mon_addrs_size - 1, mon_addrs + mon_addrs_size - 1,
parse_rbd_opts_token, rbd_opts); parse_rbd_opts_token, rbd_opts);
kfree(options); kfree(options);
if (IS_ERR(*ceph_opts)) {
ret = PTR_ERR(*ceph_opts);
goto out_err;
}
*opts = rbd_opts; *opts = rbd_opts;
return ceph_opts; return 0;
out_mem: out_mem:
err_ptr = ERR_PTR(-ENOMEM); ret = -ENOMEM;
out_err: out_err:
kfree(rbd_dev->image_name); kfree(rbd_dev->image_name);
rbd_dev->image_name = NULL; rbd_dev->image_name = NULL;
...@@ -2923,7 +2928,7 @@ static struct ceph_options *rbd_add_parse_args(struct rbd_device *rbd_dev, ...@@ -2923,7 +2928,7 @@ static struct ceph_options *rbd_add_parse_args(struct rbd_device *rbd_dev,
rbd_dev->pool_name = NULL; rbd_dev->pool_name = NULL;
kfree(options); kfree(options);
return err_ptr; return ret;
} }
/* /*
...@@ -3131,7 +3136,7 @@ static ssize_t rbd_add(struct bus_type *bus, ...@@ -3131,7 +3136,7 @@ static ssize_t rbd_add(struct bus_type *bus,
size_t count) size_t count)
{ {
struct rbd_device *rbd_dev = NULL; struct rbd_device *rbd_dev = NULL;
struct ceph_options *ceph_opts; struct ceph_options *ceph_opts = NULL;
struct rbd_options *rbd_opts = NULL; struct rbd_options *rbd_opts = NULL;
struct ceph_osd_client *osdc; struct ceph_osd_client *osdc;
int rc = -ENOMEM; int rc = -ENOMEM;
...@@ -3150,11 +3155,9 @@ static ssize_t rbd_add(struct bus_type *bus, ...@@ -3150,11 +3155,9 @@ static ssize_t rbd_add(struct bus_type *bus,
init_rwsem(&rbd_dev->header_rwsem); init_rwsem(&rbd_dev->header_rwsem);
/* parse add command */ /* parse add command */
ceph_opts = rbd_add_parse_args(rbd_dev, buf, &rbd_opts); rc = rbd_add_parse_args(rbd_dev, buf, &ceph_opts, &rbd_opts);
if (IS_ERR(ceph_opts)) { if (rc < 0)
rc = PTR_ERR(ceph_opts);
goto err_out_mem; goto err_out_mem;
}
rbd_dev->mapping.read_only = rbd_opts->read_only; rbd_dev->mapping.read_only = rbd_opts->read_only;
rc = rbd_get_client(rbd_dev, ceph_opts); rc = rbd_get_client(rbd_dev, ceph_opts);
......
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