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