diff mbox

kvm tools: Improve init within a custom filesystem

Message ID 1314202772-16252-1-git-send-email-levinsasha928@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sasha Levin Aug. 24, 2011, 4:19 p.m. UTC
This patch adds the following improvements:

 * Automatically start dhcpcd. Since we provide usermode netowrking
we should make it fully transparent to the user.

 * Mount more kernel filesystems such as debugfs and shm.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/builtin-setup.c |    4 ++++
 tools/kvm/guest/init.c    |    7 +++++++
 2 files changed, 11 insertions(+), 0 deletions(-)

Comments

Avi Kivity Aug. 24, 2011, 5:30 p.m. UTC | #1
On 08/24/2011 07:19 PM, Sasha Levin wrote:
> This patch adds the following improvements:
>
>   * Automatically start dhcpcd. Since we provide usermode netowrking
> we should make it fully transparent to the user.

On my hosts, I have dhclient instead of dhcpd.

>
> +	puts("Running dhcpcd...");
> +
> +	system("dhcpcd -z eth* -A");
> +
>   	puts("Starting '/bin/sh'...");
>

Better not  depend on interface names, instead get the interface names 
from the kernel.
Sasha Levin Aug. 24, 2011, 5:41 p.m. UTC | #2
On Wed, 2011-08-24 at 20:30 +0300, Avi Kivity wrote:
> On 08/24/2011 07:19 PM, Sasha Levin wrote:
> > This patch adds the following improvements:
> >
> >   * Automatically start dhcpcd. Since we provide usermode netowrking
> > we should make it fully transparent to the user.
> 
> On my hosts, I have dhclient instead of dhcpd.
> 

I was wondering if we should bring our own tiny dhcp client instead of
assuming the host has one.

Would it be better than assuming the host has it and then trying to
figure out which one?

> >
> > +	puts("Running dhcpcd...");
> > +
> > +	system("dhcpcd -z eth* -A");
> > +
> >   	puts("Starting '/bin/sh'...");
> >
> 
> Better not  depend on interface names, instead get the interface names 
> from the kernel.
> 

Will do.
Pekka Enberg Aug. 24, 2011, 6:17 p.m. UTC | #3
On Wed, Aug 24, 2011 at 8:41 PM, Sasha Levin <levinsasha928@gmail.com> wrote:
>> On my hosts, I have dhclient instead of dhcpd.
>
> I was wondering if we should bring our own tiny dhcp client instead of
> assuming the host has one.
>
> Would it be better than assuming the host has it and then trying to
> figure out which one?

That'd be awesome if we can keep it small and clean.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Avi Kivity Aug. 24, 2011, 6:51 p.m. UTC | #4
On 08/24/2011 08:41 PM, Sasha Levin wrote:
> On Wed, 2011-08-24 at 20:30 +0300, Avi Kivity wrote:
> >  On 08/24/2011 07:19 PM, Sasha Levin wrote:
> >  >  This patch adds the following improvements:
> >  >
> >  >    * Automatically start dhcpcd. Since we provide usermode netowrking
> >  >  we should make it fully transparent to the user.
> >
> >  On my hosts, I have dhclient instead of dhcpd.
> >
>
> I was wondering if we should bring our own tiny dhcp client instead of
> assuming the host has one.
>
> Would it be better than assuming the host has it and then trying to
> figure out which one?
>

You don't really need a dhcp client, since you already have a 
communication channel - the kernel command line.  Read the IP address 
and other info from there, and poke it into the interface.

There is also the ip= kernel parameter, but I don't know if it works 
with a modular network driver.

I suggest something like "kvmtool.nic.$macaddr=$ip/$netmask 
kvmtool.defaultroute=$gateway" - this is interface name agnostic.
Pekka Enberg Aug. 24, 2011, 6:59 p.m. UTC | #5
On Wed, Aug 24, 2011 at 9:51 PM, Avi Kivity <avi@redhat.com> wrote:
> On 08/24/2011 08:41 PM, Sasha Levin wrote:
>>
>> On Wed, 2011-08-24 at 20:30 +0300, Avi Kivity wrote:
>> >  On 08/24/2011 07:19 PM, Sasha Levin wrote:
>> >  >  This patch adds the following improvements:
>> >  >
>> >  >    * Automatically start dhcpcd. Since we provide usermode netowrking
>> >  >  we should make it fully transparent to the user.
>> >
>> >  On my hosts, I have dhclient instead of dhcpd.
>> >
>>
>> I was wondering if we should bring our own tiny dhcp client instead of
>> assuming the host has one.
>>
>> Would it be better than assuming the host has it and then trying to
>> figure out which one?
>>
>
> You don't really need a dhcp client, since you already have a communication
> channel - the kernel command line.  Read the IP address and other info from
> there, and poke it into the interface.
>
> There is also the ip= kernel parameter, but I don't know if it works with a
> modular network driver.
>
> I suggest something like "kvmtool.nic.$macaddr=$ip/$netmask
> kvmtool.defaultroute=$gateway" - this is interface name agnostic.

We had "ip=dhcp" enabled for a while:

https://github.com/penberg/linux-kvm/commit/f0aec23a91368e916a53e6072f2173bb481b1544

Unfortunately the option makes nfsroot override the 9p rootfs. I guess
we could just fix that.

                         Pekka
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/tools/kvm/builtin-setup.c b/tools/kvm/builtin-setup.c
index 3c6ad48..347398d 100644
--- a/tools/kvm/builtin-setup.c
+++ b/tools/kvm/builtin-setup.c
@@ -100,12 +100,16 @@  error_close_in:
 
 static const char *guestfs_dirs[] = {
 	"/dev",
+	"/dev/pts",
+	"/dev/shm",
 	"/etc",
 	"/home",
 	"/host",
 	"/proc",
 	"/root",
 	"/sys",
+	"/sys/kernel",
+	"/sys/kernel/debug",
 	"/var",
 	"/var/lib",
 	"/virt",
diff --git a/tools/kvm/guest/init.c b/tools/kvm/guest/init.c
index 837acfb..caa671d 100644
--- a/tools/kvm/guest/init.c
+++ b/tools/kvm/guest/init.c
@@ -22,6 +22,9 @@  static void do_mounts(void)
 	mount("", "/sys", "sysfs", 0, NULL);
 	mount("proc", "/proc", "proc", 0, NULL);
 	mount("devtmpfs", "/dev", "devtmpfs", 0, NULL);
+	mount("debugfs", "/sys/kernel/debug", "debugfs", 0, NULL);
+	mount("shm", "/dev/shm", "tmpfs", 0, NULL);
+	mount("devpts", "/dev/pts", "devpts", 0, NULL);
 }
 
 int main(int argc, char *argv[])
@@ -30,6 +33,10 @@  int main(int argc, char *argv[])
 
 	do_mounts();
 
+	puts("Running dhcpcd...");
+
+	system("dhcpcd -z eth* -A");
+
 	puts("Starting '/bin/sh'...");
 
 	run_process("/bin/sh");