qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PULL 0/2] NBD patches for 6.2-rc2, 2021-11-22
@ 2021-11-22 14:02 Eric Blake
  2021-11-22 14:02 ` [PULL 1/2] nbd/server: Don't complain on certain client disconnects Eric Blake
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Eric Blake @ 2021-11-22 14:02 UTC (permalink / raw)
  To: qemu-devel

The following changes since commit 49aaac3548bc5a4632a14de939d5312b28dc1ba2:

  Merge tag 'linux-user-for-6.2-pull-request' of git://github.com/vivier/qemu into staging (2021-11-22 10:33:13 +0100)

are available in the Git repository at:

  https://repo.or.cz/qemu/ericb.git tags/pull-nbd-2021-11-22

for you to fetch changes up to e35574226a63f29e32eda8da5cc14832f19850e2:

  nbd/server: Simplify zero and trim (2021-11-22 07:37:15 -0600)

----------------------------------------------------------------
nbd patches for 2021-11-22

- Eric Blake: Avoid uninitialized memory on client hard disconnect
- Eric Blake: Take advantage of block layer 64-bit zero/trim

----------------------------------------------------------------
Eric Blake (2):
      nbd/server: Don't complain on certain client disconnects
      nbd/server: Simplify zero and trim

 nbd/server.c | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)

-- 
2.33.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PULL 1/2] nbd/server: Don't complain on certain client disconnects
  2021-11-22 14:02 [PULL 0/2] NBD patches for 6.2-rc2, 2021-11-22 Eric Blake
@ 2021-11-22 14:02 ` Eric Blake
  2021-11-22 14:02 ` [PULL 2/2] nbd/server: Simplify zero and trim Eric Blake
  2021-11-22 22:21 ` [PULL 0/2] NBD patches for 6.2-rc2, 2021-11-22 Richard Henderson
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Blake @ 2021-11-22 14:02 UTC (permalink / raw)
  To: qemu-devel
  Cc: Vladimir Sementsov-Ogievskiy, qemu-stable,
	open list:Network Block Dev...

When a client disconnects abruptly, but did not have any pending
requests (for example, when using nbdsh without calling h.shutdown),
we used to output the following message:

$ qemu-nbd -f raw file
$ nbdsh -u 'nbd://localhost:10809' -c 'h.trim(1,0)'
qemu-nbd: Disconnect client, due to: Failed to read request: Unexpected end-of-file before all bytes were read

Then in commit f148ae7, we refactored nbd_receive_request() to use
nbd_read_eof(); when this returns 0, we regressed into tracing
uninitialized memory (if tracing is enabled) and reporting a
less-specific:

qemu-nbd: Disconnect client, due to: Request handling failed in intermediate state

Note that with Unix sockets, we have yet another error message,
unchanged by the 6.0 regression:

$ qemu-nbd -k /tmp/sock -f raw file
$ nbdsh -u 'nbd+unix:///?socket=/tmp/sock' -c 'h.trim(1,0)'
qemu-nbd: Disconnect client, due to: Failed to send reply: Unable to write to socket: Broken pipe

But in all cases, the error message goes away if the client performs a
soft shutdown by using NBD_CMD_DISC, rather than a hard shutdown by
abrupt disconnect:

$ nbdsh -u 'nbd://localhost:10809' -c 'h.trim(1,0)' -c 'h.shutdown()'

This patch fixes things to avoid uninitialized memory, and in general
avoids warning about a client that does a hard shutdown when not in
the middle of a packet.  A client that aborts mid-request, or which
does not read the full server's reply, can still result in warnings,
but those are indeed much more unusual situations.

CC: qemu-stable@nongnu.org
Fixes: f148ae7d36 ("nbd/server: Quiesce coroutines on context switch", v6.0.0)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
[eblake: defer unrelated typo fixes to later patch]
Message-Id: <20211117170230.1128262-2-eblake@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
---
 nbd/server.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/nbd/server.c b/nbd/server.c
