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] [PATCH 23/24] [xen-unstable.hg] remove arbitrary limit in mi

To: "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH 23/24] [xen-unstable.hg] remove arbitrary limit in minios on number of grant refs it can accept
From: Alex Zeffertt <alex.zeffertt@xxxxxxxxxxxxx>
Date: Mon, 23 Mar 2009 15:21:37 +0000
Delivery-date: Mon, 23 Mar 2009 08:40:11 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
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/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Thunderbird 2.0.0.19 (X11/20090105)


Changes the minios gntmap implementation to use a list instead of an array.
This allows it to grow as necessary to support any number of grants.

As an result of this change, setting a maximum number of grants doesn't make
much sense anymore, so it's now just a no-op.

Signed-off-by: Diego Ongaro <diego.ongaro@xxxxxxxxxx>
Signed-off-by: Alex Zeffertt <alex.zeffertt@xxxxxxxxxxxxx>
---

diff -r 7a579b4789b1 extras/mini-os/gntmap.c
--- a/extras/mini-os/gntmap.c   Wed Mar 18 16:34:53 2009 +0000
+++ b/extras/mini-os/gntmap.c   Wed Mar 18 17:17:11 2009 +0000
@@ -37,44 +37,20 @@
 #include <inttypes.h>
 #include "gntmap.h"
 
-#define DEFAULT_MAX_GRANTS 128
-
 struct gntmap_entry {
+    struct minios_list_head list;
     unsigned long host_addr;
     grant_handle_t handle;
 };
 
-static inline int
-gntmap_entry_used(struct gntmap_entry *entry)
-{
-    return entry->host_addr != 0;
-}
-
-static struct gntmap_entry*
-gntmap_find_free_entry(struct gntmap *map)
-{
-    int i;
-
-    for (i = 0; i < map->nentries; i++) {
-        if (!gntmap_entry_used(&map->entries[i]))
-            return &map->entries[i];
-    }
-
-#ifdef GNTMAP_DEBUG
-    printk("gntmap_find_free_entry(map=%p): all %d entries full\n",
-           map, map->nentries);
-#endif
-    return NULL;
-}
-
 static struct gntmap_entry*
 gntmap_find_entry(struct gntmap *map, unsigned long addr)
 {
-    int i;
+    struct gntmap_entry *i;
 
-    for (i = 0; i < map->nentries; i++) {
-        if (map->entries[i].host_addr == addr)
-            return &map->entries[i];
+    minios_list_for_each_entry(i, &map->entries, list) {
+        if (i->host_addr == addr)
+            return i;
     }
     return NULL;
 }
@@ -82,19 +58,6 @@
 int
 gntmap_set_max_grants(struct gntmap *map, int count)
 {
-#ifdef GNTMAP_DEBUG
-    printk("gntmap_set_max_grants(map=%p, count=%d)\n", map, count);
-#endif
-
-    if (map->nentries != 0)
-        return -EBUSY;
-
-    map->entries = xmalloc_array(struct gntmap_entry, count);
-    if (map->entries == NULL)
-        return -ENOMEM;
-
-    memset(map->entries, 0, sizeof(struct gntmap_entry) * count);
-    map->nentries = count;
     return 0;
 }
 
@@ -169,6 +132,8 @@
         }
 
         rc = _gntmap_unmap_grant_ref(ent);
+        minios_list_del(&ent->list);
+        xfree(ent);
         if (rc != 0)
             return rc;
     }
@@ -197,14 +162,12 @@
            refs, refs == NULL ? 0 : refs[0], writable);
 #endif
 
-    (void) gntmap_set_max_grants(map, DEFAULT_MAX_GRANTS);
-
     addr = allocate_ondemand((unsigned long) count, 1);
     if (addr == 0)
         return NULL;
 
     for (i = 0; i < count; i++) {
-        ent = gntmap_find_free_entry(map);
+        ent = xmalloc(struct gntmap_entry);
         if (ent == NULL ||
             _gntmap_map_grant_ref(ent,
                                   addr + PAGE_SIZE * i,
@@ -212,9 +175,11 @@
                                   refs[i],
                                   writable) != 0) {
 
+            xfree(ent);
             (void) gntmap_munmap(map, addr, i);
             return NULL;
         }
+        minios_list_add(&ent->list, &map->entries);
     }
 
     return (void*) addr;
@@ -226,27 +191,21 @@
 #ifdef GNTMAP_DEBUG
     printk("gntmap_init(map=%p)\n", map);
 #endif
-    map->nentries = 0;
-    map->entries = NULL;
+    MINIOS_INIT_LIST_HEAD(&map->entries);
 }
 
 void
 gntmap_fini(struct gntmap *map)
 {
-    struct gntmap_entry *ent;
-    int i;
+    struct gntmap_entry *ent, *tmp;
 
 #ifdef GNTMAP_DEBUG
     printk("gntmap_fini(map=%p)\n", map);
 #endif
 
-    for (i = 0; i < map->nentries; i++) {
-        ent = &map->entries[i];
-        if (gntmap_entry_used(ent))
-            (void) _gntmap_unmap_grant_ref(ent);
+    minios_list_for_each_entry_safe(ent, tmp, &map->entries, list) {
+        (void) _gntmap_unmap_grant_ref(ent);
+        minios_list_del(&ent->list);
+        xfree(ent);
     }
-
-    xfree(map->entries);
-    map->entries = NULL;
-    map->nentries = 0;
 }
diff -r 7a579b4789b1 extras/mini-os/include/gntmap.h
--- a/extras/mini-os/include/gntmap.h   Wed Mar 18 16:34:53 2009 +0000
+++ b/extras/mini-os/include/gntmap.h   Wed Mar 18 17:17:11 2009 +0000
@@ -2,14 +2,14 @@
 #define __GNTMAP_H__
 
 #include <os.h>
+#include "list.h"
 
 /*
  * Please consider struct gntmap opaque. If instead you choose to disregard
  * this message, I insist that you keep an eye out for raptors.
  */
 struct gntmap {
-    int nentries;
-    struct gntmap_entry *entries;
+    struct minios_list_head entries;
 };
 
 int


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH 23/24] [xen-unstable.hg] remove arbitrary limit in minios on number of grant refs it can accept, Alex Zeffertt <=