nbdkit-blocksize-policy-filter(1)
okay so bestie, welcome to nbdkit-blocksize-policy-filter(1) β a page from the NBDKIT manuals, and honestly? it's a good one π
β¨ NAME β¨
nbdkit-blocksize-policy-filter β sets minimum, preferred and maximum block size, and applies an error policy. that's the whole vibe π
π¦ SYNOPSIS π¦
nbdkit --filter=blocksize-policy PLUGIN
[blocksize-error-policy=allow|error|strict-error]
[blocksize-minimum=N]
[blocksize-preferred=N]
[blocksize-maximum=N]
[blocksize-write-disconnect=N]
π DESCRIPTION π
nbdkit-blocksize-policy-filter is an nbdkit(1) filter, and what it does is: it adds block size constraints to plugins that don't already support them. lowkey a glow-up for those plugins β¨. it can also enforce an error policy for badly behaved clients that straight up ignore the block size constraints. no cap.
if you want the full lore on block size constraints, go read the 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 that doesn't advertise block size constraints, and then set the blocksize-minimum, blocksize-preferred and blocksize-maximum parameters with whatever constraints you want. for example:
nbdkit --filter=blocksize-policy memory 1G \
blocksize-preferred=32K
would adjust nbdkit-memory-plugin(1) so that clients should prefer 32K requests. it's giving "please, respectfully, use 32K". you can query the constraints the NBD server advertised using nbdinfo(1):
$ nbdinfo nbd://localhost
[...]
block_size_minimum: 1
block_size_preferred: 32768
block_size_maximum: 4294967295
the second part of this filter is adjusting the error policy for 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. bye bestie π
normally, nbdkit will accept write requests up to 64M in length, and reply with a graceful 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. matching energy, fr fr π
π Combining with nbdkit-truncate-filter(1) π
this filter does not alter the underlying size of the plugin, even when that size is not a multiple of the minimum block size. so when the plugin size is unaligned, blocksize-error-policy=error will permit unaligned lengths for requests that extend through the end of the plugin size, so that the client may attempt to access those last few bytes of the image π₯Ί. blocksize-error-policy=strict-error prevents any access to the unaligned tail. however, it may be more convenient to ensure that the client sees an image size that is a multiple of the minimum block size β at which point there is literally no difference between the error and strict-error policies. iconic behavior honestly.
it's possible to combine this filter with the truncate filter to ensure that the client need only worry about aligned requests (note that the order of the filters is important β οΈ). you can either ignore the unaligned tail:
nbdkit --filter=blocksize-policy \
--filter=truncate \
PLUGIN ... \
blocksize-error-policy=error \
blocksize-minimum=512 round-down=512
or expose a larger image, where the extra bytes are forced to zero:
nbdkit --filter=blocksize-policy \
--filter=truncate \
PLUGIN ... \
blocksize-error-policy=error \
blocksize-minimum=512 round-up=512
π§ Combining with nbdkit-blocksize-filter(1) π§
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. so it's the "chop it up" one, and this is the "set the rules" one π«Ά
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. either way, the plugin will only see requests on 64K (or multiples of 64K) boundaries. slay β¨
π PARAMETERS π
blocksize-error-policy=allow,blocksize-error-policy=errorβ if 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-policychooses what the filter will do. the default (and also nbdkit's default) isallow, which means pass the request through to the plugin. useerrorto return anEINVALerror back to the client β the plugin will not see the badly formed request in this case. π«blocksize-error-policy=strict-errorβ (nbdkit β₯ 1.44)
the strict-error policy is like the error policy, except when the image size advertised to the plugin is not a multiple of the minimum block size. in that case, the normal error policy permits unaligned lengths that coincide with the end of the image (offsets must still be aligned, and any unaligned length that does not reach to the end of the image is still rejected), while strict-error also prevents any attempt to access the unaligned tail of the image. no sneaking into the tail, periodt π
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. yes, the whole connection, gone, bye βοΈ. 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=N,blocksize-preferred=N,blocksize-maximum=Nβ advertise minimum, preferred and/or maximum block size to the client. well-behaved clients should obey these constraints, bestie π
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. either way, you're covered π
π FILES π
$filterdir/nbdkit-blocksize-policy-filter.soβ the filter. β¨
use nbdkit --dump-config to find the location of $filterdir.
β VERSION β
nbdkit-limit-filter first appeared in nbdkit 1.30. (yes, that's what it says, bestie, we don't make the rules π)
πΈ SEE ALSO πΈ
nbdkit(1), nbdkit-blocksize-filter(1), nbdkit-truncate-filter(1), nbdkit-filter(3), nbdkit-plugin(3).
π AUTHORS π
Richard W.M. Jones π
π COPYRIGHT π
Copyright Red Hat
π LICENSE π
redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- neither the name of Red Hat nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
and that's the whole page bestie!! this one's from nbdkit-1.48.1, dated 2026-08-29 β go forth and constrain those block sizes π πβ¨
π¦ where this page comes from
- fedora 44: nbdkit-basic-filters 1.48.1-1.fc44 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms