WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] minios: free blkfront resources on error/shutdown

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] minios: free blkfront resources on error/shutdown
From: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>
Date: Mon, 12 May 2008 11:59:20 +0200
Delivery-date: Mon, 12 May 2008 02:59:56 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
In-reply-to: <20080512093438.GA5753@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Mail-followup-to: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxx
References: <20080512093438.GA5753@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.12-2006-07-14
minios: free blkfront resources on error/shutdown

Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>

diff -r b0d7780794eb extras/mini-os/blkfront.c
--- a/extras/mini-os/blkfront.c Thu May 08 13:40:40 2008 +0100
+++ b/extras/mini-os/blkfront.c Mon May 12 11:58:01 2008 +0200
@@ -68,6 +68,21 @@
     wake_up(&blkfront_queue);
 }
 
+static void free_blkfront(struct blkfront_dev *dev)
+{
+    mask_evtchn(dev->evtchn);
+
+    free(dev->backend);
+
+    gnttab_end_access(dev->ring_ref);
+    free_page(dev->ring.sring);
+
+    unbind_evtchn(dev->evtchn);
+
+    free(dev->nodename);
+    free(dev);
+}
+
 struct blkfront_dev *init_blkfront(char *nodename, struct blkfront_info *info)
 {
     xenbus_transaction_t xbt;
@@ -88,6 +103,7 @@
     printk("******************* BLKFRONT for %s **********\n\n\n", nodename);
 
     dev = malloc(sizeof(*dev));
+    memset(dev, 0, sizeof(*dev));
     dev->nodename = strdup(nodename);
 
     snprintf(path, sizeof(path), "%s/backend-id", nodename);
@@ -139,7 +155,7 @@
 
 abort_transaction:
     xenbus_transaction_end(xbt, 1, &retry);
-    return NULL;
+    goto error;
 
 done:
 
@@ -147,7 +163,7 @@
     msg = xenbus_read(XBT_NIL, path, &dev->backend);
     if (msg) {
         printk("Error %s when reading the backend path %s\n", msg, path);
-        return NULL;
+        goto error;
     }
 
     printk("backend at %s\n", dev->backend);
@@ -160,7 +176,7 @@
         msg = xenbus_read(XBT_NIL, path, &c);
         if (msg) {
             printk("Error %s when reading the mode\n", msg);
-            return NULL;
+            goto error;
         }
         if (*c == 'w')
             dev->info.mode = O_RDWR;
@@ -198,6 +214,10 @@
     printk("**************************\n");
 
     return dev;
+
+error:
+    free_blkfront(dev);
+    return NULL;
 }
 
 void shutdown_blkfront(struct blkfront_dev *dev)
@@ -220,11 +240,7 @@
 
     xenbus_unwatch_path(XBT_NIL, path);
 
-    unbind_evtchn(dev->evtchn);
-
-    free(nodename);
-    free(dev->backend);
-    free(dev);
+    free_blkfront(dev);
 }
 
 static void blkfront_wait_slot(struct blkfront_dev *dev)

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