diff options
author | Alex Elder <elder@inktank.com> | 2012-09-06 17:00:54 -0400 |
---|---|---|
committer | Alex Elder <elder@inktank.com> | 2012-10-01 15:30:50 -0400 |
commit | aafb230ebc3bcdbbd1781f56e482ec75f7f1f263 (patch) | |
tree | f0743e2261248902a582528a65a5d82c8562be2c | |
parent | 65ccfe21dd8fb402547bb1c50bbc2737c4ef37b8 (diff) |
rbd: define rbd_assert()
Define rbd_assert() and use it in place of various BUG_ON() calls
now present in the code. By default assertion checking is enabled;
we want to do this differently at some point.
Signed-off-by: Alex Elder <elder@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
-rw-r--r-- | drivers/block/rbd.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 7ba70c49bbdb..d84b5341bea2 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c | |||
@@ -41,6 +41,8 @@ | |||
41 | 41 | ||
42 | #include "rbd_types.h" | 42 | #include "rbd_types.h" |
43 | 43 | ||
44 | #define RBD_DEBUG /* Activate rbd_assert() calls */ | ||
45 | |||
44 | /* | 46 | /* |
45 | * The basic unit of block I/O is a sector. It is interpreted in a | 47 | * The basic unit of block I/O is a sector. It is interpreted in a |
46 | * number of contexts in Linux (blk, bio, genhd), but the default is | 48 | * number of contexts in Linux (blk, bio, genhd), but the default is |
@@ -232,6 +234,18 @@ static struct device rbd_root_dev = { | |||
232 | .release = rbd_root_dev_release, | 234 | .release = rbd_root_dev_release, |
233 | }; | 235 | }; |
234 | 236 | ||
237 | #ifdef RBD_DEBUG | ||
238 | #define rbd_assert(expr) \ | ||
239 | if (unlikely(!(expr))) { \ | ||
240 | printk(KERN_ERR "\nAssertion failure in %s() " \ | ||
241 | "at line %d:\n\n" \ | ||
242 | "\trbd_assert(%s);\n\n", \ | ||
243 | __func__, __LINE__, #expr); \ | ||
244 | BUG(); \ | ||
245 | } | ||
246 | #else /* !RBD_DEBUG */ | ||
247 | # define rbd_assert(expr) ((void) 0) | ||
248 | #endif /* !RBD_DEBUG */ | ||
235 | 249 | ||
236 | static struct device *rbd_get_dev(struct rbd_device *rbd_dev) | 250 | static struct device *rbd_get_dev(struct rbd_device *rbd_dev) |
237 | { | 251 | { |
@@ -406,7 +420,8 @@ static int parse_rbd_opts_token(char *c, void *private) | |||
406 | rbd_opts->read_only = false; | 420 | rbd_opts->read_only = false; |
407 | break; | 421 | break; |
408 | default: | 422 | default: |
409 | BUG_ON(token); | 423 | rbd_assert(false); |
424 | break; | ||
410 | } | 425 | } |
411 | return 0; | 426 | return 0; |
412 | } | 427 | } |
@@ -705,7 +720,7 @@ static u64 rbd_segment_length(struct rbd_device *rbd_dev, | |||
705 | 720 | ||
706 | offset &= segment_size - 1; | 721 | offset &= segment_size - 1; |
707 | 722 | ||
708 | BUG_ON(length > U64_MAX - offset); | 723 | rbd_assert(length <= U64_MAX - offset); |
709 | if (offset + length > segment_size) | 724 | if (offset + length > segment_size) |
710 | length = segment_size - offset; | 725 | length = segment_size - offset; |
711 | 726 | ||
@@ -842,7 +857,7 @@ static struct bio *bio_chain_clone(struct bio **old, struct bio **next, | |||
842 | total += tmp->bi_size; | 857 | total += tmp->bi_size; |
843 | } | 858 | } |
844 | 859 | ||
845 | BUG_ON(total < len); | 860 | rbd_assert(total == len); |
846 | 861 | ||
847 | *old = old_chain; | 862 | *old = old_chain; |
848 | 863 | ||
@@ -1101,7 +1116,7 @@ static int rbd_req_sync_op(struct rbd_device *rbd_dev, | |||
1101 | struct page **pages; | 1116 | struct page **pages; |
1102 | int num_pages; | 1117 | int num_pages; |
1103 | 1118 | ||
1104 | BUG_ON(ops == NULL); | 1119 | rbd_assert(ops != NULL); |
1105 | 1120 | ||
1106 | num_pages = calc_pages_for(ofs , len); | 1121 | num_pages = calc_pages_for(ofs , len); |
1107 | pages = ceph_alloc_page_vector(num_pages, GFP_KERNEL); | 1122 | pages = ceph_alloc_page_vector(num_pages, GFP_KERNEL); |
@@ -1163,7 +1178,7 @@ static int rbd_do_op(struct request *rq, | |||
1163 | /* we've taken care of segment sizes earlier when we | 1178 | /* we've taken care of segment sizes earlier when we |
1164 | cloned the bios. We should never have a segment | 1179 | cloned the bios. We should never have a segment |
1165 | truncated at this point */ | 1180 | truncated at this point */ |
1166 | BUG_ON(seg_len < len); | 1181 | rbd_assert(seg_len == len); |
1167 | 1182 | ||
1168 | ret = rbd_do_request(rq, rbd_dev, snapc, snapid, | 1183 | ret = rbd_do_request(rq, rbd_dev, snapc, snapid, |
1169 | seg_name, seg_ofs, seg_len, | 1184 | seg_name, seg_ofs, seg_len, |
@@ -2186,7 +2201,7 @@ static int __rbd_init_snaps_header(struct rbd_device *rbd_dev) | |||
2186 | : CEPH_NOSNAP; | 2201 | : CEPH_NOSNAP; |
2187 | snap = links != head ? list_entry(links, struct rbd_snap, node) | 2202 | snap = links != head ? list_entry(links, struct rbd_snap, node) |
2188 | : NULL; | 2203 | : NULL; |
2189 | BUG_ON(snap && snap->id == CEPH_NOSNAP); | 2204 | rbd_assert(!snap || snap->id != CEPH_NOSNAP); |
2190 | 2205 | ||
2191 | if (snap_id == CEPH_NOSNAP || (snap && snap->id > snap_id)) { | 2206 | if (snap_id == CEPH_NOSNAP || (snap && snap->id > snap_id)) { |
2192 | struct list_head *next = links->next; | 2207 | struct list_head *next = links->next; |
@@ -2222,8 +2237,9 @@ static int __rbd_init_snaps_header(struct rbd_device *rbd_dev) | |||
2222 | } else { | 2237 | } else { |
2223 | /* Already have this one */ | 2238 | /* Already have this one */ |
2224 | 2239 | ||
2225 | BUG_ON(snap->size != rbd_dev->header.snap_sizes[index]); | 2240 | rbd_assert(snap->size == |
2226 | BUG_ON(strcmp(snap->name, snap_name)); | 2241 | rbd_dev->header.snap_sizes[index]); |
2242 | rbd_assert(!strcmp(snap->name, snap_name)); | ||
2227 | 2243 | ||
2228 | /* Done with this list entry; advance */ | 2244 | /* Done with this list entry; advance */ |
2229 | 2245 | ||
@@ -2313,7 +2329,7 @@ static void rbd_id_put(struct rbd_device *rbd_dev) | |||
2313 | int rbd_id = rbd_dev->dev_id; | 2329 | int rbd_id = rbd_dev->dev_id; |
2314 | int max_id; | 2330 | int max_id; |
2315 | 2331 | ||
2316 | BUG_ON(rbd_id < 1); | 2332 | rbd_assert(rbd_id > 0); |
2317 | 2333 | ||
2318 | spin_lock(&rbd_dev_list_lock); | 2334 | spin_lock(&rbd_dev_list_lock); |
2319 | list_del_init(&rbd_dev->node); | 2335 | list_del_init(&rbd_dev->node); |
@@ -2705,6 +2721,7 @@ static ssize_t rbd_remove(struct bus_type *bus, | |||
2705 | 2721 | ||
2706 | done: | 2722 | done: |
2707 | mutex_unlock(&ctl_mutex); | 2723 | mutex_unlock(&ctl_mutex); |
2724 | |||
2708 | return ret; | 2725 | return ret; |
2709 | } | 2726 | } |
2710 | 2727 | ||