aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/rbd.c
diff options
context:
space:
mode:
authorJosh Durgin <josh.durgin@inktank.com>2013-09-04 20:57:31 -0400
committerJosh Durgin <josh.durgin@inktank.com>2013-09-09 14:16:44 -0400
commitda6a6b63978d45f9ae582d1f362f182012da3a22 (patch)
tree536126934cdf348b186d1505c047fb967f71f812 /drivers/block/rbd.c
parentefadc98aab674153709cc357ba565f04e3164fcd (diff)
rbd: fix error handling from rbd_snap_name()
rbd_snap_name() calls rbd_dev_v{1,2}_snap_name() depending on the format of the image. The format 1 version returns NULL on error, which is handled by the caller. The format 2 version returns an ERR_PTR, which the caller of rbd_snap_name() does not expect. Fortunately this is unlikely to occur in practice because rbd_snap_id_by_name() is called before rbd_snap_name(). This would hit similar errors to rbd_snap_name() (like the snapshot not existing) and return early, so rbd_snap_name() would not hit an error unless the snapshot was removed between the two calls or memory was exhausted. Use an ERR_PTR in rbd_dev_v1_snap_name() so that the specific error can be propagated, and it is consistent with rbd_dev_v2_snap_name(). Handle the ERR_PTR in the only rbd_snap_name() caller. Suggested-by: Alex Elder <alex.elder@linaro.org> Signed-off-by: Josh Durgin <josh.durgin@inktank.com> Reviewed-by: Alex Elder <elder@linaro.org>
Diffstat (limited to 'drivers/block/rbd.c')
-rw-r--r--drivers/block/rbd.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 626a7136fb2f..2f00778e1024 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -927,12 +927,14 @@ static const char *rbd_dev_v1_snap_name(struct rbd_device *rbd_dev,
927 u64 snap_id) 927 u64 snap_id)
928{ 928{
929 u32 which; 929 u32 which;
930 const char *snap_name;
930 931
931 which = rbd_dev_snap_index(rbd_dev, snap_id); 932 which = rbd_dev_snap_index(rbd_dev, snap_id);
932 if (which == BAD_SNAP_INDEX) 933 if (which == BAD_SNAP_INDEX)
933 return NULL; 934 return ERR_PTR(-ENOENT);
934 935
935 return _rbd_dev_v1_snap_name(rbd_dev, which); 936 snap_name = _rbd_dev_v1_snap_name(rbd_dev, which);
937 return snap_name ? snap_name : ERR_PTR(-ENOMEM);
936} 938}
937 939
938static const char *rbd_snap_name(struct rbd_device *rbd_dev, u64 snap_id) 940static const char *rbd_snap_name(struct rbd_device *rbd_dev, u64 snap_id)
@@ -4163,8 +4165,8 @@ static int rbd_dev_spec_update(struct rbd_device *rbd_dev)
4163 /* Look up the snapshot name, and make a copy */ 4165 /* Look up the snapshot name, and make a copy */
4164 4166
4165 snap_name = rbd_snap_name(rbd_dev, spec->snap_id); 4167 snap_name = rbd_snap_name(rbd_dev, spec->snap_id);
4166 if (!snap_name) { 4168 if (IS_ERR(snap_name)) {
4167 ret = -ENOMEM; 4169 ret = PTR_ERR(snap_name);
4168 goto out_err; 4170 goto out_err;
4169 } 4171 }
4170 4172