All of lore.kernel.org
 help / color / mirror / Atom feed
From: aq <aquynh@gmail.com>
To: Xen Dev <xen-devel@lists.xensource.com>,
	Andrew Warfield <andrew.warfield@cl.cam.ac.uk>
Subject: [PATCH] handling errors in blktaplib
Date: Mon, 13 Jun 2005 17:11:59 +0900	[thread overview]
Message-ID: <9cde8bff05061301113528cc1@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 695 bytes --]

blktaplib doesnt handle errors properly in several places: it just
printed out the error message and exit, which is a bad behaviour for a
library.

this patch (against ChangeSet@1.1712) fixes the problem and then
handles the potential errors in blkdump. it also makes few cleanups.
(Andrew, there is another fix for parallax, but it will be sent later,
after  my last patch on parallax get merged/rejected)

Signed-off-by: Nguyen Anh Quynh <aquynh@gmail.com>


$ diffstat blktap2.patch 
 blkdump.c   |   18 +++++++++++++++---
 blktaplib.c |   46 +++++++++++++++++++++++++++++++---------------
 blktaplib.h |   12 +++++++++---
 3 files changed, 55 insertions(+), 21 deletions(-)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: blktap2.patch --]
[-- Type: text/x-patch; name="blktap2.patch", Size: 6199 bytes --]

===== 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);

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

                 reply	other threads:[~2005-06-13  8:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9cde8bff05061301113528cc1@mail.gmail.com \
    --to=aquynh@gmail.com \
    --cc=andrew.warfield@cl.cam.ac.uk \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.