From patchwork Fri Sep 7 13:39:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1422401 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id EB1F1DF283 for ; Fri, 7 Sep 2012 13:39:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757304Ab2IGNjT (ORCPT ); Fri, 7 Sep 2012 09:39:19 -0400 Received: from mail-ie0-f174.google.com ([209.85.223.174]:60946 "EHLO mail-ie0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758909Ab2IGNjR (ORCPT ); Fri, 7 Sep 2012 09:39:17 -0400 Received: by ieje11 with SMTP id e11so5001652iej.19 for ; Fri, 07 Sep 2012 06:39:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=00kMroXoZzlbkTVKTXItA6D96aZuG0ZGOwQnVwURIe8=; b=l75fV213Mh83eDMuGAaJ9vqGlpOcopDAue4GCZ57KKYeJYjw+3nkWk/yORCjZ7FS4o VXDn9JWOopEeRduYdFlW9DfgfdOF/5B/GsIZ4uqIMCJpGDgF/gwbwTdPv6C1JeJ8W1cc JYxIogC7MjbCMpkMBqHpOy6P4nYjPqsnCDnA2J3pniLubcp3w92GZSZ9FTLAUuvDajSJ jeLu1CKwkPuQ5jGQill52kuw6ZTGLjjy8pgeF6z3RyQ5GJi4XP2gAhgQCRJRCziQNEpP S0r2Yu3/4HTXv6Qk4ZNJQ5rkevxVsLlPQB7PNIdkP94s0VIYItdpJ7C6S1kQE525KVMu qIYA== Received: by 10.42.54.3 with SMTP id p3mr6999133icg.41.1347025156909; Fri, 07 Sep 2012 06:39:16 -0700 (PDT) Received: from [172.22.22.4] (c-71-195-31-37.hsd1.mn.comcast.net. [71.195.31.37]) by mx.google.com with ESMTPS id ch4sm8134347igb.2.2012.09.07.06.39.15 (version=SSLv3 cipher=OTHER); Fri, 07 Sep 2012 06:39:15 -0700 (PDT) Message-ID: <5049F903.4070003@inktank.com> Date: Fri, 07 Sep 2012 08:39:15 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: [PATCH 1/5] rbd: define rbd_assert() References: <5049F7F5.1070609@inktank.com> In-Reply-To: <5049F7F5.1070609@inktank.com> X-Gm-Message-State: ALoCoQk+fZK6k5lFMs8tJC/IA1c2puZXNWb7UNkJLcYyrJe7nAGv6RKjjpNChNruvxSPCWufW2+q Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org 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 Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) @@ -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; } 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;