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

[Xen-changelog] [xen-unstable] tools, bsd: complete implementation of discard_file_cache



# HG changeset patch
# User Christoph Egger <Christoph.Egger@xxxxxxx>
# Date 1292523716 0
# Node ID 3bb6574e6707a8f6007e97c7d0933b6534d10348
# Parent  f1b435507f343a480e61c926a1b72a4889175ce7
tools, bsd: complete implementation of discard_file_cache

attached patch completes discard_file_cache() for NetBSD.

Signed-off-by: Christoph Egger <Christoph.Egger@xxxxxxx>
Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 tools/libxc/xc_netbsd.c |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletion(-)

diff -r f1b435507f34 -r 3bb6574e6707 tools/libxc/xc_netbsd.c
--- a/tools/libxc/xc_netbsd.c   Thu Dec 16 18:04:08 2010 +0000
+++ b/tools/libxc/xc_netbsd.c   Thu Dec 16 18:21:56 2010 +0000
@@ -280,11 +280,36 @@ int xc_evtchn_unmask(int xce_handle, evt
 /* Optionally flush file to disk and discard page cache */
 void discard_file_cache(xc_interface *xch, int fd, int flush) 
 {
+    off_t cur = 0;
+    int saved_errno = errno;
 
     if ( flush && (fsync(fd) < 0) )
     {
         /*PERROR("Failed to flush file: %s", strerror(errno));*/
-    }
+        goto out;
+    }
+
+    /*
+     * Calculate last page boundry of amount written so far
+     * unless we are flushing in which case entire cache
+     * is discarded.
+     */
+    if ( !flush )
+    {
+        if ( ( cur = lseek(fd, 0, SEEK_CUR)) == (off_t)-1 )
+            cur = 0;
+        cur &= ~(PAGE_SIZE - 1);
+    }
+
+    /* Discard from the buffer cache. */
+    if ( posix_fadvise(fd, 0, cur, POSIX_FADV_DONTNEED) < 0 )
+    {
+        /*PERROR("Failed to discard cache: %s", strerror(errno));*/
+        goto out;
+    }
+
+ out:
+    errno = saved_errno;
 }
 
 grant_entry_v1_t *xc_gnttab_map_table_v1(

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


 


Rackspace

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