X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=flow.c;h=e0ac13521f453ed32f2e1ce2fbcdaeb93e70adcc;hp=e5c4a40462ceb5e6e94bebcf3534016ebf6091a4;hb=d7e9266cdb9311b07e2cfeb16a1c4390ca610836;hpb=9e684a4976b7934f5ce011ea281dfef3352e5738 diff --git a/flow.c b/flow.c index e5c4a404..e0ac1352 100644 --- a/flow.c +++ b/flow.c @@ -23,8 +23,11 @@ int flow_threshold_exceeded(struct thread_data *td) sign = td->o.flow > 0 ? 1 : -1; if (sign * flow->flow_counter > td->o.flow_watermark) { - if (td->o.flow_sleep) + if (td->o.flow_sleep) { + io_u_quiesce(td); usleep(td->o.flow_sleep); + } + return 1; } @@ -36,9 +39,12 @@ int flow_threshold_exceeded(struct thread_data *td) static struct fio_flow *flow_get(unsigned int id) { - struct fio_flow *flow; + struct fio_flow *flow = NULL; struct flist_head *n; + if (!flow_lock) + return NULL; + fio_mutex_down(flow_lock); flist_for_each(n, flow_list) { @@ -51,6 +57,11 @@ static struct fio_flow *flow_get(unsigned int id) if (!flow) { flow = smalloc(sizeof(*flow)); + if (!flow) { + log_err("fio: smalloc pool exhausted\n"); + fio_mutex_up(flow_lock); + return NULL; + } flow->refs = 0; INIT_FLIST_HEAD(&flow->list); flow->id = id; @@ -66,6 +77,9 @@ static struct fio_flow *flow_get(unsigned int id) static void flow_put(struct fio_flow *flow) { + if (!flow_lock) + return; + fio_mutex_down(flow_lock); if (!--flow->refs) { @@ -92,13 +106,26 @@ void flow_exit_job(struct thread_data *td) void flow_init(void) { - flow_lock = fio_mutex_init(1); flow_list = smalloc(sizeof(*flow_list)); + if (!flow_list) { + log_err("fio: smalloc pool exhausted\n"); + return; + } + + flow_lock = fio_mutex_init(FIO_MUTEX_UNLOCKED); + if (!flow_lock) { + log_err("fio: failed to allocate flow lock\n"); + sfree(flow_list); + return; + } + INIT_FLIST_HEAD(flow_list); } void flow_exit(void) { - fio_mutex_remove(flow_lock); - sfree(flow_list); + if (flow_lock) + fio_mutex_remove(flow_lock); + if (flow_list) + sfree(flow_list); }