[Libguestfs] [PATCH 1/4] lib: Remove libguestfs live

Richard W.M. Jones rjones at redhat.com
Tue Mar 8 15:57:51 UTC 2022


This experimental feature allowed you (in theory) to connect to an
existing instance of the libguestfs daemon.  (Again, in theory) it
allowed you to attach to running guests.  This didn't work well in
practice.  If you want to do this, install qemu-guest-agent inside
your guest instead.

This was never supported in RHEL.

The daemon tests relied on this connection method to perform tests on
a bare daemon, so this removes those tests.  They were not especially
valuable.

See-also: https://bugzilla.redhat.com/798980
---
 configure.ac                      |   1 -
 docs/C_SOURCE_FILES               |   1 -
 lib/Makefile.am                   |   1 -
 lib/guestfs-internal.h            |   1 -
 lib/guestfs.pod                   |  66 ---------------
 lib/launch-unix.c                 | 130 ------------------------------
 lib/launch.c                      |   1 -
 tests/Makefile.am                 |   9 ---
 tests/daemon/captive-daemon.pm.in | 122 ----------------------------
 tests/daemon/test-btrfs.pl        |  82 -------------------
 tests/daemon/test-daemon-start.pl |  35 --------
 11 files changed, 449 deletions(-)

diff --git a/configure.ac b/configure.ac
index d8383ec173..03180eeafb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -280,7 +280,6 @@ AC_CONFIG_FILES([Makefile
                  test-data/phony-guests/guests.xml
                  test-tool/Makefile
                  tests/Makefile
-                 tests/daemon/captive-daemon.pm
                  tests/disks/test-qemu-drive-libvirt.xml
                  website/index.html])
 
diff --git a/docs/C_SOURCE_FILES b/docs/C_SOURCE_FILES
index 6a97d8b0e6..7837120173 100644
--- a/docs/C_SOURCE_FILES
+++ b/docs/C_SOURCE_FILES
@@ -314,7 +314,6 @@ lib/journal.c
 lib/launch-direct.c
 lib/launch-libvirt.c
 lib/launch-uml.c
-lib/launch-unix.c
 lib/launch.c
 lib/libvirt-auth.c
 lib/libvirt-domain.c
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 433dd530cd..5cb7c8e841 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -98,7 +98,6 @@ libguestfs_la_SOURCES = \
 	launch-direct.c \
 	launch-libvirt.c \
 	launch-uml.c \
-	launch-unix.c \
 	libvirt-auth.c \
 	libvirt-domain.c \
 	lpj.c \
diff --git a/lib/guestfs-internal.h b/lib/guestfs-internal.h
index 4a19e5c6bb..c6432a219f 100644
--- a/lib/guestfs-internal.h
+++ b/lib/guestfs-internal.h
@@ -813,7 +813,6 @@ void guestfs_int_init_direct_backend (void) __attribute__((constructor));
 void guestfs_int_init_libvirt_backend (void) __attribute__((constructor));
 #endif
 void guestfs_int_init_uml_backend (void) __attribute__((constructor));
-void guestfs_int_init_unix_backend (void) __attribute__((constructor));
 
 /* qemu.c */
 struct qemu_data;
diff --git a/lib/guestfs.pod b/lib/guestfs.pod
index ff58aa0bb2..f9c3d4dc25 100644
--- a/lib/guestfs.pod
+++ b/lib/guestfs.pod
@@ -1492,14 +1492,6 @@ User-Mode Linux can be much faster, simpler and more lightweight than
 using a full-blown virtual machine, but it also has some shortcomings.
 See L</USER-MODE LINUX BACKEND> below.
 
-=item C<unix:I<path>>
-
-Connect to the Unix domain socket I<path>.
-
-This method lets you connect to an existing daemon or (using
-virtio-serial) to a live guest.  For more information, see
-L</ATTACHING TO RUNNING DAEMONS>.
-
 =back
 
 C<direct> is usually the default backend.  However since libguestfs
@@ -1561,64 +1553,6 @@ On Fedora, install C<kernel-debuginfo> for the C<vmlinux> file
 (containing symbols).  Make sure the symbols precisely match the
 kernel being used.
 
