From 9342d5f807795f973fb76c89c48d8e4afd5e5887 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 3 Jul 2014 21:19:57 -0600 Subject: [PATCH] flist: add flist_first_entry() Signed-off-by: Jens Axboe --- diskutil.c | 4 ++-- flist.h | 12 ++++++++++++ gclient.c | 2 +- gfio.c | 2 +- goptions.c | 4 ++-- graph.c | 12 ++++++------ io_u.c | 2 +- iolog.c | 8 +++----- lib/tp.c | 6 ++---- trim.c | 2 +- verify.c | 4 ++-- 11 files changed, 33 insertions(+), 25 deletions(-) diff --git a/diskutil.c b/diskutil.c index cb285cff..c5c5ea6c 100644 --- a/diskutil.c +++ b/diskutil.c @@ -30,7 +30,7 @@ static void disk_util_free(struct disk_util *du) while (!flist_empty(&du->slaves)) { struct disk_util *slave; - slave = flist_entry(du->slaves.next, struct disk_util, slavelist); + slave = flist_first_entry(&du->slaves, struct disk_util, slavelist); flist_del(&slave->slavelist); slave->users--; } @@ -562,7 +562,7 @@ void disk_util_prune_entries(void) while (!flist_empty(&disk_list)) { struct disk_util *du; - du = flist_entry(disk_list.next, struct disk_util, list); + du = flist_first_entry(&disk_list, struct disk_util, list); flist_del(&du->list); disk_util_free(du); } diff --git a/flist.h b/flist.h index 938ce1d8..d453e791 100644 --- a/flist.h +++ b/flist.h @@ -147,6 +147,15 @@ static inline void flist_splice_tail(struct flist_head *list, __flist_splice(list, head->prev, head); } +static inline void flist_splice_tail_init(struct flist_head *list, + struct flist_head *head) +{ + if (!flist_empty(list)) { + __flist_splice(list, head->prev, head); + INIT_FLIST_HEAD(list); + } +} + static inline void flist_splice_init(struct flist_head *list, struct flist_head *head) { @@ -165,6 +174,9 @@ static inline void flist_splice_init(struct flist_head *list, #define flist_entry(ptr, type, member) \ container_of(ptr, type, member) +#define flist_first_entry(ptr, type, member) \ + flist_entry((ptr)->next, type, member) + /** * flist_for_each - iterate over a list * @pos: the &struct flist_head to use as a loop counter. diff --git a/gclient.c b/gclient.c index d236f866..42bc7614 100644 --- a/gclient.c +++ b/gclient.c @@ -694,7 +694,7 @@ static void gfio_client_job_start(struct fio_client *client, struct fio_net_cmd static void gfio_client_iolog(struct fio_client *client, struct cmd_iolog_pdu *pdu) { - printf("got iolog: name=%s, type=%u, entries=%u\n", pdu->name, pdu->log_type, pdu->nr_samples); + printf("got iolog: name=%s, type=%u, entries=%lu\n", pdu->name, pdu->log_type, (unsigned long) pdu->nr_samples); free(pdu); } diff --git a/gfio.c b/gfio.c index 65302e60..37c1db69 100644 --- a/gfio.c +++ b/gfio.c @@ -444,7 +444,7 @@ static int send_job_file(struct gui_entry *ge) while (!flist_empty(&gc->o_list)) { struct gfio_client_options *gco; - gco = flist_entry(gc->o_list.next, struct gfio_client_options, list); + gco = flist_first_entry(&gc->o_list, struct gfio_client_options, list); flist_del(&gco->list); free(gco); } diff --git a/goptions.c b/goptions.c index 5b5c89ea..c01b6cc7 100644 --- a/goptions.c +++ b/goptions.c @@ -1433,7 +1433,7 @@ static int gopt_handle_changed_options(struct gopt_job_view *gjv) goto done; while (!flist_empty(&gjv->changed_list)) { - gopt = flist_entry(gjv->changed_list.next, struct gopt, changed_list); + gopt = flist_first_entry(&gjv->changed_list, struct gopt, changed_list); flist_del_init(&gopt->changed_list); } @@ -1577,7 +1577,7 @@ void gopt_get_options_window(GtkWidget *window, struct gfio_client *gc) gjv = calloc(1, sizeof(*gjv)); INIT_FLIST_HEAD(&gjv->changed_list); - gco = flist_entry(gc->o_list.next, struct gfio_client_options, list); + gco = flist_first_entry(&gc->o_list, struct gfio_client_options, list); gjv->o = &gco->o; gjv->dialog = dialog; gjv->client = gc; diff --git a/graph.c b/graph.c index 5c865dcf..c45954c7 100644 --- a/graph.c +++ b/graph.c @@ -687,7 +687,7 @@ static void graph_value_drop(struct graph_label *l, struct graph_value *v) */ while (!(v->flags & GV_F_ON_PRIO)) { assert(!flist_empty(&v->alias)); - v = flist_entry(v->alias.next, struct graph_value, alias); + v = flist_first_entry(&v->alias, struct graph_value, alias); } prio_tree_remove(&l->prio_tree, &v->node); @@ -698,7 +698,7 @@ static void graph_value_drop(struct graph_label *l, struct graph_value *v) while (!flist_empty(&v->alias)) { struct graph_value *a; - a = flist_entry(v->alias.next, struct graph_value, alias); + a = flist_first_entry(&v->alias, struct graph_value, alias); flist_del_init(&a->alias); __graph_value_drop(l, a); @@ -773,7 +773,7 @@ static void graph_label_add_value(struct graph_label *i, void *value, to_drop = 2; while (to_drop-- && !flist_empty(&i->value_list)) { - x = flist_entry(i->value_list.next, struct graph_value, list); + x = flist_first_entry(&i->value_list, struct graph_value, list); graph_value_drop(i, x); /* @@ -836,7 +836,7 @@ static void graph_free_values(struct graph_label *l) struct graph_value *i; while (!flist_empty(&l->value_list)) { - i = flist_entry(l->value_list.next, struct graph_value, list); + i = flist_first_entry(&l->value_list, struct graph_value, list); graph_value_drop(l, i); } } @@ -846,7 +846,7 @@ static void graph_free_labels(struct graph *g) struct graph_label *i; while (!flist_empty(&g->label_list)) { - i = flist_entry(g->label_list.next, struct graph_label, list); + i = flist_first_entry(&g->label_list, struct graph_label, list); flist_del(&i->list); graph_free_values(i); free(i); @@ -1010,7 +1010,7 @@ const char *graph_find_tooltip(struct graph *g, int ix, int iy) } } if (!flist_empty(&v->alias)) - v = flist_entry(v->alias.next, struct graph_value, alias); + v = flist_first_entry(&v->alias, struct graph_value, alias); } while (v != rootv); } while ((n = prio_tree_next(&iter)) != NULL); diff --git a/io_u.c b/io_u.c index 5b9d483d..16b52d63 100644 --- a/io_u.c +++ b/io_u.c @@ -223,7 +223,7 @@ static int get_next_rand_offset(struct thread_data *td, struct fio_file *f, if (!flist_empty(&td->next_rand_list)) { struct rand_off *r; fetch: - r = flist_entry(td->next_rand_list.next, struct rand_off, list); + r = flist_first_entry(&td->next_rand_list, struct rand_off, list); flist_del(&r->list); *b = r->off; free(r); diff --git a/iolog.c b/iolog.c index 8bfd5bcf..c725a4fd 100644 --- a/iolog.c +++ b/iolog.c @@ -131,7 +131,7 @@ int read_iolog_get(struct thread_data *td, struct io_u *io_u) while (!flist_empty(&td->io_log_list)) { int ret; - ipo = flist_entry(td->io_log_list.next, struct io_piece, list); + ipo = flist_first_entry(&td->io_log_list, struct io_piece, list); flist_del(&ipo->list); remove_trim_entry(td, ipo); @@ -184,7 +184,7 @@ void prune_io_piece_log(struct thread_data *td) } while (!flist_empty(&td->io_hist_list)) { - ipo = flist_entry(td->io_hist_list.next, struct io_piece, list); + ipo = flist_entry(&td->io_hist_list, struct io_piece, list); flist_del(&ipo->list); remove_trim_entry(td, ipo); td->io_hist_len--; @@ -773,14 +773,12 @@ static int flush_chunk(struct iolog_compress *ic, int gz_hdr, FILE *f, static void flush_gz_chunks(struct io_log *log, FILE *f) { struct flush_chunk_iter iter = { .chunk_sz = log->log_gz, }; - struct flist_head *node; z_stream stream; while (!flist_empty(&log->chunk_list)) { struct iolog_compress *ic; - node = log->chunk_list.next; - ic = flist_entry(node, struct iolog_compress, list); + ic = flist_first_entry(&log->chunk_list, struct iolog_compress, list); flist_del(&ic->list); if (log->log_gz_store) diff --git a/lib/tp.c b/lib/tp.c index 25f7eb6d..5111910e 100644 --- a/lib/tp.c +++ b/lib/tp.c @@ -33,10 +33,8 @@ static void *tp_thread(void *data) if (!tdat->thread_exit && flist_empty(&tdat->work)) pthread_cond_wait(&tdat->cv, &tdat->lock); - if (!flist_empty(&tdat->work)) { - flist_splice(&tdat->work, &work_list); - INIT_FLIST_HEAD(&tdat->work); - } + if (!flist_empty(&tdat->work)) + flist_splice_tail_init(&tdat->work, &work_list); pthread_mutex_unlock(&tdat->lock); diff --git a/trim.c b/trim.c index de792dc4..a7f1b867 100644 --- a/trim.c +++ b/trim.c @@ -24,7 +24,7 @@ int get_next_trim(struct thread_data *td, struct io_u *io_u) return 1; 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); io_u->offset = ipo->offset; diff --git a/verify.c b/verify.c index 26157012..11963e15 100644 --- a/verify.c +++ b/verify.c @@ -1082,7 +1082,7 @@ int get_next_verify(struct thread_data *td, struct io_u *io_u) assert(ipo->flags & IP_F_ONRB); ipo->flags &= ~IP_F_ONRB; } else if (!flist_empty(&td->io_hist_list)) { - ipo = flist_entry(td->io_hist_list.next, struct io_piece, list); + ipo = flist_first_entry(&td->io_hist_list, struct io_piece, list); /* * Ensure that the associated IO has completed @@ -1187,7 +1187,7 @@ static void *verify_async_thread(void *data) continue; while (!flist_empty(&list)) { - io_u = flist_entry(list.next, struct io_u, verify_list); + io_u = flist_first_entry(&list, struct io_u, verify_list); flist_del(&io_u->verify_list); ret = verify_io_u(td, io_u); -- 2.25.1