The following changes since commit dc0518cad2a86ce860347f77880b4cdcb842c296: Fix Windows build by defining clock sources and adding include file. (2013-01-28 18:44:55 +0100) are available in the git repository at: git://git.kernel.dk/fio.git master Jens Axboe (4): configure: add --extra-cflags configure: enable --extra-cflags for Windows client/server: fixup missing TRIM conversions smalloc: alloc failure cleanups Ken Raeburn (1): Fix crash with absurdly but not impossibly deeply nested device stacks cgroup.c | 18 ++++++++++++++++++ client.c | 14 +++++++------- configure | 24 ++++++++++++++++++++---- diskutil.c | 14 +++++++++++++- diskutil.h | 2 +- fio.c | 8 -------- flow.c | 29 ++++++++++++++++++++++++++--- gettime-thread.c | 6 ++++-- server.c | 12 ++++++------ verify.c | 1 - 10 files changed, 95 insertions(+), 33 deletions(-) --- Diff of recent changes: diff --git a/cgroup.c b/cgroup.c index 86d4d5e..34b61de 100644 --- a/cgroup.c +++ b/cgroup.c @@ -52,9 +52,22 @@ static void add_cgroup(struct thread_data *td, const char *name, { struct cgroup_member *cm; + if (!lock) + return; + cm = smalloc(sizeof(*cm)); + if (!cm) { +err: + log_err("fio: failed to allocate cgroup member\n"); + return; + } + INIT_FLIST_HEAD(&cm->list); cm->root = smalloc_strdup(name); + if (!cm->root) { + sfree(cm); + goto err; + } if (td->o.cgroup_nodelete) cm->cgroup_nodelete = 1; fio_mutex_down(lock); @@ -67,6 +80,9 @@ void cgroup_kill(struct flist_head *clist) struct flist_head *n, *tmp; struct cgroup_member *cm; + if (!lock) + return; + fio_mutex_down(lock); flist_for_each_safe(n, tmp, clist) { @@ -183,6 +199,8 @@ void cgroup_shutdown(struct thread_data *td, char **mnt) static void fio_init cgroup_init(void) { lock = fio_mutex_init(FIO_MUTEX_UNLOCKED); + if (!lock) + log_err("fio: failed to allocate cgroup lock\n"); } static void fio_exit cgroup_exit(void) diff --git a/client.c b/client.c index 83cb57e..6021e4a 100644 --- a/client.c +++ b/client.c @@ -596,7 +596,7 @@ static void convert_ts(struct thread_stat *dst, struct thread_stat *src) dst->pid = le32_to_cpu(src->pid); dst->members = le32_to_cpu(src->members); - for (i = 0; i < 2; i++) { + for (i = 0; i < DDIR_RWDIR_CNT; i++) { convert_io_stat(&dst->clat_stat[i], &src->clat_stat[i]); convert_io_stat(&dst->slat_stat[i], &src->slat_stat[i]); convert_io_stat(&dst->lat_stat[i], &src->lat_stat[i]); @@ -628,11 +628,11 @@ static void convert_ts(struct thread_stat *dst, struct thread_stat *src) dst->io_u_lat_m[i] = le32_to_cpu(src->io_u_lat_m[i]); } - for (i = 0; i < 2; i++) + for (i = 0; i < DDIR_RWDIR_CNT; i++) for (j = 0; j < FIO_IO_U_PLAT_NR; j++) dst->io_u_plat[i][j] = le32_to_cpu(src->io_u_plat[i][j]); - for (i = 0; i < 3; i++) { + for (i = 0; i < DDIR_RWDIR_CNT; i++) { dst->total_io_u[i] = le64_to_cpu(src->total_io_u[i]); dst->short_io_u[i] = le64_to_cpu(src->short_io_u[i]); } @@ -640,7 +640,7 @@ static void convert_ts(struct thread_stat *dst, struct thread_stat *src) dst->total_submit = le64_to_cpu(src->total_submit); dst->total_complete = le64_to_cpu(src->total_complete); - for (i = 0; i < 2; i++) { + for (i = 0; i < DDIR_RWDIR_CNT; i++) { dst->io_bytes[i] = le64_to_cpu(src->io_bytes[i]); dst->runtime[i] = le64_to_cpu(src->runtime[i]); } @@ -656,7 +656,7 @@ static void convert_gs(struct group_run_stats *dst, struct group_run_stats *src) { int i; - for (i = 0; i < 2; i++) { + for (i = 0; i < DDIR_RWDIR_CNT; i++) { dst->max_run[i] = le64_to_cpu(src->max_run[i]); dst->min_run[i] = le64_to_cpu(src->min_run[i]); dst->max_bw[i] = le64_to_cpu(src->max_bw[i]); @@ -763,7 +763,7 @@ static void convert_jobs_eta(struct jobs_eta *je) je->m_iops = le32_to_cpu(je->m_iops); je->t_iops = le32_to_cpu(je->t_iops); - for (i = 0; i < 2; i++) { + for (i = 0; i < DDIR_RWDIR_CNT; i++) { je->rate[i] = le32_to_cpu(je->rate[i]); je->iops[i] = le32_to_cpu(je->iops[i]); } @@ -786,7 +786,7 @@ static void sum_jobs_eta(struct jobs_eta *dst, struct jobs_eta *je) dst->m_iops += je->m_iops; dst->t_iops += je->t_iops; - for (i = 0; i < 2; i++) { + for (i = 0; i < DDIR_RWDIR_CNT; i++) { dst->rate[i] += je->rate[i]; dst->iops[i] += je->iops[i]; } diff --git a/configure b/configure index 3ea10b2..583e3ab 100755 --- a/configure +++ b/configure @@ -30,7 +30,8 @@ rm -rf $config_host_mak rm -rf $config_host_h # Default CFLAGS -EXTFLAGS="-include config-host.h -D_GNU_SOURCE" +CFLAGS="-D_GNU_SOURCE" +EXTFLAGS="-include config-host.h" # Print a helpful header at the top of config.log echo "# FIO configure log $(date)" >> config.log @@ -121,18 +122,33 @@ cpu="" cc="${CC-${cross_prefix}gcc}" +show_help="no" +exit_val=0 + # parse options for opt do optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` case "$opt" in --cc=*) CC="$optarg" ;; + --extra-cflags=*) CFLAGS="$CFLAGS $optarg" + ;; + --help) + show_help="yes" + ;; *) echo "Bad option $opt" - exit 1 + show_help="yes" + exit_val=1 esac done +if test "$show_help" = "yes" ; then + echo "--cc= Specify compiler to use" + echo "--extra-cflags= Specify extra CFLAGS to pass to compiler" + exit $exit_val +fi + if check_define __linux__ ; then targetos="Linux" elif check_define __OpenBSD__ ; then @@ -185,7 +201,7 @@ CYGWIN*) output_sym "CONFIG_GETTIMEOFDAY" output_sym "CONFIG_CLOCK_GETTIME" echo "CC=$CC" >> $config_host_mak - echo "EXTFLAGS=-include config-host.h -D_GNU_SOURCE" >> $config_host_mak + echo "EXTFLAGS=$CFLAGS -include config-host.h -D_GNU_SOURCE" >> $config_host_mak exit 0 esac @@ -934,4 +950,4 @@ fi echo "LIBS+=$LIBS" >> $config_host_mak echo "CC=$cc" >> $config_host_mak -echo "EXTFLAGS=$EXTFLAGS" >> $config_host_mak +echo "EXTFLAGS=$EXTFLAGS $CFLAGS" >> $config_host_mak diff --git a/diskutil.c b/diskutil.c index fbc4268..e29d1c3 100644 --- a/diskutil.c +++ b/diskutil.c @@ -276,13 +276,25 @@ static struct disk_util *disk_util_add(struct thread_data *td, int majdev, { struct disk_util *du, *__du; struct flist_head *entry; + int l; dprint(FD_DISKUTIL, "add maj/min %d/%d: %s\n", majdev, mindev, path); du = smalloc(sizeof(*du)); + if (!du) { + log_err("fio: smalloc() pool exhausted\n"); + return NULL; + } + memset(du, 0, sizeof(*du)); INIT_FLIST_HEAD(&du->list); - sprintf(du->path, "%s/stat", path); + l = snprintf(du->path, sizeof(du->path), "%s/stat", path); + if (l < 0 || l >= sizeof(du->path)) { + log_err("constructed path \"%.100s[...]/stat\" larger than buffer (%zu bytes)\n", + path, sizeof(du->path) - 1); + sfree(du); + return NULL; + } strncpy((char *) du->dus.name, basename(path), FIO_DU_NAME_SZ); du->sysfs_root = path; du->major = majdev; diff --git a/diskutil.h b/diskutil.h index b89aacc..ddd6471 100644 --- a/diskutil.h +++ b/diskutil.h @@ -42,7 +42,7 @@ struct disk_util { char *name; char *sysfs_root; - char path[256]; + char path[PATH_MAX]; int major, minor; struct disk_util_stat dus; diff --git a/fio.c b/fio.c index a408727..af4c12c 100644 --- a/fio.c +++ b/fio.c @@ -26,15 +26,7 @@ #include <time.h> #include "fio.h" -#include "hash.h" #include "smalloc.h" -#include "verify.h" -#include "trim.h" -#include "diskutil.h" -#include "profile.h" -#include "lib/rand.h" -#include "memalign.h" -#include "server.h" uintptr_t page_mask; uintptr_t page_size; diff --git a/flow.c b/flow.c index 2993f4e..b7a2fb1 100644 --- a/flow.c +++ b/flow.c @@ -39,6 +39,9 @@ static struct fio_flow *flow_get(unsigned int id) 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 +54,10 @@ static struct fio_flow *flow_get(unsigned int id) if (!flow) { flow = smalloc(sizeof(*flow)); + if (!flow) { + log_err("fio: smalloc pool exhausted\n"); + return NULL; + } flow->refs = 0; INIT_FLIST_HEAD(&flow->list); flow->id = id; @@ -66,6 +73,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 +102,26 @@ void flow_exit_job(struct thread_data *td) void flow_init(void) { - flow_lock = fio_mutex_init(FIO_MUTEX_UNLOCKED); 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); } diff --git a/gettime-thread.c b/gettime-thread.c index da40904..c1b4b09 100644 --- a/gettime-thread.c +++ b/gettime-thread.c @@ -14,12 +14,14 @@ static pthread_t gtod_thread; void fio_gtod_init(void) { fio_tv = smalloc(sizeof(struct timeval)); - assert(fio_tv); + if (!fio_tv) + log_err("fio: smalloc pool exhausted\n"); } static void fio_gtod_update(void) { - gettimeofday(fio_tv, NULL); + if (fio_tv) + gettimeofday(fio_tv, NULL); } static void *gtod_thread_main(void *data) diff --git a/server.c b/server.c index 3607ee8..0cc3fad 100644 --- a/server.c +++ b/server.c @@ -445,7 +445,7 @@ static int handle_send_eta_cmd(struct fio_net_cmd *cmd) je->m_iops = cpu_to_le32(je->m_iops); je->t_iops = cpu_to_le32(je->t_iops); - for (i = 0; i < 2; i++) { + for (i = 0; i < DDIR_RWDIR_CNT; i++) { je->rate[i] = cpu_to_le32(je->rate[i]); je->iops[i] = cpu_to_le32(je->iops[i]); } @@ -637,7 +637,7 @@ static void convert_gs(struct group_run_stats *dst, struct group_run_stats *src) { int i; - for (i = 0; i < 2; i++) { + for (i = 0; i < DDIR_RWDIR_CNT; i++) { dst->max_run[i] = cpu_to_le64(src->max_run[i]); dst->min_run[i] = cpu_to_le64(src->min_run[i]); dst->max_bw[i] = cpu_to_le64(src->max_bw[i]); @@ -672,7 +672,7 @@ void fio_server_send_ts(struct thread_stat *ts, struct group_run_stats *rs) p.ts.pid = cpu_to_le32(ts->pid); p.ts.members = cpu_to_le32(ts->members); - for (i = 0; i < 2; i++) { + for (i = 0; i < DDIR_RWDIR_CNT; i++) { convert_io_stat(&p.ts.clat_stat[i], &ts->clat_stat[i]); convert_io_stat(&p.ts.slat_stat[i], &ts->slat_stat[i]); convert_io_stat(&p.ts.lat_stat[i], &ts->lat_stat[i]); @@ -704,11 +704,11 @@ void fio_server_send_ts(struct thread_stat *ts, struct group_run_stats *rs) p.ts.io_u_lat_m[i] = cpu_to_le32(ts->io_u_lat_m[i]); } - for (i = 0; i < 2; i++) + for (i = 0; i < DDIR_RWDIR_CNT; i++) for (j = 0; j < FIO_IO_U_PLAT_NR; j++) p.ts.io_u_plat[i][j] = cpu_to_le32(ts->io_u_plat[i][j]); - for (i = 0; i < 3; i++) { + for (i = 0; i < DDIR_RWDIR_CNT; i++) { p.ts.total_io_u[i] = cpu_to_le64(ts->total_io_u[i]); p.ts.short_io_u[i] = cpu_to_le64(ts->short_io_u[i]); } @@ -716,7 +716,7 @@ void fio_server_send_ts(struct thread_stat *ts, struct group_run_stats *rs) p.ts.total_submit = cpu_to_le64(ts->total_submit); p.ts.total_complete = cpu_to_le64(ts->total_complete); - for (i = 0; i < 2; i++) { + for (i = 0; i < DDIR_RWDIR_CNT; i++) { p.ts.io_bytes[i] = cpu_to_le64(ts->io_bytes[i]); p.ts.runtime[i] = cpu_to_le64(ts->runtime[i]); } diff --git a/verify.c b/verify.c index cb13b62..daa2f04 100644 --- a/verify.c +++ b/verify.c @@ -10,7 +10,6 @@ #include "fio.h" #include "verify.h" -#include "smalloc.h" #include "trim.h" #include "lib/rand.h" #include "lib/hweight.h" -- To unsubscribe from this list: send the line "unsubscribe fio" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html