Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


error checking in file close
[palacios.releases.git] / linux_module / buddy.c
index ea5b705..43247b6 100644 (file)
@@ -235,7 +235,13 @@ static int __buddy_remove_mempool(struct buddy_memzone * zone,
 
     *user_metadata = pool->user_metadata;
     
-    list_del(&(block->link));
+    if (is_available(pool,block)) { 
+       list_del(&(block->link));
+    } else {
+       // we may not be on the free list if we are being
+       // forcibly removed before all allocations are freed
+    }
+       
     rb_erase(&(pool->tree_node), &(zone->mempools));
 
     palacios_free(pool->tag_bits);
@@ -254,6 +260,7 @@ int buddy_remove_pool(struct buddy_memzone * zone,
     unsigned long flags = 0;
     int ret = 0;
 
+
     palacios_spinlock_lock_irqsave(&(zone->lock), flags);    
     ret = __buddy_remove_mempool(zone, base_addr, force, user_metadata);
     palacios_spinlock_unlock_irqrestore(&(zone->lock), flags);
@@ -380,7 +387,7 @@ buddy_alloc(struct buddy_memzone *zone, unsigned long order, int constraints)
 /**
  * Returns a block of memory to the buddy system memory allocator.
  */
-void
+int
 buddy_free(
        //!    Buddy system memory allocator object.
        struct buddy_memzone *  zone,
@@ -415,9 +422,9 @@ buddy_free(
     pool = find_mempool(zone, addr);
 
     if ((pool == NULL) || (order > pool->pool_order)) {
-       WARNING("Attempted to free an invalid page address (%p)\n", (void *)addr);
+       WARNING("Attempted to free an invalid page address (%p) - pool=%p order=%lu\n", (void *)addr,pool,order);
        palacios_spinlock_unlock_irqrestore(&(zone->lock), flags);
-       return;
+       return -1;
     }
 
 
@@ -427,7 +434,7 @@ buddy_free(
     if (is_available(pool, block)) {
        ERROR("Error: Freeing an available block\n");
        palacios_spinlock_unlock_irqrestore(&(zone->lock), flags);
-       return;
+       return -1;
     }
 
     pool->num_free_blocks += (1UL << (order - zone->min_order));
@@ -458,6 +465,8 @@ buddy_free(
     list_add(&(block->link), &(zone->avail[order]));
 
     palacios_spinlock_unlock_irqrestore(&(zone->lock), flags);
+
+    return 0;
 }