X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=filesetup.c;h=5ce0f6803ae7d952c262d25728b1a60ec7bff86f;hp=1acf6adcf377cfe861590ad067baec1e0db643b6;hb=1417daeb92c44632f2e1e376d736a0f198d7af8d;hpb=5903e7b7907854014478b6febfc5645a203ff59e diff --git a/filesetup.c b/filesetup.c index 1acf6adc..5ce0f680 100644 --- a/filesetup.c +++ b/filesetup.c @@ -50,10 +50,11 @@ static int extend_file(struct thread_data *td, struct fio_file *f) * does that for operations involving reads, or for writes * where overwrite is set */ - if (td_read(td) || (td_write(td) && td->o.overwrite) || + if (td_read(td) || + (td_write(td) && td->o.overwrite && !td->o.file_append) || (td_write(td) && td->io_ops->flags & FIO_NOEXTEND)) new_layout = 1; - if (td_write(td) && !td->o.overwrite) + if (td_write(td) && !td->o.overwrite && !td->o.file_append) unlink_file = 1; if (unlink_file || new_layout) { @@ -209,8 +210,7 @@ static int pre_read_file(struct thread_data *td, struct fio_file *f) did_open = 1; } - old_runstate = td->runstate; - td_set_runstate(td, TD_PRE_READING); + old_runstate = td_bump_runstate(td, TD_PRE_READING); bs = td->o.max_bs[DDIR_READ]; b = malloc(bs); @@ -234,7 +234,7 @@ static int pre_read_file(struct thread_data *td, struct fio_file *f) } } - td_set_runstate(td, old_runstate); + td_restore_runstate(td, old_runstate); if (did_open) td->io_ops->close_file(td, f); @@ -723,8 +723,13 @@ static unsigned long long get_fs_free_counts(struct thread_data *td) return ret; } -uint64_t get_start_offset(struct thread_data *td) +uint64_t get_start_offset(struct thread_data *td, struct fio_file *f) { + struct thread_options *o = &td->o; + + if (o->file_append && f->filetype == FIO_TYPE_FILE) + return f->real_file_size; + return td->o.start_offset + (td->thread_number - 1) * td->o.offset_increment; } @@ -745,8 +750,7 @@ int setup_files(struct thread_data *td) dprint(FD_FILE, "setup files\n"); - old_state = td->runstate; - td_set_runstate(td, TD_SETTING_UP); + old_state = td_bump_runstate(td, TD_SETTING_UP); if (o->read_iolog_file) goto done; @@ -812,7 +816,7 @@ int setup_files(struct thread_data *td) extend_size = total_size = 0; need_extend = 0; for_each_file(td, f, i) { - f->file_offset = get_start_offset(td); + f->file_offset = get_start_offset(td, f); if (!o->file_size_low) { /* @@ -925,12 +929,12 @@ done: if (o->create_only) td->done = 1; - td_set_runstate(td, old_state); + td_restore_runstate(td, old_state); return 0; err_offset: log_err("%s: you need to specify valid offset=\n", o->name); err_out: - td_set_runstate(td, old_state); + td_restore_runstate(td, old_state); return 1; } @@ -980,11 +984,12 @@ static int init_rand_distribution(struct thread_data *td) if (td->o.random_distribution == FIO_RAND_DIST_RANDOM) return 0; - state = td->runstate; - td_set_runstate(td, TD_SETTING_UP); + state = td_bump_runstate(td, TD_SETTING_UP); + for_each_file(td, f, i) __init_rand_distribution(td, f); - td_set_runstate(td, state); + + td_restore_runstate(td, state); return 1; } @@ -1010,7 +1015,7 @@ int init_random_map(struct thread_data *td) seed = td->rand_seeds[FIO_RAND_BLOCK_OFF]; - if (!lfsr_init(&f->lfsr, blocks, seed, seed & 0xF)) + if (!lfsr_init(&f->lfsr, blocks, seed, 0)) continue; } else if (!td->o.norandommap) { f->io_axmap = axmap_new(blocks); @@ -1053,16 +1058,16 @@ void close_and_free_files(struct thread_data *td) dprint(FD_FILE, "close files\n"); for_each_file(td, f, i) { - if (td->o.unlink && f->filetype == FIO_TYPE_FILE) { - dprint(FD_FILE, "free unlink %s\n", f->file_name); - unlink(f->file_name); - } - if (fio_file_open(f)) td_io_close_file(td, f); remove_file_hash(f); + if (td->o.unlink && f->filetype == FIO_TYPE_FILE) { + dprint(FD_FILE, "free unlink %s\n", f->file_name); + unlink(f->file_name); + } + sfree(f->file_name); f->file_name = NULL; axmap_free(f->io_axmap);