From: Jens Axboe Date: Tue, 25 Feb 2014 19:35:27 +0000 (-0800) Subject: Ensure that fio_get_kb_base() doesn't assume 'data' is thread_options X-Git-Tag: fio-2.1.6~17 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=cb1402d674fb7694d1b09d7ef4aeb3d4506f23f0 Ensure that fio_get_kb_base() doesn't assume 'data' is thread_options Nasty hack, but at least we don't corrupt option data. Signed-off-by: Jens Axboe --- diff --git a/options.c b/options.c index 53559829..625d3a25 100644 --- a/options.c +++ b/options.c @@ -3790,6 +3790,7 @@ int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt, void fio_fill_default_options(struct thread_data *td) { + td->o.magic = OPT_MAGIC; fill_default_options(td, fio_options); } @@ -3834,7 +3835,16 @@ unsigned int fio_get_kb_base(void *data) struct thread_options *o = data; unsigned int kb_base = 0; - if (o) + /* + * This is a hack... For private options, *data is not holding + * a pointer to the thread_options, but to private data. This means + * we can't safely dereference it, but magic is first so mem wise + * it is valid. But this also means that if the job first sets + * kb_base and expects that to be honored by private options, + * it will be disappointed. We will return the global default + * for this. + */ + if (o && o->magic == OPT_MAGIC) kb_base = o->kb_base; if (!kb_base) kb_base = 1024; diff --git a/thread_options.h b/thread_options.h index b7a88ed3..14a4e54a 100644 --- a/thread_options.h +++ b/thread_options.h @@ -28,8 +28,10 @@ struct bssplit { uint32_t perc; }; +#define OPT_MAGIC 0x4f50544e + struct thread_options { - int pad; + int magic; char *description; char *name; char *directory;