[PATCH 2/7] libfrog: convert bitmap.c to negative error codes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Darrick J. Wong <darrick.wong@xxxxxxxxxx>

Convert libfrog functions to return negative error codes like libxfs
does.

Signed-off-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx>
Reviewed-by: Christoph Hellwig <hch@xxxxxx>
---
 libfrog/bitmap.c |   27 +++++++++++++++------------
 repair/rmap.c    |    4 ++--
 scrub/phase6.c   |   12 ++++++------
 3 files changed, 23 insertions(+), 20 deletions(-)


diff --git a/libfrog/bitmap.c b/libfrog/bitmap.c
index c928d26f..5af5ab8d 100644
--- a/libfrog/bitmap.c
+++ b/libfrog/bitmap.c
@@ -76,14 +76,14 @@ bitmap_alloc(
 
 	bmap = calloc(1, sizeof(struct bitmap));
 	if (!bmap)
-		return errno;
+		return -errno;
 	bmap->bt_tree = malloc(sizeof(struct avl64tree_desc));
 	if (!bmap->bt_tree) {
-		ret = errno;
+		ret = -errno;
 		goto out;
 	}
 
-	ret = pthread_mutex_init(&bmap->bt_lock, NULL);
+	ret = -pthread_mutex_init(&bmap->bt_lock, NULL);
 	if (ret)
 		goto out_tree;
 
@@ -149,12 +149,12 @@ __bitmap_insert(
 
 	ext = bitmap_node_init(start, length);
 	if (!ext)
-		return errno;
+		return -errno;
 
 	node = avl64_insert(bmap->bt_tree, &ext->btn_node);
 	if (node == NULL) {
 		free(ext);
-		return EEXIST;
+		return -EEXIST;
 	}
 
 	return 0;
@@ -235,7 +235,7 @@ bitmap_set(
 
 #if 0	/* Unused, provided for completeness. */
 /* Clear a region of bits. */
-bool
+int
 bitmap_clear(
 	struct bitmap		*bmap,
 	uint64_t		start,
@@ -259,7 +259,7 @@ bitmap_clear(
 	/* Nothing, we're done. */
 	if (firstn == NULL && lastn == NULL) {
 		pthread_mutex_unlock(&bmap->bt_lock);
-		return true;
+		return 0;
 	}
 
 	assert(firstn != NULL && lastn != NULL);
@@ -297,20 +297,23 @@ bitmap_clear(
 					new_start;
 
 			ext = bitmap_node_init(new_start, new_length);
-			if (!ext)
-				return false;
+			if (!ext) {
+				ret = -errno;
+				goto out;
+			}
 
 			node = avl64_insert(bmap->bt_tree, &ext->btn_node);
 			if (node == NULL) {
-				errno = EEXIST;
-				return false;
+				ret = -EEXIST;
+				goto out;
 			}
 			break;
 		}
 	}
 
+out:
 	pthread_mutex_unlock(&bmap->bt_lock);
-	return true;
+	return ret;
 }
 #endif
 
diff --git a/repair/rmap.c b/repair/rmap.c
index c6ed25a9..c4c99131 100644
--- a/repair/rmap.c
+++ b/repair/rmap.c
@@ -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_alloc(&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) {
 			/*
diff --git a/scrub/phase6.c b/scrub/phase6.c
index 6dbadcee..6e959069 100644
--- a/scrub/phase6.c
+++ b/scrub/phase6.c
@@ -195,7 +195,7 @@ report_data_loss(
 	else
 		bmp = vs->d_bad;
 
-	return bitmap_iterate_range(bmp, bmap->bm_physical, bmap->bm_length,
+	return -bitmap_iterate_range(bmp, bmap->bm_physical, bmap->bm_length,
 			report_badfile, br);
 }
 
@@ -446,7 +446,7 @@ report_ioerr(
 	(keys + 1)->fmr_owner = ULLONG_MAX;
 	(keys + 1)->fmr_offset = ULLONG_MAX;
 	(keys + 1)->fmr_flags = UINT_MAX;
-	return scrub_iterate_fsmap(dioerr->ctx, keys, report_ioerr_fsmap,
+	return -scrub_iterate_fsmap(dioerr->ctx, keys, report_ioerr_fsmap,
 			&start);
 }
 
@@ -468,7 +468,7 @@ report_disk_ioerrs(
 	tree = bitmap_for_disk(ctx, disk, vs);
 	if (!tree)
 		return 0;
-	return bitmap_iterate(tree, report_ioerr, &dioerr);
+	return -bitmap_iterate(tree, report_ioerr, &dioerr);
 }
 
 /* Given bad extent lists for the data & rtdev, find bad files. */
@@ -598,7 +598,7 @@ remember_ioerr(
 		return;
 	}
 
-	ret = bitmap_set(tree, start, length);
+	ret = -bitmap_set(tree, start, length);
 	if (ret)
 		str_liberror(ctx, ret, _("setting bad block bitmap"));
 }
@@ -661,13 +661,13 @@ phase6_func(
 	struct media_verify_state	vs = { NULL };
 	int				ret, ret2, ret3;
 
-	ret = bitmap_alloc(&vs.d_bad);
+	ret = -bitmap_alloc(&vs.d_bad);
 	if (ret) {
 		str_liberror(ctx, ret, _("creating datadev badblock bitmap"));
 		return ret;
 	}
 
-	ret = bitmap_alloc(&vs.r_bad);
+	ret = -bitmap_alloc(&vs.r_bad);
 	if (ret) {
 		str_liberror(ctx, ret, _("creating realtime badblock bitmap"));
 		goto out_dbad;




[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux