From: Josh Durgin <josh.durgin@inktank.com>
To: Alex Elder <elder@inktank.com>
Cc: ceph-devel@vger.kernel.org
Subject: Re: [PATCH 1/5] rbd: define rbd_assert()
Date: Fri, 07 Sep 2012 11:13:35 -0700 [thread overview]
Message-ID: <504A394F.5090200@inktank.com> (raw)
In-Reply-To: <5049F903.4070003@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
On 09/07/2012 06:39 AM, Alex Elder wrote:
> 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>
> ---
> drivers/block/rbd.c | 35 ++++++++++++++++++++++++++---------
> 1 file changed, 26 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index 7ba70c4..d84b534 100644
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -41,6 +41,8 @@
>
> #include "rbd_types.h"
>
> +#define RBD_DEBUG /* Activate rbd_assert() calls */
> +
> /*
> * The basic unit of block I/O is a sector. It is interpreted in a
> * number of contexts in Linux (blk, bio, genhd), but the default is
> @@ -232,6 +234,18 @@ static struct device rbd_root_dev = {
> .release = rbd_root_dev_release,
> };
>
> +#ifdef RBD_DEBUG
> +#define rbd_assert(expr) \
> + if (unlikely(!(expr))) { \
> + printk(KERN_ERR "\nAssertion failure in %s() " \
> + "at line %d:\n\n" \
> + "\trbd_assert(%s);\n\n", \
> + __func__, __LINE__, #expr); \
> + BUG(); \
> + }
> +#else /* !RBD_DEBUG */
> +# define rbd_assert(expr) ((void) 0)
> +#endif /* !RBD_DEBUG */
>
> static struct device *rbd_get_dev(struct rbd_device *rbd_dev)
> {
> @@ -406,7 +420,8 @@ static int parse_rbd_opts_token(char *c, void *private)
> rbd_opts->read_only = false;
> break;
> default:
> - BUG_ON(token);
> + rbd_assert(false);
> + break;
> }
> return 0;
> }
> @@ -705,7 +720,7 @@ static u64 rbd_segment_length(struct rbd_device
> *rbd_dev,
>
> offset &= segment_size - 1;
>
> - BUG_ON(length > U64_MAX - offset);
> + rbd_assert(length <= U64_MAX - offset);
> if (offset + length > segment_size)
> length = segment_size - offset;
>
> @@ -842,7 +857,7 @@ static struct bio *bio_chain_clone(struct bio **old,
> struct bio **next,
> total += tmp->bi_size;
> }
>
> - BUG_ON(total < len);
> + rbd_assert(total == len);
>
> *old = old_chain;
>
> @@ -1101,7 +1116,7 @@ static int rbd_req_sync_op(struct rbd_device *rbd_dev,
> struct page **pages;
> int num_pages;
>
> - BUG_ON(ops == NULL);
> + rbd_assert(ops != NULL);
>
> num_pages = calc_pages_for(ofs , len);
> pages = ceph_alloc_page_vector(num_pages, GFP_KERNEL);
> @@ -1163,7 +1178,7 @@ static int rbd_do_op(struct request *rq,
> /* we've taken care of segment sizes earlier when we
> cloned the bios. We should never have a segment
> truncated at this point */
> - BUG_ON(seg_len < len);
> + rbd_assert(seg_len == len);
>
> ret = rbd_do_request(rq, rbd_dev, snapc, snapid,
> seg_name, seg_ofs, seg_len,
> @@ -2186,7 +2201,7 @@ static int __rbd_init_snaps_header(struct
> rbd_device *rbd_dev)
> : CEPH_NOSNAP;
> snap = links != head ? list_entry(links, struct rbd_snap, node)
> : NULL;
> - BUG_ON(snap && snap->id == CEPH_NOSNAP);
> + rbd_assert(!snap || snap->id != CEPH_NOSNAP);
>
> if (snap_id == CEPH_NOSNAP || (snap && snap->id > snap_id)) {
> struct list_head *next = links->next;
> @@ -2222,8 +2237,9 @@ static int __rbd_init_snaps_header(struct
> rbd_device *rbd_dev)
> } else {
> /* Already have this one */
>
> - BUG_ON(snap->size != rbd_dev->header.snap_sizes[index]);
> - BUG_ON(strcmp(snap->name, snap_name));
> + rbd_assert(snap->size ==
> + rbd_dev->header.snap_sizes[index]);
> + rbd_assert(!strcmp(snap->name, snap_name));
>
> /* Done with this list entry; advance */
>
> @@ -2313,7 +2329,7 @@ static void rbd_id_put(struct rbd_device *rbd_dev)
> int rbd_id = rbd_dev->dev_id;
> int max_id;
>
> - BUG_ON(rbd_id < 1);
> + rbd_assert(rbd_id > 0);
>
> spin_lock(&rbd_dev_list_lock);
> list_del_init(&rbd_dev->node);
> @@ -2705,6 +2721,7 @@ static ssize_t rbd_remove(struct bus_type *bus,
>
> done:
> mutex_unlock(&ctl_mutex);
> +
> return ret;
> }
>
next prev parent reply other threads:[~2012-09-07 18:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-07 13:34 [PATCH 0/5] rbd: code cleanup Alex Elder
2012-09-07 13:39 ` [PATCH 1/5] rbd: define rbd_assert() Alex Elder
2012-09-07 18:13 ` Josh Durgin [this message]
2012-09-07 13:39 ` [PATCH 2/5] rbd: rename rbd_id_get() Alex Elder
2012-09-07 18:14 ` Josh Durgin
2012-09-07 13:39 ` [PATCH 3/5] rbd: rename __rbd_init_snaps_header() Alex Elder
2012-09-07 18:16 ` Josh Durgin
2012-09-07 13:39 ` [PATCH 4/5] rbd: kill rbd_dev->q Alex Elder
2012-09-07 18:16 ` Josh Durgin
2012-09-07 13:39 ` [PATCH 5/5] rbd: kill rbd_image_header->total_snaps Alex Elder
2012-09-07 18:17 ` Josh Durgin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=504A394F.5090200@inktank.com \
--to=josh.durgin@inktank.com \
--cc=ceph-devel@vger.kernel.org \
--cc=elder@inktank.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.