index d9164ee6d0da..74ba48709451 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -1418,6 +1418,9 @@ static int nbd_receive_request(NBDClient *client, NBDRequest *request,
     if (ret < 0) {
         return ret;
     }
+    if (ret == 0) {
+        return -EIO;
+    }

     /* Request
        [ 0 ..  3]   magic   (NBD_REQUEST_MAGIC)
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PULL 2/2] nbd/server: Simplify zero and trim
  2021-11-22 14:02 [PULL 0/2] NBD patches for 6.2-rc2, 2021-11-22 Eric Blake
  2021-11-22 14:02 ` [PULL 1/2] nbd/server: Don't complain on certain client disconnects Eric Blake
@ 2021-11-22 14:02 ` Eric Blake
  2021-11-22 22:21 ` [PULL 0/2] NBD patches for 6.2-rc2, 2021-11-22 Richard Henderson
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Blake @ 2021-11-22 14:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: Vladimir Sementsov-Ogievskiy, open list:Network Block Dev...

Now that the block layer supports 64-bit operations (see commit
2800637a and friends, new to v6.2), we no longer have to self-fragment
requests larger than 2G, reverting the workaround added in 890cbccb08
("nbd: Fix large trim/zero requests", v5.1.0).

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20211117170230.1128262-3-eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 nbd/server.c | 23 +++--------------------
 1 file changed, 3 insertions(+), 20 deletions(-)

diff --git a/nbd/server.c b/nbd/server.c
index 74ba48709451..4630dd732250 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -2509,16 +2509,8 @@ static coroutine_fn int nbd_handle_request(NBDClient *client,
         if (request->flags & NBD_CMD_FLAG_FAST_ZERO) {
             flags |= BDRV_REQ_NO_FALLBACK;
         }
-        ret = 0;
-        /* FIXME simplify this when blk_pwrite_zeroes switches to 64-bit */
-        while (ret >= 0 && request->len) {
-            int align = client->check_align ?: 1;
-            int len = MIN(request->len, QEMU_ALIGN_DOWN(BDRV_REQUEST_MAX_BYTES,
-                                                        align));
-            ret = blk_pwrite_zeroes(exp->common.blk, request->from, len, flags);
-            request->len -= len;
-            request->from += len;
-        }
+        ret = blk_pwrite_zeroes(exp->common.blk, request->from, request->len,
+                                flags);
         return nbd_send_generic_reply(client, request->handle, ret,
                                       "writing to file failed", errp);

@@ -2532,16 +2524,7 @@ static coroutine_fn int nbd_handle_request(NBDClient *client,
                                       "flush failed", errp);

     case NBD_CMD_TRIM:
-        ret = 0;
-        /* FIXME simplify this when blk_co_pdiscard switches to 64-bit */
-        while (ret >= 0 && request->len) {
-            int align = client->check_align ?: 1;
-            int len = MIN(request->len, QEMU_ALIGN_DOWN(BDRV_REQUEST_MAX_BYTES,
-                                                        align));
-            ret = blk_co_pdiscard(exp->common.blk, request->from, len);
-            request->len -= len;
-            request->from += len;
-        }
+        ret = blk_co_pdiscard(exp->common.blk, request->from, request->len);
         if (ret >= 0 && request->flags & NBD_CMD_FLAG_FUA) {
             ret = blk_co_flush(exp->common.blk);
         }
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PULL 0/2] NBD patches for 6.2-rc2, 2021-11-22
  2021-11-22 14:02 [PULL 0/2] NBD patches for 6.2-rc2, 2021-11-22 Eric Blake
  2021-11-22 14:02 ` [PULL 1/2] nbd/server: Don't complain on certain client disconnects Eric Blake
  2021-11-22 14:02 ` [PULL 2/2] nbd/server: Simplify zero and trim Eric Blake
@ 2021-11-22 22:21 ` Richard Henderson
  2 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2021-11-22 22:21 UTC (permalink / raw)
  To: Eric Blake, qemu-devel

On 11/22/21 3:02 PM, Eric Blake wrote:
> The following changes since commit 49aaac3548bc5a4632a14de939d5312b28dc1ba2:
> 
>    Merge tag 'linux-user-for-6.2-pull-request' of git://github.com/vivier/qemu into staging (2021-11-22 10:33:13 +0100)
> 
> are available in the Git repository at:
> 
>    https://repo.or.cz/qemu/ericb.git tags/pull-nbd-2021-11-22
> 
> for you to fetch changes up to e35574226a63f29e32eda8da5cc14832f19850e2:
> 
>    nbd/server: Simplify zero and trim (2021-11-22 07:37:15 -0600)
> 
> ----------------------------------------------------------------
> nbd patches for 2021-11-22
> 
> - Eric Blake: Avoid uninitialized memory on client hard disconnect
> - Eric Blake: Take advantage of block layer 64-bit zero/trim
> 
> ----------------------------------------------------------------
> Eric Blake (2):
>        nbd/server: Don't complain on certain client disconnects
>        nbd/server: Simplify zero and trim
> 
>   nbd/server.c | 26 ++++++--------------------
>   1 file changed, 6 insertions(+), 20 deletions(-)

Applied, thanks.

r~



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-22 22:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-22 14:02 [PULL 0/2] NBD patches for 6.2-rc2, 2021-11-22 Eric Blake
2021-11-22 14:02 ` [PULL 1/2] nbd/server: Don't complain on certain client disconnects Eric Blake
2021-11-22 14:02 ` [PULL 2/2] nbd/server: Simplify zero and trim Eric Blake
2021-11-22 22:21 ` [PULL 0/2] NBD patches for 6.2-rc2, 2021-11-22 Richard Henderson

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).