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

[Xen-changelog] [xen-unstable] libxc: Quieten the discard_file_cache() function. Preserve errno



# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Date 1172686542 0
# Node ID d66dff09338a892c016bdb4bfb1fcdd07b1ec8b7
# Parent  d2646466e0a7352ebc11f3277d51d99f737d0fd3
libxc: Quieten the discard_file_cache() function. Preserve errno
across it. No longer make calls to the function dependent on 'non-live
save/restore': it's not a good test of whether the fd is a socket.
Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>
---
 tools/libxc/xc_linux.c      |   18 ++++++++++--------
 tools/libxc/xc_linux_save.c |   33 +++++++++++++--------------------
 tools/libxc/xc_private.h    |    2 +-
 tools/libxc/xc_solaris.c    |    5 ++---
 4 files changed, 26 insertions(+), 32 deletions(-)

diff -r d2646466e0a7 -r d66dff09338a tools/libxc/xc_linux.c
--- a/tools/libxc/xc_linux.c    Wed Feb 28 18:06:56 2007 +0000
+++ b/tools/libxc/xc_linux.c    Wed Feb 28 18:15:42 2007 +0000
@@ -329,14 +329,15 @@ int xc_evtchn_unmask(int xce_handle, evt
 }
 
 /* Optionally flush file to disk and discard page cache */
-int discard_file_cache(int fd, int flush) 
+void discard_file_cache(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));
-        return -errno;
+        /*PERROR("Failed to flush file: %s", strerror(errno));*/
+        goto out;
     }
 
     /* 
@@ -354,11 +355,12 @@ int discard_file_cache(int fd, int flush
     /* Discard from the buffer cache. */
     if ( posix_fadvise64(fd, 0, cur, POSIX_FADV_DONTNEED) < 0 )
     {
-        PERROR("Failed to discard cache: %s", strerror(errno));
-        return -errno;
-    }
-
-    return 0;
+        /*PERROR("Failed to discard cache: %s", strerror(errno));*/
+        goto out;
+    }
+
+ out:
+    errno = saved_errno;
 }
 
 /*
diff -r d2646466e0a7 -r d66dff09338a tools/libxc/xc_linux_save.c
--- a/tools/libxc/xc_linux_save.c       Wed Feb 28 18:06:56 2007 +0000
+++ b/tools/libxc/xc_linux_save.c       Wed Feb 28 18:15:42 2007 +0000
@@ -178,20 +178,14 @@ static int noncached_write(int fd, int l
 
     int rc = write(fd,buffer,len);
 
-    if (!live) {
-        write_count += len;
-
-        if (write_count >= MAX_PAGECACHE_USAGE*PAGE_SIZE) {
-            int serrno = errno;
-
-            /* Time to discard cache - dont care if this fails */
-            discard_file_cache(fd, 0 /* no flush */);
-
-            write_count = 0;
-
-            errno = serrno;
-        }
-    }
+    write_count += len;
+
+    if (write_count >= MAX_PAGECACHE_USAGE*PAGE_SIZE) {
+        /* Time to discard cache - dont care if this fails */
+        discard_file_cache(fd, 0 /* no flush */);
+        write_count = 0;
+    }
+
     return rc;
 }
 
@@ -1286,10 +1280,9 @@ int xc_linux_save(int xc_handle, int io_
             DPRINTF("Warning - couldn't disable shadow mode");
         }
     }
-    else {
-        // flush last write and discard cache for file
-        discard_file_cache(io_fd, 1 /* flush */);
-    }            
+
+    // flush last write and discard cache for file
+    discard_file_cache(io_fd, 1 /* flush */);
 
     if (live_shinfo)
         munmap(live_shinfo, PAGE_SIZE);
@@ -1300,10 +1293,10 @@ int xc_linux_save(int xc_handle, int io_
     if (live_p2m_frame_list)
         munmap(live_p2m_frame_list, P2M_FLL_ENTRIES * PAGE_SIZE);
 
-    if(live_p2m)
+    if (live_p2m)
         munmap(live_p2m, P2M_SIZE);
 
-    if(live_m2p)
+    if (live_m2p)
         munmap(live_m2p, M2P_SIZE(max_mfn));
 
     free(pfn_type);
diff -r d2646466e0a7 -r d66dff09338a tools/libxc/xc_private.h
--- a/tools/libxc/xc_private.h  Wed Feb 28 18:06:56 2007 +0000
+++ b/tools/libxc/xc_private.h  Wed Feb 28 18:15:42 2007 +0000
@@ -166,6 +166,6 @@ void bitmap_byte_to_64(uint64_t *lp, con
 void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits);
 
 /* Optionally flush file to disk and discard page cache */
-int discard_file_cache(int fd, int flush);
+void discard_file_cache(int fd, int flush);
 
 #endif /* __XC_PRIVATE_H__ */
diff -r d2646466e0a7 -r d66dff09338a tools/libxc/xc_solaris.c
--- a/tools/libxc/xc_solaris.c  Wed Feb 28 18:06:56 2007 +0000
+++ b/tools/libxc/xc_solaris.c  Wed Feb 28 18:15:42 2007 +0000
@@ -244,8 +244,7 @@ int xc_evtchn_unmask(int xce_handle, evt
 }
 
 /* Optionally flush file to disk and discard page cache */
-int discard_file_cache(int fd, int flush) 
+void discard_file_cache(int fd, int flush) 
 {
     // TODO: Implement for Solaris!
-    return 0;
-}
+}

_______________________________________________
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®.