On Wed, Feb 23, 2022 at 09:45:33AM -0600, Eric Blake wrote:
--- a/filters/blocksize/blocksize.c
+++ b/filters/blocksize/blocksize.c
@@ -171,17 +171,30 @@ blocksize_prepare (nbdkit_next *next, void *handle,
int readonly)
{
struct blocksize_handle *h = handle;
+ uint32_t minimum, preferred, maximum;
+
+ /* Here, minimum and maximum will clamp per-handle defaults not set
+ * by globals in .config; preferred has no impact until .block_size.
+ */
+ if (next->block_size (next, &minimum, &preferred, &maximum) == -1)
+ return -1;
+
+ h->minblock = MAX (MAX (h->minblock, 1), minimum);
- if (h->minblock == 0)
- h->minblock = 1;
if (h->maxdata == 0) {
if (h->maxlen)
h->maxdata = MIN (h->maxlen, 64 * 1024 * 1024);
else
h->maxdata = 64 * 1024 * 1024;
}
+ if (maximum)
+ h->maxdata = MIN (h->maxdata, maximum);
+ h->maxdata = ROUND_DOWN (h->maxdata, h->minblock);
+
if (h->maxlen == 0)
h->maxlen = -h->minblock;
+ else
+ h->maxlen = ROUND_DOWN (h->maxlen, h->minblock);
return 0;
I think an nbdkit_debug statement would be useful just before the
return statement, to print the values calculated by the filter. It's
hard to predict what block sizes are actually going to be used given
that it now depends on 3 factors: the command line, the plugin, and
various minima/maxima in rules built into the filter.
}
@@ -220,11 +233,11 @@ blocksize_block_size (nbdkit_next *next, void *handle,
{
struct blocksize_handle *h = handle;
+ /* Here we only need preferred; see also blocksize_prepare. */
if (next->block_size (next, minimum, preferred, maximum) == -1)
return -1;
- if (*preferred == 0)
- *preferred = MAX (4096, h->minblock);
+ *preferred = MAX (MAX (*preferred, 4096), h->minblock);
And here too.
ACK
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v