Richard W.M. Jones
2010-Aug-24 10:56 UTC
[Libguestfs] [PATCH] New APIs: set-network and get-network to enable network support.
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://et.redhat.com/~rjones/libguestfs/ See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html -------------- next part -------------->From 56f426a0be9b0c2e6551ae7a841d236c5909b488 Mon Sep 17 00:00:00 2001From: Richard Jones <rjones at redhat.com> Date: Tue, 24 Aug 2010 11:53:40 +0100 Subject: [PATCH] New APIs: set-network and get-network to enable network support. guestfs_set_network (g, true) enables network support in the appliance. --- src/generator.ml | 19 +++++++++++++++++++ src/guestfs-internal.h | 1 + src/guestfs.c | 13 +++++++++++++ src/guestfs.pod | 5 +++++ src/launch.c | 8 ++++++++ 5 files changed, 46 insertions(+), 0 deletions(-) diff --git a/src/generator.ml b/src/generator.ml index 233f8bd..00caa6a 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -1289,6 +1289,25 @@ for a filesystem to be shared between operating systems. Please read L<guestfs(3)/INSPECTION> for more details. See also C<guestfs_inspect_get_mountpoints>."); + ("set_network", (RErr, [Bool "network"]), -1, [FishAlias "network"], + [], + "set enable network flag", + "\ +If C<network> is true, then the network is enabled in the +libguestfs appliance. The default is false. + +This affects whether commands are able to access the network +(see L<guestfs(3)/RUNNING COMMANDS>). + +You must call this before calling C<guestfs_launch>, otherwise +it has no effect."); + + ("get_network", (RBool "network", []), -1, [], + [], + "get enable network flag", + "\ +This returns the enable network flag."); + ] (* daemon_functions are any functions which cause some action diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h index b534b6a..e37c9c2 100644 --- a/src/guestfs-internal.h +++ b/src/guestfs-internal.h @@ -98,6 +98,7 @@ struct guestfs_h int autosync; int direct; int recovery_proc; + int enable_network; char *path; /* Path to kernel, initrd. */ char *qemu; /* Qemu binary. */ diff --git a/src/guestfs.c b/src/guestfs.c index 74de38c..eaacd39 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -601,6 +601,19 @@ guestfs__get_recovery_proc (guestfs_h *g) return g->recovery_proc; } +int +guestfs__set_network (guestfs_h *g, int v) +{ + g->enable_network = !!v; + return 0; +} + +int +guestfs__get_network (guestfs_h *g) +{ + return g->enable_network; +} + void guestfs_set_log_message_callback (guestfs_h *g, guestfs_log_message_cb cb, void *opaque) diff --git a/src/guestfs.pod b/src/guestfs.pod index 4dafb07..590c768 100644 --- a/src/guestfs.pod +++ b/src/guestfs.pod @@ -358,6 +358,11 @@ The command will be running in limited memory. =item * +The network may not be available unless you enable it +(see L</guestfs_set_network>). + +=item * + Only supports Linux guests (not Windows, BSD, etc). =item * diff --git a/src/launch.c b/src/launch.c index 1e1ea8e..df78b1a 100644 --- a/src/launch.c +++ b/src/launch.c @@ -410,6 +410,14 @@ guestfs__launch (guestfs_h *g) add_cmdline (g, "-device"); add_cmdline (g, "virtserialport,chardev=channel0,name=org.libguestfs.channel.0"); + /* Enable user networking. */ + if (g->enable_network) { + add_cmdline (g, "-net"); + add_cmdline (g, "user,vlan=0,net=" NETWORK); + add_cmdline (g, "-net"); + add_cmdline (g, "nic,model=" NET_IF ",vlan=0"); + } + #define LINUX_CMDLINE \ "panic=1 " /* force kernel to panic if daemon exits */ \ "console=ttyS0 " /* serial console */ \ -- 1.7.1
Daniel P. Berrange
2010-Aug-24 11:13 UTC
[Libguestfs] [PATCH] New APIs: set-network and get-network to enable network support.
On Tue, Aug 24, 2010 at 11:56:00AM +0100, Richard W.M. Jones wrote:> > -- > Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones > libguestfs lets you edit virtual machines. Supports shell scripting, > bindings from many languages. http://et.redhat.com/~rjones/libguestfs/ > See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html> >From 56f426a0be9b0c2e6551ae7a841d236c5909b488 Mon Sep 17 00:00:00 2001 > From: Richard Jones <rjones at redhat.com> > Date: Tue, 24 Aug 2010 11:53:40 +0100 > Subject: [PATCH] New APIs: set-network and get-network to enable network support. > > guestfs_set_network (g, true) enables network support in the appliance. > --- > src/generator.ml | 19 +++++++++++++++++++ > src/guestfs-internal.h | 1 + > src/guestfs.c | 13 +++++++++++++ > src/guestfs.pod | 5 +++++ > src/launch.c | 8 ++++++++ > 5 files changed, 46 insertions(+), 0 deletions(-)> diff --git a/src/launch.c b/src/launch.c > index 1e1ea8e..df78b1a 100644 > --- a/src/launch.c > +++ b/src/launch.c > @@ -410,6 +410,14 @@ guestfs__launch (guestfs_h *g) > add_cmdline (g, "-device"); > add_cmdline (g, "virtserialport,chardev=channel0,name=org.libguestfs.channel.0"); > > + /* Enable user networking. */ > + if (g->enable_network) { > + add_cmdline (g, "-net"); > + add_cmdline (g, "user,vlan=0,net=" NETWORK); > + add_cmdline (g, "-net"); > + add_cmdline (g, "nic,model=" NET_IF ",vlan=0"); > + }If you can rely on QEMU >= 0.12 then you should switch to using -netdev, since -net is going the way of the Dodo in upstream QEMU. eg -netdev user,id=hostnet0 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:1b:a1:fc FWIW, I'd say this gives better performance, but with user mode that's not true. With TAP networking this syntax would allow for zero-copy since it eliminates the vlan multiplexor Regards, Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Apparently Analagous Threads
- [PATCH 00/10] Remove the need for vmchannel
- [PATCH] Fix networking in the appliance
- [PATCH 0/3] RFC: Allow use of external QEMU process with libguestfs
- [PATCH] Enable new-style -chardev ... guestfwd command line
- [PATCH 0/5] Assorted patches to add virtio-scsi support.