nbd: Don't trim unrequested bytes
commitfb26337641ef7e68c8e633139c18b7832978cd47
authorEric Blake <eblake@redhat.com>
Wed, 25 May 2016 10:59:25 +0000 (25 04:59 -0600)
committerMichael Roth <mdroth@linux.vnet.ibm.com>
Fri, 5 Aug 2016 18:28:06 +0000 (5 13:28 -0500)
tree00ae16daf04f71741ad6a361985ad09d99fe300d
parent509e13298f498117f9283afb9dfceaf3edac17ff
nbd: Don't trim unrequested bytes

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: qemu-stable@nongnu.org
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1464173965-9694-1-git-send-email-eblake@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit 353ab969730742b7392414d62f4ba9632e8cf22c)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
nbd/server.c