[libguestfs PATCH] java: free JNI local refs in the event callback
by qiuyucheng
java_callback allocates a jstring and a jlongArray on every event.
The callback runs on the Java thread already inside a JNI native
method, so those local refs stay in the outer frame until that
method returns. A progress or appliance-log handler can fire often
enough in one call to overflow the JNI local reference table.
Push a local frame around the callback and pop it after
CallVoidMethod returns.
Fixes: https://github.com/libguestfs/libguestfs/issues/403
Signed-off-by: qiuyucheng <2847117296(a)qq.com>
---
java/handle.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/java/handle.c b/java/handle.c
index 629dfd95e..501c09e7f 100644
--- a/java/handle.c
+++ b/java/handle.c
@@ -155,6 +155,15 @@ java_callback (guestfs_h *g,
}
}
+ /* Events run on the Java thread already inside a JNI call, so
+ * local refs created here stay live until that outer call returns.
+ */
+ if ((*env)->PushLocalFrame (env, 16) < 0) {
+ (*env)->ExceptionDescribe (env);
+ (*env)->ExceptionClear (env);
+ return;
+ }
+
/* Convert the buffer and array to Java objects. */
jbuf = (*env)->NewStringUTF (env, buf); // XXX size
@@ -175,6 +184,8 @@ java_callback (guestfs_h *g,
(*env)->ExceptionDescribe (env);
(*env)->ExceptionClear (env);
}
+
+ (*env)->PopLocalFrame (env, NULL);
}
JNIEXPORT jint JNICALL
--
2.33.0
1 week
[libnbd PATCH] fuse: Recommend soft unmount
by Eric Blake
On some corporate systems, the presence of scanning software tries to
make sure that mountpoints are not going to forbidden destinations;
this can result in race conditions where a bare fusermount3 -u hits a
device still temporarily in use even after libnbd has released
things. A lazy unmount solves the problems; I was previously hitting
test failures about 60% of test runs, while this one let me do 100
back-to-back runs with no failures.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
fuse/nbdfuse.pod | 14 +++++++-------
fuse/test-errors.sh | 2 +-
fuse/test-file-mode.sh | 2 +-
fuse/test-nbdkit-command.sh | 2 +-
fuse/test-nbdkit-file-null.sh | 2 +-
fuse/test-nbdkit.sh | 2 +-
fuse/test-parallel.sh | 2 +-
fuse/test-pattern.sh | 2 +-
fuse/test-qcow2.sh | 2 +-
fuse/test-trim.sh | 4 ++--
fuse/test-unix.sh | 4 ++--
fuse/test-zero.sh | 4 ++--
12 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/fuse/nbdfuse.pod b/fuse/nbdfuse.pod
index 071c4a17..937f826d 100644
--- a/fuse/nbdfuse.pod
+++ b/fuse/nbdfuse.pod
@@ -35,7 +35,7 @@ nbdfuse - mount a network block device in the local filesystem
To unmount:
- fusermount3 -u MOUNTPOINT
+ fusermount3 -u -z MOUNTPOINT
Other options:
@@ -65,7 +65,7 @@ specified as an NBD URI (like C<nbd://localhost>), or as an NBD server
running as a subprocess of nbdfuse (using S<C<[ ... ]>>), or in
various other ways (see L</MODES>).
-Use C<fusermount3 -u MOUNTPOINT> to unmount the filesystem after you
+Use C<fusermount3 -u -z MOUNTPOINT> to unmount the filesystem after you
have used it.
=head1 EXAMPLES
@@ -86,7 +86,7 @@ The file is called F<dir/nbd> and you can read and write to it as if
it is a normal file. Note that writes to the file will write to the
remote NBD server. After using it, unmount it:
- $ fusermount3 -u dir
+ $ fusermount3 -u -z dir
$ rmdir dir
=head2 Use nbdkit to create a file backed by a temporary RAM disk
@@ -109,7 +109,7 @@ When you have finished with the RAM disk, you can unmount it as below
which will cause nbdkit to exit and the RAM disk contents to be
discarded:
- $ fusermount3 -u dir
+ $ fusermount3 -u -z dir
$ rmdir dir
=head2 Use qemu-nbd to read and modify a qcow2 file
@@ -127,7 +127,7 @@ File F<dir/file.raw> is in raw format, backed by F<file.qcow2>. Any
changes made to F<dir/file.raw> are reflected into the qcow2 file. To
unmount the file do:
- $ fusermount3 -u dir
+ $ fusermount3 -u -z dir
$ rmdir dir
=head2 Use nbdkit to create a local file from a file on a web server
@@ -148,7 +148,7 @@ virtual files:
dir/disk.iso: DOS/MBR boot sector
$ qemu-system-x86_64 -m 4G \
-drive file=dir/disk.iso,format=raw,if=virtio,snapshot=on
- $ fusermount3 -u dir
+ $ fusermount3 -u -z dir
In this example we have used the virtual file to boot qemu, but qemu
can much more efficiently access NBD servers directly so in the real
@@ -226,7 +226,7 @@ Use these options to map UIDs and GIDs.
When nbdfuse is ready to serve, write the nbdfuse process ID (PID) to
F<PIDFILE>. This can be used in scripts to wait until nbdfuse is
-ready. Note you mustn't try to kill nbdfuse. Use C<fusermount3 -u>
+ready. Note you mustn't try to kill nbdfuse. Use C<fusermount3 -u -z>
to unmount the mountpoint which will cause nbdfuse to exit cleanly.
=item B<-r>
diff --git a/fuse/test-errors.sh b/fuse/test-errors.sh
index 71dd3186..4059aadf 100755
--- a/fuse/test-errors.sh
+++ b/fuse/test-errors.sh
@@ -38,7 +38,7 @@ fi
mp=test-errors.d
pidfile=test-errors.pid
-cleanup_fn fusermount3 -u $mp
+cleanup_fn fusermount3 -u -z $mp
cleanup_fn rm -rf $mp $pidfile
mkdir $mp
diff --git a/fuse/test-file-mode.sh b/fuse/test-file-mode.sh
index 53ec78c5..87356429 100755
--- a/fuse/test-file-mode.sh
+++ b/fuse/test-file-mode.sh
@@ -36,7 +36,7 @@ fi
pidfile=test-file-mode.pid
mp=test-file-mode
data=test-file-mode.data
-cleanup_fn fusermount3 -u $mp
+cleanup_fn fusermount3 -u -z $mp
cleanup_fn rm -f $pidfile $mp $data
touch $mp
diff --git a/fuse/test-nbdkit-command.sh b/fuse/test-nbdkit-command.sh
index 2ff794f3..b958d4b9 100755
--- a/fuse/test-nbdkit-command.sh
+++ b/fuse/test-nbdkit-command.sh
@@ -36,7 +36,7 @@ fi
pidfile=test-nbdkit-command.pid
mp=test-nbdkit-command.d
data=test-nbdkit-command.data
-cleanup_fn fusermount3 -u $mp
+cleanup_fn fusermount3 -u -z $mp
cleanup_fn rm -rf $mp
cleanup_fn rm -f $pidfile $data
diff --git a/fuse/test-nbdkit-file-null.sh b/fuse/test-nbdkit-file-null.sh
index 9103c235..ade6dd8e 100755
--- a/fuse/test-nbdkit-file-null.sh
+++ b/fuse/test-nbdkit-file-null.sh
@@ -30,7 +30,7 @@ requires $TRUNCATE --version
pidfile=test-nbdkit-file-null.pid
mp=test-nbdkit-file-null
rm -f $pidfile $mp
-cleanup_fn fusermount3 -u $mp
+cleanup_fn fusermount3 -u -z $mp
cleanup_fn rm -f $pidfile $mp
# Create the underlying file/mountpoint as non-zero sized.
diff --git a/fuse/test-nbdkit.sh b/fuse/test-nbdkit.sh
index 7e193101..6f4637a2 100755
--- a/fuse/test-nbdkit.sh
+++ b/fuse/test-nbdkit.sh
@@ -36,7 +36,7 @@ fi
pidfile=test-nbdkit.pid
mp=test-nbdkit.d
data=test-nbdkit.data
-cleanup_fn fusermount3 -u $mp
+cleanup_fn fusermount3 -u -z $mp
cleanup_fn rm -rf $mp
cleanup_fn rm -f $pidfile $data
diff --git a/fuse/test-parallel.sh b/fuse/test-parallel.sh
index d9136d55..cd072f2f 100755
--- a/fuse/test-parallel.sh
+++ b/fuse/test-parallel.sh
@@ -37,7 +37,7 @@ fi
mp=test-parallel.d
pidfile=test-parallel.pid
-cleanup_fn fusermount3 -u $mp
+cleanup_fn fusermount3 -u -z $mp
cleanup_fn rm -rf $mp $pidfile
mkdir $mp
diff --git a/fuse/test-pattern.sh b/fuse/test-pattern.sh
index dffcdaff..dbfce132 100755
--- a/fuse/test-pattern.sh
+++ b/fuse/test-pattern.sh
@@ -41,7 +41,7 @@ fi
mp=test-pattern.d
out=test-pattern.out
pidfile=test-pattern.pid
-cleanup_fn fusermount3 -u $mp
+cleanup_fn fusermount3 -u -z $mp
cleanup_fn rm -rf $mp $out $pidfile
mkdir $mp
diff --git a/fuse/test-qcow2.sh b/fuse/test-qcow2.sh
index 3d25f2b2..e9c1753c 100755
--- a/fuse/test-qcow2.sh
+++ b/fuse/test-qcow2.sh
@@ -39,7 +39,7 @@ pidfile=test-qcow2.pid
mp=test-qcow2.d
data=test-qcow2.data
qcow2=test-qcow2.qcow2
-cleanup_fn fusermount3 -u $mp
+cleanup_fn fusermount3 -u -z $mp
cleanup_fn rm -rf $mp
cleanup_fn rm -f $pidfile $data $qcow2
diff --git a/fuse/test-trim.sh b/fuse/test-trim.sh
index 04ec41ab..dc4d9b9a 100755
--- a/fuse/test-trim.sh
+++ b/fuse/test-trim.sh
@@ -39,7 +39,7 @@ fi
mp=test-trim.d
pidfile=test-trim.pid
out=test-trim.out
-cleanup_fn fusermount3 -u $mp
+cleanup_fn fusermount3 -u -z $mp
cleanup_fn rm -rf $mp $pidfile $out
mkdir $mp
@@ -75,7 +75,7 @@ fallocate -p -l 512 -o 512 $mp/nbd
# We have to explicitly unmount it here else nbdfuse will
# never exit and nbdkit will hang.
-fusermount3 -u $mp
+fusermount3 -u -z $mp
' <<'EOF'
# The nbdkit server script.
case "$1" in
diff --git a/fuse/test-unix.sh b/fuse/test-unix.sh
index 43d2b890..b6a5a25d 100755
--- a/fuse/test-unix.sh
+++ b/fuse/test-unix.sh
@@ -35,7 +35,7 @@ fi
mp=test-unix.d
pidfile=test-unix.pid
-cleanup_fn fusermount3 -u $mp
+cleanup_fn fusermount3 -u -z $mp
cleanup_fn rm -rf $mp $pidfile
mkdir $mp
@@ -62,5 +62,5 @@ $NBDKIT -U - null --run '
# We have to explicitly unmount it here else nbdfuse will
# never exit and nbdkit will hang.
- fusermount3 -u $mp
+ fusermount3 -u -z $mp
'
diff --git a/fuse/test-zero.sh b/fuse/test-zero.sh
index a95680b7..81a307e3 100755
--- a/fuse/test-zero.sh
+++ b/fuse/test-zero.sh
@@ -42,7 +42,7 @@ fi
mp=test-zero.d
pidfile=test-zero.pid
out=test-zero.out
-cleanup_fn fusermount3 -u $mp
+cleanup_fn fusermount3 -u -z $mp
cleanup_fn rm -rf $mp $pidfile $out
mkdir $mp
@@ -78,7 +78,7 @@ fallocate -z -l 512 -o 512 $mp/nbd
# We have to explicitly unmount it here else nbdfuse will
# never exit and nbdkit will hang.
-fusermount3 -u $mp
+fusermount3 -u -z $mp
' <<'EOF'
# The nbdkit server script.
case "$1" in
--
2.55.0
1 week, 3 days