$filterdir/nbdkit-blocksize-policy-filter.so
The filter.
Use "nbdkit --dump-config" to find the location of $filterdir.
Set minimum, preferred and maximum block size, and apply error policy
nbdkit --filter=blocksize-policy
PLUGIN
[{blocksize-error-policy=allow | error}]
[blocksize-minimum=N]
[blocksize-preferred=N]
[blocksize-maximum=N]
[blocksize-write-disconnect=N]
"nbdkit-blocksize-policy-filter" is an nbdkit(1) filter that can add block size constraints to plugins which don't already support them. It can also enforce an error policy for badly behaved clients which do not obey the block size constraints.
For more information about block size constraints, see section "Block size constraints" in https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md.
The simplest usage is to place this filter on top of any plugin which does not advertise block size constraints, and set the "blocksize-minimum", "blocksize-preferred" and "blocksize-maximum" parameters with the desired constraints. For example:
nbdkit --filter=blocksize-policy memory 1G \blocksize-preferred=32K
would adjust nbdkit-memory-plugin(1) so that clients should prefer 32K requests. You can query the NBD server advertised constraints using nbdinfo(1):
$ nbdinfo nbd://localhost[...]block_size_minimum: 1block_size_preferred: 32768block_size_maximum: 4294967295
The second part of this filter is adjusting the error policy when badly behaved clients do not obey the minimum or maximum request size. Normally nbdkit permits these requests, leaving it up to the plugin whether it rejects the request with an error or tries to process the request (eg. trying to split an over-large request or doing a read-modify-write for an unaligned write). With this filter you can use "blocksize-error-policy=error" to reject these requests in the filter with an EINVAL error. The plugin will not see them.
Normally, nbdkit will accept write requests up to 64M in length, and reply with a gracful error message rather than a hard disconnect for a buffer up to twice that large. But many other servers (for example, qemu-nbd) will give a hard disconnect for a write request larger than 32M. With this filter you can use "blocksize-write-disconnect=32M" to emulate the behavior of other servers.
A related filter is nbdkit-blocksize-filter(1). That filter can split and combine requests for plugins that cannot handle requests under or over a particular size.
Both filters may be used together like this (note that the order of the filters is important):
nbdkit --filter=blocksize-policy \--filter=blocksize \PLUGIN ... \blocksize-error-policy=allow \blocksize-minimum=64K minblock=64K
This says to advertise a minimum block size of 64K. Well-behaved clients will obey this. Badly behaved clients will send requests < 64K which will be converted to slow 64K read-modify-write cycles to the underlying plugin. In either case the plugin will only see requests on 64K (or multiples of 64K) boundaries.
blocksize-error-policy=allowblocksize-error-policy=errorIf a client sends a request which is smaller than the permitted minimum size or larger than the permitted maximum size, or not aligned to the minimum size, "blocksize-error-policy" chooses what the filter will do. The default (and also nbdkit's default) is "allow" which means pass the request through to the plugin.
Use "error" to return an EINVAL error back to the client. The plugin will not see the badly formed request in this case.
blocksize-write-disconnect=N(nbdkit ≥ 1.34)
If a client sends a write request which is larger than the specified size (using the usual size modifiers like "32M"), abruptly close the connection. This can be used to emulate qemu's behavior of disconnecting for write requests larger than 32M, rather than nbdkit's default of keeping the connection alive for write requests up to 128M (although nbdkit does not let the plugin see requests larger than 64M). The write disconnect size is independent of any advertised maximum block size or its accompanying error policy.
blocksize-minimum=Nblocksize-preferred=Nblocksize-maximum=NAdvertise minimum, preferred and/or maximum block size to the client. Well-behaved clients should obey these constraints.
For each parameter, you can specify it as a size (using the usual modifiers like "4K").
If the parameter is omitted then either the constraint advertised by the plugin itself is used, or a sensible default for plugins which do not advertise block size constraints.
$filterdir/nbdkit-blocksize-policy-filter.so
The filter.
Use "nbdkit --dump-config" to find the location of $filterdir.
"nbdkit-limit-filter" first appeared in nbdkit 1.30.
2 releases since Debian 12 (Bookworm); the text changed 1 time.