Skip to contentSkip to conversation

kvm tools: Use kernel dhcp for network autoconfiguration

PATCH In review Sasha Levin 3 participants 7 messages Sep 14, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 kvm tools: Use kernel dhcp for network autoconfiguration

This patch removes the manual/usermode dhcp client configuration and instead uses the DHCP client built within the kernel.

Since this client is tightly integrated with NFS (if NFS config is set), we will add a specific NFS root addr in our DHCP offer to point it to a non existent address so that we won't hang trying to poke it for our root.

---
 tools/kvm/builtin-run.c     |    2 +-
 tools/kvm/guest/init.c      |    4 ----
 tools/kvm/guest/setnet.sh   |   22 ----------------------
 tools/kvm/include/kvm/uip.h |    2 ++
 tools/kvm/net/uip/dhcp.c    |    8 ++++++++
 5 files changed, 11 insertions(+), 27 deletions(-)
 delete mode 100755 tools/kvm/guest/setnet.sh
tools/kvm/builtin-run.c +1 -1
index 591fd77..465bbe7 100644
@@ -764,7 +764,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 	if (using_rootfs) {
 		strcat(real_cmdline, " root=/dev/root rw rootflags=rw,trans=virtio,version=9p2000.L rootfstype=9p");
 		if (custom_rootfs)
-			strcat(real_cmdline, " init=/virt/init");
+			strcat(real_cmdline, " init=/virt/init ip=dhcp");
 	} else if (!strstr(real_cmdline, "root=")) {
 		strlcat(real_cmdline, " root=/dev/vda rw ", sizeof(real_cmdline));
 	}
tools/kvm/guest/init.c +0 -4
index 7733026..837acfb 100644
@@ -30,10 +30,6 @@ int main(int argc, char *argv[])
 
 	do_mounts();
 
-	puts("Setting up network...");
-
-	system("/bin/sh virt/setnet.sh");
-
 	puts("Starting '/bin/sh'...");
 
 	run_process("/bin/sh");
