qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, armbru@redhat.com, qemu-stable@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] qemu-nbd: return ENOSPC for out-of-range writes
Date: Fri, 08 May 2015 14:38:44 +0200	[thread overview]
Message-ID: <554CAE54.60409@redhat.com> (raw)
In-Reply-To: <1431080484-9760-1-git-send-email-pbonzini@redhat.com>

On 08.05.2015 12:21, Paolo Bonzini wrote:
> This ensures that werror=enospc works fine for NBD-backed devices.
> Recovery can be done through live snapshots even if the NBD server
> does not support online resizing.
>
> Suggested-by: Kevin Wolf <kwolf@redhat.com>
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   nbd.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)

Good thing: NBD doesn't have a very extensive manual, so in theory we 
can do whatever we want to.
Bad thing: Because of this, our implementation generally seems to look 
to the reference implementation (nbd-server).

Well, and that reference implementation handles this case here: 
https://github.com/yoe/nbd/blob/master/nbd-server.c#l1621 - so it does 
always send EINVAL.

Two things follow: First, our implementation will behave differently 
from nbd-server. Second, even if we don't care, werror=enospc will only 
work with qemu-nbd, and not when using nbd-server.

One could argue that you should only use qemu-nbd with qemu, and not 
nbd-server, but then I'm wondering why we implemented a pre-existing 
protocol in the first place and didn't implement our own...

I think this should be done in the client. If a request beyond the EOF 
(for writes) is to be generated, ENOSPC should be returned before making 
the request to the server at all.

Alternatively, we could actually use my series which introduces the 
debatable (and debated) warning to implement this case more generally: 
It does introduce a flag which tells the block layer whether a BDS 
supports write accesses beyond EOF or not, so using that the block layer 
itself would be able to intercept such writes and return ENOSPC 
automatically.

Max

> diff --git a/nbd.c b/nbd.c
> index 57d71b2..a04ba80 100644
> --- a/nbd.c
> +++ b/nbd.c
> @@ -1297,7 +1297,8 @@ static void nbd_trip(void *opaque)
>                       request.from, request.len,
>                       (uint64_t)exp->size, (uint64_t)exp->dev_offset);
>           LOG("requested operation past EOF--bad client?");
> -        goto invalid_request;
> +        reply.error = (command == NBD_CMD_WRITE) ? ENOSPC : EINVAL;
> +        goto error_reply;
>       }
>   
>       switch (command) {
> @@ -1390,7 +1391,6 @@ static void nbd_trip(void *opaque)
>           break;
>       default:
>           LOG("invalid request type (%u) received", request.type);
> -    invalid_request:
>           reply.error = EINVAL;
>       error_reply:
>           if (nbd_co_send_reply(req, &reply, 0) < 0) {

  reply	other threads:[~2015-05-08 12:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-08 10:21 [Qemu-devel] [PATCH] qemu-nbd: return ENOSPC for out-of-range writes Paolo Bonzini
2015-05-08 12:38 ` Max Reitz [this message]
2015-05-08 12:40   ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=554CAE54.60409@redhat.com \
    --to=mreitz@redhat.com \
    --cc=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).