flist: add flist_first_entry()
authorJens Axboe <axboe@fb.com>
Fri, 4 Jul 2014 03:19:57 +0000 (21:19 -0600)
committerJens Axboe <axboe@fb.com>
Fri, 4 Jul 2014 03:19:57 +0000 (21:19 -0600)
Signed-off-by: Jens Axboe <axboe@fb.com>
diskutil.c
flist.h
gclient.c
gfio.c
goptions.c
graph.c
io_u.c
iolog.c
lib/tp.c
trim.c
verify.c

index cb285cffb31d3137421518dbba6c5c42e14e1bbf..c5c5ea6ca91b05ab38fcdb69bbf0f3b9b4dc52cd 100644 (file)
@@ -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 938ce1d8317378e18b5824128ac7c4b37f4ff893..d453e791e9072eb67b37c5ff6038bf8ff8eae2fc 100644 (file)
--- 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.
index d236f86667ffeb4624222c2d14de626438a59ce6..42bc7614c5dba730f9a5c8dc0a997c765e63f9f0 100644 (file)
--- 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 65302e6075a01daad0b794417909e0e213b4f66a..37c1db6918d0f8e25280bceea5ec6735dcabee0d 100644 (file)
--- 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);
        }
index 5b5c89ead6995b68c5a40f9bdf7893e372d8ee8b..c01b6cc7d8f835bd3113a8601dc0404aaff50911 100644 (file)
@@ -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 5c865dcf2964fc4c809b1011d45fdbe45c9f3f65..c45954c7f79939b2e38cebacbc028d932076c234 100644 (file)
--- 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 5b9d483dcd330b69ff0ddff4f86cb9512247cf31..16b52d63aa0971e5c73dd9ddb651a14054289bb6 100644 (file)
--- 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 8bfd5bcf25ee5401ce7bbeaf29e1f1868cab3509..c725a4fd4d3f06f9c476cdc29a3ee21378c781c6 100644 (file)
--- 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)
index 25f7eb6dfc034c778a6766ac8265f14a47eca37c..5111910ec518f9d318f7b444d13eea462b5a98fc 100644 (file)
--- 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 de792dc46fd499beed43baffcc9b68184b04cf13..a7f1b8673396413f818eaa20534c3d686886f5ad 100644 (file)
--- 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;
index 261570127c5b21cf8cc6797877d997102c58a1cf..11963e15072d78b43d263cbe258bda90cbf4c0b9 100644 (file)
--- 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);