ia64/xen-unstable
changeset 17120:803c964e3ede
xentrace: Add option to reserve disk space
Before writing records, xentrace will check to make sure that there is
a minimum amount of space left on the output filesystem.
Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
Before writing records, xentrace will check to make sure that there is
a minimum amount of space left on the output filesystem.
Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
author | Keir Fraser <keir.fraser@citrix.com> |
---|---|
date | Tue Feb 26 14:38:57 2008 +0000 (2008-02-26) |
parents | 644ddc6514b1 |
children | 0d732e2455b3 |
files | tools/xentrace/xentrace.c |
line diff
1.1 --- a/tools/xentrace/xentrace.c Tue Feb 26 14:38:39 2008 +0000 1.2 +++ b/tools/xentrace/xentrace.c Tue Feb 26 14:38:57 2008 +0000 1.3 @@ -15,6 +15,7 @@ 1.4 #include <sys/mman.h> 1.5 #include <sys/stat.h> 1.6 #include <sys/types.h> 1.7 +#include <sys/vfs.h> 1.8 #include <fcntl.h> 1.9 #include <unistd.h> 1.10 #include <errno.h> 1.11 @@ -53,6 +54,7 @@ typedef struct settings_st { 1.12 uint32_t evt_mask; 1.13 uint32_t cpu_mask; 1.14 unsigned long tbuf_size; 1.15 + unsigned long disk_rsvd; 1.16 uint8_t discard:1; 1.17 } settings_t; 1.18 1.19 @@ -83,8 +85,36 @@ void close_handler(int signal) 1.20 void write_buffer(unsigned int cpu, unsigned char *start, int size, 1.21 int total_size, int outfd) 1.22 { 1.23 + struct statfs stat; 1.24 size_t written = 0; 1.25 1.26 + if ( opts.disk_rsvd != 0 ) 1.27 + { 1.28 + unsigned long long freespace; 1.29 + 1.30 + /* Check that filesystem has enough space. */ 1.31 + if ( fstatfs (outfd, &stat) ) 1.32 + { 1.33 + fprintf(stderr, "Statfs failed!\n"); 1.34 + goto fail; 1.35 + } 1.36 + 1.37 + freespace = stat.f_bsize * (unsigned long long)stat.f_bfree; 1.38 + 1.39 + if ( total_size ) 1.40 + freespace -= total_size; 1.41 + else 1.42 + freespace -= size; 1.43 + 1.44 + freespace >>= 20; /* Convert to MB */ 1.45 + 1.46 + if ( freespace <= opts.disk_rsvd ) 1.47 + { 1.48 + fprintf(stderr, "Disk space limit reached (free space: %lluMB, limit: %luMB).\n", freespace, opts.disk_rsvd); 1.49 + exit (EXIT_FAILURE); 1.50 + } 1.51 + } 1.52 + 1.53 /* Write a CPU_BUF record on each buffer "window" written. Wrapped 1.54 * windows may involve two writes, so only write the record on the 1.55 * first write. */ 1.56 @@ -541,6 +571,7 @@ void parse_args(int argc, char **argv) 1.57 { "cpu-mask", required_argument, 0, 'c' }, 1.58 { "evt-mask", required_argument, 0, 'e' }, 1.59 { "trace-buf-size", required_argument, 0, 'S' }, 1.60 + { "reserve-disk-space", required_argument, 0, 'r' }, 1.61 { "discard-buffers", no_argument, 0, 'D' }, 1.62 { "help", no_argument, 0, '?' }, 1.63 { "version", no_argument, 0, 'V' }, 1.64 @@ -572,11 +603,15 @@ void parse_args(int argc, char **argv) 1.65 printf("%s\n", program_version); 1.66 exit(EXIT_SUCCESS); 1.67 break; 1.68 - 1.69 + 1.70 case 'D': /* Discard traces currently in buffer */ 1.71 opts.discard = 1; 1.72 break; 1.73 - 1.74 + 1.75 + case 'r': /* Disk-space reservation */ 1.76 + opts.disk_rsvd = argtol(optarg, 0); 1.77 + break; 1.78 + 1.79 default: 1.80 usage(); 1.81 } 1.82 @@ -604,6 +639,7 @@ int main(int argc, char **argv) 1.83 opts.poll_sleep = POLL_SLEEP_MILLIS; 1.84 opts.evt_mask = 0; 1.85 opts.cpu_mask = 0; 1.86 + opts.disk_rsvd = 0; 1.87 1.88 parse_args(argc, argv); 1.89