diff options
author | Christoph Egger <Christoph.Egger@amd.com> | 2010-12-16 18:21:56 +0000 |
---|---|---|
committer | Christoph Egger <Christoph.Egger@amd.com> | 2010-12-16 18:21:56 +0000 |
commit | f6574fa1d4715dbf93b4eab25e8e865d0ce593ab (patch) | |
tree | f71d3ebd3d29b564376553fd575a7e3aab48727a /tools/libxc/xc_netbsd.c | |
parent | cacf9acf525a76c5d2f2d0acd3915fff3d54939a (diff) | |
download | xen-f6574fa1d4715dbf93b4eab25e8e865d0ce593ab.tar.gz xen-f6574fa1d4715dbf93b4eab25e8e865d0ce593ab.tar.bz2 xen-f6574fa1d4715dbf93b4eab25e8e865d0ce593ab.zip |
tools, bsd: complete implementation of discard_file_cache
attached patch completes discard_file_cache() for NetBSD.
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Diffstat (limited to 'tools/libxc/xc_netbsd.c')
-rw-r--r-- | tools/libxc/xc_netbsd.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tools/libxc/xc_netbsd.c b/tools/libxc/xc_netbsd.c index 47f84853ed..41cfa63e49 100644 --- a/tools/libxc/xc_netbsd.c +++ b/tools/libxc/xc_netbsd.c @@ -280,11 +280,36 @@ int xc_evtchn_unmask(int xce_handle, evtchn_port_t port) /* 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( |