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.
This commit is contained in:
Patrick J Cherry
2018-02-05 17:01:32 +00:00
parent ad2014ac9d
commit afa1bb0efb
2 changed files with 5 additions and 2 deletions

View File

@@ -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); debug("request flush from=%"PRIu64", len=%"PRIu32", handle=0x%08X", request.from, request.len, request.handle);
ERROR_IF_NEGATIVE( ERROR_IF_NEGATIVE(
fsync(client->fileno), msync(client->mapped, client->mapped_size, MS_SYNC | MS_INVALIDATE),
"flush failed" "flush failed"
); );
@@ -697,7 +697,7 @@ void* client_serve(void* client_uncast)
open_and_mmap( open_and_mmap(
client->serve->filename, client->serve->filename,
&client->fileno, &client->fileno,
NULL, &client->mapped_size,
(void**) &client->mapped (void**) &client->mapped
), ),
"Couldn't open/mmap file %s: %s", client->serve->filename, strerror( errno ) "Couldn't open/mmap file %s: %s", client->serve->filename, strerror( errno )

View File

@@ -3,6 +3,7 @@
#include <signal.h> #include <signal.h>
#include <time.h> #include <time.h>
#include <inttypes.h>
/** CLIENT_HANDLER_TIMEOUT /** CLIENT_HANDLER_TIMEOUT
* This is the length of time (in seconds) any request can be outstanding for. * This is the length of time (in seconds) any request can be outstanding for.
@@ -31,6 +32,8 @@ struct client {
int fileno; int fileno;
char* mapped; char* mapped;
uint64_t mapped_size;
struct self_pipe * stop_signal; struct self_pipe * stop_signal;
struct server* serve; /* FIXME: remove above duplication */ struct server* serve; /* FIXME: remove above duplication */