[libvirt] [sandbox 0/3] Getting dhcp to work on openSUSE

Hi all, Two of these patches are getting dhclient and netconfig to work properly in virt-sandboxes running on openSUSE. af_packet module is required to get dhclient to run and /dev/fd is needed to get openSUSE's netconfig and network script to properly update /etc/resolv.conf. Cédric Bosdonnat (3): Add af_packet module for dhclient to work Only show dhclient output in debug mode. Create /dev/fd symlink to /proc/self/fd libvirt-sandbox/libvirt-sandbox-builder-machine.c | 2 ++ libvirt-sandbox/libvirt-sandbox-init-common.c | 10 +++++++++- libvirt-sandbox/libvirt-sandbox-init-qemu.c | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) -- 2.1.4

dhclient requires the af_packet to be loaded to work. Some distros have it built-in, others like openSUSE have it as a module. Adding the module to the init image, makes sure we have it. Of course no error should be raised if the module can't be found. --- libvirt-sandbox/libvirt-sandbox-builder-machine.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libvirt-sandbox/libvirt-sandbox-builder-machine.c b/libvirt-sandbox/libvirt-sandbox-builder-machine.c index a458882..43372b5 100644 --- a/libvirt-sandbox/libvirt-sandbox-builder-machine.c +++ b/libvirt-sandbox/libvirt-sandbox-builder-machine.c @@ -181,6 +181,8 @@ static gchar *gvir_sandbox_builder_machine_mkinitrd(GVirSandboxConfig *config, #if 0 gvir_sandbox_config_initrd_add_module(initrd, "virtio_balloon.ko"); #endif + /* For dhclient to work */ + gvir_sandbox_config_initrd_add_module(initrd, "af_packet.ko"); if (!gvir_sandbox_builder_initrd_construct(builder, initrd, targetfile, error)) goto cleanup; -- 2.1.4

On Mon, Aug 24, 2015 at 12:17:04PM +0200, Cédric Bosdonnat wrote:
dhclient requires the af_packet to be loaded to work. Some distros have it built-in, others like openSUSE have it as a module. Adding the module to the init image, makes sure we have it. Of course no error should be raised if the module can't be found. --- libvirt-sandbox/libvirt-sandbox-builder-machine.c | 2 ++ 1 file changed, 2 insertions(+)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

We surely don't want to mix dhclient and user's command output, make sure dhclient is verbose only if LIBVIRT_SANDBOX_DEBUG is set to 2. --- libvirt-sandbox/libvirt-sandbox-init-common.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libvirt-sandbox/libvirt-sandbox-init-common.c b/libvirt-sandbox/libvirt-sandbox-init-common.c index d35f760..6008739 100644 --- a/libvirt-sandbox/libvirt-sandbox-init-common.c +++ b/libvirt-sandbox/libvirt-sandbox-init-common.c @@ -159,11 +159,19 @@ start_shell(void) static gboolean start_dhcp(const gchar *devname, GError **error) { - const gchar *argv[] = { "/sbin/dhclient", "-v", "--no-pid", devname, NULL }; + const gchar *argv[5]; + size_t nargs = 0; gboolean ret; sigset_t newset; sigset_t oldset; + argv[nargs++] = "/sbin/dhclient"; + if (debug) + argv[nargs++] = "-v"; + argv[nargs++] = "--no-pid"; + argv[nargs++] = devname; + argv[nargs++] = NULL; + sigemptyset(&newset); sigaddset(&newset, SIGHUP); -- 2.1.4

On Mon, Aug 24, 2015 at 12:17:05PM +0200, Cédric Bosdonnat wrote:
We surely don't want to mix dhclient and user's command output, make sure dhclient is verbose only if LIBVIRT_SANDBOX_DEBUG is set to 2. --- libvirt-sandbox/libvirt-sandbox-init-common.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Some applications and scripts are using /dev/fd. Netconfig and openSUSE network scripts are in such a case, getting the symlink makes them work. --- libvirt-sandbox/libvirt-sandbox-init-qemu.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libvirt-sandbox/libvirt-sandbox-init-qemu.c b/libvirt-sandbox/libvirt-sandbox-init-qemu.c index cd6055a..5ecc3de 100644 --- a/libvirt-sandbox/libvirt-sandbox-init-qemu.c +++ b/libvirt-sandbox/libvirt-sandbox-init-qemu.c @@ -356,6 +356,12 @@ main(int argc ATTR_UNUSED, char **argv ATTR_UNUSED) /* Main special filesystems */ mount_other("/dev", "devtmpfs", 0755); + if (symlink("/proc/self/fd", "/dev/fd") < 0) { + fprintf(stderr, "libvirt-sandbox-init-qemu: %s: failed to create /dev/fd symlink: %s\n", + __func__, strerror(errno)); + exit_poweroff(); + } + mount_other_opts("/dev/pts", "devpts", "gid=5,mode=620,ptmxmode=000", 0755); mount_other("/sys", "sysfs", 0755); mount_other("/proc", "proc", 0755); -- 2.1.4

On Mon, Aug 24, 2015 at 12:17:06PM +0200, Cédric Bosdonnat wrote:
Some applications and scripts are using /dev/fd. Netconfig and openSUSE network scripts are in such a case, getting the symlink makes them work. --- libvirt-sandbox/libvirt-sandbox-init-qemu.c | 6 ++++++ 1 file changed, 6 insertions(+)
ACK but do we need this for LXC too ? Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Mon, 2015-08-24 at 11:26 +0100, Daniel P. Berrange wrote:
On Mon, Aug 24, 2015 at 12:17:06PM +0200, Cédric Bosdonnat wrote:
Some applications and scripts are using /dev/fd. Netconfig and openSUSE network scripts are in such a case, getting the symlink makes them work. --- libvirt-sandbox/libvirt-sandbox-init-qemu.c | 6 ++++++ 1 file changed, 6 insertions(+)
ACK
but do we need this for LXC too ?
No, libvirt's lxc driver does it for us in lxcContainerSetupDevices. -- Cedric
participants (3)
-
Cedric Bosdonnat
-
Cédric Bosdonnat
-
Daniel P. Berrange