]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
broken count
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Tue, 19 Aug 2025 15:06:04 +0000 (11:06 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Tue, 19 Aug 2025 15:06:04 +0000 (11:06 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
lib/maple_tree.c

index 992df6a12d8ced3dced3b031aa9579f2686db5dd..f394569af9d1ca85ca421816d4aaae9d677706c7 100644 (file)
@@ -2969,25 +2969,50 @@ static void mas_spanning_rebalance(struct ma_state *mas,
 
 static noinline void mas_wr_spanning_rebalance(struct ma_state *mas,
                struct maple_subtree_state *mast, unsigned char height,
-               struct ma_wr_state *l_wr_mas)
+               struct ma_wr_state *l_wr_mas, struct ma_wr_state *r_wr_mas)
 {
+       unsigned char data_size;
        struct maple_big_node b_node;
        MA_STATE(l_mas, mas->tree, mas->index, mas->index);
        MA_STATE(r_mas, mas->tree, mas->index, mas->last);
        MA_STATE(m_mas, mas->tree, mas->index, mas->index);
 
+       data_size = mast->orig_l->offset;
+       if (l_wr_mas->r_min < mas->index)
+               data_size++;
+
        memset(&b_node, 0, sizeof(struct maple_big_node));
        /* Copy l_mas and store the value in b_node. */
        mas_store_b_node(l_wr_mas, &b_node, mast->orig_l->end);
+       WARN_ON(data_size != b_node.b_end);
+
+
+       data_size += mast->orig_r->end - mast->orig_r->offset;
+       if (r_wr_mas->r_max > mas->last)
+               data_size++;
+
        /* Copy r_mas into b_node if there is anything to copy. */
-       if (mast->orig_r->max > mast->orig_r->last)
+       if (mast->orig_r->max > mast->orig_r->last) {
                mas_mab_cp(mast->orig_r, mast->orig_r->offset,
                           mast->orig_r->end, &b_node, b_node.b_end + 1);
-       else
+               printk("%u Copy %u - %u\n", mast->orig_r->offset, mast->orig_r->end);
+       WARN_ON(data_size != b_node.b_end);
+       } else {
+               data_size++;
                b_node.b_end++;
+       WARN_ON(data_size != b_node.b_end);
+       }
+       if (data_size != b_node.b_end) {
+               printk("data size = %u\n", mast->orig_l->offset);
+               printk("r_end %u off %u\n", mast->orig_r->end, mast->orig_r->offset);
+               printk("r max %lx vs %lx\n", r_wr_mas->r_max, mast->orig_r->last);
+               printk("data %u != end %u\n", data_size, b_node.b_end);
+               printk("data is %p\n", l_wr_mas->entry);
+       }
+       WARN_ON(data_size != b_node.b_end);
 
        /* Stop spanning searches by searching for just index. */
-       mast->orig_l->last = mas->index;
+       mast->orig_l->index = mast->orig_l->last = mas->index;
 
        mast->bn = &b_node;
        /* Combine l_mas and r_mas and split them up evenly again. */
@@ -3828,6 +3853,9 @@ static void mas_wr_spanning_store(struct ma_wr_state *wr_mas)
        r_mas.index = r_mas.last;
        mas_wr_walk_index(&r_wr_mas);
        r_mas.last = r_mas.index = mas->last;
+       mt_dump(mas->tree, mt_dump_hex);
+       printk("r_mas is at %p\n", r_mas.node);
+       BUG_ON(!r_mas.end);
 
        /* Set up left side. */
        l_mas = *mas;
@@ -3848,7 +3876,8 @@ static void mas_wr_spanning_store(struct ma_wr_state *wr_mas)
 
        mast.orig_l = &l_mas;
        mast.orig_r = &r_mas;
-       mas_wr_spanning_rebalance(mas, &mast, height + 1, &l_wr_mas);
+       mas_wr_spanning_rebalance(mas, &mast, height + 1, &l_wr_mas,
+                                 &r_wr_mas);
 }
 
 /*