glusterfs: update for new API
[fio.git] / goptions.c
index b78accd..f44254b 100644 (file)
@@ -1,5 +1,5 @@
 #include <locale.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include <glib.h>
@@ -11,6 +11,7 @@
 #include "ghelpers.h"
 #include "gerror.h"
 #include "parse.h"
+#include "optgroup.h"
 
 struct gopt {
        GtkWidget *box;
@@ -92,10 +93,10 @@ struct gopt_job_view {
 static GNode *gopt_dep_tree;
 
 static GtkWidget *gopt_get_group_frame(struct gopt_job_view *gjv,
-                                      GtkWidget *box, unsigned int groupmask)
+                                      GtkWidget *box, uint64_t groupmask)
 {
-       unsigned int mask, group;
-       struct opt_group *og;
+       uint64_t mask, group;
+       const struct opt_group *og;
        GtkWidget *frame, *hbox;
        struct gopt_frame_widget *gfw;
 
@@ -107,7 +108,7 @@ static GtkWidget *gopt_get_group_frame(struct gopt_job_view *gjv,
        if (!og)
                return NULL;
 
-       group = ffz(~groupmask);
+       group = ffz64(~groupmask);
        gfw = &gjv->g_widgets[group];
        if (!gfw->vbox[0]) {
                frame = gtk_frame_new(og->name);
@@ -825,7 +826,7 @@ static struct gopt *gopt_new_str_val(struct gopt_job_view *gjv,
                                     unsigned long long *p, unsigned int idx)
 {
        struct gopt_str_val *g;
-       const gchar *postfix[] = { "B", "KB", "MB", "GB", "PB", "TB", "" };
+       const gchar *postfix[] = { "B", "KiB", "MiB", "GiB", "PiB", "PiB", "" };
        GtkWidget *label;
        int i;
 
@@ -874,7 +875,7 @@ static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o,
                struct gopt_str_val *g;
 
                if (o->off1)
-                       ullp = td_var(to, o->off1);
+                       ullp = td_var(to, o, o->off1);
 
                g = container_of(gopt, struct gopt_str_val, gopt);
                if (ullp)
@@ -886,32 +887,43 @@ static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o,
                struct gopt_int *i;
 
                if (o->off1)
-                       ullp = td_var(to, o->off1);
+                       ullp = td_var(to, o, o->off1);
 
                i = container_of(gopt, struct gopt_int, gopt);
                if (ullp)
                        gopt_int_set_val(i, *ullp);
                break;
                }
-       case FIO_OPT_INT: {
-               unsigned int *ip = NULL;
-               struct gopt_int *i;
+       case FIO_OPT_INT:
+               if (o->posval[0].ival) {
+                       unsigned int *ip = NULL;
+                       struct gopt_combo *c;
 
-               if (o->off1)
-                       ip = td_var(to, o->off1);
+                       if (o->off1)
+                               ip = td_var(to, o, o->off1);
 
-               i = container_of(gopt, struct gopt_int, gopt);
-               if (ip)
-                       gopt_int_set_val(i, *ip);
-               break;
+                       c = container_of(gopt, struct gopt_combo, gopt);
+                       if (ip)
+                               gopt_combo_int_set_val(c, *ip);
+               } else {
+                       unsigned int *ip = NULL;
+                       struct gopt_int *i;
+
+                       if (o->off1)
+                               ip = td_var(to, o, o->off1);
+
+                       i = container_of(gopt, struct gopt_int, gopt);
+                       if (ip)
+                               gopt_int_set_val(i, *ip);
                }
+               break;
        case FIO_OPT_STR_SET:
        case FIO_OPT_BOOL: {
                unsigned int *ip = NULL;
                struct gopt_bool *b;
 
                if (o->off1)
-                       ip = td_var(to, o->off1);
+                       ip = td_var(to, o, o->off1);
 
                b = container_of(gopt, struct gopt_bool, gopt);
                if (ip)
@@ -924,7 +936,7 @@ static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o,
                        struct gopt_combo *c;
 
                        if (o->off1)
-                               ip = td_var(to, o->off1);
+                               ip = td_var(to, o, o->off1);
 
                        c = container_of(gopt, struct gopt_combo, gopt);
                        if (ip)
@@ -934,7 +946,7 @@ static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o,
                        char *text = NULL;
 
                        if (o->off1) {
-                               char **p = td_var(to, o->off1);
+                               char **p = td_var(to, o, o->off1);
 
                                text = *p;
                        }
@@ -950,7 +962,7 @@ static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o,
                char *text = NULL;
 
                if (o->off1) {
-                       char **p = td_var(to, o->off1);
+                       char **p = td_var(to, o, o->off1);
                        text = *p;
                }
 
@@ -972,10 +984,10 @@ static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o,
                break;
        case FIO_OPT_RANGE: {
                struct gopt_range *r;
-               unsigned int *ip[4] = { td_var(to, o->off1),
-                                       td_var(to, o->off2),
-                                       td_var(to, o->off3),
-                                       td_var(to, o->off4) };
+               unsigned int *ip[4] = { td_var(to, o, o->off1),
+                                       td_var(to, o, o->off2),
+                                       td_var(to, o, o->off3),
+                                       td_var(to, o, o->off4) };
 
                r = container_of(gopt, struct gopt_range, gopt);
                gopt_int_range_set_val(r, *ip);
@@ -1003,7 +1015,7 @@ static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox,
                unsigned long long *ullp = NULL;
 
                if (o->off1)
-                       ullp = td_var(to, o->off1);
+                       ullp = td_var(to, o, o->off1);
 
                go = gopt_new_str_val(gjv, o, ullp, opt_index);
                break;
@@ -1012,26 +1024,34 @@ static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox,
                unsigned long long *ullp = NULL;
 
                if (o->off1)
-                       ullp = td_var(to, o->off1);
+                       ullp = td_var(to, o, o->off1);
 
                go = gopt_new_ullong(gjv, o, ullp, opt_index);
                break;
                }
-       case FIO_OPT_INT: {
-               unsigned int *ip = NULL;
+       case FIO_OPT_INT:
+               if (o->posval[0].ival) {
+                       unsigned int *ip = NULL;
 
-               if (o->off1)
-                       ip = td_var(to, o->off1);
+                       if (o->off1)
+                               ip = td_var(to, o, o->off1);
 
-               go = gopt_new_int(gjv, o, ip, opt_index);
-               break;
+                       go = gopt_new_combo_int(gjv, o, ip, opt_index);
+               } else {
+                       unsigned int *ip = NULL;
+
+                       if (o->off1)
+                               ip = td_var(to, o, o->off1);
+
+                       go = gopt_new_int(gjv, o, ip, opt_index);
                }
+               break;
        case FIO_OPT_STR_SET:
        case FIO_OPT_BOOL: {
                unsigned int *ip = NULL;
 
                if (o->off1)
-                       ip = td_var(to, o->off1);
+                       ip = td_var(to, o, o->off1);
 
                go = gopt_new_bool(gjv, o, ip, opt_index);
                break;
@@ -1041,7 +1061,7 @@ static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox,
                        unsigned int *ip = NULL;
 
                        if (o->off1)
-                               ip = td_var(to, o->off1);
+                               ip = td_var(to, o, o->off1);
 
                        go = gopt_new_combo_int(gjv, o, ip, opt_index);
                } else {
@@ -1055,7 +1075,7 @@ static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox,
                char *text = NULL;
 
                if (o->off1) {
-                       char **p = td_var(to, o->off1);
+                       char **p = td_var(to, o, o->off1);
                        text = *p;
                }
 
@@ -1071,10 +1091,10 @@ static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox,
                go = gopt_new_str_multi(gjv, o, opt_index);
                break;
        case FIO_OPT_RANGE: {
-               unsigned int *ip[4] = { td_var(to, o->off1),
-                                       td_var(to, o->off2),
-                                       td_var(to, o->off3),
-                                       td_var(to, o->off4) };
+               unsigned int *ip[4] = { td_var(to, o, o->off1),
+                                       td_var(to, o, o->off2),
+                                       td_var(to, o, o->off3),
+                                       td_var(to, o, o->off4) };
 
                go = gopt_new_int_range(gjv, o, ip, opt_index);
                break;
@@ -1116,11 +1136,11 @@ static void gopt_add_options(struct gopt_job_view *gjv,
         */
        for (i = 0; fio_options[i].name; i++) {
                struct fio_option *o = &fio_options[i];
-               unsigned int mask = o->category;
-               struct opt_group *og;
+               uint64_t mask = o->category;
+               const struct opt_group *og;
 
                while ((og = opt_group_from_mask(&mask)) != NULL) {
-                       GtkWidget *vbox = gjv->vboxes[ffz(~og->mask)];
+                       GtkWidget *vbox = gjv->vboxes[ffz64(~og->mask)];
 
                        hbox = gtk_hbox_new(FALSE, 3);
                        gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
@@ -1158,19 +1178,20 @@ static GtkWidget *gopt_add_tab(GtkWidget *notebook, const char *name)
        return vbox;
 }
 
-static GtkWidget *gopt_add_group_tab(GtkWidget *notebook, struct opt_group *og)
+static GtkWidget *gopt_add_group_tab(GtkWidget *notebook,
+                                    const struct opt_group *og)
 {
        return gopt_add_tab(notebook, og->name);
 }
 
 static void gopt_add_group_tabs(GtkWidget *notebook, struct gopt_job_view *gjv)
 {
-       struct opt_group *og;
+       const struct opt_group *og;
        unsigned int i;
 
        i = 0;
        do {
-               unsigned int mask = (1U << i);
+               uint64_t mask = (1ULL << i);
 
                og = opt_group_from_mask(&mask);
                if (!og)
@@ -1184,7 +1205,7 @@ static void gopt_handle_str_multi_changed(struct gopt_job_view *gjv,
                                          struct gopt_str_multi *m,
                                          struct fio_option *o)
 {
-       unsigned int *ip = td_var(gjv->o, o->off1);
+       unsigned int *ip = td_var(gjv->o, o, o->off1);
        struct value_pair *vp;
        gboolean set;
        guint val = 0;
@@ -1197,7 +1218,7 @@ static void gopt_handle_str_multi_changed(struct gopt_job_view *gjv,
                        break;
                set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m->checks[i]));
                if (set) {
-                       if (vp->or)
+                       if (vp->orval)
                                val |= vp->oval;
                        else
                                val = vp->oval;
@@ -1214,10 +1235,10 @@ static void gopt_handle_range_changed(struct gopt_job_view *gjv,
                                      struct gopt_range *r,
                                      struct fio_option *o)
 {
-       unsigned int *ip[4] = { td_var(gjv->o, o->off1),
-                               td_var(gjv->o, o->off2),
-                               td_var(gjv->o, o->off3),
-                               td_var(gjv->o, o->off4) };
+       unsigned int *ip[4] = { td_var(gjv->o, o, o->off1),
+                               td_var(gjv->o, o, o->off2),
+                               td_var(gjv->o, o, o->off3),
+                               td_var(gjv->o, o, o->off4) };
        gint val;
        int i;
 
@@ -1231,7 +1252,7 @@ static void gopt_handle_str_val_changed(struct gopt_job_view *gjv,
                                        struct gopt_str_val *s,
                                        struct fio_option *o)
 {
-       unsigned long long *ullp = td_var(gjv->o, o->off1);
+       unsigned long long *ullp = td_var(gjv->o, o, o->off1);
        GtkAdjustment *adj;
        gint index;
 
@@ -1255,7 +1276,7 @@ static void gopt_handle_str_val_changed(struct gopt_job_view *gjv,
 static void gopt_handle_str_changed(struct gopt_job_view *gjv,
                                    struct gopt_str *s, struct fio_option *o)
 {
-       char **p = td_var(gjv->o, o->off1);
+       char **p = td_var(gjv->o, o, o->off1);
 
        if (*p)
                free(*p);
@@ -1266,7 +1287,7 @@ static void gopt_handle_str_changed(struct gopt_job_view *gjv,
 static void gopt_handle_bool_changed(struct gopt_job_view *gjv,
                                     struct gopt_bool *b, struct fio_option *o)
 {
-       unsigned int *ip = td_var(gjv->o, o->off1);
+       unsigned int *ip = td_var(gjv->o, o, o->off1);
        gboolean set;
 
        set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b->check));
@@ -1276,7 +1297,7 @@ static void gopt_handle_bool_changed(struct gopt_job_view *gjv,
 static void gopt_handle_int_changed(struct gopt_job_view *gjv,
                                    struct gopt_int *i, struct fio_option *o)
 {
-       unsigned int *ip = td_var(gjv->o, o->off1);
+       unsigned int *ip = td_var(gjv->o, o, o->off1);
        GtkAdjustment *adj;
        guint val;
 
@@ -1289,7 +1310,7 @@ static void gopt_handle_combo_str_changed(struct gopt_job_view *gjv,
                                          struct gopt_combo *c,
                                          struct fio_option *o)
 {
-       char **p = td_var(gjv->o, o->off1);
+       char **p = td_var(gjv->o, o, o->off1);
 
        if (*p)
                free(*p);
@@ -1301,7 +1322,7 @@ static void gopt_handle_combo_int_changed(struct gopt_job_view *gjv,
                                          struct gopt_combo *c,
                                          struct fio_option *o)
 {
-       unsigned int *ip = td_var(gjv->o, o->off1);
+       unsigned int *ip = td_var(gjv->o, o, o->off1);
        gint index;
 
        index = gtk_combo_box_get_active(GTK_COMBO_BOX(c->combo));
@@ -1371,8 +1392,8 @@ static void gopt_handle_changed(struct gopt *gopt)
                break;
                }
        default:
-               log_err("gfio: bad option type %s/%d\n", gopt->opt_type);
-               return;
+               log_err("gfio: bad option type%d\n", gopt->opt_type);
+               break;
        }
 }
 
@@ -1414,7 +1435,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);
        }
 
@@ -1558,7 +1579,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;