tools/kvm/guest/setnet.sh deleted +0 -22
deleted file mode 100755
index 3da9c22..0000000
@@ -1,22 +0,0 @@
-for f in /sys/class/net/*; do
-	type=`cat $f/type`
-	if [ $type -eq 1 ]; then
-		f=${f#/sys/class/net/}
-
-		eval "dhcpcd -A $f 2> /dev/null"
-		if [ $? -eq 0 ]; then
-			exit
-		fi
-
-		eval "dhclient $f 2> /dev/null"
-		if [ $? -eq 0 ]; then
-			exit
-		fi
-
-		ifconfig $f 192.168.33.15
-		route add default 192.168.33.1
-		echo "nameserver 8.8.8.8" >> /etc/resolv.conf
-
-		exit
-	fi
-done
tools/kvm/include/kvm/uip.h +2 -0
index 344ec09..3501d36 100644
@@ -58,6 +58,8 @@
 #define UIP_DHCP_TAG_SUBMASK_LEN	4
 #define UIP_DHCP_TAG_ROUTER		3
 #define UIP_DHCP_TAG_ROUTER_LEN		4
+#define UIP_DHCP_TAG_ROOT		17
+#define UIP_DHCP_TAG_ROOT_LEN		4
 #define UIP_DHCP_TAG_DNS_SERVER		6
 #define UIP_DHCP_TAG_DNS_SERVER_LEN	4
 #define UIP_DHCP_TAG_DOMAIN_NAME	15
tools/kvm/net/uip/dhcp.c +8 -0
index bd3c53b..e91a7c7 100644
@@ -2,6 +2,8 @@
 
 #include <arpa/inet.h>
 
+#define EMPTY_ADDR "0.0.0.0"
+
 static inline bool uip_dhcp_is_discovery(struct uip_dhcp *dhcp)
 {
 	return (dhcp->option[2] == UIP_DHCP_DISCOVER &&
@@ -127,6 +129,12 @@ static int uip_dhcp_fill_option(struct uip_info *info, struct uip_dhcp *dhcp, in
 	*addr		= htonl(info->host_ip);
 	i		+= UIP_DHCP_TAG_ROUTER_LEN;
 
+	opt[i++]	= UIP_DHCP_TAG_ROOT;
+	opt[i++]	= strlen(EMPTY_ADDR);
+	addr		= (u32 *)&opt[i];
+	strncpy((void *) addr, EMPTY_ADDR, strlen(EMPTY_ADDR));
+	i		+= strlen(EMPTY_ADDR);
+
 	i 		= uip_dhcp_fill_option_name_and_server(info, opt, i);
 
 	opt[i++]	= UIP_DHCP_TAG_END;
Signature · 1 line
1.7.6.1
#1 lore raw

PATCH 2/2 kvm tools: Don't use i8042 AUX port

We currently don't have sufficient support for mouse, this patch disables it by default to prevent the delay when booting.

It should be removed once sufficient mouse support is added.

---
 tools/kvm/builtin-run.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
tools/kvm/builtin-run.c +2 -1
index 465bbe7..2795115 100644
@@ -736,7 +736,8 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 		vidmode = 0;
 
 	memset(real_cmdline, 0, sizeof(real_cmdline));
-	strcpy(real_cmdline, "notsc noapic noacpi pci=conf1 reboot=k panic=1 i8042.direct=1 i8042.dumbkbd=1 i8042.nopnp=1");
+	strcpy(real_cmdline, "notsc noapic noacpi pci=conf1 reboot=k panic=1 i8042.direct=1 "
+				"i8042.dumbkbd=1 i8042.nopnp=1 i8042.noaux=1");
 	if (vnc || sdl) {
 		strcat(real_cmdline, " video=vesafb console=tty0");
 	} else
Signature · 1 line
1.7.6.1
#2 lore raw

Re: [PATCH 2/2] kvm tools: Don't use i8042 AUX port

Quoted 15 lines · Sasha Levin

We currently don't have sufficient support for mouse, this patch disables it by default to prevent the delay when booting.

It should be removed once sufficient mouse support is added.

---
 tools/kvm/builtin-run.c |    3 ++-

 1 files changed, 2 insertions(+), 1 deletions(-)
tools/kvm/builtin-run.c +0 -0
index 465bbe7..2795115 100644

tools/kvm/builtin-run.c int kvm_cmd_run(int argc, const char **argv, const char *prefix) · line 743

Quoted 9 lines
tools/kvm/builtin-run.c +2 -1
@@ -736,7 +736,8 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
                vidmode = 0;
 
        memset(real_cmdline, 0, sizeof(real_cmdline));
-       strcpy(real_cmdline, "notsc noapic noacpi pci=conf1 reboot=k panic=1 i8042.direct=1 i8042.dumbkbd=1 i8042.nopnp=1");
+       strcpy(real_cmdline, "notsc noapic noacpi pci=conf1 reboot=k panic=1 i8042.direct=1 "
+                               "i8042.dumbkbd=1 i8042.nopnp=1 i8042.noaux=1");
        if (vnc || sdl) {
                strcat(real_cmdline, " video=vesafb console=tty0");
        } else

What's the problem? IIRC mouse works just fine in VNC mode?

#3 lore raw

Re: [PATCH 2/2] kvm tools: Don't use i8042 AUX port

Quoted 18 lines · Pekka Enberg
Quoted 17 lines · Sasha Levin

We currently don't have sufficient support for mouse, this patch disables it by default to prevent the delay when booting.

It should be removed once sufficient mouse support is added.

---
 tools/kvm/builtin-run.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
tools/kvm/builtin-run.c +0 -0
index 465bbe7..2795115 100644
@@ -736,7 +736,8 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
               vidmode = 0;
 
Quoted 9 lines

tools/kvm/builtin-run.c int kvm_cmd_run(int argc, const char **argv, const char *prefix) · line 743

Quoted 7 lines
tools/kvm/builtin-run.c +2 -1
       memset(real_cmdline, 0, sizeof(real_cmdline));
-       strcpy(real_cmdline, "notsc noapic noacpi pci=conf1 reboot=k panic=1 i8042.direct=1 i8042.dumbkbd=1 i8042.nopnp=1");
+       strcpy(real_cmdline, "notsc noapic noacpi pci=conf1 reboot=k panic=1 i8042.direct=1 "
+                               "i8042.dumbkbd=1 i8042.nopnp=1 i8042.noaux=1");
       if (vnc || sdl) {
               strcat(real_cmdline, " video=vesafb console=tty0");
       } else

What's the problem? IIRC mouse works just fine in VNC mode?

The problem is that it causes a pretty long delay (~5-6 sec) during boot.

VNC mouse could use some more love before I'd say it's good, one example that the host mouse and guest mouse aren't synced.

Signature · 1 line
Sasha.
#4 lore raw

Re: [PATCH 2/2] kvm tools: Don't use i8042 AUX port

Quoted 5 lines · Sasha Levin

The problem is that it causes a pretty long delay (~5-6 sec) during boot.

VNC mouse could use some more love before I'd say it's good, one example that the host mouse and guest mouse aren't synced.

Maybe but it's likely good enough for the people who are actually using it. We can't just disable it silently!

So I think we should enable AUX if user asks for VNC, no?

Pekka

#5 lore raw

Re: [PATCH 2/2] kvm tools: Don't use i8042 AUX port

Quoted 11 lines · Pekka Enberg
Quoted 5 lines · Sasha Levin

The problem is that it causes a pretty long delay (~5-6 sec) during boot.

VNC mouse could use some more love before I'd say it's good, one example that the host mouse and guest mouse aren't synced.

Maybe but it's likely good enough for the people who are actually using it. We can't just disable it silently!

So I think we should enable AUX if user asks for VNC, no?

Yup, let's make it disabled only when !vnc and !sdl.

Signature · 1 line
Sasha.
Acked-by on v1 1/2
#6 lore raw
In reply to Sasha Levin
Quoted 8 lines · Sasha Levin

This patch removes the manual/usermode dhcp client configuration and instead uses the DHCP client built within the kernel.

Since this client is tightly integrated with NFS (if NFS config is set), we will add a specific NFS root addr in our DHCP offer to point it to a non existent address so that we won't hang trying to poke it for our root.

Signature · 1 line
Asias He