-=head2 ATTACHING TO RUNNING DAEMONS
-
-I<Note (1):> This is B<highly experimental> and has a tendency to eat
-babies.  Use with caution.
-
-I<Note (2):> This section explains how to attach to a running daemon
-from a low level perspective.  For most users, simply using virt tools
-such as L<guestfish(1)> with the I<--live> option will "just work".
-
-=head3 Using guestfs_set_backend
-
-By calling L</guestfs_set_backend> you can change how the library
-connects to the C<guestfsd> daemon in L</guestfs_launch> (read
-L<guestfs-internals(1)/ARCHITECTURE> for some background).
-
-The normal backend is C<direct>, where a small appliance is created
-containing the daemon, and then the library connects to this.
-C<libvirt> or C<libvirt:I<URI>> are alternatives that use libvirt to
-start the appliance.
-
-Setting the backend to C<unix:I<path>> (where I<path> is the path of a
-Unix domain socket) causes L</guestfs_launch> to connect to an
-existing daemon over the Unix domain socket.
-
-The normal use for this is to connect to a running virtual machine
-that contains a C<guestfsd> daemon, and send commands so you can read
-and write files inside the live virtual machine.
-
-=head3 Using guestfs_add_domain with live flag
-
-L</guestfs_add_domain> provides some help for getting the correct
-backend.  If you pass the C<live> option to this function, then (if
-the virtual machine is running) it will examine the libvirt XML
-looking for a virtio-serial channel to connect to:
-
- <domain>
-   ...
-   <devices>
-     ...
-     <channel type='unix'>
-       <source mode='bind' path='/path/to/socket'/>
-       <target type='virtio' name='org.libguestfs.channel.0'/>
-     </channel>
-     ...
-   </devices>
- </domain>
-
-L</guestfs_add_domain> extracts F</path/to/socket> and sets the
-backend to C<unix:/path/to/socket>.
-
-Some of the libguestfs tools (including guestfish) support a I<--live>
-option which is passed through to L</guestfs_add_domain> thus allowing
-you to attach to and modify live virtual machines.
-
-The virtual machine needs to have been set up beforehand so that it
-has the virtio-serial channel and so that guestfsd is running inside
-it.
-
 =head2 USER-MODE LINUX BACKEND
 
 Setting the following environment variables (or the equivalent in the
diff --git a/lib/launch-unix.c b/lib/launch-unix.c
deleted file mode 100644
index 0d344f9df9..0000000000
--- a/lib/launch-unix.c
+++ /dev/null
@@ -1,130 +0,0 @@
-/* libguestfs
- * Copyright (C) 2009-2020 Red Hat Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <config.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include <sys/un.h>  /* sockaddr_un */
-#include <string.h>
-#include <libintl.h>
-
-#include "guestfs.h"
-#include "guestfs-internal.h"
-#include "guestfs_protocol.h"
-
-/* Alternate backend: instead of launching the appliance,
- * connect to an existing unix socket.
- */
-
-static int
-launch_unix (guestfs_h *g, void *datav, const char *sockpath)
-{
-  int r, daemon_sock = -1;
-  struct sockaddr_un addr;
-  uint32_t size;
-  void *buf = NULL;
-
-  if (g->hv_params) {
-    error (g, _("cannot set hv parameters with the 'unix:' backend"));
-    return -1;
-  }
-
-  if (strlen (sockpath) > UNIX_PATH_MAX-1) {
-    error (g, _("socket filename too long (more than %d characters): %s"),
-           UNIX_PATH_MAX-1, sockpath);
-    return -1;
-  }
-
-  debug (g, "connecting to %s", sockpath);
-
-  daemon_sock = socket (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
-  if (daemon_sock == -1) {
-    perrorf (g, "socket");
-    return -1;
-  }
-
-  addr.sun_family = AF_UNIX;
-  strncpy (addr.sun_path, sockpath, UNIX_PATH_MAX);
-  addr.sun_path[UNIX_PATH_MAX-1] = '\0';
-
-  g->state = LAUNCHING;
-
-  if (connect (daemon_sock, (struct sockaddr *) &addr, sizeof addr) == -1) {
-    perrorf (g, "bind");
-    goto cleanup;
-  }
-
-  g->conn = guestfs_int_new_conn_socket_connected (g, daemon_sock, -1);
-  if (!g->conn)
-    goto cleanup;
-
-  /* g->conn now owns this socket. */
-  daemon_sock = -1;
-
-  r = guestfs_int_recv_from_daemon (g, &size, &buf);
-  free (buf);
-
-  if (r == -1) goto cleanup;
-
-  if (size != GUESTFS_LAUNCH_FLAG) {
-    error (g, _("guestfs_launch failed, unexpected initial message from guestfsd"));
-    goto cleanup;
-  }
-
-  debug (g, "connected");
-
-  if (g->state != READY) {
-    error (g, _("contacted guestfsd, but state != READY"));
-    goto cleanup;
-  }
-
-  return 0;
-
- cleanup:
-  if (daemon_sock >= 0)
-    close (daemon_sock);
-  if (g->conn) {
-    g->conn->ops->free_connection (g, g->conn);
-    g->conn = NULL;
-  }
-  return -1;
-}
-
-static int
-shutdown_unix (guestfs_h *g, void *datav, int check_for_errors)
-{
-  /* Merely closing g->daemon_sock is sufficient and that is already done
-   * in the calling code.
-   */
-  return 0;
-}
-
-static struct backend_ops backend_unix_ops = {
-  .data_size = 0,
-  .launch = launch_unix,
-  .shutdown = shutdown_unix,
-};
-
-void
-guestfs_int_init_unix_backend (void)
-{
-  guestfs_int_register_backend ("unix", &backend_unix_ops);
-}
diff --git a/lib/launch.c b/lib/launch.c
index 0e4adcf1c0..0675fe98be 100644
--- a/lib/launch.c
+++ b/lib/launch.c
@@ -432,5 +432,4 @@ guestfs_int_force_load_backends[] = {
   guestfs_int_init_libvirt_backend,
 #endif
   guestfs_int_init_uml_backend,
-  guestfs_int_init_unix_backend,
 };
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3c7a132dfe..707a840225 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -326,15 +326,6 @@ charsets_test_charset_fidelity_LDADD = \
 TESTS += create/test-disk-create.sh
 EXTRA_DIST += create/test-disk-create.sh
 
-check_DATA = daemon/captive-daemon.pm
-
-TESTS += \
-	daemon/test-daemon-start.pl \
-	daemon/test-btrfs.pl
-EXTRA_DIST += \
-	daemon/test-daemon-start.pl \
-	daemon/test-btrfs.pl
-
 TESTS += \
 	discard/test-blkdiscard.pl \
 	discard/test-discard.pl \
diff --git a/tests/daemon/captive-daemon.pm.in b/tests/daemon/captive-daemon.pm.in
deleted file mode 100644
index 77600821af..0000000000
--- a/tests/daemon/captive-daemon.pm.in
+++ /dev/null
@@ -1,122 +0,0 @@
-# libguestfs
-# Copyright (C) 2015 Red Hat Inc.
-# @configure_input@
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-# Small library to help testing the daemon directly.
-
-package CaptiveDaemon;
-
-use strict;
-use warnings;
-
-use Sys::Guestfs;
-
-$| = 1;
-
-# Filled in by autoconf.
-my %var;
-$var{abs_top_srcdir} = "@abs_top_srcdir@";
-$var{abs_top_builddir} = "@abs_top_builddir@";
-$var{VALGRIND} = "@VALGRIND@";
-
-# Now we have to substitute the above variables into this one:
-my $VG = '@VG@';
-$VG =~ s/\$\(([A-Za-z_]+)\)/ $var{"$1"} /ge;
-
-# Refuse to run if the user is trying to run tests as root.  There's
-# too much risk that things will go badly wrong.
-if ($> == 0) {
-    print "$0: don't run the libguestfs tests as root!\n";
-    exit 77
-}
-
-sub run_tests {
-    my $g = Sys::Guestfs->new();
-    my $tmpdir = $g->get_tmpdir;
-    my $verbose = $g->get_verbose;
-    $g->close;
-
-    # Choose a random name for the socket.  The daemon will create the
-    # socket so we don't need to do that.
-    my @chars = ("A".."Z", "a".."z", "0".."9");
-    my $sockname = $tmpdir;
-    $sockname .= "/";
-    $sockname .= $chars[rand @chars] for 1..8;
-
-    # Assemble the command we will run in the subprocess.
-    my $cmd =
-        "$var{abs_top_builddir}/daemon/guestfsd --channel $sockname -r -t -l";
-    if ($verbose) {
-        $cmd = $cmd . " -v"
-    }
-    if ($ENV{VG}) { # $VG env var will be set when make check-valgrind.
-        $cmd = $VG . " " . $cmd
-    }
-
-    if ($verbose) {
-        print "$0: running: $cmd\n";
-    }
-
-    # Fork to run the daemon in the background.
-    my $pid = fork ();
-    die "fork: $!" unless defined $pid;
-    if ($pid == 0) {
-        # Child process: the daemon.
-        exec $cmd or die "guestfsd: $!";
-    }
-
-    # Wait for the daemon to create the socket, but if it doesn't
-    # appear after a short timeout, assume there has been a failure.
-    for (my $i = 0; $i < 10; ++$i) {
-        last if -S $sockname;
-        sleep 1;
-    }
-    die "subprocess did not create the socket, check earlier messages\n"
-        unless -S $sockname;
-
-    # Create the libguestfs handle and connect to the daemon using
-    # libguestfs live.
-    $g = Sys::Guestfs->new ();
-    $g->set_backend ("unix:" . $sockname);
-    $g->set_autosync (0);
-    $g->launch;
-
-    # Run the user tests.
-    my $r = ::tests ($g);
-
-    # Tell the daemon to exit cleanly, and remove the socket.
-    $g->internal_exit;
-    $g->close;
-    unlink $sockname;
-
-    waitpid ($pid, 0) or die "waitpid: $!";
-    if ($? != 0) {
-        my $signal = $? & 127;
-        die "ERROR: guestfsd died on signal $signal\n" if $signal;
-        my $crash = $? & 128;
-        die "ERROR: guestfsd core dumped\n" if $crash;
-        my $status = $? >> 8;
-        die "ERROR: guestfsd died with exit code 119 (valgrind failure)\n"
-            if $status == 119;
-        die "ERROR: guestfsd died with exit code $status\n";
-    }
-
-    # Exit with failure if the user test failed.
-    exit 1 unless $r
-}
-
-1;
diff --git a/tests/daemon/test-btrfs.pl b/tests/daemon/test-btrfs.pl
deleted file mode 100755
index b7f4214a89..0000000000
--- a/tests/daemon/test-btrfs.pl
+++ /dev/null
@@ -1,82 +0,0 @@
-#!/usr/bin/env perl
-# libguestfs
-# Copyright (C) 2015 Red Hat Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-# Test that the daemon starts and stops.
-
-use strict;
-use warnings;
-
-use File::Temp qw/tempdir/;
-
-require './daemon/captive-daemon.pm';
-
-# Set $PATH to include directory that will have phony 'btrfs' binary.
-my $bindir = tempdir (CLEANUP => 1);
-$ENV{PATH} = $bindir . ":" . $ENV{PATH};
-
-sub set_btrfs_output {
-    my $output = shift;
-    open BTRFS, ">$bindir/btrfs" or die "$bindir/btrfs: $!";
-    print BTRFS "#!/bin/sh\n";
-    print BTRFS "cat << '__EOF'\n";
-    print BTRFS $output;
-    print BTRFS "__EOF\n";
-    close BTRFS;
-    chmod 0755, "$bindir/btrfs" or die "chmod: $bindir/btrfs: $!";
-}
-
-sub tests {
-    my $g = shift;
-
-    # Test btrfs_subvolume_list.
-    my $output = <<EOF;
-ID 256 gen 30 top level 5 path test1
-ID 257 gen 30 top level 5 path dir/test2
-ID 258 gen 30 top level 5 path test3
-EOF
-    set_btrfs_output ($output);
-    my @r = $g->btrfs_subvolume_list ("/");
-    die unless @r == 3;
-    die unless $r[0]->{btrfssubvolume_id} == 256;
-    die unless $r[0]->{btrfssubvolume_top_level_id} == 5;
-    die unless $r[0]->{btrfssubvolume_path} eq "test1";
-    die unless $r[1]->{btrfssubvolume_id} == 257;
-    die unless $r[1]->{btrfssubvolume_top_level_id} == 5;
-    die unless $r[1]->{btrfssubvolume_path} eq "dir/test2";
-    die unless $r[2]->{btrfssubvolume_id} == 258;
-    die unless $r[2]->{btrfssubvolume_top_level_id} == 5;
-    die unless $r[2]->{btrfssubvolume_path} eq "test3";
-
-    # Test btrfs_qgroup_show.
-    $output = <<EOF;
-qgroupid rfer excl 
--------- ---- ---- 
-0/5      4096 4096 
-EOF
-    set_btrfs_output ($output);
-    @r = $g->btrfs_qgroup_show ("/");
-    die unless @r == 1;
-    die unless $r[0]->{btrfsqgroup_id} eq "0/5";
-    die unless $r[0]->{btrfsqgroup_rfer} == 4096;
-    die unless $r[0]->{btrfsqgroup_excl} == 4096;
-
-    # Return true to indicate the test succeeded.
-    1;
-}
-
-CaptiveDaemon::run_tests ()
diff --git a/tests/daemon/test-daemon-start.pl b/tests/daemon/test-daemon-start.pl
deleted file mode 100755
index bac4d08c53..0000000000
--- a/tests/daemon/test-daemon-start.pl
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/usr/bin/env perl
-# libguestfs
-# Copyright (C) 2015 Red Hat Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-# Test that the daemon starts and stops.
-
-use strict;
-use warnings;
-
-require './daemon/captive-daemon.pm';
-
-sub tests {
-    my $g = shift;
-
-    $g->ping_daemon;
-
-    # Return true to indicate the test succeeded.
-    1;
-}
-
-CaptiveDaemon::run_tests ()
-- 
2.35.1



More information about the Libguestfs mailing list