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