Don't leak f_out file desciptor if specified more than once
[fio.git] / options.c
index c1a8f323e956986f30155fa0c43976376c449afc..9096a322bbc089db652662f8a1b04defd3f228b3 100644 (file)
--- a/options.c
+++ b/options.c
@@ -283,7 +283,9 @@ static int ignore_error_type(struct thread_data *td, int etype, char *str)
                td->o.continue_on_error |= 1 << etype;
                td->o.ignore_error_nr[etype] = i;
                td->o.ignore_error[etype] = error;
-       }
+       } else
+               free(error);
+
        return 0;
 
 }
@@ -320,7 +322,7 @@ static int str_rw_cb(void *data, const char *str)
 {
        struct thread_data *td = data;
        struct thread_options *o = &td->o;
-       char *nr = get_opt_postfix(str);
+       char *nr;
 
        if (parse_dryrun())
                return 0;
@@ -328,6 +330,7 @@ static int str_rw_cb(void *data, const char *str)
        o->ddir_seq_nr = 1;
        o->ddir_seq_add = 0;
 
+       nr = get_opt_postfix(str);
        if (!nr)
                return 0;
 
@@ -394,16 +397,23 @@ static int str_exitall_cb(void)
 }
 
 #ifdef FIO_HAVE_CPU_AFFINITY
-int fio_cpus_split(os_cpu_mask_t *mask, unsigned int cpu)
+int fio_cpus_split(os_cpu_mask_t *mask, unsigned int cpu_index)
 {
+       unsigned int i, index, cpus_in_mask;
        const long max_cpu = cpus_online();
-       unsigned int i;
 
+       cpus_in_mask = fio_cpu_count(mask);
+       cpu_index = cpu_index % cpus_in_mask;
+
+       index = 0;
        for (i = 0; i < max_cpu; i++) {
-               if (cpu != i) {
-                       fio_cpu_clear(mask, i);
+               if (!fio_cpu_isset(mask, i))
                        continue;
-               }
+
+               if (cpu_index != index)
+                       fio_cpu_clear(mask, i);
+
+               index++;
        }
 
        return fio_cpu_count(mask);
@@ -995,6 +1005,15 @@ static int str_buffer_pattern_cb(void *data, const char *input)
        return ret;
 }
 
+static int str_buffer_compress_cb(void *data, unsigned long long *il)
+{
+       struct thread_data *td = data;
+
+       td->flags |= TD_F_COMPRESS;
+       td->o.compress_percentage = *il;
+       return 0;
+}
+
 static int str_verify_pattern_cb(void *data, const char *input)
 {
        struct thread_data *td = data;
@@ -1598,6 +1617,16 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
                .category = FIO_OPT_C_FILE,
                .group  = FIO_OPT_G_INVALID,
        },
+       {
+               .name   = "file_append",
+               .lname  = "File append",
+               .type   = FIO_OPT_BOOL,
+               .off1   = td_var_offset(file_append),
+               .help   = "IO will start at the end of the file(s)",
+               .def    = "0",
+               .category = FIO_OPT_C_FILE,
+               .group  = FIO_OPT_G_INVALID,
+       },
        {
                .name   = "offset",
                .lname  = "IO offset",
@@ -3111,7 +3140,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
                .name   = "buffer_compress_percentage",
                .lname  = "Buffer compression percentage",
                .type   = FIO_OPT_INT,
-               .off1   = td_var_offset(compress_percentage),
+               .cb     = str_buffer_compress_cb,
                .maxval = 100,
                .minval = 0,
                .help   = "How compressible the buffer is (approximately)",
@@ -3627,8 +3656,10 @@ static char *bc_calc(char *str)
                return NULL;
 
        ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
-       if (ret <= 0)
+       if (ret <= 0) {
+               pclose(f);
                return NULL;
+       }
 
        pclose(f);
        buf[(tmp - str) + ret - 1] = '\0';