engines: Add Network Block Device (NBD) support.
PATCH 1/1 engines: Add Network Block Device (NBD) support.
Hi fio developers,
I'm attaching initial support for testing Network Block Device (NBD) servers directly. There are some problems with this patch, so it's only for discussion.
At the moment you can test NBD servers indirectly by loop mounting a filesystem using nbd.ko. The loop mount method is described here:
https://github.com/libguestfs/nbdkit/blob/master/BENCHMARKING
This tests rather a lot of machinery like the kernel and filesystems which is not part of the NBD server, so I would like to extend fio with an engine that supports NBD servers directly.
NBD servers (generally, not always) expose a single block device per server. You can usually make multiple connections to the server, and all connections will see a single view of the device. There is of course no concept of files.
I'm having some problems understanding the execution model of fio: in what order do engine methods get called? how do threads correspond to files? are "jobs" the same as "files"?
Nevertheless I think I have mapped a single job to the NBD block device. You can test it using nbdkit plus a ramdisk like this:
$ rm /tmp/socket $ nbdkit -U /tmp/socket memory size=1G --run './fio examples/nbd.fio'
If there are multiple jobs (files?) should these be striped over the block device?
For some reason fio doesn't recognize the new --sockname parameter:
$ ./fio examples/nbd.fio --sockname=foo ./fio: unrecognized option '--sockname=foo' ./fio: unrecognized option '--sockname=foo'
If this was fixed then you could use an implicit socket:
$ nbdkit -U - memory size=1G \
--run './fio examples/nbd.fio --sockname=$unixsocket'The .queue method in this engine is synchronous. It's possible for multiple requests to be issued asynchronously on a single TCP socket, but I don't know if it is worth doing this.
Although I said above that all connections to an NBD server see the "same" view of the device, the view is not guaranteed to be consistent *unless* the server returns the NBD_FLAG_CAN_MULTI_CONN export flag. We do not check this currently (mainly because qemu-nbd does not set it).
Another problem is that we don't read the export size from the NBD server until it's "too late" to use it to determine the file size. Therefore users must take care to set a file size which is smaller than the NBD export, although this isn't much of a problem in practice. I notice that the RBD engine works around this by connecting to their server early (during .setup).
Here is how to test qemu-nbd, another popular NBD server:
$ rm disk.img $ truncate -s 1G disk.img $ rm /tmp/socket $ qemu-nbd -f raw -t disk.img -k /tmp/socket $ ./fio examples/nbd.fio
Feedback welcome!
Rich.
PATCH 1/1 engines: Add Network Block Device (NBD) support.
--- Makefile | 2 +- engines/nbd.c | 570 +++++++++++++++++++++++++++++++++++++++++++++++ examples/nbd.fio | 9 + optgroup.c | 4 + optgroup.h | 2 + options.c | 3 + 6 files changed, 589 insertions(+), 1 deletion(-)
Makefile +1 -1
@@ -45,7 +45,7 @@ SOURCE := $(sort $(patsubst $(SRCDIR)/%,%,$(wildcard $(SRCDIR)/crc/*.c)) \ pshared.c options.c \ smalloc.c filehash.c profile.c debug.c engines/cpu.c \ engines/mmap.c engines/sync.c engines/null.c engines/net.c \ - engines/ftruncate.c engines/filecreate.c \ + engines/ftruncate.c engines/filecreate.c engines/nbd.c \ server.c client.c iolog.c backend.c libfio.c flow.c cconv.c \ gettime-thread.c helpers.c json.c idletime.c td_error.c \ profiles/tiobench.c profiles/act.c io_u_queue.c filelock.c \
engines/nbd.c new file +570 -0
570 lines not on this page · raw message
examples/nbd.fio new file +9 -0
@@ -0,0 +1,9 @@ +[test] +ioengine=nbd +sockname=/tmp/socket +rw=randrw +size=64m +nbdsize=64m +iodepth=4 +time_based +runtime=120
optgroup.c +4 -0
@@ -169,6 +169,10 @@ static const struct opt_group fio_opt_cat_groups[] = { .name = "libhdfs I/O engine", /* libhdfs */ .mask = FIO_OPT_G_HDFS, }, + { + .name = "NBD I/O engine", /* NBD */ + .mask = FIO_OPT_G_NBD, + }, { .name = NULL, },
optgroup.h +2 -0
@@ -61,6 +61,7 @@ enum opt_category_group { __FIO_OPT_G_MTD, __FIO_OPT_G_HDFS, __FIO_OPT_G_SG, + __FIO_OPT_G_NBD, __FIO_OPT_G_NR, FIO_OPT_G_RATE = (1ULL << __FIO_OPT_G_RATE),
@@ -97,6 +98,7 @@ enum opt_category_group {FIO_OPT_G_MTD = (1ULL << __FIO_OPT_G_MTD),FIO_OPT_G_HDFS = (1ULL << __FIO_OPT_G_HDFS),FIO_OPT_G_SG = (1ULL << __FIO_OPT_G_SG), +FIO_OPT_G_NBD = (1ULL << __FIO_OPT_G_NBD), FIO_OPT_G_INVALID = (1ULL << __FIO_OPT_G_NR), };
options.c +3 -0
@@ -1899,6 +1899,9 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .help = "HTTP (WebDAV/S3) IO engine", },#endif + { .ival = "nbd", + .help ="Network Block Device (NBD) IO engine" + }, }, }, {
Signature · 1 line
2.20.1
Just a few random style comments, not a complete review...
Quoted 5 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Richard W.M. Jones
Sent: Thursday, April 18, 2019 9:10 AM
Subject: [PATCH fio] engines: Add Network Block Device (NBD) support.
...
engines/nbd.c line 244
Quoted 2 lines
engines/nbd.c new file +2
-0+ r =getaddrinfo (hostname, port, &hints, &result); +if (r !=0 ) {
if() is not a function, so include a space.
...
engines/nbd.c line 321
Quoted 2 lines
engines/nbd.c new file +2
-0+log_err ("fio: nbd: unexpected end of file " +"reading from server\n" );
Please keep strings on one line so they can be found with grep. That's more important than wrapping at 80 characters.
Hello Richard!
(Thanks for all your NBD work over the years)
On Thu, 18 Apr 2019 at 15:10, Richard W.M. Jones <[email protected]> wrote:
<snip>
Quoted 8 lines
NBD servers (generally, not always) expose a single block device per server. You can usually make multiple connections to the server, and all connections will see a single view of the device. There is of course no concept of files.
I'm having some problems understanding the execution model of fio: in what order do engine methods get called? how do threads correspond to files? are "jobs" the same as "files"?
The order of method calls for a synchronous engine (IF they are defined) is roughly:
->load (engines are all loaded together)
->file_size
->init
->open
(per I/O)
->prep
->queue
->close
->cleanup
->free
<-close
It's possible to define more functions than this though.
A thread may have one or more files associated with it depending on what the engine can cope with and what the user requested (see
https://fio.readthedocs.io/en/latest/fio_doc.html#cmdoption-arg-filename
). A "job" is the definition of an fio workload and via filename it may define multiple files to work with. A filename may be auto generated but this may not make sense with a diskless ioengine such as the one you're writing.
Quoted 8 lines
Nevertheless I think I have mapped a single job to the NBD block device. You can test it using nbdkit plus a ramdisk like this:
$ rm /tmp/socket $ nbdkit -U /tmp/socket memory size=1G --run './fio examples/nbd.fio'If there are multiple jobs (files?) should these be striped over the block device?
It depends on how you define the job. If you were to just copy the job and give it a new name it would likely just overlap the first job (because it's just going to do the same thing at the same time). You would need to use something like numjobs
(https://fio.readthedocs.io/en/latest/fio_doc.html#cmdoption-arg-numjobs
) offset_increment
(https://fio.readthedocs.io/en/latest/fio_doc.html#cmdoption-arg-offset-increment
) and a workload that skipped (e.g. rw=write:12k -
https://fio.readthedocs.io/en/latest/fio_doc.html#cmdoption-arg-readwrite
) to achieve striping.
Quoted 6 lines
For some reason fio doesn't recognize the new --sockname parameter:
$ ./fio examples/nbd.fio --sockname=foo ./fio: unrecognized option '--sockname=foo' ./fio: unrecognized option '--sockname=foo'
We'd have to debug this by looking at the code to see that the new option was registered correctly.
Quoted 14 lines
If this was fixed then you could use an implicit socket:
$ nbdkit -U - memory size=1G \ --run './fio examples/nbd.fio --sockname=$unixsocket'The .queue method in this engine is synchronous. It's possible for multiple requests to be issued asynchronously on a single TCP socket, but I don't know if it is worth doing this.
Although I said above that all connections to an NBD server see the "same" view of the device, the view is not guaranteed to be consistent *unless* the server returns the
NBD_FLAG_CAN_MULTI_CONNexport flag. We do not check this currently (mainly because qemu-nbd does not set it).
Quoted 6 lines
Another problem is that we don't read the export size from the NBD server until it's "too late" to use it to determine the file size. Therefore users must take care to set a file size which is smaller than the NBD export, although this isn't much of a problem in practice. I notice that the RBD engine works around this by connecting to their server early (during .setup).
Yeah - I think I had to do something similar in my never submitted libiscsi engine. I think there I stash some information whenever the file is opened and then make use of that information in getsize
(https://github.com/sitsofe/fio/blob/libiscsi/engines/libiscsi.c#L869
).
--
Sitsofe | http://sucs.org/~sits/
Quoted 4 lines · Sitsofe Wheeler
Quoted 2 lines · Richard W.M. Jones
If there are multiple jobs (files?) should these be striped over the block device?
Quoted 10 lines
It depends on how you define the job. If you were to just copy the job and give it a new name it would likely just overlap the first job (because it's just going to do the same thing at the same time). You would need to use something like numjobs
(https://fio.readthedocs.io/en/latest/fio_doc.html#cmdoption-arg-numjobs
)offset_increment
(https://fio.readthedocs.io/en/latest/fio_doc.html#cmdoption-arg-offset-increment
) and a workload that skipped (e.g. rw=write:12k -
https://fio.readthedocs.io/en/latest/fio_doc.html#cmdoption-arg-readwrite
) to achieve striping.
I meant should the NBD engine stripe the jobs. Something like: job 0 gets to use the first <size> bytes of the NBD device, job 1 gets to us the next <size> bytes, etc. (Or actually striped/interleaved using a smaller block size). In other words it would be something hidden inside the NBD engine and not "visible" to fio.
Thanks for the rest of the email - very helpful.
Rich.
Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
Quoted 17 lines · Richard W.M. Jones
Quoted 4 lines · Sitsofe Wheeler
Quoted 2 lines · Richard W.M. Jones
If there are multiple jobs (files?) should these be striped over the block device?
Quoted 10 lines
It depends on how you define the job. If you were to just copy the job and give it a new name it would likely just overlap the first job (because it's just going to do the same thing at the same time). You would need to use something like numjobs
(https://fio.readthedocs.io/en/latest/fio_doc.html#cmdoption-arg-numjobs
)offset_increment
(https://fio.readthedocs.io/en/latest/fio_doc.html#cmdoption-arg-offset-increment
) and a workload that skipped (e.g. rw=write:12k -
https://fio.readthedocs.io/en/latest/fio_doc.html#cmdoption-arg-readwrite
) to achieve striping.
Quoted 5 lines
I meant should the NBD engine stripe the jobs. Something like: job 0 gets to use the first <size> bytes of the NBD device, job 1 gets to us the next <size> bytes, etc. (Or actually striped/interleaved using a smaller block size). In other words it would be something hidden inside the NBD engine and not "visible" to fio.
I would leave this to the fio job definition - someone can always build the filename and the job file programmatically...
Signature · 1 line
Sitsofe | http://sucs.org/~sits/