From 343cb4a98200757bdcb0c5203e9120bb777625a8 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 9 Mar 2012 17:16:51 +0100 Subject: [PATCH] gfio: hold a reference to the fio_client structure Signed-off-by: Jens Axboe --- client.c | 16 ++++++++++------ client.h | 2 ++ gfio.c | 6 +++++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/client.c b/client.c index 7eb0cdcf..f9a16026 100644 --- a/client.c +++ b/client.c @@ -87,10 +87,8 @@ static struct fio_client *find_client_by_fd(int fd) flist_for_each(entry, &client_hash[bucket]) { client = flist_entry(entry, struct fio_client, hash_list); - if (client->fd == fd) { - client->refs++; - return client; - } + if (client->fd == fd) + return fio_get_client(client); } return NULL; @@ -124,11 +122,17 @@ static void remove_client(struct fio_client *client) sum_stat_clients--; } -static void put_client(struct fio_client *client) +void fio_put_client(struct fio_client *client) { remove_client(client); } +struct fio_client *fio_get_client(struct fio_client *client) +{ + client->refs++; + return client; +} + static void __fio_client_add_cmd_option(struct fio_client *client, const char *opt) { @@ -1193,7 +1197,7 @@ int fio_handle_clients(struct client_ops *ops) retval = 1; } else if (client->error) retval = 1; - put_client(client); + fio_put_client(client); } } diff --git a/client.h b/client.h index e280adbd..caeb432a 100644 --- a/client.h +++ b/client.h @@ -115,6 +115,8 @@ extern struct fio_client *fio_client_add_explicit(struct client_ops *, const cha extern void fio_client_add_cmd_option(void *, const char *); extern void fio_client_terminate(struct fio_client *); extern void fio_clients_terminate(void); +extern struct fio_client *fio_get_client(struct fio_client *); +extern void fio_put_client(struct fio_client *); #endif diff --git a/gfio.c b/gfio.c index c8e178f2..52389bef 100644 --- a/gfio.c +++ b/gfio.c @@ -1777,7 +1777,7 @@ static void gfio_client_added(struct gui_entry *ge, struct fio_client *client) gc = malloc(sizeof(*gc)); memset(gc, 0, sizeof(*gc)); gc->ge = ge; - gc->client = client; + gc->client = fio_get_client(client); ge->client = gc; @@ -1804,6 +1804,10 @@ static struct gui_entry *alloc_new_gui_entry(struct gui *ui) static void ge_destroy(GtkWidget *w, gpointer data) { struct gui_entry *ge = data; + struct gfio_client *gc = ge->client; + + if (gc->client) + fio_put_client(gc->client); flist_del(&ge->list); free(ge); -- 2.25.1