The NBD spec says that we must tolerate a client sending
NBD_CMD_FLAG_FUA on any command (due to historical behavior
of at least qemu sending it on READ), but that it only has
to have defined semantics on commands that can cause write
actions. It will be easier for future patches to support
plugins that can honor FUA semantics on write if we silently
ignore FUA on non-writes (the NBD spec says only WRITE,
WRITE_ZEROES, and TRIM have write semantics).
Note that validate_request already ensured that that we are
not calling a write command if conn->readonly; since only
write commands can leave flush_after_command set, we no longer
need to check conn->readonly in handle_request.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
src/connections.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/connections.c b/src/connections.c
index 111a810..a16c118 100644
--- a/src/connections.c
+++ b/src/connections.c
@@ -1,5 +1,5 @@
/* nbdkit
- * Copyright (C) 2013-2017 Red Hat Inc.
+ * Copyright (C) 2013-2018 Red Hat Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -871,9 +871,7 @@ handle_request (struct connection *conn,
bool flush_after_command;
/* Flush after command performed? */
- flush_after_command = (flags & NBD_CMD_FLAG_FUA) != 0;
- if (!conn->can_flush || conn->readonly)
- flush_after_command = false;
+ flush_after_command = conn->can_flush && (flags & NBD_CMD_FLAG_FUA);
/* The plugin should call nbdkit_set_error() to request a particular
error, otherwise we fallback to errno or EIO. */
@@ -881,6 +879,7 @@ handle_request (struct connection *conn,
switch (cmd) {
case NBD_CMD_READ:
+ flush_after_command = false;
if (plugin_pread (conn, buf, count, offset) == -1)
return get_error (conn);
break;
@@ -891,6 +890,7 @@ handle_request (struct connection *conn,
break;
case NBD_CMD_FLUSH:
+ flush_after_command = false;
if (plugin_flush (conn) == -1)
return get_error (conn);
break;
--
2.14.3