When support for NBD_CMD_CACHE was first introduced, I coded up a generic fallback under NBDKIT_CACHE_EMULATE that defers to .pread. But due to a bug, the fallback repeatedly re-reads the first 64M of the request, rather than actually advancing over the entire cache request. Sadly, I didn't even notice the bug when moving the NBDKIT_CACHE_EMULATE code to the backend for use by all filters and plugins, in 14eb056c (v1.15.1). The next patch will add testsuite coverage. Fixes: fdf06817 ("server: Internal hooks for implementing NBD_CMD_CACHE", v1.13.4) --- docs/nbdkit-filter.pod | 4 ++-- docs/nbdkit-plugin.pod | 3 ++- server/backend.c | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/nbdkit-filter.pod b/docs/nbdkit-filter.pod index c4ec1004..f3d83b6e 100644 --- a/docs/nbdkit-filter.pod +++ b/docs/nbdkit-filter.pod @@ -1054,8 +1054,8 @@ cache requests. This function will not be called if C<.can_cache> returned C<NBDKIT_CACHE_NONE> or C<NBDKIT_CACHE_EMULATE>; in turn, the filter -should not call C<next-E<gt>cache> unless -C<next-E<gt>can_cache> returned C<NBDKIT_CACHE_NATIVE>. +should not call C<next-E<gt>cache> if +C<next-E<gt>can_cache> returned C<NBDKIT_CACHE_NONE>. The parameter C<flags> exists in case of future NBD protocol extensions; at this time, it will be 0 on input, and the filter should diff --git a/docs/nbdkit-plugin.pod b/docs/nbdkit-plugin.pod index 383dcffe..6a1d5ea5 100644 --- a/docs/nbdkit-plugin.pod +++ b/docs/nbdkit-plugin.pod @@ -1101,7 +1101,8 @@ result. =item C<NBDKIT_CACHE_NATIVE> -The C<.cache> callback will be called. +Cache support is advertised to the client. The C<.cache> callback will +be called if it exists, otherwise all cache requests instantly succeed. =back diff --git a/server/backend.c b/server/backend.c index 30ec4c24..3bbba601 100644 --- a/server/backend.c +++ b/server/backend.c @@ -828,6 +828,7 @@ backend_cache (struct context *c, if (backend_pread (c, buf, limit, offset, flags, err) == -1) return -1; count -= limit; + offset += limit; } return 0; } -- 2.36.1