[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] xentrace: simplify map_page function in xenctx



There were several problems:

1. Variable mapped was set to NULL so the following two "if"s were
   useless.
2. Variable previous_mfn was set but never used.

Simplify the function by removing two "if"s and previous_mfn.  Check if
mfn == 0 instead. Finally remove the now unused out label.

Wrapped long lines while I was there.

Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
Compile test only.

Cc: George Dunlap <george.dunlap@xxxxxxxxxxxxx>
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Cc: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
---
 tools/xentrace/xenctx.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index e647179..ee6f800 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -686,28 +686,27 @@ static void print_ctx(vcpu_guest_context_any_t *ctx_any)
 #ifndef NO_TRANSLATION
 static void *map_page(vcpu_guest_context_any_t *ctx, int vcpu, guest_word_t 
virt)
 {
-    static unsigned long previous_mfn = 0;
     static void *mapped = NULL;
-
-    unsigned long mfn = xc_translate_foreign_address(xenctx.xc_handle, 
xenctx.domid, vcpu, virt);
+    unsigned long mfn;
     unsigned long offset = virt & ~XC_PAGE_MASK;
 
-    if (mapped && mfn == previous_mfn)
-        goto out;
-
-    if (mapped)
-        munmap(mapped, XC_PAGE_SIZE);
 
-    previous_mfn = mfn;
+    mfn = xc_translate_foreign_address(xenctx.xc_handle, xenctx.domid,
+                                       vcpu, virt);
+    if (mfn == 0) {
+        fprintf(stderr, "\nfailed to translate "FMT_32B_WORD" into MFN.\n",
+                virt);
+        return NULL;
+    }
 
-    mapped = xc_map_foreign_range(xenctx.xc_handle, xenctx.domid, 
XC_PAGE_SIZE, PROT_READ, mfn);
+    mapped = xc_map_foreign_range(xenctx.xc_handle, xenctx.domid,
+                                  XC_PAGE_SIZE, PROT_READ, mfn);
 
     if (mapped == NULL) {
         fprintf(stderr, "\nfailed to map page for "FMT_32B_WORD".\n", virt);
         return NULL;
     }
 
- out:
     return (void *)(mapped + offset);
 }
 
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.