Commit 4e891e0a authored by Alex Elder's avatar Alex Elder Committed by Sage Weil

rbd: have __rbd_add_snap_dev() return a pointer

It's not obvious whether the snapshot pointer whose address is
provided to __rbd_add_snap_dev() will be assigned by that function.
Change it to return the snapshot, or a pointer-coded errno in the
event of a failure.
Signed-off-by: default avatarAlex Elder <elder@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com> 
parent 61399191
...@@ -2029,15 +2029,21 @@ static int rbd_register_snap_dev(struct rbd_snap *snap, ...@@ -2029,15 +2029,21 @@ static int rbd_register_snap_dev(struct rbd_snap *snap,
return ret; return ret;
} }
static int __rbd_add_snap_dev(struct rbd_device *rbd_dev, static struct rbd_snap *__rbd_add_snap_dev(struct rbd_device *rbd_dev,
int i, const char *name, int i, const char *name)
struct rbd_snap **snapp)
{ {
struct rbd_snap *snap;
int ret; int ret;
struct rbd_snap *snap = kzalloc(sizeof(*snap), GFP_KERNEL);
snap = kzalloc(sizeof (*snap), GFP_KERNEL);
if (!snap) if (!snap)
return -ENOMEM; return ERR_PTR(-ENOMEM);
ret = -ENOMEM;
snap->name = kstrdup(name, GFP_KERNEL); snap->name = kstrdup(name, GFP_KERNEL);
if (!snap->name)
goto err;
snap->size = rbd_dev->header.snap_sizes[i]; snap->size = rbd_dev->header.snap_sizes[i];
snap->id = rbd_dev->header.snapc->snaps[i]; snap->id = rbd_dev->header.snapc->snaps[i];
if (device_is_registered(&rbd_dev->dev)) { if (device_is_registered(&rbd_dev->dev)) {
...@@ -2045,12 +2051,14 @@ static int __rbd_add_snap_dev(struct rbd_device *rbd_dev, ...@@ -2045,12 +2051,14 @@ static int __rbd_add_snap_dev(struct rbd_device *rbd_dev,
if (ret < 0) if (ret < 0)
goto err; goto err;
} }
*snapp = snap;
return 0; return snap;
err: err:
kfree(snap->name); kfree(snap->name);
kfree(snap); kfree(snap);
return ret;
return ERR_PTR(ret);
} }
/* /*
...@@ -2083,7 +2091,6 @@ static int __rbd_init_snaps_header(struct rbd_device *rbd_dev) ...@@ -2083,7 +2091,6 @@ static int __rbd_init_snaps_header(struct rbd_device *rbd_dev)
const char *name, *first_name; const char *name, *first_name;
int i = rbd_dev->header.total_snaps; int i = rbd_dev->header.total_snaps;
struct rbd_snap *snap, *old_snap = NULL; struct rbd_snap *snap, *old_snap = NULL;
int ret;
struct list_head *p, *n; struct list_head *p, *n;
first_name = rbd_dev->header.snap_names; first_name = rbd_dev->header.snap_names;
...@@ -2126,9 +2133,9 @@ static int __rbd_init_snaps_header(struct rbd_device *rbd_dev) ...@@ -2126,9 +2133,9 @@ static int __rbd_init_snaps_header(struct rbd_device *rbd_dev)
if (cur_id >= old_snap->id) if (cur_id >= old_snap->id)
break; break;
/* a new snapshot */ /* a new snapshot */
ret = __rbd_add_snap_dev(rbd_dev, i - 1, name, &snap); snap = __rbd_add_snap_dev(rbd_dev, i - 1, name);
if (ret < 0) if (IS_ERR(snap))
return ret; return PTR_ERR(snap);
/* note that we add it backward so using n and not p */ /* note that we add it backward so using n and not p */
list_add(&snap->node, n); list_add(&snap->node, n);
...@@ -2142,9 +2149,9 @@ static int __rbd_init_snaps_header(struct rbd_device *rbd_dev) ...@@ -2142,9 +2149,9 @@ static int __rbd_init_snaps_header(struct rbd_device *rbd_dev)
WARN_ON(1); WARN_ON(1);
return -EINVAL; return -EINVAL;
} }
ret = __rbd_add_snap_dev(rbd_dev, i - 1, name, &snap); snap = __rbd_add_snap_dev(rbd_dev, i - 1, name);
if (ret < 0) if (IS_ERR(snap))
return ret; return PTR_ERR(snap);
list_add(&snap->node, &rbd_dev->snaps); list_add(&snap->node, &rbd_dev->snaps);
} }
......
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