[PATCH] v2v: Model machine type explicitly.
by Richard W.M. Jones
QEMU for x86 supports two machine types, "pc" (emulating the ancient
Intel i440FX chipset originally used by the Pentium Pro), and "q35"
(https://wiki.qemu.org/Features/Q35).
Currently virt-v2v does not set any machine type, so libvirt or the
target hypervisor will choose some default, probably i440fx. The
latest advice from the QEMU and libvirt communities is not to rely on
the default machine type but to specify what we need explicitly, but
it may also be that the libvirt configuration file has been changed to
set the default machine type to Q35 (either by the distro or the end
user).
None of this matters for reasonably new guests since they can boot
with either chipset. However there are some very old guests (notably
Windows XP) which cannot handle Q35.
This commit changes virt-v2v so it always tries to specify the machine
type explicitly (assuming the target supports that, and not all of
them do). For x86_64 guests this patch always selects i440fx (pc).
In future we hope to get the correct machine type for the guest from
libosinfo but this is not available yet.
For non-x86 architectures we select the "virt" model which will
probably only work for AArch64. More work is needed for POWER.
For secure boot we still have to force the machine type to Q35. In a
future version this forcing can be removed since any guest which is
using secure boot will be new enough that it'll be using Q35 anyway
(on x86).
---
v2v/convert_linux.ml | 7 +++++++
v2v/convert_windows.ml | 7 +++++++
v2v/create_libvirt_xml.ml | 37 +++++++++++++++++++++++++------------
v2v/create_ovf.ml | 2 ++
v2v/output_glance.ml | 5 +++++
v2v/output_qemu.ml | 30 +++++++++++++++++++-----------
v2v/test-v2v-i-ova.xml | 2 +-
v2v/types.ml | 8 ++++++++
v2v/types.mli | 6 ++++--
9 files changed, 78 insertions(+), 26 deletions(-)
diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
index 02dc2fee2..726915875 100644
--- a/v2v/convert_linux.ml
+++ b/v2v/convert_linux.ml
@@ -122,6 +122,12 @@ let convert (g : G.guestfs) inspect source output rcaps =
SELinux_relabel.relabel g;
+ (* XXX Look up this information in libosinfo in future. *)
+ let machine =
+ match inspect.i_arch with
+ | "i386"|"x86_64" -> I440FX
+ | _ -> Virt in
+
(* Return guest capabilities from the convert () function. *)
let guestcaps = {
gcaps_block_bus = block_type;
@@ -130,6 +136,7 @@ let convert (g : G.guestfs) inspect source output rcaps =
gcaps_virtio_rng = kernel.ki_supports_virtio_rng;
gcaps_virtio_balloon = kernel.ki_supports_virtio_balloon;
gcaps_isa_pvpanic = kernel.ki_supports_isa_pvpanic;
+ gcaps_machine = machine;
gcaps_arch = Utils.kvm_arch inspect.i_arch;
gcaps_acpi = acpi;
} in
diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml
index 163319545..1e058136e 100644
--- a/v2v/convert_windows.ml
+++ b/v2v/convert_windows.ml
@@ -212,6 +212,12 @@ let convert (g : G.guestfs) inspect source output rcaps =
warning (f_"this guest has Anti-Virus (AV) software and a new virtio block device driver was installed. In some circumstances, AV may prevent new drivers from working (resulting in a 7B boot error). If this happens, try disabling AV before doing the conversion.");
);
+ (* XXX Look up this information in libosinfo in future. *)
+ let machine =
+ match inspect.i_arch with
+ | "i386"|"x86_64" -> I440FX
+ | _ -> Virt in
+
(* Return guest capabilities from the convert () function. *)
let guestcaps = {
gcaps_block_bus = block_driver;
@@ -220,6 +226,7 @@ let convert (g : G.guestfs) inspect source output rcaps =
gcaps_virtio_rng = virtio_rng_supported;
gcaps_virtio_balloon = virtio_ballon_supported;
gcaps_isa_pvpanic = isa_pvpanic_supported;
+ gcaps_machine = machine;
gcaps_arch = Utils.kvm_arch inspect.i_arch;
gcaps_acpi = true;
} in
diff --git a/v2v/create_libvirt_xml.ml b/v2v/create_libvirt_xml.ml
index cf2cad0a2..ac07f9e9e 100644
--- a/v2v/create_libvirt_xml.ml
+++ b/v2v/create_libvirt_xml.ml
@@ -86,15 +86,17 @@ let create_libvirt_xml ?pool source target_buses guestcaps
match target_firmware with
| TargetBIOS -> None
| TargetUEFI -> Some (find_uefi_firmware guestcaps.gcaps_arch) in
- let secure_boot_required =
- match uefi_firmware with
- | Some { Uefi.flags = flags }
- when List.mem Uefi.UEFI_FLAG_SECURE_BOOT_REQUIRED flags -> true
- | _ -> false in
- (* Currently these are required by secure boot, but in theory they
- * might be independent properties.
- *)
- let machine_q35 = secure_boot_required in
+ let machine, secure_boot_required =
+ match guestcaps.gcaps_machine, uefi_firmware with
+ | _, Some { Uefi.flags = flags }
+ when List.mem Uefi.UEFI_FLAG_SECURE_BOOT_REQUIRED flags ->
+ (* Force machine type to Q35 because PC does not support
+ * secure boot. We must remove this when we get the
+ * correct machine type from libosinfo in future. XXX
+ *)
+ Q35, true
+ | machine, _ ->
+ machine, false in
let smm = secure_boot_required in
(* We have the machine features of the guest when it was on the
@@ -145,7 +147,18 @@ let create_libvirt_xml ?pool source target_buses guestcaps
(* The <os> section subelements. *)
let os_section =
- let machine = if machine_q35 then [ "machine", "q35" ] else [] in
+ let os = ref [] in
+
+ let machine =
+ match machine with
+ | I440FX -> "pc"
+ | Q35 -> "q35"
+ | Virt -> "virt" in
+
+ List.push_back os
+ (e "type" ["arch", guestcaps.gcaps_arch;
+ "machine", machine]
+ [PCData "hvm"]);
let loader =
match uefi_firmware with
@@ -157,8 +170,8 @@ let create_libvirt_xml ?pool source target_buses guestcaps
[ PCData code ];
e "nvram" ["template", vars_template] [] ] in
- (e "type" (["arch", guestcaps.gcaps_arch] @ machine) [PCData "hvm"])
- :: loader in
+ List.push_back_list os loader;
+ !os in
List.push_back_list body [
e "os" [] os_section;
diff --git a/v2v/create_ovf.ml b/v2v/create_ovf.ml
index 2cf610333..92b13d827 100644
--- a/v2v/create_ovf.ml
+++ b/v2v/create_ovf.ml
@@ -602,6 +602,8 @@ let rec create_ovf source targets guestcaps inspect
source.s_vcpu memsize_mb)]
] in
+ (* XXX How to set machine type for Q35? *)
+
List.push_back virtual_hardware_section_items (
e "Item" [] ([
e "rasd:Caption" [] [PCData (sprintf "%d virtual cpu" source.s_vcpu)];
diff --git a/v2v/output_glance.ml b/v2v/output_glance.ml
index c334def42..96c31da59 100644
--- a/v2v/output_glance.ml
+++ b/v2v/output_glance.ml
@@ -86,6 +86,11 @@ object
(match guestcaps.gcaps_video with
| QXL -> "qxl"
| Cirrus -> "cirrus");
+ "hw_machine_type",
+ (match guestcaps.gcaps_machine with
+ | I440FX -> "pc"
+ | Q35 -> "q35"
+ | Virt -> "virt");
"architecture", guestcaps.gcaps_arch;
"hypervisor_type", "kvm";
"vm_mode", "hvm";
diff --git a/v2v/output_qemu.ml b/v2v/output_qemu.ml
index 07eee4cb3..01dc80089 100644
--- a/v2v/output_qemu.ml
+++ b/v2v/output_qemu.ml
@@ -56,17 +56,25 @@ object
match target_firmware with
| TargetBIOS -> None
| TargetUEFI -> Some (find_uefi_firmware guestcaps.gcaps_arch) in
- let secure_boot_required =
- match uefi_firmware with
- | Some { Uefi.flags }
- when List.mem Uefi.UEFI_FLAG_SECURE_BOOT_REQUIRED flags -> true
- | _ -> false in
- (* Currently these are required by secure boot, but in theory they
- * might be independent properties.
- *)
- let machine_q35 = secure_boot_required in
+ let machine, secure_boot_required =
+ match guestcaps.gcaps_machine, uefi_firmware with
+ | _, Some { Uefi.flags }
+ when List.mem Uefi.UEFI_FLAG_SECURE_BOOT_REQUIRED flags ->
+ (* Force machine type to Q35 because PC does not support
+ * secure boot. We must remove this when we get the
+ * correct machine type from libosinfo in future. XXX
+ *)
+ Q35, true
+ | machine, _ ->
+ machine, false in
let smm = secure_boot_required in
+ let machine =
+ match machine with
+ | I440FX -> "pc"
+ | Q35 -> "q35"
+ | Virt -> "virt" in
+
(* Construct the command line. Note that the [Qemuopts]
* module deals with shell and qemu comma quoting.
*)
@@ -87,8 +95,8 @@ object
arg_list "-device" ["vmgenid"; sprintf "guid=%s" genid; "id=vmgenid0"]
);
- arg_list "-machine" (if machine_q35 then ["q35"] else [] @
- if smm then ["smm=on"] else [] @
+ arg_list "-machine" (machine ::
+ (if smm then ["smm=on"] else []) @
["accel=kvm:tcg"]);
(match uefi_firmware with
diff --git a/v2v/test-v2v-i-ova.xml b/v2v/test-v2v-i-ova.xml
index 5a303b80a..b277193a8 100644
--- a/v2v/test-v2v-i-ova.xml
+++ b/v2v/test-v2v-i-ova.xml
@@ -10,7 +10,7 @@
<apic/>
</features>
<os>
- <type arch='x86_64'>hvm</type>
+ <type arch='x86_64' machine='pc'>hvm</type>
</os>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
diff --git a/v2v/types.ml b/v2v/types.ml
index 3e3f0fc26..900275834 100644
--- a/v2v/types.ml
+++ b/v2v/types.ml
@@ -411,6 +411,7 @@ type guestcaps = {
gcaps_virtio_rng : bool;
gcaps_virtio_balloon : bool;
gcaps_isa_pvpanic : bool;
+ gcaps_machine : guestcaps_machine;
gcaps_arch : string;
gcaps_acpi : bool;
}
@@ -422,6 +423,7 @@ and requested_guestcaps = {
and guestcaps_block_type = Virtio_blk | Virtio_SCSI | IDE
and guestcaps_net_type = Virtio_net | E1000 | RTL8139
and guestcaps_video_type = QXL | Cirrus
+and guestcaps_machine = I440FX | Q35 | Virt
let string_of_block_type = function
| Virtio_blk -> "virtio-blk"
@@ -434,17 +436,23 @@ let string_of_net_type = function
let string_of_video = function
| QXL -> "qxl"
| Cirrus -> "cirrus"
+let string_of_machine = function
+ | I440FX -> "i440fx"
+ | Q35 -> "q35"
+ | Virt -> "virt"
let string_of_guestcaps gcaps =
sprintf "\
gcaps_block_bus = %s
gcaps_net_bus = %s
gcaps_video = %s
+gcaps_machine = %s
gcaps_arch = %s
gcaps_acpi = %b
" (string_of_block_type gcaps.gcaps_block_bus)
(string_of_net_type gcaps.gcaps_net_bus)
(string_of_video gcaps.gcaps_video)
+ (string_of_machine gcaps.gcaps_machine)
gcaps.gcaps_arch
gcaps.gcaps_acpi
diff --git a/v2v/types.mli b/v2v/types.mli
index 891caeafe..71788a53f 100644
--- a/v2v/types.mli
+++ b/v2v/types.mli
@@ -258,8 +258,9 @@ type guestcaps = {
gcaps_virtio_balloon : bool; (** Guest supports virtio balloon. *)
gcaps_isa_pvpanic : bool; (** Guest supports ISA pvpanic device. *)
- gcaps_arch : string; (** Architecture that KVM must emulate. *)
- gcaps_acpi : bool; (** True if guest supports acpi. *)
+ gcaps_machine : guestcaps_machine; (** Machine model. *)
+ gcaps_arch : string; (** Architecture that KVM must emulate. *)
+ gcaps_acpi : bool; (** True if guest supports acpi. *)
}
(** Guest capabilities after conversion. eg. Was virtio found or installed? *)
@@ -275,6 +276,7 @@ and requested_guestcaps = {
and guestcaps_block_type = Virtio_blk | Virtio_SCSI | IDE
and guestcaps_net_type = Virtio_net | E1000 | RTL8139
and guestcaps_video_type = QXL | Cirrus
+and guestcaps_machine = I440FX | Q35 | Virt
val string_of_guestcaps : guestcaps -> string
val string_of_requested_guestcaps : requested_guestcaps -> string
--
2.18.0
6 years, 4 months
[PATCH] v2v: -o rhv-upload: check for ovirtsdk4 (RHBZ#1601943)
by Pino Toscano
Check earlier whether the ovirtsdk4 Python can be imported correctly,
to avoid errors later on during the migration.
---
v2v/output_rhv_upload.ml | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/v2v/output_rhv_upload.ml b/v2v/output_rhv_upload.ml
index 0152b8d5a..63fa2411a 100644
--- a/v2v/output_rhv_upload.ml
+++ b/v2v/output_rhv_upload.ml
@@ -126,6 +126,13 @@ class output_rhv_upload output_alloc output_conn
python3
in
+ (* Check that the 'ovirtsdk4' Python module is available. *)
+ let error_unless_ovirtsdk4_module_available () =
+ let res = run_command [ python3; "-c"; "import ovirtsdk4" ] in
+ if res <> 0 then
+ error (f_"the Python module ‘ovirtsdk4’ could not be loaded, is it installed? See previous messages for problems.")
+ in
+
(* Check that nbdkit is available and new enough. *)
let error_unless_nbdkit_working () =
if 0 <> Sys.command "nbdkit --version >/dev/null" then
@@ -231,6 +238,7 @@ object
method precheck () =
error_unless_python_binary_on_path ();
+ error_unless_ovirtsdk4_module_available ();
error_unless_nbdkit_working ();
error_unless_nbdkit_python3_working ();
error_unless_output_alloc_sparse ();
--
2.17.1
6 years, 4 months
[PATCH] uefi: add non-deprecated Fedora paths for OVMF w/ secboot
by Pino Toscano
Add new paths for the Secure Boot variant of OVMF as found in Fedora.
---
generator/UEFI.ml | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/generator/UEFI.ml b/generator/UEFI.ml
index 1ff3f84d2..bca3fa1ae 100644
--- a/generator/UEFI.ml
+++ b/generator/UEFI.ml
@@ -52,6 +52,12 @@ let firmware = [
"/usr/share/edk2/ovmf/OVMF_VARS.fd",
[];
+ "x86_64",
+ "/usr/share/edk2/ovmf/OVMF_CODE.secboot.fd",
+ None,
+ "/usr/share/edk2/ovmf/OVMF_VARS.fd",
+ [ "UEFI_FLAG_SECURE_BOOT_REQUIRED" ];
+
"x86_64",
"/usr/share/qemu/ovmf-x86_64-code.bin",
None,
--
2.17.1
6 years, 4 months
[PATCH 1/2] Revert "v2v: oVirt changed the ResourceType for QXL video devices (RHBZ#1598715)."
by Pino Toscano
The change is not correct in case the OVF is used in -o vdsm mode, for
example. Let's revert it, and then implement it properly.
This reverts commit 296b2f66c71df0bf5ee2ee605fe4b92672796ab3.
---
v2v/create_ovf.ml | 2 +-
v2v/test-v2v-o-rhv.ovf.expected | 2 +-
v2v/test-v2v-o-vdsm-options.ovf.expected | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/v2v/create_ovf.ml b/v2v/create_ovf.ml
index 1cba165a4..901d47528 100644
--- a/v2v/create_ovf.ml
+++ b/v2v/create_ovf.ml
@@ -646,7 +646,7 @@ let rec create_ovf source targets guestcaps inspect
e "Item" [] [
e "rasd:Caption" [] [PCData "Graphical Controller"];
e "rasd:InstanceId" [] [PCData (uuidgen ())];
- e "rasd:ResourceType" [] [PCData "32768"];
+ e "rasd:ResourceType" [] [PCData "20"];
e "Type" [] [PCData "video"];
e "rasd:VirtualQuantity" [] [PCData "1"];
e "rasd:Device" [] [PCData "qxl"];
diff --git a/v2v/test-v2v-o-rhv.ovf.expected b/v2v/test-v2v-o-rhv.ovf.expected
index 2f1032b1f..7bcc456c5 100644
--- a/v2v/test-v2v-o-rhv.ovf.expected
+++ b/v2v/test-v2v-o-rhv.ovf.expected
@@ -56,7 +56,7 @@
<Item>
<rasd:Caption>Graphical Controller</rasd:Caption>
<rasd:InstanceId>#UUID#</rasd:InstanceId>
- <rasd:ResourceType>32768</rasd:ResourceType>
+ <rasd:ResourceType>20</rasd:ResourceType>
<Type>video</Type>
<rasd:VirtualQuantity>1</rasd:VirtualQuantity>
<rasd:Device>qxl</rasd:Device>
diff --git a/v2v/test-v2v-o-vdsm-options.ovf.expected b/v2v/test-v2v-o-vdsm-options.ovf.expected
index abaf37e54..c1282c19b 100644
--- a/v2v/test-v2v-o-vdsm-options.ovf.expected
+++ b/v2v/test-v2v-o-vdsm-options.ovf.expected
@@ -56,7 +56,7 @@
<Item>
<rasd:Caption>Graphical Controller</rasd:Caption>
<rasd:InstanceId>#UUID#</rasd:InstanceId>
- <rasd:ResourceType>32768</rasd:ResourceType>
+ <rasd:ResourceType>20</rasd:ResourceType>
<Type>video</Type>
<rasd:VirtualQuantity>1</rasd:VirtualQuantity>
<rasd:Device>qxl</rasd:Device>
--
2.17.1
6 years, 5 months
filesystem type unknow for lvm root fs
by Abhilasha m revur
Hi:
I am trying to get filesystems of a VM which has root fs on lvm. The
libguestfs tool is not able to detect the filesystem type of this. I have
attached logs for reference.
These disks are exported from vmware vms.
Thanks,
Abhilasha Revur
6 years, 5 months
[PATCH] v2v: oVirt changed the ResourceType for QXL video devices (RHBZ#1598715).
by Richard W.M. Jones
See:
https://bugzilla.redhat.com/show_bug.cgi?id=1598715#c5
---
v2v/create_ovf.ml | 2 +-
v2v/test-v2v-o-rhv.ovf.expected | 2 +-
v2v/test-v2v-o-vdsm-options.ovf.expected | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/v2v/create_ovf.ml b/v2v/create_ovf.ml
index b2a240907..f5f29cdc4 100644
--- a/v2v/create_ovf.ml
+++ b/v2v/create_ovf.ml
@@ -648,7 +648,7 @@ let rec create_ovf source targets guestcaps inspect
e "Item" [] [
e "rasd:Caption" [] [PCData "Graphical Controller"];
e "rasd:InstanceId" [] [PCData (uuidgen ())];
- e "rasd:ResourceType" [] [PCData "20"];
+ e "rasd:ResourceType" [] [PCData "32768"];
e "Type" [] [PCData "video"];
e "rasd:VirtualQuantity" [] [PCData "1"];
e "rasd:Device" [] [PCData "qxl"];
diff --git a/v2v/test-v2v-o-rhv.ovf.expected b/v2v/test-v2v-o-rhv.ovf.expected
index 7bcc456c5..2f1032b1f 100644
--- a/v2v/test-v2v-o-rhv.ovf.expected
+++ b/v2v/test-v2v-o-rhv.ovf.expected
@@ -56,7 +56,7 @@
<Item>
<rasd:Caption>Graphical Controller</rasd:Caption>
<rasd:InstanceId>#UUID#</rasd:InstanceId>
- <rasd:ResourceType>20</rasd:ResourceType>
+ <rasd:ResourceType>32768</rasd:ResourceType>
<Type>video</Type>
<rasd:VirtualQuantity>1</rasd:VirtualQuantity>
<rasd:Device>qxl</rasd:Device>
diff --git a/v2v/test-v2v-o-vdsm-options.ovf.expected b/v2v/test-v2v-o-vdsm-options.ovf.expected
index c1282c19b..abaf37e54 100644
--- a/v2v/test-v2v-o-vdsm-options.ovf.expected
+++ b/v2v/test-v2v-o-vdsm-options.ovf.expected
@@ -56,7 +56,7 @@
<Item>
<rasd:Caption>Graphical Controller</rasd:Caption>
<rasd:InstanceId>#UUID#</rasd:InstanceId>
- <rasd:ResourceType>20</rasd:ResourceType>
+ <rasd:ResourceType>32768</rasd:ResourceType>
<Type>video</Type>
<rasd:VirtualQuantity>1</rasd:VirtualQuantity>
<rasd:Device>qxl</rasd:Device>
--
2.17.1
6 years, 5 months
[PATCH nbdkit] Add Tcl plugin, for writing plugins in Tcl.
by Richard W.M. Jones
This lets you write simple plugins in Tcl. All the basic features of
nbdkit are supported, but serious Tcl users will probably want to
enhance the plugin further.
Unfortunately Tcl as a language is not very well suited to handling
binary data. It prefers to store binary data in UCS-2 strings,
meaning that every second byte is wasted. Also there appears to be no
way to replace part of such a string/array in-place.
Strictly speaking Tcl requires that:
"only the thread that created a Tcl interpreter can use that
interpreter. In other words, multiple threads can not access the
same Tcl interpreter."
Apparently this applies even if nbdkit uses mutexes to ensure that
multiple threads are not calling into the interpreter at the same
time. We do not have such a threading model in nbdkit (see also VDDK)
but at the same time I was not able to get Tcl to crash.
The Tcl interpreter leaks quite a lot of memory from the tcl_load and
tcl_open calls. This may be connected with the previous point. It
makes valgrind fairly useless so it is disabled for Tcl.
---
.gitignore | 1 +
README | 6 +-
common-rules.mk | 1 +
configure.ac | 17 +
docs/nbdkit-plugin.pod.in | 8 +-
docs/nbdkit.pod.in | 3 +-
plugins/tcl/Makefile.am | 68 ++++
plugins/tcl/example.tcl | 90 +++++
plugins/tcl/nbdkit-tcl-plugin.pod | 333 ++++++++++++++++++
plugins/tcl/tcl.c | 553 ++++++++++++++++++++++++++++++
tests/Makefile.am | 13 +
tests/test-dump-plugin.sh | 2 +-
tests/test-lang-plugins.c | 3 +-
tests/test.tcl | 28 ++
14 files changed, 1119 insertions(+), 7 deletions(-)
diff --git a/.gitignore b/.gitignore
index c986d76..de091f7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -81,5 +81,6 @@ Makefile.in
/tests/test-socket-activation
/tests/test-split
/tests/test-streaming
+/tests/test-tcl
/tests/test-xz
/test-driver
diff --git a/README b/README
index ab71a5d..e51b564 100644
--- a/README
+++ b/README
@@ -15,7 +15,7 @@ The key features are:
* Well-documented, simple plugin API with a stable ABI guarantee.
Lets you export "unconventional" block devices easily.
- * You can write plugins in C, Perl, Python, OCaml or Ruby.
+ * You can write plugins in C, Perl, Python, OCaml, Ruby or Tcl.
For documentation, see the docs/ directory.
@@ -91,6 +91,10 @@ For the OCaml plugin:
- OCaml >= 4.02.2 which has support for shared libraries, see:
http://caml.inria.fr/mantis/view.php?id=6693
+For the Tcl plugin:
+
+ - Tcl development library and headers
+
For bash tab completion:
- bash-completion >= 1.99
diff --git a/common-rules.mk b/common-rules.mk
index feb12c0..038f495 100644
--- a/common-rules.mk
+++ b/common-rules.mk
@@ -52,6 +52,7 @@ plugins = \
split \
streaming \
tar \
+ tcl \
vddk \
xz \
zero
diff --git a/configure.ac b/configure.ac
index be05d86..16e3250 100644
--- a/configure.ac
+++ b/configure.ac
@@ -364,6 +364,22 @@ AS_IF([test "x$RUBY" != "xno" && test "x$enable_ruby" != "xno"],[
AM_CONDITIONAL([HAVE_RUBY],[test "x$RUBY" != "xno" &&
test "x$enable_ruby" = "xyes"])
+dnl Check for Tcl, for embedding in the Tcl plugin.
+AC_ARG_ENABLE([tcl],
+ AS_HELP_STRING([--disable-tcl], [disable Tcl plugin]),
+ [],
+ [enable_tcl=yes])
+AS_IF([test "x$enable_tcl" != "xno"],[
+ PKG_CHECK_MODULES([TCL], [tcl], [
+ AC_SUBST([TCL_CFLAGS])
+ AC_SUBST([TCL_LIBS])
+ ],[
+ AC_MSG_WARN([Tcl not found])
+ enable_tcl=no
+ ])
+])
+AM_CONDITIONAL([HAVE_TCL],[test "x$enable_tcl" = "xyes"])
+
dnl Check for curl (only if you want to compile the curl plugin).
AC_ARG_WITH([curl],[
AS_HELP_STRING([--without-curl],
@@ -584,6 +600,7 @@ AC_CONFIG_FILES([Makefile
plugins/split/Makefile
plugins/streaming/Makefile
plugins/tar/Makefile
+ plugins/tcl/Makefile
plugins/vddk/Makefile
plugins/xz/Makefile
plugins/zero/Makefile
diff --git a/docs/nbdkit-plugin.pod.in b/docs/nbdkit-plugin.pod.in
index 22ca40e..d75ef3b 100644
--- a/docs/nbdkit-plugin.pod.in
+++ b/docs/nbdkit-plugin.pod.in
@@ -63,7 +63,8 @@ To write plugins in other languages, see:
L<nbdkit-ocaml-plugin(3)>,
L<nbdkit-perl-plugin(3)>,
L<nbdkit-python-plugin(3)>,
-L<nbdkit-ruby-plugin(3)>.
+L<nbdkit-ruby-plugin(3)>,
+L<nbdkit-tcl-plugin(3)>.
=head1 C<#define NBDKIT_API_VERSION 2>
@@ -849,14 +850,15 @@ which defines C<$(NBDKIT_PLUGINDIR)> in automake-generated Makefiles.
=head1 WRITING PLUGINS IN OTHER PROGRAMMING LANGUAGES
-You can also write nbdkit plugins in OCaml, Perl, Python or Ruby.
+You can also write nbdkit plugins in OCaml, Perl, Python, Ruby or Tcl.
Other programming languages may be offered in future.
For more information see:
L<nbdkit-ocaml-plugin(3)>,
L<nbdkit-perl-plugin(3)>,
L<nbdkit-python-plugin(3)>,
-L<nbdkit-ruby-plugin(3)>.
+L<nbdkit-ruby-plugin(3)>,
+L<nbdkit-tcl-plugin(3)>.
Plugins written in scripting languages may also be installed in
C<$plugindir>. These must be called C<nbdkit-I<name>-plugin> without
diff --git a/docs/nbdkit.pod.in b/docs/nbdkit.pod.in
index 115db3c..15196d0 100644
--- a/docs/nbdkit.pod.in
+++ b/docs/nbdkit.pod.in
@@ -978,7 +978,8 @@ L<nbdkit-filter(3)>.
L<nbdkit-ocaml-plugin(3)>,
L<nbdkit-perl-plugin(3)>,
L<nbdkit-python-plugin(3)>,
-L<nbdkit-ruby-plugin(3)>.
+L<nbdkit-ruby-plugin(3)>,
+L<nbdkit-tcl-plugin(3)>.
=head2 NBD clients
diff --git a/plugins/tcl/Makefile.am b/plugins/tcl/Makefile.am
new file mode 100644
index 0000000..618c21c
--- /dev/null
+++ b/plugins/tcl/Makefile.am
@@ -0,0 +1,68 @@
+# nbdkit
+# Copyright (C) 2018 Red Hat Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# * Neither the name of Red Hat nor the names of its contributors may be
+# used to endorse or promote products derived from this software without
+# specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+include $(top_srcdir)/common-rules.mk
+
+EXTRA_DIST = \
+ nbdkit-tcl-plugin.pod \
+ example.pl
+
+if HAVE_TCL
+
+plugin_LTLIBRARIES = nbdkit-tcl-plugin.la
+
+nbdkit_tcl_plugin_la_SOURCES = \
+ tcl.c \
+ $(top_srcdir)/include/nbdkit-plugin.h
+
+nbdkit_tcl_plugin_la_CPPFLAGS = \
+ -I$(top_srcdir)/include
+nbdkit_tcl_plugin_la_CFLAGS = \
+ $(WARNINGS_CFLAGS) \
+ $(TCL_CFLAGS)
+nbdkit_tcl_plugin_la_LDFLAGS = \
+ -module -avoid-version -shared \
+ $(TCL_LIBS)
+
+if HAVE_POD2MAN
+
+man_MANS = nbdkit-tcl-plugin.3
+CLEANFILES += $(man_MANS)
+
+nbdkit-tcl-plugin.3: nbdkit-tcl-plugin.pod
+ $(POD2MAN) $(POD2MAN_ARGS) --section=3 --name=`basename $@ .3` $< $@.t && \
+ if grep 'POD ERROR' $@.t; then rm $@.t; exit 1; fi && \
+ mv $@.t $@
+
+endif
+
+endif
diff --git a/plugins/tcl/example.tcl b/plugins/tcl/example.tcl
new file mode 100644
index 0000000..306632b
--- /dev/null
+++ b/plugins/tcl/example.tcl
@@ -0,0 +1,90 @@
+# Example Tcl plugin.
+#
+# This example can be freely used for any purpose.
+
+# Run it from the build directory like this:
+#
+# ./nbdkit -f -v tcl ./plugins/tcl/example.tcl file=disk.img
+#
+# Or run it after installing nbdkit like this:
+#
+# nbdkit -f -v tcl ./plugins/tcl/example.tcl file=disk.img
+#
+# The -f -v arguments are optional. They cause the server to stay in
+# the foreground and print debugging, which is useful when testing.
+#
+# You can connect to the server using guestfish or qemu, eg:
+#
+# guestfish --format=raw -a nbd://localhost
+# ><fs> run
+# ><fs> part-disk /dev/sda mbr
+# ><fs> mkfs ext2 /dev/sda1
+# ><fs> list-filesystems
+# ><fs> mount /dev/sda1 /
+# ><fs> [etc]
+
+# This is called from: nbdkit tcl example.tcl --dump-plugin
+proc dump_plugin {} {
+ puts "example_tcl=1"
+}
+
+# We expect a file=... parameter pointing to the file to serve.
+proc config {key value} {
+ global file
+
+ if { $key == "file" } {
+ set file $value
+ } else {
+ error "unknown parameter $key=$value"
+ }
+}
+
+# Check the file parameter was passed.
+proc config_complete {} {
+ global file
+
+ if { ![info exists file] } {
+ error "file parameter missing"
+ }
+}
+
+# Open a new client connection.
+proc plugin_open {readonly} {
+ global file
+
+ # Open the file.
+ if { $readonly } {
+ set flags "r"
+ } else {
+ set flags "r+"
+ }
+ set fh [open $file $flags]
+
+ # Stop Tcl from trying to convert to and from UTF-8.
+ fconfigure $fh -translation binary
+
+ # We can return any Tcl object as the handle. In this
+ # plugin it's convenient to return the file handle.
+ return $fh
+}
+
+# Close a client connection.
+proc plugin_close {fh} {
+ close $fh
+}
+
+proc get_size {fh} {
+ global file
+
+ return [file size $file]
+}
+
+proc pread {fh count offset} {
+ seek $fh $offset
+ return [read $fh $count]
+}
+
+proc pwrite {fh buf offset} {
+ seek $fh $offset
+ puts -nonewline $fh $buf
+}
diff --git a/plugins/tcl/nbdkit-tcl-plugin.pod b/plugins/tcl/nbdkit-tcl-plugin.pod
new file mode 100644
index 0000000..d21ab5b
--- /dev/null
+++ b/plugins/tcl/nbdkit-tcl-plugin.pod
@@ -0,0 +1,333 @@
+=encoding utf8
+
+=head1 NAME
+
+nbdkit-tcl-plugin - nbdkit Tcl plugin
+
+=head1 SYNOPSIS
+
+ nbdkit tcl /path/to/plugin.tcl [arguments...]
+
+=head1 DESCRIPTION
+
+C<nbdkit-tcl-plugin> is an embedded Tcl interpreter for
+L<nbdkit(1)>, allowing you to write nbdkit plugins in Tcl.
+
+Broadly speaking, Tcl nbdkit plugins work like C ones, so you should
+read L<nbdkit-plugin(3)> first.
+
+=head2 USING A TCL NBDKIT PLUGIN
+
+Assuming you have a Tcl script which is an nbdkit plugin, you run it
+like this:
+
+ nbdkit tcl /path/to/plugin.tcl
+
+You may have to add further C<key=value> arguments to the command
+line. Read the Tcl script to see if it requires any.
+
+=head1 WRITING A TCL NBDKIT PLUGIN
+
+For an example plugin written in Tcl, see:
+L<https://github.com/libguestfs/nbdkit/blob/master/plugins/tcl/example.tcl>
+
+To write a Tcl nbdkit plugin, you create a Tcl file which contains
+at least the following required subroutines:
+
+ proc plugin_open {readonly} {
+ # see below
+ return $h
+ }
+ proc get_size {h} {
+ # see below
+ return $size
+ }
+ proc pread {h count offset} {
+ # see below
+ return $buf
+ }
+
+Note that the subroutines must have those literal names (like
+C<plugin_open>), because the C part looks up and calls those functions
+directly. You may want to include documentation and globals (eg. for
+storing global state). Also any top-level statements are run when
+nbdkit starts up.
+
+=head2 EXECUTABLE SCRIPT
+
+If you want you can make the script executable and include a "shebang"
+at the top:
+
+ #!/usr/sbin/nbdkit tcl
+
+See also L<nbdkit(1)/Shebang scripts>.
+
+These scripts can also be installed in the C<$plugindir>. See
+L<nbdkit-plugin(3)/WRITING PLUGINS IN OTHER PROGRAMMING LANGUAGES>.
+
+=head2 EXCEPTIONS
+
+Tcl plugin methods can indicate an error by calling C<error>.
+
+=head2 BINARY DATA
+
+When writing your Tcl script, be careful to ensure that it is
+processing binary data (not Unicode). If reading and writing from
+local disk files, you should use:
+
+ fconfigure $fp -translation binary
+
+Note also that the value returned from C<pread> should convertible to
+a byte array, and the buffer passed to C<pwrite> is also a byte array.
+
+See also: L<https://wiki.tcl.tk/1180>
+
+=head2 TCL CALLBACKS
+
+This just documents the arguments to the callbacks in Tcl, and any
+way that they differ from the C callbacks. In all other respects they
+work the same way as the C callbacks, so you should go and read
+L<nbdkit-plugin(3)>.
+
+=over 4
+
+=item C<dump_plugin>
+
+(Optional)
+
+There are no arguments or return value.
+
+=item C<config>
+
+(Optional)
+
+ proc config {key value} {
+ # No return value.
+ }
+
+=item C<config_complete>
+
+(Optional)
+
+There are no arguments or return value.
+
+=item C<plugin_open>
+
+(Required)
+
+ proc plugin_open {readonly} {
+ set handle ...
+ return $handle
+ }
+
+The C<readonly> flag is a boolean.
+
+You can return any Tcl string or object as the handle. It is passed
+back to subsequent calls.
+
+=item C<plugin_close>
+
+(Optional)
+
+ proc plugin_close {h} {
+ # No return value
+ }
+
+After C<plugin_close> returns, the reference count of the handle is
+decremented in the C part, which usually means that the handle and its
+contents will be garbage collected.
+
+=item C<get_size>
+
+(Required)
+
+ proc get_size {h} {
+ set size .. the size of the disk ..
+ return $size
+ }
+
+This returns the size of the disk.
+
+=item C<can_write>
+
+(Optional)
+
+ proc can_write {h} {
+ return $bool
+ }
+
+Return a boolean indicating whether the disk is writable.
+
+=item C<can_flush>
+
+(Optional)
+
+ proc can_flush {h} {
+ return $bool
+ }
+
+Return a boolean indicating whether flush can be performed.
+
+=item C<is_rotational>
+
+(Optional)
+
+ proc is_rotational {h} {
+ return $bool
+ }
+
+Return a boolean indicating whether the disk is rotational.
+
+=item C<can_trim>
+
+(Optional)
+
+ proc can_trim {h} {
+ return $bool
+ }
+
+Return a boolean indicating whether trim/discard can be performed.
+
+=item C<pread>
+
+(Required)
+
+ proc pread {h count offset} {
+ # Construct a buffer of length $count bytes and return it.
+ return $buf
+ }
+
+The body of your C<pread> function should construct a buffer of length
+(at least) C<$count> bytes. You should read C<$count> bytes from the
+disk starting at C<$offset>.
+
+NBD only supports whole reads, so your function should try to read the
+whole region (perhaps requiring a loop). If the read fails or is
+partial, your function should call C<error>.
+
+=item C<pwrite>
+
+(Optional)
+
+ proc pwrite {h buf offset} {
+ # No return value
+ }
+
+The body of your C<pwrite> function should write the C<$buf> string to
+the disk. You should write C<$count> bytes to the disk starting at
+C<$offset>.
+
+NBD only supports whole writes, so your function should try to write
+the whole region (perhaps requiring a loop). If the write fails or is
+partial, your function should call C<error>.
+
+=item C<plugin_flush>
+
+(Optional)
+
+ proc plugin_flush {h} {
+ # No return value
+ }
+
+The body of your C<plugin_flush> function should do a L<sync(2)> or
+L<fdatasync(2)> or equivalent on the backing store.
+
+=item C<trim>
+
+(Optional)
+
+ proc trim {h count offset} {
+ # No return value
+ }
+
+The body of your C<trim> function should "punch a hole" in the backing
+store.
+
+=item C<zero>
+
+(Optional)
+
+ proc zero {h count offset may_trim} {
+ # No return value
+ }
+
+The body of your C<zero> function should ensure that C<$count> bytes
+of the disk, starting at C<$offset>, will read back as zero. If
+C<$may_trim> is true, the operation may be optimized as a trim as long
+as subsequent reads see zeroes.
+
+NBD only supports whole writes, so your function should try to write
+the whole region (perhaps requiring a loop). If the write fails or is
+partial, your function should call C<error>.
+
+=back
+
+=head2 MISSING CALLBACKS
+
+=over 4
+
+=item Missing: C<load>, C<unload>, C<name>, C<version>, C<longname>, C<description>, C<config_help>
+
+These are not yet supported.
+
+=back
+
+=head2 THREADS
+
+The thread model for Tcl callbacks currently cannot be set from Tcl.
+It is hard-coded in the C part to
+C<NBDKIT_THREAD_MODEL_SERIALIZE_ALL_REQUESTS>. This may change or be
+settable in future.
+
+=head1 SEE ALSO
+
+L<nbdkit(1)>,
+L<nbdkit-plugin(3)>.
+
+=head1 AUTHORS
+
+Richard W.M. Jones
+
+=head1 COPYRIGHT
+
+Copyright (C) 2018 Red Hat Inc.
+
+=head1 LICENSE
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+=over 4
+
+=item *
+
+Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+=item *
+
+Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+=item *
+
+Neither the name of Red Hat nor the names of its contributors may be
+used to endorse or promote products derived from this software without
+specific prior written permission.
+
+=back
+
+THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
diff --git a/plugins/tcl/tcl.c b/plugins/tcl/tcl.c
new file mode 100644
index 0000000..8b93a9b
--- /dev/null
+++ b/plugins/tcl/tcl.c
@@ -0,0 +1,553 @@
+/* nbdkit
+ * Copyright (C) 2018 Red Hat Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of Red Hat nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <assert.h>
+
+#include <tcl.h>
+
+#include <nbdkit-plugin.h>
+
+static Tcl_Interp *interp;
+static const char *script;
+
+static void
+tcl_load (void)
+{
+ //Tcl_FindExecutable ("nbdkit");
+ interp = Tcl_CreateInterp ();
+ if (Tcl_Init (interp) != TCL_OK) {
+ nbdkit_error ("cannot initialize Tcl interpreter: %s",
+ Tcl_GetStringResult (interp));
+ exit (EXIT_FAILURE);
+ }
+}
+
+static void
+tcl_unload (void)
+{
+ if (interp)
+ Tcl_DeleteInterp (interp);
+ Tcl_Finalize ();
+}
+
+/* Test if proc was defined by the Tcl code. */
+static int
+proc_defined (const char *name)
+{
+ int r;
+ Tcl_Obj *cmd;
+
+ cmd = Tcl_NewObj ();
+ Tcl_IncrRefCount (cmd);
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewStringObj ("info", -1));
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewStringObj ("procs", -1));
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewStringObj (name, -1));
+ r = Tcl_EvalObjEx (interp, cmd, TCL_EVAL_DIRECT);
+ Tcl_DecrRefCount (cmd);
+ if (r != TCL_OK) {
+ nbdkit_error ("info procs: %s", Tcl_GetStringResult (interp));
+ return 0; /* We can't return an error here, just return false. */
+ }
+
+ /* 'info procs name' returns the proc name if it exists, else empty
+ * string, so we can just check if the result is not empty.
+ */
+ return strcmp (Tcl_GetStringResult (interp), "") != 0;
+}
+
+static void
+tcl_dump_plugin (void)
+{
+ if (script && proc_defined ("dump_plugin")) {
+ int r;
+ Tcl_Obj *cmd;
+
+ cmd = Tcl_NewObj ();
+ Tcl_IncrRefCount (cmd);
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewStringObj ("dump_plugin", -1));
+ r = Tcl_EvalObjEx (interp, cmd, TCL_EVAL_DIRECT);
+ Tcl_DecrRefCount (cmd);
+ if (r != TCL_OK)
+ nbdkit_error ("dump_plugin: %s", Tcl_GetStringResult (interp));
+ }
+}
+
+static int
+tcl_config (const char *key, const char *value)
+{
+ int r;
+
+ if (!script) {
+ /* The first parameter MUST be "script". */
+ if (strcmp (key, "script") != 0) {
+ nbdkit_error ("the first parameter must be script=/path/to/script.tcl");
+ return -1;
+ }
+ script = value;
+
+ assert (interp);
+
+ /* Load the Tcl file. */
+ r = Tcl_EvalFile (interp, script);
+ if (r != TCL_OK) {
+ if (r == TCL_ERROR)
+ nbdkit_error ("could not load Tcl script: %s: line %d: %s",
+ script, Tcl_GetErrorLine (interp),
+ Tcl_GetStringResult (interp));
+ else
+ nbdkit_error ("could not load Tcl script: %s: %s",
+ script, Tcl_GetStringResult (interp));
+ return -1;
+ }
+
+ /* Minimal set of callbacks which are required (by nbdkit itself). */
+ if (!proc_defined ("plugin_open") ||
+ !proc_defined ("get_size") ||
+ !proc_defined ("pread")) {
+ nbdkit_error ("%s: one of the required callbacks 'plugin_open', 'get_size' or 'pread' is not defined by this Tcl script. nbdkit requires these callbacks.", script);
+ return -1;
+ }
+ }
+ else if (proc_defined ("config")) {
+ int r;
+ Tcl_Obj *cmd;
+
+ cmd = Tcl_NewObj ();
+ Tcl_IncrRefCount (cmd);
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewStringObj ("config", -1));
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewStringObj (key, -1));
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewStringObj (value, -1));
+ r = Tcl_EvalObjEx (interp, cmd, TCL_EVAL_DIRECT);
+ Tcl_DecrRefCount (cmd);
+ if (r != TCL_OK) {
+ nbdkit_error ("config: %s", Tcl_GetStringResult (interp));
+ return -1;
+ }
+ }
+ else {
+ /* Emulate what core nbdkit does if a config callback is NULL. */
+ nbdkit_error ("%s: this plugin does not need command line configuration",
+ script);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int
+tcl_config_complete (void)
+{
+ int r;
+ Tcl_Obj *cmd;
+
+ if (proc_defined ("config_complete")) {
+ cmd = Tcl_NewObj ();
+ Tcl_IncrRefCount (cmd);
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewStringObj ("config_complete", -1));
+ r = Tcl_EvalObjEx (interp, cmd, TCL_EVAL_DIRECT);
+ Tcl_DecrRefCount (cmd);
+ if (r != TCL_OK) {
+ nbdkit_error ("config_complete: %s", Tcl_GetStringResult (interp));
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+static void *
+tcl_open (int readonly)
+{
+ int r;
+ Tcl_Obj *cmd, *res;
+
+ cmd = Tcl_NewObj ();
+ Tcl_IncrRefCount (cmd);
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewStringObj ("plugin_open", -1));
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewBooleanObj (readonly));
+ r = Tcl_EvalObjEx (interp, cmd, TCL_EVAL_DIRECT);
+ Tcl_DecrRefCount (cmd);
+ if (r != TCL_OK) {
+ nbdkit_error ("plugin_open: %s", Tcl_GetStringResult (interp));
+ return NULL;
+ }
+
+ res = Tcl_GetObjResult (interp);
+ Tcl_IncrRefCount (res);
+ return res;
+}
+
+static void
+tcl_close (void *handle)
+{
+ int r;
+ Tcl_Obj *h = handle, *cmd;
+
+ if (proc_defined ("plugin_close")) {
+ cmd = Tcl_NewObj ();
+ Tcl_IncrRefCount (cmd);
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewStringObj ("plugin_close", -1));
+ Tcl_ListObjAppendElement (0, cmd, h);
+ r = Tcl_EvalObjEx (interp, cmd, TCL_EVAL_DIRECT);
+ Tcl_DecrRefCount (cmd);
+ if (r != TCL_OK)
+ nbdkit_error ("plugin_close: %s", Tcl_GetStringResult (interp));
+ }
+
+ /* Ensure that the handle is freed. */
+ Tcl_DecrRefCount (h);
+}
+
+static int64_t
+tcl_get_size (void *handle)
+{
+ int r;
+ Tcl_Obj *h = handle, *cmd, *res;
+ Tcl_WideInt size;
+
+ cmd = Tcl_NewObj ();
+ Tcl_IncrRefCount (cmd);
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewStringObj ("get_size", -1));
+ Tcl_ListObjAppendElement (0, cmd, h);
+ r = Tcl_EvalObjEx (interp, cmd, TCL_EVAL_DIRECT);
+ Tcl_DecrRefCount (cmd);
+ if (r != TCL_OK) {
+ nbdkit_error ("get_size: %s", Tcl_GetStringResult (interp));
+ return -1;
+ }
+
+ res = Tcl_GetObjResult (interp);
+ if (Tcl_GetWideIntFromObj (interp, res, &size) != TCL_OK) {
+ nbdkit_error ("get_size: Tcl_GetWideIntFromObj: %s",
+ Tcl_GetStringResult (interp));
+ return -1;
+ }
+ return size;
+}
+
+static int
+tcl_pread (void *handle, void *buf, uint32_t count, uint64_t offset)
+{
+ int r;
+ Tcl_Obj *h = handle, *cmd, *res;
+ unsigned char *res_bin;
+ int res_len;
+
+ cmd = Tcl_NewObj ();
+ Tcl_IncrRefCount (cmd);
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewStringObj ("pread", -1));
+ Tcl_ListObjAppendElement (0, cmd, h);
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewIntObj (count));
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewWideIntObj (offset));
+ r = Tcl_EvalObjEx (interp, cmd, TCL_EVAL_DIRECT);
+ Tcl_DecrRefCount (cmd);
+ if (r != TCL_OK) {
+ nbdkit_error ("pread: %s", Tcl_GetStringResult (interp));
+ return -1;
+ }
+
+ res = Tcl_GetObjResult (interp);
+ res_bin = Tcl_GetByteArrayFromObj (res, &res_len);
+ if (res_len < count) {
+ nbdkit_error ("pread: buffer returned from pread is too small");
+ return -1;
+ }
+
+ memcpy (buf, res_bin, count);
+ return 0;
+}
+
+static int
+tcl_pwrite (void *handle, const void *buf, uint32_t count, uint64_t offset)
+{
+ if (proc_defined ("pwrite")) {
+ int r;
+ Tcl_Obj *h = handle, *cmd;
+
+ cmd = Tcl_NewObj ();
+ Tcl_IncrRefCount (cmd);
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewStringObj ("pwrite", -1));
+ Tcl_ListObjAppendElement (0, cmd, h);
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewByteArrayObj (buf, count));
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewWideIntObj (offset));
+ r = Tcl_EvalObjEx (interp, cmd, TCL_EVAL_DIRECT);
+ Tcl_DecrRefCount (cmd);
+ if (r != TCL_OK) {
+ nbdkit_error ("pwrite: %s", Tcl_GetStringResult (interp));
+ return -1;
+ }
+ return 0;
+ }
+
+ nbdkit_error ("pwrite not implemented");
+ return -1;
+}
+
+static int
+tcl_can_write (void *handle)
+{
+ if (proc_defined ("can_write")) {
+ int r;
+ Tcl_Obj *h = handle, *cmd, *res;
+
+ cmd = Tcl_NewObj ();
+ Tcl_IncrRefCount (cmd);
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewStringObj ("can_write", -1));
+ Tcl_ListObjAppendElement (0, cmd, h);
+ r = Tcl_EvalObjEx (interp, cmd, TCL_EVAL_DIRECT);
+ Tcl_DecrRefCount (cmd);
+ if (r != TCL_OK) {
+ nbdkit_error ("can_write: %s", Tcl_GetStringResult (interp));
+ return -1;
+ }
+ res = Tcl_GetObjResult (interp);
+ Tcl_GetBooleanFromObj (interp, res, &r);
+ return r;
+ }
+ /* No can_write callback, but there's a pwrite callback defined, so
+ * return 1. (In C modules, nbdkit would do this).
+ */
+ else if (proc_defined ("pwrite"))
+ return 1;
+ else
+ return 0;
+}
+
+static int
+tcl_can_flush (void *handle)
+{
+ if (proc_defined ("can_flush")) {
+ int r;
+ Tcl_Obj *h = handle, *cmd, *res;
+
+ cmd = Tcl_NewObj ();
+ Tcl_IncrRefCount (cmd);
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewStringObj ("can_flush", -1));
+ Tcl_ListObjAppendElement (0, cmd, h);
+ r = Tcl_EvalObjEx (interp, cmd, TCL_EVAL_DIRECT);
+ Tcl_DecrRefCount (cmd);
+ if (r != TCL_OK) {
+ nbdkit_error ("can_flush: %s", Tcl_GetStringResult (interp));
+ return -1;
+ }
+ res = Tcl_GetObjResult (interp);
+ Tcl_GetBooleanFromObj (interp, res, &r);
+ return r;
+ }
+ /* No can_flush callback, but there's a plugin_flush callback
+ * defined, so return 1. (In C modules, nbdkit would do this).
+ */
+ else if (proc_defined ("plugin_flush"))
+ return 1;
+ else
+ return 0;
+}
+
+static int
+tcl_can_trim (void *handle)
+{
+ if (proc_defined ("can_trim")) {
+ int r;
+ Tcl_Obj *h = handle, *cmd, *res;
+
+ cmd = Tcl_NewObj ();
+ Tcl_IncrRefCount (cmd);
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewStringObj ("can_trim", -1));
+ Tcl_ListObjAppendElement (0, cmd, h);
+ r = Tcl_EvalObjEx (interp, cmd, TCL_EVAL_DIRECT);
+ Tcl_DecrRefCount (cmd);
+ if (r != TCL_OK) {
+ nbdkit_error ("can_trim: %s", Tcl_GetStringResult (interp));
+ return -1;
+ }
+ res = Tcl_GetObjResult (interp);
+ Tcl_GetBooleanFromObj (interp, res, &r);
+ return r;
+ }
+ /* No can_trim callback, but there's a trim callback defined, so
+ * return 1. (In C modules, nbdkit would do this).
+ */
+ else if (proc_defined ("trim"))
+ return 1;
+ else
+ return 0;
+}
+
+static int
+tcl_zero (void *handle, uint32_t count, uint64_t offset, int may_trim)
+{
+ if (proc_defined ("zero")) {
+ int r;
+ Tcl_Obj *h = handle, *cmd, *res;
+
+ cmd = Tcl_NewObj ();
+ Tcl_IncrRefCount (cmd);
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewStringObj ("can_zero", -1));
+ Tcl_ListObjAppendElement (0, cmd, h);
+ r = Tcl_EvalObjEx (interp, cmd, TCL_EVAL_DIRECT);
+ Tcl_DecrRefCount (cmd);
+ if (r != TCL_OK) {
+ nbdkit_error ("can_zero: %s", Tcl_GetStringResult (interp));
+ return -1;
+ }
+ res = Tcl_GetObjResult (interp);
+ Tcl_GetBooleanFromObj (interp, res, &r);
+ return r;
+ }
+
+ nbdkit_debug ("zero falling back to pwrite");
+ nbdkit_set_error (EOPNOTSUPP);
+ return -1;
+}
+
+static int
+tcl_is_rotational (void *handle)
+{
+ if (proc_defined ("is_rotational")) {
+ int r;
+ Tcl_Obj *h = handle, *cmd, *res;
+
+ cmd = Tcl_NewObj ();
+ Tcl_IncrRefCount (cmd);
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewStringObj ("is_rotational", -1));
+ Tcl_ListObjAppendElement (0, cmd, h);
+ r = Tcl_EvalObjEx (interp, cmd, TCL_EVAL_DIRECT);
+ Tcl_DecrRefCount (cmd);
+ if (r != TCL_OK) {
+ nbdkit_error ("is_rotational: %s", Tcl_GetStringResult (interp));
+ return -1;
+ }
+ res = Tcl_GetObjResult (interp);
+ Tcl_GetBooleanFromObj (interp, res, &r);
+ return r;
+ }
+ else
+ return 0;
+}
+
+static int
+tcl_flush (void *handle)
+{
+ if (proc_defined ("plugin_flush")) {
+ int r;
+ Tcl_Obj *h = handle, *cmd;
+
+ cmd = Tcl_NewObj ();
+ Tcl_IncrRefCount (cmd);
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewStringObj ("plugin_flush", -1));
+ Tcl_ListObjAppendElement (0, cmd, h);
+ r = Tcl_EvalObjEx (interp, cmd, TCL_EVAL_DIRECT);
+ Tcl_DecrRefCount (cmd);
+ if (r != TCL_OK) {
+ nbdkit_error ("plugin_flush: %s", Tcl_GetStringResult (interp));
+ return -1;
+ }
+ return 0;
+ }
+
+ /* Ignore lack of flush callback, although probably nbdkit will
+ * never call this since .can_flush returns false.
+ */
+ return 0;
+}
+
+static int
+tcl_trim (void *handle, uint32_t count, uint64_t offset)
+{
+ if (proc_defined ("trim")) {
+ int r;
+ Tcl_Obj *h = handle, *cmd;
+
+ cmd = Tcl_NewObj ();
+ Tcl_IncrRefCount (cmd);
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewStringObj ("trim", -1));
+ Tcl_ListObjAppendElement (0, cmd, h);
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewIntObj (count));
+ Tcl_ListObjAppendElement (0, cmd, Tcl_NewWideIntObj (offset));
+ r = Tcl_EvalObjEx (interp, cmd, TCL_EVAL_DIRECT);
+ Tcl_DecrRefCount (cmd);
+ if (r != TCL_OK) {
+ nbdkit_error ("trim: %s", Tcl_GetStringResult (interp));
+ return -1;
+ }
+ return 0;
+ }
+
+ /* Ignore lack of trim callback, although probably nbdkit will never
+ * call this since .can_trim returns false.
+ */
+ return 0;
+}
+
+#define tcl_config_help \
+ "script=<FILENAME> (required) The Tcl script to run.\n" \
+ "[other arguments may be used by the plugin that you load]"
+
+#define THREAD_MODEL NBDKIT_THREAD_MODEL_SERIALIZE_ALL_REQUESTS
+
+static struct nbdkit_plugin plugin = {
+ .name = "tcl",
+ .version = PACKAGE_VERSION,
+
+ .load = tcl_load,
+ .unload = tcl_unload,
+ .dump_plugin = tcl_dump_plugin,
+
+ .config = tcl_config,
+ .config_complete = tcl_config_complete,
+ .config_help = tcl_config_help,
+
+ .open = tcl_open,
+ .close = tcl_close,
+
+ .get_size = tcl_get_size,
+ .can_write = tcl_can_write,
+ .can_flush = tcl_can_flush,
+ .is_rotational = tcl_is_rotational,
+ .can_trim = tcl_can_trim,
+
+ .pread = tcl_pread,
+ .pwrite = tcl_pwrite,
+ .flush = tcl_flush,
+ .trim = tcl_trim,
+ .zero = tcl_zero,
+};
+
+NBDKIT_REGISTER_PLUGIN(plugin)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a7a31b9..d42daeb 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -461,6 +461,19 @@ test_ruby_LDADD = libtest.la $(LIBGUESTFS_LIBS)
endif HAVE_RUBY
+# Tcl plugin test.
+if HAVE_TCL
+
+LIBGUESTFS_TESTS += test-tcl
+
+test_tcl_SOURCES = test-lang-plugins.c test.h
+test_tcl_CFLAGS = \
+ -DLANG='"tcl"' -DSCRIPT='"test.tcl"' \
+ $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
+test_tcl_LDADD = libtest.la $(LIBGUESTFS_LIBS)
+
+endif HAVE_TCL
+
#----------------------------------------------------------------------
# Tests of filters.
diff --git a/tests/test-dump-plugin.sh b/tests/test-dump-plugin.sh
index 1104727..6f94eab 100755
--- a/tests/test-dump-plugin.sh
+++ b/tests/test-dump-plugin.sh
@@ -64,7 +64,7 @@ for p in $plugins; do
# VDDK won't run without special environment variables
# being set, so ignore it.
;;
- perl-valgrind | python-valgrind | ruby-valgrind | \
+ perl-valgrind | python-valgrind | ruby-valgrind | tcl-valgrind | \
example4-valgrind | tar-valgrind)
# Plugins written in scripting languages can't run under valgrind.
;;
diff --git a/tests/test-lang-plugins.c b/tests/test-lang-plugins.c
index fc3cbef..92a7ec2 100644
--- a/tests/test-lang-plugins.c
+++ b/tests/test-lang-plugins.c
@@ -56,7 +56,8 @@ main (int argc, char *argv[])
*/
if (getenv ("NBDKIT_VALGRIND") != NULL &&
(strcmp (LANG, "python") == 0 ||
- strcmp (LANG, "ruby") == 0)) {
+ strcmp (LANG, "ruby") == 0 ||
+ strcmp (LANG, "tcl") == 0)) {
fprintf (stderr, "%s test skipped under valgrind.\n", LANG);
exit (77); /* Tells automake to skip the test. */
}
diff --git a/tests/test.tcl b/tests/test.tcl
new file mode 100644
index 0000000..57e8d15
--- /dev/null
+++ b/tests/test.tcl
@@ -0,0 +1,28 @@
+# XXX This actually creates a Unicode (UCS-2) array. It's also rather
+# slow to run. It's possible we should be using a list instead.
+set disk [string repeat "\u0000" [expr 1024*1024]]
+
+proc plugin_open {readonly} {
+ return 1
+}
+
+proc get_size {h} {
+ global disk
+
+ return [string length $disk]
+}
+
+proc pread {h count offset} {
+ global disk
+
+ set last [expr $offset+$count-1]
+ return [string range $disk $offset $last]
+}
+
+proc pwrite {h buf offset} {
+ global disk
+
+ set count [string length $buf]
+ set last [expr $offset+$count-1]
+ set disk [string replace $disk $offset $last $buf]
+}
--
2.17.1
6 years, 5 months
[PATCH nbdkit] valgrind: Don't call dlclose when running under valgrind.
by Richard W.M. Jones
When valgrinding plugins, the following sequence can happen:
plugin_free
-> dlclose
-> unloads the plugin and symbol table
exit
-> valgrind prints failures
(the same applies to filters). When valgrind is printing the
failures, it looks up the addresses in the symbol table, but that has
been unloaded already so all you see are "???", resulting in useless
messages like:
==14189== 49,152 bytes in 3 blocks are possibly lost in loss record 69 of 69
==14189== at 0x4C2EBAB: malloc (vg_replace_malloc.c:299)
==14189== by 0x7928C79: ???
==14189== by 0x7928FEE: ???
==14189== by 0x784662B: ???
==14189== by 0x79329BA: ???
==14189== by 0x78BFAC0: ???
==14189== by 0x78C59C5: ???
==14189== by 0x7841C4B: ???
==14189== by 0x75FA074: ???
==14189== by 0x40A512: plugin_register (plugins.c:749)
==14189== by 0x404436: open_plugin_so (main.c:740)
==14189== by 0x404436: main (main.c:565)
We can improve this using the valgrind macro RUNNING_ON_VALGRIND to
prevent calling dlclose(3).
I have made this opt-in since we don't generally want to make
production nbdkit binaries which rely on probing valgrind. Developers
have to enable it using ./configure --enable-valgrind. I also took
this opportunity to improve developer documentation.
With this change you should see full stack traces from plugins, eg:
==2441== 32,768 bytes in 2 blocks are possibly lost in loss record 73 of 78
==2441== at 0x4C2EBAB: malloc (vg_replace_malloc.c:299)
==2441== by 0x7928C79: GetBlocks (tclThreadAlloc.c:1044)
==2441== by 0x7928C79: TclpAlloc (tclThreadAlloc.c:358)
==2441== by 0x7928FEE: TclpRealloc (tclThreadAlloc.c:514)
==2441== by 0x784662B: Tcl_Realloc (tclCkalloc.c:1145)
==2441== by 0x79329BA: Tcl_DStringSetLength (tclUtil.c:2819)
==2441== by 0x78BFAC0: Tcl_ExternalToUtfDString (tclEncoding.c:1155)
==2441== by 0x78C59C5: TclSetupEnv (tclEnv.c:124)
==2441== by 0x7841C4B: Tcl_CreateInterp (tclBasic.c:907)
==2441== by 0x75FA074: tcl_load (tcl.c:54)
==2441== by 0x40A5E2: plugin_register (plugins.c:750)
==2441== by 0x404436: open_plugin_so (main.c:740)
==2441== by 0x404436: main (main.c:565)
---
README | 15 ++++++++++++---
configure.ac | 17 +++++++++++++++++
src/Makefile.am | 3 ++-
src/filters.c | 3 ++-
src/internal.h | 8 ++++++++
src/plugins.c | 3 ++-
6 files changed, 43 insertions(+), 6 deletions(-)
diff --git a/README b/README
index 29e16c3..e51b564 100644
--- a/README
+++ b/README
@@ -105,7 +105,7 @@ To run the test suite:
To test for memory leaks ('make check-valgrind'):
- - valgrind
+ - valgrind program and development headers
For non-essential enhancements to the test suite:
@@ -121,7 +121,6 @@ After installing any dependencies:
./configure ./configure
make make
make check make check
- make check-valgrind make check-valgrind
To run nbdkit from the source directory, use the top level ./nbdkit
script. It will run nbdkit and plugins from the locally compiled
@@ -157,8 +156,18 @@ nbdkit + plugins as a captive process, and tests them using
libguestfs. If there is a failure, look at the corresponding
tests/*.log file for debug information.
-You can run the tests under valgrind, if it is available, using:
+Developers
+----------
+Install the valgrind program and development headers.
+
+Use:
+
+ ./configure --enable-gcc-warnings --enable-valgrind
+
+When testing use:
+
+ make check
make check-valgrind
Packager information
diff --git a/configure.ac b/configure.ac
index 25851b1..16e3250 100644
--- a/configure.ac
+++ b/configure.ac
@@ -166,6 +166,23 @@ AS_IF([test "$GNUTLS_LIBS" != ""],[
dnl Check for valgrind.
AC_CHECK_PROG([VALGRIND],[valgrind],[valgrind],[no])
+dnl If valgrind headers are available (optional).
+dnl Since this is only useful for developers, you have to enable
+dnl it explicitly using --enable-valgrind.
+AC_ARG_ENABLE([valgrind],
+ AS_HELP_STRING([--enable-valgrind], [enable Valgrind extensions, for developers]),
+ [enable_valgrind=yes],
+ [enable_valgrind=no])
+AS_IF([test "x$enable_valgrind" = "xyes"],[
+ PKG_CHECK_MODULES([VALGRIND], [valgrind], [
+ AC_SUBST([VALGRIND_CFLAGS])
+ AC_SUBST([VALGRIND_LIBS])
+ AC_DEFINE([HAVE_VALGRIND],[1],[Valgrind headers found at compile time])
+ ],[
+ AC_MSG_ERROR([--enable-valgrind given, but Valgrind headers are not available])
+ ])
+])
+
dnl Bash completion.
PKG_CHECK_MODULES([BASH_COMPLETION], [bash-completion >= 2.0], [
bash_completion=yes
diff --git a/src/Makefile.am b/src/Makefile.am
index 7ead75c..915efe4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -63,7 +63,8 @@ nbdkit_CPPFLAGS = \
nbdkit_CFLAGS = \
-pthread \
$(WARNINGS_CFLAGS) \
- $(GNUTLS_CFLAGS)
+ $(GNUTLS_CFLAGS) \
+ $(VALGRIND_CFLAGS)
nbdkit_LDADD = \
$(GNUTLS_LIBS) \
-ldl
diff --git a/src/filters.c b/src/filters.c
index 3d2c07e..18948bc 100644
--- a/src/filters.c
+++ b/src/filters.c
@@ -80,7 +80,8 @@ filter_free (struct backend *b)
if (f->filter.unload)
f->filter.unload ();
- dlclose (f->dl);
+ if (DO_DLCLOSE)
+ dlclose (f->dl);
free (f->filename);
unlock_unload ();
diff --git a/src/internal.h b/src/internal.h
index ec19841..96a68f2 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -94,6 +94,14 @@
# endif
#endif
+#if HAVE_VALGRIND
+# include <valgrind.h>
+/* http://valgrind.org/docs/manual/faq.html#faq.unhelpful */
+# define DO_DLCLOSE !RUNNING_ON_VALGRIND
+#else
+# define DO_DLCLOSE 1
+#endif
+
#define container_of(ptr, type, member) ({ \
const typeof (((type *) 0)->member) *__mptr = (ptr); \
(type *) ((char *) __mptr - offsetof(type, member)); \
diff --git a/src/plugins.c b/src/plugins.c
index 23223b3..a56ad79 100644
--- a/src/plugins.c
+++ b/src/plugins.c
@@ -73,7 +73,8 @@ plugin_free (struct backend *b)
if (p->plugin.unload)
p->plugin.unload ();
- dlclose (p->dl);
+ if (DO_DLCLOSE)
+ dlclose (p->dl);
free (p->filename);
unlock_unload ();
--
2.17.1
6 years, 5 months
ANNOUNCE: nbdkit 1.4.0 - an NBD server toolkit with stable plugin ABI and permissive license
by Richard W.M. Jones
NBD is a protocol for accessing Block Devices (hard disks and
disk-like things) over a Network.
'nbdkit' is a toolkit for creating NBD servers.
The key features are:
* Multithreaded NBD server written in C with good performance.
* Minimal dependencies for the basic server.
* Liberal license (BSD) allows nbdkit to be linked to proprietary
libraries or included in proprietary code.
* Well-documented, simple plugin API with a stable ABI guarantee.
Lets you export "unconventional" block devices easily.
* You can write plugins in C, Perl, Python, OCaml, Ruby or [new!] Tcl.
I'm pleased to announce the release of the new stable branch 1.4.
Download it here: http://download.libguestfs.org/nbdkit/1.4-stable/
There are many new features since the previous stable branch (1.2):
* You can write plugins in Tcl.
* Other new plugins: ext2, random, zero.
* New filters: blocksize, fua, log, nozero,
* Bash tab completion of nbdkit commands.
* TLS Pre-Shared Keys (PSK) authentication.
* We now default to the newstyle protocol, use -o to select oldstyle.
* On-demand ramping of thread pool.
* TRIM support in the file plugin.
* Reworked error handling.
* New can_zero, can_fua methods and better handling of FUA.
* New nbdkit_realpath function.
* nbdkit_parse_size rewritten.
* Better handling of shutdown path to ensure plugins can do long cleanups.
* New PKG_CHECK_VAR variables.
* Regression test for IPv6 connections.
* Of course numerous smaller bug fixes and improvements.
Thanks in particular to Eric Blake and Pino Toscano.
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/
6 years, 5 months