mirror of
https://github.com/followmsi/android_kernel_google_msm.git
synced 2024-11-06 23:17:41 +00:00
rbd: encapsulate argument parsing for rbd_add()
Move the code that parses the arguments provided to rbd_add() (which are supplied via /sys/bus/rbd/add) into a separate function. Also rename the "mon_dev_name" variable in rbd_add() to be "mon_addrs". The variable represents a list of one or more comma-separated monitor IP addresses, each with an optional port number. I think "mon_addrs" captures that notion a little better. Signed-off-by: Alex Elder <elder@dreamhost.com>
This commit is contained in:
parent
27cc25943f
commit
a725f65e52
1 changed files with 43 additions and 27 deletions
|
@ -2220,12 +2220,43 @@ static void rbd_id_put(struct rbd_device *rbd_dev)
|
||||||
atomic64_cmpxchg(&rbd_id_max, rbd_id, max_id);
|
atomic64_cmpxchg(&rbd_id_max, rbd_id, max_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This fills in the pool_name, obj, obj_len, snap_name, obj_len,
|
||||||
|
* rbd_dev, rbd_md_name, and name fields of the given rbd_dev, based
|
||||||
|
* on the list of monitor addresses and other options provided via
|
||||||
|
* /sys/bus/rbd/add.
|
||||||
|
*/
|
||||||
|
static int rbd_add_parse_args(struct rbd_device *rbd_dev,
|
||||||
|
const char *buf,
|
||||||
|
char *mon_addrs,
|
||||||
|
char *options)
|
||||||
|
{
|
||||||
|
if (sscanf(buf, "%" __stringify(RBD_MAX_OPT_LEN) "s "
|
||||||
|
"%" __stringify(RBD_MAX_OPT_LEN) "s "
|
||||||
|
"%" __stringify(RBD_MAX_POOL_NAME_LEN) "s "
|
||||||
|
"%" __stringify(RBD_MAX_OBJ_NAME_LEN) "s"
|
||||||
|
"%" __stringify(RBD_MAX_SNAP_NAME_LEN) "s",
|
||||||
|
mon_addrs, options, rbd_dev->pool_name,
|
||||||
|
rbd_dev->obj, rbd_dev->snap_name) < 4)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (rbd_dev->snap_name[0] == 0)
|
||||||
|
memcpy(rbd_dev->snap_name, RBD_SNAP_HEAD_NAME,
|
||||||
|
sizeof (RBD_SNAP_HEAD_NAME));
|
||||||
|
|
||||||
|
rbd_dev->obj_len = strlen(rbd_dev->obj);
|
||||||
|
snprintf(rbd_dev->obj_md_name, sizeof(rbd_dev->obj_md_name), "%s%s",
|
||||||
|
rbd_dev->obj, RBD_SUFFIX);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static ssize_t rbd_add(struct bus_type *bus,
|
static ssize_t rbd_add(struct bus_type *bus,
|
||||||
const char *buf,
|
const char *buf,
|
||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
struct rbd_device *rbd_dev;
|
struct rbd_device *rbd_dev;
|
||||||
char *mon_dev_name = NULL;
|
char *mon_addrs = NULL;
|
||||||
char *options = NULL;
|
char *options = NULL;
|
||||||
struct ceph_osd_client *osdc;
|
struct ceph_osd_client *osdc;
|
||||||
int rc = -ENOMEM;
|
int rc = -ENOMEM;
|
||||||
|
@ -2236,8 +2267,8 @@ static ssize_t rbd_add(struct bus_type *bus,
|
||||||
rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL);
|
rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL);
|
||||||
if (!rbd_dev)
|
if (!rbd_dev)
|
||||||
goto err_nomem;
|
goto err_nomem;
|
||||||
mon_dev_name = kmalloc(count, GFP_KERNEL);
|
mon_addrs = kmalloc(count, GFP_KERNEL);
|
||||||
if (!mon_dev_name)
|
if (!mon_addrs)
|
||||||
goto err_nomem;
|
goto err_nomem;
|
||||||
options = kmalloc(count, GFP_KERNEL);
|
options = kmalloc(count, GFP_KERNEL);
|
||||||
if (!options)
|
if (!options)
|
||||||
|
@ -2253,30 +2284,15 @@ static ssize_t rbd_add(struct bus_type *bus,
|
||||||
/* generate unique id: find highest unique id, add one */
|
/* generate unique id: find highest unique id, add one */
|
||||||
rbd_id_get(rbd_dev);
|
rbd_id_get(rbd_dev);
|
||||||
|
|
||||||
/* parse add command */
|
/* Fill in the device name, now that we have its id. */
|
||||||
if (sscanf(buf, "%" __stringify(RBD_MAX_OPT_LEN) "s "
|
|
||||||
"%" __stringify(RBD_MAX_OPT_LEN) "s "
|
|
||||||
"%" __stringify(RBD_MAX_POOL_NAME_LEN) "s "
|
|
||||||
"%" __stringify(RBD_MAX_OBJ_NAME_LEN) "s"
|
|
||||||
"%" __stringify(RBD_MAX_SNAP_NAME_LEN) "s",
|
|
||||||
mon_dev_name, options, rbd_dev->pool_name,
|
|
||||||
rbd_dev->obj, rbd_dev->snap_name) < 4) {
|
|
||||||
rc = -EINVAL;
|
|
||||||
goto err_put_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rbd_dev->snap_name[0] == 0)
|
|
||||||
memcpy(rbd_dev->snap_name, RBD_SNAP_HEAD_NAME,
|
|
||||||
sizeof (RBD_SNAP_HEAD_NAME));
|
|
||||||
|
|
||||||
rbd_dev->obj_len = strlen(rbd_dev->obj);
|
|
||||||
snprintf(rbd_dev->obj_md_name, sizeof(rbd_dev->obj_md_name), "%s%s",
|
|
||||||
rbd_dev->obj, RBD_SUFFIX);
|
|
||||||
|
|
||||||
/* 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);
|
||||||
|
|
||||||
rbd_dev->rbd_client = rbd_get_client(mon_dev_name, options);
|
/* parse add command */
|
||||||
|
rc = rbd_add_parse_args(rbd_dev, buf, mon_addrs, options);
|
||||||
|
if (rc)
|
||||||
|
goto err_put_id;
|
||||||
|
|
||||||
|
rbd_dev->rbd_client = rbd_get_client(mon_addrs, options);
|
||||||
if (IS_ERR(rbd_dev->rbd_client)) {
|
if (IS_ERR(rbd_dev->rbd_client)) {
|
||||||
rc = PTR_ERR(rbd_dev->rbd_client);
|
rc = PTR_ERR(rbd_dev->rbd_client);
|
||||||
goto err_put_id;
|
goto err_put_id;
|
||||||
|
@ -2317,7 +2333,7 @@ err_out_bus:
|
||||||
|
|
||||||
rbd_bus_del_dev(rbd_dev);
|
rbd_bus_del_dev(rbd_dev);
|
||||||
kfree(options);
|
kfree(options);
|
||||||
kfree(mon_dev_name);
|
kfree(mon_addrs);
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
err_out_blkdev:
|
err_out_blkdev:
|
||||||
|
@ -2328,7 +2344,7 @@ err_put_id:
|
||||||
rbd_id_put(rbd_dev);
|
rbd_id_put(rbd_dev);
|
||||||
err_nomem:
|
err_nomem:
|
||||||
kfree(options);
|
kfree(options);
|
||||||
kfree(mon_dev_name);
|
kfree(mon_addrs);
|
||||||
kfree(rbd_dev);
|
kfree(rbd_dev);
|
||||||
|
|
||||||
dout("Error adding device %s\n", buf);
|
dout("Error adding device %s\n", buf);
|
||||||
|
|
Loading…
Reference in a new issue