tools/libxl & tools/libxc: Add a new "-l" lazy switch.

Add a new "-l" option to xl restore which implies use of lazy restore.
Plumb the lazy argument from libxl to libxc.

Please note that the lazy restore is to be enabled only for HVM guests.
If "-l" is passed as an argument to non HVM guest then the process will
exit with error.

Signed-off-by: Dushyant Behl <myselfdushyantbehl@gmail.com>
tools/libxc: refactored mempaging code from xenpaging to libxc.

This patch moves the code to initialize and teardown mempaging from xenpaging
to libxc. The code refactored from xenpaging is the code which sets up paging,
initializes a shared ring and event channel to communicate with xen. This
communication is done between the hypervisor and the dom0 tool which performs
the activity of pager. Another routine is also added by this patch which will
teardown the ring and mem paging setup. The xenpaging code is changed to use
the newly created routines and is tested to properly build and work with this code.
The refactored code is to be placed in libxc with LGPL license while the old
xenpaging code was under GPL2+ license, hence proper permission has been taken
from previous copyright holders to relicense the code.

The refactoring is done so that the tools lazy restore pager and xenpaging which
rely on memory paging can use the same routines to initialize mempaging. This refactoring
will also allow any future (in-tree) tools to use mempaging. The refactored code in
xc_mem_paging_ring_setup is to be compiled into libxenguest.

Note:- The name of a macro in the file tools/ocaml/libs/xc/xenctrl_stubs.c is changed
from RING_SIZE to BUF_RING_SIZE because the earlier name collides with xen shared ring
definitions in io/ring.h

Signed-off-by: Dushyant Behl <myselfdushyantbehl@gmail.com>
Reviewed-by: Andres Lagar-Cavilla <andres@lagarcavilla.org>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: David Scott <dave.scott@citrix.com>
tools/libxc/xc_mem_paging_setup.c: replacing deprecated function calls.

This patch replaces the calls to the deprecated function
xc_map_foreign_batch with the calls to xc_map_foreign_bulk
in tools/libxc/xc_mem_paging_ring_setup.c
The function xc_map_foreign_bulk has a cleaner error reporting
interface than xc_map_foreign_batch.

Signed-off-by: Dushyant Behl <myselfdushyantbehl@gmail.com>
Reviewed-by: Andres Lagar-Cavilla <andres@lagarcavilla.org>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
tools/libxc/xc_mem_paging_setup.c: FIX- Race condition between initializing shared ring and mempaging.

This patch is meant to fix a known race condition bug in mempaging
ring setup routines. The race condition was between initializing
mem paging and initializing shared ring, earlier the code initialized
mem paging before removing the ring page from guest's physical map
which could enable the guest to interfere with the ring initialisation.
Now the code removes the page from the guest's physical map before
enabling mempaging so that the guest cannot clobber the ring after
we initialise it.

Signed-off-by: Dushyant Behl <myselfdushyantbehl@gmail.com>
Reviewed-by: Andres Lagar-Cavilla <andres@lagarcavilla.org>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Adding hashtable to libxc.

This patch adds the C implementation of hashtable present in
tools/xenstore/hashtable* and tools/blktap2/drivers/hashtable*
to libxc. The files are added to use the hashtable in the
implementation of lazy restore in libxc.

Signed-off-by: Dushyant Behl <myselfdushyantbehl@gmail.com>
Adding pager for lazy restore to libxc domain restore.

This patch adds the functionality of lazy restor pager to the
xc_domain_restore.c, the pager code is highly inspired by the
xenpaging code.
The pager is run in a separate daemon process which processes
requests for page in one by one through a shared ring and event
channel setup with xen.

Changed a few things here and there,
1. Used old code's apply_batch to populate the pages.
2. Introduced a new fallback flag to differentiate between the first pass
   to apply_batch (where we only populate the pages) and second pass (where we
   actually load pages from the file and apply them).
3. Removed the code which used xenstore due to linking issue. Although this
   also removed the code by which we check for doamin shutdown, which is
   actually necessary. I think.
4. Moved the libxl callback code to the end of the restore function -
   This is because the fallback to normal restore process takes a lot of time
   loading the actual memory pages and if the callback is called before that
   then there is a race condition where xl toolstack gets corrupt due to the
   callback cleanup.
5. Moved the code which nominates and evicts pfn's to the pager, which is called
   after the ring is inplace.
   Please have a look at this code it is relatively new.

Signed-off-by:- Dushyant Behl <myselfdushyantbehl@gmail.com>