[Libvir] [RFC] 4 of 4 Linux Container support - start container
by Dave Leskovec
This patch adds the start container support. A couple new source files are
added - lxc_container.h and lxc_container.c These contain the setup code that
runs within the container namespace prior to exec'ing the user specified init.
This is a rough outline of the functions involved in starting a container and
the namespace and process under which they run:
lxcVmStart() - runs under callers process
lxcSetupTtyTunnel() - opens a tty and socket pair, tty stored in vmDef
double fork to separate from parent process
grandchild calls lxcStartContainer() see below
parent continues
wait for child process(es)
if child process was successful, change vm state to running
return
lxcStartContainer() - runs in parent namespace, child process from lxcVmStart
Allocate stack for container
clone() - child process will start in lxcChild() see below
exit() - once lxcTtyForward returns, the container has exited
lxcChild() - runs within container, child process from clone()
mount user filesystems
mount container /proc
lxcExecWithTty() - see below, will not return
lxcExecWithTty() - runs within container
lxcSetupContainerTty() - opens tty for container
Set up SIGCHLD handler
fork()
Child calls lxcExecContainerInit() see below
Parent continues
lxcTtyForward - shuttles data between file descriptors until flag is set
in this case between the master end of the container tty
and the master end of the parent tty
exit() - when lxcTtyForward returns, container init has exited
lxcExecContainerInit() - runs within contianer, child process from
lxcExecWithTty
exec containers init
if exec fails, exit()
There's (at least) a couple issues I don't have good solutions for -
1) In this setup with a tty console, we end up with at least 2 processes per
container. One process is running the user init. The CMD listed under ps will
be the init as specified in the XML (unless it changes it to something else).
The other process is forwarding console traffic between the parent and container
pts. The CMD listed in ps depends will depend on the mgmt app used to start the
container. Using virsh, it's something like this outside the container:
root 10141 1 93 22:05 pts/6 00:27:50
/home/dlesko/src/dev/libvirt-ss/libvirt/src/.libs/lt-virsh -c lxc:///
and this inside the container:
root 1 0 93 22:05 pts/6 00:29:19
/home/dlesko/src/dev/libvirt-ss/libvirt/src/.libs/lt-virsh -c lxc:///
This can be a bit confusing. I'm not sure how important it is but it would be
nice to change this to something a little more meaningful as is done by ssh.
2) The container can stall when nothing is connected to the parent side pty and
console output fills up the buffer. To avoid this, we set the parent side pty
to be non-blocking. The result of this is that we will discard any console
output once the buffer has filled. When a user does connect to the console,
they may get a flood of (potentially very) old data. It would be nice to be
able to provide some more recent output once someone connects to the console.
--
Best Regards,
Dave Leskovec
IBM Linux Technology Center
Open Virtualization
16 years, 7 months
[Libvir] [PATCH] Fix MAC address parsing for 1-digit case
by Hiroyuki Kaguchi
libvirt fails in parsing when MAC address like "00:16:3e:12:3:61"
is specified for installation.
This is because virt-install can pass 1-digit (like 3) for
MAC address from Cset:316 for Solaris
But libvirt cannot support this MAC 1-digit (like 3) parameter.
This patch fixes libvirt parsing in the MAC address
against virt-inst Cset:316
Thanks
Signed-off-by: Hiroyuki Kaguchi <fj7025cf(a)aa.jp.fujitsu.com>
? parse_macaddr.patch
Index: src/xml.c
===================================================================
RCS file: /data/cvs/libvirt/src/xml.c,v
retrieving revision 1.113
diff -u -r1.113 xml.c
--- src/xml.c 27 Feb 2008 04:35:08 -0000 1.113
+++ src/xml.c 18 Mar 2008 05:30:14 -0000
@@ -17,6 +17,7 @@
#include <string.h>
#include <stdarg.h>
#include <limits.h>
+#include <ctype.h>
#ifdef WITH_XEN
#include <xs.h>
#endif
@@ -537,6 +538,44 @@
************************************************************************/
#if WITH_XEN
/**
+ * parseMacAddr:
+ * @str: mac addrress string
+ * @addr: mac addrress numbers
+ *
+ * Parse a mac addrress
+ *
+ * Returns 0 in case success or -1 in case of error.
+ */
+static int
+parseMacAddr(const char* str, unsigned char *addr)
+{
+ int i;
+ for (i = 0; i < 6; i++) {
+ char *end_ptr;
+ unsigned long result;
+
+ if (!isdigit(*str) && !isalpha(*str))
+ break;
+
+ result = strtoul(str, &end_ptr, 16);
+
+ if ((end_ptr - str) < 1 || 2 < (end_ptr - str) ||
+ (errno == ERANGE) ||
+ (0xFF < result))
+ break;
+
+ addr[i] = (unsigned char) result;
+
+ if (*end_ptr != ':')
+ return (i == 5) ? 0 : -1;
+
+ str = end_ptr + 1;
+ }
+
+ return -1;
+}
+
+/**
* virtDomainParseXMLGraphicsDescImage:
* @conn: pointer to the hypervisor connection
* @node: node containing graphics description
@@ -1233,22 +1272,8 @@
virBufferAddLit(buf, "(vif ");
if (mac != NULL) {
- unsigned int addr[12];
- int tmp = sscanf((const char *) mac,
- "%01x%01x:%01x%01x:%01x%01x:%01x%01x:%01x%01x:%01x%01x",
- (unsigned int *) &addr[0],
- (unsigned int *) &addr[1],
- (unsigned int *) &addr[2],
- (unsigned int *) &addr[3],
- (unsigned int *) &addr[4],
- (unsigned int *) &addr[5],
- (unsigned int *) &addr[6],
- (unsigned int *) &addr[7],
- (unsigned int *) &addr[8],
- (unsigned int *) &addr[9],
- (unsigned int *) &addr[10],
- (unsigned int *) &addr[11]);
- if (tmp != 12 || strlen((const char *) mac) != 17) {
+ unsigned char addr[6];
+ if (parseMacAddr((const char*) mac, addr) == -1) {
virXMLError(conn, VIR_ERR_INVALID_MAC, (const char *) mac, 0);
goto error;
}
16 years, 7 months
[Libvir] [PATCH] Add new testing framework and the first test to use it.
by Jim Meyering
A week or so ago, I read a bug report on this list with a simple
reproducer + fix that was just begging for a test suite addition.
This change adds framework to make that easy, and adds the first test.
I uncovered problems in tests/Makefile.am along the way and just
posted a patch for that.
This adds most of a portable (bourne-shell-based) test framework that also
provides for convenient isolation of individual tests (so we can easily
parallelize them without worrying one will tromp on files of another).
In a couple years when running "make check" runs hundreds of tests,
you'll definitely want them to run in parallel. The mktempd script is
not new. I first used it in coreutils and parted, but removed it from
coreutils after that package acquired its own C-based implementation.
test-lib.sh is from coreutils, but was inspired by the file by the
same name in git.git's own t/ (tests) directory.
Add new testing framework and the first test to use it.
* tests/Makefile.am (test_scripts): Add vcpupin.
(EXTRA_DIST): Add test-lib.sh.
* tests/test-lib.sh: Testing framework, from coreutils.
* tests/vcpupin: New file.
* build-aux/mktempd: New file, from gnulib.
* bootstrap: Add posix-shell and mktempd to the list of imported modules.
* gnulib/m4/posix-shell.m4: New file, from gnulib.
This also updates lots of files from gnulib, as you can see from the
diffstat output. The diffs below include everything not under gnulib/.
---
bootstrap | 2 +
build-aux/.cvsignore | 1 +
build-aux/mktempd | 132 ++++++++++++++++++++++++++++++++
build-aux/useless-if-before-free | 6 +-
gnulib/lib/Makefile.am | 37 +++++++---
gnulib/lib/alloca.in.h | 4 +-
gnulib/lib/getaddrinfo.c | 2 +-
gnulib/lib/getdelim.c | 6 +-
gnulib/lib/unistd.in.h | 22 +++++-
gnulib/lib/xsize.h | 2 +-
gnulib/m4/absolute-header.m4 | 49 ------------
gnulib/m4/fseeko.m4 | 8 ++-
gnulib/m4/gnulib-cache.m4 | 6 +-
gnulib/m4/gnulib-comp.m4 | 6 +-
gnulib/m4/include_next.m4 | 7 +-
gnulib/m4/lib-link.m4 | 66 ++++++++++++-----
gnulib/m4/posix-shell.m4 | 58 ++++++++++++++
gnulib/m4/unistd_h.m4 | 6 +-
gnulib/tests/Makefile.am | 2 +-
tests/Makefile.am | 7 ++-
tests/test-lib.sh | 155 ++++++++++++++++++++++++++++++++++++++
tests/vcpupin | 37 +++++++++
22 files changed, 521 insertions(+), 100 deletions(-)
create mode 100755 build-aux/mktempd
delete mode 100644 gnulib/m4/absolute-header.m4
create mode 100644 gnulib/m4/posix-shell.m4
create mode 100644 tests/test-lib.sh
create mode 100755 tests/vcpupin
diff --git a/bootstrap b/bootstrap
index d8b79d9..f7b6aec 100755
--- a/bootstrap
+++ b/bootstrap
@@ -79,6 +79,8 @@ $gnulib_tool \
sys_stat vasprintf strndup \
strsep poll gettext getpass \
useless-if-before-free \
+ posix-shell \
+ mktempd \
vc-list-files
rm -f \
diff --git a/build-aux/.cvsignore b/build-aux/.cvsignore
index 1798f40..096cccb 100644
--- a/build-aux/.cvsignore
+++ b/build-aux/.cvsignore
@@ -7,3 +7,4 @@ install-sh
ltmain.sh
missing
mkinstalldirs
+mktempd
diff --git a/build-aux/mktempd b/build-aux/mktempd
new file mode 100755
index 0000000..7ac914b
--- /dev/null
+++ b/build-aux/mktempd
@@ -0,0 +1,132 @@
+#!/bin/sh
+# Create a temporary directory, much like mktemp -d does.
+
+# Copyright (C) 2007-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/>.
+
+# Written by Jim Meyering.
+
+# Usage: mktempd /tmp phoey.XXXXXXXXXX
+
+# First, try to use the mktemp program.
+# Failing that, we'll roll our own mktemp-like function:
+# - try to get random bytes from /dev/urandom
+# - failing that, generate output from a combination of quickly-varying
+# sources and gzip. Ignore non-varying gzip header, and extract
+# "random" bits from there.
+# - given those bits, map to file-name bytes using tr, and try to create
+# the desired directory.
+# - make only $MAX_TRIES attempts
+
+ME=`basename "$0"`
+die() { echo >&2 "$ME: $@"; exit 1; }
+
+MAX_TRIES=4
+
+rand_bytes()
+{
+ n=$1
+
+ chars=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
+
+ dev_rand=/dev/urandom
+ if test -r "$dev_rand"; then
+ # Note: 256-length($chars) == 194; 3 copies of $chars is 186 + 8 = 194.
+ head -c$n "$dev_rand" | tr -c $chars 01234567$chars$chars$chars
+ return
+ fi
+
+ cmds='date; date +%N; free; who -a; w; ps auxww; ps ef; netstat -n'
+ data=` (eval "$cmds") 2>&1 | gzip `
+
+ n_plus_50=`expr $n + 50`
+
+ # Ensure that $data has length at least 50+$n
+ while :; do
+ len=`echo "$data"|wc -c`
+ test $n_plus_50 -le $len && break;
+ data=` (echo "$data"; eval "$cmds") 2>&1 | gzip `
+ done
+
+ echo "$data" \
+ | dd bs=1 skip=50 count=$n 2>/dev/null \
+ | tr -c $chars 01234567$chars$chars$chars
+}
+
+mktempd()
+{
+ case $# in
+ 2);;
+ *) die "Usage: $ME DIR TEMPLATE";;
+ esac
+
+ destdir=$1
+ template=$2
+
+ # Disallow any trailing slash on specified destdir:
+ # it would subvert the post-mktemp "case"-based destdir test.
+ case $destdir in
+ /) ;;
+ */) die "invalid destination dir: remove trailing slash(es)";;
+ esac
+
+ case $template in
+ *XXXX) ;;
+ *) die "invalid template: $template (must have a suffix of at least 4 X's)";;
+ esac
+
+ fail=0
+
+ # First, try to use mktemp.
+ d=`env -u TMPDIR mktemp -d -t -p "$destdir" "$template" 2>/dev/null` \
+ || fail=1
+
+ # The resulting name must be in the specified directory.
+ case $d in "$destdir"*);; *) fail=1;; esac
+
+ # It must have created the directory.
+ test -d "$d" || fail=1
+
+ # It must have 0700 permissions. Handle sticky "S" bits.
+ perms=`ls -dgo "$d" 2>/dev/null|tr S -` || fail=1
+ case $perms in drwx------*) ;; *) fail=1;; esac
+
+ test $fail = 0 && {
+ echo "$d"
+ return
+ }
+
+ # If we reach this point, we'll have to create a directory manually.
+
+ # Get a copy of the template without its suffix of X's.
+ base_template=`echo "$template"|sed 's/XX*$//'`
+
+ # Calculate how many X's we've just removed.
+ nx=`expr length "$template" - length "$base_template"`
+
+ err=
+ i=1
+ while :; do
+ X=`rand_bytes $nx`
+ candidate_dir="$destdir/$base_template$X"
+ err=`mkdir -m 0700 "$candidate_dir" 2>&1` \
+ && { echo "$candidate_dir"; return; }
+ test $MAX_TRIES -le $i && break;
+ i=`expr $i + 1`
+ done
+ die "$err"
+}
+
+mktempd "$@"
diff --git a/build-aux/useless-if-before-free b/build-aux/useless-if-before-free
index eb18483..626d19a 100755
--- a/build-aux/useless-if-before-free
+++ b/build-aux/useless-if-before-free
@@ -2,7 +2,7 @@
# Detect instances of "if (p) free (p);".
# Likewise for "if (p != NULL) free (p);". And with braces.
-my $VERSION = '2008-02-11 08:08'; # UTC
+my $VERSION = '2008-03-12 13:06'; # UTC
# The definition above must lie within the first 8 lines in order
# for the Emacs time-stamp write hook (at end) to update it.
# If you change this file with Emacs, please let the write hook
@@ -123,8 +123,8 @@ EOF
{
if ($line =~
/\b(if\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\)
- (?: \s*$regexp\s*\(\s*\2\s*\)|
- \s*\{\s*$regexp\s*\(\s*\2\s*\)\s*;\s*\}))/sx)
+ (?: \s*$regexp\s*\((?:\s*\([^)]+\))\s*\2\s*\)|
+ \s*\{\s*$regexp\s*\((?:\s*\([^)]+\))\s*\2\s*\)\s*;\s*\}))/sx)
{
$found_match = 1;
$list
diff --git a/tests/test-lib.sh b/tests/test-lib.sh
new file mode 100644
index 0000000..cdbea5d
--- /dev/null
+++ b/tests/test-lib.sh
@@ -0,0 +1,155 @@
+# source this file; set up for tests
+
+# Skip this test if the shell lacks support for functions.
+unset function_test
+eval 'function_test() { return 11; }; function_test'
+if test $? != 11; then
+ echo "$0: /bin/sh lacks support for functions; skipping this test." 1>&2
+ (exit 77); exit 77
+fi
+
+skip_test_()
+{
+ echo "$0: skipping test: $@" 1>&2
+ (exit 77); exit 77
+}
+
+require_acl_()
+{
+ getfacl --version < /dev/null > /dev/null 2>&1 \
+ && setfacl --version < /dev/null > /dev/null 2>&1 \
+ || skip_test_ "This test requires getfacl and setfacl."
+
+ id -u bin > /dev/null 2>&1 \
+ || skip_test_ "This test requires a local user named bin."
+}
+
+require_ulimit_()
+{
+ ulimit_works=yes
+ # Expect to be able to exec a program in 10MB of virtual memory,
+ # but not in 20KB. I chose "date". It must not be a shell built-in
+ # function, so you can't use echo, printf, true, etc.
+ # Of course, in coreutils, I could use $top_builddir/src/true,
+ # but this should be able to work for other projects, too.
+ ( ulimit -v 10000; date ) > /dev/null 2>&1 || ulimit_works=no
+ ( ulimit -v 20; date ) > /dev/null 2>&1 && ulimit_works=no
+
+ test $ulimit_works = no \
+ && skip_test_ "this shell lacks ulimit support"
+}
+
+require_readable_root_()
+{
+ test -r / || skip_test_ "/ is not readable"
+}
+
+# Skip the current test if strace is not available or doesn't work.
+require_strace_()
+{
+ strace -V < /dev/null > /dev/null 2>&1 ||
+ skip_test_ 'no strace program'
+
+ strace -qe unlink echo > /dev/null 2>&1 ||
+ skip_test_ 'strace does not work'
+}
+
+require_built_()
+{
+ skip_=no
+ for i in "$@"; do
+ case " $built_programs " in
+ *" $i "*) ;;
+ *) echo "$i: not built" 1>&2; skip_=yes ;;
+ esac
+ done
+
+ test $skip_ = yes && skip_test_ "required program(s) not built"
+}
+
+uid_is_privileged_()
+{
+ # Make sure id -u succeeds.
+ my_uid=$(id -u) \
+ || { echo "$0: cannot run \`id -u'" 1>&2; return 1; }
+
+ # Make sure it gives valid output.
+ case $my_uid in
+ 0) ;;
+ *[!0-9]*)
+ echo "$0: invalid output (\`$my_uid') from \`id -u'" 1>&2
+ return 1 ;;
+ *) return 1 ;;
+ esac
+}
+
+skip_if_()
+{
+ case $1 in
+ root) skip_test_ must be run as root ;;
+ non-root) skip_test_ must be run as non-root ;;
+ *) ;; # FIXME?
+ esac
+}
+
+require_selinux_()
+{
+ case `ls -Zd .` in
+ '? .'|'unlabeled .')
+ skip_test_ "this system (or maybe just" \
+ "the current file system) lacks SELinux support"
+ ;;
+ esac
+}
+
+very_expensive_()
+{
+ if test "$RUN_VERY_EXPENSIVE_TESTS" != yes; then
+ skip_test_ '
+This test is very expensive, so it is disabled by default.
+To run it anyway, rerun make check with the RUN_VERY_EXPENSIVE_TESTS
+environment variable set to yes. E.g.,
+
+ env RUN_VERY_EXPENSIVE_TESTS=yes make check
+'
+ fi
+}
+
+require_root_() { uid_is_privileged_ || skip_test_ "must be run as root"; }
+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'; }
+
+test_dir_=$(pwd)
+
+this_test_() { echo "./$0" | sed 's,.*/,,'; }
+this_test=$(this_test_)
+
+# This is a stub function that is run upon trap (upon regular exit and
+# interrupt). Override it with a per-test function, e.g., to unmount
+# a partition, or to undo any other global state changes.
+cleanup_() { :; }
+
+mktempd="$abs_top_srcdir/build-aux/mktempd"
+t_=$("$SHELL" "$mktempd" "$test_dir_" lv-$this_test.XXXXXXXXXX) \
+ || error_ "failed to create temporary directory in $test_dir_"
+
+# Run each test from within a temporary sub-directory named after the
+# test itself, and arrange to remove it upon exception or normal exit.
+trap 'st=$?; cleanup_; d='"$t_"';
+ cd '"$test_dir_"' && chmod -R u+rwx "$d" && rm -rf "$d" && exit $st' 0
+trap '(exit $?); exit $?' 1 2 13 15
+
+cd "$t_" || error_ "failed to cd to $t_"
+
+if ( diff --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then
+ compare() { diff -u "$@"; }
+elif ( cmp --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then
+ compare() { cmp -s "$@"; }
+else
+ compare() { cmp "$@"; }
+fi
+
+# Local Variables:
+# indent-tabs-mode: nil
+# End:
diff --git a/tests/vcpupin b/tests/vcpupin
new file mode 100755
index 0000000..b56c7f2
--- /dev/null
+++ b/tests/vcpupin
@@ -0,0 +1,37 @@
+#!/bin/sh
+# ensure that an invalid CPU spec elicits a diagnostic
+
+# 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
+virsh --connect test:///default vcpupin test a 0,1 > out 2>&1
+test $? = 1 || fail=1
+
+cat <<\EOF > exp || fail=1
+error: vcpupin: Invalid or missing vCPU number.
+
+EOF
+
+compare out exp || fail=1
+
+(exit $fail); exit $fail
--
1.5.4.4.482.g16f99
16 years, 7 months
[Libvir] [PATCH] Fix bugs in tests/Makefile.am.
by Jim Meyering
I added a new test (coming in next message), but it failed
due to problems fixed here:
Fix bugs in tests/Makefile.am.
* tests/Makefile.am (abs_top_builddir): Correct invalid
settings of abs_top_builddir and abs_top_srcdir.
Also prepend src/ to PATH, so we test the just-built virsh,
not whatever happens to be in the original $PATH.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 644715e..4810179 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -53,13 +53,15 @@ if ENABLE_XEN_TESTS
TESTS += reconnect
endif
+path_add = $$abs_top_builddir/src$(PATH_SEPARATOR)$$abs_top_builddir/qemud
+
# NB, automake < 1.10 does not provide the real
# abs_top_{src/build}dir variables, so don't rely
# on them here. Fake them with 'pwd'
TESTS_ENVIRONMENT = \
- abs_top_builddir=`pwd`/'$(top_builddir)' \
- abs_top_srcdir=`pwd`/'$(top_srcdir)' \
- PATH="$$abs_top_builddir/qemud$(PATH_SEPARATOR)$$PATH" \
+ abs_top_builddir=`cd '$(top_builddir)'; pwd` \
+ abs_top_srcdir=`cd '$(top_srcdir)'; pwd` \
+ PATH="$(path_add)$(PATH_SEPARATOR)$$PATH" \
$(VG)
valgrind:
--
1.5.4.4.482.g16f99
16 years, 7 months
[Libvir] [PATCH] Sync Makefile rules from coreutils.
by Jim Meyering
This change is a net no-op for "make all" builds.
For "make syntax-check", it adds the getopt.h check, and...
It includes name-space clean-up and VPATH "make distcheck" support in
GNUmakefile, and factoring and renaming changes in Makefile.maint.
Sync Makefile rules from coreutils.
* Makefile.maint: Merge.
* GNUmakefile: Update from coreutils.
---
GNUmakefile | 8 ++-
Makefile.maint | 159 ++++++++++++++++++++++++++++----------------------------
2 files changed, 85 insertions(+), 82 deletions(-)
diff --git a/GNUmakefile b/GNUmakefile
index 9eefe40..157f432 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -4,7 +4,7 @@
# It is necessary if you want to build targets usually of interest
# only to the maintainer.
-# Copyright (C) 2001, 2003, 2006-2007 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2003, 2006-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
@@ -29,11 +29,11 @@ else
SHELL = sh
endif
-have-Makefile := $(shell test -f Makefile && echo yes)
+_have-Makefile := $(shell test -f Makefile && echo yes)
# If the user runs GNU make but has not yet run ./configure,
# give them a diagnostic.
-ifeq ($(have-Makefile),yes)
+ifeq ($(_have-Makefile),yes)
# Make tar archive easier to reproduce.
export TAR_OPTIONS = --owner=0 --group=0 --numeric-owner
@@ -50,6 +50,8 @@ all:
@echo "You must run ./configure before running \`make'." 1>&2
@exit 1
+check dist distcheck install: all
+
endif
# Tell version 3.79 and up of GNU make to not build goals in this
diff --git a/Makefile.maint b/Makefile.maint
index 92cdf29..3a838c5 100644
--- a/Makefile.maint
+++ b/Makefile.maint
@@ -8,25 +8,23 @@ gzip_rsyncable := \
$(shell gzip --help 2>/dev/null|grep rsyncable >/dev/null && echo --rsyncable)
GZIP_ENV = '--no-name --best $(gzip_rsyncable)'
-CVS_LIST = build-aux/vc-list-files
+VC_LIST = build-aux/vc-list-files
-CVS_LIST_EXCEPT = \
-$(CVS_LIST) | if test -f .x-$@; then grep -vEf .x-$@; else grep -v ChangeLog; fi
+VC_LIST_EXCEPT = \
+ $(VC_LIST) | if test -f .x-$@; then grep -vEf .x-$@; else grep -v ChangeLog; fi
# Prevent programs like 'sort' from considering distinct strings to be equal.
# Doing it here saves us from having to set LC_ALL elsewhere in this file.
export LC_ALL = C
# Collect the names of rules starting with `sc_'.
-syntax-check-rules := $(shell sed -n 's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' $(ME))
+syntax-check-rules := $(shell sed -n 's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' \
+ $(srcdir)/$(ME))
.PHONY: $(syntax-check-rules)
-# Checks that don't require cvs.
-# Run `changelog-check' last, as previous test may reveal problems requiring
-# new ChangeLog entries.
local-checks-available = \
po-check copyright-check m4-check author_mark_check \
- changelog-check patch-check strftime-check $(syntax-check-rules) \
+ patch-check strftime-check $(syntax-check-rules) \
makefile_path_separator_check \
makefile-check check-AUTHORS
.PHONY: $(local-checks-available)
@@ -34,23 +32,29 @@ local-checks-available = \
local-check := $(filter-out $(local-checks-to-skip), $(local-checks-available))
syntax-check: $(local-check)
+# @grep -nE '# *include <(limits|std(def|arg|bool))\.h>' \
+# $$(find -type f -name '*.[chly]') && \
+# { echo '$(ME): found conditional include' 1>&2; \
+# exit 1; } || :
-## --------------- ##
-## Sanity checks. ##
-## --------------- ##
+# grep -nE '^# *include <(string|stdlib)\.h>' \
+# $(srcdir)/{lib,src}/*.[chy] && \
+# { echo '$(ME): FIXME' 1>&2; \
+# exit 1; } || :
+# FIXME: don't allow `#include .strings\.h' anywhere
sc_avoid_if_before_free:
@$(srcdir)/build-aux/useless-if-before-free \
$(useless_free_options) \
- $$($(CVS_LIST_EXCEPT)) && \
+ $$($(VC_LIST_EXCEPT)) && \
{ echo '$(ME): found useless "if" before "free" above' 1>&2; \
exit 1; } || :
# Avoid uses of write(2). Either switch to streams (fwrite), or use
# the safewrite wrapper.
sc_avoid_write:
- @if $(CVS_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then \
- grep '\<write *(' $$($(CVS_LIST_EXCEPT) | grep '\.c$$') && \
+ @if $(VC_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then \
+ grep '\<write *(' $$($(VC_LIST_EXCEPT) | grep '\.c$$') && \
{ echo "$(ME): the above files use write;" \
" consider using the safewrite wrapper instead" \
1>&2; exit 1; } || :; \
@@ -58,22 +62,22 @@ sc_avoid_write:
fi
sc_cast_of_argument_to_free:
- @grep -nE '\<free \(\(' $$($(CVS_LIST_EXCEPT)) && \
+ @grep -nE '\<free \(\(' $$($(VC_LIST_EXCEPT)) && \
{ echo '$(ME): don'\''t cast free argument' 1>&2; \
exit 1; } || :
sc_cast_of_x_alloc_return_value:
- @grep -nE '\*\) *x(m|c|re)alloc\>' $$($(CVS_LIST_EXCEPT)) && \
+ @grep -nE '\*\) *x(m|c|re)alloc\>' $$($(VC_LIST_EXCEPT)) && \
{ echo '$(ME): don'\''t cast x*alloc return value' 1>&2; \
exit 1; } || :
sc_cast_of_alloca_return_value:
- @grep -nE '\*\) *alloca\>' $$($(CVS_LIST_EXCEPT)) && \
+ @grep -nE '\*\) *alloca\>' $$($(VC_LIST_EXCEPT)) && \
{ echo '$(ME): don'\''t cast alloca return value' 1>&2; \
exit 1; } || :
sc_space_tab:
- @grep -n '[ ] ' $$($(CVS_LIST_EXCEPT)) && \
+ @grep -n '[ ] ' $$($(VC_LIST_EXCEPT)) && \
{ echo '$(ME): found SPACE-TAB sequence; remove the SPACE' \
1>&2; exit 1; } || :
@@ -81,14 +85,14 @@ sc_space_tab:
# They provide no error checking mechanism.
# Instead, use strto* functions.
sc_prohibit_atoi_atof:
- @grep -nE '\<([fs]?scanf|ato([filq]|ll))\>' $$($(CVS_LIST_EXCEPT)) && \
+ @grep -nE '\<([fs]?scanf|ato([filq]|ll))\>' $$($(VC_LIST_EXCEPT)) && \
{ echo '$(ME): do not use *scan''f, ato''f, ato''i, ato''l, ato''ll, ato''q, or ss''canf' \
1>&2; exit 1; } || :
# Use STREQ rather than comparing strcmp == 0, or != 0.
sc_prohibit_strcmp:
- @grep -nE '! *str''cmp \(|\<str''cmp \([^)]+\) *==' \
- $$($(CVS_LIST_EXCEPT)) && \
+ @grep -nE '! *str''cmp \(|\<str''cmp \([^)]+\) *==' \
+ $$($(VC_LIST_EXCEPT)) && \
{ echo '$(ME): use STREQ in place of the above uses of str''cmp' \
1>&2; exit 1; } || :
@@ -101,66 +105,61 @@ sc_error_exit_success:
exit 1; } || :
sc_file_system:
- @grep -ni 'file''system' $$($(CVS_LIST_EXCEPT)) && \
+ @grep -ni 'file''system' $$($(VC_LIST_EXCEPT)) && \
{ echo '$(ME): found use of "file''system";' \
'rewrite to use "file system"' 1>&2; \
exit 1; } || :
sc_no_have_config_h:
- @grep -n '^# *if.*HAVE''_CONFIG_H' $$($(CVS_LIST_EXCEPT)) && \
+ @grep -n '^# *if.*HAVE''_CONFIG_H' $$($(VC_LIST_EXCEPT)) && \
{ echo '$(ME): found use of HAVE''_CONFIG_H; remove' \
1>&2; exit 1; } || :
# Nearly all .c files must include <config.h>.
sc_require_config_h:
- @if $(CVS_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then \
+ @if $(VC_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then \
grep -L '^# *include <config\.h>' \
- $$($(CVS_LIST_EXCEPT) | grep '\.c$$') \
+ $$($(VC_LIST_EXCEPT) | grep '\.c$$') \
| grep . && \
{ echo '$(ME): the above files do not include <config.h>' \
1>&2; exit 1; } || :; \
else :; \
fi
+# To use this "command" macro, you must first define two shell variables:
+# h: the header, enclosed in <> or ""
+# re: a regular expression that matches IFF something provided by $h is used.
+define _header_without_use
+ h_esc=`echo "$$h"|sed 's/\./\\./'`; \
+ if $(VC_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then \
+ files=$$(grep -l '^# *include '"$$h_esc" \
+ $$($(VC_LIST_EXCEPT) | grep '\.c$$')) && \
+ grep -LE "$$re" $$files | grep . && \
+ { echo "$(ME): the above files include $$h but don't use it" \
+ 1>&2; exit 1; } || :; \
+ else :; \
+ fi
+endef
+
# Prohibit the inclusion of assert.h without an actual use of assert.
sc_prohibit_assert_without_use:
- @if $(CVS_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then \
- files=$$(grep -l '# *include <assert\.h>' \
- $$($(CVS_LIST_EXCEPT) | grep '\.c$$')) && \
- grep -L '\<assert (' $$files \
- | grep . && \
- { echo "$(ME): the above files include <assert.h> but don't use it" \
- 1>&2; exit 1; } || :; \
- else :; \
- fi
+ @h='<assert.h>' re='\<assert *\(' $(_header_without_use)
+
+# Prohibit the inclusion of getopt.h without an actual use.
+sc_prohibit_getopt_without_use:
+ @h='<getopt.h>' re='\<getopt(_long)? *\(' $(_header_without_use)
# Don't include quotearg.h unless you use one of its functions.
sc_prohibit_quotearg_without_use:
- @if $(CVS_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then \
- files=$$(grep -l '# *include "quotearg\.h"' \
- $$($(CVS_LIST_EXCEPT) | grep '\.c$$')) && \
- grep -LE '\<quotearg(_[^ ]+)? \(' $$files \
- | grep . && \
- { echo "$(ME): the above files include "quotearg.h" but don't use it" \
- 1>&2; exit 1; } || :; \
- else :; \
- fi
+ @h='"quotearg.h"' re='\<quotearg(_[^ ]+)? *\(' $(_header_without_use)
# Don't include quote.h unless you use one of its functions.
sc_prohibit_quote_without_use:
- @if $(CVS_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then \
- files=$$(grep -l '# *include "quote\.h"' \
- $$($(CVS_LIST_EXCEPT) | grep '\.c$$')) && \
- grep -LE '\<quote(_n)? \(' $$files \
- | grep . && \
- { echo "$(ME): the above files include "quote.h" but don't use it" \
- 1>&2; exit 1; } || :; \
- else :; \
- fi
+ @h='"quote.h"' re='\<quote(_n)? *\(' $(_header_without_use)
sc_obsolete_symbols:
@grep -nE '\<(HAVE''_FCNTL_H|O''_NDELAY)\>' \
- $$($(CVS_LIST_EXCEPT)) && \
+ $$($(VC_LIST_EXCEPT)) && \
{ echo '$(ME): do not use HAVE''_FCNTL_H or O''_NDELAY' \
1>&2; exit 1; } || :
@@ -194,7 +193,7 @@ endif
# Make sure that none are inadvertently reintroduced.
sc_prohibit_jm_in_m4:
@grep -nE 'jm_[A-Z]' \
- $$($(CVS_LIST) m4 |grep '\.m4$$'; echo /dev/null) && \
+ $$($(VC_LIST) m4 |grep '\.m4$$'; echo /dev/null) && \
{ echo '$(ME): do not use jm_ in m4 macro names' \
1>&2; exit 1; } || :
@@ -202,8 +201,8 @@ sc_root_tests:
@if test -d tests \
&& grep check-root tests/Makefile.am>/dev/null 2>&1; then \
t1=sc-root.expected; t2=sc-root.actual; \
- grep -nl '^PRIV_CHECK_ARG=require-root' \
- $$($(CVS_LIST) tests) |sed s,tests,., |sort > $$t1; \
+ grep -nl '^require_root_$$' \
+ $$($(VC_LIST) tests) |sed s,tests,., |sort > $$t1; \
sed -n 's, cd \([^ ]*\) .*MAKE..check TESTS=\(.*\),./\1/\2,p' \
$(srcdir)/tests/Makefile.am |sort > $$t2; \
diff -u $$t1 $$t2 || diff=1; \
@@ -242,7 +241,7 @@ headers_with_interesting_macro_defs = \
sc_always_defined_macros: .re-defmac
@if test -f $(srcdir)/src/system.h; then \
trap 'rc=$$?; rm -f .re-defmac; exit $$rc' 0 1 2 3 15; \
- grep -f .re-defmac $$($(CVS_LIST)) \
+ grep -f .re-defmac $$($(VC_LIST)) \
&& { echo '$(ME): define the above via some gnulib .h file' \
1>&2; exit 1; } || :; \
fi
@@ -262,7 +261,7 @@ sc_system_h_headers: .re-list
@if test -f $(srcdir)/src/system.h; then \
trap 'rc=$$?; rm -f .re-list; exit $$rc' 0 1 2 3 15; \
grep -nE -f .re-list \
- $$($(CVS_LIST) src | \
+ $$($(VC_LIST) src | \
grep -Ev '((copy|system)\.h|parse-gram\.c)$$') \
&& { echo '$(ME): the above are already included via system.h'\
1>&2; exit 1; } || :; \
@@ -271,12 +270,12 @@ sc_system_h_headers: .re-list
sc_sun_os_names:
@grep -nEi \
'solaris[^[:alnum:]]*2\.(7|8|9|[1-9][0-9])|sunos[^[:alnum:]][6-9]' \
- $$($(CVS_LIST_EXCEPT)) && \
+ $$($(VC_LIST_EXCEPT)) && \
{ echo '$(ME): found misuse of Sun OS version numbers' 1>&2; \
exit 1; } || :
sc_the_the:
- @grep -ni '\<the ''the\>' $$($(CVS_LIST_EXCEPT)) && \
+ @grep -ni '\<the ''the\>' $$($(VC_LIST_EXCEPT)) && \
{ echo '$(ME): found use of "the ''the";' 1>&2; \
exit 1; } || :
@@ -284,7 +283,7 @@ sc_tight_scope:
$(MAKE) -C src $@
sc_trailing_blank:
- @grep -n '[ ]$$' $$($(CVS_LIST_EXCEPT)) && \
+ @grep -n '[ ]$$' $$($(VC_LIST_EXCEPT)) && \
{ echo '$(ME): found trailing blank(s)' \
1>&2; exit 1; } || :
@@ -294,7 +293,7 @@ sc_trailing_blank:
longopt_re = --[a-z][0-9A-Za-z-]*(\[?=[0-9A-Za-z-]*\]?)?
sc_two_space_separator_in_usage:
@grep -nE '^ *(-[A-Za-z],)? $(longopt_re) [^ ].*\\$$' \
- $$($(CVS_LIST_EXCEPT)) && \
+ $$($(VC_LIST_EXCEPT)) && \
{ echo "$(ME): help2man requires at least two spaces between"; \
echo "$(ME): an option and its description"; \
1>&2; exit 1; } || :
@@ -309,32 +308,32 @@ err_func_re = \
# "%s", _("no storage vol w..."
sc_unmarked_diagnostics:
@grep -nE \
- '\<(vshError|error) \([^"]*"[^"]*[a-z]{3}' $$($(CVS_LIST_EXCEPT)) \
+ '\<(vshError|error) \([^"]*"[^"]*[a-z]{3}' $$($(VC_LIST_EXCEPT)) \
| grep -v '_''(' && \
{ echo '$(ME): found unmarked diagnostic(s)' 1>&2; \
exit 1; } || :
- @{ grep -nE '\<$(err_func_re) *\(.*;$$' $$($(CVS_LIST_EXCEPT)); \
- grep -A1 -nE '\<$(err_func_re) *\(.*,$$' $$($(CVS_LIST_EXCEPT)); } \
+ @{ grep -nE '\<$(err_func_re) *\(.*;$$' $$($(VC_LIST_EXCEPT)); \
+ grep -A1 -nE '\<$(err_func_re) *\(.*,$$' $$($(VC_LIST_EXCEPT)); } \
| sed 's/_("[^"][^"]*"//;s/[ ]"%s"//' \
| grep '[ ]"' && \
{ echo '$(ME): found unmarked diagnostic(s)' 1>&2; \
exit 1; } || :
sc_prohibit_virBufferAdd_with_string_literal:
- @grep -nE '\<virBufferAdd *\([^,]+, *"[^"]' $$($(CVS_LIST_EXCEPT)) && \
+ @grep -nE '\<virBufferAdd *\([^,]+, *"[^"]' $$($(VC_LIST_EXCEPT)) && \
{ echo '$(ME): use virBufferAddLit, not virBufferAdd,' \
'with a string literal' 1>&2; exit 1; } || :
# Avoid useless parentheses like those in this example:
# #if defined (SYMBOL) || defined (SYM2)
sc_useless_cpp_parens:
- @grep -n '^# *if .*defined *(' $$($(CVS_LIST_EXCEPT)) && \
+ @grep -n '^# *if .*defined *(' $$($(VC_LIST_EXCEPT)) && \
{ echo '$(ME): found useless parentheses in cpp directive' \
1>&2; exit 1; } || :
# Require the latest GPL.
sc_GPL_version:
- @grep -n 'either ''version [^3]' $$($(CVS_LIST_EXCEPT)) && \
+ @grep -n 'either ''version [^3]' $$($(VC_LIST_EXCEPT)) && \
{ echo '$(ME): GPL vN, N!=3' 1>&2; exit 1; } || :
# Ensure that the c99-to-c89 patch applies cleanly.
@@ -410,12 +409,16 @@ po-check:
grep -E -v '^(#|$$)' po/POTFILES.in \
| grep -v '^src/false\.c$$' | sort > $@-1; \
files=; \
- for file in $$($(CVS_LIST_EXCEPT)); do \
+ for file in $$($(VC_LIST_EXCEPT)); do \
+ case $$file in \
+ djgpp/* | man/*) continue;; \
+ */c99-to-c89.diff) continue;; \
+ esac; \
case $$file in \
*.[ch]) \
base=`expr " $$file" : ' \(.*\)\..'`; \
{ test -f $$base.l || test -f $$base.y; } && continue;; \
- *) continue;; \
+ *) continue;; \
esac; \
files="$$files $$file"; \
done; \
@@ -447,16 +450,14 @@ makefile_path_separator_check:
# Check that `make alpha' will not fail at the end of the process.
writable-files:
if test -d $(release_archive_dir); then :; else \
- mkdir $(release_archive_dir); \
+ for file in $(distdir).tar.gz \
+ $(release_archive_dir)/$(distdir).tar.gz; do \
+ test -e $$file || continue; \
+ test -w $$file \
+ || { echo ERROR: $$file is not writable; fail=1; }; \
+ done; \
+ test "$$fail" && exit 1 || :
fi
- for file in $(distdir).tar.gz $(xd-delta) \
- $(release_archive_dir)/$(distdir).tar.gz \
- $(release_archive_dir)/$(xd-delta); do \
- test -e $$file || continue; \
- test -w $$file \
- || { echo ERROR: $$file is not writable; fail=1; }; \
- done; \
- test "$$fail" && exit 1 || :
v_etc_file = lib/version-etc.c
sample-test = tests/sample-test
--
1.5.4.4.482.g16f99
16 years, 7 months
[Libvir] Announcement : Enomalism 2.0 Alpha Released
by Reuven Cohen
This is an general announcement of the release of Enomalism 2.0 (Alpha) Now
Available for Download.
--
Enomaly, Inc. is pleased to announce the Alpha release of the Enomalism
Elastic Computing Platform. The Enomalism v2.0 Alpha has been completely
redeveloped from the ground up and further builds on the concept of "
Elastic / Cloud Computing". The platform extensively uses libvirt to manage
several virtual environments including Amazon EC2 (Elastic Compute Cloud).
Over the coming weeks there will be ongoing developments as we continue to
improve the application. We hope to move to a stable "BETA" within a couple
weeks. The current release is considered "Alpha" and should be used at your
own risk.
New Enomalism Features include:
* Web Services API - RESTful
* Automated VM Deployment with Elastic Valet
* Multi-Server Support
* Virtual Cluster Engine
* Extensible system monitoring integration
* Flexible business process management with SOA (jBPM)
* Integrated appliance / module repository
* Extended User / Group Management
* Elastic Dashboard / Portal Framework
* System Metering (Utility / Chargeback)
* Increased Virtual Machine / Hypervisor Support
o Xen, KVM, Qemu, OpenVZ, Amazon EC2 * (Ec2 Module)
* Support for installation in Linux & Windows
* New Open Source License (AGPL)
For installation Documentation and core distribution download, please visit
http://trac.enomalism.com/enomalism/
BETA TESTERS
We are currently seeking BETA testers to assist with the following tasks
* Interface Debugging CSS, JS (IE7,Firefox)
* Platform Testing (Linux,Windows,BSD,OSX)
* Cluster Testing
* Amazon EC2 Testing
* Repository / Appliance Testing
* Module Testing
* User Management Testing
* REST API Testing
* Anything else that needs fixing.
If you are interested in lending a hand, please visit the Enomalism forums
at
http://www.enomalism.com/resources/community-center/
Reuven Cohen
Chief Technologist, Enomaly Inc.
www.enomaly.com :: 212 203 4734 x 1
16 years, 7 months
[Libvir] [PATCH] * qemud/remote.c: Don't include <getopt.h>. Not used.
by Jim Meyering
I had a few in-progress changes from a week or two ago,
and am clearing the decks.
I added a new build-checking rule (coming separately)
and it exposed an unnecessary include:
* qemud/remote.c: Don't include <getopt.h>. Not used.
diff --git a/qemud/remote.c b/qemud/remote.c
index 85df9cd..c7db5fa 100644
--- a/qemud/remote.c
+++ b/qemud/remote.c
@@ -41,7 +41,6 @@
#include <syslog.h>
#include <string.h>
#include <errno.h>
-#include <getopt.h>
#include <ctype.h>
#include <fnmatch.h>
--
1.5.4.4.482.g16f99
16 years, 7 months
[Libvir] [PATCH] Implement memory operations for qemu driver
by Cole Robinson
The attached patch implements the following operations for the qemu driver:
virDomainGetMaxMemory
virDomainSetMaxMemory
virDomainSetMemory
A few questions/comments:
1) I changed maxmem and memory in the qemu_vm_def struct to unsigned long
to match the public api for memory values. Seems to work, but not sure
if there are any undesirable side effects to this.
2) Should SetMaxMem be able to be called on a running guest? This code
allows it, since maxmem is basically a metavalue that doesn't directly
affect a guest.
3) Should maxmem be able to be set lower than the currently allocated mem?
This code does not allow this. If this changed, would also need to take
into account how we would handle this if we can change the maxmem while
the guest is running. After rethinking, we probably should be able to
do this, but I haven't changed the code.
Thanks,
Cole
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index a196bb8..f6ae06b 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -1650,7 +1650,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
(vm->def->graphicsType == QEMUD_GRAPHICS_SDL ? 0 : 1)) + /* graphics */
(vm->migrateFrom[0] ? 3 : 0); /* migrateFrom */
- snprintf(memory, sizeof(memory), "%d", vm->def->memory/1024);
+ snprintf(memory, sizeof(memory), "%lu", vm->def->memory/1024);
snprintf(vcpus, sizeof(vcpus), "%d", vm->def->vcpus);
if (!(*argv = malloc(sizeof(**argv) * (len+1))))
@@ -2820,9 +2820,9 @@ char *qemudGenerateXML(virConnectPtr conn,
virUUIDFormat(uuid, uuidstr);
if (virBufferVSprintf(buf, " <uuid>%s</uuid>\n", uuidstr) < 0)
goto no_memory;
- if (virBufferVSprintf(buf, " <memory>%d</memory>\n", def->maxmem) < 0)
+ if (virBufferVSprintf(buf, " <memory>%lu</memory>\n", def->maxmem) < 0)
goto no_memory;
- if (virBufferVSprintf(buf, " <currentMemory>%d</currentMemory>\n", def->memory) < 0)
+ if (virBufferVSprintf(buf, " <currentMemory>%lu</currentMemory>\n", def->memory) < 0)
goto no_memory;
if (virBufferVSprintf(buf, " <vcpu>%d</vcpu>\n", def->vcpus) < 0)
goto no_memory;
diff --git a/src/qemu_conf.h b/src/qemu_conf.h
index 12aa6ae..c1aae75 100644
--- a/src/qemu_conf.h
+++ b/src/qemu_conf.h
@@ -193,8 +193,8 @@ struct qemud_vm_def {
unsigned char uuid[VIR_UUID_BUFLEN];
char name[QEMUD_MAX_NAME_LEN];
- int memory;
- int maxmem;
+ unsigned long memory;
+ unsigned long maxmem;
int vcpus;
int noReboot;
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 2b4c2a6..215f4c4 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -1765,6 +1765,66 @@ static char *qemudDomainGetOSType(virDomainPtr dom) {
return type;
}
+/* Returns max memory in kb, 0 if error */
+static unsigned long qemudDomainGetMaxMemory(virDomainPtr dom) {
+ struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData;
+ struct qemud_vm *vm = qemudFindVMByUUID(driver, dom->uuid);
+
+ if (!vm) {
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN,
+ "no domain with matching uuid '%s'", dom->uuid);
+ return 0;
+ }
+
+ return vm->def->maxmem;
+}
+
+static int qemudDomainSetMaxMemory(virDomainPtr dom, unsigned long memory) {
+ struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData;
+ struct qemud_vm *vm = qemudFindVMByUUID(driver, dom->uuid);
+
+ if (!vm) {
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN,
+ "no domain with matching uuid '%s'", dom->uuid);
+ return -1;
+ }
+
+ if (memory < vm->def->maxmem) {
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_ARG,
+ "cannot set max memory lower than current memory");
+ return -1;
+ }
+
+ vm->def->maxmem = memory;
+ return 0;
+}
+
+static int qemudDomainSetMemory(virDomainPtr dom, unsigned long memory) {
+ struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData;
+ struct qemud_vm *vm = qemudFindVMByUUID(driver, dom->uuid);
+
+ if (!vm) {
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN,
+ "no domain with matching uuid '%s'", dom->uuid);
+ return -1;
+ }
+
+ if (qemudIsActiveVM(vm)) {
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR,
+ "cannot set memory of an active domain");
+ return -1;
+ }
+
+ if (memory > vm->def->maxmem) {
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_ARG,
+ "cannot set memory higher than max memory");
+ return -1;
+ }
+
+ vm->def->memory = memory;
+ return 0;
+}
+
static int qemudDomainGetInfo(virDomainPtr dom,
virDomainInfoPtr info) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData;
@@ -2886,9 +2946,9 @@ static virDriver qemuDriver = {
NULL, /* domainReboot */
qemudDomainDestroy, /* domainDestroy */
qemudDomainGetOSType, /* domainGetOSType */
- NULL, /* domainGetMaxMemory */
- NULL, /* domainSetMaxMemory */
- NULL, /* domainSetMemory */
+ qemudDomainGetMaxMemory, /* domainGetMaxMemory */
+ qemudDomainSetMaxMemory, /* domainSetMaxMemory */
+ qemudDomainSetMemory, /* domainSetMemory */
qemudDomainGetInfo, /* domainGetInfo */
qemudDomainSave, /* domainSave */
qemudDomainRestore, /* domainRestore */
16 years, 7 months