[Libvir] [PATCH 1/2] lxc: start container
by Dave Leskovec
This is a repost of the start container support. Changes from the last version:
* Report an error when allocation for init string fails in lxcExecContainerInit()
* Change to find by name in lxcStartDomain()
* Move tty forwarding process outside of the container. This allows
consolidating the forwarding into a single process at a later time. This also
means the the container init process as specified by the user now runs as the
container root process with pid = 1. The tty setup will require some (hopefully
minor) modifications when pts namespaces are enabled.
* Add header comments to a number of the functions.
This is an updated rough outline of the functions involved in starting a
container and the namespace and process under which they run:
lxcVmStart() - runs under libvirtd process
lxcSetupTtyTunnel() - opens and configures parent tty
lxcSetupContainerTty() - opens container tty
fork
child process calls lxcTtyForward() see below
parent continues
lxcStartContainer - see below
return
lxcStartContainer() - runs in parent namespace, libvirtd process
Allocate stack for container
clone() - child process will start in lxcChild() see below
return
lxcChild() - runs within container, child process from clone()
mount user filesystems
mount container /proc
lxcExecWithTty() - see below, will not return
lxcExecWithTty() - runs within container, root process
lxcSetContainerStdio - sets container tty as primary console
lxcExecContainerInit - see below, should not return
exit()
lxcExecContainerInit() - runs within container, root process
exec containers init
if exec fails, exit()
Thanks!
--
Best Regards,
Dave Leskovec
IBM Linux Technology Center
Open Virtualization
16 years, 7 months
[libvir] [PATCH] Extra symbol in openvz_conf.c
by Anton Protopopov
Hi all,
there is an extra symbol ('_') in openvz_conf.c: openvzParseXML,
which leads to compile error [does anybody compile libvirt with
openvz support :)] Patch fixes it.
16 years, 7 months
[Libvir] Release of libvirt-0.4.2
by Daniel Veillard
A lot of things accumulated since last month, especially bug fixes,
so it was time for a new release, available at
ftp://libvirt.org/libvirt/
I didn't list Linux Container support in the new features as this isn't
complete yet (but looks like it will be shortly)
* New features:
- memory operation for QEmu/KVM driver (Cole Robinson)
- new routed networking schemas (Mads Olesen)
* Documentation:
- storage documentation fixes (Atsushi Sakai)
- many typo cleanups (Atsushi Sakai)
- string fixes (Francesco Tombolini)
* Bug fixes:
- pointer errors in qemu (Jim Meyering)
- iSCSI login fix (Chris Lalancette)
- well formedness error in test driver capabilities (Cole Robinson)
- fixes cleanup code when daemon exits (Daniel Berrange)
- CD Rom change on live QEmu/KVM domains (Cole Robinson)
- setting scheduler parameter is forbidden for read-only (Saori Fukuta)i
- fixes for TAP devices (Daniel Berrange)
- assorted storage driver fixes (Daniel Berrange)
- Makefile fixes (Jim Meyering)
- Xen-3.2 hypercall fix
- fix iptables rules to avoid blocking traffic within virtual network (Daniel Berrange)
- XML output fix for directory pools (Daniel Berrange)
- remove dandling domain/net/conn pointers from error data
- do not ask polkit auth when root (Daniel Berrange)
- handling of fork and pipe errors when starting the daemon (Richard Jones)
* Improvements:
- better validation of MAC addresses (Jim Meyering and Hiroyuki Kaguchi)
- virsh vcpupin error report (Shigeki Sakamoto)
- keep boot tag on HVM domains (Cole Robinson)
- virsh non-root should not be limited to read only anymore (Daniel Berrange)
- switch to polkit-auth from polkit-grant (Daniel Berrange)
- better handling of missing SElinux data (Daniel Berrange and Jim Meyering)
- cleanup of the connection opening logic (Daniel Berrange)
- first bits of Linux Containers support (Dave Leskovec)
- scheduler API support via xend (Saori Fukuta)
- improvement of the testing framework and first tests (Jim Meyering)
- missing error messages from virsh parameters validation (Shigeki Sakamoto)
- improve support of older iscsiadm command (Chris Lalancette)
- move linux container support in the daemon (Dan Berrange)
- older awk implementation support (Mike Gerdts)
- NUMA support in test driver (Cole Robinson)
- xen and hvm added to test driver capabilities (Cole Robinson)
* Code cleanup:
- remove unused getopt header (Jim Meyering)
- mark more strings as translatable (Guido Günther and Jim Meyering)
- convert error strings to something meaningful and translatable (Jim Meyering)
- Linux Containers code cleanup
- last error initializer (Guido Günther)
Quite a lot of changes in a month, thanks a lot for everybody who contributed
with ideas, reports or patches !
Daniel
--
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard | virtualization library http://libvirt.org/
veillard(a)redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
16 years, 7 months
[Libvir] [PATCH] (for discussion only) KVM migration v1
by Richard W.M. Jones
This patch implements KVM to KVM migration. It is for discussion
only, partly because it doesn't work for some reason I can't quite
work out at the moment.
We implement a second version of the migration protocol. This second
version has two differences:
(1) Prepare step is replaced by Prepare2, which passes the domain XML.
As explained previously this is required for KVM because we use this
on the target host to recreate the precise qemu-kvm command line as on
the source host.
(2) Finish step is replaced by Finish2. There are two differences
here: firstly Finish2 is always called on the destination host, even
if the migration failed. Secondly the return code from the migration
(Perform step) is passed to Finish2. This is required for KVM
migration because if the migration failed we need to tear down the
empty qemu shell, otherwise failed migrations could leave effectively
zombie qemu processes around.
libvirt.c:virDomainMigrate function has been changed so that it can
support either form of migration protocol, and the Xen driver
continues to use version 1. The changes here are pretty minor, and
there are no changes to the Xen driver.
The additional code involves implementing Prepare2 / Finish2 in the
remote protocol, and of course implementing migration in the qemu
driver itself.
A final word about the parameters to virDomainMigrate.
- flags is ignored. All KVM migrations are "live", it doesn't matter
if you supply the live flag or not.
- desturi may optionally be used to control the TCP port used for
migration. If desturi is NULL then a TCP port is chosen at
random (or in future, some suitable secure method will be used
instead). If desturi is set to "tcp://hostname:port" then the
given port number is used, and hostname is expected to be the
hostname or IP address of the target server.
You cannot do localhost->localhost migrations (even though this is
supported by KVM) because libvirtd doesn't like you creating two VMs
with the same UUID, even if only temporarily. So to test this you
really need two machines, or at least two instances of libvirtd
configured not to stomp on each other.
Rich.
--
Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
16 years, 7 months
[Libvir] <model>e1000</model> - Specifying model in XML Configs
by Henri Cook
Hi guys,
I just tried to port a few customers over to this libvirt setup i'm
hoping to run and I couldn't get their machines started because there's
no mechanism to specify a model in the XML!
I know redhat have changed KVM's default driver to e1000, which I think
is the one I like the most and almost if not all of my VMs use. Ubuntu
haven't done that yet however!
Is there a model directive in the latest version? In the works? Just so
I know which solution I should pursue (updating libvirt or harassing
ubuntu to change the default)
Thanks,
Henri
16 years, 7 months
[Libvir] Don't fail to read a file because it's non-seekable (e.g., a pipe).
by Jim Meyering
FYI, I expect to add fread_file_lim or something like it to gnulib,
and it already has some unit tests (passed).
I removed the "* tab-width: 4" line because it seriously
mangled the code that I initially added. Besides saying "tab-width 4"
is contradictory with the "indent-tabs-mode: nil" setting.
This fix addresses a problem exposed in an ovirt script whereby
trying to use bash process substitution, e.g., in
virsh define <(command to generate xml)
would fail.
Oops. Just noticed that the indentation in the added function
(gnulib style) is not consistent with the rest of the file.
I'll adjust that before committing, of course.
Don't fail to read a file because it's non-seekable (e.g., a pipe).
* src/util.c (fread_file_lim): New function.
(__virFileReadAll): Use fread_file_lim, rather than requiring
that stat.st_size provide a usable file size.
* tests/read-non-seekable: New test, for the above.
* tests/Makefile.am (test_scripts): Add read-non-seekable.
* tests/test-lib.sh (mkfifo_or_skip_): New helper function.
Signed-off-by: Jim Meyering <meyering(a)redhat.com>
---
src/util.c | 87 +++++++++++++++++++++++++++++++++++++---------
tests/Makefile.am | 1 +
tests/read-non-seekable | 47 +++++++++++++++++++++++++
tests/test-lib.sh | 12 ++++++
4 files changed, 130 insertions(+), 17 deletions(-)
create mode 100755 tests/read-non-seekable
diff --git a/src/util.c b/src/util.c
index 0667780..e951eb5 100644
--- a/src/util.c
+++ b/src/util.c
@@ -49,6 +49,10 @@
#include "util-lib.c"
+#ifndef MIN
+# define MIN(a, b) ((a) < (b) ? (a) : (b))
+#endif
+
#define MAX_ERROR_LEN 1024
#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
@@ -283,6 +287,61 @@ virExecNonBlock(virConnectPtr conn,
#endif /* __MINGW32__ */
+/* Like gnulib's fread_file, but read no more than the specified maximum
+ number of bytes. If the length of the input is <= max_len, and
+ upon error while reading that data, it works just like fread_file. */
+static char *
+fread_file_lim (FILE *stream, size_t max_len, size_t *length)
+{
+ char *buf = NULL;
+ size_t alloc = 0;
+ size_t size = 0;
+ int save_errno;
+
+ for (;;)
+ {
+ size_t count;
+ size_t requested;
+
+ if (size + BUFSIZ + 1 > alloc)
+ {
+ char *new_buf;
+
+ alloc += alloc / 2;
+ if (alloc < size + BUFSIZ + 1)
+ alloc = size + BUFSIZ + 1;
+
+ new_buf = realloc (buf, alloc);
+ if (!new_buf)
+ {
+ save_errno = errno;
+ break;
+ }
+
+ buf = new_buf;
+ }
+
+ /* Ensure that (size + requested <= max_len); */
+ requested = MIN (size < max_len ? max_len - size : 0,
+ alloc - size - 1);
+ count = fread (buf + size, 1, requested, stream);
+ size += count;
+
+ if (count != requested || requested == 0)
+ {
+ save_errno = errno;
+ if (ferror (stream))
+ break;
+ buf[size] = '\0';
+ *length = size;
+ return buf;
+ }
+ }
+
+ free (buf);
+ errno = save_errno;
+ return NULL;
+}
int __virFileReadAll(const char *path,
int maxlen,
@@ -291,6 +350,8 @@ int __virFileReadAll(const char *path,
FILE *fh;
struct stat st;
int ret = -1;
+ size_t len;
+ char *s;
if (!(fh = fopen(path, "r"))) {
virLog("Failed to open file '%s': %s",
@@ -309,28 +370,21 @@ int __virFileReadAll(const char *path,
goto error;
}
- if (st.st_size > maxlen) {
- virLog("File '%s' is too large %d, max %d", path, (int)st.st_size, maxlen);
- goto error;
- }
-
- *buf = malloc(st.st_size + 1);
- if (*buf == NULL) {
- virLog("Failed to allocate data");
+ s = fread_file_lim(fh, maxlen+1, &len);
+ if (s == NULL) {
+ virLog("Failed to read '%s': %s", path, strerror (errno));
goto error;
}
- if ((ret = fread(*buf, st.st_size, 1, fh)) != 1) {
- free(*buf);
- *buf = NULL;
- virLog("Failed to read config file '%s': %s",
- path, strerror(errno));
+ if (len > maxlen || (int)len != len) {
+ free(s);
+ virLog("File '%s' is too large %d, max %d",
+ path, (int)st.st_size, maxlen);
goto error;
}
- (*buf)[st.st_size] = '\0';
-
- ret = st.st_size;
+ *buf = s;
+ ret = len;
error:
if (fh)
@@ -739,6 +793,5 @@ virParseMacAddr(const char* str, unsigned char *addr)
* indent-tabs-mode: nil
* c-indent-level: 4
* c-basic-offset: 4
- * tab-width: 4
* End:
*/
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 901e88a..ca12b84 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -46,6 +46,7 @@ noinst_PROGRAMS = xmlrpctest xml2sexprtest sexpr2xmltest virshtest conftest \
test_scripts = \
daemon-conf \
int-overflow \
+ read-non-seekable \
vcpupin
EXTRA_DIST += $(test_scripts)
diff --git a/tests/read-non-seekable b/tests/read-non-seekable
new file mode 100755
index 0000000..9bb4a21
--- /dev/null
+++ b/tests/read-non-seekable
@@ -0,0 +1,47 @@
+#!/bin/sh
+# ensure that certain file-reading commands can handle non-seekable files
+
+# Copyright (C) 2008 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+if test "$VERBOSE" = yes; then
+ set -x
+ virsh --version
+fi
+
+. $srcdir/test-lib.sh
+
+fail=0
+
+cat <<\EOF > dom
+<domain type='test' id='2'>
+ <name>t2</name>
+ <uuid>004b96e1-2d78-c30f-5aa5-000000000000</uuid>
+ <memory>8388608</memory>
+ <vcpu>2</vcpu>
+ <on_reboot>restart</on_reboot>
+ <on_poweroff>destroy</on_poweroff>
+ <on_crash>restart</on_crash>
+</domain>
+EOF
+
+virsh -c test:///default define dom > /dev/null || fail=1
+
+mkfifo_or_skip_ fifo
+cat dom > fifo &
+
+virsh -c test:///default define fifo > /dev/null || fail=1
+
+(exit $fail); exit $fail
diff --git a/tests/test-lib.sh b/tests/test-lib.sh
index cdbea5d..a007109 100644
--- a/tests/test-lib.sh
+++ b/tests/test-lib.sh
@@ -120,6 +120,18 @@ skip_if_root_() { uid_is_privileged_ && skip_test_ "must be run as non-root"; }
error_() { echo "$0: $@" 1>&2; (exit 1); exit 1; }
framework_failure() { error_ 'failure in testing framework'; }
+mkfifo_or_skip_()
+{
+ test $# = 1 || framework_failure
+ if ! mkfifo "$1"; then
+ # Make an exception of this case -- usually we interpret framework-creation
+ # failure as a test failure. However, in this case, when running on a SunOS
+ # system using a disk NFS mounted from OpenBSD, the above fails like this:
+ # mkfifo: cannot make fifo `fifo-10558': Not owner
+ skip_test_ 'NOTICE: unable to create test prerequisites'
+ fi
+}
+
test_dir_=$(pwd)
this_test_() { echo "./$0" | sed 's,.*/,,'; }
--
1.5.5.rc2.7.g144a
16 years, 7 months