===== tools/blktap/blkdump.c 1.3 vs edited ===== --- 1.3/tools/blktap/blkdump.c 2005-05-20 23:49:32 +09:00 +++ edited/tools/blktap/blkdump.c 2005-06-13 16:58:33 +09:00 @@ -122,9 +122,21 @@ int main(int argc, char *argv[]) { - blktap_register_ctrl_hook("control_print", control_print); - blktap_register_request_hook("request_print", request_print); - blktap_register_response_hook("response_print", response_print); + if (blktap_register_ctrl_hook("control_print", control_print) == -1) + { + printf("Error on registering control_print hook. Halt!\n"); + return -1; + } + if (blktap_register_request_hook("request_print", request_print) == -1) + { + printf("Error on registering request_print hook. Halt!\n"); + return -1; + } + if (blktap_register_response_hook("response_print", response_print) == -1) + { + printf("Error on registering response_print hook. Halt!\n"); + return -1; + } blktap_listen(); return 0; ===== tools/blktap/blktaplib.c 1.6 vs edited ===== --- 1.6/tools/blktap/blktaplib.c 2005-06-04 23:00:20 +09:00 +++ edited/tools/blktap/blktaplib.c 2005-06-13 16:48:30 +09:00 @@ -110,12 +110,17 @@ static request_hook_t *request_hook_chain = NULL; static response_hook_t *response_hook_chain = NULL; -void blktap_register_ctrl_hook(char *name, int (*ch)(control_msg_t *)) +/* blktap_register_ctrl_hook returns -1 on error, 0 on success */ +int blktap_register_ctrl_hook(char *name, int (*ch)(control_msg_t *)) { ctrl_hook_t *ch_ent, **c; ch_ent = (ctrl_hook_t *)malloc(sizeof(ctrl_hook_t)); - if (!ch_ent) { printf("couldn't allocate a new hook\n"); exit(-1); } + if (!ch_ent) + { + DPRINTF("blktap_register_ctrl_hook: couldn't allocate a new hook\n"); + return -1; + } ch_ent->func = ch; ch_ent->next = NULL; @@ -127,14 +132,20 @@ c = &(*c)->next; } *c = ch_ent; + return 0; } -void blktap_register_request_hook(char *name, int (*rh)(blkif_request_t *)) +/* blktap_register_request_hook returns -1 on error, 0 on success */ +int blktap_register_request_hook(char *name, int (*rh)(blkif_request_t *)) { request_hook_t *rh_ent, **c; rh_ent = (request_hook_t *)malloc(sizeof(request_hook_t)); - if (!rh_ent) { printf("couldn't allocate a new hook\n"); exit(-1); } + if (!rh_ent) + { + DPRINTF("blktap_register_request_hook: couldn't allocate a new hook\n"); + return -1; + } rh_ent->func = rh; rh_ent->next = NULL; @@ -145,14 +156,20 @@ c = &(*c)->next; } *c = rh_ent; + return 0; } -void blktap_register_response_hook(char *name, int (*rh)(blkif_response_t *)) +/* blktap_register_response_hook returns -1 on error, 0 on success */ +int blktap_register_response_hook(char *name, int (*rh)(blkif_response_t *)) { response_hook_t *rh_ent, **c; rh_ent = (response_hook_t *)malloc(sizeof(response_hook_t)); - if (!rh_ent) { printf("couldn't allocate a new hook\n"); exit(-1); } + if (!rh_ent) + { + DPRINTF("blktap_register_response_hook: couldn't allocate a new hook\n"); + return -1; + } rh_ent->func = rh; rh_ent->next = NULL; @@ -163,6 +180,7 @@ c = &(*c)->next; } *c = rh_ent; + return 0; } void print_hooks(void) @@ -198,8 +216,6 @@ /*-----[ Data to/from Backend (server) VM ]------------------------------*/ - - inline int write_req_to_be_ring(blkif_request_t *req) { blkif_request_t *req_d; @@ -289,7 +305,7 @@ pollhook_t *ph; if (nr_pollhooks() == MAX_POLLFDS) { - printf("Too many pollhooks!\n"); + DPRINTF("blktap_attach_poll: the number of pollhook reached the limit of %d!\n", MAX_POLLFDS); return -1; } @@ -454,9 +470,9 @@ } /* Using this as a unidirectional ring. */ ctrl_ring.req_cons = ctrl_ring.rsp_prod_pvt = i; -pthread_mutex_lock(&push_mutex); + pthread_mutex_lock(&push_mutex); RING_PUSH_RESPONSES(&ctrl_ring); -pthread_mutex_unlock(&push_mutex); + pthread_mutex_unlock(&push_mutex); /* empty the fe_ring */ notify_fe = 0; @@ -524,18 +540,18 @@ if (notify_be) { DPRINTF("notifying be\n"); -pthread_mutex_lock(&push_mutex); + pthread_mutex_lock(&push_mutex); RING_PUSH_REQUESTS(&be_ring); ioctl(fd, BLKTAP_IOCTL_KICK_BE); -pthread_mutex_unlock(&push_mutex); + pthread_mutex_unlock(&push_mutex); } if (notify_fe) { DPRINTF("notifying fe\n"); -pthread_mutex_lock(&push_mutex); + pthread_mutex_lock(&push_mutex); RING_PUSH_RESPONSES(&fe_ring); ioctl(fd, BLKTAP_IOCTL_KICK_FE); -pthread_mutex_unlock(&push_mutex); + pthread_mutex_unlock(&push_mutex); } } } ===== tools/blktap/blktaplib.h 1.5 vs edited ===== --- 1.5/tools/blktap/blktaplib.h 2005-06-09 22:37:52 +09:00 +++ edited/tools/blktap/blktaplib.h 2005-06-13 16:41:48 +09:00 @@ -67,9 +67,15 @@ inline unsigned int ID_TO_IDX(unsigned long id); inline domid_t ID_TO_DOM(unsigned long id); -void blktap_register_ctrl_hook(char *name, int (*ch)(control_msg_t *)); -void blktap_register_request_hook(char *name, int (*rh)(blkif_request_t *)); -void blktap_register_response_hook(char *name, int (*rh)(blkif_response_t *)); +/* blktap_register_ctrl_hook returns -1 on error, 0 on success */ +int blktap_register_ctrl_hook(char *name, int (*ch)(control_msg_t *)); + +/* blktap_register_request_hook returns -1 on error, 0 on success */ +int blktap_register_request_hook(char *name, int (*rh)(blkif_request_t *)); + +/* blktap_register_response_hook returns -1 on error, 0 on success */ +int blktap_register_response_hook(char *name, int (*rh)(blkif_response_t *)); + void blktap_inject_response(blkif_response_t *); int blktap_attach_poll(int fd, short events, int (*func)(int)); void blktap_detach_poll(int fd);