ia64/xen-unstable

changeset 14186:d66dff09338a

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@xensource.com>
author kfraser@localhost.localdomain
date Wed Feb 28 18:15:42 2007 +0000 (2007-02-28)
parents d2646466e0a7
children 3379f667c3a6
files tools/libxc/xc_linux.c tools/libxc/xc_linux_save.c tools/libxc/xc_private.h tools/libxc/xc_solaris.c
line diff
     1.1 --- a/tools/libxc/xc_linux.c	Wed Feb 28 18:06:56 2007 +0000
     1.2 +++ b/tools/libxc/xc_linux.c	Wed Feb 28 18:15:42 2007 +0000
     1.3 @@ -329,14 +329,15 @@ int xc_evtchn_unmask(int xce_handle, evt
     1.4  }
     1.5  
     1.6  /* Optionally flush file to disk and discard page cache */
     1.7 -int discard_file_cache(int fd, int flush) 
     1.8 +void discard_file_cache(int fd, int flush) 
     1.9  {
    1.10      off_t cur = 0;
    1.11 +    int saved_errno = errno;
    1.12  
    1.13      if ( flush && (fsync(fd) < 0) )
    1.14      {
    1.15 -        PERROR("Failed to flush file: %s", strerror(errno));
    1.16 -        return -errno;
    1.17 +        /*PERROR("Failed to flush file: %s", strerror(errno));*/
    1.18 +        goto out;
    1.19      }
    1.20  
    1.21      /* 
    1.22 @@ -354,11 +355,12 @@ int discard_file_cache(int fd, int flush
    1.23      /* Discard from the buffer cache. */
    1.24      if ( posix_fadvise64(fd, 0, cur, POSIX_FADV_DONTNEED) < 0 )
    1.25      {
    1.26 -        PERROR("Failed to discard cache: %s", strerror(errno));
    1.27 -        return -errno;
    1.28 +        /*PERROR("Failed to discard cache: %s", strerror(errno));*/
    1.29 +        goto out;
    1.30      }
    1.31  
    1.32 -    return 0;
    1.33 + out:
    1.34 +    errno = saved_errno;
    1.35  }
    1.36  
    1.37  /*
     2.1 --- a/tools/libxc/xc_linux_save.c	Wed Feb 28 18:06:56 2007 +0000
     2.2 +++ b/tools/libxc/xc_linux_save.c	Wed Feb 28 18:15:42 2007 +0000
     2.3 @@ -178,20 +178,14 @@ static int noncached_write(int fd, int l
     2.4  
     2.5      int rc = write(fd,buffer,len);
     2.6  
     2.7 -    if (!live) {
     2.8 -        write_count += len;
     2.9 -
    2.10 -        if (write_count >= MAX_PAGECACHE_USAGE*PAGE_SIZE) {
    2.11 -            int serrno = errno;
    2.12 +    write_count += len;
    2.13  
    2.14 -            /* Time to discard cache - dont care if this fails */
    2.15 -            discard_file_cache(fd, 0 /* no flush */);
    2.16 +    if (write_count >= MAX_PAGECACHE_USAGE*PAGE_SIZE) {
    2.17 +        /* Time to discard cache - dont care if this fails */
    2.18 +        discard_file_cache(fd, 0 /* no flush */);
    2.19 +        write_count = 0;
    2.20 +    }
    2.21  
    2.22 -            write_count = 0;
    2.23 -
    2.24 -            errno = serrno;
    2.25 -        }
    2.26 -    }
    2.27      return rc;
    2.28  }
    2.29  
    2.30 @@ -1286,10 +1280,9 @@ int xc_linux_save(int xc_handle, int io_
    2.31              DPRINTF("Warning - couldn't disable shadow mode");
    2.32          }
    2.33      }
    2.34 -    else {
    2.35 -        // flush last write and discard cache for file
    2.36 -        discard_file_cache(io_fd, 1 /* flush */);
    2.37 -    }            
    2.38 +
    2.39 +    // flush last write and discard cache for file
    2.40 +    discard_file_cache(io_fd, 1 /* flush */);
    2.41  
    2.42      if (live_shinfo)
    2.43          munmap(live_shinfo, PAGE_SIZE);
    2.44 @@ -1300,10 +1293,10 @@ int xc_linux_save(int xc_handle, int io_
    2.45      if (live_p2m_frame_list)
    2.46          munmap(live_p2m_frame_list, P2M_FLL_ENTRIES * PAGE_SIZE);
    2.47  
    2.48 -    if(live_p2m)
    2.49 +    if (live_p2m)
    2.50          munmap(live_p2m, P2M_SIZE);
    2.51  
    2.52 -    if(live_m2p)
    2.53 +    if (live_m2p)
    2.54          munmap(live_m2p, M2P_SIZE(max_mfn));
    2.55  
    2.56      free(pfn_type);
     3.1 --- a/tools/libxc/xc_private.h	Wed Feb 28 18:06:56 2007 +0000
     3.2 +++ b/tools/libxc/xc_private.h	Wed Feb 28 18:15:42 2007 +0000
     3.3 @@ -166,6 +166,6 @@ void bitmap_64_to_byte(uint8_t *bp, cons
     3.4  void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits);
     3.5  
     3.6  /* Optionally flush file to disk and discard page cache */
     3.7 -int discard_file_cache(int fd, int flush);
     3.8 +void discard_file_cache(int fd, int flush);
     3.9  
    3.10  #endif /* __XC_PRIVATE_H__ */
     4.1 --- a/tools/libxc/xc_solaris.c	Wed Feb 28 18:06:56 2007 +0000
     4.2 +++ b/tools/libxc/xc_solaris.c	Wed Feb 28 18:15:42 2007 +0000
     4.3 @@ -244,8 +244,7 @@ int xc_evtchn_unmask(int xce_handle, evt
     4.4  }
     4.5  
     4.6  /* Optionally flush file to disk and discard page cache */
     4.7 -int discard_file_cache(int fd, int flush) 
     4.8 +void discard_file_cache(int fd, int flush) 
     4.9  {
    4.10      // TODO: Implement for Solaris!
    4.11 -    return 0;
    4.12  }