From afa1bb0efba2816c7a7b269b9e1c8867a279dd6f Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Mon, 5 Feb 2018 17:01:32 +0000 Subject: [PATCH] Use msync rather than fsync to flush the entire disc This involves storing the size of the mapped disc in the client struct, and then supplying that to the msync command. --- src/server/client.c | 4 ++-- src/server/client.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/server/client.c b/src/server/client.c index 6d8543b..eb203b3 100644 --- a/src/server/client.c +++ b/src/server/client.c @@ -500,7 +500,7 @@ void client_reply_to_flush( struct client* client, struct nbd_request request ) debug("request flush from=%"PRIu64", len=%"PRIu32", handle=0x%08X", request.from, request.len, request.handle); ERROR_IF_NEGATIVE( - fsync(client->fileno), + msync(client->mapped, client->mapped_size, MS_SYNC | MS_INVALIDATE), "flush failed" ); @@ -697,7 +697,7 @@ void* client_serve(void* client_uncast) open_and_mmap( client->serve->filename, &client->fileno, - NULL, + &client->mapped_size, (void**) &client->mapped ), "Couldn't open/mmap file %s: %s", client->serve->filename, strerror( errno ) diff --git a/src/server/client.h b/src/server/client.h index 9110d7d..a03ea44 100644 --- a/src/server/client.h +++ b/src/server/client.h @@ -3,6 +3,7 @@ #include #include +#include /** CLIENT_HANDLER_TIMEOUT * This is the length of time (in seconds) any request can be outstanding for. @@ -31,6 +32,8 @@ struct client { int fileno; char* mapped; + uint64_t mapped_size; + struct self_pipe * stop_signal; struct server* serve; /* FIXME: remove above duplication */