diff options
author | Alex Elder <elder@inktank.com> | 2012-07-10 21:30:10 -0400 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2012-07-30 21:21:45 -0400 |
commit | 4e891e0af0f0011c90067373c46d7228568ec079 (patch) | |
tree | 8697591dc252aef8bce4a349c5f254995f8d3677 /drivers/block/rbd.c | |
parent | 6139919133377652992a5fe134e22abce3e9c25e (diff) |
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: Alex Elder <elder@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'drivers/block/rbd.c')
-rw-r--r-- | drivers/block/rbd.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 30eb01e300a4..aba0d71a0345 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c | |||
@@ -2029,15 +2029,21 @@ static int rbd_register_snap_dev(struct rbd_snap *snap, | |||
2029 | return ret; | 2029 | return ret; |
2030 | } | 2030 | } |
2031 | 2031 | ||
2032 | static int __rbd_add_snap_dev(struct rbd_device *rbd_dev, | 2032 | static struct rbd_snap *__rbd_add_snap_dev(struct rbd_device *rbd_dev, |
2033 | int i, const char *name, | 2033 | int i, const char *name) |
2034 | struct rbd_snap **snapp) | ||
2035 | { | 2034 | { |
2035 | struct rbd_snap *snap; | ||
2036 | int ret; | 2036 | int ret; |
2037 | struct rbd_snap *snap = kzalloc(sizeof(*snap), GFP_KERNEL); | 2037 | |
2038 | snap = kzalloc(sizeof (*snap), GFP_KERNEL); | ||
2038 | if (!snap) | 2039 | if (!snap) |
2039 | return -ENOMEM; | 2040 | return ERR_PTR(-ENOMEM); |
2041 | |||
2042 | ret = -ENOMEM; | ||
2040 | snap->name = kstrdup(name, GFP_KERNEL); | 2043 | snap->name = kstrdup(name, GFP_KERNEL); |
2044 | if (!snap->name) | ||
2045 | goto err; | ||
2046 | |||
2041 | snap->size = rbd_dev->header.snap_sizes[i]; | 2047 | snap->size = rbd_dev->header.snap_sizes[i]; |
2042 | snap->id = rbd_dev->header.snapc->snaps[i]; | 2048 | snap->id = rbd_dev->header.snapc->snaps[i]; |
2043 | if (device_is_registered(&rbd_dev->dev)) { | 2049 | if (device_is_registered(&rbd_dev->dev)) { |
@@ -2045,12 +2051,14 @@ static int __rbd_add_snap_dev(struct rbd_device *rbd_dev, | |||
2045 | if (ret < 0) | 2051 | if (ret < 0) |
2046 | goto err; | 2052 | goto err; |
2047 | } | 2053 | } |
2048 | *snapp = snap; | 2054 | |
2049 | return 0; | 2055 | return snap; |
2056 | |||
2050 | err: | 2057 | err: |
2051 | kfree(snap->name); | 2058 | kfree(snap->name); |
2052 | kfree(snap); | 2059 | kfree(snap); |
2053 | return ret; | 2060 | |
2061 | return ERR_PTR(ret); | ||
2054 | } | 2062 | } |
2055 | 2063 | ||
2056 | /* | 2064 | /* |
@@ -2083,7 +2091,6 @@ static int __rbd_init_snaps_header(struct rbd_device *rbd_dev) | |||
2083 | const char *name, *first_name; | 2091 | const char *name, *first_name; |
2084 | int i = rbd_dev->header.total_snaps; | 2092 | int i = rbd_dev->header.total_snaps; |
2085 | struct rbd_snap *snap, *old_snap = NULL; | 2093 | struct rbd_snap *snap, *old_snap = NULL; |
2086 | int ret; | ||
2087 | struct list_head *p, *n; | 2094 | struct list_head *p, *n; |
2088 | 2095 | ||
2089 | first_name = rbd_dev->header.snap_names; | 2096 | first_name = rbd_dev->header.snap_names; |
@@ -2126,9 +2133,9 @@ static int __rbd_init_snaps_header(struct rbd_device *rbd_dev) | |||
2126 | if (cur_id >= old_snap->id) | 2133 | if (cur_id >= old_snap->id) |
2127 | break; | 2134 | break; |
2128 | /* a new snapshot */ | 2135 | /* a new snapshot */ |
2129 | ret = __rbd_add_snap_dev(rbd_dev, i - 1, name, &snap); | 2136 | snap = __rbd_add_snap_dev(rbd_dev, i - 1, name); |
2130 | if (ret < 0) | 2137 | if (IS_ERR(snap)) |
2131 | return ret; | 2138 | return PTR_ERR(snap); |
2132 | 2139 | ||
2133 | /* note that we add it backward so using n and not p */ | 2140 | /* note that we add it backward so using n and not p */ |
2134 | list_add(&snap->node, n); | 2141 | list_add(&snap->node, n); |
@@ -2142,9 +2149,9 @@ static int __rbd_init_snaps_header(struct rbd_device *rbd_dev) | |||
2142 | WARN_ON(1); | 2149 | WARN_ON(1); |
2143 | return -EINVAL; | 2150 | return -EINVAL; |
2144 | } | 2151 | } |
2145 | ret = __rbd_add_snap_dev(rbd_dev, i - 1, name, &snap); | 2152 | snap = __rbd_add_snap_dev(rbd_dev, i - 1, name); |
2146 | if (ret < 0) | 2153 | if (IS_ERR(snap)) |
2147 | return ret; | 2154 | return PTR_ERR(snap); |
2148 | list_add(&snap->node, &rbd_dev->snaps); | 2155 | list_add(&snap->node, &rbd_dev->snaps); |
2149 | } | 2156 | } |
2150 | 2157 | ||