Fixed plug/unplug logic in btt
[blktrace.git] / btt / dip_rb.c
index 6ff09dff70116dd44869c219fa83488984eafb32..867a97bd999773ffe1301e7a7ae45772cfc0ed6e 100644 (file)
 #include <stdio.h>
 #include "globals.h"
 
-void rb_insert(struct rb_root *root, struct io *iop)
+int rb_insert(struct rb_root *root, struct io *iop)
 {
        struct io *__iop;
        struct rb_node *parent = NULL;
        struct rb_node **p = &root->rb_node;
        __u64 __s, s = BIT_START(iop);
 
-       ASSERT(root != NULL && iop != NULL);
        while (*p) {
                parent = *p;
                __iop = rb_entry(parent, struct io, rb_node);
@@ -39,11 +38,12 @@ void rb_insert(struct rb_root *root, struct io *iop)
                else if (s > __s)
                        p = &(*p)->rb_right;
                else
-                       p = &(*p)->rb_right;
+                       return 0;
        }
 
        rb_link_node(&iop->rb_node, parent, p);
        rb_insert_color(&iop->rb_node, root);
+       return 1;
 }
 
 struct io *rb_find_sec(struct rb_root *root, __u64 sec)
@@ -64,7 +64,7 @@ struct io *rb_find_sec(struct rb_root *root, __u64 sec)
        return NULL;
 }
 
-void rb_foreach(struct rb_node *n, struct io *iop, 
+void rb_foreach(struct rb_node *n, struct io *iop,
                      void (*fnc)(struct io *iop, struct io *this),
                      struct list_head *head)
 {
@@ -75,7 +75,8 @@ void rb_foreach(struct rb_node *n, struct io *iop,
 
                if ((iop_s <= this_s) && (this_e <= iop_e)) {
                        if (fnc) fnc(iop, this);
-                       if (head) list_add_tail(&this->f_head, head);
+                       if (head)
+                               list_add_tail(&this->f_head, head);
                }
                if (iop_s < this_s)
                        rb_foreach(n->rb_left, iop, fnc, head);