Eric Blake
2022-Feb-17 21:58 UTC
[Libguestfs] [PATCH nbdkit v2 7/7] New filter: nbdkit-block-size-constraint-filter
On Thu, Feb 17, 2022 at 02:36:48PM +0000, Richard W.M. Jones wrote:> This filter 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. > --- > +=item B<blocksize-error-policy=allow> > + > +=item B<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, C<blocksize-error-policy> chooses what the filter > +will do. The default (and also nbdkit's default) is C<allow> which > +means pass the request through to the plugin. > + > +Use C<error> to return an EIO error back to the client. The plugin > +will not see the badly formed request in this case. > +> + > +/* This function checks the error policy for all request functions below. */ > +static int > +check_policy (nbdkit_next *next, const char *type, > + uint32_t count, uint64_t offset, int *err) > +{ > + uint32_t minimum, preferred, maximum; > + > + if (error_policy == ALLOW) > + return 0; > + > + /* Get the current block size constraints. Note these are cached in > + * the backend so if they've already been computed then this simply > + * returns the cached values. The plugin is only asked once per > + * connection. > + */ > + errno = 0; > + if (next->block_size (next, &minimum, &preferred, &maximum) == -1) { > + *err = errno ? : EIO; > + return -1; > + }After re-reading libnbd's nbd_get_block_size(), I noticed something: The NBD protocol spec recommends EINVAL (rather than EIO) for requests that violate block size constraints. Do we want to hardcode EINVAL, or else tweak the error policy to allow the user to specify which errno to provide? -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Richard W.M. Jones
2022-Feb-17 22:00 UTC
[Libguestfs] [PATCH nbdkit v2 7/7] New filter: nbdkit-block-size-constraint-filter
On Thu, Feb 17, 2022 at 03:58:07PM -0600, Eric Blake wrote:> The NBD protocol spec recommends EINVAL (rather than EIO) for requests > that violate block size constraints. Do we want to hardcode EINVAL, > or else tweak the error policy to allow the user to specify which > errno to provide?I err on not overthinking this. I'll change it to EINVAL, and if ever we need to choose another errno then we can add a knob for it. Rich. -- 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/