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