b5f8430a27
resolves: rhbz#2011709 Includes these important commits: plugins/python: Fix extents() count format string tests: Add configure --disable-libguestfs-tests flag tests: Use mke2fs -d to create ext4 test image Use new --disable-libguestfs-tests on non-guestfs arches.
339 lines
9.7 KiB
Diff
339 lines
9.7 KiB
Diff
From 4aa2334a7c986cf062b1a2d792c056165e8e3b59 Mon Sep 17 00:00:00 2001
|
|
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
Date: Sat, 30 Oct 2021 08:27:39 +0100
|
|
Subject: [PATCH] vddk: Move config, debug/error and utility functions around
|
|
|
|
Move the functions so they are nearer to where they are used.
|
|
Introduce a utils.c file for utility functions.
|
|
|
|
This is just code rearrangement with no other effects.
|
|
|
|
(cherry picked from commit c59be086210a06688b9195e0b91f8603a668654a)
|
|
---
|
|
plugins/vddk/Makefile.am | 1 +
|
|
plugins/vddk/utils.c | 51 ++++++++++
|
|
plugins/vddk/vddk.c | 201 +++++++++++++++++++--------------------
|
|
plugins/vddk/vddk.h | 3 +
|
|
4 files changed, 151 insertions(+), 105 deletions(-)
|
|
create mode 100644 plugins/vddk/utils.c
|
|
|
|
diff --git a/plugins/vddk/Makefile.am b/plugins/vddk/Makefile.am
|
|
index f8382fc9..02113da0 100644
|
|
--- a/plugins/vddk/Makefile.am
|
|
+++ b/plugins/vddk/Makefile.am
|
|
@@ -47,6 +47,7 @@ nbdkit_vddk_plugin_la_SOURCES = \
|
|
vddk.h \
|
|
reexec.c \
|
|
stats.c \
|
|
+ utils.c \
|
|
vddk-structs.h \
|
|
vddk-stubs.h \
|
|
worker.c \
|
|
diff --git a/plugins/vddk/utils.c b/plugins/vddk/utils.c
|
|
new file mode 100644
|
|
index 00000000..f0c19950
|
|
--- /dev/null
|
|
+++ b/plugins/vddk/utils.c
|
|
@@ -0,0 +1,51 @@
|
|
+/* nbdkit
|
|
+ * Copyright (C) 2013-2021 Red Hat Inc.
|
|
+ *
|
|
+ * 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>
|
|
+
|
|
+#define NBDKIT_API_VERSION 2
|
|
+#include <nbdkit-plugin.h>
|
|
+
|
|
+#include "vddk.h"
|
|
+
|
|
+void
|
|
+trim (char *str)
|
|
+{
|
|
+ size_t len = strlen (str);
|
|
+
|
|
+ if (len > 0 && str[len-1] == '\n')
|
|
+ str[len-1] = '\0';
|
|
+}
|
|
diff --git a/plugins/vddk/vddk.c b/plugins/vddk/vddk.c
|
|
index 184f1a9c..31e5e23b 100644
|
|
--- a/plugins/vddk/vddk.c
|
|
+++ b/plugins/vddk/vddk.c
|
|
@@ -114,61 +114,6 @@ vddk_unload (void)
|
|
free (password);
|
|
}
|
|
|
|
-static void
|
|
-trim (char *str)
|
|
-{
|
|
- size_t len = strlen (str);
|
|
-
|
|
- if (len > 0 && str[len-1] == '\n')
|
|
- str[len-1] = '\0';
|
|
-}
|
|
-
|
|
-/* Turn log messages from the library into nbdkit_debug. */
|
|
-static void
|
|
-debug_function (const char *fs, va_list args)
|
|
-{
|
|
- CLEANUP_FREE char *str = NULL;
|
|
-
|
|
- if (vasprintf (&str, fs, args) == -1) {
|
|
- nbdkit_debug ("lost debug message: %s", fs);
|
|
- return;
|
|
- }
|
|
-
|
|
- trim (str);
|
|
-
|
|
- nbdkit_debug ("%s", str);
|
|
-}
|
|
-
|
|
-/* Turn error messages from the library into nbdkit_error. */
|
|
-static void
|
|
-error_function (const char *fs, va_list args)
|
|
-{
|
|
- CLEANUP_FREE char *str = NULL;
|
|
-
|
|
- /* If the thread-local error_suppression flag is non-zero then we
|
|
- * will suppress error messages from VDDK in this thread.
|
|
- */
|
|
- if (error_suppression) return;
|
|
-
|
|
- if (vasprintf (&str, fs, args) == -1) {
|
|
- nbdkit_error ("lost error message: %s", fs);
|
|
- return;
|
|
- }
|
|
-
|
|
- trim (str);
|
|
-
|
|
- /* VDDK 7 added a useless error message about their "phone home"
|
|
- * system called CEIP which only panics users. Demote it to a debug
|
|
- * statement. https://bugzilla.redhat.com/show_bug.cgi?id=1834267
|
|
- */
|
|
- if (strstr (str, "Get CEIP status failed") != NULL) {
|
|
- nbdkit_debug ("%s", str);
|
|
- return;
|
|
- }
|
|
-
|
|
- nbdkit_error ("%s", str);
|
|
-}
|
|
-
|
|
/* Configuration. */
|
|
static int
|
|
vddk_config (const char *key, const char *value)
|
|
@@ -282,6 +227,56 @@ vddk_config (const char *key, const char *value)
|
|
return 0;
|
|
}
|
|
|
|
+static int
|
|
+vddk_config_complete (void)
|
|
+{
|
|
+ if (filename == NULL) {
|
|
+ nbdkit_error ("you must supply the file=<FILENAME> parameter "
|
|
+ "after the plugin name on the command line");
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
+ /* For remote connections, check all the parameters have been
|
|
+ * passed. Note that VDDK will segfault if parameters that it
|
|
+ * expects are NULL (and there's no real way to tell what parameters
|
|
+ * it is expecting). This implements the same test that the VDDK
|
|
+ * sample program does.
|
|
+ */
|
|
+ is_remote =
|
|
+ vmx_spec ||
|
|
+ server_name ||
|
|
+ username ||
|
|
+ password ||
|
|
+ cookie ||
|
|
+ thumb_print ||
|
|
+ port ||
|
|
+ nfc_host_port;
|
|
+
|
|
+ if (is_remote) {
|
|
+#define missing(test, param) \
|
|
+ if (test) { \
|
|
+ nbdkit_error ("remote connection requested, missing parameter: %s", \
|
|
+ param); \
|
|
+ return -1; \
|
|
+ }
|
|
+ missing (!server_name, "server");
|
|
+ missing (!username, "user");
|
|
+ missing (!password, "password");
|
|
+ missing (!vmx_spec, "vm");
|
|
+#undef missing
|
|
+ }
|
|
+
|
|
+ /* Restore original LD_LIBRARY_PATH after reexec. */
|
|
+ if (restore_ld_library_path () == -1)
|
|
+ return -1;
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+#define vddk_config_help \
|
|
+ "[file=]<FILENAME> (required) The filename (eg. VMDK file) to serve.\n" \
|
|
+ "Many optional parameters are supported, see nbdkit-vddk-plugin(1)."
|
|
+
|
|
static void
|
|
missing_required_symbol (const char *fn)
|
|
{
|
|
@@ -378,56 +373,6 @@ load_library (bool load_error_is_fatal)
|
|
#undef OPTIONAL_STUB
|
|
}
|
|
|
|
-static int
|
|
-vddk_config_complete (void)
|
|
-{
|
|
- if (filename == NULL) {
|
|
- nbdkit_error ("you must supply the file=<FILENAME> parameter "
|
|
- "after the plugin name on the command line");
|
|
- return -1;
|
|
- }
|
|
-
|
|
- /* For remote connections, check all the parameters have been
|
|
- * passed. Note that VDDK will segfault if parameters that it
|
|
- * expects are NULL (and there's no real way to tell what parameters
|
|
- * it is expecting). This implements the same test that the VDDK
|
|
- * sample program does.
|
|
- */
|
|
- is_remote =
|
|
- vmx_spec ||
|
|
- server_name ||
|
|
- username ||
|
|
- password ||
|
|
- cookie ||
|
|
- thumb_print ||
|
|
- port ||
|
|
- nfc_host_port;
|
|
-
|
|
- if (is_remote) {
|
|
-#define missing(test, param) \
|
|
- if (test) { \
|
|
- nbdkit_error ("remote connection requested, missing parameter: %s", \
|
|
- param); \
|
|
- return -1; \
|
|
- }
|
|
- missing (!server_name, "server");
|
|
- missing (!username, "user");
|
|
- missing (!password, "password");
|
|
- missing (!vmx_spec, "vm");
|
|
-#undef missing
|
|
- }
|
|
-
|
|
- /* Restore original LD_LIBRARY_PATH after reexec. */
|
|
- if (restore_ld_library_path () == -1)
|
|
- return -1;
|
|
-
|
|
- return 0;
|
|
-}
|
|
-
|
|
-#define vddk_config_help \
|
|
- "[file=]<FILENAME> (required) The filename (eg. VMDK file) to serve.\n" \
|
|
- "Many optional parameters are supported, see nbdkit-vddk-plugin(1)."
|
|
-
|
|
static int
|
|
vddk_get_ready (void)
|
|
{
|
|
@@ -435,6 +380,52 @@ vddk_get_ready (void)
|
|
return 0;
|
|
}
|
|
|
|
+/* Turn log messages from the library into nbdkit_debug. */
|
|
+static void
|
|
+debug_function (const char *fs, va_list args)
|
|
+{
|
|
+ CLEANUP_FREE char *str = NULL;
|
|
+
|
|
+ if (vasprintf (&str, fs, args) == -1) {
|
|
+ nbdkit_debug ("lost debug message: %s", fs);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ trim (str);
|
|
+
|
|
+ nbdkit_debug ("%s", str);
|
|
+}
|
|
+
|
|
+/* Turn error messages from the library into nbdkit_error. */
|
|
+static void
|
|
+error_function (const char *fs, va_list args)
|
|
+{
|
|
+ CLEANUP_FREE char *str = NULL;
|
|
+
|
|
+ /* If the thread-local error_suppression flag is non-zero then we
|
|
+ * will suppress error messages from VDDK in this thread.
|
|
+ */
|
|
+ if (error_suppression) return;
|
|
+
|
|
+ if (vasprintf (&str, fs, args) == -1) {
|
|
+ nbdkit_error ("lost error message: %s", fs);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ trim (str);
|
|
+
|
|
+ /* VDDK 7 added a useless error message about their "phone home"
|
|
+ * system called CEIP which only panics users. Demote it to a debug
|
|
+ * statement. https://bugzilla.redhat.com/show_bug.cgi?id=1834267
|
|
+ */
|
|
+ if (strstr (str, "Get CEIP status failed") != NULL) {
|
|
+ nbdkit_debug ("%s", str);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ nbdkit_error ("%s", str);
|
|
+}
|
|
+
|
|
/* Defer VDDK initialization until after fork because it is known to
|
|
* create background threads from VixDiskLib_InitEx. Unfortunately
|
|
* error reporting from this callback is difficult, but we have
|
|
diff --git a/plugins/vddk/vddk.h b/plugins/vddk/vddk.h
|
|
index 0e3dd79e..d99b6f4b 100644
|
|
--- a/plugins/vddk/vddk.h
|
|
+++ b/plugins/vddk/vddk.h
|
|
@@ -183,6 +183,9 @@ extern pthread_mutex_t stats_lock;
|
|
#undef OPTIONAL_STUB
|
|
extern void display_stats (void);
|
|
|
|
+/* utils.c */
|
|
+extern void trim (char *str);
|
|
+
|
|
/* worker.c */
|
|
extern const char *command_type_string (enum command_type type);
|
|
extern int send_command_and_wait (struct vddk_handle *h, struct command *cmd);
|
|
--
|
|
2.31.1
|
|
|