On 04/15/2016 06:03 AM, Alex Bligh wrote:
> This is a very basic implementation which could do with optimisation.
>
> Signed-off-by: Alex Bligh <alex@...872...>
> ---
> nbd-server.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
> nbd.h | 4 +++-
> 2 files changed, 73 insertions(+), 5 deletions(-)
>
> This is marked PATCH/RFC as it's only compile tested as I don't yet have
> a client that interoperates with it.
I posted qemu patches a while back, but they need a refresh.
> +int expwrite_zeroes(struct nbd_request* req, CLIENT* client) {
> + off_t a = req->from;
> + size_t len = req->len;
> + int fua = !!(req->type & NBD_CMD_FLAG_FUA);
> + size_t maxsize = 64LL*1024LL*1024LL;
> + /* use calloc() as sadly MAP_ANON is apparently not POSIX standard */
> + char *buf = calloc (1, maxsize);
> + int ret;
> + while (len > 0) {
> + size_t l = len;
> + if (l > maxsize)
> + l = maxsize;
> + ret = expwrite(a, buf, l, client, fua);
> + if (ret) {
> + free(buf);
> + return ret;
> + }
> + len -= l;
> + }
> + free(buf);
> + return 0;
> +}
You completely ignore NBD_CMD_FLAG_NO_HOLE; you could obey that flag
(when set, do the calloc() here; when cleared, call into the trim code
if you can guarantee that you'll read zero after trims). But if nothing
else, you have a bug for not permitting the NBD_CMD_FLAG_NO_HOLE (even
if you intend to ignore it by ALWAYS operating in no-hole mode, as was
done here).
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Attachment:
signature.asc
Description: OpenPGP digital signature