]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
libfrog: add bitmap_clear
authorDarrick J. Wong <djwong@kernel.org>
Sat, 3 Aug 2024 05:08:16 +0000 (07:08 +0200)
committerChristoph Hellwig <hch@lst.de>
Tue, 6 Aug 2024 12:53:50 +0000 (05:53 -0700)
Uncomment and fix bitmap_clear so that xfs_repair can start using it.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
[hch: split from a larger patch]
Signed-off-by: Christoph Hellwig <hch@lst.de>
libfrog/bitmap.c
libfrog/bitmap.h

index 5af5ab8dd6b3bb853d2ff3e8bdfadff4fb8a850f..0308886d446ff2b554319fb734c73725b1195e85 100644 (file)
@@ -233,10 +233,9 @@ bitmap_set(
        return res;
 }
 
-#if 0  /* Unused, provided for completeness. */
 /* Clear a region of bits. */
-int
-bitmap_clear(
+static int
+__bitmap_clear(
        struct bitmap           *bmap,
        uint64_t                start,
        uint64_t                len)
@@ -251,8 +250,8 @@ bitmap_clear(
        uint64_t                new_length;
        struct avl64node        *node;
        int                     stat;
+       int                     ret = 0;
 
-       pthread_mutex_lock(&bmap->bt_lock);
        /* Find any existing nodes over that range. */
        avl64_findranges(bmap->bt_tree, start, start + len, &firstn, &lastn);
 
@@ -312,10 +311,24 @@ bitmap_clear(
        }
 
 out:
-       pthread_mutex_unlock(&bmap->bt_lock);
        return ret;
 }
-#endif
+
+/* Clear a region of bits. */
+int
+bitmap_clear(
+       struct bitmap           *bmap,
+       uint64_t                start,
+       uint64_t                length)
+{
+       int                     res;
+
+       pthread_mutex_lock(&bmap->bt_lock);
+       res = __bitmap_clear(bmap, start, length);
+       pthread_mutex_unlock(&bmap->bt_lock);
+
+       return res;
+}
 
 /* Iterate the set regions of this bitmap. */
 int
index 043b77eece65b3ffdf64ff0ccee883ca482afce5..47df0ad38467ced0eeb91cdb33e60a552ef09e34 100644 (file)
@@ -14,6 +14,7 @@ struct bitmap {
 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_clear(struct bitmap *bmap, uint64_t start, uint64_t length);
 int bitmap_iterate(struct bitmap *bmap, int (*fn)(uint64_t, uint64_t, void *),
                void *arg);
 int bitmap_iterate_range(struct bitmap *bmap, uint64_t start, uint64_t length,