From ddf2284295cd4ee05d01dd3157b6f7c6ba20292c Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 16 Feb 2006 20:07:00 +0100 Subject: [PATCH] [PATCH] blktrace: don't truncate/open local files when in net client mode --- blktrace.c | 88 +++++++++++++++++++++++++++++------------------------- 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/blktrace.c b/blktrace.c index 3cecc1e..1520029 100644 --- a/blktrace.c +++ b/blktrace.c @@ -541,7 +541,6 @@ static int get_subbuf_sendfile(struct thread_information *tip, struct tip_subbuf *ts = malloc(sizeof(*ts)); struct stat sb; - ts->buf = malloc(buf_size); ts->max_len = maxlen; ts->buf = NULL; @@ -928,48 +927,65 @@ static void fill_ops(struct thread_information *tip) tip->read_data = read_data_file; } -static int start_threads(struct device_information *dip) +static int tip_open_output(struct device_information *dip, + struct thread_information *tip) { - struct thread_information *tip; - int j, pipeline = output_name && !strcmp(output_name, "-"); + int pipeline = output_name && !strcmp(output_name, "-"); int mode, vbuf_size; char op[64]; - for_each_tip(dip, tip, j) { - tip->cpu = j; - tip->device = dip; - tip->events_processed = 0; - memset(&tip->fifo, 0, sizeof(tip->fifo)); - tip->leftover_ts = NULL; - - if (pipeline) { - tip->ofile = fdopen(STDOUT_FILENO, "w"); - tip->ofile_stdout = 1; - tip->ofile_mmap = 0; - mode = _IOLBF; - vbuf_size = 512; - } else { - fill_ofname(op, dip->buts_name, tip->cpu); - tip->ofile = fopen(op, "w+"); - tip->ofile_stdout = 0; - tip->ofile_mmap = 1; - mode = _IOFBF; - vbuf_size = OFILE_BUF; - } + if (net_mode == Net_client) { + tip->ofile = NULL; + tip->ofile_stdout = 0; + tip->ofile_mmap = 0; + vbuf_size = 0; + } else if (pipeline) { + tip->ofile = fdopen(STDOUT_FILENO, "w"); + tip->ofile_stdout = 1; + tip->ofile_mmap = 0; + mode = _IOLBF; + vbuf_size = 512; + } else { + fill_ofname(op, dip->buts_name, tip->cpu); + tip->ofile = fopen(op, "w+"); + tip->ofile_stdout = 0; + tip->ofile_mmap = 1; + mode = _IOFBF; + vbuf_size = OFILE_BUF; + } - if (tip->ofile == NULL) { - perror(op); - return 1; - } + if (net_mode != Net_client && tip->ofile == NULL) { + perror(op); + return 1; + } + if (vbuf_size) { tip->ofile_buffer = malloc(vbuf_size); if (setvbuf(tip->ofile, tip->ofile_buffer, mode, vbuf_size)) { perror("setvbuf"); close_thread(tip); return 1; } + } + + fill_ops(tip); + return 0; +} - fill_ops(tip); +static int start_threads(struct device_information *dip) +{ + struct thread_information *tip; + int j; + + for_each_tip(dip, tip, j) { + tip->cpu = j; + tip->device = dip; + tip->events_processed = 0; + memset(&tip->fifo, 0, sizeof(tip->fifo)); + tip->leftover_ts = NULL; + + if (tip_open_output(dip, tip)) + return 1; if (pthread_create(&tip->thread, NULL, thread_main, tip)) { perror("pthread_create"); @@ -1166,22 +1182,12 @@ static struct device_information *net_get_dip(char *buts_name) */ for (i = 0; i < ncpus; i++) { struct thread_information *tip = &dip->threads[i]; - char op[64]; tip->cpu = i; - tip->ofile_stdout = 0; - tip->ofile_mmap = 1; tip->device = dip; - fill_ops(tip); - - fill_ofname(op, dip->buts_name, tip->cpu); - - tip->ofile = fopen(op, "w+"); - if (!tip->ofile) { - perror("fopen"); + if (tip_open_output(dip, tip)) return NULL; - } } return dip; -- 2.25.1