Skip to content

Commit 888c9eb

Browse files
author
Laszlo Ersek
committed
remove qemu-nbd support
On 03/24/22 10:13, Richard W.M. Jones wrote: > virt-p2v needs an NBD server running on the p2v machine to export the > disks. Originally we used qemu-nbd since that was the only choice. > In 2017, I added support for nbdkit as an alternative to qemu-nbd. > > So now we're in the situation where either server can be used (see > virt-p2v.git/nbd.c). For added complexity we also support both > servers in either systemd socket activation (SA) mode or "no-SA" mode, > so that's 4 combinations. > > This is silly, we should support only one NBD server, and since > systemd socket activation is well-supported and more flexible, we > should just use it. > > So the question is *which* NBD server to support. That's not so much > a technical matter since both servers can easily serve a local block > device (always raw format). However I do think that nbdkit might > genuinely be the better choice here: > > - qemu-nbd links to the whole qemu block layer, nbdkit can be shipped > with just the plugin we need, so it should be smaller with less > code surface > > - nbdkit-file-plugin has a better method of not trashing the host > page cache > > - could use nbdkit --exit-with-parent feature (which we don't at the > moment) > > - nbdkit is widely available in distros these days > > Also that file uses AI_ADDRCONFIG so I guess it has problems with IPv6. This patch removes qemu-nbd support, as the first step. "test-virt-p2v.sh" is simply removed, as the remaining "test-virt-p2v-nbdkit.sh" is mostly identical. The package references for the various distros, in "dependencies.m4", come from: - https://packages.debian.org/sid/amd64/nbdkit/filelist - https://aur.archlinux.org/packages/nbdkit Ref: https://listman.redhat.com/archives/libguestfs/2022-March/028475.html Suggested-by: Richard W.M. Jones <[email protected]> Signed-off-by: Laszlo Ersek <[email protected]> Message-Id: <[email protected]> Reviewed-by: Richard W.M. Jones <[email protected]>
1 parent c1a4bd8 commit 888c9eb

12 files changed

+35
-263
lines changed

Makefile.am

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ EXTRA_DIST = \
3131
contrib/aux-scripts/do-build.sh \
3232
contrib/build-p2v-iso.sh \
3333
contrib/patches/0001-RHEL-5-ONLY-DISABLE-AUTOMATIC-REMOTE-PORT-ALLOCATION.patch \
34-
contrib/patches/0002-RHEL-5-ONLY-QEMU-NBD-1.4-HAS-NO-f-OPTION.patch \
3534
contrib/test-p2v-iso.sh \
3635
dependencies.m4 \
3736
generate-p2v-authors.pl \
@@ -339,7 +338,6 @@ TESTS = \
339338
test-virt-p2v-docs.sh
340339

341340
LIBGUESTFS_TESTS = \
342-
test-virt-p2v.sh \
343341
test-virt-p2v-nbdkit.sh
344342

345343
if HAVE_LIBGUESTFS

contrib/aux-scripts/do-build.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ case $osversion in
5959
sed -i -e 's/-Wno-strict-overflow//' configure
6060
# Apply some RHEL 5 only patches.
6161
patch -p1 < ../patches/0001-RHEL-5-ONLY-DISABLE-AUTOMATIC-REMOTE-PORT-ALLOCATION.patch
62-
patch -p1 < ../patches/0002-RHEL-5-ONLY-QEMU-NBD-1.4-HAS-NO-f-OPTION.patch
6362
;;
6463
rhel-6.*|centos-6.*)
6564
# This just forces configure to ignore these missing dependencies.
@@ -122,7 +121,8 @@ case $osversion in
122121
-e 's,^mesa-dri-drivers.*,,g' \
123122
-e 's,^network-manager-applet.*,,g' \
124123
-e 's,^nm-connection-editor.*,,g' \
125-
-e 's,^/usr/bin/qemu-nbd.*,,g' \
124+
-e 's,^nbdkit-server.*,,g' \
125+
-e 's,^nbdkit-file-plugin.*,,g' \
126126
-e '/^net-tools/a syslinux' \
127127
p2v.ks
128128
# Remove systemctl lines, doesn't exist on RHEL 5.
@@ -137,7 +137,8 @@ case $osversion in
137137
-e 's,^firewalld.*,,g' \
138138
-e 's,^network-manager-applet.*,,g' \
139139
-e 's,^nm-connection-editor.*,,g' \
140-
-e 's,^/usr/bin/qemu-nbd.*,,g' \
140+
-e 's,^nbdkit-server.*,,g' \
141+
-e 's,^nbdkit-file-plugin.*,,g' \
141142
p2v.ks
142143
# Remove systemctl lines, doesn't exist on RHEL 5.
143144
sed -i \

