X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=trim.c;h=78cf67244efa22534604fd6b6652379457a571a2;hp=cf42625b20f26c51f95af6e3d45ba29f838543c5;hb=c32e1a09dc24d570274172efb6d7686c0f0e1291;hpb=0d29de831183dfd049c97a03008d425ce21e2fa4 diff --git a/trim.c b/trim.c index cf42625b..78cf6724 100644 --- a/trim.c +++ b/trim.c @@ -11,7 +11,7 @@ #include "trim.h" #ifdef FIO_HAVE_TRIM -int get_next_trim(struct thread_data *td, struct io_u *io_u) +bool get_next_trim(struct thread_data *td, struct io_u *io_u) { struct io_piece *ipo; @@ -19,14 +19,17 @@ int get_next_trim(struct thread_data *td, struct io_u *io_u) * this io_u is from a requeue, we already filled the offsets */ if (io_u->file) - return 0; + return true; if (flist_empty(&td->trim_list)) - return 0; + return false; assert(td->trim_entries); - ipo = flist_entry(td->trim_list.next, struct io_piece, trim_list); + ipo = flist_first_entry(&td->trim_list, struct io_piece, trim_list); remove_trim_entry(td, ipo); - ipo->flags |= IP_F_TRIMMED; + + io_u->offset = ipo->offset; + io_u->buflen = ipo->len; + io_u->file = ipo->file; /* * If not verifying that trimmed ranges return zeroed data, @@ -40,11 +43,9 @@ int get_next_trim(struct thread_data *td, struct io_u *io_u) rb_erase(&ipo->rb_node, &td->io_hist_tree); } td->io_hist_len--; - } - - io_u->offset = ipo->offset; - io_u->buflen = ipo->len; - io_u->file = ipo->file; + free(ipo); + } else + ipo->flags |= IP_F_TRIMMED; if (!fio_file_open(io_u->file)) { int r = td_io_open_file(td, io_u->file); @@ -52,33 +53,34 @@ int get_next_trim(struct thread_data *td, struct io_u *io_u) if (r) { dprint(FD_VERIFY, "failed file %s open\n", io_u->file->file_name); - return 1; + return false; } } - get_file(ipo->file); + get_file(io_u->file); assert(fio_file_open(io_u->file)); io_u->ddir = DDIR_TRIM; io_u->xfer_buf = NULL; io_u->xfer_buflen = io_u->buflen; - free(ipo); dprint(FD_VERIFY, "get_next_trim: ret io_u %p\n", io_u); - return 0; + return true; } -int io_u_should_trim(struct thread_data *td, struct io_u *io_u) +bool io_u_should_trim(struct thread_data *td, struct io_u *io_u) { unsigned long long val; - long r; + uint64_t frand_max; + unsigned long r; if (!td->o.trim_percentage) - return 0; + return false; - r = os_random_long(&td->trim_state); - val = (OS_RAND_MAX / 100ULL); - val *= (unsigned long long) td->o.trim_percentage; + frand_max = rand_max(&td->trim_state); + r = __rand(&td->trim_state); + val = (frand_max / 100ULL); + val *= (unsigned long long) td->o.trim_percentage; return r <= val; } #endif