Commit 7931b600 authored by Mark Fasheh's avatar Mark Fasheh

- replace if (condition) abort; in files with abort_on(condition)

- add a new macro abort_lineno for places where we just want a naked() abort
  call
parent 32f15c63
......@@ -20,6 +20,7 @@
#include <gcrypt.h>
#include "csum.h"
#include "debug.h"
#define HASH_FUNC GCRY_MD_SHA256
......@@ -52,8 +53,7 @@ int init_hash(void)
if (!digest_len)
return 1;
if (digest_len == 0 || digest_len > DIGEST_LEN_MAX)
abort();
abort_on(digest_len == 0 || digest_len > DIGEST_LEN_MAX);
return 0;
}
......
......@@ -20,6 +20,7 @@
#include <mhash.h>
#include "csum.h"
#include "debug.h"
static MHASH td;
......@@ -30,8 +31,7 @@ unsigned int digest_len = 0;
void checksum_block(char *buf, int len, unsigned char *digest)
{
td = mhash_init(HASH_FUNC);
if (td == MHASH_FAILED)
abort();
abort_on(td == MHASH_FAILED);
mhash(td, buf, len);
mhash_deinit(td, digest);
......@@ -43,8 +43,7 @@ int init_hash(void)
if (!digest_len)
return 1;
if (digest_len == 0 || digest_len > DIGEST_LEN_MAX)
abort();
abort_on(digest_len == 0 || digest_len > DIGEST_LEN_MAX);
return 0;
}
......
......@@ -8,6 +8,11 @@ extern int debug;
#define dprintf(args...) if (debug) printf(args)
#define vprintf(args...) if (verbose) printf(args)
#define abort_lineno() do { \
printf("ERROR: %s:%d\n", __FILE__, __LINE__); \
abort(); \
} while (0)
#define abort_on(condition) do { \
if (condition) { \
printf("ERROR: %s:%d\n", __FILE__, __LINE__);\
......
......@@ -178,8 +178,7 @@ int add_extent_to_dedupe(struct dedupe_ctxt *ctxt, uint64_t loff,
{
struct dedupe_req *req = new_dedupe_req(file, loff);
if (ctxt->num_queued >= ctxt->max_queable)
abort();
abort_on(ctxt->num_queued >= ctxt->max_queable);
if (req == NULL)
return -1;
......@@ -198,8 +197,7 @@ static void add_dedupe_request(struct dedupe_ctxt *ctxt,
struct btrfs_ioctl_same_extent_info *info;
struct filerec *file = req->req_file;
if (same->dest_count >= ctxt->max_queable)
abort();
abort_on(same->dest_count >= ctxt->max_queable);
req->req_idx = same_idx;
info = &same->info[same_idx];
......
......@@ -46,7 +46,7 @@ static void insert_filerec(struct filerec *file)
else if (file->inum > tmp->inum)
p = &(*p)->rb_right;
else
abort(); /* We should never find a duplicate */
abort_lineno(); /* We should never find a duplicate */
}
rb_link_node(&file->inum_node, parent, p);
......
......@@ -29,6 +29,7 @@
#include "filerec.h"
#include "hash-tree.h"
#include "debug.h"
static void insert_block_list(struct hash_tree *tree,
struct dupe_blocks_list *list)
......@@ -48,7 +49,7 @@ static void insert_block_list(struct hash_tree *tree,
p = &(*p)->rb_left;
else if (cmp > 0)
p = &(*p)->rb_right;
else abort(); /* We should never find a duplicate */
else abort_lineno(); /* We should never find a duplicate */
}
rb_link_node(&list->dl_node, parent, p);
......@@ -119,8 +120,7 @@ static void remove_hashed_block(struct hash_tree *tree,
{
struct dupe_blocks_list *blocklist = block->b_parent;
if (blocklist->dl_num_elem == 0)
abort();
abort_on(blocklist->dl_num_elem == 0);
list_del(&block->b_file_next);
list_del(&block->b_list);
......
......@@ -29,6 +29,7 @@
#include "filerec.h"
#include "results-tree.h"
#include "debug.h"
static struct extent *_alloc_extent(void)
{
......@@ -92,7 +93,7 @@ static void insert_dupe_extents(struct results_tree *res,
else if (cmp > 0)
p = &(*p)->rb_right;
else
abort(); /* We should never find a duplicate */
abort_lineno(); /* We should never find a duplicate */
}
}
......@@ -169,8 +170,7 @@ int insert_result(struct results_tree *res, unsigned char *digest,
add_score = 0;
}
if (dext->de_len != len)
abort();
abort_on(dext->de_len != len);
insert_extent_list_free(dext, &e0);
insert_extent_list_free(dext, &e1);
......@@ -209,8 +209,8 @@ again:
if (p->de_num_dupes == 1) {
/* It doesn't make sense to have one extent in a dup
* list. */
if (list_empty(&p->de_extents))
abort(); /* Another potential logic error */
abort_on(list_empty(&p->de_extents));/* logic error */
extent = list_entry(p->de_extents.next, struct extent, e_list);
goto again;
}
......@@ -233,8 +233,8 @@ static int compare_extent(struct results_tree *res,
list_for_each_entry_continue(pos, head, e_file_extents) {
/* This is a logic error - we shouldn't loop back on
* ourselves. */
if (pos == extent)
abort();
abort_on(pos == extent);
// if (pos->e_loff == extent->e_loff
// && extent_len(pos) == extent_len(extent))
// continue; /* Same extent? Skip. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment