ae23c9
From bbcd98d89650ff2394cef9d446ed8b595b4703c7 Mon Sep 17 00:00:00 2001
ae23c9
From: John Snow <jsnow@redhat.com>
ae23c9
Date: Wed, 10 Oct 2018 18:19:24 +0100
ae23c9
Subject: [PATCH 03/49] nbd: fix NBD_FLAG_SEND_CACHE value
ae23c9
ae23c9
RH-Author: John Snow <jsnow@redhat.com>
ae23c9
Message-id: <20181010181924.30470-3-jsnow@redhat.com>
ae23c9
Patchwork-id: 82578
ae23c9
O-Subject: [RHEL8/rhel qemu-kvm PATCH 2/2] nbd: fix NBD_FLAG_SEND_CACHE value
ae23c9
Bugzilla: 1636142
ae23c9
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ae23c9
RH-Acked-by: Danilo de Paula <ddepaula@redhat.com>
ae23c9
RH-Acked-by: Thomas Huth <thuth@redhat.com>
ae23c9
ae23c9
From: "Denis V. Lunev" <den@openvz.org>
ae23c9
ae23c9
Commit bc37b06a5 added NBD_CMD_CACHE support, but used the wrong value
ae23c9
for NBD_FLAG_SEND_CACHE flag for negotiation. That commit picked bit 8,
ae23c9
which had already been assigned by the NBD specification to mean
ae23c9
NBD_FLAG_CAN_MULTI_CONN, and which was already implemented in the
ae23c9
Linux kernel as a part of stable userspace-kernel API since 4.10:
ae23c9
ae23c9
"bit 8, NBD_FLAG_CAN_MULTI_CONN: Indicates that the server operates
ae23c9
entirely without cache, or that the cache it uses is shared among all
ae23c9
connections to the given device. In particular, if this flag is
ae23c9
present, then the effects of NBD_CMD_FLUSH and NBD_CMD_FLAG_FUA
ae23c9
MUST be visible across all connections when the server sends its reply
ae23c9
to that command to the client. In the absense of this flag, clients
ae23c9
SHOULD NOT multiplex their commands over more than one connection to
ae23c9
the export.
ae23c9
...
ae23c9
bit 10, NBD_FLAG_SEND_CACHE: documents that the server understands
ae23c9
NBD_CMD_CACHE; however, note that server implementations exist
ae23c9
which support the command without advertising this bit, and
ae23c9
conversely that this bit does not guarantee that the command will
ae23c9
succeed or have an impact."
ae23c9
ae23c9
Consequences:
ae23c9
- a client trying to use NBD_CMD_CACHE per the NBD spec will not
ae23c9
see the feature as available from a qemu 3.0 server (not fatal,
ae23c9
clients already have to be prepared for caching to not exist)
ae23c9
- a client accidentally coded to the qemu 3.0 bit value instead
ae23c9
of following the spec may interpret NBD_CMD_CACHE as being available
ae23c9
when it is not (probably not fatal, the spec says the server should
ae23c9
gracefully fail unknown commands, and that clients of NBD_CMD_CACHE
ae23c9
should be prepared for failure even when the feature is advertised);
ae23c9
such clients are unlikely (perhaps only in unreleased Virtuozzo code),
ae23c9
and will disappear over time
ae23c9
- a client prepared to use multiple connections based on
ae23c9
NBD_FLAG_CAN_MULTI_CONN may cause data corruption when it assumes
ae23c9
that caching is consistent when in reality qemu 3.0 did not have
ae23c9
a consistent cache. Partially mitigated by using read-only
ae23c9
connections (where nothing needs to be flushed, so caching is
ae23c9
indeed consistent) or when using qemu-nbd with the default -e 1
ae23c9
(at most one client at a time); visible only when using -e 2 or
ae23c9
more for a writable export.
ae23c9
ae23c9
Thus the commit fixes negotiation flag in QEMU according to the
ae23c9
specification.
ae23c9
ae23c9
Signed-off-by: Denis V. Lunev <den@openvz.org>
ae23c9
CC: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
ae23c9
CC: Valery Vdovin <valery.vdovin@acronis.com>
ae23c9
CC: Eric Blake <eblake@redhat.com>
ae23c9
CC: Paolo Bonzini <pbonzini@redhat.com>
ae23c9
CC: qemu-stable@nongnu.org
ae23c9
Message-Id: <20181004100313.4253-1-den@openvz.org>
ae23c9
Reviewed-by: Eric Blake <eblake@redhat.com>
ae23c9
[eblake: enhance commit message, add defines for unimplemented flags]
ae23c9
Signed-off-by: Eric Blake <eblake@redhat.com>
ae23c9
(cherry picked from commit df91328adab8490367776d2b21b35d790a606120)
ae23c9
Signed-off-by: John Snow <jsnow@redhat.com>
ae23c9
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 include/block/nbd.h | 4 +++-
ae23c9
 1 file changed, 3 insertions(+), 1 deletion(-)
ae23c9
ae23c9
diff --git a/include/block/nbd.h b/include/block/nbd.h
ae23c9
index 4638c83..a53b0cf 100644
ae23c9
--- a/include/block/nbd.h
ae23c9
+++ b/include/block/nbd.h
ae23c9
@@ -135,7 +135,9 @@ typedef struct NBDExtent {
ae23c9
 #define NBD_FLAG_SEND_TRIM         (1 << 5) /* Send TRIM (discard) */
ae23c9
 #define NBD_FLAG_SEND_WRITE_ZEROES (1 << 6) /* Send WRITE_ZEROES */
ae23c9
 #define NBD_FLAG_SEND_DF           (1 << 7) /* Send DF (Do not Fragment) */
ae23c9
-#define NBD_FLAG_SEND_CACHE        (1 << 8) /* Send CACHE (prefetch) */
ae23c9
+#define NBD_FLAG_CAN_MULTI_CONN    (1 << 8) /* Multi-client cache consistent */
ae23c9
+#define NBD_FLAG_SEND_RESIZE       (1 << 9) /* Send resize */
ae23c9
+#define NBD_FLAG_SEND_CACHE        (1 << 10) /* Send CACHE (prefetch) */
ae23c9
 
ae23c9
 /* New-style handshake (global) flags, sent from server to client, and
ae23c9
    control what will happen during handshake phase. */
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9