nbdkit-blocksize-policy-filter - Man Page

set minimum, preferred and maximum block size, and apply error policy

Synopsis

 nbdkit --filter=blocksize-policy PLUGIN
        [blocksize-error-policy=allow|error]
        [blocksize-minimum=N]
        [blocksize-preferred=N]
        [blocksize-maximum=N]
        [blocksize-write-disconnect=N]

Description

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: 1
     block_size_preferred: 32768
     block_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.

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.

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.

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-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=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.

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.

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.

See Also

nbdkit(1), nbdkit-blocksize-filter(1), nbdkit-filter(3), nbdkit-plugin(3).

Authors

Richard W.M. Jones

License

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

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.

Referenced By

nbdkit(1), nbdkit-blocksize-filter(1), nbdkit-filter(3), nbdkit-plugin(3), nbdkit-release-notes-1.30(1), nbdkit-release-notes-1.34(1).

2024-10-14 nbdkit-1.41.8