From: Jens Axboe <axboe@kernel.dk>
To: Daniel Gollub <daniel.gollub@t-online.de>, fio@vger.kernel.org
Cc: Daniel Gollub <d.gollub@telekom.de>
Subject: Re: [PATCH 1/2] Introduce get_ioengine for external engines
Date: Wed, 12 Feb 2014 21:12:16 -0700 [thread overview]
Message-ID: <52FC4620.3030205@kernel.dk> (raw)
In-Reply-To: <1392232426-16152-1-git-send-email-d.gollub@telekom.de>
On 2014-02-12 12:13, Daniel Gollub wrote:
> This makes life easier for plugins written in C++
> since they do not need to deal with struct initilization issues
> with the ioengine_ops symbol.
>
> With g++ a non-static ioengine_ops in global scope like this:
>
> struct ioengine_ops ioengine = {
> .name = "null",
> .version = FIO_IOOPS_VERSION,
> .queue = fio_null_queue,
> .commit = fio_null_commit,
> };
>
> Results in:
>
> cpp_null2.cc: At global scope:
> cpp_null2.cc:112:1: error: C99 designator ‘name’ outside aggregate initializer
> cpp_null2.cc:112:1: sorry, unimplemented: non-trivial designated initializers not supported
> cpp_null2.cc:112:1: sorry, unimplemented: non-trivial designated initializers not supported
> cpp_null2.cc:112:1: sorry, unimplemented: non-trivial designated initializers not supported
> cpp_null2.cc:112:1: sorry, unimplemented: non-trivial designated initializers not supported
> $
>
> Example get_iongine() symbol usage:
>
> ---8<---
> extern "C" {
> void get_ioengine(struct ioengine_ops **ioengine_ptr) {
> struct ioengine_ops *ioengine;
> *ioengine_ptr = (struct ioengine_ops *) malloc(sizeof(struct ioengine_ops));
> ioengine = *ioengine_ptr;
>
> strcpy(ioengine->name, "cpp_null");
> ioengine->version = FIO_IOOPS_VERSION;
> ioengine->queue = fio_null_queue;
> ioengine->commit = fio_null_commit;
> ioengine->getevents = fio_null_getevents;
> ioengine->event = fio_null_event;
> ioengine->init = fio_null_init;
> ioengine->cleanup = fio_null_cleanup;
> ioengine->open_file = fio_null_open;
> ioengine->flags = FIO_DISKLESSIO;
> }
> }
> --->8---
>
> Signed-off-by: Daniel Gollub <d.gollub@telekom.de>
> ---
> ioengines.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/ioengines.c b/ioengines.c
> index d71e372..c080da3 100644
> --- a/ioengines.c
> +++ b/ioengines.c
> @@ -90,6 +90,7 @@ static struct ioengine_ops *dlopen_ioengine(struct thread_data *td,
> {
> struct ioengine_ops *ops;
> void *dlhandle;
> + typedef void (*get_ioengine_t)(struct ioengine_ops **);
>
> dprint(FD_IO, "dload engine %s\n", engine_lib);
>
> @@ -107,6 +108,19 @@ static struct ioengine_ops *dlopen_ioengine(struct thread_data *td,
> ops = dlsym(dlhandle, engine_lib);
> if (!ops)
> ops = dlsym(dlhandle, "ioengine");
> +
> + /*
> + * For some external engines (like C++ ones) it is not that trivial
> + * to provide a non-static ionengine structure that we can reference.
> + * Instead we call a method which allocates the required ioengine
> + * structure.
> + */
> + if (!ops) {
> + get_ioengine_t get_ioengine = dlsym(dlhandle, "get_ioengine");
> + if (get_ioengine)
> + get_ioengine(&ops);
> + }
> +
> if (!ops) {
> td_vmsg(td, -1, dlerror(), "dlsym");
> dlclose(dlhandle);
>
This looks fine, but lets put that typedef in ioengine.h instead.
--
Jens Axboe
prev parent reply other threads:[~2014-02-13 4:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-12 19:13 [PATCH 1/2] Introduce get_ioengine for external engines Daniel Gollub
2014-02-12 19:13 ` [PATCH 2/2] engines/null: allow build as external C++ ioengine Daniel Gollub
2014-02-13 4:13 ` Jens Axboe
2014-02-13 6:25 ` Daniel Gollub
2014-02-13 4:12 ` Jens Axboe [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=52FC4620.3030205@kernel.dk \
--to=axboe@kernel.dk \
--cc=d.gollub@telekom.de \
--cc=daniel.gollub@t-online.de \
--cc=fio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox