X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=linux_module%2Flinux-exts.c;h=19160bbcb43d95e0d4b6b35f069b8a7cd0a0a643;hb=f240f8a3c11478abe180bd906c746c68eb8c3a3c;hp=f393edcf3f7740b09175e00ddc8fc2e4d8d815ed;hpb=5c2a2684778fa080c41a0f04518721ebe476efb1;p=palacios.git diff --git a/linux_module/linux-exts.c b/linux_module/linux-exts.c index f393edc..19160bb 100644 --- a/linux_module/linux-exts.c +++ b/linux_module/linux-exts.c @@ -43,7 +43,7 @@ static inline struct global_ctrl * __insert_global_ctrl(struct global_ctrl * ctr int add_global_ctrl(unsigned int cmd, int (*handler)(unsigned int cmd, unsigned long arg)) { - struct global_ctrl * ctrl = palacios_alloc_extended(sizeof(struct global_ctrl), GFP_KERNEL); + struct global_ctrl * ctrl = palacios_alloc_extended(sizeof(struct global_ctrl), GFP_KERNEL,-1); if (ctrl == NULL) { printk("Error: Could not allocate global ctrl %d\n", cmd); @@ -53,7 +53,7 @@ int add_global_ctrl(unsigned int cmd, ctrl->cmd = cmd; ctrl->handler = handler; - if (__insert_global_ctrl(ctrl) != NULL) { + if (__insert_global_ctrl(ctrl) != NULL) { printk("Could not insert guest ctrl %d\n", cmd); palacios_free(ctrl); return -1; @@ -65,9 +65,9 @@ int add_global_ctrl(unsigned int cmd, } -struct global_ctrl * get_global_ctrl(unsigned int cmd) { +static struct rb_node * find_match(unsigned int cmd) { struct rb_node * n = global_ctrls.rb_node; - struct global_ctrl * ctrl = NULL; + struct global_ctrl *ctrl; while (n) { ctrl = rb_entry(n, struct global_ctrl, tree_node); @@ -77,7 +77,7 @@ struct global_ctrl * get_global_ctrl(unsigned int cmd) { } else if (cmd > ctrl->cmd) { n = n->rb_right; } else { - return ctrl; + return n; } } @@ -85,6 +85,38 @@ struct global_ctrl * get_global_ctrl(unsigned int cmd) { } +struct global_ctrl * get_global_ctrl(unsigned int cmd) { + struct rb_node *n = find_match(cmd); + + if (n) { + return rb_entry(n, struct global_ctrl, tree_node); + } else { + return NULL; + } +} + + +int remove_global_ctrl(unsigned int cmd) +{ + struct rb_node *n = find_match(cmd); + struct global_ctrl *c; + + if (!n) { + return -1; + } + + c = rb_entry(n, struct global_ctrl, tree_node); + + rb_erase(n,&global_ctrls); + + if (c) { + palacios_free(c); + } + + return 0; +} + +