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
 -----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCAAdFiEEccLMIrHEYCkn0vOqp6FrSiUnQ2oFAmGboTsACgkQp6FrSiUn
 Q2pHYAf/VEfIEhd8+JR04Ie4X0rDo7NDo0I5SkIIUfslmBcGl6hp91/fW6K5qz9U
 BNnkSc3VQ2qFgq50F5g435QR/1TXuCP81Hhjbr1zecbabf87+YgfukA6yW3OeBJw
 jKC6vza02eXVz5Sia9oinjIwMFyznxD31hwvhQLbHBMxda//tNMU2mwyGJ10Y8yl
 A3O47lr8H0n8tremlw1GcBkHHUL9PBT1YbOWwdFdJtY7J4bk3e8eIEP5bZGfwnye
 8F8XlwjyUxjCCfOkBRTZe5qQMHJQJVc7jSs/fo5piHo8cBlcmoRAFPzxbPqptXKS
 tAmG32CzuN1T042hfuNl9qPxE5jx+Q==
 =honP
 -----END PGP SIGNATURE-----

Merge tag 'pull-nbd-2021-11-22' of https://repo.or.cz/qemu/ericb into staging

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

# gpg: Signature made Mon 22 Nov 2021 02:55:07 PM CET
# gpg:                using RSA key 71C2CC22B1C4602927D2F3AAA7A16B4A2527436A
# gpg: Good signature from "Eric Blake <eblake@redhat.com>" [full]
# gpg:                 aka "Eric Blake (Free Software Programmer) <ebb9@byu.net>" [full]
# gpg:                 aka "[jpeg image of size 6874]" [full]

* tag 'pull-nbd-2021-11-22' of https://repo.or.cz/qemu/ericb:
  nbd/server: Simplify zero and trim
  nbd/server: Don't complain on certain client disconnects

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson 2021-11-22 19:15:05 +01:00
commit d8a6311dab
1 changed files with 6 additions and 20 deletions

View File

@ -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)
@ -2506,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);
@ -2529,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);
}