[PATCH v2 nbdkit 0/6] Add truncate filter and other fixes.
by Richard W.M. Jones
I have dropped the map filter from this series for now while I try to
get it working.
However I think the truncate filter is in a good shape. This
incorporates all feedback from Eric's review.
Also there are three small fixes to the filter code, all revealed when
I was testing using multiple filters which we'd not done much of
before.
Rich.
6 years, 3 months
[PATCH nbdkit] tests: Adjust test-fua.sh for correct use .prepare in log filter.
by Richard W.M. Jones
Commit b5ce88e889a2df4baa0b73033f7302e5b40f0570 fixed the cases where
multiple filters are placed in front of a plugin, so that now .prepare
and .finalize methods are called properly in the second and subsequent
filters.
This causes an additional log message to be emitted (correctly) from
the newly called .prepare method in the log filter:
2018-08-01 15:17:45.249533 connection=1 Connect [...]
However this extra log message incidentally breaks the FUA test.
Fix this by filtering out the additional log message before counting
the instances of the fua=1 flag in this test.
Thanks: Eric Blake.
---
tests/test-fua.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/test-fua.sh b/tests/test-fua.sh
index 8a8c7fc..0329807 100755
--- a/tests/test-fua.sh
+++ b/tests/test-fua.sh
@@ -132,14 +132,14 @@ test $(grep -c 'connection=1 Flush' fua1.log) -lt \
# all earlier parts of the transaction do not have fua
flush1=$(grep -c 'connection=1 Flush' fua2.log || :)
flush2=$(grep -c 'connection=2 Flush' fua2.log || :)
-fua=$(grep -c 'connection=2.*fua=1' fua2.log || :)
+fua=$(grep -v "Connect" fua2.log | grep -c 'connection=2.*fua=1' || :)
test $(( $flush2 - $flush1 + $fua )) = 2
# Test 3: every part of split has fua, and no flushes are added
flush1=$(grep -c 'connection=1 Flush' fua3.log || :)
flush2=$(grep -c 'connection=2 Flush' fua3.log || :)
test $flush1 = $flush2
-test $(grep -c 'connection=2.*fua=1' fua3.log) = 32
+test $(grep -v "Connect" fua3.log | grep -c 'connection=2.*fua=1') = 32
# Test 4: flush is no-op, and every transaction has fua
if grep 'fua=0' fua4.log; then
--
2.18.0
6 years, 3 months
[PATCH nbdkit] tests: Cancel trap in cleanup function to avoid recursive traps.
by Richard W.M. Jones
In these test functions, when a test fails, the bash ‘trap’ command
causes the cleanup function to be called. However bash does not annul
or cancel the traps when cleanup is called, so at the end of the
cleanup function when ‘exit’ is called, cleanup is called recursively.
Avoid this by cancelling the traps at the top of the cleanup function.
Also an extra debugging message is emitted here giving the value of
$status which can be useful.
---
tests/test-blocksize.sh | 2 ++
tests/test-cache.sh | 2 ++
tests/test-cow.sh | 2 ++
tests/test-fua.sh | 2 ++
tests/test-log.sh | 2 ++
tests/test-nozero.sh | 2 ++
tests/test-offset2.sh | 2 ++
tests/test-pattern-largest.sh | 2 ++
tests/test-pattern.sh | 2 ++
tests/test-single.sh | 2 ++
tests/test-tls-psk.sh | 2 ++
tests/test-tls.sh | 2 ++
tests/test-zero.sh | 13 ++++++++++++-
13 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/tests/test-blocksize.sh b/tests/test-blocksize.sh
index 9cadf30..e008f5e 100755
--- a/tests/test-blocksize.sh
+++ b/tests/test-blocksize.sh
@@ -55,6 +55,8 @@ pid1= pid2=
cleanup ()
{
status=$?
+ trap '' INT QUIT TERM EXIT ERR
+ echo $0: cleanup: exit code $status
test "$pid1" && kill $pid1
test "$pid2" && kill $pid2
diff --git a/tests/test-cache.sh b/tests/test-cache.sh
index c46e7be..da1f6d3 100755
--- a/tests/test-cache.sh
+++ b/tests/test-cache.sh
@@ -61,6 +61,8 @@ pid="$(cat cache.pid)"
cleanup ()
{
status=$?
+ trap '' INT QUIT TERM EXIT ERR
+ echo $0: cleanup: exit code $status
kill $pid
rm -f $files
diff --git a/tests/test-cow.sh b/tests/test-cow.sh
index 01d2d04..7211958 100755
--- a/tests/test-cow.sh
+++ b/tests/test-cow.sh
@@ -62,6 +62,8 @@ pid="$(cat cow.pid)"
cleanup ()
{
status=$?
+ trap '' INT QUIT TERM EXIT ERR
+ echo $0: cleanup: exit code $status
kill $pid
rm -f $files
diff --git a/tests/test-fua.sh b/tests/test-fua.sh
index 0ec9ef0..8a8c7fc 100755
--- a/tests/test-fua.sh
+++ b/tests/test-fua.sh
@@ -56,6 +56,8 @@ pid1= pid2= pid3= pid4=
cleanup ()
{
status=$?
+ trap '' INT QUIT TERM EXIT ERR
+ echo $0: cleanup: exit code $status
test "$pid1" && kill $pid1
test "$pid2" && kill $pid2
diff --git a/tests/test-log.sh b/tests/test-log.sh
index 94d3960..8948c2c 100755
--- a/tests/test-log.sh
+++ b/tests/test-log.sh
@@ -64,6 +64,8 @@ pid="$(cat log.pid)"
cleanup ()
{
status=$?
+ trap '' INT QUIT TERM EXIT ERR
+ echo $0: cleanup: exit code $status
kill $pid
# For easier debugging, dump the final log file before removing it.
diff --git a/tests/test-nozero.sh b/tests/test-nozero.sh
index 57c4452..77fda0b 100755
--- a/tests/test-nozero.sh
+++ b/tests/test-nozero.sh
@@ -66,6 +66,8 @@ pid1= pid2= pid3= pid4= pid5a= pid5b=
cleanup ()
{
status=$?
+ trap '' INT QUIT TERM EXIT ERR
+ echo $0: cleanup: exit code $status
test "$pid1" && kill $pid1
test "$pid2" && kill $pid2
diff --git a/tests/test-offset2.sh b/tests/test-offset2.sh
index a4f44cc..78bb690 100755
--- a/tests/test-offset2.sh
+++ b/tests/test-offset2.sh
@@ -70,6 +70,8 @@ pid="$(cat offset2.pid)"
cleanup ()
{
status=$?
+ trap '' INT QUIT TERM EXIT ERR
+ echo $0: cleanup: exit code $status
kill $pid
rm -f $files
diff --git a/tests/test-pattern-largest.sh b/tests/test-pattern-largest.sh
index 5ff891f..9789675 100755
--- a/tests/test-pattern-largest.sh
+++ b/tests/test-pattern-largest.sh
@@ -68,6 +68,8 @@ pid="$(cat pattern-largest.pid)"
cleanup ()
{
status=$?
+ trap '' INT QUIT TERM EXIT ERR
+ echo $0: cleanup: exit code $status
kill $pid
rm -f $files
diff --git a/tests/test-pattern.sh b/tests/test-pattern.sh
index 2db4e0c..c6e605d 100755
--- a/tests/test-pattern.sh
+++ b/tests/test-pattern.sh
@@ -70,6 +70,8 @@ pid="$(cat pattern.pid)"
cleanup ()
{
status=$?
+ trap '' INT QUIT TERM EXIT ERR
+ echo $0: cleanup: exit code $status
kill $pid
rm -f $files
diff --git a/tests/test-single.sh b/tests/test-single.sh
index fdcfc62..b4aefcc 100755
--- a/tests/test-single.sh
+++ b/tests/test-single.sh
@@ -57,6 +57,8 @@ pid=$!
cleanup ()
{
status=$?
+ trap '' INT QUIT TERM EXIT ERR
+ echo $0: cleanup: exit code $status
kill $pid
rm -f $files
diff --git a/tests/test-tls-psk.sh b/tests/test-tls-psk.sh
index 4f8111a..e7954bb 100755
--- a/tests/test-tls-psk.sh
+++ b/tests/test-tls-psk.sh
@@ -98,6 +98,8 @@ pid="$(cat tls-psk.pid)"
cleanup ()
{
status=$?
+ trap '' INT QUIT TERM EXIT ERR
+ echo $0: cleanup: exit code $status
kill $pid
rm -f tls-psk.pid tls-psk.out
diff --git a/tests/test-tls.sh b/tests/test-tls.sh
index 7a6c949..dcf34a2 100755
--- a/tests/test-tls.sh
+++ b/tests/test-tls.sh
@@ -92,6 +92,8 @@ pid="$(cat tls.pid)"
cleanup ()
{
status=$?
+ trap '' INT QUIT TERM EXIT ERR
+ echo $0: cleanup: exit code $status
kill $pid
rm -f tls.pid tls.out
diff --git a/tests/test-zero.sh b/tests/test-zero.sh
index b590345..1f4549c 100755
--- a/tests/test-zero.sh
+++ b/tests/test-zero.sh
@@ -42,7 +42,18 @@ fi
files="test-zero.out"
rm -f $files
-trap "rm $files" INT QUIT TERM EXIT ERR
+
+cleanup ()
+{
+ status=$?
+ trap '' INT QUIT TERM EXIT ERR
+ echo $0: cleanup: exit code $status
+
+ rm $files
+
+ exit $status
+}
+trap cleanup INT QUIT TERM EXIT ERR
nbdkit -U - zero --run 'qemu-img convert $nbd test-zero.out'
--
2.18.0
6 years, 3 months
[PATCH nbdkit 0/4] Add truncate and map filters.
by Richard W.M. Jones
This patch series proposes two new filters.
* truncate: This can truncate, extend, round up or round down the size
of a plugin/device. A typical usage is to fix the qemu problem that
it can only handle devices which are a multiple of 512-bytes:
nbdkit --filter=truncate random size=500 round-up=512
This will serve a virtual device with size 512 bytes. Reading from
the last 12 bytes will return zeroes. And writing is permitted,
provided you only write zeroes.
An alternative might have been to extend the offset filter to deal
with this, but that could have got quite clumsy.
* map: This is an all-purpose remapping filter. Best to read the man
page to see what this does.
(These filters are not really related to each other, except that the
truncate filter turned out to be necessary to test the map filter.)
Rich.
6 years, 3 months