From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christoph Egger Subject: [PATCH][TOOLS] libxc: finish discard_file_cache() for NetBSD Date: Wed, 15 Dec 2010 12:35:53 +0100 Message-ID: <201012151235.53820.Christoph.Egger@amd.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Boundary-00=_ZgKCNAgRwK5g2h5" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --Boundary-00=_ZgKCNAgRwK5g2h5 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, attached patch completes discard_file_cache() for NetBSD. Signed-off-by: Christoph Egger -- ---to satisfy European Law for business letters: Advanced Micro Devices GmbH Einsteinring 24, 85609 Dornach b. Muenchen Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632 --Boundary-00=_ZgKCNAgRwK5g2h5 Content-Type: text/x-diff; charset="iso 8859-15"; name="xen_libxc.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="xen_libxc.diff" Content-Description: xen_libxc.diff diff -r be72873a6f30 tools/libxc/xc_netbsd.c --- a/tools/libxc/xc_netbsd.c Wed Dec 15 11:49:51 2010 +0100 +++ b/tools/libxc/xc_netbsd.c Wed Dec 15 12:08:47 2010 +0100 @@ -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; } int xc_gnttab_open(void) --Boundary-00=_ZgKCNAgRwK5g2h5 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --Boundary-00=_ZgKCNAgRwK5g2h5--