mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
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>
This commit is contained in:
1 parent
cacf9acf52
commit
f6574fa1d4
1 file changed
+25
@@ -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(
|
||||
|
||||