Eric Blake
2022-Feb-16 18:16 UTC
[Libguestfs] [PATCH nbdkit 4/6] eval, sh: Implement block_size method
On Wed, Feb 16, 2022 at 04:20:39PM +0000, Richard W.M. Jones wrote:> The main reason to implement block_size in these plugins first is so > we then have an easy way to implement tests of the feature. > --- > plugins/eval/nbdkit-eval-plugin.pod | 2 + > plugins/sh/nbdkit-sh-plugin.pod | 10 +++++ > plugins/sh/methods.h | 3 ++ > plugins/eval/eval.c | 2 + > plugins/sh/methods.c | 66 +++++++++++++++++++++++++++++ > plugins/sh/sh.c | 1 + > 6 files changed, 84 insertions(+) > > +int > +sh_block_size (void *handle, > + uint32_t *minimum, uint32_t *preferred, uint32_t *maximum) > +{ > + const char *method = "block_size"; > + const char *script = get_script (method); > + struct sh_handle *h = handle; > + const char *args[] = { script, method, h->h, NULL }; > + CLEANUP_FREE char *s = NULL; > + size_t slen; > + const char *delim = " \t\n"; > + char *sp, *p; > + int64_t r; > + > + switch (call_read (&s, &slen, args)) { > + case OK: > + if ((p = strtok_r (s, delim, &sp)) == NULL) { > + parse_error: > + nbdkit_error ("%s: %s method cannot be parsed", script, method); > + return -1; > + } > + r = nbdkit_parse_size (p); > + if (r == -1 || r > UINT32_MAX) > + goto parse_error; > + *minimum = r; > + > + if ((p = strtok_r (NULL, delim, &sp)) == NULL) > + goto parse_error; > + r = nbdkit_parse_size (p); > + if (r == -1 || r > UINT32_MAX) > + goto parse_error; > + *preferred = r; > + > + if ((p = strtok_r (NULL, delim, &sp)) == NULL) > + goto parse_error; > + r = nbdkit_parse_size (p); > + if (r == -1 || r > UINT32_MAX) > + goto parse_error; > + *maximum = r; > + > +#if 0 > + nbdkit_debug ("setting block_size: " > + "minimum=%" PRIu32 " " > + "preferred=%" PRIu32 " " > + "maximum=%" PRIu32, > + *minimum, *preferred, *maximum); > +#endif > + return 0;Do we care about checking that there is no trailing garbage after the three numbers? Otherwise, yes, this makes a good first plugin for an implementation ;) -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Richard W.M. Jones
2022-Feb-17 09:49 UTC
[Libguestfs] [PATCH nbdkit 4/6] eval, sh: Implement block_size method
On Wed, Feb 16, 2022 at 12:16:57PM -0600, Eric Blake wrote:> Do we care about checking that there is no trailing garbage after the > three numbers?I actually think we should allow it, to allow for future expansion. 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