On Fri, Aug 04, 2023 at 12:20:54PM +0100, Richard W.M. Jones wrote:
> > Acked-by: Richard W.M. Jones <rjones(a)redhat.com>
> >
> > ... although I wonder if this might break something. I think it's
> > possible for an nbdkit plugin to return a zero length extent, for
> > example if it has a simplistic internal model of regions of the disk.
> > Since the client can still make progress if at least the total length
> > of extents returned is > 0 I'm fairly sure this would work right now.
>
> Like this:
>
> $ cat extents.sh
> case "$1" in
> get_size) echo 10M ;;
> pread) dd if=/dev/zero count=$3 iflag=count_bytes ;;
> can_extents) exit 0 ;;
> extents)
> echo "0 1M"
> echo "1M 0 hole,zero"
> echo "1M 9M"
> exit 0 ;;
> *) exit 2 ;;
> esac
>
> $ nbdinfo --map [ nbdkit sh ./extents.sh ]
> 0 10485760 0 data
>
> I wonder if this breaks after this patch?
I looked at the code & it turns out that nbdkit ignores zero-length
extents, and merges extents with the same type, so I think the above
is actually sending a single 10M extent.
https://gitlab.com/nbdkit/nbdkit/-/blob/e94597fb99a86a38fcc0aea32c6102565...
Yep, I remember we spent a considerable amount of time on nbdkit
allowing plugins to throw whatever was most convenient for them at the
core code, but then santizing it so that our wire reply is
spec-compliant and as consolidated as possible. I would have to write
a custom server (ie. a one-off hack to nbdkit) to actually send a
zero-length block status reply. Right now, if you ask nbdkit for
block status with width zero, it responds with EINVAL failure; and for
the example server you gave, it does indeed merge into a single
extent.
Maybe we should tweak nbdkit to allow a zero-length status request
(aka let the plugin reply with as much as it wants), similar to how we
allow zero-length pread and pwrite requests, but that's a different
patch, and it still seems like the best response will be to either
return a non-zero extent or to just report success without reporting
any extents.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:
qemu.org |
libguestfs.org