pygrub: cope better with big files in the guest.

Only read the first megabyte of a configuration file (grub etc.) and read the
kernel and ramdisk files from the guest in one megabyte pieces so pygrub
doesn't use a lot of memory if the files are large.  With --not-really option
check that the chosen kernel and ramdisk files exist.  If there are problems
writing the copy of the kernel or ramdisk, delete the copied files and exit in
case they have filled the filesystem.

Signed-off-by: Michael Young <m.a.young@durham.ac.uk>
Acked-by: Matt Wilson <msw@amazon.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
hotplug/Linux: use flock based locking

In the normal case of a single domain booting with one disk, the disk hotplug
script will fire once. In this case taking out the lock will never cause a
sleep because there's no other concurrent invocations. If a domain has 4 disks
configured, then the hotplug script will fire 4 times, all 4 invocations at
pretty much the same time. If there is even a little load on the system, the
locking function in the shell script will sleep for a few seconds - as many as
5 seconds, or potentially even time out & fail completely.

If say 4 or even more domains each with 4 disks start up at once, that's 16
invocations of the hotplug script running at once. There will be a lot of
sleep's done & because of the very coarse 1 second granularity the delay can
add up significantly.

The change to using flock() removes the arbitrary 1 second sleep, so the very
instant once hotplug script finishes, another can start & there is no repeated
attempts & failures to lock which would add more delay.

In addition the current locking implementation would allow two processes get
the lock simultaneously if one decided the other had timed out.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Zhigang Wang <zhigang.x.wang@oracle.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
xl: Allow use of /dev/null with xl create to enable command-line definition

xm allows specifying /dev/null as the domain configuration argument to its
create option; add same functionality to xl. xl treats the configuration
argument /dev/null as a special case.  This allows specifying an entire
domain configuration on the command line.

Signed-off-by: W. Michael Petullo <mike@flyn.org>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
[ ijc -- ported to xen-unstable from 4.1 ]
Committed-by: Ian Campbell <ian.campbell@citrix.com>
tools/configure.ac: add version check for glib2

xen-unstable fails to build in a SLES10SP4 environment since a long time
because the included version of glib is slightly older than the required
glib version. According to the glib docs version 2.12 includes base64
support, but SLES10 is shipped with glib 2.8.6:

qemu-timer-common.o: In function `init_get_clock':
/usr/src/packages/BUILD/xen-4.2.25432/non-dbg/tools/qemu-xen-dir/qemu-timer-common.c:57:
undefined reference to `clock_gettime'
qga/guest-agent-commands.o: In function `qmp_guest_file_write':
qga/guest-agent-commands.c:249: undefined reference to `g_base64_decode'
qga/guest-agent-commands.o: In function `qmp_guest_file_read':
qga/guest-agent-commands.c:224: undefined reference to `g_base64_encode'
collect2: ld returned 1 exit status
make[3]: *** [qemu-ga] Error 1

Add a version check to toplevel configure to require at least glib 2.12.
This makes sure configure can detect the condition early instead of
failing later in the middle of tools build when qemu-upstream errors
out.

Please rerun autoconf after applying this.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
Acked-by: Roger Pau Monn? <roger.pau@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
tools/m4: add AC_LANG_SOURCE to fix autoconf warnings

I see these warnings with autoconf 2.68, add AC_LANG_SOURCE as suggested
by upstream documentation.

...
 # bash autogen.sh
