Add OCaml 5 support

This commit is contained in:
Richard W.M. Jones 2023-06-22 08:41:54 +01:00
parent b1584dedf3
commit 46c79ec2b2
2 changed files with 83 additions and 2 deletions

View File

@ -0,0 +1,75 @@
From 2c909bc3b8594943c4306ec78e8c13327ca16284 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Wed, 21 Jun 2023 22:41:43 +0100
Subject: [PATCH] ocaml: Release runtime lock around call to nbd_close
OCaml 5 is stricter than earlier versions about correct locking.
We must release the OCaml runtime lock when calling nbd_close since it
may do some long-running operations and we want to allow concurrent
threads to run.
However specifically if there are callbacks (eg. a debug callback)
then we would end up trying to re-acquire the lock in the callback,
resulting in a crash:
(gdb) bt
#0 __pthread_kill_implementation (threadid=<optimized out>,
signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1 0x00007f47ffc8f773 in __pthread_kill_internal (signo=6,
threadid=<optimized out>) at pthread_kill.c:78
#2 0x00007f47ffc3e71e in __GI_raise (sig=sig@entry=6)
at ../sysdeps/posix/raise.c:26
#3 0x00007f47ffc2687f in __GI_abort () at abort.c:79
#4 0x0000560c9eb62779 in caml_fatal_error ()
#5 0x0000560c9eb63238 in caml_plat_fatal_error ()
#6 0x0000560c9eb4ea77 in caml_acquire_domain_lock ()
#7 0x0000560c9eb65cdc in caml_leave_blocking_section ()
#8 0x0000560c9eaf8a87 in debug_wrapper (user_data=0x560ca0af2670,
context=0x7f47fff8ca60 "nbd_close", msg=0x560ca0af28b0 "closing handle")
at ../nbd-c.c:187
#9 0x00007f47fff7072f in nbd_internal_debug (h=h@entry=0x560ca0b57db0,
context=0x7f47fff8ca60 "nbd_close", context@entry=0x0,
fs=fs@entry=0x7f47fff8ca6a "closing handle")
at /home/rjones/d/libnbd/lib/debug.c:90
#10 0x00007f47fff73f23 in nbd_close (h=0x560ca0b57db0)
at /home/rjones/d/libnbd/lib/handle.c:127
#11 0x0000560c9eae8dbe in nbd_internal_ocaml_handle_finalize (
hv=<optimized out>) at ../handle.c:39
#12 nbd_internal_ocaml_nbd_close (hv=<optimized out>) at ../handle.c:62
#13 <signal handler called>
#14 0x0000560c9eae84dc in camlTest_140_explicit_close__entry () at NBD.ml:148
#15 0x0000560c9eae5c5b in caml_program ()
#16 <signal handler called>
#17 0x0000560c9eb6cb77 in caml_startup_common ()
#18 0x0000560c9eb6cbef in caml_main ()
#19 0x0000560c9eae5910 in main ()
---
ocaml/handle.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/ocaml/handle.c b/ocaml/handle.c
index fb45b30102..b3e5a0fc33 100644
--- a/ocaml/handle.c
+++ b/ocaml/handle.c
@@ -26,6 +26,7 @@
#include <caml/fail.h>
#include <caml/memory.h>
#include <caml/mlvalues.h>
+#include <caml/threads.h>
#include <libnbd.h>
@@ -36,7 +37,9 @@ nbd_internal_ocaml_handle_finalize (value hv)
{
struct nbd_handle *h = NBD_val (hv);
+ caml_enter_blocking_section ();
nbd_close (h);
+ caml_leave_blocking_section ();
}
value
--
2.41.0

View File

@ -5,14 +5,14 @@
%global verify_tarball_signature 1 %global verify_tarball_signature 1
# If there are patches which touch autotools files, set this to 1. # If there are patches which touch autotools files, set this to 1.
%global patches_touch_autotools %{nil} %global patches_touch_autotools 1
# The source directory. # The source directory.
%global source_directory 1.17-development %global source_directory 1.17-development
Name: libnbd Name: libnbd
Version: 1.17.1 Version: 1.17.1
Release: 1%{?dist} Release: 2%{?dist}
Summary: NBD client library in userspace Summary: NBD client library in userspace
License: LGPL-2.0-or-later AND BSD-3-Clause License: LGPL-2.0-or-later AND BSD-3-Clause
@ -28,6 +28,9 @@ Source2: libguestfs.keyring
# Maintainer script which helps with handling patches. # Maintainer script which helps with handling patches.
Source3: copy-patches.sh Source3: copy-patches.sh
# Upstream patch to fix OCaml 5 support.
Patch: 0001-ocaml-Release-runtime-lock-around-call-to-nbd_close.patch
%if 0%{patches_touch_autotools} %if 0%{patches_touch_autotools}
BuildRequires: autoconf, automake, libtool BuildRequires: autoconf, automake, libtool
%endif %endif
@ -356,6 +359,9 @@ make %{?_smp_mflags} check || {
%changelog %changelog
* Thu Jun 22 2023 Richard W.M. Jones <rjones@redhat.com> - 1.17.1-2
- Add OCaml 5 support
* Mon Jun 19 2023 Richard W.M. Jones <rjones@redhat.com> - 1.17.1-1 * Mon Jun 19 2023 Richard W.M. Jones <rjones@redhat.com> - 1.17.1-1
- New upstream development version 1.17.1 - New upstream development version 1.17.1