contrib/patches/0002-RHEL-5-ONLY-QEMU-NBD-1.4-HAS-NO-f-OPTION.patch

Lines changed: 0 additions & 34 deletions
This file was deleted.

dependencies.m4

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ ifelse(REDHAT,1,
2929

3030
dnl Run as external programs by the p2v binary.
3131
/usr/bin/ssh
32-
/usr/bin/qemu-nbd
32+
nbdkit-server
33+
nbdkit-file-plugin
3334
which
3435

3536
dnl Generally useful tools to use within xterm
@@ -66,7 +67,7 @@ ifelse(DEBIAN,1,
6667
ifelse(GTK_VERSION,2,libgtk`'GTK_VERSION`'.0-0,libgtk-`'GTK_VERSION`'-0)
6768
libdbus-1-3
6869
openssh-client
69-
qemu-utils
70+
nbdkit
7071
debianutils
7172
vim-tiny
7273
open-iscsi
@@ -86,7 +87,7 @@ ifelse(ARCHLINUX,1,
8687
gtk`'GTK_VERSION
8788
dbus
8889
openssh
89-
qemu
90+
nbdkit
9091
which
9192
vim-tiny
9293
open-iscsi
@@ -107,7 +108,8 @@ ifelse(SUSE,1,
107108
libxml2
108109
gtk`'GTK_VERSION
109110
libdbus-1-3
110-
qemu-tools
111+
nbdkit-server
112+
nbdkit-file-plugin
111113
openssh
112114
dnl /usr/bin/which is in util-linux on SUSE
113115
vim
@@ -134,7 +136,8 @@ ifelse(OPENMANDRIVA,1,
134136

135137
dnl Run as external programs by the p2v binary.
136138
/usr/bin/ssh
137-
/usr/bin/qemu-nbd
139+
nbdkit-server
140+
nbdkit-file-plugin
138141
which
139142

140143
dnl Generally useful tools to use within xterm

docs/p2v-building.pod

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,12 @@ I<Required>.
7373

7474
I<Required>.
7575

76-
=item qemu-nbd
77-
7876
=item nbdkit
7977

80-
Optional. qemu-nbd is used for testing.
78+
Optional.
8179

82-
L<virt-p2v(1)> requires either qemu-nbd or nbdkit, but these only need
83-
to be present on the virt-p2v ISO, they do not need to be installed at
84-
compile time.
80+
L<virt-p2v(1)> requires nbdkit, but it only needs to be present on the
81+
virt-p2v ISO, it does not need to be installed at compile time.
8582

8683
=item Gtk E<ge> 2.24, or 3
8784

main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ usage (int status)
9999
" --cmdline=CMDLINE Used to debug command line parsing\n"
100100
" --colors|--colours Use ANSI colour sequences even if not tty\n"
101101
" --iso Running in the ISO environment\n"
102-
" --nbd=qemu-nbd,nbdkit Search order for NBD servers\n"
102+
" --nbd=nbdkit Search order for NBD servers\n"
103103
" --test-disk=DISK.IMG For testing, use disk as /dev/sda\n"
104104
" -v|--verbose Verbose messages\n"
105105
" -V|--version Display version and exit\n"

nbd.c

Lines changed: 5 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
/**
1919
* This file handles the virt-p2v I<--nbd> command line option
20-
* and running either L<qemu-nbd(8)> or L<nbdkit(1)>.
20+
* and running L<nbdkit(1)>.
2121
*/
2222

2323
#include <config.h>
@@ -50,10 +50,8 @@ static int nbd_local_port;
5050
/* List of servers specified by the --nbd option. */
5151
enum nbd_server {
5252
/* 0 is reserved for "end of list" */
53-
QEMU_NBD = 1,
54-
QEMU_NBD_NO_SA = 2,
55-
NBDKIT = 3,
56-
NBDKIT_NO_SA = 4,
53+
NBDKIT = 1,
54+
NBDKIT_NO_SA = 2,
5755
};
5856
static enum nbd_server *cmdline_servers = NULL;
5957

@@ -63,8 +61,6 @@ nbd_server_string (enum nbd_server s)
6361
const char *ret = NULL;
6462

6563
switch (s) {
66-
case QEMU_NBD: ret = "qemu-nbd"; break;
67-
case QEMU_NBD_NO_SA: ret = "qemu-nbd-no-sa"; break;
6864
case NBDKIT: ret = "nbdkit"; break;
6965
case NBDKIT_NO_SA: ret = "nbdkit-no-sa"; break;
7066
}
@@ -79,14 +75,13 @@ nbd_server_string (enum nbd_server s)
7975
* Must match the documentation in virt-p2v(1).
8076
*/
8177
static const enum nbd_server standard_servers[] =
82-
{ QEMU_NBD, QEMU_NBD_NO_SA, NBDKIT, NBDKIT_NO_SA, 0 };
78+
{ NBDKIT, NBDKIT_NO_SA, 0 };
8379

8480
/* After testing the list of servers passed by the user, this is
8581
* server we decide to use.
8682
*/
8783
static enum nbd_server use_server;
8884

89-
static pid_t start_qemu_nbd (const char *device, const char *ipaddr, int port, int *fds, size_t nr_fds);
9085
static pid_t start_nbdkit (const char *device, const char *ipaddr, int port, int *fds, size_t nr_fds);
9186
static int get_local_port (void);
9287
static int open_listening_socket (const char *ipaddr, int **fds, size_t *nr_fds);
@@ -150,11 +145,7 @@ set_nbd_option (const char *opt)
150145
error (EXIT_FAILURE, errno, _("malloc"));
151146

152147
for (i = 0; strs[i] != NULL; ++i) {
153-
if (STREQ (strs[i], "qemu-nbd") || STREQ (strs[i], "qemu"))
154-
cmdline_servers[i] = QEMU_NBD;
155-
else if (STREQ (strs[i], "qemu-nbd-no-sa") || STREQ (strs[i], "qemu-no-sa"))
156-
cmdline_servers[i] = QEMU_NBD_NO_SA;
157-
else if (STREQ (strs[i], "nbdkit"))
148+
if (STREQ (strs[i], "nbdkit"))
158149
cmdline_servers[i] = NBDKIT;
159150
else if (STREQ (strs[i], "nbdkit-no-sa"))
160151
cmdline_servers[i] = NBDKIT_NO_SA;
@@ -205,31 +196,6 @@ test_nbd_servers (void)
205196
#endif
206197

207198
switch (servers[i]) {
208-
case QEMU_NBD: /* with socket activation */
209-
r = system ("qemu-nbd --version"
210-
#ifndef DEBUG_STDERR
211-
" >/dev/null 2>&1"
212-
#endif
213-
" && grep -sq LISTEN_PID `which qemu-nbd`"
214-
);
215-
if (r == 0) {
216-
use_server = servers[i];
217-
goto finish;
218-
}
219-
break;
220-
221-
case QEMU_NBD_NO_SA:
222-
r = system ("qemu-nbd --version"
223-
#ifndef DEBUG_STDERR
224-
" >/dev/null 2>&1"
225-
#endif
226-
);
227-
if (r == 0) {
228-
use_server = servers[i];
229-
goto finish;
230-
}
231-
break;
232-
233199
case NBDKIT: /* with socket activation */
234200
r = system ("nbdkit file --version"
235201
#ifndef DEBUG_STDERR
@@ -294,27 +260,6 @@ start_nbd_server (const char **ipaddr, int *port, const char *device)
294260
pid_t pid;
295261

296262
switch (use_server) {
297-
case QEMU_NBD: /* qemu-nbd with socket activation */
298-
/* Ideally we would bind this socket to "localhost", but that
299-
* requires two listening FDs, and qemu-nbd currently cannot
300-
* support socket activation with two FDs. So we only bind to the
301-
* IPv4 address.
302-
*/
303-
*ipaddr = "127.0.0.1";
304-
*port = open_listening_socket (*ipaddr, &fds, &nr_fds);
305-
if (*port == -1) return -1;
306-
pid = start_qemu_nbd (device, *ipaddr, *port, fds, nr_fds);
307-
for (i = 0; i < nr_fds; ++i)
308-
close (fds[i]);
309-
free (fds);
310-
return pid;
311-
312-
case QEMU_NBD_NO_SA: /* qemu-nbd without socket activation */
313-
*ipaddr = "localhost";
314-
*port = get_local_port ();
315-
if (*port == -1) return -1;
316-
return start_qemu_nbd (device, *ipaddr, *port, NULL, 0);
317-
318263
case NBDKIT: /* nbdkit with socket activation */
319264
*ipaddr = "localhost";
320265
*port = open_listening_socket (*ipaddr, &fds, &nr_fds);
@@ -366,77 +311,6 @@ socket_activation (int *fds, size_t nr_fds)
366311
setenv ("LISTEN_PID", pid_str, 1);
367312
}
368313

369-
/**
370-
* Start a local L<qemu-nbd(1)> process.
371-
*
372-
* If we are using socket activation, C<fds> and C<nr_fds> will
373-
* contain the locally pre-opened file descriptors for this.
374-
* Otherwise if C<fds == NULL> we pass the port number.
375-
*
376-
* Returns the process ID (E<gt> 0) or C<0> if there is an error.
377-
*/
378-
static pid_t
379-
start_qemu_nbd (const char *device,
380-
const char *ipaddr, int port, int *fds, size_t nr_fds)
381-
{
382-
pid_t pid;
383-
char port_str[64];
384-
385-
#if DEBUG_STDERR
386-
fprintf (stderr, "starting qemu-nbd for %s on %s:%d%s\n",
387-
device, ipaddr, port,
388-
fds == NULL ? "" : " using socket activation");
389-
#endif
390-
391-
snprintf (port_str, sizeof port_str, "%d", port);
392-
393-
pid = fork ();
394-
if (pid == -1) {
395-
set_nbd_error ("fork: %m");
396-
return 0;
397-
}
398-
399-
if (pid == 0) { /* Child. */
400-
close (0);
401-
if (open ("/dev/null", O_RDONLY) == -1) {
402-
perror ("open: /dev/null");
403-
_exit (EXIT_FAILURE);
404-
}
405-
406-
if (fds == NULL) { /* without socket activation */
407-
execlp ("qemu-nbd",
408-
"qemu-nbd",
409-
"-r", /* readonly (vital!) */
410-
"-p", port_str, /* listening port */
411-
"-t", /* persistent */
412-
"-f", "raw", /* force raw format */
413-
"-b", ipaddr, /* listen only on loopback interface */
414-
"--cache=unsafe", /* use unsafe caching for speed */
415-
device, /* a device like /dev/sda */
416-
NULL);
417-
perror ("qemu-nbd");
418-
_exit (EXIT_FAILURE);
419-
}
420-
else { /* socket activation */
421-
socket_activation (fds, nr_fds);
422-
423-
execlp ("qemu-nbd",
424-
"qemu-nbd",
425-
"-r", /* readonly (vital!) */
426-
"-t", /* persistent */
427-
"-f", "raw", /* force raw format */
428-
"--cache=unsafe", /* use unsafe caching for speed */
429-
device, /* a device like /dev/sda */
430-
NULL);
431-
perror ("qemu-nbd");
432-
_exit (EXIT_FAILURE);
433-
}
434-
}
435-
436-
/* Parent. */
437-
return pid;
438-
}
439-
440314
/**
441315
* Start a local L<nbdkit(1)> process using the
442316
* L<nbdkit-file-plugin(1)>.

test-virt-p2v-nbdkit.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# You should have received a copy of the GNU General Public License
1616
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1717

18-
# Test virt-p2v in non-GUI mode using nbdkit instead of qemu-nbd.
18+
# Test virt-p2v in non-GUI mode using nbdkit.
1919

2020
set -e
2121

@@ -47,7 +47,7 @@ export PATH=$d:$PATH
4747
# The Linux kernel command line.
4848
cmdline="p2v.server=localhost p2v.name=fedora p2v.disks=$f1,$f2 p2v.o=local p2v.os=$(pwd)/$d p2v.network=em1:wired,other p2v.post="
4949

50-
# Only use nbdkit, disable qemu-nbd.
50+
# Only use nbdkit.
5151
$VG virt-p2v --cmdline="$cmdline" --nbd=nbdkit,nbdkit-no-sa
5252

5353
# Test the libvirt XML metadata and a disk was created.

test-virt-p2v-scp.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# You should have received a copy of the GNU General Public License
1515
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

17-
# This is an scp substitute used by test-virt-p2v.sh.
17+
# This is an scp substitute used by test-virt-p2v-nbdkit.sh.
1818

1919
TEMP=`getopt \
2020
-o 'o:P:' \

test-virt-p2v-ssh.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# You should have received a copy of the GNU General Public License
1515
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

17-
# This is an ssh substitute used by test-virt-p2v.sh.
17+
# This is an ssh substitute used by test-virt-p2v-nbdkit.sh.
1818

1919
TEMP=`getopt \
2020
-o 'l:No:p:R:' \
@@ -37,7 +37,7 @@ while true ; do
3737

3838
# ssh -R 0:localhost:<port> (port forwarding). Don't actually
3939
# port forward, just return the original port number here so that
40-
# the conversion process connects directly to qemu-nbd.
40+
# the conversion process connects directly to nbdkit.
4141
-R)
4242
arg="$2"
4343
port="$(echo $arg | awk -F: '{print $3}')"

0 commit comments

Comments
 (0)