configure.ac:141: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body
../../lib/autoconf/lang.m4:194: AC_LANG_CONFTEST is expanded from...
../../lib/autoconf/general.m4:2662: _AC_LINK_IFELSE is expanded from...
../../lib/autoconf/general.m4:2679: AC_LINK_IFELSE is expanded from...
../../lib/m4sugar/m4sh.m4:606: AS_IF is expanded from...
../../lib/autoconf/general.m4:2032: AC_CACHE_VAL is expanded from...
../../lib/autoconf/general.m4:2053: AC_CACHE_CHECK is expanded from...
m4/pthread.m4:21: AX_CHECK_PTHREAD is expanded from...
configure.ac:141: the top level
configure.ac:142: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body
../../lib/autoconf/lang.m4:194: AC_LANG_CONFTEST is expanded from...
../../lib/autoconf/general.m4:2662: _AC_LINK_IFELSE is expanded from...
../../lib/autoconf/general.m4:2679: AC_LINK_IFELSE is expanded from...
../../lib/m4sugar/m4sh.m4:606: AS_IF is expanded from...
../../lib/autoconf/general.m4:2032: AC_CACHE_VAL is expanded from...
../../lib/autoconf/general.m4:2053: AC_CACHE_CHECK is expanded from...
m4/ptyfuncs.m4:1: AX_CHECK_PTYFUNCS is expanded from...
configure.ac:142: the top level
configure.ac:141: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body
../../lib/autoconf/lang.m4:194: AC_LANG_CONFTEST is expanded from...
../../lib/autoconf/general.m4:2662: _AC_LINK_IFELSE is expanded from...
../../lib/autoconf/general.m4:2679: AC_LINK_IFELSE is expanded from...
../../lib/m4sugar/m4sh.m4:606: AS_IF is expanded from...
../../lib/autoconf/general.m4:2032: AC_CACHE_VAL is expanded from...
../../lib/autoconf/general.m4:2053: AC_CACHE_CHECK is expanded from...
m4/pthread.m4:21: AX_CHECK_PTHREAD is expanded from...
configure.ac:141: the top level
configure.ac:142: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body
../../lib/autoconf/lang.m4:194: AC_LANG_CONFTEST is expanded from...
../../lib/autoconf/general.m4:2662: _AC_LINK_IFELSE is expanded from...
../../lib/autoconf/general.m4:2679: AC_LINK_IFELSE is expanded from...
../../lib/m4sugar/m4sh.m4:606: AS_IF is expanded from...
../../lib/autoconf/general.m4:2032: AC_CACHE_VAL is expanded from...
../../lib/autoconf/general.m4:2053: AC_CACHE_CHECK is expanded from...
m4/ptyfuncs.m4:1: AX_CHECK_PTYFUNCS is expanded from...
configure.ac:142: the top level

Please rerun autoconf after applying this.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
tools: honour --libdir when it is passed to ./configure

Currently shared libraries are automatically installed into /usr/lib
or /usr/lib64, depending on the supplied --prefix value and
$(XEN_TARGET_ARCH). Some systems, like recent Debian and Ubuntu releases,
do not use /usr/lib64, but instead /usr/lib/x86_64-linux-gnu.

With this change, packagers can supply the desired location for shared
libraries on the ./configure command line. Packagers need to note that
the default behaviour on 64-bit Linux systems will be to install shared
libraries in /usr/lib, not /usr/lib64, unless a --libdir value is provided
to ./configure.

Additionally, the libfsimage plugins are now loaded explicitly from
$LIBDIR/fs, removing platform-based decision trees in code.

Signed-off-by: Matt Wilson <msw@amazon.com>
Acked-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
[ ijc -- resolve rejects in configure by rerunning autogen.sh. Dropped changes
to remove m4/default_lib.m4 and update m4/pkg.m4 since they cause LIBDIR=/lib
instead of /usr/lib. Reran ./autogen.sh after that too ]
Committed-by: Ian Campbell <ian.campbell@citrix.com>
hotplug/Linux: do not leak lockfiles

25590:bb250383a4f5 introduced a new locking scheme.  Unfortunately it
leaves behind files in /var/run/xen-hotplug.  These are spotted as
regressions by the autotester.

Fix this.  This involves changing the locking protocol to allow
lockfiles to be deleted (as removing lockfiles is unsafe with a naive
flock-based algorithm).

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>