[Libguestfs] [nbdkit PATCH v2] Introduce cacheextents filter

Richard W.M. Jones rjones at redhat.com
Thu May 16 07:42:43 UTC 2019


Apply the attached patch on top of yours which contains miscellaneous
fixes.  If you use ‘./configure --enable-gcc-warnings’ then it will
enable GCC warnings.

The test doesn't really test anything.  If extents are being cached
then I have two ideas about how you could see that: Either (1) you
could look at debug messages, the second extents call shouldn't be
processed at the plugin layer.  Or (2) write a small nbdkit-sh-plugin
script which should see the first extent request and not the second
one (and even test that a subsequent write should kill the cache so
another extent request is seen by the plugin).

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/
-------------- next part --------------
diff --git a/filters/cacheextents/cacheextents.c b/filters/cacheextents/cacheextents.c
index 01c0328..6cd22a7 100644
--- a/filters/cacheextents/cacheextents.c
+++ b/filters/cacheextents/cacheextents.c
@@ -50,9 +50,6 @@
 /* This lock protects the global state. */
 static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
 
-/* The real size of the underlying plugin. */
-static uint64_t size;
-
 /* Cached extents from the last extents () call and its start and end for the
    sake of simplicity. */
 struct nbdkit_extents *cache_extents;
@@ -131,9 +128,8 @@ cacheextents_extents (struct nbdkit_next_ops *next_ops, void *nxdata,
   }
 
   nbdkit_debug ("cacheextents: cache miss");
-  int r = next_ops->extents (nxdata, count, offset, flags, extents, err);
-  if (r == -1)
-    return r;
+  if (next_ops->extents (nxdata, count, offset, flags, extents, err) == -1)
+    return -1;
 
   return cacheextents_fill (extents, err);
 }
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a2bbaea..aaf7450 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -366,9 +366,7 @@ test_oldstyle_LDADD = libtest.la $(LIBGUESTFS_LIBS)
 endif HAVE_LIBGUESTFS
 
 # Test export flags.
-TESTS += \
-	test-cacheextents.sh \
-	test-eflags.sh
+TESTS += test-eflags.sh
 
 # common disk image shared with several tests
 if HAVE_GUESTFISH
@@ -868,6 +866,9 @@ TESTS += \
 endif HAVE_GUESTFISH
 TESTS += test-cache-max-size.sh
 
+# cacheextents filter test.
+TESTS += test-cacheextents.sh
+
 # cow filter test.
 if HAVE_GUESTFISH
 TESTS += test-cow.sh
diff --git a/tests/test-cacheextents.sh b/tests/test-cacheextents.sh
index fd0bd1c..b9145ed 100755
--- a/tests/test-cacheextents.sh
+++ b/tests/test-cacheextents.sh
@@ -38,6 +38,10 @@ requires diff --version
 requires grep --version
 requires qemu-img --version
 
+files="test-cacheextents-actual.log test-cacheextents-expected.log"
+rm -f $files
+cleanup_fn rm -f $files
+
 nbdkit \
     -U - \
     --filter=cacheextents \


More information about the Libguestfs mailing list