[PATCH 4/7] nbd-server: Log the replies
The transaction log contains only the request from the clients, the
replies from the server were missing.
The change adds the replies to the transaction log.
Signed-off-by: Manfred Spraul <manfred.spraul@de.bosch.com>
---
nbd-server.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/nbd-server.c b/nbd-server.c
index 5cd86b0..ccfebc9 100644
--- a/nbd-server.c
+++ b/nbd-server.c
@@ -2579,6 +2579,15 @@ static void setup_reply(struct nbd_reply* rep, struct nbd_request* req) {
memcpy(&(rep->handle), &(req->handle), sizeof(req->handle));
}
+static void log_reply(CLIENT *client, struct nbd_reply *prply)
+{
+ if (client->transactionlogfd != -1) {
+ lock_logsem(client);
+ writeit(client->transactionlogfd, prply, sizeof(*prply));
+ unlock_logsem(client);
+ }
+}
+
#ifdef HAVE_SPLICE
static int handle_splice_read(CLIENT *client, struct nbd_request *req)
{
@@ -2600,6 +2609,7 @@ static int handle_splice_read(CLIENT *client, struct nbd_request *req)
DEBUG("handling read request (splice)\n");
setup_reply(&rep, req);
+ log_reply(client, &rep);
pthread_mutex_lock(&(client->lock));
writeit(client->net, &rep, sizeof(rep));
spliceit(pipefd[0], NULL, client->net, NULL, req->len);
@@ -2623,6 +2633,7 @@ static void handle_normal_read(CLIENT *client, struct nbd_request *req)
DEBUG("Read failed: %m");
rep.error = nbd_errno(errno);
}
+ log_reply(client, &rep);
pthread_mutex_lock(&(client->lock));
socket_write(client, &rep, sizeof rep);
if(!rep.error) {
@@ -2671,6 +2682,7 @@ static void handle_write(struct work_package *pkg)
rep.error = nbd_errno(errno);
}
}
+ log_reply(client, &rep);
pthread_mutex_lock(&(client->lock));
socket_write(client, &rep, sizeof rep);
pthread_mutex_unlock(&(client->lock));
@@ -2684,6 +2696,7 @@ static void handle_flush(CLIENT* client, struct nbd_request* req) {
DEBUG("Flush failed: %m");
rep.error = nbd_errno(errno);
}
+ log_reply(client, &rep);
pthread_mutex_lock(&(client->lock));
socket_write(client, &rep, sizeof rep);
pthread_mutex_unlock(&(client->lock));
@@ -2697,6 +2710,7 @@ static void handle_trim(CLIENT* client, struct nbd_request* req) {
DEBUG("Trim failed: %m");
rep.error = nbd_errno(errno);
}
+ log_reply(client, &rep);
pthread_mutex_lock(&(client->lock));
socket_write(client, &rep, sizeof rep);
pthread_mutex_unlock(&(client->lock));
@@ -2714,6 +2728,7 @@ static void handle_write_zeroes(CLIENT* client, struct nbd_request* req) {
// For now, don't trim
// TODO: handle this far more efficiently with reference to the
// actual backing driver
+ log_reply(client, &rep);
pthread_mutex_lock(&(client->lock));
socket_write(client, &rep, sizeof rep);
pthread_mutex_unlock(&(client->lock));
@@ -2800,6 +2815,7 @@ static void handle_request(gpointer data, gpointer user_data) {
error:
setup_reply(&rep, package->req);
rep.error = nbd_errno(err);
+ log_reply(package->client, &rep);
pthread_mutex_lock(&(package->client->lock));
socket_write(package->client, &rep, sizeof rep);
pthread_mutex_unlock(&(package->client->lock));
--
2.33.1
Reply to: