Commit 2edc322d authored by Linus Torvalds's avatar Linus Torvalds

Merge git://git.infradead.org/~dwmw2/rbtree-2.6

* git://git.infradead.org/~dwmw2/rbtree-2.6:
  [RBTREE] Switch rb_colour() et al to en_US spelling of 'color' for consistency
  Update UML kernel/physmem.c to use rb_parent() accessor macro
  [RBTREE] Update hrtimers to use rb_parent() accessor macro.
  [RBTREE] Add explicit alignment to sizeof(long) for struct rb_node.
  [RBTREE] Merge colour and parent fields of struct rb_node.
  [RBTREE] Remove dead code in rb_erase()
  [RBTREE] Update JFFS2 to use rb_parent() accessor macro.
  [RBTREE] Update eventpoll.c to use rb_parent() accessor macro.
  [RBTREE] Update key.c to use rb_parent() accessor macro.
  [RBTREE] Update ext3 to use rb_parent() accessor macro.
  [RBTREE] Change rbtree off-tree marking in I/O schedulers.
  [RBTREE] Add accessor macros for colour and parent fields of rb_node
parents be967b7e 2f3243ae
...@@ -69,7 +69,7 @@ static void insert_phys_mapping(struct phys_desc *desc) ...@@ -69,7 +69,7 @@ static void insert_phys_mapping(struct phys_desc *desc)
panic("Physical remapping for %p already present", panic("Physical remapping for %p already present",
desc->virt); desc->virt);
rb_link_node(&desc->rb, (*n)->rb_parent, n); rb_link_node(&desc->rb, rb_parent(*n), n);
rb_insert_color(&desc->rb, &phys_mappings); rb_insert_color(&desc->rb, &phys_mappings);
} }
......
...@@ -353,10 +353,9 @@ static struct request *as_find_arq_hash(struct as_data *ad, sector_t offset) ...@@ -353,10 +353,9 @@ static struct request *as_find_arq_hash(struct as_data *ad, sector_t offset)
/* /*
* rb tree support functions * rb tree support functions
*/ */
#define RB_NONE (2)
#define RB_EMPTY(root) ((root)->rb_node == NULL) #define RB_EMPTY(root) ((root)->rb_node == NULL)
#define ON_RB(node) ((node)->rb_color != RB_NONE) #define ON_RB(node) (rb_parent(node) != node)
#define RB_CLEAR(node) ((node)->rb_color = RB_NONE) #define RB_CLEAR(node) (rb_set_parent(node, node))
#define rb_entry_arq(node) rb_entry((node), struct as_rq, rb_node) #define rb_entry_arq(node) rb_entry((node), struct as_rq, rb_node)
#define ARQ_RB_ROOT(ad, arq) (&(ad)->sort_list[(arq)->is_sync]) #define ARQ_RB_ROOT(ad, arq) (&(ad)->sort_list[(arq)->is_sync])
#define rq_rb_key(rq) (rq)->sector #define rq_rb_key(rq) (rq)->sector
......
...@@ -60,14 +60,9 @@ static DEFINE_SPINLOCK(cfq_exit_lock); ...@@ -60,14 +60,9 @@ static DEFINE_SPINLOCK(cfq_exit_lock);
/* /*
* rb-tree defines * rb-tree defines
*/ */
#define RB_NONE (2)
#define RB_EMPTY(node) ((node)->rb_node == NULL) #define RB_EMPTY(node) ((node)->rb_node == NULL)
#define RB_CLEAR_COLOR(node) (node)->rb_color = RB_NONE
#define RB_CLEAR(node) do { \ #define RB_CLEAR(node) do { \
(node)->rb_parent = NULL; \ memset(node, 0, sizeof(*node)); \
RB_CLEAR_COLOR((node)); \
(node)->rb_right = NULL; \
(node)->rb_left = NULL; \
} while (0) } while (0)
#define RB_CLEAR_ROOT(root) ((root)->rb_node = NULL) #define RB_CLEAR_ROOT(root) ((root)->rb_node = NULL)
#define rb_entry_crq(node) rb_entry((node), struct cfq_rq, rb_node) #define rb_entry_crq(node) rb_entry((node), struct cfq_rq, rb_node)
...@@ -567,7 +562,6 @@ static inline void cfq_del_crq_rb(struct cfq_rq *crq) ...@@ -567,7 +562,6 @@ static inline void cfq_del_crq_rb(struct cfq_rq *crq)
cfq_update_next_crq(crq); cfq_update_next_crq(crq);
rb_erase(&crq->rb_node, &cfqq->sort_list); rb_erase(&crq->rb_node, &cfqq->sort_list);
RB_CLEAR_COLOR(&crq->rb_node);
if (cfq_cfqq_on_rr(cfqq) && RB_EMPTY(&cfqq->sort_list)) if (cfq_cfqq_on_rr(cfqq) && RB_EMPTY(&cfqq->sort_list))
cfq_del_cfqq_rr(cfqd, cfqq); cfq_del_cfqq_rr(cfqd, cfqq);
......
...@@ -165,10 +165,9 @@ deadline_find_drq_hash(struct deadline_data *dd, sector_t offset) ...@@ -165,10 +165,9 @@ deadline_find_drq_hash(struct deadline_data *dd, sector_t offset)
/* /*
* rb tree support functions * rb tree support functions
*/ */
#define RB_NONE (2)
#define RB_EMPTY(root) ((root)->rb_node == NULL) #define RB_EMPTY(root) ((root)->rb_node == NULL)
#define ON_RB(node) ((node)->rb_color != RB_NONE) #define ON_RB(node) (rb_parent(node) != node)
#define RB_CLEAR(node) ((node)->rb_color = RB_NONE) #define RB_CLEAR(node) (rb_set_parent(node, node))
#define rb_entry_drq(node) rb_entry((node), struct deadline_rq, rb_node) #define rb_entry_drq(node) rb_entry((node), struct deadline_rq, rb_node)
#define DRQ_RB_ROOT(dd, drq) (&(dd)->sort_list[rq_data_dir((drq)->request)]) #define DRQ_RB_ROOT(dd, drq) (&(dd)->sort_list[rq_data_dir((drq)->request)])
#define rq_rb_key(rq) (rq)->sector #define rq_rb_key(rq) (rq)->sector
......
...@@ -337,20 +337,20 @@ static inline int ep_cmp_ffd(struct epoll_filefd *p1, ...@@ -337,20 +337,20 @@ static inline int ep_cmp_ffd(struct epoll_filefd *p1,
/* Special initialization for the rb-tree node to detect linkage */ /* Special initialization for the rb-tree node to detect linkage */
static inline void ep_rb_initnode(struct rb_node *n) static inline void ep_rb_initnode(struct rb_node *n)
{ {
n->rb_parent = n; rb_set_parent(n, n);
} }
/* Removes a node from the rb-tree and marks it for a fast is-linked check */ /* Removes a node from the rb-tree and marks it for a fast is-linked check */
static inline void ep_rb_erase(struct rb_node *n, struct rb_root *r) static inline void ep_rb_erase(struct rb_node *n, struct rb_root *r)
{ {
rb_erase(n, r); rb_erase(n, r);
n->rb_parent = n; rb_set_parent(n, n);
} }
/* Fast check to verify that the item is linked to the main rb-tree */ /* Fast check to verify that the item is linked to the main rb-tree */
static inline int ep_rb_linked(struct rb_node *n) static inline int ep_rb_linked(struct rb_node *n)
{ {
return n->rb_parent != n; return rb_parent(n) != n;
} }
/* /*
......
...@@ -284,7 +284,7 @@ static void free_rb_tree_fname(struct rb_root *root) ...@@ -284,7 +284,7 @@ static void free_rb_tree_fname(struct rb_root *root)
* beginning of the loop and try to free the parent * beginning of the loop and try to free the parent
* node. * node.
*/ */
parent = n->rb_parent; parent = rb_parent(n);
fname = rb_entry(n, struct fname, rb_hash); fname = rb_entry(n, struct fname, rb_hash);
while (fname) { while (fname) {
struct fname * old = fname; struct fname * old = fname;
......
...@@ -315,7 +315,6 @@ static inline struct jffs2_node_frag *frag_last(struct rb_root *root) ...@@ -315,7 +315,6 @@ static inline struct jffs2_node_frag *frag_last(struct rb_root *root)
return rb_entry(node, struct jffs2_node_frag, rb); return rb_entry(node, struct jffs2_node_frag, rb);
} }
#define rb_parent(rb) ((rb)->rb_parent)
#define frag_next(frag) rb_entry(rb_next(&(frag)->rb), struct jffs2_node_frag, rb) #define frag_next(frag) rb_entry(rb_next(&(frag)->rb), struct jffs2_node_frag, rb)
#define frag_prev(frag) rb_entry(rb_prev(&(frag)->rb), struct jffs2_node_frag, rb) #define frag_prev(frag) rb_entry(rb_prev(&(frag)->rb), struct jffs2_node_frag, rb)
#define frag_parent(frag) rb_entry(rb_parent(&(frag)->rb), struct jffs2_node_frag, rb) #define frag_parent(frag) rb_entry(rb_parent(&(frag)->rb), struct jffs2_node_frag, rb)
......
...@@ -66,7 +66,7 @@ static void jffs2_free_tmp_dnode_info_list(struct rb_root *list) ...@@ -66,7 +66,7 @@ static void jffs2_free_tmp_dnode_info_list(struct rb_root *list)
jffs2_free_full_dnode(tn->fn); jffs2_free_full_dnode(tn->fn);
jffs2_free_tmp_dnode_info(tn); jffs2_free_tmp_dnode_info(tn);
this = this->rb_parent; this = rb_parent(this);
if (!this) if (!this)
break; break;
...@@ -708,12 +708,12 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c, ...@@ -708,12 +708,12 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
jffs2_mark_node_obsolete(c, fn->raw); jffs2_mark_node_obsolete(c, fn->raw);
BUG_ON(rb->rb_left); BUG_ON(rb->rb_left);
if (rb->rb_parent && rb->rb_parent->rb_left == rb) { if (rb_parent(rb) && rb_parent(rb)->rb_left == rb) {
/* We were then left-hand child of our parent. We need /* We were then left-hand child of our parent. We need
* to move our own right-hand child into our place. */ * to move our own right-hand child into our place. */
repl_rb = rb->rb_right; repl_rb = rb->rb_right;
if (repl_rb) if (repl_rb)
repl_rb->rb_parent = rb->rb_parent; rb_set_parent(repl_rb, rb_parent(rb));
} else } else
repl_rb = NULL; repl_rb = NULL;
...@@ -721,14 +721,14 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c, ...@@ -721,14 +721,14 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
/* Remove the spent tn from the tree; don't bother rebalancing /* Remove the spent tn from the tree; don't bother rebalancing
* but put our right-hand child in our own place. */ * but put our right-hand child in our own place. */
if (tn->rb.rb_parent) { if (rb_parent(&tn->rb)) {
if (tn->rb.rb_parent->rb_left == &tn->rb) if (rb_parent(&tn->rb)->rb_left == &tn->rb)
tn->rb.rb_parent->rb_left = repl_rb; rb_parent(&tn->rb)->rb_left = repl_rb;
else if (tn->rb.rb_parent->rb_right == &tn->rb) else if (rb_parent(&tn->rb)->rb_right == &tn->rb)
tn->rb.rb_parent->rb_right = repl_rb; rb_parent(&tn->rb)->rb_right = repl_rb;
else BUG(); else BUG();
} else if (tn->rb.rb_right) } else if (tn->rb.rb_right)
tn->rb.rb_right->rb_parent = NULL; rb_set_parent(tn->rb.rb_right, NULL);
jffs2_free_tmp_dnode_info(tn); jffs2_free_tmp_dnode_info(tn);
if (ret) { if (ret) {
......
...@@ -127,7 +127,7 @@ extern ktime_t hrtimer_get_next_event(void); ...@@ -127,7 +127,7 @@ extern ktime_t hrtimer_get_next_event(void);
static inline int hrtimer_active(const struct hrtimer *timer) static inline int hrtimer_active(const struct hrtimer *timer)
{ {
return timer->node.rb_parent != HRTIMER_INACTIVE; return rb_parent(&timer->node) != &timer->node;
} }
/* Forward a hrtimer so it expires after now: */ /* Forward a hrtimer so it expires after now: */
......
...@@ -99,19 +99,36 @@ static inline struct page * rb_insert_page_cache(struct inode * inode, ...@@ -99,19 +99,36 @@ static inline struct page * rb_insert_page_cache(struct inode * inode,
struct rb_node struct rb_node
{ {
struct rb_node *rb_parent; unsigned long rb_parent_color;
int rb_color;
#define RB_RED 0 #define RB_RED 0
#define RB_BLACK 1 #define RB_BLACK 1
struct rb_node *rb_right; struct rb_node *rb_right;
struct rb_node *rb_left; struct rb_node *rb_left;
}; } __attribute__((aligned(sizeof(long))));
/* The alignment might seem pointless, but allegedly CRIS needs it */
struct rb_root struct rb_root
{ {
struct rb_node *rb_node; struct rb_node *rb_node;
}; };
#define rb_parent(r) ((struct rb_node *)((r)->rb_parent_color & ~3))
#define rb_color(r) ((r)->rb_parent_color & 1)
#define rb_is_red(r) (!rb_color(r))
#define rb_is_black(r) rb_color(r)
#define rb_set_red(r) do { (r)->rb_parent_color &= ~1; } while (0)
#define rb_set_black(r) do { (r)->rb_parent_color |= 1; } while (0)
static inline void rb_set_parent(struct rb_node *rb, struct rb_node *p)
{
rb->rb_parent_color = (rb->rb_parent_color & 3) | (unsigned long)p;
}
static inline void rb_set_color(struct rb_node *rb, int color)
{
rb->rb_parent_color = (rb->rb_parent_color & ~1) | color;
}
#define RB_ROOT (struct rb_root) { NULL, } #define RB_ROOT (struct rb_root) { NULL, }
#define rb_entry(ptr, type, member) container_of(ptr, type, member) #define rb_entry(ptr, type, member) container_of(ptr, type, member)
...@@ -131,8 +148,7 @@ extern void rb_replace_node(struct rb_node *victim, struct rb_node *new, ...@@ -131,8 +148,7 @@ extern void rb_replace_node(struct rb_node *victim, struct rb_node *new,
static inline void rb_link_node(struct rb_node * node, struct rb_node * parent, static inline void rb_link_node(struct rb_node * node, struct rb_node * parent,
struct rb_node ** rb_link) struct rb_node ** rb_link)
{ {
node->rb_parent = parent; node->rb_parent_color = (unsigned long )parent;
node->rb_color = RB_RED;
node->rb_left = node->rb_right = NULL; node->rb_left = node->rb_right = NULL;
*rb_link = node; *rb_link = node;
......
...@@ -393,7 +393,7 @@ static void __remove_hrtimer(struct hrtimer *timer, struct hrtimer_base *base) ...@@ -393,7 +393,7 @@ static void __remove_hrtimer(struct hrtimer *timer, struct hrtimer_base *base)
if (base->first == &timer->node) if (base->first == &timer->node)
base->first = rb_next(&timer->node); base->first = rb_next(&timer->node);
rb_erase(&timer->node, &base->active); rb_erase(&timer->node, &base->active);
timer->node.rb_parent = HRTIMER_INACTIVE; rb_set_parent(&timer->node, &timer->node);
} }
/* /*
...@@ -582,7 +582,7 @@ void hrtimer_init(struct hrtimer *timer, clockid_t clock_id, ...@@ -582,7 +582,7 @@ void hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
clock_id = CLOCK_MONOTONIC; clock_id = CLOCK_MONOTONIC;
timer->base = &bases[clock_id]; timer->base = &bases[clock_id];
timer->node.rb_parent = HRTIMER_INACTIVE; rb_set_parent(&timer->node, &timer->node);
} }
EXPORT_SYMBOL_GPL(hrtimer_init); EXPORT_SYMBOL_GPL(hrtimer_init);
......
This diff is collapsed.
...@@ -211,12 +211,12 @@ static inline void key_alloc_serial(struct key *key) ...@@ -211,12 +211,12 @@ static inline void key_alloc_serial(struct key *key)
key->serial = 2; key->serial = 2;
key_serial_next = key->serial + 1; key_serial_next = key->serial + 1;
if (!parent->rb_parent) if (!rb_parent(parent))
p = &key_serial_tree.rb_node; p = &key_serial_tree.rb_node;
else if (parent->rb_parent->rb_left == parent) else if (rb_parent(parent)->rb_left == parent)
p = &parent->rb_parent->rb_left; p = &(rb_parent(parent)->rb_left);
else else
p = &parent->rb_parent->rb_right; p = &(rb_parent(parent)->rb_right);
parent = rb_next(parent); parent = rb_next(parent);
if (!parent) if (!parent)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment