aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/rbd.c
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2013-04-26 16:44:36 -0400
committerSage Weil <sage@inktank.com>2013-05-02 00:19:50 -0400
commit05a46afdc7f0f73d42dcecd8ee80f9558b4c38f7 (patch)
treed672f8caa4264b9c353599c2320915f5571f5920 /drivers/block/rbd.c
parent124afba25d58e2b52d7d4bad993065572a28d57f (diff)
rbd: encapsulate removing parent devices
Encapsulate the code that removes an rbd device's parent images into a new function, rbd_dev_remove_parent(). 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.c45
1 files changed, 26 insertions, 19 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index c80fc1a3a604..87ef01189b83 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -427,8 +427,9 @@ void rbd_warn(struct rbd_device *rbd_dev, const char *fmt, ...)
427# define rbd_assert(expr) ((void) 0) 427# define rbd_assert(expr) ((void) 0)
428#endif /* !RBD_DEBUG */ 428#endif /* !RBD_DEBUG */
429 429
430static void rbd_img_parent_read(struct rbd_obj_request *obj_request);
431static int rbd_img_obj_request_submit(struct rbd_obj_request *obj_request); 430static int rbd_img_obj_request_submit(struct rbd_obj_request *obj_request);
431static void rbd_img_parent_read(struct rbd_obj_request *obj_request);
432static void rbd_dev_remove_parent(struct rbd_device *rbd_dev);
432 433
433static int rbd_dev_refresh(struct rbd_device *rbd_dev, u64 *hver); 434static int rbd_dev_refresh(struct rbd_device *rbd_dev, u64 *hver);
434static int rbd_dev_v2_refresh(struct rbd_device *rbd_dev, u64 *hver); 435static int rbd_dev_v2_refresh(struct rbd_device *rbd_dev, u64 *hver);
@@ -4988,6 +4989,29 @@ static void __rbd_remove(struct rbd_device *rbd_dev)
4988 rbd_bus_del_dev(rbd_dev); 4989 rbd_bus_del_dev(rbd_dev);
4989} 4990}
4990 4991
4992static void rbd_dev_remove_parent(struct rbd_device *rbd_dev)
4993{
4994 while (rbd_dev->parent_spec) {
4995 struct rbd_device *first = rbd_dev;
4996 struct rbd_device *second = first->parent;
4997 struct rbd_device *third;
4998
4999 /*
5000 * Follow to the parent with no grandparent and
5001 * remove it.
5002 */
5003 while (second && (third = second->parent)) {
5004 first = second;
5005 second = third;
5006 }
5007 __rbd_remove(second);
5008 rbd_spec_put(first->parent_spec);
5009 first->parent_spec = NULL;
5010 first->parent_overlap = 0;
5011 first->parent = NULL;
5012 }
5013}
5014
4991static ssize_t rbd_remove(struct bus_type *bus, 5015static ssize_t rbd_remove(struct bus_type *bus,
4992 const char *buf, 5016 const char *buf,
4993 size_t count) 5017 size_t count)
@@ -5023,25 +5047,8 @@ static ssize_t rbd_remove(struct bus_type *bus,
5023 if (ret < 0) 5047 if (ret < 0)
5024 goto done; 5048 goto done;
5025 5049
5026 while (rbd_dev->parent_spec) { 5050 rbd_dev_remove_parent(rbd_dev);
5027 struct rbd_device *first = rbd_dev;
5028 struct rbd_device *second = first->parent;
5029 struct rbd_device *third;
5030 5051
5031 /*
5032 * Follow to the parent with no grandparent and
5033 * remove it.
5034 */
5035 while (second && (third = second->parent)) {
5036 first = second;
5037 second = third;
5038 }
5039 __rbd_remove(second);
5040 rbd_spec_put(first->parent_spec);
5041 first->parent_spec = NULL;
5042 first->parent_overlap = 0;
5043 first->parent = NULL;
5044 }
5045 __rbd_remove(rbd_dev); 5052 __rbd_remove(rbd_dev);
5046 5053
5047done: 5054done: