libguestfs preview for RHEL 7.4
by Richard W.M. Jones
With the release of RHEL 7.3 happening today, fixing 88 reported bugs
in libguestfs and virt-v2v, and countless other ones, it's time to
look ahead to RHEL 7.4.
Again we intend to rebase libguestfs, virt-v2v and virt-p2v:
https://bugzilla.redhat.com/show_bug.cgi?id=1359086
1359086 NEW Rebase libguestfs in RHEL 7.4
To help with testing I have set up a preview repository here:
http://people.redhat.com/~rjones/libguestfs-RHEL-7.4-preview/
As always:
(1) THE PACKAGES ARE NOT SUPPORTED! Do not contact Red Hat Support
about these packages. However you are welcome to file bugs or send
comments to <libguestfs(a)redhat.com>. The link for filing bugs is:
https://bugzilla.redhat.com/enter_bug.cgi?product=Red%20Hat%20Enterprise%...
(2) These packages should work on top of RHEL 7.3 or CentOS 7.3.
(3) To install the packages you should create a yum repo file like the
one below, and then use yum commands as normal:
$ cat /etc/yum.repos.d/libguestfs-RHEL-7.4-preview.repo
[libguestfs-RHEL-7.4-preview]
name=libguestfs RHEL 7.4 preview
baseurl=http://people.redhat.com/~rjones/libguestfs-RHEL-7.4-preview/
enabled=1
gpgcheck=0
Notable changes in packaging:
- The 'virt-v2v' package now only includes virt-v2v, not virt-p2v.
- To build your own virt-p2v bootable USB key, install 'virt-p2v-maker'.
- virt-v2v installs Windows virtio drivers using a new technique
which tries to make the minimal possible changes to the Windows
registry. This may create exciting new bugs, so I'm particularly
interested in further testing in this area.
- There is currently a bogus dependency on 'kernel-rt' which
shouldn't be there ... under investigation.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html
7 years, 8 months
ntfs-3g data deduplication support in guestmount for creating file based back-ups on visualization platform
by Jelle de Jong
Hello everybody,
I am using libguestfs-tools version 1.28.1 in a bunch of bash scripts to
make back-ups of the files on a visualisation platform.
I been trying to get read access to ntfs volumes with data deduplication
working.
The ntfs-3g guys developed some support and I have this working when
using the commands our back-up servers.
However when using the guestmount tool the read suport foor dedub is gone.
See this email for all the commands I use (working mount -t ntfs and
non-working guestmount commands).
https://sourceforge.net/p/ntfs-3g/mailman/message/35595392/
How can I see what version of ntfs-3g is used in guestmount and if it is
using the /usr/lib/x86_64-linux-gnu/ntfs-3g/ntfs-plugin-80000013.so
plugin that is on my back-up server?
Thank you in advance!
Kind regards,
Jelle de Jong
7 years, 9 months
[PATCH v6 0/3] Import directly from OVA tar archive if possible
by Tomáš Golembiovský
v6:
- just rebase
v5:
- rebase, patches 1,3,5 were merged
- 1/3: we still need to discuss whether to detect compressed discs
- 2/3:
- renamed argument noempty to keep_empty
- tests were not run
- 3/3:
- using JSON module to generate JSON (as suggested by Pino)
- all the other comments raised by Pino
v4:
- rebase to more recent master
- 1/6: using just "quote" instead of "Filename.quote"
- 2/6: reformated block of code according to Richards suggestion
- 4/6: added tests for nsplit
v3: Addressed Pino's comments, namely:
- input_ova.ml
- untar takes list of paths
- renamed untar_partial to untar_metadata
- replaced uggly regex with nsplit
- tests
- test changes are part of the main commit
- renamed test-data/guestfs-hashsums.sh to test-data/test-utils.sh
- renamed qemu_version to qemu_is_version and moved it to
test-data/test-utils.sh
- normalize paths in expect files
v2:
- rewritten the tar invocations, the output processing is now done in
OcaML rather than with a shell code; it turned out to be easier and
more readable than I have feared.
- added QEMU version check
- addressed Pino's comments
- changed tests; the expected result is now based on the QEMU used
during testing
This series is related to the problem of inefficient import of OVA
files. The needed enhancements of QEMU were merged into the codebase and
should be available in QEMU 2.8. From there we can use 'size' and
'offset' options in raw driver to tell QEMU to use only subset of a file
as an image.
The patch set is more or less complete. The only outstanding issue is
the missing detection of sparse files inside tar. But this can be done
in a separate patch. As pointed out before I didn't find a way how to
detect that by using the tar tool only and would probably require use of
some external library.
Tomáš Golembiovský (3):
v2v: ova: don't detect compressed disks, read the OVF instead
mllib: modify nsplit to take optional noempty and count arguments
v2v: ova: don't extract files from OVA if it's not needed
mllib/common_utils.ml | 13 ++-
mllib/common_utils.mli | 12 +-
mllib/common_utils_tests.ml | 30 +++++
test-data/test-utils.sh | 20 ++++
v2v/Makefile.am | 2 +
v2v/input_ova.ml | 198 +++++++++++++++++++++++++++++---
v2v/test-v2v-i-ova-formats.sh | 5 +-
v2v/test-v2v-i-ova-gz.ovf | 2 +-
v2v/test-v2v-i-ova-subfolders.expected2 | 18 +++
v2v/test-v2v-i-ova-subfolders.sh | 13 ++-
v2v/test-v2v-i-ova-tar.expected | 18 +++
v2v/test-v2v-i-ova-tar.expected2 | 18 +++
v2v/test-v2v-i-ova-tar.ovf | 138 ++++++++++++++++++++++
v2v/test-v2v-i-ova-tar.sh | 72 ++++++++++++
v2v/test-v2v-i-ova-two-disks.expected2 | 19 +++
v2v/test-v2v-i-ova-two-disks.sh | 13 ++-
16 files changed, 561 insertions(+), 30 deletions(-)
create mode 100644 v2v/test-v2v-i-ova-subfolders.expected2
create mode 100644 v2v/test-v2v-i-ova-tar.expected
create mode 100644 v2v/test-v2v-i-ova-tar.expected2
create mode 100644 v2v/test-v2v-i-ova-tar.ovf
create mode 100755 v2v/test-v2v-i-ova-tar.sh
create mode 100644 v2v/test-v2v-i-ova-two-disks.expected2
--
2.11.0
7 years, 9 months
[nbdkit PATCH] tls: Fix build on RHEL 5
by Eric Blake
Don't assume that errno will be implicitly available.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
src/tls.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/tls.c b/src/tls.c
index 5d380e3..0e9ea11 100644
--- a/src/tls.c
+++ b/src/tls.c
@@ -38,6 +38,7 @@
#include <string.h>
#include <unistd.h>
#include <assert.h>
+#include <errno.h>
#include <pthread.h>
--
2.9.3
7 years, 9 months
[nbdkit PATCH 0/2] fix pod and other errors in recent patches
by Eric Blake
POD errors are not nice, and 'pod2man --stderr' does not do what we
want.
Eric Blake (2):
perl: Fix previous patches
build: Kill build on POD error
.gitignore | 2 ++
configure.ac | 10 +---------
docs/Makefile.am | 8 ++++++--
docs/nbdkit-plugin.pod | 2 +-
plugins/curl/Makefile.am | 4 +++-
plugins/example1/Makefile.am | 4 +++-
plugins/example2/Makefile.am | 4 +++-
plugins/example3/Makefile.am | 4 +++-
plugins/file/Makefile.am | 4 +++-
plugins/guestfs/Makefile.am | 4 +++-
plugins/gzip/Makefile.am | 4 +++-
plugins/libvirt/Makefile.am | 4 +++-
plugins/ocaml/Makefile.am | 4 +++-
plugins/perl/Makefile.am | 4 +++-
plugins/perl/perl.c | 9 +++++----
plugins/python/Makefile.am | 4 +++-
plugins/ruby/Makefile.am | 4 +++-
plugins/streaming/Makefile.am | 4 +++-
plugins/vddk/Makefile.am | 4 +++-
plugins/xz/Makefile.am | 4 +++-
20 files changed, 60 insertions(+), 31 deletions(-)
--
2.9.3
7 years, 9 months
[nbdkit PATCH v3 0/3] bind .zero to Perl
by Eric Blake
Requires patch 1 and 2 of the python series:
https://www.redhat.com/archives/libguestfs/2017-January/msg00126.html
This is the perl implementation along the same lines.
We still haven't decided if patch 1 of the python series should
change OCaml to report errno as reliable or not, but perhaps we
can commit that patch as-is now and then touch things up further
when we actually get set_error and zero working in OCaml.
Eric Blake (3):
perl: Allow use of modules
perl: Expose nbdkit_set_error to perl script
perl: Support zero callback
plugins/perl/example.pl | 16 +++++++++
plugins/perl/nbdkit-perl-plugin.pod | 56 +++++++++++++++++++++++++++++---
plugins/perl/perl.c | 65 ++++++++++++++++++++++++++++++++++++-
3 files changed, 131 insertions(+), 6 deletions(-)
--
2.9.3
7 years, 9 months
[PATCH nbdkit] Add support for socket activation.
by Richard W.M. Jones
Socket activation (aka systemd socket activation) is a simple protocol
that lets you pass in an opened, listening socket to a server.
Supporting socket activation allows you to use a modern superserver to
serve infrequent NBD requests without needing nbdkit to be running the
whole time.
Although the protocol was invented by systemd, it has been implemented
in a few other places, and the protocol is almost trivially simple.
This implementation is based on the one in libvirt.
Thanks: Dan Berrange, libvirt team
---
.gitignore | 1 +
docs/nbdkit.pod | 67 +++++++++++-
src/main.c | 111 ++++++++++++++++++++
tests/Makefile.am | 10 +-
tests/test-socket-activation.c | 226 +++++++++++++++++++++++++++++++++++++++++
5 files changed, 411 insertions(+), 4 deletions(-)
create mode 100644 tests/test-socket-activation.c
diff --git a/.gitignore b/.gitignore
index 4a51dea..f8918a7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -50,6 +50,7 @@ Makefile.in
/tests/test-perl
/tests/test-python
/tests/test-ruby
+/tests/test-socket-activation
/tests/test-streaming
/tests/test-xz
/test-driver
diff --git a/docs/nbdkit.pod b/docs/nbdkit.pod
index 2b11eed..ad02ec3 100644
--- a/docs/nbdkit.pod
+++ b/docs/nbdkit.pod
@@ -192,9 +192,11 @@ This option implies I<--foreground>.
Don't fork. Handle a single NBD connection on stdin/stdout. After
stdin closes, the server exits.
-You can use this option to run nbdkit from inetd, systemd or similar
+You can use this option to run nbdkit from inetd or similar
superservers; or just for testing; or if you want to run nbdkit in a
-non-conventional way.
+non-conventional way. Note that if you want to run nbdkit from
+systemd, then it may be better to use L</SOCKET ACTIVATION> instead of
+this option.
This option implies I<--foreground>.
@@ -263,6 +265,48 @@ To list all the options supported by a plugin, do:
nbdkit --help file
+=head1 SOCKET ACTIVATION
+
+nbdkit supports socket activation (sometimes called systemd socket
+activation). This is a simple protocol where instead of nbdkit itself
+opening the listening socket(s), the parent process (typically
+systemd) passes in pre-opened file descriptors. Socket activation
+lets you serve infrequent NBD requests using a superserver without
+needing nbdkit to be running the whole time.
+
+Socket activation is triggered when both the C<LISTEN_FDS> and
+C<LISTEN_PID> environment variables are set. In this mode using
+I<-i>, I<-p>, I<--run>, I<-s> or I<-U> flags on the command line is
+illegal and will cause an error. Also in this mode nbdkit does not
+fork into the background (ie. I<-f> is implied).
+
+=head2 Using socket activation with systemd
+
+To use nbdkit with socket activation from systemd, create a unit file
+ending in C<.socket> (eg. C</etc/systemd/system/nbdkit.socket>)
+containing:
+
+ [Unit]
+ Description=NBDKit Network Block Device server
+
+ [Socket]
+ ListenStream=0.0.0.0:10809
+
+ [Install]
+ WantedBy=sockets.target
+
+There are various formats for the C<ListenStream> key. See
+L<systemd.socket(5)> for more information.
+
+Also create a service unit (eg. C</etc/systemd/system/nbdkit.service>)
+containing:
+
+ [Service]
+ ExecStart=/usr/sbin/nbdkit file file=/path/to/serve
+
+For more information on systemd and socket activation, see
+L<http://0pointer.de/blog/projects/socket-activation.html>
+
=head1 CAPTIVE NBDKIT
You can run nbdkit as a "captive process", using the I<--run> option.
@@ -382,8 +426,23 @@ This signal is ignored.
=back
+=head1 ENVIRONMENT VARIABLES
+
+=over 4
+
+=item C<LISTEN_FDS>
+
+=item C<LISTEN_PID>
+
+If present in the environment when nbdkit starts up, these trigger
+L</SOCKET ACTIVATION>.
+
+=back
+
=head1 SEE ALSO
+Other nbdkit manual pages:
+
L<nbdkit-plugin(3)>,
L<nbdkit-curl-plugin(1)>,
L<nbdkit-example1-plugin(1)>,
@@ -398,6 +457,10 @@ L<nbdkit-python-plugin(3)>,
L<nbdkit-vddk-plugin(1)>.
L<nbdkit-xz-plugin(1)>.
+Other manual pages of interest:
+
+L<systemd.socket(5)>.
+
=head1 AUTHORS
Richard W.M. Jones
diff --git a/src/main.c b/src/main.c
index 9453cce..e935da2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -54,6 +54,8 @@
#include "nbdkit-plugin.h"
#include "internal.h"
+#define FIRST_SOCKET_ACTIVATION_FD 3 /* defined by systemd ABI */
+
static char *make_random_fifo (void);
static void open_plugin_so (const char *filename);
static void start_serving (void);
@@ -64,6 +66,7 @@ static void write_pidfile (void);
static void fork_into_background (void);
static uid_t parseuser (const char *);
static gid_t parsegroup (const char *);
+static unsigned int get_socket_activation (void);
const char *exportname; /* -e */
int foreground; /* -f */
@@ -77,6 +80,7 @@ int listen_stdin; /* -s */
char *unixsocket; /* -U */
const char *user, *group; /* -u & -g */
int verbose; /* -v */
+unsigned int socket_activation /* $LISTEN_FDS and $LISTEN_PID set */;
volatile int quit;
@@ -157,6 +161,9 @@ main (int argc, char *argv[])
tls_init ();
+ /* Returns 0 if no socket activation, or the number of FDs. */
+ socket_activation = get_socket_activation ();
+
for (;;) {
c = getopt_long (argc, argv, short_options, long_options, &option_index);
if (c == -1)
@@ -172,6 +179,11 @@ main (int argc, char *argv[])
dump_plugin = 1;
}
else if (strcmp (long_options[option_index].name, "run") == 0) {
+ if (socket_activation) {
+ fprintf (stderr, "%s: cannot use socket activation with --run flag\n",
+ program_name);
+ exit (EXIT_FAILURE);
+ }
run = optarg;
foreground = 1;
}
@@ -196,6 +208,11 @@ main (int argc, char *argv[])
break;
case 'i':
+ if (socket_activation) {
+ fprintf (stderr, "%s: cannot use socket activation with -i flag\n",
+ program_name);
+ exit (EXIT_FAILURE);
+ }
ipaddr = optarg;
break;
@@ -214,6 +231,11 @@ main (int argc, char *argv[])
break;
case 'p':
+ if (socket_activation) {
+ fprintf (stderr, "%s: cannot use socket activation with -p flag\n",
+ program_name);
+ exit (EXIT_FAILURE);
+ }
port = optarg;
break;
@@ -222,10 +244,20 @@ main (int argc, char *argv[])
break;
case 's':
+ if (socket_activation) {
+ fprintf (stderr, "%s: cannot use socket activation with -s flag\n",
+ program_name);
+ exit (EXIT_FAILURE);
+ }
listen_stdin = 1;
break;
case 'U':
+ if (socket_activation) {
+ fprintf (stderr, "%s: cannot use socket activation with -U flag\n",
+ program_name);
+ exit (EXIT_FAILURE);
+ }
if (strcmp (optarg, "-") == 0)
unixsocket = make_random_fifo ();
else
@@ -454,6 +486,7 @@ start_serving (void)
{
int *socks;
size_t nr_socks;
+ size_t i;
/* If the user has mixed up -p/-U/-s options, then give an error.
*
@@ -470,6 +503,27 @@ start_serving (void)
set_up_signals ();
+ /* Socket activation -- we are handling connections on pre-opened
+ * file descriptors [FIRST_SOCKET_ACTIVATION_FD ..
+ * FIRST_SOCKET_ACTIVATION_FD+nr_socks-1].
+ */
+ if (socket_activation) {
+ nr_socks = socket_activation;
+ debug ("using socket activation, nr_socks = %zu", nr_socks);
+ socks = malloc (sizeof (int) * nr_socks);
+ if (socks == NULL) {
+ perror ("malloc");
+ exit (EXIT_FAILURE);
+ }
+ for (i = 0; i < nr_socks; ++i)
+ socks[i] = FIRST_SOCKET_ACTIVATION_FD + i;
+ change_user ();
+ write_pidfile ();
+ accept_incoming_connections (socks, nr_socks);
+ free_listening_sockets (socks, nr_socks); /* also closes them */
+ return;
+ }
+
/* Handling a single connection on stdin/stdout. */
if (listen_stdin) {
change_user ();
@@ -752,3 +806,60 @@ parsegroup (const char *id)
return grp->gr_gid;
}
+
+/* Returns 0 if no socket activation, or the number of FDs.
+ * See also virGetListenFDs in libvirt.org:src/util/virutil.c
+ */
+static unsigned int
+get_socket_activation (void)
+{
+ const char *s;
+ unsigned int pid;
+ unsigned int nr_fds;
+ unsigned int i;
+ int fd;
+
+ s = getenv ("LISTEN_PID");
+ if (s == NULL)
+ return 0;
+ if (sscanf (s, "%u", &pid) != 1) {
+ fprintf (stderr, "%s: malformed %s environment variable (ignored)\n",
+ program_name, "LISTEN_PID");
+ return 0;
+ }
+ if (pid != getpid ()) {
+ fprintf (stderr, "%s: %s was not for us (ignored)\n",
+ program_name, "LISTEN_PID");
+ return 0;
+ }
+
+ s = getenv ("LISTEN_FDS");
+ if (s == NULL)
+ return 0;
+ if (sscanf (s, "%u", &nr_fds) != 1) {
+ fprintf (stderr, "%s: malformed %s environment variable (ignored)\n",
+ program_name, "LISTEN_FDS");
+ return 0;
+ }
+
+ /* So these are not passed to any child processes we might start. */
+ unsetenv ("LISTEN_FDS");
+ unsetenv ("LISTEN_PID");
+
+ /* So the file descriptors don't leak into child processes. */
+ for (i = 0; i < nr_fds; ++i) {
+ fd = FIRST_SOCKET_ACTIVATION_FD + i;
+ if (fcntl (fd, F_SETFD, FD_CLOEXEC) == -1) {
+ /* If we cannot set FD_CLOEXEC then it probably means the file
+ * descriptor is invalid, so socket activation has gone wrong
+ * and we should exit.
+ */
+ fprintf (stderr, "%s: socket activation: "
+ "invalid file descriptor fd = %d: %m\n",
+ program_name, fd);
+ exit (EXIT_FAILURE);
+ }
+ }
+
+ return nr_fds;
+}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index afb9975..389bcfa 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -83,7 +83,14 @@ TESTS = \
test-single.sh \
test-captive.sh \
test-random-sock.sh \
- test-ipv4.sh
+ test-ipv4.sh \
+ test-socket-activation
+
+check_PROGRAMS = \
+ test-socket-activation
+
+test_socket_activation_SOURCES = test-socket-activation.c
+test_socket_activation_CFLAGS = $(WARNINGS_CFLAGS)
# In-depth tests need libguestfs, since that is a convenient way to
# drive qemu.
@@ -103,7 +110,6 @@ check_LTLIBRARIES = libtest.la
libtest_la_SOURCES = test.c test.h
libtest_la_CFLAGS = $(WARNINGS_CFLAGS)
-check_PROGRAMS =
check_DATA =
check_SCRIPTS =
diff --git a/tests/test-socket-activation.c b/tests/test-socket-activation.c
new file mode 100644
index 0000000..5ecdde1
--- /dev/null
+++ b/tests/test-socket-activation.c
@@ -0,0 +1,226 @@
+/* nbdkit
+ * Copyright (C) 2017 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.
+ */
+
+/* Test socket activation.
+ *
+ * We cannot use the test framework for this since the framework
+ * always uses the -U flag which is incompatible with socket
+ * activation. Unfortunately this does mean we duplicate some code
+ * from the test framework.
+ *
+ * It's *almost* possible to test this from a shell script
+ * (cf. test-ipv4.sh) but as far as I can tell setting LISTEN_PID
+ * correctly is impossible from shell.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <signal.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/wait.h>
+
+#define FIRST_SOCKET_ACTIVATION_FD 3
+
+#define NBDKIT_START_TIMEOUT 30 /* seconds */
+
+#define NBDKIT_PLUGIN(name) \
+ "../plugins/" name "/.libs/nbdkit-" name "-plugin.so"
+
+/* Declare program_name. */
+#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME == 1
+#include <errno.h>
+#define program_name program_invocation_short_name
+#else
+#define program_name "nbdkit"
+#endif
+
+static char tmpdir[] = "/tmp/nbdkitXXXXXX";
+static char sockpath[] = "/tmp/nbdkitXXXXXX/sock";
+static char pidpath[] = "/tmp/nbdkitXXXXXX/pid";
+
+static pid_t pid = 0;
+
+static void
+cleanup (void)
+{
+ if (pid > 0)
+ kill (pid, SIGTERM);
+
+ unlink (pidpath);
+ unlink (sockpath);
+ rmdir (tmpdir);
+}
+
+int
+main (int argc, char *argv[])
+{
+ int sock;
+ struct sockaddr_un addr;
+ char pid_str[16];
+ size_t i, len;
+ char magic[8];
+
+ if (mkdtemp (tmpdir) == NULL) {
+ perror ("mkdtemp");
+ exit (EXIT_FAILURE);
+ }
+ len = strlen (tmpdir);
+ memcpy (sockpath, tmpdir, len);
+ memcpy (pidpath, tmpdir, len);
+
+ atexit (cleanup);
+
+ /* Open the listening socket which will be passed into nbdkit. */
+ sock = socket (AF_UNIX, SOCK_STREAM /* NB do not use SOCK_CLOEXEC */, 0);
+ if (sock == -1) {
+ perror ("socket");
+ exit (EXIT_FAILURE);
+ }
+
+ addr.sun_family = AF_UNIX;
+ len = strlen (sockpath);
+ memcpy (addr.sun_path, sockpath, len+1 /* trailing \0 */);
+
+ if (bind (sock, (struct sockaddr *) &addr, sizeof addr) == -1) {
+ perror (sockpath);
+ exit (EXIT_FAILURE);
+ }
+
+ if (listen (sock, 1) == -1) {
+ perror ("listen");
+ exit (EXIT_FAILURE);
+ }
+
+ if (sock != FIRST_SOCKET_ACTIVATION_FD) {
+ if (dup2 (sock, FIRST_SOCKET_ACTIVATION_FD) == -1) {
+ perror ("dup2");
+ exit (EXIT_FAILURE);
+ }
+ close (sock);
+ }
+
+ /* Run nbdkit. */
+ pid = fork ();
+ if (pid == -1) {
+ perror ("fork");
+ exit (EXIT_FAILURE);
+ }
+ if (pid == 0) {
+ /* Run nbdkit in the child. */
+ setenv ("LISTEN_FDS", "1", 1);
+ snprintf (pid_str, sizeof pid_str, "%d", (int) getpid ());
+ setenv ("LISTEN_PID", pid_str, 1);
+
+ execlp ("../src/nbdkit",
+ "nbdkit",
+ "-P", pidpath,
+ "-o",
+ "-v",
+ NBDKIT_PLUGIN ("example1"), NULL);
+ perror ("exec: nbdkit");
+ _exit (EXIT_FAILURE);
+ }
+
+ /* We don't need the listening socket now. */
+ close (sock);
+
+ /* Wait for the pidfile to turn up, which indicates that nbdkit has
+ * started up successfully and is ready to serve requests. However
+ * if 'pid' exits in this time it indicates a failure to start up.
+ * Also there is a timeout in case nbdkit hangs.
+ */
+ for (i = 0; i < NBDKIT_START_TIMEOUT; ++i) {
+ if (waitpid (pid, NULL, WNOHANG) == pid)
+ goto early_exit;
+
+ if (kill (pid, 0) == -1) {
+ if (errno == ESRCH) {
+ early_exit:
+ fprintf (stderr,
+ "%s FAILED: nbdkit exited before starting to serve files\n",
+ program_name);
+ pid = 0;
+ exit (EXIT_FAILURE);
+ }
+ perror ("kill");
+ }
+
+ if (access (pidpath, F_OK) == 0)
+ break;
+
+ sleep (1);
+ }
+
+ /* Now nbdkit is supposed to be listening on the Unix domain socket
+ * (which it got via the listening socket that we passed down to it,
+ * not from the path), so we should be able to connect to the Unix
+ * domain socket by its path and receive an NBD magic string.
+ */
+ sock = socket (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
+ if (sock == -1) {
+ perror ("socket");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Reuse addr which was set up above. */
+ if (connect (sock, (struct sockaddr *) &addr, sizeof addr) == -1) {
+ perror (sockpath);
+ exit (EXIT_FAILURE);
+ }
+
+ if (read (sock, magic, 8) != 8) {
+ perror ("read");
+ exit (EXIT_FAILURE);
+ }
+
+ if (memcmp (magic, "NBDMAGIC", 8) != 0) {
+ fprintf (stderr, "%s FAILED: did not read magic string from server\n",
+ program_name);
+ exit (EXIT_FAILURE);
+ }
+
+ close (sock);
+
+ /* Test succeeded. */
+ exit (EXIT_SUCCESS);
+}
--
2.10.2
7 years, 9 months
Re: [Libguestfs] virt-p2v-make-disk not making disk
by Richard W.M. Jones
On Sat, Jan 28, 2017 at 04:26:08PM -0800, Martin Lanner wrote:
> I've used the following commands:
>
> ```
> # virt-p2v-make-disk -o /dev/sdb --inject-ssh-identity id_rsa_p2v
> # virt-p2v-make-disk -o /dev/sdb centos-7.3 --inject-ssh-identity id_rsa_p2v
> # virt-p2v-make-disk -o p2v/p2v.img centos-7.3 --inject-ssh-identity id_rsa_p2v
> ```
>
> ... on both CentOS 7.3 and Ubuntu 16.04, including from a bare metal machine to a USB drive, from a VM to a .img, as well as from a container to .img, and none of them seem to work. It downloads the base image, uncompresses it, and finally tries to open it. But that's where it stops:
>
> ```
> root@p2v:~# virt-p2v-make-disk -o p2v/p2v.img centos-7.3 --inject-ssh-identity id_rsa_p2v
> [ 1.6] Downloading: http://libguestfs.org/download/builder/centos-7.3.xz
> ################################################################## 100.0%
> [ 223.9] Planning how to build this image
> [ 223.9] Uncompressing
> [ 235.7] Opening the new disk
> ...
> ```
Run libguestfs-test-tool and post the complete, unedited output
on the mailing list.
See also:
http://libguestfs.org/guestfs-faq.1.html#debugging-libguestfs
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines. Supports shell scripting,
bindings from many languages. http://libguestfs.org
7 years, 9 months
[nbdkit PATCH v3 0/4] bind .zero to Python
by Eric Blake
This cleans up the existing code base with regards to implicit
use of errno from language bindings, then rebases the previous
work in python on top of that.
I'm still playing with the perl bindings, but got further after
reading 'perldoc perlembed'.
Eric Blake (4):
plugins: Don't use bogus errno from non-C plugins
plugins: Add new nbdkit_set_error() utility function
python: Expose nbdkit_set_error to python script
python: Support zero callback
docs/nbdkit-plugin.pod | 64 +++++++++++++++++++++++----
include/nbdkit-plugin.h | 14 +++++-
plugins/ocaml/nbdkit-ocaml-plugin.pod | 11 +++++
plugins/ocaml/ocaml.c | 12 ++++++
plugins/perl/nbdkit-perl-plugin.pod | 5 +++
plugins/perl/perl.c | 12 ++++++
plugins/python/example.py | 11 +++++
plugins/python/nbdkit-python-plugin.pod | 53 +++++++++++++++++++++--
plugins/python/python.c | 76 +++++++++++++++++++++++++++++++++
plugins/ruby/nbdkit-ruby-plugin.pod | 5 +++
plugins/ruby/ruby.c | 12 ++++++
src/connections.c | 36 ++++++++++++----
src/errors.c | 6 +++
src/internal.h | 4 ++
src/plugins.c | 25 ++++++++++-
src/tls.c | 30 ++++++++++++-
16 files changed, 349 insertions(+), 27 deletions(-)
--
2.9.3
7 years, 9 months