[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 08/31] nbd: Don't trim unrequested bytes
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 08/31] nbd: Don't trim unrequested bytes |
Date: |
Fri, 27 May 2016 12:06:21 +0200 |
From: Eric Blake <address@hidden>
Similar to commit df7b97ff, we are mishandling clients that
give an unaligned NBD_CMD_TRIM request, and potentially
trimming bytes that occur before their request; which in turn
can cause potential unintended data loss (unlikely in
practice, since most clients are sane and issue aligned trim
requests). However, while we fixed read and write by switching
to the byte interfaces of blk_, we don't yet have a byte
interface for discard. On the other hand, trim is advisory, so
rounding the user's request to simply ignore the first and last
unaligned sectors (or the entire request, if it is sub-sector
in length) is just fine.
CC: address@hidden
Signed-off-by: Eric Blake <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
nbd/server.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/nbd/server.c b/nbd/server.c
index fa862cd..b2cfeb9 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -1153,12 +1153,20 @@ static void nbd_trip(void *opaque)
break;
case NBD_CMD_TRIM:
TRACE("Request type is TRIM");
- ret = blk_co_discard(exp->blk, (request.from + exp->dev_offset)
- / BDRV_SECTOR_SIZE,
- request.len / BDRV_SECTOR_SIZE);
- if (ret < 0) {
- LOG("discard failed");
- reply.error = -ret;
+ /* Ignore unaligned head or tail, until block layer adds byte
+ * interface */
+ if (request.len >= BDRV_SECTOR_SIZE) {
+ request.len -= (request.from + request.len) % BDRV_SECTOR_SIZE;
+ ret = blk_co_discard(exp->blk,
+ DIV_ROUND_UP(request.from + exp->dev_offset,
+ BDRV_SECTOR_SIZE),
+ request.len / BDRV_SECTOR_SIZE);
+ if (ret < 0) {
+ LOG("discard failed");
+ reply.error = -ret;
+ }
+ } else {
+ TRACE("trim request too small, ignoring");
}
if (nbd_co_send_reply(req, &reply, 0) < 0) {
goto out;
--
2.5.5
- [Qemu-devel] [PULL 00/31] Misc changes for 2016-05-27, Paolo Bonzini, 2016/05/27
- [Qemu-devel] [PULL 03/31] hw/char: QOM'ify escc.c, Paolo Bonzini, 2016/05/27
- [Qemu-devel] [PULL 04/31] hw/char: QOM'ify etraxfs_ser.c, Paolo Bonzini, 2016/05/27
- [Qemu-devel] [PULL 01/31] Add optionrom compatible with fw_cfg DMA version, Paolo Bonzini, 2016/05/27
- [Qemu-devel] [PULL 05/31] hw/char: QOM'ify lm32_juart.c, Paolo Bonzini, 2016/05/27
- [Qemu-devel] [PULL 08/31] nbd: Don't trim unrequested bytes,
Paolo Bonzini <=
- [Qemu-devel] [PULL 06/31] hw/char: QOM'ify lm32_uart.c, Paolo Bonzini, 2016/05/27
- [Qemu-devel] [PULL 02/31] Revert "memory: Drop FlatRange.romd_mode", Paolo Bonzini, 2016/05/27
- [Qemu-devel] [PULL 07/31] hw/char: QOM'ify milkymist-uart.c, Paolo Bonzini, 2016/05/27
- [Qemu-devel] [PULL 11/31] scsi: mptsas: infinite loop while fetching requests, Paolo Bonzini, 2016/05/27
- [Qemu-devel] [PULL 13/31] scsi: megasas: initialise local configuration data buffer, Paolo Bonzini, 2016/05/27
- [Qemu-devel] [PULL 14/31] scsi: megasas: check 'read_queue_head' index value, Paolo Bonzini, 2016/05/27
- [Qemu-devel] [PULL 10/31] scsi: pvscsi: check command descriptor ring buffer size (CVE-2016-4952), Paolo Bonzini, 2016/05/27
- [Qemu-devel] [PULL 09/31] kvm_stat: Remove, Paolo Bonzini, 2016/05/27
- [Qemu-devel] [PULL 12/31] scsi: megasas: use appropriate property buffer size, Paolo Bonzini, 2016/05/27