]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libfrog: fix bitmap error communication problems
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 17 Oct 2019 02:35:25 +0000 (22:35 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Thu, 17 Oct 2019 02:35:25 +0000 (22:35 -0400)
Convert all the libfrog code and callers away from the libc-style
indirect errno returns to directly returning error codes to callers.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libfrog/bitmap.c
libfrog/bitmap.h
repair/rmap.c
scrub/phase6.c

index 4dafc4c970724194596c4fd1f11c6c286c41744e..be95965fcbe4b8d82240549018c273a5acbdb45f 100644 (file)
@@ -23,7 +23,8 @@
  */
 
 #define avl_for_each_range_safe(pos, n, l, first, last) \
-       for (pos = (first), n = pos->avl_nextino, l = (last)->avl_nextino; pos != (l); \
+       for (pos = (first), n = pos->avl_nextino, l = (last)->avl_nextino; \
+                       pos != (l); \
                        pos = n, n = pos ? pos->avl_nextino : NULL)
 
 #define avl_for_each_safe(tree, pos, n) \
@@ -67,18 +68,18 @@ static struct avl64ops bitmap_ops = {
 
 /* Initialize a bitmap. */
 int
-bitmap_init(
+bitmap_alloc(
        struct bitmap           **bmapp)
 {
        struct bitmap           *bmap;
 
        bmap = calloc(1, sizeof(struct bitmap));
        if (!bmap)
-               return -ENOMEM;
+               return errno;
        bmap->bt_tree = malloc(sizeof(struct avl64tree_desc));
        if (!bmap->bt_tree) {
                free(bmap);
-               return -ENOMEM;
+               return errno;
        }
 
        pthread_mutex_init(&bmap->bt_lock, NULL);
@@ -139,12 +140,12 @@ __bitmap_insert(
 
        ext = bitmap_node_init(start, length);
        if (!ext)
-               return -ENOMEM;
+               return errno;
 
        node = avl64_insert(bmap->bt_tree, &ext->btn_node);
        if (node == NULL) {
                free(ext);
-               return -EEXIST;
+               return EEXIST;
        }
 
        return 0;
index 40119b9cb75e73b91dab7e159f526de306b7d93d..759386a8f4f3609f45c003d4e2172ded70250ed9 100644 (file)
@@ -11,7 +11,7 @@ struct bitmap {
        struct avl64tree_desc   *bt_tree;
 };
 
-int bitmap_init(struct bitmap **bmap);
+int bitmap_alloc(struct bitmap **bmap);
 void bitmap_free(struct bitmap **bmap);
 int bitmap_set(struct bitmap *bmap, uint64_t start, uint64_t length);
 int bitmap_iterate(struct bitmap *bmap, int (*fn)(uint64_t, uint64_t, void *),
index b907383e7222e65876f98e42a886bc9c73c7ae39..c6ed25a95b51ca18035bb0a8196509b6de168a13 100644 (file)
@@ -490,13 +490,13 @@ rmap_store_ag_btree_rec(
        error = init_slab_cursor(ag_rmap->ar_raw_rmaps, rmap_compare, &rm_cur);
        if (error)
                goto err;
-       error = -bitmap_init(&own_ag_bitmap);
+       error = bitmap_alloc(&own_ag_bitmap);
        if (error)
                goto err_slab;
        while ((rm_rec = pop_slab_cursor(rm_cur)) != NULL) {
                if (rm_rec->rm_owner != XFS_RMAP_OWN_AG)
                        continue;
-               error = -bitmap_set(own_ag_bitmap, rm_rec->rm_startblock,
+               error = bitmap_set(own_ag_bitmap, rm_rec->rm_startblock,
                                        rm_rec->rm_blockcount);
                if (error) {
                        /*
index aff04e76f06040cfd58ff9ebf289cb3aa016f694..d9285feed702e3aa7e480daa4c1518ddf8e3dfa9 100644 (file)
@@ -341,6 +341,7 @@ xfs_check_rmap_ioerr(
        struct media_verify_state       *vs = arg;
        struct bitmap                   *tree;
        dev_t                           dev;
+       int                             ret;
 
        dev = xfs_disk_to_dev(ctx, disk);
 
@@ -355,9 +356,9 @@ xfs_check_rmap_ioerr(
        else
                tree = NULL;
        if (tree) {
-               errno = -bitmap_set(tree, start, length);
-               if (errno)
-                       str_errno(ctx, ctx->mntpoint);
+               ret = bitmap_set(tree, start, length);
+               if (ret)
+                       str_liberror(ctx, ret, _("setting bad block bitmap"));
        }
 
        snprintf(descr, DESCR_BUFSZ, _("dev %d:%d ioerr @ %"PRIu64":%"PRIu64" "),
@@ -454,16 +455,17 @@ xfs_scan_blocks(
 {
        struct media_verify_state       vs = { NULL };
        bool                            moveon = false;
+       int                             ret;
 
-       errno = -bitmap_init(&vs.d_bad);
-       if (errno) {
-               str_errno(ctx, ctx->mntpoint);
+       ret = bitmap_alloc(&vs.d_bad);
+       if (ret) {
+               str_liberror(ctx, ret, _("creating datadev badblock bitmap"));
                goto out;
        }
 
-       errno = -bitmap_init(&vs.r_bad);
-       if (errno) {
-               str_errno(ctx, ctx->mntpoint);
+       ret = bitmap_alloc(&vs.r_bad);
+       if (ret) {
+               str_liberror(ctx, ret, _("creating realtime badblock bitmap"));
                goto out_dbad;
        }