From 2104686eb708bf87070c21e7af0e70e0317306b6 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 5 Jul 2021 21:36:41 +0100 Subject: [PATCH] vddk: Implement can_flush and can_fua VDDK < 6.0 doesn't support flush. Previously we advertised flush and FUA but ignored them if VDDK didn't support it. Instead, correctly set these flags in the NBD protocol according to what VDDK supports. (cherry picked from commit 04b05274414a8cf4615eb2d6f46d5658814509c1) --- plugins/vddk/vddk.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/plugins/vddk/vddk.c b/plugins/vddk/vddk.c index 76faa768..b5bce9a0 100644 --- a/plugins/vddk/vddk.c +++ b/plugins/vddk/vddk.c @@ -772,12 +772,28 @@ vddk_pwrite (void *handle, const void *buf, uint32_t count, uint64_t offset, return -1; } - if (fua && vddk_flush (handle, 0) == -1) - return -1; + if (fua) { + if (vddk_flush (handle, 0) == -1) + return -1; + } return 0; } +static int +vddk_can_fua (void *handle) +{ + /* The Flush call was not available in VDDK < 6.0. */ + return VixDiskLib_Flush != NULL ? NBDKIT_FUA_NATIVE : NBDKIT_FUA_NONE; +} + +static int +vddk_can_flush (void *handle) +{ + /* The Flush call was not available in VDDK < 6.0. */ + return VixDiskLib_Flush != NULL; +} + /* Flush data to the file. */ static int vddk_flush (void *handle, uint32_t flags) @@ -785,12 +801,6 @@ vddk_flush (void *handle, uint32_t flags) struct vddk_handle *h = handle; VixError err; - /* The Flush call was not available in VDDK < 6.0 so this is simply - * ignored on earlier versions. - */ - if (VixDiskLib_Flush == NULL) - return 0; - DEBUG_CALL ("VixDiskLib_Flush", "handle"); err = VixDiskLib_Flush (h->handle); if (err != VIX_OK) { @@ -985,6 +995,8 @@ static struct nbdkit_plugin plugin = { .get_size = vddk_get_size, .pread = vddk_pread, .pwrite = vddk_pwrite, + .can_fua = vddk_can_fua, + .can_flush = vddk_can_flush, .flush = vddk_flush, .can_extents = vddk_can_extents, .extents = vddk_extents, -- 2.31.1