|
|
357786 |
From f834b08ab5b70b9a39bb0b6c351a65ad46b5879f Mon Sep 17 00:00:00 2001
|
|
|
357786 |
From: John Snow <jsnow@redhat.com>
|
|
|
357786 |
Date: Wed, 18 Jul 2018 22:55:06 +0200
|
|
|
357786 |
Subject: [PATCH 81/89] nbd/server: introduce NBD_CMD_CACHE
|
|
|
357786 |
|
|
|
357786 |
RH-Author: John Snow <jsnow@redhat.com>
|
|
|
357786 |
Message-id: <20180718225511.14878-31-jsnow@redhat.com>
|
|
|
357786 |
Patchwork-id: 81419
|
|
|
357786 |
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 30/35] nbd/server: introduce NBD_CMD_CACHE
|
|
|
357786 |
Bugzilla: 1207657
|
|
|
357786 |
RH-Acked-by: Eric Blake <eblake@redhat.com>
|
|
|
357786 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
357786 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
357786 |
|
|
|
357786 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
|
|
|
357786 |
|
|
|
357786 |
Handle nbd CACHE command. Just do read, without sending read data back.
|
|
|
357786 |
Cache mechanism should be done by exported node driver chain.
|
|
|
357786 |
|
|
|
357786 |
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
|
|
|
357786 |
Message-Id: <20180413143156.11409-1-vsementsov@virtuozzo.com>
|
|
|
357786 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
357786 |
[eblake: fix two missing case labels in switch statements]
|
|
|
357786 |
Signed-off-by: Eric Blake <eblake@redhat.com>
|
|
|
357786 |
(cherry picked from commit bc37b06a5cde24fb24c2a2cc44dd86756034ba9d)
|
|
|
357786 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
357786 |
|
|
|
357786 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
357786 |
---
|
|
|
357786 |
include/block/nbd.h | 3 ++-
|
|
|
357786 |
nbd/common.c | 2 ++
|
|
|
357786 |
nbd/server.c | 11 +++++++----
|
|
|
357786 |
3 files changed, 11 insertions(+), 5 deletions(-)
|
|
|
357786 |
|
|
|
357786 |
diff --git a/include/block/nbd.h b/include/block/nbd.h
|
|
|
357786 |
index 8bb9606..daaeae6 100644
|
|
|
357786 |
--- a/include/block/nbd.h
|
|
|
357786 |
+++ b/include/block/nbd.h
|
|
|
357786 |
@@ -135,6 +135,7 @@ typedef struct NBDExtent {
|
|
|
357786 |
#define NBD_FLAG_SEND_TRIM (1 << 5) /* Send TRIM (discard) */
|
|
|
357786 |
#define NBD_FLAG_SEND_WRITE_ZEROES (1 << 6) /* Send WRITE_ZEROES */
|
|
|
357786 |
#define NBD_FLAG_SEND_DF (1 << 7) /* Send DF (Do not Fragment) */
|
|
|
357786 |
+#define NBD_FLAG_SEND_CACHE (1 << 8) /* Send CACHE (prefetch) */
|
|
|
357786 |
|
|
|
357786 |
/* New-style handshake (global) flags, sent from server to client, and
|
|
|
357786 |
control what will happen during handshake phase. */
|
|
|
357786 |
@@ -195,7 +196,7 @@ enum {
|
|
|
357786 |
NBD_CMD_DISC = 2,
|
|
|
357786 |
NBD_CMD_FLUSH = 3,
|
|
|
357786 |
NBD_CMD_TRIM = 4,
|
|
|
357786 |
- /* 5 reserved for failed experiment NBD_CMD_CACHE */
|
|
|
357786 |
+ NBD_CMD_CACHE = 5,
|
|
|
357786 |
NBD_CMD_WRITE_ZEROES = 6,
|
|
|
357786 |
NBD_CMD_BLOCK_STATUS = 7,
|
|
|
357786 |
};
|
|
|
357786 |
diff --git a/nbd/common.c b/nbd/common.c
|
|
|
357786 |
index 8c95c1d..41f5ed8 100644
|
|
|
357786 |
--- a/nbd/common.c
|
|
|
357786 |
+++ b/nbd/common.c
|
|
|
357786 |
@@ -148,6 +148,8 @@ const char *nbd_cmd_lookup(uint16_t cmd)
|
|
|
357786 |
return "flush";
|
|
|
357786 |
case NBD_CMD_TRIM:
|
|
|
357786 |
return "trim";
|
|
|
357786 |
+ case NBD_CMD_CACHE:
|
|
|
357786 |
+ return "cache";
|
|
|
357786 |
case NBD_CMD_WRITE_ZEROES:
|
|
|
357786 |
return "write zeroes";
|
|
|
357786 |
case NBD_CMD_BLOCK_STATUS:
|
|
|
357786 |
diff --git a/nbd/server.c b/nbd/server.c
|
|
|
357786 |
index 2c2d62c..2746046 100644
|
|
|
357786 |
--- a/nbd/server.c
|
|
|
357786 |
+++ b/nbd/server.c
|
|
|
357786 |
@@ -1252,7 +1252,7 @@ static coroutine_fn int nbd_negotiate(NBDClient *client, Error **errp)
|
|
|
357786 |
int ret;
|
|
|
357786 |
const uint16_t myflags = (NBD_FLAG_HAS_FLAGS | NBD_FLAG_SEND_TRIM |
|
|
|
357786 |
NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA |
|
|
|
357786 |
- NBD_FLAG_SEND_WRITE_ZEROES);
|
|
|
357786 |
+ NBD_FLAG_SEND_WRITE_ZEROES | NBD_FLAG_SEND_CACHE);
|
|
|
357786 |
bool oldStyle;
|
|
|
357786 |
|
|
|
357786 |
/* Old style negotiation header, no room for options
|
|
|
357786 |
@@ -2034,7 +2034,9 @@ static int nbd_co_receive_request(NBDRequestData *req, NBDRequest *request,
|
|
|
357786 |
return -EIO;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
- if (request->type == NBD_CMD_READ || request->type == NBD_CMD_WRITE) {
|
|
|
357786 |
+ if (request->type == NBD_CMD_READ || request->type == NBD_CMD_WRITE ||
|
|
|
357786 |
+ request->type == NBD_CMD_CACHE)
|
|
|
357786 |
+ {
|
|
|
357786 |
if (request->len > NBD_MAX_BUFFER_SIZE) {
|
|
|
357786 |
error_setg(errp, "len (%" PRIu32" ) is larger than max len (%u)",
|
|
|
357786 |
request->len, NBD_MAX_BUFFER_SIZE);
|
|
|
357786 |
@@ -2119,7 +2121,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *client, NBDRequest *request,
|
|
|
357786 |
int ret;
|
|
|
357786 |
NBDExport *exp = client->exp;
|
|
|
357786 |
|
|
|
357786 |
- assert(request->type == NBD_CMD_READ);
|
|
|
357786 |
+ assert(request->type == NBD_CMD_READ || request->type == NBD_CMD_CACHE);
|
|
|
357786 |
|
|
|
357786 |
/* XXX: NBD Protocol only documents use of FUA with WRITE */
|
|
|
357786 |
if (request->flags & NBD_CMD_FLAG_FUA) {
|
|
|
357786 |
@@ -2138,7 +2140,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *client, NBDRequest *request,
|
|
|
357786 |
|
|
|
357786 |
ret = blk_pread(exp->blk, request->from + exp->dev_offset, data,
|
|
|
357786 |
request->len);
|
|
|
357786 |
- if (ret < 0) {
|
|
|
357786 |
+ if (ret < 0 || request->type == NBD_CMD_CACHE) {
|
|
|
357786 |
return nbd_send_generic_reply(client, request->handle, ret,
|
|
|
357786 |
"reading from file failed", errp);
|
|
|
357786 |
}
|
|
|
357786 |
@@ -2171,6 +2173,7 @@ static coroutine_fn int nbd_handle_request(NBDClient *client,
|
|
|
357786 |
|
|
|
357786 |
switch (request->type) {
|
|
|
357786 |
case NBD_CMD_READ:
|
|
|
357786 |
+ case NBD_CMD_CACHE:
|
|
|
357786 |
return nbd_do_cmd_read(client, request, data, errp);
|
|
|
357786 |
|
|
|
357786 |
case NBD_CMD_WRITE:
|
|
|
357786 |
--
|
|
|
357786 |
1.8.3.1
|
|
|
357786 |
|