All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
To: "xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>
Subject: [PATCH 23/24] [xen-unstable.hg] remove arbitrary limit in minios on number of grant refs it can accept
Date: Mon, 23 Mar 2009 15:21:37 +0000	[thread overview]
Message-ID: <49C7A901.4040306@eu.citrix.com> (raw)

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




[-- Attachment #2: gntmap_list --]
[-- Type: text/plain, Size: 4520 bytes --]

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@citrix.com>
Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
---

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



[-- 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:[~2009-03-23 15:21 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=49C7A901.4040306@eu.citrix.com \
    --to=alex.zeffertt@eu.citrix.com \
    --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.